@univerjs/engine-formula 0.1.1 → 0.1.2

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.
Files changed (88) hide show
  1. package/README.md +6 -2
  2. package/lib/cjs/index.js +1 -1
  3. package/lib/es/index.js +4630 -3883
  4. package/lib/types/basics/__tests__/regex.spec.d.ts +16 -0
  5. package/lib/types/basics/common.d.ts +3 -1
  6. package/lib/types/basics/date.d.ts +8 -0
  7. package/lib/types/basics/regex.d.ts +8 -6
  8. package/lib/types/engine/reference-object/base-reference-object.d.ts +2 -0
  9. package/lib/types/engine/utils/__tests__/math-kit.spec.d.ts +16 -0
  10. package/lib/types/engine/utils/__tests__/object-covert.spec.d.ts +16 -0
  11. package/lib/types/engine/utils/math-kit.d.ts +7 -0
  12. package/lib/types/engine/utils/object-covert.d.ts +18 -0
  13. package/lib/types/engine/utils/reference.d.ts +0 -3
  14. package/lib/types/engine/value-object/array-value-object.d.ts +26 -5
  15. package/lib/types/engine/value-object/base-value-object.d.ts +12 -0
  16. package/lib/types/engine/value-object/primitive-object.d.ts +3 -0
  17. package/lib/types/functions/base-function.d.ts +11 -1
  18. package/lib/types/functions/compatibility/function-map.d.ts +3 -1
  19. package/lib/types/functions/date/day/index.d.ts +1 -0
  20. package/lib/types/functions/date/month/index.d.ts +1 -0
  21. package/lib/types/functions/date/year/index.d.ts +1 -0
  22. package/lib/types/functions/information/iserr/__tests__/index.spec.d.ts +16 -0
  23. package/lib/types/functions/information/iserr/index.d.ts +20 -0
  24. package/lib/types/functions/information/iserror/__tests__/index.spec.d.ts +16 -0
  25. package/lib/types/functions/information/iserror/index.d.ts +20 -0
  26. package/lib/types/functions/information/islogical/__tests__/index.spec.d.ts +16 -0
  27. package/lib/types/functions/information/islogical/index.d.ts +20 -0
  28. package/lib/types/functions/information/isna/__tests__/index.spec.d.ts +16 -0
  29. package/lib/types/functions/information/isna/index.d.ts +20 -0
  30. package/lib/types/functions/information/isnontext/__tests__/index.spec.d.ts +16 -0
  31. package/lib/types/functions/information/isnontext/index.d.ts +20 -0
  32. package/lib/types/functions/information/isnumber/__tests__/index.spec.d.ts +16 -0
  33. package/lib/types/functions/information/isnumber/index.d.ts +20 -0
  34. package/lib/types/functions/information/isref/__tests__/index.spec.d.ts +16 -0
  35. package/lib/types/functions/information/isref/index.d.ts +22 -0
  36. package/lib/types/functions/information/istext/__tests__/index.spec.d.ts +16 -0
  37. package/lib/types/functions/information/istext/index.d.ts +20 -0
  38. package/lib/types/functions/logical/function-map.d.ts +2 -1
  39. package/lib/types/functions/logical/iferror/index.d.ts +2 -1
  40. package/lib/types/functions/lookup/column/__tests__/index.spec.d.ts +16 -0
  41. package/lib/types/functions/lookup/column/index.d.ts +21 -0
  42. package/lib/types/functions/lookup/columns/__tests__/index.spec.d.ts +16 -0
  43. package/lib/types/functions/lookup/columns/index.d.ts +20 -0
  44. package/lib/types/functions/lookup/function-map.d.ts +6 -1
  45. package/lib/types/functions/lookup/index/__test__/index.spec.d.ts +16 -0
  46. package/lib/types/functions/lookup/index/index.d.ts +24 -0
  47. package/lib/types/functions/lookup/lookup/index.d.ts +1 -0
  48. package/lib/types/functions/lookup/row/__tests__/index.spec.d.ts +16 -0
  49. package/lib/types/functions/lookup/row/index.d.ts +21 -0
  50. package/lib/types/functions/lookup/rows/__tests__/index.spec.d.ts +16 -0
  51. package/lib/types/functions/lookup/rows/index.d.ts +20 -0
  52. package/lib/types/functions/lookup/xlookup/index.d.ts +1 -1
  53. package/lib/types/functions/math/function-map.d.ts +3 -1
  54. package/lib/types/functions/math/mod/__tests__/index.spec.d.ts +16 -0
  55. package/lib/types/functions/math/mod/index.d.ts +20 -0
  56. package/lib/types/functions/math/power/__tests__/index.spec.d.ts +16 -0
  57. package/lib/types/functions/math/power/index.d.ts +2 -3
  58. package/lib/types/functions/math/product/__tests__/index.spec.d.ts +16 -0
  59. package/lib/types/functions/math/product/index.d.ts +21 -0
  60. package/lib/types/functions/math/subtotal/__tests__/index.spec.d.ts +16 -0
  61. package/lib/types/functions/math/subtotal/index.d.ts +38 -0
  62. package/lib/types/functions/math/sum/__tests__/index.spec.d.ts +16 -0
  63. package/lib/types/functions/statistical/average/__tests__/index.spec.d.ts +16 -0
  64. package/lib/types/functions/statistical/count/__tests__/index.spec.d.ts +16 -0
  65. package/lib/types/functions/statistical/counta/__tests__/index.spec.d.ts +16 -0
  66. package/lib/types/functions/statistical/counta/index.d.ts +1 -1
  67. package/lib/types/functions/statistical/function-map.d.ts +2 -2
  68. package/lib/types/functions/statistical/max/__tests__/index.spec.d.ts +16 -0
  69. package/lib/types/functions/statistical/min/__tests__/index.spec.d.ts +16 -0
  70. package/lib/types/functions/statistical/stdev-p/__tests__/index.spec.d.ts +16 -0
  71. package/lib/types/functions/statistical/stdev-p/index.d.ts +20 -0
  72. package/lib/types/functions/statistical/stdev-s/__tests__/index.spec.d.ts +16 -0
  73. package/lib/types/functions/statistical/stdev-s/index.d.ts +20 -0
  74. package/lib/types/functions/statistical/stdeva/__tests__/index.spec.d.ts +16 -0
  75. package/lib/types/functions/statistical/stdeva/index.d.ts +20 -0
  76. package/lib/types/functions/statistical/stdevpa/__tests__/index.spec.d.ts +16 -0
  77. package/lib/types/functions/statistical/stdevpa/index.d.ts +20 -0
  78. package/lib/types/functions/statistical/var-p/__tests__/index.spec.d.ts +16 -0
  79. package/lib/types/functions/statistical/var-p/index.d.ts +20 -0
  80. package/lib/types/functions/statistical/var-s/__tests__/index.spec.d.ts +16 -0
  81. package/lib/types/functions/statistical/var-s/index.d.ts +20 -0
  82. package/lib/types/functions/statistical/vara/__tests__/index.spec.d.ts +16 -0
  83. package/lib/types/functions/statistical/vara/index.d.ts +20 -0
  84. package/lib/types/functions/statistical/varpa/__tests__/index.spec.d.ts +16 -0
  85. package/lib/types/functions/statistical/varpa/index.d.ts +20 -0
  86. package/lib/types/index.d.ts +3 -3
  87. package/lib/umd/index.js +1 -1
  88. package/package.json +4 -4
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var In=Object.defineProperty;var Qn=(r,n,e)=>n in r?In(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var _=(r,n,e)=>(Qn(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),A=require("@wendellhu/redi"),Bt=require("rxjs");function Fr(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 h=(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))(h||{});const wt=new Set(Object.values(h));var $r=(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))($r||{}),K=(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))(K||{}),y=(r=>(r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(y||{});const rt=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),je=new Set(rt.keys()),Yn=new Set(["=","<>",">",">=","<","<="]);var U=(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))(U||{}),ce=(r=>(r.PERCENTAGE="%",r.POUND="#",r))(ce||{});const jn=new Set(["%","#"]);var Q=(r=>(r.AT="@",r.MINUS="-",r))(Q||{});const kr=[...Object.values(y),...Object.values(K),...Object.values(U),...Object.values(ce),...Object.values(Q)];function nt(r){return kr.includes(r)}function Tr(r){for(const n of kr)if(r.indexOf(n)>-1)return!0;return!1}function Hn(r){return r[0]==="'"&&r[r.length-1]==="'"?r.substring(1,r.length-1):r}function Ir(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 d.ObjectMatrix(i)})}),n}const Gt={id:"formula.mutation.register-function",type:d.CommandType.MUTATION,handler:()=>!0};class Dt{constructor(n){_(this,"_cache");this._cache=new d.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 d.hashAlgorithm(n)}}const he='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Wn=/[^0-9]/g,Xn=/[^A-Za-z]/g;function He(r){const n=r[0]==="$",t=r.substring(1).indexOf("$")>-1;return n&&t?d.AbsoluteRefType.ALL:n?d.AbsoluteRefType.COLUMN:t?d.AbsoluteRefType.ROW:d.AbsoluteRefType.NONE}function Gn(r){const n=r.split("!");n.length>1&&(r=n[n.length-1]);const e=r.split(":");return e.length>1?{startAbsoluteRefType:He(e[0]),endAbsoluteRefType:He(e[1])}:{startAbsoluteRefType:He(e[0])}}function gr(r=d.AbsoluteRefType.NONE){let n="",e="";return r===d.AbsoluteRefType.ROW?n="$":r===d.AbsoluteRefType.COLUMN?e="$":r===d.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function Se(r){const{startColumn:n,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=d.RANGE_TYPE.NORMAL}=r,u=gr(i),l=gr(a);if(o===d.RANGE_TYPE.ROW||o===d.RANGE_TYPE.ALL){const g=`${u.rowAbsoluteString}${e+1}`,R=`${l.rowAbsoluteString}${s+1}`;return`${g}:${R}`}if(o===d.RANGE_TYPE.COLUMN){const g=`${u.columnAbsoluteString}${d.Tools.chatAtABC(n)}`,R=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}`;return`${g}:${R}`}const c=`${u.columnAbsoluteString}${d.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return c===m?c:`${c}:${m}`}function Qr(r,n){return ct(r)?`'${r}'!${Se(n)}`:`${r}!${Se(n)}`}function Yr(r,n,e){return ct(r)||ct(n)?`'[${r}]${n}'!${Se(e)}`:`[${r}]${n}!${Se(e)}`}function jr(r){const{unitId:n,sheetName:e,range:t}=r;return n!=null&&n.length>0&&e!=null&&e.length>0?Yr(n,e,t):e!=null&&e.length>0?Qr(e,t):Se(t)}function Ut(r){const n=Number.parseInt(r.replace(Wn,""))-1,e=d.Tools.ABCatNum(r.replace(Xn,"")),t=He(r);return{row:n,column:e,absoluteRefType:t}}function Hr(r){const n=new RegExp(he).exec(r);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),r=r.replace(new RegExp(he),""));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 ke(r){const{refBody:n,sheetName:e,unitId:t}=Hr(r),s=n.indexOf(":");if(s===-1){const E=Ut(n),p=E.row,C=E.column,D=E.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:p,startColumn:C,endRow:p,endColumn:C,startAbsoluteRefType:D,endAbsoluteRefType:D}}}const i=n.substring(0,s),a=n.substring(s+1),o=Ut(i),u=Ut(a),l=o.row,c=o.column,m=u.row,g=u.column;let R=d.RANGE_TYPE.NORMAL;return isNaN(l)&&isNaN(m)?R=d.RANGE_TYPE.COLUMN:isNaN(c)&&isNaN(g)&&(R=d.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:l,startColumn:c,endRow:m,endColumn:g,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:R}}}function ct(r){return r.length===0?!1:!!(Tr(r)||Kn(r)||qn(r)||zn(r)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(r))}function Kn(r){const n=r.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(r)&&n!==null&&Number.parseInt(n[0],10)<=1048576}function qn(r){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(r)}function zn(r){return!new RegExp("^\\p{Letter}","u").test(r.charAt(0))}const Te="((?![\\[\\]\\/?*\\\\]).)*!",pe="$",Kt="\\s*?:\\s*?",Yt=`\\${pe}?[A-Za-z]+\\${pe}?[0-9]+`,Zn=`^(${Q.AT})?(${he})?(${Te})?${Yt}${Kt}${Yt}$`,yt=`^(${he})?(${Te})?\\s*?${Yt}(${ce.POUND})?$`,Wr=`^(${he})?(${Te})?\\${pe}?[0-9]+${Kt}\\${pe}?[0-9]+$`,Xr=`^(${he})?(${Te})?\\${pe}?[A-Za-z]+${Kt}\\${pe}?[A-Za-z]+$`,Jn=`^(${he})?(${Te})?\\s*?\\${pe}?[0-9]+$`,Nn=`^(${he})?(${Te})?\\s*?\\${pe}?[A-Za-z]+$`,Gr="[.*?]",es="{.*?}";function ts(r){return new RegExp(yt).test(r)||new RegExp(Zn).test(r)||new RegExp(Wr).test(r)||new RegExp(Xr).test(r)}const De="P_1",Re="R_1",Fe="L_1",ze="LR_1",Kr="LO_1",rs="LET",Ge="LAMBDA";var Z=(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))(Z||{});function qr(r){let n="";for(const e of r)typeof e=="string"?n+=e:n+=e.token;return n}class v{constructor(){_(this,"_parent");_(this,"_token",Re);_(this,"_children",[]);_(this,"_lambdaId");_(this,"_functionDefinitionPrivacyVar");_(this,"_lambdaParameter","");_(this,"_startIndex",-1);_(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const 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 v?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 zr=1e5,Ot=new Dt(zr),Mt=new Dt(zr);class bt extends d.Disposable{constructor(){super(...arguments);_(this,"_currentLexerNode",new v);_(this,"_upLevel",0);_(this,"_segment","");_(this,"_bracketState",[]);_(this,"_squareBracketState",0);_(this,"_bracesState",0);_(this,"_singleQuotationState",0);_(this,"_doubleQuotationState",0);_(this,"_lambdaState",!1);_(this,"_colonState",!1);_(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Ot.clear(),Mt.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const s=this._getCurrentParamIndex(e,t);if(s==null||s===h.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!==De&&!nt(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!==Z.REFERENCE){a.push(l);continue}const{token:c}=l,m=ke(c),{range:g,sheetName:R,unitId:E}=m,p=d.Rectangle.moveOffset(g,t,s);let C="";d.isValidRange(p)?C=jr({range:p,unitId:E,sheetName:R}):C=h.REF,a.push({...l,token:C})}return`=${qr(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===U.CLOSE_BRACKET||i===" ")&&s>=0;)i===U.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===h.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(a[1]===U.OPEN_BRACKET&&l++;u;){const c=u.getToken();c!==De&&c!==U.COLON&&u.getStartIndex()!==-1&&c.toUpperCase()!==Ge&&(t===0?l+=1:t--),u=u.getParent()}return l}sequenceNodesBuilder(e){const t=Mt.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Mt.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,cur:m}=o;if(c===U.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(c);continue}let g=(u==null?void 0:u.segment)||"";const R=i-g.length;let E=i-1;const p=i-1;if(i===a-1&&this._isLastMergeString(c)&&(g+=c,E+=1),g===""||rt.has(g)){t.push(c);continue}const C=g.trim(),D=this._replacePrefixString(C);s===!0&&C[C.length-1]===U.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(t,{nodeType:Z.STRING,token:g,startIndex:R,endIndex:E},p)):new RegExp(yt).test(D)?this._pushSequenceNode(t,{nodeType:Z.REFERENCE,token:g,startIndex:R,endIndex:E},p):d.Tools.isStringNumber(C)?this._pushSequenceNode(t,{nodeType:Z.NUMBER,token:g,startIndex:R,endIndex:E},p):C.length>0&&this._pushSequenceNode(t,{nodeType:Z.FUNCTION,token:g,startIndex:R,endIndex:E},p),(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===U.DOUBLE_QUOTATION||d.Tools.isStringNumber(e)||!nt(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()===U.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===Z.FUNCTION&&o.token.trim().substring(0,1)===U.OPEN_BRACES){o.nodeType=Z.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===U.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&ts((a.token+o+u.token).trim())&&(a.nodeType=Z.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){return e.replace(new RegExp(Q.AT,"g"),"").replace(new RegExp(Q.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const c=Ot.get(e);if(c)return c}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re);const i=[];let a=this._nodeMaker(e,i);if(a===h.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(Re),a=this._nodeMaker(`=${u}`),a===h.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),t&&(this._suffixExpressionHandler(this._currentLexerNode),Ot.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const t=e.getChildren();if(!t)return;const s=t.length,i=[],a=[];for(let l=0;l<s;l++){const c=t[l];if(c instanceof v)this._suffixExpressionHandler(c),i.push(c);else{const m=c.trim();if(m==="")continue;if(je.has(m)){for(;a.length>0;){const g=(o=a[a.length-1])==null?void 0:o.trim();if(!g||g===U.OPEN_BRACKET)break;const R=rt.get(g),E=rt.get(m);if(!R||!E)break;if(E>=R)i.push(a.pop());else break}a.push(c)}else if(m===U.OPEN_BRACKET)a.push(c);else if(m===U.CLOSE_BRACKET)for(;a.length>0;){const g=(u=a[a.length-1])==null?void 0:u.trim();if(!g)break;if(g===U.OPEN_BRACKET){a.pop();break}i.push(a.pop())}else i.push(c)}}for(;a.length>0;)i.push(a.pop());e.setChildren(i)}_resetCurrentLexerNode(){this._currentLexerNode=new v}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof v)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()===Fe){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 v)&&this.isColonOpen()){const i=new v;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 v;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!!(je.has(e)||e===U.OPEN_BRACKET||e===U.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new v,this._upLevel=0,this._segment="",this._bracketState=[],this._bracesState=0,this._singleQuotationState=0,this._doubleQuotationState=0,this._lambdaState=!1,this._colonState=!1}_checkSimilarErrorToken(e,t,s){if(e!==ce.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!nt(i)}_nodeMaker(e,t,s){e.substring(0,1)===K.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(s===o)return[this._currentLexerNode,u];if(u===U.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===U.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(De,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===U.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const c=i[o+1];if(c&&c===U.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return h.VALUE;this._newAndPushCurrentLexerNode(Fe,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return h.VALUE}else return h.VALUE;this._closeBracket()}else if(u===U.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===U.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===U.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===U.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===U.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===U.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===U.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===U.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===U.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return h.VALUE;this._newAndPushCurrentLexerNode(De,o)}else return h.VALUE}else if(u===U.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new v;l.setToken(u);const c=new v;c.setToken(De),c.setParent(l);const m=new v;m.setToken(De),m.setParent(l),l.getChildren().push(c,m);let g=l,R=0;if(this._segmentCount()>0){let E,p,C=0;const D=this._segment.trim(),b=D[0],L=D[1];if(b===Q.MINUS&&(E=new v,E.setToken(Q.MINUS),C++),(b===Q.AT||L===Q.AT)&&(p=new v,p.setToken(Q.AT),E&&(E.addChildren(p),p.setParent(E)),C++),C>0&&(this._segment=D.slice(C)),R=C,p)if(p.addChildren(l),l.setParent(p),p.getParent()){const $=p.getParent();$&&(g=$)}else g=p;else E&&(g=E,E.addChildren(l),l.setParent(E));const S=new v;S.setToken(this._segment),S.setParent(c),c.getChildren().push(S),this._resetSegment()}else{const E=this._getLastChildCurrentLexerNode();E&&E.changeToParent(c)}this._setCurrentLexerNode(g),this._currentLexerNode=m,this._openColon(R)}else if(jn.has(u)&&this._checkSimilarErrorToken(u,o,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new v;l.setToken(u);const c=this._getLastChildCurrent();c instanceof v?c.changeToParent(l):c!==!1&&(l.getChildren().push(c),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(je.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===K.MINUS&&l===""){const c=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(c)){this._pushSegment(K.MINUS),t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===K.LESS_THAN||u===K.GREATER_THAN){const c=i[o+1];c&&je.has(u+c)?(this._pushNodeToChildren(l+u+c),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var ns=Object.defineProperty,ss=Object.getOwnPropertyDescriptor,is=(r,n,e,t)=>{for(var s=t>1?void 0:t?ss(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&&ns(n,e,s),s},dr=(r,n)=>(e,t)=>n(e,t,r);exports.FormulaDataModel=class extends d.Disposable{constructor(e,t){super();_(this,"_formulaData",{});_(this,"_arrayFormulaRange",{});_(this,"_arrayFormulaCellData",{});_(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,g;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 d.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,E)=>{var S;const p=(S=o==null?void 0:o[R])==null?void 0:S[E];if(p==null)return!0;const{startRow:C,startColumn:D,endRow:b,endColumn:L}=p;for(let $=C;$<=b;$++)for(let I=D;I<=L;I++)u.setValue($,I,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,g;const a=s[i];let o=new d.ObjectMatrix,u=new d.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(o=new d.ObjectMatrix((c=this._arrayFormulaRange[t])==null?void 0:c[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,E)=>{const p=o==null?void 0:o.getValue(R,E);if(p==null)return!0;const{startRow:C,startColumn:D,endRow:b,endColumn:L}=p;for(let S=C;S<=b;S++)for(let $=D;$<=L;$++)u.setValue(S,$,null)}),a.forValue((R,E,p)=>{u.setValue(R,E,p)}),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 d.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 d.ObjectMatrix(s[i]);let o=new d.ObjectMatrix;(u=this._arrayFormulaRange[t])!=null&&u[i]&&(o=new d.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((c,m,g)=>{o.setValue(c,m,g)}),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 d.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=o.getData()))}initFormulaData(){this._currentUniverService.getAllUniverSheetsInstance();const e=this._currentUniverService.getCurrentUniverSheetInstance(),t=e.getUnitId();this._formulaData[t]={},e.getSheets().forEach(i=>{const a=i.getCellMatrix(),o=i.getSheetId();Zr(this._formulaData,t,o,a)})}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(),g=c.getConfig();u[m]={cellData:new d.ObjectMatrix(g.cellData),rowCount:g.rowCount,columnCount:g.columnCount},l[c.getName()]=c.getSheetId()}t[a]=u,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new d.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 d.ObjectMatrix(l[t]);i.forValue((m,g,R)=>{const E=(R==null?void 0:R.f)||"",p=(R==null?void 0:R.si)||"",C=d.isFormulaString(E),D=d.isFormulaId(p);if(C&&D)c.setValue(m,g,{f:E,si:p}),a.set(p,{f:E,r:m,c:g});else if(C&&!D)c.setValue(m,g,{f:E});else if(!C&&D)c.setValue(m,g,{f:"",si:p});else if(!C&&!D&&c.getValue(m,g)){const b=c.getValue(m,g),L=(b==null?void 0:b.f)||"",S=(b==null?void 0:b.si)||"";d.isFormulaString(L)&&d.isFormulaId(S)&&o.set(S,L),c.realDeleteValue(m,g)}}),c.forValue((m,g,R)=>{const E=(R==null?void 0:R.f)||"",p=(R==null?void 0:R.si)||"";if(d.isFormulaId(p)){const C=a.get(p),D=o.get(p);if(C&&!d.isFormulaString(E)){const b=C.f,L=g-C.c,S=m-C.r;c.setValue(m,g,{f:b,si:p,x:L,y:S})}else if(typeof D=="string"){const b=R.x||0,L=R.y||0,S=this._lexerTreeBuilder.moveFormulaRefOffset(D,b,L);o.set(p,{r:m,c:g,f:S}),c.setValue(m,g,{f:S,si:p})}else if(typeof D=="object"){const b=g-D.c,L=m-D.r;c.setValue(m,g,{f:D.f,si:p,x:b,y:L})}}})}updateArrayFormulaRange(e,t,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(!i)return;const a=new d.ObjectMatrix(i);new d.ObjectMatrix(s).forValue((l,c,m)=>{if((a==null?void 0:a.getValue(l,c))==null)return!0;const R=(m==null?void 0:m.f)||"",E=(m==null?void 0:m.si)||"",p=d.isFormulaString(R),C=d.isFormulaId(E);!p&&!C&&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 d.ObjectMatrix(i),o=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!o)return;const u=new d.ObjectMatrix(o);new d.ObjectMatrix(s).forValue((g,R,E)=>{const p=a==null?void 0:a.getValue(g,R);if(p==null)return!0;const C=(E==null?void 0:E.f)||"",D=(E==null?void 0:E.si)||"",b=d.isFormulaString(C),L=d.isFormulaId(D);if(!b&&!L){const{startRow:S,startColumn:$,endRow:I,endColumn:k}=p;for(let P=S;P<=I;P++)for(let x=$;x<=k;x++)u.realDeleteValue(P,x)}})}updateNumfmtData(e,t,s){var c,m;const i=(c=this._arrayFormulaRange[e])==null?void 0:c[t],a=new d.ObjectMatrix(i),o=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!o)return;const u=new d.ObjectMatrix(o);new d.ObjectMatrix(s).forValue((g,R,E)=>{const p=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"",D=d.isFormulaString(p),b=d.isFormulaId(C);if(!D&&!b){u.setValue(g,R,null);const L=a.getValue(g,R);if(L){const{startRow:S,startColumn:$,endRow:I,endColumn:k}=L;for(let P=S;P<=I;P++)for(let x=$;x<=k;x++)u.setValue(P,x,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 d.ObjectMatrix(a[t]);let u=null;return o.forValue((l,c,m)=>{const{f:g,si:R,x:E=0,y:p=0}=m;if(R===e&&g.length>0&&E===0&&p===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 d.ObjectMatrix(a[t]).forValue((u,l,c)=>{const m=(c==null?void 0:c.f)||"",g=(c==null?void 0:c.si)||"",R=(c==null?void 0:c.x)||0,E=(c==null?void 0:c.y)||0;d.isFormulaString(m)&&d.isFormulaId(g)&&R===0&&E===0&&s.set(g,{f:m,r:u,c:l})}),s}};exports.FormulaDataModel=is([dr(0,d.IUniverInstanceService),dr(1,A.Inject(bt))],exports.FormulaDataModel);function Zr(r,n,e,t){const s=new Map,i=new d.ObjectMatrix;t.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",c=(u==null?void 0:u.si)||"",m=d.isFormulaString(l),g=d.isFormulaId(c);m&&g?(i.setValue(a,o,{f:l,si:c}),s.set(c,{f:l,r:a,c:o})):m&&!g?i.setValue(a,o,{f:l}):!m&&g&&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(d.isFormulaId(c)&&!d.isFormulaString(l)){const m=s.get(c);if(m){const g=m.f,R=o-m.c,E=a-m.r;i.setValue(a,o,{f:g,si:c,x:R,y:E})}}}),r[n]&&(r[n][e]=i.getData())}const as=r=>{const n=r.get(exports.FormulaDataModel),e=d.Tools.deepClone(n.getArrayFormulaRange()),t=d.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},ht={id:"formula.mutation.set-array-formula-data",type:d.CommandType.MUTATION,handler:(r,n)=>{const e=r.get(exports.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Lt={id:"formula.mutation.set-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},St={id:"formula.mutation.remove-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},qt={id:"formula.mutation.set-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},zt={id:"formula.mutation.remove-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},Zt={id:"formula.mutation.set-formula-calculation-start",type:d.CommandType.MUTATION,handler:()=>!0},Jt={id:"formula.mutation.set-formula-calculation-stop",type:d.CommandType.MUTATION,handler:()=>!0},ft={id:"formula.mutation.set-formula-calculation-notification",type:d.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.set-formula-calculation-result",type:d.CommandType.MUTATION,handler:()=>!0},er={id:"formula.mutation.set-formula-data",type:d.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).setFormulaData(n.formulaData),!0)},tr={id:"formula.mutation.set-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},rr={id:"formula.mutation.remove-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},Jr={id:"formula.mutation.set-super-table",type:d.CommandType.MUTATION,handler:()=>!0},Nr={id:"formula.mutation.remove-super-table",type:d.CommandType.MUTATION,handler:()=>!0},nr={id:"formula.mutation.set-super-table-option",type:d.CommandType.MUTATION,handler:()=>!0},sr={id:"formula.mutation.unregister-function",type:d.CommandType.MUTATION,handler:()=>!0};class Pt extends d.Disposable{constructor(){super(...arguments);_(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 Pe=(r=>(r.FALSE="FALSE",r.TRUE="TRUE",r))(Pe||{}),Le=(r=>(r[r.SUCCESS=0]="SUCCESS",r[r.ERROR=1]="ERROR",r))(Le||{}),ye=(r=>(r.ALL="#All",r.DATA="#Data",r.HEADERS="#Headers",r.TOTALS="#Totals",r))(ye||{}),te=(r=>(r[r.FRONT=0]="FRONT",r[r.BACK=1]="BACK",r))(te||{});class os{constructor(){_(this,"_cache",new Map);_(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=[],u.set(s,l)),l.push(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 me=new os;var ue=(r=>(r[r.MIN=0]="MIN",r[r.MAX=1]="MAX",r))(ue||{}),X=(r=>(r[r.NORMAL=0]="NORMAL",r[r.MIN=1]="MIN",r[r.MAX=2]="MAX",r))(X||{});function Rr(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(r,n)=>r.localeCompare(n)}function us(r){return r.indexOf("*")>-1||r.indexOf("?")>-1}function pr(r,n){const e=n.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(r)}function Er(r){return r.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function ls(r,n,e){let t=!1;switch(e){case y.EQUALS:t=pr(r,n);break;case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:t=pr(r,n)||r>Er(n);break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:t=r<Er(n);break}return t}class Ce extends Pt{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return new f(h.VALUE)}max(){return new f(h.VALUE)}min(){return new f(h.VALUE)}count(){return new f(h.VALUE)}countA(){return new f(h.VALUE)}countBlank(){return new f(h.VALUE)}getNegative(){return new f(h.NAME)}getReciprocal(){return new f(h.NAME)}plus(n){return new f(h.NAME)}minus(n){return new f(h.NAME)}multiply(n){return new f(h.NAME)}divided(n){return new f(h.NAME)}map(n){return new f(h.NAME)}mapValue(n){return new f(h.NAME)}product(n,e){return e(this,n)}compare(n,e){return new f(h.NAME)}isEqual(n){return this.compare(n,y.EQUALS)}isNotEqual(n){return this.compare(n,y.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,y.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,y.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,y.LESS_THAN)}isGreaterThan(n){return this.compare(n,y.GREATER_THAN)}concatenateFront(n){return new f(h.NAME)}concatenateBack(n){return new f(h.NAME)}plusBy(n){return new f(h.NAME)}minusBy(n){return new f(h.NAME)}multiplyBy(n){return new f(h.NAME)}dividedBy(n){return new f(h.NAME)}compareBy(n,e){return new f(h.NAME)}concatenate(n,e=te.FRONT){let t=this.getValue().toString();if(typeof n=="string")e===te.FRONT?t=n+t:t+=n;else if(typeof n=="number")e===te.FRONT?t=n.toString()+t:t+=n.toString();else if(typeof n=="boolean"){const s=n?"TRUE":"FALSE";e===te.FRONT?t=s+t:t+=s}return t}pow(n){return new f(h.VALUE)}powInverse(n){return new f(h.VALUE)}sqrt(){return new f(h.VALUE)}cbrt(){return new f(h.VALUE)}cos(){return new f(h.VALUE)}acos(){return new f(h.VALUE)}acosh(){return new f(h.VALUE)}sin(){return new f(h.VALUE)}asin(){return new f(h.VALUE)}asinh(){return new f(h.VALUE)}tan(){return new f(h.VALUE)}tanh(){return new f(h.VALUE)}atan(){return new f(h.VALUE)}atan2(n){return new f(h.VALUE)}atan2Inverse(n){return new f(h.VALUE)}atanh(){return new f(h.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new f(h.VALUE)}log10(){return new f(h.VALUE)}exp(){return new f(h.VALUE)}abs(){return new f(h.VALUE)}round(n){return new f(h.VALUE)}roundInverse(n){return new f(h.VALUE)}floor(n){return new f(h.VALUE)}floorInverse(n){return new f(h.VALUE)}ceil(n){return new f(h.VALUE)}ceilInverse(n){return new f(h.VALUE)}}class f extends Ce{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var cs=20,hs=1,xe=1e6,Cr=1e6,fs=-7,ms=21,gs=!1,Ze="[big.js] ",ve=Ze+"Invalid ",xt=ve+"decimal places",ds=ve+"rounding mode",en=Ze+"Division by zero",O={},se=void 0,Rs=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function tn(){function r(n){var e=this;if(!(e instanceof r))return n===se?tn():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(ve+"value");n=n===0&&1/n<0?"-0":String(n)}ps(e,n)}e.constructor=r}return r.prototype=O,r.DP=cs,r.RM=hs,r.NE=fs,r.PE=ms,r.strict=gs,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}function ps(r,n){var e,t,s;if(!Rs.test(n))throw Error(ve+"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 Be(r,n,e,t){var s=r.c;if(e===se&&(e=r.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ds);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]!==se))),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]!==se||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 Ie(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}O.abs=function(){var r=new this.constructor(this);return r.s=1,r};O.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};O.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>xe)throw Error(xt);if(!s[0])throw Error(en);if(!t[0])return r.s=i,r.c=[r.e=0],r;var o,u,l,c,m,g=s.slice(),R=o=s.length,E=t.length,p=t.slice(0,o),C=p.length,D=r,b=D.c=[],L=0,S=a+(D.e=n.e-r.e)+1;for(D.s=i,i=S<0?0:S,g.unshift(0);C++<o;)p.push(0);do{for(l=0;l<10;l++){if(o!=(C=p.length))c=o>C?1:-1;else for(m=-1,c=0;++m<o;)if(s[m]!=p[m]){c=s[m]>p[m]?1:-1;break}if(c<0){for(u=C==o?s:g;C;){if(p[--C]<u[C]){for(m=C;m&&!p[--m];)p[m]=9;--p[m],p[C]+=10}p[C]-=u[C]}for(;!p[0];)p.shift()}else break}b[L++]=c?l:++l,p[0]&&c?p[C]=t[R]||0:p=[t[R]]}while((R++<E||p[0]!==se)&&i--);return!b[0]&&L!=1&&(b.shift(),D.e--,S--),L>S&&Be(D,S,e.RM,p[0]!==se),D};O.eq=function(r){return this.cmp(r)===0};O.gt=function(r){return this.cmp(r)>0};O.gte=function(r){return this.cmp(r)>-1};O.lt=function(r){return this.cmp(r)<0};O.lte=function(r){return this.cmp(r)<1};O.minus=O.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,g=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-g){for((s=o<0)?(o=-o,t=l):(g=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(),--g;return l[0]||(r.s=1,l=[g=0]),r.c=l,r.e=g,r};O.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(en);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)))};O.neg=function(){var r=new this.constructor(this);return r.s=-r.s,r};O.plus=O.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};O.pow=function(r){var n=this,e=new n.constructor("1"),t=e,s=r<0;if(r!==~~r||r<-Cr||r>Cr)throw Error(ve+"exponent");for(s&&(r=-r);r&1&&(t=t.times(n)),r>>=1,!!r;)n=n.times(n);return s?e.div(t):t};O.prec=function(r,n){if(r!==~~r||r<1||r>xe)throw Error(ve+"precision");return Be(new this.constructor(this),r,n)};O.round=function(r,n){if(r===se)r=0;else if(r!==~~r||r<-xe||r>xe)throw Error(xt);return Be(new this.constructor(this),r+this.e+1,n)};O.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(Ze+"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 Be(r,(s.DP-=4)+r.e+1,s.RM)};O.times=O.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};O.toExponential=function(r,n){var e=this,t=e.c[0];if(r!==se){if(r!==~~r||r<0||r>xe)throw Error(xt);for(e=Be(new e.constructor(e),++r,n);e.c.length<r;)e.c.push(0)}return Ie(e,!0,!!t)};O.toFixed=function(r,n){var e=this,t=e.c[0];if(r!==se){if(r!==~~r||r<0||r>xe)throw Error(xt);for(e=Be(new e.constructor(e),r+e.e+1,n),r=r+e.e+1;e.c.length<r;)e.c.push(0)}return Ie(e,!1,!!t)};O[Symbol.for("nodejs.util.inspect.custom")]=O.toJSON=O.toString=function(){var r=this,n=r.constructor;return Ie(r,r.e<=n.NE||r.e>=n.PE,!!r.c[0])};O.toNumber=function(){var r=Number(Ie(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(r.toString()))throw Error(Ze+"Imprecise conversion");return r};O.toPrecision=function(r,n){var e=this,t=e.constructor,s=e.c[0];if(r!==se){if(r!==~~r||r<1||r>xe)throw Error(ve+"precision");for(e=Be(new t(e),r,n);e.c.length<r;)e.c.push(0)}return Ie(e,r<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)};O.valueOf=function(){var r=this,n=r.constructor;if(n.strict===!0)throw Error(Ze+"valueOf disallowed");return Ie(r,r.e<=n.NE||r.e>=n.PE,!0)};var H=tn();function rn(r){let n;switch(r){case y.EQUALS:n=y.EQUALS;break;case y.GREATER_THAN:n=y.LESS_THAN;break;case y.GREATER_THAN_OR_EQUAL:n=y.LESS_THAN_OR_EQUAL;break;case y.LESS_THAN:n=y.GREATER_THAN;break;case y.LESS_THAN_OR_EQUAL:n=y.GREATER_THAN_OR_EQUAL;break;case y.NOT_EQUAL:n=y.NOT_EQUAL;break}return n}function ir(r,n){return H(r).times(n).toNumber()}function _r(r,n){const e=10**Math.floor(n);return Math.round(ir(r,e))/e}function wr(r,n){const e=10**Math.floor(n);return Math.floor(ir(r,e))/e}function Dr(r,n){const e=10**Math.floor(n);return Math.ceil(ir(r,e))/e}function yr(r,n){return r**n}class le extends Ce{isNull(){return!0}plus(n){return new w(0,!0).plus(n)}minus(n){return new w(0,!0).minus(n)}multiply(n){return new w(0,!0).multiply(n)}divided(n){return new w(0,!0).divided(n)}compare(n,e){return n.isString()?new j("").compare(n,e):n.isBoolean()?new T(!1).compare(n,e):new w(0,!0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(new j("")):new j(this.concatenate(n.getValue(),te.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(new j("")):new j(this.concatenate(n.getValue(),te.BACK))}plusBy(n){return new w(0).plusBy(n)}minusBy(n){return new w(0).minusBy(n)}multiplyBy(n){return new w(0).multiplyBy(n)}dividedBy(n){return new w(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?new j("").compareBy(n,e):typeof n=="boolean"?new T(!1).compareBy(n,e):new w(0,!0).compareBy(n,e)}pow(n){return new w(0,!0).pow(n)}sqrt(){return new w(0,!0).sqrt()}cbrt(){return new w(0,!0).cbrt()}cos(){return new w(0,!0).cos()}acos(){return new w(0,!0).acos()}acosh(){return new w(0,!0).acosh()}sin(){return new w(0,!0).sin()}asin(){return new w(0,!0).asin()}asinh(){return new w(0,!0).asinh()}tan(){return new w(0,!0).tan()}tanh(){return new w(0,!0).tanh()}atan(){return new w(0,!0).atan()}atan2(n){return new w(0,!0).atan2(n)}atanh(){return new w(0,!0).atanh()}log(){return new f(h.NUM)}log10(){return new f(h.NUM)}exp(){return new w(0,!0).exp()}abs(){return new w(0,!0).abs()}round(n){return new w(0,!0).round(n)}floor(n){return new w(0,!0).floor(n)}ceil(n){return new w(0,!0).ceil(n)}}class T extends Ce{constructor(e,t=!1){super(e);_(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===Pe.TRUE?this._value=!0:s===Pe.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),new w(-t,!0)}getReciprocal(){return this.getValue()?new w(1,!0):new f(h.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),new w(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class w extends Ce{constructor(e,t=!1){super(e);_(this,"_value",0);if(t){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new w(0).minus(this)}getReciprocal(){return new w(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:(t.setPattern(this.getPattern()||e.getPattern()),t)}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new j(this.concatenate(e.getValue(),te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new j(this.concatenate(e.getValue(),te.BACK))}compare(e,t){return e.isArray()?e.compare(this,rn(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return wt.has(e)?new f(e):new f(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new f(h.NUM);const s=H(t).plus(e).toNumber();return Number.isFinite(s)?new w(s):new f(h.NUM)}return typeof e=="boolean"?new w(H(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return new f(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new f(h.NUM);const s=H(t).minus(e).toNumber();return Number.isFinite(s)?new w(s):new f(h.NUM)}return typeof e=="boolean"?new w(H(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return new f(h.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return new f(h.NUM);const s=H(t).times(e).toNumber();return Number.isFinite(s)?new w(s):new f(h.NUM)}return typeof e=="boolean"?new w(H(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return new f(h.VALUE);if(typeof e=="number"){if(e===0)return new f(h.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return new f(h.NUM);const s=H(t).div(e).toNumber();return Number.isFinite(s)?new w(s):new f(h.NUM)}return typeof e=="boolean"?e===!1?new f(h.DIV_BY_ZERO):new w(H(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case y.EQUALS:i=H(s).eq(e);break;case y.GREATER_THAN:i=H(s).gt(e);break;case y.GREATER_THAN_OR_EQUAL:i=H(s).gte(e);break;case y.LESS_THAN:i=H(s).lt(e);break;case y.LESS_THAN_OR_EQUAL:i=H(s).lte(e);break;case y.NOT_EQUAL:i=!H(s).eq(e);break}else if(typeof e=="boolean")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new T(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new f(h.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new f(h.NUM);const i=yr(t,s);return Number.isFinite(i)?new w(i):new f(h.NUM)}return typeof s=="boolean"?new w(yr(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=H(e).sqrt().toNumber();return Number.isFinite(t)?new w(t):new f(h.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.cos(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.acos(e);return Number.isNaN(t)?new f(h.NUM):new w(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.acosh(e);return Number.isNaN(t)?new f(h.NUM):new w(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.sin(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.asin(e);return Number.isNaN(t)?new f(h.NUM):new w(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.asinh(e);return Number.isNaN(t)?new f(h.NUM):new w(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.tan(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.atan(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new f(h.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new f(h.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?new w(i):new f(h.NUM)}return typeof s=="boolean"?new w(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new f(h.NUM);if(!Number.isFinite(e))return new f(h.NUM);const t=Math.log(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new f(h.NUM);if(!Number.isFinite(e))return new f(h.NUM);const t=Math.log10(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.exp(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new f(h.NUM);const t=Math.abs(e);return Number.isFinite(t)?new w(t):new f(h.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new f(h.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new f(h.NUM);const i=_r(t,s);return Number.isFinite(i)?new w(i):new f(h.NUM)}return typeof s=="boolean"?new w(_r(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 f(h.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new f(h.NUM);const i=wr(t,s);return Number.isFinite(i)?new w(i):new f(h.NUM)}return typeof s=="boolean"?new w(wr(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 f(h.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new f(h.NUM);const i=Dr(t,s);return Number.isFinite(i)?new w(i):new f(h.NUM)}return typeof s=="boolean"?new w(Dr(t,s?1:0)):this}_compareInfinity(e,t,s){let i=!1;switch(s){case y.EQUALS:i=e===t;break;case y.GREATER_THAN:i=e>t;break;case y.GREATER_THAN_OR_EQUAL:i=e>=t;break;case y.LESS_THAN:i=e<t;break;case y.LESS_THAN_OR_EQUAL:i=e<=t;break;case y.NOT_EQUAL:i=e!==t;break}return i}}class j extends Ce{constructor(e,t=!1){super(e);_(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 j(this.concatenate(e.getValue(),te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new j(this.concatenate(e.getValue(),te.BACK))}compare(e,t){return e.isArray()?e.compare(this,rn(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(us(e))return this._checkWildcard(e,t);switch(t){case y.EQUALS:i=s===e;break;case y.GREATER_THAN:i=s>e;break;case y.GREATER_THAN_OR_EQUAL:i=s>=e;break;case y.LESS_THAN:i=s<e;break;case y.LESS_THAN_OR_EQUAL:i=s<=e;break;case y.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case y.NOT_EQUAL:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!0;break;case y.EQUALS:case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new T(i)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=ls(s,e,t);return new T(i)}}function Es(r){return""}function Cs(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]=Ee.create(i)}}return n}function _s(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.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class q extends Ce{constructor(e){var n=(...ro)=>(super(...ro),_(this,"_values",[]),_(this,"_rowCount",-1),_(this,"_columnCount",-1),_(this,"_unitId",""),_(this,"_sheetId",""),_(this,"_currentRow",-1),_(this,"_currentColumn",-1),_(this,"_sliceCache",new Map),_(this,"_flattenCache"),_(this,"_flattenPosition"),this);if(typeof e=="string")n(e);else{const t=Es();n(t)}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 le(0);const i=s[t];return i==null?new le(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(),o=this.getArrayValue();for(let u=t;u<=s;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!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)}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 le(0)]],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.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.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 g=[],R=this._values;let E=0,p=0;for(let L=s;L<i;L+=a){p=0,g[E]==null&&(g[E]=[]);for(let S=o;S<u;S+=l)g[E][p]=R[L][S],p++;E++}if(g.length===0||g[0].length===0)return;const C=a>1?-1:s+this._currentRow,D=l>1?-1:o+this._currentColumn,b=this._createNewArray(g,g.length,g[0].length,C,D);return this._sliceCache.set(c,b),b}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=X.MIN,s=!1,i=!1){let a,o,u,l;const c=(m,g,R)=>{if(m==null)return!0;let E;if(i===!0?E=m.compare(e,y.EQUALS):E=m.isEqual(e),(E==null?void 0:E.getValue())===!0)return a=m,u={row:g,column:R},!1;t===X.MAX?m.isGreaterThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,l={row:g,column:R}):t===X.MIN&&m.isLessThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=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 E=g-1;E>=0;E--){const p=this._values[R][E];c(p,R,E)}}else this.iterator((m,g,R)=>{c(m,g,R)});if(a!=null)return u;if(o!=null)return l}binarySearch(e,t=ue.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=ue.MIN){const a=Rr(),o=e.getValue().toString();let u=0,l=t.length-1,c=null;for(;u<=l;){const m=Math.floor((u+l)/2),g=t[m];let R=0;if(g.isNull())R=1;else{const E=g.getValue();R=a(E.toString(),o)}if(R===0)return s[m];R===-1?(u=m+1,i===ue.MIN&&(c=m)):(l=m-1,i===ue.MAX&&(c=m))}if(c!=null)return s[c]}sum(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new w(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new w(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new w(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return new q("{0}").minus(this)}getReciprocal(){return new q("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}compare(e,t){return this._batchOperator(e,4,t)}concatenateFront(e){return this._batchOperator(e,5)}concatenateBack(e){return this._batchOperator(e,6)}product(e,t){return this._batchOperator(e,7,t)}map(e){const t=(s,i,a)=>s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a,o;const t=this._rowCount,s=this._columnCount,i=[];for(let u=0;u<t;u++){const l=[];for(let c=0;c<s;c++){const m=(o=(a=this._values)==null?void 0:a[u])==null?void 0:o[c];m?l[c]=e(m,u,c):l[c]=new f(h.VALUE)}i.push(l)}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(){const e=this.sum(),t=this.count();return e.divided(t)}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0);if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2),a=t.get(0,s/2-1);return i.plus(a).divided(new w(2,!0))}return t.get(0,(s-1)/2)}var(){const e=this.mean(),t=[[]];this.iterator(m=>{if(m==null||m.isError()||m.isString()||m.isBoolean()||m.isNull())return;const g=m.minus(e).pow(new w(2,!0));g.isError()||t[0].push(g)});const{_rowCount:s,_columnCount:i,_unitId:a,_sheetId:o,_currentRow:u,_currentColumn:l}=this;return new q({calculateValueList:t,rowCount:1,columnCount:t[0].length,unitId:a,sheetId:o,row:u,column:l}).mean()}std(){const e=this.var();return e.isError()?e:e.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(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 _s(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=Rr();return(s,i)=>{const a=s[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,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 g=0;g<o;g++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let g=0;g<o;g++)i.push(m[0][g])}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 R,E;const o=this._rowCount;let u=!1;const l=this.getUnitId(),c=this.getSheetId(),m=this.getCurrentRow(),g=this.getCurrentColumn();if(i===4&&(u=me.canUseCache(l,c,t+g,m,m+o-1),u===!0)){if(a===y.EQUALS){const p=me.getCellPositions(l,c,t+g,e.getValue());for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),p!=null&&p.includes(C+m)?s[C][t]=new T(!0):s[C][t]=new T(!1)}else{const p=me.getCellValuePositions(l,c,t+g);if(p!=null){p.forEach((C,D)=>{let b;if(typeof D=="string"?b=new j(D):typeof D=="number"?b=new w(D):typeof D=="boolean"&&(b=new T(D)),b==null)return!0;b.compare(e,a).getValue()===!0&&C.forEach(S=>{S>=m&&S<=m+o-1&&(s[S-m]==null&&(s[S-m]=[]),s[S-m][t]=new T(!0))})});for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),s[C][t]==null&&(s[C][t]=new T(!1))}else for(let C=0;C<o;C++)s[C]==null&&(s[C]=[]),s[C][t]=new T(!1)}return}for(let p=0;p<o;p++){const C=(E=(R=this._values)==null?void 0:R[p])==null?void 0:E[t];if(s[p]==null&&(s[p]=[]),C&&e)if(C.isError())s[p][t]=C;else if(e.isError())s[p][t]=e;else switch(i){case 1:s[p][t]=C.plus(e);break;case 0:s[p][t]=C.minus(e);break;case 2:s[p][t]=C.multiply(e);break;case 3:s[p][t]=C.divided(e);break;case 4:a?s[p][t]=C.compare(e,a):s[p][t]=new f(h.VALUE);break;case 5:s[p][t]=C.concatenateFront(e);break;case 6:s[p][t]=C.concatenateBack(e);break;case 7:a?s[p][t]=C.product(e,a):s[p][t]=new f(h.VALUE);break;case 8:s[p][t]=C.pow(e);break;case 9:s[p][t]=C.round(e);break;case 10:s[p][t]=C.floor(e);break;case 12:s[p][t]=C.atan2(e);break;case 11:s[p][t]=C.ceil(e);break}else s[p][t]=new f(h.NA);C!=null&&(C.isError()?me.set(l,c,t+g,C.getErrorType(),p+m):C.isNull()?me.set(l,c,t+g,null,p+m):me.set(l,c,t+g,C.getValue(),p+m))}me.setContinueBuildingCache(l,c,t+g,m,m+o-1)}_batchOperatorArray(e,t,s){var m,g,R,E,p,C,D,b,L,S,$,I;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 k=0;k<i;k++){const P=[];for(let x=0;x<a;x++){let M;l===3?M=(g=(m=this._values)==null?void 0:m[0])==null?void 0:g[0]:l===1?M=(E=(R=this._values)==null?void 0:R[0])==null?void 0:E[x]:l===2?M=(C=(p=this._values)==null?void 0:p[k])==null?void 0:C[0]:M=(b=(D=this._values)==null?void 0:D[k])==null?void 0:b[x];let F;if(c===3?F=(L=u==null?void 0:u[0])==null?void 0:L[0]:c===1?F=(S=u==null?void 0:u[0])==null?void 0:S[x]:c===2?F=($=u==null?void 0:u[k])==null?void 0:$[0]:F=(I=u==null?void 0:u[k])==null?void 0:I[x],M&&F)if(M.isError())P[x]=M;else if(F.isError())P[x]=F;else switch(t){case 1:P[x]=M.plus(F);break;case 0:P[x]=M.minus(F);break;case 2:P[x]=M.multiply(F);break;case 3:P[x]=M.divided(F);break;case 4:s?P[x]=M.compare(F,s):P[x]=new f(h.VALUE);break;case 5:P[x]=M.concatenateFront(F);break;case 6:P[x]=M.concatenateBack(F);break;case 7:s?P[x]=M.product(F,s):P[x]=new f(h.VALUE);break;case 8:P[x]=M.pow(F);break;case 9:P[x]=M.round(F);break;case 12:P[x]=M.atan2(F);break;case 10:P[x]=M.floor(F);break;case 11:P[x]=M.ceil(F);break}else P[x]=new f(h.NA)}o.push(P)}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 g=0;g<c;g++){const R=l[g].trim();m.push(Ee.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 o={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new q(o)}}class Ee{static create(n){if(n==null)return new le(0);if(typeof n=="boolean")return new T(n,!0);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return wt.has(e)?new f(e):e===Pe.TRUE||e===Pe.FALSE?new T(e):d.isRealNum(n)?new w(n):new RegExp(es,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?new q(n.replace(/\n/g,"").replace(/\r/g,"")):new j(n)}return typeof n=="number"?Number.isFinite(n)?new w(n,!0):new f(h.NUM):new f(h.NA)}}function ws(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)===d.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(r==null?void 0:r.v)||0}const Ds=1e5,jt=new Dt(Ds);class Qe extends Pt{constructor(e){super();_(this,"_forcedSheetId","");_(this,"_forcedSheetName","");_(this,"_defaultSheetId","");_(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});_(this,"_unitData",{});_(this,"_defaultUnitId","");_(this,"_forcedUnitId","");_(this,"_runtimeData",{});_(this,"_arrayFormulaCellData",{});_(this,"_runtimeArrayFormulaCellData",{});_(this,"_runtimeFeatureCellData",{});_(this,"_numfmtItemData",{});_(this,"_refOffsetX",0);_(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,c,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(new f(h.VALUE),t,i);const o=this._forcedUnitId||this._defaultUnitId,u=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 f(h.REF),g,R);const E=this.getCellData(g,R);let p=!1;if(E==null||d.isNullCell(E)){p=e(null,g,R);continue}const C=this.getCellValueObject(E),D=(m=(c=(l=this._numfmtItemData[o])==null?void 0:l[u])==null?void 0:c[g])==null?void 0:m[R];if(D&&C.setPattern(D),p=e(C,g,R),p===!1)return}}getFirstCell(){var l,c,m;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return new w(0,!0);const i=this.getCellValueObject(s),a=this._forcedUnitId||this._defaultUnitId,o=this._forcedSheetId||this._defaultSheetId,u=(m=(c=(l=this._numfmtItemData[a])==null?void 0:l[o])==null?void 0:c[e])==null?void 0:m[t];return u&&i.setPattern(u),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}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return new f(h.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=ws(e);return wt.has(t)?new f(t):e.t===d.CellValueType.NUMBER?new w(t):e.t===d.CellValueType.STRING||e.t===d.CellValueType.FORCE_STRING?new j(t):e.t===d.CellValueType.BOOLEAN?new T(t):Ee.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):new f(h.VALUE)}toArrayValueObject(e=!0){var E;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,u=jt.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((p,C,D)=>{const b=C-t,L=D-i;m[b]||(m[b]=new Array(c)),p==null&&(p=new le(0)),m[b][L]=p});const g={calculateValueList:m,rowCount:m.length,columnCount:((E=m[0])==null?void 0:E.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},R=new q(g);return e&&jt.set(o,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 q(e)}}class ys extends Pt{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class bs extends Pt{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 new q(e)}}class Ke extends Qe{constructor(n,e,t){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const br=/[\[\]]/g;function Lr(r,n){if(br.test(r)){const e=Number(r.replace(br,""));return n+e}return Number(r)-1}function Ft(r,n=0,e=0){r=r.toLocaleUpperCase();const t=r.split(/[RC]/),s=t[1],i=t[2],a=Lr(s,n),o=Lr(i,e);return{row:a,column:o,absoluteRefType:d.AbsoluteRefType.NONE}}function nn(r,n=0,e=0){const{refBody:t,sheetName:s,unitId:i}=Hr(r),a=t.indexOf(":");if(a===-1){const p=Ft(t,n,e),C=p.row,D=p.column,b=p.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:C,startColumn:D,endRow:C,endColumn:D,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const o=t.substring(0,a),u=t.substring(a+1),l=Ft(o,n,e),c=Ft(u,n,e),m=l.row,g=l.column,R=c.row,E=c.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:g,endRow:R,endColumn:E,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:c.absoluteRefType}}}function Ls(r){const n=Je(r.startRow,r.startAbsoluteRefType,!0),e=Je(r.startColumn,r.startAbsoluteRefType,!1),t=Je(r.endRow,r.endAbsoluteRefType,!0),s=Je(r.endColumn,r.endAbsoluteRefType,!1);return n===t&&e===s?`R${n}C${e}`:`R${n}C${e}:R${t}C${s}`}function Je(r,n=d.AbsoluteRefType.ALL,e){switch(r+=1,n){case d.AbsoluteRefType.ALL:return`${r}`;case d.AbsoluteRefType.ROW:return e?`${r}`:`[${r}]`;case d.AbsoluteRefType.COLUMN:return e?`[${r}]`:`${r}`;case d.AbsoluteRefType.NONE:return`[${r}]`}}const sn=[];var Ss=(r=>{})();class V extends d.Disposable{constructor(e){super();_(this,"_unitId");_(this,"_subUnitId");_(this,"_row",-1);_(this,"_column",-1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return new f(h.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 f(h.VALUE):t;if(e.isString()){const s=Number(e.getValue());return isNaN(s)?new f(h.REF):s}else if(e.isNumber())return e.getValue();return new f(h.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 f(h.NA);let o;return s.getRowCount()===1?o=s.get(0,a):o=s.get(a,0),o.isNull()?new f(h.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()?new f(h.NA):o}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,y.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?new f(h.NA):o}orderSearch(e,t,s,i=X.MIN,a=!1){const o=t.orderSearch(e,i,a);if(o==null)return new f(h.NA);const u=s.get(o.row,o.column);return u.isNull()?new f(h.NA):u}binarySearchExpand(e,t,s,i=0,a){const o=t.binarySearch(e,a);return o==null?new f(h.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?new f(h.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,y.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?new f(h.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,t,s,i=X.MIN,a=!1,o=0){const u=t.orderSearch(e,i,a);return u==null?new f(h.NA):o===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}}const an=[];var on=(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))(on||{});const un=[];var ln=(r=>(r.CUBEKPIMEMBER="CUBEKPIMEMBER",r.CUBEMEMBER="CUBEMEMBER",r.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",r.CUBERANKEDMEMBER="CUBERANKEDMEMBER",r.CUBESET="CUBESET",r.CUBESETCOUNT="CUBESETCOUNT",r.CUBEVALUE="CUBEVALUE",r))(ln||{});const cn=[];var hn=(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))(hn||{});const ar="yyyy-mm-dd;@";function or(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 Ae(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 G(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:new le(0));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:new le(0));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:new le(0));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 Ps(s,r,n)}function Ps(r,n,e){const t={calculateValueList:r,rowCount:n,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return new q(t)}class xs extends V{calculate(n,e,t){if(n==null||e==null||t==null)return new f(h.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=G(s,i,n),o=G(s,i,e),u=G(s,i,t);return a.map((l,c,m)=>{const g=o.get(c,m),R=u.get(c,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 f(h.VALUE);let E=+l.getValue();const p=Math.floor(+g.getValue()),C=+R.getValue();if(E<0||E>9999)return new f(h.NUM);E>=0&&E<1899&&(E+=1900);const D=new Date(E,p-1,C),b=or(D);if(b<0)return new f(h.NUM);const L=new w(b);return L.setPattern(ar),L})}}class As extends V{calculate(n){return n==null?new f(h.NA):n.isError()?n:n.isArray()?n.map(e=>{if(e.isError())return e;if(e.isString()||e.isNull())return new f(h.VALUE);const t=+e.getValue();if(t<0)return new f(h.NUM);if(t===0)return new w(0);const i=Ae(t).getDate();return new w(i)}):new w(Ae(+n.getValue()).getDate())}}class Vs extends V{calculate(n,e){if(n==null||e==null)return new f(h.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=G(t,s,n),a=G(t,s,e);return i.map((o,u,l)=>{const c=a.get(u,l);if(o.isError())return o;if(c.isError())return c;if(o.isString()||o.isBoolean()||c.isString()||c.isBoolean())return new f(h.VALUE);const m=+o.getValue();if(m<0)return new f(h.NUM);const g=Math.floor(+c.getValue()),R=Ae(m),E=R.getUTCFullYear(),p=R.getUTCMonth()+g,C=R.getUTCDate(),D=new Date(Date.UTC(E,p,C)),b=or(D),L=new w(b);return L.setPattern(ar),L})}}var ge=(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))(ge||{});class vs extends V{calculate(n){return n==null?new f(h.NA):n.isError()?n:n.isArray()?n.map(e=>{if(e.isError())return e;if(e.isString())return new f(h.VALUE);const t=+e.getValue();if(t<0)return new f(h.NUM);if(t===0)return new w(1);const i=Ae(t).getUTCMonth()+1;return new w(i)}):new w(Ae(+n.getValue()).getUTCMonth()+1)}}class Bs extends V{calculate(n){if(n)return new f(h.NA);const e=or(new Date),t=new w(e);return t.setPattern(ar),t}}class Us extends V{calculate(n){return n==null?new f(h.NA):n.isError()?n:n.isArray()?n.map((e,t,s)=>{if(e.isError())return e;if(e.isString())return new f(h.VALUE);const i=+e.getValue();if(i<0)return new f(h.NUM);if(i===0)return new w(1900);const o=Ae(i).getUTCFullYear();return new w(o)}):new w(Ae(+n.getValue()).getUTCFullYear())}}const fn=[[xs,ge.DATE],[As,ge.DAY],[Vs,ge.EDATE],[vs,ge.MONTH],[Bs,ge.TODAY],[Us,ge.YEAR]],mn=[];var gn=(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))(gn||{});const dn=[];var Rn=(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))(Rn||{}),ur=(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))(ur||{});class Os extends V{calculate(n){return n==null?new f(h.NA):n.isNull()?new T(!0):n.isArray()?n.map(e=>e.isNull()?new T(!0):new T(!1)):new T(!1)}}const pn=[[Os,ur.ISBLANK]];class Ms extends V{calculate(...n){if(n.length===0)return new f(h.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?new f(h.VALUE):new T(e)}}var be=(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))(be||{});class Fs extends V{calculate(n,e,t=new T(!1)){if(n==null||e==null)return new f(h.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=G(s,i,n),o=G(s,i,e,new f(h.NA)),u=G(s,i,t,new f(h.NA));return a.map((l,c,m)=>{if(l.isNull())return new f(h.NA);{const g=o.get(c,m),R=u.get(c,m);return this._calculateSingleCell(l,g,R)}})}_getSingleValueObject(n){return n.isArray()&&n.getRowCount()===1&&n.getColumnCount()===1?n.getFirstCell():n}_calculateSingleCell(n,e,t){return n.isNull()?new f(h.NA):n.getValue()?e.isNull()?new f(h.NA):e:t.isNull()?new f(h.NA):t}}class $s extends V{calculate(n,e){if(n==null||e==null)return new f(h.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=G(t,s,n),a=G(t,s,e);return i.iterator((o,u,l)=>{o!=null&&o.isError()&&i.set(u,l,a.get(u,l))}),i}}class ks extends V{calculate(...n){return new f(h.VALUE)}}class Ts extends V{calculate(...n){if(n.length!==3)return new f(h.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 new f(h.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(new w(a+1),new w(o+1));i[a][o]=u}}return new bs(i)}isAsync(){return!0}}const En=[[Ms,be.AND],[ks,be.LAMBDA],[Ts,be.MAKEARRAY],[Fs,be.IF],[$s,be.IFERROR]];class Is extends V{calculate(n,e,t,s,i){if(n==null||e==null)return new f(h.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 new f(h.VALUE);const u=t?Qs(t.getValue()):d.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),c=i?`${i.getValue()}`:"",m=ct(c)?`'${c}'`:c,g={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},R=s&&!l?Ls(g):Se(g);return new j(m!==""?`${m}!${R}`:R)}}function Qs(r){switch(r){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}}var N=(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))(N||{});class Ys extends V{calculate(n,e,t,s){if(n==null||e==null||t==null)return new f(h.NA);if(n.isError())return n;if(e.isError())return new f(h.REF);if(!e.isArray())return new f(h.VALUE);if(t.isError())return new f(h.NA);if(s!=null&&s.isError())return new f(h.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new f(h.VALUE);const a=this.getIndexNumValue(t);if(a instanceof f)return a;const o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?new f(h.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 Cn extends Qe{constructor(n){super(n);const e=ke(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return new f(h.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 Ke(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 _n extends Qe{constructor(n){super(n);const e=ke(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 new f(h.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new f(h.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this}}class wn extends Qe{constructor(n){super(n);const e=ke(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 new f(h.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return new f(h.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 js extends V{calculate(n,e){if(n==null)return new f(h.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(()=>new f(h.VALUE))}if(!n.isString())return new f(h.REF);const s=n.getValue();if(t===0){const c=nn(s),{range:m,sheetName:g,unitId:R}=c,E=new Ke(m);return E.setForcedUnitIdDirect(R),E.setForcedSheetName(g),this._setDefault(E)}if(new RegExp(yt).test(s))return this._setDefault(new Cn(s));if(new RegExp(Wr).test(s))return this._setDefault(new wn(s));if(new RegExp(Xr).test(s))return this._setDefault(new _n(s));const i=ke(s),{range:a,sheetName:o,unitId:u}=i,l=new Ke(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),this._setDefault(l)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new f(h.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class Hs extends V{calculate(n,e,t){return n==null||e==null?new f(h.NA):n.isError()?n:e.isError()?new f(h.REF):e.isArray()?t!=null&&t.isError()?t:e.getColumnCount()===1||e.getRowCount()===1?t!=null&&!t.isArray()?new f(h.REF):this._handleVector(n,e,t):this._handleArray(n,e):new f(h.VALUE)}_handleVector(n,e,t){if(t==null)t=e;else if(t.getRowCount()!==e.getRowCount()||t.getColumnCount()!==e.getColumnCount())return new f(h.REF);return n.isArray()?n.map(s=>this.binarySearch(s,e,t)):this.binarySearch(n,e,t)}_handleArray(n,e){const t=e.getRowCount(),s=e.getColumnCount();let i,a;return s>t?(i=e.slice([0,1]),a=e.slice([t-1,t])):(i=e.slice(void 0,[0,1]),a=e.slice(void 0,[s-1,s])),i==null||a==null?new f(h.VALUE):n.isArray()?n.map(o=>this.binarySearch(o,i,a)):this.binarySearch(n,i,a)}}class Ws extends V{calculate(n,e,t){if(n==null||e==null)return new f(h.NA);if(n.isError())return n;if(e.isError())return new f(h.REF);if(!e.isArray())return new f(h.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1)return new f(h.NA);if(t!=null&&t.isError())return new f(h.NA);const a=this.getMatchTypeValue(t);return a==null?new f(h.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 new f(h.NA);if(i instanceof f)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return new w(a)}_getSearchModeValue(n){switch(n){case 1:return X.MIN;case 0:return X.NORMAL;case-1:return X.MAX}}}class Xs extends V{calculate(n,e,t,s,i){var P,x;if(n==null||e==null||t==null)return new f(h.NA);if(n.isError())return n;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(!n.isArray())return new f(h.VALUE);const a=n.getCurrentRow(),o=n.getCurrentColumn(),u=this.getIndexNumValue(e),l=this.getIndexNumValue(t);if(typeof u!="number"||typeof l!="number")return new f(h.VALUE);const c=a+u,m=o+l;if(c<0||m<0||c>1048576||m>16384)return new f(h.REF);const g=(P=s&&this.getIndexNumValue(s))!=null?P:1,R=(x=i&&this.getIndexNumValue(i))!=null?x:1;if(typeof g!="number"||typeof R!="number")return new f(h.VALUE);if(g===0||R===0)return new f(h.REF);const E=g>0?c+g-1:c+g+1,p=R>0?m+R-1:m+R+1;if(E<0||p<0||E>1048576||p>16384)return new f(h.REF);const C=c<E?c:E,D=m<p?m:p,b=c>E?c:E,L=m>p?m:p,S={startRow:C,startColumn:D,endRow:b,endColumn:L},$=n.getUnitId(),I=n.getSheetId(),k=new Ke(S,I,$);return this._setDefault(k)}_setDefault(n){return this.unitId==null||this.subUnitId==null?new f(h.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class Gs extends V{calculate(n,e,t,s){if(n==null||e==null||t==null)return new f(h.NA);if(n.isError())return n;if(e.isError())return new f(h.REF);if(!e.isArray())return new f(h.VALUE);if(t.isError())return new f(h.NA);if(s!=null&&s.isError())return new f(h.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return new f(h.VALUE);const a=this.getIndexNumValue(t);if(a instanceof f)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?new f(h.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 Ks extends V{calculate(n,e,t,s,i,a){if(n==null||e==null||t==null)return new f(h.NA);if(n.isError())return n;if(e.isError())return new f(h.REF);if(!e.isArray())return new f(h.VALUE);const o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==1)return new f(h.VALUE);if(t.isError())return new f(h.REF);if(!t.isArray())return new f(h.VALUE);const l=t.getRowCount(),c=t.getColumnCount();if(o!==l&&u!==c)return new f(h.VALUE);if(s!=null&&s.isError())return new f(h.NA);if(i!=null&&i.isError())return new f(h.NA);if(a!=null&&a.isError())return new f(h.NA);s==null&&(s=new f(h.NA));const m=this.getIndexNumValue(i||new w(0));if(m instanceof f)return m;const g=this.getIndexNumValue(a||new w(1));if(g instanceof f)return g;if(n.isArray()){let p;return o===1?p=t.slice([0,1]):p=t.slice(void 0,[0,1]),p==null?new f(h.NA):n.map(C=>{const D=this._handleSingleObject(C,e,p,m,g);return D.isError()?s:D})}if(u===c&&o===l){const p=this._handleSingleObject(n,e,t,m,g);return p.isError()?s:p}let R=0;u===c&&(R=1);const E=this._handleExpandObject(n,e,t,m,g,R);return E==null?new f(h.NA):E}_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?X.MAX:X.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?X.MAX:X.MIN,i===-1):this.equalSearch(n,e,t,i!==-1)}_getSearchModeValue(n){return n===-2?ue.MAX:ue.MIN}}class qs extends V{calculate(n,e,t,s){if(n==null||e==null)return new f(h.NA);if(n.isError())return n;if(e.isError())return new f(h.REF);if(!e.isArray())return new f(h.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return new f(h.VALUE);if(t!=null&&t.isError())return new f(h.NA);if(s!=null&&s.isError())return new f(h.NA);const o=this.getIndexNumValue(t||new w(0));if(o instanceof f)return o;const u=this.getIndexNumValue(s||new w(1));return u instanceof f?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,y.EQUALS);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return new f(h.NA);i=e.getRowCount()===1?o.column:o.row}else if(t===-1||t===1){const a=e.orderSearch(n,t===1?X.MAX:X.MIN,s===-1);if(a==null)return new f(h.NA);if(a instanceof f)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 new f(h.NA);i=e.getRowCount()===1?o.column:o.row}return i==null?new f(h.NA):new w(i+1)}_getSearchModeValue(n){return n===-2?ue.MAX:ue.MIN}}const Dn=[[Is,N.ADDRESS],[js,N.INDIRECT],[Xs,N.OFFSET],[Gs,N.VLOOKUP],[Hs,N.LOOKUP],[Ws,N.MATCH],[Ys,N.HLOOKUP],[Ks,N.XLOOKUP],[qs,N.XMATCH]];class zs extends V{calculate(n){return n==null?new f(h.NA):n.isError()?new f(h.VALUE):n.abs()}}class Zs extends V{calculate(n){return n==null?new f(h.NA):n.isError()?n:n.acos()}}class Js extends V{calculate(n){return n==null?new f(h.NA):n.isError()?new f(h.VALUE):n.acosh()}}class Ns extends V{calculate(n){return n==null?new f(h.NA):n.isError()?n:n.isArray()?n.map(e=>e.isError()?e:Sr(e)):Sr(n)}}function Sr(r){let n=r.getValue();if(r.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return new f(h.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?new f(h.VALUE):new w(e)}var ee=(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))(ee||{});class ei extends V{calculate(n,e){return new f(h.VALUE)}}class ti extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError())return s;if(s.isString())return new f(h.VALUE);if(e.isError())return e;s.isArray()&&(s=s.sum()),e=e.plus(s)}return e}}function ri(r){const n=[y.EQUALS,y.NOT_EQUAL,y.GREATER_THAN_OR_EQUAL,y.GREATER_THAN,y.LESS_THAN_OR_EQUAL,y.LESS_THAN];for(const e of n)if(r.startsWith(e)){const t=r.substring(e.length);return[e,Ee.create(t)]}return[y.EQUALS,Ee.create(r)]}function yn(r,n,e){if(!e)if(n.isString()){const t=`${n.getValue()}`,[s,i]=ri(t);e=s,n=i}else e=y.EQUALS;return r.compare(n,e)}function ni(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=G(e,t,r),i=G(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())?new T(a.getValue()&&l.getValue()):new T(!1)})}class si extends V{calculate(n,e,t){return n==null||e==null?new f(h.NA):n.isError()||e.isError()||t!=null&&t.isError()?new f(h.NA):!n.isArray()||t&&!t.isArray()?new f(h.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,t)):this._handleSingleObject(n,e,t)}_handleSingleObject(n,e,t){const s=yn(n,e),i=t?t.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():new f(h.VALUE)}}class ii extends V{calculate(n,...e){if(n==null)return new f(h.NA);if(e.length<2)return new f(h.NA);if(n.isError())return new f(h.NA);if(!n.isArray())return new f(h.VALUE);if(e.length<2||e.length%2!==0)return new f(h.VALUE);if(e.some((c,m)=>m%2===0&&!c.isArray()))return new f(h.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 g=c;i=Math.max(i,g.getRowCount()),a=Math.max(a,g.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],g=m.getRowCount(),R=m.getColumnCount();if(g!==t||R!==s)return G(i,a,new f(h.NA));const E=e[c+1];G(i,a,E,new f(h.NA)).iterator((C,D,b)=>{if(!C)return;const L=yn(m,C);if(o[D]===void 0&&(o[D]=[]),o[D][b]===void 0){o[D][b]=L;return}o[D][b]=ni(o[D][b],L)})}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 new q(l)}}const bn=[[zs,ee.ABS],[Zs,ee.ACOS],[Js,ee.ACOSH],[Ns,ee.ACOT],[ti,ee.SUM],[si,ee.SUMIF],[ii,ee.SUMIFS],[ei,ee.POWER]];class ai extends V{constructor(){super(...arguments);_(this,"_compareType",y.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?e:e.compare(t,this._compareType)}}class oi extends V{calculate(n,e){return n.isError()||e.isError()?n:!e.isArray()&&e.getValue()===0?new f(h.DIV_BY_ZERO):n.divided(e)}}var W=(r=>(r.COMPARE="COMPARE",r.DIVIDED="DIVIDED",r.MINUS="MINUS",r.MULTIPLY="MULTIPLY",r.PLUS="PLUS",r.UNION="UNION",r))(W||{});class ui extends V{calculate(n,e){return n.isError()||e.isError()?n:n.minus(e)}}class li extends V{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class ci extends V{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const Ln=[[ai,W.COMPARE],[oi,W.DIVIDED],[ui,W.MINUS],[li,W.MULTIPLY],[ci,W.PLUS]];class hi extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(0),t=new w(0);for(let s=0;s<n.length;s++){const i=n[s];if(i.isError())return i;if(e.isError())return e;i.isArray()?(e=e.plus(i.sum()),t=t.plus(i.count())):i.isNull()||(t=t.plus(new w(1)))}return e.divided(t)}}class fi extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(0);for(let t=0;t<n.length;t++){let s=n[t];s.isError()||(s.isArray()?(s=s.count(),e=e.plus(s)):!s.isNull()&&!s.isString()&&(e=e.plus(new w(1))))}return e}}class mi extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError()){e=e.plus(new w(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new w(1)))}return e}}var de=(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))(de||{});class gi extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(Number.NEGATIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError())return s;s.isArray()&&(s=s.max()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class Pr extends V{calculate(...n){if(n.length===0)return new f(h.NA);let e=new w(Number.POSITIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError())return s;s.isArray()&&(s=s.min()),!s.isNull()&&(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}const Sn=[[hi,de.AVERAGE],[fi,de.COUNT],[gi,de.MAX],[Pr,de.MIN],[Pr,de.MIN],[mi,de.COUNTA]];class di extends V{calculate(...n){if(n.length===0)return new f(h.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=G(e,t,i,new f(h.NA)).mapValue((o,u,l)=>{var R,E;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()?"":(R=c==null?void 0:c.getValue())!=null?R:"",g=o!=null&&o.isNull()?"":(E=o==null?void 0:o.getValue())!=null?E:"";return new j(`${m}${g}`)});return s||new f(h.VALUE)}}var At=(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))(At||{});const Pn=[[di,At.CONCATENATE]],xn=[];var Ri=(r=>{})();const An=[];var Vn=(r=>(r.ENCODEURL="ENCODEURL",r.FILTERXML="FILTERXML",r.WEBSERVICE="WEBSERVICE",r))(Vn||{});class pi extends d.Disposable{constructor(){super(...arguments);_(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 Vt=A.createIdentifier("univer.formula.defined-names.service");var Ei=Object.defineProperty,Ci=Object.getOwnPropertyDescriptor,_i=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ci(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&&Ei(n,e,s),s},wi=(r,n)=>(e,t)=>n(e,t,r);let Ht=class extends d.Disposable{constructor(n){super();_(this,"_unitData",{});_(this,"_arrayFormulaCellData",{});_(this,"_formulaData",{});_(this,"_sheetNameMap",{});_(this,"_forceCalculate",!1);_(this,"_dirtyRanges",[]);_(this,"_dirtyNameMap",{});_(this,"_numfmtItemMap",{});_(this,"_dirtyUnitFeatureMap",{});_(this,"_excludedCell");this._currentUniverService=n}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(n){if(n.allUnitData&&n.unitSheetNameMap)this._unitData=n.allUnitData,this._sheetNameMap=n.unitSheetNameMap;else{const{allUnitData:e,unitSheetNameMap:t}=this._loadSheetData();this._unitData=e,this._sheetNameMap=t}this._formulaData=n.formulaData,this._arrayFormulaCellData=Ir(n.arrayFormulaCellData),this._forceCalculate=n.forceCalculate,this._dirtyRanges=n.dirtyRanges,this._dirtyNameMap=n.dirtyNameMap,this._numfmtItemMap=n.numfmtItemMap,this._dirtyUnitFeatureMap=n.dirtyUnitFeatureMap,this._excludedCell=n.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(n,e){this._dirtyRanges=n,this._excludedCell=e,this._dirtyNameMap={}}registerUnitData(n){this._unitData=n}registerFormulaData(n){this._formulaData=n}registerSheetNameMap(n){this._sheetNameMap=n}_mergeNameMap(n,e){Object.keys(e).forEach(t=>{e[t]&&Object.keys(e[t]).forEach(s=>{n[t]==null&&(n[t]={}),n[t][e[t][s]]=s})})}_loadSheetData(){const n=this._currentUniverService.getAllUniverSheetsInstance(),e={},t={};for(const s of n){const i=s.getUnitId(),a=s.getSheets(),o={},u={};for(const l of a){const c=l.getSheetId(),m=l.getConfig();o[c]={cellData:new d.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount},u[l.getName()]=l.getSheetId()}e[i]=o,t[i]=u}return{allUnitData:e,unitSheetNameMap:t}}};Ht=_i([wi(0,d.IUniverInstanceService)],Ht);const Ue=A.createIdentifier("univer.formula.current-data.service");var Di=Object.defineProperty,yi=Object.getOwnPropertyDescriptor,bi=(r,n,e,t)=>{for(var s=t>1?void 0:t?yi(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&&Di(n,e,s),s},Li=(r,n)=>(e,t)=>n(e,t,r),ne=(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))(ne||{}),Me=(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))(Me||{});let Wt=class extends d.Disposable{constructor(n){super();_(this,"_formulaExecuteStage",0);_(this,"_stopState",!1);_(this,"_currentRow",-1);_(this,"_currentColumn",-1);_(this,"_currentRowCount",Number.NEGATIVE_INFINITY);_(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);_(this,"_currentSubUnitId","");_(this,"_currentUnitId","");_(this,"_runtimeData",{});_(this,"_runtimeOtherData",{});_(this,"_unitArrayFormulaRange",{});_(this,"_runtimeArrayFormulaCellData",{});_(this,"_runtimeClearArrayFormulaCellData",{});_(this,"_numfmtItemMap",{});_(this,"_runtimeFeatureRange",{});_(this,"_runtimeFeatureCellData",{});_(this,"_functionsExecutedState",0);_(this,"_functionDefinitionPrivacyVar",new Map);_(this,"_totalFormulasToCalculate",0);_(this,"_completedFormulasCount",0);_(this,"_totalArrayFormulasToCalculate",0);_(this,"_completedArrayFormulasCount",0);_(this,"_isCycleDependency",!1);this._currentConfigService=n}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(n){this._totalArrayFormulasToCalculate=n}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(n){this._completedArrayFormulasCount=n}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(n){this._totalFormulasToCalculate=n}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(n){this._completedFormulasCount=n}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(n){this._formulaExecuteStage=n}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(n,e,t,s,i,a){this._currentRow=n,this._currentColumn=e,this._currentRowCount=t,this._currentColumnCount=s,this._currentSubUnitId=i,this._currentUnitId=a}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(n,e){this._functionDefinitionPrivacyVar.set(n,e)}getFunctionDefinitionPrivacyVar(n){return this._functionDefinitionPrivacyVar.get(n)}setRuntimeOtherData(n,e){const 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[n]=this._objectValueToCellValue(e)}setRuntimeData(n){const e=this._currentRow,t=this._currentColumn,s=this._currentRowCount,i=this.currentColumnCount,a=this._currentSubUnitId,o=this._currentUnitId;this._runtimeData[o]==null&&(this._runtimeData[o]={});const u=this._runtimeData[o];u[a]==null&&(u[a]=new d.ObjectMatrix),this._unitArrayFormulaRange[o]==null&&(this._unitArrayFormulaRange[o]={}),this._numfmtItemMap[o]==null&&(this._numfmtItemMap[o]={}),this._numfmtItemMap[o][a]==null&&(this._numfmtItemMap[o][a]={});const l=this._numfmtItemMap[o][a],c=this._unitArrayFormulaRange[o];let m=new d.ObjectMatrix;c[a]&&(m=new d.ObjectMatrix(c[a])),this._runtimeArrayFormulaCellData[o]===void 0&&(this._runtimeArrayFormulaCellData[o]={});const g=this._runtimeArrayFormulaCellData[o];g[a]==null&&(g[a]=new d.ObjectMatrix),this._runtimeClearArrayFormulaCellData[o]===void 0&&(this._runtimeClearArrayFormulaCellData[o]={});const R=this._runtimeClearArrayFormulaCellData[o];R[a]==null&&(R[a]=new d.ObjectMatrix);const E=u[a],p=g[a],C=R[a];if(n.isReferenceObject()||n.isValueObject()&&n.isArray()){const D=n,{startRow:b,startColumn:L,endRow:S,endColumn:$}=D.getRangePosition();if(b===S&&L===$){const k=D.getFirstCell(),P=this._objectValueToCellValue(k);E.setValue(e,t,P),C.setValue(e,t,P),l[e]==null&&(l[e]={}),l[e][t]=k.getPattern();return}const I={startRow:e,startColumn:t,endRow:S-b+e,endColumn:$-L+t};if(m.setValue(e,t,I),c[a]=m.getData(),this._checkIfArrayFormulaRangeHasData(o,a,e,t,I)||this._checkIfArrayFormulaExceeded(s,i,I)){const k=this._objectValueToCellValue(new f(h.SPILL));E.setValue(e,t,k),C.setValue(e,t,k)}else{const k=new f(h.SPILL);D.iterator((P,x,M)=>{const F=this._objectValueToCellValue(P);if(x===b&&M===L){if(P!=null&&P.isError()&&P.isEqualType(k))return C.setValue(e,t,{}),E.setValue(e,t,{...this._objectValueToCellValue(k)}),!1;E.setValue(e,t,{...F})}const Oe=x-b+e,fr=M-L+t;p.setValue(Oe,fr,F);const mr=P==null?void 0:P.getPattern();mr&&(l[Oe]==null&&(l[Oe]={}),l[Oe][fr]=mr)})}}else{const D=this._objectValueToCellValue(n);E.setValue(e,t,D),l[e]==null&&(l[e]={}),l[e][t]=n.getPattern(),C.setValue(e,t,D)}}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(n,e){this._runtimeFeatureRange[n]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(n,e){this._runtimeFeatureCellData[n]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),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(n){if(n==null)return{v:0,t:d.CellValueType.NUMBER};if(n.isError())return{v:n.getErrorType(),t:d.CellValueType.STRING};if(n.isValueObject()){const e=n,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(n,e,t,s,i){var g,R,E,p,C,D,b,L,S,$,I,k;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,c=this._currentConfigService.getUnitData(),m=(E=(R=(g=this._unitArrayFormulaRange[n])==null?void 0:g[e])==null?void 0:R[t])==null?void 0:E[s];for(let P=a;P<=u;P++)for(let x=o;x<=l;x++){if(P===t&&s===x)continue;const M=(D=(C=(p=this._runtimeData)==null?void 0:p[n])==null?void 0:C[e])==null?void 0:D.getValue(P,x),F=(S=(L=(b=this._runtimeArrayFormulaCellData)==null?void 0:b[n])==null?void 0:L[e])==null?void 0:S.getValue(P,x),Oe=(k=(I=($=c==null?void 0:c[n])==null?void 0:$[e])==null?void 0:I.cellData)==null?void 0:k.getValue(P,x);if(!d.isNullCell(M)||!d.isNullCell(F)&&!this._isInArrayFormulaRange(m,P,x)||!d.isNullCell(Oe))return!0}return!1}_isInArrayFormulaRange(n,e,t){if(n==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:o}=n;return e>=s&&e<=a&&t>=i&&t<=o}_checkIfArrayFormulaExceeded(n,e,t){return t.endRow>=n||t.endColumn>=e}_isInDirtyRange(n,e,t,s){const i=this._currentConfigService.getDirtyRanges();return i.length===0?!0:Fr(i,n,e,t,s)}};Wt=bi([Li(0,Ue)],Wt);const re=A.createIdentifier("univer.formula.runtime.service");var Si=Object.defineProperty,Pi=Object.getOwnPropertyDescriptor,xi=(r,n,e,t)=>{for(var s=t>1?void 0:t?Pi(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&&Si(n,e,s),s},$t=(r,n)=>(e,t)=>n(e,t,r);let Ve=class extends d.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===Z.REFERENCE||l===Z.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}}};Ve=xi([$t(0,Vt),$t(1,re),$t(2,A.Inject(bt))],Ve);var B=(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))(B||{});const ie=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class z extends d.Disposable{constructor(e){super();_(this,"_children",[]);_(this,"_parent");_(this,"_valueObject");_(this,"_calculateState",!1);_(this,"_async",!1);_(this,"_address",!1);_(this,"_refOffsetX",0);_(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return B.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(Le.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 Y extends z{constructor(e){super(e);_(this,"_errorValueObject");this._errorValueObject=new f(e)}get nodeType(){return B.ERROR}static create(e){return new Y(e)}getValue(){return this._errorValueObject}}const ae=100;class oe extends d.Disposable{get zIndex(){return 0}create(n,e,t){let s;return n instanceof v?s=n.getToken():s=n,new z(s)}checkAndCreateNodeType(n){}}class Xt extends z{get nodeType(){return B.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class vn extends oe{get zIndex(){return ie.get(B.ROOT)||ae}checkAndCreateNodeType(n){if(!(n instanceof v))return;if(n.getToken()===Re)return new Xt(Re)}}class Bn extends d.Disposable{constructor(){super(...arguments);_(this,"_functionExecutors",new Map);_(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 fe=A.createIdentifier("univer.formula.function.service");var Ai=Object.defineProperty,Vi=Object.getOwnPropertyDescriptor,vi=(r,n,e,t)=>{for(var s=t>1?void 0:t?Vi(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&&Ai(n,e,s),s},xr=(r,n)=>(e,t)=>n(e,t,r);class mt extends z{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return B.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===Q.MINUS?t=this._functionExecutor.calculate(new w(0),e):this._operatorString===Q.AT?t=this._handlerAT(e):t=new f(h.VALUE),this.setValue(t)}_handlerAT(n){if(!n.isReferenceObject())return new f(h.VALUE);const e=n;if(e.isCell())return new f(h.VALUE);const t=this._accessor.get(re),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 f(h.VALUE)}}let gt=class extends oe{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ie.get(B.PREFIX)||ae}checkAndCreateNodeType(r){if(!(r instanceof v))return;const n=r.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Q.MINUS)t=W.MINUS;else return e===Q.AT?new mt(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new mt(this._injector,e,s):(console.error(`No function ${n}`),Y.create(h.NAME))}};gt=vi([xr(0,fe),xr(1,A.Inject(A.Injector))],gt);var Bi=Object.defineProperty,Ui=Object.getOwnPropertyDescriptor,Oi=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ui(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&&Bi(n,e,s),s},Ne=(r,n)=>(e,t)=>n(e,t,r);class Mi extends z{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 B.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(Le.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()?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.name!=="LOOKUP"||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,g=c-u+1,{startRow:R,startColumn:E,endRow:p,endColumn:C}=a,D=p-R+1,b=C-E+1;m!==D&&(a.endRow+=m-D),g!==b&&(a.endColumn+=g-b)}_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=Ee.create(s);else{const i=Cs(s);e=new q({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 dt=class extends oe{constructor(r,n,e,t){super(),this._functionService=r,this._currentConfigService=n,this._runtimeService=e,this._injector=t}get zIndex(){return ie.get(B.FUNCTION)||ae}create(r){const n=this._functionService.getExecutor(r);return n?new Mi(r,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${r}`),Y.create(h.NAME))}checkAndCreateNodeType(r){if(typeof r=="string")return;let e=r.getToken().trim().toUpperCase(),t,s;const i=e.slice(0,2);let a=0;if(new RegExp(Q.MINUS,"g").test(i)){const o=this._functionService.getExecutor(W.MINUS);t=new mt(this._injector,Q.MINUS,o),a++}if(new RegExp(Q.AT,"g").test(i)&&(s=new mt(this._injector,Q.AT),t&&s.setParent(t),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return s?o.setParent(s):t&&o.setParent(t),o}}};dt=Oi([Ne(0,fe),Ne(1,Ue),Ne(2,re),Ne(3,A.Inject(A.Injector))],dt);var Fi=Object.defineProperty,$i=Object.getOwnPropertyDescriptor,ki=(r,n,e,t)=>{for(var s=t>1?void 0:t?$i(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&&Fi(n,e,s),s},Ti=(r,n)=>(e,t)=>n(e,t,r);let $e=class extends d.Disposable{constructor(r){super(),this._runtimeService=r}dispose(){}async executeAsync(r){if(!r)return new f(h.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 new f(h.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(Le.ERROR);const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return r.nodeType===B.FUNCTION&&r.isAsync()?await r.executeAsync():r.execute(),Promise.resolve(Le.SUCCESS)}_execute(r){if(this._runtimeService.isStopExecution())return Le.ERROR;const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return r.execute(),Le.SUCCESS}};$e=ki([Ti(0,re)],$e);function Un(r){return r instanceof v?r.getToken()===Fe:!1}function Ii(r){return r instanceof v?r.getToken()===Kr:!1}function On(r){if(!r)return;if(r.getToken()!==ze)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:On(s)}class Qi extends Ce{constructor(e,t,s){super(0);_(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 f(h.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new ys(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()===ze){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const c=a.getCurrentLambdaPrivacyVar(),m=On(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 Yi=Object.defineProperty,ji=Object.getOwnPropertyDescriptor,Hi=(r,n,e,t)=>{for(var s=t>1?void 0:t?ji(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&&Yi(n,e,s),s},Ar=(r,n)=>(e,t)=>n(e,t,r);class Wi extends z{constructor(e,t,s,i){super(e);_(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return B.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 Qi(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let Rt=class extends oe{constructor(r,n){super(),this._runtimeService=r,this._interpreter=n}get zIndex(){return ie.get(B.LAMBDA)||ae}create(r){const n=r.getChildren(),e=n[0];let t=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof v&&s instanceof v))return Y.create(h.NAME);if(e.getToken()===Fe){const o=e.getChildren();if(t.length!==o.length)return Y.create(h.VALUE)}else t=n.slice(0,-1);const i=d.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof v){const l=u.getChildren()[0];u.setToken(Kr),a.set(l.trim(),void 0)}else return Y.create(h.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new Wi(r.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(r){if(!(!(r instanceof v)||r.getToken().trim().toUpperCase()!==Ge))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(!(Un(i)&&a!==0))if(o instanceof v)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const l=new v;l.setToken(ze),l.setLambdaId(n),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),t[a]=l}}}}};Rt=Hi([Ar(0,re),Ar(1,A.Inject($e))],Rt);function Mn(r){if(!r)return;if(r.getToken()!==ze)return r;const n=r,e=n.getCurrentLambdaPrivacyVar(),t=n.getLambdaParameter();if(e)return Mn(e.get(t))}class Xi extends z{constructor(n,e,t){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return B.LAMBDA_PARAMETER}execute(){const n=Mn(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(new f(h.SPILL))}}}class Fn extends oe{get zIndex(){return ie.get(B.LAMBDA_PARAMETER)||ae}create(n){const e=n.getFunctionDefinitionPrivacyVar(),t=n.getLambdaParameter();return e?new Xi(n.getToken(),t,e):new Y(h.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof v)||n.getToken().trim()!==ze))return this.create(n)}}class Gi extends z{constructor(n){super(n),this._operatorString=n}get nodeType(){return B.NULL}execute(){this.setValue(new le(0))}}var Ki=Object.defineProperty,qi=Object.getOwnPropertyDescriptor,zi=(r,n,e,t)=>{for(var s=t>1?void 0:t?qi(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&&Ki(n,e,s),s},Zi=(r,n)=>(e,t)=>n(e,t,r);class Ji extends z{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return B.OPERATOR}execute(){const n=this.getChildren();this._functionExecutor.name===W.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=n[0].getValue(),t=n[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 pt=class extends oe{constructor(r){super(),this._functionService=r}get zIndex(){return ie.get(B.OPERATOR)||ae}create(r){let n="";const e=r;e===K.PLUS?n=W.PLUS:e===K.MINUS?n=W.MINUS:e===K.MULTIPLY?n=W.MULTIPLY:e===K.DIVIDED?n=W.DIVIDED:e===K.CONCATENATE?n=At.CONCATENATE:e===K.POWER?n=ee.POWER:Yn.has(e)&&(n=W.COMPARE);const t=this._functionService.getExecutor(n);return t?new Ji(e,t):(console.error(`No function ${r}`),Y.create(h.NAME))}checkAndCreateNodeType(r){if(r instanceof v)return;const n=r.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&je.has(n))return this.create(n)}};pt=zi([Zi(0,fe)],pt);class Ni extends d.Disposable{constructor(){super(...arguments);_(this,"_tableMap",new Map);_(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 lr=A.createIdentifier("univer.formula.super-table.service");class ea extends Qe{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 g=-1,R=-1;const E=a.startRow,p=a.startColumn;m===ye.ALL?(g=E,R=p):m===ye.DATA?(g=E+1,R=p):m===ye.HEADERS?(g=E,R=E):m===ye.TOTALS&&(g=p,R=p),this.setRangeData({startColumn:l,endColumn:c,startRow:g,endRow:R})}isTable(){return!0}_stringToColumnData(n,e,t){n=n.substring(1,-1);const s=n.indexOf(U.COMMA);let i=-1,a=-1,o=ye.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=ye.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(U.COLON);if(new RegExp(Gr,"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 ta=Object.defineProperty,ra=Object.getOwnPropertyDescriptor,na=(r,n,e,t)=>{for(var s=t>1?void 0:t?ra(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&&ta(n,e,s),s},Ye=(r,n)=>(e,t)=>n(e,t,r);class et extends z{constructor(n,e,t,s=!1){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return B.REFERENCE}execute(){const n=this._accessor.get(Ue),e=this._accessor.get(re);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(new f(h.NAME)):this.setValue(this._referenceObject)}}let Et=class extends oe{constructor(r,n,e,t,s){super(),this._definedNamesService=r,this._superTableService=n,this._formulaRuntimeService=e,this._lexer=t,this._injector=s}get zIndex(){return ie.get(B.REFERENCE)||ae}checkAndCreateNodeType(r){var u,l;let n=!1,e,t=!1;if(r instanceof v?(n=!0,e=r.getToken().trim(),((l=(u=r.getParent())==null?void 0:u.getParent())==null?void 0:l.getToken().trim())===U.COLON&&(t=!0)):e=r.trim(),!n&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(yt).test(e))return new et(this._injector,e,new Cn(e),t);if(n&&new RegExp(Jn).test(e))return new et(this._injector,e,new wn(e),t);if(n&&new RegExp(Nn).test(e))return new et(this._injector,e,new _n(e),t);const s=this._formulaRuntimeService.currentUnitId,i=this._superTableService.getTableMap(s),a=new RegExp(Gr,"g"),o=e.replace(a,"");if(!n&&(i!=null&&i.has(o))){const c=a.exec(e);let m="";c&&(m=c[0]);const g=i.get(o),R=this._superTableService.getTableOptionMap();return new et(this._injector,e,new ea(e,g,m,R))}}};Et=na([Ye(0,Vt),Ye(1,lr),Ye(2,re),Ye(3,A.Inject(Ve)),Ye(4,A.Inject(A.Injector))],Et);var sa=Object.defineProperty,ia=Object.getOwnPropertyDescriptor,aa=(r,n,e,t)=>{for(var s=t>1?void 0:t?ia(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&&sa(n,e,s),s},Vr=(r,n)=>(e,t)=>n(e,t,r);class vr extends z{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return B.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===ce.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,new w(100)),t.setPattern("0.00%")):this._operatorString===ce.POUND?t=this._handlerPound(e):t=new f(h.VALUE),this.setValue(t)}_handlerPound(n){var c,m,g,R;if(!n.isReferenceObject())return new f(h.VALUE);if(!n.isCell())return new f(h.VALUE);const e=this._accessor.get(Ue),t=this._accessor.get(Ve),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(R=(g=(m=(c=u==null?void 0:u[a])==null?void 0:c[o])==null?void 0:m[i.startRow])==null?void 0:g[i.startColumn])==null?void 0:R.f;return l?(t.treeBuilder(l),new f(h.VALUE)):new f(h.VALUE)}}let Ct=class extends oe{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ie.get(B.SUFFIX)||ae}checkAndCreateNodeType(r){if(!(r instanceof v))return;const n=r.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===ce.PERCENTAGE)e=W.DIVIDED;else return n===ce.POUND?new vr(this._injector,n):void 0;const t=this._functionService.getExecutor(e);return t?new vr(this._injector,n,t):(console.error(`No function ${r}`),Y.create(h.NAME))}};Ct=aa([Vr(0,fe),Vr(1,A.Inject(A.Injector))],Ct);var oa=Object.defineProperty,ua=Object.getOwnPropertyDescriptor,la=(r,n,e,t)=>{for(var s=t>1?void 0:t?ua(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&&oa(n,e,s),s},ca=(r,n)=>(e,t)=>n(e,t,r);class ha extends z{constructor(n){super(n),this._operatorString=n}get nodeType(){return B.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===U.COLON?s=this._unionFunction(e,t):s=new f(h.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()?new f(h.REF):!n.isReferenceObject()||!e.isReferenceObject()?new f(h.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):new f(h.REF))}}let _t=class extends oe{constructor(r){super(),this._functionService=r}get zIndex(){return ie.get(B.UNION)||ae}create(r){return new ha(r)}checkAndCreateNodeType(r){if(!(r instanceof v))return;const e=r.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===U.COLON)return this.create(e)}};_t=la([ca(0,fe)],_t);class fa extends z{constructor(n){super(n),this._operatorString=n}get nodeType(){return B.VALUE}execute(){this.setValue(Ee.create(this._operatorString))}}class $n extends oe{get zIndex(){return ie.get(B.VALUE)||ae}_checkValueNode(n){if(Number.isNaN(Number(n))){const e=n.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(wt.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===Pe.TRUE||i===Pe.FALSE)return this.create(i)}else return this.create(n)}create(n){return new fa(n)}checkAndCreateNodeType(n){if(!(n instanceof v))return this._checkValueNode(n)}}var ma=Object.defineProperty,ga=Object.getOwnPropertyDescriptor,da=(r,n,e,t)=>{for(var s=t>1?void 0:t?ga(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&&ma(n,e,s),s},J=(r,n)=>(e,t)=>n(e,t,r);let qe=class extends d.Disposable{constructor(n,e,t,s,i,a,o,u,l,c,m){super();_(this,"_astNodeFactoryList",[]);_(this,"_refOffsetX",0);_(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 Xt(Re);return this._refOffsetX=e,this._refOffsetY=t,this._parse(n,s)}_lambdaParameterHandler(n,e){const t=e.getLambdaId(),s=new Xt(Re),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 g=o[m];if(g instanceof v)this._parse(g,s);else return!1}const l=s.getChildren(),c=l.length;for(let m=0;m<c;m++){const g=l[m];i.set(a[m],g)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new v;s.setToken(Ge);const i=new v;i.setToken(Fe);const a=[...e];for(let u=0;u<t;u++){const l=a[u];if(!(l instanceof v))return;u%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_getTopParent(n){let e=n;for(;e!=null&&e.getParent();)e=e.getParent();return e}_parse(n,e){const t=n.getChildren(),s=t.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===rs){const c=this._changeLetToLambda(n);return c!=null?this._parse(c,e):Y.create(h.ERROR)}if(o===De){if(a=e,s===0)return new Gi(Re).setParent(e),a}else{if(o===Fe){let c=this._lambdaParameterHandler(n,e);return c===!1&&(c=Y.create(h.ERROR)),c}if(a=this._checkAstNode(n),a==null)return Y.create(h.ERROR)}const u=t[0];for(let c=0;c<s;c++){const m=t[c];if(Un(u)){if(c!==0&&c!==s-1)continue}else if(Ii(m)&&c!==s-1)continue;let g=null;if(m instanceof v){if(g=this._parse(m,a),g===a)continue}else g=this._checkAstNode(m);if(g==null)return Y.create(h.NAME);if(g=this._getTopParent(g),g==null)return;switch(g.nodeType){case B.ERROR:return g;case B.FUNCTION:i.push(g);break;case B.LAMBDA:i.push(g);break;case B.LAMBDA_PARAMETER:i.push(g);break;case B.OPERATOR:{const R=i.pop(),E=i.pop();if(E)E.setParent(g);else return Y.create(h.ERROR);if(R)R.setParent(g);else return Y.create(h.ERROR);i.push(g);break}case B.REFERENCE:g.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(g);break;case B.ROOT:i.push(g);break;case B.UNION:i.push(g);break;case B.VALUE:i.push(g);break;case B.PREFIX:i.push(g);break;case B.SUFFIX:i.push(g);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(d.sortRules)}};qe=da([J(0,re),J(1,A.Inject(vn)),J(2,A.Inject(dt)),J(3,A.Inject(Rt)),J(4,A.Inject(Fn)),J(5,A.Inject(pt)),J(6,A.Inject(gt)),J(7,A.Inject(Et)),J(8,A.Inject(Ct)),J(9,A.Inject(_t)),J(10,A.Inject($n))],qe);class kn extends d.Disposable{constructor(){super(...arguments);_(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const vt=A.createIdentifier("univer.formula.feature-calculation-manager.service");class Tn extends d.Disposable{constructor(){super(...arguments);_(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 cr=A.createIdentifier("univer.formula.other-formula-manager.service");class kt extends d.Disposable{constructor(){super(...arguments);_(this,"node");_(this,"children",[]);_(this,"parents",[]);_(this,"formula","");_(this,"row",-1);_(this,"column",-1);_(this,"rowCount",Number.NEGATIVE_INFINITY);_(this,"columnCount",Number.NEGATIVE_INFINITY);_(this,"subUnitId","");_(this,"unitId","");_(this,"rangeList",[]);_(this,"formulaId");_(this,"featureId");_(this,"getDirtyData");_(this,"_state",0)}dispose(){var e;this.children.forEach(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:g}=l;if(((i=t[c])==null?void 0:i[m])!=null)return!0;if(!e.has(c))continue;const R=e.get(c);if(!R.has(m))continue;const E=R.get(m),p=(a=s==null?void 0:s[c])==null?void 0:a[m];let{startRow:C,endRow:D,startColumn:b,endColumn:L}=g;isNaN(C)&&(C=0),isNaN(b)&&(b=0),isNaN(D)&&(D=Number.POSITIVE_INFINITY),isNaN(L)&&(L=Number.POSITIVE_INFINITY);for(const S of E){const{startRow:$,startColumn:I,endRow:k,endColumn:P}=S;if(!(C>k||D<$||b>P||L<I)){let x=!0;if(p==null||p.forValue((M,F)=>{if(M>=C&&M<=D&&F>=b&&F<=L)return x=!1,!1}),x)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,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var Ra=Object.defineProperty,pa=Object.getOwnPropertyDescriptor,Ea=(r,n,e,t)=>{for(var s=t>1?void 0:t?pa(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&&Ra(n,e,s),s},_e=(r,n)=>(e,t)=>n(e,t,r);const Ca=1e5,Tt=new Dt(Ca);let We=class extends d.Disposable{constructor(n,e,t,s,i,a,o){super();_(this,"_updateRangeFlattenCache",new Map);_(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(),Tt.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),s=await this._generateTreeList(n,e,t),i=this._getUpdateTreeListAndMakeDependency(s);this._checkIsCycleDependency(i)&&this._runtimeService.enableCycleDependency();const o=this._calculateRunList(i);return Promise.resolve(o)}_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 o of s){const u=n[o];if(u==null)continue;const l=Object.keys(u);for(const c of l)new d.ObjectMatrix(u[c]).forValue((g,R,E)=>{if(E==null)return!0;const{f:p,x:C,y:D}=E,b=this._generateAstNode(p,C,D),L=new kt,S=t[o][c];L.node=b,L.formula=p,L.unitId=o,L.subUnitId=c,L.row=g,L.column=R,L.rowCount=S.rowCount,L.columnCount=S.columnCount,a.push(L)})}for(const o of i){const u=e[o];if(u==null)continue;const l=Object.keys(u);for(const c of l){const m=u[c];if(m==null)continue;const g=Object.keys(m);for(const R of g){const E=m[R],{f:p}=E,C=this._generateAstNode(p),D=new kt;D.node=C,D.formula=p,D.unitId=o,D.subUnitId=c,D.formulaId=R,a.push(D)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((o,u)=>{const{unitId:l,subUnitId:c,dependencyRanges:m,getDirtyData:g}=o,R=new kt;R.unitId=l,R.subUnitId=c,R.getDirtyData=g,R.featureId=u,R.rangeList=m,a.push(R)});for(let o=0,u=a.length;o<u;o++){const l=a[o];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const c=await this._getRangeListByNode(l.node);for(let m=0,g=c.length;m<g;m++)l.pushRangeList(c[m])}return a}_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=Tt.get(`${n}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(i in h)return Y.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return Tt.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===B.UNION||n.nodeType===B.PREFIX&&n.getToken()===Q.AT||n.nodeType===B.SUFFIX&&n.getToken()===ce.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===B.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===B.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();s.push(l)}for(let i=0,a=t.length;i<a;i++){const o=t[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}return s}_getUpdateTreeListAndMakeDependency(n){const e=[],t=new Set,s=this._currentConfigService.isForceCalculate();for(let i=0,a=n.length;i<a;i++){const o=n[i];for(let u=0,l=n.length;u<l;u++){const c=n[u];o!==c&&o.dependency(c)&&o.pushChildren(c)}(s||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!t.has(o)&&(e.push(o),t.add(o))}return e}_includeTree(n){var l,c,m,g,R;const e=n.unitId,t=n.subUnitId,s=n.featureId;if(s!=null){const E=this._currentConfigService.getDirtyUnitFeatureMap();if(((c=(l=E==null?void 0:E[e])==null?void 0:l[t])==null?void 0:c[s])!=null)return!0}const i=(g=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:g[t];let a=!1;if(i==null||i.forValue((E,p)=>{if(n.row===E&&n.column===p)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 o=this._updateRangeFlattenCache.get(e);if(!o.has(t))return!1;const u=o.get(t);for(const E of u)if(n.inRangeData(E))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];i.push(u)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};We=Ea([d.OnLifecycle(d.LifecycleStages.Rendered,We),_e(0,Ue),_e(1,re),_e(2,cr),_e(3,vt),_e(4,A.Inject($e)),_e(5,A.Inject(qe)),_e(6,A.Inject(Ve))],We);var _a=Object.defineProperty,wa=Object.getOwnPropertyDescriptor,Da=(r,n,e,t)=>{for(var s=t>1?void 0:t?wa(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&&_a(n,e,s),s},we=(r,n)=>(e,t)=>n(e,t,r);const ya=1;exports.CalculateFormulaService=class extends d.Disposable{constructor(e,t,s,i,a,o,u){super();_(this,"_executionStartListener$",new Bt.Subject);_(this,"executionStartListener$",this._executionStartListener$.asObservable());_(this,"_executionCompleteListener$",new Bt.Subject);_(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());_(this,"_executionInProgressListener$",new Bt.Subject);_(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")||ya;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(ne.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),jt.clear(),me.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 d.ObjectMatrix(o[u]);if(l==null)return!0;const c=new d.ObjectMatrix;l.forValue((m,g,R)=>{c.setValue(m,g,!0),s.push({unitId:a,sheetId:u,range:R})}),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 g of m)s.push({unitId:u,sheetId:c,range:g})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(ne.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(ne.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(ne.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(ne.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(ne.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:g}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,m),this._runtimeService.setRuntimeFeatureRange(o.featureId,g)}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(ne.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(ne.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(h).includes(s))return Y.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=Da([d.OnLifecycle(d.LifecycleStages.Rendered,exports.CalculateFormulaService),we(0,d.IConfigService),we(1,A.Inject(Ve)),we(2,Ue),we(3,re),we(4,A.Inject(We)),we(5,A.Inject($e)),we(6,A.Inject(qe))],exports.CalculateFormulaService);const hr={id:"formula.mutation.set-numfmt-formula-data",type:d.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).updateNumfmtItemMap(n.numfmtItemMap),!0)};var ba=Object.defineProperty,La=Object.getOwnPropertyDescriptor,Sa=(r,n,e,t)=>{for(var s=t>1?void 0:t?La(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&&ba(n,e,s),s},tt=(r,n)=>(e,t)=>n(e,t,r);let st=class extends d.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===Jt.id)this._calculateFormulaService.stopFormulaExecution();else if(r.id===er.id){const e=r.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(r.id===Zt.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===ht.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 Me.NOT_EXECUTED:break;case Me.STOP_EXECUTION:break;case Me.SUCCESS:this._applyFormula(r);break;case Me.INITIAL:break}this._commandService.executeCommand(ft.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(r=>{this._commandService.executeCommand(ft.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(ht.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),d.Tools.isEmptyObject(a)||this._commandService.executeCommand(hr.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Nt.id,{unitData:n,unitOtherData:e},{onlyLocal:!0})}};st=Sa([d.OnLifecycle(d.LifecycleStages.Ready,st),tt(0,d.ICommandService),tt(1,A.Inject(exports.CalculateFormulaService)),tt(2,d.IUniverInstanceService),tt(3,A.Inject(exports.FormulaDataModel))],st);var Pa=Object.defineProperty,xa=Object.getOwnPropertyDescriptor,Aa=(r,n,e,t)=>{for(var s=t>1?void 0:t?xa(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&&Pa(n,e,s),s},It=(r,n)=>(e,t)=>n(e,t,r);let Xe=class extends d.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(){[er,ht,Zt,Jt,ft,Nt,hr,Lt,St,qt,zt,tr,rr,Jr,Nr,nr,Gt,sr].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_registerFunctions(){const r=[...sn,...an,...un,...cn,...fn,...mn,...dn,...pn,...En,...Dn,...bn,...Ln,...Sn,...Pn,...xn,...An].concat(this._function).map(n=>{const e=n[0],t=n[1];return new e(t)});this._functionService.registerExecutors(...r)}};Xe=Aa([d.OnLifecycle(d.LifecycleStages.Ready,Xe),It(1,d.ICommandService),It(2,A.Inject(A.Injector)),It(3,fe)],Xe);var Va=Object.defineProperty,va=Object.getOwnPropertyDescriptor,Ba=(r,n,e,t)=>{for(var s=t>1?void 0:t?va(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&&Va(n,e,s),s},Qt=(r,n)=>(e,t)=>n(e,t,r);let it=class extends d.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===Gt.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 Oa(a,o)});this._functionService.registerExecutors(...s)}else if(r.id===sr.id){const e=r.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};it=Ba([d.OnLifecycle(d.LifecycleStages.Ready,it),Qt(0,d.ICommandService),Qt(1,A.Inject(exports.FormulaDataModel)),Qt(2,fe)],it);class Ua extends V{isCustom(){return!0}}function Oa(r,n){const e=new Ua(n),t=new Function(`return ${r}`)();return e.calculateCustom=t,e}var Ma=Object.defineProperty,Fa=Object.getOwnPropertyDescriptor,$a=(r,n,e,t)=>{for(var s=t>1?void 0:t?Fa(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&&Ma(n,e,s),s},Br=(r,n)=>(e,t)=>n(e,t,r);let at=class extends d.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===Lt.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===St.id){const n=r.params;if(n==null)return;const{unitId:e,name:t}=n;this._definedNamesService.removeDefinedName(e,t)}}))}};at=$a([d.OnLifecycle(d.LifecycleStages.Ready,at),Br(0,d.ICommandService),Br(1,Vt)],at);var ka=Object.defineProperty,Ta=Object.getOwnPropertyDescriptor,Ia=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ta(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&&ka(n,e,s),s},Ur=(r,n)=>(e,t)=>n(e,t,r);let ot=class extends d.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===qt.id){const n=r.params;if(n==null)return;const{featureId:e,calculationParam:t}=n;this._featureCalculationManagerService.register(e,t)}else if(r.id===zt.id){const n=r.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};ot=Ia([d.OnLifecycle(d.LifecycleStages.Ready,ot),Ur(0,d.ICommandService),Ur(1,vt)],ot);var Qa=Object.defineProperty,Ya=Object.getOwnPropertyDescriptor,ja=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ya(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&&Qa(n,e,s),s},Or=(r,n)=>(e,t)=>n(e,t,r);let ut=class extends d.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===tr.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(r.id===rr.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};ut=ja([d.OnLifecycle(d.LifecycleStages.Ready,ut),Or(0,d.ICommandService),Or(1,cr)],ut);var Ha=Object.defineProperty,Wa=Object.getOwnPropertyDescriptor,Xa=(r,n,e,t)=>{for(var s=t>1?void 0:t?Wa(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&&Ha(n,e,s),s},Mr=(r,n)=>(e,t)=>n(e,t,r);let lt=class extends d.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===Lt.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===St.id){const n=r.params;if(n==null)return;const{unitId:e,tableName:t}=n;this._superTableService.remove(e,t)}else if(r.id===nr.id){const n=r.params;if(n==null)return;const{tableOption:e,tableOptionType:t}=n;this._superTableService.registerTableOptionMap(e,t)}}))}};lt=Xa([d.OnLifecycle(d.LifecycleStages.Ready,lt),Mr(0,d.ICommandService),Mr(1,lr)],lt);var Ga=Object.defineProperty,Ka=Object.getOwnPropertyDescriptor,qa=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ka(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&&Ga(n,e,s),s},za=(r,n)=>(e,t)=>n(e,t,r);const Za="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends d.Plugin{constructor(n,e){super(Za),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[fe,{useClass:Bn}],[vt,{useClass:kn}],[Vt,{useClass:pi}],[exports.FormulaDataModel],[bt],[Xe,{useFactory:()=>{var t;return this._injector.createInstance(Xe,(t=this._config)==null?void 0:t.function)}}],[ot]];(e=this._config)!=null&&e.notExecuteFormula||n.push([exports.CalculateFormulaService],[cr,{useClass:Tn}],[lr,{useClass:Ni}],[Ue,{useClass:Ht}],[re,{useClass:Wt}],[st],[at],[ut],[lt],[it],[We],[$e],[qe],[Ve],[vn],[dt],[Rt],[Fn],[pt],[gt],[Et],[Ct],[_t],[$n]),n.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=qa([za(1,A.Inject(A.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=q;exports.BaseFunction=V;exports.BaseReferenceObject=Qe;exports.BaseValueObject=Ce;exports.BooleanValueObject=T;exports.ErrorType=h;exports.ErrorValueObject=f;exports.FUNCTION_NAMES_ARRAY=Ss;exports.FUNCTION_NAMES_COMPATIBILITY=on;exports.FUNCTION_NAMES_CUBE=ln;exports.FUNCTION_NAMES_DATABASE=hn;exports.FUNCTION_NAMES_DATE=ge;exports.FUNCTION_NAMES_ENGINEERING=gn;exports.FUNCTION_NAMES_FINANCIAL=Rn;exports.FUNCTION_NAMES_INFORMATION=ur;exports.FUNCTION_NAMES_LOGICAL=be;exports.FUNCTION_NAMES_LOOKUP=N;exports.FUNCTION_NAMES_MATH=ee;exports.FUNCTION_NAMES_STATISTICAL=de;exports.FUNCTION_NAMES_TEXT=At;exports.FUNCTION_NAMES_UNIVER=Ri;exports.FUNCTION_NAMES_WEB=Vn;exports.FeatureCalculationManagerService=kn;exports.FormulaExecuteStageType=ne;exports.FormulaExecutedStateType=Me;exports.FunctionService=Bn;exports.FunctionType=$r;exports.IFeatureCalculationManagerService=vt;exports.IFunctionService=fe;exports.LexerNode=v;exports.LexerTreeBuilder=bt;exports.NumberValueObject=w;exports.OtherFormulaManagerService=Tn;exports.RangeReferenceObject=Ke;exports.RegisterFunctionMutation=Gt;exports.RemoveDefinedNameMutation=St;exports.RemoveFeatureCalculationMutation=zt;exports.RemoveOtherFormulaMutation=rr;exports.RemoveSuperTableMutation=Nr;exports.SetArrayFormulaDataMutation=ht;exports.SetArrayFormulaDataUndoMutationFactory=as;exports.SetDefinedNameMutation=Lt;exports.SetFeatureCalculationMutation=qt;exports.SetFormulaCalculationNotificationMutation=ft;exports.SetFormulaCalculationResultMutation=Nt;exports.SetFormulaCalculationStartMutation=Zt;exports.SetFormulaCalculationStopMutation=Jt;exports.SetFormulaDataMutation=er;exports.SetNumfmtFormulaDataMutation=hr;exports.SetOtherFormulaMutation=tr;exports.SetSuperTableMutation=Jr;exports.SetSuperTableOptionMutation=nr;exports.StringValueObject=j;exports.UNIT_NAME_REGEX=he;exports.UnregisterFunctionMutation=sr;exports.ValueObjectFactory=Ee;exports.compareToken=y;exports.convertUnitDataToRuntime=Ir;exports.deserializeRangeForR1C1=nn;exports.deserializeRangeWithSheet=ke;exports.functionArray=sn;exports.functionCompatibility=an;exports.functionCube=un;exports.functionDatabase=cn;exports.functionDate=fn;exports.functionEngineering=mn;exports.functionFinancial=dn;exports.functionInformation=pn;exports.functionLogical=En;exports.functionLookup=Dn;exports.functionMath=bn;exports.functionMeta=Ln;exports.functionStatistical=Sn;exports.functionText=Pn;exports.functionUniver=xn;exports.functionWeb=An;exports.generateStringWithSequence=qr;exports.getAbsoluteRefTypeWitString=Gn;exports.getAbsoluteRefTypeWithSingleString=He;exports.includeFormulaLexerToken=Tr;exports.initSheetFormulaData=Zr;exports.isFormulaLexerToken=nt;exports.isInDirtyRange=Fr;exports.matchToken=U;exports.normalizeSheetName=Hn;exports.sequenceNodeType=Z;exports.serializeRange=Se;exports.serializeRangeToRefString=jr;exports.serializeRangeWithSheet=Qr;exports.serializeRangeWithSpreadsheet=Yr;
1
+ "use strict";var qn=Object.defineProperty;var zn=(n,r,e)=>r in n?qn(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var C=(n,r,e)=>(zn(n,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),v=require("@wendellhu/redi"),Ot=require("rxjs");function Qr(n,r,e,t,s){for(let i=0,a=n.length;i<a;i++){const o=n[i];if(r!==o.unitId||e!==o.sheetId)continue;const{startRow:u,startColumn:l,endRow:f,endColumn:m}=o.range;if(t>=u&&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 yt=new Set(Object.values(c));var Yr=(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))(Yr||{}),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||{}),y=(n=>(n.EQUALS="=",n.NOT_EQUAL="<>",n.GREATER_THAN=">",n.GREATER_THAN_OR_EQUAL=">=",n.LESS_THAN="<",n.LESS_THAN_OR_EQUAL="<=",n))(y||{});const rt=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),He=new Set(rt.keys()),Zn=new Set(["=","<>",">",">=","<","<="]);var M=(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))(M||{}),he=(n=>(n.PERCENTAGE="%",n.POUND="#",n))(he||{});const Jn=new Set(["%","#"]);var Q=(n=>(n.AT="@",n.MINUS="-",n))(Q||{});const Hr=[...Object.values(y),...Object.values(J),...Object.values(M),...Object.values(he),...Object.values(Q)];function nt(n){return Hr.includes(n)}function jr(n){for(const r of Hr)if(n.indexOf(r)>-1)return!0;return!1}function Nn(n){return n[0]==="'"&&n[n.length-1]==="'"?n.substring(1,n.length-1):n}function Wr(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 Zt={id:"formula.mutation.register-function",type:d.CommandType.MUTATION,handler:()=>!0};class bt{constructor(r){C(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 Wt='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',es="((?![\\[\\]\\/?*\\\\]).)*!",pe="$",Jt="\\s*?:\\s*?",ke=`'?(${Wt})?(${es})?'?`,Xt=`\\${pe}?[A-Za-z]+\\${pe}?[0-9]+`,ts=`^(${Q.AT})?${ke}${Xt}${Jt}${Xt}$`,St=`^${ke}\\s*?${Xt}(${he.POUND})?$`,Xr=`^${ke}\\${pe}?[0-9]+${Jt}\\${pe}?[0-9]+$`,Gr=`^${ke}\\${pe}?[A-Za-z]+${Jt}\\${pe}?[A-Za-z]+$`,rs=`^${ke}\\s*?\\${pe}?[0-9]+$`,ns=`^${ke}\\s*?\\${pe}?[A-Za-z]+$`,Kr="[.*?]",ss="{.*?}";function qr(n){return new RegExp(St).test(n)||new RegExp(ts).test(n)||new RegExp(Xr).test(n)||new RegExp(Gr).test(n)}const De="P_1",Re="R_1",Fe="L_1",ze="LR_1",zr="LO_1",is="LET",Ge="LAMBDA",as=/[^0-9]/g,os=/[^A-Za-z]/g;function je(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:je(e[0]),endAbsoluteRefType:je(e[1])}:{startAbsoluteRefType:je(e[0])}}function Er(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 Le(n){const{startColumn:r,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=d.RANGE_TYPE.NORMAL}=n,u=Er(i),l=Er(a);if(o===d.RANGE_TYPE.ROW||o===d.RANGE_TYPE.ALL){const g=`${u.rowAbsoluteString}${e+1}`,R=`${l.rowAbsoluteString}${s+1}`;return`${g}:${R}`}if(o===d.RANGE_TYPE.COLUMN){const g=`${u.columnAbsoluteString}${d.Tools.chatAtABC(r)}`,R=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}`;return`${g}:${R}`}const f=`${u.columnAbsoluteString}${d.Tools.chatAtABC(r)}${u.rowAbsoluteString}${e+1}`,m=`${l.columnAbsoluteString}${d.Tools.chatAtABC(t)}${l.rowAbsoluteString}${s+1}`;return f===m?f:`${f}:${m}`}function Zr(n,r){return ct(n)?`'${n}'!${Le(r)}`:`${n}!${Le(r)}`}function Jr(n,r,e){return ct(n)||ct(r)?`'[${n}]${r}'!${Le(e)}`:`[${n}]${r}!${Le(e)}`}function Nr(n){const{unitId:r,sheetName:e,range:t}=n;return r!=null&&r.length>0&&e!=null&&e.length>0?Jr(r,e,t):e!=null&&e.length>0?Zr(e,t):Le(t)}function Ft(n){const r=Number.parseInt(n.replace(as,""))-1,e=d.Tools.ABCatNum(n.replace(os,"")),t=je(n);return{row:r,column:e,absoluteRefType:t}}function en(n){const r=new RegExp(Wt).exec(n);let e="";r!=null&&(e=r[0].trim(),e=e.slice(1,e.length-1),n=n.replace(new RegExp(Wt),""));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 Ie(n){const{refBody:r,sheetName:e,unitId:t}=en(n),s=r.indexOf(":");if(s===-1){const E=Ft(r),p=E.row,_=E.column,D=E.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:p,startColumn:_,endRow:p,endColumn:_,startAbsoluteRefType:D,endAbsoluteRefType:D}}}const i=r.substring(0,s),a=r.substring(s+1),o=Ft(i),u=Ft(a),l=o.row,f=o.column,m=u.row,g=u.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:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:R}}}function ct(n){return n.length===0?!1:!!(jr(n)||ls(n)||cs(n)||fs(n)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(n))}function ls(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 cs(n){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(n)}function fs(n){return!new RegExp("^\\p{Letter}","u").test(n.charAt(0))}var ee=(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))(ee||{});function tn(n){let r="";for(const e of n)typeof e=="string"?r+=e:r+=e.token;return r}class B{constructor(){C(this,"_parent");C(this,"_token",Re);C(this,"_children",[]);C(this,"_lambdaId");C(this,"_functionDefinitionPrivacyVar");C(this,"_lambdaParameter","");C(this,"_startIndex",-1);C(this,"_endIndex",-1)}dispose(){var r;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(r=this._functionDefinitionPrivacyVar)==null||r.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(r){this._lambdaId=r}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(r){this._functionDefinitionPrivacyVar=r}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(r){this._lambdaParameter=r}getParent(){return this._parent}setParent(r){this._parent=r}getChildren(){return this._children}setChildren(r){this._children=r}addChildren(r){this._children.push(r)}addChildrenFirst(r){this._children.unshift(r)}getToken(){return this._token}setToken(r){this._token=r}setIndex(r,e){this._startIndex=r,this._endIndex=e}replaceChild(r,e){const t=this._getIndexInParent(r);t!=null&&(this.getChildren().splice(t,1,e),e.setParent(this))}changeToParent(r){const e=this.getParent();e&&e.removeChild(this),this.setParent(r),r.getChildren().push(this)}removeChild(r){const e=this._getIndexInParent(r);e!=null&&this.getChildren().splice(e,1)}serialize(){const r=this.getToken(),e=this.getChildren(),t=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof B?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 rn=1e5,$t=new bt(rn),kt=new bt(rn);class Lt extends d.Disposable{constructor(){super(...arguments);C(this,"_currentLexerNode",new B);C(this,"_upLevel",0);C(this,"_segment","");C(this,"_bracketState",[]);C(this,"_squareBracketState",0);C(this,"_bracesState",0);C(this,"_singleQuotationState",0);C(this,"_doubleQuotationState",0);C(this,"_lambdaState",!1);C(this,"_colonState",!1);C(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),$t.clear(),kt.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(),o=i;for(;a;){const u=a.getToken();if(u!==De&&!nt(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!==ee.REFERENCE){a.push(l);continue}const{token:f}=l,m=Ie(f),{range:g,sheetName:R,unitId:E}=m,p=d.Rectangle.moveOffset(g,t,s);let _="";d.isValidRange(p)?_=Nr({range:p,unitId:E,sheetName:R}):_=c.REF,a.push({...l,token:_})}return`=${tn(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===M.CLOSE_BRACKET||i===" ")&&s>=0;)i===M.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===c.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),l=0;for(a[1]===M.OPEN_BRACKET&&l++;u;){const f=u.getToken();f!==De&&f!==M.COLON&&u.getStartIndex()!==-1&&f.toUpperCase()!==Ge&&(t===0?l+=1:t--),u=u.getParent()}return l}sequenceNodesBuilder(e){const t=kt.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return kt.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:f,cur:m}=o;if(f===M.DOUBLE_QUOTATION&&(s=!0),(l!==""||i===0)&&i!==a-1){t.push(f);continue}let g=(u==null?void 0:u.segment)||"";const R=i-g.length;let E=i-1;const p=i-1;if(i===a-1&&this._isLastMergeString(f)&&(g+=f,E+=1),g===""||rt.has(g)){t.push(f);continue}const _=g.trim(),D=this._replacePrefixString(_);s===!0&&_[_.length-1]===M.DOUBLE_QUOTATION?(s=!1,this._pushSequenceNode(t,{nodeType:ee.STRING,token:g,startIndex:R,endIndex:E},p)):new RegExp(St).test(D)?this._pushSequenceNode(t,{nodeType:ee.REFERENCE,token:g,startIndex:R,endIndex:E},p):d.Tools.isStringNumber(_)?this._pushSequenceNode(t,{nodeType:ee.NUMBER,token:g,startIndex:R,endIndex:E},p):_.length>0&&this._pushSequenceNode(t,{nodeType:ee.FUNCTION,token:g,startIndex:R,endIndex:E},p),(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===M.DOUBLE_QUOTATION||d.Tools.isStringNumber(e)||!nt(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()===M.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===ee.FUNCTION&&o.token.trim().substring(0,1)===M.OPEN_BRACES){o.nodeType=ee.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===M.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&qr((a.token+o+u.token).trim())&&(a.nodeType=ee.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){return e.replace(new RegExp(Q.AT,"g"),"").replace(new RegExp(Q.MINUS,"g"),"")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const f=$t.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 o=!1,u="";if(s){const{hasDefinedName:f,sequenceString:m}=s(i);o=f,u=m}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(Re),a=this._nodeMaker(`=${u}`),a===c.VALUE))return a;const l=this._getTopNode(this._currentLexerNode);return l&&(this._currentLexerNode=l),t&&(this._suffixExpressionHandler(this._currentLexerNode),$t.set(e,this._currentLexerNode)),this._currentLexerNode}_suffixExpressionHandler(e){var o,u;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 B)this._suffixExpressionHandler(f),i.push(f);else{const m=f.trim();if(m==="")continue;if(He.has(m)){for(;a.length>0;){const g=(o=a[a.length-1])==null?void 0:o.trim();if(!g||g===M.OPEN_BRACKET)break;const R=rt.get(g),E=rt.get(m);if(!R||!E)break;if(E>=R)i.push(a.pop());else break}a.push(f)}else if(m===M.OPEN_BRACKET)a.push(f);else if(m===M.CLOSE_BRACKET)for(;a.length>0;){const g=(u=a[a.length-1])==null?void 0:u.trim();if(!g)break;if(g===M.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 B}_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 B)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()===Fe){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const f=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();f&&(this._currentLexerNode=f),t=!0}}else if(e!=null&&e.getParent()){const f=(u=this._currentLexerNode.getParent())==null?void 0:u.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 B)&&this.isColonOpen()){const i=new B;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 B;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===M.OPEN_BRACKET||e===M.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new B,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!!nt(i)}_nodeMaker(e,t,s){e.substring(0,1)===J.EQUALS&&(e=e.substring(1));const i=e.split(""),a=i.length;let o=0;for(this._resetTemp();o<a;){const u=i[o];if(s===o)return[this._currentLexerNode,u];if(u===M.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,o),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=i[o+1];if(l&&l===M.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return c.VALUE;o++}else l&&this._newAndPushCurrentLexerNode(De,o)}else this._pushNodeToChildren(u),this._openBracket(0);else if(u===M.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(u);else if(l===1){const f=i[o+1];if(f&&f===M.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&o!==a-1)return c.VALUE;this._newAndPushCurrentLexerNode(Fe,o,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&o!==a-1)return c.VALUE}else return c.VALUE;this._closeBracket()}else if(u===M.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._openBraces();else if(u===M.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(u),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(u===M.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(u),this._openSquareBracket();else if(u===M.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(u),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(u);else if(u===M.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=i[o+1];l&&l===M.DOUBLE_QUOTATION?o++:this._closeDoubleQuotation()}this._pushSegment(u)}else if(u===M.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=i[o+1];l&&l===M.SINGLE_QUOTATION?o++:this._closeSingleQuotation()}this._pushSegment(u)}else if(u===M.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&o!==a-1&&l!=null)return c.VALUE;this._newAndPushCurrentLexerNode(De,o)}else return c.VALUE}else if(u===M.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new B;l.setToken(u);const f=new B;f.setToken(De),f.setParent(l);const m=new B;m.setToken(De),m.setParent(l),l.getChildren().push(f,m);let g=l,R=0;if(this._segmentCount()>0){let E,p,_=0;const D=this._segment.trim(),b=D[0],S=D[1];if(b===Q.MINUS&&(E=new B,E.setToken(Q.MINUS),_++),(b===Q.AT||S===Q.AT)&&(p=new B,p.setToken(Q.AT),E&&(E.addChildren(p),p.setParent(E)),_++),_>0&&(this._segment=D.slice(_)),R=_,p)if(p.addChildren(l),l.setParent(p),p.getParent()){const k=p.getParent();k&&(g=k)}else g=p;else E&&(g=E,E.addChildren(l),l.setParent(E));const x=new B;x.setToken(this._segment),x.setParent(f),f.getChildren().push(x),this._resetSegment()}else{const E=this._getLastChildCurrentLexerNode();E&&E.changeToParent(f)}this._setCurrentLexerNode(g),this._currentLexerNode=m,this._openColon(R)}else if(Jn.has(u)&&this._checkSimilarErrorToken(u,o,i)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new B;l.setToken(u);const f=this._getLastChildCurrent();f instanceof B?f.changeToParent(l):f!==!1&&(l.getChildren().push(f),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(He.has(u)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(u===J.MINUS&&l===""){const f=this._findPreviousToken(i,o-1)||"";if(this._negativeCondition(f)){this._pushSegment(J.MINUS),t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++;continue}}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(u===J.LESS_THAN||u===J.GREATER_THAN){const f=i[o+1];f&&He.has(u+f)?(this._pushNodeToChildren(l+u+f),o++):this._pushNodeToChildren(l+u)}else this._pushNodeToChildren(l+u);this._resetSegment()}else this._pushSegment(u);t==null||t.push({segment:this._segment,currentString:u,cur:o,currentLexerNode:this._currentLexerNode}),o++}this._pushNodeToChildren(this._segment)}}var hs=Object.defineProperty,ms=Object.getOwnPropertyDescriptor,gs=(n,r,e,t)=>{for(var s=t>1?void 0:t?ms(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&&hs(r,e,s),s},wr=(n,r)=>(e,t)=>r(e,t,n);exports.FormulaDataModel=class extends d.Disposable{constructor(e,t){super();C(this,"_formulaData",{});C(this,"_arrayFormulaRange",{});C(this,"_arrayFormulaCellData",{});C(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],o=(f=(l=this._arrayFormulaRange)==null?void 0:l[t])==null?void 0:f[i];if(o==null)return!0;let u=new d.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,E)=>{var x;const p=(x=o==null?void 0:o[R])==null?void 0:x[E];if(p==null)return!0;const{startRow:_,startColumn:D,endRow:b,endColumn:S}=p;for(let k=_;k<=b;k++)for(let T=D;T<=S;T++)u.setValue(k,T,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,f,m,g;const a=s[i];let o=new d.ObjectMatrix,u=new d.ObjectMatrix;((l=this._arrayFormulaRange[t])==null?void 0:l[i])!=null&&(o=new d.ObjectMatrix((f=this._arrayFormulaRange[t])==null?void 0:f[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new d.ObjectMatrix((g=this._arrayFormulaCellData[t])==null?void 0:g[i])),a.forValue((R,E)=>{const p=o==null?void 0:o.getValue(R,E);if(p==null)return!0;const{startRow:_,startColumn:D,endRow:b,endColumn:S}=p;for(let x=_;x<=b;x++)for(let k=D;k<=S;k++)u.setValue(x,k,null)}),a.forValue((R,E,p)=>{u.setValue(R,E,p)}),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 d.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),o.forValue((u,l,f)=>{this._numfmtItemMap[t][i][u]==null&&(this._numfmtItemMap[t][i][u]={}),this._numfmtItemMap[t][i][u][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 u,l;const a=new d.ObjectMatrix(s[i]);let o=new d.ObjectMatrix;(u=this._arrayFormulaRange[t])!=null&&u[i]&&(o=new d.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),a.forValue((f,m,g)=>{o.setValue(f,m,g)}),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 d.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();nn(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 f of o){const m=f.getSheetId(),g=f.getConfig();u[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]=u,s[a]=l}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new d.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 f=new d.ObjectMatrix(l[t]);i.forValue((m,g,R)=>{const E=(R==null?void 0:R.f)||"",p=(R==null?void 0:R.si)||"",_=d.isFormulaString(E),D=d.isFormulaId(p);if(_&&D)f.setValue(m,g,{f:E,si:p}),a.set(p,{f:E,r:m,c:g});else if(_&&!D)f.setValue(m,g,{f:E});else if(!_&&D)f.setValue(m,g,{f:"",si:p});else if(!_&&!D&&f.getValue(m,g)){const b=f.getValue(m,g),S=(b==null?void 0:b.f)||"",x=(b==null?void 0:b.si)||"";d.isFormulaString(S)&&d.isFormulaId(x)&&o.set(x,S),f.realDeleteValue(m,g)}}),f.forValue((m,g,R)=>{const E=(R==null?void 0:R.f)||"",p=(R==null?void 0:R.si)||"";if(d.isFormulaId(p)){const _=a.get(p),D=o.get(p);if(_&&!d.isFormulaString(E)){const b=_.f,S=g-_.c,x=m-_.r;f.setValue(m,g,{f:b,si:p,x:S,y:x})}else if(typeof D=="string"){const b=R.x||0,S=R.y||0,x=this._lexerTreeBuilder.moveFormulaRefOffset(D,b,S);o.set(p,{r:m,c:g,f:x}),f.setValue(m,g,{f:x,si:p})}else if(typeof D=="object"){const b=g-D.c,S=m-D.r;f.setValue(m,g,{f:D.f,si:p,x:b,y:S})}}})}updateArrayFormulaRange(e,t,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[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)||"",E=(m==null?void 0:m.si)||"",p=d.isFormulaString(R),_=d.isFormulaId(E);!p&&!_&&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),o=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!o)return;const u=new d.ObjectMatrix(o);new d.ObjectMatrix(s).forValue((g,R,E)=>{const p=a==null?void 0:a.getValue(g,R);if(p==null)return!0;const _=(E==null?void 0:E.f)||"",D=(E==null?void 0:E.si)||"",b=d.isFormulaString(_),S=d.isFormulaId(D);if(!b&&!S){const{startRow:x,startColumn:k,endRow:T,endColumn:I}=p;for(let P=x;P<=T;P++)for(let V=k;V<=I;V++)u.realDeleteValue(P,V)}})}updateNumfmtData(e,t,s){var f,m;const i=(f=this._arrayFormulaRange[e])==null?void 0:f[t],a=new d.ObjectMatrix(i),o=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!o)return;const u=new d.ObjectMatrix(o);new d.ObjectMatrix(s).forValue((g,R,E)=>{const p=(E==null?void 0:E.f)||"",_=(E==null?void 0:E.si)||"",D=d.isFormulaString(p),b=d.isFormulaId(_);if(!D&&!b){u.setValue(g,R,null);const S=a.getValue(g,R);if(S){const{startRow:x,startColumn:k,endRow:T,endColumn:I}=S;for(let P=x;P<=T;P++)for(let V=k;V<=I;V++)u.setValue(P,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 o=new d.ObjectMatrix(a[t]);let u=null;return o.forValue((l,f,m)=>{const{f:g,si:R,x:E=0,y:p=0}=m;if(R===e&&g.length>0&&E===0&&p===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 d.ObjectMatrix(a[t]).forValue((u,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,E=(f==null?void 0:f.y)||0;d.isFormulaString(m)&&d.isFormulaId(g)&&R===0&&E===0&&s.set(g,{f:m,r:u,c:l})}),s}};exports.FormulaDataModel=gs([wr(0,d.IUniverInstanceService),wr(1,v.Inject(Lt))],exports.FormulaDataModel);function nn(n,r,e,t){const s=new Map,i=new d.ObjectMatrix;t.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",f=(u==null?void 0:u.si)||"",m=d.isFormulaString(l),g=d.isFormulaId(f);m&&g?(i.setValue(a,o,{f:l,si:f}),s.set(f,{f:l,r:a,c:o})):m&&!g?i.setValue(a,o,{f:l}):!m&&g&&i.setValue(a,o,{f:"",si:f})}),i.forValue((a,o,u)=>{const l=(u==null?void 0:u.f)||"",f=(u==null?void 0:u.si)||"";if(d.isFormulaId(f)&&!d.isFormulaString(l)){const m=s.get(f);if(m){const g=m.f,R=o-m.c,E=a-m.r;i.setValue(a,o,{f:g,si:f,x:R,y:E})}}}),n[r]&&(n[r][e]=i.getData())}const ds=n=>{const r=n.get(exports.FormulaDataModel),e=d.Tools.deepClone(r.getArrayFormulaRange()),t=d.Tools.deepClone(r.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},ft={id:"formula.mutation.set-array-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>{const e=n.get(exports.FormulaDataModel);return e.setArrayFormulaRange(r.arrayFormulaRange),e.setArrayFormulaCellData(r.arrayFormulaCellData),!0}},At={id:"formula.mutation.set-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},xt={id:"formula.mutation.remove-defined-name",type:d.CommandType.MUTATION,handler:()=>!0},Nt={id:"formula.mutation.set-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},er={id:"formula.mutation.remove-feature-calculation",type:d.CommandType.MUTATION,handler:()=>!0},tr={id:"formula.mutation.set-formula-calculation-start",type:d.CommandType.MUTATION,handler:()=>!0},rr={id:"formula.mutation.set-formula-calculation-stop",type:d.CommandType.MUTATION,handler:()=>!0},ht={id:"formula.mutation.set-formula-calculation-notification",type:d.CommandType.MUTATION,handler:()=>!0},nr={id:"formula.mutation.set-formula-calculation-result",type:d.CommandType.MUTATION,handler:()=>!0},sr={id:"formula.mutation.set-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(exports.FormulaDataModel).setFormulaData(r.formulaData),!0)},ir={id:"formula.mutation.set-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},ar={id:"formula.mutation.remove-other-formula",type:d.CommandType.MUTATION,handler:()=>!0},sn={id:"formula.mutation.set-super-table",type:d.CommandType.MUTATION,handler:()=>!0},an={id:"formula.mutation.remove-super-table",type:d.CommandType.MUTATION,handler:()=>!0},or={id:"formula.mutation.set-super-table-option",type:d.CommandType.MUTATION,handler:()=>!0},ur={id:"formula.mutation.unregister-function",type:d.CommandType.MUTATION,handler:()=>!0};class Pt extends d.Disposable{constructor(){super(...arguments);C(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 Ae=(n=>(n.FALSE="FALSE",n.TRUE="TRUE",n))(Ae||{}),Se=(n=>(n[n.SUCCESS=0]="SUCCESS",n[n.ERROR=1]="ERROR",n))(Se||{}),ye=(n=>(n.ALL="#All",n.DATA="#Data",n.HEADERS="#Headers",n.TOTALS="#Totals",n))(ye||{}),ne=(n=>(n[n.FRONT=0]="FRONT",n[n.BACK=1]="BACK",n))(ne||{});class Rs{constructor(){C(this,"_cache",new Map);C(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 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=[],u.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,o;return(o=(a=(i=this._cache.get(r))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:o.get(s)}getCellPosition(r,e,t,s,i,a){const o=this.getCellPositions(r,e,t,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(r,e,t,s,i){let a=this._continueBuildingCache.get(r);a==null&&(a=new Map,this._continueBuildingCache.set(r,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);if(u==null){u={startRow:s,endRow:i},o.set(t,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(r,e,t,s){var u,l;const i=(l=(u=this._continueBuildingCache.get(r))==null?void 0:u.get(e))==null?void 0:l.get(t);if(i==null)return!0;const{startRow:a,endRow:o}=i;return!(s>=a&&s<=o)}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:o,endRow:u}=a;return!(s>u||i<o)}clear(){this._cache.clear(),this._continueBuildingCache.clear()}}const ge=new Rs;var fe=(n=>(n[n.MIN=0]="MIN",n[n.MAX=1]="MAX",n))(fe||{}),q=(n=>(n[n.NORMAL=0]="NORMAL",n[n.MIN=1]="MIN",n[n.MAX=2]="MAX",n))(q||{});function _r(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(n,r)=>n.localeCompare(r)}function ps(n){return n.indexOf("*")>-1||n.indexOf("?")>-1}function Cr(n,r){const e=r.replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(n)}function Dr(n){return n.replace(/~?[*?]/g,r=>r.startsWith("~")?r.substring(1):" ")}function Es(n,r,e){let t=!1;switch(e){case y.EQUALS:t=Cr(n,r);break;case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:t=Cr(n,r)||n>Dr(r);break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:t=n<Dr(r);break}return t}class we extends Pt{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,y.EQUALS)}isNotEqual(r){return this.compare(r,y.NOT_EQUAL)}isGreaterThanOrEqual(r){return this.compare(r,y.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(r){return this.compare(r,y.LESS_THAN_OR_EQUAL)}isLessThan(r){return this.compare(r,y.LESS_THAN)}isGreaterThan(r){return this.compare(r,y.GREATER_THAN)}concatenateFront(r){return new h(c.NAME)}concatenateBack(r){return new h(c.NAME)}plusBy(r){return new h(c.NAME)}minusBy(r){return new h(c.NAME)}multiplyBy(r){return new h(c.NAME)}dividedBy(r){return new h(c.NAME)}modInverse(r){return new h(c.VALUE)}compareBy(r,e){return new h(c.NAME)}concatenate(r,e=ne.FRONT){let t=this.getValue().toString();if(typeof r=="string")e===ne.FRONT?t=r+t:t+=r;else if(typeof r=="number")e===ne.FRONT?t=r.toString()+t:t+=r.toString();else if(typeof r=="boolean"){const s=r?"TRUE":"FALSE";e===ne.FRONT?t=s+t:t+=s}return t}pow(r){return new h(c.VALUE)}powInverse(r){return new h(c.VALUE)}sqrt(){return new h(c.VALUE)}cbrt(){return new h(c.VALUE)}cos(){return new h(c.VALUE)}acos(){return new h(c.VALUE)}acosh(){return new h(c.VALUE)}sin(){return new h(c.VALUE)}asin(){return new h(c.VALUE)}asinh(){return new h(c.VALUE)}tan(){return new h(c.VALUE)}tanh(){return new h(c.VALUE)}atan(){return new h(c.VALUE)}atan2(r){return new h(c.VALUE)}atan2Inverse(r){return new h(c.VALUE)}atanh(){return new h(c.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return new h(c.VALUE)}log10(){return new h(c.VALUE)}exp(){return new h(c.VALUE)}abs(){return new h(c.VALUE)}round(r){return new h(c.VALUE)}roundInverse(r){return new h(c.VALUE)}floor(r){return new h(c.VALUE)}floorInverse(r){return new h(c.VALUE)}ceil(r){return new h(c.VALUE)}ceilInverse(r){return new h(c.VALUE)}}class h extends 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,xe=1e6,yr=1e6,Cs=-7,Ds=21,ys=!1,Ze="[big.js] ",Ve=Ze+"Invalid ",Vt=Ve+"decimal places",bs=Ve+"rounding mode",on=Ze+"Division by zero",$={},oe=void 0,Ss=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function un(){function n(r){var e=this;if(!(e instanceof n))return r===oe?un():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(Ve+"value");r=r===0&&1/r<0?"-0":String(r)}Ls(e,r)}e.constructor=n}return n.prototype=$,n.DP=ws,n.RM=_s,n.NE=Cs,n.PE=Ds,n.strict=ys,n.roundDown=0,n.roundHalfUp=1,n.roundHalfEven=2,n.roundUp=3,n}function Ls(n,r){var e,t,s;if(!Ss.test(r))throw Error(Ve+"number");for(n.s=r.charAt(0)=="-"?(r=r.slice(1),-1):1,(e=r.indexOf("."))>-1&&(r=r.replace(".","")),(t=r.search(/e/i))>0?(e<0&&(e=t),e+=+r.slice(t+1),r=r.substring(0,t)):e<0&&(e=r.length),s=r.length,t=0;t<s&&r.charAt(t)=="0";)++t;if(t==s)n.c=[n.e=0];else{for(;s>0&&r.charAt(--s)=="0";);for(n.e=e-t-1,n.c=[],e=0;t<=s;)n.c[e++]=+r.charAt(t++)}return n}function ve(n,r,e,t){var s=n.c;if(e===oe&&(e=n.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(bs);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]!==oe))),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]!==oe||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 Te(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}$.abs=function(){var n=new this.constructor(this);return n.s=1,n};$.cmp=function(n){var r,e=this,t=e.c,s=(n=new e.constructor(n)).c,i=e.s,a=n.s,o=e.e,u=n.e;if(!t[0]||!s[0])return t[0]?i:s[0]?-a:0;if(i!=a)return i;if(r=i<0,o!=u)return o>u^r?1:-1;for(a=(o=t.length)<(u=s.length)?o:u,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^r?1:-1;return o==u?0:o>u^r?1:-1};$.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>xe)throw Error(Vt);if(!s[0])throw Error(on);if(!t[0])return n.s=i,n.c=[n.e=0],n;var o,u,l,f,m,g=s.slice(),R=o=s.length,E=t.length,p=t.slice(0,o),_=p.length,D=n,b=D.c=[],S=0,x=a+(D.e=r.e-n.e)+1;for(D.s=i,i=x<0?0:x,g.unshift(0);_++<o;)p.push(0);do{for(l=0;l<10;l++){if(o!=(_=p.length))f=o>_?1:-1;else for(m=-1,f=0;++m<o;)if(s[m]!=p[m]){f=s[m]>p[m]?1:-1;break}if(f<0){for(u=_==o?s:g;_;){if(p[--_]<u[_]){for(m=_;m&&!p[--m];)p[m]=9;--p[m],p[_]+=10}p[_]-=u[_]}for(;!p[0];)p.shift()}else break}b[S++]=f?l:++l,p[0]&&f?p[_]=t[R]||0:p=[t[R]]}while((R++<E||p[0]!==oe)&&i--);return!b[0]&&S!=1&&(b.shift(),D.e--,x--),S>x&&ve(D,x,e.RM,p[0]!==oe),D};$.eq=function(n){return this.cmp(n)===0};$.gt=function(n){return this.cmp(n)>0};$.gte=function(n){return this.cmp(n)>-1};$.lt=function(n){return this.cmp(n)<0};$.lte=function(n){return this.cmp(n)<1};$.minus=$.sub=function(n){var r,e,t,s,i=this,a=i.constructor,o=i.s,u=(n=new a(n)).s;if(o!=u)return n.s=-u,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=-u:l[0]?n=new a(i):n.s=1,n;if(o=f-g){for((s=o<0)?(o=-o,t=l):(g=f,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,n.s=-n.s),(u=(e=m.length)-(r=l.length))>0)for(;u--;)l[r++]=0;for(u=r;e>o;){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[--u]===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};$.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(on);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)))};$.neg=function(){var n=new this.constructor(this);return n.s=-n.s,n};$.plus=$.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,o=s.c,u=n.e,l=n.c;if(!o[0]||!l[0])return l[0]||(o[0]?n=new i(s):n.s=s.s),n;if(o=o.slice(),r=a-u){for(r>0?(u=a,t=l):(r=-r,t=o),t.reverse();r--;)t.push(0);t.reverse()}for(o.length-l.length<0&&(t=l,l=o,o=t),r=l.length,e=0;r;o[r]%=10)e=(o[--r]=o[r]+l[r]+e)/10|0;for(e&&(o.unshift(e),++u),r=o.length;o[--r]===0;)o.pop();return n.c=o,n.e=u,n};$.pow=function(n){var r=this,e=new r.constructor("1"),t=e,s=n<0;if(n!==~~n||n<-yr||n>yr)throw Error(Ve+"exponent");for(s&&(n=-n);n&1&&(t=t.times(r)),n>>=1,!!n;)r=r.times(r);return s?e.div(t):t};$.prec=function(n,r){if(n!==~~n||n<1||n>xe)throw Error(Ve+"precision");return ve(new this.constructor(this),n,r)};$.round=function(n,r){if(n===oe)n=0;else if(n!==~~n||n<-xe||n>xe)throw Error(Vt);return ve(new this.constructor(this),n+this.e+1,r)};$.sqrt=function(){var n,r,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(Ze+"No square root");i=Math.sqrt(t+""),i===0||i===1/0?(r=t.c.join(""),r.length+a&1||(r+="0"),i=Math.sqrt(r),a=((a+1)/2|0)-(a<0||a&1),n=new s((i==1/0?"5e":(i=i.toExponential()).slice(0,i.indexOf("e")+1))+a)):n=new s(i+""),a=n.e+(s.DP+=4);do e=n,n=o.times(e.plus(t.div(e)));while(e.c.slice(0,a).join("")!==n.c.slice(0,a).join(""));return ve(n,(s.DP-=4)+n.e+1,s.RM)};$.times=$.mul=function(n){var r,e=this,t=e.constructor,s=e.c,i=(n=new t(n)).c,a=s.length,o=i.length,u=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=u+l,a<o&&(r=s,s=i,i=r,l=a,a=o,o=l),r=new Array(l=a+o);l--;)r[l]=0;for(u=o;u--;){for(o=0,l=a+u;l>u;)o=r[l]+i[u]*s[l-u-1]+o,r[l--]=o%10,o=o/10|0;r[l]=o}for(o?++n.e:r.shift(),u=r.length;!r[--u];)r.pop();return n.c=r,n};$.toExponential=function(n,r){var e=this,t=e.c[0];if(n!==oe){if(n!==~~n||n<0||n>xe)throw Error(Vt);for(e=ve(new e.constructor(e),++n,r);e.c.length<n;)e.c.push(0)}return Te(e,!0,!!t)};$.toFixed=function(n,r){var e=this,t=e.c[0];if(n!==oe){if(n!==~~n||n<0||n>xe)throw Error(Vt);for(e=ve(new e.constructor(e),n+e.e+1,r),n=n+e.e+1;e.c.length<n;)e.c.push(0)}return Te(e,!1,!!t)};$[Symbol.for("nodejs.util.inspect.custom")]=$.toJSON=$.toString=function(){var n=this,r=n.constructor;return Te(n,n.e<=r.NE||n.e>=r.PE,!!n.c[0])};$.toNumber=function(){var n=Number(Te(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(n.toString()))throw Error(Ze+"Imprecise conversion");return n};$.toPrecision=function(n,r){var e=this,t=e.constructor,s=e.c[0];if(n!==oe){if(n!==~~n||n<1||n>xe)throw Error(Ve+"precision");for(e=ve(new t(e),n,r);e.c.length<n;)e.c.push(0)}return Te(e,n<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)};$.valueOf=function(){var n=this,r=n.constructor;if(r.strict===!0)throw Error(Ze+"valueOf disallowed");return Te(n,n.e<=r.NE||n.e>=r.PE,!0)};var Y=un();function ln(n){let r;switch(n){case y.EQUALS:r=y.EQUALS;break;case y.GREATER_THAN:r=y.LESS_THAN;break;case y.GREATER_THAN_OR_EQUAL:r=y.LESS_THAN_OR_EQUAL;break;case y.LESS_THAN:r=y.GREATER_THAN;break;case y.LESS_THAN_OR_EQUAL:r=y.GREATER_THAN_OR_EQUAL;break;case y.NOT_EQUAL:r=y.NOT_EQUAL;break}return r}function lr(n,r){return Y(n).times(r).toNumber()}function br(n,r){const e=10**Math.floor(r);return Math.round(lr(n,e))/e}function Sr(n,r){const e=10**Math.floor(r);return Math.floor(lr(n,e))/e}function Lr(n,r){const e=10**Math.floor(r);return Math.ceil(lr(n,e))/e}function Ar(n,r){const e=new Y(n),t=new Y(r),s=Math.floor(n/r);return e.minus(t.times(s)).toNumber()}function xr(n,r){return n**r}class ae extends we{isNull(){return!0}plus(r){return new w(0,!0).plus(r)}minus(r){return new w(0,!0).minus(r)}multiply(r){return new w(0,!0).multiply(r)}divided(r){return new w(0,!0).divided(r)}mod(r){return new w(0,!0).mod(r)}compare(r,e){return r.isString()?new W("").compare(r,e):r.isBoolean()?new A(!1).compare(r,e):new w(0,!0).compare(r,e)}concatenateFront(r){return r.isArray()?r.concatenateBack(new W("")):new W(this.concatenate(r.getValue(),ne.FRONT))}concatenateBack(r){return r.isArray()?r.concatenateFront(new W("")):new W(this.concatenate(r.getValue(),ne.BACK))}plusBy(r){return new w(0).plusBy(r)}minusBy(r){return new w(0).minusBy(r)}multiplyBy(r){return new w(0).multiplyBy(r)}dividedBy(r){return new w(0).dividedBy(r)}compareBy(r,e){return typeof r=="string"?new W("").compareBy(r,e):typeof r=="boolean"?new A(!1).compareBy(r,e):new w(0,!0).compareBy(r,e)}pow(r){return new w(0,!0).pow(r)}sqrt(){return new w(0,!0).sqrt()}cbrt(){return new w(0,!0).cbrt()}cos(){return new w(0,!0).cos()}acos(){return new w(0,!0).acos()}acosh(){return new w(0,!0).acosh()}sin(){return new w(0,!0).sin()}asin(){return new w(0,!0).asin()}asinh(){return new w(0,!0).asinh()}tan(){return new w(0,!0).tan()}tanh(){return new w(0,!0).tanh()}atan(){return new w(0,!0).atan()}atan2(r){return new w(0,!0).atan2(r)}atanh(){return new w(0,!0).atanh()}log(){return new h(c.NUM)}log10(){return new h(c.NUM)}exp(){return new w(0,!0).exp()}abs(){return new w(0,!0).abs()}round(r){return new w(0,!0).round(r)}floor(r){return new w(0,!0).floor(r)}ceil(r){return new w(0,!0).ceil(r)}}class A extends we{constructor(e,t=!1){super(e);C(this,"_value",!1);if(t){this._value=e;return}if(typeof e=="boolean")this._value=e;else if(typeof e=="string"){const s=e.toLocaleUpperCase();s===Ae.TRUE?this._value=!0:s===Ae.FALSE&&(this._value=!1)}else e===1?this._value=!0:this._value=!1}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),new w(-t,!0)}getReciprocal(){return this.getValue()?new w(1,!0):new h(c.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}mod(e){return this._convertTonNumber().mod(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),new w(t,!0)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}}class w extends we{constructor(e,t=!1){super(e);C(this,"_value",0);if(t){this._value=e;return}this._value=Number(e)}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return new w(0).minus(this)}getReciprocal(){return new w(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()?this:(t.setPattern(this.getPattern()||e.getPattern()),t)}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return new h(c.DIV_BY_ZERO);if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(s===0)return new h(c.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Ar(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?new h(c.DIV_BY_ZERO):new w(Ar(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):new W(this.concatenate(e.getValue(),ne.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new W(this.concatenate(e.getValue(),ne.BACK))}compare(e,t){return e.isArray()?e.compare(this,ln(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return yt.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=Y(t).plus(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(Y(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=Y(t).minus(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(Y(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=Y(t).times(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?new w(Y(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=Y(t).div(e).toNumber();return Number.isFinite(s)?new w(s):new h(c.NUM)}return typeof e=="boolean"?e===!1?new h(c.DIV_BY_ZERO):new w(Y(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}else if(typeof e=="number")if(!Number.isFinite(s)||!Number.isFinite(e))i=this._compareInfinity(s,e,t);else switch(t){case y.EQUALS:i=Y(s).eq(e);break;case y.GREATER_THAN:i=Y(s).gt(e);break;case y.GREATER_THAN_OR_EQUAL:i=Y(s).gte(e);break;case y.LESS_THAN:i=Y(s).lt(e);break;case y.LESS_THAN_OR_EQUAL:i=Y(s).lte(e);break;case y.NOT_EQUAL:i=!Y(s).eq(e);break}else if(typeof e=="boolean")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new A(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=xr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(xr(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Y(e).sqrt().toNumber();return Number.isFinite(t)?new w(t):new h(c.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.cos(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acos(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.acosh(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.sin(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asin(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.asinh(e);return Number.isNaN(t)?new h(c.NUM):new w(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tan(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.tanh(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atan(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.atanh(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0)return new h(c.NUM);if(!Number.isFinite(e))return new h(c.NUM);const t=Math.log10(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.exp(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return new h(c.NUM);const t=Math.abs(e);return Number.isFinite(t)?new w(t):new h(c.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return new h(c.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return new h(c.NUM);const i=br(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(br(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=Sr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Sr(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=Lr(t,s);return Number.isFinite(i)?new w(i):new h(c.NUM)}return typeof s=="boolean"?new w(Lr(t,s?1:0)):this}_compareInfinity(e,t,s){let i=!1;switch(s){case y.EQUALS:i=e===t;break;case y.GREATER_THAN:i=e>t;break;case y.GREATER_THAN_OR_EQUAL:i=e>=t;break;case y.LESS_THAN:i=e<t;break;case y.LESS_THAN_OR_EQUAL:i=e<=t;break;case y.NOT_EQUAL:i=e!==t;break}return i}}class W extends we{constructor(e,t=!1){super(e);C(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 W(this.concatenate(e.getValue(),ne.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):new W(this.concatenate(e.getValue(),ne.BACK))}compare(e,t){return e.isArray()?e.compare(this,ln(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(ps(e))return this._checkWildcard(e,t);switch(t){case y.EQUALS:i=s===e;break;case y.GREATER_THAN:i=s>e;break;case y.GREATER_THAN_OR_EQUAL:i=s>=e;break;case y.LESS_THAN:i=s<e;break;case y.LESS_THAN_OR_EQUAL:i=s<=e;break;case y.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case y.NOT_EQUAL:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!0;break;case y.EQUALS:case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case y.EQUALS:case y.GREATER_THAN:case y.GREATER_THAN_OR_EQUAL:i=!1;break;case y.LESS_THAN:case y.LESS_THAN_OR_EQUAL:case y.NOT_EQUAL:i=!0;break}return new A(i)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=Es(s,e,t);return new A(i)}}function As(n){return""}function xs(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]=Ee.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:As());C(this,"_values",[]);C(this,"_rowCount",-1);C(this,"_columnCount",-1);C(this,"_unitId","");C(this,"_sheetId","");C(this,"_currentRow",-1);C(this,"_currentColumn",-1);C(this,"_sliceCache",new Map);C(this,"_flattenCache");C(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 ae(0);const i=s[t];return i==null?new ae(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(),o=this.getArrayValue();for(let u=t;u<=s;u++)for(let l=i;l<=a;l++)if(e(o[u][l],u,l)===!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)}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 ae(0)]],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.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 f=this.get(u,l);if(f.isError()||f.isNull()){a++;continue}f.isString()?(e.push(f),s.push(a++)):(t.push(f),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 f=`${s}_${i}_${a}_${o}_${u}_${l}`,m=this._sliceCache.get(f);if(m!=null)return m;const g=[],R=this._values;let E=0,p=0;for(let S=s;S<i;S+=a){p=0,g[E]==null&&(g[E]=[]);for(let x=o;x<u;x+=l)g[E][p]=R[S][x],p++;E++}if(g.length===0||g[0].length===0)return;const _=a>1?-1:s+this._currentRow,D=l>1?-1:o+this._currentColumn,b=this._createNewArray(g,g.length,g[0].length,_,D);return this._sliceCache.set(f,b),b}sortByRow(e){const t=this._transposeArray(this._values);t.sort(this._sort(e)),this._clearCache(),this._values=this._transposeArray(t)}sortByColumn(e){this._clearCache(),this._values.sort(this._sort(e))}transpose(){const e=this._transposeArray(this._values),t=this._rowCount,s=this._columnCount;return this._createNewArray(e,s,t)}orderSearch(e,t=q.MIN,s=!1,i=!1){let a,o,u,l;const f=(m,g,R)=>{if(m==null)return!0;let E;if(i===!0?E=m.compare(e,y.EQUALS):E=m.isEqual(e),(E==null?void 0:E.getValue())===!0)return a=m,u={row:g,column:R},!1;t===q.MAX?m.isGreaterThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,l={row:g,column:R}):t===q.MIN&&m.isLessThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=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 E=g-1;E>=0;E--){const p=this._values[R][E];f(p,R,E)}}else this.iterator((m,g,R)=>{f(m,g,R)});if(a!=null)return u;if(o!=null)return l}binarySearch(e,t=fe.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=fe.MIN){const a=_r(),o=e.getValue().toString();let u=0,l=t.length-1,f=null;for(;u<=l;){const m=Math.floor((u+l)/2),g=t[m];let R=0;if(g.isNull())R=1;else{const E=g.getValue();R=a(E.toString(),o)}if(R===0)return s[m];R===-1?(u=m+1,i===fe.MIN&&(f=m)):(l=m-1,i===fe.MAX&&(f=m))}if(f!=null)return s[f]}sum(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=new w(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=new w(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=new w(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=new w(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return new 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,o;const t=this._rowCount,s=this._columnCount,i=[];for(let u=0;u<t;u++){const l=[];for(let f=0;f<s;f++){const m=(o=(a=this._values)==null?void 0:a[u])==null?void 0:o[f];m?l[f]=e(m,u,f):l[f]=new h(c.VALUE)}i.push(l)}return this._createNewArray(i,t,s)}pow(e){return this._batchOperator(e,9)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,13)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0);if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2),a=t.get(0,s/2-1);return i.plus(a).divided(new w(2,!0))}return t.get(0,(s-1)/2)}var(e=0){const t=this.mean(),s=[[]];this.iterator(f=>{if(f==null||f.isError()||f.isString()||f.isBoolean()||f.isNull())return;const m=f.minus(t).pow(new w(2,!0));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:o,_currentColumn:u}=this;return new z({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,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=_r();return(s,i)=>{const a=s[e],o=i[e];return a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,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(),f=e.getColumnCount();if(a=Math.max(l,a),o=Math.max(f,o),l===1&&f===1){const m=e.getFirstCell();for(let g=0;g<o;g++)i.push(m)}else if(l===1&&this._columnCount>1){const m=e.getArrayValue();for(let g=0;g<o;g++)i.push(m[0][g])}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 f=i[l];this._batchOperatorValue(f,l,u,t,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,s,i,a){var R,E;const o=this._rowCount;let u=!1;const l=this.getUnitId(),f=this.getSheetId(),m=this.getCurrentRow(),g=this.getCurrentColumn();if(i===5&&(u=ge.canUseCache(l,f,t+g,m,m+o-1),u===!0)){if(a===y.EQUALS){const p=ge.getCellPositions(l,f,t+g,e.getValue());for(let _=0;_<o;_++)s[_]==null&&(s[_]=[]),p!=null&&p.includes(_+m)?s[_][t]=new A(!0):s[_][t]=new A(!1)}else{const p=ge.getCellValuePositions(l,f,t+g);if(p!=null){p.forEach((_,D)=>{let b=new ae(0);typeof D=="string"?b=new W(D):typeof D=="number"?b=new w(D):typeof D=="boolean"&&(b=new A(D)),b.compare(e,a).getValue()===!0&&_.forEach(x=>{x>=m&&x<=m+o-1&&(s[x-m]==null&&(s[x-m]=[]),s[x-m][t]=new A(!0))})});for(let _=0;_<o;_++)s[_]==null&&(s[_]=[]),s[_][t]==null&&(s[_][t]=new A(!1))}else for(let _=0;_<o;_++)s[_]==null&&(s[_]=[]),s[_][t]=new A(!1)}return}for(let p=0;p<o;p++){const _=(E=(R=this._values)==null?void 0:R[p])==null?void 0:E[t];if(s[p]==null&&(s[p]=[]),_&&e)if(_.isError())s[p][t]=_;else if(e.isError())s[p][t]=e;else switch(i){case 1:s[p][t]=_.plus(e);break;case 0:s[p][t]=_.minus(e);break;case 2:s[p][t]=_.multiply(e);break;case 3:s[p][t]=_.divided(e);break;case 4:s[p][t]=_.mod(e);break;case 5:a?s[p][t]=_.compare(e,a):s[p][t]=new h(c.VALUE);break;case 6:s[p][t]=_.concatenateFront(e);break;case 7:s[p][t]=_.concatenateBack(e);break;case 8:a?s[p][t]=_.product(e,a):s[p][t]=new h(c.VALUE);break;case 9:s[p][t]=_.pow(e);break;case 10:s[p][t]=_.round(e);break;case 11:s[p][t]=_.floor(e);break;case 13:s[p][t]=_.atan2(e);break;case 12:s[p][t]=_.ceil(e);break}else s[p][t]=new h(c.NA);_!=null&&(_.isError()?ge.set(l,f,t+g,_.getErrorType(),p+m):_.isNull()?ge.set(l,f,t+g,null,p+m):ge.set(l,f,t+g,_.getValue(),p+m))}ge.setContinueBuildingCache(l,f,t+g,m,m+o-1)}_batchOperatorArray(e,t,s){var m,g,R,E,p,_,D,b,S,x,k,T;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),f=this._checkArrayCalculateType(e);for(let I=0;I<i;I++){const P=[];for(let V=0;V<a;V++){let O;l===3?O=(g=(m=this._values)==null?void 0:m[0])==null?void 0:g[0]:l===1?O=(E=(R=this._values)==null?void 0:R[0])==null?void 0:E[V]:l===2?O=(_=(p=this._values)==null?void 0:p[I])==null?void 0:_[0]:O=(b=(D=this._values)==null?void 0:D[I])==null?void 0:b[V];let F;if(f===3?F=(S=u==null?void 0:u[0])==null?void 0:S[0]:f===1?F=(x=u==null?void 0:u[0])==null?void 0:x[V]:f===2?F=(k=u==null?void 0:u[I])==null?void 0:k[0]:F=(T=u==null?void 0:u[I])==null?void 0:T[V],O&&F)if(O.isError())P[V]=O;else if(F.isError())P[V]=F;else switch(t){case 1:P[V]=O.plus(F);break;case 0:P[V]=O.minus(F);break;case 2:P[V]=O.multiply(F);break;case 3:P[V]=O.divided(F);break;case 4:P[V]=O.mod(F);break;case 5:s?P[V]=O.compare(F,s):P[V]=new h(c.VALUE);break;case 6:P[V]=O.concatenateFront(F);break;case 7:P[V]=O.concatenateBack(F);break;case 8:s?P[V]=O.product(F,s):P[V]=new h(c.VALUE);break;case 9:P[V]=O.pow(F);break;case 10:P[V]=O.round(F);break;case 13:P[V]=O.atan2(F);break;case 11:P[V]=O.floor(F);break;case 12:P[V]=O.ceil(F);break}else P[V]=new h(c.NA)}o.push(P)}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(","),f=l.length;a<f&&(a=f);const m=[];for(let g=0;g<f;g++){const R=l[g].trim();m.push(Ee.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 o={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return new z(o)}}class Ee{static create(r){if(r==null)return new ae(0);if(typeof r=="boolean")return new A(r,!0);if(typeof r=="string"){const e=r.toLocaleUpperCase().trim();return yt.has(e)?new h(e):e===Ae.TRUE||e===Ae.FALSE?new A(e):d.isRealNum(r)?new w(r):new RegExp(ss,"g").test(r.replace(/\n/g,"").replace(/\r/g,""))?new z(r.replace(/\n/g,"").replace(/\r/g,"")):new W(r)}return typeof r=="number"?Number.isFinite(r)?new w(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 vs=1e5,Gt=new bt(vs);class Qe extends Pt{constructor(e){super();C(this,"_forcedSheetId","");C(this,"_forcedSheetName","");C(this,"_defaultSheetId","");C(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});C(this,"_unitData",{});C(this,"_defaultUnitId","");C(this,"_forcedUnitId","");C(this,"_runtimeData",{});C(this,"_arrayFormulaCellData",{});C(this,"_runtimeArrayFormulaCellData",{});C(this,"_runtimeFeatureCellData",{});C(this,"_numfmtItemData",{});C(this,"_refOffsetX",0);C(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 o=this._forcedUnitId||this._defaultUnitId,u=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 E=this.getCellData(g,R);let p=!1;if(E==null||d.isNullCell(E)){p=e(null,g,R);continue}const _=this.getCellValueObject(E),D=(m=(f=(l=this._numfmtItemData[o])==null?void 0:l[u])==null?void 0:f[g])==null?void 0:m[R];if(D&&_.setPattern(D),p=e(_,g,R),p===!1)return}}getFirstCell(){var l,f,m;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return new w(0,!0);const i=this.getCellValueObject(s),a=this._forcedUnitId||this._defaultUnitId,o=this._forcedSheetId||this._defaultSheetId,u=(m=(f=(l=this._numfmtItemData[a])==null?void 0:l[o])==null?void 0:f[e])==null?void 0:m[t];return u&&i.setPattern(u),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 yt.has(t)?new h(t):e.t===d.CellValueType.NUMBER?new w(t):e.t===d.CellValueType.STRING||e.t===d.CellValueType.FORCE_STRING?new W(t):e.t===d.CellValueType.BOOLEAN?new A(t):Ee.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):new h(c.VALUE)}toArrayValueObject(e=!0){var E;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,u=Gt.get(o);if(u&&e)return u;const l=s-t+1,f=a-i+1;if(l<0||f<0)return this._getBlankArrayValueObject();const m=new Array(l);this.iterator((p,_,D)=>{const b=_-t,S=D-i;m[b]||(m[b]=new Array(f)),p==null&&(p=new ae(0)),m[b][S]=p});const g={calculateValueList:m,rowCount:m.length,columnCount:((E=m[0])==null?void 0:E.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},R=new z(g);return e&&Gt.set(o,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 Bs extends Pt{constructor(r){super(),this._promise=r}isAsyncObject(){return!0}async getValue(){return this._promise}}class Us extends Pt{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 o=i[a];o.isAsyncObject()?r[s][a]=await o.getValue():r[s][a]=o}}const e={calculateValueList:r,rowCount:r.length,columnCount:((t=r[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:0,column:0};return new z(e)}}class Ke extends Qe{constructor(r,e,t){super(""),this.setRangeData(r),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const Pr=/[\[\]]/g;function Vr(n,r){if(Pr.test(n)){const e=Number(n.replace(Pr,""));return r+e}return Number(n)-1}function It(n,r=0,e=0){n=n.toLocaleUpperCase();const t=n.split(/[RC]/),s=t[1],i=t[2],a=Vr(s,r),o=Vr(i,e);return{row:a,column:o,absoluteRefType:d.AbsoluteRefType.NONE}}function cn(n,r=0,e=0){const{refBody:t,sheetName:s,unitId:i}=en(n),a=t.indexOf(":");if(a===-1){const p=It(t,r,e),_=p.row,D=p.column,b=p.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:_,startColumn:D,endRow:_,endColumn:D,startAbsoluteRefType:b,endAbsoluteRefType:b}}}const o=t.substring(0,a),u=t.substring(a+1),l=It(o,r,e),f=It(u,r,e),m=l.row,g=l.column,R=f.row,E=f.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:g,endRow:R,endColumn:E,startAbsoluteRefType:l.absoluteRefType,endAbsoluteRefType:f.absoluteRefType}}}function Ms(n){const r=Je(n.startRow,n.startAbsoluteRefType,!0),e=Je(n.startColumn,n.startAbsoluteRefType,!1),t=Je(n.endRow,n.endAbsoluteRefType,!0),s=Je(n.endColumn,n.endAbsoluteRefType,!1);return r===t&&e===s?`R${r}C${e}`:`R${r}C${e}:R${t}C${s}`}function Je(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 fn=[];var Os=(n=>{})();function mt(n){const r=n.getValue();let e=0;return r&&(e=1),new w(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 o=e.getFirstCell();for(let u=0;u<n;u++){const l=[];for(let f=0;f<r;f++)l.push(o);s.push(l)}}else if(i===1&&a>1)for(let o=0;o<n;o++){const u=[];for(let l=0;l<r;l++){const f=e.getRealValue(0,l)||(t!=null?t:new ae(0));u.push(f)}s.push(u)}else if(a===1&&i>1)for(let o=0;o<n;o++){const u=[];for(let l=0;l<r;l++){const f=e.getRealValue(o,0)||(t!=null?t:new ae(0));u.push(f)}s.push(u)}else for(let o=0;o<n;o++){const u=[];for(let l=0;l<r;l++){const f=e.getRealValue(o,l)||(t!=null?t:new ae(0));u.push(f)}s.push(u)}}else for(let i=0;i<n;i++){const a=[];for(let o=0;o<r;o++)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 L extends d.Disposable{constructor(e){super();C(this,"_unitId");C(this,"_subUnitId");C(this,"_row",-1);C(this,"_column",-1);C(this,"needsExpandParams",!1);C(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 o;return s.getRowCount()===1?o=s.get(0,a):o=s.get(a,0),o.isNull()?new h(c.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()?new h(c.NA):o}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,y.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?new h(c.NA):o}orderSearch(e,t,s,i=q.MIN,a=!1){const o=t.orderSearch(e,i,a);if(o==null)return new h(c.NA);const u=s.get(o.row,o.column);return u.isNull()?new h(c.NA):u}binarySearchExpand(e,t,s,i=0,a){const o=t.binarySearch(e,a);return o==null?new h(c.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?new h(c.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,y.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?new h(c.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,t,s,i=q.MIN,a=!1,o=0){const u=t.orderSearch(e,i,a);return u==null?new h(c.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.isError())return a;if(a.isString()){const o=a.getValue();if(!d.isRealNum(o))return new h(c.VALUE);a=new w(o)}if(a.isBoolean()&&(a=mt(a)),a.isNull()&&(a=new w(0)),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 gt(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=mt(e)),e.isString()){const t=Number(e.getValue());e=new w(isNaN(t)?0:t)}return e}}class hn extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std()}}class mn extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.std(1)}}class gn extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var()}}class dn extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r);return e.isError()?e:e.var(1)}}var Me=(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))(Me||{});const Rn=[[mn,Me.STDEV],[hn,Me.STDEVP],[dn,Me.VAR],[gn,Me.VARP]],pn=[];var En=(n=>(n.CUBEKPIMEMBER="CUBEKPIMEMBER",n.CUBEMEMBER="CUBEMEMBER",n.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",n.CUBERANKEDMEMBER="CUBERANKEDMEMBER",n.CUBESET="CUBESET",n.CUBESETCOUNT="CUBESETCOUNT",n.CUBEVALUE="CUBEVALUE",n))(En||{});const wn=[];var _n=(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))(_n||{});const cr="yyyy-mm-dd;@";function fr(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 vt(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 hr(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"),o=`${s}-${i}-${a}`;return n.replace(/\//g,"-").split("-").map(l=>l.padStart(2,"0")).join("-")===o}class Fs extends L{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),o=j(s,i,e),u=j(s,i,t);return a.map((l,f,m)=>{const g=o.get(f,m),R=u.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 E=+l.getValue();const p=Math.floor(+g.getValue()),_=+R.getValue();if(E<0||E>9999)return new h(c.NUM);E>=0&&E<1899&&(E+=1900);const D=new Date(E,p-1,_),b=fr(D);if(b<0)return new h(c.NUM);const S=new w(b);return S.setPattern(cr),S})}}class $s extends L{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(!hr(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new w(0);e=vt(a)}const s=e.getDate();return new w(s)}}class ks extends L{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((o,u,l)=>{const f=a.get(u,l);if(o.isError())return o;if(f.isError())return f;if(o.isString()||o.isBoolean()||f.isString()||f.isBoolean())return new h(c.VALUE);const m=+o.getValue();if(m<0)return new h(c.NUM);const g=Math.floor(+f.getValue()),R=vt(m),E=R.getUTCFullYear(),p=R.getUTCMonth()+g,_=R.getUTCDate(),D=new Date(Date.UTC(E,p,_)),b=fr(D),S=new w(b);return S.setPattern(cr),S})}}var de=(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))(de||{});class Is extends L{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(!hr(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+r.getValue();if(a<0)return new h(c.NUM);if(a===0)return new w(1);e=vt(a)}const s=e.getUTCMonth()+1;return new w(s)}}class Ts extends L{calculate(r){if(r)return new h(c.NA);const e=fr(new Date),t=new w(e);return t.setPattern(cr),t}}class Qs extends L{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(!hr(`${t}`))return new h(c.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return new h(c.NUM);if(a===0)return new w(1900);e=vt(a)}const s=e.getUTCFullYear();return new w(s)}}const Cn=[[Fs,de.DATE],[$s,de.DAY],[ks,de.EDATE],[Is,de.MONTH],[Ts,de.TODAY],[Qs,de.YEAR]],Dn=[];var yn=(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))(yn||{});const bn=[];var Sn=(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))(Sn||{}),re=(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))(re||{});class Ys extends L{calculate(r){return r==null?new h(c.NA):r.isNull()?new A(!0):r.isArray()?r.mapValue(e=>e.isNull()?new A(!0):new A(!1)):new A(!1)}}class Hs extends L{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new A(!1):r.isError()?new A(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new A(!1):e.isError()?new A(!0):new A(!1)):new A(!1)}}class js extends L{calculate(r){return r==null?new h(c.NA):r.isError()?new A(!0):r.isArray()?r.mapValue(e=>e.isError()?new A(!0):new A(!1)):new A(!1)}}class Ws extends L{calculate(r){return r==null?new h(c.NA):r.isBoolean()?new A(!0):r.isArray()?r.mapValue(e=>e.isBoolean()?new A(!0):new A(!1)):new A(!1)}}class Xs extends L{calculate(r){return r==null?new h(c.NA):r.getValue()===c.NA?new A(!0):r.isArray()?r.mapValue(e=>e.getValue()===c.NA?new A(!0):new A(!1)):new A(!1)}}class Gs extends L{calculate(r){return r==null?new h(c.NA):!r.isArray()&&!r.isString()?new A(!0):r.isArray()?r.mapValue(e=>e.isString()?new A(!1):new A(!0)):new A(!1)}}class Ks extends L{calculate(r){return r==null?new h(c.NA):r.isNumber()?new A(!0):r.isArray()?r.mapValue(e=>e.isNumber()?new A(!0):new A(!1)):new A(!1)}}class qs extends L{constructor(){super(...arguments);C(this,"needsReferenceObject",!0)}calculate(e){return e==null?new h(c.NA):e.isReferenceObject()?new A(!0):new A(!1)}}class zs extends L{calculate(r){return r==null?new h(c.NA):r.isString()?new A(!0):r.isArray()?r.mapValue(e=>e.isString()?new A(!0):new A(!1)):new A(!1)}}const Ln=[[Ys,re.ISBLANK],[Hs,re.ISERR],[js,re.ISERROR],[Ws,re.ISLOGICAL],[Xs,re.ISNA],[Gs,re.ISNONTEXT],[Ks,re.ISNUMBER],[qs,re.ISREF],[zs,re.ISTEXT]];class Zs extends L{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 A(e)}}var be=(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))(be||{});class Js extends L{calculate(r,e,t=new A(!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),o=j(s,i,e,new h(c.NA)),u=j(s,i,t,new h(c.NA));return a.map((l,f,m)=>{if(l.isNull())return new h(c.NA);{const g=o.get(f,m),R=u.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 Ns extends L{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((o,u,l)=>{o!=null&&o.isError()&&i.set(u,l,a.get(u,l))}),i}}class ei extends L{calculate(...r){return new h(c.VALUE)}}class ti extends L{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 o=0;o<t;o++){const u=s.execute(new w(a+1),new w(o+1));i[a][o]=u}}return new Us(i)}isAsync(){return!0}}const An=[[Zs,be.AND],[ei,be.LAMBDA],[ti,be.MAKEARRAY],[Js,be.IF],[Ns,be.IFERROR]];class ri extends L{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,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return new h(c.VALUE);const u=t?ni(t.getValue()):d.AbsoluteRefType.ALL,l=this.getZeroOrOneByOneDefault(s),f=i?`${i.getValue()}`:"",m=ct(f)?`'${f}'`:f,g={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},R=s&&!l?Ms(g):Le(g);return new W(m!==""?`${m}!${R}`:R)}}function ni(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 si extends L{calculate(r){if(r==null)return new w(this.column+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentColumn(),t=r.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(new w(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class ii extends L{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new w(1);if(!r.isArray())return new h(c.NA);const e=r.getColumnCount();return new w(e)}}var X=(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))(X||{});class ai extends L{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 o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?new h(c.REF):r.isArray()?r.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(r,o,u,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class xn extends Qe{constructor(r){super(r);const e=Ie(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,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(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 Pn extends Qe{constructor(r){super(r);const e=Ie(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 Vn extends Qe{constructor(r){super(r);const e=Ie(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 oi extends L{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=cn(s),{range:m,sheetName:g,unitId:R}=f,E=new Ke(m);return E.setForcedUnitIdDirect(R),E.setForcedSheetName(g),this._setDefault(E)}if(new RegExp(St).test(s))return this._setDefault(new xn(s));if(new RegExp(Xr).test(s))return this._setDefault(new Vn(s));if(new RegExp(Gr).test(s))return this._setDefault(new Pn(s));const i=Ie(s),{range:a,sheetName:o,unitId:u}=i,l=new Ke(a);return l.setForcedUnitIdDirect(u),l.setForcedSheetName(o),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 L{constructor(){super(...arguments);C(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,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?new h(c.VALUE):e.isArray()?e.map(u=>this.binarySearch(u,a,o)):this.binarySearch(e,a,o)}}class li extends L{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(o=>this._handleSingleObject(o,e,a)):this._handleSingleObject(r,e,a)}_handleSingleObject(r,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(r,s);if(i==null)return new h(c.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return new w(a)}_getSearchModeValue(r){switch(r){case 1:return q.MIN;case 0:return q.NORMAL;case-1:return q.MAX}}}class ci extends L{calculate(r,e,t,s,i){var P,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(),o=r.getCurrentColumn(),u=this.getIndexNumValue(e),l=this.getIndexNumValue(t);if(typeof u!="number"||typeof l!="number")return new h(c.VALUE);const f=a+u,m=o+l;if(f<0||m<0||f>1048576||m>16384)return new h(c.REF);const g=(P=s&&this.getIndexNumValue(s))!=null?P: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 E=g>0?f+g-1:f+g+1,p=R>0?m+R-1:m+R+1;if(E<0||p<0||E>1048576||p>16384)return new h(c.REF);const _=f<E?f:E,D=m<p?m:p,b=f>E?f:E,S=m>p?m:p,x={startRow:_,startColumn:D,endRow:b,endColumn:S},k=r.getUnitId(),T=r.getSheetId(),I=new Ke(x,T,k);return this._setDefault(I)}_setDefault(r){return this.unitId==null||this.subUnitId==null?new h(c.REF):(r.setDefaultUnitId(this.unitId),r.setDefaultSheetId(this.subUnitId),r)}}class fi extends L{calculate(r){if(r==null)return new w(this.row+1);if(r.isError())return r;if(!r.isArray())return new h(c.NA);const e=r.getCurrentRow(),t=r.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([new w(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return new z(i)}}class hi extends L{calculate(r){if(r==null)return new h(c.NA);if(r.isError())return r;if(r.isString()||r.isNumber()||r.isBoolean())return new w(1);if(!r.isArray())return new h(c.NA);const e=r.getRowCount();return new w(e)}}class mi extends L{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 o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?new h(c.VALUE):r.isArray()?r.map(l=>this._handleSingleObject(l,o,u,i)):this._handleSingleObject(r,o,u,i)}_handleSingleObject(r,e,t,s){return s===0?this.equalSearch(r,e,t):this.binarySearch(r,e,t)}}class gi extends L{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 o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==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(o!==l&&u!==f)return new h(c.VALUE);if(s!=null&&s.isError())return new h(c.NA);if(i!=null&&i.isError())return new h(c.NA);if(a!=null&&a.isError())return new h(c.NA);s==null&&(s=new h(c.NA));const m=this.getIndexNumValue(i||new w(0));if(m instanceof h)return m;const g=this.getIndexNumValue(a||new w(1));if(g instanceof h)return g;if(r.isArray()){let p;return o===1?p=t.slice([0,1]):p=t.slice(void 0,[0,1]),p==null?new h(c.NA):r.map(_=>{const D=this._handleSingleObject(_,e,p,m,g);return D.isError()?s:D})}if(u===f&&o===l){const p=this._handleSingleObject(r,e,t,m,g);return p.isError()?s:p}let R=0;u===f&&(R=1);const E=this._handleExpandObject(r,e,t,m,g,R);return E==null?new h(c.NA):E}_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?fe.MAX:fe.MIN}}class di extends L{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 o=this.getIndexNumValue(t||new w(0));if(o instanceof h)return o;const u=this.getIndexNumValue(s||new w(1));return u instanceof h?u:r.isArray()?r.map(l=>this._handleSingleObject(l,e,o,u)):this._handleSingleObject(r,e,o,u)}_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,y.EQUALS);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return new h(c.NA);i=e.getRowCount()===1?o.column:o.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 o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return new h(c.NA);i=e.getRowCount()===1?o.column:o.row}return i==null?new h(c.NA):new w(i+1)}_getSearchModeValue(r){return r===-2?fe.MAX:fe.MIN}}class Ri extends L{calculate(r,e,t,s){if(r==null)return new h(c.NA);if(r.isError())return r;if(e!=null&&e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(!r.isArray())return new h(c.REF);const i=r.getRowCount(),a=r.getColumnCount();i===1&&a>1&&t==null?(t=e!=null?e:new w(0),e=new w(0)):(e=e!=null?e:new w(0),t=t!=null?t:new w(0)),s=s!=null?s:new w(1);const o=Math.max(e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1),u=Math.max(e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1);if(o===1&&u===1)return this._calculateSingleCell(r,e,t,s);{const l=j(o,u,e,new h(c.NA)),f=j(o,u,t,new h(c.NA)),m=j(o,u,s,new h(c.NA));return l.map((g,R,E)=>{const p=f.get(R,E),_=m.get(R,E),D=this._calculateSingleCell(r,g,p,_);return D.isArray()?D.getFirstCell():D})}}_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 o=this._getAreaNumberValue(s);if(o===void 0||o<1)return new h(c.VALUE);const u=i===0?[void 0]:[i-1,i],l=a===0?[void 0]:[a-1,a],f=r.slice(u,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 vn=[[ri,X.ADDRESS],[si,X.COLUMN],[ii,X.COLUMNS],[Ri,X.INDEX],[oi,X.INDIRECT],[ci,X.OFFSET],[fi,X.ROW],[hi,X.ROWS],[mi,X.VLOOKUP],[ui,X.LOOKUP],[li,X.MATCH],[ai,X.HLOOKUP],[gi,X.XLOOKUP],[di,X.XMATCH]];class pi extends L{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.abs()}}class Ei extends L{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.acos()}}class wi extends L{calculate(r){return r==null?new h(c.NA):r.isError()?new h(c.VALUE):r.acosh()}}class _i extends L{calculate(r){return r==null?new h(c.NA):r.isError()?r:r.isArray()?r.map(e=>e.isError()?e:vr(e)):vr(r)}}function vr(n){let r=n.getValue();if(n.isBoolean()&&(r=r?1:0),!Number.isFinite(r))return new h(c.VALUE);const e=Math.atan(1/Number(r));return Number.isNaN(e)?new h(c.VALUE):new w(e)}var Z=(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))(Z||{});class Ci extends L{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.mod(e)}}class Di extends L{calculate(r,e){return r==null||e==null?new h(c.NA):r.isError()?r:e.isError()?e:r.pow(e)}}class yi extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(1);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isArray()&&(s=this._multiplyArray(s),s.isError()))return s;if(!s.isNull()&&(e=e.multiply(s),e.isError()))return e}return e}_multiplyArray(r){let e=new w(1);return r.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class bi extends L{constructor(){super(...arguments);C(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,o)=>{s[a]==null&&(s[a]=[]),s[a][o]=this._handleSingleObject(i,...t)}),gt(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=new h(c.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(isNaN(t))return new h(c.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:new h(c.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=new w(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return new h(c.VALUE);const 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)?new w(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new w(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return new w(0);let i=new w(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?new h(c.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return new h(c.VALUE);const o=a.getRowData();let u;if(a.iterator((l,f)=>{if(e&&this._isRowHidden(o,f)||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 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 Si extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function Li(n){const r=[y.EQUALS,y.NOT_EQUAL,y.GREATER_THAN_OR_EQUAL,y.GREATER_THAN,y.LESS_THAN_OR_EQUAL,y.LESS_THAN];for(const e of r)if(n.startsWith(e)){const t=n.substring(e.length);return[e,Ee.create(t)]}return[y.EQUALS,Ee.create(n)]}function Bn(n,r,e){if(!e)if(r.isString()){const t=`${r.getValue()}`,[s,i]=Li(t);e=s,r=i}else e=y.EQUALS;return n.compare(r,e)}function Ai(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,o,u)=>{const l=i.get(o,u);return a!=null&&a.isError()?a:l!=null&&l.isError()?l:a!=null&&a.isBoolean()&&(l!=null&&l.isBoolean())?new A(a.getValue()&&l.getValue()):new A(!1)})}class xi extends L{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=Bn(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 L{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 o=[];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 E=e[f+1];j(i,a,E,new h(c.NA)).iterator((_,D,b)=>{if(!_)return;const S=Bn(m,_);if(o[D]===void 0&&(o[D]=[]),o[D][b]===void 0){o[D][b]=S;return}o[D][b]=Ai(o[D][b],S)})}const u=o.map(f=>f.map(m=>r.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 new z(l)}}const Un=[[pi,Z.ABS],[Ei,Z.ACOS],[wi,Z.ACOSH],[_i,Z.ACOT],[Ci,Z.MOD],[bi,Z.SUBTOTAL],[Si,Z.SUM],[xi,Z.SUMIF],[Pi,Z.SUMIFS],[Di,Z.POWER],[yi,Z.PRODUCT]];class Vi extends L{constructor(){super(...arguments);C(this,"_compareType",y.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()||t.isError()?e:e.compare(t,this._compareType)}}class vi extends L{calculate(r,e){return r.isError()||e.isError()?r:!e.isArray()&&e.getValue()===0?new h(c.DIV_BY_ZERO):r.divided(e)}}var K=(n=>(n.COMPARE="COMPARE",n.DIVIDED="DIVIDED",n.MINUS="MINUS",n.MULTIPLY="MULTIPLY",n.PLUS="PLUS",n.UNION="UNION",n))(K||{});class Bi extends L{calculate(r,e){return r.isError()||e.isError()?r:r.minus(e)}}class Ui extends L{calculate(r,e){return r.isError()?r:e.isError()?e:r.multiply(e)}}class Mi extends L{calculate(r,e){return r.isError()?r:e.isError()?e:r.plus(e)}}const Mn=[[Vi,K.COMPARE],[vi,K.DIVIDED],[Bi,K.MINUS],[Ui,K.MULTIPLY],[Mi,K.PLUS]];class Oi extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0),t=new w(0);for(let s=0;s<r.length;s++){let i=r[s];if(i.isError())return i;if(i.isString()){const a=i.getValue();if(!d.isRealNum(a))return new h(c.VALUE);i=new w(a)}if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(new w(i.getValue())),t=t.plus(new w(1)))}return e.divided(t)}}class Fi extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(!s.isError())if(s.isArray())s=s.count(),e=e.plus(s);else if(s.isString()){const i=s.getValue();d.isRealNum(i)&&(e=e.plus(new w(1)))}else s.isNull()||(e=e.plus(new w(1)))}return e}}class $i extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(0);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError()){e=e.plus(new w(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(new w(1)))}return e}}var G=(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))(G||{});class ki extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(Number.NEGATIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.max(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isLessThan(e).getValue()&&(r=e),r}}class Br extends L{calculate(...r){if(r.length===0)return new h(c.NA);let e=new w(Number.POSITIVE_INFINITY);for(let t=0;t<r.length;t++){let s=r[t];if(s.isError())return s;if(s.isString()){const i=s.getValue();if(!d.isRealNum(i))return new h(c.VALUE);s=new w(i)}if(s.isBoolean()&&(s=mt(s)),s.isArray()&&(s=s.min(),s.isError()))return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(r,e){return r.isGreaterThan(e).getValue()&&(r=e),r}}class Ii extends L{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 Ti extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.std()}}class Qi extends L{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 Yi extends L{calculate(...r){if(r.length===0)return new h(c.NA);const e=this.flattenArray(r,!1);return e.isError()?e:e.var()}}const On=[[Oi,G.AVERAGE],[Fi,G.COUNT],[ki,G.MAX],[Br,G.MIN],[Br,G.MIN],[$i,G.COUNTA],[hn,G.STDEV_P],[mn,G.STDEV_S],[Ii,G.STDEVA],[Ti,G.STDEVPA],[gn,G.VAR_P],[dn,G.VAR_S],[Qi,G.VARA],[Yi,G.VARPA]];class Hi extends L{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((o,u,l)=>{var R,E;const f=s&&s.get(u,l);if(f!=null&&f.isError())return f;if(o.isError())return o;const m=f!=null&&f.isNull()?"":(R=f==null?void 0:f.getValue())!=null?R:"",g=o!=null&&o.isNull()?"":(E=o==null?void 0:o.getValue())!=null?E:"";return new W(`${m}${g}`)});return s||new h(c.VALUE)}}var Bt=(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))(Bt||{});const Fn=[[Hi,Bt.CONCATENATE]],$n=[];var ji=(n=>{})();const kn=[];var In=(n=>(n.ENCODEURL="ENCODEURL",n.FILTERXML="FILTERXML",n.WEBSERVICE="WEBSERVICE",n))(In||{});class Wi extends d.Disposable{constructor(){super(...arguments);C(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 Ut=v.createIdentifier("univer.formula.defined-names.service");var Xi=Object.defineProperty,Gi=Object.getOwnPropertyDescriptor,Ki=(n,r,e,t)=>{for(var s=t>1?void 0:t?Gi(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&&Xi(r,e,s),s},qi=(n,r)=>(e,t)=>r(e,t,n);let Kt=class extends d.Disposable{constructor(r){super();C(this,"_unitData",{});C(this,"_arrayFormulaCellData",{});C(this,"_formulaData",{});C(this,"_sheetNameMap",{});C(this,"_forceCalculate",!1);C(this,"_dirtyRanges",[]);C(this,"_dirtyNameMap",{});C(this,"_numfmtItemMap",{});C(this,"_dirtyUnitFeatureMap",{});C(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=Wr(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(),o={},u={};for(const l of a){const f=l.getSheetId(),m=l.getConfig();o[f]={cellData:new d.ObjectMatrix(m.cellData),rowCount:m.rowCount,columnCount:m.columnCount,rowData:m.rowData,columnData:m.columnData},u[l.getName()]=l.getSheetId()}e[i]=o,t[i]=u}return{allUnitData:e,unitSheetNameMap:t}}};Kt=Ki([qi(0,d.IUniverInstanceService)],Kt);const Be=v.createIdentifier("univer.formula.current-data.service");var zi=Object.defineProperty,Zi=Object.getOwnPropertyDescriptor,Ji=(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&&zi(r,e,s),s},Ni=(n,r)=>(e,t)=>r(e,t,n),ie=(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))(ie||{}),Oe=(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))(Oe||{});let qt=class extends d.Disposable{constructor(r){super();C(this,"_formulaExecuteStage",0);C(this,"_stopState",!1);C(this,"_currentRow",-1);C(this,"_currentColumn",-1);C(this,"_currentRowCount",Number.NEGATIVE_INFINITY);C(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);C(this,"_currentSubUnitId","");C(this,"_currentUnitId","");C(this,"_runtimeData",{});C(this,"_runtimeOtherData",{});C(this,"_unitArrayFormulaRange",{});C(this,"_runtimeArrayFormulaCellData",{});C(this,"_runtimeClearArrayFormulaCellData",{});C(this,"_numfmtItemMap",{});C(this,"_runtimeFeatureRange",{});C(this,"_runtimeFeatureCellData",{});C(this,"_functionsExecutedState",0);C(this,"_functionDefinitionPrivacyVar",new Map);C(this,"_totalFormulasToCalculate",0);C(this,"_completedFormulasCount",0);C(this,"_totalArrayFormulasToCalculate",0);C(this,"_completedArrayFormulasCount",0);C(this,"_isCycleDependency",!1);this._currentConfigService=r}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get 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,o=this._currentUnitId;this._runtimeData[o]==null&&(this._runtimeData[o]={});const u=this._runtimeData[o];u[a]==null&&(u[a]=new d.ObjectMatrix),this._unitArrayFormulaRange[o]==null&&(this._unitArrayFormulaRange[o]={}),this._numfmtItemMap[o]==null&&(this._numfmtItemMap[o]={}),this._numfmtItemMap[o][a]==null&&(this._numfmtItemMap[o][a]={});const l=this._numfmtItemMap[o][a],f=this._unitArrayFormulaRange[o];let m=new d.ObjectMatrix;f[a]&&(m=new d.ObjectMatrix(f[a])),this._runtimeArrayFormulaCellData[o]===void 0&&(this._runtimeArrayFormulaCellData[o]={});const g=this._runtimeArrayFormulaCellData[o];g[a]==null&&(g[a]=new d.ObjectMatrix),this._runtimeClearArrayFormulaCellData[o]===void 0&&(this._runtimeClearArrayFormulaCellData[o]={});const R=this._runtimeClearArrayFormulaCellData[o];R[a]==null&&(R[a]=new d.ObjectMatrix);const E=u[a],p=g[a],_=R[a];if(r.isReferenceObject()||r.isValueObject()&&r.isArray()){const D=r,{startRow:b,startColumn:S,endRow:x,endColumn:k}=D.getRangePosition();if(b===x&&S===k){const I=D.getFirstCell(),P=this._objectValueToCellValue(I);E.setValue(e,t,P),_.setValue(e,t,P),l[e]==null&&(l[e]={}),l[e][t]=I.getPattern();return}const T={startRow:e,startColumn:t,endRow:x-b+e,endColumn:k-S+t};if(m.setValue(e,t,T),f[a]=m.getData(),this._checkIfArrayFormulaRangeHasData(o,a,e,t,T)||this._checkIfArrayFormulaExceeded(s,i,T)){const I=this._objectValueToCellValue(new h(c.SPILL));E.setValue(e,t,I),_.setValue(e,t,I)}else{const I=new h(c.SPILL);D.iterator((P,V,O)=>{const F=this._objectValueToCellValue(P);if(V===b&&O===S){if(P!=null&&P.isError()&&P.isEqualType(I))return _.setValue(e,t,{}),E.setValue(e,t,{...this._objectValueToCellValue(I)}),!1;E.setValue(e,t,{...F})}const Ue=V-b+e,Rr=O-S+t;p.setValue(Ue,Rr,F);const pr=P==null?void 0:P.getPattern();pr&&(l[Ue]==null&&(l[Ue]={}),l[Ue][Rr]=pr)})}}else{const D=this._objectValueToCellValue(r);E.setValue(e,t,D),l[e]==null&&(l[e]={}),l[e][t]=r.getPattern(),_.setValue(e,t,D)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(r,e){this._runtimeFeatureRange[r]=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(r,e){this._runtimeFeatureCellData[r]=e}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),numfmtItemMap:this.getNumfmtItemMap(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(r){if(r==null)return{v:0,t:d.CellValueType.NUMBER};if(r.isError())return{v:r.getErrorType(),t:d.CellValueType.STRING};if(r.isValueObject()){const e=r,t=e.getValue();return e.isNumber()?{v:t,t:d.CellValueType.NUMBER}:e.isBoolean()?{v:t,t:d.CellValueType.BOOLEAN}:e.isString()&&d.isRealNum(t)?{v:t,t:d.CellValueType.FORCE_STRING}:{v:t,t:d.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(r,e,t,s,i){var g,R,E,p,_,D,b,S,x,k,T,I;const{startRow:a,startColumn:o,endRow:u,endColumn:l}=i,f=this._currentConfigService.getUnitData(),m=(E=(R=(g=this._unitArrayFormulaRange[r])==null?void 0:g[e])==null?void 0:R[t])==null?void 0:E[s];for(let P=a;P<=u;P++)for(let V=o;V<=l;V++){if(P===t&&s===V)continue;const O=(D=(_=(p=this._runtimeData)==null?void 0:p[r])==null?void 0:_[e])==null?void 0:D.getValue(P,V),F=(x=(S=(b=this._runtimeArrayFormulaCellData)==null?void 0:b[r])==null?void 0:S[e])==null?void 0:x.getValue(P,V),Ue=(I=(T=(k=f==null?void 0:f[r])==null?void 0:k[e])==null?void 0:T.cellData)==null?void 0:I.getValue(P,V);if(!d.isNullCell(O)||!d.isNullCell(F)&&!this._isInArrayFormulaRange(m,P,V)||!d.isNullCell(Ue))return!0}return!1}_isInArrayFormulaRange(r,e,t){if(r==null)return!1;const{startRow:s,startColumn:i,endRow:a,endColumn:o}=r;return e>=s&&e<=a&&t>=i&&t<=o}_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:Qr(i,r,e,t,s)}};qt=Ji([Ni(0,Be)],qt);const se=v.createIdentifier("univer.formula.runtime.service");var ea=Object.defineProperty,ta=Object.getOwnPropertyDescriptor,ra=(n,r,e,t)=>{for(var s=t>1?void 0:t?ta(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ea(r,e,s),s},Tt=(n,r)=>(e,t)=>r(e,t,n);let Pe=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,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){t+=u;continue}const{nodeType:l,token:f}=u;if(l===ee.REFERENCE||l===ee.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}}};Pe=ra([Tt(0,Ut),Tt(1,se),Tt(2,v.Inject(Lt))],Pe);var U=(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))(U||{});const ue=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class N extends d.Disposable{constructor(e){super();C(this,"_children",[]);C(this,"_parent");C(this,"_valueObject");C(this,"_calculateState",!1);C(this,"_async",!1);C(this,"_address",!1);C(this,"_refOffsetX",0);C(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return U.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(Se.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 H extends N{constructor(e){super(e);C(this,"_errorValueObject");this._errorValueObject=new h(e)}get nodeType(){return U.ERROR}static create(e){return new H(e)}getValue(){return this._errorValueObject}}const le=100;class ce extends d.Disposable{get zIndex(){return 0}create(r,e,t){let s;return r instanceof B?s=r.getToken():s=r,new N(s)}checkAndCreateNodeType(r){}}class zt extends N{get nodeType(){return U.ROOT}execute(){const e=this.getChildren()[0];this.setValue(e.getValue())}}class Tn extends ce{get zIndex(){return ue.get(U.ROOT)||le}checkAndCreateNodeType(r){if(!(r instanceof B))return;if(r.getToken()===Re)return new zt(Re)}}class Qn extends d.Disposable{constructor(){super(...arguments);C(this,"_functionExecutors",new Map);C(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const 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 me=v.createIdentifier("univer.formula.function.service");var na=Object.defineProperty,sa=Object.getOwnPropertyDescriptor,ia=(n,r,e,t)=>{for(var s=t>1?void 0:t?sa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&na(r,e,s),s},Ur=(n,r)=>(e,t)=>r(e,t,n);class dt extends N{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return U.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===Q.MINUS?t=this._functionExecutor.calculate(new w(0),e):this._operatorString===Q.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 Rt=class extends ce{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return ue.get(U.PREFIX)||le}checkAndCreateNodeType(n){if(!(n instanceof B))return;const r=n.getToken(),e=r.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Q.MINUS)t=K.MINUS;else return e===Q.AT?new dt(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new dt(this._injector,e,s):(console.error(`No function ${r}`),H.create(c.NAME))}};Rt=ia([Ur(0,me),Ur(1,v.Inject(v.Injector))],Rt);var aa=Object.defineProperty,oa=Object.getOwnPropertyDescriptor,ua=(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&&aa(r,e,s),s},Ne=(n,r)=>(e,t)=>r(e,t,n);class la extends N{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 U.FUNCTION}async executeAsync(){const r=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;a++){const o=e[a].getValue();o!=null&&(o.isReferenceObject()?r.push(o.toArrayValueObject()):r.push(o))}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(Se.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:o,startColumn:u,endRow:l,endColumn:f}=i,m=l-o+1,g=f-u+1,{startRow:R,startColumn:E,endRow:p,endColumn:_}=a,D=p-R+1,b=_-E+1;m!==D&&(a.endRow+=m-D),g!==b&&(a.endColumn+=g-b)}_calculate(r){var t;let e;if(this._setRefInfo(),this._functionExecutor.isCustom()){const s=this._functionExecutor.calculateCustom(...r.map(i=>i.isArray()?i.toValue():i.getValue()));if(typeof s!="object"||s==null)e=Ee.create(s);else{const i=xs(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 ce{constructor(n,r,e,t){super(),this._functionService=n,this._currentConfigService=r,this._runtimeService=e,this._injector=t}get zIndex(){return ue.get(U.FUNCTION)||le}create(n){const r=this._functionService.getExecutor(n);return r?new la(n,r,this._currentConfigService,this._runtimeService):(console.error(`No function ${n}`),H.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(Q.MINUS,"g").test(i)){const o=this._functionService.getExecutor(K.MINUS);t=new dt(this._injector,Q.MINUS,o),a++}if(new RegExp(Q.AT,"g").test(i)&&(s=new dt(this._injector,Q.AT),t&&s.setParent(t),a++),a>0&&(e=e.slice(a)),this._functionService.hasExecutor(e)){const o=this.create(e);return s?o.setParent(s):t&&o.setParent(t),o}}};pt=ua([Ne(0,me),Ne(1,Be),Ne(2,se),Ne(3,v.Inject(v.Injector))],pt);var ca=Object.defineProperty,fa=Object.getOwnPropertyDescriptor,ha=(n,r,e,t)=>{for(var s=t>1?void 0:t?fa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ca(r,e,s),s},ma=(n,r)=>(e,t)=>r(e,t,n);let $e=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(Se.ERROR);const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return n.nodeType===U.FUNCTION&&n.isAsync()?await n.executeAsync():n.execute(),Promise.resolve(Se.SUCCESS)}_execute(n){if(this._runtimeService.isStopExecution())return Se.ERROR;const r=n.getChildren(),e=r.length;for(let t=0;t<e;t++){const s=r[t];if(s.getToken().toUpperCase()===Ge&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return n.execute(),Se.SUCCESS}};$e=ha([ma(0,se)],$e);function Yn(n){return n instanceof B?n.getToken()===Fe:!1}function ga(n){return n instanceof B?n.getToken()===zr:!1}function Hn(n){if(!n)return;if(n.getToken()!==ze)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:Hn(s)}class da extends we{constructor(e,t,s){super(0);C(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 Bs(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()===ze){const u=a.getLambdaParameter(),l=this._lambdaPrivacyValueMap.get(u);if(l)a.setValue(l);else{const f=a.getCurrentLambdaPrivacyVar(),m=Hn(f.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 Ra=Object.defineProperty,pa=Object.getOwnPropertyDescriptor,Ea=(n,r,e,t)=>{for(var s=t>1?void 0:t?pa(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},Mr=(n,r)=>(e,t)=>r(e,t,n);class wa extends N{constructor(e,t,s,i){super(e);C(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return U.LAMBDA}setNotEmpty(e=!1){this._isNotEmpty=e}isEmptyParamFunction(){return this.getChildren().length<2&&this._isNotEmpty}isFunctionParameter(){return this._lambdaId===null}getLambdaId(){return this._lambdaId}execute(){if(this.isEmptyParamFunction())this.setValue(new da(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let Et=class extends ce{constructor(n,r){super(),this._runtimeService=n,this._interpreter=r}get zIndex(){return ue.get(U.LAMBDA)||le}create(n){const r=n.getChildren(),e=r[0];let t=r.slice(1,-1);const s=r[r.length-1];if(!(e instanceof B&&s instanceof B))return H.create(c.NAME);if(e.getToken()===Fe){const o=e.getChildren();if(t.length!==o.length)return H.create(c.VALUE)}else t=r.slice(0,-1);const i=d.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof B){const l=u.getChildren()[0];u.setToken(zr),a.set(l.trim(),void 0)}else return H.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 B)||n.getToken().trim().toUpperCase()!==Ge))return this.create(n)}_updateLambdaStatement(n,r,e){this._updateTree(n,r,e)}_updateTree(n,r,e){const t=n.getChildren(),s=t.length,i=t[0];for(let a=0;a<s;a++){const o=t[a];if(!(Yn(i)&&a!==0))if(o instanceof B)this._updateTree(o,r,e);else{const u=o.trim();if(e.has(u)){const l=new B;l.setToken(ze),l.setLambdaId(r),l.setLambdaPrivacyVar(e),l.setLambdaParameter(u),t[a]=l}}}}};Et=Ea([Mr(0,se),Mr(1,v.Inject($e))],Et);function jn(n){if(!n)return;if(n.getToken()!==ze)return n;const r=n,e=r.getCurrentLambdaPrivacyVar(),t=r.getLambdaParameter();if(e)return jn(e.get(t))}class _a extends N{constructor(r,e,t){super(r),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return U.LAMBDA_PARAMETER}execute(){const r=jn(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 Wn extends ce{get zIndex(){return ue.get(U.LAMBDA_PARAMETER)||le}create(r){const e=r.getFunctionDefinitionPrivacyVar(),t=r.getLambdaParameter();return e?new _a(r.getToken(),t,e):new H(c.SPILL)}checkAndCreateNodeType(r){if(!(!(r instanceof B)||r.getToken().trim()!==ze))return this.create(r)}}class Ca extends N{constructor(r){super(r),this._operatorString=r}get nodeType(){return U.NULL}execute(){this.setValue(new ae(0))}}var Da=Object.defineProperty,ya=Object.getOwnPropertyDescriptor,ba=(n,r,e,t)=>{for(var s=t>1?void 0:t?ya(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},Sa=(n,r)=>(e,t)=>r(e,t,n);class La extends N{constructor(r,e){super(r),this._operatorString=r,this._functionExecutor=e}get nodeType(){return U.OPERATOR}execute(){const r=this.getChildren();this._functionExecutor.name===K.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 wt=class extends ce{constructor(n){super(),this._functionService=n}get zIndex(){return ue.get(U.OPERATOR)||le}create(n){let r="";const e=n;e===J.PLUS?r=K.PLUS:e===J.MINUS?r=K.MINUS:e===J.MULTIPLY?r=K.MULTIPLY:e===J.DIVIDED?r=K.DIVIDED:e===J.CONCATENATE?r=Bt.CONCATENATE:e===J.POWER?r=Z.POWER:Zn.has(e)&&(r=K.COMPARE);const t=this._functionService.getExecutor(r);return t?new La(e,t):(console.error(`No function ${n}`),H.create(c.NAME))}checkAndCreateNodeType(n){if(n instanceof B)return;const r=n.trim();if(!(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')&&He.has(r))return this.create(r)}};wt=ba([Sa(0,me)],wt);class Aa extends d.Disposable{constructor(){super(...arguments);C(this,"_tableMap",new Map);C(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var 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 mr=v.createIdentifier("univer.formula.super-table.service");class xa extends Qe{constructor(r,e,t,s){super(r),this._tableData=e,this._columnDataString=t;const i=this._tableData.sheetId,a=this._tableData.range,o=this._tableData.titleMap;this.setForcedSheetIdDirect(i);const u=this._stringToColumnData(this._columnDataString,o,s),l=u.startColumn,f=u.endColumn,m=u.type;let g=-1,R=-1;const E=a.startRow,p=a.startColumn;m===ye.ALL?(g=E,R=p):m===ye.DATA?(g=E+1,R=p):m===ye.HEADERS?(g=E,R=E):m===ye.TOTALS&&(g=p,R=p),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(M.COMMA);let i=-1,a=-1,o=ye.ALL;if(s===-1){const u=this._columnHandler(r,e);i=u.startColumn,a=u.endColumn}else{const u=r.substring(0,s).substring(1,-1),l=r.substring(s+1),f=this._columnHandler(l,e,!0);i=f.startColumn,a=f.endColumn,o=t.get(u),o||(o=ye.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(r,e,t=!1){var o,u,l;let s=-1,i=-1;const a=r.indexOf(M.COLON);if(new RegExp(Kr,"g").test(r)){const f=r.substring(0,a).substring(1,-1),m=r.substring(a+1).substring(1,-1);s=(o=e.get(f))!=null?o:-1,i=(u=e.get(m))!=null?u:-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,va=(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},Ye=(n,r)=>(e,t)=>r(e,t,n);class et extends N{constructor(r,e,t,s=!1){super(e),this._accessor=r,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return U.REFERENCE}execute(){const r=this._accessor.get(Be),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 _t=class extends ce{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 ue.get(U.REFERENCE)||le}checkAndCreateNodeType(n){var u,l;let r=!1,e,t=!1;if(n instanceof B?(r=!0,e=n.getToken().trim(),((l=(u=n.getParent())==null?void 0:u.getParent())==null?void 0:l.getToken().trim())===M.COLON&&(t=!0)):e=n.trim(),!r&&e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;if(new RegExp(St).test(e))return new et(this._injector,e,new xn(e),t);if(r&&new RegExp(rs).test(e))return new et(this._injector,e,new Vn(e),t);if(r&&new RegExp(ns).test(e))return new et(this._injector,e,new Pn(e),t);const s=this._formulaRuntimeService.currentUnitId,i=this._superTableService.getTableMap(s),a=new RegExp(Kr,"g"),o=e.replace(a,"");if(!r&&(i!=null&&i.has(o))){const f=a.exec(e);let m="";f&&(m=f[0]);const g=i.get(o),R=this._superTableService.getTableOptionMap();return new et(this._injector,e,new xa(e,g,m,R))}}};_t=va([Ye(0,Ut),Ye(1,mr),Ye(2,se),Ye(3,v.Inject(Pe)),Ye(4,v.Inject(v.Injector))],_t);var Ba=Object.defineProperty,Ua=Object.getOwnPropertyDescriptor,Ma=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ua(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&&Ba(r,e,s),s},Or=(n,r)=>(e,t)=>r(e,t,n);class Fr extends N{constructor(r,e,t){super(e),this._accessor=r,this._operatorString=e,this._functionExecutor=t}get nodeType(){return U.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 w(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(Be),t=this._accessor.get(Pe),s=r,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),l=(R=(g=(m=(f=u==null?void 0:u[a])==null?void 0:f[o])==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 Ct=class extends ce{constructor(n,r){super(),this._functionService=n,this._injector=r}get zIndex(){return ue.get(U.SUFFIX)||le}checkAndCreateNodeType(n){if(!(n instanceof B))return;const r=n.getToken().trim();if(r.charAt(0)==='"'&&r.charAt(r.length-1)==='"')return;let e="";if(r===he.PERCENTAGE)e=K.DIVIDED;else return r===he.POUND?new Fr(this._injector,r):void 0;const t=this._functionService.getExecutor(e);return t?new Fr(this._injector,r,t):(console.error(`No function ${n}`),H.create(c.NAME))}};Ct=Ma([Or(0,me),Or(1,v.Inject(v.Injector))],Ct);var Oa=Object.defineProperty,Fa=Object.getOwnPropertyDescriptor,$a=(n,r,e,t)=>{for(var s=t>1?void 0:t?Fa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Oa(r,e,s),s},ka=(n,r)=>(e,t)=>r(e,t,n);class Ia extends N{constructor(r){super(r),this._operatorString=r}get nodeType(){return U.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===M.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 Dt=class extends ce{constructor(n){super(),this._functionService=n}get zIndex(){return ue.get(U.UNION)||le}create(n){return new Ia(n)}checkAndCreateNodeType(n){if(!(n instanceof B))return;const e=n.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===M.COLON)return this.create(e)}};Dt=$a([ka(0,me)],Dt);class Ta extends N{constructor(r){super(r),this._operatorString=r}get nodeType(){return U.VALUE}execute(){this.setValue(Ee.create(this._operatorString))}}class Xn extends ce{get zIndex(){return ue.get(U.VALUE)||le}_checkValueNode(r){if(Number.isNaN(Number(r))){const e=r.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(yt.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===Ae.TRUE||i===Ae.FALSE)return this.create(i)}else return this.create(r)}create(r){return new Ta(r)}checkAndCreateNodeType(r){if(!(r instanceof B))return this._checkValueNode(r)}}var Qa=Object.defineProperty,Ya=Object.getOwnPropertyDescriptor,Ha=(n,r,e,t)=>{for(var s=t>1?void 0:t?Ya(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&&Qa(r,e,s),s},te=(n,r)=>(e,t)=>r(e,t,n);let qe=class extends d.Disposable{constructor(r,e,t,s,i,a,o,u,l,f,m){super();C(this,"_astNodeFactoryList",[]);C(this,"_refOffsetX",0);C(this,"_refOffsetY",0);this._runtimeService=r,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=f,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(r=>{r.dispose()}),this._astNodeFactoryList=[]}parse(r,e=0,t=0){const s=new zt(Re);return this._refOffsetX=e,this._refOffsetY=t,this._parse(r,s)}_lambdaParameterHandler(r,e){const t=e.getLambdaId(),s=new zt(Re),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],o=r.getChildren(),u=o.length;for(let m=0;m<u;m++){const g=o[m];if(g instanceof B)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 B;s.setToken(Ge);const i=new B;i.setToken(Fe);const a=[...e];for(let u=0;u<t;u++){const l=a[u];if(!(l instanceof B))return;u%2===0?l.changeToParent(s):l.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=r.getParent();return o==null||o.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 o=r.getToken().trim().toUpperCase();if(o===is){const f=this._changeLetToLambda(r);return f!=null?this._parse(f,e):H.create(c.ERROR)}if(o===De){if(a=e,s===0)return new Ca(Re).setParent(e),a}else{if(o===Fe){let f=this._lambdaParameterHandler(r,e);return f===!1&&(f=H.create(c.ERROR)),f}if(a=this._checkAstNode(r),a==null)return H.create(c.ERROR)}const u=t[0];for(let f=0;f<s;f++){const m=t[f];if(Yn(u)){if(f!==0&&f!==s-1)continue}else if(ga(m)&&f!==s-1)continue;let g=null;if(m instanceof B){if(g=this._parse(m,a),g===a)continue}else g=this._checkAstNode(m);if(g==null)return H.create(c.NAME);if(g=this._getTopParent(g),g==null)return;switch(g.nodeType){case U.ERROR:return g;case U.FUNCTION:i.push(g);break;case U.LAMBDA:i.push(g);break;case U.LAMBDA_PARAMETER:i.push(g);break;case U.OPERATOR:{const R=i.pop(),E=i.pop();if(E)E.setParent(g);else return H.create(c.ERROR);if(R)R.setParent(g);else return H.create(c.ERROR);i.push(g);break}case U.REFERENCE:g.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(g);break;case U.ROOT:i.push(g);break;case U.UNION:i.push(g);break;case U.VALUE:i.push(g);break;case U.PREFIX:i.push(g);break;case U.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)}};qe=Ha([te(0,se),te(1,v.Inject(Tn)),te(2,v.Inject(pt)),te(3,v.Inject(Et)),te(4,v.Inject(Wn)),te(5,v.Inject(wt)),te(6,v.Inject(Rt)),te(7,v.Inject(_t)),te(8,v.Inject(Ct)),te(9,v.Inject(Dt)),te(10,v.Inject(Xn))],qe);class Gn extends d.Disposable{constructor(){super(...arguments);C(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Mt=v.createIdentifier("univer.formula.feature-calculation-manager.service");class Kn extends d.Disposable{constructor(){super(...arguments);C(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 gr=v.createIdentifier("univer.formula.other-formula-manager.service");class Qt extends d.Disposable{constructor(){super(...arguments);C(this,"node");C(this,"children",[]);C(this,"parents",[]);C(this,"formula","");C(this,"row",-1);C(this,"column",-1);C(this,"rowCount",Number.NEGATIVE_INFINITY);C(this,"columnCount",Number.NEGATIVE_INFINITY);C(this,"subUnitId","");C(this,"unitId","");C(this,"rangeList",[]);C(this,"formulaId");C(this,"featureId");C(this,"getDirtyData");C(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,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: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 E=R.get(m),p=(a=s==null?void 0:s[f])==null?void 0:a[m];let{startRow:_,endRow:D,startColumn:b,endColumn:S}=g;isNaN(_)&&(_=0),isNaN(b)&&(b=0),isNaN(D)&&(D=Number.POSITIVE_INFINITY),isNaN(S)&&(S=Number.POSITIVE_INFINITY);for(const x of E){const{startRow:k,startColumn:T,endRow:I,endColumn:P}=x;if(!(_>I||D<k||b>P||S<T)){let V=!0;if(p==null||p.forValue((O,F)=>{if(O>=_&&O<=D&&F>=b&&F<=S)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,o=i.sheetId,u=i.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}var ja=Object.defineProperty,Wa=Object.getOwnPropertyDescriptor,Xa=(n,r,e,t)=>{for(var s=t>1?void 0:t?Wa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&ja(r,e,s),s},_e=(n,r)=>(e,t)=>r(e,t,n);const Ga=1e5,Yt=new bt(Ga);let We=class extends d.Disposable{constructor(r,e,t,s,i,a,o){super();C(this,"_updateRangeFlattenCache",new Map);C(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=r,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),Yt.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 o=this._calculateRunList(i);return Promise.resolve(o)}_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 o of s){const u=r[o];if(u==null)continue;const l=Object.keys(u);for(const f of l)new d.ObjectMatrix(u[f]).forValue((g,R,E)=>{if(E==null)return!0;const{f:p,x:_,y:D}=E,b=this._generateAstNode(p,_,D),S=new Qt,x=t[o][f];S.node=b,S.formula=p,S.unitId=o,S.subUnitId=f,S.row=g,S.column=R,S.rowCount=x.rowCount,S.columnCount=x.columnCount,a.push(S)})}for(const o of i){const u=e[o];if(u==null)continue;const l=Object.keys(u);for(const f of l){const m=u[f];if(m==null)continue;const g=Object.keys(m);for(const R of g){const E=m[R],{f:p}=E,_=this._generateAstNode(p),D=new Qt;D.node=_,D.formula=p,D.unitId=o,D.subUnitId=f,D.formulaId=R,a.push(D)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((o,u)=>{const{unitId:l,subUnitId:f,dependencyRanges:m,getDirtyData:g}=o,R=new Qt;R.unitId=l,R.subUnitId=f,R.getDirtyData=g,R.featureId=u,R.rangeList=m,a.push(R)});for(let o=0,u=a.length;o<u;o++){const l=a[o];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const 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,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(r,e=0,t=0){let s=Yt.get(`${r}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(r);if(i in c)return H.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return Yt.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===U.UNION||r.nodeType===U.PREFIX&&r.getToken()===Q.AT||r.nodeType===U.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===U.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===U.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 o=e[i],l=(await this._executeNode(o)).toUnitRange();s.push(l)}for(let i=0,a=t.length;i<a;i++){const o=t[i],l=(await this._executeNode(o)).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 o=r[i];for(let u=0,l=r.length;u<l;u++){const f=r[u];o!==f&&o.dependency(f)&&o.pushChildren(f)}(s||o.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(o))&&!t.has(o)&&(e.push(o),t.add(o))}return e}_includeTree(r){var l,f,m,g,R;const e=r.unitId,t=r.subUnitId,s=r.featureId;if(s!=null){const E=this._currentConfigService.getDirtyUnitFeatureMap();if(((f=(l=E==null?void 0:E[e])==null?void 0:l[t])==null?void 0:f[s])!=null)return!0}const i=(g=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:g[t];let a=!1;if(i==null||i.forValue((E,p)=>{if(r.row===E&&r.column===p)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 o=this._updateRangeFlattenCache.get(e);if(!o.has(t))return!1;const u=o.get(t);for(const E of u)if(r.inRangeData(E))return!0;return!1}_calculateRunList(r){let e=r;const t=[];for(;e.length>0;){const 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];i.push(u)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};We=Xa([d.OnLifecycle(d.LifecycleStages.Rendered,We),_e(0,Be),_e(1,se),_e(2,gr),_e(3,Mt),_e(4,v.Inject($e)),_e(5,v.Inject(qe)),_e(6,v.Inject(Pe))],We);var Ka=Object.defineProperty,qa=Object.getOwnPropertyDescriptor,za=(n,r,e,t)=>{for(var s=t>1?void 0:t?qa(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ka(r,e,s),s},Ce=(n,r)=>(e,t)=>r(e,t,n);const Za=1;exports.CalculateFormulaService=class extends d.Disposable{constructor(e,t,s,i,a,o,u){super();C(this,"_executionStartListener$",new Ot.Subject);C(this,"executionStartListener$",this._executionStartListener$.asObservable());C(this,"_executionCompleteListener$",new Ot.Subject);C(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());C(this,"_executionInProgressListener$",new Ot.Subject);C(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")||Za;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage(ie.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Gt.clear(),ge.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 d.ObjectMatrix(o[u]);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:u,range:R})}),i[a]==null&&(i[a]={}),i[a][u]=f})}),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(f=>{const m=l[f];if(m==null)return!0;for(const g of m)s.push({unitId:u,sheetId:f,range:g})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage(ie.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage(ie.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage(ie.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage(ie.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(ie.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,l=o.getDirtyData;let f;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:g}=l(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,m),this._runtimeService.setRuntimeFeatureRange(o.featureId,g)}else u!=null&&(s.checkAsyncNode(u)?f=await s.executeAsync(u):f=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,f):this._runtimeService.setRuntimeData(f));e?(this._runtimeService.setFormulaExecuteStage(ie.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage(ie.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 H.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=za([d.OnLifecycle(d.LifecycleStages.Rendered,exports.CalculateFormulaService),Ce(0,d.IConfigService),Ce(1,v.Inject(Pe)),Ce(2,Be),Ce(3,se),Ce(4,v.Inject(We)),Ce(5,v.Inject($e)),Ce(6,v.Inject(qe))],exports.CalculateFormulaService);const dr={id:"formula.mutation.set-numfmt-formula-data",type:d.CommandType.MUTATION,handler:(n,r)=>(n.get(exports.FormulaDataModel).updateNumfmtItemMap(r.numfmtItemMap),!0)};var Ja=Object.defineProperty,Na=Object.getOwnPropertyDescriptor,eo=(n,r,e,t)=>{for(var s=t>1?void 0:t?Na(r,e):r,i=n.length-1,a;i>=0;i--)(a=n[i])&&(s=(t?a(r,e,s):a(s))||s);return t&&s&&Ja(r,e,s),s},tt=(n,r)=>(e,t)=>r(e,t,n);let st=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===rr.id)this._calculateFormulaService.stopFormulaExecution();else if(n.id===sr.id){const e=n.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(n.id===tr.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===ft.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 Oe.NOT_EXECUTED:break;case Oe.STOP_EXECUTION:break;case Oe.SUCCESS:this._applyFormula(n);break;case Oe.INITIAL:break}this._commandService.executeCommand(ht.id,{functionsExecutedState:r},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(n=>{this._commandService.executeCommand(ht.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(ft.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),d.Tools.isEmptyObject(a)||this._commandService.executeCommand(dr.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(nr.id,{unitData:r,unitOtherData:e},{onlyLocal:!0})}};st=eo([d.OnLifecycle(d.LifecycleStages.Ready,st),tt(0,d.ICommandService),tt(1,v.Inject(exports.CalculateFormulaService)),tt(2,d.IUniverInstanceService),tt(3,v.Inject(exports.FormulaDataModel))],st);var to=Object.defineProperty,ro=Object.getOwnPropertyDescriptor,no=(n,r,e,t)=>{for(var s=t>1?void 0:t?ro(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&&to(r,e,s),s},Ht=(n,r)=>(e,t)=>r(e,t,n);let Xe=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(){[sr,ft,tr,rr,ht,nr,dr,At,xt,Nt,er,ir,ar,sn,an,or,Zt,ur].forEach(n=>this.disposeWithMe(this._commandService.registerCommand(n)))}_registerFunctions(){const n=[...fn,...Rn,...pn,...wn,...Cn,...Dn,...bn,...Ln,...An,...vn,...Un,...Mn,...On,...Fn,...$n,...kn].concat(this._function).map(r=>{const e=r[0],t=r[1];return new e(t)});this._functionService.registerExecutors(...n)}};Xe=no([d.OnLifecycle(d.LifecycleStages.Ready,Xe),Ht(1,d.ICommandService),Ht(2,v.Inject(v.Injector)),Ht(3,me)],Xe);var so=Object.defineProperty,io=Object.getOwnPropertyDescriptor,ao=(n,r,e,t)=>{for(var s=t>1?void 0:t?io(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&&so(r,e,s),s},jt=(n,r)=>(e,t)=>r(e,t,n);let it=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===Zt.id){const e=n.params;if(e==null)return;const{functions:t}=e,s=t.map(i=>{const a=i[0],o=i[1];return uo(a,o)});this._functionService.registerExecutors(...s)}else if(n.id===ur.id){const e=n.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};it=ao([d.OnLifecycle(d.LifecycleStages.Ready,it),jt(0,d.ICommandService),jt(1,v.Inject(exports.FormulaDataModel)),jt(2,me)],it);class oo extends L{isCustom(){return!0}}function uo(n,r){const e=new oo(r),t=new Function(`return ${n}`)();return e.calculateCustom=t,e}var lo=Object.defineProperty,co=Object.getOwnPropertyDescriptor,fo=(n,r,e,t)=>{for(var s=t>1?void 0:t?co(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&&lo(r,e,s),s},$r=(n,r)=>(e,t)=>r(e,t,n);let at=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===At.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===xt.id){const r=n.params;if(r==null)return;const{unitId:e,name:t}=r;this._definedNamesService.removeDefinedName(e,t)}}))}};at=fo([d.OnLifecycle(d.LifecycleStages.Ready,at),$r(0,d.ICommandService),$r(1,Ut)],at);var ho=Object.defineProperty,mo=Object.getOwnPropertyDescriptor,go=(n,r,e,t)=>{for(var s=t>1?void 0:t?mo(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&&ho(r,e,s),s},kr=(n,r)=>(e,t)=>r(e,t,n);let ot=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===Nt.id){const r=n.params;if(r==null)return;const{featureId:e,calculationParam:t}=r;this._featureCalculationManagerService.register(e,t)}else if(n.id===er.id){const r=n.params;if(r==null)return;const{featureId:e}=r;this._featureCalculationManagerService.remove(e)}}))}};ot=go([d.OnLifecycle(d.LifecycleStages.Ready,ot),kr(0,d.ICommandService),kr(1,Mt)],ot);var Ro=Object.defineProperty,po=Object.getOwnPropertyDescriptor,Eo=(n,r,e,t)=>{for(var s=t>1?void 0:t?po(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&&Ro(r,e,s),s},Ir=(n,r)=>(e,t)=>r(e,t,n);let ut=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===ir.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.register(r)}else if(n.id===ar.id){const r=n.params;if(r==null)return;this._otherFormulaManagerService.remove(r)}}))}};ut=Eo([d.OnLifecycle(d.LifecycleStages.Ready,ut),Ir(0,d.ICommandService),Ir(1,gr)],ut);var wo=Object.defineProperty,_o=Object.getOwnPropertyDescriptor,Co=(n,r,e,t)=>{for(var s=t>1?void 0:t?_o(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&&wo(r,e,s),s},Tr=(n,r)=>(e,t)=>r(e,t,n);let lt=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===At.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===xt.id){const r=n.params;if(r==null)return;const{unitId:e,tableName:t}=r;this._superTableService.remove(e,t)}else if(n.id===or.id){const r=n.params;if(r==null)return;const{tableOption:e,tableOptionType:t}=r;this._superTableService.registerTableOptionMap(e,t)}}))}};lt=Co([d.OnLifecycle(d.LifecycleStages.Ready,lt),Tr(0,d.ICommandService),Tr(1,mr)],lt);var Do=Object.defineProperty,yo=Object.getOwnPropertyDescriptor,bo=(n,r,e,t)=>{for(var s=t>1?void 0:t?yo(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&&Do(r,e,s),s},So=(n,r)=>(e,t)=>r(e,t,n);const Lo="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends d.Plugin{constructor(r,e){super(Lo),this._config=r,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const r=[[me,{useClass:Qn}],[Mt,{useClass:Gn}],[Ut,{useClass:Wi}],[exports.FormulaDataModel],[Lt],[Xe,{useFactory:()=>{var t;return this._injector.createInstance(Xe,(t=this._config)==null?void 0:t.function)}}],[ot]];(e=this._config)!=null&&e.notExecuteFormula||r.push([exports.CalculateFormulaService],[gr,{useClass:Kn}],[mr,{useClass:Aa}],[Be,{useClass:Kt}],[se,{useClass:qt}],[st],[at],[ut],[lt],[it],[We],[$e],[qe],[Pe],[Tn],[pt],[Et],[Wn],[wt],[Rt],[_t],[Ct],[Dt],[Xn]),r.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=bo([So(1,v.Inject(v.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=z;exports.BaseFunction=L;exports.BaseReferenceObject=Qe;exports.BaseValueObject=we;exports.BooleanValueObject=A;exports.ErrorType=c;exports.ErrorValueObject=h;exports.FUNCTION_NAMES_ARRAY=Os;exports.FUNCTION_NAMES_COMPATIBILITY=Me;exports.FUNCTION_NAMES_CUBE=En;exports.FUNCTION_NAMES_DATABASE=_n;exports.FUNCTION_NAMES_DATE=de;exports.FUNCTION_NAMES_ENGINEERING=yn;exports.FUNCTION_NAMES_FINANCIAL=Sn;exports.FUNCTION_NAMES_INFORMATION=re;exports.FUNCTION_NAMES_LOGICAL=be;exports.FUNCTION_NAMES_LOOKUP=X;exports.FUNCTION_NAMES_MATH=Z;exports.FUNCTION_NAMES_STATISTICAL=G;exports.FUNCTION_NAMES_TEXT=Bt;exports.FUNCTION_NAMES_UNIVER=ji;exports.FUNCTION_NAMES_WEB=In;exports.FeatureCalculationManagerService=Gn;exports.FormulaExecuteStageType=ie;exports.FormulaExecutedStateType=Oe;exports.FunctionService=Qn;exports.FunctionType=Yr;exports.IFeatureCalculationManagerService=Mt;exports.IFunctionService=me;exports.LexerNode=B;exports.LexerTreeBuilder=Lt;exports.NumberValueObject=w;exports.OtherFormulaManagerService=Kn;exports.RangeReferenceObject=Ke;exports.RegisterFunctionMutation=Zt;exports.RemoveDefinedNameMutation=xt;exports.RemoveFeatureCalculationMutation=er;exports.RemoveOtherFormulaMutation=ar;exports.RemoveSuperTableMutation=an;exports.SetArrayFormulaDataMutation=ft;exports.SetArrayFormulaDataUndoMutationFactory=ds;exports.SetDefinedNameMutation=At;exports.SetFeatureCalculationMutation=Nt;exports.SetFormulaCalculationNotificationMutation=ht;exports.SetFormulaCalculationResultMutation=nr;exports.SetFormulaCalculationStartMutation=tr;exports.SetFormulaCalculationStopMutation=rr;exports.SetFormulaDataMutation=sr;exports.SetNumfmtFormulaDataMutation=dr;exports.SetOtherFormulaMutation=ir;exports.SetSuperTableMutation=sn;exports.SetSuperTableOptionMutation=or;exports.StringValueObject=W;exports.UnregisterFunctionMutation=ur;exports.ValueObjectFactory=Ee;exports.compareToken=y;exports.convertUnitDataToRuntime=Wr;exports.deserializeRangeForR1C1=cn;exports.deserializeRangeWithSheet=Ie;exports.functionArray=fn;exports.functionCompatibility=Rn;exports.functionCube=pn;exports.functionDatabase=wn;exports.functionDate=Cn;exports.functionEngineering=Dn;exports.functionFinancial=bn;exports.functionInformation=Ln;exports.functionLogical=An;exports.functionLookup=vn;exports.functionMath=Un;exports.functionMeta=Mn;exports.functionStatistical=On;exports.functionText=Fn;exports.functionUniver=$n;exports.functionWeb=kn;exports.generateStringWithSequence=tn;exports.getAbsoluteRefTypeWitString=us;exports.getAbsoluteRefTypeWithSingleString=je;exports.includeFormulaLexerToken=jr;exports.initSheetFormulaData=nn;exports.isFormulaLexerToken=nt;exports.isInDirtyRange=Qr;exports.isReferenceString=qr;exports.matchToken=M;exports.normalizeSheetName=Nn;exports.operatorToken=J;exports.sequenceNodeType=ee;exports.serializeRange=Le;exports.serializeRangeToRefString=Nr;exports.serializeRangeWithSheet=Zr;exports.serializeRangeWithSpreadsheet=Jr;