@univerjs/engine-formula 0.1.2 → 0.1.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 +5872 -4638
- package/lib/types/basics/common.d.ts +11 -4
- package/lib/types/basics/date.d.ts +1 -1
- package/lib/types/basics/format.d.ts +24 -0
- package/lib/types/basics/inverted-index-cache.d.ts +2 -2
- package/lib/types/basics/match-token.d.ts +5 -0
- package/lib/types/basics/object-class-type.d.ts +4 -0
- package/lib/types/basics/runtime.d.ts +2 -1
- package/lib/types/basics/token-type.d.ts +1 -0
- package/lib/types/basics/token.d.ts +1 -0
- package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +2 -2
- package/lib/types/engine/analysis/lexer-tree-builder.d.ts +5 -1
- package/lib/types/engine/analysis/parser.d.ts +0 -1
- package/lib/types/engine/ast-node/reference-node.d.ts +3 -3
- package/lib/types/engine/dependency/dependency-tree.d.ts +20 -4
- package/lib/types/engine/dependency/formula-dependency.d.ts +0 -6
- package/lib/types/engine/reference-object/base-reference-object.d.ts +8 -6
- package/lib/types/engine/utils/ast-node-tool.d.ts +18 -0
- package/lib/types/engine/utils/char-kit.d.ts +25 -0
- package/lib/types/engine/utils/compare.d.ts +1 -0
- package/lib/types/engine/utils/object-compare.d.ts +0 -1
- package/lib/types/engine/utils/prefixHandler.d.ts +24 -0
- package/lib/types/engine/utils/r1c1-reference.d.ts +2 -3
- package/lib/types/engine/utils/reference.d.ts +4 -9
- package/lib/types/engine/value-object/__tests__/array-value-divided.spec.d.ts +16 -0
- package/lib/types/engine/value-object/__tests__/array-value-minus.spec.d.ts +16 -0
- package/lib/types/engine/value-object/__tests__/array-value-multiply.spec.d.ts +16 -0
- package/lib/types/engine/value-object/__tests__/array-value-plus.spec.d.ts +16 -0
- package/lib/types/engine/value-object/array-value-object.d.ts +7 -7
- package/lib/types/engine/value-object/base-value-object.d.ts +9 -4
- package/lib/types/engine/value-object/cube-value-object.d.ts +30 -0
- package/lib/types/engine/value-object/lambda-value-object.d.ts +1 -0
- package/lib/types/engine/value-object/primitive-object.d.ts +25 -4
- package/lib/types/functions/base-function.d.ts +4 -9
- package/lib/types/functions/logical/or/__tests__/index.spec.d.ts +16 -0
- package/lib/types/functions/logical/or/index.d.ts +20 -0
- package/lib/types/functions/lookup/function-map.d.ts +1 -4
- package/lib/types/functions/lookup/index/index.d.ts +11 -2
- package/lib/types/functions/lookup/offset/index.d.ts +2 -2
- package/lib/types/functions/meta/cube/index.d.ts +20 -0
- package/lib/types/functions/meta/function-map.d.ts +2 -2
- package/lib/types/functions/meta/function-names.d.ts +2 -1
- package/lib/types/functions/text/len/__test__/index.spec.d.ts +16 -0
- package/lib/types/functions/text/len/index.d.ts +21 -0
- package/lib/types/functions/text/lenb/__test__/index.spec.d.ts +16 -0
- package/lib/types/functions/text/lenb/index.d.ts +21 -0
- package/lib/types/functions/text/text/__test__/index.spec.d.ts +16 -0
- package/lib/types/functions/text/text/index.d.ts +20 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/current-data.service.d.ts +3 -0
- package/lib/umd/index.js +1 -1
- package/package.json +13 -11
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(D,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],d):(D=typeof globalThis<"u"?globalThis:D||self,d(D.UniverEngineFormula={},D.UniverCore,D["@wendellhu/redi"],D.rxjs))})(this,function(D,d,B,Ft){"use strict";var Su=Object.defineProperty;var Lu=(D,d,B)=>d in D?Su(D,d,{enumerable:!0,configurable:!0,writable:!0,value:B}):D[d]=B;var p=(D,d,B)=>(Lu(D,typeof d!="symbol"?d+"":d,B),B);function Er(n,r,e,t,s){for(let i=0,a=n.length;i<a;i++){const u=n[i];if(r!==u.unitId||e!==u.sheetId)continue;const{startRow:o,startColumn:l,endRow:f,endColumn:m}=u.range;if(t>=o&&t<=f&&s>=l&&s<=m)return!0}return!1}var c=(n=>(n.DIV_BY_ZERO="#DIV/0!",n.NAME="#NAME?",n.VALUE="#VALUE!",n.NUM="#NUM!",n.NA="#N/A",n.CYCLE="#CYCLE!",n.REF="#REF!",n.SPILL="#SPILL!",n.CALC="#CALC!",n.ERROR="#ERROR!",n.CONNECT="#GETTING_DATA",n.NULL="#NULL!",n))(c||{});const Ne=new Set(Object.values(c));var wr=(n=>(n[n.Financial=0]="Financial",n[n.Date=1]="Date",n[n.Math=2]="Math",n[n.Statistical=3]="Statistical",n[n.Lookup=4]="Lookup",n[n.Database=5]="Database",n[n.Text=6]="Text",n[n.Logical=7]="Logical",n[n.Information=8]="Information",n[n.Engineering=9]="Engineering",n[n.Cube=10]="Cube",n[n.Compatibility=11]="Compatibility",n[n.Web=12]="Web",n[n.Array=13]="Array",n[n.Univer=14]="Univer",n[n.User=15]="User",n))(wr||{}),J=(n=>(n.PLUS="+",n.MINUS="-",n.MULTIPLY="*",n.DIVIDED="/",n.CONCATENATE="&",n.POWER="^",n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(J||{}),b=(n=>(n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(b||{});const et=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),He=new Set(et.keys()),zn=new Set(["=","<>",">",">=","<","<="]);var O=(n=>(n.OPEN_BRACKET="(",n.CLOSE_BRACKET=")",n.COMMA=",",n.SINGLE_QUOTATION="'",n.DOUBLE_QUOTATION='"',n.OPEN_BRACES="{",n.CLOSE_BRACES="}",n.COLON=":",n.OPEN_SQUARE_BRACKET="[",n.CLOSE_SQUARE_BRACKET="]",n))(O||{}),he=(n=>(n.PERCENTAGE="%",n.POUND="#",n))(he||{});const Zn=new Set(["%","#"]);var Y=(n=>(n.AT="@",n.MINUS="-",n))(Y||{});const _r=[...Object.values(b),...Object.values(J),...Object.values(O),...Object.values(he),...Object.values(Y)];function tt(n){return _r.includes(n)}function Cr(n){for(const r of _r)if(n.indexOf(r)>-1)return!0;return!1}function Jn(n){return n[0]==="'"&&n[n.length-1]==="'"?n.substring(1,n.length-1):n}function pr(n){const r={};return Object.keys(n).forEach(e=>{const t=n[e];if(t==null)return!0;r[e]==null&&(r[e]={}),Object.keys(t).forEach(s=>{const i=t[s];r[e][s]=new d.ObjectMatrix(i)})}),r}const $t={id:"formula.mutation.register-function",type:d.CommandType.MUTATION,handler:()=>!0};class rt{constructor(r){p(this,"_cache");this._cache=new d.LRUMap(r)}set(r,e){const t=this._hash(r);this._cache.set(t,e)}get(r){const e=this._hash(r);return this._cache.get(e)}clear(){this._cache.clear()}_hash(r){return d.hashAlgorithm(r)}}const kt='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Nn="((?![\\[\\]\\/?*\\\\]).)*!",de="$",It="\\s*?:\\s*?",Me=`'?(${kt})?(${Nn})?'?`,Tt=`\\${de}?[A-Za-z]+\\${de}?[0-9]+`,es=`^(${Y.AT})?${Me}${Tt}${It}${Tt}$`,nt=`^${Me}\\s*?${Tt}(${he.POUND})?$`,Dr=`^${Me}\\${de}?[0-9]+${It}\\${de}?[0-9]+$`,yr=`^${Me}\\${de}?[A-Za-z]+${It}\\${de}?[A-Za-z]+$`,ts=`^${Me}\\s*?\\${de}?[0-9]+$`,rs=`^${Me}\\s*?\\${de}?[A-Za-z]+$`,br="[.*?]",ns="{.*?}";function Sr(n){return new RegExp(nt).test(n)||new RegExp(es).test(n)||new RegExp(Dr).test(n)||new RegExp(yr).test(n)}const pe="P_1",Re="R_1",Oe="L_1",je="LR_1",Lr="LO_1",ss="LET",We="LAMBDA",is=/[^0-9]/g,as=/[^A-Za-z]/g;function Xe(n){const r=n[0]==="$",t=n.substring(1).indexOf("$")>-1;return r&&t?d.AbsoluteRefType.ALL:r?d.AbsoluteRefType.COLUMN:t?d.AbsoluteRefType.ROW:d.AbsoluteRefType.NONE}function us(n){const r=n.split("!");r.length>1&&(n=r[r.length-1]);const e=n.split(":");return e.length>1?{startAbsoluteRefType:Xe(e[0]),endAbsoluteRefType:Xe(e[1])}:{startAbsoluteRefType:Xe(e[0])}}function Ar(n=d.AbsoluteRefType.NONE){let r="",e="";return n===d.AbsoluteRefType.ROW?r="$":n===d.AbsoluteRefType.COLUMN?e="$":n===d.AbsoluteRefType.ALL&&(r="$",e="$"),{rowAbsoluteString:r,columnAbsoluteString:e}}function De(n){const{startColumn:r,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:u=d.RANGE_TYPE.NORMAL}=n,o=Ar(i),l=Ar(a);if(u===d.RANGE_TYPE.ROW||u===d.RANGE_TYPE.ALL){const g=`${o.rowAbsoluteString}${e+1}`,R=`${l.rowAbsoluteString}${s+1}`;return`${g}:${R}`}if(u===d.RANGE_TYPE.COLUMN){const g=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}`,R=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}`;return`${g}:${R}`}const f=`${o.columnAbsoluteString}${d.Tools.chatAtABC(r)}${o.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return f===m?f:`${f}:${m}`}function Pr(n,r){return st(n)?`'${n}'!${De(r)}`:`${n}!${De(r)}`}function Vr(n,r,e){return st(n)||st(r)?`'[${n}]${r}'!${De(e)}`:`[${n}]${r}!${De(e)}`}function xr(n){const{unitId:r,sheetName:e,range:t}=n;return r!=null&&r.length>0&&e!=null&&e.length>0?Vr(r,e,t):e!=null&&e.length>0?Pr(e,t):De(t)}function Qt(n){const r=Number.parseInt(n.replace(is,""))-1,e=d.Tools.ABCatNum(n.replace(as,"")),t=Xe(n);return{row:r,column:e,absoluteRefType:t}}function vr(n){const r=new RegExp(kt).exec(n);let e="";r!=null&&(e=r[0].trim(),e=e.slice(1,e.length-1),n=n.replace(new RegExp(kt),""));const t=n.indexOf("!");let s="",i="";return t>-1?(s=n.substring(0,t),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=n.substring(t)):i=n,{refBody:i,sheetName:s,unitId:e}}function Fe(n){const{refBody:r,sheetName:e,unitId:t}=vr(n),s=r.indexOf(":");if(s===-1){const w=Qt(r),E=w.row,C=w.column,y=w.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:E,startColumn:C,endRow:E,endColumn:C,startAbsoluteRefType:y,endAbsoluteRefType:y}}}const i=r.substring(0,s),a=r.substring(s+1),u=Qt(i),o=Qt(a),l=u.row,f=u.column,m=o.row,g=o.column;let R=d.RANGE_TYPE.NORMAL;return Number.isNaN(l)&&Number.isNaN(m)?R=d.RANGE_TYPE.COLUMN:Number.isNaN(f)&&Number.isNaN(g)&&(R=d.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:l,startColumn:f,endRow:m,endColumn:g,startAbsoluteRefType:u.absoluteRefType,endAbsoluteRefType:o.absoluteRefType,rangeType:R}}}function st(n){return n.length===0?!1:!!(Cr(n)||os(n)||ls(n)||cs(n)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(n))}function os(n){const r=n.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(n)&&r!==null&&Number.parseInt(r[0],10)<=1048576}function ls(n){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(n)}function cs(n){return!new RegExp("^\\p{Letter}","u").test(n.charAt(0))}var te=(n=>(n[n.NORMAL=0]="NORMAL",n[n.NUMBER=1]="NUMBER",n[n.STRING=2]="STRING",n[n.FUNCTION=3]="FUNCTION",n[n.REFERENCE=4]="REFERENCE",n[n.ARRAY=5]="ARRAY",n))(te||{});function Br(n){let r="";for(const e of n)typeof e=="string"?r+=e:r+=e.token;return r}class U{constructor(){p(this,"_parent");p(this,"_token",Re);p(this,"_children",[]);p(this,"_lambdaId");p(this,"_functionDefinitionPrivacyVar");p(this,"_lambdaParameter","");p(this,"_startIndex",-1);p(this,"_endIndex",-1)}dispose(){var r;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(r=this._functionDefinitionPrivacyVar)==null||r.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(r){this._lambdaId=r}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(r){this._functionDefinitionPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(r){this._lambdaParameter=r}getParent(){return this._parent}setParent(r){this._parent=r}getChildren(){return this._children}setChildren(r){this._children=r}addChildren(r){this._children.push(r)}addChildrenFirst(r){this._children.unshift(r)}getToken(){return this._token}setToken(r){this._token=r}setIndex(r,e){this._startIndex=r,this._endIndex=e}replaceChild(r,e){const t=this._getIndexInParent(r);t!=null&&(this.getChildren().splice(t,1,e),e.setParent(this))}changeToParent(r){const e=this.getParent();e&&e.removeChild(this),this.setParent(r),r.getChildren().push(this)}removeChild(r){const e=this._getIndexInParent(r);e!=null&&this.getChildren().splice(e,1)}serialize(){const r=this.getToken(),e=this.getChildren(),t=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof U?t.push(a.serialize()):t.push(a)}return{token:r,st:this._startIndex,ed:this._endIndex,children:t}}_getIndexInParent(r){const e=this.getChildren(),t=e.length;for(let s=0;s<t;s++)if(e[s]===r)return s}}const Ur=1e5,Yt=new rt(Ur),Ht=new rt(Ur);class it extends d.Disposable{constructor(){super(...arguments);p(this,"_currentLexerNode",new U);p(this,"_upLevel",0);p(this,"_segment","");p(this,"_bracketState",[]);p(this,"_squareBracketState",0);p(this,"_bracesState",0);p(this,"_singleQuotationState",0);p(this,"_doubleQuotationState",0);p(this,"_lambdaState",!1);p(this,"_colonState",!1);p(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Yt.clear(),Ht.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const s=this._getCurrentParamIndex(e,t);if(s==null||s===c.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),u=i;for(;a;){const o=a.getToken();if(o!==pe&&!tt(o)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(u);return{functionName:o,paramIndex:l}}u=a,a=a.getParent()}}moveFormulaRefOffset(e,t,s){const i=this.sequenceNodesBuilder(e);if(i==null)return e;const a=[];for(let u=0,o=i.length;u<o;u++){const l=i[u];if(typeof l=="string"||l.nodeType!==te.REFERENCE){a.push(l);continue}const{token:f}=l,m=Fe(f),{range:g,sheetName:R,unitId:w}=m,E=d.Rectangle.moveOffset(g,t,s);let C="";d.isValidRange(E)?C=xr({range:E,unitId:w,sheetName:R}):C=c.REF,a.push({...l,token:C})}return`=${Br(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===O.CLOSE_BRACKET||i===" ")&&s>=0;)i===O.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===c.VALUE)return 0;const u=a[0];if(typeof u=="string")return 0;let o=u.getParent(),l=0;for(a[1]===O.OPEN_BRACKET&&l++;o;){const f=o.getToken();f!==pe&&f!==O.COLON&&o.getStartIndex()!==-1&&f.toUpperCase()!==We&&(t===0?l+=1:t--),o=o.getParent()}return l}sequenceNodesBuilder(e){const t=Ht.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Ht.set(e,[...i]),i}getSequenceNode(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const u=e[i],o=e[i-1],{segment:l,currentString:f,cur:m}=u;if(f===O.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(f);continue}let g=(o==null?void 0:o.segment)||"";const R=i-g.length;let w=i-1;const E=i-1;if(i===a-1&&this._isLastMergeString(f)&&(g+=f,w+=1),g===""||et.has(g)){t.push(f);continue}const C=g.trim(),y=this._replacePrefixString(C);s===!0&&C[C.length-1]===O.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(t,{nodeType:te.STRING,token:g,startIndex:R,endIndex:w},E)):new RegExp(nt).test(y)?this._pushSequenceNode(t,{nodeType:te.REFERENCE,token:g,startIndex:R,endIndex:w},E):d.Tools.isStringNumber(C)?this._pushSequenceNode(t,{nodeType:te.NUMBER,token:g,startIndex:R,endIndex:w},E):C.length>0&&this._pushSequenceNode(t,{nodeType:te.FUNCTION,token:g,startIndex:R,endIndex:w},E),(i!==a-1||!this._isLastMergeString(f))&&t.push(f)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===O.DOUBLE_QUOTATION||d.Tools.isStringNumber(e)||!tt(e)}_mergeSequenceNodeReference(e){const t=[],s=e.length;let i=0;for(;i<s;){const a=e[i];if(typeof a=="string"){const u=e[i-1];if(a.trim()===O.CLOSE_BRACES&&u!=null&&typeof u!="string"&&u.nodeType===te.FUNCTION&&u.token.trim().substring(0,1)===O.OPEN_BRACES){u.nodeType=te.ARRAY,u.token+=a,u.endIndex+=a.length,i++;continue}t.push(a)}else{const u=e[i+1],o=e[i+2];u===O.COLON&&typeof a!="string"&&o!=null&&typeof o!="string"&&Sr((a.token+u+o.token).trim())&&(a.nodeType=te.REFERENCE,a.token+=u+o.token,a.endIndex=o.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){return e.replace(new RegExp(Y.AT,"g"),"").replace(new RegExp(Y.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const f=Yt.get(e);if(f)return f}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re);const i=[];let a=this._nodeMaker(e,i);if(a===c.VALUE||i.length===0)return a;let u=!1,o="";if(s){const{hasDefinedName:f,sequenceString:m}=s(i);u=f,o=m}if(u&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re),a=this._nodeMaker(`=${o}`),a===c.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),t&&(this._suffixExpressionHandler(this._currentLexerNode),Yt.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var u,o;const t=e.getChildren();if(!t)return;const s=t.length,i=[],a=[];for(let l=0;l<s;l++){const f=t[l];if(f instanceof U)this._suffixExpressionHandler(f),i.push(f);else{const m=f.trim();if(m==="")continue;if(He.has(m)){for(;a.length>0;){const g=(u=a[a.length-1])==null?void 0:u.trim();if(!g||g===O.OPEN_BRACKET)break;const R=et.get(g),w=et.get(m);if(!R||!w)break;if(w>=R)i.push(a.pop());else break}a.push(f)}else if(m===O.OPEN_BRACKET)a.push(f);else if(m===O.CLOSE_BRACKET)for(;a.length>0;){const g=(o=a[a.length-1])==null?void 0:o.trim();if(!g)break;if(g===O.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(f)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new U}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof U)return t}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var s,i,a,u,o,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===Oe){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const f=(u=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:u.getParent();f&&(this._currentLexerNode=f),t=!0}}else if(e!=null&&e.getParent()){const f=(o=this._currentLexerNode.getParent())==null?void 0:o.getParent();f&&(this._currentLexerNode=f),t=!0}for(let f=0;f<this._upLevel;f++){const m=(l=this._currentLexerNode)==null?void 0:l.getParent();m&&(this._currentLexerNode=m),this._currentLexerNode?t=!0:t=!1}return t}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,t=!1){if(e!==""){const s=this._currentLexerNode.getChildren();if(!(e instanceof U)&&this.isColonOpen()){const i=new U;i.setToken(e),i.setParent(this._currentLexerNode),e=i}t?s.unshift(e):s.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,t=!1){this._pushNodeToChildren(e,t),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,t,s=!1){const i=new U;i.setToken(e),i.setIndex(t-e.length,t-1),this._setCurrentLexerNode(i,s)}_getTopNode(e){let t=e;for(;t!=null&&t.getParent();)t=t.getParent();return t}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,t){for(;t>=0;){const s=e[t];if(s!==" ")return s;t--}}_negativeCondition(e){return!!(He.has(e)||e===O.OPEN_BRACKET||e===O.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new U,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,t,s){if(e!==he.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!tt(i)}_nodeMaker(e,t,s){e.substring(0,1)===J.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let u=0;for(this._resetTemp();u<a;){const o=i[u];if(s===u)return[this._currentLexerNode,o];if(o===O.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,u),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[u+1];if(l&&l===O.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==a-1)return c.VALUE;u++}else l&&this._newAndPushCurrentLexerNode(pe,u)}else this._pushNodeToChildren(o),this._openBracket(0);else if(o===O.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(o);else if(l===1){const f=i[u+1];if(f&&f===O.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==a-1)return c.VALUE;this._newAndPushCurrentLexerNode(Oe,u,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&u!==a-1)return c.VALUE}else return c.VALUE;this._closeBracket()}else if(o===O.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(o),this._openBraces();else if(o===O.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(o),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(o===O.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(o),this._openSquareBracket();else if(o===O.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(o),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(o);else if(o===O.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[u+1];l&&l===O.DOUBLE_QUOTATION?u++:this._closeDoubleQuotation()}this._pushSegment(o)}else if(o===O.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[u+1];l&&l===O.SINGLE_QUOTATION?u++:this._closeSingleQuotation()}this._pushSegment(o)}else if(o===O.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&u!==a-1&&l!=null)return c.VALUE;this._newAndPushCurrentLexerNode(pe,u)}else return c.VALUE}else if(o===O.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new U;l.setToken(o);const f=new U;f.setToken(pe),f.setParent(l);const m=new U;m.setToken(pe),m.setParent(l),l.getChildren().push(f,m);let g=l,R=0;if(this._segmentCount()>0){let w,E,C=0;const y=this._segment.trim(),S=y[0],L=y[1];if(S===Y.MINUS&&(w=new U,w.setToken(Y.MINUS),C++),(S===Y.AT||L===Y.AT)&&(E=new U,E.setToken(Y.AT),w&&(w.addChildren(E),E.setParent(w)),C++),C>0&&(this._segment=y.slice(C)),R=C,E)if(E.addChildren(l),l.setParent(E),E.getParent()){const I=E.getParent();I&&(g=I)}else g=E;else w&&(g=w,w.addChildren(l),l.setParent(w));const V=new U;V.setToken(this._segment),V.setParent(f),f.getChildren().push(V),this._resetSegment()}else{const w=this._getLastChildCurrentLexerNode();w&&w.changeToParent(f)}this._setCurrentLexerNode(g),this._currentLexerNode=m,this._openColon(R)}else if(Zn.has(o)&&this._checkSimilarErrorToken(o,u,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new U;l.setToken(o);const f=this._getLastChildCurrent();f instanceof U?f.changeToParent(l):f!==!1&&(l.getChildren().push(f),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(He.has(o)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(o===J.MINUS&&l===""){const f=this._findPreviousToken(i,u-1)||"";if(this._negativeCondition(f)){this._pushSegment(J.MINUS),t==null||t.push({segment:this._segment,currentString:o,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(o===J.LESS_THAN||o===J.GREATER_THAN){const f=i[u+1];f&&He.has(o+f)?(this._pushNodeToChildren(l+o+f),u++):this._pushNodeToChildren(l+o)}else this._pushNodeToChildren(l+o);this._resetSegment()}else this._pushSegment(o);t==null||t.push({segment:this._segment,currentString:o,cur:u,currentLexerNode:this._currentLexerNode}),u++}this._pushNodeToChildren(this._segment)}}var fs=Object.defineProperty,hs=Object.getOwnPropertyDescriptor,ms=(n,r,e,t)=>{for(var s=t>1?void 0:t?hs(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&fs(r,e,s),s},Mr=(n,r)=>(e,t)=>r(e,t,n);D.FormulaDataModel=class extends d.Disposable{constructor(e,t){super();p(this,"_formulaData",{});p(this,"_arrayFormulaRange",{});p(this,"_arrayFormulaCellData",{});p(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i],u=(f=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:f[i];if(u==null)return!0;let o=new d.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,w)=>{var V;const E=(V=u==null?void 0:u[R])==null?void 0:V[w];if(E==null)return!0;const{startRow:C,startColumn:y,endRow:S,endColumn:L}=E;for(let I=C;I<=S;I++)for(let Q=y;Q<=L;Q++)o.setValue(I,Q,null)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(s).forEach(i=>{var l,f,m,g;const a=s[i];let u=new d.ObjectMatrix,o=new d.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(u=new d.ObjectMatrix((f=this._arrayFormulaRange[t])==null?void 0:f[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(o=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,w)=>{const E=u==null?void 0:u.getValue(R,w);if(E==null)return!0;const{startRow:C,startColumn:y,endRow:S,endColumn:L}=E;for(let V=C;V<=S;V++)for(let I=y;I<=L;I++)o.setValue(V,I,null)}),a.forValue((R,w,E)=>{o.setValue(R,w,E)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=o.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getNumfmtItemMap(){return this._numfmtItemMap}getNumfmtValue(e,t,s,i){var a,u,o;return(o=(u=(a=this._numfmtItemMap[e])==null?void 0:a[t])==null?void 0:u[s])==null?void 0:o[i]}setNumfmtItemMap(e){this._numfmtItemMap=e}updateNumfmtItemMap(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._numfmtItemMap[t]==null&&(this._numfmtItemMap[t]={}),Object.keys(s).forEach(i=>{const a=s[i],u=new d.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),u.forValue((o,l,f)=>{this._numfmtItemMap[t][i][o]==null&&(this._numfmtItemMap[t][i][o]={}),this._numfmtItemMap[t][i][o][l]=f})})})}mergeArrayFormulaRange(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]||(this._arrayFormulaRange[t]={}),Object.keys(s).forEach(i=>{var o,l;const a=new d.ObjectMatrix(s[i]);let u=new d.ObjectMatrix;(o=this._arrayFormulaRange[t])!=null&&o[i]&&(u=new d.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((f,m,g)=>{u.setValue(f,m,g)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=u.getData())})})}deleteArrayFormulaRange(e,t,s,i){var o;const a=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(a==null)return;const u=new d.ObjectMatrix(a);u.getValue(s,i)&&(u.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=u.getData()))}initFormulaData(){if(this._currentUniverService.getAllUniverSheetsInstance().length===0)return;const t=this._currentUniverService.getCurrentUniverSheetInstance(),s=t.getUnitId();this._formulaData[s]={},t.getSheets().forEach(a=>{const u=a.getCellMatrix(),o=a.getSheetId();Or(this._formulaData,s,o,u)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),u=i.getSheets(),o={},l={};for(const f of u){const m=f.getSheetId(),g=f.getConfig();o[m]={cellData:new d.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount,rowData:g.rowData,columnData:g.columnData},l[f.getName()]=f.getSheetId()}t[a]=o,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new d.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),u=new Map,o=this._formulaData;o[e]==null&&(o[e]={});const l=o[e];l[t]==null&&(l[t]={});const f=new d.ObjectMatrix(l[t]);i.forValue((m,g,R)=>{const w=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"",C=d.isFormulaString(w),y=d.isFormulaId(E);if(C&&y)f.setValue(m,g,{f:w,si:E}),a.set(E,{f:w,r:m,c:g});else if(C&&!y)f.setValue(m,g,{f:w});else if(!C&&y)f.setValue(m,g,{f:"",si:E});else if(!C&&!y&&f.getValue(m,g)){const S=f.getValue(m,g),L=(S==null?void 0:S.f)||"",V=(S==null?void 0:S.si)||"";d.isFormulaString(L)&&d.isFormulaId(V)&&u.set(V,L),f.realDeleteValue(m,g)}}),f.forValue((m,g,R)=>{const w=(R==null?void 0:R.f)||"",E=(R==null?void 0:R.si)||"";if(d.isFormulaId(E)){const C=a.get(E),y=u.get(E);if(C&&!d.isFormulaString(w)){const S=C.f,L=g-C.c,V=m-C.r;f.setValue(m,g,{f:S,si:E,x:L,y:V})}else if(typeof y=="string"){const S=R.x||0,L=R.y||0,V=this._lexerTreeBuilder.moveFormulaRefOffset(y,S,L);u.set(E,{r:m,c:g,f:V}),f.setValue(m,g,{f:V,si:E})}else if(typeof y=="object"){const S=g-y.c,L=m-y.r;f.setValue(m,g,{f:y.f,si:E,x:S,y:L})}}})}updateArrayFormulaRange(e,t,s){var o;const i=(o=this._arrayFormulaRange[e])==null?void 0:o[t];if(!i)return;const a=new d.ObjectMatrix(i);new d.ObjectMatrix(s).forValue((l,f,m)=>{if((a==null?void 0:a.getValue(l,f))==null)return!0;const R=(m==null?void 0:m.f)||"",w=(m==null?void 0:m.si)||"",E=d.isFormulaString(R),C=d.isFormulaId(w);!E&&!C&&a.realDeleteValue(l,f)})}updateArrayFormulaCellData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t];if(!i)return;const a=new d.ObjectMatrix(i),u=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,w)=>{const E=a==null?void 0:a.getValue(g,R);if(E==null)return!0;const C=(w==null?void 0:w.f)||"",y=(w==null?void 0:w.si)||"",S=d.isFormulaString(C),L=d.isFormulaId(y);if(!S&&!L){const{startRow:V,startColumn:I,endRow:Q,endColumn:T}=E;for(let x=V;x<=Q;x++)for(let v=I;v<=T;v++)o.realDeleteValue(x,v)}})}updateNumfmtData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t],a=new d.ObjectMatrix(i),u=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!u)return;const o=new d.ObjectMatrix(u);new d.ObjectMatrix(s).forValue((g,R,w)=>{const E=(w==null?void 0:w.f)||"",C=(w==null?void 0:w.si)||"",y=d.isFormulaString(E),S=d.isFormulaId(C);if(!y&&!S){o.setValue(g,R,null);const L=a.getValue(g,R);if(L){const{startRow:V,startColumn:I,endRow:Q,endColumn:T}=L;for(let x=V;x<=Q;x++)for(let v=I;v<=T;v++)o.setValue(x,v,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const u=new d.ObjectMatrix(a[t]);let o=null;return u.forValue((l,f,m)=>{const{f:g,si:R,x:w=0,y:E=0}=m;if(R===e&&g.length>0&&w===0&&E===0)return o=m,!1}),o}getFormulaDataItem(e,t,s,i){var a,u,o,l;return(l=(o=(u=(a=this._formulaData)==null?void 0:a[i])==null?void 0:u[s])==null?void 0:o[e])==null?void 0:l[t]}getFormulaIdMap(e,t){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[t])==null||new d.ObjectMatrix(a[t]).forValue((o,l,f)=>{const m=(f==null?void 0:f.f)||"",g=(f==null?void 0:f.si)||"",R=(f==null?void 0:f.x)||0,w=(f==null?void 0:f.y)||0;d.isFormulaString(m)&&d.isFormulaId(g)&&R===0&&w===0&&s.set(g,{f:m,r:o,c:l})}),s}},D.FormulaDataModel=ms([Mr(0,d.IUniverInstanceService),Mr(1,B.Inject(it))],D.FormulaDataModel);function Or(n,r,e,t){const s=new Map,i=new d.ObjectMatrix;t.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"",m=d.isFormulaString(l),g=d.isFormulaId(f);m&&g?(i.setValue(a,u,{f:l,si:f}),s.set(f,{f:l,r:a,c:u})):m&&!g?i.setValue(a,u,{f:l}):!m&&g&&i.setValue(a,u,{f:"",si:f})}),i.forValue((a,u,o)=>{const l=(o==null?void 0:o.f)||"",f=(o==null?void 0:o.si)||"";if(d.isFormulaId(f)&&!d.isFormulaString(l)){const m=s.get(f);if(m){const g=m.f,R=u-m.c,w=a-m.r;i.setValue(a,u,{f:g,si:f,x:R,y:w})}}}),n[r]&&(n[r][e]=i.getData())}const gs=n=>{const r=n.get(D.FormulaDataModel),e=d.Tools.deepClone(r.getArrayFormulaRange()),t=d.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},at={id:"formula.mutation.set-array-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>{const e=n.get(D.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},ut={id:"formula.mutation.set-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},ot={id:"formula.mutation.remove-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},jt={id:"formula.mutation.set-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Wt={id:"formula.mutation.remove-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Xt={id:"formula.mutation.set-formula-calculation-start",type:d.CommandType.MUTATION,handler:()=>!0},Gt={id:"formula.mutation.set-formula-calculation-stop",type:d.CommandType.MUTATION,handler:()=>!0},lt={id:"formula.mutation.set-formula-calculation-notification",type:d.CommandType.MUTATION,handler:()=>!0},Kt={id:"formula.mutation.set-formula-calculation-result",type:d.CommandType.MUTATION,handler:()=>!0},qt={id:"formula.mutation.set-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).setFormulaData(r.formulaData),!0)},zt={id:"formula.mutation.set-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.remove-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Fr={id:"formula.mutation.set-super-table",type:d.CommandType.MUTATION,handler:()=>!0},$r={id:"formula.mutation.remove-super-table",type:d.CommandType.MUTATION,handler:()=>!0},Jt={id:"formula.mutation.set-super-table-option",type:d.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.unregister-function",type:d.CommandType.MUTATION,handler:()=>!0};class ct extends d.Disposable{constructor(){super(...arguments);p(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var ye=(n=>(n.FALSE="FALSE",n.TRUE="TRUE",n))(ye||{}),be=(n=>(n[n.SUCCESS=0]="SUCCESS",n[n.ERROR=1]="ERROR",n))(be||{}),Se=(n=>(n.ALL="#All",n.DATA="#Data",n.HEADERS="#Headers",n.TOTALS="#Totals",n))(Se||{}),re=(n=>(n[n.FRONT=0]="FRONT",n[n.BACK=1]="BACK",n))(re||{});class ds{constructor(){p(this,"_cache",new Map);p(this,"_continueBuildingCache",new Map)}set(r,e,t,s,i){if(!this.shouldContinueBuildingCache(r,e,t,i))return;let a=this._cache.get(r);a==null&&(a=new Map,this._cache.set(r,a));let u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);o==null&&(o=new Map,u.set(t,o));let l=o.get(s);l==null&&(l=[],o.set(s,l)),l.push(i)}getCellValuePositions(r,e,t){var s,i;return(i=(s=this._cache.get(r))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(r,e,t,s){var i,a,u;return(u=(a=(i=this._cache.get(r))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:u.get(s)}getCellPosition(r,e,t,s,i,a){const u=this.getCellPositions(r,e,t,s);if(u!=null){for(const o of u)if(o>=i&&o<=a)return o}}setContinueBuildingCache(r,e,t,s,i){let a=this._continueBuildingCache.get(r);a==null&&(a=new Map,this._continueBuildingCache.set(r,a));let u=a.get(e);u==null&&(u=new Map,a.set(e,u));let o=u.get(t);if(o==null){o={startRow:s,endRow:i},u.set(t,o);return}o.startRow=Math.min(o.startRow,s),o.endRow=Math.max(o.endRow,i)}shouldContinueBuildingCache(r,e,t,s){var o,l;const i=(l=(o=this._continueBuildingCache.get(r))==null?void 0:o.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:u}=i;return!(s>=a&&s<=u)}canUseCache(r,e,t,s,i){var l,f;if(t===-1||s===-1||i===-1)return!1;const a=(f=(l=this._continueBuildingCache.get(r))==null?void 0:l.get(e))==null?void 0:f.get(t);if(a==null)return!1;const{startRow:u,endRow:o}=a;return!(s>o||i<u)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const Ee=new ds;var me=(n=>(n[n.MIN=0]="MIN",n[n.MAX=1]="MAX",n))(me||{}),q=(n=>(n[n.NORMAL=0]="NORMAL",n[n.MIN=1]="MIN",n[n.MAX=2]="MAX",n))(q||{});function kr(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(n,r)=>n.localeCompare(r)}function Rs(n){return n.indexOf("*")>-1||n.indexOf("?")>-1}function Ir(n,r){const e=r.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(n)}function Tr(n){return n.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Es(n,r,e){let t=!1;switch(e){case b.EQUALS:t=Ir(n,r);break;case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:t=Ir(n,r)||n>Tr(r);break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:t=n<Tr(r);break}return t}class we extends ct{constructor(r){super(),this._rawValue=r}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(r){}setArrayValue(r){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new h(c.VALUE)}max(){return new h(c.VALUE)}min(){return new h(c.VALUE)}count(){return new h(c.VALUE)}countA(){return new h(c.VALUE)}countBlank(){return new h(c.VALUE)}getNegative(){return new h(c.NAME)}getReciprocal(){return new h(c.NAME)}plus(r){return new h(c.NAME)}minus(r){return new h(c.NAME)}multiply(r){return new h(c.NAME)}divided(r){return new h(c.NAME)}mod(r){return new h(c.VALUE)}map(r){return new h(c.NAME)}mapValue(r){return new h(c.NAME)}product(r,e){return e(this,r)}compare(r,e){return new h(c.NAME)}isEqual(r){return this.compare(r,b.EQUALS)}isNotEqual(r){return this.compare(r,b.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,b.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,b.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,b.LESS_THAN)}isGreaterThan(r){return this.compare(r,b.GREATER_THAN)}concatenateFront(r){return new h(c.NAME)}concatenateBack(r){return new h(c.NAME)}plusBy(r){return new h(c.NAME)}minusBy(r){return new h(c.NAME)}multiplyBy(r){return new h(c.NAME)}dividedBy(r){return new h(c.NAME)}modInverse(r){return new h(c.VALUE)}compareBy(r,e){return new h(c.NAME)}concatenate(r,e=re.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===re.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===re.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const s=r?"TRUE":"FALSE";e===re.FRONT?t=s+t:t+=s}return t}pow(r){return new h(c.VALUE)}powInverse(r){return new h(c.VALUE)}sqrt(){return new h(c.VALUE)}cbrt(){return new h(c.VALUE)}cos(){return new h(c.VALUE)}acos(){return new h(c.VALUE)}acosh(){return new h(c.VALUE)}sin(){return new h(c.VALUE)}asin(){return new h(c.VALUE)}asinh(){return new h(c.VALUE)}tan(){return new h(c.VALUE)}tanh(){return new h(c.VALUE)}atan(){return new h(c.VALUE)}atan2(r){return new h(c.VALUE)}atan2Inverse(r){return new h(c.VALUE)}atanh(){return new h(c.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new h(c.VALUE)}log10(){return new h(c.VALUE)}exp(){return new h(c.VALUE)}abs(){return new h(c.VALUE)}round(r){return new h(c.VALUE)}roundInverse(r){return new h(c.VALUE)}floor(r){return new h(c.VALUE)}floorInverse(r){return new h(c.VALUE)}ceil(r){return new h(c.VALUE)}ceilInverse(r){return new h(c.VALUE)}}class h extends we{constructor(r,e=""){super(r),this._errorType=r,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(r){return r.getErrorType()===this.getErrorType()}isError(){return!0}}var ws=20,_s=1,Le=1e6,Qr=1e6,Cs=-7,ps=21,Ds=!1,Ge="[big.js] ",Ae=Ge+"Invalid ",ft=Ae+"decimal places",ys=Ae+"rounding mode",Yr=Ge+"Division by zero",F={},ae=void 0,bs=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Hr(){function n(r){var e=this;if(!(e instanceof n))return r===ae?Hr():new n(r);if(r instanceof n)e.s=r.s,e.e=r.e,e.c=r.c.slice();else{if(typeof r!="string"){if(n.strict===!0&&typeof r!="bigint")throw TypeError(Ae+"value");r=r===0&&1/r<0?"-0":String(r)}Ss(e,r)}e.constructor=n}return n.prototype=F,n.DP=ws,n.RM=_s,n.NE=Cs,n.PE=ps,n.strict=Ds,n.roundDown=0,n.roundHalfUp=1,n.roundHalfEven=2,n.roundUp=3,n}function Ss(n,r){var e,t,s;if(!bs.test(r))throw Error(Ae+"number");for(n.s=r.charAt(0)=="-"?(r=r.slice(1),-1):1,(e=r.indexOf("."))>-1&&(r=r.replace(".","")),(t=r.search(/e/i))>0?(e<0&&(e=t),e+=+r.slice(t+1),r=r.substring(0,t)):e<0&&(e=r.length),s=r.length,t=0;t<s&&r.charAt(t)=="0";)++t;if(t==s)n.c=[n.e=0];else{for(;s>0&&r.charAt(--s)=="0";);for(n.e=e-t-1,n.c=[],e=0;t<=s;)n.c[e++]=+r.charAt(t++)}return n}function Pe(n,r,e,t){var s=n.c;if(e===ae&&(e=n.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ys);if(r<1)t=e===3&&(t||!!s[0])||r===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(t||s[1]!==ae))),s.length=1,t?(n.e=n.e-r+1,s[0]=1):s[0]=n.e=0;else if(r<s.length){if(t=e===1&&s[r]>=5||e===2&&(s[r]>5||s[r]===5&&(t||s[r+1]!==ae||s[r-1]&1))||e===3&&(t||!!s[0]),s.length=r,t){for(;++s[--r]>9;)if(s[r]=0,r===0){++n.e,s.unshift(1);break}}for(r=s.length;!s[--r];)s.pop()}return n}function $e(n,r,e){var t=n.e,s=n.c.join(""),i=s.length;if(r)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)s="0"+s;s="0."+s}else if(t>0)if(++t>i)for(t-=i;t--;)s+="0";else t<i&&(s=s.slice(0,t)+"."+s.slice(t));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return n.s<0&&e?"-"+s:s}F.abs=function(){var n=new this.constructor(this);return n.s=1,n},F.cmp=function(n){var r,e=this,t=e.c,s=(n=new e.constructor(n)).c,i=e.s,a=n.s,u=e.e,o=n.e;if(!t[0]||!s[0])return t[0]?i:s[0]?-a:0;if(i!=a)return i;if(r=i<0,u!=o)return u>o^r?1:-1;for(a=(u=t.length)<(o=s.length)?u:o,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^r?1:-1;return u==o?0:u>o^r?1:-1},F.div=function(n){var r=this,e=r.constructor,t=r.c,s=(n=new e(n)).c,i=r.s==n.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>Le)throw Error(ft);if(!s[0])throw Error(Yr);if(!t[0])return n.s=i,n.c=[n.e=0],n;var u,o,l,f,m,g=s.slice(),R=u=s.length,w=t.length,E=t.slice(0,u),C=E.length,y=n,S=y.c=[],L=0,V=a+(y.e=r.e-n.e)+1;for(y.s=i,i=V<0?0:V,g.unshift(0);C++<u;)E.push(0);do{for(l=0;l<10;l++){if(u!=(C=E.length))f=u>C?1:-1;else for(m=-1,f=0;++m<u;)if(s[m]!=E[m]){f=s[m]>E[m]?1:-1;break}if(f<0){for(o=C==u?s:g;C;){if(E[--C]<o[C]){for(m=C;m&&!E[--m];)E[m]=9;--E[m],E[C]+=10}E[C]-=o[C]}for(;!E[0];)E.shift()}else break}S[L++]=f?l:++l,E[0]&&f?E[C]=t[R]||0:E=[t[R]]}while((R++<w||E[0]!==ae)&&i--);return!S[0]&&L!=1&&(S.shift(),y.e--,V--),L>V&&Pe(y,V,e.RM,E[0]!==ae),y},F.eq=function(n){return this.cmp(n)===0},F.gt=function(n){return this.cmp(n)>0},F.gte=function(n){return this.cmp(n)>-1},F.lt=function(n){return this.cmp(n)<0},F.lte=function(n){return this.cmp(n)<1},F.minus=F.sub=function(n){var r,e,t,s,i=this,a=i.constructor,u=i.s,o=(n=new a(n)).s;if(u!=o)return n.s=-o,i.plus(n);var l=i.c.slice(),f=i.e,m=n.c,g=n.e;if(!l[0]||!m[0])return m[0]?n.s=-o:l[0]?n=new a(i):n.s=1,n;if(u=f-g){for((s=u<0)?(u=-u,t=l):(g=f,t=m),t.reverse(),o=u;o--;)t.push(0);t.reverse()}else for(e=((s=l.length<m.length)?l:m).length,u=o=0;o<e;o++)if(l[o]!=m[o]){s=l[o]<m[o];break}if(s&&(t=l,l=m,m=t,n.s=-n.s),(o=(e=m.length)-(r=l.length))>0)for(;o--;)l[r++]=0;for(o=r;e>u;){if(l[--e]<m[e]){for(r=e;r&&!l[--r];)l[r]=9;--l[r],l[e]+=10}l[e]-=m[e]}for(;l[--o]===0;)l.pop();for(;l[0]===0;)l.shift(),--g;return l[0]||(n.s=1,l=[g=0]),n.c=l,n.e=g,n},F.mod=function(n){var r,e=this,t=e.constructor,s=e.s,i=(n=new t(n)).s;if(!n.c[0])throw Error(Yr);return e.s=n.s=1,r=n.cmp(e)==1,e.s=s,n.s=i,r?new t(e):(s=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(n),t.DP=s,t.RM=i,this.minus(e.times(n)))},F.neg=function(){var n=new this.constructor(this);return n.s=-n.s,n},F.plus=F.add=function(n){var r,e,t,s=this,i=s.constructor;if(n=new i(n),s.s!=n.s)return n.s=-n.s,s.minus(n);var a=s.e,u=s.c,o=n.e,l=n.c;if(!u[0]||!l[0])return l[0]||(u[0]?n=new i(s):n.s=s.s),n;if(u=u.slice(),r=a-o){for(r>0?(o=a,t=l):(r=-r,t=u),t.reverse();r--;)t.push(0);t.reverse()}for(u.length-l.length<0&&(t=l,l=u,u=t),r=l.length,e=0;r;u[r]%=10)e=(u[--r]=u[r]+l[r]+e)/10|0;for(e&&(u.unshift(e),++o),r=u.length;u[--r]===0;)u.pop();return n.c=u,n.e=o,n},F.pow=function(n){var r=this,e=new r.constructor("1"),t=e,s=n<0;if(n!==~~n||n<-Qr||n>Qr)throw Error(Ae+"exponent");for(s&&(n=-n);n&1&&(t=t.times(r)),n>>=1,!!n;)r=r.times(r);return s?e.div(t):t},F.prec=function(n,r){if(n!==~~n||n<1||n>Le)throw Error(Ae+"precision");return Pe(new this.constructor(this),n,r)},F.round=function(n,r){if(n===ae)n=0;else if(n!==~~n||n<-Le||n>Le)throw Error(ft);return Pe(new this.constructor(this),n+this.e+1,r)},F.sqrt=function(){var n,r,e,t=this,s=t.constructor,i=t.s,a=t.e,u=new s("0.5");if(!t.c[0])return new s(t);if(i<0)throw Error(Ge+"No square root");i=Math.sqrt(t+""),i===0||i===1/0?(r=t.c.join(""),r.length+a&1||(r+="0"),i=Math.sqrt(r),a=((a+1)/2|0)-(a<0||a&1),n=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):n=new s(i+""),a=n.e+(s.DP+=4);do e=n,n=u.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==n.c.slice(0,a).join(""));return Pe(n,(s.DP-=4)+n.e+1,s.RM)},F.times=F.mul=function(n){var r,e=this,t=e.constructor,s=e.c,i=(n=new t(n)).c,a=s.length,u=i.length,o=e.e,l=n.e;if(n.s=e.s==n.s?1:-1,!s[0]||!i[0])return n.c=[n.e=0],n;for(n.e=o+l,a<u&&(r=s,s=i,i=r,l=a,a=u,u=l),r=new Array(l=a+u);l--;)r[l]=0;for(o=u;o--;){for(u=0,l=a+o;l>o;)u=r[l]+i[o]*s[l-o-1]+u,r[l--]=u%10,u=u/10|0;r[l]=u}for(u?++n.e:r.shift(),o=r.length;!r[--o];)r.pop();return n.c=r,n},F.toExponential=function(n,r){var e=this,t=e.c[0];if(n!==ae){if(n!==~~n||n<0||n>Le)throw Error(ft);for(e=Pe(new e.constructor(e),++n,r);e.c.length<n;)e.c.push(0)}return $e(e,!0,!!t)},F.toFixed=function(n,r){var e=this,t=e.c[0];if(n!==ae){if(n!==~~n||n<0||n>Le)throw Error(ft);for(e=Pe(new e.constructor(e),n+e.e+1,r),n=n+e.e+1;e.c.length<n;)e.c.push(0)}return $e(e,!1,!!t)},F[Symbol.for("nodejs.util.inspect.custom")]=F.toJSON=F.toString=function(){var n=this,r=n.constructor;return $e(n,n.e<=r.NE||n.e>=r.PE,!!n.c[0])},F.toNumber=function(){var n=Number($e(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(n.toString()))throw Error(Ge+"Imprecise conversion");return n},F.toPrecision=function(n,r){var e=this,t=e.constructor,s=e.c[0];if(n!==ae){if(n!==~~n||n<1||n>Le)throw Error(Ae+"precision");for(e=Pe(new t(e),n,r);e.c.length<n;)e.c.push(0)}return $e(e,n<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)},F.valueOf=function(){var n=this,r=n.constructor;if(r.strict===!0)throw Error(Ge+"valueOf disallowed");return $e(n,n.e<=r.NE||n.e>=r.PE,!0)};var H=Hr();function jr(n){let r;switch(n){case b.EQUALS:r=b.EQUALS;break;case b.GREATER_THAN:r=b.LESS_THAN;break;case b.GREATER_THAN_OR_EQUAL:r=b.LESS_THAN_OR_EQUAL;break;case b.LESS_THAN:r=b.GREATER_THAN;break;case b.LESS_THAN_OR_EQUAL:r=b.GREATER_THAN_OR_EQUAL;break;case b.NOT_EQUAL:r=b.NOT_EQUAL;break}return r}function er(n,r){return H(n).times(r).toNumber()}function Wr(n,r){const e=10**Math.floor(r);return Math.round(er(n,e))/e}function Xr(n,r){const e=10**Math.floor(r);return Math.floor(er(n,e))/e}function Gr(n,r){const e=10**Math.floor(r);return Math.ceil(er(n,e))/e}function Kr(n,r){const e=new H(n),t=new H(r),s=Math.floor(n/r);return e.minus(t.times(s)).toNumber()}function qr(n,r){return n**r}class ue extends we{isNull(){return!0}plus(r){return new _(0,!0).plus(r)}minus(r){return new _(0,!0).minus(r)}multiply(r){return new _(0,!0).multiply(r)}divided(r){return new _(0,!0).divided(r)}mod(r){return new _(0,!0).mod(r)}compare(r,e){return r.isString()?new X("").compare(r,e):r.isBoolean()?new P(!1).compare(r,e):new _(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new X("")):new X(this.concatenate(r.getValue(),re.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new X("")):new X(this.concatenate(r.getValue(),re.BACK))}plusBy(r){return new _(0).plusBy(r)}minusBy(r){return new _(0).minusBy(r)}multiplyBy(r){return new _(0).multiplyBy(r)}dividedBy(r){return new _(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new X("").compareBy(r,e):typeof r=="boolean"?new P(!1).compareBy(r,e):new _(0,!0).compareBy(r,e)}pow(r){return new _(0,!0).pow(r)}sqrt(){return new _(0,!0).sqrt()}cbrt(){return new _(0,!0).cbrt()}cos(){return new _(0,!0).cos()}acos(){return new _(0,!0).acos()}acosh(){return new _(0,!0).acosh()}sin(){return new _(0,!0).sin()}asin(){return new _(0,!0).asin()}asinh(){return new _(0,!0).asinh()}tan(){return new _(0,!0).tan()}tanh(){return new _(0,!0).tanh()}atan(){return new _(0,!0).atan()}atan2(r){return new _(0,!0).atan2(r)}atanh(){return new _(0,!0).atanh()}log(){return new h(c.NUM)}log10(){return new h(c.NUM)}exp(){return new _(0,!0).exp()}abs(){return new _(0,!0).abs()}round(r){return new _(0,!0).round(r)}floor(r){return new _(0,!0).floor(r)}ceil(r){return new _(0,!0).ceil(r)}}class P extends we{constructor(e,t=!1){super(e);p(this,"_value",!1);if(t){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===ye.TRUE?this._value=!0:s===ye.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),new _(-t,!0)}getReciprocal(){return this.getValue()?new _(1,!0):new h(c.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}mod(e){return this._convertTonNumber().mod(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),new _(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class _ extends we{constructor(e,t=!1){super(e);p(this,"_value",0);if(t){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new _(0).minus(this)}getReciprocal(){return new _(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:(t.setPattern(this.getPattern()||e.getPattern()),t)}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return new h(c.DIV_BY_ZERO);if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(s===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Kr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?new h(c.DIV_BY_ZERO):new _(Kr(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),re.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),re.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return Ne.has(e)?new h(e):new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).plus(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).minus(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).times(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?new _(H(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return new h(c.VALUE);if(typeof e=="number"){if(e===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return new h(c.NUM);const s=H(t).div(e).toNumber();return Number.isFinite(s)?new _(s):new h(c.NUM)}return typeof e=="boolean"?e===!1?new h(c.DIV_BY_ZERO):new _(H(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case b.EQUALS:i=H(s).eq(e);break;case b.GREATER_THAN:i=H(s).gt(e);break;case b.GREATER_THAN_OR_EQUAL:i=H(s).gte(e);break;case b.LESS_THAN:i=H(s).lt(e);break;case b.LESS_THAN_OR_EQUAL:i=H(s).lte(e);break;case b.NOT_EQUAL:i=!H(s).eq(e);break}else if(typeof e=="boolean")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}return new P(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=qr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(qr(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=H(e).sqrt().toNumber();return Number.isFinite(t)?new _(t):new h(c.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cos(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acos(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acosh(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.sin(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asin(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asinh(e);return Number.isNaN(t)?new h(c.NUM):new _(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tan(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atan(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log10(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.exp(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.abs(e);return Number.isFinite(t)?new _(t):new h(c.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Wr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Wr(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Xr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Xr(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Gr(t,s);return Number.isFinite(i)?new _(i):new h(c.NUM)}return typeof s=="boolean"?new _(Gr(t,s?1:0)):this}_compareInfinity(e,t,s){let i=!1;switch(s){case b.EQUALS:i=e===t;break;case b.GREATER_THAN:i=e>t;break;case b.GREATER_THAN_OR_EQUAL:i=e>=t;break;case b.LESS_THAN:i=e<t;break;case b.LESS_THAN_OR_EQUAL:i=e<=t;break;case b.NOT_EQUAL:i=e!==t;break}return i}}class X extends we{constructor(e,t=!1){super(e);p(this,"_value");if(t){this._value=e;return}let s=e.toString();s.charAt(0)==='"'&&s.charAt(s.length-1)==='"'&&(s=s.slice(1,-1),s=s.replace(/""/g,'"')),this._value=s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new X(this.concatenate(e.getValue(),re.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new X(this.concatenate(e.getValue(),re.BACK))}compare(e,t){return e.isArray()?e.compare(this,jr(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Rs(e))return this._checkWildcard(e,t);switch(t){case b.EQUALS:i=s===e;break;case b.GREATER_THAN:i=s>e;break;case b.GREATER_THAN_OR_EQUAL:i=s>=e;break;case b.LESS_THAN:i=s<e;break;case b.LESS_THAN_OR_EQUAL:i=s<=e;break;case b.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case b.NOT_EQUAL:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!0;break;case b.EQUALS:case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case b.EQUALS:case b.GREATER_THAN:case b.GREATER_THAN_OR_EQUAL:i=!1;break;case b.LESS_THAN:case b.LESS_THAN_OR_EQUAL:case b.NOT_EQUAL:i=!0;break}return new P(i)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=Es(s,e,t);return new P(i)}}function Ls(n){return""}function As(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];r[e][s]=_e.create(i)}}return r}function Ps(n=[]){const r=[];for(let e=0;e<n.length;e++){const t=n[e];r[e]==null&&(r[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i.isError()?r[e][s]=i.getErrorType():r[e][s]=i.getValue()}}return r}class z extends we{constructor(e){super(typeof e=="string"?e:Ls());p(this,"_values",[]);p(this,"_rowCount",-1);p(this,"_columnCount",-1);p(this,"_unitId","");p(this,"_sheetId","");p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_sliceCache",new Map);p(this,"_flattenCache");p(this,"_flattenPosition");this._values=this._formatValue(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,t){this._currentRow=e,this._currentColumn=t}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return new ue(0);const i=s[t];return i==null?new ue(0):i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=t;o<=s;o++)for(let l=i;l<=a;l++)if(e(u[o][l],o,l)===!1)return}iteratorReverse(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=this.getArrayValue();for(let o=s;o>=t;o--)for(let l=a;l>=i;l--)if(e(u[o][l],o,l)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[new ue(0)]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let u=0;u<s;u++){const o=e.get(a,u),l=this.get(a,u);o.isError()||o.getValue()===!0&&i[0].push(l)}return this._createNewArray(i,1,i[0].length)}flatten(){if(this._flattenCache!=null)return this._flattenCache;const e=[];e[0]=[];for(let s=0;s<this._rowCount;s++)for(let i=0;i<this._columnCount;i++){const a=this.get(s,i);e[0].push(a)}const t=this._createNewArray(e,1,e[0].length);return this._flattenCache=t,t}flattenPosition(){if(this._flattenPosition!=null)return this._flattenPosition;const e=[],t=[],s=[],i=[];let a=0;for(let o=0;o<this._rowCount;o++)for(let l=0;l<this._columnCount;l++){const f=this.get(o,l);if(f.isError()||f.isNull()){a++;continue}f.isString()?(e.push(f),s.push(a++)):(t.push(f),i.push(a++))}const u={stringArray:e,numberArray:t,stringPosition:s,numberPosition:i};return this._flattenPosition=u,u}slice(e,t){let s=0,i=this._rowCount,a=1,u=0,o=this._columnCount,l=1;if(e!=null&&(s=e[0]||0,i=e[1]||this._rowCount,a=e[2]||1),t!=null&&(u=t[0]||0,o=t[1]||this._columnCount,l=t[2]||1),s>=this._rowCount||u>=this._columnCount)return;const f=`${s}_${i}_${a}_${u}_${o}_${l}`,m=this._sliceCache.get(f);if(m!=null)return m;const g=[],R=this._values;let w=0,E=0;for(let L=s;L<i;L+=a){E=0,g[w]==null&&(g[w]=[]);for(let V=u;V<o;V+=l)g[w][E]=R[L][V],E++;w++}if(g.length===0||g[0].length===0)return;const C=a>1?-1:s+this._currentRow,y=l>1?-1:u+this._currentColumn,S=this._createNewArray(g,g.length,g[0].length,C,y);return this._sliceCache.set(f,S),S}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=q.MIN,s=!1,i=!1){let a,u,o,l;const f=(m,g,R)=>{if(m==null)return!0;let w;if(i===!0?w=m.compare(e,b.EQUALS):w=m.isEqual(e),(w==null?void 0:w.getValue())===!0)return a=m,o={row:g,column:R},!1;t===q.MAX?m.isGreaterThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R}):t===q.MIN&&m.isLessThan(e).getValue()===!0&&(u==null||m.minus(e).abs().isLessThanOrEqual(u.minus(e).abs()).getValue()===!0)&&(u=m,l={row:g,column:R})};if(s){const m=this._values.length;if(this._values[0]==null)return;const g=this._values[0].length;for(let R=m-1;R>=0;R--)for(let w=g-1;w>=0;w--){const E=this._values[R][w];f(E,R,w)}}else this.iterator((m,g,R)=>{f(m,g,R)});if(a!=null)return o;if(u!=null)return l}binarySearch(e,t=me.MIN){if(e.isError())return;const{stringArray:s,stringPosition:i,numberArray:a,numberPosition:u}=this.flattenPosition();return e.isString()?this._binarySearch(e,s,i,t):this._binarySearch(e,a,u,t)}_binarySearch(e,t,s,i=me.MIN){const a=kr(),u=e.getValue().toString();let o=0,l=t.length-1,f=null;for(;o<=l;){const m=Math.floor((o+l)/2),g=t[m];let R=0;if(g.isNull())R=1;else{const w=g.getValue();R=a(w.toString(),u)}if(R===0)return s[m];R===-1?(o=m+1,i===me.MIN&&(f=m)):(l=m-1,i===me.MAX&&(f=m))}if(f!=null)return s[f]}sum(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new _(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new _(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=new _(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new _(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return new z("{0}").minus(this)}getReciprocal(){return new z("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}product(e,t){return this._batchOperator(e,8,t)}map(e){const t=(s,i,a)=>s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a,u;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const l=[];for(let f=0;f<s;f++){const m=(u=(a=this._values)==null?void 0:a[o])==null?void 0:u[f];m?l[f]=e(m,o,f):l[f]=new h(c.VALUE)}i.push(l)}return this._createNewArray(i,t,s)}pow(e){return this._batchOperator(e,9)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,13)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0);if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2),a=t.get(0,s/2-1);return i.plus(a).divided(new _(2,!0))}return t.get(0,(s-1)/2)}var(e=0){const t=this.mean(),s=[[]];this.iterator(f=>{if(f==null||f.isError()||f.isString()||f.isBoolean()||f.isNull())return;const m=f.minus(t).pow(new _(2,!0));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:u,_currentColumn:o}=this;return new z({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:u,column:o}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,10)}roundInverse(e){return this.map(t=>t.isError()?t:e.round(t))}floor(e){return this._batchOperator(e,11)}floorInverse(e){return this.map(t=>t.isError()?t:e.floor(t))}ceil(e){return this._batchOperator(e,12)}ceilInverse(e){return this.map(t=>t.isError()?t:e.ceil(t))}toValue(){return Ps(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=kr();return(s,i)=>{const a=s[e],u=i[e];return a.isError()&&a.isError()?0:a.isError()?1:u.isError()?-1:t(a.getValue(),u.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let u=0;u<t;u++)i[a][u]=e[u][a]}return i}_batchOperator(e,t,s){const i=[];let a=this._rowCount,u=this._columnCount;if(e.isArray()){const l=e.getRowCount(),f=e.getColumnCount();if(a=Math.max(l,a),u=Math.max(f,u),l===1&&f===1){const m=e.getFirstCell();for(let g=0;g<u;g++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let g=0;g<u;g++)i.push(m[0][g])}else return this._batchOperatorArray(e,t,s)}else for(let l=0;l<u;l++)i.push(e);const o=[];for(let l=0;l<u;l++){const f=i[l];this._batchOperatorValue(f,l,o,t,s)}return this._createNewArray(o,a,u)}_batchOperatorValue(e,t,s,i,a){var R,w;const u=this._rowCount;let o=!1;const l=this.getUnitId(),f=this.getSheetId(),m=this.getCurrentRow(),g=this.getCurrentColumn();if(i===5&&(o=Ee.canUseCache(l,f,t+g,m,m+u-1),o===!0)){if(a===b.EQUALS){const E=Ee.getCellPositions(l,f,t+g,e.getValue());for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),E!=null&&E.includes(C+m)?s[C][t]=new P(!0):s[C][t]=new P(!1)}else{const E=Ee.getCellValuePositions(l,f,t+g);if(E!=null){E.forEach((C,y)=>{let S=new ue(0);typeof y=="string"?S=new X(y):typeof y=="number"?S=new _(y):typeof y=="boolean"&&(S=new P(y)),S.compare(e,a).getValue()===!0&&C.forEach(V=>{V>=m&&V<=m+u-1&&(s[V-m]==null&&(s[V-m]=[]),s[V-m][t]=new P(!0))})});for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]==null&&(s[C][t]=new P(!1))}else for(let C=0;C<u;C++)s[C]==null&&(s[C]=[]),s[C][t]=new P(!1)}return}for(let E=0;E<u;E++){const C=(w=(R=this._values)==null?void 0:R[E])==null?void 0:w[t];if(s[E]==null&&(s[E]=[]),C&&e)if(C.isError())s[E][t]=C;else if(e.isError())s[E][t]=e;else switch(i){case 1:s[E][t]=C.plus(e);break;case 0:s[E][t]=C.minus(e);break;case 2:s[E][t]=C.multiply(e);break;case 3:s[E][t]=C.divided(e);break;case 4:s[E][t]=C.mod(e);break;case 5:a?s[E][t]=C.compare(e,a):s[E][t]=new h(c.VALUE);break;case 6:s[E][t]=C.concatenateFront(e);break;case 7:s[E][t]=C.concatenateBack(e);break;case 8:a?s[E][t]=C.product(e,a):s[E][t]=new h(c.VALUE);break;case 9:s[E][t]=C.pow(e);break;case 10:s[E][t]=C.round(e);break;case 11:s[E][t]=C.floor(e);break;case 13:s[E][t]=C.atan2(e);break;case 12:s[E][t]=C.ceil(e);break}else s[E][t]=new h(c.NA);C!=null&&(C.isError()?Ee.set(l,f,t+g,C.getErrorType(),E+m):C.isNull()?Ee.set(l,f,t+g,null,E+m):Ee.set(l,f,t+g,C.getValue(),E+m))}Ee.setContinueBuildingCache(l,f,t+g,m,m+u-1)}_batchOperatorArray(e,t,s){var m,g,R,w,E,C,y,S,L,V,I,Q;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const u=[],o=e.getArrayValue(),l=this._checkArrayCalculateType(this),f=this._checkArrayCalculateType(e);for(let T=0;T<i;T++){const x=[];for(let v=0;v<a;v++){let $;l===3?$=(g=(m=this._values)==null?void 0:m[0])==null?void 0:g[0]:l===1?$=(w=(R=this._values)==null?void 0:R[0])==null?void 0:w[v]:l===2?$=(C=(E=this._values)==null?void 0:E[T])==null?void 0:C[0]:$=(S=(y=this._values)==null?void 0:y[T])==null?void 0:S[v];let k;if(f===3?k=(L=o==null?void 0:o[0])==null?void 0:L[0]:f===1?k=(V=o==null?void 0:o[0])==null?void 0:V[v]:f===2?k=(I=o==null?void 0:o[T])==null?void 0:I[0]:k=(Q=o==null?void 0:o[T])==null?void 0:Q[v],$&&k)if($.isError())x[v]=$;else if(k.isError())x[v]=k;else switch(t){case 1:x[v]=$.plus(k);break;case 0:x[v]=$.minus(k);break;case 2:x[v]=$.multiply(k);break;case 3:x[v]=$.divided(k);break;case 4:x[v]=$.mod(k);break;case 5:s?x[v]=$.compare(k,s):x[v]=new h(c.VALUE);break;case 6:x[v]=$.concatenateFront(k);break;case 7:x[v]=$.concatenateBack(k);break;case 8:s?x[v]=$.product(k,s):x[v]=new h(c.VALUE);break;case 9:x[v]=$.pow(k);break;case 10:x[v]=$.round(k);break;case 13:x[v]=$.atan2(k);break;case 11:x[v]=$.floor(k);break;case 12:x[v]=$.ceil(k);break}else x[v]=new h(c.NA)}u.push(x)}return this._createNewArray(u,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const t=e.split(";"),s=t.length,i=[];let a=0;for(let u=0;u<s;u++){const l=t[u].split(","),f=l.length;a<f&&(a=f);const m=[];for(let g=0;g<f;g++){const R=l[g].trim();m.push(_e.create(R))}i.push(m)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,t,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const u={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new z(u)}}class _e{static create(r){if(r==null)return new ue(0);if(typeof r=="boolean")return new P(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase().trim();return Ne.has(e)?new h(e):e===ye.TRUE||e===ye.FALSE?new P(e):d.isRealNum(r)?new _(r):new RegExp(ns,"g").test(r.replace(/\n/g,"").replace(/\r/g,""))?new z(r.replace(/\n/g,"").replace(/\r/g,"")):new X(r)}return typeof r=="number"?Number.isFinite(r)?new _(r,!0):new h(c.NUM):new h(c.NA)}}function Vs(n){if(n===null)return 0;if(n!=null&&n.p){const r=n==null?void 0:n.p.body;if(r==null)return 0;const e=r.dataStream;return e.substring(e.length-2,e.length)===d.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(n==null?void 0:n.v)||0}const xs=1e5,tr=new rt(xs);class ke extends ct{constructor(e){super();p(this,"_forcedSheetId","");p(this,"_forcedSheetName","");p(this,"_defaultSheetId","");p(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});p(this,"_unitData",{});p(this,"_defaultUnitId","");p(this,"_forcedUnitId","");p(this,"_runtimeData",{});p(this,"_arrayFormulaCellData",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeFeatureCellData",{});p(this,"_numfmtItemData",{});p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return isNaN(e)&&(e=0),isNaN(s)&&(s=0),isNaN(t)&&(t=this.getRowCount()-1),isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var l,f,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new h(c.VALUE),t,i);const u=this._forcedUnitId||this._defaultUnitId,o=this._forcedSheetId||this._defaultSheetId;for(let g=t;g<=s;g++)for(let R=i;R<=a;R++){if(g<0||R<0)return e(new h(c.REF),g,R);const w=this.getCellData(g,R);let E=!1;if(w==null||d.isNullCell(w)){E=e(null,g,R);continue}const C=this.getCellValueObject(w),y=(m=(f=(l=this._numfmtItemData[u])==null?void 0:l[o])==null?void 0:f[g])==null?void 0:m[R];if(y&&C.setPattern(y),E=e(C,g,R),E===!1)return}}getFirstCell(){var l,f,m;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return new _(0,!0);const i=this.getCellValueObject(s),a=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,o=(m=(f=(l=this._numfmtItemData[a])==null?void 0:l[u])==null?void 0:f[e])==null?void 0:m[t];return o&&i.setPattern(o),i}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var t;this._forcedSheetId=(t=e[this.getUnitId()])==null?void 0:t[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getNumfmtItemData(){return this._numfmtItemData}setNumfmtItemData(e){this._numfmtItemData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new h(c.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=Vs(e);return Ne.has(t)?new h(t):e.t===d.CellValueType.NUMBER?new _(t):e.t===d.CellValueType.STRING||e.t===d.CellValueType.FORCE_STRING?new X(t):e.t===d.CellValueType.BOOLEAN?new P(t):_e.create(t)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,t;return(t=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,t;return(t=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,t;return(t=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCellData(e,t){const s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),u=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,t))||(u==null?void 0:u.getValue(e,t))||this.getRuntimeFeatureCellValue(e,t)||(a==null?void 0:a.getValue(e,t))||(s==null?void 0:s.cellData.getValue(e,t))}getRuntimeFeatureCellValue(e,t){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const u=this._runtimeFeatureCellData[a],o=(i=u==null?void 0:u[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(o==null)continue;const l=o.getValue(e,t);if(l!=null)return l}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):new h(c.VALUE)}toArrayValueObject(e=!0){var w;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),u=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,o=tr.get(u);if(o&&e)return o;const l=s-t+1,f=a-i+1;if(l<0||f<0)return this._getBlankArrayValueObject();const m=new Array(l);this.iterator((E,C,y)=>{const S=C-t,L=y-i;m[S]||(m[S]=new Array(f)),E==null&&(E=new ue(0)),m[S][L]=E});const g={calculateValueList:m,rowCount:m.length,columnCount:((w=m[0])==null?void 0:w.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},R=new z(g);return e&&tr.set(u,R),R}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return new z(e)}}class vs extends ct{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class Bs extends ct{constructor(r){super(),this._promiseList=r}isAsyncArrayObject(){return!0}async getValue(){var t;const r=[];for(let s=0;s<this._promiseList.length;s++){const i=this._promiseList[s];r[s]==null&&(r[s]=[]);for(let a=0;a<i.length;a++){const u=i[a];u.isAsyncObject()?r[s][a]=await u.getValue():r[s][a]=u}}const e={calculateValueList:r,rowCount:r.length,columnCount:((t=r[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:0,column:0};return new z(e)}}class Ke extends ke{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const zr=/[\[\]]/g;function Zr(n,r){if(zr.test(n)){const e=Number(n.replace(zr,""));return r+e}return Number(n)-1}function rr(n,r=0,e=0){n=n.toLocaleUpperCase();const t=n.split(/[RC]/),s=t[1],i=t[2],a=Zr(s,r),u=Zr(i,e);return{row:a,column:u,absoluteRefType:d.AbsoluteRefType.NONE}}function Jr(n,r=0,e=0){const{refBody:t,sheetName:s,unitId:i}=vr(n),a=t.indexOf(":");if(a===-1){const E=rr(t,r,e),C=E.row,y=E.column,S=E.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:C,startColumn:y,endRow:C,endColumn:y,startAbsoluteRefType:S,endAbsoluteRefType:S}}}const u=t.substring(0,a),o=t.substring(a+1),l=rr(u,r,e),f=rr(o,r,e),m=l.row,g=l.column,R=f.row,w=f.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:g,endRow:R,endColumn:w,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:f.absoluteRefType}}}function Us(n){const r=ht(n.startRow,n.startAbsoluteRefType,!0),e=ht(n.startColumn,n.startAbsoluteRefType,!1),t=ht(n.endRow,n.endAbsoluteRefType,!0),s=ht(n.endColumn,n.endAbsoluteRefType,!1);return r===t&&e===s?`R${r}C${e}`:`R${r}C${e}:R${t}C${s}`}function ht(n,r=d.AbsoluteRefType.ALL,e){switch(n+=1,r){case d.AbsoluteRefType.ALL:return`${n}`;case d.AbsoluteRefType.ROW:return e?`${n}`:`[${n}]`;case d.AbsoluteRefType.COLUMN:return e?`[${n}]`:`${n}`;case d.AbsoluteRefType.NONE:return`[${n}]`}}const Nr=[];var Ms=(n=>{})();function mt(n){const r=n.getValue();let e=0;return r&&(e=1),new _(e,!0)}function j(n,r,e,t){const s=[];if(e.isArray()){const i=e.getRowCount(),a=e.getColumnCount();if(i===1&&a===1){const u=e.getFirstCell();for(let o=0;o<n;o++){const l=[];for(let f=0;f<r;f++)l.push(u);s.push(l)}}else if(i===1&&a>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(0,l)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}else if(a===1&&i>1)for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,0)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}else for(let u=0;u<n;u++){const o=[];for(let l=0;l<r;l++){const f=e.getRealValue(u,l)||(t!=null?t:new ue(0));o.push(f)}s.push(o)}}else for(let i=0;i<n;i++){const a=[];for(let u=0;u<r;u++)a.push(e);s.push(a)}return gt(s,n,r)}function gt(n,r,e){const t={calculateValueList:n,rowCount:r,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return new z(t)}class A extends d.Disposable{constructor(e){super();p(this,"_unitId");p(this,"_subUnitId");p(this,"_row",-1);p(this,"_column",-1);p(this,"needsExpandParams",!1);p(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new h(c.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?new h(c.VALUE):t;if(e.isString()){const s=Number(e.getValue());return isNaN(s)?new h(c.REF):s}else if(e.isNumber())return e.getValue();return new h(c.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return new h(c.NA);let u;return s.getRowCount()===1?u=s.get(0,a):u=s.get(a,0),u.isNull()?new h(c.NA):u}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,b.EQUALS));let u;return i?u=a.getFirstCell():u=a.getLastCell(),u.isNull()?new h(c.NA):u}orderSearch(e,t,s,i=q.MIN,a=!1){const u=t.orderSearch(e,i,a);if(u==null)return new h(c.NA);const o=s.get(u.row,u.column);return o.isNull()?new h(c.NA):o}binarySearchExpand(e,t,s,i=0,a){const u=t.binarySearch(e,a);return u==null?new h(c.NA):i===0?s.slice([u,u+1]):s.slice(void 0,[u,u+1])}equalSearchExpand(e,t,s,i=!0,a=0){const u=t.isEqual(e);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const u=t.compare(e,b.EQUALS);let o;return i?o=u.getFirstTruePosition():o=u.getLastTruePosition(),o==null?new h(c.NA):a===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}orderSearchExpand(e,t,s,i=q.MIN,a=!1,u=0){const o=t.orderSearch(e,i,a);return o==null?new h(c.NA):u===0?s.slice([o.row,o.row+1]):s.slice(void 0,[o.column,o.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if(a.isError())return a;if(a.isString()){const u=a.getValue();if(!d.isRealNum(u))return new h(c.VALUE);a=new _(u)}if(a.isBoolean()&&(a=mt(a)),a.isNull()&&(a=new _(0)),a.isArray()){let u;if(a.iterator(o=>{if(o==null||o.isNull()||t&&(o.isString()||o.isBoolean()))return!0;if(o=this._includingLogicalValuesAndText(o),o.isError())return u=o,!1;s[0].push(o)}),u!=null&&u.isError())return u}else s[0].push(a)}return gt(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=mt(e)),e.isString()){const t=Number(e.getValue());e=new _(isNaN(t)?0:t)}return e}}class en extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std()}}class tn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std(1)}}class rn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var()}}class nn extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var(1)}}var Ie=(n=>(n.BETADIST="BETADIST",n.BETAINV="BETAINV",n.BINOMDIST="BINOMDIST",n.CHIDIST="CHIDIST",n.CHIINV="CHIINV",n.CHITEST="CHITEST",n.CONFIDENCE="CONFIDENCE",n.COVAR="COVAR",n.CRITBINOM="CRITBINOM",n.EXPONDIST="EXPONDIST",n.FDIST="FDIST",n.FINV="FINV",n.FTEST="FTEST",n.GAMMADIST="GAMMADIST",n.GAMMAINV="GAMMAINV",n.HYPGEOMDIST="HYPGEOMDIST",n.LOGINV="LOGINV",n.LOGNORMDIST="LOGNORMDIST",n.MODE="MODE",n.NEGBINOMDIST="NEGBINOMDIST",n.NORMDIST="NORMDIST",n.NORMINV="NORMINV",n.NORMSDIST="NORMSDIST",n.NORMSINV="NORMSINV",n.PERCENTILE="PERCENTILE",n.PERCENTRANK="PERCENTRANK",n.POISSON="POISSON",n.QUARTILE="QUARTILE",n.RANK="RANK",n.STDEV="STDEV",n.STDEVP="STDEVP",n.TDIST="TDIST",n.TINV="TINV",n.TTEST="TTEST",n.VAR="VAR",n.VARP="VARP",n.WEIBULL="WEIBULL",n.ZTEST="ZTEST",n))(Ie||{});const sn=[[tn,Ie.STDEV],[en,Ie.STDEVP],[nn,Ie.VAR],[rn,Ie.VARP]],an=[];var un=(n=>(n.CUBEKPIMEMBER="CUBEKPIMEMBER",n.CUBEMEMBER="CUBEMEMBER",n.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",n.CUBERANKEDMEMBER="CUBERANKEDMEMBER",n.CUBESET="CUBESET",n.CUBESETCOUNT="CUBESETCOUNT",n.CUBEVALUE="CUBEVALUE",n))(un||{});const on=[];var ln=(n=>(n.DAVERAGE="DAVERAGE",n.DCOUNT="DCOUNT",n.DCOUNTA="DCOUNTA",n.DGET="DGET",n.DMAX="DMAX",n.DMIN="DMIN",n.DPRODUCT="DPRODUCT",n.DSTDEV="DSTDEV",n.DSTDEVP="DSTDEVP",n.DSUM="DSUM",n.DVAR="DVAR",n.DVARP="DVARP",n))(ln||{});const nr="yyyy-mm-dd;@";function sr(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28)),t=Date.UTC(n.getFullYear(),n.getMonth(),n.getDate());let s=(t-r.getTime())/(1e3*3600*24);return t>e.getTime()&&(s+=1),Math.floor(s)+1}function dt(n){const r=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28));let t=Math.floor(n)-1;return t>(e.getTime()-r.getTime())/(1e3*3600*24)&&(t-=1),new Date(r.getTime()+t*(1e3*3600*24))}function ir(n){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(n))return!1;const e=n.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),u=`${s}-${i}-${a}`;return n.replace(/\//g,"-").split("-").map(l=>l.padStart(2,"0")).join("-")===u}class Os extends A{calculate(r,e,t){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=j(s,i,r),u=j(s,i,e),o=j(s,i,t);return a.map((l,f,m)=>{const g=u.get(f,m),R=o.get(f,m);if(l.isError())return l;if(g.isError())return g;if(R.isError())return R;if(l.isString()||g.isString()||R.isString())return new h(c.VALUE);let w=+l.getValue();const E=Math.floor(+g.getValue()),C=+R.getValue();if(w<0||w>9999)return new h(c.NUM);w>=0&&w<1899&&(w+=1900);const y=new Date(w,E-1,C),S=sr(y);if(S<0)return new h(c.NUM);const L=new _(S);return L.setPattern(nr),L})}}class Fs extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new _(0);e=dt(a)}const s=e.getDate();return new _(s)}}class $s extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=j(t,s,r),a=j(t,s,e);return i.map((u,o,l)=>{const f=a.get(o,l);if(u.isError())return u;if(f.isError())return f;if(u.isString()||u.isBoolean()||f.isString()||f.isBoolean())return new h(c.VALUE);const m=+u.getValue();if(m<0)return new h(c.NUM);const g=Math.floor(+f.getValue()),R=dt(m),w=R.getUTCFullYear(),E=R.getUTCMonth()+g,C=R.getUTCDate(),y=new Date(Date.UTC(w,E,C)),S=sr(y),L=new _(S);return L.setPattern(nr),L})}}var Ce=(n=>(n.DATE="DATE",n.DATEDIF="DATEDIF",n.DATEVALUE="DATEVALUE",n.DAY="DAY",n.DAYS="DAYS",n.DAYS360="DAYS360",n.EDATE="EDATE",n.EOMONTH="EOMONTH",n.HOUR="HOUR",n.ISOWEEKNUM="ISOWEEKNUM",n.MINUTE="MINUTE",n.MONTH="MONTH",n.NETWORKDAYS="NETWORKDAYS",n.NETWORKDAYS_INTL="NETWORKDAYS.INTL",n.NOW="NOW",n.SECOND="SECOND",n.TIME="TIME",n.TIMEVALUE="TIMEVALUE",n.TODAY="TODAY",n.WEEKDAY="WEEKDAY",n.WEEKNUM="WEEKNUM",n.WORKDAY="WORKDAY",n.WORKDAY_INTL="WORKDAY.INTL",n.YEAR="YEAR",n.YEARFRAC="YEARFRAC",n))(Ce||{});class ks extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new _(1);e=dt(a)}const s=e.getUTCMonth()+1;return new _(s)}}class Is extends A{calculate(r){if(r)return new h(c.NA);const e=sr(new Date),t=new _(e);return t.setPattern(nr),t}}class Ts extends A{calculate(r){return r==null?new h(c.NA):r.isArray()?r.map(e=>this._handleSingleObject(e)):this._handleSingleObject(r)}_handleSingleObject(r){if(r.isError())return r;let e;const t=r.getValue();if(r.isString()){if(!ir(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return new h(c.NUM);if(a===0)return new _(1900);e=dt(a)}const s=e.getUTCFullYear();return new _(s)}}const cn=[[Os,Ce.DATE],[Fs,Ce.DAY],[$s,Ce.EDATE],[ks,Ce.MONTH],[Is,Ce.TODAY],[Ts,Ce.YEAR]],fn=[];var hn=(n=>(n.BESSELI="BESSELI",n.BESSELJ="BESSELJ",n.BESSELK="BESSELK",n.BESSELY="BESSELY",n.BIN2DEC="BIN2DEC",n.BIN2HEX="BIN2HEX",n.BIN2OCT="BIN2OCT",n.BITAND="BITAND",n.BITLSHIFT="BITLSHIFT",n.BITOR="BITOR",n.BITRSHIFT="BITRSHIFT",n.BITXOR="BITXOR",n.COMPLEX="COMPLEX",n.CONVERT="CONVERT",n.DEC2BIN="DEC2BIN",n.DEC2HEX="DEC2HEX",n.DEC2OCT="DEC2OCT",n.DELTA="DELTA",n.ERF="ERF",n.ERF_PRECISE="ERF.PRECISE",n.ERFC="ERFC",n.ERFC_PRECISE="ERFC.PRECISE",n.GESTEP="GESTEP",n.HEX2BIN="HEX2BIN",n.HEX2DEC="HEX2DEC",n.HEX2OCT="HEX2OCT",n.IMABS="IMABS",n.IMAGINARY="IMAGINARY",n.IMARGUMENT="IMARGUMENT",n.IMCONJUGATE="IMCONJUGATE",n.IMCOS="IMCOS",n.IMCOSH="IMCOSH",n.IMCOT="IMCOT",n.IMCSC="IMCSC",n.IMCSCH="IMCSCH",n.IMDIV="IMDIV",n.IMEXP="IMEXP",n.IMLN="IMLN",n.IMLOG10="IMLOG10",n.IMLOG2="IMLOG2",n.IMPOWER="IMPOWER",n.IMPRODUCT="IMPRODUCT",n.IMREAL="IMREAL",n.IMSEC="IMSEC",n.IMSECH="IMSECH",n.IMSIN="IMSIN",n.IMSINH="IMSINH",n.IMSQRT="IMSQRT",n.IMSUB="IMSUB",n.IMSUM="IMSUM",n.IMTAN="IMTAN",n.OCT2BIN="OCT2BIN",n.OCT2DEC="OCT2DEC",n.OCT2HEX="OCT2HEX",n))(hn||{});const mn=[];var gn=(n=>(n.ACCRINT="ACCRINT",n.ACCRINTM="ACCRINTM",n.AMORDEGRC="AMORDEGRC",n.AMORLINC="AMORLINC",n.COUPDAYBS="COUPDAYBS",n.COUPDAYS="COUPDAYS",n.COUPDAYSNC="COUPDAYSNC",n.COUPNCD="COUPNCD",n.COUPNUM="COUPNUM",n.COUPPCD="COUPPCD",n.CUMIPMT="CUMIPMT",n.CUMPRINC="CUMPRINC",n.DB="DB",n.DDB="DDB",n.DISC="DISC",n.DOLLARDE="DOLLARDE",n.DOLLARFR="DOLLARFR",n.DURATION="DURATION",n.EFFECT="EFFECT",n.FV="FV",n.FVSCHEDULE="FVSCHEDULE",n.INTRATE="INTRATE",n.IPMT="IPMT",n.IRR="IRR",n.ISPMT="ISPMT",n.MDURATION="MDURATION",n.MIRR="MIRR",n.NOMINAL="NOMINAL",n.NPER="NPER",n.NPV="NPV",n.ODDFPRICE="ODDFPRICE",n.ODDFYIELD="ODDFYIELD",n.ODDLPRICE="ODDLPRICE",n.ODDLYIELD="ODDLYIELD",n.PDURATION="PDURATION",n.PMT="PMT",n.PPMT="PPMT",n.PRICE="PRICE",n.PRICEDISC="PRICEDISC",n.PRICEMAT="PRICEMAT",n.PV="PV",n.RATE="RATE",n.RECEIVED="RECEIVED",n.RRI="RRI",n.SLN="SLN",n.SYD="SYD",n.TBILLEQ="TBILLEQ",n.TBILLPRICE="TBILLPRICE",n.TBILLYIELD="TBILLYIELD",n.VDB="VDB",n.XIRR="XIRR",n.XNPV="XNPV",n.YIELD="YIELD",n.YIELDDISC="YIELDDISC",n.YIELDMAT="YIELDMAT",n))(gn||{}),ne=(n=>(n.CELL="CELL",n.ERROR_TYPE="ERROR.TYPE",n.INFO="INFO",n.ISBLANK="ISBLANK",n.ISERR="ISERR",n.ISERROR="ISERROR",n.ISEVEN="ISEVEN",n.ISFORMULA="ISFORMULA",n.ISLOGICAL="ISLOGICAL",n.ISNA="ISNA",n.ISNONTEXT="ISNONTEXT",n.ISNUMBER="ISNUMBER",n.ISODD="ISODD",n.ISOMITTED="ISOMITTED",n.ISREF="ISREF",n.ISTEXT="ISTEXT",n.N="N",n.NA="NA",n.SHEET="SHEET",n.SHEETS="SHEETS",n.TYPE="TYPE",n))(ne||{});class Qs extends A{calculate(r){return r==null?new h(c.NA):r.isNull()?new P(!0):r.isArray()?r.mapValue(e=>e.isNull()?new P(!0):new P(!1)):new P(!1)}}class Ys extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!1):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!1):e.isError()?new P(!0):new P(!1)):new P(!1)}}class Hs extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new P(!0):r.isArray()?r.mapValue(e=>e.isError()?new P(!0):new P(!1)):new P(!1)}}class js extends A{calculate(r){return r==null?new h(c.NA):r.isBoolean()?new P(!0):r.isArray()?r.mapValue(e=>e.isBoolean()?new P(!0):new P(!1)):new P(!1)}}class Ws extends A{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new P(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new P(!0):new P(!1)):new P(!1)}}class Xs extends A{calculate(r){return r==null?new h(c.NA):!r.isArray()&&!r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!1):new P(!0)):new P(!1)}}class Gs extends A{calculate(r){return r==null?new h(c.NA):r.isNumber()?new P(!0):r.isArray()?r.mapValue(e=>e.isNumber()?new P(!0):new P(!1)):new P(!1)}}class Ks extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e){return e==null?new h(c.NA):e.isReferenceObject()?new P(!0):new P(!1)}}class qs extends A{calculate(r){return r==null?new h(c.NA):r.isString()?new P(!0):r.isArray()?r.mapValue(e=>e.isString()?new P(!0):new P(!1)):new P(!1)}}const dn=[[Qs,ne.ISBLANK],[Ys,ne.ISERR],[Hs,ne.ISERROR],[js,ne.ISLOGICAL],[Ws,ne.ISNA],[Xs,ne.ISNONTEXT],[Gs,ne.ISNUMBER],[Ks,ne.ISREF],[qs,ne.ISTEXT]];class zs extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=!0,t=!0,s=null;for(const i of r){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e&&!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?new h(c.VALUE):new P(e)}}var Ve=(n=>(n.AND="AND",n.BYCOL="BYCOL",n.BYROW="BYROW",n.FALSE="FALSE",n.IF="IF",n.IFERROR="IFERROR",n.IFNA="IFNA",n.IFS="IFS",n.LAMBDA="LAMBDA",n.LET="LET",n.MAKEARRAY="MAKEARRAY",n.MAP="MAP",n.NOT="NOT",n.OR="OR",n.REDUCE="REDUCE",n.SCAN="SCAN",n.SWITCH="SWITCH",n.TRUE="TRUE",n.XOR="XOR",n))(Ve||{});class Zs extends A{calculate(r,e,t=new P(!1)){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(r=this._getSingleValueObject(r),!r.isArray())return r.getValue()?e:t;const s=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=j(s,i,r),u=j(s,i,e,new h(c.NA)),o=j(s,i,t,new h(c.NA));return a.map((l,f,m)=>{if(l.isNull())return new h(c.NA);{const g=u.get(f,m),R=o.get(f,m);return this._calculateSingleCell(l,g,R)}})}_getSingleValueObject(r){return r.isArray()&&r.getRowCount()===1&&r.getColumnCount()===1?r.getFirstCell():r}_calculateSingleCell(r,e,t){return r.isNull()?new h(c.NA):r.getValue()?e.isNull()?new h(c.NA):e:t.isNull()?new h(c.NA):t}}class Js extends A{calculate(r,e){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(!r.isArray())return r.isError()?e:r;const t=Math.max(r.isArray()?r.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(r.isArray()?r.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=j(t,s,r),a=j(t,s,e);return i.iterator((u,o,l)=>{u!=null&&u.isError()&&i.set(o,l,a.get(o,l))}),i}}class Ns extends A{calculate(...r){return new h(c.VALUE)}}class ei extends A{calculate(...r){if(r.length!==3)return new h(c.VALUE);const e=this.getIndexNumValue(r[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(r[1]);if(typeof t!="number")return t;if(!(r[2].isValueObject()&&r[2].isLambda()))return new h(c.VALUE);const s=r[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let u=0;u<t;u++){const o=s.execute(new _(a+1),new _(u+1));i[a][u]=o}}return new Bs(i)}isAsync(){return!0}}const Rn=[[zs,Ve.AND],[Ns,Ve.LAMBDA],[ei,Ve.MAKEARRAY],[Zs,Ve.IF],[Js,Ve.IFERROR]];class ti extends A{calculate(r,e,t,s,i){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(r.getValue())-1,u=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(u))return new h(c.VALUE);const o=t?ri(t.getValue()):d.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),f=i?`${i.getValue()}`:"",m=st(f)?`'${f}'`:f,g={startRow:a,startColumn:u,endRow:a,endColumn:u,startAbsoluteRefType:o,endAbsoluteRefType:o},R=s&&!l?Us(g):De(g);return new X(m!==""?`${m}!${R}`:R)}}function ri(n){switch(n){case 1:return d.AbsoluteRefType.ALL;case 2:return d.AbsoluteRefType.ROW;case 3:return d.AbsoluteRefType.COLUMN;case 4:return d.AbsoluteRefType.NONE;default:return d.AbsoluteRefType.ALL}}class ni extends A{calculate(r){if(r==null)return new _(this.column+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentColumn(),t=r.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(new _(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class si extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new _(1);if(!r.isArray())return new h(c.NA);const e=r.getColumnCount();return new _(e)}}var G=(n=>(n.ADDRESS="ADDRESS",n.AREAS="AREAS",n.CHOOSE="CHOOSE",n.CHOOSECOLS="CHOOSECOLS",n.CHOOSEROWS="CHOOSEROWS",n.COLUMN="COLUMN",n.COLUMNS="COLUMNS",n.DROP="DROP",n.EXPAND="EXPAND",n.FILTER="FILTER",n.FORMULATEXT="FORMULATEXT",n.GETPIVOTDATA="GETPIVOTDATA",n.HLOOKUP="HLOOKUP",n.HSTACK="HSTACK",n.HYPERLINK="HYPERLINK",n.IMAGE="IMAGE",n.INDEX="INDEX",n.INDIRECT="INDIRECT",n.LOOKUP="LOOKUP",n.MATCH="MATCH",n.OFFSET="OFFSET",n.ROW="ROW",n.ROWS="ROWS",n.RTD="RTD",n.SORT="SORT",n.SORTBY="SORTBY",n.TAKE="TAKE",n.TOCOL="TOCOL",n.TOROW="TOROW",n.TRANSPOSE="TRANSPOSE",n.UNIQUE="UNIQUE",n.VLOOKUP="VLOOKUP",n.VSTACK="VSTACK",n.WRAPCOLS="WRAPCOLS",n.WRAPROWS="WRAPROWS",n.XLOOKUP="XLOOKUP",n.XMATCH="XMATCH",n))(G||{});class ii extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.NA);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice([0,1]),o=e.slice([a-1,a]);return u==null||o==null?new h(c.REF):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class En extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(r){if(!r.isCell())return new h(c.REF);const e=r,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(r,e){const t=r.startRow,s=r.startColumn,i=e.startRow,a=e.startColumn,u={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(u.startRow=i,u.endRow=t):(u.startRow=t,u.endRow=i),s>a?(u.startColumn=a,u.endColumn=s):(u.startColumn=s,u.endColumn=a),u}_createRange(r){const e=new Ke(r,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setNumfmtItemData(this.getNumfmtItemData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();e.setRefOffset(t,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class wn extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(r){if(!r.isColumn())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this}}class _n extends ke{constructor(r){super(r);const e=Fe(r);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(r){if(!r.isRow())return new h(c.REF);const e=r;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new h(c.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this}}class ai extends A{calculate(r,e){if(r==null)return new h(c.NA);if(r.isError())return r;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),r.isArray()){const f=r;if(f.getRowCount()===1&&f.getColumnCount()===1)r=f.getFirstCell();else return f.map(()=>new h(c.VALUE))}if(!r.isString())return new h(c.REF);const s=r.getValue();if(t===0){const f=Jr(s),{range:m,sheetName:g,unitId:R}=f,w=new Ke(m);return w.setForcedUnitIdDirect(R),w.setForcedSheetName(g),this._setDefault(w)}if(new RegExp(nt).test(s))return this._setDefault(new En(s));if(new RegExp(Dr).test(s))return this._setDefault(new _n(s));if(new RegExp(yr).test(s))return this._setDefault(new wn(s));const i=Fe(s),{range:a,sheetName:u,unitId:o}=i,l=new Ke(a);return l.setForcedUnitIdDirect(o),l.setForcedSheetName(u),this._setDefault(l)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class ui extends A{constructor(){super(...arguments);p(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?new h(c.NA):e.isError()?e:t.isError()?new h(c.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?new h(c.REF):this._handleVector(e,t,s):this._handleArray(e,t):new h(c.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return new h(c.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,u;return i>s?(a=t.slice([0,1]),u=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),u=t.slice(void 0,[i-1,i])),a==null||u==null?new h(c.VALUE):e.isArray()?e.map(o=>this.binarySearch(o,a,u)):this.binarySearch(e,a,u)}}class oi extends A{calculate(r,e,t){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1)return new h(c.NA);if(t!=null&&t.isError())return new h(c.NA);const a=this.getMatchTypeValue(t);return a==null?new h(c.VALUE):r.isArray()?r.map(u=>this._handleSingleObject(u,e,a)):this._handleSingleObject(r,e,a)}_handleSingleObject(r,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(r,s);if(i==null)return new h(c.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return new _(a)}_getSearchModeValue(r){switch(r){case 1:return q.MIN;case 0:return q.NORMAL;case-1:return q.MAX}}}class li extends A{calculate(r,e,t,s,i){var x,v;if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return e;if(t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;if(!r.isArray())return new h(c.VALUE);const a=r.getCurrentRow(),u=r.getCurrentColumn(),o=this.getIndexNumValue(e),l=this.getIndexNumValue(t);if(typeof o!="number"||typeof l!="number")return new h(c.VALUE);const f=a+o,m=u+l;if(f<0||m<0||f>1048576||m>16384)return new h(c.REF);const g=(x=s&&this.getIndexNumValue(s))!=null?x:1,R=(v=i&&this.getIndexNumValue(i))!=null?v:1;if(typeof g!="number"||typeof R!="number")return new h(c.VALUE);if(g===0||R===0)return new h(c.REF);const w=g>0?f+g-1:f+g+1,E=R>0?m+R-1:m+R+1;if(w<0||E<0||w>1048576||E>16384)return new h(c.REF);const C=f<w?f:w,y=m<E?m:E,S=f>w?f:w,L=m>E?m:E,V={startRow:C,startColumn:y,endRow:S,endColumn:L},I=r.getUnitId(),Q=r.getSheetId(),T=new Ke(V,Q,I);return this._setDefault(T)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class ci extends A{calculate(r){if(r==null)return new _(this.row+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentRow(),t=r.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([new _(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class fi extends A{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new _(1);if(!r.isArray())return new h(c.NA);const e=r.getRowCount();return new _(e)}}class hi extends A{calculate(r,e,t,s){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);if(t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new h(c.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const u=e.slice(void 0,[0,1]),o=e.slice(void 0,[a-1,a]);return u==null||o==null?new h(c.VALUE):r.isArray()?r.map(l=>this._handleSingleObject(l,u,o,i)):this._handleSingleObject(r,u,o,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class mi extends A{calculate(r,e,t,s,i,a){if(r==null||e==null||t==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const u=e.getRowCount(),o=e.getColumnCount();if(u!==1&&o!==1)return new h(c.VALUE);if(t.isError())return new h(c.REF);if(!t.isArray())return new h(c.VALUE);const l=t.getRowCount(),f=t.getColumnCount();if(u!==l&&o!==f)return new h(c.VALUE);if(s!=null&&s.isError())return new h(c.NA);if(i!=null&&i.isError())return new h(c.NA);if(a!=null&&a.isError())return new h(c.NA);s==null&&(s=new h(c.NA));const m=this.getIndexNumValue(i||new _(0));if(m instanceof h)return m;const g=this.getIndexNumValue(a||new _(1));if(g instanceof h)return g;if(r.isArray()){let E;return u===1?E=t.slice([0,1]):E=t.slice(void 0,[0,1]),E==null?new h(c.NA):r.map(C=>{const y=this._handleSingleObject(C,e,E,m,g);return y.isError()?s:y})}if(o===f&&u===l){const E=this._handleSingleObject(r,e,t,m,g);return E.isError()?s:E}let R=0;o===f&&(R=1);const w=this._handleExpandObject(r,e,t,m,g,R);return w==null?new h(c.NA):w}_handleExpandObject(r,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(r,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(r,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(r,e,t,s===1?q.MAX:q.MIN,i===-1,a):this.equalSearchExpand(r,e,t,i!==-1,a)}_handleSingleObject(r,e,t,s,i){return(i===2||i===-2)&&s!==2?this.binarySearch(r,e,t,this._getSearchModeValue(i)):s===2?this.fuzzySearch(r,e,t,i!==-1):s===-1||s===1?this.orderSearch(r,e,t,s===1?q.MAX:q.MIN,i===-1):this.equalSearch(r,e,t,i!==-1)}_getSearchModeValue(r){return r===-2?me.MAX:me.MIN}}class gi extends A{calculate(r,e,t,s){if(r==null||e==null)return new h(c.NA);if(r.isError())return r;if(e.isError())return new h(c.REF);if(!e.isArray())return new h(c.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return new h(c.VALUE);if(t!=null&&t.isError())return new h(c.NA);if(s!=null&&s.isError())return new h(c.NA);const u=this.getIndexNumValue(t||new _(0));if(u instanceof h)return u;const o=this.getIndexNumValue(s||new _(1));return o instanceof h?o:r.isArray()?r.map(l=>this._handleSingleObject(l,e,u,o)):this._handleSingleObject(r,e,u,o)}_handleSingleObject(r,e,t,s){let i;if((s===2||s===-2)&&t!==2){const a=this._getSearchModeValue(s);i=e.binarySearch(r,a)}else if(t===2){const a=e.compare(r,b.EQUALS);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}else if(t===-1||t===1){const a=e.orderSearch(r,t===1?q.MAX:q.MIN,s===-1);if(a==null)return new h(c.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(r);let u;if(s!==-1?u=a.getFirstTruePosition():u=a.getLastTruePosition(),u==null)return new h(c.NA);i=e.getRowCount()===1?u.column:u.row}return i==null?new h(c.NA):new _(i+1)}_getSearchModeValue(r){return r===-2?me.MAX:me.MIN}}class di extends A{calculate(r,e,t,s){if(r==null)return new h(c.NA);if(r.isError())return r;if(e!=null&&e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(!r.isArray())return new h(c.REF);const i=r.getRowCount(),a=r.getColumnCount();i===1&&a>1&&t==null?(t=e!=null?e:new _(0),e=new _(0)):(e=e!=null?e:new _(0),t=t!=null?t:new _(0)),s=s!=null?s:new _(1);const u=Math.max(e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1),o=Math.max(e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1);if(u===1&&o===1)return this._calculateSingleCell(r,e,t,s);{const l=j(u,o,e,new h(c.NA)),f=j(u,o,t,new h(c.NA)),m=j(u,o,s,new h(c.NA));return l.map((g,R,w)=>{const E=f.get(R,w),C=m.get(R,w),y=this._calculateSingleCell(r,g,E,C);return y.isArray()?y.getFirstCell():y})}}_calculateSingleCell(r,e,t,s){if(e.isError())return e;const i=this._getNumberValue(e);if(i===void 0||i<0)return new h(c.VALUE);if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return new h(c.VALUE);if(s.isError())return s;const u=this._getAreaNumberValue(s);if(u===void 0||u<1)return new h(c.VALUE);const o=i===0?[void 0]:[i-1,i],l=a===0?[void 0]:[a-1,a],f=r.slice(o,l);return f||new h(c.REF)}_getNumberValue(r){if(r==null)return 0;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}_getAreaNumberValue(r){if(r==null)return 1;let e=0;if(r.isBoolean())r.getValue()===!0&&(e=1);else{if(r.isString())return;r.isNumber()?e=Math.floor(r.getValue()):r.isNull()&&(e=0)}return e}}const Cn=[[ti,G.ADDRESS],[ni,G.COLUMN],[si,G.COLUMNS],[di,G.INDEX],[ai,G.INDIRECT],[li,G.OFFSET],[ci,G.ROW],[fi,G.ROWS],[hi,G.VLOOKUP],[ui,G.LOOKUP],[oi,G.MATCH],[ii,G.HLOOKUP],[mi,G.XLOOKUP],[gi,G.XMATCH]];class Ri extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.abs()}}class Ei extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.acos()}}class wi extends A{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.acosh()}}class _i extends A{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.isArray()?r.map(e=>e.isError()?e:pn(e)):pn(r)}}function pn(n){let r=n.getValue();if(n.isBoolean()&&(r=r?1:0),!Number.isFinite(r))return new h(c.VALUE);const e=Math.atan(1/Number(r));return Number.isNaN(e)?new h(c.VALUE):new _(e)}var N=(n=>(n.ABS="ABS",n.ACOS="ACOS",n.ACOSH="ACOSH",n.ACOT="ACOT",n.ACOTH="ACOTH",n.AGGREGATE="AGGREGATE",n.ARABIC="ARABIC",n.ASIN="ASIN",n.ASINH="ASINH",n.ATAN="ATAN",n.ATAN2="ATAN2",n.ATANH="ATANH",n.BASE="BASE",n.CEILING="CEILING",n.CEILING_MATH="CEILING.MATH",n.CEILING_PRECISE="CEILING.PRECISE",n.COMBIN="COMBIN",n.COMBINA="COMBINA",n.COS="COS",n.COSH="COSH",n.COT="COT",n.COTH="COTH",n.CSC="CSC",n.CSCH="CSCH",n.DECIMAL="DECIMAL",n.DEGREES="DEGREES",n.EVEN="EVEN",n.EXP="EXP",n.FACT="FACT",n.FACTDOUBLE="FACTDOUBLE",n.FLOOR="FLOOR",n.FLOOR_MATH="FLOOR.MATH",n.FLOOR_PRECISE="FLOOR.PRECISE",n.GCD="GCD",n.INT="INT",n.ISO_CEILING="ISO.CEILING",n.LCM="LCM",n.LET="LET",n.LN="LN",n.LOG="LOG",n.LOG10="LOG10",n.MDETERM="MDETERM",n.MINVERSE="MINVERSE",n.MMULT="MMULT",n.MOD="MOD",n.MROUND="MROUND",n.MULTINOMIAL="MULTINOMIAL",n.MUNIT="MUNIT",n.ODD="ODD",n.PI="PI",n.POWER="POWER",n.PRODUCT="PRODUCT",n.QUOTIENT="QUOTIENT",n.RADIANS="RADIANS",n.RAND="RAND",n.RANDARRAY="RANDARRAY",n.RANDBETWEEN="RANDBETWEEN",n.ROMAN="ROMAN",n.ROUND="ROUND",n.ROUNDDOWN="ROUNDDOWN",n.ROUNDUP="ROUNDUP",n.SEC="SEC",n.SECH="SECH",n.SERIESSUM="SERIESSUM",n.SEQUENCE="SEQUENCE",n.SIGN="SIGN",n.SIN="SIN",n.SINH="SINH",n.SQRT="SQRT",n.SQRTPI="SQRTPI",n.SUBTOTAL="SUBTOTAL",n.SUM="SUM",n.SUMIF="SUMIF",n.SUMIFS="SUMIFS",n.SUMPRODUCT="SUMPRODUCT",n.SUMSQ="SUMSQ",n.SUMX2MY2="SUMX2MY2",n.SUMX2PY2="SUMX2PY2",n.SUMXMY2="SUMXMY2",n.TAN="TAN",n.TANH="TANH",n.TRUNC="TRUNC",n))(N||{});class Ci extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.mod(e)}}class pi extends A{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.pow(e)}}class Di extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(1);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isArray()&&(s=this._multiplyArray(s),s.isError()))return s;if(!s.isNull()&&(e=e.multiply(s),e.isError()))return e}return e}_multiplyArray(r){let e=new _(1);return r.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class yi extends A{constructor(){super(...arguments);p(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return new h(c.NA);if(e.isError())return e;if(t.length===0)return new h(c.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,u)=>{s[a]==null&&(s[a]=[]),s[a][u]=this._handleSingleObject(i,...t)}),gt(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=new h(c.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(isNaN(t))return new h(c.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:new h(c.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=new _(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();a.iterator((o,l)=>{if(e&&this._isRowHidden(u,l)||o==null||o.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new _(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new _(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return new _(0);let i=new _(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return new h(c.VALUE);const u=a.getRowData();let o;if(a.iterator((l,f)=>{if(e&&this._isRowHidden(u,f)||l==null||l.isNull()||l.isString()||l.isBoolean())return!0;if(l.isError())return o=l,!1;s[0].push(l)}),o!=null&&o.isError())return o}return gt(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===d.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class bi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function Si(n){const r=[b.EQUALS,b.NOT_EQUAL,b.GREATER_THAN_OR_EQUAL,b.GREATER_THAN,b.LESS_THAN_OR_EQUAL,b.LESS_THAN];for(const e of r)if(n.startsWith(e)){const t=n.substring(e.length);return[e,_e.create(t)]}return[b.EQUALS,_e.create(n)]}function Dn(n,r,e){if(!e)if(r.isString()){const t=`${r.getValue()}`,[s,i]=Si(t);e=s,r=i}else e=b.EQUALS;return n.compare(r,e)}function Li(n,r){const e=Math.max(n.isArray()?n.getRowCount():1,r.isArray()?r.getRowCount():1),t=Math.max(n.isArray()?n.getColumnCount():1,r.isArray()?r.getColumnCount():1),s=j(e,t,n),i=j(e,t,r);return s.mapValue((a,u,o)=>{const l=i.get(u,o);return a!=null&&a.isError()?a:l!=null&&l.isError()?l:a!=null&&a.isBoolean()&&(l!=null&&l.isBoolean())?new P(a.getValue()&&l.getValue()):new P(!1)})}class Ai extends A{calculate(r,e,t){return r==null||e==null?new h(c.NA):r.isError()||e.isError()||t!=null&&t.isError()?new h(c.NA):!r.isArray()||t&&!t.isArray()?new h(c.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(r,s,t)):this._handleSingleObject(r,e,t)}_handleSingleObject(r,e,t){const s=Dn(r,e),i=t?t.slice([0,r.getRowCount()],[0,r.getColumnCount()]):r;return i?i.pick(s).sum():new h(c.VALUE)}}class Pi extends A{calculate(r,...e){if(r==null)return new h(c.NA);if(e.length<2)return new h(c.NA);if(r.isError())return new h(c.NA);if(!r.isArray())return new h(c.VALUE);if(e.length<2||e.length%2!==0)return new h(c.VALUE);if(e.some((f,m)=>m%2===0&&!f.isArray()))return new h(c.VALUE);const t=r.getRowCount(),s=r.getColumnCount();let i=0,a=0;e.forEach((f,m)=>{if(m%2===1)if(f.isArray()){const g=f;i=Math.max(i,g.getRowCount()),a=Math.max(a,g.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const u=[];for(let f=0;f<e.length;f++){if(f%2===1)continue;const m=e[f],g=m.getRowCount(),R=m.getColumnCount();if(g!==t||R!==s)return j(i,a,new h(c.NA));const w=e[f+1];j(i,a,w,new h(c.NA)).iterator((C,y,S)=>{if(!C)return;const L=Dn(m,C);if(u[y]===void 0&&(u[y]=[]),u[y][S]===void 0){u[y][S]=L;return}u[y][S]=Li(u[y][S],L)})}const o=u.map(f=>f.map(m=>r.pick(m).sum())),l={calculateValueList:o,rowCount:o.length,columnCount:o[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(l)}}const yn=[[Ri,N.ABS],[Ei,N.ACOS],[wi,N.ACOSH],[_i,N.ACOT],[Ci,N.MOD],[yi,N.SUBTOTAL],[bi,N.SUM],[Ai,N.SUMIF],[Pi,N.SUMIFS],[pi,N.POWER],[Di,N.PRODUCT]];class Vi extends A{constructor(){super(...arguments);p(this,"_compareType",b.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?e:e.compare(t,this._compareType)}}class xi extends A{calculate(r,e){return r.isError()||e.isError()?r:!e.isArray()&&e.getValue()===0?new h(c.DIV_BY_ZERO):r.divided(e)}}var Z=(n=>(n.COMPARE="COMPARE",n.DIVIDED="DIVIDED",n.MINUS="MINUS",n.MULTIPLY="MULTIPLY",n.PLUS="PLUS",n.UNION="UNION",n))(Z||{});class vi extends A{calculate(r,e){return r.isError()||e.isError()?r:r.minus(e)}}class Bi extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.multiply(e)}}class Ui extends A{calculate(r,e){return r.isError()?r:e.isError()?e:r.plus(e)}}const bn=[[Vi,Z.COMPARE],[xi,Z.DIVIDED],[vi,Z.MINUS],[Bi,Z.MULTIPLY],[Ui,Z.PLUS]];class Mi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0),t=new _(0);for(let s=0;s<r.length;s++){let i=r[s];if(i.isError())return i;if(i.isString()){const a=i.getValue();if(!d.isRealNum(a))return new h(c.VALUE);i=new _(a)}if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(new _(i.getValue())),t=t.plus(new _(1)))}return e.divided(t)}}class Oi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(!s.isError())if(s.isArray())s=s.count(),e=e.plus(s);else if(s.isString()){const i=s.getValue();d.isRealNum(i)&&(e=e.plus(new _(1)))}else s.isNull()||(e=e.plus(new _(1)))}return e}}class Fi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError()){e=e.plus(new _(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new _(1)))}return e}}var K=(n=>(n.AVEDEV="AVEDEV",n.AVERAGE="AVERAGE",n.AVERAGEA="AVERAGEA",n.AVERAGEIF="AVERAGEIF",n.AVERAGEIFS="AVERAGEIFS",n.BETA_DIST="BETA.DIST",n.BETA_INV="BETA.INV",n.BINOM_DIST="BINOM.DIST",n.BINOM_DIST_RANGE="BINOM.DIST.RANGE",n.BINOM_INV="BINOM.INV",n.CHISQ_DIST="CHISQ.DIST",n.CHISQ_DIST_RT="CHISQ.DIST.RT",n.CHISQ_INV="CHISQ.INV",n.CHISQ_INV_RT="CHISQ.INV.RT",n.CHISQ_TEST="CHISQ.TEST",n.CONFIDENCE_NORM="CONFIDENCE.NORM",n.CONFIDENCE_T="CONFIDENCE.T",n.CORREL="CORREL",n.COUNT="COUNT",n.COUNTA="COUNTA",n.COUNTBLANK="COUNTBLANK",n.COUNTIF="COUNTIF",n.COUNTIFS="COUNTIFS",n.COVARIANCE_P="COVARIANCE.P",n.COVARIANCE_S="COVARIANCE.S",n.DEVSQ="DEVSQ",n.EXPON_DIST="EXPON.DIST",n.F_DIST="F.DIST",n.F_DIST_RT="F.DIST.RT",n.F_INV="F.INV",n.F_INV_RT="F.INV.RT",n.F_TEST="F.TEST",n.FISHER="FISHER",n.FISHERINV="FISHERINV",n.FORECAST="FORECAST",n.FORECAST_ETS="FORECAST.ETS",n.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",n.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",n.FORECAST_ETS_STAT="FORECAST.ETS.STAT",n.FORECAST_LINEAR="FORECAST.LINEAR",n.FREQUENCY="FREQUENCY",n.GAMMA="GAMMA",n.GAMMA_DIST="GAMMA.DIST",n.GAMMA_INV="GAMMA.INV",n.GAMMALN="GAMMALN",n.GAMMALN_PRECISE="GAMMALN.PRECISE",n.GAUSS="GAUSS",n.GEOMEAN="GEOMEAN",n.GROWTH="GROWTH",n.HARMEAN="HARMEAN",n.HYPGEOM_DIST="HYPGEOM.DIST",n.INTERCEPT="INTERCEPT",n.KURT="KURT",n.LARGE="LARGE",n.LINEST="LINEST",n.LOGEST="LOGEST",n.LOGNORM_DIST="LOGNORM.DIST",n.LOGNORM_INV="LOGNORM.INV",n.MAX="MAX",n.MAXA="MAXA",n.MAXIFS="MAXIFS",n.MEDIAN="MEDIAN",n.MIN="MIN",n.MINA="MINA",n.MINIFS="MINIFS",n.MODE_MULT="MODE.MULT",n.MODE_SNGL="MODE.SNGL",n.NEGBINOM_DIST="NEGBINOM.DIST",n.NORM_DIST="NORM.DIST",n.NORM_INV="NORM.INV",n.NORM_S_DIST="NORM.S.DIST",n.NORM_S_INV="NORM.S.INV",n.PEARSON="PEARSON",n.PERCENTILE_EXC="PERCENTILE.EXC",n.PERCENTILE_INC="PERCENTILE.INC",n.PERCENTRANK_EXC="PERCENTRANK.EXC",n.PERCENTRANK_INC="PERCENTRANK.INC",n.PERMUT="PERMUT",n.PERMUTATIONA="PERMUTATIONA",n.PHI="PHI",n.POISSON_DIST="POISSON.DIST",n.PROB="PROB",n.QUARTILE_EXC="QUARTILE.EXC",n.QUARTILE_INC="QUARTILE.INC",n.RANK_AVG="RANK.AVG",n.RANK_EQ="RANK.EQ",n.RSQ="RSQ",n.SKEW="SKEW",n.SKEW_P="SKEW.P",n.SLOPE="SLOPE",n.SMALL="SMALL",n.STANDARDIZE="STANDARDIZE",n.STDEV_P="STDEV.P",n.STDEV_S="STDEV.S",n.STDEVA="STDEVA",n.STDEVPA="STDEVPA",n.STEYX="STEYX",n.T_DIST="T.DIST",n.T_DIST_2T="T.DIST.2T",n.T_DIST_RT="T.DIST.RT",n.T_INV="T.INV",n.T_INV_2T="T.INV.2T",n.T_TEST="T.TEST",n.TREND="TREND",n.TRIMMEAN="TRIMMEAN",n.VAR_P="VAR.P",n.VAR_S="VAR.S",n.VARA="VARA",n.VARPA="VARPA",n.WEIBULL_DIST="WEIBULL.DIST",n.Z_TEST="Z.TEST",n))(K||{});class $i extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(Number.NEGATIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.max(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isLessThan(e).getValue()&&(r=e),r}}class Sn extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=new _(Number.POSITIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new _(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.min(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isGreaterThan(e).getValue()&&(r=e),r}}class ki extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std(1)}}class Ii extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std()}}class Ti extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var(1)}}class Qi extends A{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var()}}const Ln=[[Mi,K.AVERAGE],[Oi,K.COUNT],[$i,K.MAX],[Sn,K.MIN],[Sn,K.MIN],[Fi,K.COUNTA],[en,K.STDEV_P],[tn,K.STDEV_S],[ki,K.STDEVA],[Ii,K.STDEVPA],[rn,K.VAR_P],[nn,K.VAR_S],[Ti,K.VARA],[Qi,K.VARPA]];class Yi extends A{calculate(...r){if(r.length===0)return new h(c.NA);let e=0,t=0;r.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of r)s=j(e,t,i,new h(c.NA)).mapValue((u,o,l)=>{var R,w;const f=s&&s.get(o,l);if(f!=null&&f.isError())return f;if(u.isError())return u;const m=f!=null&&f.isNull()?"":(R=f==null?void 0:f.getValue())!=null?R:"",g=u!=null&&u.isNull()?"":(w=u==null?void 0:u.getValue())!=null?w:"";return new X(`${m}${g}`)});return s||new h(c.VALUE)}}var Rt=(n=>(n.ASC="ASC",n.ARRAYTOTEXT="ARRAYTOTEXT",n.BAHTTEXT="BAHTTEXT",n.CHAR="CHAR",n.CLEAN="CLEAN",n.CODE="CODE",n.CONCAT="CONCAT",n.CONCATENATE="CONCATENATE",n.DBCS="DBCS",n.DOLLAR="DOLLAR",n.EXACT="EXACT",n.FIND="FIND",n.FINDB="FINDB",n.FIXED="FIXED",n.LEFT="LEFT",n.LEFTB="LEFTB",n.LEN="LEN",n.LENB="LENB",n.LOWER="LOWER",n.MID="MID",n.MIDB="MIDB",n.NUMBERVALUE="NUMBERVALUE",n.PHONETIC="PHONETIC",n.PROPER="PROPER",n.REPLACE="REPLACE",n.REPLACEB="REPLACEB",n.REPT="REPT",n.RIGHT="RIGHT",n.RIGHTB="RIGHTB",n.SEARCH="SEARCH",n.SEARCHB="SEARCHB",n.SUBSTITUTE="SUBSTITUTE",n.T="T",n.TEXT="TEXT",n.TEXTAFTER="TEXTAFTER",n.TEXTBEFORE="TEXTBEFORE",n.TEXTJOIN="TEXTJOIN",n.TEXTSPLIT="TEXTSPLIT",n.TRIM="TRIM",n.UNICHAR="UNICHAR",n.UNICODE="UNICODE",n.UPPER="UPPER",n.VALUE="VALUE",n.VALUETOTEXT="VALUETOTEXT",n.CALL="CALL",n.EUROCONVERT="EUROCONVERT",n.REGISTER_ID="REGISTER.ID",n))(Rt||{});const An=[[Yi,Rt.CONCATENATE]],Pn=[];var Hi=(n=>{})();const Vn=[];var xn=(n=>(n.ENCODEURL="ENCODEURL",n.FILTERXML="FILTERXML",n.WEBSERVICE="WEBSERVICE",n))(xn||{});class ji extends d.Disposable{constructor(){super(...arguments);p(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const Et=B.createIdentifier("univer.formula.defined-names.service");var Wi=Object.defineProperty,Xi=Object.getOwnPropertyDescriptor,Gi=(n,r,e,t)=>{for(var s=t>1?void 0:t?Xi(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Wi(r,e,s),s},Ki=(n,r)=>(e,t)=>r(e,t,n);let ar=class extends d.Disposable{constructor(r){super();p(this,"_unitData",{});p(this,"_arrayFormulaCellData",{});p(this,"_formulaData",{});p(this,"_sheetNameMap",{});p(this,"_forceCalculate",!1);p(this,"_dirtyRanges",[]);p(this,"_dirtyNameMap",{});p(this,"_numfmtItemMap",{});p(this,"_dirtyUnitFeatureMap",{});p(this,"_excludedCell");this._currentUniverService=r}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},this._dirtyUnitFeatureMap={},this._excludedCell={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}load(r){if(r.allUnitData&&r.unitSheetNameMap)this._unitData=r.allUnitData,this._sheetNameMap=r.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:t}=this._loadSheetData();this._unitData=e,this._sheetNameMap=t}this._formulaData=r.formulaData,this._arrayFormulaCellData=pr(r.arrayFormulaCellData),this._forceCalculate=r.forceCalculate,this._dirtyRanges=r.dirtyRanges,this._dirtyNameMap=r.dirtyNameMap,this._numfmtItemMap=r.numfmtItemMap,this._dirtyUnitFeatureMap=r.dirtyUnitFeatureMap,this._excludedCell=r.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(r,e){this._dirtyRanges=r,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(r){this._unitData=r}registerFormulaData(r){this._formulaData=r}registerSheetNameMap(r){this._sheetNameMap=r}_mergeNameMap(r,e){Object.keys(e).forEach(t=>{e[t]&&Object.keys(e[t]).forEach(s=>{r[t]==null&&(r[t]={}),r[t][e[t][s]]=s})})}_loadSheetData(){const r=this._currentUniverService.getAllUniverSheetsInstance(),e={},t={};for(const s of r){const i=s.getUnitId(),a=s.getSheets(),u={},o={};for(const l of a){const f=l.getSheetId(),m=l.getConfig();u[f]={cellData:new d.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount,rowData:m.rowData,columnData:m.columnData},o[l.getName()]=l.getSheetId()}e[i]=u,t[i]=o}return{allUnitData:e,unitSheetNameMap:t}}};ar=Gi([Ki(0,d.IUniverInstanceService)],ar);const xe=B.createIdentifier("univer.formula.current-data.service");var qi=Object.defineProperty,zi=Object.getOwnPropertyDescriptor,Zi=(n,r,e,t)=>{for(var s=t>1?void 0:t?zi(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&qi(r,e,s),s},Ji=(n,r)=>(e,t)=>r(e,t,n),oe=(n=>(n[n.IDLE=0]="IDLE",n[n.START_DEPENDENCY=1]="START_DEPENDENCY",n[n.START_CALCULATION=2]="START_CALCULATION",n[n.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",n[n.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",n[n.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",n[n.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",n[n.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",n))(oe||{}),Te=(n=>(n[n.INITIAL=0]="INITIAL",n[n.STOP_EXECUTION=1]="STOP_EXECUTION",n[n.NOT_EXECUTED=2]="NOT_EXECUTED",n[n.SUCCESS=3]="SUCCESS",n))(Te||{});let ur=class extends d.Disposable{constructor(r){super();p(this,"_formulaExecuteStage",0);p(this,"_stopState",!1);p(this,"_currentRow",-1);p(this,"_currentColumn",-1);p(this,"_currentRowCount",Number.NEGATIVE_INFINITY);p(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);p(this,"_currentSubUnitId","");p(this,"_currentUnitId","");p(this,"_runtimeData",{});p(this,"_runtimeOtherData",{});p(this,"_unitArrayFormulaRange",{});p(this,"_runtimeArrayFormulaCellData",{});p(this,"_runtimeClearArrayFormulaCellData",{});p(this,"_numfmtItemMap",{});p(this,"_runtimeFeatureRange",{});p(this,"_runtimeFeatureCellData",{});p(this,"_functionsExecutedState",0);p(this,"_functionDefinitionPrivacyVar",new Map);p(this,"_totalFormulasToCalculate",0);p(this,"_completedFormulasCount",0);p(this,"_totalArrayFormulasToCalculate",0);p(this,"_completedArrayFormulasCount",0);p(this,"_isCycleDependency",!1);this._currentConfigService=r}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(r){this._totalArrayFormulasToCalculate=r}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(r){this._completedArrayFormulasCount=r}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(r){this._totalFormulasToCalculate=r}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(r){this._completedFormulasCount=r}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(r){this._formulaExecuteStage=r}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(r,e,t,s,i,a){this._currentRow=r,this._currentColumn=e,this._currentRowCount=t,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(r,e){this._functionDefinitionPrivacyVar.set(r,e)}getFunctionDefinitionPrivacyVar(r){return this._functionDefinitionPrivacyVar.get(r)}setRuntimeOtherData(r,e){const t=this._currentSubUnitId,s=this._currentUnitId;this._runtimeOtherData[s]===void 0&&(this._runtimeOtherData[s]={});const i=this._runtimeOtherData[s];i[t]===void 0&&(i[t]={});const a=i[t];a[r]=this._objectValueToCellValue(e)}setRuntimeData(r){const e=this._currentRow,t=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const o=this._runtimeData[u];o[a]==null&&(o[a]=new d.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][a]==null&&(this._numfmtItemMap[u][a]={});const l=this._numfmtItemMap[u][a],f=this._unitArrayFormulaRange[u];let m=new d.ObjectMatrix;f[a]&&(m=new d.ObjectMatrix(f[a])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const g=this._runtimeArrayFormulaCellData[u];g[a]==null&&(g[a]=new d.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const R=this._runtimeClearArrayFormulaCellData[u];R[a]==null&&(R[a]=new d.ObjectMatrix);const w=o[a],E=g[a],C=R[a];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const y=r,{startRow:S,startColumn:L,endRow:V,endColumn:I}=y.getRangePosition();if(S===V&&L===I){const T=y.getFirstCell(),x=this._objectValueToCellValue(T);w.setValue(e,t,x),C.setValue(e,t,x),l[e]==null&&(l[e]={}),l[e][t]=T.getPattern();return}const Q={startRow:e,startColumn:t,endRow:V-S+e,endColumn:I-L+t};if(m.setValue(e,t,Q),f[a]=m.getData(),this._checkIfArrayFormulaRangeHasData(u,a,e,t,Q)||this._checkIfArrayFormulaExceeded(s,i,Q)){const T=this._objectValueToCellValue(new h(c.SPILL));w.setValue(e,t,T),C.setValue(e,t,T)}else{const T=new h(c.SPILL);y.iterator((x,v,$)=>{const k=this._objectValueToCellValue(x);if(v===S&&$===L){if(x!=null&&x.isError()&&x.isEqualType(T))return C.setValue(e,t,{}),w.setValue(e,t,{...this._objectValueToCellValue(T)}),!1;w.setValue(e,t,{...k})}const Ye=v-S+e,Kn=$-L+t;E.setValue(Ye,Kn,k);const qn=x==null?void 0:x.getPattern();qn&&(l[Ye]==null&&(l[Ye]={}),l[Ye][Kn]=qn)})}}else{const y=this._objectValueToCellValue(r);w.setValue(e,t,y),l[e]==null&&(l[e]={}),l[e][t]=r.getPattern(),C.setValue(e,t,y)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(r,e){this._runtimeFeatureRange[r]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(r,e){this._runtimeFeatureCellData[r]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),numfmtItemMap:this.getNumfmtItemMap(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(r){if(r==null)return{v:0,t:d.CellValueType.NUMBER};if(r.isError())return{v:r.getErrorType(),t:d.CellValueType.STRING};if(r.isValueObject()){const e=r,t=e.getValue();return e.isNumber()?{v:t,t:d.CellValueType.NUMBER}:e.isBoolean()?{v:t,t:d.CellValueType.BOOLEAN}:e.isString()&&d.isRealNum(t)?{v:t,t:d.CellValueType.FORCE_STRING}:{v:t,t:d.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(r,e,t,s,i){var g,R,w,E,C,y,S,L,V,I,Q,T;const{startRow:a,startColumn:u,endRow:o,endColumn:l}=i,f=this._currentConfigService.getUnitData(),m=(w=(R=(g=this._unitArrayFormulaRange[r])==null?void 0:g[e])==null?void 0:R[t])==null?void 0:w[s];for(let x=a;x<=o;x++)for(let v=u;v<=l;v++){if(x===t&&s===v)continue;const $=(y=(C=(E=this._runtimeData)==null?void 0:E[r])==null?void 0:C[e])==null?void 0:y.getValue(x,v),k=(V=(L=(S=this._runtimeArrayFormulaCellData)==null?void 0:S[r])==null?void 0:L[e])==null?void 0:V.getValue(x,v),Ye=(T=(Q=(I=f==null?void 0:f[r])==null?void 0:I[e])==null?void 0:Q.cellData)==null?void 0:T.getValue(x,v);if(!d.isNullCell($)||!d.isNullCell(k)&&!this._isInArrayFormulaRange(m,x,v)||!d.isNullCell(Ye))return!0}return!1}_isInArrayFormulaRange(r,e,t){if(r==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:u}=r;return e>=s&&e<=a&&t>=i&&t<=u}_checkIfArrayFormulaExceeded(r,e,t){return t.endRow>=r||t.endColumn>=e}_isInDirtyRange(r,e,t,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:Er(i,r,e,t,s)}};ur=Zi([Ji(0,xe)],ur);const se=B.createIdentifier("univer.formula.runtime.service");var Ni=Object.defineProperty,ea=Object.getOwnPropertyDescriptor,ta=(n,r,e,t)=>{for(var s=t>1?void 0:t?ea(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ni(r,e,s),s},or=(n,r)=>(e,t)=>r(e,t,n);let ve=class extends d.Disposable{constructor(n,r,e){super(),this._definedNamesService=n,this._runtimeService=r,this._lexerTreeBuilder=e}treeBuilder(n,r=!0){return this._lexerTreeBuilder.treeBuilder(n,r,this._injectDefinedName.bind(this))}_injectDefinedName(n){var i;const r=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(r))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(n);let t="",s=!1;for(let a=0,u=e.length;a<u;a++){const o=e[a];if(typeof o=="string"){t+=o;continue}const{nodeType:l,token:f}=o;if(l===te.REFERENCE||l===te.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(r))==null?void 0:i.get(f);m?(t+=m,s=!0):t+=f}else t+=f}return{sequenceString:t,hasDefinedName:s}}};ve=ta([or(0,Et),or(1,se),or(2,B.Inject(it))],ve);var M=(n=>(n.REFERENCE="ReferenceNode",n.VALUE="ValueNode",n.OPERATOR="OperatorNode",n.FUNCTION="FunctionNode",n.LAMBDA="LambdaNode",n.LAMBDA_PARAMETER="LambdaNodeParameter",n.ERROR="ErrorNode",n.BASE="Base",n.ROOT="Root",n.UNION="UnionNode",n.PREFIX="PrefixNode",n.SUFFIX="SuffixNode",n.NULL="NullNode",n))(M||{});const le=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class ee extends d.Disposable{constructor(e){super();p(this,"_children",[]);p(this,"_parent");p(this,"_valueObject");p(this,"_calculateState",!1);p(this,"_async",!1);p(this,"_address",!1);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return M.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(be.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let u=0;u<i;u++){const o=t[u];s.push(o.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class W extends ee{constructor(e){super(e);p(this,"_errorValueObject");this._errorValueObject=new h(e)}get nodeType(){return M.ERROR}static create(e){return new W(e)}getValue(){return this._errorValueObject}}const ce=100;class fe extends d.Disposable{get zIndex(){return 0}create(r,e,t){let s;return r instanceof U?s=r.getToken():s=r,new ee(s)}checkAndCreateNodeType(r){}}class lr extends ee{get nodeType(){return M.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class vn extends fe{get zIndex(){return le.get(M.ROOT)||ce}checkAndCreateNodeType(r){if(!(r instanceof U))return;if(r.getToken()===Re)return new lr(Re)}}class Bn extends d.Disposable{constructor(){super(...arguments);p(this,"_functionExecutors",new Map);p(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const ge=B.createIdentifier("univer.formula.function.service");var ra=Object.defineProperty,na=Object.getOwnPropertyDescriptor,sa=(n,r,e,t)=>{for(var s=t>1?void 0:t?na(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ra(r,e,s),s},Un=(n,r)=>(e,t)=>r(e,t,n);class wt extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.PREFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===Y.MINUS?t=this._functionExecutor.calculate(new _(0),e):this._operatorString===Y.AT?t=this._handlerAT(e):t=new h(c.VALUE),this.setValue(t)}_handlerAT(r){if(!r.isReferenceObject())return new h(c.VALUE);const e=r;if(e.isCell())return new h(c.VALUE);const t=this._accessor.get(se),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():new h(c.VALUE)}}let _t=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.PREFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof U))return;const r=n.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Y.MINUS)t=Z.MINUS;else return e===Y.AT?new wt(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new wt(this._injector,e,s):(console.error(`No function ${r}`),W.create(c.NAME))}};_t=sa([Un(0,ge),Un(1,B.Inject(B.Injector))],_t);var ia=Object.defineProperty,aa=Object.getOwnPropertyDescriptor,ua=(n,r,e,t)=>{for(var s=t>1?void 0:t?aa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ia(r,e,s),s},Ct=(n,r)=>(e,t)=>r(e,t,n);class oa extends ee{constructor(r,e,t,s){super(r),this._functionExecutor=e,this._currentConfigService=t,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return M.FUNCTION}async executeAsync(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;a++){const u=e[a].getValue();u!=null&&(u.isReferenceObject()?r.push(u.toArrayValueObject()):r.push(u))}const s=this._calculate(r);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(be.SUCCESS)}execute(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?r.push(a.toArrayValueObject()):r.push(a))}const s=this._calculate(r);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const r=this.getChildren(),e=r.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=r[1].getValue(),s=r[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:u,startColumn:o,endRow:l,endColumn:f}=i,m=l-u+1,g=f-o+1,{startRow:R,startColumn:w,endRow:E,endColumn:C}=a,y=E-R+1,S=C-w+1;m!==y&&(a.endRow+=m-y),g!==S&&(a.endColumn+=g-S)}_calculate(r){var t;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...r.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=_e.create(s);else{const i=As(s);e=new z({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...r);return e}_setRefInfo(){const{currentUnitId:r,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(r,e,t,s)}_setRefData(r){if(!r.isReferenceObject())return;const e=r;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let pt=class extends fe{constructor(n,r,e,t){super(),this._functionService=n,this._currentConfigService=r,this._runtimeService=e,this._injector=t}get zIndex(){return le.get(M.FUNCTION)||ce}create(n){const r=this._functionService.getExecutor(n);return r?new oa(n,r,this._currentConfigService,this._runtimeService):(console.error(`No function ${n}`),W.create(c.NAME))}checkAndCreateNodeType(n){if(typeof n=="string")return;let e=n.getToken().trim().toUpperCase(),t,s;const i=e.slice(0,2);let a=0;if(new RegExp(Y.MINUS,"g").test(i)){const u=this._functionService.getExecutor(Z.MINUS);t=new wt(this._injector,Y.MINUS,u),a++}if(new RegExp(Y.AT,"g").test(i)&&(s=new wt(this._injector,Y.AT),t&&s.setParent(t),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const u=this.create(e);return s?u.setParent(s):t&&u.setParent(t),u}}};pt=ua([Ct(0,ge),Ct(1,xe),Ct(2,se),Ct(3,B.Inject(B.Injector))],pt);var la=Object.defineProperty,ca=Object.getOwnPropertyDescriptor,fa=(n,r,e,t)=>{for(var s=t>1?void 0:t?ca(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&la(r,e,s),s},ha=(n,r)=>(e,t)=>r(e,t,n);let Qe=class extends d.Disposable{constructor(n){super(),this._runtimeService=n}dispose(){}async executeAsync(n){if(!n)return new h(c.VALUE);await this._executeAsync(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return Promise.resolve(r)}execute(n){if(!n)return new h(c.VALUE);this._execute(n);const r=n.getValue();if(r==null)throw new Error("node value is null");return r}executePreCalculateNode(n){return n.execute(),n.getValue()}checkAsyncNode(n){const r=[];this._checkAsyncNode(n,r);for(let e=0,t=r.length;e<t;e++)if(r[e]===!0)return!0;return!1}_checkAsyncNode(n,r){const e=n.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];r.push(i.isAsync()),this._checkAsyncNode(i,r)}}async _executeAsync(n){if(this._runtimeService.isStopExecution())return Promise.resolve(be.ERROR);const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return n.nodeType===M.FUNCTION&&n.isAsync()?await n.executeAsync():n.execute(),Promise.resolve(be.SUCCESS)}_execute(n){if(this._runtimeService.isStopExecution())return be.ERROR;const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===We&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return n.execute(),be.SUCCESS}};Qe=fa([ha(0,se)],Qe);function Mn(n){return n instanceof U?n.getToken()===Oe:!1}function ma(n){return n instanceof U?n.getToken()===Lr:!1}function On(n){if(!n)return;if(n.getToken()!==je)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(!e)return;const s=e.get(t);return s==null&&n.getValue()?n:On(s)}class ga extends we{constructor(e,t,s){super(0);p(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return new h(c.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new vs(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const t=e.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.getToken()===je){const o=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(o);if(l)a.setValue(l);else{const f=a.getCurrentLambdaPrivacyVar(),m=On(f.get(o));m!=null&&a.setValue(m.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let t=0;t<e.length;t++){const s=e[t],i=this._lambdaPrivacyVarKeys[t];this._lambdaPrivacyValueMap.set(i,s)}}}var da=Object.defineProperty,Ra=Object.getOwnPropertyDescriptor,Ea=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ra(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&da(r,e,s),s},Fn=(n,r)=>(e,t)=>r(e,t,n);class wa extends ee{constructor(e,t,s,i){super(e);p(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return M.LAMBDA}setNotEmpty(e=!1){this._isNotEmpty=e}isEmptyParamFunction(){return this.getChildren().length<2&&this._isNotEmpty}isFunctionParameter(){return this._lambdaId===null}getLambdaId(){return this._lambdaId}execute(){if(this.isEmptyParamFunction())this.setValue(new ga(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let Dt=class extends fe{constructor(n,r){super(),this._runtimeService=n,this._interpreter=r}get zIndex(){return le.get(M.LAMBDA)||ce}create(n){const r=n.getChildren(),e=r[0];let t=r.slice(1,-1);const s=r[r.length-1];if(!(e instanceof U&&s instanceof U))return W.create(c.NAME);if(e.getToken()===Oe){const u=e.getChildren();if(t.length!==u.length)return W.create(c.VALUE)}else t=r.slice(0,-1);const i=d.Tools.generateRandomId(8),a=new Map;for(let u=0;u<t.length;u++){const o=t[u];if(o instanceof U){const l=o.getChildren()[0];o.setToken(Lr),a.set(l.trim(),void 0)}else return W.create(c.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new wa(n.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(n){if(!(!(n instanceof U)||n.getToken().trim().toUpperCase()!==We))return this.create(n)}_updateLambdaStatement(n,r,e){this._updateTree(n,r,e)}_updateTree(n,r,e){const t=n.getChildren(),s=t.length,i=t[0];for(let a=0;a<s;a++){const u=t[a];if(!(Mn(i)&&a!==0))if(u instanceof U)this._updateTree(u,r,e);else{const o=u.trim();if(e.has(o)){const l=new U;l.setToken(je),l.setLambdaId(r),l.setLambdaPrivacyVar(e),l.setLambdaParameter(o),t[a]=l}}}}};Dt=Ea([Fn(0,se),Fn(1,B.Inject(Qe))],Dt);function $n(n){if(!n)return;if(n.getToken()!==je)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(e)return $n(e.get(t))}class _a extends ee{constructor(r,e,t){super(r),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return M.LAMBDA_PARAMETER}execute(){const r=$n(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(r)this.setValue(r.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new h(c.SPILL))}}}class kn extends fe{get zIndex(){return le.get(M.LAMBDA_PARAMETER)||ce}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new _a(r.getToken(),t,e):new W(c.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof U)||r.getToken().trim()!==je))return this.create(r)}}class Ca extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.NULL}execute(){this.setValue(new ue(0))}}var pa=Object.defineProperty,Da=Object.getOwnPropertyDescriptor,ya=(n,r,e,t)=>{for(var s=t>1?void 0:t?Da(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&pa(r,e,s),s},ba=(n,r)=>(e,t)=>r(e,t,n);class Sa extends ee{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return M.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===Z.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=r[0].getValue(),t=r[1].getValue();if(e==null||t==null)throw new Error("object1 or object2 is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let yt=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.OPERATOR)||ce}create(n){let r="";const e=n;e===J.PLUS?r=Z.PLUS:e===J.MINUS?r=Z.MINUS:e===J.MULTIPLY?r=Z.MULTIPLY:e===J.DIVIDED?r=Z.DIVIDED:e===J.CONCATENATE?r=Rt.CONCATENATE:e===J.POWER?r=N.POWER:zn.has(e)&&(r=Z.COMPARE);const t=this._functionService.getExecutor(r);return t?new Sa(e,t):(console.error(`No function ${n}`),W.create(c.NAME))}checkAndCreateNodeType(n){if(n instanceof U)return;const r=n.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&He.has(r))return this.create(r)}};yt=ya([ba(0,ge)],yt);class La extends d.Disposable{constructor(){super(...arguments);p(this,"_tableMap",new Map);p(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const cr=B.createIdentifier("univer.formula.super-table.service");class Aa extends ke{constructor(r,e,t,s){super(r),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,u=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const o=this._stringToColumnData(this._columnDataString,u,s),l=o.startColumn,f=o.endColumn,m=o.type;let g=-1,R=-1;const w=a.startRow,E=a.startColumn;m===Se.ALL?(g=w,R=E):m===Se.DATA?(g=w+1,R=E):m===Se.HEADERS?(g=w,R=w):m===Se.TOTALS&&(g=E,R=E),this.setRangeData({startColumn:l,endColumn:f,startRow:g,endRow:R})}isTable(){return!0}_stringToColumnData(r,e,t){r=r.substring(1,-1);const s=r.indexOf(O.COMMA);let i=-1,a=-1,u=Se.ALL;if(s===-1){const o=this._columnHandler(r,e);i=o.startColumn,a=o.endColumn}else{const o=r.substring(0,s).substring(1,-1),l=r.substring(s+1),f=this._columnHandler(l,e,!0);i=f.startColumn,a=f.endColumn,u=t.get(o),u||(u=Se.ALL)}return{startColumn:i,endColumn:a,type:u}}_columnHandler(r,e,t=!1){var u,o,l;let s=-1,i=-1;const a=r.indexOf(O.COLON);if(new RegExp(br,"g").test(r)){const f=r.substring(0,a).substring(1,-1),m=r.substring(a+1).substring(1,-1);s=(u=e.get(f))!=null?u:-1,i=(o=e.get(m))!=null?o:-1}else t&&(r=r.substring(1,-1)),s=(l=e.get(r))!=null?l:-1,i=s;return{startColumn:s,endColumn:i}}}var Pa=Object.defineProperty,Va=Object.getOwnPropertyDescriptor,xa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Va(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Pa(r,e,s),s},qe=(n,r)=>(e,t)=>r(e,t,n);class bt extends ee{constructor(r,e,t,s=!1){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return M.REFERENCE}execute(){const r=this._accessor.get(xe),e=this._accessor.get(se);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(r.getSheetNameMap()),this._referenceObject.setUnitData(r.getUnitData()),this._referenceObject.setArrayFormulaCellData(r.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setNumfmtItemData(r.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(new h(c.NAME)):this.setValue(this._referenceObject)}}let St=class extends fe{constructor(n,r,e,t,s){super(),this._definedNamesService=n,this._superTableService=r,this._formulaRuntimeService=e,this._lexer=t,this._injector=s}get zIndex(){return le.get(M.REFERENCE)||ce}checkAndCreateNodeType(n){var o,l;let r=!1,e,t=!1;if(n instanceof U?(r=!0,e=n.getToken().trim(),((l=(o=n.getParent())==null?void 0:o.getParent())==null?void 0:l.getToken().trim())===O.COLON&&(t=!0)):e=n.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(nt).test(e))return new bt(this._injector,e,new En(e),t);if(r&&new RegExp(ts).test(e))return new bt(this._injector,e,new _n(e),t);if(r&&new RegExp(rs).test(e))return new bt(this._injector,e,new wn(e),t);const s=this._formulaRuntimeService.currentUnitId,i=this._superTableService.getTableMap(s),a=new RegExp(br,"g"),u=e.replace(a,"");if(!r&&(i!=null&&i.has(u))){const f=a.exec(e);let m="";f&&(m=f[0]);const g=i.get(u),R=this._superTableService.getTableOptionMap();return new bt(this._injector,e,new Aa(e,g,m,R))}}};St=xa([qe(0,Et),qe(1,cr),qe(2,se),qe(3,B.Inject(ve)),qe(4,B.Inject(B.Injector))],St);var va=Object.defineProperty,Ba=Object.getOwnPropertyDescriptor,Ua=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ba(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&va(r,e,s),s},In=(n,r)=>(e,t)=>r(e,t,n);class Tn extends ee{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return M.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===he.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new _(100)),t.setPattern("0.00%")):this._operatorString===he.POUND?t=this._handlerPound(e):t=new h(c.VALUE),this.setValue(t)}_handlerPound(r){var f,m,g,R;if(!r.isReferenceObject())return new h(c.VALUE);if(!r.isCell())return new h(c.VALUE);const e=this._accessor.get(xe),t=this._accessor.get(ve),s=r,i=s.getRangePosition(),a=s.getUnitId(),u=s.getSheetId(),o=e.getFormulaData(),l=(R=(g=(m=(f=o==null?void 0:o[a])==null?void 0:f[u])==null?void 0:m[i.startRow])==null?void 0:g[i.startColumn])==null?void 0:R.f;return l?(t.treeBuilder(l),new h(c.VALUE)):new h(c.VALUE)}}let Lt=class extends fe{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return le.get(M.SUFFIX)||ce}checkAndCreateNodeType(n){if(!(n instanceof U))return;const r=n.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===he.PERCENTAGE)e=Z.DIVIDED;else return r===he.POUND?new Tn(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Tn(this._injector,r,t):(console.error(`No function ${n}`),W.create(c.NAME))}};Lt=Ua([In(0,ge),In(1,B.Inject(B.Injector))],Lt);var Ma=Object.defineProperty,Oa=Object.getOwnPropertyDescriptor,Fa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Oa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ma(r,e,s),s},$a=(n,r)=>(e,t)=>r(e,t,n);class ka extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.UNION}execute(){const r=this.getChildren(),e=r[0].getValue(),t=r[1].getValue();if(e==null||t==null)throw new Error("leftNode and rightNode");let s;this._operatorString===O.COLON?s=this._unionFunction(e,t):s=new h(c.NAME),this.setValue(s)}_unionFunction(r,e){return r.isError()||e.isError()?new h(c.REF):!r.isReferenceObject()||!e.isReferenceObject()?new h(c.REF):(r=r,e=e,r.isCell()&&e.isCell()||r.isRow()&&e.isRow()||r.isColumn()&&e.isColumn()?r.unionBy(e):new h(c.REF))}}let At=class extends fe{constructor(n){super(),this._functionService=n}get zIndex(){return le.get(M.UNION)||ce}create(n){return new ka(n)}checkAndCreateNodeType(n){if(!(n instanceof U))return;const e=n.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===O.COLON)return this.create(e)}};At=Fa([$a(0,ge)],At);class Ia extends ee{constructor(r){super(r),this._operatorString=r}get nodeType(){return M.VALUE}execute(){this.setValue(_e.create(this._operatorString))}}class Qn extends fe{get zIndex(){return le.get(M.VALUE)||ce}_checkValueNode(r){if(Number.isNaN(Number(r))){const e=r.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(Ne.has(e))return this.create(e);if(t==='"'&&s==='"')return this.create(e);if(t==="{"&&s==="}")return this.create(e);const i=e.toUpperCase();if(i===ye.TRUE||i===ye.FALSE)return this.create(i)}else return this.create(r)}create(r){return new Ia(r)}checkAndCreateNodeType(r){if(!(r instanceof U))return this._checkValueNode(r)}}var Ta=Object.defineProperty,Qa=Object.getOwnPropertyDescriptor,Ya=(n,r,e,t)=>{for(var s=t>1?void 0:t?Qa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ta(r,e,s),s},ie=(n,r)=>(e,t)=>r(e,t,n);let ze=class extends d.Disposable{constructor(r,e,t,s,i,a,u,o,l,f,m){super();p(this,"_astNodeFactoryList",[]);p(this,"_refOffsetX",0);p(this,"_refOffsetY",0);this._runtimeService=r,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=u,this._referenceNodeFactory=o,this._suffixNodeFactory=l,this._unionNodeFactory=f,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const s=new lr(Re);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,s)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),s=new lr(Re),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],u=r.getChildren(),o=u.length;for(let m=0;m<o;m++){const g=u[m];if(g instanceof U)this._parse(g,s);else return!1}const l=s.getChildren(),f=l.length;for(let m=0;m<f;m++){const g=l[m];i.set(a[m],g)}return s.setParent(e),e}_changeLetToLambda(r){const e=r.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new U;s.setToken(We);const i=new U;i.setToken(Oe);const a=[...e];for(let o=0;o<t;o++){const l=a[o];if(!(l instanceof U))return;o%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const u=r.getParent();return u==null||u.replaceChild(r,s),s}_getTopParent(r){let e=r;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(r,e){const t=r.getChildren(),s=t.length,i=[];let a=null;const u=r.getToken().trim().toUpperCase();if(u===ss){const f=this._changeLetToLambda(r);return f!=null?this._parse(f,e):W.create(c.ERROR)}if(u===pe){if(a=e,s===0)return new Ca(Re).setParent(e),a}else{if(u===Oe){let f=this._lambdaParameterHandler(r,e);return f===!1&&(f=W.create(c.ERROR)),f}if(a=this._checkAstNode(r),a==null)return W.create(c.ERROR)}const o=t[0];for(let f=0;f<s;f++){const m=t[f];if(Mn(o)){if(f!==0&&f!==s-1)continue}else if(ma(m)&&f!==s-1)continue;let g=null;if(m instanceof U){if(g=this._parse(m,a),g===a)continue}else g=this._checkAstNode(m);if(g==null)return W.create(c.NAME);if(g=this._getTopParent(g),g==null)return;switch(g.nodeType){case M.ERROR:return g;case M.FUNCTION:i.push(g);break;case M.LAMBDA:i.push(g);break;case M.LAMBDA_PARAMETER:i.push(g);break;case M.OPERATOR:{const R=i.pop(),w=i.pop();if(w)w.setParent(g);else return W.create(c.ERROR);if(R)R.setParent(g);else return W.create(c.ERROR);i.push(g);break}case M.REFERENCE:g.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(g);break;case M.ROOT:i.push(g);break;case M.UNION:i.push(g);break;case M.VALUE:i.push(g);break;case M.PREFIX:i.push(g);break;case M.SUFFIX:i.push(g);break}}const l=i.length;for(let f=0;f<l;f++)i[f].setParent(a);return a}_checkAstNode(r){let e=null;const t=this._astNodeFactoryList.length;for(let s=0;s<t&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(r),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(d.sortRules)}};ze=Ya([ie(0,se),ie(1,B.Inject(vn)),ie(2,B.Inject(pt)),ie(3,B.Inject(Dt)),ie(4,B.Inject(kn)),ie(5,B.Inject(yt)),ie(6,B.Inject(_t)),ie(7,B.Inject(St)),ie(8,B.Inject(Lt)),ie(9,B.Inject(At)),ie(10,B.Inject(Qn))],ze);class Yn extends d.Disposable{constructor(){super(...arguments);p(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pt=B.createIdentifier("univer.formula.feature-calculation-manager.service");class Hn extends d.Disposable{constructor(){super(...arguments);p(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,u,o;const{unitId:t,subUnitId:s,formulaId:i}=e;(o=(u=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:u[s])==null||delete o[i]}get(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return(u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i]}has(e){var a,u;const{unitId:t,subUnitId:s,formulaId:i}=e;return((u=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:u[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]&&(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const fr=B.createIdentifier("univer.formula.other-formula-manager.service");class hr extends d.Disposable{constructor(){super(...arguments);p(this,"node");p(this,"children",[]);p(this,"parents",[]);p(this,"formula","");p(this,"row",-1);p(this,"column",-1);p(this,"rowCount",Number.NEGATIVE_INFINITY);p(this,"columnCount",Number.NEGATIVE_INFINITY);p(this,"subUnitId","");p(this,"unitId","");p(this,"rangeList",[]);p(this,"formulaId");p(this,"featureId");p(this,"getDirtyData");p(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let u=0,o=this.rangeList.length;u<o;u++){const l=this.rangeList[u],{unitId:f,sheetId:m,range:g}=l;if(((i=t[f])==null?void 0:i[m])!=null)return!0;if(!e.has(f))continue;const R=e.get(f);if(!R.has(m))continue;const w=R.get(m),E=(a=s==null?void 0:s[f])==null?void 0:a[m];let{startRow:C,endRow:y,startColumn:S,endColumn:L}=g;isNaN(C)&&(C=0),isNaN(S)&&(S=0),isNaN(y)&&(y=Number.POSITIVE_INFINITY),isNaN(L)&&(L=Number.POSITIVE_INFINITY);for(const V of w){const{startRow:I,startColumn:Q,endRow:T,endColumn:x}=V;if(!(C>T||y<I||S>x||L<Q)){let v=!0;if(E==null||E.forValue(($,k)=>{if($>=C&&$<=y&&k>=S&&k<=L)return v=!1,!1}),v)return!0}}}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let t=0,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.unitId,u=i.sheetId,o=i.range;if(e.unitId===a&&e.subUnitId===u&&e.inRangeData(o))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Ha=Object.defineProperty,ja=Object.getOwnPropertyDescriptor,Wa=(n,r,e,t)=>{for(var s=t>1?void 0:t?ja(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ha(r,e,s),s},Be=(n,r)=>(e,t)=>r(e,t,n);const Xa=1e5,mr=new rt(Xa);let Ze=class extends d.Disposable{constructor(r,e,t,s,i,a,u){super();p(this,"_updateRangeFlattenCache",new Map);p(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=r,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=u}dispose(){this._updateRangeFlattenCache.clear(),mr.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const r=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),s=await this._generateTreeList(r,e,t),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(i);return Promise.resolve(u)}_isCyclicUtil(r,e,t){if(!e.has(r)){e.add(r),t.add(r);for(let s=0;s<r.children.length;s++)if(!e.has(r.children[s])&&this._isCyclicUtil(r.children[s],e,t)||t.has(r.children[s]))return!0}return t.delete(r),!1}_checkIsCycleDependency(r){const e=new Set,t=new Set;for(let s=0,i=r.length;s<i;s++){const a=r[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(r,e,t){const s=Object.keys(r),i=Object.keys(e),a=[];for(const u of s){const o=r[u];if(o==null)continue;const l=Object.keys(o);for(const f of l)new d.ObjectMatrix(o[f]).forValue((g,R,w)=>{if(w==null)return!0;const{f:E,x:C,y}=w,S=this._generateAstNode(E,C,y),L=new hr,V=t[u][f];L.node=S,L.formula=E,L.unitId=u,L.subUnitId=f,L.row=g,L.column=R,L.rowCount=V.rowCount,L.columnCount=V.columnCount,a.push(L)})}for(const u of i){const o=e[u];if(o==null)continue;const l=Object.keys(o);for(const f of l){const m=o[f];if(m==null)continue;const g=Object.keys(m);for(const R of g){const w=m[R],{f:E}=w,C=this._generateAstNode(E),y=new hr;y.node=C,y.formula=E,y.unitId=u,y.subUnitId=f,y.formulaId=R,a.push(y)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,o)=>{const{unitId:l,subUnitId:f,dependencyRanges:m,getDirtyData:g}=u,R=new hr;R.unitId=l,R.subUnitId=f,R.getDirtyData=g,R.featureId=o,R.rangeList=m,a.push(R)});for(let u=0,o=a.length;u<o;u++){const l=a[u];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const f=await this._getRangeListByNode(l.node);for(let m=0,g=f.length;m<g;m++)l.pushRangeList(f[m])}return a}_updateRangeFlatten(){const r=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!r){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,u=s.unitId;this._addFlattenCache(u,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(r,e=0,t=0){let s=mr.get(`${r}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(r);if(i in c)return W.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return mr.set(`${r}##${e}${t}`,s),s}_addFlattenCache(r,e,t){let s=this._updateRangeFlattenCache.get(r);s==null&&(s=new Map,this._updateRangeFlattenCache.set(r,s));let i=s.get(e);i==null&&(i=[],s.set(e,i)),i.push(t)}_isPreCalculateNode(r){return r.nodeType===M.UNION||r.nodeType===M.PREFIX&&r.getToken()===Y.AT||r.nodeType===M.SUFFIX&&r.getToken()===he.POUND}_nodeTraversalRef(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===M.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(r,e){const t=r.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.nodeType===M.FUNCTION&&a.isAddress()){e.push(a);continue}this._nodeTraversalReferenceFunction(a,e)}}async _executeNode(r){let e;return this._interpreter.checkAsyncNode(r)?e=await this._interpreter.executeAsync(r):e=this._interpreter.execute(r),e}async _getRangeListByNode(r){const e=[],t=[];this._nodeTraversalRef(r,e),this._nodeTraversalReferenceFunction(r,t);const s=[];for(let i=0,a=e.length;i<a;i++){const u=e[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}for(let i=0,a=t.length;i<a;i++){const u=t[i],l=(await this._executeNode(u)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(r){const e=[],t=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=r.length;i<a;i++){const u=r[i];for(let o=0,l=r.length;o<l;o++){const f=r[o];u!==f&&u.dependency(f)&&u.pushChildren(f)}(s||u.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(u))&&!t.has(u)&&(e.push(u),t.add(u))}return e}_includeTree(r){var l,f,m,g,R;const e=r.unitId,t=r.subUnitId,s=r.featureId;if(s!=null){const w=this._currentConfigService.getDirtyUnitFeatureMap();if(((f=(l=w==null?void 0:w[e])==null?void 0:l[t])==null?void 0:f[s])!=null)return!0}const i=(g=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:g[t];let a=!1;if(i==null||i.forValue((w,E)=>{if(r.row===w&&r.column===E)return a=!0,!1}),a)return!1;if(((R=this._dirtyUnitSheetNameMap[e])==null?void 0:R[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const u=this._updateRangeFlattenCache.get(e);if(!u.has(t))return!1;const o=u.get(t);for(const w of o)if(r.inRangeData(w))return!0;return!1}_calculateRunList(r){let e=r;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,u=s.parents.length;a<u;a++){const o=s.parents[a];i.push(o)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};Ze=Wa([d.OnLifecycle(d.LifecycleStages.Rendered,Ze),Be(0,xe),Be(1,se),Be(2,fr),Be(3,Pt),Be(4,B.Inject(Qe)),Be(5,B.Inject(ze)),Be(6,B.Inject(ve))],Ze);var Ga=Object.defineProperty,Ka=Object.getOwnPropertyDescriptor,qa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ka(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ga(r,e,s),s},Ue=(n,r)=>(e,t)=>r(e,t,n);const za=1;D.CalculateFormulaService=class extends d.Disposable{constructor(e,t,s,i,a,u,o){super();p(this,"_executionStartListener$",new Ft.Subject);p(this,"executionStartListener$",this._executionStartListener$.asObservable());p(this,"_executionCompleteListener$",new Ft.Subject);p(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());p(this,"_executionInProgressListener$",new Ft.Subject);p(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=u,this._astTreeBuilder=o}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,t){this._runtimeService.setRuntimeFeatureCellData(e,t)}setRuntimeFeatureRange(e,t){this._runtimeService.setRuntimeFeatureRange(e,t)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const t=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||za;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(oe.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),tr.clear(),Ee.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:t,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(t,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,t){const s=[],i={};return Object.keys(e).forEach(a=>{const u=e[a];if(u==null)return!0;Object.keys(u).forEach(o=>{const l=new d.ObjectMatrix(u[o]);if(l==null)return!0;const f=new d.ObjectMatrix;l.forValue((m,g,R)=>{f.setValue(m,g,!0),s.push({unitId:a,sheetId:o,range:R})}),i[a]==null&&(i[a]={}),i[a][o]=f})}),Object.keys(t).forEach(a=>{const u=t[a];Object.keys(u).forEach(o=>{const l=u[o];if(l==null)return!0;Object.keys(l).forEach(f=>{const m=l[f];if(m==null)return!0;for(const g of m)s.push({unitId:o,sheetId:f,range:g})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(oe.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(oe.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(oe.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(t.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=t.length;i<a;i++){if(await new Promise(m=>{d.requestImmediateMacroTask(m)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage(oe.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const u=t[i],o=u.node,l=u.getDirtyData;let f;if(o==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(u.row,u.column,u.rowCount,u.columnCount,u.subUnitId,u.unitId),l!=null&&u.featureId!=null){const{runtimeCellData:m,dirtyRanges:g}=l(u);this._runtimeService.setRuntimeFeatureCellData(u.featureId,m),this._runtimeService.setRuntimeFeatureRange(u.featureId,g)}else o!=null&&(s.checkAsyncNode(o)?f=await s.executeAsync(o):f=s.execute(o),u.formulaId!=null?this._runtimeService.setRuntimeOtherData(u.formulaId,f):this._runtimeService.setRuntimeData(f));e?(this._runtimeService.setFormulaExecuteStage(oe.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(oe.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return t.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,t=!0){const s=this._lexer.treeBuilder(e,t);if(Object.values(c).includes(s))return W.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}},D.CalculateFormulaService=qa([d.OnLifecycle(d.LifecycleStages.Rendered,D.CalculateFormulaService),Ue(0,d.IConfigService),Ue(1,B.Inject(ve)),Ue(2,xe),Ue(3,se),Ue(4,B.Inject(Ze)),Ue(5,B.Inject(Qe)),Ue(6,B.Inject(ze))],D.CalculateFormulaService);const gr={id:"formula.mutation.set-numfmt-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(D.FormulaDataModel).updateNumfmtItemMap(r.numfmtItemMap),!0)};var Za=Object.defineProperty,Ja=Object.getOwnPropertyDescriptor,Na=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ja(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Za(r,e,s),s},Vt=(n,r)=>(e,t)=>r(e,t,n);let xt=class extends d.Disposable{constructor(n,r,e,t){super(),this._commandService=n,this._calculateFormulaService=r,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===Gt.id)this._calculateFormulaService.stopFormulaExecution();else if(n.id===qt.id){const e=n.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(n.id===Xt.id){const e=n.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:s,dirtyUnitFeatureMap:i,numfmtItemMap:a}=e;this._calculate(!1,t,s,i,a)}}else if(n.id===at.id){const e=n.params;if(e==null)return;const{arrayFormulaRange:t,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(t),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(n=!1,r=[],e={},t={},s={}){if(r.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&n===!1)return;const i=this._formulaDataModel.getFormulaData(),a=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:i,arrayFormulaCellData:a,forceCalculate:n,dirtyRanges:r,dirtyNameMap:e,dirtyUnitFeatureMap:t,numfmtItemMap:s})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(n=>{const r=n.functionsExecutedState;switch(r){case Te.NOT_EXECUTED:break;case Te.STOP_EXECUTION:break;case Te.SUCCESS:this._applyFormula(n);break;case Te.INITIAL:break}this._commandService.executeCommand(lt.id,{functionsExecutedState:r},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(n=>{this._commandService.executeCommand(lt.id,{stageInfo:n},{onlyLocal:!0})})}async _applyFormula(n){const{unitData:r,unitOtherData:e,arrayFormulaRange:t,arrayFormulaCellData:s,clearArrayFormulaCellData:i,numfmtItemMap:a}=n;if(!r){console.error("No sheetData from Formula Engine!");return}t&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(t),this._commandService.executeCommand(at.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),d.Tools.isEmptyObject(a)||this._commandService.executeCommand(gr.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Kt.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};xt=Na([d.OnLifecycle(d.LifecycleStages.Ready,xt),Vt(0,d.ICommandService),Vt(1,B.Inject(D.CalculateFormulaService)),Vt(2,d.IUniverInstanceService),Vt(3,B.Inject(D.FormulaDataModel))],xt);var eu=Object.defineProperty,tu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var s=t>1?void 0:t?tu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&eu(r,e,s),s},dr=(n,r)=>(e,t)=>r(e,t,n);let Je=class extends d.Disposable{constructor(n=[],r,e,t){super(),this._function=n,this._commandService=r,this._injector=e,this._functionService=t,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[qt,at,Xt,Gt,lt,Kt,gr,ut,ot,jt,Wt,zt,Zt,Fr,$r,Jt,$t,Nt].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_registerFunctions(){const n=[...Nr,...sn,...an,...on,...cn,...fn,...mn,...dn,...Rn,...Cn,...yn,...bn,...Ln,...An,...Pn,...Vn].concat(this._function).map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...n)}};Je=ru([d.OnLifecycle(d.LifecycleStages.Ready,Je),dr(1,d.ICommandService),dr(2,B.Inject(B.Injector)),dr(3,ge)],Je);var nu=Object.defineProperty,su=Object.getOwnPropertyDescriptor,iu=(n,r,e,t)=>{for(var s=t>1?void 0:t?su(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&nu(r,e,s),s},Rr=(n,r)=>(e,t)=>r(e,t,n);let vt=class extends d.Disposable{constructor(n,r,e){super(),this._commandService=n,this._formulaDataModel=r,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((n,r)=>{if(n.id===$t.id){const e=n.params;if(e==null)return;const{functions:t}=e,s=t.map(i=>{const a=i[0],u=i[1];return uu(a,u)});this._functionService.registerExecutors(...s)}else if(n.id===Nt.id){const e=n.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};vt=iu([d.OnLifecycle(d.LifecycleStages.Ready,vt),Rr(0,d.ICommandService),Rr(1,B.Inject(D.FormulaDataModel)),Rr(2,ge)],vt);class au extends A{isCustom(){return!0}}function uu(n,r){const e=new au(r),t=new Function(`return ${n}`)();return e.calculateCustom=t,e}var ou=Object.defineProperty,lu=Object.getOwnPropertyDescriptor,cu=(n,r,e,t)=>{for(var s=t>1?void 0:t?lu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ou(r,e,s),s},jn=(n,r)=>(e,t)=>r(e,t,n);let Bt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._definedNamesService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,name:t,formulaOrRefString:s}=r;this._definedNamesService.registerDefinedName(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};Bt=cu([d.OnLifecycle(d.LifecycleStages.Ready,Bt),jn(0,d.ICommandService),jn(1,Et)],Bt);var fu=Object.defineProperty,hu=Object.getOwnPropertyDescriptor,mu=(n,r,e,t)=>{for(var s=t>1?void 0:t?hu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&fu(r,e,s),s},Wn=(n,r)=>(e,t)=>r(e,t,n);let Ut=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._featureCalculationManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===jt.id){const r=n.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(n.id===Wt.id){const r=n.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};Ut=mu([d.OnLifecycle(d.LifecycleStages.Ready,Ut),Wn(0,d.ICommandService),Wn(1,Pt)],Ut);var gu=Object.defineProperty,du=Object.getOwnPropertyDescriptor,Ru=(n,r,e,t)=>{for(var s=t>1?void 0:t?du(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&gu(r,e,s),s},Xn=(n,r)=>(e,t)=>r(e,t,n);let Mt=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._otherFormulaManagerService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===zt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(n.id===Zt.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};Mt=Ru([d.OnLifecycle(d.LifecycleStages.Ready,Mt),Xn(0,d.ICommandService),Xn(1,fr)],Mt);var Eu=Object.defineProperty,wu=Object.getOwnPropertyDescriptor,_u=(n,r,e,t)=>{for(var s=t>1?void 0:t?wu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Eu(r,e,s),s},Gn=(n,r)=>(e,t)=>r(e,t,n);let Ot=class extends d.Disposable{constructor(n,r){super(),this._commandService=n,this._superTableService=r,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===ut.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t,reference:s}=r;this._superTableService.registerTable(e,t,s)}else if(n.id===ot.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(n.id===Jt.id){const r=n.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};Ot=_u([d.OnLifecycle(d.LifecycleStages.Ready,Ot),Gn(0,d.ICommandService),Gn(1,cr)],Ot);var Cu=Object.defineProperty,pu=Object.getOwnPropertyDescriptor,Du=(n,r,e,t)=>{for(var s=t>1?void 0:t?pu(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Cu(r,e,s),s},yu=(n,r)=>(e,t)=>r(e,t,n);const bu="base-formula-engine";D.UniverFormulaEnginePlugin=class extends d.Plugin{constructor(r,e){super(bu),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[ge,{useClass:Bn}],[Pt,{useClass:Yn}],[Et,{useClass:ji}],[D.FormulaDataModel],[it],[Je,{useFactory:()=>{var t;return this._injector.createInstance(Je,(t=this._config)==null?void 0:t.function)}}],[Ut]];(e=this._config)!=null&&e.notExecuteFormula||r.push([D.CalculateFormulaService],[fr,{useClass:Hn}],[cr,{useClass:La}],[xe,{useClass:ar}],[se,{useClass:ur}],[xt],[Bt],[Mt],[Ot],[vt],[Ze],[Qe],[ze],[ve],[vn],[pt],[Dt],[kn],[yt],[_t],[St],[Lt],[At],[Qn]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(D.FormulaDataModel).initFormulaData()}},D.UniverFormulaEnginePlugin=Du([yu(1,B.Inject(B.Injector))],D.UniverFormulaEnginePlugin),D.ArrayValueObject=z,D.BaseFunction=A,D.BaseReferenceObject=ke,D.BaseValueObject=we,D.BooleanValueObject=P,D.ErrorType=c,D.ErrorValueObject=h,D.FUNCTION_NAMES_ARRAY=Ms,D.FUNCTION_NAMES_COMPATIBILITY=Ie,D.FUNCTION_NAMES_CUBE=un,D.FUNCTION_NAMES_DATABASE=ln,D.FUNCTION_NAMES_DATE=Ce,D.FUNCTION_NAMES_ENGINEERING=hn,D.FUNCTION_NAMES_FINANCIAL=gn,D.FUNCTION_NAMES_INFORMATION=ne,D.FUNCTION_NAMES_LOGICAL=Ve,D.FUNCTION_NAMES_LOOKUP=G,D.FUNCTION_NAMES_MATH=N,D.FUNCTION_NAMES_STATISTICAL=K,D.FUNCTION_NAMES_TEXT=Rt,D.FUNCTION_NAMES_UNIVER=Hi,D.FUNCTION_NAMES_WEB=xn,D.FeatureCalculationManagerService=Yn,D.FormulaExecuteStageType=oe,D.FormulaExecutedStateType=Te,D.FunctionService=Bn,D.FunctionType=wr,D.IFeatureCalculationManagerService=Pt,D.IFunctionService=ge,D.LexerNode=U,D.LexerTreeBuilder=it,D.NumberValueObject=_,D.OtherFormulaManagerService=Hn,D.RangeReferenceObject=Ke,D.RegisterFunctionMutation=$t,D.RemoveDefinedNameMutation=ot,D.RemoveFeatureCalculationMutation=Wt,D.RemoveOtherFormulaMutation=Zt,D.RemoveSuperTableMutation=$r,D.SetArrayFormulaDataMutation=at,D.SetArrayFormulaDataUndoMutationFactory=gs,D.SetDefinedNameMutation=ut,D.SetFeatureCalculationMutation=jt,D.SetFormulaCalculationNotificationMutation=lt,D.SetFormulaCalculationResultMutation=Kt,D.SetFormulaCalculationStartMutation=Xt,D.SetFormulaCalculationStopMutation=Gt,D.SetFormulaDataMutation=qt,D.SetNumfmtFormulaDataMutation=gr,D.SetOtherFormulaMutation=zt,D.SetSuperTableMutation=Fr,D.SetSuperTableOptionMutation=Jt,D.StringValueObject=X,D.UnregisterFunctionMutation=Nt,D.ValueObjectFactory=_e,D.compareToken=b,D.convertUnitDataToRuntime=pr,D.deserializeRangeForR1C1=Jr,D.deserializeRangeWithSheet=Fe,D.functionArray=Nr,D.functionCompatibility=sn,D.functionCube=an,D.functionDatabase=on,D.functionDate=cn,D.functionEngineering=fn,D.functionFinancial=mn,D.functionInformation=dn,D.functionLogical=Rn,D.functionLookup=Cn,D.functionMath=yn,D.functionMeta=bn,D.functionStatistical=Ln,D.functionText=An,D.functionUniver=Pn,D.functionWeb=Vn,D.generateStringWithSequence=Br,D.getAbsoluteRefTypeWitString=us,D.getAbsoluteRefTypeWithSingleString=Xe,D.includeFormulaLexerToken=Cr,D.initSheetFormulaData=Or,D.isFormulaLexerToken=tt,D.isInDirtyRange=Er,D.isReferenceString=Sr,D.matchToken=O,D.normalizeSheetName=Jn,D.operatorToken=J,D.sequenceNodeType=te,D.serializeRange=De,D.serializeRangeToRefString=xr,D.serializeRangeWithSheet=Pr,D.serializeRangeWithSpreadsheet=Vr,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(L,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","rxjs"],_):(L=typeof globalThis<"u"?globalThis:L||self,_(L.UniverEngineFormula={},L.UniverCore,L["@wendellhu/redi"],L.rxjs))})(this,function(L,_,Z,vr){"use strict";var Dl=Object.defineProperty;var yl=(L,_,Z)=>_ in L?Dl(L,_,{enumerable:!0,configurable:!0,writable:!0,value:Z}):L[_]=Z;var S=(L,_,Z)=>(yl(L,typeof _!="symbol"?_+"":_,Z),Z);function En(r,n,e,t,s){for(let i=0,a=r.length;i<a;i++){const o=r[i];if(n!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:c,endColumn:m}=o.range;if(t>=u&&t<=c&&s>=l&&s<=m)return!0}return!1}var f=(r=>(r.DIV_BY_ZERO="#DIV/0!",r.NAME="#NAME?",r.VALUE="#VALUE!",r.NUM="#NUM!",r.NA="#N/A",r.CYCLE="#CYCLE!",r.REF="#REF!",r.SPILL="#SPILL!",r.CALC="#CALC!",r.ERROR="#ERROR!",r.CONNECT="#GETTING_DATA",r.NULL="#NULL!",r))(f||{});const Mt=new Set(Object.values(f));var Cn=(r=>(r[r.Financial=0]="Financial",r[r.Date=1]="Date",r[r.Math=2]="Math",r[r.Statistical=3]="Statistical",r[r.Lookup=4]="Lookup",r[r.Database=5]="Database",r[r.Text=6]="Text",r[r.Logical=7]="Logical",r[r.Information=8]="Information",r[r.Engineering=9]="Engineering",r[r.Cube=10]="Cube",r[r.Compatibility=11]="Compatibility",r[r.Web=12]="Web",r[r.Array=13]="Array",r[r.Univer=14]="Univer",r[r.User=15]="User",r))(Cn||{}),pe=(r=>(r.PLUS="+",r.MINUS="-",r.MULTIPLY="*",r.DIVIDED="/",r.CONCATENATE="&",r.POWER="^",r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(pe||{}),O=(r=>(r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(O||{});const Kt=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),ot=new Set(Kt.keys()),hi=new Set(["=","<>",">",">=","<","<="]);var X=(r=>(r.OPEN_BRACKET="(",r.CLOSE_BRACKET=")",r.COMMA=",",r.SINGLE_QUOTATION="'",r.DOUBLE_QUOTATION='"',r.OPEN_BRACES="{",r.CLOSE_BRACES="}",r.COLON=":",r.OPEN_SQUARE_BRACKET="[",r.CLOSE_SQUARE_BRACKET="]",r))(X||{}),Xe=(r=>(r.PERCENTAGE="%",r.POUND="#",r))(Xe||{});const mi=new Set(["%","#"]);var _e=(r=>(r.AT="@",r.MINUS="-",r))(_e||{});const di=" ",Dn=[...Object.values(O),...Object.values(pe),...Object.values(X),...Object.values(Xe),...Object.values(_e)];function Ft(r){return Dn.includes(r)}function yn(r){for(const n of Dn)if(r.indexOf(n)>-1)return!0;return!1}function gi(r){return r[0]==="'"&&r[r.length-1]==="'"?r.substring(1,r.length-1):r}function pi(r){return Ft(r)&&r!==X.CLOSE_BRACES&&r!==X.CLOSE_BRACKET&&r!==X.SINGLE_QUOTATION&&r!==X.DOUBLE_QUOTATION||r===" "}function bn(r){const n={};return Object.keys(r).forEach(e=>{const t=r[e];if(t==null)return!0;n[e]==null&&(n[e]={}),Object.keys(t).forEach(s=>{const i=t[s];n[e][s]=new _.ObjectMatrix(i)})}),n}function Ri(r){const n={};return Object.keys(r).forEach(e=>{const t=r[e];if(t==null)return!0;n[e]==null&&(n[e]={}),Object.keys(t).forEach(s=>{const i=t[s];n[e][s]=i.getData()})}),n}const Mr={id:"formula.mutation.register-function",type:_.CommandType.MUTATION,handler:()=>!0};class ut{constructor(n){S(this,"_cache");this._cache=new _.LRUMap(n)}set(n,e){const t=this._hash(n);this._cache.set(t,e)}get(n){const e=this._hash(n);return this._cache.get(e)}clear(){this._cache.clear()}_hash(n){return _.hashAlgorithm(n)}}const Fr='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',_i="((?![\\[\\]\\/?*\\\\]).)*!",Ne="$",Br="\\s*?:\\s*?",Ct=`'?(${Fr})?(${_i})?'?`,Or=`\\${Ne}?[A-Za-z]+\\${Ne}?[0-9]+`,Ei=`^(${_e.AT})?${Ct}${Or}${Br}${Or}$`,Bt=`^${Ct}\\s*?${Or}(${Xe.POUND})?$`,Sn=`^${Ct}\\${Ne}?[0-9]+${Br}\\${Ne}?[0-9]+$`,Ln=`^${Ct}\\${Ne}?[A-Za-z]+${Br}\\${Ne}?[A-Za-z]+$`,An=`^${Ct}\\s*?\\${Ne}?[0-9]+$`,wn=`^${Ct}\\s*?\\${Ne}?[A-Za-z]+$`,Pn="[.*?]",Ci="{.*?}";function Vn(r){return new RegExp(Bt).test(r)||new RegExp(Ei).test(r)||new RegExp(Sn).test(r)||new RegExp(Ln).test(r)}const Ke="P_1",et="R_1",Dt="L_1",Ot="LR_1",xn="LO_1",Di="LET",Ut="LAMBDA",yi="CUBE",bi=/[^0-9]/g,Si=/[^A-Za-z]/g;function kt(r){const n=r[0]==="$",t=r.substring(1).indexOf("$")>-1;return n&&t?_.AbsoluteRefType.ALL:n?_.AbsoluteRefType.COLUMN:t?_.AbsoluteRefType.ROW:_.AbsoluteRefType.NONE}function Li(r){const n=r.split("!");n.length>1&&(r=n[n.length-1]);const e=r.split(":");return e.length>1?{startAbsoluteRefType:kt(e[0]),endAbsoluteRefType:kt(e[1])}:{startAbsoluteRefType:kt(e[0])}}function vn(r=_.AbsoluteRefType.NONE){let n="",e="";return r===_.AbsoluteRefType.ROW?n="$":r===_.AbsoluteRefType.COLUMN?e="$":r===_.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function lt(r){const{startColumn:n,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=_.RANGE_TYPE.NORMAL}=r,u=vn(i),l=vn(a);if(o===_.RANGE_TYPE.ROW||o===_.RANGE_TYPE.ALL){const d=`${u.rowAbsoluteString}${e+1}`,E=`${l.rowAbsoluteString}${s+1}`;return`${d}:${E}`}if(o===_.RANGE_TYPE.COLUMN){const d=`${u.columnAbsoluteString}${_.Tools.chatAtABC(n)}`,E=`${l.columnAbsoluteString}${_.Tools.chatAtABC(t)}`;return`${d}:${E}`}const c=`${u.columnAbsoluteString}${_.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${_.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return c===m?c:`${c}:${m}`}function Mn(r,n){return qt(r)?`'${r}'!${lt(n)}`:`${r}!${lt(n)}`}function Fn(r,n,e){return qt(r)||qt(n)?`'[${r}]${n}'!${lt(e)}`:`[${r}]${n}!${lt(e)}`}function yt(r){const{unitId:n,sheetName:e,range:t}=r;return n!=null&&n.length>0&&e!=null&&e.length>0?Fn(n,e,t):e!=null&&e.length>0?Mn(e,t):lt(t)}function Ur(r){const n=Number.parseInt(r.replace(bi,""))-1,e=_.Tools.ABCatNum(r.replace(Si,"")),t=kt(r);return{row:n,column:e,absoluteRefType:t}}function Bn(r){const n=new RegExp(Fr).exec(r);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),r=r.replace(new RegExp(Fr),""));const t=r.indexOf("!");let s="",i="";return t>-1?(s=r.substring(0,t),s[0]==="'"&&s[s.length-1]==="'"&&(s=s.substring(1,s.length-1)),i=r.substring(t)):i=r,{refBody:i,sheetName:s,unitId:e}}function bt(r){const{refBody:n,sheetName:e,unitId:t}=Bn(r),s=n.indexOf(":");if(s===-1){const D=Ur(n),C=D.row,A=D.column,P=D.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:C,startColumn:A,endRow:C,endColumn:A,startAbsoluteRefType:P,endAbsoluteRefType:P}}}const i=n.substring(0,s),a=n.substring(s+1),o=Ur(i),u=Ur(a),l=o.row,c=o.column,m=u.row,d=u.column;let E=_.RANGE_TYPE.NORMAL;return Number.isNaN(l)&&Number.isNaN(m)?E=_.RANGE_TYPE.COLUMN:Number.isNaN(c)&&Number.isNaN(d)&&(E=_.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:l,startColumn:c,endRow:m,endColumn:d,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:E}}}function qt(r){return r.length===0?!1:!!(yn(r)||Ai(r)||wi(r)||Pi(r)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(r))}function Ai(r){const n=r.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(r)&&n!==null}function wi(r){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(r)}function Pi(r){return!new RegExp("^\\p{Letter}","u").test(r.charAt(0))}var ve=(r=>(r[r.NORMAL=0]="NORMAL",r[r.NUMBER=1]="NUMBER",r[r.STRING=2]="STRING",r[r.FUNCTION=3]="FUNCTION",r[r.REFERENCE=4]="REFERENCE",r[r.ARRAY=5]="ARRAY",r))(ve||{});function On(r){let n="";for(const e of r)typeof e=="string"?n+=e:n+=e.token;return n}class ee{constructor(){S(this,"_parent");S(this,"_token",et);S(this,"_children",[]);S(this,"_lambdaId");S(this,"_functionDefinitionPrivacyVar");S(this,"_lambdaParameter","");S(this,"_startIndex",-1);S(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 t=this._getIndexInParent(n);t!=null&&(this.getChildren().splice(t,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(),t=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof ee?t.push(a.serialize()):t.push(a)}return{token:n,st:this._startIndex,ed:this._endIndex,children:t}}_getIndexInParent(n){const e=this.getChildren(),t=e.length;for(let s=0;s<t;s++)if(e[s]===n)return s}}const Un=1e5,kr=new ut(Un),Tr=new ut(Un);class Zt extends _.Disposable{constructor(){super(...arguments);S(this,"_currentLexerNode",new ee);S(this,"_upLevel",0);S(this,"_segment","");S(this,"_bracketState",[]);S(this,"_squareBracketState",0);S(this,"_bracesState",0);S(this,"_singleQuotationState",0);S(this,"_doubleQuotationState",0);S(this,"_lambdaState",!1);S(this,"_colonState",!1);S(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),kr.clear(),Tr.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const s=this._getCurrentParamIndex(e,t);if(s==null||s===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!==Ke&&!Ft(u)&&a.getStartIndex()!==-1){const l=a.getChildren().indexOf(o);return{functionName:u,paramIndex:l}}o=a,a=a.getParent()}}moveFormulaRefOffset(e,t,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!==ve.REFERENCE){a.push(l);continue}const{token:c}=l,m=bt(c),{range:d,sheetName:E,unitId:D}=m,C=_.Rectangle.moveOffset(d,t,s);let A="";_.isValidRange(C)?A=yt({range:C,unitId:D,sheetName:E}):A=f.REF,a.push({...l,token:A})}return`=${On(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===X.CLOSE_BRACKET||i===" ")&&s>=0;)i===X.CLOSE_BRACKET&&t++,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(a[1]===X.OPEN_BRACKET&&l++;u;){const c=u.getToken();c!==Ke&&c!==X.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==Ut&&(t===0?l+=1:t--),u=u.getParent()}return l}sequenceNodesBuilder(e){const t=Tr.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Tr.set(e,[...i]),i}getSequenceNode(e){const t=[];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}=o;if(c===X.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(c);continue}let m=(u==null?void 0:u.segment)||"",d=i-m.length,E=i-1,D=i-1;if(i===a-1&&this._isLastMergeString(c)&&(m+=c,E+=1),m===""||Kt.has(m)){t.push(c);continue}const C=m.trim(),A=this._replacePrefixString(C);if(s===!0&&C[C.length-1]===X.DOUBLE_QUOTATION)s=!1,this._pushSequenceNode(t,{nodeType:ve.STRING,token:m,startIndex:d,endIndex:E},D);else if(new RegExp(Bt).test(A)){if(A.length!==C.length){const P=C.length-A.length;D+=P,d+=P,m=this._replacePrefixString(m)}this._pushSequenceNode(t,{nodeType:ve.REFERENCE,token:m,startIndex:d,endIndex:E},D)}else _.Tools.isStringNumber(C)?this._pushSequenceNode(t,{nodeType:ve.NUMBER,token:m,startIndex:d,endIndex:E},D):C.length>0&&this._pushSequenceNode(t,{nodeType:ve.FUNCTION,token:m,startIndex:d,endIndex:E},D);(i!==a-1||!this._isLastMergeString(c))&&t.push(c)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===X.DOUBLE_QUOTATION||_.Tools.isStringNumber(e)||!Ft(e)}_mergeSequenceNodeReference(e){const t=[],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()===X.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===ve.FUNCTION&&o.token.trim().substring(0,1)===X.OPEN_BRACES){o.nodeType=ve.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===X.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&Vn((a.token+o+u.token).trim())&&(a.nodeType=ve.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i];if(o===di&&!s)t.push(o);else{if(!s&&(o===_e.AT||o===_e.MINUS))continue;t.push(o),s=!0}}return t.join("")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const c=kr.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(et);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:m}=s(i);o=c,u=m}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(et),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);if(l&&(this._currentLexerNode=l),t){if(!this._suffixExpressionHandler(this._currentLexerNode))return f.VALUE;kr.set(e,this._currentLexerNode)}return this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const t=e.getChildren();if(!t)return!1;const s=t.length,i=[],a=[];for(let l=0;l<s;l++){const c=t[l];if(c instanceof ee)this._suffixExpressionHandler(c),i.push(c);else{const m=c.trim();if(m==="")continue;if(ot.has(m)){if(m===pe.PLUS&&this._deletePlusForPreNode(t[l-1]))continue;if(m!==pe.PLUS&&m!==pe.MINUS&&this._deletePlusForPreNode(t[l-1]))return!1;for(;a.length>0;){const d=(o=a[a.length-1])==null?void 0:o.trim();if(!d||d===X.OPEN_BRACKET)break;const E=Kt.get(d),D=Kt.get(m);if(!E||!D)break;if(D>=E)i.push(a.pop());else break}a.push(c)}else if(m===X.OPEN_BRACKET)a.push(c);else if(m===X.CLOSE_BRACKET){if(this._checkOpenBracket(t[l-1])||this._checkOperator(t[l-1]))return!1;for(;a.length>0;){const d=(u=a[a.length-1])==null?void 0:u.trim();if(!d)break;if(d===X.OPEN_BRACKET){a.pop();break}i.push(a.pop())}}else{if(this._checkCloseBracket(t[l-1]))return!1;i.push(c)}}}for(;a.length>0;){const l=a.pop();if(l===X.OPEN_BRACKET||l===X.CLOSE_BRACKET)return!1;i.push(l)}return e.setChildren(i),!0}_checkCloseBracket(e){return e===X.CLOSE_BRACKET}_checkOpenBracket(e){return e===X.OPEN_BRACKET}_checkOperator(e){return e==null||e instanceof ee?!1:ot.has(e)}_deletePlusForPreNode(e){if(e==null)return!0;if(!(e instanceof ee)){const t=e.trim();if(ot.has(t)||t===X.OPEN_BRACKET)return!0}return!1}_resetCurrentLexerNode(){this._currentLexerNode=new ee}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_changeCurrentBracket(e){const t=this._bracketState;t[t.length-1]=e}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof ee)return t}return!1}_getLastChildCurrent(){const e=this._currentLexerNode.getChildren();return e&&e.length>0?e[e.length-1]:!1}_setParentCurrentLexerNode(){const e=this._currentLexerNode.getParent();return e?(this._currentLexerNode=e,!0):!1}_setAncestorCurrentLexerNode(){var s,i,a,o,u,l;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===Dt){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const c=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();c&&(this._currentLexerNode=c),t=!0}}else if(e!=null&&e.getParent()){const c=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();c&&(this._currentLexerNode=c),t=!0}for(let c=0;c<this._upLevel;c++){const m=(l=this._currentLexerNode)==null?void 0:l.getParent();m&&(this._currentLexerNode=m),this._currentLexerNode?t=!0:t=!1}return t}_segmentCount(){return this._segment.trim().length}_pushSegment(e){this._segment+=e}_pushNodeToChildren(e,t=!1){if(e!==""){const s=this._currentLexerNode.getChildren();if(!(e instanceof ee)&&this.isColonOpen()){const i=new ee;i.setToken(e),i.setParent(this._currentLexerNode),e=i}t?s.unshift(e):s.push(e)}this.isColonOpen()&&(this._setAncestorCurrentLexerNode(),this._closeColon())}_setCurrentLexerNode(e,t=!1){this._pushNodeToChildren(e,t),e.setParent(this._currentLexerNode),this._currentLexerNode=e}_newAndPushCurrentLexerNode(e,t,s=!1){const i=new ee;i.setToken(e),i.setIndex(t-e.length,t-1),this._setCurrentLexerNode(i,s)}_getTopNode(e){let t=e;for(;t!=null&&t.getParent();)t=t.getParent();return t}_removeLastChild(){this._currentLexerNode.getChildren().splice(-1)}_findPreviousToken(e,t){for(;t>=0;){const s=e[t];if(s!==" ")return s;t--}}_negativeCondition(e){return!!(ot.has(e)||e===X.OPEN_BRACKET||e===X.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new ee,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,t,s){if(e!==Xe.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!Ft(i)}_nodeMaker(e,t,s){e.substring(0,1)===pe.EQUALS&&(e=e.substring(1));let i=!1;e.substring(0,1)===pe.MINUS&&(e=`0${e}`,i=!0);const a=e.split(""),o=a.length;let u=0;for(this._resetTemp();u<o;){const l=a[u];if(s===u)return[this._currentLexerNode,l];if(l===X.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,u),this._resetSegment()),this._openBracket(1),this._closeLambda();const c=a[u+1];if(c&&c===X.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;u++}else c&&this._newAndPushCurrentLexerNode(Ke,u)}else this._pushNodeToChildren(l),this._openBracket(0);else if(l===X.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const c=this._getCurrentBracket();if(c===0)this._pushNodeToChildren(l);else if(c===1){const m=a[u+1];if(m&&m===X.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;this._newAndPushCurrentLexerNode(Dt,u,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&u!==o-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(l===X.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(l),this._openBraces();else if(l===X.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(l),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(l===X.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(l),this._openSquareBracket();else if(l===X.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(l),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(l);else if(l===X.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const c=a[u+1];c&&c===X.DOUBLE_QUOTATION?u++:this._closeDoubleQuotation()}this._pushSegment(l)}else if(l===X.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const c=a[u+1];c&&c===X.SINGLE_QUOTATION?u++:this._closeSingleQuotation()}this._pushSegment(l)}else if(l===X.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=this._getCurrentBracket();if(c===1||c==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&u!==o-1&&c!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Ke,u)}else{const m=new ee;m.setToken(yi);const d=new ee;d.setToken(Ke),d.changeToParent(m);const E=this._currentLexerNode.getParent();if(E&&E.getToken()===X.COLON){const D=E.getParent();if(!D)return f.VALUE;E.changeToParent(d),D.setChildren([]),m.changeToParent(D)}else return f.VALUE;this._changeCurrentBracket(1),this._pushNodeToChildren(this._segment),this._resetSegment(),this._currentLexerNode=m,this._newAndPushCurrentLexerNode(Ke,u)}}else if(l===X.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const c=new ee;c.setToken(l);const m=new ee;m.setToken(Ke),m.setParent(c);const d=new ee;d.setToken(Ke),d.setParent(c),c.getChildren().push(m,d);let E=c,D=0;if(this._segmentCount()>0){let C,A,P=0;const x=this._segment.trim(),U=x[0],$=x[1];if(U===_e.MINUS&&(C=new ee,C.setToken(_e.MINUS),P++),(U===_e.AT||$===_e.AT)&&(A=new ee,A.setToken(_e.AT),C&&(C.addChildren(A),A.setParent(C)),P++),P>0&&(this._segment=x.slice(P)),D=P,A)if(A.addChildren(c),c.setParent(A),A.getParent()){const he=A.getParent();he&&(E=he)}else E=A;else C&&(E=C,C.addChildren(c),c.setParent(C));const se=new ee;se.setToken(this._segment),se.setParent(m),m.getChildren().push(se),this._resetSegment()}else{const C=this._getLastChildCurrentLexerNode();C&&C.changeToParent(m)}this._setCurrentLexerNode(E),this._currentLexerNode=d,this._openColon(D)}else if(mi.has(l)&&this._checkSimilarErrorToken(l,u,a)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const c=new ee;c.setToken(l);const m=this._getLastChildCurrent();m instanceof ee?m.changeToParent(c):m!==!1&&(c.getChildren().push(m),this._removeLastChild()),this._pushNodeToChildren(c),c.setParent(this._currentLexerNode),this._resetSegment()}else if(ot.has(l)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let c=this._segment.trim();if(l===pe.MINUS&&c===""){const m=this._findPreviousToken(a,u-1)||"";if(this._negativeCondition(m)){this._pushSegment(pe.MINUS),i&&u===0||t==null||t.push({segment:this._segment,currentString:l,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}}else if(this._segment.length>0&&a[u-1]&&a[u-1].toUpperCase()==="E"&&(l===pe.MINUS||l===pe.PLUS)){this._pushSegment(l),i&&u===0||t==null||t.push({segment:this._segment,currentString:l,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}else this._segment.length>0&&c===""?c=this._segment:(this._pushNodeToChildren(this._segment),c="");if(l===pe.LESS_THAN||l===pe.GREATER_THAN){const m=a[u+1];m&&ot.has(l+m)?(this._pushNodeToChildren(c+l+m),u++):this._pushNodeToChildren(c+l)}else this._pushNodeToChildren(c+l);this._resetSegment()}else this._pushSegment(l);i&&u===0||t==null||t.push({segment:this._segment,currentString:l,cur:u,currentLexerNode:this._currentLexerNode}),u++}this._pushNodeToChildren(this._segment)}}var Vi=Object.defineProperty,xi=Object.getOwnPropertyDescriptor,vi=(r,n,e,t)=>{for(var s=t>1?void 0:t?xi(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Vi(n,e,s),s},kn=(r,n)=>(e,t)=>n(e,t,r);L.FormulaDataModel=class extends _.Disposable{constructor(e,t){super();S(this,"_formulaData",{});S(this,"_arrayFormulaRange",{});S(this,"_arrayFormulaCellData",{});S(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var l,c,m,d;const a=s[i],o=(c=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:c[i];if(o==null)return!0;let u=new _.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new _.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((E,D)=>{var $;const C=($=o==null?void 0:o[E])==null?void 0:$[D];if(C==null)return!0;const{startRow:A,startColumn:P,endRow:x,endColumn:U}=C;for(let se=A;se<=x;se++)for(let he=P;he<=U;he++)u.setValue(se,he,null)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=u.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(s).forEach(i=>{var l,c,m,d;const a=s[i];let o=new _.ObjectMatrix,u=new _.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(o=new _.ObjectMatrix((c=this._arrayFormulaRange[t])==null?void 0:c[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new _.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((E,D)=>{const C=o==null?void 0:o.getValue(E,D);if(C==null)return!0;const{startRow:A,startColumn:P,endRow:x,endColumn:U}=C;for(let $=A;$<=x;$++)for(let se=P;se<=U;se++)u.setValue($,se,null)}),a.forValue((E,D,C)=>{u.setValue(E,D,C)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=u.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getNumfmtItemMap(){return this._numfmtItemMap}getNumfmtValue(e,t,s,i){var a,o,u;return(u=(o=(a=this._numfmtItemMap[e])==null?void 0:a[t])==null?void 0:o[s])==null?void 0:u[i]}setNumfmtItemMap(e){this._numfmtItemMap=e}updateNumfmtItemMap(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._numfmtItemMap[t]==null&&(this._numfmtItemMap[t]={}),Object.keys(s).forEach(i=>{const a=s[i],o=new _.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),o.forValue((u,l,c)=>{this._numfmtItemMap[t][i][u]==null&&(this._numfmtItemMap[t][i][u]={}),this._numfmtItemMap[t][i][u][l]=c})})})}mergeArrayFormulaRange(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]||(this._arrayFormulaRange[t]={}),Object.keys(s).forEach(i=>{var u,l;const a=new _.ObjectMatrix(s[i]);let o=new _.ObjectMatrix;(u=this._arrayFormulaRange[t])!=null&&u[i]&&(o=new _.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((c,m,d)=>{o.setValue(c,m,d)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=o.getData())})})}deleteArrayFormulaRange(e,t,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(a==null)return;const o=new _.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=o.getData()))}initFormulaData(){if(this._currentUniverService.getAllUniverSheetsInstance().length===0)return;const t=this._currentUniverService.getCurrentUniverSheetInstance(),s=t.getUnitId();this._formulaData[s]={},t.getSheets().forEach(a=>{const o=a.getCellMatrix(),u=a.getSheetId();Tn(this._formulaData,s,u,o)})}getCalculateData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const m=c.getSheetId(),d=c.getConfig();u[m]={cellData:new _.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},l[c.getName()]=c.getSheetId()}t[a]=u,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new _.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const l=u[e];l[t]==null&&(l[t]={});const c=new _.ObjectMatrix(l[t]);i.forValue((m,d,E)=>{const D=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"",A=_.isFormulaString(D),P=_.isFormulaId(C);if(A&&P)c.setValue(m,d,{f:D,si:C}),a.set(C,{f:D,r:m,c:d});else if(A&&!P)c.setValue(m,d,{f:D});else if(!A&&P)c.setValue(m,d,{f:"",si:C});else if(!A&&!P&&c.getValue(m,d)){const x=c.getValue(m,d),U=(x==null?void 0:x.f)||"",$=(x==null?void 0:x.si)||"";_.isFormulaString(U)&&_.isFormulaId($)&&o.set($,U),c.realDeleteValue(m,d)}}),c.forValue((m,d,E)=>{const D=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"";if(_.isFormulaId(C)){const A=a.get(C),P=o.get(C);if(A&&!_.isFormulaString(D)){const x=A.f,U=d-A.c,$=m-A.r;c.setValue(m,d,{f:x,si:C,x:U,y:$})}else if(typeof P=="string"){const x=E.x||0,U=E.y||0,$=this._lexerTreeBuilder.moveFormulaRefOffset(P,x,U);o.set(C,{r:m,c:d,f:$}),c.setValue(m,d,{f:$,si:C})}else if(typeof P=="object"){const x=d-P.c,U=m-P.r;c.setValue(m,d,{f:P.f,si:C,x,y:U})}}})}updateArrayFormulaRange(e,t,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(!i)return;const a=new _.ObjectMatrix(i);new _.ObjectMatrix(s).forValue((l,c,m)=>{if((a==null?void 0:a.getValue(l,c))==null)return!0;const E=(m==null?void 0:m.f)||"",D=(m==null?void 0:m.si)||"",C=_.isFormulaString(E),A=_.isFormulaId(D);!C&&!A&&a.realDeleteValue(l,c)})}updateArrayFormulaCellData(e,t,s){var c,m;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[t];if(!i)return;const a=new _.ObjectMatrix(i),o=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!o)return;const u=new _.ObjectMatrix(o);new _.ObjectMatrix(s).forValue((d,E,D)=>{const C=a==null?void 0:a.getValue(d,E);if(C==null)return!0;const A=(D==null?void 0:D.f)||"",P=(D==null?void 0:D.si)||"",x=_.isFormulaString(A),U=_.isFormulaId(P);if(!x&&!U){const{startRow:$,startColumn:se,endRow:he,endColumn:me}=C;for(let J=$;J<=he;J++)for(let z=se;z<=me;z++)u.realDeleteValue(J,z)}})}updateNumfmtData(e,t,s){var c,m;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[t],a=new _.ObjectMatrix(i),o=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!o)return;const u=new _.ObjectMatrix(o);new _.ObjectMatrix(s).forValue((d,E,D)=>{const C=(D==null?void 0:D.f)||"",A=(D==null?void 0:D.si)||"",P=_.isFormulaString(C),x=_.isFormulaId(A);if(!P&&!x){u.setValue(d,E,null);const U=a.getValue(d,E);if(U){const{startRow:$,startColumn:se,endRow:he,endColumn:me}=U;for(let J=$;J<=he;J++)for(let z=se;z<=me;z++)u.setValue(J,z,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const o=new _.ObjectMatrix(a[t]);let u=null;return o.forValue((l,c,m)=>{const{f:d,si:E,x:D=0,y:C=0}=m;if(E===e&&d.length>0&&D===0&&C===0)return u=m,!1}),u}getFormulaDataItem(e,t,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[t]}getFormulaIdMap(e,t){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[t])==null||new _.ObjectMatrix(a[t]).forValue((u,l,c)=>{const m=(c==null?void 0:c.f)||"",d=(c==null?void 0:c.si)||"",E=(c==null?void 0:c.x)||0,D=(c==null?void 0:c.y)||0;_.isFormulaString(m)&&_.isFormulaId(d)&&E===0&&D===0&&s.set(d,{f:m,r:u,c:l})}),s}},L.FormulaDataModel=vi([kn(0,_.IUniverInstanceService),kn(1,Z.Inject(Zt))],L.FormulaDataModel);function Tn(r,n,e,t){const s=new Map,i=new _.ObjectMatrix;t.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",m=_.isFormulaString(l),d=_.isFormulaId(c);m&&d?(i.setValue(a,o,{f:l,si:c}),s.set(c,{f:l,r:a,c:o})):m&&!d?i.setValue(a,o,{f:l}):!m&&d&&i.setValue(a,o,{f:"",si:c})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"";if(_.isFormulaId(c)&&!_.isFormulaString(l)){const m=s.get(c);if(m){const d=m.f,E=o-m.c,D=a-m.r;i.setValue(a,o,{f:d,si:c,x:E,y:D})}}}),r[n]&&(r[n][e]=i.getData())}const Mi=r=>{const n=r.get(L.FormulaDataModel),e=_.Tools.deepClone(n.getArrayFormulaRange()),t=_.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},Jt={id:"formula.mutation.set-array-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>{const e=r.get(L.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Nt={id:"formula.mutation.set-defined-name",type:_.CommandType.MUTATION,handler:()=>!0},er={id:"formula.mutation.remove-defined-name",type:_.CommandType.MUTATION,handler:()=>!0},jr={id:"formula.mutation.set-feature-calculation",type:_.CommandType.MUTATION,handler:()=>!0},Ir={id:"formula.mutation.remove-feature-calculation",type:_.CommandType.MUTATION,handler:()=>!0},$r={id:"formula.mutation.set-formula-calculation-start",type:_.CommandType.MUTATION,handler:()=>!0},Yr={id:"formula.mutation.set-formula-calculation-stop",type:_.CommandType.MUTATION,handler:()=>!0},tr={id:"formula.mutation.set-formula-calculation-notification",type:_.CommandType.MUTATION,handler:()=>!0},zr={id:"formula.mutation.set-formula-calculation-result",type:_.CommandType.MUTATION,handler:()=>!0},Qr={id:"formula.mutation.set-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>(r.get(L.FormulaDataModel).setFormulaData(n.formulaData),!0)},Hr={id:"formula.mutation.set-other-formula",type:_.CommandType.MUTATION,handler:()=>!0},Wr={id:"formula.mutation.remove-other-formula",type:_.CommandType.MUTATION,handler:()=>!0},jn={id:"formula.mutation.set-super-table",type:_.CommandType.MUTATION,handler:()=>!0},In={id:"formula.mutation.remove-super-table",type:_.CommandType.MUTATION,handler:()=>!0},Gr={id:"formula.mutation.set-super-table-option",type:_.CommandType.MUTATION,handler:()=>!0},Xr={id:"formula.mutation.unregister-function",type:_.CommandType.MUTATION,handler:()=>!0};class rr extends _.Disposable{constructor(){super(...arguments);S(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var ct=(r=>(r.FALSE="FALSE",r.TRUE="TRUE",r))(ct||{}),ft=(r=>(r[r.SUCCESS=0]="SUCCESS",r[r.ERROR=1]="ERROR",r))(ft||{}),ht=(r=>(r.ALL="#All",r.DATA="#Data",r.HEADERS="#Headers",r.TOTALS="#Totals",r))(ht||{}),Oe=(r=>(r[r.FRONT=0]="FRONT",r[r.BACK=1]="BACK",r))(Oe||{});class Fi{constructor(){S(this,"_cache",new Map);S(this,"_continueBuildingCache",new Map)}set(n,e,t,s,i){if(!this.shouldContinueBuildingCache(n,e,t,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(t);u==null&&(u=new Map,o.set(t,u));let l=u.get(s);l==null&&(l=new Set,u.set(s,l)),l.add(i)}getCellValuePositions(n,e,t){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(n,e,t,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:o.get(s)}getCellPosition(n,e,t,s,i,a){const o=this.getCellPositions(n,e,t,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,t,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(t);if(u==null){u={startRow:s,endRow:i},o.set(t,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,t,s){var u,l;const i=(l=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(s>=a&&s<=o)}canUseCache(n,e,t,s,i){var l,c;if(t===-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(t);if(a==null)return!1;const{startRow:o,endRow:u}=a;return!(s>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const tt=new Fi;var qe=(r=>(r[r.MIN=0]="MIN",r[r.MAX=1]="MAX",r))(qe||{}),Pe=(r=>(r[r.NORMAL=0]="NORMAL",r[r.MIN=1]="MIN",r[r.MAX=2]="MAX",r))(Pe||{});function $n(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(r,n)=>r.localeCompare(n)}function Bi(r){return r.indexOf("*")>-1||r.indexOf("?")>-1}function Yn(r,n){const e=Ui(n).replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(r)}function zn(r){return r.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function Oi(r,n,e){let t=!1;switch(e){case O.EQUALS:t=Yn(r,n);break;case O.GREATER_THAN:case O.GREATER_THAN_OR_EQUAL:t=Yn(r,n)||r>zn(n);break;case O.LESS_THAN:case O.LESS_THAN_OR_EQUAL:t=r<zn(n);break}return t}function Ui(r){return r.replace(/[.+^${}()|[\]\\]/g,"\\$&")}class Ze extends rr{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){}isCube(){return!1}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return h.create(f.VALUE)}max(){return h.create(f.VALUE)}min(){return h.create(f.VALUE)}count(){return h.create(f.VALUE)}countA(){return h.create(f.VALUE)}countBlank(){return h.create(f.VALUE)}getNegative(){return h.create(f.VALUE)}getReciprocal(){return h.create(f.VALUE)}plus(n){return h.create(f.VALUE)}minus(n){return h.create(f.VALUE)}multiply(n){return h.create(f.VALUE)}divided(n){return h.create(f.VALUE)}mod(n){return h.create(f.VALUE)}map(n){return h.create(f.NAME)}mapValue(n){return h.create(f.NAME)}compare(n,e){return h.create(f.NAME)}isEqual(n){return this.compare(n,O.EQUALS)}isNotEqual(n){return this.compare(n,O.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,O.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,O.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,O.LESS_THAN)}isGreaterThan(n){return this.compare(n,O.GREATER_THAN)}concatenateFront(n){return h.create(f.NAME)}concatenateBack(n){return h.create(f.NAME)}plusBy(n){return h.create(f.VALUE)}minusBy(n){return h.create(f.VALUE)}multiplyBy(n){return h.create(f.VALUE)}dividedBy(n){return h.create(f.VALUE)}modInverse(n){return h.create(f.VALUE)}compareBy(n,e){return h.create(f.NAME)}concatenate(n,e=Oe.FRONT){let t=this.getValue().toString();if(typeof n=="string")e===Oe.FRONT?t=n+t:t+=n;else if(typeof n=="number")e===Oe.FRONT?t=n.toString()+t:t+=n.toString();else if(typeof n=="boolean"){const s=n?"TRUE":"FALSE";e===Oe.FRONT?t=s+t:t+=s}return t}pow(n){return h.create(f.VALUE)}powInverse(n){return h.create(f.VALUE)}sqrt(){return h.create(f.VALUE)}cbrt(){return h.create(f.VALUE)}cos(){return h.create(f.VALUE)}acos(){return h.create(f.VALUE)}acosh(){return h.create(f.VALUE)}sin(){return h.create(f.VALUE)}asin(){return h.create(f.VALUE)}asinh(){return h.create(f.VALUE)}tan(){return h.create(f.VALUE)}tanh(){return h.create(f.VALUE)}atan(){return h.create(f.VALUE)}atan2(n){return h.create(f.VALUE)}atan2Inverse(n){return h.create(f.VALUE)}atanh(){return h.create(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return h.create(f.VALUE)}log10(){return h.create(f.VALUE)}exp(){return h.create(f.VALUE)}abs(){return h.create(f.VALUE)}round(n){return h.create(f.VALUE)}roundInverse(n){return h.create(f.VALUE)}floor(n){return h.create(f.VALUE)}floorInverse(n){return h.create(f.VALUE)}ceil(n){return h.create(f.VALUE)}ceilInverse(n){return h.create(f.VALUE)}convertToNumberObjectValue(){return h.create(f.VALUE)}convertToBooleanObjectValue(){return h.create(f.VALUE)}}const ki=1e3,Qn=new ut(ki);class h extends Ze{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}static create(n,e=""){const t=`${n}-${e}`,s=Qn.get(t);if(s)return s;const i=new h(n,e);return Qn.set(t,i),i}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var Ti=20,ji=1,mt=1e6,Hn=1e6,Ii=-7,$i=21,Yi=!1,Tt="[big.js] ",dt=Tt+"Invalid ",nr=dt+"decimal places",zi=dt+"rounding mode",Wn=Tt+"Division by zero",fe={},Ie=void 0,Qi=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Gn(){function r(n){var e=this;if(!(e instanceof r))return n===Ie?Gn():new r(n);if(n instanceof r)e.s=n.s,e.e=n.e,e.c=n.c.slice();else{if(typeof n!="string"){if(r.strict===!0&&typeof n!="bigint")throw TypeError(dt+"value");n=n===0&&1/n<0?"-0":String(n)}Hi(e,n)}e.constructor=r}return r.prototype=fe,r.DP=Ti,r.RM=ji,r.NE=Ii,r.PE=$i,r.strict=Yi,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}function Hi(r,n){var e,t,s;if(!Qi.test(n))throw Error(dt+"number");for(r.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1,(e=n.indexOf("."))>-1&&(n=n.replace(".","")),(t=n.search(/e/i))>0?(e<0&&(e=t),e+=+n.slice(t+1),n=n.substring(0,t)):e<0&&(e=n.length),s=n.length,t=0;t<s&&n.charAt(t)=="0";)++t;if(t==s)r.c=[r.e=0];else{for(;s>0&&n.charAt(--s)=="0";);for(r.e=e-t-1,r.c=[],e=0;t<=s;)r.c[e++]=+n.charAt(t++)}return r}function gt(r,n,e,t){var s=r.c;if(e===Ie&&(e=r.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(zi);if(n<1)t=e===3&&(t||!!s[0])||n===0&&(e===1&&s[0]>=5||e===2&&(s[0]>5||s[0]===5&&(t||s[1]!==Ie))),s.length=1,t?(r.e=r.e-n+1,s[0]=1):s[0]=r.e=0;else if(n<s.length){if(t=e===1&&s[n]>=5||e===2&&(s[n]>5||s[n]===5&&(t||s[n+1]!==Ie||s[n-1]&1))||e===3&&(t||!!s[0]),s.length=n,t){for(;++s[--n]>9;)if(s[n]=0,n===0){++r.e,s.unshift(1);break}}for(n=s.length;!s[--n];)s.pop()}return r}function St(r,n,e){var t=r.e,s=r.c.join(""),i=s.length;if(n)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)s="0"+s;s="0."+s}else if(t>0)if(++t>i)for(t-=i;t--;)s+="0";else t<i&&(s=s.slice(0,t)+"."+s.slice(t));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return r.s<0&&e?"-"+s:s}fe.abs=function(){var r=new this.constructor(this);return r.s=1,r},fe.cmp=function(r){var n,e=this,t=e.c,s=(r=new e.constructor(r)).c,i=e.s,a=r.s,o=e.e,u=r.e;if(!t[0]||!s[0])return t[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=t.length)<(u=s.length)?o:u,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^n?1:-1;return o==u?0:o>u^n?1:-1},fe.div=function(r){var n=this,e=n.constructor,t=n.c,s=(r=new e(r)).c,i=n.s==r.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>mt)throw Error(nr);if(!s[0])throw Error(Wn);if(!t[0])return r.s=i,r.c=[r.e=0],r;var o,u,l,c,m,d=s.slice(),E=o=s.length,D=t.length,C=t.slice(0,o),A=C.length,P=r,x=P.c=[],U=0,$=a+(P.e=n.e-r.e)+1;for(P.s=i,i=$<0?0:$,d.unshift(0);A++<o;)C.push(0);do{for(l=0;l<10;l++){if(o!=(A=C.length))c=o>A?1:-1;else for(m=-1,c=0;++m<o;)if(s[m]!=C[m]){c=s[m]>C[m]?1:-1;break}if(c<0){for(u=A==o?s:d;A;){if(C[--A]<u[A]){for(m=A;m&&!C[--m];)C[m]=9;--C[m],C[A]+=10}C[A]-=u[A]}for(;!C[0];)C.shift()}else break}x[U++]=c?l:++l,C[0]&&c?C[A]=t[E]||0:C=[t[E]]}while((E++<D||C[0]!==Ie)&&i--);return!x[0]&&U!=1&&(x.shift(),P.e--,$--),U>$&>(P,$,e.RM,C[0]!==Ie),P},fe.eq=function(r){return this.cmp(r)===0},fe.gt=function(r){return this.cmp(r)>0},fe.gte=function(r){return this.cmp(r)>-1},fe.lt=function(r){return this.cmp(r)<0},fe.lte=function(r){return this.cmp(r)<1},fe.minus=fe.sub=function(r){var n,e,t,s,i=this,a=i.constructor,o=i.s,u=(r=new a(r)).s;if(o!=u)return r.s=-u,i.plus(r);var l=i.c.slice(),c=i.e,m=r.c,d=r.e;if(!l[0]||!m[0])return m[0]?r.s=-u:l[0]?r=new a(i):r.s=1,r;if(o=c-d){for((s=o<0)?(o=-o,t=l):(d=c,t=m),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((s=l.length<m.length)?l:m).length,o=u=0;u<e;u++)if(l[u]!=m[u]){s=l[u]<m[u];break}if(s&&(t=l,l=m,m=t,r.s=-r.s),(u=(e=m.length)-(n=l.length))>0)for(;u--;)l[n++]=0;for(u=n;e>o;){if(l[--e]<m[e]){for(n=e;n&&!l[--n];)l[n]=9;--l[n],l[e]+=10}l[e]-=m[e]}for(;l[--u]===0;)l.pop();for(;l[0]===0;)l.shift(),--d;return l[0]||(r.s=1,l=[d=0]),r.c=l,r.e=d,r},fe.mod=function(r){var n,e=this,t=e.constructor,s=e.s,i=(r=new t(r)).s;if(!r.c[0])throw Error(Wn);return e.s=r.s=1,n=r.cmp(e)==1,e.s=s,r.s=i,n?new t(e):(s=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(r),t.DP=s,t.RM=i,this.minus(e.times(r)))},fe.neg=function(){var r=new this.constructor(this);return r.s=-r.s,r},fe.plus=fe.add=function(r){var n,e,t,s=this,i=s.constructor;if(r=new i(r),s.s!=r.s)return r.s=-r.s,s.minus(r);var a=s.e,o=s.c,u=r.e,l=r.c;if(!o[0]||!l[0])return l[0]||(o[0]?r=new i(s):r.s=s.s),r;if(o=o.slice(),n=a-u){for(n>0?(u=a,t=l):(n=-n,t=o),t.reverse();n--;)t.push(0);t.reverse()}for(o.length-l.length<0&&(t=l,l=o,o=t),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 r.c=o,r.e=u,r},fe.pow=function(r){var n=this,e=new n.constructor("1"),t=e,s=r<0;if(r!==~~r||r<-Hn||r>Hn)throw Error(dt+"exponent");for(s&&(r=-r);r&1&&(t=t.times(n)),r>>=1,!!r;)n=n.times(n);return s?e.div(t):t},fe.prec=function(r,n){if(r!==~~r||r<1||r>mt)throw Error(dt+"precision");return gt(new this.constructor(this),r,n)},fe.round=function(r,n){if(r===Ie)r=0;else if(r!==~~r||r<-mt||r>mt)throw Error(nr);return gt(new this.constructor(this),r+this.e+1,n)},fe.sqrt=function(){var r,n,e,t=this,s=t.constructor,i=t.s,a=t.e,o=new s("0.5");if(!t.c[0])return new s(t);if(i<0)throw Error(Tt+"No square root");i=Math.sqrt(t+""),i===0||i===1/0?(n=t.c.join(""),n.length+a&1||(n+="0"),i=Math.sqrt(n),a=((a+1)/2|0)-(a<0||a&1),r=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):r=new s(i+""),a=r.e+(s.DP+=4);do e=r,r=o.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==r.c.slice(0,a).join(""));return gt(r,(s.DP-=4)+r.e+1,s.RM)},fe.times=fe.mul=function(r){var n,e=this,t=e.constructor,s=e.c,i=(r=new t(r)).c,a=s.length,o=i.length,u=e.e,l=r.e;if(r.s=e.s==r.s?1:-1,!s[0]||!i[0])return r.c=[r.e=0],r;for(r.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?++r.e:n.shift(),u=n.length;!n[--u];)n.pop();return r.c=n,r},fe.toExponential=function(r,n){var e=this,t=e.c[0];if(r!==Ie){if(r!==~~r||r<0||r>mt)throw Error(nr);for(e=gt(new e.constructor(e),++r,n);e.c.length<r;)e.c.push(0)}return St(e,!0,!!t)},fe.toFixed=function(r,n){var e=this,t=e.c[0];if(r!==Ie){if(r!==~~r||r<0||r>mt)throw Error(nr);for(e=gt(new e.constructor(e),r+e.e+1,n),r=r+e.e+1;e.c.length<r;)e.c.push(0)}return St(e,!1,!!t)},fe[Symbol.for("nodejs.util.inspect.custom")]=fe.toJSON=fe.toString=function(){var r=this,n=r.constructor;return St(r,r.e<=n.NE||r.e>=n.PE,!!r.c[0])},fe.toNumber=function(){var r=Number(St(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(r.toString()))throw Error(Tt+"Imprecise conversion");return r},fe.toPrecision=function(r,n){var e=this,t=e.constructor,s=e.c[0];if(r!==Ie){if(r!==~~r||r<1||r>mt)throw Error(dt+"precision");for(e=gt(new t(e),r,n);e.c.length<r;)e.c.push(0)}return St(e,r<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)},fe.valueOf=function(){var r=this,n=r.constructor;if(n.strict===!0)throw Error(Tt+"valueOf disallowed");return St(r,r.e<=n.NE||r.e>=n.PE,!0)};var Ce=Gn();function Xn(r){let n;switch(r){case O.EQUALS:n=O.EQUALS;break;case O.GREATER_THAN:n=O.LESS_THAN;break;case O.GREATER_THAN_OR_EQUAL:n=O.LESS_THAN_OR_EQUAL;break;case O.LESS_THAN:n=O.GREATER_THAN;break;case O.LESS_THAN_OR_EQUAL:n=O.GREATER_THAN_OR_EQUAL;break;case O.NOT_EQUAL:n=O.NOT_EQUAL;break}return n}function Kr(r,n){return Ce(r).times(n).toNumber()}function Kn(r,n){const e=10**Math.floor(n);return Math.round(Kr(r,e))/e}function qn(r,n){const e=10**Math.floor(n);return Math.floor(Kr(r,e))/e}function Zn(r,n){const e=10**Math.floor(n);return Math.ceil(Kr(r,e))/e}function Jn(r,n){const e=new Ce(r),t=new Ce(n),s=Math.floor(r/n);return e.minus(t.times(s)).toNumber()}function Nn(r,n){return r**n}const wr=class wr extends Ze{static create(){return this._instance=this._instance||new wr(0),this._instance}isNull(){return!0}plus(n){return b.create(0).plus(n)}minus(n){return b.create(0).minus(n)}multiply(n){return b.create(0).multiply(n)}divided(n){return b.create(0).divided(n)}mod(n){return b.create(0).mod(n)}compare(n,e){return n.isString()?Ee.create("").compare(n,e):n.isBoolean()?H.create(!1).compare(n,e):b.create(0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(Ee.create("")):Ee.create(this.concatenate(n.getValue(),Oe.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(Ee.create("")):Ee.create(this.concatenate(n.getValue(),Oe.BACK))}plusBy(n){return b.create(0).plusBy(n)}minusBy(n){return b.create(0).minusBy(n)}multiplyBy(n){return b.create(0).multiplyBy(n)}dividedBy(n){return b.create(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?Ee.create("").compareBy(n,e):typeof n=="boolean"?H.create(!1).compareBy(n,e):b.create(0).compareBy(n,e)}pow(n){return b.create(0).pow(n)}sqrt(){return b.create(0).sqrt()}cbrt(){return b.create(0).cbrt()}cos(){return b.create(0).cos()}acos(){return b.create(0).acos()}acosh(){return b.create(0).acosh()}sin(){return b.create(0).sin()}asin(){return b.create(0).asin()}asinh(){return b.create(0).asinh()}tan(){return b.create(0).tan()}tanh(){return b.create(0).tanh()}atan(){return b.create(0).atan()}atan2(n){return b.create(0).atan2(n)}atanh(){return b.create(0).atanh()}log(){return h.create(f.NUM)}log10(){return h.create(f.NUM)}exp(){return b.create(0).exp()}abs(){return b.create(0).abs()}round(n){return b.create(0).round(n)}floor(n){return b.create(0).floor(n)}ceil(n){return b.create(0).ceil(n)}convertToNumberObjectValue(){return b.create(0)}convertToBooleanObjectValue(){return H.create(!1)}};S(wr,"_instance");let ce=wr;const xt=class xt extends Ze{constructor(e){super(e);S(this,"_value",!1);this._value=e}static create(e){return e?(this._instanceTrue=this._instanceTrue||new xt(!0),this._instanceTrue):(this._instanceFalse=this._instanceFalse||new xt(!1),this._instanceFalse)}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),b.create(-t)}getReciprocal(){return this.getValue()?b.create(1):h.create(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)}mod(e){return this._convertTonNumber().mod(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),b.create(t)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}convertToNumberObjectValue(){return ir(this.getValue())}convertToBooleanObjectValue(){return this}};S(xt,"_instanceTrue"),S(xt,"_instanceFalse");let H=xt;const Wi=2e5,es=new ut(Wi);class b extends Ze{constructor(e){super(e);S(this,"_value",0);this._value=Number(e)}static create(e,t=""){const s=`${e}-${t}`,i=es.get(s);if(i)return i;const a=new b(e);return a.setPattern(t),es.set(s,a),a}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return b.create(0).minus(this)}getReciprocal(){return b.create(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return h.create(f.DIV_BY_ZERO);if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(s===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Jn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?h.create(f.DIV_BY_ZERO):b.create(Jn(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):Ee.create(this.concatenate(e.getValue(),Oe.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):Ee.create(this.concatenate(e.getValue(),Oe.BACK))}compare(e,t){return e.isArray()?e.compare(this,Xn(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return Mt.has(e)?h.create(e):h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).plus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).minus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).times(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(e===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).div(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?e===!1?h.create(f.DIV_BY_ZERO):b.create(Ce(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case O.EQUALS:case O.GREATER_THAN:case O.GREATER_THAN_OR_EQUAL:i=!1;break;case O.LESS_THAN:case O.LESS_THAN_OR_EQUAL:case O.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case O.EQUALS:i=Ce(s).eq(e);break;case O.GREATER_THAN:i=Ce(s).gt(e);break;case O.GREATER_THAN_OR_EQUAL:i=Ce(s).gte(e);break;case O.LESS_THAN:i=Ce(s).lt(e);break;case O.LESS_THAN_OR_EQUAL:i=Ce(s).lte(e);break;case O.NOT_EQUAL:i=!Ce(s).eq(e);break}else if(typeof e=="boolean")switch(t){case O.EQUALS:case O.GREATER_THAN:case O.GREATER_THAN_OR_EQUAL:i=!1;break;case O.LESS_THAN:case O.LESS_THAN_OR_EQUAL:case O.NOT_EQUAL:i=!0;break}return H.create(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Nn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Nn(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Ce(e).sqrt().toNumber();return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cos(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acos(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acosh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.sin(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asin(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asinh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log10(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.exp(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.abs(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Kn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Kn(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=qn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(qn(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Zn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Zn(t,s?1:0)):this}convertToNumberObjectValue(){return this}convertToBooleanObjectValue(){return sr(!0)}_compareInfinity(e,t,s){let i=!1;switch(s){case O.EQUALS:i=e===t;break;case O.GREATER_THAN:i=e>t;break;case O.GREATER_THAN_OR_EQUAL:i=e>=t;break;case O.LESS_THAN:i=e<t;break;case O.LESS_THAN_OR_EQUAL:i=e<=t;break;case O.NOT_EQUAL:i=e!==t;break}return i}}const Gi=2e5,ts=new ut(Gi);class Ee extends Ze{constructor(e){super(e);S(this,"_value");this._value=e}static create(e){const t=ts.get(e);if(t)return t;const s=new Ee(e);return ts.set(e,s),s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):Ee.create(this.concatenate(e.getValue(),Oe.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):Ee.create(this.concatenate(e.getValue(),Oe.BACK))}compare(e,t){return e.isArray()?e.compare(this,Xn(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Bi(e))return this._checkWildcard(e,t);switch(t){case O.EQUALS:i=s===e;break;case O.GREATER_THAN:i=s>e;break;case O.GREATER_THAN_OR_EQUAL:i=s>=e;break;case O.LESS_THAN:i=s<e;break;case O.LESS_THAN_OR_EQUAL:i=s<=e;break;case O.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case O.NOT_EQUAL:case O.GREATER_THAN:case O.GREATER_THAN_OR_EQUAL:i=!0;break;case O.EQUALS:case O.LESS_THAN:case O.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case O.EQUALS:case O.GREATER_THAN:case O.GREATER_THAN_OR_EQUAL:i=!1;break;case O.LESS_THAN:case O.LESS_THAN_OR_EQUAL:case O.NOT_EQUAL:i=!0;break}return H.create(i)}convertToNumberObjectValue(){return ir(this.getValue())}convertToBooleanObjectValue(){return H.create(!0)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=Oi(s,e,t);return H.create(i)}}function sr(r){if(typeof r=="boolean")return H.create(r);let n=!1;if(typeof r=="string"){const e=r.toLocaleUpperCase();e===ct.TRUE?n=!0:e===ct.FALSE&&(n=!1)}else r===1?n=!0:n=!1;return H.create(n)}function qr(r){let n=r.toString();return n.charAt(0)==='"'&&n.charAt(n.length-1)==='"'&&(n=n.slice(1,-1),n=n.replace(/""/g,'"')),Ee.create(n)}function ir(r){if(typeof r=="boolean"){let n=0;return r&&(n=1),b.create(n)}else{if(typeof r=="number")return Number.isFinite(r)?b.create(r):h.create(f.NUM);if(_.isRealNum(r))return b.create(Number(r))}return h.create(f.VALUE)}function Xi(r){return""}function Ki(r=[]){const n=[];for(let e=0;e<r.length;e++){const t=r[e];n[e]==null&&(n[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];n[e][s]=rt.create(i)}}return n}function qi(r=[]){const n=[];for(let e=0;e<r.length;e++){const t=r[e];n[e]==null&&(n[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i==null?n[e][s]=null:i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class be extends Ze{constructor(e){super(typeof e=="string"?e:Xi());S(this,"_values",[]);S(this,"_rowCount",-1);S(this,"_columnCount",-1);S(this,"_unitId","");S(this,"_sheetId","");S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_sliceCache",new Map);S(this,"_flattenCache");S(this,"_flattenPosition");this._values=this._formatValue(e)}static create(e){return new be(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t==null||t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,t){this._currentRow=e,this._currentColumn=t}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){var u;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let l=t;l<=s;l++)for(let c=i;c<=a;c++)if(e((u=o[l])==null?void 0:u[c],l,c)===!1)return}iteratorReverse(e){const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let u=s;u>=t;u--)for(let l=a;l>=i;l--)if(e(o[u][l],u,l)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[ce.create()]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let o=0;o<s;o++){const u=e.get(a,o),l=this.get(a,o);u==null||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 t=this._createNewArray(e,1,e[0].length);return this._flattenCache=t,t}flattenPosition(){if(this._flattenPosition!=null)return this._flattenPosition;const e=[],t=[],s=[],i=[];let a=0;for(let u=0;u<this._rowCount;u++)for(let l=0;l<this._columnCount;l++){const c=this.get(u,l);if(c==null||c.isError()||c.isNull()){a++;continue}c.isString()?(e.push(c),s.push(a++)):(t.push(c),i.push(a++))}const o={stringArray:e,numberArray:t,stringPosition:s,numberPosition:i};return this._flattenPosition=o,o}slice(e,t){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),t!=null&&(o=t[0]||0,u=t[1]||this._columnCount,l=t[2]||1),s>=this._rowCount||o>=this._columnCount)return;const c=`${s}_${i}_${a}_${o}_${u}_${l}`,m=this._sliceCache.get(c);if(m!=null)return m;const d=[],E=this._values;let D=0,C=0;for(let U=s;U<i;U+=a){C=0,d[D]==null&&(d[D]=[]);for(let $=o;$<u;$+=l){if(!E[U])return;let se=E[U][$];se==null&&(se=ce.create()),d[D][C]=se,C++}D++}if(d.length===0||d[0].length===0)return;const A=a>1?-1:s+this._currentRow,P=l>1?-1:o+this._currentColumn,x=this._createNewArray(d,d.length,d[0].length,A,P);return this._sliceCache.set(c,x),x}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=Pe.MIN,s=!1,i=!1){let a,o,u,l;const c=(m,d,E)=>{if(m==null)return!0;let D;if(i===!0?D=m.compare(e,O.EQUALS):D=m.isEqual(e),(D==null?void 0:D.getValue())===!0)return a=m,u={row:d,column:E},!1;t===Pe.MAX?m.isGreaterThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,l={row:d,column:E}):t===Pe.MIN&&m.isLessThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,l={row:d,column:E})};if(s){const m=this._values.length;if(this._values[0]==null)return;const d=this._values[0].length;for(let E=m-1;E>=0;E--)for(let D=d-1;D>=0;D--){const C=this._values[E][D];c(C,E,D)}}else this.iterator((m,d,E)=>{c(m,d,E)});if(a!=null)return u;if(o!=null)return l}binarySearch(e,t=qe.MIN){if(e.isError())return;const{stringArray:s,stringPosition:i,numberArray:a,numberPosition:o}=this.flattenPosition();return e.isString()?this._binarySearch(e,s,i,t):this._binarySearch(e,a,o,t)}_binarySearch(e,t,s,i=qe.MIN){const a=$n(),o=e.getValue().toString();let u=0,l=t.length-1,c=null;for(;u<=l;){const m=Math.floor((u+l)/2),d=t[m];let E=0;if(d.isNull())E=1;else{const D=d.getValue();E=a(D.toString(),o)}if(E===0)return s[m];E===-1?(u=m+1,i===qe.MIN&&(c=m)):(l=m-1,i===qe.MAX&&(c=m))}if(c!=null)return s[c]}sum(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=b.create(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return be.create("{0}").minus(this)}getReciprocal(){return be.create("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}map(e){const t=(s,i,a)=>s==null?ce.create():s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const u=[];for(let l=0;l<s;l++){const c=(a=this._values)==null?void 0:a[o];if(c==null)u[l]=h.create(f.VALUE);else{const m=c[l];m?u[l]=e(m,o,l):u[l]=ce.create()}}i.push(u)}return this._createNewArray(i,t,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0)||ce.create();if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2)||ce.create(),a=t.get(0,s/2-1)||ce.create();return i.plus(a).divided(b.create(2))}return t.get(0,(s-1)/2)||ce.create()}var(e=0){const t=this.mean(),s=[[]];this.iterator(c=>{if(c==null||c.isError()||c.isString()||c.isBoolean()||c.isNull())return;const m=c.minus(t).pow(b.create(2));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:o,_currentColumn:u}=this;return be.create({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:o,column:u}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(t=>t.isError()?t:e.round(t))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(t=>t.isError()?t:e.floor(t))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(t=>t.isError()?t:e.ceil(t))}toValue(){return qi(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=$n();return(s,i)=>{const a=s[e],o=i[e];return a==null?1:o==null?-1:a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<t;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,t,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 m=e.getFirstCell();for(let d=0;d<o;d++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let d=0;d<o;d++)i.push(m[0][d])}else return this._batchOperatorArray(e,t,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,t,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,s,i,a){var E,D;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),m=this.getCurrentRow(),d=this.getCurrentColumn();if(i===5&&(u=tt.canUseCache(l,c,t+d,m,m+o-1),u===!0)){if(a===O.EQUALS){const C=tt.getCellPositions(l,c,t+d,e.getValue());C!=null&&C.forEach(A=>{const P=A-m;s[P]==null&&(s[P]=[]),s[P][t]=H.create(!0)})}else{const C=tt.getCellValuePositions(l,c,t+d);C!=null&&C.forEach((A,P)=>{let x=ce.create();typeof P=="string"?x=Ee.create(P):typeof P=="number"?x=b.create(P):typeof P=="boolean"&&(x=H.create(P)),x.compare(e,a).getValue()===!0&&A.forEach($=>{$>=m&&$<=m+o-1&&(s[$-m]==null&&(s[$-m]=[]),s[$-m][t]=H.create(!0))})})}return}for(let C=0;C<o;C++){const A=(D=(E=this._values)==null?void 0:E[C])==null?void 0:D[t];if(s[C]==null&&(s[C]=[]),A&&e)if(A.isError())s[C][t]=A;else if(e.isError())s[C][t]=e;else switch(i){case 1:s[C][t]=A.plus(e);break;case 0:s[C][t]=A.minus(e);break;case 2:s[C][t]=A.multiply(e);break;case 3:s[C][t]=A.divided(e);break;case 4:s[C][t]=A.mod(e);break;case 5:a?s[C][t]=A.compare(e,a):s[C][t]=h.create(f.VALUE);break;case 6:s[C][t]=A.concatenateFront(e);break;case 7:s[C][t]=A.concatenateBack(e);break;case 8:s[C][t]=A.pow(e);break;case 9:s[C][t]=A.round(e);break;case 10:s[C][t]=A.floor(e);break;case 12:s[C][t]=A.atan2(e);break;case 11:s[C][t]=A.ceil(e);break}else s[C][t]=h.create(f.NA);A!=null&&(A.isError()?tt.set(l,c,t+d,A.getErrorType(),C+m):A.isNull()?tt.set(l,c,t+d,null,C+m):tt.set(l,c,t+d,A.getValue(),C+m))}tt.setContinueBuildingCache(l,c,t+d,m,m+o-1)}_batchOperatorArray(e,t,s){var m,d,E,D,C,A,P,x,U,$,se,he;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 me=0;me<i;me++){const J=[];for(let z=0;z<a;z++){let te;l===3?te=(d=(m=this._values)==null?void 0:m[0])==null?void 0:d[0]:l===1?te=(D=(E=this._values)==null?void 0:E[0])==null?void 0:D[z]:l===2?te=(A=(C=this._values)==null?void 0:C[me])==null?void 0:A[0]:te=(x=(P=this._values)==null?void 0:P[me])==null?void 0:x[z];let N;if(c===3?N=(U=u==null?void 0:u[0])==null?void 0:U[0]:c===1?N=($=u==null?void 0:u[0])==null?void 0:$[z]:c===2?N=(se=u==null?void 0:u[me])==null?void 0:se[0]:N=(he=u==null?void 0:u[me])==null?void 0:he[z],te&&N)if(te.isError())J[z]=te;else if(N.isError())J[z]=N;else switch(t){case 1:J[z]=te.plus(N);break;case 0:J[z]=te.minus(N);break;case 2:J[z]=te.multiply(N);break;case 3:J[z]=te.divided(N);break;case 4:J[z]=te.mod(N);break;case 5:s?J[z]=te.compare(N,s):J[z]=h.create(f.VALUE);break;case 6:J[z]=te.concatenateFront(N);break;case 7:J[z]=te.concatenateBack(N);break;case 8:J[z]=te.pow(N);break;case 9:J[z]=te.round(N);break;case 12:J[z]=te.atan2(N);break;case 10:J[z]=te.floor(N);break;case 11:J[z]=te.ceil(N);break}else J[z]=h.create(f.NA)}o.push(J)}return this._createNewArray(o,i,a)}_checkArrayCalculateType(e){return e.getRowCount()===1&&e.getColumnCount()===1?3:e.getRowCount()===1?1:e.getColumnCount()===1?2:0}_formatValue(e){if(typeof e!="string")return e=e,this._rowCount=e.rowCount,this._columnCount=e.columnCount,this._unitId=e.unitId,this._sheetId=e.sheetId,this._currentRow=e.row,this._currentColumn=e.column,e.calculateValueList;e=e.slice(1,-1);const t=e.split(";"),s=t.length,i=[];let a=0;for(let o=0;o<s;o++){const l=t[o].split(","),c=l.length;a<c&&(a=c);const m=[];for(let d=0;d<c;d++){const E=l[d].trim();m.push(rt.create(E))}i.push(m)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,t,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const o={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return be.create(o)}}class rt{static create(n){if(n==null)return ce.create();if(typeof n=="boolean")return H.create(n);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return Mt.has(e)?h.create(e):e===ct.TRUE||e===ct.FALSE?sr(n):_.isRealNum(n)?b.create(Number(n)):new RegExp(Ci,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?be.create(n.replace(/\n/g,"").replace(/\r/g,"")):qr(n)}return typeof n=="number"?ir(n):h.create(f.VALUE)}}function Zi(r){if(r===null)return 0;if(r!=null&&r.p){const n=r==null?void 0:r.p.body;if(n==null)return 0;const e=n.dataStream;return e.substring(e.length-2,e.length)===_.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(r==null?void 0:r.v)||0}const Ji=1e5,Zr=new ut(Ji);class Lt extends rr{constructor(e){super();S(this,"_forcedSheetId","");S(this,"_forcedSheetName","");S(this,"_defaultSheetId","");S(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});S(this,"_unitData",{});S(this,"_defaultUnitId","");S(this,"_forcedUnitId","");S(this,"_runtimeData",{});S(this,"_arrayFormulaCellData",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeFeatureCellData",{});S(this,"_numfmtItemData",{});S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}getToken(){return this._token}setToken(e){this._token=e}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return Number.isNaN(e)&&(e=0),Number.isNaN(s)&&(s=0),Number.isNaN(t)&&(t=this.getRowCount()-1),Number.isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var l,c,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(h.create(f.VALUE),t,i);const o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId;for(let d=t;d<=s;d++)for(let E=i;E<=a;E++){if(d<0||E<0)return e(h.create(f.REF),d,E);const D=this.getCellData(d,E);let C=!1;if(D==null||_.isNullCell(D)){C=e(null,d,E);continue}const A=this.getCellValueObject(D),P=A.isNumber(),x=(m=(c=(l=this._numfmtItemData[o])==null?void 0:l[u])==null?void 0:c[d])==null?void 0:m[E];if(x&&P&&A.setPattern(x),C=e(A,d,E),C===!1)return}}getFirstCell(){var c,m,d;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return b.create(0);const i=this.getCellValueObject(s),a=i.isNumber(),o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,l=(d=(m=(c=this._numfmtItemData[o])==null?void 0:c[u])==null?void 0:m[e])==null?void 0:d[t];return l&&a&&i.setPattern(l),i}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var t;this._forcedSheetId=(t=e[this.getUnitId()])==null?void 0:t[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getNumfmtItemData(){return this._numfmtItemData}setNumfmtItemData(e){this._numfmtItemData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return h.create(f.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=Zi(e);return Mt.has(t)?h.create(t):e.t===_.CellValueType.NUMBER?ir(t):e.t===_.CellValueType.STRING||e.t===_.CellValueType.FORCE_STRING?qr(t):e.t===_.CellValueType.BOOLEAN?sr(t):rt.create(t)}getCellByRow(e){return this.getCellByPosition(e)}getCellByColumn(e){return this.getCellByPosition(void 0,e)}getCurrentActiveSheetData(){return this._unitData[this.getUnitId()][this.getSheetId()]}getCurrentRuntimeSheetData(){var e,t;return(t=(e=this._runtimeData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentActiveArrayFormulaCellData(){var e,t;return(t=(e=this._arrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCurrentRuntimeActiveArrayFormulaCellData(){var e,t;return(t=(e=this._runtimeArrayFormulaCellData)==null?void 0:e[this.getUnitId()])==null?void 0:t[this.getSheetId()]}getCellData(e,t){const s=this.getCurrentActiveSheetData(),i=this.getCurrentRuntimeSheetData(),a=this.getCurrentActiveArrayFormulaCellData(),o=this.getCurrentRuntimeActiveArrayFormulaCellData();return(i==null?void 0:i.getValue(e,t))||(o==null?void 0:o.getValue(e,t))||this.getRuntimeFeatureCellValue(e,t)||(a==null?void 0:a.getValue(e,t))||(s==null?void 0:s.cellData.getValue(e,t))}getRuntimeFeatureCellValue(e,t){var i;const s=Object.keys(this._runtimeFeatureCellData);for(const a of s){const o=this._runtimeFeatureCellData[a],u=(i=o==null?void 0:o[this.getUnitId()])==null?void 0:i[this.getSheetId()];if(u==null)continue;const l=u.getValue(e,t);if(l!=null)return l}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):h.create(f.VALUE)}toArrayValueObject(e=!0){var D;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,u=Zr.get(o);if(u&&e)return u;const l=s-t+1,c=a-i+1;if(l<0||c<0)return this._getBlankArrayValueObject();const m=new Array(l);this.iterator((C,A,P)=>{const x=A-t,U=P-i;m[x]||(m[x]=new Array(c)),C==null&&(C=ce.create()),m[x][U]=C});const d={calculateValueList:m,rowCount:m.length,columnCount:((D=m[0])==null?void 0:D.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},E=be.create(d);return e&&Zr.set(o,E),E}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return be.create(e)}}class Ni extends rr{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class ea extends rr{constructor(n){super(),this._promiseList=n}isAsyncArrayObject(){return!0}async getValue(){var t;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:((t=n[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:0,column:0};return be.create(e)}}class jt extends Lt{constructor(n,e,t){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const rs=/[\[\]]/g;function ns(r,n){if(rs.test(r)){const e=Number(r.replace(rs,""));return n+e}return Number(r)-1}function Jr(r,n=0,e=0){r=r.toLocaleUpperCase();const t=r.split(/[RC]/),s=t[1],i=t[2],a=ns(s,n),o=ns(i,e);return{row:a,column:o,absoluteRefType:_.AbsoluteRefType.NONE}}function ss(r,n=0,e=0){const{refBody:t,sheetName:s,unitId:i}=Bn(r),a=t.indexOf(":");if(a===-1){const C=Jr(t,n,e),A=C.row,P=C.column,x=C.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:A,startColumn:P,endRow:A,endColumn:P,startAbsoluteRefType:x,endAbsoluteRefType:x}}}const o=t.substring(0,a),u=t.substring(a+1),l=Jr(o,n,e),c=Jr(u,n,e),m=l.row,d=l.column,E=c.row,D=c.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:d,endRow:E,endColumn:D,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:c.absoluteRefType}}}function ta(r){const n=ar(r.startRow,r.startAbsoluteRefType,!0),e=ar(r.startColumn,r.startAbsoluteRefType,!1),t=ar(r.endRow,r.endAbsoluteRefType,!0),s=ar(r.endColumn,r.endAbsoluteRefType,!1);return n===t&&e===s?`R${n}C${e}`:`R${n}C${e}:R${t}C${s}`}function ar(r,n=_.AbsoluteRefType.ALL,e){switch(r+=1,n){case _.AbsoluteRefType.ALL:return`${r}`;case _.AbsoluteRefType.ROW:return e?`${r}`:`[${r}]`;case _.AbsoluteRefType.COLUMN:return e?`[${r}]`:`${r}`;case _.AbsoluteRefType.NONE:return`[${r}]`}}const is=[];var ra=(r=>{})();function na(r){const n=r.getValue();let e=0;return n&&(e=1),b.create(e)}function Re(r,n,e,t){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<r;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<r;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(0,l)||(t!=null?t:ce.create());u.push(c)}s.push(u)}else if(a===1&&i>1)for(let o=0;o<r;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(o,0)||(t!=null?t:ce.create());u.push(c)}s.push(u)}else for(let o=0;o<r;o++){const u=[];for(let l=0;l<n;l++){const c=e.getRealValue(o,l)||(t!=null?t:ce.create());u.push(c)}s.push(u)}}else for(let i=0;i<r;i++){const a=[];for(let o=0;o<n;o++)a.push(e);s.push(a)}return or(s,r,n)}function or(r,n,e){const t={calculateValueList:r,rowCount:n,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return be.create(t)}class Nr extends Lt{constructor(n){super(n);const e=bt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return h.create(f.REF);const e=n,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(n,e){const t=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(o.startRow=i,o.endRow=t):(o.startRow=t,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new jt(n,this.getForcedSheetId(),this.getForcedUnitId());e.setUnitData(this.getUnitData()),e.setDefaultSheetId(this.getDefaultSheetId()),e.setDefaultUnitId(this.getDefaultUnitId()),e.setRuntimeData(this.getRuntimeData()),e.setNumfmtItemData(this.getNumfmtItemData()),e.setArrayFormulaCellData(this.getArrayFormulaCellData()),e.setRuntimeArrayFormulaCellData(this.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();e.setRefOffset(t,s);const i=this.getForcedSheetId();e.setForcedSheetName(this.getForcedSheetName()),i!=null&&e.setForcedSheetIdDirect(i);const a=this.getForcedUnitId();return a&&e.setForcedUnitIdDirect(a),e}}class en extends Lt{constructor(n){super(n);const e=bt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(n){if(!n.isRow())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this.setToken(`${this.getToken()}${X.COLON}${e.getToken()}`),this}}class tn extends Lt{constructor(n){super(n);const e=bt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this.setToken(`${this.getToken()}${X.COLON}${e.getToken()}`),this}}class I extends _.Disposable{constructor(e){super();S(this,"_unitId");S(this,"_subUnitId");S(this,"_row",-1);S(this,"_column",-1);S(this,"needsExpandParams",!1);S(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return h.create(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?h.create(f.VALUE):t;if(e.isString()){const s=Number(e.getValue());return Number.isNaN(s)?h.create(f.REF):s}else if(e.isNumber())return e.getValue();return h.create(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return h.create(f.NA);let o;return s.getRowCount()===1?o=s.get(0,a)||ce.create():o=s.get(a,0)||ce.create(),o.isNull()?h.create(f.NA):o}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,O.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}orderSearch(e,t,s,i=Pe.MIN,a=!1){const o=t.orderSearch(e,i,a);if(o==null)return h.create(f.NA);const u=s.get(o.row,o.column)||ce.create();return u.isNull()?h.create(f.NA):u}binarySearchExpand(e,t,s,i=0,a){const o=t.binarySearch(e,a);return o==null?h.create(f.NA):i===0?s.slice([o,o+1]):s.slice(void 0,[o,o+1])}equalSearchExpand(e,t,s,i=!0,a=0){const o=t.isEqual(e);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const o=t.compare(e,O.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,t,s,i=Pe.MIN,a=!1,o=0){const u=t.orderSearch(e,i,a);return u==null?h.create(f.NA):o===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if((a.isString()||a.isBoolean()||a.isNull())&&(a=a.convertToNumberObjectValue()),a.isError())return a;if(a.isArray()){let o;if(a.iterator(u=>{if(u==null||u.isNull()||t&&(u.isString()||u.isBoolean()))return!0;if(u=this._includingLogicalValuesAndText(u),u.isError())return o=u,!1;s[0].push(u)}),o!=null&&o.isError())return o}else s[0].push(a)}return or(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=na(e)),e.isString()){const t=Number(e.getValue());e=b.create(Number.isNaN(t)?0:t)}return e}createReferenceObject(e,t){const s=e.getForcedUnitId(),i=e.getForcedSheetId()||"",a=e.getForcedSheetName(),u=yt({unitId:s,sheetName:a,range:t});let l;return new RegExp(Bt).test(u)?l=new Nr(u):new RegExp(An).test(u)?l=new en(u):new RegExp(wn).test(u)?l=new tn(u):l=new jt(t,i,s),this._setReferenceDefault(e,l)}_setReferenceDefault(e,t){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(t.setDefaultUnitId(this.unitId),t.setDefaultSheetId(this.subUnitId),t.setUnitData(e.getUnitData()),t.setRuntimeData(e.getRuntimeData()),t.setArrayFormulaCellData(e.getArrayFormulaCellData()),t.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),t)}}class as extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std()}}class os extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std(1)}}class us extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var()}}class ls extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var(1)}}var At=(r=>(r.BETADIST="BETADIST",r.BETAINV="BETAINV",r.BINOMDIST="BINOMDIST",r.CHIDIST="CHIDIST",r.CHIINV="CHIINV",r.CHITEST="CHITEST",r.CONFIDENCE="CONFIDENCE",r.COVAR="COVAR",r.CRITBINOM="CRITBINOM",r.EXPONDIST="EXPONDIST",r.FDIST="FDIST",r.FINV="FINV",r.FTEST="FTEST",r.GAMMADIST="GAMMADIST",r.GAMMAINV="GAMMAINV",r.HYPGEOMDIST="HYPGEOMDIST",r.LOGINV="LOGINV",r.LOGNORMDIST="LOGNORMDIST",r.MODE="MODE",r.NEGBINOMDIST="NEGBINOMDIST",r.NORMDIST="NORMDIST",r.NORMINV="NORMINV",r.NORMSDIST="NORMSDIST",r.NORMSINV="NORMSINV",r.PERCENTILE="PERCENTILE",r.PERCENTRANK="PERCENTRANK",r.POISSON="POISSON",r.QUARTILE="QUARTILE",r.RANK="RANK",r.STDEV="STDEV",r.STDEVP="STDEVP",r.TDIST="TDIST",r.TINV="TINV",r.TTEST="TTEST",r.VAR="VAR",r.VARP="VARP",r.WEIBULL="WEIBULL",r.ZTEST="ZTEST",r))(At||{});const cs=[[os,At.STDEV],[as,At.STDEVP],[ls,At.VAR],[us,At.VARP]],fs=[];var hs=(r=>(r.CUBEKPIMEMBER="CUBEKPIMEMBER",r.CUBEMEMBER="CUBEMEMBER",r.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",r.CUBERANKEDMEMBER="CUBERANKEDMEMBER",r.CUBESET="CUBESET",r.CUBESETCOUNT="CUBESETCOUNT",r.CUBEVALUE="CUBEVALUE",r))(hs||{});const ms=[];var ds=(r=>(r.DAVERAGE="DAVERAGE",r.DCOUNT="DCOUNT",r.DCOUNTA="DCOUNTA",r.DGET="DGET",r.DMAX="DMAX",r.DMIN="DMIN",r.DPRODUCT="DPRODUCT",r.DSTDEV="DSTDEV",r.DSTDEVP="DSTDEVP",r.DSUM="DSUM",r.DVAR="DVAR",r.DVARP="DVARP",r))(ds||{});const rn="yyyy/mm/dd;@";function nn(r){const n=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28)),t=Date.UTC(r.getFullYear(),r.getMonth(),r.getDate());let s=(t-n.getTime())/(1e3*3600*24);return t>e.getTime()&&(s+=1),Math.floor(s)+1}function ur(r){const n=new Date(Date.UTC(1900,0,1)),e=new Date(Date.UTC(1900,1,28));let t=Math.floor(r)-1;return t>(e.getTime()-n.getTime())/(1e3*3600*24)&&(t-=1),new Date(n.getTime()+t*(1e3*3600*24))}function sn(r){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(r))return!1;const e=r.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),o=`${s}-${i}-${a}`;return r.replace(/\//g,"-").split("-").map(l=>l.padStart(2,"0")).join("-")===o}class sa extends I{calculate(n,e,t){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t.isError())return t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=Re(s,i,n),o=Re(s,i,e),u=Re(s,i,t);return a.map((l,c,m)=>{const d=o.get(c,m)||ce.create(),E=u.get(c,m)||ce.create();if(l.isError())return l;if(d.isError())return d;if(E.isError())return E;if(l.isString()||d.isString()||E.isString())return h.create(f.VALUE);let D=+l.getValue();const C=Math.floor(+d.getValue()),A=+E.getValue();if(D<0||D>9999)return h.create(f.NUM);D>=0&&D<1899&&(D+=1900);const P=new Date(D,C-1,A),x=nn(P);if(x<0)return h.create(f.NUM);const U=b.create(x);return U.setPattern(rn),U})}}class ia extends I{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!sn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(0);e=ur(a)}const s=e.getDate();return b.create(s)}}class aa extends I{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=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=Re(t,s,n),a=Re(t,s,e);return i.map((o,u,l)=>{const c=a.get(u,l)||ce.create();if(o.isError())return o;if(c.isError())return c;if(o.isString()||o.isBoolean()||c.isString()||c.isBoolean())return h.create(f.VALUE);const m=+o.getValue();if(m<0)return h.create(f.NUM);const d=Math.floor(+c.getValue()),E=ur(m),D=E.getUTCFullYear(),C=E.getUTCMonth()+d,A=E.getUTCDate(),P=new Date(Date.UTC(D,C,A)),x=nn(P),U=b.create(x);return U.setPattern(rn),U})}}var nt=(r=>(r.DATE="DATE",r.DATEDIF="DATEDIF",r.DATEVALUE="DATEVALUE",r.DAY="DAY",r.DAYS="DAYS",r.DAYS360="DAYS360",r.EDATE="EDATE",r.EOMONTH="EOMONTH",r.HOUR="HOUR",r.ISOWEEKNUM="ISOWEEKNUM",r.MINUTE="MINUTE",r.MONTH="MONTH",r.NETWORKDAYS="NETWORKDAYS",r.NETWORKDAYS_INTL="NETWORKDAYS.INTL",r.NOW="NOW",r.SECOND="SECOND",r.TIME="TIME",r.TIMEVALUE="TIMEVALUE",r.TODAY="TODAY",r.WEEKDAY="WEEKDAY",r.WEEKNUM="WEEKNUM",r.WORKDAY="WORKDAY",r.WORKDAY_INTL="WORKDAY.INTL",r.YEAR="YEAR",r.YEARFRAC="YEARFRAC",r))(nt||{});class oa extends I{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!sn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(1);e=ur(a)}const s=e.getUTCMonth()+1;return b.create(s)}}class ua extends I{calculate(n){if(n)return h.create(f.NA);const e=nn(new Date),t=b.create(e);return t.setPattern(rn),t}}class la extends I{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!sn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return h.create(f.NUM);if(a===0)return b.create(1900);e=ur(a)}const s=e.getUTCFullYear();return b.create(s)}}const gs=[[sa,nt.DATE],[ia,nt.DAY],[aa,nt.EDATE],[oa,nt.MONTH],[ua,nt.TODAY],[la,nt.YEAR]],ps=[];var Rs=(r=>(r.BESSELI="BESSELI",r.BESSELJ="BESSELJ",r.BESSELK="BESSELK",r.BESSELY="BESSELY",r.BIN2DEC="BIN2DEC",r.BIN2HEX="BIN2HEX",r.BIN2OCT="BIN2OCT",r.BITAND="BITAND",r.BITLSHIFT="BITLSHIFT",r.BITOR="BITOR",r.BITRSHIFT="BITRSHIFT",r.BITXOR="BITXOR",r.COMPLEX="COMPLEX",r.CONVERT="CONVERT",r.DEC2BIN="DEC2BIN",r.DEC2HEX="DEC2HEX",r.DEC2OCT="DEC2OCT",r.DELTA="DELTA",r.ERF="ERF",r.ERF_PRECISE="ERF.PRECISE",r.ERFC="ERFC",r.ERFC_PRECISE="ERFC.PRECISE",r.GESTEP="GESTEP",r.HEX2BIN="HEX2BIN",r.HEX2DEC="HEX2DEC",r.HEX2OCT="HEX2OCT",r.IMABS="IMABS",r.IMAGINARY="IMAGINARY",r.IMARGUMENT="IMARGUMENT",r.IMCONJUGATE="IMCONJUGATE",r.IMCOS="IMCOS",r.IMCOSH="IMCOSH",r.IMCOT="IMCOT",r.IMCSC="IMCSC",r.IMCSCH="IMCSCH",r.IMDIV="IMDIV",r.IMEXP="IMEXP",r.IMLN="IMLN",r.IMLOG10="IMLOG10",r.IMLOG2="IMLOG2",r.IMPOWER="IMPOWER",r.IMPRODUCT="IMPRODUCT",r.IMREAL="IMREAL",r.IMSEC="IMSEC",r.IMSECH="IMSECH",r.IMSIN="IMSIN",r.IMSINH="IMSINH",r.IMSQRT="IMSQRT",r.IMSUB="IMSUB",r.IMSUM="IMSUM",r.IMTAN="IMTAN",r.OCT2BIN="OCT2BIN",r.OCT2DEC="OCT2DEC",r.OCT2HEX="OCT2HEX",r))(Rs||{});const _s=[];var Es=(r=>(r.ACCRINT="ACCRINT",r.ACCRINTM="ACCRINTM",r.AMORDEGRC="AMORDEGRC",r.AMORLINC="AMORLINC",r.COUPDAYBS="COUPDAYBS",r.COUPDAYS="COUPDAYS",r.COUPDAYSNC="COUPDAYSNC",r.COUPNCD="COUPNCD",r.COUPNUM="COUPNUM",r.COUPPCD="COUPPCD",r.CUMIPMT="CUMIPMT",r.CUMPRINC="CUMPRINC",r.DB="DB",r.DDB="DDB",r.DISC="DISC",r.DOLLARDE="DOLLARDE",r.DOLLARFR="DOLLARFR",r.DURATION="DURATION",r.EFFECT="EFFECT",r.FV="FV",r.FVSCHEDULE="FVSCHEDULE",r.INTRATE="INTRATE",r.IPMT="IPMT",r.IRR="IRR",r.ISPMT="ISPMT",r.MDURATION="MDURATION",r.MIRR="MIRR",r.NOMINAL="NOMINAL",r.NPER="NPER",r.NPV="NPV",r.ODDFPRICE="ODDFPRICE",r.ODDFYIELD="ODDFYIELD",r.ODDLPRICE="ODDLPRICE",r.ODDLYIELD="ODDLYIELD",r.PDURATION="PDURATION",r.PMT="PMT",r.PPMT="PPMT",r.PRICE="PRICE",r.PRICEDISC="PRICEDISC",r.PRICEMAT="PRICEMAT",r.PV="PV",r.RATE="RATE",r.RECEIVED="RECEIVED",r.RRI="RRI",r.SLN="SLN",r.SYD="SYD",r.TBILLEQ="TBILLEQ",r.TBILLPRICE="TBILLPRICE",r.TBILLYIELD="TBILLYIELD",r.VDB="VDB",r.XIRR="XIRR",r.XNPV="XNPV",r.YIELD="YIELD",r.YIELDDISC="YIELDDISC",r.YIELDMAT="YIELDMAT",r))(Es||{}),Ue=(r=>(r.CELL="CELL",r.ERROR_TYPE="ERROR.TYPE",r.INFO="INFO",r.ISBLANK="ISBLANK",r.ISERR="ISERR",r.ISERROR="ISERROR",r.ISEVEN="ISEVEN",r.ISFORMULA="ISFORMULA",r.ISLOGICAL="ISLOGICAL",r.ISNA="ISNA",r.ISNONTEXT="ISNONTEXT",r.ISNUMBER="ISNUMBER",r.ISODD="ISODD",r.ISOMITTED="ISOMITTED",r.ISREF="ISREF",r.ISTEXT="ISTEXT",r.N="N",r.NA="NA",r.SHEET="SHEET",r.SHEETS="SHEETS",r.TYPE="TYPE",r))(Ue||{});class ca extends I{calculate(n){return n==null?h.create(f.NA):n.isNull()?H.create(!0):n.isArray()?n.mapValue(e=>e.isNull()?H.create(!0):H.create(!1)):H.create(!1)}}class fa extends I{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?H.create(!1):n.isError()?H.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?H.create(!1):e.isError()?H.create(!0):H.create(!1)):H.create(!1)}}class ha extends I{calculate(n){return n==null?h.create(f.NA):n.isError()?H.create(!0):n.isArray()?n.mapValue(e=>e.isError()?H.create(!0):H.create(!1)):H.create(!1)}}class ma extends I{calculate(n){return n==null?h.create(f.NA):n.isBoolean()?H.create(!0):n.isArray()?n.mapValue(e=>e.isBoolean()?H.create(!0):H.create(!1)):H.create(!1)}}class da extends I{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?H.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?H.create(!0):H.create(!1)):H.create(!1)}}class ga extends I{calculate(n){return n==null?h.create(f.NA):!n.isArray()&&!n.isString()?H.create(!0):n.isArray()?n.mapValue(e=>e.isString()?H.create(!1):H.create(!0)):H.create(!1)}}class pa extends I{calculate(n){return n==null?h.create(f.NA):n.isNumber()?H.create(!0):n.isArray()?n.mapValue(e=>e.isNumber()?H.create(!0):H.create(!1)):H.create(!1)}}class Ra extends I{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e){return e==null?h.create(f.NA):e.isReferenceObject()?H.create(!0):H.create(!1)}}class _a extends I{calculate(n){return n==null?h.create(f.NA):n.isString()?H.create(!0):n.isArray()?n.mapValue(e=>e.isString()?H.create(!0):H.create(!1)):H.create(!1)}}const Cs=[[ca,Ue.ISBLANK],[fa,Ue.ISERR],[ha,Ue.ISERROR],[ma,Ue.ISLOGICAL],[da,Ue.ISNA],[ga,Ue.ISNONTEXT],[pa,Ue.ISNUMBER],[Ra,Ue.ISREF],[_a,Ue.ISTEXT]];class Ea extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=!0,t=!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(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?h.create(f.VALUE):H.create(e)}}var st=(r=>(r.AND="AND",r.BYCOL="BYCOL",r.BYROW="BYROW",r.FALSE="FALSE",r.IF="IF",r.IFERROR="IFERROR",r.IFNA="IFNA",r.IFS="IFS",r.LAMBDA="LAMBDA",r.LET="LET",r.MAKEARRAY="MAKEARRAY",r.MAP="MAP",r.NOT="NOT",r.OR="OR",r.REDUCE="REDUCE",r.SCAN="SCAN",r.SWITCH="SWITCH",r.TRUE="TRUE",r.XOR="XOR",r))(st||{});class Ca extends I{calculate(n,e,t=H.create(!1)){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(n=this._getSingleValueObject(n),!n.isArray())return n.getValue()?e:t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=Re(s,i,n),o=Re(s,i,e,h.create(f.NA)),u=Re(s,i,t,h.create(f.NA));return a.map((l,c,m)=>{if(l.isNull())return h.create(f.NA);{const d=o.get(c,m)||ce.create(),E=u.get(c,m)||ce.create();return this._calculateSingleCell(l,d,E)}})}_getSingleValueObject(n){return n.isArray()&&n.getRowCount()===1&&n.getColumnCount()===1?n.getFirstCell():n}_calculateSingleCell(n,e,t){return n.isNull()?h.create(f.NA):n.getValue()?e.isNull()?h.create(f.NA):e:t.isNull()?h.create(f.NA):t}}class Da extends I{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(!n.isArray())return n.isError()?e:n;const t=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=Re(t,s,n),a=Re(t,s,e);return i.iterator((o,u,l)=>{o!=null&&o.isError()&&i.set(u,l,a.get(u,l))}),i}}class ya extends I{calculate(...n){return h.create(f.VALUE)}}class ba extends I{calculate(...n){if(n.length!==3)return h.create(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(n[1]);if(typeof t!="number")return t;if(!(n[2].isValueObject()&&n[2].isLambda()))return h.create(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<t;o++){const u=s.execute(b.create(a+1),b.create(o+1));i[a][o]=u}}return new ea(i)}isAsync(){return!0}}class Sa extends I{calculate(...n){if(n.length===0)return new h(f.NA);let e=!1,t=!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(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e||!!i.getValue(),t=!1)}return t?new h(f.VALUE):new H(e)}}const Ds=[[Ea,st.AND],[Ca,st.IF],[ya,st.LAMBDA],[ba,st.MAKEARRAY],[Sa,st.OR],[Da,st.IFERROR]];class La extends I{calculate(n,e,t,s,i){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return h.create(f.VALUE);const u=t?Aa(t.getValue()):_.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),c=i?`${i.getValue()}`:"",m=qt(c)?`'${c}'`:c,d={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},E=s&&!l?ta(d):lt(d);return Ee.create(m!==""?`${m}!${E}`:E)}}function Aa(r){switch(r){case 1:return _.AbsoluteRefType.ALL;case 2:return _.AbsoluteRefType.ROW;case 3:return _.AbsoluteRefType.COLUMN;case 4:return _.AbsoluteRefType.NONE;default:return _.AbsoluteRefType.ALL}}class wa extends I{calculate(n){if(n==null)return b.create(this.column+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentColumn(),t=n.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(b.create(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return be.create(i)}}class Pa extends I{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getColumnCount();return b.create(e)}}var Se=(r=>(r.ADDRESS="ADDRESS",r.AREAS="AREAS",r.CHOOSE="CHOOSE",r.CHOOSECOLS="CHOOSECOLS",r.CHOOSEROWS="CHOOSEROWS",r.COLUMN="COLUMN",r.COLUMNS="COLUMNS",r.DROP="DROP",r.EXPAND="EXPAND",r.FILTER="FILTER",r.FORMULATEXT="FORMULATEXT",r.GETPIVOTDATA="GETPIVOTDATA",r.HLOOKUP="HLOOKUP",r.HSTACK="HSTACK",r.HYPERLINK="HYPERLINK",r.IMAGE="IMAGE",r.INDEX="INDEX",r.INDIRECT="INDIRECT",r.LOOKUP="LOOKUP",r.MATCH="MATCH",r.OFFSET="OFFSET",r.ROW="ROW",r.ROWS="ROWS",r.RTD="RTD",r.SORT="SORT",r.SORTBY="SORTBY",r.TAKE="TAKE",r.TOCOL="TOCOL",r.TOROW="TOROW",r.TRANSPOSE="TRANSPOSE",r.UNIQUE="UNIQUE",r.VLOOKUP="VLOOKUP",r.VSTACK="VSTACK",r.WRAPCOLS="WRAPCOLS",r.WRAPROWS="WRAPROWS",r.XLOOKUP="XLOOKUP",r.XMATCH="XMATCH",r))(Se||{});class Va extends I{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray()||t.isError()||s!=null&&s.isError())return h.create(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return h.create(f.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?h.create(f.REF):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,t,s){return s===0?this.equalSearch(n,e,t):this.binarySearch(n,e,t)}}class xa extends I{calculate(n,e){if(n==null)return h.create(f.NA);if(n.isError())return n;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),n.isArray()){const c=n;if(c.getRowCount()===1&&c.getColumnCount()===1)n=c.getFirstCell();else return c.map(()=>h.create(f.VALUE))}if(!n.isString())return h.create(f.REF);const s=n.getValue();if(t===0){const c=ss(s),{range:m,sheetName:d,unitId:E}=c,D=new jt(m);return D.setForcedUnitIdDirect(E),D.setForcedSheetName(d),this._setDefault(D)}if(new RegExp(Bt).test(s))return this._setDefault(new Nr(s));if(new RegExp(Sn).test(s))return this._setDefault(new en(s));if(new RegExp(Ln).test(s))return this._setDefault(new tn(s));const i=bt(s),{range:a,sheetName:o,unitId:u}=i,l=new jt(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),this._setDefault(l)}_setDefault(n){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class va extends I{constructor(){super(...arguments);S(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?h.create(f.NA):e.isError()?e:t.isError()?h.create(f.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?h.create(f.REF):this._handleVector(e,t,s):this._handleArray(e,t):h.create(f.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return h.create(f.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,o;return i>s?(a=t.slice([0,1]),o=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),o=t.slice(void 0,[i-1,i])),a==null||o==null?h.create(f.VALUE):e.isArray()?e.map(u=>this.binarySearch(u,a,o)):this.binarySearch(e,a,o)}}class Ma extends I{calculate(n,e,t){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1||t!=null&&t.isError())return h.create(f.NA);const a=this.getMatchTypeValue(t);return a==null?h.create(f.VALUE):n.isArray()?n.map(o=>this._handleSingleObject(o,e,a)):this._handleSingleObject(n,e,a)}_handleSingleObject(n,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(n,s);if(i==null)return h.create(f.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return b.create(a)}_getSearchModeValue(n){switch(n){case 1:return Pe.MIN;case 0:return Pe.NORMAL;case-1:return Pe.MAX}}}class Fa extends I{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i,a){var z,te;const o=e;if(o==null||t==null||s==null)return h.create(f.NA);if(o.isError())return o;if(t.isError())return t;if(s.isError())return s;if(i!=null&&i.isError())return i;if(a!=null&&a.isError())return a;if(!o.isReferenceObject())return h.create(f.VALUE);const{startRow:u,endRow:l,startColumn:c,endColumn:m}=o.getRangeData();t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject());const d=this.getIndexNumValue(t),E=this.getIndexNumValue(s);if(typeof d!="number"||typeof E!="number")return h.create(f.VALUE);const D=u+d,C=c+E;if(D<0||C<0)return h.create(f.REF);i!=null&&i.isReferenceObject()&&(i=i.toArrayValueObject()),a!=null&&a.isReferenceObject()&&(a=a.toArrayValueObject());const A=(z=i&&this.getIndexNumValue(i))!=null?z:1,P=(te=a&&this.getIndexNumValue(a))!=null?te:1;if(typeof A!="number"||typeof P!="number")return h.create(f.VALUE);if(A===0||P===0)return h.create(f.REF);const x=A>0?D+A-1:D+A+1,U=P>0?C+P-1:C+P+1;if(x<0||U<0)return h.create(f.REF);const $=D<x?D:x,se=C<U?C:U,he=D>x?D:x,me=C>U?C:U,J={startRow:$,startColumn:se,endRow:he,endColumn:me};return this.createReferenceObject(o,J)}}class Ba extends I{calculate(n){if(n==null)return b.create(this.row+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentRow(),t=n.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([b.create(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return be.create(i)}}class Oa extends I{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getRowCount();return b.create(e)}}class Ua extends I{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);if(t.isError()||s!=null&&s.isError())return h.create(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return h.create(f.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?h.create(f.VALUE):n.isArray()?n.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,t,s){return s===0?this.equalSearch(n,e,t):this.binarySearch(n,e,t)}}class ka extends I{calculate(n,e,t,s,i,a){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==1)return h.create(f.VALUE);if(t.isError())return h.create(f.REF);if(!t.isArray())return h.create(f.VALUE);const l=t.getRowCount(),c=t.getColumnCount();if(o!==l&&u!==c)return h.create(f.VALUE);if(s!=null&&s.isError()||i!=null&&i.isError()||a!=null&&a.isError())return h.create(f.NA);s==null&&(s=h.create(f.NA));const m=this.getIndexNumValue(i||b.create(0));if(m instanceof h)return m;const d=this.getIndexNumValue(a||b.create(1));if(d instanceof h)return d;if(n.isArray()){let C;return o===1?C=t.slice([0,1]):C=t.slice(void 0,[0,1]),C==null?h.create(f.NA):n.map(A=>{const P=this._handleSingleObject(A,e,C,m,d);return P.isError()?s:P})}if(u===c&&o===l){const C=this._handleSingleObject(n,e,t,m,d);return C.isError()?s:C}let E=0;u===c&&(E=1);const D=this._handleExpandObject(n,e,t,m,d,E);return D==null?h.create(f.NA):D}_handleExpandObject(n,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(n,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(n,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(n,e,t,s===1?Pe.MAX:Pe.MIN,i===-1,a):this.equalSearchExpand(n,e,t,i!==-1,a)}_handleSingleObject(n,e,t,s,i){return(i===2||i===-2)&&s!==2?this.binarySearch(n,e,t,this._getSearchModeValue(i)):s===2?this.fuzzySearch(n,e,t,i!==-1):s===-1||s===1?this.orderSearch(n,e,t,s===1?Pe.MAX:Pe.MIN,i===-1):this.equalSearch(n,e,t,i!==-1)}_getSearchModeValue(n){return n===-2?qe.MAX:qe.MIN}}class Ta extends I{calculate(n,e,t,s){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return h.create(f.VALUE);if(t!=null&&t.isError()||s!=null&&s.isError())return h.create(f.NA);const o=this.getIndexNumValue(t||b.create(0));if(o instanceof h)return o;const u=this.getIndexNumValue(s||b.create(1));return u instanceof h?u:n.isArray()?n.map(l=>this._handleSingleObject(l,e,o,u)):this._handleSingleObject(n,e,o,u)}_handleSingleObject(n,e,t,s){let i;if((s===2||s===-2)&&t!==2){const a=this._getSearchModeValue(s);i=e.binarySearch(n,a)}else if(t===2){const a=e.compare(n,O.EQUALS);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}else if(t===-1||t===1){const a=e.orderSearch(n,t===1?Pe.MAX:Pe.MIN,s===-1);if(a==null)return h.create(f.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(n);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}return i==null?h.create(f.NA):b.create(i+1)}_getSearchModeValue(n){return n===-2?qe.MAX:qe.MIN}}class ja extends I{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i){const a=e;if(a==null)return h.create(f.NA);if(a.isError())return a;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;if(!a.isRange())return h.create(f.REF);const{startRow:o,endRow:u,startColumn:l,endColumn:c}=a.getRangeData(),m=u-o+1,d=c-l+1;m===1&&d>1&&s==null?(s=t!=null?t:b.create(0),t=b.create(0)):(t=t!=null?t:b.create(0),s=s!=null?s:b.create(0)),i=i!=null?i:b.create(1),t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject()),i.isReferenceObject()&&(i=i.toArrayValueObject());const E=Math.max(t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1,i.isArray()?i.getRowCount():1),D=Math.max(t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1,i.isArray()?i.getColumnCount():1);if(E===1&&D===1)return this._calculateSingleCell(a,t,s,i);{const C=Re(E,D,t,h.create(f.NA)),A=Re(E,D,s,h.create(f.NA)),P=Re(E,D,i,h.create(f.NA));return C.map((x,U,$)=>{const se=A.get(U,$)||ce.create(),he=P.get(U,$)||ce.create(),me=this._calculateSingleCell(a,x,se,he);return me.isReferenceObject()?me.toArrayValueObject().getFirstCell():me})}}_calculateSingleCell(e,t,s,i){if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return h.create(f.VALUE);if(s.isError())return s;const o=this._getNumberValue(s);if(o===void 0||o<0)return h.create(f.VALUE);if(i.isError())return i;const u=this._getAreaNumberValue(i);return u===void 0||u<1?h.create(f.VALUE):this._getReferenceObject(e,a,o,u)}_getNumberValue(e){if(e==null)return 0;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getAreaNumberValue(e){if(e==null)return 1;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getReferenceObject(e,t,s,i){const{startRow:a,endRow:o,startColumn:u,endColumn:l}=e.getRangeData();let c=0,m=0,d=0,E=0;if(t===0?(c=a,m=o):c=m=a+t-1,s===0?(d=u,E=l):d=E=u+s-1,c>o||d>l)return h.create(f.REF);const D={startRow:c,startColumn:d,endRow:m,endColumn:E};return this.createReferenceObject(e,D)}}const ys=[[La,Se.ADDRESS],[wa,Se.COLUMN],[Pa,Se.COLUMNS],[ja,Se.INDEX],[xa,Se.INDIRECT],[Fa,Se.OFFSET],[Ba,Se.ROW],[Oa,Se.ROWS],[Ua,Se.VLOOKUP],[va,Se.LOOKUP],[Ma,Se.MATCH],[Va,Se.HLOOKUP],[ka,Se.XLOOKUP],[Ta,Se.XMATCH]];class Ia extends I{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.abs())}}class $a extends I{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?new h(f.VALUE):n.acos())}}class Ya extends I{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.acosh())}}class za extends I{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:n.isArray()?n.map(e=>e.isError()?e:bs(e)):bs(n))}}function bs(r){let n=r.getValue();if(r.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return h.create(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?h.create(f.VALUE):b.create(e)}var Ve=(r=>(r.ABS="ABS",r.ACOS="ACOS",r.ACOSH="ACOSH",r.ACOT="ACOT",r.ACOTH="ACOTH",r.AGGREGATE="AGGREGATE",r.ARABIC="ARABIC",r.ASIN="ASIN",r.ASINH="ASINH",r.ATAN="ATAN",r.ATAN2="ATAN2",r.ATANH="ATANH",r.BASE="BASE",r.CEILING="CEILING",r.CEILING_MATH="CEILING.MATH",r.CEILING_PRECISE="CEILING.PRECISE",r.COMBIN="COMBIN",r.COMBINA="COMBINA",r.COS="COS",r.COSH="COSH",r.COT="COT",r.COTH="COTH",r.CSC="CSC",r.CSCH="CSCH",r.DECIMAL="DECIMAL",r.DEGREES="DEGREES",r.EVEN="EVEN",r.EXP="EXP",r.FACT="FACT",r.FACTDOUBLE="FACTDOUBLE",r.FLOOR="FLOOR",r.FLOOR_MATH="FLOOR.MATH",r.FLOOR_PRECISE="FLOOR.PRECISE",r.GCD="GCD",r.INT="INT",r.ISO_CEILING="ISO.CEILING",r.LCM="LCM",r.LET="LET",r.LN="LN",r.LOG="LOG",r.LOG10="LOG10",r.MDETERM="MDETERM",r.MINVERSE="MINVERSE",r.MMULT="MMULT",r.MOD="MOD",r.MROUND="MROUND",r.MULTINOMIAL="MULTINOMIAL",r.MUNIT="MUNIT",r.ODD="ODD",r.PI="PI",r.POWER="POWER",r.PRODUCT="PRODUCT",r.QUOTIENT="QUOTIENT",r.RADIANS="RADIANS",r.RAND="RAND",r.RANDARRAY="RANDARRAY",r.RANDBETWEEN="RANDBETWEEN",r.ROMAN="ROMAN",r.ROUND="ROUND",r.ROUNDDOWN="ROUNDDOWN",r.ROUNDUP="ROUNDUP",r.SEC="SEC",r.SECH="SECH",r.SERIESSUM="SERIESSUM",r.SEQUENCE="SEQUENCE",r.SIGN="SIGN",r.SIN="SIN",r.SINH="SINH",r.SQRT="SQRT",r.SQRTPI="SQRTPI",r.SUBTOTAL="SUBTOTAL",r.SUM="SUM",r.SUMIF="SUMIF",r.SUMIFS="SUMIFS",r.SUMPRODUCT="SUMPRODUCT",r.SUMSQ="SUMSQ",r.SUMX2MY2="SUMX2MY2",r.SUMX2PY2="SUMX2PY2",r.SUMXMY2="SUMXMY2",r.TAN="TAN",r.TANH="TANH",r.TRUNC="TRUNC",r))(Ve||{});class Qa extends I{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.mod(e)))}}class Ha extends I{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.pow(e)))}}class Wa extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(1);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=this._multiplyArray(s)),s.isError())return s;if(e=e.multiply(s),e.isError())return e}}return e}_multiplyArray(n){let e=b.create(1);return n.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class Ga extends I{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return h.create(f.NA);if(e.isError())return e;if(t.length===0)return h.create(f.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,o)=>{s[a]==null&&(s[a]=[]),s[a][o]=this._handleSingleObject(i,...t)}),or(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=h.create(f.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(Number.isNaN(t))return h.create(f.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:h.create(f.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=b.create(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();a.iterator((u,l)=>{if(e&&this._isRowHidden(o,l)||u==null||u.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return b.create(0);let i=b.create(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();let u;if(a.iterator((l,c)=>{if(e&&this._isRowHidden(o,c)||l==null||l.isNull()||l.isString()||l.isBoolean())return!0;if(l.isError())return u=l,!1;s[0].push(l)}),u!=null&&u.isError())return u}return or(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===_.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class Xa extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isError())return s;if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function Ka(r){const n=[O.EQUALS,O.NOT_EQUAL,O.GREATER_THAN_OR_EQUAL,O.GREATER_THAN,O.LESS_THAN_OR_EQUAL,O.LESS_THAN];for(const e of n)if(r.startsWith(e)){const t=r.substring(e.length);return[e,rt.create(t)]}return[O.EQUALS,rt.create(r)]}function Ss(r,n,e){if(!e)if(n.isString()){const t=`${n.getValue()}`,[s,i]=Ka(t);e=s,n=i}else e=O.EQUALS;return r.compare(n,e)}function qa(r,n){const e=Math.max(r.isArray()?r.getRowCount():1,n.isArray()?n.getRowCount():1),t=Math.max(r.isArray()?r.getColumnCount():1,n.isArray()?n.getColumnCount():1),s=Re(e,t,r),i=Re(e,t,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())?sr(a.getValue()&&l.getValue()):H.create(!1)})}class Za extends I{calculate(n,e,t){return n==null||e==null||n.isError()||e.isError()||t!=null&&t.isError()?h.create(f.NA):!n.isArray()||t&&!t.isArray()?h.create(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,t)):this._handleSingleObject(n,e,t)}_handleSingleObject(n,e,t){const s=Ss(n,e),i=t?t.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():h.create(f.VALUE)}}class Ja extends I{calculate(n,...e){if(n==null||e.length<2||n.isError())return h.create(f.NA);if(!n.isArray()||e.length<2||e.length%2!==0||e.some((c,m)=>m%2===0&&!c.isArray()))return h.create(f.VALUE);const t=n.getRowCount(),s=n.getColumnCount();let i=0,a=0;e.forEach((c,m)=>{if(m%2===1)if(c.isArray()){const d=c;i=Math.max(i,d.getRowCount()),a=Math.max(a,d.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 m=e[c],d=m.getRowCount(),E=m.getColumnCount();if(d!==t||E!==s)return Re(i,a,h.create(f.NA));const D=e[c+1];Re(i,a,D,h.create(f.NA)).iterator((A,P,x)=>{if(!A)return;const U=Ss(m,A);if(o[P]===void 0&&(o[P]=[]),o[P][x]===void 0){o[P][x]=U;return}o[P][x]=qa(o[P][x],U)})}const u=o.map(c=>c.map(m=>n.pick(m).sum())),l={calculateValueList:u,rowCount:u.length,columnCount:u[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return be.create(l)}}const Ls=[[Ia,Ve.ABS],[$a,Ve.ACOS],[Ya,Ve.ACOSH],[za,Ve.ACOT],[Qa,Ve.MOD],[Ga,Ve.SUBTOTAL],[Xa,Ve.SUM],[Za,Ve.SUMIF],[Ja,Ve.SUMIFS],[Ha,Ve.POWER],[Wa,Ve.PRODUCT]];class Na extends I{constructor(){super(...arguments);S(this,"_compareType",O.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()?e:t.isError()?t:e.compare(t,this._compareType)}}class an extends Ze{constructor(e){super("");S(this,"_values",[]);this._values=e}static create(e){return new an(e)}isCube(){return!0}sum(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.sum())}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isLessThan(s)&&(e=s)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isGreaterThan(s)&&(e=s)}),e}count(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.count())}),e}countA(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countA())}),e}countBlank(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countBlank())}),e}}class eo extends I{calculate(...n){if(n.length===0)return h.create(f.VALUE);const e=[];for(let t=0;t<n.length;t++){const s=n[t];if(s.isError())return s;if(!s.isArray())return h.create(f.VALUE);e.push(s)}return an.create(e)}}class to extends I{calculate(n,e){return n.isError()?n:e.isError()?e:!e.isArray()&&e.getValue()===0?h.create(f.DIV_BY_ZERO):n.divided(e)}}var Le=(r=>(r.COMPARE="COMPARE",r.DIVIDED="DIVIDED",r.MINUS="MINUS",r.MULTIPLY="MULTIPLY",r.PLUS="PLUS",r.UNION="UNION",r.CUBE="CUBE",r))(Le||{});class ro extends I{calculate(n,e){return n.isError()?n:e.isError()?e:n.minus(e)}}class no extends I{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class so extends I{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const As=[[Na,Le.COMPARE],[to,Le.DIVIDED],[ro,Le.MINUS],[no,Le.MULTIPLY],[so,Le.PLUS],[eo,Le.CUBE]];class io extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0),t=b.create(0);for(let s=0;s<n.length;s++){let i=n[s];if(i.isString()&&(i=i.convertToNumberObjectValue()),i.isError())return i;if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(i),t=t.plus(b.create(1)))}return e.divided(t)}}class ao extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){const s=n[t];s.isError()||(s.isArray()?e=e.plus(s.count()):s.isString()?s.convertToNumberObjectValue().isError()||(e=e.plus(b.create(1))):s.isNull()||(e=e.plus(b.create(1))))}return e}}class oo extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError()){e=e.plus(b.create(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(b.create(1)))}return e}}var Ae=(r=>(r.AVEDEV="AVEDEV",r.AVERAGE="AVERAGE",r.AVERAGEA="AVERAGEA",r.AVERAGEIF="AVERAGEIF",r.AVERAGEIFS="AVERAGEIFS",r.BETA_DIST="BETA.DIST",r.BETA_INV="BETA.INV",r.BINOM_DIST="BINOM.DIST",r.BINOM_DIST_RANGE="BINOM.DIST.RANGE",r.BINOM_INV="BINOM.INV",r.CHISQ_DIST="CHISQ.DIST",r.CHISQ_DIST_RT="CHISQ.DIST.RT",r.CHISQ_INV="CHISQ.INV",r.CHISQ_INV_RT="CHISQ.INV.RT",r.CHISQ_TEST="CHISQ.TEST",r.CONFIDENCE_NORM="CONFIDENCE.NORM",r.CONFIDENCE_T="CONFIDENCE.T",r.CORREL="CORREL",r.COUNT="COUNT",r.COUNTA="COUNTA",r.COUNTBLANK="COUNTBLANK",r.COUNTIF="COUNTIF",r.COUNTIFS="COUNTIFS",r.COVARIANCE_P="COVARIANCE.P",r.COVARIANCE_S="COVARIANCE.S",r.DEVSQ="DEVSQ",r.EXPON_DIST="EXPON.DIST",r.F_DIST="F.DIST",r.F_DIST_RT="F.DIST.RT",r.F_INV="F.INV",r.F_INV_RT="F.INV.RT",r.F_TEST="F.TEST",r.FISHER="FISHER",r.FISHERINV="FISHERINV",r.FORECAST="FORECAST",r.FORECAST_ETS="FORECAST.ETS",r.FORECAST_ETS_CONFINT="FORECAST.ETS.CONFINT",r.FORECAST_ETS_SEASONALITY="FORECAST.ETS.SEASONALITY",r.FORECAST_ETS_STAT="FORECAST.ETS.STAT",r.FORECAST_LINEAR="FORECAST.LINEAR",r.FREQUENCY="FREQUENCY",r.GAMMA="GAMMA",r.GAMMA_DIST="GAMMA.DIST",r.GAMMA_INV="GAMMA.INV",r.GAMMALN="GAMMALN",r.GAMMALN_PRECISE="GAMMALN.PRECISE",r.GAUSS="GAUSS",r.GEOMEAN="GEOMEAN",r.GROWTH="GROWTH",r.HARMEAN="HARMEAN",r.HYPGEOM_DIST="HYPGEOM.DIST",r.INTERCEPT="INTERCEPT",r.KURT="KURT",r.LARGE="LARGE",r.LINEST="LINEST",r.LOGEST="LOGEST",r.LOGNORM_DIST="LOGNORM.DIST",r.LOGNORM_INV="LOGNORM.INV",r.MAX="MAX",r.MAXA="MAXA",r.MAXIFS="MAXIFS",r.MEDIAN="MEDIAN",r.MIN="MIN",r.MINA="MINA",r.MINIFS="MINIFS",r.MODE_MULT="MODE.MULT",r.MODE_SNGL="MODE.SNGL",r.NEGBINOM_DIST="NEGBINOM.DIST",r.NORM_DIST="NORM.DIST",r.NORM_INV="NORM.INV",r.NORM_S_DIST="NORM.S.DIST",r.NORM_S_INV="NORM.S.INV",r.PEARSON="PEARSON",r.PERCENTILE_EXC="PERCENTILE.EXC",r.PERCENTILE_INC="PERCENTILE.INC",r.PERCENTRANK_EXC="PERCENTRANK.EXC",r.PERCENTRANK_INC="PERCENTRANK.INC",r.PERMUT="PERMUT",r.PERMUTATIONA="PERMUTATIONA",r.PHI="PHI",r.POISSON_DIST="POISSON.DIST",r.PROB="PROB",r.QUARTILE_EXC="QUARTILE.EXC",r.QUARTILE_INC="QUARTILE.INC",r.RANK_AVG="RANK.AVG",r.RANK_EQ="RANK.EQ",r.RSQ="RSQ",r.SKEW="SKEW",r.SKEW_P="SKEW.P",r.SLOPE="SLOPE",r.SMALL="SMALL",r.STANDARDIZE="STANDARDIZE",r.STDEV_P="STDEV.P",r.STDEV_S="STDEV.S",r.STDEVA="STDEVA",r.STDEVPA="STDEVPA",r.STEYX="STEYX",r.T_DIST="T.DIST",r.T_DIST_2T="T.DIST.2T",r.T_DIST_RT="T.DIST.RT",r.T_INV="T.INV",r.T_INV_2T="T.INV.2T",r.T_TEST="T.TEST",r.TREND="TREND",r.TRIMMEAN="TRIMMEAN",r.VAR_P="VAR.P",r.VAR_S="VAR.S",r.VARA="VARA",r.VARPA="VARPA",r.WEIBULL_DIST="WEIBULL.DIST",r.Z_TEST="Z.TEST",r))(Ae||{});class uo extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.NEGATIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.max()),s.isError())return s;e=this._validator(e,s)}}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class ws extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.POSITIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.min()),s.isError())return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}class lo extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std(1)}}class co extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std()}}class fo extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var(1)}}class ho extends I{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var()}}const Ps=[[io,Ae.AVERAGE],[ao,Ae.COUNT],[uo,Ae.MAX],[ws,Ae.MIN],[ws,Ae.MIN],[oo,Ae.COUNTA],[as,Ae.STDEV_P],[os,Ae.STDEV_S],[lo,Ae.STDEVA],[co,Ae.STDEVPA],[us,Ae.VAR_P],[ls,Ae.VAR_S],[fo,Ae.VARA],[ho,Ae.VARPA]];class mo extends I{calculate(...n){if(n.length===0)return h.create(f.NA);let e=0,t=0;n.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of n)s=Re(e,t,i,h.create(f.NA)).mapValue((o,u,l)=>{var E,D;const c=s&&s.get(u,l);if(c!=null&&c.isError())return c;if(o.isError())return o;const m=c!=null&&c.isNull()?"":(E=c==null?void 0:c.getValue())!=null?E:"",d=o!=null&&o.isNull()?"":(D=o==null?void 0:o.getValue())!=null?D:"";return qr(`${m}${d}`)});return s||h.create(f.VALUE)}}var pt=(r=>(r.ASC="ASC",r.ARRAYTOTEXT="ARRAYTOTEXT",r.BAHTTEXT="BAHTTEXT",r.CHAR="CHAR",r.CLEAN="CLEAN",r.CODE="CODE",r.CONCAT="CONCAT",r.CONCATENATE="CONCATENATE",r.DBCS="DBCS",r.DOLLAR="DOLLAR",r.EXACT="EXACT",r.FIND="FIND",r.FINDB="FINDB",r.FIXED="FIXED",r.LEFT="LEFT",r.LEFTB="LEFTB",r.LEN="LEN",r.LENB="LENB",r.LOWER="LOWER",r.MID="MID",r.MIDB="MIDB",r.NUMBERVALUE="NUMBERVALUE",r.PHONETIC="PHONETIC",r.PROPER="PROPER",r.REPLACE="REPLACE",r.REPLACEB="REPLACEB",r.REPT="REPT",r.RIGHT="RIGHT",r.RIGHTB="RIGHTB",r.SEARCH="SEARCH",r.SEARCHB="SEARCHB",r.SUBSTITUTE="SUBSTITUTE",r.T="T",r.TEXT="TEXT",r.TEXTAFTER="TEXTAFTER",r.TEXTBEFORE="TEXTBEFORE",r.TEXTJOIN="TEXTJOIN",r.TEXTSPLIT="TEXTSPLIT",r.TRIM="TRIM",r.UNICHAR="UNICHAR",r.UNICODE="UNICODE",r.UPPER="UPPER",r.VALUE="VALUE",r.VALUETOTEXT="VALUETOTEXT",r.CALL="CALL",r.EUROCONVERT="EUROCONVERT",r.REGISTER_ID="REGISTER.ID",r))(pt||{});class go extends I{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString();return b.create(e.length)}return h.create(f.VALUE)}}function po(r){let n=0;for(let e=0;e<r.length;e++){const t=r.charCodeAt(e);t>=12352&&t<=12543||t>=19968&&t<=40959||t>=44032&&t<=55215?n+=2:n+=1}return n}class Ro extends I{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString(),t=po(e);return b.create(t)}return h.create(f.VALUE)}}var _o=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Eo(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Vs={exports:{}};(function(r,n){(function(e,t){r.exports=t()})(typeof self<"u"?self:_o,function(){return function(){var e={d:function(p,g){for(var R in g)e.o(g,R)&&!e.o(p,R)&&Object.defineProperty(p,R,{enumerable:!0,get:g[R]})},o:function(p,g){return Object.prototype.hasOwnProperty.call(p,g)}},t={};e.d(t,{default:function(){return Cl}});var s={1078:"af",1052:"sq",1118:"am",5121:"ar_DZ",15361:"ar_BH",3073:"ar_EG",2049:"ar_IQ",11265:"ar_JO",13313:"ar_KW",12289:"ar_LB",4097:"ar_LY",6145:"ar_MA",8193:"ar_OM",16385:"ar_QA",1025:"ar_SA",10241:"ar_SY",7169:"ar_TN",14337:"ar_AE",9217:"ar_YE",1067:"hy",1101:"as",2092:"az_AZ",1068:"az_AZ",1069:"eu",1059:"be",2117:"bn",1093:"bn_IN",5146:"bs",1026:"bg",1109:"my",1027:"ca",2052:"zh_CN",3076:"zh_HK",5124:"zh_MO",4100:"zh_SG",1028:"zh_TW",1050:"hr",1029:"cs",1030:"da",1125:"dv",2067:"nl_BE",1043:"nl_NL",1126:"bin",3081:"en_AU",10249:"en_BZ",4105:"en_CA",9225:"en_CB",2057:"en_GB",16393:"en_IN",6153:"en_IE",8201:"en_JM",5129:"en_NZ",13321:"en_PH",7177:"en_ZA",11273:"en_TT",1033:"en_US",12297:"en_ZW",1061:"et",1071:"mk",1080:"fo",1065:"fa",1124:"fil",1035:"fi",2060:"fr_BE",11276:"fr_CM",3084:"fr_CA",9228:"fr_CG",12300:"fr_CI",1036:"fr_FR",5132:"fr_LU",13324:"fr_ML",6156:"fr_MC",14348:"fr_MA",10252:"fr_SN",4108:"fr_CH",7180:"fr",1122:"fy_NL",2108:"gd_IE",1084:"gd",1110:"gl",1079:"ka",3079:"de_AT",1031:"de_DE",5127:"de_LI",4103:"de_LU",2055:"de_CH",1032:"el",1140:"gn",1095:"gu",1279:"en",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig_NG",1057:"id",1040:"it_IT",2064:"it_CH",1041:"ja",1099:"kn",1120:"ks",1087:"kk",1107:"km",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1142:"la",1062:"lv",1063:"lt",2110:"ms_BN",1086:"ms_MY",1100:"ml",1082:"mt",1112:"mni",1153:"mi",1102:"mr",1104:"mn",2128:"mn",1121:"ne",1044:"no_NO",2068:"no_NO",1096:"or",1045:"pl",1046:"pt_BR",2070:"pt_PT",1094:"pa",1047:"rm",2072:"ro_MO",1048:"ro_RO",1049:"ru",2073:"ru_MO",1083:"se",1103:"sa",3098:"sr_SP",2074:"sr_SP",1072:"st",1074:"tn",1113:"sd",1115:"si",1051:"sk",1060:"sl",1143:"so",1070:"sb",11274:"es_AR",16394:"es_BO",13322:"es_CL",9226:"es_CO",5130:"es_CR",7178:"es_DO",12298:"es_EC",17418:"es_SV",4106:"es_GT",18442:"es_HN",2058:"es_MX",19466:"es_NI",6154:"es_PA",15370:"es_PY",10250:"es_PE",20490:"es_PR",1034:"es_ES",14346:"es_UY",8202:"es_VE",1089:"sw",2077:"sv_FI",1053:"sv_SE",1114:"syc",1064:"tg",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1073:"ts",1055:"tr",1090:"tk",1058:"uk",1056:"ur",2115:"uz_UZ",1091:"uz_UZ",1075:"ve",1066:"vi",1106:"cy",1076:"xh",1085:"yi",1077:"zu"};const i=/^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i,a={},o={group:" ",decimal:".",positive:"+",negative:"-",percent:"%",exponent:"E",nan:"NaN",infinity:"∞",ampm:["AM","PM"],mmmm6:["Muharram","Safar","Rabiʻ I","Rabiʻ II","Jumada I","Jumada II","Rajab","Shaʻban","Ramadan","Shawwal","Dhuʻl-Qiʻdah","Dhuʻl-Hijjah"],mmm6:["Muh.","Saf.","Rab. I","Rab. II","Jum. I","Jum. II","Raj.","Sha.","Ram.","Shaw.","Dhuʻl-Q.","Dhuʻl-H."],mmmm:["January","February","March","April","May","June","July","August","September","October","November","December"],mmm:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function u(p){const g=i.exec(p);if(!g)throw new SyntaxError("Malformed locale: ".concat(p));return{lang:g[1]+(g[2]?"_"+g[2]:""),language:g[1],territory:g[2]||"",codeset:g[3]||"",modifier:g[4]||""}}function l(p){if(typeof p=="number")return s[65535&p]||null;const g=parseInt(p,16);return isFinite(g)&&s[65535&g]?s[65535&g]||null:i.test(p)?p:null}function c(p){const g=l(p);let R=null;if(g){const w=u(g);R=a[w.lang]||a[w.language]||null}return R}function m(p){return Object.assign({},o,p)}function d(p,g){const R=typeof g=="object"?g:u(g);return a[R.lang]=m(p),R.language===R.lang||a[R.language]||(a[R.language]=m(p)),a[R.lang]}const E=m({group:","});function D(p,g){if(typeof p!="number")return p;if(p<0)return-D(-p,g);if(g){const R=10**(g||0)||1;return D(p*R,0)/R}return Math.round(p)}E.isDefault=!0,d({group:",",ampm:["上午","下午"],mmmm:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["周日","周一","周二","周三","周四","周五","周六"]},"zh_CN"),d({group:",",nan:"非數值",ampm:["上午","下午"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["週日","週一","週二","週三","週四","週五","週六"]},"zh_TW"),d({group:",",ampm:["午前","午後"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日"],ddd:["日","月","火","水","木","金","土"]},"ja"),d({group:",",ampm:["오전","오후"],mmmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],mmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],dddd:["일요일","월요일","화요일","수요일","목요일","금요일","토요일"],ddd:["일","월","화","수","목","금","토"]},"ko"),d({group:",",ampm:["ก่อนเที่ยง","หลังเที่ยง"],mmmm:["มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม"],mmm:["ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค."],dddd:["วันอาทิตย์","วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัสบดี","วันศุกร์","วันเสาร์"],ddd:["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."]},"th"),d({decimal:",",ampm:["dop.","odp."],mmmm:["ledna","února","března","dubna","května","června","července","srpna","září","října","listopadu","prosince"],mmm:["led","úno","bře","dub","kvě","čvn","čvc","srp","zář","říj","lis","pro"],dddd:["neděle","pondělí","úterý","středa","čtvrtek","pátek","sobota"],ddd:["ne","po","út","st","čt","pá","so"]},"cs"),d({group:".",decimal:",",mmmm:["januar","februar","marts","april","maj","juni","juli","august","september","oktober","november","december"],mmm:["jan.","feb.","mar.","apr.","maj","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"da"),d({group:".",decimal:",",ampm:["a.m.","p.m."],mmmm:["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"],mmm:["jan.","feb.","mrt.","apr.","mei","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag"],ddd:["zo","ma","di","wo","do","vr","za"]},"nl"),d({group:","},"en"),d({decimal:",",nan:"epäluku",ampm:["ap.","ip."],mmmm:["tammikuuta","helmikuuta","maaliskuuta","huhtikuuta","toukokuuta","kesäkuuta","heinäkuuta","elokuuta","syyskuuta","lokakuuta","marraskuuta","joulukuuta"],mmm:["tammik.","helmik.","maalisk.","huhtik.","toukok.","kesäk.","heinäk.","elok.","syysk.","lokak.","marrask.","jouluk."],dddd:["sunnuntaina","maanantaina","tiistaina","keskiviikkona","torstaina","perjantaina","lauantaina"],ddd:["su","ma","ti","ke","to","pe","la"]},"fi"),d({group:" ",decimal:",",mmmm:["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],mmm:["janv.","févr.","mars","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc."],dddd:["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],ddd:["dim.","lun.","mar.","mer.","jeu.","ven.","sam."]},"fr"),d({group:".",decimal:",",mmmm:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],mmm:["Jan.","Feb.","März","Apr.","Mai","Juni","Juli","Aug.","Sept.","Okt.","Nov.","Dez."],dddd:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],ddd:["So.","Mo.","Di.","Mi.","Do.","Fr.","Sa."]},"de"),d({group:".",decimal:",",ampm:["π.μ.","μ.μ."],mmmm:["Ιανουαρίου","Φεβρουαρίου","Μαρτίου","Απριλίου","Μαΐου","Ιουνίου","Ιουλίου","Αυγούστου","Σεπτεμβρίου","Οκτωβρίου","Νοεμβρίου","Δεκεμβρίου"],mmm:["Ιαν","Φεβ","Μαρ","Απρ","Μαΐ","Ιουν","Ιουλ","Αυγ","Σεπ","Οκτ","Νοε","Δεκ"],dddd:["Κυριακή","Δευτέρα","Τρίτη","Τετάρτη","Πέμπτη","Παρασκευή","Σάββατο"],ddd:["Κυρ","Δευ","Τρί","Τετ","Πέμ","Παρ","Σάβ"]},"el"),d({decimal:",",ampm:["de.","du."],mmmm:["január","február","március","április","május","június","július","augusztus","szeptember","október","november","december"],mmm:["jan.","febr.","márc.","ápr.","máj.","jún.","júl.","aug.","szept.","okt.","nov.","dec."],dddd:["vasárnap","hétfő","kedd","szerda","csütörtök","péntek","szombat"],ddd:["V","H","K","Sze","Cs","P","Szo"]},"hu"),d({group:".",decimal:",",ampm:["f.h.","e.h."],mmmm:["janúar","febrúar","mars","apríl","maí","júní","júlí","ágúst","september","október","nóvember","desember"],mmm:["jan.","feb.","mar.","apr.","maí","jún.","júl.","ágú.","sep.","okt.","nóv.","des."],dddd:["sunnudagur","mánudagur","þriðjudagur","miðvikudagur","fimmtudagur","föstudagur","laugardagur"],ddd:["sun.","mán.","þri.","mið.","fim.","fös.","lau."]},"is"),d({group:".",decimal:",",mmmm:["Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"],mmm:["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des"],dddd:["Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu"],ddd:["Min","Sen","Sel","Rab","Kam","Jum","Sab"]},"id"),d({group:".",decimal:",",mmmm:["gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"],mmm:["gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"],dddd:["domenica","lunedì","martedì","mercoledì","giovedì","venerdì","sabato"],ddd:["dom","lun","mar","mer","gio","ven","sab"]},"it"),d({decimal:",",ampm:["a.m.","p.m."],mmmm:["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],mmm:["jan.","feb.","mar.","apr.","mai","jun.","jul.","aug.","sep.","okt.","nov.","des."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"nb"),d({decimal:",",mmmm:["stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia"],mmm:["sty","lut","mar","kwi","maj","cze","lip","sie","wrz","paź","lis","gru"],dddd:["niedziela","poniedziałek","wtorek","środa","czwartek","piątek","sobota"],ddd:["niedz.","pon.","wt.","śr.","czw.","pt.","sob."]},"pl"),d({group:".",decimal:",",mmmm:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"],mmm:["jan.","fev.","mar.","abr.","mai.","jun.","jul.","ago.","set.","out.","nov.","dez."],dddd:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"],ddd:["dom.","seg.","ter.","qua.","qui.","sex.","sáb."]},"pt"),d({decimal:",",nan:"не число",mmmm:["января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"],mmm:["янв.","февр.","мар.","апр.","мая","июн.","июл.","авг.","сент.","окт.","нояб.","дек."],dddd:["воскресенье","понедельник","вторник","среда","четверг","пятница","суббота"],ddd:["вс","пн","вт","ср","чт","пт","сб"]},"ru"),d({decimal:",",mmmm:["januára","februára","marca","apríla","mája","júna","júla","augusta","septembra","októbra","novembra","decembra"],mmm:["jan","feb","mar","apr","máj","jún","júl","aug","sep","okt","nov","dec"],dddd:["nedeľa","pondelok","utorok","streda","štvrtok","piatok","sobota"],ddd:["ne","po","ut","st","št","pi","so"]},"sk"),d({group:".",decimal:",",ampm:["a. m.","p. m."],mmmm:["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],mmm:["ene.","feb.","mar.","abr.","may.","jun.","jul.","ago.","sept.","oct.","nov.","dic."],dddd:["domingo","lunes","martes","miércoles","jueves","viernes","sábado"],ddd:["dom.","lun.","mar.","mié.","jue.","vie.","sáb."]},"es"),d({decimal:",",ampm:["fm","em"],mmmm:["januari","februari","mars","april","maj","juni","juli","augusti","september","oktober","november","december"],mmm:["jan.","feb.","mars","apr.","maj","juni","juli","aug.","sep.","okt.","nov.","dec."],dddd:["söndag","måndag","tisdag","onsdag","torsdag","fredag","lördag"],ddd:["sön","mån","tis","ons","tors","fre","lör"]},"sv"),d({group:".",decimal:",",ampm:["ÖÖ","ÖS"],mmmm:["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık"],mmm:["Oca","Şub","Mar","Nis","May","Haz","Tem","Ağu","Eyl","Eki","Kas","Ara"],dddd:["Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi"],ddd:["Paz","Pzt","Sal","Çar","Per","Cum","Cmt"]},"tr");function C(p,g,R){const w=p<0?-1:1,v=10**(g||2),k=10**(R||2);let M,V,y=Math.abs(p),j=0,W=0,F=0,G=1;if((p=y)%1==0)V=[p*w,1];else if(p<1e-19)V=[w,1e19];else if(p>1e19)V=[1e19*w,1];else{do if(y=1/(y-Math.floor(y)),M=G,G=G*Math.floor(y)+j,j=M,W=F,F=Math.floor(p*G+.5),F>=v||G>=k)return[w*W,j];while(Math.abs(p-F/G)>=1e-10&&y!==Math.floor(y));V=[w*F,G]}return V}const A={overflow:"######",dateErrorThrows:!1,dateErrorNumber:!0,dateSpanLarge:!0,leap1900:!0,nbsp:!0,throws:!0,invalid:"######",locale:"",ignoreTimezone:!1},P=Object.assign({},A);function x(p){if(p===null&&(p=A),p){for(const g in p)if(g in A){const R=p[g];P[g]=R==null?A[g]:R}}return{...P}}const U={"#":"",0:"0","?":" "},$={"@":"text","-":"minus","+":"plus"},se=["#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#800","#080","#008","#880","#808","#088","#CCC","#888","#99F","#936","#FFC","#CFF","#606","#F88","#06C","#CCF","#008","#F0F","#FF0","#0FF","#808","#800","#088","#00F","#0CF","#CFF","#CFC","#FF9","#9CF","#F9C","#C9F","#FC9","#36F","#3CC","#9C0","#FC0"],he=["¤","$","£","¥","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],me=new RegExp("["+he.join("")+"]");function J(p,g,R){return g[R+"_max"]=p.length,g[R+"_min"]=p.replace(/#/g,"").length,g}const z={};function te(p){if(!(p in z)){const g=[],R=p.replace(/^[#,]+/,"").replace(/[1-9]\d*/g,w=>"?".repeat(w.length));for(let w=0;w<R.length;w++){const v=R.charAt(w);g[w]=v in U?U[v]:v}z[p]=g.join("")}return z[p]}function N(p,g){typeof p=="string"&&(p={type:"string",value:p=p.replace(/ /g,U["?"])}),g.push(p)}function Fe(p){const g=[],R={scale:1,percent:!1,text:!1,date:0,date_eval:!1,date_system:1,sec_decimals:0,general:!1,clock:24,int_pattern:[],frac_pattern:[],man_pattern:[],den_pattern:[],num_pattern:[],tokens:g};let w=p+"",v="int",k=!1,M=null;const V=[];let y,j,W=!1;for(;w&&!k;){if(y=/^General/i.exec(w))R.general=!0,N({type:"general"},g);else if(v==="int"&&(y=/^[#?0]+(?:,[#?0]+)*/.exec(w))||v==="den"&&(y=/^[#?\d]+/.exec(w))||(y=/^[#?0]+/.exec(w)))R[v+"_pattern"].push(y[0]),M={type:v,num:y[0]},N(M,g);else if((y=/^\//.exec(w))&&R[v+"_pattern"].length){if(!M)throw new SyntaxError("Missing a numerator in pattern ".concat(p));R.fractions=!0,R.num_pattern.push(R[v+"_pattern"].pop()),M.type="num",v="den",N({type:"div"},g)}else if(y=/^,+/.exec(w)){const B=w.charAt(1)in U;j.slice(-1)in U&&(y[0].length>1||!B)?R.scale=.001**y[0].length:R.dec_fractions||N(y[0],g)}else{if(y=/^;/.exec(w)){k=!0;break}if(y=/^[@+-]/.exec(w))y[0]==="@"&&(R.text=!0),N({type:$[y[0]]},g);else if(y=/^(?:\[(h+|m+|s+)\])/i.exec(w)){const B=y[1].toLowerCase(),Q=B[0],q={type:"",size:0,date:1,raw:y[0],pad:B.length};Q==="h"?(q.size=16,q.type="hour-elap"):Q==="m"?(q.size=32,q.type="min-elap"):(q.size=64,q.type="sec-elap"),R.date=R.date|q.size,V.push(q),N(q,g)}else if(y=/^(?:B2)/i.exec(w))W||(R.date_system=6);else if(y=/^(?:B1)/i.exec(w))W||(R.date_system=1);else if(y=/^(?:([hHmMsSyYbBdDegG])\1*)/.exec(w)){const B={type:"",size:0,date:1,raw:y[0]},Q=y[0].toLowerCase(),q=Q[0];if(Q==="y"||Q==="yy")B.size=2,B.type="year-short";else if(q==="y"||q==="e")B.size=2,B.type="year";else if(Q==="b"||Q==="bb")B.size=2,B.type="b-year-short";else if(q==="b")B.size=2,B.type="b-year";else if(Q==="d"||Q==="dd")B.size=8,B.type="day",B.pad=/dd/.test(Q);else if(Q==="ddd")B.size=8,B.type="weekday-short";else if(q==="d")B.size=8,B.type="weekday";else if(q==="h")B.size=16,B.type="hour",B.pad=/hh/i.test(Q);else if(q==="m"){Q.length===3?(B.size=4,B.type="monthname-short"):Q.length===5?(B.size=4,B.type="monthname-single"):Q.length>=4&&(B.size=4,B.type="monthname");const ie=V[V.length-1];!B.type&&ie&&!ie.used&&80&ie.size&&(ie.used=!0,B.size=32,B.type="min",B.pad=/mm/.test(Q)),B.type||(B.size=4,B.type="month",B.pad=/mm/.test(Q),B.indeterminate=!0)}else if(q==="s"){B.size=64,B.type="sec",B.pad=/ss/.test(Q);const ie=V[V.length-1];ie&&32&ie.size?B.used=!0:ie&&ie.indeterminate&&(delete ie.indeterminate,ie.size=32,ie.type="min",B.used=!0)}R.date=R.date|B.size,R.date_eval=!0,V.push(B),N(B,g)}else if(y=/^(?:AM\/PM|am\/pm|A\/P)/.exec(w))R.clock=12,R.date=16|R.date,R.date_eval=!0,N({type:"am",short:y[0]==="A/P"},g);else if(R.date&&(y=/^\.0{1,3}/i.exec(w))){const B=y[0].length-1,Q=[64,128,256,512][B];R.date=R.date|Q,R.date_eval=!0,R.sec_decimals=Math.max(R.sec_decimals,B),N({type:"subsec",size:Q,decimals:B,date:1,raw:y[0]},g)}else if((y=/^\\(.)/.exec(w))||(y=/^"([^"]*?)"/.exec(w)))N(y[1],g);else if(y=/^\[(<[=>]?|>=?|=)\s*(-?[.\d]+)\]/.exec(w))R.condition=[y[1],parseFloat(y[2],10)];else if(y=/^\[\$([^\]]+)\]/.exec(w)){const B=y[1].split("-"),Q=B.length<2?"":B[B.length-1],q=B[0];q&&N(q,g);const ie=l(Q);ie&&(R.locale=ie);const ue=parseInt(Q,16);isFinite(ue)&&16711680&ue&&(ue>>16&255)===6&&(R.date_system=6),W=!0}else if(y=/^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*(\d+))\]/i.exec(w))R.color=y[2]?se[parseInt(y[2],10)]||"#000":y[1].toLowerCase();else if(!(y=/^\[(DBNum1|ENG|HIJ|JPN|TWN)\]/i.exec(w))){if(y=/^%/.exec(w))R.scale=100,R.percent=!0,N("%",g);else if(y=/^_(\\.|.)/.exec(w))N(" ",g);else if(y=/^\./.exec(w))N({type:"point",value:y[0]},g),R.dec_fractions=!0,v="frac";else if(y=/^[Ee]([+-]?|(?=[0#?]))/.exec(w))R.exponential=!0,R.exp_plus=y[1]==="+",v="man",N({type:"exp",plus:y[1]==="+"},g);else if(!(y=/^\*(\\.|.)/.exec(w))){if(y=/^[BENn[]/.exec(w))throw new SyntaxError("Unexpected char ".concat(w.charAt(0)," in pattern ").concat(p));w[0]==="("&&(R.parens=!0),y=[w[0]],N(y[0],g)}}}j=y[0],w=w.slice(y?y[0].length:1)}if(R.pattern=p.slice(0,p.length-w.length),/^((?:\[[^\]]+\])+)(;|$)/.test(R.pattern)&&!/^\[(?:h+|m+|s+)\]/.test(R.pattern)&&N({type:"text"},g),R.fractions&&R.dec_fractions||R.fractions&&R.exponential)throw new SyntaxError("Invalid pattern: ".concat(R.pattern));const F=R.int_pattern.join("");if(R.grouping=F.indexOf(",")>=0,R.grouping){const B=F.split(","),Q=B.length;Q===2?(R.group_pri=B[1].length,R.group_sec=R.group_pri):Q>2&&(R.group_pri=B[Q-1].length,R.group_sec=B[Q-2].length)}else R.group_pri=0,R.group_sec=0;J(F.replace(/[,]/g,""),R,"int"),J(R.frac_pattern.join(""),R,"frac"),J(R.man_pattern.join(""),R,"man");let G=R.num_pattern.join(""),re=R.den_pattern.join("");const K=/\?/.test(re)||/\?/.test(G);return re=re.replace(/\d/g,K?"?":"#"),K&&(re=re.replace(/#$/g,"?")),J(G,R,"num"),J(re,R,"den"),K&&(G=G.replace(/#$/g,"?")),R.int_padding=te(R.int_pattern.join("")),R.man_padding=te(R.man_pattern.join("")),R.num_padding=te(G),R.den_padding=te(re),R.den_pattern.length&&(R.denominator=parseInt(R.den_pattern.join("").replace(/\D/g,""),10)),R.integer=!!R.int_pattern.join("").length,R.fractions&&g.forEach((B,Q)=>{const q=g[Q+1];B.type==="string"&&q&&(q.type==="num"?B.rule="num+int":q.type==="div"?B.rule="num":q.type==="den"&&(B.rule="den"))}),R}const We=p=>{const g=p.condition;g&&g[1]<0&&(g[0]==="<"||g[0]==="<="||g[0]==="=")||p.tokens.unshift({type:"minus",volatile:!0})};function Ht(p){const g=[];let R,w=!1,v=null,k=p,M=0,V=!1,y=0,j=0;do{if(V=Fe(k),(V.date||V.general)&&(V.int_pattern.length||V.frac_pattern.length||V.scale!==1||V.text))throw new Error("Illegal format");if(V.condition&&(j++,w=!0),V.text){if(v)throw new Error("Unexpected partition");v=V}V.locale&&(R=l(V.locale)),g.push(V),M=k.charAt(V.pattern.length)===";"?1:0,k=k.slice(V.pattern.length+M),y++}while(M&&y<4&&j<3);if(M)throw new Error("Unexpected partition");if(j>2)throw new Error("Unexpected condition");const W=g[3];if(W&&(W.int_pattern.length||W.frac_pattern.length||W.date))throw new Error("Unexpected partition");if(w){const F=g.length;if(F===1&&(g[1]=Fe("General"),g[1].generated=!0),F<3){const G=g[0],re=g[1];if(We(G),re.condition)We(re);else{const K=G.condition;(K[0]==="="||K[1]>=0&&(K[0]===">"||K[0]===">="))&&re.tokens.unshift({type:"minus",volatile:!0})}}else g.forEach(We)}else{if(g.length<4&&v)for(let F=0,G=g.length;F<G;F++)g[F]===v&&g.splice(F,1);if(g.length<1&&v&&(g[0]=Fe("General"),g[0].generated=!0),g.length<2){const F=Fe(g[0].pattern);F.tokens.unshift({type:"minus",volatile:!0}),F.generated=!0,g.push(F)}if(g.length<3){const F=Fe(g[0].pattern);F.generated=!0,g.push(F)}if(g.length<4)if(v)g.push(v);else{const F=Fe("@");F.generated=!0,g.push(F)}g[0].condition=[">",0],g[1].condition=["<",0],g[2].condition=null}return{pattern:p,partitions:g,locale:R}}const we=Math.floor;function Ns(p){if((!(arguments.length>1&&arguments[1]!==void 0)||arguments[1])&&p>=0){if(p===0)return[1900,1,0];if(p===60)return[1900,2,29];if(p<60)return[1900,p<32?1:2,(p-1)%31+1]}let R=p+68569+2415019;const w=we(4*R/146097);R-=we((146097*w+3)/4);const v=we(4e3*(R+1)/1461001);R=R-we(1461*v/4)+31;const k=we(80*R/2447),M=R-we(2447*k/80);R=we(k/11);const V=k+2-12*R;return[0|100*(w-49)+v+R,0|V,0|M]}function ol(p){return Ns(p+1462)}function ul(p){if(p===60)throw new Error("#VALUE!");if(p<=1)return[1317,8,29];if(p<60)return[1317,p<32?9:10,1+(p-2)%30];const g=10631/30,R=.1335;let w=p+466935;const v=we(w/10631);w-=10631*v;const k=we((w-R)/g);w-=we(k*g+R);const M=we((w+28.5001)/29.5);return M===13?[30*v+k,12,30]:[30*v+k,M,w-we(29.5001*M-29)]}function ei(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,R=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];const w=we(p);return g===6?ul(w):g===-1?ol(w):Ns(w,R)}const Pr=Math.floor,Rn=86400;function Vr(p,g){let R=null;if(Array.isArray(p)){const[w,v,k,M,V,y]=p;R=Date.UTC(w,v==null?0:v-1,k!=null?k:1,M||0,V||0,y||0)}else if(p instanceof Date&&(R=1*p,!g||!g.ignoreTimezone)){const w=new Date;w.setUTCFullYear(p.getFullYear(),p.getMonth(),p.getDate()),w.setUTCHours(p.getHours(),p.getMinutes(),p.getSeconds(),p.getMilliseconds()),R=1*w}if(R!=null&&isFinite(R)){const w=R/864e5;return w-(w<=-25509?-25568:-25569)}return p}function ti(p,g){let R=0|p;const w=Rn*(p-R);let v=Pr(w);w-v>.9999&&(v+=1,v===Rn&&(v=0,R+=1));const k=v<0?Rn+v:v,[M,V,y]=ei(p,0,g&&g.leap1900),j=Pr(k/60/60)%60,W=Pr(k/60)%60,F=Pr(k)%60;if(g&&g.nativeDate){const G=new Date(0);return G.setUTCFullYear(M,V-1,y),G.setUTCHours(j,W,F),G}return[M,V,y,j,W,F]}function ll(p){return!!(p[0]&&p[0].percent||p[1]&&p[1].percent||p[2]&&p[2].percent||p[3]&&p[3].percent)}function cl(p){return!!(p[0]&&p[0].date||p[1]&&p[1].date||p[2]&&p[2].date||p[3]&&p[3].date)}function fl(p){const[g,R,w,v]=p;return!(g&&!g.generated||R&&!R.generated||w&&!w.generated||!v||!v.text||v.generated)}const hl={text:15,datetime:10.8,date:10.8,time:10.8,percent:10.6,currency:10.4,grouped:10.2,scientific:6,number:4,fraction:2,general:0,error:0},ml=[["DMY",1],["DM",2],["MY",3],["MDY",4],["MD",5],["hmsa",6],["hma",7],["hms",8],["hm",9]],dl={total:1,sign:0,period:0,int:1,frac:0},Wt=(p,g)=>p.replace(/\./,g.decimal);function ri(p,g,R,w){const v=0|R;if(typeof R=="string")p.push(R);else if(R===v)p.push(Math.abs(v));else{const k=Math.abs(R);let M=k?Math.floor(Math.log10(k)):0,V=M<0?k*10**-M:k/10**M;V===10&&(V=1,M++);const y=function(W){let F=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];const G=Math.abs(W);if(!G)return dl;const re=F&&W<0?1:0,K=Math.floor(G),B=Math.floor(Math.log10(G)+1);let Q=0,q=0;if(K!==G){Q=1;const ie=String(D(B<0?G*10**-B:G/10**B,15));let ue=ie.length,oe=!0,De=0;for(;De<=ie.length;){if(ie[De]==="."){ue--;break}ie[De]==="0"&&oe?ue--:oe=!1,De++}q=ue-B,q<0&&(q=0,Q=0)}return{total:re+Math.max(B,1)+Q+q,digits:Math.max(B,0)+q,sign:re,period:Q,int:Math.max(B,1),frac:q}}(k),j=()=>{const W=Math.abs(M);let F;F=V===1?V:D(V,5),p.push(Wt(F+"",w),w.exponent,M<0?w.negative:w.positive,W<10?"0":"",W)};if(M>=-4&&M<=-1){const W=k.toPrecision(10+M).replace(/\.?0+$/,"");p.push(Wt(W,w))}else if(M===10){const W=k.toFixed(10).slice(0,12).replace(/\.$/,"");p.push(Wt(W,w))}else if(Math.abs(M)<=9)if(y.total<=11){const W=D(k,9).toFixed(y.frac);p.push(Wt(W,w))}else M===9?p.push(Math.floor(k)):M>=0&&M<9?p.push(D(k,9-M)):j();else y.total>=12?j():Math.floor(k)===k?p.push(Math.floor(k)):p.push(Wt(D(k,9).toFixed(y.frac),w))}return p}const Gt=86400,ni={int:"integer",frac:"fraction",man:"mantissa",num:"numerator",den:"denominator"},si=function(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;const R=Math.floor(Math.log10(p));return g>1?Math.floor(R/g)*g:R};function ii(p,g,R,w){let v="",k="",M="",V="",y="",j=0,W=0|p,F=0,G=0,re=1,K=0,B=0,Q=0,q=0,ie=0,ue=0;const oe=w||E;if(!g.text&&isFinite(g.scale)&&g.scale!==1&&(p=function(ae){if(ae===0)return ae;const le=Math.ceil(Math.log10(ae<0?-ae:ae)),T=10**(16-Math.floor(le));return Math.round(ae*T)/T}(p*g.scale)),g.exponential){let ae=Math.abs(p);if(ae){const le=10**-si(ae,g.int_max),T=D(ae*le,g.frac_max)/le;j=si(T,g.int_max)}ae/=10**j,p=p<0?-ae:ae,v+=Math.abs(j)}if(g.integer){const ae=Math.abs(D(p,g.fractions?1:g.frac_max));y+=ae<1?"":Math.floor(ae)}if(g.grouping){let ae="",le=y.length;for(le>g.group_pri&&(le-=g.group_pri,ae=oe.group+y.slice(le,le+g.group_pri)+ae);le>g.group_sec;)le-=g.group_sec,ae=oe.group+y.slice(le,le+g.group_sec)+ae;y=le?y.slice(0,le)+ae:ae}g.dec_fractions&&(V=String(D(p,g.frac_max)).split(".")[1]||"");let De=!1;if(g.fractions){const ae=Math.abs(g.integer?p%1:p);if(ae)if(De=!0,isFinite(g.denominator))M+=g.denominator,k+=D(ae*g.denominator),k==="0"&&(k="",M="",De=!1,y||(y="0"));else{const le=C(ae,g.integer?g.num_max:1/0,g.den_max);k+=le[0],M+=le[1],g.integer&&k==="0"&&(y||(y="0"),k="",M="",De=!1)}}if(g.date){W=Math.trunc(p);const ae=Gt*(p-W);if(F=Math.floor(ae),ue=ae-F,Math.abs(ue)<1e-6?ue=0:ue>.9999&&(ue=0,F+=1,F===Gt&&(F=0,W+=1)),ue){const le=512&g.date||256&g.date||128&g.date;(le===512&&ue>.9995||le===256&&ue>.995||le===128&&ue>.95||!le&&ue>=.5)&&(F++,ue=0)}if(W||g.date_system){const le=ei(p,g.date_system,R.leap1900);G=le[0],re=le[1],K=le[2]}if(F){const le=F<0?Gt+F:F;ie=Math.floor(le)%60,q=Math.floor(le/60)%60,Q=Math.floor(le/60/60)%60}if(B=(6+W)%7,g.date_eval&&(Je=p,Et=W+F/Gt,R.dateSpanLarge?Je<-694324||Et>=35830291:Je<0||Et>=2958466)){if(R.dateErrorThrows)throw new Error("Date out of bounds");return R.dateErrorNumber?ri(p<0?[oe.negative]:[],0,p,oe).join(""):R.overflow}}var Je,Et;if(g.int_padding&&(y=g.int_padding.length===1?y||g.int_padding:g.int_padding.substring(0,g.int_padding.length-y.length)+y),g.num_padding&&(k=g.num_padding.length===1?k||g.num_padding:g.num_padding.substring(0,g.num_padding.length-k.length)+k),g.den_padding&&(M=g.den_padding.length===1?M||g.den_padding:M+g.den_padding.slice(M.length)),g.man_padding){const ae=g.exp_plus?"+":"";v=g.man_padding.length===1?(j<0?"-":ae)+(v||g.man_padding):(j<0?"-":ae)+g.man_padding.slice(0,g.man_padding.length-v.length)+v}const Y=[];let Be=0;const at={int:0,frac:0,man:0,num:0,den:0};for(let ae=0,le=g.tokens.length;ae<le;ae++){const T=g.tokens[ae],xr=T.num?T.num.length:0;if(T.type==="string")T.rule?T.rule==="num"?De?Y.push(T.value):(g.num_min>0||g.den_min>0)&&Y.push(T.value.replace(/./g,U["?"])):T.rule==="num+int"?De&&y?Y.push(T.value):g.den_min>0&&(y||g.num_min)&&Y.push(T.value.replace(/./g,U["?"])):T.rule==="den"&&(De?Y.push(T.value):(g.den_min>0||g.den_min>0)&&Y.push(T.value.replace(/./g,U["?"]))):Y.push(T.value);else if(T.type==="error")Y.push(R.invalid);else if(T.type==="point")Y.push(g.date?T.value:oe.decimal);else if(T.type==="general")ri(Y,0,p,oe);else if(T.type==="exp")Y.push(oe.exponent);else if(T.type==="minus")T.volatile&&g.date||T.volatile&&(p>=0||typeof p!="number")||(T.volatile&&!g.fractions&&(g.integer||g.dec_fractions)?(p<0&&y&&y!=="0"||V)&&Y.push(oe.negative):Y.push(oe.negative));else if(T.type==="plus")Y.push(oe.positive);else if(T.type==="text")Y.push(p);else if(T.type==="div")De?Y.push("/"):g.num_min>0||g.den_min>0?Y.push(U["?"]):Y.push(U["#"]);else if(T.type==="int")if(g.int_pattern.length===1)Y.push(y);else{const ge=Be?g.int_pattern.join("").length-at.int:1/0,vt=Be===g.int_pattern.length-1?0:g.int_pattern.join("").length-(at.int+T.num.length);Y.push(y.substring(y.length-ge,y.length-vt)),Be++,at.int+=T.num.length}else if(T.type==="frac"){const ge=at.frac;for(let vt=0;vt<xr;vt++)Y.push(V[vt+ge]||U[T.num[vt]]);at.frac+=xr}else if(T.type in ni)g[T.type+"_pattern"].length===1?(T.type==="int"&&Y.push(y),T.type==="frac"&&Y.push(V),T.type==="man"&&Y.push(v),T.type==="num"&&Y.push(k),T.type==="den"&&Y.push(M)):(Y.push(ni[T.type].slice(at[T.type],at[T.type]+xr)),at[T.type]+=xr);else if(T.type==="year")G<0&&Y.push(oe.negative),Y.push(String(Math.abs(G)).padStart(4,"0"));else if(T.type==="year-short"){const ge=G%100;Y.push(ge<10?"0":"",ge)}else if(T.type==="month")Y.push(T.pad&&re<10?"0":"",re);else if(T.type==="monthname-single")g.date_system===6?Y.push(oe.mmmm6[re-1].charAt(0)):Y.push(oe.mmmm[re-1].charAt(0));else if(T.type==="monthname-short")g.date_system===6?Y.push(oe.mmm6[re-1]):Y.push(oe.mmm[re-1]);else if(T.type==="monthname")g.date_system===6?Y.push(oe.mmmm6[re-1]):Y.push(oe.mmmm[re-1]);else if(T.type==="weekday-short")Y.push(oe.ddd[B]);else if(T.type==="weekday")Y.push(oe.dddd[B]);else if(T.type==="day")Y.push(T.pad&&K<10?"0":"",K);else if(T.type==="hour"){const ge=Q%g.clock||(g.clock<24?g.clock:0);Y.push(T.pad&&ge<10?"0":"",ge)}else if(T.type==="min")Y.push(T.pad&&q<10?"0":"",q);else if(T.type==="sec")Y.push(T.pad&&ie<10?"0":"",ie);else if(T.type==="subsec"){Y.push(oe.decimal);const ge=ue.toFixed(g.sec_decimals);Y.push(ge.slice(2,2+T.decimals))}else if(T.type==="am"){const ge=Q<12?0:1;T.short&&!w?Y.push("AP"[ge]):Y.push(oe.ampm[ge])}else if(T.type==="hour-elap"){p<0&&Y.push(oe.negative);const ge=24*W+Math.floor(Math.abs(F)/3600);Y.push(String(Math.abs(ge)).padStart(T.pad,"0"))}else if(T.type==="min-elap"){p<0&&Y.push(oe.negative);const ge=1440*W+Math.floor(Math.abs(F)/60);Y.push(String(Math.abs(ge)).padStart(T.pad,"0"))}else if(T.type==="sec-elap"){p<0&&Y.push(oe.negative);const ge=W*Gt+Math.abs(F);Y.push(String(Math.abs(ge)).padStart(T.pad,"0"))}else if(T.type==="b-year")Y.push(G+543);else if(T.type==="b-year-short"){const ge=(G+543)%100;Y.push(ge<10?"0":"",ge)}}return R.nbsp?Y.join(""):Y.join("").replace(/\u00a0/g," ")}function ai(p,g){for(let R=0;R<3;R++){const w=g[R];if(w){let v;if(w.condition){const k=w.condition[0],M=w.condition[1];k==="="?v=p===M:k===">"?v=p>M:k==="<"?v=p<M:k===">="?v=p>=M:k==="<="?v=p<=M:k==="<>"&&(v=p!==M)}else v=!0;if(v)return w}}}const oi=Fe("@"),ui="black",Te={};function je(p,g){if(p){const R=p[0];g[R]=g[R]||{},je(p.slice(1),g[R])}else g.$=!0}["d-F-y","d-F-Y","d-M-y","d-M-Y","F-d-y","F-d-Y","F-j-y","F-j-Y","j-F-y","j-F-Y","j-M-y","j-M-Y","M-d-y","M-d-Y","M-j-y","M-j-Y","m-d-y","m-d-Y","m-j-y","m-j-Y","n-d-y","n-d-Y","n-j-y","n-j-Y","y-F-d","y-F-j","y-M-d","y-M-j","Y-F-d","Y-F-j","Y-M-d","Y-m-d","Y-M-j","Y-m-j","Y-n-d","Y-n-j","j-F","j-M","d-F","d-M","n-d","n-j","n-Y","m-d","m-j","m-Y","M-Y","M-y","F-y","F-Y","Y-M","Y-n","Y-m","Y-F","Y-M"].forEach(p=>{je(p,Te),je(p+" x",Te),je(p+" l",Te),je(p+" l x",Te),je("l "+p,Te),je("l "+p+" x",Te),je(p+" D",Te),je(p+" D x",Te),je("D "+p,Te),je("D "+p+" x",Te)});const gl={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12},pl={january:1,february:2,march:3,april:4,june:6,july:7,august:8,september:9,october:10,november:11,december:12},Rl={sunday:"l",monday:"l",tuesday:"l",wednesday:"l",thursday:"l",friday:"l",saturday:"l",sun:"D",mon:"D",tue:"D",wed:"D",thu:"D",fri:"D",sat:"D"},_l=new Date().getUTCFullYear();function li(p){const g=new RegExp("^([\\s+%"+he.join("")+"(-]*)(((?:(?:\\d[\\d,]*)(?:\\.\\d*)?|(?:\\.\\d+)))([eE][+-]?\\d+)?)([\\s%"+he.join("")+")]*)$").exec(p);if(g){const[,R,w,v,k,M]=g;let V=1,y="",j=!1,W=!1,F=!1,G=!1,re=!1,K=null,B=!1,Q=parseFloat(w.replace(/,/g,""));if(!isFinite(Q))return null;for(let ie=0;ie<R.length;ie++){const ue=R[ie];if(ue==="-"){if(j||W)return null;j=!0,V=-1}else if(me.test(ue)){if(re)return null;re=!0,K=ue}else if(ue==="("){if(W||j)return null;W=!0,V=-1}else if(ue==="%"){if(G)return null;G=!0}}for(let ie=0;ie<M.length;ie++){const ue=M[ie];if(me.test(ue)){if(re)return null;re=!0,K=ue,B=!0}else if(ue===")"){if(F||!W)return null;F=!0}else if(ue==="%"){if(G)return null;G=!0}}if(k){if(G||re)return null;y="0.00E+00"}else if(G){if(re)return null;y=v.includes(".")?"0.00%":"0%",Q*=.01}else if(re){const ie=v.includes(".")?"#,##0.00":"#,##0";y=B?ie+K:K+ie}else v.includes(",")&&(y=v.includes(".")?"#,##0.00":"#,##0");const q={v:Q*V};return y&&(q.z=y),q}}const Ge=(p,g,R)=>{const w=R.path||"",v=Object.keys(g);for(let k=0;k<v.length;k++){let M;const V=v[k];if(g[V]){if(V==="$"||V==="€")p||(M=R);else if(V==="-"){const y=/^(\s*([./-]|,\s)\s*|\s+)/.exec(p);if(y){const j=y[1]==="-"||y[1]==="/"||y[1]==="."?y[1]:" ";if(!R.sep||R.sep===j){const W=y[0].replace(/\s+/g," ");M=Ge(p.slice(y[0].length),g[V],{...R,sep:j,path:w+W})}}}else if(V===" "){const y=/^[,.]?\s+/.exec(p);if(y){const j=y[0].replace(/\s+/g," ");M=Ge(p.slice(y[0].length),g[V],{...R,path:w+j})}}else if(V==="j"||V==="d"){const y=/^(0?[1-9]|1\d|2\d|3[01])\b/.exec(p);y&&(M=Ge(p.slice(y[0].length),g[V],{...R,day:y[0],path:w+V}))}else if(V==="n"||V==="m"){const y=/^(0?[1-9]|1[012])\b/.exec(p);y&&(M=Ge(p.slice(y[0].length),g[V],{...R,month:+y[0],_mon:y[0],path:w+V}))}else if(V==="F"||V==="M"){const y=/^([a-z]{3,9})\b/i.exec(p),j=y&&(V==="F"?pl:gl)[y[0].toLowerCase()];j&&(M=Ge(p.slice(y[0].length),g[V],{...R,month:j,_mon:y[0],path:w+V}))}else if(V==="l"||V==="D"){const y=/^([a-z]{3,9})\b/i.exec(p);(y&&Rl[y[0].toLowerCase()])===V&&(M=Ge(p.slice(y[0].length),g[V],{...R,path:w+V}))}else if(V==="y"){const y=/^\d\d\b/.exec(p);if(y){const j=+y[0]>=30?+y[0]+1900:+y[0]+2e3;M=Ge(p.slice(y[0].length),g[V],{...R,year:j,path:w+V})}}else if(V==="Y"){const y=/^\d\d\d\d\b/.exec(p);y&&(M=Ge(p.slice(y[0].length),g[V],{...R,year:+y[0],path:w+V}))}else{if(V!=="x")throw new Error('Unknown date token "'.concat(V,'"'));{const y=_n(p);y&&(M=Ge("",g[V],{...R,time:y.v,tf:y.z,path:w+V}))}}if(M)return M}}};function ci(p,g){const R=Ge(p.trim(),Te,{path:""});if(R){var w;if(R.sep==="."&&R.path.length===3)return null;const v=+((w=R.year)!==null&&w!==void 0?w:_l);if(R.day||(R.day=1),!function(V,y,j){if(j<1||y<1||y>12)return!1;if(y===2){if(j>(V%4==0&&V%100!=0||V%400==0||V===1900?29:28))return!1}else if((y===4||y===6||y===9||y===11)&&j>30||(y===1||y===3||y===5||y===7||y===8||y===10||y===12)&&j>31)return!1;return!0}(v,R.month,R.day))return null;let k=-1/0;if(v<1900)return null;v<=1900&&R.month<=2?k=25568:v<1e4&&(k=25569);const M=Date.UTC(v,R.month-1,R.day)/864e5+k+(R.time||0);if(M>=0&&M<=2958465){const V=R._mon[0]==="0"||R.day[0]==="0"||R._mon.length===2&&R.day.length===2,y=R.path.replace(/[jdlDnmMFyYx-]/g,j=>j==="j"||j==="d"?V?"dd":"d":j==="D"?"ddd":j==="l"?"dddd":j==="n"||j==="m"?V?"mm":"m":j==="M"?"mmm":j==="F"?"mmmm":j==="y"?"yy":j==="x"?R.tf||"":j==="Y"?"yyyy":j);return g&&g.nativeDate?{v:ti(M,g),z:y}:{v:M,z:y}}}return null}function _n(p){const g=/^\s*([10]?\d|2[0-4])(?::([0-5]\d|\d))?(?::([0-5]\d|\d))?(\.\d{1,10})?(?:\s*([AP])M?)?\s*$/i.exec(p);if(g){const[,R,w,v,k,M]=g;if(k&&!v||!M&&!w&&!v)return null;let V=1*(R||0);if(M){if(V>=13)return null;M[0]!=="p"&&M[0]!=="P"||(V+=12)}return{v:(60*V*60+60*(1*(w||0))+1*(v||0)+1*(k||0))/86400,z:(R.length===2?"hh":"h")+":mm"+(v?":ss":"")+(M?" AM/PM":"")}}return null}function fi(p){return/^\s*true\s*$/i.test(p)?{v:!0}:/^\s*false\s*$/i.test(p)?{v:!1}:null}const Xt={};function El(p,g){const{pattern:R,partitions:w,locale:v}=p,k=y=>{const j=Object.assign({},x(),g,y);return v&&(j.locale=v),j},M=(y,j)=>{const W=k(j);return function(F,G,re){const K=c(re.locale),B=G[3]?G[3]:oi;if(typeof F=="boolean"&&(F=F?"TRUE":"FALSE"),F==null)return"";if(typeof F!="number")return ii(F,B,re,K);if(!isFinite(F)){const q=K||E;return isNaN(F)?q.nan:(F<0?q.negative:"")+q.infinity}const Q=ai(F,G);return Q?ii(F,Q,re,K):re.overflow}(Vr(y,W),w,W)};M.color=(y,j)=>function(W,F){if(typeof W!="number"||!isFinite(W))return(F[3]?F[3].color:oi.color)||ui;const G=ai(W,F);return G&&G.color||ui}(Vr(y,k(j)),w);const V=function(y){var j;let W=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;const[F,G]=y,re=F.frac_max,K={type:"general",isDate:cl(y),isText:fl(y),isPercent:ll(y),maxDecimals:F.general?9:re,scale:(j=F.scale)!==null&&j!==void 0?j:1,color:0,parentheses:0,grouped:F.grouping?1:0,_partitions:y},B=!K.isDate&&!K.isText&&!F.error&&F.tokens.some(oe=>oe.type==="string"&&(W?oe.value===W:me.test(oe.value)));let Q="G",q=re>=0?Math.min(15,re):"",ie="",ue="";if(G&&G.color&&(ue="-",K.color=1),F.parens&&(ie="()",K.parentheses=1),B)Q="C",K.type="currency";else if(F.error)K.type="error",K.maxDecimals=0;else if(K.isDate){let oe=0,De=0,Je="";F.tokens.forEach(Y=>{const Be=Y.type;/^(b-)?year/.test(Be)?(Je+="Y",De++):Be.startsWith("month")?(Je+="M",De++):/^(week)?day/.test(Be)?(Je+="D",De++):Be!=="hour"&&Be!=="min"&&Be!=="sec"&&Be!=="am"||(Je+=Be[0],oe++)}),K.type="date",De&&oe?K.type="datetime":!De&&oe&&(K.type="time");const Et=ml.find(Y=>Je.startsWith(Y[0]));Q=Et?"D":"G",q=Et?Et[1]:""}else K.isText?(Q="G",K.type="text",q="",K.maxDecimals=0):F.general?(Q="G",K.type="general",q=""):F.fractions?(Q="G",K.type="fraction",q=""):F.exponential?(Q="S",K.type="scientific"):K.isPercent?(Q="P",K.type="percent"):F.grouping?(Q=",",K.type="grouped"):(F.int_max||re)&&(Q="F",K.type="number");return K.code=Q+q+ue+ie,K.level=hl[K.type],Object.freeze(K)}(w,(g||{}).currency)||new SyntaxError;return M.info=V,M.dateInfo=function(y){const[j]=y;return{year:!!(2&j.date),month:!!(4&j.date),day:!!(8&j.date),hours:!!(16&j.date),minutes:!!(32&j.date),seconds:!!(64&j.date),clockType:j.clock===12?12:24}}(w),M.isPercent=()=>!!V.isPercent,M.isDate=()=>!!V.isDate,M.isText=()=>!!V.isText,M.pattern=R,p.error&&(M.error=p.error),M.options=k,M.locale=v||g&&g.locale||"",Object.freeze(M)}function de(p,g){p||(p="General");let R=null;return Xt[p]?R=Xt[p]:(R=Object.assign({},x(),g).throws?Ht(p):function(w){try{return Ht(w)}catch(v){const k={tokens:[{type:"error"}],error:v.message};return{pattern:w,partitions:[k,k,k,k],error:v.message,locale:null}}}(p),R.error||(Xt[p]=R)),El(R,g)}de.isDate=p=>de(p,{throws:!1}).isDate(),de.isPercent=p=>de(p,{throws:!1}).isPercent(),de.isText=p=>de(p,{throws:!1}).isText(),de.getInfo=(p,g)=>de(p,{...g,throws:!1}).info,de.getDateInfo=(p,g)=>de(p,{...g,throws:!1}).dateInfo,de.dateToSerial=Vr,de.dateFromSerial=ti,de.options=x,de.dec2frac=C,de.round=D,de.codeToLocale=s,de.parseLocale=u,de.getLocale=c,de.addLocale=(p,g)=>{const R=u(g);return delete Xt[R.lang],delete Xt[R.language],d(p,R)},de.format=function(p,g,R){let w=arguments.length>3&&arguments[3]!==void 0&&arguments[3];const v=R&&typeof R=="object"?R:{locale:R,throws:!w};return de(p,v)(Vr(g,v),v)},de.is_date=de.isDate,de.parseNumber=li,de.parseDate=ci,de.parseTime=_n,de.parseBool=fi,de.parseValue=function(p,g){var R,w,v;return(R=(w=(v=li(p))!==null&&v!==void 0?v:ci(p,g))!==null&&w!==void 0?w:_n(p))!==null&&R!==void 0?R:fi(p)};var Cl=de;return t=t.default}()})})(Vs);var Co=Vs.exports,Do=Co;const yo=Eo(Do),bo=(r,n)=>yo.format(r,n);class So extends I{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=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=Re(t,s,n),a=Re(t,s,e);return i.map((o,u,l)=>{if(o.isError()||o.isString()||o.isBoolean())return o;let c=a.get(u,l)||Ee.create(" ");if(c.isError())return c;if(c.isBoolean())return h.create(f.VALUE);c.isNull()&&(c=Ee.create(" "));const m=`${c.getValue()}`;o.isNull()&&(o=b.create(0));const d=o.getValue(),E=bo(m,d);return Ee.create(E)})}}const xs=[[mo,pt.CONCATENATE],[go,pt.LEN],[Ro,pt.LENB],[So,pt.TEXT]],vs=[];var Lo=(r=>{})();const Ms=[];var Fs=(r=>(r.ENCODEURL="ENCODEURL",r.FILTERXML="FILTERXML",r.WEBSERVICE="WEBSERVICE",r))(Fs||{});class Bs extends _.Disposable{constructor(){super(...arguments);S(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const It=Z.createIdentifier("univer.formula.defined-names.service");var Ao=Object.defineProperty,wo=Object.getOwnPropertyDescriptor,Po=(r,n,e,t)=>{for(var s=t>1?void 0:t?wo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Ao(n,e,s),s},Vo=(r,n)=>(e,t)=>n(e,t,r);L.FormulaCurrentConfigService=class extends _.Disposable{constructor(e){super();S(this,"_unitData",{});S(this,"_arrayFormulaCellData",{});S(this,"_formulaData",{});S(this,"_sheetNameMap",{});S(this,"_forceCalculate",!1);S(this,"_dirtyRanges",[]);S(this,"_dirtyNameMap",{});S(this,"_numfmtItemMap",{});S(this,"_dirtyUnitFeatureMap",{});S(this,"_excludedCell");S(this,"_sheetIdToNameMap",{});this._currentUniverService=e}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},this._dirtyUnitFeatureMap={},this._excludedCell={},this._sheetIdToNameMap={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}getSheetName(e,t){return this._sheetIdToNameMap[e]==null?"":this._sheetIdToNameMap[e][t]||""}load(e){if(e.allUnitData&&e.unitSheetNameMap)this._unitData=e.allUnitData,this._sheetNameMap=e.unitSheetNameMap;else{const{allUnitData:t,unitSheetNameMap:s}=this._loadSheetData();this._unitData=t,this._sheetNameMap=s}this._formulaData=e.formulaData,this._arrayFormulaCellData=bn(e.arrayFormulaCellData),this._forceCalculate=e.forceCalculate,this._dirtyRanges=e.dirtyRanges,this._dirtyNameMap=e.dirtyNameMap,this._numfmtItemMap=e.numfmtItemMap,this._dirtyUnitFeatureMap=e.dirtyUnitFeatureMap,this._excludedCell=e.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(e,t){this._dirtyRanges=e,this._excludedCell=t,this._dirtyNameMap={}}registerUnitData(e){this._unitData=e}registerFormulaData(e){this._formulaData=e}registerSheetNameMap(e){this._sheetNameMap=e}_mergeNameMap(e,t){Object.keys(t).forEach(s=>{t[s]&&Object.keys(t[s]).forEach(i=>{e[s]==null&&(e[s]={}),e[s][t[s][i]]=i})}),this._sheetIdToNameMap={},Object.keys(e).forEach(s=>{Object.keys(e[s]).forEach(i=>{this._sheetIdToNameMap[s]==null&&(this._sheetIdToNameMap[s]={}),this._sheetIdToNameMap[s][e[s][i]]=i})})}_loadSheetData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},l={};for(const c of o){const m=c.getSheetId(),d=c.getConfig();u[m]={cellData:new _.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},l[c.getName()]=c.getSheetId()}t[a]=u,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}},L.FormulaCurrentConfigService=Po([Vo(0,_.IUniverInstanceService)],L.FormulaCurrentConfigService);const it=Z.createIdentifier("univer.formula.current-data.service");var xo=Object.defineProperty,vo=Object.getOwnPropertyDescriptor,Mo=(r,n,e,t)=>{for(var s=t>1?void 0:t?vo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&xo(n,e,s),s},Fo=(r,n)=>(e,t)=>n(e,t,r),$e=(r=>(r[r.IDLE=0]="IDLE",r[r.START_DEPENDENCY=1]="START_DEPENDENCY",r[r.START_CALCULATION=2]="START_CALCULATION",r[r.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",r[r.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",r[r.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",r[r.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",r[r.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",r))($e||{}),wt=(r=>(r[r.INITIAL=0]="INITIAL",r[r.STOP_EXECUTION=1]="STOP_EXECUTION",r[r.NOT_EXECUTED=2]="NOT_EXECUTED",r[r.SUCCESS=3]="SUCCESS",r))(wt||{});L.FormulaRuntimeService=class extends _.Disposable{constructor(e){super();S(this,"_formulaExecuteStage",0);S(this,"_stopState",!1);S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_currentRowCount",Number.NEGATIVE_INFINITY);S(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);S(this,"_currentSubUnitId","");S(this,"_currentUnitId","");S(this,"_runtimeData",{});S(this,"_runtimeOtherData",{});S(this,"_unitArrayFormulaRange",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeClearArrayFormulaCellData",{});S(this,"_numfmtItemMap",{});S(this,"_runtimeFeatureRange",{});S(this,"_runtimeFeatureCellData",{});S(this,"_functionsExecutedState",0);S(this,"_functionDefinitionPrivacyVar",new Map);S(this,"_totalFormulasToCalculate",0);S(this,"_completedFormulasCount",0);S(this,"_totalArrayFormulasToCalculate",0);S(this,"_completedArrayFormulasCount",0);S(this,"_isCycleDependency",!1);this._currentConfigService=e}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(e){this._totalArrayFormulasToCalculate=e}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(e){this._completedArrayFormulasCount=e}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(e){this._totalFormulasToCalculate=e}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(e){this._completedFormulasCount=e}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(e){this._formulaExecuteStage=e}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(e,t,s,i,a,o){this._currentRow=e,this._currentColumn=t,this._currentRowCount=s,this._currentColumnCount=i,this._currentSubUnitId=a,this._currentUnitId=o}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(e,t){this._functionDefinitionPrivacyVar.set(e,t)}getFunctionDefinitionPrivacyVar(e){return this._functionDefinitionPrivacyVar.get(e)}setRuntimeOtherData(e,t){const s=this._currentSubUnitId,i=this._currentUnitId;this._runtimeOtherData[i]===void 0&&(this._runtimeOtherData[i]={});const a=this._runtimeOtherData[i];a[s]===void 0&&(a[s]={});const o=a[s];o[e]=this._objectValueToCellValue(t)}setRuntimeData(e){const t=this._currentRow,s=this._currentColumn,i=this._currentRowCount,a=this.currentColumnCount,o=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const l=this._runtimeData[u];l[o]==null&&(l[o]=new _.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][o]==null&&(this._numfmtItemMap[u][o]={});const c=this._numfmtItemMap[u][o],m=this._unitArrayFormulaRange[u];let d=new _.ObjectMatrix;m[o]&&(d=new _.ObjectMatrix(m[o])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const E=this._runtimeArrayFormulaCellData[u];E[o]==null&&(E[o]=new _.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const D=this._runtimeClearArrayFormulaCellData[u];D[o]==null&&(D[o]=new _.ObjectMatrix);const C=l[o],A=E[o],P=D[o];if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const x=e,{startRow:U,startColumn:$,endRow:se,endColumn:he}=x.getRangePosition();if(U===se&&$===he){const J=x.getFirstCell(),z=this._objectValueToCellValue(J);C.setValue(t,s,z),P.setValue(t,s,z),c[t]==null&&(c[t]={}),c[t][s]=J.getPattern();return}const me={startRow:t,startColumn:s,endRow:se-U+t,endColumn:he-$+s};if(d.setValue(t,s,me),m[o]=d.getData(),this._checkIfArrayFormulaRangeHasData(u,o,t,s,me)||this._checkIfArrayFormulaExceeded(i,a,me)){const J=this._objectValueToCellValue(h.create(f.SPILL));C.setValue(t,s,J),P.setValue(t,s,J)}else{const J=h.create(f.SPILL);x.iterator((z,te,N)=>{const Fe=this._objectValueToCellValue(z);if(te===U&&N===$){if(z!=null&&z.isError()&&z.isEqualType(J))return P.setValue(t,s,{}),C.setValue(t,s,{...this._objectValueToCellValue(J)}),!1;C.setValue(t,s,{...Fe})}const We=te-U+t,Ht=N-$+s;A.setValue(We,Ht,Fe);const we=z==null?void 0:z.getPattern();we&&(c[We]==null&&(c[We]={}),c[We][Ht]=we)})}}else{const x=this._objectValueToCellValue(e);C.setValue(t,s,x),c[t]==null&&(c[t]={}),c[t][s]=e.getPattern(),P.setValue(t,s,x)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(e,t){this._runtimeFeatureRange[e]=t}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e,t){this._runtimeFeatureCellData[e]=t}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),numfmtItemMap:this.getNumfmtItemMap(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(e){if(e==null)return{v:0,t:_.CellValueType.NUMBER};if(e.isError())return{v:e.getErrorType(),t:_.CellValueType.STRING};if(e.isValueObject()){const t=e,s=t.getValue();return t.isNumber()?{v:s,t:_.CellValueType.NUMBER}:t.isBoolean()?{v:s,t:_.CellValueType.BOOLEAN}:t.isString()&&_.isRealNum(s)?{v:s,t:_.CellValueType.FORCE_STRING}:{v:s,t:_.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(e,t,s,i,a){var E,D,C,A,P,x,U,$,se,he,me,J;const{startRow:o,startColumn:u,endRow:l,endColumn:c}=a,m=this._currentConfigService.getUnitData(),d=(C=(D=(E=this._unitArrayFormulaRange[e])==null?void 0:E[t])==null?void 0:D[s])==null?void 0:C[i];for(let z=o;z<=l;z++)for(let te=u;te<=c;te++){if(z===s&&i===te)continue;const N=(x=(P=(A=this._runtimeData)==null?void 0:A[e])==null?void 0:P[t])==null?void 0:x.getValue(z,te),Fe=(se=($=(U=this._runtimeArrayFormulaCellData)==null?void 0:U[e])==null?void 0:$[t])==null?void 0:se.getValue(z,te),We=(J=(me=(he=m==null?void 0:m[e])==null?void 0:he[t])==null?void 0:me.cellData)==null?void 0:J.getValue(z,te);if(!_.isNullCell(N)||!_.isNullCell(Fe)&&!this._isInArrayFormulaRange(d,z,te)||!_.isNullCell(We))return!0}return!1}_isInArrayFormulaRange(e,t,s){if(e==null)return!1;const{startRow:i,startColumn:a,endRow:o,endColumn:u}=e;return t>=i&&t<=o&&s>=a&&s<=u}_checkIfArrayFormulaExceeded(e,t,s){return s.endRow>=e||s.endColumn>=t}_isInDirtyRange(e,t,s,i){const a=this._currentConfigService.getDirtyRanges();return a.length===0?!0:En(a,e,t,s,i)}},L.FormulaRuntimeService=Mo([Fo(0,it)],L.FormulaRuntimeService);const Me=Z.createIdentifier("univer.formula.runtime.service");var Bo=Object.defineProperty,Oo=Object.getOwnPropertyDescriptor,Uo=(r,n,e,t)=>{for(var s=t>1?void 0:t?Oo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Bo(n,e,s),s},on=(r,n)=>(e,t)=>n(e,t,r);let Pt=class extends _.Disposable{constructor(r,n,e){super(),this._definedNamesService=r,this._runtimeService=n,this._lexerTreeBuilder=e}treeBuilder(r,n=!0){return this._lexerTreeBuilder.treeBuilder(r,n,this._injectDefinedName.bind(this))}_injectDefinedName(r){var i;const n=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(n))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(r);let t="",s=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){t+=u;continue}const{nodeType:l,token:c}=u;if(l===ve.REFERENCE||l===ve.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(c);m?(t+=m,s=!0):t+=c}else t+=c}return{sequenceString:t,hasDefinedName:s}}};Pt=Uo([on(0,It),on(1,Me),on(2,Z.Inject(Zt))],Pt);var ne=(r=>(r.REFERENCE="ReferenceNode",r.VALUE="ValueNode",r.OPERATOR="OperatorNode",r.FUNCTION="FunctionNode",r.LAMBDA="LambdaNode",r.LAMBDA_PARAMETER="LambdaNodeParameter",r.ERROR="ErrorNode",r.BASE="Base",r.ROOT="Root",r.UNION="UnionNode",r.PREFIX="PrefixNode",r.SUFFIX="SuffixNode",r.NULL="NullNode",r))(ne||{});const Ye=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class xe extends _.Disposable{constructor(e){super();S(this,"_children",[]);S(this,"_parent");S(this,"_valueObject");S(this,"_calculateState",!1);S(this,"_async",!1);S(this,"_address",!1);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return ne.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(ft.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let o=0;o<i;o++){const u=t[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class ye extends xe{constructor(e){super(e);S(this,"_errorValueObject");this._errorValueObject=h.create(e)}get nodeType(){return ne.ERROR}static create(e){return new ye(e)}getValue(){return this._errorValueObject}}const ze=100;class Qe extends _.Disposable{get zIndex(){return 0}create(n,e,t){let s;return n instanceof ee?s=n.getToken():s=n,new xe(s)}checkAndCreateNodeType(n){}}class un extends xe{get nodeType(){return ne.ROOT}execute(){const e=this.getChildren()[0];e==null?this.setValue(h.create(f.VALUE)):this.setValue(e.getValue())}}class Os extends Qe{get zIndex(){return Ye.get(ne.ROOT)||ze}checkAndCreateNodeType(n){if(!(n instanceof ee))return;if(n.getToken()===et)return new un(et)}}class Us extends _.Disposable{constructor(){super(...arguments);S(this,"_functionExecutors",new Map);S(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const He=Z.createIdentifier("univer.formula.function.service");var ko=Object.defineProperty,To=Object.getOwnPropertyDescriptor,jo=(r,n,e,t)=>{for(var s=t>1?void 0:t?To(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&ko(n,e,s),s},ks=(r,n)=>(e,t)=>n(e,t,r);class lr extends xe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return ne.PREFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");e.isReferenceObject()&&(e=e.toArrayValueObject()),this._operatorString===_e.MINUS?t=this._functionExecutor.calculate(b.create(0),e):this._operatorString===_e.AT?t=this._handlerAT(e):t=h.create(f.VALUE),this.setValue(t)}_handlerAT(n){if(!n.isReferenceObject())return h.create(f.VALUE);const e=n;if(e.isCell())return h.create(f.VALUE);const t=this._accessor.get(Me),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():h.create(f.VALUE)}}let cr=class extends Qe{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return Ye.get(ne.PREFIX)||ze}checkAndCreateNodeType(r){if(!(r instanceof ee))return;const n=r.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===_e.MINUS)t=Le.MINUS;else return e===_e.AT?new lr(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new lr(this._injector,e,s):(console.error(`No function ${n}`),ye.create(f.NAME))}};cr=jo([ks(0,He),ks(1,Z.Inject(Z.Injector))],cr);function Ts(r,n,e){let t,s;const i=r.slice(0,2);let a=0;if(new RegExp(_e.MINUS,"g").test(i)){const o=n.getExecutor(Le.MINUS);t=new lr(e,_e.MINUS,o),a++}return new RegExp(_e.AT,"g").test(i)&&(s=new lr(e,_e.AT),t&&s.setParent(t),a++),a>0&&(r=r.slice(a)),{tokenTrim:r,minusPrefixNode:t,atPrefixNode:s}}var Io=Object.defineProperty,$o=Object.getOwnPropertyDescriptor,Yo=(r,n,e,t)=>{for(var s=t>1?void 0:t?$o(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Io(n,e,s),s},fr=(r,n)=>(e,t)=>n(e,t,r);class zo extends xe{constructor(n,e,t,s){super(n),this._functionExecutor=e,this._currentConfigService=t,this._runtimeService=s,this._functionExecutor.isAsync()&&this.setAsync(),this._functionExecutor.isAddress()&&this.setAddress()}get nodeType(){return ne.FUNCTION}async executeAsync(){const n=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;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(ft.SUCCESS)}execute(){const n=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const n=this.getChildren(),e=n.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=n[1].getValue(),s=n[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:o,startColumn:u,endRow:l,endColumn:c}=i,m=l-o+1,d=c-u+1,{startRow:E,startColumn:D,endRow:C,endColumn:A}=a,P=C-E+1,x=A-D+1;m!==P&&(a.endRow+=m-P),d!==x&&(a.endColumn+=d-x)}_calculate(n){var t;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=rt.create(s);else{const i=Ki(s);e=be.create({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,t,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 hr=class extends Qe{constructor(r,n,e,t){super(),this._functionService=r,this._currentConfigService=n,this._runtimeService=e,this._injector=t}get zIndex(){return Ye.get(ne.FUNCTION)||ze}create(r){const n=this._functionService.getExecutor(r);return n?new zo(r,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${r}`),ye.create(f.NAME))}checkAndCreateNodeType(r){if(typeof r=="string")return;const n=r.getToken(),{tokenTrim:e,minusPrefixNode:t,atPrefixNode:s}=Ts(n.trim(),this._functionService,this._injector);if(!Number.isNaN(Number(e)))return ye.create(f.VALUE);const i=e.toUpperCase();if(this._functionService.hasExecutor(i)){const a=this.create(i);return s?a.setParent(s):t&&a.setParent(t),a}}};hr=Yo([fr(0,He),fr(1,it),fr(2,Me),fr(3,Z.Inject(Z.Injector))],hr);var Qo=Object.defineProperty,Ho=Object.getOwnPropertyDescriptor,Wo=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ho(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Qo(n,e,s),s},Go=(r,n)=>(e,t)=>n(e,t,r);let Vt=class extends _.Disposable{constructor(r){super(),this._runtimeService=r}dispose(){}async executeAsync(r){if(!r)return h.create(f.VALUE);await this._executeAsync(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(r){if(!r)return h.create(f.VALUE);this._execute(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(r){return r.execute(),r.getValue()}checkAsyncNode(r){const n=[];this._checkAsyncNode(r,n);for(let e=0,t=n.length;e<t;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(r,n){const e=r.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(r){if(this._runtimeService.isStopExecution())return Promise.resolve(ft.ERROR);const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===Ut&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return r.nodeType===ne.FUNCTION&&r.isAsync()?await r.executeAsync():r.execute(),Promise.resolve(ft.SUCCESS)}_execute(r){if(this._runtimeService.isStopExecution())return ft.ERROR;const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===Ut&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return r.execute(),ft.SUCCESS}};Vt=Wo([Go(0,Me)],Vt);function js(r){return r instanceof ee?r.getToken()===Dt:!1}function Xo(r){return r instanceof ee?r.getToken()===xn:!1}function Is(r){if(!r)return;if(r.getToken()!==Ot)return r;const n=r,e=n.getCurrentLambdaPrivacyVar(),t=n.getLambdaParameter();if(!e)return;const s=e.get(t);return s==null&&r.getValue()?r:Is(s)}class ln extends Ze{constructor(e,t,s){super(0);S(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}static create(e,t,s){return new ln(e,t,s)}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return h.create(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new Ni(this._interpreter.executeAsync(this._lambdaNode));else{const i=this._interpreter.execute(this._lambdaNode);i.isReferenceObject()?s=i.toArrayValueObject():s=i}return this._lambdaNode.setNotEmpty(!0),s}_setLambdaNodeValue(e){const t=e.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.getToken()===Ot){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const c=a.getCurrentLambdaPrivacyVar(),m=Is(c.get(u));m!=null&&a.setValue(m.getValue())}continue}this._setLambdaNodeValue(a)}}_setLambdaPrivacyValueMap(e){for(let t=0;t<e.length;t++){const s=e[t],i=this._lambdaPrivacyVarKeys[t];this._lambdaPrivacyValueMap.set(i,s)}}}var Ko=Object.defineProperty,qo=Object.getOwnPropertyDescriptor,Zo=(r,n,e,t)=>{for(var s=t>1?void 0:t?qo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Ko(n,e,s),s},$s=(r,n)=>(e,t)=>n(e,t,r);class Jo extends xe{constructor(e,t,s,i){super(e);S(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return ne.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(ln.create(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let mr=class extends Qe{constructor(r,n){super(),this._runtimeService=r,this._interpreter=n}get zIndex(){return Ye.get(ne.LAMBDA)||ze}create(r){const n=r.getChildren(),e=n[0];let t=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof ee&&s instanceof ee))return ye.create(f.NAME);if(e.getToken()===Dt){const o=e.getChildren();if(t.length!==o.length)return ye.create(f.VALUE)}else t=n.slice(0,-1);const i=_.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof ee){const l=u.getChildren()[0];u.setToken(xn),a.set(l.trim(),void 0)}else return ye.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new Jo(r.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(r){if(!(!(r instanceof ee)||r.getToken().trim().toUpperCase()!==Ut))return this.create(r)}_updateLambdaStatement(r,n,e){this._updateTree(r,n,e)}_updateTree(r,n,e){const t=r.getChildren(),s=t.length,i=t[0];for(let a=0;a<s;a++){const o=t[a];if(!(js(i)&&a!==0))if(o instanceof ee)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const l=new ee;l.setToken(Ot),l.setLambdaId(n),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),t[a]=l}}}}};mr=Zo([$s(0,Me),$s(1,Z.Inject(Vt))],mr);function Ys(r){if(!r)return;if(r.getToken()!==Ot)return r;const n=r,e=n.getCurrentLambdaPrivacyVar(),t=n.getLambdaParameter();if(e)return Ys(e.get(t))}class No extends xe{constructor(n,e,t){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return ne.LAMBDA_PARAMETER}execute(){const n=Ys(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(h.create(f.SPILL))}}}class zs extends Qe{get zIndex(){return Ye.get(ne.LAMBDA_PARAMETER)||ze}create(n){const e=n.getFunctionDefinitionPrivacyVar(),t=n.getLambdaParameter();return e?new No(n.getToken(),t,e):new ye(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof ee)||n.getToken().trim()!==Ot))return this.create(n)}}class eu extends xe{constructor(n){super(n),this._operatorString=n}get nodeType(){return ne.NULL}execute(){this.setValue(ce.create())}}var tu=Object.defineProperty,ru=Object.getOwnPropertyDescriptor,nu=(r,n,e,t)=>{for(var s=t>1?void 0:t?ru(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&tu(n,e,s),s},su=(r,n)=>(e,t)=>n(e,t,r);class iu extends xe{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return ne.OPERATOR}execute(){var i,a;const n=this.getChildren();this._functionExecutor.name===Le.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=(i=n[0])==null?void 0:i.getValue(),t=(a=n[1])==null?void 0:a.getValue();const s=this.getToken();if((e==null||t==null)&&s!==pe.MINUS&&s!==pe.PLUS){this.setValue(h.create(f.VALUE));return}e==null&&(e=ce.create()),t==null&&(t=ce.create()),e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let dr=class extends Qe{constructor(r){super(),this._functionService=r}get zIndex(){return Ye.get(ne.OPERATOR)||ze}create(r){let n="";const e=r;e===pe.PLUS?n=Le.PLUS:e===pe.MINUS?n=Le.MINUS:e===pe.MULTIPLY?n=Le.MULTIPLY:e===pe.DIVIDED?n=Le.DIVIDED:e===pe.CONCATENATE?n=pt.CONCATENATE:e===pe.POWER?n=Ve.POWER:hi.has(e)&&(n=Le.COMPARE);const t=this._functionService.getExecutor(n);return t?new iu(e,t):(console.error(`No function ${r}`),ye.create(f.NAME))}checkAndCreateNodeType(r){if(r instanceof ee)return;const n=r.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&ot.has(n))return this.create(n)}};dr=nu([su(0,He)],dr);class au extends _.Disposable{constructor(){super(...arguments);S(this,"_tableMap",new Map);S(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const cn=Z.createIdentifier("univer.formula.super-table.service");class ou extends Lt{constructor(n,e,t,s){super(n),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,s),l=u.startColumn,c=u.endColumn,m=u.type;let d=-1,E=-1;const D=a.startRow,C=a.startColumn;m===ht.ALL?(d=D,E=C):m===ht.DATA?(d=D+1,E=C):m===ht.HEADERS?(d=D,E=D):m===ht.TOTALS&&(d=C,E=C),this.setRangeData({startColumn:l,endColumn:c,startRow:d,endRow:E})}isTable(){return!0}_stringToColumnData(n,e,t){n=n.substring(1,-1);const s=n.indexOf(X.COMMA);let i=-1,a=-1,o=ht.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=t.get(u),o||(o=ht.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,t=!1){var o,u,l;let s=-1,i=-1;const a=n.indexOf(X.COLON);if(new RegExp(Pn,"g").test(n)){const c=n.substring(0,a).substring(1,-1),m=n.substring(a+1).substring(1,-1);s=(o=e.get(c))!=null?o:-1,i=(u=e.get(m))!=null?u:-1}else t&&(n=n.substring(1,-1)),s=(l=e.get(n))!=null?l:-1,i=s;return{startColumn:s,endColumn:i}}}var uu=Object.defineProperty,lu=Object.getOwnPropertyDescriptor,cu=(r,n,e,t)=>{for(var s=t>1?void 0:t?lu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&uu(n,e,s),s},$t=(r,n)=>(e,t)=>n(e,t,r);class gr extends xe{constructor(n,e,t,s=!1){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return ne.REFERENCE}execute(){const n=this._accessor.get(it),e=this._accessor.get(Me);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.setNumfmtItemData(n.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(h.create(f.NAME)):this.setValue(this._referenceObject)}}let pr=class extends Qe{constructor(r,n,e,t,s){super(),this._definedNamesService=r,this._superTableService=n,this._formulaRuntimeService=e,this._functionService=t,this._injector=s}get zIndex(){return Ye.get(ne.REFERENCE)||ze}checkAndCreateNodeType(r){var u,l;let n=!1,e,t=!1;r instanceof ee?(n=!0,e=r.getToken().trim(),((l=(u=r.getParent())==null?void 0:u.getParent())==null?void 0:l.getToken().trim())===X.COLON&&(t=!0)):e=r.trim();const{tokenTrim:s,minusPrefixNode:i,atPrefixNode:a}=Ts(e,this._functionService,this._injector);if(!n&&s.charAt(0)==='"'&&s.charAt(s.length-1)==='"')return;let o;if(new RegExp(Bt).test(s))o=new gr(this._injector,s,new Nr(s),t);else if(n&&new RegExp(An).test(s))o=new gr(this._injector,s,new en(s),t);else if(n&&new RegExp(wn).test(s))o=new gr(this._injector,s,new tn(s),t);else{const c=this._formulaRuntimeService.currentUnitId,m=this._superTableService.getTableMap(c),d=new RegExp(Pn,"g"),E=s.replace(d,"");if(!n&&(m!=null&&m.has(E))){const D=d.exec(s);let C="";D&&(C=D[0]);const A=m.get(E),P=this._superTableService.getTableOptionMap();o=new gr(this._injector,s,new ou(s,A,C,P))}}if(o)return a?o.setParent(a):i&&o.setParent(i),o}};pr=cu([$t(0,It),$t(1,cn),$t(2,Me),$t(3,He),$t(4,Z.Inject(Z.Injector))],pr);var fu=Object.defineProperty,hu=Object.getOwnPropertyDescriptor,mu=(r,n,e,t)=>{for(var s=t>1?void 0:t?hu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&fu(n,e,s),s},Qs=(r,n)=>(e,t)=>n(e,t,r);class Hs extends xe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return ne.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===Xe.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,b.create(100)),t.isNumber()&&t.setPattern("0.00%")):this._operatorString===Xe.POUND?t=this._handlerPound(e):t=h.create(f.VALUE),this.setValue(t)}_handlerPound(n){var c,m,d,E;if(!n.isReferenceObject()||!n.isCell())return h.create(f.VALUE);const e=this._accessor.get(it),t=this._accessor.get(Pt),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(E=(d=(m=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:m[i.startRow])==null?void 0:d[i.startColumn])==null?void 0:E.f;return l&&t.treeBuilder(l),h.create(f.VALUE)}}let Rr=class extends Qe{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return Ye.get(ne.SUFFIX)||ze}checkAndCreateNodeType(r){if(!(r instanceof ee))return;const n=r.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===Xe.PERCENTAGE)e=Le.DIVIDED;else return n===Xe.POUND?new Hs(this._injector,n):void 0;const t=this._functionService.getExecutor(e);return t?new Hs(this._injector,n,t):(console.error(`No function ${r}`),ye.create(f.NAME))}};Rr=mu([Qs(0,He),Qs(1,Z.Inject(Z.Injector))],Rr);var du=Object.defineProperty,gu=Object.getOwnPropertyDescriptor,pu=(r,n,e,t)=>{for(var s=t>1?void 0:t?gu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&du(n,e,s),s},Ru=(r,n)=>(e,t)=>n(e,t,r);class _u extends xe{constructor(n){super(n),this._operatorString=n}get nodeType(){return ne.UNION}execute(){const n=this.getChildren(),e=n[0].getValue(),t=n[1].getValue();if(e==null||t==null)throw new Error("leftNode and rightNode");let s;this._operatorString===X.COLON?s=this._unionFunction(e,t):s=h.create(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()||!n.isReferenceObject()||!e.isReferenceObject()?h.create(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):h.create(f.REF))}}let _r=class extends Qe{constructor(r){super(),this._functionService=r}get zIndex(){return Ye.get(ne.UNION)||ze}create(r){return new _u(r)}checkAndCreateNodeType(r){if(!(r instanceof ee))return;const e=r.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===X.COLON)return this.create(e)}};_r=pu([Ru(0,He)],_r);class Eu extends xe{constructor(n){super(n),this._operatorString=n}get nodeType(){return ne.VALUE}execute(){this.setValue(rt.create(this._operatorString))}}class Ws extends Qe{get zIndex(){return Ye.get(ne.VALUE)||ze}_checkValueNode(n){if(Number.isNaN(Number(n))){const e=n.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(Mt.has(e))return this.create(e);if(t==='"'&&s==='"')return this.create(e);if(t==="{"&&s==="}")return this.create(e);const i=e.toUpperCase();if(i===ct.TRUE||i===ct.FALSE)return this.create(i)}else return this.create(n)}create(n){return new Eu(n)}checkAndCreateNodeType(n){if(!(n instanceof ee))return this._checkValueNode(n)}}function Cu(r){let n=r;for(;n!=null&&n.getParent();)n=n.getParent();return n}var Du=Object.defineProperty,yu=Object.getOwnPropertyDescriptor,bu=(r,n,e,t)=>{for(var s=t>1?void 0:t?yu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Du(n,e,s),s},ke=(r,n)=>(e,t)=>n(e,t,r);let Yt=class extends _.Disposable{constructor(n,e,t,s,i,a,o,u,l,c,m){super();S(this,"_astNodeFactoryList",[]);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=l,this._unionNodeFactory=c,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,t=0){const s=new un(et);return this._refOffsetX=e,this._refOffsetY=t,this._parse(n,s)}_lambdaParameterHandler(n,e){const t=e.getLambdaId(),s=new un(et),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let m=0;m<u;m++){const d=o[m];if(d instanceof ee)this._parse(d,s);else return!1}const l=s.getChildren(),c=l.length;for(let m=0;m<c;m++){const d=l[m];i.set(a[m],d)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new ee;s.setToken(Ut);const i=new ee;i.setToken(Dt);const a=[...e];for(let u=0;u<t;u++){const l=a[u];if(!(l instanceof ee))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}_parse(n,e){const t=n.getChildren(),s=t.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===Di){const c=this._changeLetToLambda(n);return c!=null?this._parse(c,e):ye.create(f.ERROR)}if(o===Ke){if(a=e,s===0)return new eu(et).setParent(e),a}else{if(o===Dt){let c=this._lambdaParameterHandler(n,e);return c===!1&&(c=ye.create(f.ERROR)),c}if(a=this._checkAstNode(n),a==null)return ye.create(f.ERROR)}const u=t[0];for(let c=0;c<s;c++){const m=t[c];if(js(u)){if(c!==0&&c!==s-1)continue}else if(Xo(m)&&c!==s-1)continue;let d=null;if(m instanceof ee){if(d=this._parse(m,a),d===a)continue}else d=this._checkAstNode(m);if(d==null)return ye.create(f.NAME);if(d=Cu(d),d==null)return;switch(d.nodeType){case ne.ERROR:return d;case ne.FUNCTION:i.push(d);break;case ne.LAMBDA:i.push(d);break;case ne.LAMBDA_PARAMETER:i.push(d);break;case ne.OPERATOR:{const E=i.pop(),D=i.pop();D&&D.setParent(d),E&&E.setParent(d),i.push(d);break}case ne.REFERENCE:d.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(d);break;case ne.ROOT:i.push(d);break;case ne.UNION:i.push(d);break;case ne.VALUE:i.push(d);break;case ne.PREFIX:i.push(d);break;case ne.SUFFIX:i.push(d);break}}const l=i.length;for(let c=0;c<l;c++)i[c].setParent(a);return a}_checkAstNode(n){let e=null;const t=this._astNodeFactoryList.length;for(let s=0;s<t&&(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(_.sortRules)}};Yt=bu([ke(0,Me),ke(1,Z.Inject(Os)),ke(2,Z.Inject(hr)),ke(3,Z.Inject(mr)),ke(4,Z.Inject(zs)),ke(5,Z.Inject(dr)),ke(6,Z.Inject(cr)),ke(7,Z.Inject(pr)),ke(8,Z.Inject(Rr)),ke(9,Z.Inject(_r)),ke(10,Z.Inject(Ws))],Yt);class Gs extends _.Disposable{constructor(){super(...arguments);S(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Er=Z.createIdentifier("univer.formula.feature-calculation-manager.service");class Xs extends _.Disposable{constructor(){super(...arguments);S(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:t,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]&&(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const fn=Z.createIdentifier("univer.formula.other-formula-manager.service");class hn extends _.Disposable{constructor(){super(...arguments);S(this,"node");S(this,"children",[]);S(this,"parents",[]);S(this,"formula","");S(this,"row",-1);S(this,"column",-1);S(this,"rowCount",Number.NEGATIVE_INFINITY);S(this,"columnCount",Number.NEGATIVE_INFINITY);S(this,"subUnitId","");S(this,"unitId","");S(this,"rangeList",[]);S(this,"formulaId");S(this,"featureId");S(this,"getDirtyData");S(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const l=this.rangeList[o],{unitId:c,sheetId:m,range:d}=l.gridRange;if(((i=t[c])==null?void 0:i[m])!=null)return!0;if(!e.has(c))continue;const E=e.get(c);if(!E.has(m))continue;const D=E.get(m),C=(a=s==null?void 0:s[c])==null?void 0:a[m];let{startRow:A,endRow:P,startColumn:x,endColumn:U}=d;Number.isNaN(A)&&(A=0),Number.isNaN(x)&&(x=0),Number.isNaN(P)&&(P=Number.POSITIVE_INFINITY),Number.isNaN(U)&&(U=Number.POSITIVE_INFINITY);for(const $ of D){const{startRow:se,startColumn:he,endRow:me,endColumn:J}=$;if(!(A>me||P<se||x>J||U<he)){let z=!0;if(C==null||C.forValue((te,N)=>{if(te>=A&&te<=P&&N>=x&&N<=U)return z=!1,!1}),z)return!0}}}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let t=0,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.gridRange.unitId,o=i.gridRange.sheetId,u=i.gridRange.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}class Su extends _.Disposable{constructor(){super(...arguments);S(this,"_cacheItems",new Map)}dispose(){this.clear()}size(){return this._cacheItems.size}add(e,t){const{token:s}=e;if(!this._cacheItems.has(s)){this._cacheItems.set(s,{unitRangeWithToken:e,treeList:[t]});return}this._cacheItems.get(s).treeList.push(t)}clear(){this._cacheItems.clear()}remove(e,t){if(!this._cacheItems.has(e))return;const s=this._cacheItems.get(e),i=s.treeList.indexOf(t);i!==-1&&s.treeList.splice(i,1)}delete(e){this._cacheItems.delete(e)}dependency(e){this._cacheItems.forEach(t=>{const{unitRangeWithToken:s,treeList:i}=t,{gridRange:a}=s,{unitId:o,sheetId:u,range:l}=a;e.unitId===o&&e.subUnitId===u&&e.inRangeData(l)&&i.forEach(c=>{if(c===e)return!0;c.pushChildren(e)})})}}var Lu=Object.defineProperty,Au=Object.getOwnPropertyDescriptor,wu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Au(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Lu(n,e,s),s},Rt=(r,n)=>(e,t)=>n(e,t,r);const Pu=1e5,mn=new ut(Pu);let zt=class extends _.Disposable{constructor(n,e,t,s,i,a,o){super();S(this,"_updateRangeFlattenCache",new Map);S(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),mn.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),{treeList:s,dependencyTreeCache:i}=await this._generateTreeList(n,e,t),a=this._getUpdateTreeListAndMakeDependency(s,i);this._checkIsCycleDependency(a)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(a);return Promise.resolve(u)}_isCyclicUtil(n,e,t){if(!e.has(n)){e.add(n),t.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,t)||t.has(n.children[s]))return!0}return t.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,t=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(n,e,t){const s=Object.keys(n),i=Object.keys(e),a=[];for(const u of s){const l=n[u];if(l==null)continue;const c=Object.keys(l);for(const m of c)new _.ObjectMatrix(l[m]).forValue((E,D,C)=>{if(C==null)return!0;const{f:A,x:P,y:x}=C,U=this._generateAstNode(A,P,x),$=new hn,se=t[u][m];$.node=U,$.formula=A,$.unitId=u,$.subUnitId=m,$.row=E,$.column=D,$.rowCount=se.rowCount,$.columnCount=se.columnCount,a.push($)})}for(const u of i){const l=e[u];if(l==null)continue;const c=Object.keys(l);for(const m of c){const d=l[m];if(d==null)continue;const E=Object.keys(d);for(const D of E){const C=d[D],{f:A}=C,P=this._generateAstNode(A),x=new hn;x.node=P,x.formula=A,x.unitId=u,x.subUnitId=m,x.formulaId=D,a.push(x)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,l)=>{const{unitId:c,subUnitId:m,dependencyRanges:d,getDirtyData:E}=u,D=new hn;D.unitId=c,D.subUnitId=m,D.getDirtyData=E,D.featureId=l,D.rangeList=d.map(C=>({gridRange:C,token:yt({...C,sheetName:this._currentConfigService.getSheetName(C.unitId,C.sheetId)})})),a.push(D)});const o=new Su;for(let u=0,l=a.length;u<l;u++){const c=a[u];if(this._runtimeService.setCurrent(c.row,c.column,c.rowCount,c.columnCount,c.subUnitId,c.unitId),c.node==null)continue;const m=await this._getRangeListByNode(c.node);for(let d=0,E=m.length;d<E;d++){const D=m[d];c.pushRangeList(D),o.add(D,c)}}return{treeList:a,dependencyTreeCache:o}}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,t=0){let s=mn.get(`${n}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(Mt.has(i))return ye.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return mn.set(`${n}##${e}${t}`,s),s}_addFlattenCache(n,e,t){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(t)}_isPreCalculateNode(n){return n.nodeType===ne.UNION||n.nodeType===ne.PREFIX&&n.getToken()===_e.AT||n.nodeType===ne.SUFFIX&&n.getToken()===Xe.POUND}_nodeTraversalRef(n,e){const t=n.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(this._isPreCalculateNode(a)){e.push(a);continue}else a.nodeType===ne.REFERENCE&&e.push(a);this._nodeTraversalRef(a,e)}}_nodeTraversalReferenceFunction(n,e){const t=n.getChildren(),s=t.length;for(let i=0;i<s;i++){const a=t[i];if(a.nodeType===ne.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=[],t=[];this._nodeTraversalRef(n,e),this._nodeTraversalReferenceFunction(n,t);const s=[];for(let i=0,a=e.length;i<a;i++){const o=e[i],l=(await this._executeNode(o)).toUnitRange(),c=yt({...l,sheetName:this._currentConfigService.getSheetName(l.unitId,l.sheetId)});s.push({gridRange:l,token:c})}for(let i=0,a=t.length;i<a;i++){const o=t[i],l=(await this._executeNode(o)).toUnitRange(),c=yt({...l,sheetName:this._currentConfigService.getSheetName(l.unitId,l.sheetId)});s.push({gridRange:l,token:c})}return s}_getUpdateTreeListAndMakeDependency(n,e){const t=[],s=new Set,i=this._currentConfigService.isForceCalculate();let a=!0;e.size()>n.length&&(a=!1);for(let o=0,u=n.length;o<u;o++){const l=n[o];if(a)e.dependency(l);else for(let c=0,m=n.length;c<m;c++){const d=n[c];l!==d&&l.dependency(d)&&l.pushChildren(d)}(i||l.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(l))&&!s.has(l)&&(t.push(l),s.add(l))}return e.dispose(),t}_includeTree(n){var l,c,m,d,E;const e=n.unitId,t=n.subUnitId,s=n.featureId;if(s!=null){const D=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=D==null?void 0:D[e])==null?void 0:l[t])==null?void 0:c[s])!=null)return!0}const i=(d=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:d[t];let a=!1;if(i==null||i.forValue((D,C)=>{if(n.row===D&&n.column===C)return a=!0,!1}),a)return!1;if(((E=this._dirtyUnitSheetNameMap[e])==null?void 0:E[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(t))return!1;const u=o.get(t);for(const D of u)if(n.inRangeData(D))return!0;return!1}_calculateRunList(n){let e=n;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];u.isAdded()||s.isSkip()||i.push(u)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};zt=wu([_.OnLifecycle(_.LifecycleStages.Rendered,zt),Rt(0,it),Rt(1,Me),Rt(2,fn),Rt(3,Er),Rt(4,Z.Inject(Vt)),Rt(5,Z.Inject(Yt)),Rt(6,Z.Inject(Pt))],zt);var Vu=Object.defineProperty,xu=Object.getOwnPropertyDescriptor,vu=(r,n,e,t)=>{for(var s=t>1?void 0:t?xu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Vu(n,e,s),s},_t=(r,n)=>(e,t)=>n(e,t,r);const Mu=1;L.CalculateFormulaService=class extends _.Disposable{constructor(e,t,s,i,a,o,u){super();S(this,"_executionStartListener$",new vr.Subject);S(this,"executionStartListener$",this._executionStartListener$.asObservable());S(this,"_executionCompleteListener$",new vr.Subject);S(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());S(this,"_executionInProgressListener$",new vr.Subject);S(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,t){this._runtimeService.setRuntimeFeatureCellData(e,t)}setRuntimeFeatureRange(e,t){this._runtimeService.setRuntimeFeatureRange(e,t)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const t=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||Mu;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage($e.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Zr.clear(),tt.clear()}async _execute(){const e=await this._apply();if(e==null)return;const{arrayFormulaRange:t,runtimeFeatureRange:s}=e,{dirtyRanges:i,excludedCell:a}=this._getArrayFormulaDirtyRangeAndExcludedRange(t,s);return i==null||i.length===0||(this._currentConfigService.loadDirtyRangesAndExcludedCell(i,a),await this._apply(!0)),!0}_getArrayFormulaDirtyRangeAndExcludedRange(e,t){const s=[],i={};return Object.keys(e).forEach(a=>{const o=e[a];if(o==null)return!0;Object.keys(o).forEach(u=>{const l=new _.ObjectMatrix(o[u]);if(l==null)return!0;const c=new _.ObjectMatrix;l.forValue((m,d,E)=>{c.setValue(m,d,!0),s.push({unitId:a,sheetId:u,range:E})}),i[a]==null&&(i[a]={}),i[a][u]=c})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const l=o[u];if(l==null)return!0;Object.keys(l).forEach(c=>{const m=l[c];if(m==null)return!0;for(const d of m)s.push({unitId:u,sheetId:c,range:d})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage($e.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage($e.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage($e.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage($e.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(t.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=t.length;i<a;i++){if(await new Promise(m=>{_.requestImmediateMacroTask(m)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage($e.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,l=o.getDirtyData;let c;if(u==null&&l==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),l!=null&&o.featureId!=null){const{runtimeCellData:m,dirtyRanges:d}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,m),this._runtimeService.setRuntimeFeatureRange(o.featureId,d)}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($e.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage($e.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return t.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,t=!0){const s=this._lexer.treeBuilder(e,t);if(Object.values(f).includes(s))return ye.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}},L.CalculateFormulaService=vu([_.OnLifecycle(_.LifecycleStages.Rendered,L.CalculateFormulaService),_t(0,_.IConfigService),_t(1,Z.Inject(Pt)),_t(2,it),_t(3,Me),_t(4,Z.Inject(zt)),_t(5,Z.Inject(Vt)),_t(6,Z.Inject(Yt))],L.CalculateFormulaService);const dn={id:"formula.mutation.set-numfmt-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>(r.get(L.FormulaDataModel).updateNumfmtItemMap(n.numfmtItemMap),!0)};var Fu=Object.defineProperty,Bu=Object.getOwnPropertyDescriptor,Ou=(r,n,e,t)=>{for(var s=t>1?void 0:t?Bu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Fu(n,e,s),s},Cr=(r,n)=>(e,t)=>n(e,t,r);let Dr=class extends _.Disposable{constructor(r,n,e,t){super(),this._commandService=r,this._calculateFormulaService=n,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((r,n)=>{if(r.id===Yr.id)this._calculateFormulaService.stopFormulaExecution();else if(r.id===Qr.id){const e=r.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(r.id===$r.id){const e=r.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:s,dirtyUnitFeatureMap:i,numfmtItemMap:a}=e;this._calculate(!1,t,s,i,a)}}else if(r.id===Jt.id){const e=r.params;if(e==null)return;const{arrayFormulaRange:t,arrayFormulaCellData:s}=e;this._formulaDataModel.setArrayFormulaRange(t),this._formulaDataModel.setArrayFormulaCellData(s)}}))}async _calculate(r=!1,n=[],e={},t={},s={}){if(n.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&r===!1)return;const i=this._formulaDataModel.getFormulaData(),a=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:i,arrayFormulaCellData:a,forceCalculate:r,dirtyRanges:n,dirtyNameMap:e,dirtyUnitFeatureMap:t,numfmtItemMap:s})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(r=>{const n=r.functionsExecutedState;switch(n){case wt.NOT_EXECUTED:break;case wt.STOP_EXECUTION:break;case wt.SUCCESS:this._applyFormula(r);break;case wt.INITIAL:break}this._commandService.executeCommand(tr.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(r=>{this._commandService.executeCommand(tr.id,{stageInfo:r},{onlyLocal:!0})})}async _applyFormula(r){const{unitData:n,unitOtherData:e,arrayFormulaRange:t,arrayFormulaCellData:s,clearArrayFormulaCellData:i,numfmtItemMap:a}=r;if(!n){console.error("No sheetData from Formula Engine!");return}t&&(this._formulaDataModel.clearPreviousArrayFormulaCellData(i),this._formulaDataModel.mergeArrayFormulaCellData(s),this._formulaDataModel.mergeArrayFormulaRange(t),this._commandService.executeCommand(Jt.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),_.Tools.isEmptyObject(a)||this._commandService.executeCommand(dn.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(zr.id,{unitData:Ri(n),unitOtherData:e},{onlyLocal:!0})}};Dr=Ou([_.OnLifecycle(_.LifecycleStages.Ready,Dr),Cr(0,_.ICommandService),Cr(1,Z.Inject(L.CalculateFormulaService)),Cr(2,_.IUniverInstanceService),Cr(3,Z.Inject(L.FormulaDataModel))],Dr);var Uu=Object.defineProperty,ku=Object.getOwnPropertyDescriptor,Tu=(r,n,e,t)=>{for(var s=t>1?void 0:t?ku(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Uu(n,e,s),s},gn=(r,n)=>(e,t)=>n(e,t,r);let Qt=class extends _.Disposable{constructor(r=[],n,e,t){super(),this._function=r,this._commandService=n,this._injector=e,this._functionService=t,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[Qr,Jt,$r,Yr,tr,zr,dn,Nt,er,jr,Ir,Hr,Wr,jn,In,Gr,Mr,Xr].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_registerFunctions(){const r=[...is,...cs,...fs,...ms,...gs,...ps,..._s,...Cs,...Ds,...ys,...Ls,...As,...Ps,...xs,...vs,...Ms].concat(this._function).map(n=>{const e=n[0],t=n[1];return new e(t)});this._functionService.registerExecutors(...r)}};Qt=Tu([_.OnLifecycle(_.LifecycleStages.Ready,Qt),gn(1,_.ICommandService),gn(2,Z.Inject(Z.Injector)),gn(3,He)],Qt);var ju=Object.defineProperty,Iu=Object.getOwnPropertyDescriptor,$u=(r,n,e,t)=>{for(var s=t>1?void 0:t?Iu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&ju(n,e,s),s},pn=(r,n)=>(e,t)=>n(e,t,r);let yr=class extends _.Disposable{constructor(r,n,e){super(),this._commandService=r,this._formulaDataModel=n,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((r,n)=>{if(r.id===Mr.id){const e=r.params;if(e==null)return;const{functions:t}=e,s=t.map(i=>{const a=i[0],o=i[1];return zu(a,o)});this._functionService.registerExecutors(...s)}else if(r.id===Xr.id){const e=r.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};yr=$u([_.OnLifecycle(_.LifecycleStages.Ready,yr),pn(0,_.ICommandService),pn(1,Z.Inject(L.FormulaDataModel)),pn(2,He)],yr);class Yu extends I{isCustom(){return!0}}function zu(r,n){const e=new Yu(n),t=new Function(`return ${r}`)();return e.calculateCustom=t,e}var Qu=Object.defineProperty,Hu=Object.getOwnPropertyDescriptor,Wu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Hu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Qu(n,e,s),s},Ks=(r,n)=>(e,t)=>n(e,t,r);let br=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._definedNamesService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===Nt.id){const n=r.params;if(n==null)return;const{unitId:e,name:t,formulaOrRefString:s}=n;this._definedNamesService.registerDefinedName(e,t,s)}else if(r.id===er.id){const n=r.params;if(n==null)return;const{unitId:e,name:t}=n;this._definedNamesService.removeDefinedName(e,t)}}))}};br=Wu([_.OnLifecycle(_.LifecycleStages.Ready,br),Ks(0,_.ICommandService),Ks(1,It)],br);var Gu=Object.defineProperty,Xu=Object.getOwnPropertyDescriptor,Ku=(r,n,e,t)=>{for(var s=t>1?void 0:t?Xu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Gu(n,e,s),s},qs=(r,n)=>(e,t)=>n(e,t,r);let Sr=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._featureCalculationManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===jr.id){const n=r.params;if(n==null)return;const{featureId:e,calculationParam:t}=n;this._featureCalculationManagerService.register(e,t)}else if(r.id===Ir.id){const n=r.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};Sr=Ku([_.OnLifecycle(_.LifecycleStages.Ready,Sr),qs(0,_.ICommandService),qs(1,Er)],Sr);var qu=Object.defineProperty,Zu=Object.getOwnPropertyDescriptor,Ju=(r,n,e,t)=>{for(var s=t>1?void 0:t?Zu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&qu(n,e,s),s},Zs=(r,n)=>(e,t)=>n(e,t,r);let Lr=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._otherFormulaManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===Hr.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(r.id===Wr.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};Lr=Ju([_.OnLifecycle(_.LifecycleStages.Ready,Lr),Zs(0,_.ICommandService),Zs(1,fn)],Lr);var Nu=Object.defineProperty,el=Object.getOwnPropertyDescriptor,tl=(r,n,e,t)=>{for(var s=t>1?void 0:t?el(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Nu(n,e,s),s},Js=(r,n)=>(e,t)=>n(e,t,r);let Ar=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._superTableService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===Nt.id){const n=r.params;if(n==null)return;const{unitId:e,tableName:t,reference:s}=n;this._superTableService.registerTable(e,t,s)}else if(r.id===er.id){const n=r.params;if(n==null)return;const{unitId:e,tableName:t}=n;this._superTableService.remove(e,t)}else if(r.id===Gr.id){const n=r.params;if(n==null)return;const{tableOption:e,tableOptionType:t}=n;this._superTableService.registerTableOptionMap(e,t)}}))}};Ar=tl([_.OnLifecycle(_.LifecycleStages.Ready,Ar),Js(0,_.ICommandService),Js(1,cn)],Ar);var rl=Object.defineProperty,nl=Object.getOwnPropertyDescriptor,sl=(r,n,e,t)=>{for(var s=t>1?void 0:t?nl(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&rl(n,e,s),s},il=(r,n)=>(e,t)=>n(e,t,r);const al="base-formula-engine";L.UniverFormulaEnginePlugin=class extends _.Plugin{constructor(n,e){super(al),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[He,{useClass:Us}],[Er,{useClass:Gs}],[It,{useClass:Bs}],[L.FormulaDataModel],[Zt],[Qt,{useFactory:()=>{var t;return this._injector.createInstance(Qt,(t=this._config)==null?void 0:t.function)}}],[Sr]];(e=this._config)!=null&&e.notExecuteFormula||n.push([L.CalculateFormulaService],[fn,{useClass:Xs}],[cn,{useClass:au}],[it,{useClass:L.FormulaCurrentConfigService}],[Me,{useClass:L.FormulaRuntimeService}],[Dr],[br],[Lr],[Ar],[yr],[zt],[Vt],[Yt],[Pt],[Os],[hr],[mr],[zs],[dr],[cr],[pr],[Rr],[_r],[Ws]),n.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(L.FormulaDataModel).initFormulaData()}},L.UniverFormulaEnginePlugin=sl([il(1,Z.Inject(Z.Injector))],L.UniverFormulaEnginePlugin),L.ArrayValueObject=be,L.BaseFunction=I,L.BaseReferenceObject=Lt,L.BaseValueObject=Ze,L.BooleanValueObject=H,L.DefinedNamesService=Bs,L.ErrorType=f,L.ErrorValueObject=h,L.FUNCTION_NAMES_ARRAY=ra,L.FUNCTION_NAMES_COMPATIBILITY=At,L.FUNCTION_NAMES_CUBE=hs,L.FUNCTION_NAMES_DATABASE=ds,L.FUNCTION_NAMES_DATE=nt,L.FUNCTION_NAMES_ENGINEERING=Rs,L.FUNCTION_NAMES_FINANCIAL=Es,L.FUNCTION_NAMES_INFORMATION=Ue,L.FUNCTION_NAMES_LOGICAL=st,L.FUNCTION_NAMES_LOOKUP=Se,L.FUNCTION_NAMES_MATH=Ve,L.FUNCTION_NAMES_STATISTICAL=Ae,L.FUNCTION_NAMES_TEXT=pt,L.FUNCTION_NAMES_UNIVER=Lo,L.FUNCTION_NAMES_WEB=Fs,L.FeatureCalculationManagerService=Gs,L.FormulaExecuteStageType=$e,L.FormulaExecutedStateType=wt,L.FunctionService=Us,L.FunctionType=Cn,L.IDefinedNamesService=It,L.IFeatureCalculationManagerService=Er,L.IFormulaCurrentConfigService=it,L.IFormulaRuntimeService=Me,L.IFunctionService=He,L.LexerNode=ee,L.LexerTreeBuilder=Zt,L.NumberValueObject=b,L.OtherFormulaManagerService=Xs,L.RangeReferenceObject=jt,L.RegisterFunctionMutation=Mr,L.RemoveDefinedNameMutation=er,L.RemoveFeatureCalculationMutation=Ir,L.RemoveOtherFormulaMutation=Wr,L.RemoveSuperTableMutation=In,L.SetArrayFormulaDataMutation=Jt,L.SetArrayFormulaDataUndoMutationFactory=Mi,L.SetDefinedNameMutation=Nt,L.SetFeatureCalculationMutation=jr,L.SetFormulaCalculationNotificationMutation=tr,L.SetFormulaCalculationResultMutation=zr,L.SetFormulaCalculationStartMutation=$r,L.SetFormulaCalculationStopMutation=Yr,L.SetFormulaDataMutation=Qr,L.SetNumfmtFormulaDataMutation=dn,L.SetOtherFormulaMutation=Hr,L.SetSuperTableMutation=jn,L.SetSuperTableOptionMutation=Gr,L.StringValueObject=Ee,L.UnregisterFunctionMutation=Xr,L.ValueObjectFactory=rt,L.compareToken=O,L.convertUnitDataToRuntime=bn,L.deserializeRangeForR1C1=ss,L.deserializeRangeWithSheet=bt,L.functionArray=is,L.functionCompatibility=cs,L.functionCube=fs,L.functionDatabase=ms,L.functionDate=gs,L.functionEngineering=ps,L.functionFinancial=_s,L.functionInformation=Cs,L.functionLogical=Ds,L.functionLookup=ys,L.functionMath=Ls,L.functionMeta=As,L.functionStatistical=Ps,L.functionText=xs,L.functionUniver=vs,L.functionWeb=Ms,L.generateStringWithSequence=On,L.getAbsoluteRefTypeWitString=Li,L.getAbsoluteRefTypeWithSingleString=kt,L.includeFormulaLexerToken=yn,L.initSheetFormulaData=Tn,L.isFormulaLexerToken=Ft,L.isInDirtyRange=En,L.isReferenceString=Vn,L.matchRefDrawToken=pi,L.matchToken=X,L.normalizeSheetName=gi,L.operatorToken=pe,L.sequenceNodeType=ve,L.serializeRange=lt,L.serializeRangeToRefString=yt,L.serializeRangeWithSheet=Mn,L.serializeRangeWithSpreadsheet=Fn,Object.defineProperty(L,Symbol.toStringTag,{value:"Module"})});
|