@univerjs/engine-formula 0.1.4 → 0.1.5

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 (167) hide show
  1. package/lib/cjs/index.js +1 -1
  2. package/lib/es/index.js +2662 -2498
  3. package/lib/types/basics/calculate.d.ts +1 -15
  4. package/lib/types/basics/common.d.ts +11 -17
  5. package/lib/types/basics/dirty.d.ts +2 -16
  6. package/lib/types/basics/function.d.ts +18 -32
  7. package/lib/types/basics/match-token.d.ts +1 -15
  8. package/lib/types/basics/object-class-type.d.ts +2 -15
  9. package/lib/types/basics/runtime.d.ts +2 -16
  10. package/lib/types/commands/mutations/register-function.mutation.d.ts +2 -16
  11. package/lib/types/commands/mutations/set-array-formula-data.mutation.d.ts +4 -18
  12. package/lib/types/commands/mutations/set-defined-name.mutation.d.ts +2 -16
  13. package/lib/types/commands/mutations/set-feature-calculation.mutation.d.ts +3 -17
  14. package/lib/types/commands/mutations/set-formula-calculation.mutation.d.ts +5 -18
  15. package/lib/types/commands/mutations/set-formula-data.mutation.d.ts +3 -17
  16. package/lib/types/commands/mutations/set-numfmt-formula-data.mutation.d.ts +3 -17
  17. package/lib/types/commands/mutations/set-other-formula.mutation.d.ts +15 -19
  18. package/lib/types/commands/mutations/set-super-table.mutation.d.ts +4 -18
  19. package/lib/types/commands/mutations/unregister-function.mutation.d.ts +2 -16
  20. package/lib/types/controller/calculate.controller.d.ts +3 -17
  21. package/lib/types/controller/formula.controller.d.ts +5 -20
  22. package/lib/types/controller/register-function.controller.d.ts +3 -17
  23. package/lib/types/controller/set-defined-name.controller.d.ts +2 -16
  24. package/lib/types/controller/set-feature-calculation.controller.d.ts +2 -16
  25. package/lib/types/controller/set-other-formula.controller.d.ts +2 -16
  26. package/lib/types/controller/set-super-table.controller.d.ts +2 -16
  27. package/lib/types/engine/analysis/__tests__/create-command-test-bed.d.ts +11 -26
  28. package/lib/types/engine/analysis/lexer-node.d.ts +3 -17
  29. package/lib/types/engine/analysis/lexer-tree-builder.d.ts +5 -19
  30. package/lib/types/engine/analysis/lexer.d.ts +5 -19
  31. package/lib/types/engine/analysis/parser.d.ts +14 -29
  32. package/lib/types/engine/ast-node/ast-root-node.d.ts +4 -18
  33. package/lib/types/engine/ast-node/base-ast-node-factory.d.ts +3 -18
  34. package/lib/types/engine/ast-node/base-ast-node.d.ts +6 -21
  35. package/lib/types/engine/ast-node/function-node.d.ts +10 -24
  36. package/lib/types/engine/ast-node/lambda-node.d.ts +6 -20
  37. package/lib/types/engine/ast-node/lambda-parameter-node.d.ts +4 -19
  38. package/lib/types/engine/ast-node/null-node.d.ts +2 -16
  39. package/lib/types/engine/ast-node/operator-node.d.ts +6 -20
  40. package/lib/types/engine/ast-node/prefix-node.d.ts +8 -23
  41. package/lib/types/engine/ast-node/reference-node.d.ts +10 -25
  42. package/lib/types/engine/ast-node/suffix-node.d.ts +7 -22
  43. package/lib/types/engine/ast-node/union-node.d.ts +5 -19
  44. package/lib/types/engine/ast-node/value-node.d.ts +4 -18
  45. package/lib/types/engine/dependency/dependency-tree.d.ts +4 -19
  46. package/lib/types/engine/dependency/formula-dependency.d.ts +11 -25
  47. package/lib/types/engine/interpreter/interpreter.d.ts +6 -20
  48. package/lib/types/engine/reference-object/base-reference-object.d.ts +20 -32
  49. package/lib/types/engine/reference-object/cell-reference-object.d.ts +4 -18
  50. package/lib/types/engine/reference-object/column-reference-object.d.ts +2 -16
  51. package/lib/types/engine/reference-object/range-reference-object.d.ts +2 -16
  52. package/lib/types/engine/reference-object/row-reference-object.d.ts +2 -16
  53. package/lib/types/engine/reference-object/table-reference-object.d.ts +2 -17
  54. package/lib/types/engine/utils/array-object.d.ts +3 -17
  55. package/lib/types/engine/utils/ast-node-tool.d.ts +3 -17
  56. package/lib/types/engine/utils/cell.d.ts +2 -16
  57. package/lib/types/engine/utils/compare.d.ts +1 -15
  58. package/lib/types/engine/utils/function-definition.d.ts +1 -15
  59. package/lib/types/engine/utils/node-type.d.ts +5 -19
  60. package/lib/types/engine/utils/object-compare.d.ts +2 -16
  61. package/lib/types/engine/utils/prefixHandler.d.ts +4 -18
  62. package/lib/types/engine/utils/r1c1-reference.d.ts +2 -16
  63. package/lib/types/engine/utils/reference.d.ts +2 -17
  64. package/lib/types/engine/utils/sequence.d.ts +2 -16
  65. package/lib/types/engine/utils/value-object.d.ts +6 -0
  66. package/lib/types/engine/value-object/array-value-object.d.ts +5 -20
  67. package/lib/types/engine/value-object/base-value-object.d.ts +6 -21
  68. package/lib/types/engine/value-object/cube-value-object.d.ts +3 -17
  69. package/lib/types/engine/value-object/lambda-value-object.d.ts +4 -18
  70. package/lib/types/engine/value-object/primitive-object.d.ts +3 -17
  71. package/lib/types/functions/__tests__/create-function-test-bed.d.ts +13 -26
  72. package/lib/types/functions/base-function.d.ts +8 -24
  73. package/lib/types/functions/compatibility/function-map.d.ts +2 -16
  74. package/lib/types/functions/date/date/index.d.ts +2 -16
  75. package/lib/types/functions/date/day/index.d.ts +2 -16
  76. package/lib/types/functions/date/edate/index.d.ts +2 -16
  77. package/lib/types/functions/date/function-map.d.ts +2 -16
  78. package/lib/types/functions/date/month/index.d.ts +2 -16
  79. package/lib/types/functions/date/today/index.d.ts +3 -18
  80. package/lib/types/functions/date/year/index.d.ts +2 -16
  81. package/lib/types/functions/information/function-map.d.ts +2 -16
  82. package/lib/types/functions/information/isblank/index.d.ts +2 -16
  83. package/lib/types/functions/information/iserr/index.d.ts +2 -16
  84. package/lib/types/functions/information/iserror/index.d.ts +2 -16
  85. package/lib/types/functions/information/islogical/index.d.ts +2 -16
  86. package/lib/types/functions/information/isna/index.d.ts +2 -16
  87. package/lib/types/functions/information/isnontext/index.d.ts +2 -16
  88. package/lib/types/functions/information/isnumber/index.d.ts +2 -16
  89. package/lib/types/functions/information/isref/index.d.ts +3 -17
  90. package/lib/types/functions/information/istext/index.d.ts +2 -16
  91. package/lib/types/functions/logical/and/index.d.ts +2 -16
  92. package/lib/types/functions/logical/function-map.d.ts +4 -18
  93. package/lib/types/functions/logical/if/index.d.ts +2 -16
  94. package/lib/types/functions/logical/iferror/index.d.ts +3 -17
  95. package/lib/types/functions/logical/lambda/index.d.ts +2 -16
  96. package/lib/types/functions/logical/makearray/index.d.ts +3 -17
  97. package/lib/types/functions/logical/or/index.d.ts +2 -16
  98. package/lib/types/functions/lookup/address/index.d.ts +2 -16
  99. package/lib/types/functions/lookup/column/index.d.ts +3 -17
  100. package/lib/types/functions/lookup/columns/index.d.ts +2 -16
  101. package/lib/types/functions/lookup/function-map.d.ts +12 -22
  102. package/lib/types/functions/lookup/hlookup/index.d.ts +2 -16
  103. package/lib/types/functions/lookup/index/index.d.ts +3 -19
  104. package/lib/types/functions/lookup/indirect/index.d.ts +3 -17
  105. package/lib/types/functions/lookup/lookup/index.d.ts +3 -17
  106. package/lib/types/functions/lookup/match/index.d.ts +3 -17
  107. package/lib/types/functions/lookup/offset/index.d.ts +4 -18
  108. package/lib/types/functions/lookup/row/index.d.ts +3 -17
  109. package/lib/types/functions/lookup/rows/index.d.ts +2 -16
  110. package/lib/types/functions/lookup/vlookup/index.d.ts +5 -17
  111. package/lib/types/functions/lookup/xlookup/index.d.ts +3 -17
  112. package/lib/types/functions/lookup/xmatch/index.d.ts +3 -17
  113. package/lib/types/functions/math/abs/index.d.ts +2 -16
  114. package/lib/types/functions/math/acos/index.d.ts +2 -16
  115. package/lib/types/functions/math/acosh/index.d.ts +2 -16
  116. package/lib/types/functions/math/acot/index.d.ts +2 -16
  117. package/lib/types/functions/math/function-map.d.ts +4 -18
  118. package/lib/types/functions/math/mod/index.d.ts +2 -16
  119. package/lib/types/functions/math/power/index.d.ts +2 -16
  120. package/lib/types/functions/math/product/index.d.ts +2 -16
  121. package/lib/types/functions/math/subtotal/index.d.ts +3 -17
  122. package/lib/types/functions/math/sum/index.d.ts +2 -16
  123. package/lib/types/functions/math/sumif/index.d.ts +2 -16
  124. package/lib/types/functions/math/sumifs/index.d.ts +3 -18
  125. package/lib/types/functions/meta/compare/index.d.ts +3 -17
  126. package/lib/types/functions/meta/cube/index.d.ts +2 -16
  127. package/lib/types/functions/meta/divided/index.d.ts +2 -16
  128. package/lib/types/functions/meta/function-map.d.ts +2 -16
  129. package/lib/types/functions/meta/minus/index.d.ts +2 -16
  130. package/lib/types/functions/meta/multiply/index.d.ts +2 -16
  131. package/lib/types/functions/meta/plus/index.d.ts +2 -16
  132. package/lib/types/functions/statistical/average/index.d.ts +2 -16
  133. package/lib/types/functions/statistical/count/index.d.ts +2 -16
  134. package/lib/types/functions/statistical/counta/index.d.ts +2 -16
  135. package/lib/types/functions/statistical/function-map.d.ts +2 -16
  136. package/lib/types/functions/statistical/max/index.d.ts +2 -16
  137. package/lib/types/functions/statistical/min/index.d.ts +2 -16
  138. package/lib/types/functions/statistical/stdev-p/index.d.ts +3 -17
  139. package/lib/types/functions/statistical/stdev-s/index.d.ts +3 -17
  140. package/lib/types/functions/statistical/stdeva/index.d.ts +3 -17
  141. package/lib/types/functions/statistical/stdevpa/index.d.ts +3 -17
  142. package/lib/types/functions/statistical/var-p/index.d.ts +3 -17
  143. package/lib/types/functions/statistical/var-s/index.d.ts +3 -17
  144. package/lib/types/functions/statistical/vara/index.d.ts +3 -17
  145. package/lib/types/functions/statistical/varpa/index.d.ts +3 -17
  146. package/lib/types/functions/text/concatenate/index.d.ts +2 -16
  147. package/lib/types/functions/text/function-map.d.ts +2 -16
  148. package/lib/types/functions/text/len/index.d.ts +2 -16
  149. package/lib/types/functions/text/lenb/index.d.ts +2 -16
  150. package/lib/types/functions/text/text/index.d.ts +2 -16
  151. package/lib/types/index.d.ts +5 -3
  152. package/lib/types/models/__tests__/create-command-test-bed.d.ts +10 -25
  153. package/lib/types/models/formula-data.model.d.ts +3 -18
  154. package/lib/types/plugin.d.ts +4 -19
  155. package/lib/types/services/active-dirty-manager.service.d.ts +34 -0
  156. package/lib/types/services/calculate-formula.service.d.ts +12 -27
  157. package/lib/types/services/current-data.service.d.ts +7 -19
  158. package/lib/types/services/defined-names.service.d.ts +3 -18
  159. package/lib/types/services/feature-calculation-manager.service.d.ts +5 -20
  160. package/lib/types/services/function.service.d.ts +5 -20
  161. package/lib/types/services/other-formula-manager.service.d.ts +8 -19
  162. package/lib/types/services/runtime.service.d.ts +6 -21
  163. package/lib/types/services/super-table.service.d.ts +4 -19
  164. package/lib/umd/index.js +1 -1
  165. package/package.json +6 -6
  166. package/lib/types/engine/utils/object-covert.d.ts +0 -18
  167. /package/lib/types/engine/utils/__tests__/{object-covert.spec.d.ts → value-object.spec.d.ts} +0 -0
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Li=Object.defineProperty;var Ai=(r,n,e)=>n in r?Li(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var S=(r,n,e)=>(Ai(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@univerjs/core"),te=require("@wendellhu/redi"),Mr=require("rxjs");function ns(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:c,endRow:l,endColumn:m}=o.range;if(t>=u&&t<=l&&s>=c&&s<=m)return!0}return!1}var f=(r=>(r.DIV_BY_ZERO="#DIV/0!",r.NAME="#NAME?",r.VALUE="#VALUE!",r.NUM="#NUM!",r.NA="#N/A",r.CYCLE="#CYCLE!",r.REF="#REF!",r.SPILL="#SPILL!",r.CALC="#CALC!",r.ERROR="#ERROR!",r.CONNECT="#GETTING_DATA",r.NULL="#NULL!",r))(f||{});const zt=new Set(Object.values(f));var ss=(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))(ss||{}),ge=(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))(ge||{}),F=(r=>(r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(F||{});const tr=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),ct=new Set(tr.keys()),xi=new Set(["=","<>",">",">=","<","<="]);var G=(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))(G||{}),qe=(r=>(r.PERCENTAGE="%",r.POUND="#",r))(qe||{});const wi=new Set(["%","#"]);var Re=(r=>(r.AT="@",r.MINUS="-",r))(Re||{});const Pi=" ",is=[...Object.values(F),...Object.values(ge),...Object.values(G),...Object.values(qe),...Object.values(Re)];function Ut(r){return is.includes(r)}function as(r){for(const n of is)if(r.indexOf(n)>-1)return!0;return!1}function Vi(r){return r[0]==="'"&&r[r.length-1]==="'"?r.substring(1,r.length-1):r}function vi(r){return Ut(r)&&r!==G.CLOSE_BRACES&&r!==G.CLOSE_BRACKET&&r!==G.SINGLE_QUOTATION&&r!==G.DOUBLE_QUOTATION||r===" "}function os(r){const n={};return Object.keys(r).forEach(e=>{const t=r[e];if(t==null)return!0;n[e]==null&&(n[e]={}),Object.keys(t).forEach(s=>{const i=t[s];n[e][s]=new _.ObjectMatrix(i)})}),n}function Mi(r){const n={};return Object.keys(r).forEach(e=>{const t=r[e];if(t==null)return!0;n[e]==null&&(n[e]={}),Object.keys(t).forEach(s=>{const i=t[s];n[e][s]=i.getData()})}),n}const Wr={id:"formula.mutation.register-function",type:_.CommandType.MUTATION,handler:()=>!0};class pt{constructor(n){S(this,"_cache");this._cache=new _.LRUMap(n)}set(n,e){const t=this._hash(n);this._cache.set(t,e)}get(n){const e=this._hash(n);return this._cache.get(e)}clear(){this._cache.clear()}_hash(n){return _.hashAlgorithm(n)}}const Yr='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',Bi="((?![\\[\\]\\/?*\\\\]).)*!",nt="$",Gr="\\s*?:\\s*?",xt=`'?(${Yr})?(${Bi})?'?`,zr=`\\${nt}?[A-Za-z]+\\${nt}?[0-9]+`,Fi=`^(${Re.AT})?${xt}${zr}${Gr}${zr}$`,Qt=`^${xt}\\s*?${zr}(${qe.POUND})?$`,us=`^${xt}\\${nt}?[0-9]+${Gr}\\${nt}?[0-9]+$`,cs=`^${xt}\\${nt}?[A-Za-z]+${Gr}\\${nt}?[A-Za-z]+$`,ls=`^${xt}\\s*?\\${nt}?[0-9]+$`,fs=`^${xt}\\s*?\\${nt}?[A-Za-z]+$`,hs="[.*?]",Oi="{.*?}";function ms(r){return new RegExp(Qt).test(r)||new RegExp(Fi).test(r)||new RegExp(us).test(r)||new RegExp(cs).test(r)}const Xe="P_1",rt="R_1",St="L_1",Ht="LR_1",ds="LO_1",Ui="LET",It="LAMBDA",ki="CUBE",Ti=/[^0-9]/g,ji=/[^A-Za-z]/g;function kt(r){const n=r[0]==="$",t=r.substring(1).indexOf("$")>-1;return n&&t?_.AbsoluteRefType.ALL:n?_.AbsoluteRefType.COLUMN:t?_.AbsoluteRefType.ROW:_.AbsoluteRefType.NONE}function Ii(r){const n=r.split("!");n.length>1&&(r=n[n.length-1]);const e=r.split(":");return e.length>1?{startAbsoluteRefType:kt(e[0]),endAbsoluteRefType:kt(e[1])}:{startAbsoluteRefType:kt(e[0])}}function vn(r=_.AbsoluteRefType.NONE){let n="",e="";return r===_.AbsoluteRefType.ROW?n="$":r===_.AbsoluteRefType.COLUMN?e="$":r===_.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function mt(r){const{startColumn:n,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=_.RANGE_TYPE.NORMAL}=r,u=vn(i),c=vn(a);if(o===_.RANGE_TYPE.ROW||o===_.RANGE_TYPE.ALL){const d=`${u.rowAbsoluteString}${e+1}`,E=`${c.rowAbsoluteString}${s+1}`;return`${d}:${E}`}if(o===_.RANGE_TYPE.COLUMN){const d=`${u.columnAbsoluteString}${_.Tools.chatAtABC(n)}`,E=`${c.columnAbsoluteString}${_.Tools.chatAtABC(t)}`;return`${d}:${E}`}const l=`${u.columnAbsoluteString}${_.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,m=`${c.columnAbsoluteString}${_.Tools.chatAtABC(t)}${c.rowAbsoluteString}${s+1}`;return l===m?l:`${l}:${m}`}function gs(r,n){return ur(r)?`'${r}'!${mt(n)}`:`${r}!${mt(n)}`}function ps(r,n,e){return ur(r)||ur(n)?`'[${r}]${n}'!${mt(e)}`:`[${r}]${n}!${mt(e)}`}function bt(r){const{unitId:n,sheetName:e,range:t}=r;return n!=null&&n.length>0&&e!=null&&e.length>0?ps(n,e,t):e!=null&&e.length>0?gs(e,t):mt(t)}function Br(r){const n=Number.parseInt(r.replace(Ti,""))-1,e=_.Tools.ABCatNum(r.replace(ji,"")),t=kt(r);return{row:n,column:e,absoluteRefType:t}}function Rs(r){const n=new RegExp(Yr).exec(r);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),r=r.replace(new RegExp(Yr),""));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 wt(r){const{refBody:n,sheetName:e,unitId:t}=Rs(r),s=n.indexOf(":");if(s===-1){const D=Br(n),C=D.row,L=D.column,x=D.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:C,startColumn:L,endRow:C,endColumn:L,startAbsoluteRefType:x,endAbsoluteRefType:x}}}const i=n.substring(0,s),a=n.substring(s+1),o=Br(i),u=Br(a),c=o.row,l=o.column,m=u.row,d=u.column;let E=_.RANGE_TYPE.NORMAL;return Number.isNaN(c)&&Number.isNaN(m)?E=_.RANGE_TYPE.COLUMN:Number.isNaN(l)&&Number.isNaN(d)&&(E=_.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:c,startColumn:l,endRow:m,endColumn:d,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:E}}}function ur(r){return r.length===0?!1:!!(as(r)||$i(r)||Yi(r)||zi(r)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(r))}function $i(r){const n=r.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(r)&&n!==null}function Yi(r){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(r)}function zi(r){return!new RegExp("^\\p{Letter}","u").test(r.charAt(0))}var Me=(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))(Me||{});function _s(r){let n="";for(const e of r)typeof e=="string"?n+=e:n+=e.token;return n}class J{constructor(){S(this,"_parent");S(this,"_token",rt);S(this,"_children",[]);S(this,"_lambdaId");S(this,"_functionDefinitionPrivacyVar");S(this,"_lambdaParameter","");S(this,"_startIndex",-1);S(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const t=this._getIndexInParent(n);t!=null&&(this.getChildren().splice(t,1,e),e.setParent(this))}changeToParent(n){const e=this.getParent();e&&e.removeChild(this),this.setParent(n),n.getChildren().push(this)}removeChild(n){const e=this._getIndexInParent(n);e!=null&&this.getChildren().splice(e,1)}serialize(){const n=this.getToken(),e=this.getChildren(),t=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof J?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 Es=1e5,Fr=new pt(Es),Or=new pt(Es);class Dr extends _.Disposable{constructor(){super(...arguments);S(this,"_currentLexerNode",new J);S(this,"_upLevel",0);S(this,"_segment","");S(this,"_bracketState",[]);S(this,"_squareBracketState",0);S(this,"_bracesState",0);S(this,"_singleQuotationState",0);S(this,"_doubleQuotationState",0);S(this,"_lambdaState",!1);S(this,"_colonState",!1);S(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Fr.clear(),Or.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const s=this._getCurrentParamIndex(e,t);if(s==null||s===f.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==Xe&&!Ut(u)&&a.getStartIndex()!==-1){const c=a.getChildren().indexOf(o);return{functionName:u,paramIndex:c}}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 c=i[o];if(typeof c=="string"||c.nodeType!==Me.REFERENCE){a.push(c);continue}const{token:l}=c,m=wt(l),{range:d,sheetName:E,unitId:D}=m,C=_.Rectangle.moveOffset(d,t,s);let L="";_.isValidRange(C)?L=bt({range:C,unitId:D,sheetName:E}):L=f.REF,a.push({...c,token:L})}return`=${_s(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===G.CLOSE_BRACKET||i===" ")&&s>=0;)i===G.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===f.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),c=0;for(a[1]===G.OPEN_BRACKET&&c++;u;){const l=u.getToken();l!==Xe&&l!==G.COLON&&u.getStartIndex()!==-1&&l.toUpperCase()!==It&&(t===0?c+=1:t--),u=u.getParent()}return c}sequenceNodesBuilder(e){const t=Or.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Or.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:c,currentString:l}=o;if(l===G.DOUBLE_QUOTATION&&(s=!0),(c!==""||i===0)&&i!==a-1){t.push(l);continue}let m=(u==null?void 0:u.segment)||"",d=i-m.length,E=i-1,D=i-1;if(i===a-1&&this._isLastMergeString(l)&&(m+=l,E+=1),m===""||tr.has(m)){t.push(l);continue}const C=m.trim(),L=this._replacePrefixString(C);if(s===!0&&C[C.length-1]===G.DOUBLE_QUOTATION)s=!1,this._pushSequenceNode(t,{nodeType:Me.STRING,token:m,startIndex:d,endIndex:E},D);else if(new RegExp(Qt).test(L)){if(L.length!==C.length){const x=C.length-L.length;D+=x,d+=x,m=this._replacePrefixString(m)}this._pushSequenceNode(t,{nodeType:Me.REFERENCE,token:m,startIndex:d,endIndex:E},D)}else _.Tools.isStringNumber(C)?this._pushSequenceNode(t,{nodeType:Me.NUMBER,token:m,startIndex:d,endIndex:E},D):C.length>0&&this._pushSequenceNode(t,{nodeType:Me.FUNCTION,token:m,startIndex:d,endIndex:E},D);(i!==a-1||!this._isLastMergeString(l))&&t.push(l)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===G.DOUBLE_QUOTATION||_.Tools.isStringNumber(e)||!Ut(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()===G.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===Me.FUNCTION&&o.token.trim().substring(0,1)===G.OPEN_BRACES){o.nodeType=Me.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===G.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&ms((a.token+o+u.token).trim())&&(a.nodeType=Me.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i];if(o===Pi&&!s)t.push(o);else{if(!s&&(o===Re.AT||o===Re.MINUS))continue;t.push(o),s=!0}}return t.join("")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const l=Fr.get(e);if(l)return l}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(rt);const i=[];let a=this._nodeMaker(e,i);if(a===f.VALUE||i.length===0)return a;let o=!1,u="";if(s){const{hasDefinedName:l,sequenceString:m}=s(i);o=l,u=m}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(rt),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const c=this._getTopNode(this._currentLexerNode);if(c&&(this._currentLexerNode=c),t){if(!this._suffixExpressionHandler(this._currentLexerNode))return f.VALUE;Fr.set(e,this._currentLexerNode)}return this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const t=e.getChildren();if(!t)return!1;const s=t.length,i=[],a=[];for(let c=0;c<s;c++){const l=t[c];if(l instanceof J)this._suffixExpressionHandler(l),i.push(l);else{const m=l.trim();if(m==="")continue;if(ct.has(m)){if(m===ge.PLUS&&this._deletePlusForPreNode(t[c-1]))continue;if(m!==ge.PLUS&&m!==ge.MINUS&&this._deletePlusForPreNode(t[c-1]))return!1;for(;a.length>0;){const d=(o=a[a.length-1])==null?void 0:o.trim();if(!d||d===G.OPEN_BRACKET)break;const E=tr.get(d),D=tr.get(m);if(!E||!D)break;if(D>=E)i.push(a.pop());else break}a.push(l)}else if(m===G.OPEN_BRACKET)a.push(l);else if(m===G.CLOSE_BRACKET){if(this._checkOpenBracket(t[c-1])||this._checkOperator(t[c-1]))return!1;for(;a.length>0;){const d=(u=a[a.length-1])==null?void 0:u.trim();if(!d)break;if(d===G.OPEN_BRACKET){a.pop();break}i.push(a.pop())}}else{if(this._checkCloseBracket(t[c-1]))return!1;i.push(l)}}}for(;a.length>0;){const c=a.pop();if(c===G.OPEN_BRACKET||c===G.CLOSE_BRACKET)return!1;i.push(c)}return e.setChildren(i),!0}_checkCloseBracket(e){return e===G.CLOSE_BRACKET}_checkOpenBracket(e){return e===G.OPEN_BRACKET}_checkOperator(e){return e==null||e instanceof J?!1:ct.has(e)}_deletePlusForPreNode(e){if(e==null)return!0;if(!(e instanceof J)){const t=e.trim();if(ct.has(t)||t===G.OPEN_BRACKET)return!0}return!1}_resetCurrentLexerNode(){this._currentLexerNode=new J}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_changeCurrentBracket(e){const t=this._bracketState;t[t.length-1]=e}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof J)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,c;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===St){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const l=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();l&&(this._currentLexerNode=l),t=!0}}else if(e!=null&&e.getParent()){const l=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();l&&(this._currentLexerNode=l),t=!0}for(let l=0;l<this._upLevel;l++){const m=(c=this._currentLexerNode)==null?void 0:c.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 J)&&this.isColonOpen()){const i=new J;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 J;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!!(ct.has(e)||e===G.OPEN_BRACKET||e===G.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new J,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!==qe.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!Ut(i)}_nodeMaker(e,t,s){e.substring(0,1)===ge.EQUALS&&(e=e.substring(1));let i=!1;e.substring(0,1)===ge.MINUS&&(e=`0${e}`,i=!0);const a=e.split(""),o=a.length;let u=0;for(this._resetTemp();u<o;){const c=a[u];if(s===u)return[this._currentLexerNode,c];if(c===G.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,u),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=a[u+1];if(l&&l===G.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;u++}else l&&this._newAndPushCurrentLexerNode(Xe,u)}else this._pushNodeToChildren(c),this._openBracket(0);else if(c===G.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(c);else if(l===1){const m=a[u+1];if(m&&m===G.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;this._newAndPushCurrentLexerNode(St,u,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&u!==o-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(c===G.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(c),this._openBraces();else if(c===G.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(c),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(c===G.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(c),this._openSquareBracket();else if(c===G.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(c),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(c);else if(c===G.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=a[u+1];l&&l===G.DOUBLE_QUOTATION?u++:this._closeDoubleQuotation()}this._pushSegment(c)}else if(c===G.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=a[u+1];l&&l===G.SINGLE_QUOTATION?u++:this._closeSingleQuotation()}this._pushSegment(c)}else if(c===G.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&u!==o-1&&l!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Xe,u)}else{const m=new J;m.setToken(ki);const d=new J;d.setToken(Xe),d.changeToParent(m);const E=this._currentLexerNode.getParent();if(E&&E.getToken()===G.COLON){const D=E.getParent();if(!D)return f.VALUE;E.changeToParent(d),D.setChildren([]),m.changeToParent(D)}else return f.VALUE;this._changeCurrentBracket(1),this._pushNodeToChildren(this._segment),this._resetSegment(),this._currentLexerNode=m,this._newAndPushCurrentLexerNode(Xe,u)}}else if(c===G.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new J;l.setToken(c);const m=new J;m.setToken(Xe),m.setParent(l);const d=new J;d.setToken(Xe),d.setParent(l),l.getChildren().push(m,d);let E=l,D=0;if(this._segmentCount()>0){let C,L,x=0;const P=this._segment.trim(),O=P[0],I=P[1];if(O===Re.MINUS&&(C=new J,C.setToken(Re.MINUS),x++),(O===Re.AT||I===Re.AT)&&(L=new J,L.setToken(Re.AT),C&&(C.addChildren(L),L.setParent(C)),x++),x>0&&(this._segment=P.slice(x)),D=x,L)if(L.addChildren(l),l.setParent(L),L.getParent()){const le=L.getParent();le&&(E=le)}else E=L;else C&&(E=C,C.addChildren(l),l.setParent(C));const ne=new J;ne.setToken(this._segment),ne.setParent(m),m.getChildren().push(ne),this._resetSegment()}else{const C=this._getLastChildCurrentLexerNode();C&&C.changeToParent(m)}this._setCurrentLexerNode(E),this._currentLexerNode=d,this._openColon(D)}else if(wi.has(c)&&this._checkSimilarErrorToken(c,u,a)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new J;l.setToken(c);const m=this._getLastChildCurrent();m instanceof J?m.changeToParent(l):m!==!1&&(l.getChildren().push(m),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(ct.has(c)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(c===ge.MINUS&&l===""){const m=this._findPreviousToken(a,u-1)||"";if(this._negativeCondition(m)){this._pushSegment(ge.MINUS),i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}}else if(this._segment.length>0&&a[u-1]&&a[u-1].toUpperCase()==="E"&&(c===ge.MINUS||c===ge.PLUS)){this._pushSegment(c),i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(c===ge.LESS_THAN||c===ge.GREATER_THAN){const m=a[u+1];m&&ct.has(c+m)?(this._pushNodeToChildren(l+c+m),u++):this._pushNodeToChildren(l+c)}else this._pushNodeToChildren(l+c);this._resetSegment()}else this._pushSegment(c);i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++}this._pushNodeToChildren(this._segment)}}var Qi=Object.defineProperty,Hi=Object.getOwnPropertyDescriptor,Wi=(r,n,e,t)=>{for(var s=t>1?void 0:t?Hi(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&&Qi(n,e,s),s},Mn=(r,n)=>(e,t)=>n(e,t,r);exports.FormulaDataModel=class extends _.Disposable{constructor(e,t){super();S(this,"_formulaData",{});S(this,"_arrayFormulaRange",{});S(this,"_arrayFormulaCellData",{});S(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var c,l,m,d;const a=s[i],o=(l=(c=this._arrayFormulaRange)==null?void 0:c[t])==null?void 0:l[i];if(o==null)return!0;let u=new _.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new _.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((E,D)=>{var I;const C=(I=o==null?void 0:o[E])==null?void 0:I[D];if(C==null)return!0;const{startRow:L,startColumn:x,endRow:P,endColumn:O}=C;for(let ne=L;ne<=P;ne++)for(let le=x;le<=O;le++)u.setValue(ne,le,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 c,l,m,d;const a=s[i];let o=new _.ObjectMatrix,u=new _.ObjectMatrix;((c=this._arrayFormulaRange[t])==null?void 0:c[i])!=null&&(o=new _.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new _.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((E,D)=>{const C=o==null?void 0:o.getValue(E,D);if(C==null)return!0;const{startRow:L,startColumn:x,endRow:P,endColumn:O}=C;for(let I=L;I<=P;I++)for(let ne=x;ne<=O;ne++)u.setValue(I,ne,null)}),a.forValue((E,D,C)=>{u.setValue(E,D,C)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=u.getData())})})}getFormulaData(){return this._formulaData}setFormulaData(e){this._formulaData=e}getArrayFormulaRange(){return this._arrayFormulaRange}setArrayFormulaRange(e){this._arrayFormulaRange=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getNumfmtItemMap(){return this._numfmtItemMap}getNumfmtValue(e,t,s,i){var a,o,u;return(u=(o=(a=this._numfmtItemMap[e])==null?void 0:a[t])==null?void 0:o[s])==null?void 0:u[i]}setNumfmtItemMap(e){this._numfmtItemMap=e}updateNumfmtItemMap(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._numfmtItemMap[t]==null&&(this._numfmtItemMap[t]={}),Object.keys(s).forEach(i=>{const a=s[i],o=new _.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),o.forValue((u,c,l)=>{this._numfmtItemMap[t][i][u]==null&&(this._numfmtItemMap[t][i][u]={}),this._numfmtItemMap[t][i][u][c]=l})})})}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,c;const a=new _.ObjectMatrix(s[i]);let o=new _.ObjectMatrix;(u=this._arrayFormulaRange[t])!=null&&u[i]&&(o=new _.ObjectMatrix((c=this._arrayFormulaRange[t])==null?void 0:c[i])),a.forValue((l,m,d)=>{o.setValue(l,m,d)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=o.getData())})})}deleteArrayFormulaRange(e,t,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(a==null)return;const o=new _.ObjectMatrix(a);o.getValue(s,i)&&(o.realDeleteValue(s,i),this._arrayFormulaRange[e]&&(this._arrayFormulaRange[e][t]=o.getData()))}initFormulaData(){if(this._currentUniverService.getAllUniverSheetsInstance().length===0)return;const t=this._currentUniverService.getCurrentUniverSheetInstance(),s=t.getUnitId();this._formulaData[s]={},t.getSheets().forEach(a=>{const o=a.getCellMatrix(),u=a.getSheetId();Cs(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={},c={};for(const l of o){const m=l.getSheetId(),d=l.getConfig();u[m]={cellData:new _.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},c[l.getName()]=l.getSheetId()}t[a]=u,s[a]=c}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new _.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const c=u[e];c[t]==null&&(c[t]={});const l=new _.ObjectMatrix(c[t]);i.forValue((m,d,E)=>{const D=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"",L=_.isFormulaString(D),x=_.isFormulaId(C);if(L&&x)l.setValue(m,d,{f:D,si:C}),a.set(C,{f:D,r:m,c:d});else if(L&&!x)l.setValue(m,d,{f:D});else if(!L&&x)l.setValue(m,d,{f:"",si:C});else if(!L&&!x&&l.getValue(m,d)){const P=l.getValue(m,d),O=(P==null?void 0:P.f)||"",I=(P==null?void 0:P.si)||"";_.isFormulaString(O)&&_.isFormulaId(I)&&o.set(I,O),l.realDeleteValue(m,d)}}),l.forValue((m,d,E)=>{const D=(E==null?void 0:E.f)||"",C=(E==null?void 0:E.si)||"";if(_.isFormulaId(C)){const L=a.get(C),x=o.get(C);if(L&&!_.isFormulaString(D)){const P=L.f,O=d-L.c,I=m-L.r;l.setValue(m,d,{f:P,si:C,x:O,y:I})}else if(typeof x=="string"){const P=E.x||0,O=E.y||0,I=this._lexerTreeBuilder.moveFormulaRefOffset(x,P,O);o.set(C,{r:m,c:d,f:I}),l.setValue(m,d,{f:I,si:C})}else if(typeof x=="object"){const P=d-x.c,O=m-x.r;l.setValue(m,d,{f:x.f,si:C,x:P,y:O})}}})}updateArrayFormulaRange(e,t,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(!i)return;const a=new _.ObjectMatrix(i);new _.ObjectMatrix(s).forValue((c,l,m)=>{if((a==null?void 0:a.getValue(c,l))==null)return!0;const E=(m==null?void 0:m.f)||"",D=(m==null?void 0:m.si)||"",C=_.isFormulaString(E),L=_.isFormulaId(D);!C&&!L&&a.realDeleteValue(c,l)})}updateArrayFormulaCellData(e,t,s){var l,m;const i=(l=this._arrayFormulaRange[e])==null?void 0:l[t];if(!i)return;const a=new _.ObjectMatrix(i),o=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!o)return;const u=new _.ObjectMatrix(o);new _.ObjectMatrix(s).forValue((d,E,D)=>{const C=a==null?void 0:a.getValue(d,E);if(C==null)return!0;const L=(D==null?void 0:D.f)||"",x=(D==null?void 0:D.si)||"",P=_.isFormulaString(L),O=_.isFormulaId(x);if(!P&&!O){const{startRow:I,startColumn:ne,endRow:le,endColumn:fe}=C;for(let q=I;q<=le;q++)for(let Y=ne;Y<=fe;Y++)u.realDeleteValue(q,Y)}})}updateNumfmtData(e,t,s){var l,m;const i=(l=this._arrayFormulaRange[e])==null?void 0:l[t],a=new _.ObjectMatrix(i),o=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!o)return;const u=new _.ObjectMatrix(o);new _.ObjectMatrix(s).forValue((d,E,D)=>{const C=(D==null?void 0:D.f)||"",L=(D==null?void 0:D.si)||"",x=_.isFormulaString(C),P=_.isFormulaId(L);if(!x&&!P){u.setValue(d,E,null);const O=a.getValue(d,E);if(O){const{startRow:I,startColumn:ne,endRow:le,endColumn:fe}=O;for(let q=I;q<=le;q++)for(let Y=ne;Y<=fe;Y++)u.setValue(q,Y,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const o=new _.ObjectMatrix(a[t]);let u=null;return o.forValue((c,l,m)=>{const{f:d,si:E,x:D=0,y:C=0}=m;if(E===e&&d.length>0&&D===0&&C===0)return u=m,!1}),u}getFormulaDataItem(e,t,s,i){var a,o,u,c;return(c=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[s])==null?void 0:u[e])==null?void 0:c[t]}getFormulaIdMap(e,t){const s=new Map,i=this._formulaData;if(i[e]==null)return s;const a=i[e];return(a==null?void 0:a[t])==null||new _.ObjectMatrix(a[t]).forValue((u,c,l)=>{const m=(l==null?void 0:l.f)||"",d=(l==null?void 0:l.si)||"",E=(l==null?void 0:l.x)||0,D=(l==null?void 0:l.y)||0;_.isFormulaString(m)&&_.isFormulaId(d)&&E===0&&D===0&&s.set(d,{f:m,r:u,c})}),s}};exports.FormulaDataModel=Wi([Mn(0,_.IUniverInstanceService),Mn(1,te.Inject(Dr))],exports.FormulaDataModel);function Cs(r,n,e,t){const s=new Map,i=new _.ObjectMatrix;t.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"",m=_.isFormulaString(c),d=_.isFormulaId(l);m&&d?(i.setValue(a,o,{f:c,si:l}),s.set(l,{f:c,r:a,c:o})):m&&!d?i.setValue(a,o,{f:c}):!m&&d&&i.setValue(a,o,{f:"",si:l})}),i.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"";if(_.isFormulaId(l)&&!_.isFormulaString(c)){const m=s.get(l);if(m){const d=m.f,E=o-m.c,D=a-m.r;i.setValue(a,o,{f:d,si:l,x:E,y:D})}}}),r[n]&&(r[n][e]=i.getData())}const Gi=r=>{const n=r.get(exports.FormulaDataModel),e=_.Tools.deepClone(n.getArrayFormulaRange()),t=_.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},cr={id:"formula.mutation.set-array-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>{const e=r.get(exports.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},yr={id:"formula.mutation.set-defined-name",type:_.CommandType.MUTATION,handler:()=>!0},br={id:"formula.mutation.remove-defined-name",type:_.CommandType.MUTATION,handler:()=>!0},Xr={id:"formula.mutation.set-feature-calculation",type:_.CommandType.MUTATION,handler:()=>!0},Kr={id:"formula.mutation.remove-feature-calculation",type:_.CommandType.MUTATION,handler:()=>!0},qr={id:"formula.mutation.set-formula-calculation-start",type:_.CommandType.MUTATION,handler:()=>!0},Zr={id:"formula.mutation.set-formula-calculation-stop",type:_.CommandType.MUTATION,handler:()=>!0},lr={id:"formula.mutation.set-formula-calculation-notification",type:_.CommandType.MUTATION,handler:()=>!0},Jr={id:"formula.mutation.set-formula-calculation-result",type:_.CommandType.MUTATION,handler:()=>!0},Nr={id:"formula.mutation.set-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).setFormulaData(n.formulaData),!0)},en={id:"formula.mutation.set-other-formula",type:_.CommandType.MUTATION,handler:()=>!0},tn={id:"formula.mutation.remove-other-formula",type:_.CommandType.MUTATION,handler:()=>!0},Ds={id:"formula.mutation.set-super-table",type:_.CommandType.MUTATION,handler:()=>!0},ys={id:"formula.mutation.remove-super-table",type:_.CommandType.MUTATION,handler:()=>!0},rn={id:"formula.mutation.set-super-table-option",type:_.CommandType.MUTATION,handler:()=>!0},nn={id:"formula.mutation.unregister-function",type:_.CommandType.MUTATION,handler:()=>!0};class Sr extends _.Disposable{constructor(){super(...arguments);S(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var dt=(r=>(r.FALSE="FALSE",r.TRUE="TRUE",r))(dt||{}),ft=(r=>(r[r.SUCCESS=0]="SUCCESS",r[r.ERROR=1]="ERROR",r))(ft||{}),lt=(r=>(r.ALL="#All",r.DATA="#Data",r.HEADERS="#Headers",r.TOTALS="#Totals",r))(lt||{}),Te=(r=>(r[r.FRONT=0]="FRONT",r[r.BACK=1]="BACK",r))(Te||{});class Xi{constructor(){S(this,"_cache",new Map);S(this,"_continueBuildingCache",new Map)}set(n,e,t,s,i){if(!this.shouldContinueBuildingCache(n,e,t,i))return;let a=this._cache.get(n);a==null&&(a=new Map,this._cache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);u==null&&(u=new Map,o.set(t,u));let c=u.get(s);c==null&&(c=new Set,u.set(s,c)),c.add(i)}getCellValuePositions(n,e,t){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(n,e,t,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:o.get(s)}getCellPosition(n,e,t,s,i,a){const o=this.getCellPositions(n,e,t,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,t,s,i){let a=this._continueBuildingCache.get(n);a==null&&(a=new Map,this._continueBuildingCache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);if(u==null){u={startRow:s,endRow:i},o.set(t,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,t,s){var u,c;const i=(c=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:c.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 c,l;if(t===-1||s===-1||i===-1)return!1;const a=(l=(c=this._continueBuildingCache.get(n))==null?void 0:c.get(e))==null?void 0:l.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 Ne=new Xi;var Ke=(r=>(r[r.MIN=0]="MIN",r[r.MAX=1]="MAX",r))(Ke||{}),xe=(r=>(r[r.NORMAL=0]="NORMAL",r[r.MIN=1]="MIN",r[r.MAX=2]="MAX",r))(xe||{});function Bn(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(r,n)=>r.localeCompare(n)}function Ki(r){return r.indexOf("*")>-1||r.indexOf("?")>-1}function Fn(r,n){const e=Zi(n).replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(r)}function On(r){return r.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function qi(r,n,e){let t=!1;switch(e){case F.EQUALS:t=Fn(r,n);break;case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:t=Fn(r,n)||r>On(n);break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:t=r<On(n);break}return t}function Zi(r){return r.replace(/[.+^${}()|[\]\\]/g,"\\$&")}class Ze extends Sr{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isCube(){return!1}isArray(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return h.create(f.VALUE)}max(){return h.create(f.VALUE)}min(){return h.create(f.VALUE)}count(){return h.create(f.VALUE)}countA(){return h.create(f.VALUE)}countBlank(){return h.create(f.VALUE)}getNegative(){return h.create(f.VALUE)}getReciprocal(){return h.create(f.VALUE)}plus(n){return h.create(f.VALUE)}minus(n){return h.create(f.VALUE)}multiply(n){return h.create(f.VALUE)}divided(n){return h.create(f.VALUE)}mod(n){return h.create(f.VALUE)}map(n){return h.create(f.NAME)}mapValue(n){return h.create(f.NAME)}compare(n,e){return h.create(f.NAME)}isEqual(n){return this.compare(n,F.EQUALS)}isNotEqual(n){return this.compare(n,F.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,F.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,F.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,F.LESS_THAN)}isGreaterThan(n){return this.compare(n,F.GREATER_THAN)}concatenateFront(n){return h.create(f.NAME)}concatenateBack(n){return h.create(f.NAME)}plusBy(n){return h.create(f.VALUE)}minusBy(n){return h.create(f.VALUE)}multiplyBy(n){return h.create(f.VALUE)}dividedBy(n){return h.create(f.VALUE)}modInverse(n){return h.create(f.VALUE)}compareBy(n,e){return h.create(f.NAME)}concatenate(n,e=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 h.create(f.VALUE)}powInverse(n){return h.create(f.VALUE)}sqrt(){return h.create(f.VALUE)}cbrt(){return h.create(f.VALUE)}cos(){return h.create(f.VALUE)}acos(){return h.create(f.VALUE)}acosh(){return h.create(f.VALUE)}sin(){return h.create(f.VALUE)}asin(){return h.create(f.VALUE)}asinh(){return h.create(f.VALUE)}tan(){return h.create(f.VALUE)}tanh(){return h.create(f.VALUE)}atan(){return h.create(f.VALUE)}atan2(n){return h.create(f.VALUE)}atan2Inverse(n){return h.create(f.VALUE)}atanh(){return h.create(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return h.create(f.VALUE)}log10(){return h.create(f.VALUE)}exp(){return h.create(f.VALUE)}abs(){return h.create(f.VALUE)}round(n){return h.create(f.VALUE)}roundInverse(n){return h.create(f.VALUE)}floor(n){return h.create(f.VALUE)}floorInverse(n){return h.create(f.VALUE)}ceil(n){return h.create(f.VALUE)}ceilInverse(n){return h.create(f.VALUE)}convertToNumberObjectValue(){return h.create(f.VALUE)}convertToBooleanObjectValue(){return h.create(f.VALUE)}}const Ji=1e3,Un=new pt(Ji);class h extends Ze{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}static create(n,e=""){const t=`${n}-${e}`,s=Un.get(t);if(s)return s;const i=new h(n,e);return Un.set(t,i),i}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var Ni=20,ea=1,gt=1e6,kn=1e6,ta=-7,ra=21,na=!1,Wt="[big.js] ",Rt=Wt+"Invalid ",Lr=Rt+"decimal places",sa=Rt+"rounding mode",bs=Wt+"Division by zero",me={},Ye=void 0,ia=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function Ss(){function r(n){var e=this;if(!(e instanceof r))return n===Ye?Ss():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(Rt+"value");n=n===0&&1/n<0?"-0":String(n)}aa(e,n)}e.constructor=r}return r.prototype=me,r.DP=Ni,r.RM=ea,r.NE=ta,r.PE=ra,r.strict=na,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}function aa(r,n){var e,t,s;if(!ia.test(n))throw Error(Rt+"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 _t(r,n,e,t){var s=r.c;if(e===Ye&&(e=r.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(sa);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]!==Ye))),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]!==Ye||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 Pt(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}me.abs=function(){var r=new this.constructor(this);return r.s=1,r};me.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};me.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>gt)throw Error(Lr);if(!s[0])throw Error(bs);if(!t[0])return r.s=i,r.c=[r.e=0],r;var o,u,c,l,m,d=s.slice(),E=o=s.length,D=t.length,C=t.slice(0,o),L=C.length,x=r,P=x.c=[],O=0,I=a+(x.e=n.e-r.e)+1;for(x.s=i,i=I<0?0:I,d.unshift(0);L++<o;)C.push(0);do{for(c=0;c<10;c++){if(o!=(L=C.length))l=o>L?1:-1;else for(m=-1,l=0;++m<o;)if(s[m]!=C[m]){l=s[m]>C[m]?1:-1;break}if(l<0){for(u=L==o?s:d;L;){if(C[--L]<u[L]){for(m=L;m&&!C[--m];)C[m]=9;--C[m],C[L]+=10}C[L]-=u[L]}for(;!C[0];)C.shift()}else break}P[O++]=l?c:++c,C[0]&&l?C[L]=t[E]||0:C=[t[E]]}while((E++<D||C[0]!==Ye)&&i--);return!P[0]&&O!=1&&(P.shift(),x.e--,I--),O>I&&_t(x,I,e.RM,C[0]!==Ye),x};me.eq=function(r){return this.cmp(r)===0};me.gt=function(r){return this.cmp(r)>0};me.gte=function(r){return this.cmp(r)>-1};me.lt=function(r){return this.cmp(r)<0};me.lte=function(r){return this.cmp(r)<1};me.minus=me.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 c=i.c.slice(),l=i.e,m=r.c,d=r.e;if(!c[0]||!m[0])return m[0]?r.s=-u:c[0]?r=new a(i):r.s=1,r;if(o=l-d){for((s=o<0)?(o=-o,t=c):(d=l,t=m),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((s=c.length<m.length)?c:m).length,o=u=0;u<e;u++)if(c[u]!=m[u]){s=c[u]<m[u];break}if(s&&(t=c,c=m,m=t,r.s=-r.s),(u=(e=m.length)-(n=c.length))>0)for(;u--;)c[n++]=0;for(u=n;e>o;){if(c[--e]<m[e]){for(n=e;n&&!c[--n];)c[n]=9;--c[n],c[e]+=10}c[e]-=m[e]}for(;c[--u]===0;)c.pop();for(;c[0]===0;)c.shift(),--d;return c[0]||(r.s=1,c=[d=0]),r.c=c,r.e=d,r};me.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(bs);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)))};me.neg=function(){var r=new this.constructor(this);return r.s=-r.s,r};me.plus=me.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,c=r.c;if(!o[0]||!c[0])return c[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=c):(n=-n,t=o),t.reverse();n--;)t.push(0);t.reverse()}for(o.length-c.length<0&&(t=c,c=o,o=t),n=c.length,e=0;n;o[n]%=10)e=(o[--n]=o[n]+c[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};me.pow=function(r){var n=this,e=new n.constructor("1"),t=e,s=r<0;if(r!==~~r||r<-kn||r>kn)throw Error(Rt+"exponent");for(s&&(r=-r);r&1&&(t=t.times(n)),r>>=1,!!r;)n=n.times(n);return s?e.div(t):t};me.prec=function(r,n){if(r!==~~r||r<1||r>gt)throw Error(Rt+"precision");return _t(new this.constructor(this),r,n)};me.round=function(r,n){if(r===Ye)r=0;else if(r!==~~r||r<-gt||r>gt)throw Error(Lr);return _t(new this.constructor(this),r+this.e+1,n)};me.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(Wt+"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 _t(r,(s.DP-=4)+r.e+1,s.RM)};me.times=me.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,c=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+c,a<o&&(n=s,s=i,i=n,c=a,a=o,o=c),n=new Array(c=a+o);c--;)n[c]=0;for(u=o;u--;){for(o=0,c=a+u;c>u;)o=n[c]+i[u]*s[c-u-1]+o,n[c--]=o%10,o=o/10|0;n[c]=o}for(o?++r.e:n.shift(),u=n.length;!n[--u];)n.pop();return r.c=n,r};me.toExponential=function(r,n){var e=this,t=e.c[0];if(r!==Ye){if(r!==~~r||r<0||r>gt)throw Error(Lr);for(e=_t(new e.constructor(e),++r,n);e.c.length<r;)e.c.push(0)}return Pt(e,!0,!!t)};me.toFixed=function(r,n){var e=this,t=e.c[0];if(r!==Ye){if(r!==~~r||r<0||r>gt)throw Error(Lr);for(e=_t(new e.constructor(e),r+e.e+1,n),r=r+e.e+1;e.c.length<r;)e.c.push(0)}return Pt(e,!1,!!t)};me[Symbol.for("nodejs.util.inspect.custom")]=me.toJSON=me.toString=function(){var r=this,n=r.constructor;return Pt(r,r.e<=n.NE||r.e>=n.PE,!!r.c[0])};me.toNumber=function(){var r=Number(Pt(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(r.toString()))throw Error(Wt+"Imprecise conversion");return r};me.toPrecision=function(r,n){var e=this,t=e.constructor,s=e.c[0];if(r!==Ye){if(r!==~~r||r<1||r>gt)throw Error(Rt+"precision");for(e=_t(new t(e),r,n);e.c.length<r;)e.c.push(0)}return Pt(e,r<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)};me.valueOf=function(){var r=this,n=r.constructor;if(n.strict===!0)throw Error(Wt+"valueOf disallowed");return Pt(r,r.e<=n.NE||r.e>=n.PE,!0)};var Ce=Ss();function Ls(r){let n;switch(r){case F.EQUALS:n=F.EQUALS;break;case F.GREATER_THAN:n=F.LESS_THAN;break;case F.GREATER_THAN_OR_EQUAL:n=F.LESS_THAN_OR_EQUAL;break;case F.LESS_THAN:n=F.GREATER_THAN;break;case F.LESS_THAN_OR_EQUAL:n=F.GREATER_THAN_OR_EQUAL;break;case F.NOT_EQUAL:n=F.NOT_EQUAL;break}return n}function sn(r,n){return Ce(r).times(n).toNumber()}function Tn(r,n){const e=10**Math.floor(n);return Math.round(sn(r,e))/e}function jn(r,n){const e=10**Math.floor(n);return Math.floor(sn(r,e))/e}function In(r,n){const e=10**Math.floor(n);return Math.ceil(sn(r,e))/e}function $n(r,n){const e=new Ce(r),t=new Ce(n),s=Math.floor(r/n);return e.minus(t.times(s)).toNumber()}function Yn(r,n){return r**n}const Cr=class Cr extends Ze{static create(){return this._instance=this._instance||new Cr(0),this._instance}isNull(){return!0}plus(n){return b.create(0).plus(n)}minus(n){return b.create(0).minus(n)}multiply(n){return b.create(0).multiply(n)}divided(n){return b.create(0).divided(n)}mod(n){return b.create(0).mod(n)}compare(n,e){return n.isString()?_e.create("").compare(n,e):n.isBoolean()?Q.create(!1).compare(n,e):b.create(0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(_e.create("")):_e.create(this.concatenate(n.getValue(),Te.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(_e.create("")):_e.create(this.concatenate(n.getValue(),Te.BACK))}plusBy(n){return b.create(0).plusBy(n)}minusBy(n){return b.create(0).minusBy(n)}multiplyBy(n){return b.create(0).multiplyBy(n)}dividedBy(n){return b.create(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?_e.create("").compareBy(n,e):typeof n=="boolean"?Q.create(!1).compareBy(n,e):b.create(0).compareBy(n,e)}pow(n){return b.create(0).pow(n)}sqrt(){return b.create(0).sqrt()}cbrt(){return b.create(0).cbrt()}cos(){return b.create(0).cos()}acos(){return b.create(0).acos()}acosh(){return b.create(0).acosh()}sin(){return b.create(0).sin()}asin(){return b.create(0).asin()}asinh(){return b.create(0).asinh()}tan(){return b.create(0).tan()}tanh(){return b.create(0).tanh()}atan(){return b.create(0).atan()}atan2(n){return b.create(0).atan2(n)}atanh(){return b.create(0).atanh()}log(){return h.create(f.NUM)}log10(){return h.create(f.NUM)}exp(){return b.create(0).exp()}abs(){return b.create(0).abs()}round(n){return b.create(0).round(n)}floor(n){return b.create(0).floor(n)}ceil(n){return b.create(0).ceil(n)}convertToNumberObjectValue(){return b.create(0)}convertToBooleanObjectValue(){return Q.create(!1)}};S(Cr,"_instance");let ce=Cr;const yt=class yt extends Ze{constructor(e){super(e);S(this,"_value",!1);this._value=e}static create(e){return e?(this._instanceTrue=this._instanceTrue||new yt(!0),this._instanceTrue):(this._instanceFalse=this._instanceFalse||new yt(!1),this._instanceFalse)}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),b.create(-t)}getReciprocal(){return this.getValue()?b.create(1):h.create(f.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}mod(e){return this._convertTonNumber().mod(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),b.create(t)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}convertToNumberObjectValue(){return xr(this.getValue())}convertToBooleanObjectValue(){return this}};S(yt,"_instanceTrue"),S(yt,"_instanceFalse");let Q=yt;const oa=2e5,zn=new pt(oa);class b extends Ze{constructor(e){super(e);S(this,"_value",0);this._value=Number(e)}static create(e,t=""){const s=`${e}-${t}`,i=zn.get(s);if(i)return i;const a=new b(e);return a.setPattern(t),zn.set(s,a),a}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return b.create(0).minus(this)}getReciprocal(){return b.create(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return h.create(f.DIV_BY_ZERO);if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(s===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=$n(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?h.create(f.DIV_BY_ZERO):b.create($n(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):_e.create(this.concatenate(e.getValue(),Te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):_e.create(this.concatenate(e.getValue(),Te.BACK))}compare(e,t){return e.isArray()?e.compare(this,Ls(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return zt.has(e)?h.create(e):h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).plus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).minus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).times(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(e===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).div(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?e===!1?h.create(f.DIV_BY_ZERO):b.create(Ce(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.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 F.EQUALS:i=Ce(s).eq(e);break;case F.GREATER_THAN:i=Ce(s).gt(e);break;case F.GREATER_THAN_OR_EQUAL:i=Ce(s).gte(e);break;case F.LESS_THAN:i=Ce(s).lt(e);break;case F.LESS_THAN_OR_EQUAL:i=Ce(s).lte(e);break;case F.NOT_EQUAL:i=!Ce(s).eq(e);break}else if(typeof e=="boolean")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.NOT_EQUAL:i=!0;break}return Q.create(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Yn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Yn(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Ce(e).sqrt().toNumber();return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cos(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acos(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acosh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.sin(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asin(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asinh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log10(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.exp(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.abs(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Tn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Tn(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=jn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(jn(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=In(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(In(t,s?1:0)):this}convertToNumberObjectValue(){return this}convertToBooleanObjectValue(){return Ar(!0)}_compareInfinity(e,t,s){let i=!1;switch(s){case F.EQUALS:i=e===t;break;case F.GREATER_THAN:i=e>t;break;case F.GREATER_THAN_OR_EQUAL:i=e>=t;break;case F.LESS_THAN:i=e<t;break;case F.LESS_THAN_OR_EQUAL:i=e<=t;break;case F.NOT_EQUAL:i=e!==t;break}return i}}const ua=2e5,Qn=new pt(ua);class _e extends Ze{constructor(e){super(e);S(this,"_value");this._value=e}static create(e){const t=Qn.get(e);if(t)return t;const s=new _e(e);return Qn.set(e,s),s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):_e.create(this.concatenate(e.getValue(),Te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):_e.create(this.concatenate(e.getValue(),Te.BACK))}compare(e,t){return e.isArray()?e.compare(this,Ls(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Ki(e))return this._checkWildcard(e,t);switch(t){case F.EQUALS:i=s===e;break;case F.GREATER_THAN:i=s>e;break;case F.GREATER_THAN_OR_EQUAL:i=s>=e;break;case F.LESS_THAN:i=s<e;break;case F.LESS_THAN_OR_EQUAL:i=s<=e;break;case F.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case F.NOT_EQUAL:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!0;break;case F.EQUALS:case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.NOT_EQUAL:i=!0;break}return Q.create(i)}convertToNumberObjectValue(){return xr(this.getValue())}convertToBooleanObjectValue(){return Q.create(!0)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=qi(s,e,t);return Q.create(i)}}function Ar(r){if(typeof r=="boolean")return Q.create(r);let n=!1;if(typeof r=="string"){const e=r.toLocaleUpperCase();e===dt.TRUE?n=!0:e===dt.FALSE&&(n=!1)}else r===1?n=!0:n=!1;return Q.create(n)}function an(r){let n=r.toString();return n.charAt(0)==='"'&&n.charAt(n.length-1)==='"'&&(n=n.slice(1,-1),n=n.replace(/""/g,'"')),_e.create(n)}function xr(r){if(typeof r=="boolean"){let n=0;return r&&(n=1),b.create(n)}else{if(typeof r=="number")return Number.isFinite(r)?b.create(r):h.create(f.NUM);if(_.isRealNum(r))return b.create(Number(r))}return h.create(f.VALUE)}function ca(r){return""}function la(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]=st.create(i)}}return n}function fa(r=[]){const n=[];for(let e=0;e<r.length;e++){const t=r[e];n[e]==null&&(n[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i==null?n[e][s]=null:i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class Ae extends Ze{constructor(e){super(typeof e=="string"?e:ca());S(this,"_values",[]);S(this,"_rowCount",-1);S(this,"_columnCount",-1);S(this,"_unitId","");S(this,"_sheetId","");S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_sliceCache",new Map);S(this,"_flattenCache");S(this,"_flattenPosition");this._values=this._formatValue(e)}static create(e){return new Ae(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t==null||t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,t){this._currentRow=e,this._currentColumn=t}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){var u;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let c=t;c<=s;c++)for(let l=i;l<=a;l++)if(e((u=o[c])==null?void 0:u[l],c,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 c=a;c>=i;c--)if(e(o[u][c],u,c)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[ce.create()]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let o=0;o<s;o++){const u=e.get(a,o),c=this.get(a,o);u==null||u.isError()||u.getValue()===!0&&i[0].push(c)}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 c=0;c<this._columnCount;c++){const l=this.get(u,c);if(l==null||l.isError()||l.isNull()){a++;continue}l.isString()?(e.push(l),s.push(a++)):(t.push(l),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,c=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,c=t[2]||1),s>=this._rowCount||o>=this._columnCount)return;const l=`${s}_${i}_${a}_${o}_${u}_${c}`,m=this._sliceCache.get(l);if(m!=null)return m;const d=[],E=this._values;let D=0,C=0;for(let O=s;O<i;O+=a){C=0,d[D]==null&&(d[D]=[]);for(let I=o;I<u;I+=c){if(!E[O])return;let ne=E[O][I];ne==null&&(ne=ce.create()),d[D][C]=ne,C++}D++}if(d.length===0||d[0].length===0)return;const L=a>1?-1:s+this._currentRow,x=c>1?-1:o+this._currentColumn,P=this._createNewArray(d,d.length,d[0].length,L,x);return this._sliceCache.set(l,P),P}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=xe.MIN,s=!1,i=!1){let a,o,u,c;const l=(m,d,E)=>{if(m==null)return!0;let D;if(i===!0?D=m.compare(e,F.EQUALS):D=m.isEqual(e),(D==null?void 0:D.getValue())===!0)return a=m,u={row:d,column:E},!1;t===xe.MAX?m.isGreaterThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,c={row:d,column:E}):t===xe.MIN&&m.isLessThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,c={row:d,column:E})};if(s){const m=this._values.length;if(this._values[0]==null)return;const d=this._values[0].length;for(let E=m-1;E>=0;E--)for(let D=d-1;D>=0;D--){const C=this._values[E][D];l(C,E,D)}}else this.iterator((m,d,E)=>{l(m,d,E)});if(a!=null)return u;if(o!=null)return c}binarySearch(e,t=Ke.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=Ke.MIN){const a=Bn(),o=e.getValue().toString();let u=0,c=t.length-1,l=null;for(;u<=c;){const m=Math.floor((u+c)/2),d=t[m];let E=0;if(d.isNull())E=1;else{const D=d.getValue();E=a(D.toString(),o)}if(E===0)return s[m];E===-1?(u=m+1,i===Ke.MIN&&(l=m)):(c=m-1,i===Ke.MAX&&(l=m))}if(l!=null)return s[l]}sum(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=b.create(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return Ae.create("{0}").minus(this)}getReciprocal(){return Ae.create("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}map(e){const t=(s,i,a)=>s==null?ce.create():s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const u=[];for(let c=0;c<s;c++){const l=(a=this._values)==null?void 0:a[o];if(l==null)u[c]=h.create(f.VALUE);else{const m=l[c];m?u[c]=e(m,o,c):u[c]=ce.create()}}i.push(u)}return this._createNewArray(i,t,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0)||ce.create();if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2)||ce.create(),a=t.get(0,s/2-1)||ce.create();return i.plus(a).divided(b.create(2))}return t.get(0,(s-1)/2)||ce.create()}var(e=0){const t=this.mean(),s=[[]];this.iterator(l=>{if(l==null||l.isError()||l.isString()||l.isBoolean()||l.isNull())return;const m=l.minus(t).pow(b.create(2));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:o,_currentColumn:u}=this;return Ae.create({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:o,column:u}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(t=>t.isError()?t:e.round(t))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(t=>t.isError()?t:e.floor(t))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(t=>t.isError()?t:e.ceil(t))}toValue(){return fa(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=Bn();return(s,i)=>{const a=s[e],o=i[e];return a==null?1:o==null?-1:a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<t;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,t,s){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const c=e.getRowCount(),l=e.getColumnCount();if(a=Math.max(c,a),o=Math.max(l,o),c===1&&l===1){const m=e.getFirstCell();for(let d=0;d<o;d++)i.push(m)}else if(c===1&&this._columnCount>1){const m=e.getArrayValue();for(let d=0;d<o;d++)i.push(m[0][d])}else return this._batchOperatorArray(e,t,s)}else for(let c=0;c<o;c++)i.push(e);const u=[];for(let c=0;c<o;c++){const l=i[c];this._batchOperatorValue(l,c,u,t,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,s,i,a){var E,D;const o=this._rowCount;let u=!1;const c=this.getUnitId(),l=this.getSheetId(),m=this.getCurrentRow(),d=this.getCurrentColumn();if(i===5&&(u=Ne.canUseCache(c,l,t+d,m,m+o-1),u===!0)){if(a===F.EQUALS){const C=Ne.getCellPositions(c,l,t+d,e.getValue());C!=null&&C.forEach(L=>{const x=L-m;s[x]==null&&(s[x]=[]),s[x][t]=Q.create(!0)})}else{const C=Ne.getCellValuePositions(c,l,t+d);C!=null&&C.forEach((L,x)=>{let P=ce.create();typeof x=="string"?P=_e.create(x):typeof x=="number"?P=b.create(x):typeof x=="boolean"&&(P=Q.create(x)),P.compare(e,a).getValue()===!0&&L.forEach(I=>{I>=m&&I<=m+o-1&&(s[I-m]==null&&(s[I-m]=[]),s[I-m][t]=Q.create(!0))})})}return}for(let C=0;C<o;C++){const L=(D=(E=this._values)==null?void 0:E[C])==null?void 0:D[t];if(s[C]==null&&(s[C]=[]),L&&e)if(L.isError())s[C][t]=L;else if(e.isError())s[C][t]=e;else switch(i){case 1:s[C][t]=L.plus(e);break;case 0:s[C][t]=L.minus(e);break;case 2:s[C][t]=L.multiply(e);break;case 3:s[C][t]=L.divided(e);break;case 4:s[C][t]=L.mod(e);break;case 5:a?s[C][t]=L.compare(e,a):s[C][t]=h.create(f.VALUE);break;case 6:s[C][t]=L.concatenateFront(e);break;case 7:s[C][t]=L.concatenateBack(e);break;case 8:s[C][t]=L.pow(e);break;case 9:s[C][t]=L.round(e);break;case 10:s[C][t]=L.floor(e);break;case 12:s[C][t]=L.atan2(e);break;case 11:s[C][t]=L.ceil(e);break}else s[C][t]=h.create(f.NA);L!=null&&(L.isError()?Ne.set(c,l,t+d,L.getErrorType(),C+m):L.isNull()?Ne.set(c,l,t+d,null,C+m):Ne.set(c,l,t+d,L.getValue(),C+m))}Ne.setContinueBuildingCache(c,l,t+d,m,m+o-1)}_batchOperatorArray(e,t,s){var m,d,E,D,C,L,x,P,O,I,ne,le;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),c=this._checkArrayCalculateType(this),l=this._checkArrayCalculateType(e);for(let fe=0;fe<i;fe++){const q=[];for(let Y=0;Y<a;Y++){let N;c===3?N=(d=(m=this._values)==null?void 0:m[0])==null?void 0:d[0]:c===1?N=(D=(E=this._values)==null?void 0:E[0])==null?void 0:D[Y]:c===2?N=(L=(C=this._values)==null?void 0:C[fe])==null?void 0:L[0]:N=(P=(x=this._values)==null?void 0:x[fe])==null?void 0:P[Y];let Z;if(l===3?Z=(O=u==null?void 0:u[0])==null?void 0:O[0]:l===1?Z=(I=u==null?void 0:u[0])==null?void 0:I[Y]:l===2?Z=(ne=u==null?void 0:u[fe])==null?void 0:ne[0]:Z=(le=u==null?void 0:u[fe])==null?void 0:le[Y],N&&Z)if(N.isError())q[Y]=N;else if(Z.isError())q[Y]=Z;else switch(t){case 1:q[Y]=N.plus(Z);break;case 0:q[Y]=N.minus(Z);break;case 2:q[Y]=N.multiply(Z);break;case 3:q[Y]=N.divided(Z);break;case 4:q[Y]=N.mod(Z);break;case 5:s?q[Y]=N.compare(Z,s):q[Y]=h.create(f.VALUE);break;case 6:q[Y]=N.concatenateFront(Z);break;case 7:q[Y]=N.concatenateBack(Z);break;case 8:q[Y]=N.pow(Z);break;case 9:q[Y]=N.round(Z);break;case 12:q[Y]=N.atan2(Z);break;case 10:q[Y]=N.floor(Z);break;case 11:q[Y]=N.ceil(Z);break}else q[Y]=h.create(f.NA)}o.push(q)}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 c=t[o].split(","),l=c.length;a<l&&(a=l);const m=[];for(let d=0;d<l;d++){const E=c[d].trim();m.push(st.create(E))}i.push(m)}return this._rowCount=s,this._columnCount=a,i}_createNewArray(e,t,s,i=-1,a=-1){(this._currentColumn===-1||this._currentRow===-1)&&(i=-1,a=-1);const o={calculateValueList:e,rowCount:t,columnCount:s,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:i,column:a};return Ae.create(o)}}class st{static create(n){if(n==null)return ce.create();if(typeof n=="boolean")return Q.create(n);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return zt.has(e)?h.create(e):e===dt.TRUE||e===dt.FALSE?Ar(n):_.isRealNum(n)?b.create(Number(n)):new RegExp(Oi,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?Ae.create(n.replace(/\n/g,"").replace(/\r/g,"")):an(n)}return typeof n=="number"?xr(n):h.create(f.VALUE)}}function ha(r){if(r===null)return 0;if(r!=null&&r.p){const n=r==null?void 0:r.p.body;if(n==null)return 0;const e=n.dataStream;return e.substring(e.length-2,e.length)===_.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(r==null?void 0:r.v)||0}const ma=1e5,Qr=new pt(ma);class Vt extends Sr{constructor(e){super();S(this,"_forcedSheetId","");S(this,"_forcedSheetName","");S(this,"_defaultSheetId","");S(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});S(this,"_unitData",{});S(this,"_defaultUnitId","");S(this,"_forcedUnitId","");S(this,"_runtimeData",{});S(this,"_arrayFormulaCellData",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeFeatureCellData",{});S(this,"_numfmtItemData",{});S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}getToken(){return this._token}setToken(e){this._token=e}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getRowCount()||i>=this.getColumnCount()}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return Number.isNaN(e)&&(e=0),Number.isNaN(s)&&(s=0),Number.isNaN(t)&&(t=this.getRowCount()-1),Number.isNaN(i)&&(i=this.getColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var c,l,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(h.create(f.VALUE),t,i);const o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId;for(let d=t;d<=s;d++)for(let E=i;E<=a;E++){if(d<0||E<0)return e(h.create(f.REF),d,E);const D=this.getCellData(d,E);let C=!1;if(D==null||_.isNullCell(D)){C=e(null,d,E);continue}const L=this.getCellValueObject(D),x=L.isNumber(),P=(m=(l=(c=this._numfmtItemData[o])==null?void 0:c[u])==null?void 0:l[d])==null?void 0:m[E];if(P&&x&&L.setPattern(P),C=e(L,d,E),C===!1)return}}getFirstCell(){var l,m,d;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return b.create(0);const i=this.getCellValueObject(s),a=i.isNumber(),o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,c=(d=(m=(l=this._numfmtItemData[o])==null?void 0:l[u])==null?void 0:m[e])==null?void 0:d[t];return c&&a&&i.setPattern(c),i}getRangeData(){return this._rangeData}setRangeData(e){this._rangeData=e}getUnitId(){return this._forcedUnitId&&this._forcedUnitId.length>0?this._forcedUnitId:this._defaultUnitId}getSheetId(){return this._forcedSheetId&&this._forcedSheetId.length>0?this._forcedSheetId:this._defaultSheetId}setForcedUnitIdDirect(e){e.length>0&&(this._forcedUnitId=e)}getForcedUnitId(){return this._forcedUnitId}setForcedSheetId(e){var t;this._forcedSheetId=(t=e[this.getUnitId()])==null?void 0:t[this._forcedSheetName]}setForcedSheetIdDirect(e){this._forcedSheetId=e}getForcedSheetId(){return this._forcedSheetId}setForcedSheetName(e){e.length>0&&(this._forcedSheetName=e)}getForcedSheetName(){return this._forcedSheetName}setDefaultSheetId(e){this._defaultSheetId=e}getDefaultSheetId(){return this._defaultSheetId}setDefaultUnitId(e){this._defaultUnitId=e}getDefaultUnitId(){return this._defaultUnitId}getUnitData(){return this._unitData}setUnitData(e){this._unitData=e}getRuntimeData(){return this._runtimeData}setRuntimeData(e){this._runtimeData=e}getArrayFormulaCellData(){return this._arrayFormulaCellData}setArrayFormulaCellData(e){this._arrayFormulaCellData=e}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}setRuntimeArrayFormulaCellData(e){this._runtimeArrayFormulaCellData=e}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e){this._runtimeFeatureCellData=e}getNumfmtItemData(){return this._numfmtItemData}setNumfmtItemData(e){this._numfmtItemData=e}getRowCount(){return this.getCurrentActiveSheetData().rowCount}getColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return h.create(f.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=ha(e);return zt.has(t)?h.create(t):e.t===_.CellValueType.NUMBER?xr(t):e.t===_.CellValueType.STRING||e.t===_.CellValueType.FORCE_STRING?an(t):e.t===_.CellValueType.BOOLEAN?Ar(t):st.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 c=u.getValue(e,t);if(c!=null)return c}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):h.create(f.VALUE)}toArrayValueObject(e=!0){var D;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,u=Qr.get(o);if(u&&e)return u;const c=s-t+1,l=a-i+1;if(c<0||l<0)return this._getBlankArrayValueObject();const m=new Array(c);this.iterator((C,L,x)=>{const P=L-t,O=x-i;m[P]||(m[P]=new Array(l)),C==null&&(C=ce.create()),m[P][O]=C});const d={calculateValueList:m,rowCount:m.length,columnCount:((D=m[0])==null?void 0:D.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},E=Ae.create(d);return e&&Qr.set(o,E),E}toUnitRange(){return{range:this.getRangePosition(),sheetId:this.getSheetId(),unitId:this.getUnitId()}}_checkIfWorksheetMiss(){return(this._forcedSheetId==null||this._forcedSheetId.length===0)&&this._forcedSheetName.length>0}_getBlankArrayValueObject(){const e={calculateValueList:[],rowCount:0,columnCount:0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:0,column:0};return Ae.create(e)}}class da extends Sr{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class ga extends Sr{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 Ae.create(e)}}class $t extends Vt{constructor(n,e,t){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const Hn=/[\[\]]/g;function Wn(r,n){if(Hn.test(r)){const e=Number(r.replace(Hn,""));return n+e}return Number(r)-1}function Ur(r,n=0,e=0){r=r.toLocaleUpperCase();const t=r.split(/[RC]/),s=t[1],i=t[2],a=Wn(s,n),o=Wn(i,e);return{row:a,column:o,absoluteRefType:_.AbsoluteRefType.NONE}}function As(r,n=0,e=0){const{refBody:t,sheetName:s,unitId:i}=Rs(r),a=t.indexOf(":");if(a===-1){const C=Ur(t,n,e),L=C.row,x=C.column,P=C.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:L,startColumn:x,endRow:L,endColumn:x,startAbsoluteRefType:P,endAbsoluteRefType:P}}}const o=t.substring(0,a),u=t.substring(a+1),c=Ur(o,n,e),l=Ur(u,n,e),m=c.row,d=c.column,E=l.row,D=l.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:d,endRow:E,endColumn:D,startAbsoluteRefType:c.absoluteRefType,endAbsoluteRefType:l.absoluteRefType}}}function pa(r){const n=Zt(r.startRow,r.startAbsoluteRefType,!0),e=Zt(r.startColumn,r.startAbsoluteRefType,!1),t=Zt(r.endRow,r.endAbsoluteRefType,!0),s=Zt(r.endColumn,r.endAbsoluteRefType,!1);return n===t&&e===s?`R${n}C${e}`:`R${n}C${e}:R${t}C${s}`}function Zt(r,n=_.AbsoluteRefType.ALL,e){switch(r+=1,n){case _.AbsoluteRefType.ALL:return`${r}`;case _.AbsoluteRefType.ROW:return e?`${r}`:`[${r}]`;case _.AbsoluteRefType.COLUMN:return e?`[${r}]`:`${r}`;case _.AbsoluteRefType.NONE:return`[${r}]`}}const xs=[];var Ra=(r=>{})();function _a(r){const n=r.getValue();let e=0;return n&&(e=1),b.create(e)}function pe(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 c=[];for(let l=0;l<n;l++)c.push(o);s.push(c)}}else if(i===1&&a>1)for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(0,c)||(t!=null?t:ce.create());u.push(l)}s.push(u)}else if(a===1&&i>1)for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(o,0)||(t!=null?t:ce.create());u.push(l)}s.push(u)}else for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(o,c)||(t!=null?t:ce.create());u.push(l)}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 fr(s,r,n)}function fr(r,n,e){const t={calculateValueList:r,rowCount:n,columnCount:e,unitId:"",sheetId:"",row:-1,column:-1};return Ae.create(t)}class on extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return h.create(f.REF);const e=n,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(n,e){const t=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(o.startRow=i,o.endRow=t):(o.startRow=t,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new $t(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 un extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(n){if(!n.isRow())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this.setToken(`${this.getToken()}${G.COLON}${e.getToken()}`),this}}class cn extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this.setToken(`${this.getToken()}${G.COLON}${e.getToken()}`),this}}class j extends _.Disposable{constructor(e){super();S(this,"_unitId");S(this,"_subUnitId");S(this,"_row",-1);S(this,"_column",-1);S(this,"needsExpandParams",!1);S(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return h.create(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?h.create(f.VALUE):t;if(e.isString()){const s=Number(e.getValue());return Number.isNaN(s)?h.create(f.REF):s}else if(e.isNumber())return e.getValue();return h.create(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return h.create(f.NA);let o;return s.getRowCount()===1?o=s.get(0,a)||ce.create():o=s.get(a,0)||ce.create(),o.isNull()?h.create(f.NA):o}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,F.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}orderSearch(e,t,s,i=xe.MIN,a=!1){const o=t.orderSearch(e,i,a);if(o==null)return h.create(f.NA);const u=s.get(o.row,o.column)||ce.create();return u.isNull()?h.create(f.NA):u}binarySearchExpand(e,t,s,i=0,a){const o=t.binarySearch(e,a);return o==null?h.create(f.NA):i===0?s.slice([o,o+1]):s.slice(void 0,[o,o+1])}equalSearchExpand(e,t,s,i=!0,a=0){const o=t.isEqual(e);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const o=t.compare(e,F.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,t,s,i=xe.MIN,a=!1,o=0){const u=t.orderSearch(e,i,a);return u==null?h.create(f.NA):o===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if((a.isString()||a.isBoolean()||a.isNull())&&(a=a.convertToNumberObjectValue()),a.isError())return a;if(a.isArray()){let o;if(a.iterator(u=>{if(u==null||u.isNull()||t&&(u.isString()||u.isBoolean()))return!0;if(u=this._includingLogicalValuesAndText(u),u.isError())return o=u,!1;s[0].push(u)}),o!=null&&o.isError())return o}else s[0].push(a)}return fr(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=_a(e)),e.isString()){const t=Number(e.getValue());e=b.create(Number.isNaN(t)?0:t)}return e}createReferenceObject(e,t){const s=e.getForcedUnitId(),i=e.getForcedSheetId()||"",a=e.getForcedSheetName(),u=bt({unitId:s,sheetName:a,range:t});let c;return new RegExp(Qt).test(u)?c=new on(u):new RegExp(ls).test(u)?c=new un(u):new RegExp(fs).test(u)?c=new cn(u):c=new $t(t,i,s),this._setReferenceDefault(e,c)}_setReferenceDefault(e,t){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(t.setDefaultUnitId(this.unitId),t.setDefaultSheetId(this.subUnitId),t.setUnitData(e.getUnitData()),t.setRuntimeData(e.getRuntimeData()),t.setArrayFormulaCellData(e.getArrayFormulaCellData()),t.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),t)}}class ws extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std()}}class Ps extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std(1)}}class Vs extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var()}}class vs extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var(1)}}var Ct=(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))(Ct||{});const Ms=[[Ps,Ct.STDEV],[ws,Ct.STDEVP],[vs,Ct.VAR],[Vs,Ct.VARP]],Bs=[];var Fs=(r=>(r.CUBEKPIMEMBER="CUBEKPIMEMBER",r.CUBEMEMBER="CUBEMEMBER",r.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",r.CUBERANKEDMEMBER="CUBERANKEDMEMBER",r.CUBESET="CUBESET",r.CUBESETCOUNT="CUBESETCOUNT",r.CUBEVALUE="CUBEVALUE",r))(Fs||{});const Os=[];var Us=(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))(Us||{});const ln="yyyy/mm/dd;@";function fn(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 wr(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 hn(r){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(r))return!1;const e=r.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),o=`${s}-${i}-${a}`;return r.replace(/\//g,"-").split("-").map(c=>c.padStart(2,"0")).join("-")===o}class Ea extends j{calculate(n,e,t){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t.isError())return t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=pe(s,i,n),o=pe(s,i,e),u=pe(s,i,t);return a.map((c,l,m)=>{const d=o.get(l,m)||ce.create(),E=u.get(l,m)||ce.create();if(c.isError())return c;if(d.isError())return d;if(E.isError())return E;if(c.isString()||d.isString()||E.isString())return h.create(f.VALUE);let D=+c.getValue();const C=Math.floor(+d.getValue()),L=+E.getValue();if(D<0||D>9999)return h.create(f.NUM);D>=0&&D<1899&&(D+=1900);const x=new Date(D,C-1,L),P=fn(x);if(P<0)return h.create(f.NUM);const O=b.create(P);return O.setPattern(ln),O})}}class Ca extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!hn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(0);e=wr(a)}const s=e.getDate();return b.create(s)}}class Da extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=pe(t,s,n),a=pe(t,s,e);return i.map((o,u,c)=>{const l=a.get(u,c)||ce.create();if(o.isError())return o;if(l.isError())return l;if(o.isString()||o.isBoolean()||l.isString()||l.isBoolean())return h.create(f.VALUE);const m=+o.getValue();if(m<0)return h.create(f.NUM);const d=Math.floor(+l.getValue()),E=wr(m),D=E.getUTCFullYear(),C=E.getUTCMonth()+d,L=E.getUTCDate(),x=new Date(Date.UTC(D,C,L)),P=fn(x),O=b.create(P);return O.setPattern(ln),O})}}var et=(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))(et||{});class ya extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!hn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(1);e=wr(a)}const s=e.getUTCMonth()+1;return b.create(s)}}class ba extends j{calculate(n){if(n)return h.create(f.NA);const e=fn(new Date),t=b.create(e);return t.setPattern(ln),t}}class Sa extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!hn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return h.create(f.NUM);if(a===0)return b.create(1900);e=wr(a)}const s=e.getUTCFullYear();return b.create(s)}}const ks=[[Ea,et.DATE],[Ca,et.DAY],[Da,et.EDATE],[ya,et.MONTH],[ba,et.TODAY],[Sa,et.YEAR]],Ts=[];var js=(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))(js||{});const Is=[];var $s=(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))($s||{}),ke=(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))(ke||{});class La extends j{calculate(n){return n==null?h.create(f.NA):n.isNull()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isNull()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Aa extends j{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?Q.create(!1):n.isError()?Q.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?Q.create(!1):e.isError()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class xa extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isError()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class wa extends j{calculate(n){return n==null?h.create(f.NA):n.isBoolean()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isBoolean()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Pa extends j{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?Q.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Va extends j{calculate(n){return n==null?h.create(f.NA):!n.isArray()&&!n.isString()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isString()?Q.create(!1):Q.create(!0)):Q.create(!1)}}class va extends j{calculate(n){return n==null?h.create(f.NA):n.isNumber()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isNumber()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Ma extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e){return e==null?h.create(f.NA):e.isReferenceObject()?Q.create(!0):Q.create(!1)}}class Ba extends j{calculate(n){return n==null?h.create(f.NA):n.isString()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isString()?Q.create(!0):Q.create(!1)):Q.create(!1)}}const Ys=[[La,ke.ISBLANK],[Aa,ke.ISERR],[xa,ke.ISERROR],[wa,ke.ISLOGICAL],[Pa,ke.ISNA],[Va,ke.ISNONTEXT],[va,ke.ISNUMBER],[Ma,ke.ISREF],[Ba,ke.ISTEXT]];class Fa extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=!0,t=!0,s=null;for(const i of n){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e&&!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?h.create(f.VALUE):Q.create(e)}}var tt=(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))(tt||{});class Oa extends j{calculate(n,e,t=Q.create(!1)){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(n=this._getSingleValueObject(n),!n.isArray())return n.getValue()?e:t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=pe(s,i,n),o=pe(s,i,e,h.create(f.NA)),u=pe(s,i,t,h.create(f.NA));return a.map((c,l,m)=>{if(c.isNull())return h.create(f.NA);{const d=o.get(l,m)||ce.create(),E=u.get(l,m)||ce.create();return this._calculateSingleCell(c,d,E)}})}_getSingleValueObject(n){return n.isArray()&&n.getRowCount()===1&&n.getColumnCount()===1?n.getFirstCell():n}_calculateSingleCell(n,e,t){return n.isNull()?h.create(f.NA):n.getValue()?e.isNull()?h.create(f.NA):e:t.isNull()?h.create(f.NA):t}}class Ua extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(!n.isArray())return n.isError()?e:n;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=pe(t,s,n),a=pe(t,s,e);return i.iterator((o,u,c)=>{o!=null&&o.isError()&&i.set(u,c,a.get(u,c))}),i}}class ka extends j{calculate(...n){return h.create(f.VALUE)}}class Ta extends j{calculate(...n){if(n.length!==3)return h.create(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(n[1]);if(typeof t!="number")return t;if(!(n[2].isValueObject()&&n[2].isLambda()))return h.create(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<t;o++){const u=s.execute(b.create(a+1),b.create(o+1));i[a][o]=u}}return new ga(i)}isAsync(){return!0}}class ja extends j{calculate(...n){if(n.length===0)return new h(f.NA);let e=!1,t=!0,s=null;for(const i of n){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e||!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e||!!i.getValue(),t=!1)}return t?new h(f.VALUE):new Q(e)}}const zs=[[Fa,tt.AND],[Oa,tt.IF],[ka,tt.LAMBDA],[Ta,tt.MAKEARRAY],[ja,tt.OR],[Ua,tt.IFERROR]];class Ia extends j{calculate(n,e,t,s,i){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return h.create(f.VALUE);const u=t?$a(t.getValue()):_.AbsoluteRefType.ALL,c=this.getZeroOrOneByOneDefault(s),l=i?`${i.getValue()}`:"",m=ur(l)?`'${l}'`:l,d={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},E=s&&!c?pa(d):mt(d);return _e.create(m!==""?`${m}!${E}`:E)}}function $a(r){switch(r){case 1:return _.AbsoluteRefType.ALL;case 2:return _.AbsoluteRefType.ROW;case 3:return _.AbsoluteRefType.COLUMN;case 4:return _.AbsoluteRefType.NONE;default:return _.AbsoluteRefType.ALL}}class Ya extends j{calculate(n){if(n==null)return b.create(this.column+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentColumn(),t=n.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(b.create(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Ae.create(i)}}class za extends j{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getColumnCount();return b.create(e)}}var be=(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))(be||{});class Qa extends j{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray()||t.isError()||s!=null&&s.isError())return h.create(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return h.create(f.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?h.create(f.REF):n.isArray()?n.map(c=>this._handleSingleObject(c,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 Ha extends j{calculate(n,e){if(n==null)return h.create(f.NA);if(n.isError())return n;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),n.isArray()){const l=n;if(l.getRowCount()===1&&l.getColumnCount()===1)n=l.getFirstCell();else return l.map(()=>h.create(f.VALUE))}if(!n.isString())return h.create(f.REF);const s=n.getValue();if(t===0){const l=As(s),{range:m,sheetName:d,unitId:E}=l,D=new $t(m);return D.setForcedUnitIdDirect(E),D.setForcedSheetName(d),this._setDefault(D)}if(new RegExp(Qt).test(s))return this._setDefault(new on(s));if(new RegExp(us).test(s))return this._setDefault(new un(s));if(new RegExp(cs).test(s))return this._setDefault(new cn(s));const i=wt(s),{range:a,sheetName:o,unitId:u}=i,c=new $t(a);return c.setForcedUnitIdDirect(u),c.setForcedSheetName(o),this._setDefault(c)}_setDefault(n){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class Wa extends j{constructor(){super(...arguments);S(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?h.create(f.NA):e.isError()?e:t.isError()?h.create(f.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?h.create(f.REF):this._handleVector(e,t,s):this._handleArray(e,t):h.create(f.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return h.create(f.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,o;return i>s?(a=t.slice([0,1]),o=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),o=t.slice(void 0,[i-1,i])),a==null||o==null?h.create(f.VALUE):e.isArray()?e.map(u=>this.binarySearch(u,a,o)):this.binarySearch(e,a,o)}}class Ga extends j{calculate(n,e,t){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1||t!=null&&t.isError())return h.create(f.NA);const a=this.getMatchTypeValue(t);return a==null?h.create(f.VALUE):n.isArray()?n.map(o=>this._handleSingleObject(o,e,a)):this._handleSingleObject(n,e,a)}_handleSingleObject(n,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(n,s);if(i==null)return h.create(f.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return b.create(a)}_getSearchModeValue(n){switch(n){case 1:return xe.MIN;case 0:return xe.NORMAL;case-1:return xe.MAX}}}class Xa extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i,a){var Y,N;const o=e;if(o==null||t==null||s==null)return h.create(f.NA);if(o.isError())return o;if(t.isError())return t;if(s.isError())return s;if(i!=null&&i.isError())return i;if(a!=null&&a.isError())return a;if(!o.isReferenceObject())return h.create(f.VALUE);const{startRow:u,endRow:c,startColumn:l,endColumn:m}=o.getRangeData();t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject());const d=this.getIndexNumValue(t),E=this.getIndexNumValue(s);if(typeof d!="number"||typeof E!="number")return h.create(f.VALUE);const D=u+d,C=l+E;if(D<0||C<0)return h.create(f.REF);i!=null&&i.isReferenceObject()&&(i=i.toArrayValueObject()),a!=null&&a.isReferenceObject()&&(a=a.toArrayValueObject());const L=(Y=i&&this.getIndexNumValue(i))!=null?Y:1,x=(N=a&&this.getIndexNumValue(a))!=null?N:1;if(typeof L!="number"||typeof x!="number")return h.create(f.VALUE);if(L===0||x===0)return h.create(f.REF);const P=L>0?D+L-1:D+L+1,O=x>0?C+x-1:C+x+1;if(P<0||O<0)return h.create(f.REF);const I=D<P?D:P,ne=C<O?C:O,le=D>P?D:P,fe=C>O?C:O,q={startRow:I,startColumn:ne,endRow:le,endColumn:fe};return this.createReferenceObject(o,q)}}class Ka extends j{calculate(n){if(n==null)return b.create(this.row+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentRow(),t=n.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([b.create(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Ae.create(i)}}class qa extends j{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getRowCount();return b.create(e)}}class Za extends j{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);if(t.isError()||s!=null&&s.isError())return h.create(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return h.create(f.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const o=e.slice(void 0,[0,1]),u=e.slice(void 0,[a-1,a]);return o==null||u==null?h.create(f.VALUE):n.isArray()?n.map(c=>this._handleSingleObject(c,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 Ja extends j{calculate(n,e,t,s,i,a){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==1)return h.create(f.VALUE);if(t.isError())return h.create(f.REF);if(!t.isArray())return h.create(f.VALUE);const c=t.getRowCount(),l=t.getColumnCount();if(o!==c&&u!==l)return h.create(f.VALUE);if(s!=null&&s.isError()||i!=null&&i.isError()||a!=null&&a.isError())return h.create(f.NA);s==null&&(s=h.create(f.NA));const m=this.getIndexNumValue(i||b.create(0));if(m instanceof h)return m;const d=this.getIndexNumValue(a||b.create(1));if(d instanceof h)return d;if(n.isArray()){let C;return o===1?C=t.slice([0,1]):C=t.slice(void 0,[0,1]),C==null?h.create(f.NA):n.map(L=>{const x=this._handleSingleObject(L,e,C,m,d);return x.isError()?s:x})}if(u===l&&o===c){const C=this._handleSingleObject(n,e,t,m,d);return C.isError()?s:C}let E=0;u===l&&(E=1);const D=this._handleExpandObject(n,e,t,m,d,E);return D==null?h.create(f.NA):D}_handleExpandObject(n,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(n,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(n,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(n,e,t,s===1?xe.MAX:xe.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?xe.MAX:xe.MIN,i===-1):this.equalSearch(n,e,t,i!==-1)}_getSearchModeValue(n){return n===-2?Ke.MAX:Ke.MIN}}class Na extends j{calculate(n,e,t,s){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return h.create(f.VALUE);if(t!=null&&t.isError()||s!=null&&s.isError())return h.create(f.NA);const o=this.getIndexNumValue(t||b.create(0));if(o instanceof h)return o;const u=this.getIndexNumValue(s||b.create(1));return u instanceof h?u:n.isArray()?n.map(c=>this._handleSingleObject(c,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,F.EQUALS);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}else if(t===-1||t===1){const a=e.orderSearch(n,t===1?xe.MAX:xe.MIN,s===-1);if(a==null)return h.create(f.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(n);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}return i==null?h.create(f.NA):b.create(i+1)}_getSearchModeValue(n){return n===-2?Ke.MAX:Ke.MIN}}class eo extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i){const a=e;if(a==null)return h.create(f.NA);if(a.isError())return a;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;if(!a.isRange())return h.create(f.REF);const{startRow:o,endRow:u,startColumn:c,endColumn:l}=a.getRangeData(),m=u-o+1,d=l-c+1;m===1&&d>1&&s==null?(s=t!=null?t:b.create(0),t=b.create(0)):(t=t!=null?t:b.create(0),s=s!=null?s:b.create(0)),i=i!=null?i:b.create(1),t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject()),i.isReferenceObject()&&(i=i.toArrayValueObject());const E=Math.max(t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1,i.isArray()?i.getRowCount():1),D=Math.max(t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1,i.isArray()?i.getColumnCount():1);if(E===1&&D===1)return this._calculateSingleCell(a,t,s,i);{const C=pe(E,D,t,h.create(f.NA)),L=pe(E,D,s,h.create(f.NA)),x=pe(E,D,i,h.create(f.NA));return C.map((P,O,I)=>{const ne=L.get(O,I)||ce.create(),le=x.get(O,I)||ce.create(),fe=this._calculateSingleCell(a,P,ne,le);return fe.isReferenceObject()?fe.toArrayValueObject().getFirstCell():fe})}}_calculateSingleCell(e,t,s,i){if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return h.create(f.VALUE);if(s.isError())return s;const o=this._getNumberValue(s);if(o===void 0||o<0)return h.create(f.VALUE);if(i.isError())return i;const u=this._getAreaNumberValue(i);return u===void 0||u<1?h.create(f.VALUE):this._getReferenceObject(e,a,o,u)}_getNumberValue(e){if(e==null)return 0;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getAreaNumberValue(e){if(e==null)return 1;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getReferenceObject(e,t,s,i){const{startRow:a,endRow:o,startColumn:u,endColumn:c}=e.getRangeData();let l=0,m=0,d=0,E=0;if(t===0?(l=a,m=o):l=m=a+t-1,s===0?(d=u,E=c):d=E=u+s-1,l>o||d>c)return h.create(f.REF);const D={startRow:l,startColumn:d,endRow:m,endColumn:E};return this.createReferenceObject(e,D)}}const Qs=[[Ia,be.ADDRESS],[Ya,be.COLUMN],[za,be.COLUMNS],[eo,be.INDEX],[Ha,be.INDIRECT],[Xa,be.OFFSET],[Ka,be.ROW],[qa,be.ROWS],[Za,be.VLOOKUP],[Wa,be.LOOKUP],[Ga,be.MATCH],[Qa,be.HLOOKUP],[Ja,be.XLOOKUP],[Na,be.XMATCH]];class to extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.abs())}}class ro extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?new h(f.VALUE):n.acos())}}class no extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.acosh())}}class so extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:n.isArray()?n.map(e=>e.isError()?e:Gn(e)):Gn(n))}}function Gn(r){let n=r.getValue();if(r.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return h.create(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?h.create(f.VALUE):b.create(e)}var we=(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))(we||{});class io extends j{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.mod(e)))}}class ao extends j{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.pow(e)))}}class oo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(1);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=this._multiplyArray(s)),s.isError())return s;if(e=e.multiply(s),e.isError())return e}}return e}_multiplyArray(n){let e=b.create(1);return n.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class uo extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return h.create(f.NA);if(e.isError())return e;if(t.length===0)return h.create(f.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,o)=>{s[a]==null&&(s[a]=[]),s[a][o]=this._handleSingleObject(i,...t)}),fr(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=h.create(f.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(Number.isNaN(t))return h.create(f.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:h.create(f.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=b.create(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();a.iterator((u,c)=>{if(e&&this._isRowHidden(o,c)||u==null||u.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return b.create(0);let i=b.create(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();let u;if(a.iterator((c,l)=>{if(e&&this._isRowHidden(o,l)||c==null||c.isNull()||c.isString()||c.isBoolean())return!0;if(c.isError())return u=c,!1;s[0].push(c)}),u!=null&&u.isError())return u}return fr(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===_.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class co extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isError())return s;if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function lo(r){const n=[F.EQUALS,F.NOT_EQUAL,F.GREATER_THAN_OR_EQUAL,F.GREATER_THAN,F.LESS_THAN_OR_EQUAL,F.LESS_THAN];for(const e of n)if(r.startsWith(e)){const t=r.substring(e.length);return[e,st.create(t)]}return[F.EQUALS,st.create(r)]}function Hs(r,n,e){if(!e)if(n.isString()){const t=`${n.getValue()}`,[s,i]=lo(t);e=s,n=i}else e=F.EQUALS;return r.compare(n,e)}function fo(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=pe(e,t,r),i=pe(e,t,n);return s.mapValue((a,o,u)=>{const c=i.get(o,u);return a!=null&&a.isError()?a:c!=null&&c.isError()?c:a!=null&&a.isBoolean()&&(c!=null&&c.isBoolean())?Ar(a.getValue()&&c.getValue()):Q.create(!1)})}class ho extends j{calculate(n,e,t){return n==null||e==null||n.isError()||e.isError()||t!=null&&t.isError()?h.create(f.NA):!n.isArray()||t&&!t.isArray()?h.create(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,t)):this._handleSingleObject(n,e,t)}_handleSingleObject(n,e,t){const s=Hs(n,e),i=t?t.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():h.create(f.VALUE)}}class mo extends j{calculate(n,...e){if(n==null||e.length<2||n.isError())return h.create(f.NA);if(!n.isArray()||e.length<2||e.length%2!==0||e.some((l,m)=>m%2===0&&!l.isArray()))return h.create(f.VALUE);const t=n.getRowCount(),s=n.getColumnCount();let i=0,a=0;e.forEach((l,m)=>{if(m%2===1)if(l.isArray()){const d=l;i=Math.max(i,d.getRowCount()),a=Math.max(a,d.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const o=[];for(let l=0;l<e.length;l++){if(l%2===1)continue;const m=e[l],d=m.getRowCount(),E=m.getColumnCount();if(d!==t||E!==s)return pe(i,a,h.create(f.NA));const D=e[l+1];pe(i,a,D,h.create(f.NA)).iterator((L,x,P)=>{if(!L)return;const O=Hs(m,L);if(o[x]===void 0&&(o[x]=[]),o[x][P]===void 0){o[x][P]=O;return}o[x][P]=fo(o[x][P],O)})}const u=o.map(l=>l.map(m=>n.pick(m).sum())),c={calculateValueList:u,rowCount:u.length,columnCount:u[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Ae.create(c)}}const Ws=[[to,we.ABS],[ro,we.ACOS],[no,we.ACOSH],[so,we.ACOT],[io,we.MOD],[uo,we.SUBTOTAL],[co,we.SUM],[ho,we.SUMIF],[mo,we.SUMIFS],[ao,we.POWER],[oo,we.PRODUCT]];class go extends j{constructor(){super(...arguments);S(this,"_compareType",F.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()?e:t.isError()?t:e.compare(t,this._compareType)}}class mn extends Ze{constructor(e){super("");S(this,"_values",[]);this._values=e}static create(e){return new mn(e)}isCube(){return!0}sum(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.sum())}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isLessThan(s)&&(e=s)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isGreaterThan(s)&&(e=s)}),e}count(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.count())}),e}countA(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countA())}),e}countBlank(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countBlank())}),e}}class po extends j{calculate(...n){if(n.length===0)return h.create(f.VALUE);const e=[];for(let t=0;t<n.length;t++){const s=n[t];if(s.isError())return s;if(!s.isArray())return h.create(f.VALUE);e.push(s)}return mn.create(e)}}class Ro extends j{calculate(n,e){return n.isError()?n:e.isError()?e:!e.isArray()&&e.getValue()===0?h.create(f.DIV_BY_ZERO):n.divided(e)}}var Le=(r=>(r.COMPARE="COMPARE",r.DIVIDED="DIVIDED",r.MINUS="MINUS",r.MULTIPLY="MULTIPLY",r.PLUS="PLUS",r.UNION="UNION",r.CUBE="CUBE",r))(Le||{});class _o extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.minus(e)}}class Eo extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class Co extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const Gs=[[go,Le.COMPARE],[Ro,Le.DIVIDED],[_o,Le.MINUS],[Eo,Le.MULTIPLY],[Co,Le.PLUS],[po,Le.CUBE]];class Do extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0),t=b.create(0);for(let s=0;s<n.length;s++){let i=n[s];if(i.isString()&&(i=i.convertToNumberObjectValue()),i.isError())return i;if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(i),t=t.plus(b.create(1)))}return e.divided(t)}}class yo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){const s=n[t];s.isError()||(s.isArray()?e=e.plus(s.count()):s.isString()?s.convertToNumberObjectValue().isError()||(e=e.plus(b.create(1))):s.isNull()||(e=e.plus(b.create(1))))}return e}}class bo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError()){e=e.plus(b.create(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(b.create(1)))}return e}}var Se=(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))(Se||{});class So extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.NEGATIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.max()),s.isError())return s;e=this._validator(e,s)}}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class Xn extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.POSITIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.min()),s.isError())return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}class Lo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std(1)}}class Ao extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std()}}class xo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var(1)}}class wo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var()}}const Xs=[[Do,Se.AVERAGE],[yo,Se.COUNT],[So,Se.MAX],[Xn,Se.MIN],[Xn,Se.MIN],[bo,Se.COUNTA],[ws,Se.STDEV_P],[Ps,Se.STDEV_S],[Lo,Se.STDEVA],[Ao,Se.STDEVPA],[Vs,Se.VAR_P],[vs,Se.VAR_S],[xo,Se.VARA],[wo,Se.VARPA]];class Po extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=0,t=0;n.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of n)s=pe(e,t,i,h.create(f.NA)).mapValue((o,u,c)=>{var E,D;const l=s&&s.get(u,c);if(l!=null&&l.isError())return l;if(o.isError())return o;const m=l!=null&&l.isNull()?"":(E=l==null?void 0:l.getValue())!=null?E:"",d=o!=null&&o.isNull()?"":(D=o==null?void 0:o.getValue())!=null?D:"";return an(`${m}${d}`)});return s||h.create(f.VALUE)}}var ht=(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))(ht||{});class Vo extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString();return b.create(e.length)}return h.create(f.VALUE)}}function vo(r){let n=0;for(let e=0;e<r.length;e++){const t=r.charCodeAt(e);t>=12352&&t<=12543||t>=19968&&t<=40959||t>=44032&&t<=55215?n+=2:n+=1}return n}class Mo extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString(),t=vo(e);return b.create(t)}return h.create(f.VALUE)}}var Bo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Fo(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Ks={exports:{}};(function(r,n){(function(e,t){r.exports=t()})(typeof self<"u"?self:Bo,function(){return function(){var e={d:function(p,g){for(var R in g)e.o(g,R)&&!e.o(p,R)&&Object.defineProperty(p,R,{enumerable:!0,get:g[R]})},o:function(p,g){return Object.prototype.hasOwnProperty.call(p,g)}},t={};e.d(t,{default:function(){return Si}});var s={1078:"af",1052:"sq",1118:"am",5121:"ar_DZ",15361:"ar_BH",3073:"ar_EG",2049:"ar_IQ",11265:"ar_JO",13313:"ar_KW",12289:"ar_LB",4097:"ar_LY",6145:"ar_MA",8193:"ar_OM",16385:"ar_QA",1025:"ar_SA",10241:"ar_SY",7169:"ar_TN",14337:"ar_AE",9217:"ar_YE",1067:"hy",1101:"as",2092:"az_AZ",1068:"az_AZ",1069:"eu",1059:"be",2117:"bn",1093:"bn_IN",5146:"bs",1026:"bg",1109:"my",1027:"ca",2052:"zh_CN",3076:"zh_HK",5124:"zh_MO",4100:"zh_SG",1028:"zh_TW",1050:"hr",1029:"cs",1030:"da",1125:"dv",2067:"nl_BE",1043:"nl_NL",1126:"bin",3081:"en_AU",10249:"en_BZ",4105:"en_CA",9225:"en_CB",2057:"en_GB",16393:"en_IN",6153:"en_IE",8201:"en_JM",5129:"en_NZ",13321:"en_PH",7177:"en_ZA",11273:"en_TT",1033:"en_US",12297:"en_ZW",1061:"et",1071:"mk",1080:"fo",1065:"fa",1124:"fil",1035:"fi",2060:"fr_BE",11276:"fr_CM",3084:"fr_CA",9228:"fr_CG",12300:"fr_CI",1036:"fr_FR",5132:"fr_LU",13324:"fr_ML",6156:"fr_MC",14348:"fr_MA",10252:"fr_SN",4108:"fr_CH",7180:"fr",1122:"fy_NL",2108:"gd_IE",1084:"gd",1110:"gl",1079:"ka",3079:"de_AT",1031:"de_DE",5127:"de_LI",4103:"de_LU",2055:"de_CH",1032:"el",1140:"gn",1095:"gu",1279:"en",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig_NG",1057:"id",1040:"it_IT",2064:"it_CH",1041:"ja",1099:"kn",1120:"ks",1087:"kk",1107:"km",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1142:"la",1062:"lv",1063:"lt",2110:"ms_BN",1086:"ms_MY",1100:"ml",1082:"mt",1112:"mni",1153:"mi",1102:"mr",1104:"mn",2128:"mn",1121:"ne",1044:"no_NO",2068:"no_NO",1096:"or",1045:"pl",1046:"pt_BR",2070:"pt_PT",1094:"pa",1047:"rm",2072:"ro_MO",1048:"ro_RO",1049:"ru",2073:"ru_MO",1083:"se",1103:"sa",3098:"sr_SP",2074:"sr_SP",1072:"st",1074:"tn",1113:"sd",1115:"si",1051:"sk",1060:"sl",1143:"so",1070:"sb",11274:"es_AR",16394:"es_BO",13322:"es_CL",9226:"es_CO",5130:"es_CR",7178:"es_DO",12298:"es_EC",17418:"es_SV",4106:"es_GT",18442:"es_HN",2058:"es_MX",19466:"es_NI",6154:"es_PA",15370:"es_PY",10250:"es_PE",20490:"es_PR",1034:"es_ES",14346:"es_UY",8202:"es_VE",1089:"sw",2077:"sv_FI",1053:"sv_SE",1114:"syc",1064:"tg",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1073:"ts",1055:"tr",1090:"tk",1058:"uk",1056:"ur",2115:"uz_UZ",1091:"uz_UZ",1075:"ve",1066:"vi",1106:"cy",1076:"xh",1085:"yi",1077:"zu"};const i=/^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i,a={},o={group:" ",decimal:".",positive:"+",negative:"-",percent:"%",exponent:"E",nan:"NaN",infinity:"∞",ampm:["AM","PM"],mmmm6:["Muharram","Safar","Rabiʻ I","Rabiʻ II","Jumada I","Jumada II","Rajab","Shaʻban","Ramadan","Shawwal","Dhuʻl-Qiʻdah","Dhuʻl-Hijjah"],mmm6:["Muh.","Saf.","Rab. I","Rab. II","Jum. I","Jum. II","Raj.","Sha.","Ram.","Shaw.","Dhuʻl-Q.","Dhuʻl-H."],mmmm:["January","February","March","April","May","June","July","August","September","October","November","December"],mmm:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function u(p){const g=i.exec(p);if(!g)throw new SyntaxError("Malformed locale: ".concat(p));return{lang:g[1]+(g[2]?"_"+g[2]:""),language:g[1],territory:g[2]||"",codeset:g[3]||"",modifier:g[4]||""}}function c(p){if(typeof p=="number")return s[65535&p]||null;const g=parseInt(p,16);return isFinite(g)&&s[65535&g]?s[65535&g]||null:i.test(p)?p:null}function l(p){const g=c(p);let R=null;if(g){const A=u(g);R=a[A.lang]||a[A.language]||null}return R}function m(p){return Object.assign({},o,p)}function d(p,g){const R=typeof g=="object"?g:u(g);return a[R.lang]=m(p),R.language===R.lang||a[R.language]||(a[R.language]=m(p)),a[R.lang]}const E=m({group:","});function D(p,g){if(typeof p!="number")return p;if(p<0)return-D(-p,g);if(g){const R=10**(g||0)||1;return D(p*R,0)/R}return Math.round(p)}E.isDefault=!0,d({group:",",ampm:["上午","下午"],mmmm:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["周日","周一","周二","周三","周四","周五","周六"]},"zh_CN"),d({group:",",nan:"非數值",ampm:["上午","下午"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["週日","週一","週二","週三","週四","週五","週六"]},"zh_TW"),d({group:",",ampm:["午前","午後"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日"],ddd:["日","月","火","水","木","金","土"]},"ja"),d({group:",",ampm:["오전","오후"],mmmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],mmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],dddd:["일요일","월요일","화요일","수요일","목요일","금요일","토요일"],ddd:["일","월","화","수","목","금","토"]},"ko"),d({group:",",ampm:["ก่อนเที่ยง","หลังเที่ยง"],mmmm:["มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม"],mmm:["ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค."],dddd:["วันอาทิตย์","วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัสบดี","วันศุกร์","วันเสาร์"],ddd:["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."]},"th"),d({decimal:",",ampm:["dop.","odp."],mmmm:["ledna","února","března","dubna","května","června","července","srpna","září","října","listopadu","prosince"],mmm:["led","úno","bře","dub","kvě","čvn","čvc","srp","zář","říj","lis","pro"],dddd:["neděle","pondělí","úterý","středa","čtvrtek","pátek","sobota"],ddd:["ne","po","út","st","čt","pá","so"]},"cs"),d({group:".",decimal:",",mmmm:["januar","februar","marts","april","maj","juni","juli","august","september","oktober","november","december"],mmm:["jan.","feb.","mar.","apr.","maj","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"da"),d({group:".",decimal:",",ampm:["a.m.","p.m."],mmmm:["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"],mmm:["jan.","feb.","mrt.","apr.","mei","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag"],ddd:["zo","ma","di","wo","do","vr","za"]},"nl"),d({group:","},"en"),d({decimal:",",nan:"epäluku",ampm:["ap.","ip."],mmmm:["tammikuuta","helmikuuta","maaliskuuta","huhtikuuta","toukokuuta","kesäkuuta","heinäkuuta","elokuuta","syyskuuta","lokakuuta","marraskuuta","joulukuuta"],mmm:["tammik.","helmik.","maalisk.","huhtik.","toukok.","kesäk.","heinäk.","elok.","syysk.","lokak.","marrask.","jouluk."],dddd:["sunnuntaina","maanantaina","tiistaina","keskiviikkona","torstaina","perjantaina","lauantaina"],ddd:["su","ma","ti","ke","to","pe","la"]},"fi"),d({group:" ",decimal:",",mmmm:["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],mmm:["janv.","févr.","mars","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc."],dddd:["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],ddd:["dim.","lun.","mar.","mer.","jeu.","ven.","sam."]},"fr"),d({group:".",decimal:",",mmmm:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],mmm:["Jan.","Feb.","März","Apr.","Mai","Juni","Juli","Aug.","Sept.","Okt.","Nov.","Dez."],dddd:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],ddd:["So.","Mo.","Di.","Mi.","Do.","Fr.","Sa."]},"de"),d({group:".",decimal:",",ampm:["π.μ.","μ.μ."],mmmm:["Ιανουαρίου","Φεβρουαρίου","Μαρτίου","Απριλίου","Μαΐου","Ιουνίου","Ιουλίου","Αυγούστου","Σεπτεμβρίου","Οκτωβρίου","Νοεμβρίου","Δεκεμβρίου"],mmm:["Ιαν","Φεβ","Μαρ","Απρ","Μαΐ","Ιουν","Ιουλ","Αυγ","Σεπ","Οκτ","Νοε","Δεκ"],dddd:["Κυριακή","Δευτέρα","Τρίτη","Τετάρτη","Πέμπτη","Παρασκευή","Σάββατο"],ddd:["Κυρ","Δευ","Τρί","Τετ","Πέμ","Παρ","Σάβ"]},"el"),d({decimal:",",ampm:["de.","du."],mmmm:["január","február","március","április","május","június","július","augusztus","szeptember","október","november","december"],mmm:["jan.","febr.","márc.","ápr.","máj.","jún.","júl.","aug.","szept.","okt.","nov.","dec."],dddd:["vasárnap","hétfő","kedd","szerda","csütörtök","péntek","szombat"],ddd:["V","H","K","Sze","Cs","P","Szo"]},"hu"),d({group:".",decimal:",",ampm:["f.h.","e.h."],mmmm:["janúar","febrúar","mars","apríl","maí","júní","júlí","ágúst","september","október","nóvember","desember"],mmm:["jan.","feb.","mar.","apr.","maí","jún.","júl.","ágú.","sep.","okt.","nóv.","des."],dddd:["sunnudagur","mánudagur","þriðjudagur","miðvikudagur","fimmtudagur","föstudagur","laugardagur"],ddd:["sun.","mán.","þri.","mið.","fim.","fös.","lau."]},"is"),d({group:".",decimal:",",mmmm:["Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"],mmm:["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des"],dddd:["Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu"],ddd:["Min","Sen","Sel","Rab","Kam","Jum","Sab"]},"id"),d({group:".",decimal:",",mmmm:["gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"],mmm:["gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"],dddd:["domenica","lunedì","martedì","mercoledì","giovedì","venerdì","sabato"],ddd:["dom","lun","mar","mer","gio","ven","sab"]},"it"),d({decimal:",",ampm:["a.m.","p.m."],mmmm:["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],mmm:["jan.","feb.","mar.","apr.","mai","jun.","jul.","aug.","sep.","okt.","nov.","des."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"nb"),d({decimal:",",mmmm:["stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia"],mmm:["sty","lut","mar","kwi","maj","cze","lip","sie","wrz","paź","lis","gru"],dddd:["niedziela","poniedziałek","wtorek","środa","czwartek","piątek","sobota"],ddd:["niedz.","pon.","wt.","śr.","czw.","pt.","sob."]},"pl"),d({group:".",decimal:",",mmmm:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"],mmm:["jan.","fev.","mar.","abr.","mai.","jun.","jul.","ago.","set.","out.","nov.","dez."],dddd:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"],ddd:["dom.","seg.","ter.","qua.","qui.","sex.","sáb."]},"pt"),d({decimal:",",nan:"не число",mmmm:["января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"],mmm:["янв.","февр.","мар.","апр.","мая","июн.","июл.","авг.","сент.","окт.","нояб.","дек."],dddd:["воскресенье","понедельник","вторник","среда","четверг","пятница","суббота"],ddd:["вс","пн","вт","ср","чт","пт","сб"]},"ru"),d({decimal:",",mmmm:["januára","februára","marca","apríla","mája","júna","júla","augusta","septembra","októbra","novembra","decembra"],mmm:["jan","feb","mar","apr","máj","jún","júl","aug","sep","okt","nov","dec"],dddd:["nedeľa","pondelok","utorok","streda","štvrtok","piatok","sobota"],ddd:["ne","po","ut","st","št","pi","so"]},"sk"),d({group:".",decimal:",",ampm:["a. m.","p. m."],mmmm:["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],mmm:["ene.","feb.","mar.","abr.","may.","jun.","jul.","ago.","sept.","oct.","nov.","dic."],dddd:["domingo","lunes","martes","miércoles","jueves","viernes","sábado"],ddd:["dom.","lun.","mar.","mié.","jue.","vie.","sáb."]},"es"),d({decimal:",",ampm:["fm","em"],mmmm:["januari","februari","mars","april","maj","juni","juli","augusti","september","oktober","november","december"],mmm:["jan.","feb.","mars","apr.","maj","juni","juli","aug.","sep.","okt.","nov.","dec."],dddd:["söndag","måndag","tisdag","onsdag","torsdag","fredag","lördag"],ddd:["sön","mån","tis","ons","tors","fre","lör"]},"sv"),d({group:".",decimal:",",ampm:["ÖÖ","ÖS"],mmmm:["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık"],mmm:["Oca","Şub","Mar","Nis","May","Haz","Tem","Ağu","Eyl","Eki","Kas","Ara"],dddd:["Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi"],ddd:["Paz","Pzt","Sal","Çar","Per","Cum","Cmt"]},"tr");function C(p,g,R){const A=p<0?-1:1,V=10**(g||2),U=10**(R||2);let v,w,y=Math.abs(p),T=0,H=0,M=0,W=1;if((p=y)%1==0)w=[p*A,1];else if(p<1e-19)w=[A,1e19];else if(p>1e19)w=[1e19*A,1];else{do if(y=1/(y-Math.floor(y)),v=W,W=W*Math.floor(y)+T,T=v,H=M,M=Math.floor(p*W+.5),M>=V||W>=U)return[A*H,T];while(Math.abs(p-M/W)>=1e-10&&y!==Math.floor(y));w=[A*M,W]}return w}const L={overflow:"######",dateErrorThrows:!1,dateErrorNumber:!0,dateSpanLarge:!0,leap1900:!0,nbsp:!0,throws:!0,invalid:"######",locale:"",ignoreTimezone:!1},x=Object.assign({},L);function P(p){if(p===null&&(p=L),p){for(const g in p)if(g in L){const R=p[g];x[g]=R==null?L[g]:R}}return{...x}}const O={"#":"",0:"0","?":" "},I={"@":"text","-":"minus","+":"plus"},ne=["#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#800","#080","#008","#880","#808","#088","#CCC","#888","#99F","#936","#FFC","#CFF","#606","#F88","#06C","#CCF","#008","#F0F","#FF0","#0FF","#808","#800","#088","#00F","#0CF","#CFF","#CFC","#FF9","#9CF","#F9C","#C9F","#FC9","#36F","#3CC","#9C0","#FC0"],le=["¤","$","£","¥","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],fe=new RegExp("["+le.join("")+"]");function q(p,g,R){return g[R+"_max"]=p.length,g[R+"_min"]=p.replace(/#/g,"").length,g}const Y={};function N(p){if(!(p in Y)){const g=[],R=p.replace(/^[#,]+/,"").replace(/[1-9]\d*/g,A=>"?".repeat(A.length));for(let A=0;A<R.length;A++){const V=R.charAt(A);g[A]=V in O?O[V]:V}Y[p]=g.join("")}return Y[p]}function Z(p,g){typeof p=="string"&&(p={type:"string",value:p=p.replace(/ /g,O["?"])}),g.push(p)}function Ve(p){const g=[],R={scale:1,percent:!1,text:!1,date:0,date_eval:!1,date_system:1,sec_decimals:0,general:!1,clock:24,int_pattern:[],frac_pattern:[],man_pattern:[],den_pattern:[],num_pattern:[],tokens:g};let A=p+"",V="int",U=!1,v=null;const w=[];let y,T,H=!1;for(;A&&!U;){if(y=/^General/i.exec(A))R.general=!0,Z({type:"general"},g);else if(V==="int"&&(y=/^[#?0]+(?:,[#?0]+)*/.exec(A))||V==="den"&&(y=/^[#?\d]+/.exec(A))||(y=/^[#?0]+/.exec(A)))R[V+"_pattern"].push(y[0]),v={type:V,num:y[0]},Z(v,g);else if((y=/^\//.exec(A))&&R[V+"_pattern"].length){if(!v)throw new SyntaxError("Missing a numerator in pattern ".concat(p));R.fractions=!0,R.num_pattern.push(R[V+"_pattern"].pop()),v.type="num",V="den",Z({type:"div"},g)}else if(y=/^,+/.exec(A)){const B=A.charAt(1)in O;T.slice(-1)in O&&(y[0].length>1||!B)?R.scale=.001**y[0].length:R.dec_fractions||Z(y[0],g)}else{if(y=/^;/.exec(A)){U=!0;break}if(y=/^[@+-]/.exec(A))y[0]==="@"&&(R.text=!0),Z({type:I[y[0]]},g);else if(y=/^(?:\[(h+|m+|s+)\])/i.exec(A)){const B=y[1].toLowerCase(),z=B[0],K={type:"",size:0,date:1,raw:y[0],pad:B.length};z==="h"?(K.size=16,K.type="hour-elap"):z==="m"?(K.size=32,K.type="min-elap"):(K.size=64,K.type="sec-elap"),R.date=R.date|K.size,w.push(K),Z(K,g)}else if(y=/^(?:B2)/i.exec(A))H||(R.date_system=6);else if(y=/^(?:B1)/i.exec(A))H||(R.date_system=1);else if(y=/^(?:([hHmMsSyYbBdDegG])\1*)/.exec(A)){const B={type:"",size:0,date:1,raw:y[0]},z=y[0].toLowerCase(),K=z[0];if(z==="y"||z==="yy")B.size=2,B.type="year-short";else if(K==="y"||K==="e")B.size=2,B.type="year";else if(z==="b"||z==="bb")B.size=2,B.type="b-year-short";else if(K==="b")B.size=2,B.type="b-year";else if(z==="d"||z==="dd")B.size=8,B.type="day",B.pad=/dd/.test(z);else if(z==="ddd")B.size=8,B.type="weekday-short";else if(K==="d")B.size=8,B.type="weekday";else if(K==="h")B.size=16,B.type="hour",B.pad=/hh/i.test(z);else if(K==="m"){z.length===3?(B.size=4,B.type="monthname-short"):z.length===5?(B.size=4,B.type="monthname-single"):z.length>=4&&(B.size=4,B.type="monthname");const se=w[w.length-1];!B.type&&se&&!se.used&&80&se.size&&(se.used=!0,B.size=32,B.type="min",B.pad=/mm/.test(z)),B.type||(B.size=4,B.type="month",B.pad=/mm/.test(z),B.indeterminate=!0)}else if(K==="s"){B.size=64,B.type="sec",B.pad=/ss/.test(z);const se=w[w.length-1];se&&32&se.size?B.used=!0:se&&se.indeterminate&&(delete se.indeterminate,se.size=32,se.type="min",B.used=!0)}R.date=R.date|B.size,R.date_eval=!0,w.push(B),Z(B,g)}else if(y=/^(?:AM\/PM|am\/pm|A\/P)/.exec(A))R.clock=12,R.date=16|R.date,R.date_eval=!0,Z({type:"am",short:y[0]==="A/P"},g);else if(R.date&&(y=/^\.0{1,3}/i.exec(A))){const B=y[0].length-1,z=[64,128,256,512][B];R.date=R.date|z,R.date_eval=!0,R.sec_decimals=Math.max(R.sec_decimals,B),Z({type:"subsec",size:z,decimals:B,date:1,raw:y[0]},g)}else if((y=/^\\(.)/.exec(A))||(y=/^"([^"]*?)"/.exec(A)))Z(y[1],g);else if(y=/^\[(<[=>]?|>=?|=)\s*(-?[.\d]+)\]/.exec(A))R.condition=[y[1],parseFloat(y[2],10)];else if(y=/^\[\$([^\]]+)\]/.exec(A)){const B=y[1].split("-"),z=B.length<2?"":B[B.length-1],K=B[0];K&&Z(K,g);const se=c(z);se&&(R.locale=se);const oe=parseInt(z,16);isFinite(oe)&&16711680&oe&&(oe>>16&255)===6&&(R.date_system=6),H=!0}else if(y=/^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*(\d+))\]/i.exec(A))R.color=y[2]?ne[parseInt(y[2],10)]||"#000":y[1].toLowerCase();else if(!(y=/^\[(DBNum1|ENG|HIJ|JPN|TWN)\]/i.exec(A))){if(y=/^%/.exec(A))R.scale=100,R.percent=!0,Z("%",g);else if(y=/^_(\\.|.)/.exec(A))Z(" ",g);else if(y=/^\./.exec(A))Z({type:"point",value:y[0]},g),R.dec_fractions=!0,V="frac";else if(y=/^[Ee]([+-]?|(?=[0#?]))/.exec(A))R.exponential=!0,R.exp_plus=y[1]==="+",V="man",Z({type:"exp",plus:y[1]==="+"},g);else if(!(y=/^\*(\\.|.)/.exec(A))){if(y=/^[BENn[]/.exec(A))throw new SyntaxError("Unexpected char ".concat(A.charAt(0)," in pattern ").concat(p));A[0]==="("&&(R.parens=!0),y=[A[0]],Z(y[0],g)}}}T=y[0],A=A.slice(y?y[0].length:1)}if(R.pattern=p.slice(0,p.length-A.length),/^((?:\[[^\]]+\])+)(;|$)/.test(R.pattern)&&!/^\[(?:h+|m+|s+)\]/.test(R.pattern)&&Z({type:"text"},g),R.fractions&&R.dec_fractions||R.fractions&&R.exponential)throw new SyntaxError("Invalid pattern: ".concat(R.pattern));const M=R.int_pattern.join("");if(R.grouping=M.indexOf(",")>=0,R.grouping){const B=M.split(","),z=B.length;z===2?(R.group_pri=B[1].length,R.group_sec=R.group_pri):z>2&&(R.group_pri=B[z-1].length,R.group_sec=B[z-2].length)}else R.group_pri=0,R.group_sec=0;q(M.replace(/[,]/g,""),R,"int"),q(R.frac_pattern.join(""),R,"frac"),q(R.man_pattern.join(""),R,"man");let W=R.num_pattern.join(""),ee=R.den_pattern.join("");const X=/\?/.test(ee)||/\?/.test(W);return ee=ee.replace(/\d/g,X?"?":"#"),X&&(ee=ee.replace(/#$/g,"?")),q(W,R,"num"),q(ee,R,"den"),X&&(W=W.replace(/#$/g,"?")),R.int_padding=N(R.int_pattern.join("")),R.man_padding=N(R.man_pattern.join("")),R.num_padding=N(W),R.den_padding=N(ee),R.den_pattern.length&&(R.denominator=parseInt(R.den_pattern.join("").replace(/\D/g,""),10)),R.integer=!!R.int_pattern.join("").length,R.fractions&&g.forEach((B,z)=>{const K=g[z+1];B.type==="string"&&K&&(K.type==="num"?B.rule="num+int":K.type==="div"?B.rule="num":K.type==="den"&&(B.rule="den"))}),R}const je=p=>{const g=p.condition;g&&g[1]<0&&(g[0]==="<"||g[0]==="<="||g[0]==="=")||p.tokens.unshift({type:"minus",volatile:!0})};function vt(p){const g=[];let R,A=!1,V=null,U=p,v=0,w=!1,y=0,T=0;do{if(w=Ve(U),(w.date||w.general)&&(w.int_pattern.length||w.frac_pattern.length||w.scale!==1||w.text))throw new Error("Illegal format");if(w.condition&&(T++,A=!0),w.text){if(V)throw new Error("Unexpected partition");V=w}w.locale&&(R=c(w.locale)),g.push(w),v=U.charAt(w.pattern.length)===";"?1:0,U=U.slice(w.pattern.length+v),y++}while(v&&y<4&&T<3);if(v)throw new Error("Unexpected partition");if(T>2)throw new Error("Unexpected condition");const H=g[3];if(H&&(H.int_pattern.length||H.frac_pattern.length||H.date))throw new Error("Unexpected partition");if(A){const M=g.length;if(M===1&&(g[1]=Ve("General"),g[1].generated=!0),M<3){const W=g[0],ee=g[1];if(je(W),ee.condition)je(ee);else{const X=W.condition;(X[0]==="="||X[1]>=0&&(X[0]===">"||X[0]===">="))&&ee.tokens.unshift({type:"minus",volatile:!0})}}else g.forEach(je)}else{if(g.length<4&&V)for(let M=0,W=g.length;M<W;M++)g[M]===V&&g.splice(M,1);if(g.length<1&&V&&(g[0]=Ve("General"),g[0].generated=!0),g.length<2){const M=Ve(g[0].pattern);M.tokens.unshift({type:"minus",volatile:!0}),M.generated=!0,g.push(M)}if(g.length<3){const M=Ve(g[0].pattern);M.generated=!0,g.push(M)}if(g.length<4)if(V)g.push(V);else{const M=Ve("@");M.generated=!0,g.push(M)}g[0].condition=[">",0],g[1].condition=["<",0],g[2].condition=null}return{pattern:p,partitions:g,locale:R}}const ye=Math.floor;function _n(p){if((!(arguments.length>1&&arguments[1]!==void 0)||arguments[1])&&p>=0){if(p===0)return[1900,1,0];if(p===60)return[1900,2,29];if(p<60)return[1900,p<32?1:2,(p-1)%31+1]}let R=p+68569+2415019;const A=ye(4*R/146097);R-=ye((146097*A+3)/4);const V=ye(4e3*(R+1)/1461001);R=R-ye(1461*V/4)+31;const U=ye(80*R/2447),v=R-ye(2447*U/80);R=ye(U/11);const w=U+2-12*R;return[0|100*(A-49)+V+R,0|w,0|v]}function fi(p){return _n(p+1462)}function hi(p){if(p===60)throw new Error("#VALUE!");if(p<=1)return[1317,8,29];if(p<60)return[1317,p<32?9:10,1+(p-2)%30];const g=10631/30,R=.1335;let A=p+466935;const V=ye(A/10631);A-=10631*V;const U=ye((A-R)/g);A-=ye(U*g+R);const v=ye((A+28.5001)/29.5);return v===13?[30*V+U,12,30]:[30*V+U,v,A-ye(29.5001*v-29)]}function En(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,R=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];const A=ye(p);return g===6?hi(A):g===-1?fi(A):_n(A,R)}const Xt=Math.floor,Vr=86400;function Kt(p,g){let R=null;if(Array.isArray(p)){const[A,V,U,v,w,y]=p;R=Date.UTC(A,V==null?0:V-1,U!=null?U:1,v||0,w||0,y||0)}else if(p instanceof Date&&(R=1*p,!g||!g.ignoreTimezone)){const A=new Date;A.setUTCFullYear(p.getFullYear(),p.getMonth(),p.getDate()),A.setUTCHours(p.getHours(),p.getMinutes(),p.getSeconds(),p.getMilliseconds()),R=1*A}if(R!=null&&isFinite(R)){const A=R/864e5;return A-(A<=-25509?-25568:-25569)}return p}function Cn(p,g){let R=0|p;const A=Vr*(p-R);let V=Xt(A);A-V>.9999&&(V+=1,V===Vr&&(V=0,R+=1));const U=V<0?Vr+V:V,[v,w,y]=En(p,0,g&&g.leap1900),T=Xt(U/60/60)%60,H=Xt(U/60)%60,M=Xt(U)%60;if(g&&g.nativeDate){const W=new Date(0);return W.setUTCFullYear(v,w-1,y),W.setUTCHours(T,H,M),W}return[v,w,y,T,H,M]}function mi(p){return!!(p[0]&&p[0].percent||p[1]&&p[1].percent||p[2]&&p[2].percent||p[3]&&p[3].percent)}function di(p){return!!(p[0]&&p[0].date||p[1]&&p[1].date||p[2]&&p[2].date||p[3]&&p[3].date)}function gi(p){const[g,R,A,V]=p;return!(g&&!g.generated||R&&!R.generated||A&&!A.generated||!V||!V.text||V.generated)}const pi={text:15,datetime:10.8,date:10.8,time:10.8,percent:10.6,currency:10.4,grouped:10.2,scientific:6,number:4,fraction:2,general:0,error:0},Ri=[["DMY",1],["DM",2],["MY",3],["MDY",4],["MD",5],["hmsa",6],["hma",7],["hms",8],["hm",9]],_i={total:1,sign:0,period:0,int:1,frac:0},Mt=(p,g)=>p.replace(/\./,g.decimal);function Dn(p,g,R,A){const V=0|R;if(typeof R=="string")p.push(R);else if(R===V)p.push(Math.abs(V));else{const U=Math.abs(R);let v=U?Math.floor(Math.log10(U)):0,w=v<0?U*10**-v:U/10**v;w===10&&(w=1,v++);const y=function(H){let M=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];const W=Math.abs(H);if(!W)return _i;const ee=M&&H<0?1:0,X=Math.floor(W),B=Math.floor(Math.log10(W)+1);let z=0,K=0;if(X!==W){z=1;const se=String(D(B<0?W*10**-B:W/10**B,15));let oe=se.length,ae=!0,Ee=0;for(;Ee<=se.length;){if(se[Ee]==="."){oe--;break}se[Ee]==="0"&&ae?oe--:ae=!1,Ee++}K=oe-B,K<0&&(K=0,z=0)}return{total:ee+Math.max(B,1)+z+K,digits:Math.max(B,0)+K,sign:ee,period:z,int:Math.max(B,1),frac:K}}(U),T=()=>{const H=Math.abs(v);let M;M=w===1?w:D(w,5),p.push(Mt(M+"",A),A.exponent,v<0?A.negative:A.positive,H<10?"0":"",H)};if(v>=-4&&v<=-1){const H=U.toPrecision(10+v).replace(/\.?0+$/,"");p.push(Mt(H,A))}else if(v===10){const H=U.toFixed(10).slice(0,12).replace(/\.$/,"");p.push(Mt(H,A))}else if(Math.abs(v)<=9)if(y.total<=11){const H=D(U,9).toFixed(y.frac);p.push(Mt(H,A))}else v===9?p.push(Math.floor(U)):v>=0&&v<9?p.push(D(U,9-v)):T();else y.total>=12?T():Math.floor(U)===U?p.push(Math.floor(U)):p.push(Mt(D(U,9).toFixed(y.frac),A))}return p}const Bt=86400,yn={int:"integer",frac:"fraction",man:"mantissa",num:"numerator",den:"denominator"},bn=function(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;const R=Math.floor(Math.log10(p));return g>1?Math.floor(R/g)*g:R};function Sn(p,g,R,A){let V="",U="",v="",w="",y="",T=0,H=0|p,M=0,W=0,ee=1,X=0,B=0,z=0,K=0,se=0,oe=0;const ae=A||E;if(!g.text&&isFinite(g.scale)&&g.scale!==1&&(p=function(ie){if(ie===0)return ie;const ue=Math.ceil(Math.log10(ie<0?-ie:ie)),k=10**(16-Math.floor(ue));return Math.round(ie*k)/k}(p*g.scale)),g.exponential){let ie=Math.abs(p);if(ie){const ue=10**-bn(ie,g.int_max),k=D(ie*ue,g.frac_max)/ue;T=bn(k,g.int_max)}ie/=10**T,p=p<0?-ie:ie,V+=Math.abs(T)}if(g.integer){const ie=Math.abs(D(p,g.fractions?1:g.frac_max));y+=ie<1?"":Math.floor(ie)}if(g.grouping){let ie="",ue=y.length;for(ue>g.group_pri&&(ue-=g.group_pri,ie=ae.group+y.slice(ue,ue+g.group_pri)+ie);ue>g.group_sec;)ue-=g.group_sec,ie=ae.group+y.slice(ue,ue+g.group_sec)+ie;y=ue?y.slice(0,ue)+ie:ie}g.dec_fractions&&(w=String(D(p,g.frac_max)).split(".")[1]||"");let Ee=!1;if(g.fractions){const ie=Math.abs(g.integer?p%1:p);if(ie)if(Ee=!0,isFinite(g.denominator))v+=g.denominator,U+=D(ie*g.denominator),U==="0"&&(U="",v="",Ee=!1,y||(y="0"));else{const ue=C(ie,g.integer?g.num_max:1/0,g.den_max);U+=ue[0],v+=ue[1],g.integer&&U==="0"&&(y||(y="0"),U="",v="",Ee=!1)}}if(g.date){H=Math.trunc(p);const ie=Bt*(p-H);if(M=Math.floor(ie),oe=ie-M,Math.abs(oe)<1e-6?oe=0:oe>.9999&&(oe=0,M+=1,M===Bt&&(M=0,H+=1)),oe){const ue=512&g.date||256&g.date||128&g.date;(ue===512&&oe>.9995||ue===256&&oe>.995||ue===128&&oe>.95||!ue&&oe>=.5)&&(M++,oe=0)}if(H||g.date_system){const ue=En(p,g.date_system,R.leap1900);W=ue[0],ee=ue[1],X=ue[2]}if(M){const ue=M<0?Bt+M:M;se=Math.floor(ue)%60,K=Math.floor(ue/60)%60,z=Math.floor(ue/60/60)%60}if(B=(6+H)%7,g.date_eval&&(Ge=p,at=H+M/Bt,R.dateSpanLarge?Ge<-694324||at>=35830291:Ge<0||at>=2958466)){if(R.dateErrorThrows)throw new Error("Date out of bounds");return R.dateErrorNumber?Dn(p<0?[ae.negative]:[],0,p,ae).join(""):R.overflow}}var Ge,at;if(g.int_padding&&(y=g.int_padding.length===1?y||g.int_padding:g.int_padding.substring(0,g.int_padding.length-y.length)+y),g.num_padding&&(U=g.num_padding.length===1?U||g.num_padding:g.num_padding.substring(0,g.num_padding.length-U.length)+U),g.den_padding&&(v=g.den_padding.length===1?v||g.den_padding:v+g.den_padding.slice(v.length)),g.man_padding){const ie=g.exp_plus?"+":"";V=g.man_padding.length===1?(T<0?"-":ie)+(V||g.man_padding):(T<0?"-":ie)+g.man_padding.slice(0,g.man_padding.length-V.length)+V}const $=[];let ve=0;const Je={int:0,frac:0,man:0,num:0,den:0};for(let ie=0,ue=g.tokens.length;ie<ue;ie++){const k=g.tokens[ie],qt=k.num?k.num.length:0;if(k.type==="string")k.rule?k.rule==="num"?Ee?$.push(k.value):(g.num_min>0||g.den_min>0)&&$.push(k.value.replace(/./g,O["?"])):k.rule==="num+int"?Ee&&y?$.push(k.value):g.den_min>0&&(y||g.num_min)&&$.push(k.value.replace(/./g,O["?"])):k.rule==="den"&&(Ee?$.push(k.value):(g.den_min>0||g.den_min>0)&&$.push(k.value.replace(/./g,O["?"]))):$.push(k.value);else if(k.type==="error")$.push(R.invalid);else if(k.type==="point")$.push(g.date?k.value:ae.decimal);else if(k.type==="general")Dn($,0,p,ae);else if(k.type==="exp")$.push(ae.exponent);else if(k.type==="minus")k.volatile&&g.date||k.volatile&&(p>=0||typeof p!="number")||(k.volatile&&!g.fractions&&(g.integer||g.dec_fractions)?(p<0&&y&&y!=="0"||w)&&$.push(ae.negative):$.push(ae.negative));else if(k.type==="plus")$.push(ae.positive);else if(k.type==="text")$.push(p);else if(k.type==="div")Ee?$.push("/"):g.num_min>0||g.den_min>0?$.push(O["?"]):$.push(O["#"]);else if(k.type==="int")if(g.int_pattern.length===1)$.push(y);else{const de=ve?g.int_pattern.join("").length-Je.int:1/0,Et=ve===g.int_pattern.length-1?0:g.int_pattern.join("").length-(Je.int+k.num.length);$.push(y.substring(y.length-de,y.length-Et)),ve++,Je.int+=k.num.length}else if(k.type==="frac"){const de=Je.frac;for(let Et=0;Et<qt;Et++)$.push(w[Et+de]||O[k.num[Et]]);Je.frac+=qt}else if(k.type in yn)g[k.type+"_pattern"].length===1?(k.type==="int"&&$.push(y),k.type==="frac"&&$.push(w),k.type==="man"&&$.push(V),k.type==="num"&&$.push(U),k.type==="den"&&$.push(v)):($.push(yn[k.type].slice(Je[k.type],Je[k.type]+qt)),Je[k.type]+=qt);else if(k.type==="year")W<0&&$.push(ae.negative),$.push(String(Math.abs(W)).padStart(4,"0"));else if(k.type==="year-short"){const de=W%100;$.push(de<10?"0":"",de)}else if(k.type==="month")$.push(k.pad&&ee<10?"0":"",ee);else if(k.type==="monthname-single")g.date_system===6?$.push(ae.mmmm6[ee-1].charAt(0)):$.push(ae.mmmm[ee-1].charAt(0));else if(k.type==="monthname-short")g.date_system===6?$.push(ae.mmm6[ee-1]):$.push(ae.mmm[ee-1]);else if(k.type==="monthname")g.date_system===6?$.push(ae.mmmm6[ee-1]):$.push(ae.mmmm[ee-1]);else if(k.type==="weekday-short")$.push(ae.ddd[B]);else if(k.type==="weekday")$.push(ae.dddd[B]);else if(k.type==="day")$.push(k.pad&&X<10?"0":"",X);else if(k.type==="hour"){const de=z%g.clock||(g.clock<24?g.clock:0);$.push(k.pad&&de<10?"0":"",de)}else if(k.type==="min")$.push(k.pad&&K<10?"0":"",K);else if(k.type==="sec")$.push(k.pad&&se<10?"0":"",se);else if(k.type==="subsec"){$.push(ae.decimal);const de=oe.toFixed(g.sec_decimals);$.push(de.slice(2,2+k.decimals))}else if(k.type==="am"){const de=z<12?0:1;k.short&&!A?$.push("AP"[de]):$.push(ae.ampm[de])}else if(k.type==="hour-elap"){p<0&&$.push(ae.negative);const de=24*H+Math.floor(Math.abs(M)/3600);$.push(String(Math.abs(de)).padStart(k.pad,"0"))}else if(k.type==="min-elap"){p<0&&$.push(ae.negative);const de=1440*H+Math.floor(Math.abs(M)/60);$.push(String(Math.abs(de)).padStart(k.pad,"0"))}else if(k.type==="sec-elap"){p<0&&$.push(ae.negative);const de=H*Bt+Math.abs(M);$.push(String(Math.abs(de)).padStart(k.pad,"0"))}else if(k.type==="b-year")$.push(W+543);else if(k.type==="b-year-short"){const de=(W+543)%100;$.push(de<10?"0":"",de)}}return R.nbsp?$.join(""):$.join("").replace(/\u00a0/g," ")}function Ln(p,g){for(let R=0;R<3;R++){const A=g[R];if(A){let V;if(A.condition){const U=A.condition[0],v=A.condition[1];U==="="?V=p===v:U===">"?V=p>v:U==="<"?V=p<v:U===">="?V=p>=v:U==="<="?V=p<=v:U==="<>"&&(V=p!==v)}else V=!0;if(V)return A}}}const An=Ve("@"),xn="black",Fe={};function Oe(p,g){if(p){const R=p[0];g[R]=g[R]||{},Oe(p.slice(1),g[R])}else g.$=!0}["d-F-y","d-F-Y","d-M-y","d-M-Y","F-d-y","F-d-Y","F-j-y","F-j-Y","j-F-y","j-F-Y","j-M-y","j-M-Y","M-d-y","M-d-Y","M-j-y","M-j-Y","m-d-y","m-d-Y","m-j-y","m-j-Y","n-d-y","n-d-Y","n-j-y","n-j-Y","y-F-d","y-F-j","y-M-d","y-M-j","Y-F-d","Y-F-j","Y-M-d","Y-m-d","Y-M-j","Y-m-j","Y-n-d","Y-n-j","j-F","j-M","d-F","d-M","n-d","n-j","n-Y","m-d","m-j","m-Y","M-Y","M-y","F-y","F-Y","Y-M","Y-n","Y-m","Y-F","Y-M"].forEach(p=>{Oe(p,Fe),Oe(p+" x",Fe),Oe(p+" l",Fe),Oe(p+" l x",Fe),Oe("l "+p,Fe),Oe("l "+p+" x",Fe),Oe(p+" D",Fe),Oe(p+" D x",Fe),Oe("D "+p,Fe),Oe("D "+p+" x",Fe)});const Ei={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12},Ci={january:1,february:2,march:3,april:4,june:6,july:7,august:8,september:9,october:10,november:11,december:12},Di={sunday:"l",monday:"l",tuesday:"l",wednesday:"l",thursday:"l",friday:"l",saturday:"l",sun:"D",mon:"D",tue:"D",wed:"D",thu:"D",fri:"D",sat:"D"},yi=new Date().getUTCFullYear();function wn(p){const g=new RegExp("^([\\s+%"+le.join("")+"(-]*)(((?:(?:\\d[\\d,]*)(?:\\.\\d*)?|(?:\\.\\d+)))([eE][+-]?\\d+)?)([\\s%"+le.join("")+")]*)$").exec(p);if(g){const[,R,A,V,U,v]=g;let w=1,y="",T=!1,H=!1,M=!1,W=!1,ee=!1,X=null,B=!1,z=parseFloat(A.replace(/,/g,""));if(!isFinite(z))return null;for(let se=0;se<R.length;se++){const oe=R[se];if(oe==="-"){if(T||H)return null;T=!0,w=-1}else if(fe.test(oe)){if(ee)return null;ee=!0,X=oe}else if(oe==="("){if(H||T)return null;H=!0,w=-1}else if(oe==="%"){if(W)return null;W=!0}}for(let se=0;se<v.length;se++){const oe=v[se];if(fe.test(oe)){if(ee)return null;ee=!0,X=oe,B=!0}else if(oe===")"){if(M||!H)return null;M=!0}else if(oe==="%"){if(W)return null;W=!0}}if(U){if(W||ee)return null;y="0.00E+00"}else if(W){if(ee)return null;y=V.includes(".")?"0.00%":"0%",z*=.01}else if(ee){const se=V.includes(".")?"#,##0.00":"#,##0";y=B?se+X:X+se}else V.includes(",")&&(y=V.includes(".")?"#,##0.00":"#,##0");const K={v:z*w};return y&&(K.z=y),K}}const Ie=(p,g,R)=>{const A=R.path||"",V=Object.keys(g);for(let U=0;U<V.length;U++){let v;const w=V[U];if(g[w]){if(w==="$"||w==="€")p||(v=R);else if(w==="-"){const y=/^(\s*([./-]|,\s)\s*|\s+)/.exec(p);if(y){const T=y[1]==="-"||y[1]==="/"||y[1]==="."?y[1]:" ";if(!R.sep||R.sep===T){const H=y[0].replace(/\s+/g," ");v=Ie(p.slice(y[0].length),g[w],{...R,sep:T,path:A+H})}}}else if(w===" "){const y=/^[,.]?\s+/.exec(p);if(y){const T=y[0].replace(/\s+/g," ");v=Ie(p.slice(y[0].length),g[w],{...R,path:A+T})}}else if(w==="j"||w==="d"){const y=/^(0?[1-9]|1\d|2\d|3[01])\b/.exec(p);y&&(v=Ie(p.slice(y[0].length),g[w],{...R,day:y[0],path:A+w}))}else if(w==="n"||w==="m"){const y=/^(0?[1-9]|1[012])\b/.exec(p);y&&(v=Ie(p.slice(y[0].length),g[w],{...R,month:+y[0],_mon:y[0],path:A+w}))}else if(w==="F"||w==="M"){const y=/^([a-z]{3,9})\b/i.exec(p),T=y&&(w==="F"?Ci:Ei)[y[0].toLowerCase()];T&&(v=Ie(p.slice(y[0].length),g[w],{...R,month:T,_mon:y[0],path:A+w}))}else if(w==="l"||w==="D"){const y=/^([a-z]{3,9})\b/i.exec(p);(y&&Di[y[0].toLowerCase()])===w&&(v=Ie(p.slice(y[0].length),g[w],{...R,path:A+w}))}else if(w==="y"){const y=/^\d\d\b/.exec(p);if(y){const T=+y[0]>=30?+y[0]+1900:+y[0]+2e3;v=Ie(p.slice(y[0].length),g[w],{...R,year:T,path:A+w})}}else if(w==="Y"){const y=/^\d\d\d\d\b/.exec(p);y&&(v=Ie(p.slice(y[0].length),g[w],{...R,year:+y[0],path:A+w}))}else{if(w!=="x")throw new Error('Unknown date token "'.concat(w,'"'));{const y=vr(p);y&&(v=Ie("",g[w],{...R,time:y.v,tf:y.z,path:A+w}))}}if(v)return v}}};function Pn(p,g){const R=Ie(p.trim(),Fe,{path:""});if(R){var A;if(R.sep==="."&&R.path.length===3)return null;const V=+((A=R.year)!==null&&A!==void 0?A:yi);if(R.day||(R.day=1),!function(w,y,T){if(T<1||y<1||y>12)return!1;if(y===2){if(T>(w%4==0&&w%100!=0||w%400==0||w===1900?29:28))return!1}else if((y===4||y===6||y===9||y===11)&&T>30||(y===1||y===3||y===5||y===7||y===8||y===10||y===12)&&T>31)return!1;return!0}(V,R.month,R.day))return null;let U=-1/0;if(V<1900)return null;V<=1900&&R.month<=2?U=25568:V<1e4&&(U=25569);const v=Date.UTC(V,R.month-1,R.day)/864e5+U+(R.time||0);if(v>=0&&v<=2958465){const w=R._mon[0]==="0"||R.day[0]==="0"||R._mon.length===2&&R.day.length===2,y=R.path.replace(/[jdlDnmMFyYx-]/g,T=>T==="j"||T==="d"?w?"dd":"d":T==="D"?"ddd":T==="l"?"dddd":T==="n"||T==="m"?w?"mm":"m":T==="M"?"mmm":T==="F"?"mmmm":T==="y"?"yy":T==="x"?R.tf||"":T==="Y"?"yyyy":T);return g&&g.nativeDate?{v:Cn(v,g),z:y}:{v,z:y}}}return null}function vr(p){const g=/^\s*([10]?\d|2[0-4])(?::([0-5]\d|\d))?(?::([0-5]\d|\d))?(\.\d{1,10})?(?:\s*([AP])M?)?\s*$/i.exec(p);if(g){const[,R,A,V,U,v]=g;if(U&&!V||!v&&!A&&!V)return null;let w=1*(R||0);if(v){if(w>=13)return null;v[0]!=="p"&&v[0]!=="P"||(w+=12)}return{v:(60*w*60+60*(1*(A||0))+1*(V||0)+1*(U||0))/86400,z:(R.length===2?"hh":"h")+":mm"+(V?":ss":"")+(v?" AM/PM":"")}}return null}function Vn(p){return/^\s*true\s*$/i.test(p)?{v:!0}:/^\s*false\s*$/i.test(p)?{v:!1}:null}const Ft={};function bi(p,g){const{pattern:R,partitions:A,locale:V}=p,U=y=>{const T=Object.assign({},P(),g,y);return V&&(T.locale=V),T},v=(y,T)=>{const H=U(T);return function(M,W,ee){const X=l(ee.locale),B=W[3]?W[3]:An;if(typeof M=="boolean"&&(M=M?"TRUE":"FALSE"),M==null)return"";if(typeof M!="number")return Sn(M,B,ee,X);if(!isFinite(M)){const K=X||E;return isNaN(M)?K.nan:(M<0?K.negative:"")+K.infinity}const z=Ln(M,W);return z?Sn(M,z,ee,X):ee.overflow}(Kt(y,H),A,H)};v.color=(y,T)=>function(H,M){if(typeof H!="number"||!isFinite(H))return(M[3]?M[3].color:An.color)||xn;const W=Ln(H,M);return W&&W.color||xn}(Kt(y,U(T)),A);const w=function(y){var T;let H=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;const[M,W]=y,ee=M.frac_max,X={type:"general",isDate:di(y),isText:gi(y),isPercent:mi(y),maxDecimals:M.general?9:ee,scale:(T=M.scale)!==null&&T!==void 0?T:1,color:0,parentheses:0,grouped:M.grouping?1:0,_partitions:y},B=!X.isDate&&!X.isText&&!M.error&&M.tokens.some(ae=>ae.type==="string"&&(H?ae.value===H:fe.test(ae.value)));let z="G",K=ee>=0?Math.min(15,ee):"",se="",oe="";if(W&&W.color&&(oe="-",X.color=1),M.parens&&(se="()",X.parentheses=1),B)z="C",X.type="currency";else if(M.error)X.type="error",X.maxDecimals=0;else if(X.isDate){let ae=0,Ee=0,Ge="";M.tokens.forEach($=>{const ve=$.type;/^(b-)?year/.test(ve)?(Ge+="Y",Ee++):ve.startsWith("month")?(Ge+="M",Ee++):/^(week)?day/.test(ve)?(Ge+="D",Ee++):ve!=="hour"&&ve!=="min"&&ve!=="sec"&&ve!=="am"||(Ge+=ve[0],ae++)}),X.type="date",Ee&&ae?X.type="datetime":!Ee&&ae&&(X.type="time");const at=Ri.find($=>Ge.startsWith($[0]));z=at?"D":"G",K=at?at[1]:""}else X.isText?(z="G",X.type="text",K="",X.maxDecimals=0):M.general?(z="G",X.type="general",K=""):M.fractions?(z="G",X.type="fraction",K=""):M.exponential?(z="S",X.type="scientific"):X.isPercent?(z="P",X.type="percent"):M.grouping?(z=",",X.type="grouped"):(M.int_max||ee)&&(z="F",X.type="number");return X.code=z+K+oe+se,X.level=pi[X.type],Object.freeze(X)}(A,(g||{}).currency)||new SyntaxError;return v.info=w,v.dateInfo=function(y){const[T]=y;return{year:!!(2&T.date),month:!!(4&T.date),day:!!(8&T.date),hours:!!(16&T.date),minutes:!!(32&T.date),seconds:!!(64&T.date),clockType:T.clock===12?12:24}}(A),v.isPercent=()=>!!w.isPercent,v.isDate=()=>!!w.isDate,v.isText=()=>!!w.isText,v.pattern=R,p.error&&(v.error=p.error),v.options=U,v.locale=V||g&&g.locale||"",Object.freeze(v)}function he(p,g){p||(p="General");let R=null;return Ft[p]?R=Ft[p]:(R=Object.assign({},P(),g).throws?vt(p):function(A){try{return vt(A)}catch(V){const U={tokens:[{type:"error"}],error:V.message};return{pattern:A,partitions:[U,U,U,U],error:V.message,locale:null}}}(p),R.error||(Ft[p]=R)),bi(R,g)}he.isDate=p=>he(p,{throws:!1}).isDate(),he.isPercent=p=>he(p,{throws:!1}).isPercent(),he.isText=p=>he(p,{throws:!1}).isText(),he.getInfo=(p,g)=>he(p,{...g,throws:!1}).info,he.getDateInfo=(p,g)=>he(p,{...g,throws:!1}).dateInfo,he.dateToSerial=Kt,he.dateFromSerial=Cn,he.options=P,he.dec2frac=C,he.round=D,he.codeToLocale=s,he.parseLocale=u,he.getLocale=l,he.addLocale=(p,g)=>{const R=u(g);return delete Ft[R.lang],delete Ft[R.language],d(p,R)},he.format=function(p,g,R){let A=arguments.length>3&&arguments[3]!==void 0&&arguments[3];const V=R&&typeof R=="object"?R:{locale:R,throws:!A};return he(p,V)(Kt(g,V),V)},he.is_date=he.isDate,he.parseNumber=wn,he.parseDate=Pn,he.parseTime=vr,he.parseBool=Vn,he.parseValue=function(p,g){var R,A,V;return(R=(A=(V=wn(p))!==null&&V!==void 0?V:Pn(p,g))!==null&&A!==void 0?A:vr(p))!==null&&R!==void 0?R:Vn(p)};var Si=he;return t=t.default}()})})(Ks);var Oo=Ks.exports,Uo=Oo;const ko=Fo(Uo),To=(r,n)=>ko.format(r,n);class jo extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=pe(t,s,n),a=pe(t,s,e);return i.map((o,u,c)=>{if(o.isError()||o.isString()||o.isBoolean())return o;let l=a.get(u,c)||_e.create(" ");if(l.isError())return l;if(l.isBoolean())return h.create(f.VALUE);l.isNull()&&(l=_e.create(" "));const m=`${l.getValue()}`;o.isNull()&&(o=b.create(0));const d=o.getValue(),E=To(m,d);return _e.create(E)})}}const qs=[[Po,ht.CONCATENATE],[Vo,ht.LEN],[Mo,ht.LENB],[jo,ht.TEXT]],Zs=[];var Io=(r=>{})();const Js=[];var Ns=(r=>(r.ENCODEURL="ENCODEURL",r.FILTERXML="FILTERXML",r.WEBSERVICE="WEBSERVICE",r))(Ns||{});class ei extends _.Disposable{constructor(){super(...arguments);S(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const Gt=te.createIdentifier("univer.formula.defined-names.service");var $o=Object.defineProperty,Yo=Object.getOwnPropertyDescriptor,zo=(r,n,e,t)=>{for(var s=t>1?void 0:t?Yo(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&&$o(n,e,s),s},Qo=(r,n)=>(e,t)=>n(e,t,r);exports.FormulaCurrentConfigService=class extends _.Disposable{constructor(e){super();S(this,"_unitData",{});S(this,"_arrayFormulaCellData",{});S(this,"_formulaData",{});S(this,"_sheetNameMap",{});S(this,"_forceCalculate",!1);S(this,"_dirtyRanges",[]);S(this,"_dirtyNameMap",{});S(this,"_numfmtItemMap",{});S(this,"_dirtyUnitFeatureMap",{});S(this,"_excludedCell");S(this,"_sheetIdToNameMap",{});this._currentUniverService=e}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},this._dirtyUnitFeatureMap={},this._excludedCell={},this._sheetIdToNameMap={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}getSheetName(e,t){return this._sheetIdToNameMap[e]==null?"":this._sheetIdToNameMap[e][t]||""}load(e){if(e.allUnitData&&e.unitSheetNameMap)this._unitData=e.allUnitData,this._sheetNameMap=e.unitSheetNameMap;else{const{allUnitData:t,unitSheetNameMap:s}=this._loadSheetData();this._unitData=t,this._sheetNameMap=s}this._formulaData=e.formulaData,this._arrayFormulaCellData=os(e.arrayFormulaCellData),this._forceCalculate=e.forceCalculate,this._dirtyRanges=e.dirtyRanges,this._dirtyNameMap=e.dirtyNameMap,this._numfmtItemMap=e.numfmtItemMap,this._dirtyUnitFeatureMap=e.dirtyUnitFeatureMap,this._excludedCell=e.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(e,t){this._dirtyRanges=e,this._excludedCell=t,this._dirtyNameMap={}}registerUnitData(e){this._unitData=e}registerFormulaData(e){this._formulaData=e}registerSheetNameMap(e){this._sheetNameMap=e}_mergeNameMap(e,t){Object.keys(t).forEach(s=>{t[s]&&Object.keys(t[s]).forEach(i=>{e[s]==null&&(e[s]={}),e[s][t[s][i]]=i})}),this._sheetIdToNameMap={},Object.keys(e).forEach(s=>{Object.keys(e[s]).forEach(i=>{this._sheetIdToNameMap[s]==null&&(this._sheetIdToNameMap[s]={}),this._sheetIdToNameMap[s][e[s][i]]=i})})}_loadSheetData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},c={};for(const l of o){const m=l.getSheetId(),d=l.getConfig();u[m]={cellData:new _.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},c[l.getName()]=l.getSheetId()}t[a]=u,s[a]=c}return{allUnitData:t,unitSheetNameMap:s}}};exports.FormulaCurrentConfigService=zo([Qo(0,_.IUniverInstanceService)],exports.FormulaCurrentConfigService);const it=te.createIdentifier("univer.formula.current-data.service");var Ho=Object.defineProperty,Wo=Object.getOwnPropertyDescriptor,Go=(r,n,e,t)=>{for(var s=t>1?void 0:t?Wo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Ho(n,e,s),s},Xo=(r,n)=>(e,t)=>n(e,t,r),$e=(r=>(r[r.IDLE=0]="IDLE",r[r.START_DEPENDENCY=1]="START_DEPENDENCY",r[r.START_CALCULATION=2]="START_CALCULATION",r[r.CURRENTLY_CALCULATING=3]="CURRENTLY_CALCULATING",r[r.START_DEPENDENCY_ARRAY_FORMULA=4]="START_DEPENDENCY_ARRAY_FORMULA",r[r.START_CALCULATION_ARRAY_FORMULA=5]="START_CALCULATION_ARRAY_FORMULA",r[r.CURRENTLY_CALCULATING_ARRAY_FORMULA=6]="CURRENTLY_CALCULATING_ARRAY_FORMULA",r[r.CALCULATION_COMPLETED=7]="CALCULATION_COMPLETED",r))($e||{}),Dt=(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))(Dt||{});exports.FormulaRuntimeService=class extends _.Disposable{constructor(e){super();S(this,"_formulaExecuteStage",0);S(this,"_stopState",!1);S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_currentRowCount",Number.NEGATIVE_INFINITY);S(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);S(this,"_currentSubUnitId","");S(this,"_currentUnitId","");S(this,"_runtimeData",{});S(this,"_runtimeOtherData",{});S(this,"_unitArrayFormulaRange",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeClearArrayFormulaCellData",{});S(this,"_numfmtItemMap",{});S(this,"_runtimeFeatureRange",{});S(this,"_runtimeFeatureCellData",{});S(this,"_functionsExecutedState",0);S(this,"_functionDefinitionPrivacyVar",new Map);S(this,"_totalFormulasToCalculate",0);S(this,"_completedFormulasCount",0);S(this,"_totalArrayFormulasToCalculate",0);S(this,"_completedArrayFormulasCount",0);S(this,"_isCycleDependency",!1);this._currentConfigService=e}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(e){this._totalArrayFormulasToCalculate=e}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(e){this._completedArrayFormulasCount=e}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(e){this._totalFormulasToCalculate=e}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(e){this._completedFormulasCount=e}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(e){this._formulaExecuteStage=e}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(e,t,s,i,a,o){this._currentRow=e,this._currentColumn=t,this._currentRowCount=s,this._currentColumnCount=i,this._currentSubUnitId=a,this._currentUnitId=o}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(e,t){this._functionDefinitionPrivacyVar.set(e,t)}getFunctionDefinitionPrivacyVar(e){return this._functionDefinitionPrivacyVar.get(e)}setRuntimeOtherData(e,t){const s=this._currentSubUnitId,i=this._currentUnitId;this._runtimeOtherData[i]===void 0&&(this._runtimeOtherData[i]={});const a=this._runtimeOtherData[i];a[s]===void 0&&(a[s]={});const o=a[s];o[e]=this._objectValueToCellValue(t)}setRuntimeData(e){const t=this._currentRow,s=this._currentColumn,i=this._currentRowCount,a=this.currentColumnCount,o=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const c=this._runtimeData[u];c[o]==null&&(c[o]=new _.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][o]==null&&(this._numfmtItemMap[u][o]={});const l=this._numfmtItemMap[u][o],m=this._unitArrayFormulaRange[u];let d=new _.ObjectMatrix;m[o]&&(d=new _.ObjectMatrix(m[o])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const E=this._runtimeArrayFormulaCellData[u];E[o]==null&&(E[o]=new _.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const D=this._runtimeClearArrayFormulaCellData[u];D[o]==null&&(D[o]=new _.ObjectMatrix);const C=c[o],L=E[o],x=D[o];if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const P=e,{startRow:O,startColumn:I,endRow:ne,endColumn:le}=P.getRangePosition();if(O===ne&&I===le){const q=P.getFirstCell(),Y=this._objectValueToCellValue(q);C.setValue(t,s,Y),x.setValue(t,s,Y),l[t]==null&&(l[t]={}),l[t][s]=q.getPattern();return}const fe={startRow:t,startColumn:s,endRow:ne-O+t,endColumn:le-I+s};if(d.setValue(t,s,fe),m[o]=d.getData(),this._checkIfArrayFormulaRangeHasData(u,o,t,s,fe)||this._checkIfArrayFormulaExceeded(i,a,fe)){const q=this._objectValueToCellValue(h.create(f.SPILL));C.setValue(t,s,q),x.setValue(t,s,q)}else{const q=h.create(f.SPILL);P.iterator((Y,N,Z)=>{const Ve=this._objectValueToCellValue(Y);if(N===O&&Z===I){if(Y!=null&&Y.isError()&&Y.isEqualType(q))return x.setValue(t,s,{}),C.setValue(t,s,{...this._objectValueToCellValue(q)}),!1;C.setValue(t,s,{...Ve})}const je=N-O+t,vt=Z-I+s;L.setValue(je,vt,Ve);const ye=Y==null?void 0:Y.getPattern();ye&&(l[je]==null&&(l[je]={}),l[je][vt]=ye)})}}else{const P=this._objectValueToCellValue(e);C.setValue(t,s,P),l[t]==null&&(l[t]={}),l[t][s]=e.getPattern(),x.setValue(t,s,P)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(e,t){this._runtimeFeatureRange[e]=t}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e,t){this._runtimeFeatureCellData[e]=t}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),numfmtItemMap:this.getNumfmtItemMap(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(e){if(e==null)return{v:0,t:_.CellValueType.NUMBER};if(e.isError())return{v:e.getErrorType(),t:_.CellValueType.STRING};if(e.isValueObject()){const t=e,s=t.getValue();return t.isNumber()?{v:s,t:_.CellValueType.NUMBER}:t.isBoolean()?{v:s,t:_.CellValueType.BOOLEAN}:t.isString()&&_.isRealNum(s)?{v:s,t:_.CellValueType.FORCE_STRING}:{v:s,t:_.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(e,t,s,i,a){var E,D,C,L,x,P,O,I,ne,le,fe,q;const{startRow:o,startColumn:u,endRow:c,endColumn:l}=a,m=this._currentConfigService.getUnitData(),d=(C=(D=(E=this._unitArrayFormulaRange[e])==null?void 0:E[t])==null?void 0:D[s])==null?void 0:C[i];for(let Y=o;Y<=c;Y++)for(let N=u;N<=l;N++){if(Y===s&&i===N)continue;const Z=(P=(x=(L=this._runtimeData)==null?void 0:L[e])==null?void 0:x[t])==null?void 0:P.getValue(Y,N),Ve=(ne=(I=(O=this._runtimeArrayFormulaCellData)==null?void 0:O[e])==null?void 0:I[t])==null?void 0:ne.getValue(Y,N),je=(q=(fe=(le=m==null?void 0:m[e])==null?void 0:le[t])==null?void 0:fe.cellData)==null?void 0:q.getValue(Y,N);if(!_.isNullCell(Z)||!_.isNullCell(Ve)&&!this._isInArrayFormulaRange(d,Y,N)||!_.isNullCell(je))return!0}return!1}_isInArrayFormulaRange(e,t,s){if(e==null)return!1;const{startRow:i,startColumn:a,endRow:o,endColumn:u}=e;return t>=i&&t<=o&&s>=a&&s<=u}_checkIfArrayFormulaExceeded(e,t,s){return s.endRow>=e||s.endColumn>=t}_isInDirtyRange(e,t,s,i){const a=this._currentConfigService.getDirtyRanges();return a.length===0?!0:ns(a,e,t,s,i)}};exports.FormulaRuntimeService=Go([Xo(0,it)],exports.FormulaRuntimeService);const Be=te.createIdentifier("univer.formula.runtime.service");var Ko=Object.defineProperty,qo=Object.getOwnPropertyDescriptor,Zo=(r,n,e,t)=>{for(var s=t>1?void 0:t?qo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Ko(n,e,s),s},kr=(r,n)=>(e,t)=>n(e,t,r);let Lt=class extends _.Disposable{constructor(r,n,e){super(),this._definedNamesService=r,this._runtimeService=n,this._lexerTreeBuilder=e}treeBuilder(r,n=!0){return this._lexerTreeBuilder.treeBuilder(r,n,this._injectDefinedName.bind(this))}_injectDefinedName(r){var i;const n=this._runtimeService.currentUnitId;if(!this._definedNamesService.hasDefinedName(n))return{sequenceString:"",hasDefinedName:!1};const e=this._lexerTreeBuilder.getSequenceNode(r);let t="",s=!1;for(let a=0,o=e.length;a<o;a++){const u=e[a];if(typeof u=="string"){t+=u;continue}const{nodeType:c,token:l}=u;if(c===Me.REFERENCE||c===Me.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(l);m?(t+=m,s=!0):t+=l}else t+=l}return{sequenceString:t,hasDefinedName:s}}};Lt=Zo([kr(0,Gt),kr(1,Be),kr(2,te.Inject(Dr))],Lt);var re=(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))(re||{});const ze=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class Pe extends _.Disposable{constructor(e){super();S(this,"_children",[]);S(this,"_parent");S(this,"_valueObject");S(this,"_calculateState",!1);S(this,"_async",!1);S(this,"_address",!1);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return re.BASE}isAsync(){return this._async}isAddress(){return this._address}setAsync(){this._async=!0}setAddress(){this._address=!0}getParent(){return this._parent}setParent(e){this._parent=e,e.addChildren(this)}getChildren(){return this._children}addChildren(...e){this._children.push(...e)}getToken(){return this._token}setValue(e){this._valueObject=e}getValue(){return this._valueObject}isCalculated(){return this._calculateState}setCalculated(){this._calculateState=!0}execute(){}setNotEmpty(e=!0){}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}async executeAsync(){return Promise.resolve(ft.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let o=0;o<i;o++){const u=t[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class De extends Pe{constructor(e){super(e);S(this,"_errorValueObject");this._errorValueObject=h.create(e)}get nodeType(){return re.ERROR}static create(e){return new De(e)}getValue(){return this._errorValueObject}}const Qe=100;class He extends _.Disposable{get zIndex(){return 0}create(n,e,t){let s;return n instanceof J?s=n.getToken():s=n,new Pe(s)}checkAndCreateNodeType(n){}}class Hr extends Pe{get nodeType(){return re.ROOT}execute(){const e=this.getChildren()[0];e==null?this.setValue(h.create(f.VALUE)):this.setValue(e.getValue())}}class ti extends He{get zIndex(){return ze.get(re.ROOT)||Qe}checkAndCreateNodeType(n){if(!(n instanceof J))return;if(n.getToken()===rt)return new Hr(rt)}}class ri extends _.Disposable{constructor(){super(...arguments);S(this,"_functionExecutors",new Map);S(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const We=te.createIdentifier("univer.formula.function.service");var Jo=Object.defineProperty,No=Object.getOwnPropertyDescriptor,eu=(r,n,e,t)=>{for(var s=t>1?void 0:t?No(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&&Jo(n,e,s),s},Kn=(r,n)=>(e,t)=>n(e,t,r);class hr extends Pe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return re.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===Re.MINUS?t=this._functionExecutor.calculate(b.create(0),e):this._operatorString===Re.AT?t=this._handlerAT(e):t=h.create(f.VALUE),this.setValue(t)}_handlerAT(n){if(!n.isReferenceObject())return h.create(f.VALUE);const e=n;if(e.isCell())return h.create(f.VALUE);const t=this._accessor.get(Be),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():h.create(f.VALUE)}}let mr=class extends He{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ze.get(re.PREFIX)||Qe}checkAndCreateNodeType(r){if(!(r instanceof J))return;const n=r.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Re.MINUS)t=Le.MINUS;else return e===Re.AT?new hr(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new hr(this._injector,e,s):(console.error(`No function ${n}`),De.create(f.NAME))}};mr=eu([Kn(0,We),Kn(1,te.Inject(te.Injector))],mr);function ni(r,n,e){let t,s;const i=r.slice(0,2);let a=0;if(new RegExp(Re.MINUS,"g").test(i)){const o=n.getExecutor(Le.MINUS);t=new hr(e,Re.MINUS,o),a++}return new RegExp(Re.AT,"g").test(i)&&(s=new hr(e,Re.AT),t&&s.setParent(t),a++),a>0&&(r=r.slice(a)),{tokenTrim:r,minusPrefixNode:t,atPrefixNode:s}}var tu=Object.defineProperty,ru=Object.getOwnPropertyDescriptor,nu=(r,n,e,t)=>{for(var s=t>1?void 0:t?ru(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&tu(n,e,s),s},Jt=(r,n)=>(e,t)=>n(e,t,r);class su extends Pe{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 re.FUNCTION}async executeAsync(){const n=[],e=this.getChildren(),t=e.length;this._compatibility();for(let a=0;a<t;a++){const o=e[a].getValue();o!=null&&(o.isReferenceObject()?n.push(o.toArrayValueObject()):n.push(o))}const s=this._calculate(n);let i;return s.isAsyncObject()||s.isAsyncArrayObject()?i=await s.getValue():i=s,this._setRefData(i),this.setValue(i),Promise.resolve(ft.SUCCESS)}execute(){const n=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const n=this.getChildren(),e=n.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=n[1].getValue(),s=n[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:o,startColumn:u,endRow:c,endColumn:l}=i,m=c-o+1,d=l-u+1,{startRow:E,startColumn:D,endRow:C,endColumn:L}=a,x=C-E+1,P=L-D+1;m!==x&&(a.endRow+=m-x),d!==P&&(a.endColumn+=d-P)}_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=st.create(s);else{const i=la(s);e=Ae.create({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,t,s)}_setRefData(n){if(!n.isReferenceObject())return;const e=n;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let dr=class extends He{constructor(r,n,e,t){super(),this._functionService=r,this._currentConfigService=n,this._runtimeService=e,this._injector=t}get zIndex(){return ze.get(re.FUNCTION)||Qe}create(r){const n=this._functionService.getExecutor(r);return n?new su(r,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${r}`),De.create(f.NAME))}checkAndCreateNodeType(r){if(typeof r=="string")return;const n=r.getToken(),{tokenTrim:e,minusPrefixNode:t,atPrefixNode:s}=ni(n.trim(),this._functionService,this._injector);if(!Number.isNaN(Number(e)))return De.create(f.VALUE);const i=e.toUpperCase();if(this._functionService.hasExecutor(i)){const a=this.create(i);return s?a.setParent(s):t&&a.setParent(t),a}}};dr=nu([Jt(0,We),Jt(1,it),Jt(2,Be),Jt(3,te.Inject(te.Injector))],dr);var iu=Object.defineProperty,au=Object.getOwnPropertyDescriptor,ou=(r,n,e,t)=>{for(var s=t>1?void 0:t?au(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&iu(n,e,s),s},uu=(r,n)=>(e,t)=>n(e,t,r);let At=class extends _.Disposable{constructor(r){super(),this._runtimeService=r}dispose(){}async executeAsync(r){if(!r)return h.create(f.VALUE);await this._executeAsync(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(r){if(!r)return h.create(f.VALUE);this._execute(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(r){return r.execute(),r.getValue()}checkAsyncNode(r){const n=[];this._checkAsyncNode(r,n);for(let e=0,t=n.length;e<t;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(r,n){const e=r.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(r){if(this._runtimeService.isStopExecution())return Promise.resolve(ft.ERROR);const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===It&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return r.nodeType===re.FUNCTION&&r.isAsync()?await r.executeAsync():r.execute(),Promise.resolve(ft.SUCCESS)}_execute(r){if(this._runtimeService.isStopExecution())return ft.ERROR;const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===It&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return r.execute(),ft.SUCCESS}};At=ou([uu(0,Be)],At);function si(r){return r instanceof J?r.getToken()===St:!1}function cu(r){return r instanceof J?r.getToken()===ds:!1}function ii(r){if(!r)return;if(r.getToken()!==Ht)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:ii(s)}class dn extends Ze{constructor(e,t,s){super(0);S(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}static create(e,t,s){return new dn(e,t,s)}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return h.create(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new da(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()===Ht){const u=a.getLambdaParameter(),c=this._lambdaPrivacyValueMap.get(u);if(c)a.setValue(c);else{const l=a.getCurrentLambdaPrivacyVar(),m=ii(l.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 lu=Object.defineProperty,fu=Object.getOwnPropertyDescriptor,hu=(r,n,e,t)=>{for(var s=t>1?void 0:t?fu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&lu(n,e,s),s},qn=(r,n)=>(e,t)=>n(e,t,r);class mu extends Pe{constructor(e,t,s,i){super(e);S(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return re.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(dn.create(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let gr=class extends He{constructor(r,n){super(),this._runtimeService=r,this._interpreter=n}get zIndex(){return ze.get(re.LAMBDA)||Qe}create(r){const n=r.getChildren(),e=n[0];let t=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof J&&s instanceof J))return De.create(f.NAME);if(e.getToken()===St){const o=e.getChildren();if(t.length!==o.length)return De.create(f.VALUE)}else t=n.slice(0,-1);const i=_.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof J){const c=u.getChildren()[0];u.setToken(ds),a.set(c.trim(),void 0)}else return De.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new mu(r.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(r){if(!(!(r instanceof J)||r.getToken().trim().toUpperCase()!==It))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(!(si(i)&&a!==0))if(o instanceof J)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const c=new J;c.setToken(Ht),c.setLambdaId(n),c.setLambdaPrivacyVar(e),c.setLambdaParameter(u),t[a]=c}}}}};gr=hu([qn(0,Be),qn(1,te.Inject(At))],gr);function ai(r){if(!r)return;if(r.getToken()!==Ht)return r;const n=r,e=n.getCurrentLambdaPrivacyVar(),t=n.getLambdaParameter();if(e)return ai(e.get(t))}class du extends Pe{constructor(n,e,t){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return re.LAMBDA_PARAMETER}execute(){const n=ai(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(h.create(f.SPILL))}}}class oi extends He{get zIndex(){return ze.get(re.LAMBDA_PARAMETER)||Qe}create(n){const e=n.getFunctionDefinitionPrivacyVar(),t=n.getLambdaParameter();return e?new du(n.getToken(),t,e):new De(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof J)||n.getToken().trim()!==Ht))return this.create(n)}}class gu extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return re.NULL}execute(){this.setValue(ce.create())}}var pu=Object.defineProperty,Ru=Object.getOwnPropertyDescriptor,_u=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ru(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&pu(n,e,s),s},Eu=(r,n)=>(e,t)=>n(e,t,r);class Cu extends Pe{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return re.OPERATOR}execute(){var i,a;const n=this.getChildren();this._functionExecutor.name===Le.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=(i=n[0])==null?void 0:i.getValue(),t=(a=n[1])==null?void 0:a.getValue();const s=this.getToken();if((e==null||t==null)&&s!==ge.MINUS&&s!==ge.PLUS){this.setValue(h.create(f.VALUE));return}e==null&&(e=ce.create()),t==null&&(t=ce.create()),e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let pr=class extends He{constructor(r){super(),this._functionService=r}get zIndex(){return ze.get(re.OPERATOR)||Qe}create(r){let n="";const e=r;e===ge.PLUS?n=Le.PLUS:e===ge.MINUS?n=Le.MINUS:e===ge.MULTIPLY?n=Le.MULTIPLY:e===ge.DIVIDED?n=Le.DIVIDED:e===ge.CONCATENATE?n=ht.CONCATENATE:e===ge.POWER?n=we.POWER:xi.has(e)&&(n=Le.COMPARE);const t=this._functionService.getExecutor(n);return t?new Cu(e,t):(console.error(`No function ${r}`),De.create(f.NAME))}checkAndCreateNodeType(r){if(r instanceof J)return;const n=r.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&ct.has(n))return this.create(n)}};pr=_u([Eu(0,We)],pr);class Du extends _.Disposable{constructor(){super(...arguments);S(this,"_tableMap",new Map);S(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const gn=te.createIdentifier("univer.formula.super-table.service");class yu extends Vt{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),c=u.startColumn,l=u.endColumn,m=u.type;let d=-1,E=-1;const D=a.startRow,C=a.startColumn;m===lt.ALL?(d=D,E=C):m===lt.DATA?(d=D+1,E=C):m===lt.HEADERS?(d=D,E=D):m===lt.TOTALS&&(d=C,E=C),this.setRangeData({startColumn:c,endColumn:l,startRow:d,endRow:E})}isTable(){return!0}_stringToColumnData(n,e,t){n=n.substring(1,-1);const s=n.indexOf(G.COMMA);let i=-1,a=-1,o=lt.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),c=n.substring(s+1),l=this._columnHandler(c,e,!0);i=l.startColumn,a=l.endColumn,o=t.get(u),o||(o=lt.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,t=!1){var o,u,c;let s=-1,i=-1;const a=n.indexOf(G.COLON);if(new RegExp(hs,"g").test(n)){const l=n.substring(0,a).substring(1,-1),m=n.substring(a+1).substring(1,-1);s=(o=e.get(l))!=null?o:-1,i=(u=e.get(m))!=null?u:-1}else t&&(n=n.substring(1,-1)),s=(c=e.get(n))!=null?c:-1,i=s;return{startColumn:s,endColumn:i}}}var bu=Object.defineProperty,Su=Object.getOwnPropertyDescriptor,Lu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Su(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&&bu(n,e,s),s},Ot=(r,n)=>(e,t)=>n(e,t,r);class Nt extends Pe{constructor(n,e,t,s=!1){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return re.REFERENCE}execute(){const n=this._accessor.get(it),e=this._accessor.get(Be);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(n.getSheetNameMap()),this._referenceObject.setUnitData(n.getUnitData()),this._referenceObject.setArrayFormulaCellData(n.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setNumfmtItemData(n.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(h.create(f.NAME)):this.setValue(this._referenceObject)}}let Rr=class extends He{constructor(r,n,e,t,s){super(),this._definedNamesService=r,this._superTableService=n,this._formulaRuntimeService=e,this._functionService=t,this._injector=s}get zIndex(){return ze.get(re.REFERENCE)||Qe}checkAndCreateNodeType(r){var u,c;let n=!1,e,t=!1;r instanceof J?(n=!0,e=r.getToken().trim(),((c=(u=r.getParent())==null?void 0:u.getParent())==null?void 0:c.getToken().trim())===G.COLON&&(t=!0)):e=r.trim();const{tokenTrim:s,minusPrefixNode:i,atPrefixNode:a}=ni(e,this._functionService,this._injector);if(!n&&s.charAt(0)==='"'&&s.charAt(s.length-1)==='"')return;let o;if(new RegExp(Qt).test(s))o=new Nt(this._injector,s,new on(s),t);else if(n&&new RegExp(ls).test(s))o=new Nt(this._injector,s,new un(s),t);else if(n&&new RegExp(fs).test(s))o=new Nt(this._injector,s,new cn(s),t);else{const l=this._formulaRuntimeService.currentUnitId,m=this._superTableService.getTableMap(l),d=new RegExp(hs,"g"),E=s.replace(d,"");if(!n&&(m!=null&&m.has(E))){const D=d.exec(s);let C="";D&&(C=D[0]);const L=m.get(E),x=this._superTableService.getTableOptionMap();o=new Nt(this._injector,s,new yu(s,L,C,x))}}if(o)return a?o.setParent(a):i&&o.setParent(i),o}};Rr=Lu([Ot(0,Gt),Ot(1,gn),Ot(2,Be),Ot(3,We),Ot(4,te.Inject(te.Injector))],Rr);var Au=Object.defineProperty,xu=Object.getOwnPropertyDescriptor,wu=(r,n,e,t)=>{for(var s=t>1?void 0:t?xu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Au(n,e,s),s},Zn=(r,n)=>(e,t)=>n(e,t,r);class Jn extends Pe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return re.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===qe.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,b.create(100)),t.isNumber()&&t.setPattern("0.00%")):this._operatorString===qe.POUND?t=this._handlerPound(e):t=h.create(f.VALUE),this.setValue(t)}_handlerPound(n){var l,m,d,E;if(!n.isReferenceObject()||!n.isCell())return h.create(f.VALUE);const e=this._accessor.get(it),t=this._accessor.get(Lt),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),c=(E=(d=(m=(l=u==null?void 0:u[a])==null?void 0:l[o])==null?void 0:m[i.startRow])==null?void 0:d[i.startColumn])==null?void 0:E.f;return c&&t.treeBuilder(c),h.create(f.VALUE)}}let _r=class extends He{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ze.get(re.SUFFIX)||Qe}checkAndCreateNodeType(r){if(!(r instanceof J))return;const n=r.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===qe.PERCENTAGE)e=Le.DIVIDED;else return n===qe.POUND?new Jn(this._injector,n):void 0;const t=this._functionService.getExecutor(e);return t?new Jn(this._injector,n,t):(console.error(`No function ${r}`),De.create(f.NAME))}};_r=wu([Zn(0,We),Zn(1,te.Inject(te.Injector))],_r);var Pu=Object.defineProperty,Vu=Object.getOwnPropertyDescriptor,vu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Vu(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&&Pu(n,e,s),s},Mu=(r,n)=>(e,t)=>n(e,t,r);class Bu extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return re.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===G.COLON?s=this._unionFunction(e,t):s=h.create(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()||!n.isReferenceObject()||!e.isReferenceObject()?h.create(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):h.create(f.REF))}}let Er=class extends He{constructor(r){super(),this._functionService=r}get zIndex(){return ze.get(re.UNION)||Qe}create(r){return new Bu(r)}checkAndCreateNodeType(r){if(!(r instanceof J))return;const e=r.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===G.COLON)return this.create(e)}};Er=vu([Mu(0,We)],Er);class Fu extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return re.VALUE}execute(){this.setValue(st.create(this._operatorString))}}class ui extends He{get zIndex(){return ze.get(re.VALUE)||Qe}_checkValueNode(n){if(Number.isNaN(Number(n))){const e=n.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(zt.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===dt.TRUE||i===dt.FALSE)return this.create(i)}else return this.create(n)}create(n){return new Fu(n)}checkAndCreateNodeType(n){if(!(n instanceof J))return this._checkValueNode(n)}}function Ou(r){let n=r;for(;n!=null&&n.getParent();)n=n.getParent();return n}var Uu=Object.defineProperty,ku=Object.getOwnPropertyDescriptor,Tu=(r,n,e,t)=>{for(var s=t>1?void 0:t?ku(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Uu(n,e,s),s},Ue=(r,n)=>(e,t)=>n(e,t,r);let Yt=class extends _.Disposable{constructor(n,e,t,s,i,a,o,u,c,l,m){super();S(this,"_astNodeFactoryList",[]);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=c,this._unionNodeFactory=l,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,t=0){const s=new Hr(rt);return this._refOffsetX=e,this._refOffsetY=t,this._parse(n,s)}_lambdaParameterHandler(n,e){const t=e.getLambdaId(),s=new Hr(rt),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let m=0;m<u;m++){const d=o[m];if(d instanceof J)this._parse(d,s);else return!1}const c=s.getChildren(),l=c.length;for(let m=0;m<l;m++){const d=c[m];i.set(a[m],d)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new J;s.setToken(It);const i=new J;i.setToken(St);const a=[...e];for(let u=0;u<t;u++){const c=a[u];if(!(c instanceof J))return;u%2===0?c.changeToParent(s):c.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_parse(n,e){const t=n.getChildren(),s=t.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===Ui){const l=this._changeLetToLambda(n);return l!=null?this._parse(l,e):De.create(f.ERROR)}if(o===Xe){if(a=e,s===0)return new gu(rt).setParent(e),a}else{if(o===St){let l=this._lambdaParameterHandler(n,e);return l===!1&&(l=De.create(f.ERROR)),l}if(a=this._checkAstNode(n),a==null)return De.create(f.ERROR)}const u=t[0];for(let l=0;l<s;l++){const m=t[l];if(si(u)){if(l!==0&&l!==s-1)continue}else if(cu(m)&&l!==s-1)continue;let d=null;if(m instanceof J){if(d=this._parse(m,a),d===a)continue}else d=this._checkAstNode(m);if(d==null)return De.create(f.NAME);if(d=Ou(d),d==null)return;switch(d.nodeType){case re.ERROR:return d;case re.FUNCTION:i.push(d);break;case re.LAMBDA:i.push(d);break;case re.LAMBDA_PARAMETER:i.push(d);break;case re.OPERATOR:{const E=i.pop(),D=i.pop();D&&D.setParent(d),E&&E.setParent(d),i.push(d);break}case re.REFERENCE:d.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(d);break;case re.ROOT:i.push(d);break;case re.UNION:i.push(d);break;case re.VALUE:i.push(d);break;case re.PREFIX:i.push(d);break;case re.SUFFIX:i.push(d);break}}const c=i.length;for(let l=0;l<c;l++)i[l].setParent(a);return a}_checkAstNode(n){let e=null;const t=this._astNodeFactoryList.length;for(let s=0;s<t&&(e=this._astNodeFactoryList[s].checkAndCreateNodeType(n),e==null);s++);return e}_initializeAstNode(){this._astNodeFactoryList=[this._astRootNodeFactory,this._functionNodeFactory,this._lambdaNodeFactory,this._lambdaParameterNodeFactory,this._operatorNodeFactory,this._prefixNodeFactory,this._referenceNodeFactory,this._suffixNodeFactory,this._unionNodeFactory,this._valueNodeFactory].sort(_.sortRules)}};Yt=Tu([Ue(0,Be),Ue(1,te.Inject(ti)),Ue(2,te.Inject(dr)),Ue(3,te.Inject(gr)),Ue(4,te.Inject(oi)),Ue(5,te.Inject(pr)),Ue(6,te.Inject(mr)),Ue(7,te.Inject(Rr)),Ue(8,te.Inject(_r)),Ue(9,te.Inject(Er)),Ue(10,te.Inject(ui))],Yt);class ci extends _.Disposable{constructor(){super(...arguments);S(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pr=te.createIdentifier("univer.formula.feature-calculation-manager.service");class li extends _.Disposable{constructor(){super(...arguments);S(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:t,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]&&(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]&&(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}getOtherFormulaData(){return this._otherFormulaData}}const pn=te.createIdentifier("univer.formula.other-formula-manager.service");class Tr extends _.Disposable{constructor(){super(...arguments);S(this,"node");S(this,"children",[]);S(this,"parents",[]);S(this,"formula","");S(this,"row",-1);S(this,"column",-1);S(this,"rowCount",Number.NEGATIVE_INFINITY);S(this,"columnCount",Number.NEGATIVE_INFINITY);S(this,"subUnitId","");S(this,"unitId","");S(this,"rangeList",[]);S(this,"formulaId");S(this,"featureId");S(this,"getDirtyData");S(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const c=this.rangeList[o],{unitId:l,sheetId:m,range:d}=c.gridRange;if(((i=t[l])==null?void 0:i[m])!=null)return!0;if(!e.has(l))continue;const E=e.get(l);if(!E.has(m))continue;const D=E.get(m),C=(a=s==null?void 0:s[l])==null?void 0:a[m];let{startRow:L,endRow:x,startColumn:P,endColumn:O}=d;Number.isNaN(L)&&(L=0),Number.isNaN(P)&&(P=0),Number.isNaN(x)&&(x=Number.POSITIVE_INFINITY),Number.isNaN(O)&&(O=Number.POSITIVE_INFINITY);for(const I of D){const{startRow:ne,startColumn:le,endRow:fe,endColumn:q}=I;if(!(L>fe||x<ne||P>q||O<le)){let Y=!0;if(C==null||C.forValue((N,Z)=>{if(N>=L&&N<=x&&Z>=P&&Z<=O)return Y=!1,!1}),Y)return!0}}}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let t=0,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.gridRange.unitId,o=i.gridRange.sheetId,u=i.gridRange.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}class ju extends _.Disposable{constructor(){super(...arguments);S(this,"_cacheItems",new Map)}dispose(){this.clear()}size(){return this._cacheItems.size}add(e,t){const{token:s}=e;if(!this._cacheItems.has(s)){this._cacheItems.set(s,{unitRangeWithToken:e,treeList:[t]});return}this._cacheItems.get(s).treeList.push(t)}clear(){this._cacheItems.clear()}remove(e,t){if(!this._cacheItems.has(e))return;const s=this._cacheItems.get(e),i=s.treeList.indexOf(t);i!==-1&&s.treeList.splice(i,1)}delete(e){this._cacheItems.delete(e)}dependency(e){this._cacheItems.forEach(t=>{const{unitRangeWithToken:s,treeList:i}=t,{gridRange:a}=s,{unitId:o,sheetId:u,range:c}=a;e.unitId===o&&e.subUnitId===u&&e.inRangeData(c)&&i.forEach(l=>{if(l===e)return!0;l.pushChildren(e)})})}}var Iu=Object.defineProperty,$u=Object.getOwnPropertyDescriptor,Yu=(r,n,e,t)=>{for(var s=t>1?void 0:t?$u(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&&Iu(n,e,s),s},ot=(r,n)=>(e,t)=>n(e,t,r);const zu=1e5,jr=new pt(zu);let Tt=class extends _.Disposable{constructor(n,e,t,s,i,a,o){super();S(this,"_updateRangeFlattenCache",new Map);S(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),jr.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),{treeList:s,dependencyTreeCache:i}=await this._generateTreeList(n,e,t),a=this._getUpdateTreeListAndMakeDependency(s,i);this._checkIsCycleDependency(a)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(a);return Promise.resolve(u)}_isCyclicUtil(n,e,t){if(!e.has(n)){e.add(n),t.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,t)||t.has(n.children[s]))return!0}return t.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,t=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(n,e,t){const s=Object.keys(n),i=Object.keys(e),a=[];for(const u of s){const c=n[u];if(c==null)continue;const l=Object.keys(c);for(const m of l)new _.ObjectMatrix(c[m]).forValue((E,D,C)=>{if(C==null)return!0;const{f:L,x,y:P}=C,O=this._generateAstNode(L,x,P),I=new Tr,ne=t[u][m];I.node=O,I.formula=L,I.unitId=u,I.subUnitId=m,I.row=E,I.column=D,I.rowCount=ne.rowCount,I.columnCount=ne.columnCount,a.push(I)})}for(const u of i){const c=e[u];if(c==null)continue;const l=Object.keys(c);for(const m of l){const d=c[m];if(d==null)continue;const E=Object.keys(d);for(const D of E){const C=d[D],{f:L}=C,x=this._generateAstNode(L),P=new Tr;P.node=x,P.formula=L,P.unitId=u,P.subUnitId=m,P.formulaId=D,a.push(P)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,c)=>{const{unitId:l,subUnitId:m,dependencyRanges:d,getDirtyData:E}=u,D=new Tr;D.unitId=l,D.subUnitId=m,D.getDirtyData=E,D.featureId=c,D.rangeList=d.map(C=>({gridRange:C,token:bt({...C,sheetName:this._currentConfigService.getSheetName(C.unitId,C.sheetId)})})),a.push(D)});const o=new ju;for(let u=0,c=a.length;u<c;u++){const l=a[u];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const m=await this._getRangeListByNode(l.node);for(let d=0,E=m.length;d<E;d++){const D=m[d];l.pushRangeList(D),o.add(D,l)}}return{treeList:a,dependencyTreeCache:o}}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,t=0){let s=jr.get(`${n}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(zt.has(i))return De.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return jr.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===re.UNION||n.nodeType===re.PREFIX&&n.getToken()===Re.AT||n.nodeType===re.SUFFIX&&n.getToken()===qe.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===re.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===re.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],c=(await this._executeNode(o)).toUnitRange(),l=bt({...c,sheetName:this._currentConfigService.getSheetName(c.unitId,c.sheetId)});s.push({gridRange:c,token:l})}for(let i=0,a=t.length;i<a;i++){const o=t[i],c=(await this._executeNode(o)).toUnitRange(),l=bt({...c,sheetName:this._currentConfigService.getSheetName(c.unitId,c.sheetId)});s.push({gridRange:c,token:l})}return s}_getUpdateTreeListAndMakeDependency(n,e){const t=[],s=new Set,i=this._currentConfigService.isForceCalculate();let a=!0;e.size()>n.length&&(a=!1);for(let o=0,u=n.length;o<u;o++){const c=n[o];if(a)e.dependency(c);else for(let l=0,m=n.length;l<m;l++){const d=n[l];c!==d&&c.dependency(d)&&c.pushChildren(d)}(i||c.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(c))&&!s.has(c)&&(t.push(c),s.add(c))}return e.dispose(),t}_includeTree(n){var c,l,m,d,E;const e=n.unitId,t=n.subUnitId,s=n.featureId;if(s!=null){const D=this._currentConfigService.getDirtyUnitFeatureMap();if(((l=(c=D==null?void 0:D[e])==null?void 0:c[t])==null?void 0:l[s])!=null)return!0}const i=(d=(m=this._currentConfigService.getExcludedRange())==null?void 0:m[e])==null?void 0:d[t];let a=!1;if(i==null||i.forValue((D,C)=>{if(n.row===D&&n.column===C)return a=!0,!1}),a)return!1;if(((E=this._dirtyUnitSheetNameMap[e])==null?void 0:E[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const o=this._updateRangeFlattenCache.get(e);if(!o.has(t))return!1;const u=o.get(t);for(const D of u)if(n.inRangeData(D))return!0;return!1}_calculateRunList(n){let e=n;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];u.isAdded()||s.isSkip()||i.push(u)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};Tt=Yu([_.OnLifecycle(_.LifecycleStages.Rendered,Tt),ot(0,it),ot(1,Be),ot(2,pn),ot(3,Pr),ot(4,te.Inject(At)),ot(5,te.Inject(Yt)),ot(6,te.Inject(Lt))],Tt);var Qu=Object.defineProperty,Hu=Object.getOwnPropertyDescriptor,Wu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Hu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Qu(n,e,s),s},ut=(r,n)=>(e,t)=>n(e,t,r);const Gu=1;exports.CalculateFormulaService=class extends _.Disposable{constructor(e,t,s,i,a,o,u){super();S(this,"_executionStartListener$",new Mr.Subject);S(this,"executionStartListener$",this._executionStartListener$.asObservable());S(this,"_executionCompleteListener$",new Mr.Subject);S(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());S(this,"_executionInProgressListener$",new Mr.Subject);S(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,t){this._runtimeService.setRuntimeFeatureCellData(e,t)}setRuntimeFeatureRange(e,t){this._runtimeService.setRuntimeFeatureRange(e,t)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const t=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||Gu;for(let s=0;s<t&&(await this._execute(),!!this._runtimeService.isCycleDependency());s++);this._runtimeService.setFormulaExecuteStage($e.CALCULATION_COMPLETED),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState()),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData()),Qr.clear(),Ne.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 c=new _.ObjectMatrix(o[u]);if(c==null)return!0;const l=new _.ObjectMatrix;c.forValue((m,d,E)=>{l.setValue(m,d,!0),s.push({unitId:a,sheetId:u,range:E})}),i[a]==null&&(i[a]={}),i[a][u]=l})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const c=o[u];if(c==null)return!0;Object.keys(c).forEach(l=>{const m=c[l];if(m==null)return!0;for(const d of m)s.push({unitId:u,sheetId:l,range:d})})})}),{dirtyRanges:s,excludedCell:i}}async _apply(e=!1){e?this._runtimeService.setFormulaExecuteStage($e.START_DEPENDENCY_ARRAY_FORMULA):this._runtimeService.setFormulaExecuteStage($e.START_DEPENDENCY),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());const t=await this._formulaDependencyGenerator.generate(),s=this._interpreter;e?(this._runtimeService.setFormulaExecuteStage($e.START_CALCULATION_ARRAY_FORMULA),this._runtimeService.setTotalArrayFormulasToCalculate(t.length)):(this._runtimeService.setFormulaExecuteStage($e.START_CALCULATION),this._runtimeService.setTotalFormulasToCalculate(t.length)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState());for(let i=0,a=t.length;i<a;i++){if(await new Promise(m=>{_.requestImmediateMacroTask(m)}),this._runtimeService.isStopExecution()){this._runtimeService.setFormulaExecuteStage($e.IDLE),this._runtimeService.markedAsStopFunctionsExecuted(),this._executionCompleteListener$.next(this._runtimeService.getAllRuntimeData());return}const o=t[i],u=o.node,c=o.getDirtyData;let l;if(u==null&&c==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),c!=null&&o.featureId!=null){const{runtimeCellData:m,dirtyRanges:d}=c(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,m),this._runtimeService.setRuntimeFeatureRange(o.featureId,d)}else u!=null&&(s.checkAsyncNode(u)?l=await s.executeAsync(u):l=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,l):this._runtimeService.setRuntimeData(l));e?(this._runtimeService.setFormulaExecuteStage($e.CURRENTLY_CALCULATING_ARRAY_FORMULA),this._runtimeService.setCompletedArrayFormulasCount(i+1)):(this._runtimeService.setFormulaExecuteStage($e.CURRENTLY_CALCULATING),this._runtimeService.setCompletedFormulasCount(i+1)),this._executionInProgressListener$.next(this._runtimeService.getRuntimeState())}return t.length>0?this._runtimeService.markedAsSuccessfullyExecuted():e||this._runtimeService.markedAsNoFunctionsExecuted(),this._runtimeService.getAllRuntimeData()}calculate(e,t=!0){const s=this._lexer.treeBuilder(e,t);if(Object.values(f).includes(s))return De.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=Wu([_.OnLifecycle(_.LifecycleStages.Rendered,exports.CalculateFormulaService),ut(0,_.IConfigService),ut(1,te.Inject(Lt)),ut(2,it),ut(3,Be),ut(4,te.Inject(Tt)),ut(5,te.Inject(At)),ut(6,te.Inject(Yt))],exports.CalculateFormulaService);const Rn={id:"formula.mutation.set-numfmt-formula-data",type:_.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).updateNumfmtItemMap(n.numfmtItemMap),!0)};var Xu=Object.defineProperty,Ku=Object.getOwnPropertyDescriptor,qu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ku(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Xu(n,e,s),s},er=(r,n)=>(e,t)=>n(e,t,r);let rr=class extends _.Disposable{constructor(r,n,e,t){super(),this._commandService=r,this._calculateFormulaService=n,this._currentUniverService=e,this._formulaDataModel=t,this._initialize()}_initialize(){this._commandExecutedListener(),this._initialExecuteFormulaListener(),this._initialExecuteFormulaProcessListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((r,n)=>{if(r.id===Zr.id)this._calculateFormulaService.stopFormulaExecution();else if(r.id===Nr.id){const e=r.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(r.id===qr.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===cr.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 Dt.NOT_EXECUTED:break;case Dt.STOP_EXECUTION:break;case Dt.SUCCESS:this._applyFormula(r);break;case Dt.INITIAL:break}this._commandService.executeCommand(lr.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(r=>{this._commandService.executeCommand(lr.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(cr.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),_.Tools.isEmptyObject(a)||this._commandService.executeCommand(Rn.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Jr.id,{unitData:Mi(n),unitOtherData:e},{onlyLocal:!0})}};rr=qu([_.OnLifecycle(_.LifecycleStages.Ready,rr),er(0,_.ICommandService),er(1,te.Inject(exports.CalculateFormulaService)),er(2,_.IUniverInstanceService),er(3,te.Inject(exports.FormulaDataModel))],rr);var Zu=Object.defineProperty,Ju=Object.getOwnPropertyDescriptor,Nu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ju(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&&Zu(n,e,s),s},Ir=(r,n)=>(e,t)=>n(e,t,r);let jt=class extends _.Disposable{constructor(r=[],n,e,t){super(),this._function=r,this._commandService=n,this._injector=e,this._functionService=t,this._initialize()}_initialize(){this._registerCommands(),this._registerFunctions()}_registerCommands(){[Nr,cr,qr,Zr,lr,Jr,Rn,yr,br,Xr,Kr,en,tn,Ds,ys,rn,Wr,nn].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_registerFunctions(){const r=[...xs,...Ms,...Bs,...Os,...ks,...Ts,...Is,...Ys,...zs,...Qs,...Ws,...Gs,...Xs,...qs,...Zs,...Js].concat(this._function).map(n=>{const e=n[0],t=n[1];return new e(t)});this._functionService.registerExecutors(...r)}};jt=Nu([_.OnLifecycle(_.LifecycleStages.Ready,jt),Ir(1,_.ICommandService),Ir(2,te.Inject(te.Injector)),Ir(3,We)],jt);var ec=Object.defineProperty,tc=Object.getOwnPropertyDescriptor,rc=(r,n,e,t)=>{for(var s=t>1?void 0:t?tc(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&&ec(n,e,s),s},$r=(r,n)=>(e,t)=>n(e,t,r);let nr=class extends _.Disposable{constructor(r,n,e){super(),this._commandService=r,this._formulaDataModel=n,this._functionService=e,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted((r,n)=>{if(r.id===Wr.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 sc(a,o)});this._functionService.registerExecutors(...s)}else if(r.id===nn.id){const e=r.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};nr=rc([_.OnLifecycle(_.LifecycleStages.Ready,nr),$r(0,_.ICommandService),$r(1,te.Inject(exports.FormulaDataModel)),$r(2,We)],nr);class nc extends j{isCustom(){return!0}}function sc(r,n){const e=new nc(n),t=new Function(`return ${r}`)();return e.calculateCustom=t,e}var ic=Object.defineProperty,ac=Object.getOwnPropertyDescriptor,oc=(r,n,e,t)=>{for(var s=t>1?void 0:t?ac(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&&ic(n,e,s),s},Nn=(r,n)=>(e,t)=>n(e,t,r);let sr=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._definedNamesService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===yr.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===br.id){const n=r.params;if(n==null)return;const{unitId:e,name:t}=n;this._definedNamesService.removeDefinedName(e,t)}}))}};sr=oc([_.OnLifecycle(_.LifecycleStages.Ready,sr),Nn(0,_.ICommandService),Nn(1,Gt)],sr);var uc=Object.defineProperty,cc=Object.getOwnPropertyDescriptor,lc=(r,n,e,t)=>{for(var s=t>1?void 0:t?cc(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&&uc(n,e,s),s},es=(r,n)=>(e,t)=>n(e,t,r);let ir=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._featureCalculationManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===Xr.id){const n=r.params;if(n==null)return;const{featureId:e,calculationParam:t}=n;this._featureCalculationManagerService.register(e,t)}else if(r.id===Kr.id){const n=r.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};ir=lc([_.OnLifecycle(_.LifecycleStages.Ready,ir),es(0,_.ICommandService),es(1,Pr)],ir);var fc=Object.defineProperty,hc=Object.getOwnPropertyDescriptor,mc=(r,n,e,t)=>{for(var s=t>1?void 0:t?hc(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&&fc(n,e,s),s},ts=(r,n)=>(e,t)=>n(e,t,r);let ar=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._otherFormulaManagerService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===en.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.register(n)}else if(r.id===tn.id){const n=r.params;if(n==null)return;this._otherFormulaManagerService.remove(n)}}))}};ar=mc([_.OnLifecycle(_.LifecycleStages.Ready,ar),ts(0,_.ICommandService),ts(1,pn)],ar);var dc=Object.defineProperty,gc=Object.getOwnPropertyDescriptor,pc=(r,n,e,t)=>{for(var s=t>1?void 0:t?gc(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&&dc(n,e,s),s},rs=(r,n)=>(e,t)=>n(e,t,r);let or=class extends _.Disposable{constructor(r,n){super(),this._commandService=r,this._superTableService=n,this._initialize()}_initialize(){this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===yr.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===br.id){const n=r.params;if(n==null)return;const{unitId:e,tableName:t}=n;this._superTableService.remove(e,t)}else if(r.id===rn.id){const n=r.params;if(n==null)return;const{tableOption:e,tableOptionType:t}=n;this._superTableService.registerTableOptionMap(e,t)}}))}};or=pc([_.OnLifecycle(_.LifecycleStages.Ready,or),rs(0,_.ICommandService),rs(1,gn)],or);var Rc=Object.defineProperty,_c=Object.getOwnPropertyDescriptor,Ec=(r,n,e,t)=>{for(var s=t>1?void 0:t?_c(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&&Rc(n,e,s),s},Cc=(r,n)=>(e,t)=>n(e,t,r);const Dc="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends _.Plugin{constructor(n,e){super(Dc),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[We,{useClass:ri}],[Pr,{useClass:ci}],[Gt,{useClass:ei}],[exports.FormulaDataModel],[Dr],[jt,{useFactory:()=>{var t;return this._injector.createInstance(jt,(t=this._config)==null?void 0:t.function)}}],[ir]];(e=this._config)!=null&&e.notExecuteFormula||n.push([exports.CalculateFormulaService],[pn,{useClass:li}],[gn,{useClass:Du}],[it,{useClass:exports.FormulaCurrentConfigService}],[Be,{useClass:exports.FormulaRuntimeService}],[rr],[sr],[ar],[or],[nr],[Tt],[At],[Yt],[Lt],[ti],[dr],[gr],[oi],[pr],[mr],[Rr],[_r],[Er],[ui]),n.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=Ec([Cc(1,te.Inject(te.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=Ae;exports.BaseFunction=j;exports.BaseReferenceObject=Vt;exports.BaseValueObject=Ze;exports.BooleanValueObject=Q;exports.DefinedNamesService=ei;exports.ErrorType=f;exports.ErrorValueObject=h;exports.FUNCTION_NAMES_ARRAY=Ra;exports.FUNCTION_NAMES_COMPATIBILITY=Ct;exports.FUNCTION_NAMES_CUBE=Fs;exports.FUNCTION_NAMES_DATABASE=Us;exports.FUNCTION_NAMES_DATE=et;exports.FUNCTION_NAMES_ENGINEERING=js;exports.FUNCTION_NAMES_FINANCIAL=$s;exports.FUNCTION_NAMES_INFORMATION=ke;exports.FUNCTION_NAMES_LOGICAL=tt;exports.FUNCTION_NAMES_LOOKUP=be;exports.FUNCTION_NAMES_MATH=we;exports.FUNCTION_NAMES_STATISTICAL=Se;exports.FUNCTION_NAMES_TEXT=ht;exports.FUNCTION_NAMES_UNIVER=Io;exports.FUNCTION_NAMES_WEB=Ns;exports.FeatureCalculationManagerService=ci;exports.FormulaExecuteStageType=$e;exports.FormulaExecutedStateType=Dt;exports.FunctionService=ri;exports.FunctionType=ss;exports.IDefinedNamesService=Gt;exports.IFeatureCalculationManagerService=Pr;exports.IFormulaCurrentConfigService=it;exports.IFormulaRuntimeService=Be;exports.IFunctionService=We;exports.LexerNode=J;exports.LexerTreeBuilder=Dr;exports.NumberValueObject=b;exports.OtherFormulaManagerService=li;exports.RangeReferenceObject=$t;exports.RegisterFunctionMutation=Wr;exports.RemoveDefinedNameMutation=br;exports.RemoveFeatureCalculationMutation=Kr;exports.RemoveOtherFormulaMutation=tn;exports.RemoveSuperTableMutation=ys;exports.SetArrayFormulaDataMutation=cr;exports.SetArrayFormulaDataUndoMutationFactory=Gi;exports.SetDefinedNameMutation=yr;exports.SetFeatureCalculationMutation=Xr;exports.SetFormulaCalculationNotificationMutation=lr;exports.SetFormulaCalculationResultMutation=Jr;exports.SetFormulaCalculationStartMutation=qr;exports.SetFormulaCalculationStopMutation=Zr;exports.SetFormulaDataMutation=Nr;exports.SetNumfmtFormulaDataMutation=Rn;exports.SetOtherFormulaMutation=en;exports.SetSuperTableMutation=Ds;exports.SetSuperTableOptionMutation=rn;exports.StringValueObject=_e;exports.UnregisterFunctionMutation=nn;exports.ValueObjectFactory=st;exports.compareToken=F;exports.convertUnitDataToRuntime=os;exports.deserializeRangeForR1C1=As;exports.deserializeRangeWithSheet=wt;exports.functionArray=xs;exports.functionCompatibility=Ms;exports.functionCube=Bs;exports.functionDatabase=Os;exports.functionDate=ks;exports.functionEngineering=Ts;exports.functionFinancial=Is;exports.functionInformation=Ys;exports.functionLogical=zs;exports.functionLookup=Qs;exports.functionMath=Ws;exports.functionMeta=Gs;exports.functionStatistical=Xs;exports.functionText=qs;exports.functionUniver=Zs;exports.functionWeb=Js;exports.generateStringWithSequence=_s;exports.getAbsoluteRefTypeWitString=Ii;exports.getAbsoluteRefTypeWithSingleString=kt;exports.includeFormulaLexerToken=as;exports.initSheetFormulaData=Cs;exports.isFormulaLexerToken=Ut;exports.isInDirtyRange=ns;exports.isReferenceString=ms;exports.matchRefDrawToken=vi;exports.matchToken=G;exports.normalizeSheetName=Vi;exports.operatorToken=ge;exports.sequenceNodeType=Me;exports.serializeRange=mt;exports.serializeRangeToRefString=bt;exports.serializeRangeWithSheet=gs;exports.serializeRangeWithSpreadsheet=ps;
1
+ "use strict";var Pi=Object.defineProperty;var Vi=(r,n,e)=>n in r?Pi(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e;var S=(r,n,e)=>(Vi(r,typeof n!="symbol"?n+"":n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("@univerjs/core"),N=require("@wendellhu/redi"),Or=require("rxjs");function ss(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:c,endRow:l,endColumn:m}=o.range;if(t>=u&&t<=l&&s>=c&&s<=m)return!0}return!1}var f=(r=>(r.DIV_BY_ZERO="#DIV/0!",r.NAME="#NAME?",r.VALUE="#VALUE!",r.NUM="#NUM!",r.NA="#N/A",r.CYCLE="#CYCLE!",r.REF="#REF!",r.SPILL="#SPILL!",r.CALC="#CALC!",r.ERROR="#ERROR!",r.CONNECT="#GETTING_DATA",r.NULL="#NULL!",r))(f||{});const Qt=new Set(Object.values(f));var is=(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))(is||{}),pe=(r=>(r.PLUS="+",r.MINUS="-",r.MULTIPLY="*",r.DIVIDED="/",r.CONCATENATE="&",r.POWER="^",r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(pe||{}),F=(r=>(r.EQUALS="=",r.NOT_EQUAL="<>",r.GREATER_THAN=">",r.GREATER_THAN_OR_EQUAL=">=",r.LESS_THAN="<",r.LESS_THAN_OR_EQUAL="<=",r))(F||{});const rr=new Map([["<>",3],["<",3],[">=",3],["=",3],[">",3],["<=",3],["&",2],["+",2],["-",2],["/",1],["*",1],["^",0]]),lt=new Set(rr.keys()),vi=new Set(["=","<>",">",">=","<","<="]);var G=(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))(G||{}),qe=(r=>(r.PERCENTAGE="%",r.POUND="#",r))(qe||{});const Mi=new Set(["%","#"]);var Re=(r=>(r.AT="@",r.MINUS="-",r))(Re||{});const Oi=" ",as=[...Object.values(F),...Object.values(pe),...Object.values(G),...Object.values(qe),...Object.values(Re)];function Ut(r){return as.includes(r)}function os(r){for(const n of as)if(r.indexOf(n)>-1)return!0;return!1}function Fi(r){return r[0]==="'"&&r[r.length-1]==="'"?r.substring(1,r.length-1):r}function Bi(r){return Ut(r)&&r!==G.CLOSE_BRACES&&r!==G.CLOSE_BRACKET&&r!==G.SINGLE_QUOTATION&&r!==G.DOUBLE_QUOTATION||r===" "}function us(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 C.ObjectMatrix(i)})}),n}function Ui(r){const n={};return Object.keys(r).forEach(e=>{const t=r[e];if(t==null)return!0;n[e]==null&&(n[e]={}),Object.keys(t).forEach(s=>{const i=t[s];n[e][s]=i.getData()})}),n}const Gr={id:"formula.mutation.register-function",type:C.CommandType.MUTATION,handler:()=>!0};class pt{constructor(n){S(this,"_cache");this._cache=new C.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 C.hashAlgorithm(n)}}const zr='\\[([^\\[\\]\\/?:"<>|*\\\\]+)\\]',ki="((?![\\[\\]\\/?*\\\\]).)*!",nt="$",Xr="\\s*?:\\s*?",xt=`'?(${zr})?(${ki})?'?`,Qr=`\\${nt}?[A-Za-z]+\\${nt}?[0-9]+`,Ti=`^(${Re.AT})?${xt}${Qr}${Xr}${Qr}$`,Ht=`^${xt}\\s*?${Qr}(${qe.POUND})?$`,cs=`^${xt}\\${nt}?[0-9]+${Xr}\\${nt}?[0-9]+$`,ls=`^${xt}\\${nt}?[A-Za-z]+${Xr}\\${nt}?[A-Za-z]+$`,fs=`^${xt}\\s*?\\${nt}?[0-9]+$`,hs=`^${xt}\\s*?\\${nt}?[A-Za-z]+$`,ms="[.*?]",ji="{.*?}";function ds(r){return new RegExp(Ht).test(r)||new RegExp(Ti).test(r)||new RegExp(cs).test(r)||new RegExp(ls).test(r)}const Xe="P_1",rt="R_1",St="L_1",Wt="LR_1",gs="LO_1",$i="LET",$t="LAMBDA",Ii="CUBE",Yi=/[^0-9]/g,zi=/[^A-Za-z]/g;function kt(r){const n=r[0]==="$",t=r.substring(1).indexOf("$")>-1;return n&&t?C.AbsoluteRefType.ALL:n?C.AbsoluteRefType.COLUMN:t?C.AbsoluteRefType.ROW:C.AbsoluteRefType.NONE}function Qi(r){const n=r.split("!");n.length>1&&(r=n[n.length-1]);const e=r.split(":");return e.length>1?{startAbsoluteRefType:kt(e[0]),endAbsoluteRefType:kt(e[1])}:{startAbsoluteRefType:kt(e[0])}}function vn(r=C.AbsoluteRefType.NONE){let n="",e="";return r===C.AbsoluteRefType.ROW?n="$":r===C.AbsoluteRefType.COLUMN?e="$":r===C.AbsoluteRefType.ALL&&(n="$",e="$"),{rowAbsoluteString:n,columnAbsoluteString:e}}function dt(r){const{startColumn:n,startRow:e,endColumn:t,endRow:s,startAbsoluteRefType:i,endAbsoluteRefType:a,rangeType:o=C.RANGE_TYPE.NORMAL}=r,u=vn(i),c=vn(a);if(o===C.RANGE_TYPE.ROW||o===C.RANGE_TYPE.ALL){const d=`${u.rowAbsoluteString}${e+1}`,_=`${c.rowAbsoluteString}${s+1}`;return`${d}:${_}`}if(o===C.RANGE_TYPE.COLUMN){const d=`${u.columnAbsoluteString}${C.Tools.chatAtABC(n)}`,_=`${c.columnAbsoluteString}${C.Tools.chatAtABC(t)}`;return`${d}:${_}`}const l=`${u.columnAbsoluteString}${C.Tools.chatAtABC(n)}${u.rowAbsoluteString}${e+1}`,m=`${c.columnAbsoluteString}${C.Tools.chatAtABC(t)}${c.rowAbsoluteString}${s+1}`;return l===m?l:`${l}:${m}`}function ps(r,n){return cr(r)?`'${r}'!${dt(n)}`:`${r}!${dt(n)}`}function Rs(r,n,e){return cr(r)||cr(n)?`'[${r}]${n}'!${dt(e)}`:`[${r}]${n}!${dt(e)}`}function bt(r){const{unitId:n,sheetName:e,range:t}=r;return n!=null&&n.length>0&&e!=null&&e.length>0?Rs(n,e,t):e!=null&&e.length>0?ps(e,t):dt(t)}function Fr(r){const n=Number.parseInt(r.replace(Yi,""))-1,e=C.Tools.ABCatNum(r.replace(zi,"")),t=kt(r);return{row:n,column:e,absoluteRefType:t}}function _s(r){const n=new RegExp(zr).exec(r);let e="";n!=null&&(e=n[0].trim(),e=e.slice(1,e.length-1),r=r.replace(new RegExp(zr),""));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 wt(r){const{refBody:n,sheetName:e,unitId:t}=_s(r),s=n.indexOf(":");if(s===-1){const D=Fr(n),E=D.row,A=D.column,x=D.absoluteRefType;return{unitId:t,sheetName:e,range:{startRow:E,startColumn:A,endRow:E,endColumn:A,startAbsoluteRefType:x,endAbsoluteRefType:x}}}const i=n.substring(0,s),a=n.substring(s+1),o=Fr(i),u=Fr(a),c=o.row,l=o.column,m=u.row,d=u.column;let _=C.RANGE_TYPE.NORMAL;return Number.isNaN(c)&&Number.isNaN(m)?_=C.RANGE_TYPE.COLUMN:Number.isNaN(l)&&Number.isNaN(d)&&(_=C.RANGE_TYPE.ROW),{unitId:t,sheetName:e,range:{startRow:c,startColumn:l,endRow:m,endColumn:d,startAbsoluteRefType:o.absoluteRefType,endAbsoluteRefType:u.absoluteRefType,rangeType:_}}}function cr(r){return r.length===0?!1:!!(os(r)||Hi(r)||Wi(r)||Gi(r)||/[\s!$%^&*()+\-=\[\]{};':"\\|,.<>\/?]/.test(r))}function Hi(r){const n=r.match(/[1-9][0-9]{0,6}/);return/^[A-Z]+[1-9][0-9]{0,6}$/.test(r)&&n!==null}function Wi(r){return/^(R(-?[0-9]+)?C(-?[0-9]+)?|C(-?[0-9]+)?|R(-?[0-9]+)?)$/.test(r)}function Gi(r){return!new RegExp("^\\p{Letter}","u").test(r.charAt(0))}var Me=(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))(Me||{});function Es(r){let n="";for(const e of r)typeof e=="string"?n+=e:n+=e.token;return n}class J{constructor(){S(this,"_parent");S(this,"_token",rt);S(this,"_children",[]);S(this,"_lambdaId");S(this,"_functionDefinitionPrivacyVar");S(this,"_lambdaParameter","");S(this,"_startIndex",-1);S(this,"_endIndex",-1)}dispose(){var n;this._children.forEach(e=>{typeof e!="string"&&e.dispose()}),(n=this._functionDefinitionPrivacyVar)==null||n.clear(),this._parent=null}getStartIndex(){return this._startIndex}getLambdaId(){return this._lambdaId}setLambdaId(n){this._lambdaId=n}getFunctionDefinitionPrivacyVar(){return this._functionDefinitionPrivacyVar}setLambdaPrivacyVar(n){this._functionDefinitionPrivacyVar=n}getLambdaParameter(){return this._lambdaParameter}setLambdaParameter(n){this._lambdaParameter=n}getParent(){return this._parent}setParent(n){this._parent=n}getChildren(){return this._children}setChildren(n){this._children=n}addChildren(n){this._children.push(n)}addChildrenFirst(n){this._children.unshift(n)}getToken(){return this._token}setToken(n){this._token=n}setIndex(n,e){this._startIndex=n,this._endIndex=e}replaceChild(n,e){const t=this._getIndexInParent(n);t!=null&&(this.getChildren().splice(t,1,e),e.setParent(this))}changeToParent(n){const e=this.getParent();e&&e.removeChild(this),this.setParent(n),n.getChildren().push(this)}removeChild(n){const e=this._getIndexInParent(n);e!=null&&this.getChildren().splice(e,1)}serialize(){const n=this.getToken(),e=this.getChildren(),t=[],s=e.length;for(let i=0;i<s;i++){const a=e[i];a instanceof J?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 Cs=1e5,Br=new pt(Cs),Ur=new pt(Cs);class yr extends C.Disposable{constructor(){super(...arguments);S(this,"_currentLexerNode",new J);S(this,"_upLevel",0);S(this,"_segment","");S(this,"_bracketState",[]);S(this,"_squareBracketState",0);S(this,"_bracesState",0);S(this,"_singleQuotationState",0);S(this,"_doubleQuotationState",0);S(this,"_lambdaState",!1);S(this,"_colonState",!1);S(this,"_tableBracketState",!1)}dispose(){this._resetTemp(),this._currentLexerNode.dispose(),Br.clear(),Ur.clear()}getUpLevel(){return this._upLevel}isColonClose(){return this._colonState===!1}isColonOpen(){return this._colonState===!0}isDoubleQuotationClose(){return this._doubleQuotationState===0}isLambdaOpen(){return this._lambdaState===!0}isLambdaClose(){return this._lambdaState===!1}isSingleQuotationClose(){return this._singleQuotationState===0}isBracesClose(){return this._bracesState===0}isBracketClose(){return this._bracketState.length===0}isSquareBracketClose(){return this._squareBracketState===0}getCurrentLexerNode(){return this._currentLexerNode}getFunctionAndParameter(e,t){const s=this._getCurrentParamIndex(e,t);if(s==null||s===f.VALUE)return;const i=s[0];if(typeof i=="string")return;let a=i.getParent(),o=i;for(;a;){const u=a.getToken();if(u!==Xe&&!Ut(u)&&a.getStartIndex()!==-1){const c=a.getChildren().indexOf(o);return{functionName:u,paramIndex:c}}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 c=i[o];if(typeof c=="string"||c.nodeType!==Me.REFERENCE){a.push(c);continue}const{token:l}=c,m=wt(l),{range:d,sheetName:_,unitId:D}=m,E=C.Rectangle.moveOffset(d,t,s);let A="";C.isValidRange(E)?A=bt({range:E,unitId:D,sheetName:_}):A=f.REF,a.push({...c,token:A})}return`=${Es(a)}`}checkIfAddBracket(e){let t=0,s=e.length-1,i=e[s];for(;(i===G.CLOSE_BRACKET||i===" ")&&s>=0;)i===G.CLOSE_BRACKET&&t++,i=e[--s];const a=this._getCurrentParamIndex(e,e.length-2);if(a==null||a===f.VALUE)return 0;const o=a[0];if(typeof o=="string")return 0;let u=o.getParent(),c=0;for(a[1]===G.OPEN_BRACKET&&c++;u;){const l=u.getToken();l!==Xe&&l!==G.COLON&&u.getStartIndex()!==-1&&l.toUpperCase()!==$t&&(t===0?c+=1:t--),u=u.getParent()}return c}sequenceNodesBuilder(e){const t=Ur.get(e);if(t)return[...t];const s=this._getSequenceArray(e);if(s.length===0)return;const i=this.getSequenceNode(s);return Ur.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:c,currentString:l}=o;if(l===G.DOUBLE_QUOTATION&&(s=!0),(c!==""||i===0)&&i!==a-1){t.push(l);continue}let m=(u==null?void 0:u.segment)||"",d=i-m.length,_=i-1,D=i-1;if(i===a-1&&this._isLastMergeString(l)&&(m+=l,_+=1),m===""||rr.has(m)){t.push(l);continue}const E=m.trim(),A=this._replacePrefixString(E);if(s===!0&&E[E.length-1]===G.DOUBLE_QUOTATION)s=!1,this._pushSequenceNode(t,{nodeType:Me.STRING,token:m,startIndex:d,endIndex:_},D);else if(new RegExp(Ht).test(A)){if(A.length!==E.length){const x=E.length-A.length;D+=x,d+=x,m=this._replacePrefixString(m)}this._pushSequenceNode(t,{nodeType:Me.REFERENCE,token:m,startIndex:d,endIndex:_},D)}else C.Tools.isStringNumber(E)?this._pushSequenceNode(t,{nodeType:Me.NUMBER,token:m,startIndex:d,endIndex:_},D):E.length>0&&this._pushSequenceNode(t,{nodeType:Me.FUNCTION,token:m,startIndex:d,endIndex:_},D);(i!==a-1||!this._isLastMergeString(l))&&t.push(l)}return this._mergeSequenceNodeReference(t)}_getCurrentParamIndex(e,t){return this._nodeMaker(e,void 0,t)}_isLastMergeString(e){return e===G.DOUBLE_QUOTATION||C.Tools.isStringNumber(e)||!Ut(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()===G.CLOSE_BRACES&&o!=null&&typeof o!="string"&&o.nodeType===Me.FUNCTION&&o.token.trim().substring(0,1)===G.OPEN_BRACES){o.nodeType=Me.ARRAY,o.token+=a,o.endIndex+=a.length,i++;continue}t.push(a)}else{const o=e[i+1],u=e[i+2];o===G.COLON&&typeof a!="string"&&u!=null&&typeof u!="string"&&ds((a.token+o+u.token).trim())&&(a.nodeType=Me.REFERENCE,a.token+=o+u.token,a.endIndex=u.endIndex,i+=2),t.push(a)}i++}return t}_pushSequenceNode(e,t,s){const i=s-t.startIndex+1;e.splice(e.length-i,i,t)}_replacePrefixString(e){const t=[];let s=!1;for(let i=0,a=e.length;i<a;i++){const o=e[i];if(o===Oi&&!s)t.push(o);else{if(!s&&(o===Re.AT||o===Re.MINUS))continue;t.push(o),s=!0}}return t.join("")}nodeMakerTest(e){return this._nodeMaker(e)}treeBuilder(e,t=!0,s){if(t===!0){const l=Br.get(e);if(l)return l}this._resetCurrentLexerNode(),this._currentLexerNode.setToken(rt);const i=[];let a=this._nodeMaker(e,i);if(a===f.VALUE||i.length===0)return a;let o=!1,u="";if(s){const{hasDefinedName:l,sequenceString:m}=s(i);o=l,u=m}if(o&&(this._resetCurrentLexerNode(),this._currentLexerNode.setToken(rt),a=this._nodeMaker(`=${u}`),a===f.VALUE))return a;const c=this._getTopNode(this._currentLexerNode);if(c&&(this._currentLexerNode=c),t){if(!this._suffixExpressionHandler(this._currentLexerNode))return f.VALUE;Br.set(e,this._currentLexerNode)}return this._currentLexerNode}_suffixExpressionHandler(e){var o,u;const t=e.getChildren();if(!t)return!1;const s=t.length,i=[],a=[];for(let c=0;c<s;c++){const l=t[c];if(l instanceof J)this._suffixExpressionHandler(l),i.push(l);else{const m=l.trim();if(m==="")continue;if(lt.has(m)){if(m===pe.PLUS&&this._deletePlusForPreNode(t[c-1]))continue;if(m!==pe.PLUS&&m!==pe.MINUS&&this._deletePlusForPreNode(t[c-1]))return!1;for(;a.length>0;){const d=(o=a[a.length-1])==null?void 0:o.trim();if(!d||d===G.OPEN_BRACKET)break;const _=rr.get(d),D=rr.get(m);if(!_||!D)break;if(D>=_)i.push(a.pop());else break}a.push(l)}else if(m===G.OPEN_BRACKET)a.push(l);else if(m===G.CLOSE_BRACKET){if(this._checkOpenBracket(t[c-1])||this._checkOperator(t[c-1]))return!1;for(;a.length>0;){const d=(u=a[a.length-1])==null?void 0:u.trim();if(!d)break;if(d===G.OPEN_BRACKET){a.pop();break}i.push(a.pop())}}else{if(this._checkCloseBracket(t[c-1]))return!1;i.push(l)}}}for(;a.length>0;){const c=a.pop();if(c===G.OPEN_BRACKET||c===G.CLOSE_BRACKET)return!1;i.push(c)}return e.setChildren(i),!0}_checkCloseBracket(e){return e===G.CLOSE_BRACKET}_checkOpenBracket(e){return e===G.OPEN_BRACKET}_checkOperator(e){return e==null||e instanceof J?!1:lt.has(e)}_deletePlusForPreNode(e){if(e==null)return!0;if(!(e instanceof J)){const t=e.trim();if(lt.has(t)||t===G.OPEN_BRACKET)return!0}return!1}_resetCurrentLexerNode(){this._currentLexerNode=new J}_resetSegment(){this._segment=""}_openBracket(e=0){this._bracketState.push(e)}_closeBracket(){this._bracketState.pop()}_openSquareBracket(){this._squareBracketState+=1}_closeSquareBracket(){this._squareBracketState-=1}_getCurrentBracket(){const e=this._bracketState;return e[e.length-1]}_changeCurrentBracket(e){const t=this._bracketState;t[t.length-1]=e}_openBraces(){this._bracesState+=1}_closeBraces(){this._bracesState-=1}_openSingleQuotation(){this._singleQuotationState+=1}_closeSingleQuotation(){this._singleQuotationState-=1}_openDoubleQuotation(){this._doubleQuotationState+=1}_closeDoubleQuotation(){this._doubleQuotationState-=1}_openLambda(){this._lambdaState=!0}_closeLambda(){this._lambdaState=!1}_openColon(e){this._upLevel=e,this._colonState=!0}_closeColon(){this._upLevel=0,this._colonState=!1}_isTableBracket(){return this._tableBracketState}_openTableBracket(){this._tableBracketState=!0}_closeTableBracket(){this._tableBracketState=!1}_getLastChildCurrentLexerNode(){const e=this._currentLexerNode.getChildren();if(e&&e.length>0){const t=e[e.length-1];if(t instanceof J)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,c;const e=(s=this._currentLexerNode)==null?void 0:s.getParent();let t=!1;if(e&&e.getToken()===St){if((i=e==null?void 0:e.getParent())!=null&&i.getParent()){const l=(o=(a=this._currentLexerNode.getParent())==null?void 0:a.getParent())==null?void 0:o.getParent();l&&(this._currentLexerNode=l),t=!0}}else if(e!=null&&e.getParent()){const l=(u=this._currentLexerNode.getParent())==null?void 0:u.getParent();l&&(this._currentLexerNode=l),t=!0}for(let l=0;l<this._upLevel;l++){const m=(c=this._currentLexerNode)==null?void 0:c.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 J)&&this.isColonOpen()){const i=new J;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 J;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!!(lt.has(e)||e===G.OPEN_BRACKET||e===G.COMMA||e==="")}_getSequenceArray(e){const t=[];return this._nodeMaker(e,t),t}_resetTemp(){this._currentLexerNode=new J,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!==qe.POUND)return!0;let i=s[++t];for(;i===" ";)i=s[++t];return!!Ut(i)}_nodeMaker(e,t,s){e.substring(0,1)===pe.EQUALS&&(e=e.substring(1));let i=!1;e.substring(0,1)===pe.MINUS&&(e=`0${e}`,i=!0);const a=e.split(""),o=a.length;let u=0;for(this._resetTemp();u<o;){const c=a[u];if(s===u)return[this._currentLexerNode,c];if(c===G.OPEN_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())if(this._segmentCount()>0||this.isLambdaOpen()){this.isLambdaClose()&&(this._newAndPushCurrentLexerNode(this._segment,u),this._resetSegment()),this._openBracket(1),this._closeLambda();const l=a[u+1];if(l&&l===G.CLOSE_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;u++}else l&&this._newAndPushCurrentLexerNode(Xe,u)}else this._pushNodeToChildren(c),this._openBracket(0);else if(c===G.CLOSE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()){this._pushNodeToChildren(this._segment),this._resetSegment();const l=this._getCurrentBracket();if(l===0)this._pushNodeToChildren(c);else if(l===1){const m=a[u+1];if(m&&m===G.OPEN_BRACKET){if(!this._setParentCurrentLexerNode()&&u!==o-1)return f.VALUE;this._newAndPushCurrentLexerNode(St,u,!0),this._openLambda()}else if(!this._setAncestorCurrentLexerNode()&&u!==o-1)return f.VALUE}else return f.VALUE;this._closeBracket()}else if(c===G.OPEN_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(c),this._openBraces();else if(c===G.CLOSE_BRACES&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._pushSegment(c),this._pushNodeToChildren(this._segment),this._resetSegment(),this._closeBraces();else if(c===G.OPEN_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._segment.length>0&&this._openTableBracket(),this._pushSegment(c),this._openSquareBracket();else if(c===G.CLOSE_SQUARE_BRACKET&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose())this._closeSquareBracket(),this.isSquareBracketClose()?(this._pushSegment(c),this._isTableBracket()&&(this._pushNodeToChildren(this._segment),this._resetSegment()),this._closeTableBracket()):this._pushSegment(c);else if(c===G.DOUBLE_QUOTATION&&this.isSingleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){if(this.isDoubleQuotationClose())this._openDoubleQuotation();else{const l=a[u+1];l&&l===G.DOUBLE_QUOTATION?u++:this._closeDoubleQuotation()}this._pushSegment(c)}else if(c===G.SINGLE_QUOTATION&&this.isDoubleQuotationClose()){if(this.isSingleQuotationClose())this._openSingleQuotation();else{const l=a[u+1];l&&l===G.SINGLE_QUOTATION?u++:this._closeSingleQuotation()}this._pushSegment(c)}else if(c===G.COMMA&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=this._getCurrentBracket();if(l===1||l==null){if(this._pushNodeToChildren(this._segment),this._resetSegment(),!this._setParentCurrentLexerNode()&&u!==o-1&&l!=null)return f.VALUE;this._newAndPushCurrentLexerNode(Xe,u)}else{const m=new J;m.setToken(Ii);const d=new J;d.setToken(Xe),d.changeToParent(m);const _=this._currentLexerNode.getParent();if(_&&_.getToken()===G.COLON){const D=_.getParent();if(!D)return f.VALUE;_.changeToParent(d),D.setChildren([]),m.changeToParent(D)}else return f.VALUE;this._changeCurrentBracket(1),this._pushNodeToChildren(this._segment),this._resetSegment(),this._currentLexerNode=m,this._newAndPushCurrentLexerNode(Xe,u)}}else if(c===G.COLON&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isBracesClose()&&this.isSquareBracketClose()){const l=new J;l.setToken(c);const m=new J;m.setToken(Xe),m.setParent(l);const d=new J;d.setToken(Xe),d.setParent(l),l.getChildren().push(m,d);let _=l,D=0;if(this._segmentCount()>0){let E,A,x=0;const w=this._segment.trim(),U=w[0],$=w[1];if(U===Re.MINUS&&(E=new J,E.setToken(Re.MINUS),x++),(U===Re.AT||$===Re.AT)&&(A=new J,A.setToken(Re.AT),E&&(E.addChildren(A),A.setParent(E)),x++),x>0&&(this._segment=w.slice(x)),D=x,A)if(A.addChildren(l),l.setParent(A),A.getParent()){const he=A.getParent();he&&(_=he)}else _=A;else E&&(_=E,E.addChildren(l),l.setParent(E));const se=new J;se.setToken(this._segment),se.setParent(m),m.getChildren().push(se),this._resetSegment()}else{const E=this._getLastChildCurrentLexerNode();E&&E.changeToParent(m)}this._setCurrentLexerNode(_),this._currentLexerNode=d,this._openColon(D)}else if(Mi.has(c)&&this._checkSimilarErrorToken(c,u,a)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){this._pushNodeToChildren(this._segment);const l=new J;l.setToken(c);const m=this._getLastChildCurrent();m instanceof J?m.changeToParent(l):m!==!1&&(l.getChildren().push(m),this._removeLastChild()),this._pushNodeToChildren(l),l.setParent(this._currentLexerNode),this._resetSegment()}else if(lt.has(c)&&this.isSingleQuotationClose()&&this.isDoubleQuotationClose()&&this.isSquareBracketClose()){let l=this._segment.trim();if(c===pe.MINUS&&l===""){const m=this._findPreviousToken(a,u-1)||"";if(this._negativeCondition(m)){this._pushSegment(pe.MINUS),i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}}else if(this._segment.length>0&&a[u-1]&&a[u-1].toUpperCase()==="E"&&(c===pe.MINUS||c===pe.PLUS)){this._pushSegment(c),i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++;continue}else this._segment.length>0&&l===""?l=this._segment:(this._pushNodeToChildren(this._segment),l="");if(c===pe.LESS_THAN||c===pe.GREATER_THAN){const m=a[u+1];m&&lt.has(c+m)?(this._pushNodeToChildren(l+c+m),u++):this._pushNodeToChildren(l+c)}else this._pushNodeToChildren(l+c);this._resetSegment()}else this._pushSegment(c);i&&u===0||t==null||t.push({segment:this._segment,currentString:c,cur:u,currentLexerNode:this._currentLexerNode}),u++}this._pushNodeToChildren(this._segment)}}var Xi=Object.defineProperty,Ki=Object.getOwnPropertyDescriptor,qi=(r,n,e,t)=>{for(var s=t>1?void 0:t?Ki(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&&Xi(n,e,s),s},Mn=(r,n)=>(e,t)=>n(e,t,r);exports.FormulaDataModel=class extends C.Disposable{constructor(e,t){super();S(this,"_formulaData",{});S(this,"_arrayFormulaRange",{});S(this,"_arrayFormulaCellData",{});S(this,"_numfmtItemMap",{});this._currentUniverService=e,this._lexerTreeBuilder=t}clearPreviousArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{var c,l,m,d;const a=s[i],o=(l=(c=this._arrayFormulaRange)==null?void 0:c[t])==null?void 0:l[i];if(o==null)return!0;let u=new C.ObjectMatrix;((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new C.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((_,D)=>{var $;const E=($=o==null?void 0:o[_])==null?void 0:$[D];if(E==null)return!0;const{startRow:A,startColumn:x,endRow:w,endColumn:U}=E;for(let se=A;se<=w;se++)for(let he=x;he<=U;he++)u.setValue(se,he,null)}),this._arrayFormulaCellData[t]&&(this._arrayFormulaCellData[t][i]=u.getData())})})}mergeArrayFormulaCellData(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;this._arrayFormulaRange[t]==null&&(this._arrayFormulaRange[t]={}),this._arrayFormulaCellData[t]==null&&(this._arrayFormulaCellData[t]={}),Object.keys(s).forEach(i=>{var c,l,m,d;const a=s[i];let o=new C.ObjectMatrix,u=new C.ObjectMatrix;((c=this._arrayFormulaRange[t])==null?void 0:c[i])!=null&&(o=new C.ObjectMatrix((l=this._arrayFormulaRange[t])==null?void 0:l[i])),((m=this._arrayFormulaCellData[t])==null?void 0:m[i])!=null&&(u=new C.ObjectMatrix((d=this._arrayFormulaCellData[t])==null?void 0:d[i])),a.forValue((_,D)=>{const E=o==null?void 0:o.getValue(_,D);if(E==null)return!0;const{startRow:A,startColumn:x,endRow:w,endColumn:U}=E;for(let $=A;$<=w;$++)for(let se=x;se<=U;se++)u.setValue($,se,null)}),a.forValue((_,D,E)=>{u.setValue(_,D,E)}),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 C.ObjectMatrix(a);this._numfmtItemMap[t][i]==null&&(this._numfmtItemMap[t][i]={}),o.forValue((u,c,l)=>{this._numfmtItemMap[t][i][u]==null&&(this._numfmtItemMap[t][i][u]={}),this._numfmtItemMap[t][i][u][c]=l})})})}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,c;const a=new C.ObjectMatrix(s[i]);let o=new C.ObjectMatrix;(u=this._arrayFormulaRange[t])!=null&&u[i]&&(o=new C.ObjectMatrix((c=this._arrayFormulaRange[t])==null?void 0:c[i])),a.forValue((l,m,d)=>{o.setValue(l,m,d)}),this._arrayFormulaRange[t]&&(this._arrayFormulaRange[t][i]=o.getData())})})}deleteArrayFormulaRange(e,t,s,i){var u;const a=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(a==null)return;const o=new C.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();ys(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={},c={};for(const l of o){const m=l.getSheetId(),d=l.getConfig();u[m]={cellData:new C.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},c[l.getName()]=l.getSheetId()}t[a]=u,s[a]=c}return{allUnitData:t,unitSheetNameMap:s}}updateFormulaData(e,t,s){const i=new C.ObjectMatrix(s),a=this.getFormulaIdMap(e,t),o=new Map,u=this._formulaData;u[e]==null&&(u[e]={});const c=u[e];c[t]==null&&(c[t]={});const l=new C.ObjectMatrix(c[t]);i.forValue((m,d,_)=>{const D=(_==null?void 0:_.f)||"",E=(_==null?void 0:_.si)||"",A=C.isFormulaString(D),x=C.isFormulaId(E);if(A&&x)l.setValue(m,d,{f:D,si:E}),a.set(E,{f:D,r:m,c:d});else if(A&&!x)l.setValue(m,d,{f:D});else if(!A&&x)l.setValue(m,d,{f:"",si:E});else if(!A&&!x&&l.getValue(m,d)){const w=l.getValue(m,d),U=(w==null?void 0:w.f)||"",$=(w==null?void 0:w.si)||"";C.isFormulaString(U)&&C.isFormulaId($)&&o.set($,U),l.realDeleteValue(m,d)}}),l.forValue((m,d,_)=>{const D=(_==null?void 0:_.f)||"",E=(_==null?void 0:_.si)||"";if(C.isFormulaId(E)){const A=a.get(E),x=o.get(E);if(A&&!C.isFormulaString(D)){const w=A.f,U=d-A.c,$=m-A.r;l.setValue(m,d,{f:w,si:E,x:U,y:$})}else if(typeof x=="string"){const w=_.x||0,U=_.y||0,$=this._lexerTreeBuilder.moveFormulaRefOffset(x,w,U);o.set(E,{r:m,c:d,f:$}),l.setValue(m,d,{f:$,si:E})}else if(typeof x=="object"){const w=d-x.c,U=m-x.r;l.setValue(m,d,{f:x.f,si:E,x:w,y:U})}}})}updateArrayFormulaRange(e,t,s){var u;const i=(u=this._arrayFormulaRange[e])==null?void 0:u[t];if(!i)return;const a=new C.ObjectMatrix(i);new C.ObjectMatrix(s).forValue((c,l,m)=>{if((a==null?void 0:a.getValue(c,l))==null)return!0;const _=(m==null?void 0:m.f)||"",D=(m==null?void 0:m.si)||"",E=C.isFormulaString(_),A=C.isFormulaId(D);!E&&!A&&a.realDeleteValue(c,l)})}updateArrayFormulaCellData(e,t,s){var l,m;const i=(l=this._arrayFormulaRange[e])==null?void 0:l[t];if(!i)return;const a=new C.ObjectMatrix(i),o=(m=this._arrayFormulaCellData[e])==null?void 0:m[t];if(!o)return;const u=new C.ObjectMatrix(o);new C.ObjectMatrix(s).forValue((d,_,D)=>{const E=a==null?void 0:a.getValue(d,_);if(E==null)return!0;const A=(D==null?void 0:D.f)||"",x=(D==null?void 0:D.si)||"",w=C.isFormulaString(A),U=C.isFormulaId(x);if(!w&&!U){const{startRow:$,startColumn:se,endRow:he,endColumn:de}=E;for(let q=$;q<=he;q++)for(let z=se;z<=de;z++)u.realDeleteValue(q,z)}})}updateNumfmtData(e,t,s){var l,m;const i=(l=this._arrayFormulaRange[e])==null?void 0:l[t],a=new C.ObjectMatrix(i),o=(m=this._numfmtItemMap[e])==null?void 0:m[t];if(!o)return;const u=new C.ObjectMatrix(o);new C.ObjectMatrix(s).forValue((d,_,D)=>{const E=(D==null?void 0:D.f)||"",A=(D==null?void 0:D.si)||"",x=C.isFormulaString(E),w=C.isFormulaId(A);if(!x&&!w){u.setValue(d,_,null);const U=a.getValue(d,_);if(U){const{startRow:$,startColumn:se,endRow:he,endColumn:de}=U;for(let q=$;q<=he;q++)for(let z=se;z<=de;z++)u.setValue(q,z,null)}}})}getFormulaItemBySId(e,t,s){const i=this._formulaData;if(i[s]==null)return null;const a=i[s];if((a==null?void 0:a[t])==null)return null;const o=new C.ObjectMatrix(a[t]);let u=null;return o.forValue((c,l,m)=>{const{f:d,si:_,x:D=0,y:E=0}=m;if(_===e&&d.length>0&&D===0&&E===0)return u=m,!1}),u}getFormulaDataItem(e,t,s,i){var a,o,u,c;return(c=(u=(o=(a=this._formulaData)==null?void 0:a[i])==null?void 0:o[s])==null?void 0:u[e])==null?void 0:c[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 C.ObjectMatrix(a[t]).forValue((u,c,l)=>{const m=(l==null?void 0:l.f)||"",d=(l==null?void 0:l.si)||"",_=(l==null?void 0:l.x)||0,D=(l==null?void 0:l.y)||0;C.isFormulaString(m)&&C.isFormulaId(d)&&_===0&&D===0&&s.set(d,{f:m,r:u,c})}),s}};exports.FormulaDataModel=qi([Mn(0,C.IUniverInstanceService),Mn(1,N.Inject(yr))],exports.FormulaDataModel);function ys(r,n,e,t){const s=new Map,i=new C.ObjectMatrix;t.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"",m=C.isFormulaString(c),d=C.isFormulaId(l);m&&d?(i.setValue(a,o,{f:c,si:l}),s.set(l,{f:c,r:a,c:o})):m&&!d?i.setValue(a,o,{f:c}):!m&&d&&i.setValue(a,o,{f:"",si:l})}),i.forValue((a,o,u)=>{const c=(u==null?void 0:u.f)||"",l=(u==null?void 0:u.si)||"";if(C.isFormulaId(l)&&!C.isFormulaString(c)){const m=s.get(l);if(m){const d=m.f,_=o-m.c,D=a-m.r;i.setValue(a,o,{f:d,si:l,x:_,y:D})}}}),r[n]&&(r[n][e]=i.getData())}const Zi=r=>{const n=r.get(exports.FormulaDataModel),e=C.Tools.deepClone(n.getArrayFormulaRange()),t=C.Tools.deepClone(n.getArrayFormulaCellData());return{arrayFormulaRange:e,arrayFormulaCellData:t}},lr={id:"formula.mutation.set-array-formula-data",type:C.CommandType.MUTATION,handler:(r,n)=>{const e=r.get(exports.FormulaDataModel);return e.setArrayFormulaRange(n.arrayFormulaRange),e.setArrayFormulaCellData(n.arrayFormulaCellData),!0}},Dr={id:"formula.mutation.set-defined-name",type:C.CommandType.MUTATION,handler:()=>!0},br={id:"formula.mutation.remove-defined-name",type:C.CommandType.MUTATION,handler:()=>!0},Kr={id:"formula.mutation.set-feature-calculation",type:C.CommandType.MUTATION,handler:()=>!0},qr={id:"formula.mutation.remove-feature-calculation",type:C.CommandType.MUTATION,handler:()=>!0},Zr={id:"formula.mutation.set-formula-calculation-start",type:C.CommandType.MUTATION,handler:()=>!0},Jr={id:"formula.mutation.set-formula-calculation-stop",type:C.CommandType.MUTATION,handler:()=>!0},fr={id:"formula.mutation.set-formula-calculation-notification",type:C.CommandType.MUTATION,handler:()=>!0},Nr={id:"formula.mutation.set-formula-calculation-result",type:C.CommandType.MUTATION,handler:()=>!0},en={id:"formula.mutation.set-formula-data",type:C.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).setFormulaData(n.formulaData),!0)},tn={id:"formula.mutation.set-other-formula",type:C.CommandType.MUTATION,handler:()=>!0},rn={id:"formula.mutation.remove-other-formula",type:C.CommandType.MUTATION,handler:()=>!0},Ds={id:"formula.mutation.set-super-table",type:C.CommandType.MUTATION,handler:()=>!0},bs={id:"formula.mutation.remove-super-table",type:C.CommandType.MUTATION,handler:()=>!0},nn={id:"formula.mutation.set-super-table-option",type:C.CommandType.MUTATION,handler:()=>!0},sn={id:"formula.mutation.unregister-function",type:C.CommandType.MUTATION,handler:()=>!0};class Sr extends C.Disposable{constructor(){super(...arguments);S(this,"pattern","")}getPattern(){return this.pattern}setPattern(e){this.pattern=e}isError(){return!1}isAsyncObject(){return!1}isAsyncArrayObject(){return!1}isReferenceObject(){return!1}isArray(){return!1}isValueObject(){return!1}isEqualType(e){return!1}}var st=(r=>(r.FALSE="FALSE",r.TRUE="TRUE",r))(st||{}),ht=(r=>(r[r.SUCCESS=0]="SUCCESS",r[r.ERROR=1]="ERROR",r))(ht||{}),ft=(r=>(r.ALL="#All",r.DATA="#Data",r.HEADERS="#Headers",r.TOTALS="#Totals",r))(ft||{}),Te=(r=>(r[r.FRONT=0]="FRONT",r[r.BACK=1]="BACK",r))(Te||{});class Ji{constructor(){S(this,"_cache",new Map);S(this,"_continueBuildingCache",new Map)}set(n,e,t,s,i){if(!this.shouldContinueBuildingCache(n,e,t,i))return;let a=this._cache.get(n);a==null&&(a=new Map,this._cache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);u==null&&(u=new Map,o.set(t,u));let c=u.get(s);c==null&&(c=new Set,u.set(s,c)),c.add(i)}getCellValuePositions(n,e,t){var s,i;return(i=(s=this._cache.get(n))==null?void 0:s.get(e))==null?void 0:i.get(t)}getCellPositions(n,e,t,s){var i,a,o;return(o=(a=(i=this._cache.get(n))==null?void 0:i.get(e))==null?void 0:a.get(t))==null?void 0:o.get(s)}getCellPosition(n,e,t,s,i,a){const o=this.getCellPositions(n,e,t,s);if(o!=null){for(const u of o)if(u>=i&&u<=a)return u}}setContinueBuildingCache(n,e,t,s,i){let a=this._continueBuildingCache.get(n);a==null&&(a=new Map,this._continueBuildingCache.set(n,a));let o=a.get(e);o==null&&(o=new Map,a.set(e,o));let u=o.get(t);if(u==null){u={startRow:s,endRow:i},o.set(t,u);return}u.startRow=Math.min(u.startRow,s),u.endRow=Math.max(u.endRow,i)}shouldContinueBuildingCache(n,e,t,s){var u,c;const i=(c=(u=this._continueBuildingCache.get(n))==null?void 0:u.get(e))==null?void 0:c.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 c,l;if(t===-1||s===-1||i===-1)return!1;const a=(l=(c=this._continueBuildingCache.get(n))==null?void 0:c.get(e))==null?void 0:l.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 Ne=new Ji;var Ke=(r=>(r[r.MIN=0]="MIN",r[r.MAX=1]="MAX",r))(Ke||{}),xe=(r=>(r[r.NORMAL=0]="NORMAL",r[r.MIN=1]="MIN",r[r.MAX=2]="MAX",r))(xe||{});function On(){return Intl&&Intl.Collator?new Intl.Collator(void 0,{numeric:!1}).compare:(r,n)=>r.localeCompare(n)}function Ni(r){return r.indexOf("*")>-1||r.indexOf("?")>-1}function Fn(r,n){const e=ta(n).replace(/~?[*?]/g,s=>s.startsWith("~")?`\\${s.substring(1)}`:s==="*"?".*":s==="?"?".":s);return new RegExp(`^${e}$`).test(r)}function Bn(r){return r.replace(/~?[*?]/g,n=>n.startsWith("~")?n.substring(1):" ")}function ea(r,n,e){let t=!1;switch(e){case F.EQUALS:t=Fn(r,n);break;case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:t=Fn(r,n)||r>Bn(n);break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:t=r<Bn(n);break}return t}function ta(r){return r.replace(/[.+^${}()|[\]\\]/g,"\\$&")}class Ze extends Sr{constructor(n){super(),this._rawValue=n}isValueObject(){return!0}toUnitRange(){return{range:{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1},sheetId:"",unitId:""}}getValue(){return 0}getArrayValue(){return[]}setValue(n){}setArrayValue(n){}isCube(){return!1}isString(){return!1}isNumber(){return!1}isBoolean(){return!1}isLambda(){return!1}isError(){return!1}isNull(){return!1}sum(){return h.create(f.VALUE)}max(){return h.create(f.VALUE)}min(){return h.create(f.VALUE)}count(){return h.create(f.VALUE)}countA(){return h.create(f.VALUE)}countBlank(){return h.create(f.VALUE)}getNegative(){return h.create(f.VALUE)}getReciprocal(){return h.create(f.VALUE)}plus(n){return h.create(f.VALUE)}minus(n){return h.create(f.VALUE)}multiply(n){return h.create(f.VALUE)}divided(n){return h.create(f.VALUE)}mod(n){return h.create(f.VALUE)}map(n){return h.create(f.NAME)}mapValue(n){return h.create(f.NAME)}compare(n,e){return h.create(f.NAME)}isEqual(n){return this.compare(n,F.EQUALS)}isNotEqual(n){return this.compare(n,F.NOT_EQUAL)}isGreaterThanOrEqual(n){return this.compare(n,F.GREATER_THAN_OR_EQUAL)}isLessThanOrEqual(n){return this.compare(n,F.LESS_THAN_OR_EQUAL)}isLessThan(n){return this.compare(n,F.LESS_THAN)}isGreaterThan(n){return this.compare(n,F.GREATER_THAN)}concatenateFront(n){return h.create(f.NAME)}concatenateBack(n){return h.create(f.NAME)}plusBy(n){return h.create(f.VALUE)}minusBy(n){return h.create(f.VALUE)}multiplyBy(n){return h.create(f.VALUE)}dividedBy(n){return h.create(f.VALUE)}modInverse(n){return h.create(f.VALUE)}compareBy(n,e){return h.create(f.NAME)}concatenate(n,e=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 h.create(f.VALUE)}powInverse(n){return h.create(f.VALUE)}sqrt(){return h.create(f.VALUE)}cbrt(){return h.create(f.VALUE)}cos(){return h.create(f.VALUE)}acos(){return h.create(f.VALUE)}acosh(){return h.create(f.VALUE)}sin(){return h.create(f.VALUE)}asin(){return h.create(f.VALUE)}asinh(){return h.create(f.VALUE)}tan(){return h.create(f.VALUE)}tanh(){return h.create(f.VALUE)}atan(){return h.create(f.VALUE)}atan2(n){return h.create(f.VALUE)}atan2Inverse(n){return h.create(f.VALUE)}atanh(){return h.create(f.VALUE)}mean(){return this}median(){return this}var(){return this}std(){return this}log(){return h.create(f.VALUE)}log10(){return h.create(f.VALUE)}exp(){return h.create(f.VALUE)}abs(){return h.create(f.VALUE)}round(n){return h.create(f.VALUE)}roundInverse(n){return h.create(f.VALUE)}floor(n){return h.create(f.VALUE)}floorInverse(n){return h.create(f.VALUE)}ceil(n){return h.create(f.VALUE)}ceilInverse(n){return h.create(f.VALUE)}convertToNumberObjectValue(){return h.create(f.VALUE)}convertToBooleanObjectValue(){return h.create(f.VALUE)}}const ra=1e3,Un=new pt(ra);class h extends Ze{constructor(n,e=""){super(n),this._errorType=n,this._errorContent=e}static create(n,e=""){const t=`${n}-${e}`,s=Un.get(t);if(s)return s;const i=new h(n,e);return Un.set(t,i),i}getValue(){return this._errorType}getErrorType(){return this._errorType}getErrorContent(){return this._errorContent}isEqualType(n){return n.getErrorType()===this.getErrorType()}isError(){return!0}}var na=20,sa=1,gt=1e6,kn=1e6,ia=-7,aa=21,oa=!1,Gt="[big.js] ",Rt=Gt+"Invalid ",Ar=Rt+"decimal places",ua=Rt+"rounding mode",Ss=Gt+"Division by zero",fe={},Ye=void 0,ca=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function As(){function r(n){var e=this;if(!(e instanceof r))return n===Ye?As():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(Rt+"value");n=n===0&&1/n<0?"-0":String(n)}la(e,n)}e.constructor=r}return r.prototype=fe,r.DP=na,r.RM=sa,r.NE=ia,r.PE=aa,r.strict=oa,r.roundDown=0,r.roundHalfUp=1,r.roundHalfEven=2,r.roundUp=3,r}function la(r,n){var e,t,s;if(!ca.test(n))throw Error(Rt+"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 _t(r,n,e,t){var s=r.c;if(e===Ye&&(e=r.constructor.RM),e!==0&&e!==1&&e!==2&&e!==3)throw Error(ua);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]!==Ye))),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]!==Ye||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 Pt(r,n,e){var t=r.e,s=r.c.join(""),i=s.length;if(n)s=s.charAt(0)+(i>1?"."+s.slice(1):"")+(t<0?"e":"e+")+t;else if(t<0){for(;++t;)s="0"+s;s="0."+s}else if(t>0)if(++t>i)for(t-=i;t--;)s+="0";else t<i&&(s=s.slice(0,t)+"."+s.slice(t));else i>1&&(s=s.charAt(0)+"."+s.slice(1));return r.s<0&&e?"-"+s:s}fe.abs=function(){var r=new this.constructor(this);return r.s=1,r};fe.cmp=function(r){var n,e=this,t=e.c,s=(r=new e.constructor(r)).c,i=e.s,a=r.s,o=e.e,u=r.e;if(!t[0]||!s[0])return t[0]?i:s[0]?-a:0;if(i!=a)return i;if(n=i<0,o!=u)return o>u^n?1:-1;for(a=(o=t.length)<(u=s.length)?o:u,i=-1;++i<a;)if(t[i]!=s[i])return t[i]>s[i]^n?1:-1;return o==u?0:o>u^n?1:-1};fe.div=function(r){var n=this,e=n.constructor,t=n.c,s=(r=new e(r)).c,i=n.s==r.s?1:-1,a=e.DP;if(a!==~~a||a<0||a>gt)throw Error(Ar);if(!s[0])throw Error(Ss);if(!t[0])return r.s=i,r.c=[r.e=0],r;var o,u,c,l,m,d=s.slice(),_=o=s.length,D=t.length,E=t.slice(0,o),A=E.length,x=r,w=x.c=[],U=0,$=a+(x.e=n.e-r.e)+1;for(x.s=i,i=$<0?0:$,d.unshift(0);A++<o;)E.push(0);do{for(c=0;c<10;c++){if(o!=(A=E.length))l=o>A?1:-1;else for(m=-1,l=0;++m<o;)if(s[m]!=E[m]){l=s[m]>E[m]?1:-1;break}if(l<0){for(u=A==o?s:d;A;){if(E[--A]<u[A]){for(m=A;m&&!E[--m];)E[m]=9;--E[m],E[A]+=10}E[A]-=u[A]}for(;!E[0];)E.shift()}else break}w[U++]=l?c:++c,E[0]&&l?E[A]=t[_]||0:E=[t[_]]}while((_++<D||E[0]!==Ye)&&i--);return!w[0]&&U!=1&&(w.shift(),x.e--,$--),U>$&&_t(x,$,e.RM,E[0]!==Ye),x};fe.eq=function(r){return this.cmp(r)===0};fe.gt=function(r){return this.cmp(r)>0};fe.gte=function(r){return this.cmp(r)>-1};fe.lt=function(r){return this.cmp(r)<0};fe.lte=function(r){return this.cmp(r)<1};fe.minus=fe.sub=function(r){var n,e,t,s,i=this,a=i.constructor,o=i.s,u=(r=new a(r)).s;if(o!=u)return r.s=-u,i.plus(r);var c=i.c.slice(),l=i.e,m=r.c,d=r.e;if(!c[0]||!m[0])return m[0]?r.s=-u:c[0]?r=new a(i):r.s=1,r;if(o=l-d){for((s=o<0)?(o=-o,t=c):(d=l,t=m),t.reverse(),u=o;u--;)t.push(0);t.reverse()}else for(e=((s=c.length<m.length)?c:m).length,o=u=0;u<e;u++)if(c[u]!=m[u]){s=c[u]<m[u];break}if(s&&(t=c,c=m,m=t,r.s=-r.s),(u=(e=m.length)-(n=c.length))>0)for(;u--;)c[n++]=0;for(u=n;e>o;){if(c[--e]<m[e]){for(n=e;n&&!c[--n];)c[n]=9;--c[n],c[e]+=10}c[e]-=m[e]}for(;c[--u]===0;)c.pop();for(;c[0]===0;)c.shift(),--d;return c[0]||(r.s=1,c=[d=0]),r.c=c,r.e=d,r};fe.mod=function(r){var n,e=this,t=e.constructor,s=e.s,i=(r=new t(r)).s;if(!r.c[0])throw Error(Ss);return e.s=r.s=1,n=r.cmp(e)==1,e.s=s,r.s=i,n?new t(e):(s=t.DP,i=t.RM,t.DP=t.RM=0,e=e.div(r),t.DP=s,t.RM=i,this.minus(e.times(r)))};fe.neg=function(){var r=new this.constructor(this);return r.s=-r.s,r};fe.plus=fe.add=function(r){var n,e,t,s=this,i=s.constructor;if(r=new i(r),s.s!=r.s)return r.s=-r.s,s.minus(r);var a=s.e,o=s.c,u=r.e,c=r.c;if(!o[0]||!c[0])return c[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=c):(n=-n,t=o),t.reverse();n--;)t.push(0);t.reverse()}for(o.length-c.length<0&&(t=c,c=o,o=t),n=c.length,e=0;n;o[n]%=10)e=(o[--n]=o[n]+c[n]+e)/10|0;for(e&&(o.unshift(e),++u),n=o.length;o[--n]===0;)o.pop();return r.c=o,r.e=u,r};fe.pow=function(r){var n=this,e=new n.constructor("1"),t=e,s=r<0;if(r!==~~r||r<-kn||r>kn)throw Error(Rt+"exponent");for(s&&(r=-r);r&1&&(t=t.times(n)),r>>=1,!!r;)n=n.times(n);return s?e.div(t):t};fe.prec=function(r,n){if(r!==~~r||r<1||r>gt)throw Error(Rt+"precision");return _t(new this.constructor(this),r,n)};fe.round=function(r,n){if(r===Ye)r=0;else if(r!==~~r||r<-gt||r>gt)throw Error(Ar);return _t(new this.constructor(this),r+this.e+1,n)};fe.sqrt=function(){var r,n,e,t=this,s=t.constructor,i=t.s,a=t.e,o=new s("0.5");if(!t.c[0])return new s(t);if(i<0)throw Error(Gt+"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 _t(r,(s.DP-=4)+r.e+1,s.RM)};fe.times=fe.mul=function(r){var n,e=this,t=e.constructor,s=e.c,i=(r=new t(r)).c,a=s.length,o=i.length,u=e.e,c=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+c,a<o&&(n=s,s=i,i=n,c=a,a=o,o=c),n=new Array(c=a+o);c--;)n[c]=0;for(u=o;u--;){for(o=0,c=a+u;c>u;)o=n[c]+i[u]*s[c-u-1]+o,n[c--]=o%10,o=o/10|0;n[c]=o}for(o?++r.e:n.shift(),u=n.length;!n[--u];)n.pop();return r.c=n,r};fe.toExponential=function(r,n){var e=this,t=e.c[0];if(r!==Ye){if(r!==~~r||r<0||r>gt)throw Error(Ar);for(e=_t(new e.constructor(e),++r,n);e.c.length<r;)e.c.push(0)}return Pt(e,!0,!!t)};fe.toFixed=function(r,n){var e=this,t=e.c[0];if(r!==Ye){if(r!==~~r||r<0||r>gt)throw Error(Ar);for(e=_t(new e.constructor(e),r+e.e+1,n),r=r+e.e+1;e.c.length<r;)e.c.push(0)}return Pt(e,!1,!!t)};fe[Symbol.for("nodejs.util.inspect.custom")]=fe.toJSON=fe.toString=function(){var r=this,n=r.constructor;return Pt(r,r.e<=n.NE||r.e>=n.PE,!!r.c[0])};fe.toNumber=function(){var r=Number(Pt(this,!0,!0));if(this.constructor.strict===!0&&!this.eq(r.toString()))throw Error(Gt+"Imprecise conversion");return r};fe.toPrecision=function(r,n){var e=this,t=e.constructor,s=e.c[0];if(r!==Ye){if(r!==~~r||r<1||r>gt)throw Error(Rt+"precision");for(e=_t(new t(e),r,n);e.c.length<r;)e.c.push(0)}return Pt(e,r<=e.e||e.e<=t.NE||e.e>=t.PE,!!s)};fe.valueOf=function(){var r=this,n=r.constructor;if(n.strict===!0)throw Error(Gt+"valueOf disallowed");return Pt(r,r.e<=n.NE||r.e>=n.PE,!0)};var Ce=As();function Ls(r){let n;switch(r){case F.EQUALS:n=F.EQUALS;break;case F.GREATER_THAN:n=F.LESS_THAN;break;case F.GREATER_THAN_OR_EQUAL:n=F.LESS_THAN_OR_EQUAL;break;case F.LESS_THAN:n=F.GREATER_THAN;break;case F.LESS_THAN_OR_EQUAL:n=F.GREATER_THAN_OR_EQUAL;break;case F.NOT_EQUAL:n=F.NOT_EQUAL;break}return n}function an(r,n){return Ce(r).times(n).toNumber()}function Tn(r,n){const e=10**Math.floor(n);return Math.round(an(r,e))/e}function jn(r,n){const e=10**Math.floor(n);return Math.floor(an(r,e))/e}function $n(r,n){const e=10**Math.floor(n);return Math.ceil(an(r,e))/e}function In(r,n){const e=new Ce(r),t=new Ce(n),s=Math.floor(r/n);return e.minus(t.times(s)).toNumber()}function Yn(r,n){return r**n}const Cr=class Cr extends Ze{static create(){return this._instance=this._instance||new Cr(0),this._instance}isNull(){return!0}plus(n){return b.create(0).plus(n)}minus(n){return b.create(0).minus(n)}multiply(n){return b.create(0).multiply(n)}divided(n){return b.create(0).divided(n)}mod(n){return b.create(0).mod(n)}compare(n,e){return n.isString()?_e.create("").compare(n,e):n.isBoolean()?Q.create(!1).compare(n,e):b.create(0).compare(n,e)}concatenateFront(n){return n.isArray()?n.concatenateBack(_e.create("")):_e.create(this.concatenate(n.getValue(),Te.FRONT))}concatenateBack(n){return n.isArray()?n.concatenateFront(_e.create("")):_e.create(this.concatenate(n.getValue(),Te.BACK))}plusBy(n){return b.create(0).plusBy(n)}minusBy(n){return b.create(0).minusBy(n)}multiplyBy(n){return b.create(0).multiplyBy(n)}dividedBy(n){return b.create(0).dividedBy(n)}compareBy(n,e){return typeof n=="string"?_e.create("").compareBy(n,e):typeof n=="boolean"?Q.create(!1).compareBy(n,e):b.create(0).compareBy(n,e)}pow(n){return b.create(0).pow(n)}sqrt(){return b.create(0).sqrt()}cbrt(){return b.create(0).cbrt()}cos(){return b.create(0).cos()}acos(){return b.create(0).acos()}acosh(){return b.create(0).acosh()}sin(){return b.create(0).sin()}asin(){return b.create(0).asin()}asinh(){return b.create(0).asinh()}tan(){return b.create(0).tan()}tanh(){return b.create(0).tanh()}atan(){return b.create(0).atan()}atan2(n){return b.create(0).atan2(n)}atanh(){return b.create(0).atanh()}log(){return h.create(f.NUM)}log10(){return h.create(f.NUM)}exp(){return b.create(0).exp()}abs(){return b.create(0).abs()}round(n){return b.create(0).round(n)}floor(n){return b.create(0).floor(n)}ceil(n){return b.create(0).ceil(n)}convertToNumberObjectValue(){return b.create(0)}convertToBooleanObjectValue(){return Q.create(!1)}};S(Cr,"_instance");let ce=Cr;const Dt=class Dt extends Ze{constructor(e){super(e);S(this,"_value",!1);this._value=e}static create(e){return e?(this._instanceTrue=this._instanceTrue||new Dt(!0),this._instanceTrue):(this._instanceFalse=this._instanceFalse||new Dt(!1),this._instanceFalse)}getValue(){return this._value}isBoolean(){return!0}getNegative(){const e=this.getValue();let t=0;return e&&(t=1),b.create(-t)}getReciprocal(){return this.getValue()?b.create(1):h.create(f.DIV_BY_ZERO)}plus(e){return this._convertTonNumber().plus(e)}minus(e){return this._convertTonNumber().minus(e)}multiply(e){return this._convertTonNumber().multiply(e)}divided(e){return this._convertTonNumber().divided(e)}mod(e){return this._convertTonNumber().mod(e)}compare(e,t){return this._convertTonNumber().compare(e,t)}concatenateFront(e){return this._convertTonNumber().concatenateFront(e)}concatenateBack(e){return this._convertTonNumber().concatenateBack(e)}_convertTonNumber(){const e=this.getValue();let t=0;return e&&(t=1),b.create(t)}pow(e){return this._convertTonNumber().pow(e)}sqrt(){return this._convertTonNumber().sqrt()}cbrt(){return this._convertTonNumber().cbrt()}cos(){return this._convertTonNumber().cos()}acos(){return this._convertTonNumber().acos()}acosh(){return this._convertTonNumber().acosh()}sin(){return this._convertTonNumber().sin()}asin(){return this._convertTonNumber().asin()}asinh(){return this._convertTonNumber().asinh()}tan(){return this._convertTonNumber().tan()}tanh(){return this._convertTonNumber().tanh()}atan(){return this._convertTonNumber().atan()}atan2(e){return this._convertTonNumber().atan2(e)}atanh(){return this._convertTonNumber().atanh()}log(){return this._convertTonNumber().log()}log10(){return this._convertTonNumber().log10()}exp(){return this._convertTonNumber().exp()}abs(){return this._convertTonNumber().abs()}round(e){return this._convertTonNumber().round(e)}floor(e){return this._convertTonNumber().floor(e)}ceil(e){return this._convertTonNumber().ceil(e)}convertToNumberObjectValue(){return xr(this.getValue())}convertToBooleanObjectValue(){return this}};S(Dt,"_instanceTrue"),S(Dt,"_instanceFalse");let Q=Dt;const fa=2e5,zn=new pt(fa);class b extends Ze{constructor(e){super(e);S(this,"_value",0);this._value=Number(e)}static create(e,t=""){const s=`${e}-${t}`,i=zn.get(s);if(i)return i;const a=new b(e);return a.setPattern(t),zn.set(s,a),a}getValue(){return this._value}setValue(e){this._value=e}isNumber(){return!0}getNegative(){return b.create(0).minus(this)}getReciprocal(){return b.create(1).divided(this)}plus(e){if(e.isArray())return e.plus(this);const t=this.plusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}equalZero(){return this._value===0}minus(e){if(e.isArray()){const s=e.getNegative();return s.isError()?s:s.plus(this)}const t=this.minusBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}multiply(e){if(e.isArray())return e.multiply(this);const t=this.multiplyBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}divided(e){if(e.isArray()){const s=e.getReciprocal();return s.isError()?s:s.multiply(this)}const t=this.dividedBy(e.getValue());return t.isError()||t.setPattern(this.getPattern()||e.getPattern()),t}mod(e){if(e.isArray())return e.modInverse(this);const t=this.getValue(),s=e.getValue();if(e.isNull())return h.create(f.DIV_BY_ZERO);if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(s===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=In(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}if(typeof s=="boolean"){const i=s?1:0;return i===0?h.create(f.DIV_BY_ZERO):b.create(In(t,i))}return this}concatenateFront(e){return e.isArray()?e.concatenateBack(this):_e.create(this.concatenate(e.getValue(),Te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):_e.create(this.concatenate(e.getValue(),Te.BACK))}compare(e,t){return e.isArray()?e.compare(this,Ls(t)):this.compareBy(e.getValue(),t)}plusBy(e){const t=this.getValue();if(typeof e=="string")return Qt.has(e)?h.create(e):h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).plus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).plus(e?1:0).toNumber()):this}minusBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).minus(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).minus(e?1:0).toNumber()):this}multiplyBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).times(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?b.create(Ce(t).times(e?1:0).toNumber()):this}dividedBy(e){const t=this.getValue();if(typeof e=="string")return h.create(f.VALUE);if(typeof e=="number"){if(e===0)return h.create(f.DIV_BY_ZERO);if(!Number.isFinite(t)||!Number.isFinite(e))return h.create(f.NUM);const s=Ce(t).div(e).toNumber();return Number.isFinite(s)?b.create(s):h.create(f.NUM)}return typeof e=="boolean"?e===!1?h.create(f.DIV_BY_ZERO):b.create(Ce(t).div(1).toNumber()):this}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.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 F.EQUALS:i=Ce(s).eq(e);break;case F.GREATER_THAN:i=Ce(s).gt(e);break;case F.GREATER_THAN_OR_EQUAL:i=Ce(s).gte(e);break;case F.LESS_THAN:i=Ce(s).lt(e);break;case F.LESS_THAN_OR_EQUAL:i=Ce(s).lte(e);break;case F.NOT_EQUAL:i=!Ce(s).eq(e);break}else if(typeof e=="boolean")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.NOT_EQUAL:i=!0;break}return Q.create(i)}pow(e){if(e.isArray())return e.powInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Yn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Yn(t,s?1:0)):this}sqrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Ce(e).sqrt().toNumber();return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cbrt(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cbrt(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}cos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.cos(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}acos(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acos(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}acosh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.acosh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}sin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.sin(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}asin(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asin(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}asinh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.asinh(e);return Number.isNaN(t)?h.create(f.NUM):b.create(t)}tan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}tanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.tanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atan(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}atan2(e){if(e.isArray())return e.atan2Inverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Math.atan2(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Math.atan2(t,s?1:0)):this}atanh(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.atanh(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}log10(){const e=this.getValue();if(typeof e=="number"&&e<=0||!Number.isFinite(e))return h.create(f.NUM);const t=Math.log10(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}exp(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.exp(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}abs(){const e=this.getValue();if(!Number.isFinite(e))return h.create(f.NUM);const t=Math.abs(e);return Number.isFinite(t)?b.create(t):h.create(f.NUM)}round(e){if(e.isArray())return e.roundInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=Tn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(Tn(t,s?1:0)):this}floor(e){if(e.isArray())return e.floorInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=jn(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create(jn(t,s?1:0)):this}ceil(e){if(e.isArray())return e.ceilInverse(this);const t=this.getValue(),s=e.getValue();if(typeof s=="string")return h.create(f.VALUE);if(typeof s=="number"){if(!Number.isFinite(t)||!Number.isFinite(s))return h.create(f.NUM);const i=$n(t,s);return Number.isFinite(i)?b.create(i):h.create(f.NUM)}return typeof s=="boolean"?b.create($n(t,s?1:0)):this}convertToNumberObjectValue(){return this}convertToBooleanObjectValue(){return Lr(!0)}_compareInfinity(e,t,s){let i=!1;switch(s){case F.EQUALS:i=e===t;break;case F.GREATER_THAN:i=e>t;break;case F.GREATER_THAN_OR_EQUAL:i=e>=t;break;case F.LESS_THAN:i=e<t;break;case F.LESS_THAN_OR_EQUAL:i=e<=t;break;case F.NOT_EQUAL:i=e!==t;break}return i}}const ha=2e5,Qn=new pt(ha);class _e extends Ze{constructor(e){super(e);S(this,"_value");this._value=e}static create(e){const t=Qn.get(e);if(t)return t;const s=new _e(e);return Qn.set(e,s),s}getValue(){return this._value}isString(){return!0}concatenateFront(e){return e.isArray()?e.concatenateBack(this):_e.create(this.concatenate(e.getValue(),Te.FRONT))}concatenateBack(e){return e.isArray()?e.concatenateFront(this):_e.create(this.concatenate(e.getValue(),Te.BACK))}compare(e,t){return e.isArray()?e.compare(this,Ls(t)):this.compareBy(e.getValue(),t)}compareBy(e,t){const s=this.getValue();let i=!1;if(typeof e=="string"){if(Ni(e))return this._checkWildcard(e,t);switch(t){case F.EQUALS:i=s===e;break;case F.GREATER_THAN:i=s>e;break;case F.GREATER_THAN_OR_EQUAL:i=s>=e;break;case F.LESS_THAN:i=s<e;break;case F.LESS_THAN_OR_EQUAL:i=s<=e;break;case F.NOT_EQUAL:i=s!==e;break}}else if(typeof e=="number")switch(t){case F.NOT_EQUAL:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!0;break;case F.EQUALS:case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:i=!1;break}else if(typeof e=="boolean")switch(t){case F.EQUALS:case F.GREATER_THAN:case F.GREATER_THAN_OR_EQUAL:i=!1;break;case F.LESS_THAN:case F.LESS_THAN_OR_EQUAL:case F.NOT_EQUAL:i=!0;break}return Q.create(i)}convertToNumberObjectValue(){return xr(this.getValue())}convertToBooleanObjectValue(){return Q.create(!0)}_checkWildcard(e,t){const s=this.getValue().toLocaleLowerCase(),i=ea(s,e,t);return Q.create(i)}}function Lr(r){if(typeof r=="boolean")return Q.create(r);let n=!1;if(typeof r=="string"){const e=r.toLocaleUpperCase();e===st.TRUE?n=!0:e===st.FALSE&&(n=!1)}else r===1?n=!0:n=!1;return Q.create(n)}function on(r){let n=r.toString();return n.charAt(0)==='"'&&n.charAt(n.length-1)==='"'&&(n=n.slice(1,-1),n=n.replace(/""/g,'"')),_e.create(n)}function xr(r){if(typeof r=="boolean"){let n=0;return r&&(n=1),b.create(n)}else{if(typeof r=="number")return Number.isFinite(r)?b.create(r):h.create(f.NUM);if(C.isRealNum(r))return b.create(Number(r))}return h.create(f.VALUE)}function ma(r){return""}function da(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]=it.create(i)}}return n}function ga(r=[]){const n=[];for(let e=0;e<r.length;e++){const t=r[e];n[e]==null&&(n[e]=[]);for(let s=0;s<t.length;s++){const i=t[s];i==null?n[e][s]=null:i.isError()?n[e][s]=i.getErrorType():n[e][s]=i.getValue()}}return n}class Le extends Ze{constructor(e){super(typeof e=="string"?e:ma());S(this,"_values",[]);S(this,"_rowCount",-1);S(this,"_columnCount",-1);S(this,"_unitId","");S(this,"_sheetId","");S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_sliceCache",new Map);S(this,"_flattenCache");S(this,"_flattenPosition");this._values=this._formatValue(e)}static create(e){return new Le(e)}dispose(){this._values.forEach(e=>{e.forEach(t=>{t==null||t.dispose()})}),this._values=[],this._clearCache()}clone(){return this.map(e=>e)}getRowCount(){return this._rowCount}setRowCount(e){this._rowCount=e}getColumnCount(){return this._columnCount}setColumnCount(e){this._columnCount=e}setCurrent(e,t){this._currentRow=e,this._currentColumn=t}setUnitId(e){this._unitId=e}getUnitId(){return this._unitId}setSheetId(e){this._sheetId=e}getSheetId(){return this._sheetId}getCurrentRow(){return this._currentRow}getCurrentColumn(){return this._currentColumn}getArrayValue(){return this._values}setArrayValue(e){this._clearCache(),this._values=e}isArray(){return!0}get(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}getRealValue(e,t){const s=this._values[e];if(s==null)return null;const i=s[t];return i==null?null:i}set(e,t,s){if(e>=this._rowCount||t>=this._columnCount)throw new Error("Exceeding array bounds.");this._clearCache(),this._values[e][t]=s}getRangePosition(){const t=this.getRowCount(),s=0,i=this.getColumnCount();return{startRow:0,endRow:t-1,startColumn:s,endColumn:i-1}}iterator(e){var u;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=this.getArrayValue();for(let c=t;c<=s;c++)for(let l=i;l<=a;l++)if(e((u=o[c])==null?void 0:u[l],c,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 c=a;c>=i;c--)if(e(o[u][c],u,c)===!1)return}getLastTruePosition(){let e;return this.iteratorReverse((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstTruePosition(){let e;return this.iterator((t,s,i)=>{if(t!=null&&t.isBoolean()&&t.getValue()===!0)return e={row:s,column:i},!1}),e}getFirstCell(){const{startRow:e,startColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}getLastCell(){const{endRow:e,endColumn:t}=this.getRangePosition();return this.get(e,t)||ce.create()}pick(e){const t=e.getRowCount(),s=e.getColumnCount();if(t!==this._rowCount||s!==this._columnCount)return this._createNewArray([[ce.create()]],1,1);const i=[];i[0]=[];for(let a=0;a<t;a++)for(let o=0;o<s;o++){const u=e.get(a,o),c=this.get(a,o);u==null||u.isError()||u.getValue()===!0&&i[0].push(c)}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 c=0;c<this._columnCount;c++){const l=this.get(u,c);if(l==null||l.isError()||l.isNull()){a++;continue}l.isString()?(e.push(l),s.push(a++)):(t.push(l),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,c=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,c=t[2]||1),s>=this._rowCount||o>=this._columnCount)return;const l=`${s}_${i}_${a}_${o}_${u}_${c}`,m=this._sliceCache.get(l);if(m!=null)return m;const d=[],_=this._values;let D=0,E=0;for(let U=s;U<i;U+=a){E=0,d[D]==null&&(d[D]=[]);for(let $=o;$<u;$+=c){if(!_[U])return;let se=_[U][$];se==null&&(se=ce.create()),d[D][E]=se,E++}D++}if(d.length===0||d[0].length===0)return;const A=a>1?-1:s+this._currentRow,x=c>1?-1:o+this._currentColumn,w=this._createNewArray(d,d.length,d[0].length,A,x);return this._sliceCache.set(l,w),w}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=xe.MIN,s=!1,i=!1){let a,o,u,c;const l=(m,d,_)=>{if(m==null)return!0;let D;if(i===!0?D=m.compare(e,F.EQUALS):D=m.isEqual(e),(D==null?void 0:D.getValue())===!0)return a=m,u={row:d,column:_},!1;t===xe.MAX?m.isGreaterThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,c={row:d,column:_}):t===xe.MIN&&m.isLessThan(e).getValue()===!0&&(o==null||m.minus(e).abs().isLessThanOrEqual(o.minus(e).abs()).getValue()===!0)&&(o=m,c={row:d,column:_})};if(s){const m=this._values.length;if(this._values[0]==null)return;const d=this._values[0].length;for(let _=m-1;_>=0;_--)for(let D=d-1;D>=0;D--){const E=this._values[_][D];l(E,_,D)}}else this.iterator((m,d,_)=>{l(m,d,_)});if(a!=null)return u;if(o!=null)return c}binarySearch(e,t=Ke.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=Ke.MIN){const a=On(),o=e.getValue().toString();let u=0,c=t.length-1,l=null;for(;u<=c;){const m=Math.floor((u+c)/2),d=t[m];let _=0;if(d.isNull())_=1;else{const D=d.getValue();_=a(D.toString(),o)}if(_===0)return s[m];_===-1?(u=m+1,i===Ke.MIN&&(l=m)):(c=m-1,i===Ke.MAX&&(l=m))}if(l!=null)return s[l]}sum(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.plus(t)}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isLessThan(t).getValue()&&(e=t)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this.iterator(t=>{if(t==null)return!0;if(t.isError())return e=t,!1;if(t.isString()||t.isNull()||t.isBoolean())return!0;e.isGreaterThan(t).getValue()&&(e=t)}),e}count(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isError()||t.isString()||t.isNull()||t.isBoolean())return!0;e=e.plusBy(1)}),e}countA(){let e=b.create(0);return this.iterator(t=>{if(t==null||t.isNull())return!0;e=e.plusBy(1)}),e}countBlank(){let e=b.create(0);return this.iterator(t=>{if(t!=null&&!t.isNull())return!0;e=e.plusBy(1)}),e}getNegative(){return Le.create("{0}").minus(this)}getReciprocal(){return Le.create("{1}").divided(this)}plus(e){return this._batchOperator(e,1)}minus(e){return this._batchOperator(e,0)}multiply(e){return this._batchOperator(e,2)}divided(e){return this._batchOperator(e,3)}mod(e){return this._batchOperator(e,4)}modInverse(e){return this.map(t=>t.isError()?t:e.mod(t))}compare(e,t){return this._batchOperator(e,5,t)}concatenateFront(e){return this._batchOperator(e,6)}concatenateBack(e){return this._batchOperator(e,7)}map(e){const t=(s,i,a)=>s==null?ce.create():s.isError()?s:e(s,i,a);return this.mapValue(t)}mapValue(e){var a;const t=this._rowCount,s=this._columnCount,i=[];for(let o=0;o<t;o++){const u=[];for(let c=0;c<s;c++){const l=(a=this._values)==null?void 0:a[o];if(l==null)u[c]=h.create(f.VALUE);else{const m=l[c];m?u[c]=e(m,o,c):u[c]=ce.create()}}i.push(u)}return this._createNewArray(i,t,s)}pow(e){return this._batchOperator(e,8)}powInverse(e){return this.map(t=>t.isError()?t:e.pow(t))}sqrt(){return this.map(e=>e.isError()?e:e.sqrt())}cbrt(){return this.map(e=>e.isError()?e:e.cbrt())}cos(){return this.map(e=>e.isError()?e:e.cos())}acos(){return this.map(e=>e.isError()?e:e.acos())}acosh(){return this.map(e=>e.isError()?e:e.acosh())}sin(){return this.map(e=>e.isError()?e:e.sin())}asin(){return this.map(e=>e.isError()?e:e.asin())}asinh(){return this.map(e=>e.isError()?e:e.asinh())}tan(){return this.map(e=>e.isError()?e:e.tan())}tanh(){return this.map(e=>e.isError()?e:e.tanh())}atan(){return this.map(e=>e.isError()?e:e.atan())}atanh(){return this.map(e=>e.isError()?e:e.atanh())}atan2(e){return this._batchOperator(e,12)}atan2Inverse(e){return this.map(t=>t.isError()?t:e.atan2(t))}mean(e=0){const t=this.sum(),s=this.count();return t.divided(e===0?s:s.minusBy(1))}median(){const e=this.flattenPosition().numberArray,t=this._createNewArray([e],1,e.length),s=t.getColumnCount();if(s<=1)return t.get(0,0)||ce.create();if(t.sortByRow(0),s%2===0){const i=t.get(0,s/2)||ce.create(),a=t.get(0,s/2-1)||ce.create();return i.plus(a).divided(b.create(2))}return t.get(0,(s-1)/2)||ce.create()}var(e=0){const t=this.mean(),s=[[]];this.iterator(l=>{if(l==null||l.isError()||l.isString()||l.isBoolean()||l.isNull())return;const m=l.minus(t).pow(b.create(2));m.isError()||s[0].push(m)});const{_unitId:i,_sheetId:a,_currentRow:o,_currentColumn:u}=this;return Le.create({calculateValueList:s,rowCount:1,columnCount:s[0].length,unitId:i,sheetId:a,row:o,column:u}).mean(e)}std(e=0){const t=this.var(e);return t.isError()?t:t.sqrt()}log(){return this.map(e=>e.isError()?e:e.log())}log10(){return this.map(e=>e.isError()?e:e.log10())}exp(){return this.map(e=>e.isError()?e:e.exp())}abs(){return this.map(e=>e.isError()?e:e.abs())}round(e){return this._batchOperator(e,9)}roundInverse(e){return this.map(t=>t.isError()?t:e.round(t))}floor(e){return this._batchOperator(e,10)}floorInverse(e){return this.map(t=>t.isError()?t:e.floor(t))}ceil(e){return this._batchOperator(e,11)}ceilInverse(e){return this.map(t=>t.isError()?t:e.ceil(t))}toValue(){return ga(this._values)}_clearCache(){this._flattenCache=null,this._sliceCache.clear()}_sort(e){const t=On();return(s,i)=>{const a=s[e],o=i[e];return a==null?1:o==null?-1:a.isError()&&a.isError()?0:a.isError()?1:o.isError()?-1:t(a.getValue(),o.getValue())}}_transposeArray(e){const t=e.length,s=e[0].length,i=[];for(let a=0;a<s;a++){i[a]=[];for(let o=0;o<t;o++)i[a][o]=e[o][a]}return i}_batchOperator(e,t,s){const i=[];let a=this._rowCount,o=this._columnCount;if(e.isArray()){const c=e.getRowCount(),l=e.getColumnCount();if(a=Math.max(c,a),o=Math.max(l,o),c===1&&l===1){const m=e.getFirstCell();for(let d=0;d<o;d++)i.push(m)}else if(c===1&&this._columnCount>1){const m=e.getArrayValue();for(let d=0;d<o;d++)i.push(m[0][d])}else return this._batchOperatorArray(e,t,s)}else for(let c=0;c<o;c++)i.push(e);const u=[];for(let c=0;c<o;c++){const l=i[c];this._batchOperatorValue(l,c,u,t,s)}return this._createNewArray(u,a,o)}_batchOperatorValue(e,t,s,i,a){var _,D;const o=this._rowCount;let u=!1;const c=this.getUnitId(),l=this.getSheetId(),m=this.getCurrentRow(),d=this.getCurrentColumn();if(i===5&&(u=Ne.canUseCache(c,l,t+d,m,m+o-1),u===!0)){if(a===F.EQUALS){const E=Ne.getCellPositions(c,l,t+d,e.getValue());E!=null&&E.forEach(A=>{const x=A-m;s[x]==null&&(s[x]=[]),s[x][t]=Q.create(!0)})}else{const E=Ne.getCellValuePositions(c,l,t+d);E!=null&&E.forEach((A,x)=>{let w=ce.create();typeof x=="string"?w=_e.create(x):typeof x=="number"?w=b.create(x):typeof x=="boolean"&&(w=Q.create(x)),w.compare(e,a).getValue()===!0&&A.forEach($=>{$>=m&&$<=m+o-1&&(s[$-m]==null&&(s[$-m]=[]),s[$-m][t]=Q.create(!0))})})}return}for(let E=0;E<o;E++){const A=(D=(_=this._values)==null?void 0:_[E])==null?void 0:D[t];if(s[E]==null&&(s[E]=[]),A&&e)if(A.isError())s[E][t]=A;else if(e.isError())s[E][t]=e;else switch(i){case 1:s[E][t]=A.plus(e);break;case 0:s[E][t]=A.minus(e);break;case 2:s[E][t]=A.multiply(e);break;case 3:s[E][t]=A.divided(e);break;case 4:s[E][t]=A.mod(e);break;case 5:a?s[E][t]=A.compare(e,a):s[E][t]=h.create(f.VALUE);break;case 6:s[E][t]=A.concatenateFront(e);break;case 7:s[E][t]=A.concatenateBack(e);break;case 8:s[E][t]=A.pow(e);break;case 9:s[E][t]=A.round(e);break;case 10:s[E][t]=A.floor(e);break;case 12:s[E][t]=A.atan2(e);break;case 11:s[E][t]=A.ceil(e);break}else s[E][t]=h.create(f.NA);A!=null&&(A.isError()?Ne.set(c,l,t+d,A.getErrorType(),E+m):A.isNull()?Ne.set(c,l,t+d,null,E+m):Ne.set(c,l,t+d,A.getValue(),E+m))}Ne.setContinueBuildingCache(c,l,t+d,m,m+o-1)}_batchOperatorArray(e,t,s){var m,d,_,D,E,A,x,w,U,$,se,he;let i=e.getRowCount(),a=e.getColumnCount();i<this._rowCount&&(i=this._rowCount),a<this._columnCount&&(a=this._columnCount);const o=[],u=e.getArrayValue(),c=this._checkArrayCalculateType(this),l=this._checkArrayCalculateType(e);for(let de=0;de<i;de++){const q=[];for(let z=0;z<a;z++){let re;c===3?re=(d=(m=this._values)==null?void 0:m[0])==null?void 0:d[0]:c===1?re=(D=(_=this._values)==null?void 0:_[0])==null?void 0:D[z]:c===2?re=(A=(E=this._values)==null?void 0:E[de])==null?void 0:A[0]:re=(w=(x=this._values)==null?void 0:x[de])==null?void 0:w[z];let Z;if(l===3?Z=(U=u==null?void 0:u[0])==null?void 0:U[0]:l===1?Z=($=u==null?void 0:u[0])==null?void 0:$[z]:l===2?Z=(se=u==null?void 0:u[de])==null?void 0:se[0]:Z=(he=u==null?void 0:u[de])==null?void 0:he[z],re&&Z)if(re.isError())q[z]=re;else if(Z.isError())q[z]=Z;else switch(t){case 1:q[z]=re.plus(Z);break;case 0:q[z]=re.minus(Z);break;case 2:q[z]=re.multiply(Z);break;case 3:q[z]=re.divided(Z);break;case 4:q[z]=re.mod(Z);break;case 5:s?q[z]=re.compare(Z,s):q[z]=h.create(f.VALUE);break;case 6:q[z]=re.concatenateFront(Z);break;case 7:q[z]=re.concatenateBack(Z);break;case 8:q[z]=re.pow(Z);break;case 9:q[z]=re.round(Z);break;case 12:q[z]=re.atan2(Z);break;case 10:q[z]=re.floor(Z);break;case 11:q[z]=re.ceil(Z);break}else q[z]=h.create(f.NA)}o.push(q)}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 c=t[o].split(","),l=c.length;a<l&&(a=l);const m=[];for(let d=0;d<l;d++){const _=c[d].trim();m.push(it.create(_))}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 Le.create(o)}}class it{static create(n){if(n==null)return ce.create();if(typeof n=="boolean")return Q.create(n);if(typeof n=="string"){const e=n.toLocaleUpperCase().trim();return Qt.has(e)?h.create(e):e===st.TRUE||e===st.FALSE?Lr(n):C.isRealNum(n)?b.create(Number(n)):new RegExp(ji,"g").test(n.replace(/\n/g,"").replace(/\r/g,""))?Le.create(n.replace(/\n/g,"").replace(/\r/g,"")):on(n)}return typeof n=="number"?xr(n):h.create(f.VALUE)}}function pa(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)===C.DEFAULT_EMPTY_DOCUMENT_VALUE?e.substring(0,e.length-2):e}return(r==null?void 0:r.v)||0}const Ra=1e5,Hr=new pt(Ra);class Vt extends Sr{constructor(e){super();S(this,"_forcedSheetId","");S(this,"_forcedSheetName","");S(this,"_defaultSheetId","");S(this,"_rangeData",{startColumn:-1,startRow:-1,endRow:-1,endColumn:-1});S(this,"_unitData",{});S(this,"_defaultUnitId","");S(this,"_forcedUnitId","");S(this,"_runtimeData",{});S(this,"_arrayFormulaCellData",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeFeatureCellData",{});S(this,"_numfmtItemData",{});S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){this._unitData={},this._runtimeData={}}getToken(){return this._token}setToken(e){this._token=e}isExceedRange(){const{startRow:e,endRow:t,startColumn:s,endColumn:i}=this.getRangePosition();return e<0||s<0||t>=this.getActiveSheetRowCount()||i>=this.getActiveSheetColumnCount()}setRefOffset(e=0,t=0){this._refOffsetX=e,this._refOffsetY=t}getRefOffset(){return{x:this._refOffsetX,y:this._refOffsetY}}getRangePosition(){let e=this._rangeData.startRow+this._refOffsetY,t=this._rangeData.endRow+this._refOffsetY,s=this._rangeData.startColumn+this._refOffsetX,i=this._rangeData.endColumn+this._refOffsetX;return Number.isNaN(e)&&(e=0),Number.isNaN(s)&&(s=0),Number.isNaN(t)&&(t=this.getActiveSheetRowCount()-1),Number.isNaN(i)&&(i=this.getActiveSheetColumnCount()-1),{startRow:e,endRow:t,startColumn:s,endColumn:i}}isReferenceObject(){return!0}iterator(e){var c,l,m;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition();if(this._checkIfWorksheetMiss())return e(h.create(f.VALUE),t,i);const o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId;for(let d=t;d<=s;d++)for(let _=i;_<=a;_++){if(d<0||_<0)return e(h.create(f.REF),d,_);const D=this.getCellData(d,_);let E=!1;if(D==null||C.isNullCell(D)){E=e(null,d,_);continue}const A=this.getCellValueObject(D),x=A.isNumber(),w=(m=(l=(c=this._numfmtItemData[o])==null?void 0:c[u])==null?void 0:l[d])==null?void 0:m[_];if(w&&x&&A.setPattern(w),E=e(A,d,_),E===!1)return}}getFirstCell(){var l,m,d;const{startRow:e,startColumn:t}=this.getRangePosition(),s=this.getCellData(e,t);if(!s)return b.create(0);const i=this.getCellValueObject(s),a=i.isNumber(),o=this._forcedUnitId||this._defaultUnitId,u=this._forcedSheetId||this._defaultSheetId,c=(d=(m=(l=this._numfmtItemData[o])==null?void 0:l[u])==null?void 0:m[e])==null?void 0:d[t];return c&&a&&i.setPattern(c),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}getActiveSheetRowCount(){return this.getCurrentActiveSheetData().rowCount}getActiveSheetColumnCount(){return this.getCurrentActiveSheetData().columnCount}getRowCount(){return this._rangeData.endRow-this._rangeData.startRow+1}getColumnCount(){return this._rangeData.endColumn-this._rangeData.startColumn+1}getRowData(){return this.getCurrentActiveSheetData().rowData}getColumnData(){return this.getCurrentActiveSheetData().columnData}isCell(){return!1}isColumn(){return!1}isRow(){return!1}isRange(){return!1}isTable(){return!1}unionBy(e){return h.create(f.REF)}unionRange(e,t){return{startRow:-1,startColumn:-1,endRow:-1,endColumn:-1}}getCellValueObject(e){const t=pa(e);return Qt.has(t)?h.create(t):e.t===C.CellValueType.NUMBER?xr(t):e.t===C.CellValueType.STRING||e.t===C.CellValueType.FORCE_STRING?on(t):e.t===C.CellValueType.BOOLEAN?Lr(t):it.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 c=u.getValue(e,t);if(c!=null)return c}}getCellByPosition(e,t){e||(e=this._rangeData.startRow),t||(t=this._rangeData.startColumn);const s=this.getCellData(e,t);return s?this.getCellValueObject(s):h.create(f.VALUE)}toArrayValueObject(e=!0){var D;const{startRow:t,endRow:s,startColumn:i,endColumn:a}=this.getRangePosition(),o=`${this.getUnitId()}_${this.getSheetId()}_${t}_${s}_${i}_${a}`,u=Hr.get(o);if(u&&e)return u;const c=s-t+1,l=a-i+1;if(c<0||l<0)return this._getBlankArrayValueObject();const m=new Array(c);this.iterator((E,A,x)=>{const w=A-t,U=x-i;m[w]||(m[w]=new Array(l)),E==null&&(E=ce.create()),m[w][U]=E});const d={calculateValueList:m,rowCount:m.length,columnCount:((D=m[0])==null?void 0:D.length)||0,unitId:this.getUnitId(),sheetId:this.getSheetId(),row:t,column:i},_=Le.create(d);return e&&Hr.set(o,_),_}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 Le.create(e)}}class _a extends Sr{constructor(n){super(),this._promise=n}isAsyncObject(){return!0}async getValue(){return this._promise}}class Ea extends Sr{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 Le.create(e)}}class It extends Vt{constructor(n,e,t){super(""),this.setRangeData(n),e&&this.setForcedSheetIdDirect(e),t&&this.setForcedUnitIdDirect(t)}isRange(){return!0}}const Hn=/[\[\]]/g;function Wn(r,n){if(Hn.test(r)){const e=Number(r.replace(Hn,""));return n+e}return Number(r)-1}function kr(r,n=0,e=0){r=r.toLocaleUpperCase();const t=r.split(/[RC]/),s=t[1],i=t[2],a=Wn(s,n),o=Wn(i,e);return{row:a,column:o,absoluteRefType:C.AbsoluteRefType.NONE}}function xs(r,n=0,e=0){const{refBody:t,sheetName:s,unitId:i}=_s(r),a=t.indexOf(":");if(a===-1){const E=kr(t,n,e),A=E.row,x=E.column,w=E.absoluteRefType;return{unitId:i,sheetName:s,range:{startRow:A,startColumn:x,endRow:A,endColumn:x,startAbsoluteRefType:w,endAbsoluteRefType:w}}}const o=t.substring(0,a),u=t.substring(a+1),c=kr(o,n,e),l=kr(u,n,e),m=c.row,d=c.column,_=l.row,D=l.column;return{unitId:i,sheetName:s,range:{startRow:m,startColumn:d,endRow:_,endColumn:D,startAbsoluteRefType:c.absoluteRefType,endAbsoluteRefType:l.absoluteRefType}}}function Ca(r){const n=Jt(r.startRow,r.startAbsoluteRefType,!0),e=Jt(r.startColumn,r.startAbsoluteRefType,!1),t=Jt(r.endRow,r.endAbsoluteRefType,!0),s=Jt(r.endColumn,r.endAbsoluteRefType,!1);return n===t&&e===s?`R${n}C${e}`:`R${n}C${e}:R${t}C${s}`}function Jt(r,n=C.AbsoluteRefType.ALL,e){switch(r+=1,n){case C.AbsoluteRefType.ALL:return`${r}`;case C.AbsoluteRefType.ROW:return e?`${r}`:`[${r}]`;case C.AbsoluteRefType.COLUMN:return e?`[${r}]`:`${r}`;case C.AbsoluteRefType.NONE:return`[${r}]`}}const ws=[];var Ps=(r=>r)(Ps||{});function ya(r){const n=r.getValue();let e=0;return n&&(e=1),b.create(e)}function Gn(r){return r.isArray()&&r.getRowCount()===1&&r.getColumnCount()===1?!0:r.isReferenceObject()?!!(r.isCell()||r.getRowCount()===1&&r.getColumnCount()===1):(r=r,!!(r.isString()||r.isNumber()||r.isBoolean()||r.isError()||r.isNull()))}function me(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 c=[];for(let l=0;l<n;l++)c.push(o);s.push(c)}}else if(i===1&&a>1)for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(0,c)||(t!=null?t:ce.create());u.push(l)}s.push(u)}else if(a===1&&i>1)for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(o,0)||(t!=null?t:ce.create());u.push(l)}s.push(u)}else for(let o=0;o<r;o++){const u=[];for(let c=0;c<n;c++){const l=e.getRealValue(o,c)||(t!=null?t:ce.create());u.push(l)}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 Yt(s,r,n)}function Yt(r,n,e,t="",s=""){const i={calculateValueList:r,rowCount:n,columnCount:e,unitId:t,sheetId:s,row:-1,column:-1};return Le.create(i)}class un extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName),this.setRangeData(e.range)}isCell(){return!0}unionBy(n){if(!n.isCell())return h.create(f.REF);const e=n,t=this.unionRange(this.getRangeData(),e.getRangeData());return this._createRange(t)}unionRange(n,e){const t=n.startRow,s=n.startColumn,i=e.startRow,a=e.startColumn,o={startRow:-1,startColumn:-1,endRow:-1,endColumn:-1};return t>i?(o.startRow=i,o.endRow=t):(o.startRow=t,o.endRow=i),s>a?(o.startColumn=a,o.endColumn=s):(o.startColumn=s,o.endColumn=a),o}_createRange(n){const e=new It(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 cn extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:Number.NaN,startRow:e.range.startRow,endColumn:Number.NaN,endRow:-1};this.setRangeData(t)}isRow(){return!0}unionBy(n){if(!n.isRow())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startRow,i=t.startRow;return s>i?t.endRow=s:(t.startRow=s,t.endRow=i),this.setToken(`${this.getToken()}${G.COLON}${e.getToken()}`),this}}class ln extends Vt{constructor(n){super(n);const e=wt(n);this.setForcedUnitIdDirect(e.unitId),this.setForcedSheetName(e.sheetName);const t={startColumn:e.range.startColumn,startRow:Number.NaN,endColumn:-1,endRow:Number.NaN};this.setRangeData(t)}isColumn(){return!0}unionBy(n){if(!n.isColumn())return h.create(f.REF);const e=n;if(e.getForcedSheetName()!==void 0&&e.getForcedSheetName()!=="")return h.create(f.REF);const t=this.getRangeData(),s=e.getRangeData().startColumn,i=t.startColumn;return s>i?t.endColumn=s:(t.startColumn=s,t.endColumn=i),this.setToken(`${this.getToken()}${G.COLON}${e.getToken()}`),this}}class j extends C.Disposable{constructor(e){super();S(this,"_unitId");S(this,"_subUnitId");S(this,"_row",-1);S(this,"_column",-1);S(this,"needsExpandParams",!1);S(this,"needsReferenceObject",!1);this._name=e}get name(){return this._name}get unitId(){return this._unitId}get subUnitId(){return this._subUnitId}get row(){return this._row}get column(){return this._column}isAsync(){return!1}isAddress(){return!1}isCustom(){return!1}setRefInfo(e,t,s,i){this._unitId=e,this._subUnitId=t,this._row=s,this._column=i}calculateCustom(...e){return null}calculate(...e){return h.create(f.VALUE)}checkArrayType(e){return e.isReferenceObject()||e.isValueObject()&&e.isArray()}getIndexNumValue(e,t=1){if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())return e.getValue()===!1?h.create(f.VALUE):t;if(e.isString()){const s=Number(e.getValue());return Number.isNaN(s)?h.create(f.REF):s}else if(e.isNumber())return e.getValue();return h.create(f.VALUE)}getZeroOrOneByOneDefault(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;e.isNumber()&&e.getValue()===0&&(t=0)}return t}getMatchTypeValue(e){if(e==null)return 1;let t=1;if(e.isArray()&&(e=e.getFirstCell()),e.isBoolean())e.getValue()===!1&&(t=0);else{if(e.isString())return;if(e.isNumber()){const s=e.getValue();s<=0&&(t=s)}}return t}binarySearch(e,t,s,i){const a=t.binarySearch(e,i);if(a==null)return h.create(f.NA);let o;return s.getRowCount()===1?o=s.get(0,a)||ce.create():o=s.get(a,0)||ce.create(),o.isNull()?h.create(f.NA):o}equalSearch(e,t,s,i=!0){const a=s.pick(t.isEqual(e));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}fuzzySearch(e,t,s,i=!0){const a=s.pick(t.compare(e,F.EQUALS));let o;return i?o=a.getFirstCell():o=a.getLastCell(),o.isNull()?h.create(f.NA):o}orderSearch(e,t,s,i=xe.MIN,a=!1){const o=t.orderSearch(e,i,a);if(o==null)return h.create(f.NA);const u=s.get(o.row,o.column)||ce.create();return u.isNull()?h.create(f.NA):u}binarySearchExpand(e,t,s,i=0,a){const o=t.binarySearch(e,a);return o==null?h.create(f.NA):i===0?s.slice([o,o+1]):s.slice(void 0,[o,o+1])}equalSearchExpand(e,t,s,i=!0,a=0){const o=t.isEqual(e);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}fuzzySearchExpand(e,t,s,i=!0,a=0){const o=t.compare(e,F.EQUALS);let u;return i?u=o.getFirstTruePosition():u=o.getLastTruePosition(),u==null?h.create(f.NA):a===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}orderSearchExpand(e,t,s,i=xe.MIN,a=!1,o=0){const u=t.orderSearch(e,i,a);return u==null?h.create(f.NA):o===0?s.slice([u.row,u.row+1]):s.slice(void 0,[u.column,u.column+1])}flattenArray(e,t=!0){const s=[];s[0]=[];for(let i=0;i<e.length;i++){let a=e[i];if((a.isString()||a.isBoolean()||a.isNull())&&(a=a.convertToNumberObjectValue()),a.isError())return a;if(a.isArray()){let o;if(a.iterator(u=>{if(u==null||u.isNull()||t&&(u.isString()||u.isBoolean()))return!0;if(u=this._includingLogicalValuesAndText(u),u.isError())return o=u,!1;s[0].push(u)}),o!=null&&o.isError())return o}else s[0].push(a)}return Yt(s,1,s[0].length)}_includingLogicalValuesAndText(e){if(e.isBoolean()&&(e=ya(e)),e.isString()){const t=Number(e.getValue());e=b.create(Number.isNaN(t)?0:t)}return e}createReferenceObject(e,t){const s=e.getForcedUnitId(),i=e.getForcedSheetId()||"",a=e.getForcedSheetName(),u=bt({unitId:s,sheetName:a,range:t});let c;return new RegExp(Ht).test(u)?c=new un(u):new RegExp(fs).test(u)?c=new cn(u):new RegExp(hs).test(u)?c=new ln(u):c=new It(t,i,s),this._setReferenceDefault(e,c)}_setReferenceDefault(e,t){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(t.setDefaultUnitId(this.unitId),t.setDefaultSheetId(this.subUnitId),t.setUnitData(e.getUnitData()),t.setRuntimeData(e.getRuntimeData()),t.setArrayFormulaCellData(e.getArrayFormulaCellData()),t.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),t)}}class Vs extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std()}}class vs extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.std(1)}}class Ms extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var()}}class Os extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n);return e.isError()?e:e.var(1)}}var Ct=(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))(Ct||{});const Fs=[[vs,Ct.STDEV],[Vs,Ct.STDEVP],[Os,Ct.VAR],[Ms,Ct.VARP]],Bs=[];var Us=(r=>(r.CUBEKPIMEMBER="CUBEKPIMEMBER",r.CUBEMEMBER="CUBEMEMBER",r.CUBEMEMBERPROPERTY="CUBEMEMBERPROPERTY",r.CUBERANKEDMEMBER="CUBERANKEDMEMBER",r.CUBESET="CUBESET",r.CUBESETCOUNT="CUBESETCOUNT",r.CUBEVALUE="CUBEVALUE",r))(Us||{});const ks=[];var Ts=(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))(Ts||{});const fn="yyyy/mm/dd;@";function hn(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 wr(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 mn(r){if(!/^\d{4}[-/](0?[1-9]|1[012])[-/](0?[1-9]|[12][0-9]|3[01])$/.test(r))return!1;const e=r.replace(/-/g,"/").replace(/T.+/,""),t=new Date(`${e}`);if(Number.isNaN(t.getTime()))return!1;const s=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),a=t.getDate().toString().padStart(2,"0"),o=`${s}-${i}-${a}`;return r.replace(/\//g,"-").split("-").map(c=>c.padStart(2,"0")).join("-")===o}class Da extends j{calculate(n,e,t){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t.isError())return t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=me(s,i,n),o=me(s,i,e),u=me(s,i,t);return a.map((c,l,m)=>{const d=o.get(l,m)||ce.create(),_=u.get(l,m)||ce.create();if(c.isError())return c;if(d.isError())return d;if(_.isError())return _;if(c.isString()||d.isString()||_.isString())return h.create(f.VALUE);let D=+c.getValue();const E=Math.floor(+d.getValue()),A=+_.getValue();if(D<0||D>9999)return h.create(f.NUM);D>=0&&D<1899&&(D+=1900);const x=new Date(D,E-1,A),w=hn(x);if(w<0)return h.create(f.NUM);const U=b.create(w);return U.setPattern(fn),U})}}class ba extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!mn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(0);e=wr(a)}const s=e.getDate();return b.create(s)}}class Sa extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=me(t,s,n),a=me(t,s,e);return i.map((o,u,c)=>{const l=a.get(u,c)||ce.create();if(o.isError())return o;if(l.isError())return l;if(o.isString()||o.isBoolean()||l.isString()||l.isBoolean())return h.create(f.VALUE);const m=+o.getValue();if(m<0)return h.create(f.NUM);const d=Math.floor(+l.getValue()),_=wr(m),D=_.getUTCFullYear(),E=_.getUTCMonth()+d,A=_.getUTCDate(),x=new Date(Date.UTC(D,E,A)),w=hn(x),U=b.create(w);return U.setPattern(fn),U})}}var et=(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))(et||{});class Aa extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!mn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+n.getValue();if(a<0)return h.create(f.NUM);if(a===0)return b.create(1);e=wr(a)}const s=e.getUTCMonth()+1;return b.create(s)}}class La extends j{calculate(n){if(n)return h.create(f.NA);const e=hn(new Date),t=b.create(e);return t.setPattern(fn),t}}class xa extends j{calculate(n){return n==null?h.create(f.NA):n.isArray()?n.map(e=>this._handleSingleObject(e)):this._handleSingleObject(n)}_handleSingleObject(n){if(n.isError())return n;let e;const t=n.getValue();if(n.isString()){if(!mn(`${t}`))return h.create(f.VALUE);e=new Date(`${t}`)}else{const a=+t;if(a<0)return h.create(f.NUM);if(a===0)return b.create(1900);e=wr(a)}const s=e.getUTCFullYear();return b.create(s)}}const js=[[Da,et.DATE],[ba,et.DAY],[Sa,et.EDATE],[Aa,et.MONTH],[La,et.TODAY],[xa,et.YEAR]],$s=[];var Is=(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))(Is||{});const Ys=[];var zs=(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))(zs||{}),ke=(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))(ke||{});class wa extends j{calculate(n){return n==null?h.create(f.NA):n.isNull()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isNull()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Pa extends j{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?Q.create(!1):n.isError()?Q.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?Q.create(!1):e.isError()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Va extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isError()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class va extends j{calculate(n){return n==null?h.create(f.NA):n.isBoolean()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isBoolean()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Ma extends j{calculate(n){return n==null?h.create(f.NA):n.getValue()===f.NA?Q.create(!0):n.isArray()?n.mapValue(e=>e.getValue()===f.NA?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Oa extends j{calculate(n){return n==null?h.create(f.NA):!n.isArray()&&!n.isString()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isString()?Q.create(!1):Q.create(!0)):Q.create(!1)}}class Fa extends j{calculate(n){return n==null?h.create(f.NA):n.isNumber()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isNumber()?Q.create(!0):Q.create(!1)):Q.create(!1)}}class Ba extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e){return e==null?h.create(f.NA):e.isReferenceObject()?Q.create(!0):Q.create(!1)}}class Ua extends j{calculate(n){return n==null?h.create(f.NA):n.isString()?Q.create(!0):n.isArray()?n.mapValue(e=>e.isString()?Q.create(!0):Q.create(!1)):Q.create(!1)}}const Qs=[[wa,ke.ISBLANK],[Pa,ke.ISERR],[Va,ke.ISERROR],[va,ke.ISLOGICAL],[Ma,ke.ISNA],[Oa,ke.ISNONTEXT],[Fa,ke.ISNUMBER],[Ba,ke.ISREF],[Ua,ke.ISTEXT]];class ka extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=!0,t=!0,s=null;for(const i of n){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e&&!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e&&!!i.getValue(),t=!1)}return t?h.create(f.VALUE):Q.create(e)}}var tt=(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))(tt||{});class Ta extends j{calculate(n,e,t=Q.create(!1)){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(n=this._getSingleValueObject(n),!n.isArray())return n.getValue()?e:t;const s=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1,t.isArray()?t.getRowCount():1),i=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1,t.isArray()?t.getColumnCount():1),a=me(s,i,n),o=me(s,i,e,h.create(f.NA)),u=me(s,i,t,h.create(f.NA));return a.map((c,l,m)=>{if(c.isNull())return h.create(f.NA);{const d=o.get(l,m)||ce.create(),_=u.get(l,m)||ce.create();return this._calculateSingleCell(c,d,_)}})}_getSingleValueObject(n){return n.isArray()&&n.getRowCount()===1&&n.getColumnCount()===1?n.getFirstCell():n}_calculateSingleCell(n,e,t){return n.isNull()?h.create(f.NA):n.getValue()?e.isNull()?h.create(f.NA):e:t.isNull()?h.create(f.NA):t}}class ja extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(!n.isArray())return n.isError()?e:n;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=me(t,s,n),a=me(t,s,e);return i.iterator((o,u,c)=>{o!=null&&o.isError()&&i.set(u,c,a.get(u,c))}),i}}class $a extends j{calculate(...n){return h.create(f.VALUE)}}class Ia extends j{calculate(...n){if(n.length!==3)return h.create(f.VALUE);const e=this.getIndexNumValue(n[0]);if(typeof e!="number")return e;const t=this.getIndexNumValue(n[1]);if(typeof t!="number")return t;if(!(n[2].isValueObject()&&n[2].isLambda()))return h.create(f.VALUE);const s=n[2],i=[];for(let a=0;a<e;a++){i[a]==null&&(i[a]=[]);for(let o=0;o<t;o++){const u=s.execute(b.create(a+1),b.create(o+1));i[a][o]=u}}return new Ea(i)}isAsync(){return!0}}class Ya extends j{calculate(...n){if(n.length===0)return new h(f.NA);let e=!1,t=!0,s=null;for(const i of n){if(i.isError())return i;if(i.isArray()){if(i.iterator(a=>{if(a!=null&&a.isError())return s=a,!1;(a!=null&&a.isBoolean()||a!=null&&a.isNumber())&&(e=e||!!a.getValue(),t=!1)}),s)return s}else(i.isBoolean()||i.isNumber())&&(e=e||!!i.getValue(),t=!1)}return t?new h(f.VALUE):new Q(e)}}const Hs=[[ka,tt.AND],[Ta,tt.IF],[$a,tt.LAMBDA],[Ia,tt.MAKEARRAY],[Ya,tt.OR],[ja,tt.IFERROR]];class za extends j{calculate(n,e,t,s,i){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;if(t!=null&&t.isError())return t;if(s!=null&&s.isError())return s;if(i!=null&&i.isError())return i;const a=Number(n.getValue())-1,o=Number(e.getValue())-1;if(Number.isNaN(a)||Number.isNaN(o))return h.create(f.VALUE);const u=t?Qa(t.getValue()):C.AbsoluteRefType.ALL,c=this.getZeroOrOneByOneDefault(s),l=i?`${i.getValue()}`:"",m=cr(l)?`'${l}'`:l,d={startRow:a,startColumn:o,endRow:a,endColumn:o,startAbsoluteRefType:u,endAbsoluteRefType:u},_=s&&!c?Ca(d):dt(d);return _e.create(m!==""?`${m}!${_}`:_)}}function Qa(r){switch(r){case 1:return C.AbsoluteRefType.ALL;case 2:return C.AbsoluteRefType.ROW;case 3:return C.AbsoluteRefType.COLUMN;case 4:return C.AbsoluteRefType.NONE;default:return C.AbsoluteRefType.ALL}}class Ha extends j{calculate(n){if(n==null)return b.create(this.column+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentColumn(),t=n.getColumnCount(),s=[];for(let a=0;a<t;a++)s.push(b.create(e+a+1));const i={calculateValueList:[s],rowCount:1,columnCount:t,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Le.create(i)}}class Wa extends j{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getColumnCount();return b.create(e)}}var be=(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))(be||{});class Ga extends j{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray()||t.isError()||s!=null&&s.isError())return h.create(f.NA);const i=this.getZeroOrOneByOneDefault(s);if(i==null)return h.create(f.VALUE);const a=this.getIndexNumValue(t);if(a instanceof h)return a;const o=e.slice([0,1]),u=e.slice([a-1,a]);return o==null||u==null?h.create(f.REF):n.isArray()?n.map(c=>this._handleSingleObject(c,o,u,i)):this._handleSingleObject(n,o,u,i)}_handleSingleObject(n,e,t,s){return s===0?this.equalSearch(n,e,t):this.binarySearch(n,e,t)}}class Xa extends j{calculate(n,e){if(n==null)return h.create(f.NA);if(n.isError())return n;let t=this.getZeroOrOneByOneDefault(e);if(t==null&&(t=1),n.isArray()){const l=n;if(l.getRowCount()===1&&l.getColumnCount()===1)n=l.getFirstCell();else return l.map(()=>h.create(f.VALUE))}if(!n.isString())return h.create(f.REF);const s=n.getValue();if(t===0){const l=xs(s),{range:m,sheetName:d,unitId:_}=l,D=new It(m);return D.setForcedUnitIdDirect(_),D.setForcedSheetName(d),this._setDefault(D)}if(new RegExp(Ht).test(s))return this._setDefault(new un(s));if(new RegExp(cs).test(s))return this._setDefault(new cn(s));if(new RegExp(ls).test(s))return this._setDefault(new ln(s));const i=wt(s),{range:a,sheetName:o,unitId:u}=i,c=new It(a);return c.setForcedUnitIdDirect(u),c.setForcedSheetName(o),this._setDefault(c)}_setDefault(n){return this.unitId==null||this.subUnitId==null?h.create(f.REF):(n.setDefaultUnitId(this.unitId),n.setDefaultSheetId(this.subUnitId),n)}}class Ka extends j{constructor(){super(...arguments);S(this,"needsExpandParams",!0)}calculate(e,t,s){return e==null||t==null?h.create(f.NA):e.isError()?e:t.isError()?h.create(f.REF):t.isArray()?s!=null&&s.isError()?s:t.getColumnCount()===1||t.getRowCount()===1?s!=null&&!s.isArray()?h.create(f.REF):this._handleVector(e,t,s):this._handleArray(e,t):h.create(f.VALUE)}_handleVector(e,t,s){if(s==null)s=t;else if(s.getRowCount()!==t.getRowCount()||s.getColumnCount()!==t.getColumnCount())return h.create(f.REF);return e.isArray()?e.map(i=>this.binarySearch(i,t,s)):this.binarySearch(e,t,s)}_handleArray(e,t){const s=t.getRowCount(),i=t.getColumnCount();let a,o;return i>s?(a=t.slice([0,1]),o=t.slice([s-1,s])):(a=t.slice(void 0,[0,1]),o=t.slice(void 0,[i-1,i])),a==null||o==null?h.create(f.VALUE):e.isArray()?e.map(u=>this.binarySearch(u,a,o)):this.binarySearch(e,a,o)}}class qa extends j{calculate(n,e,t){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const s=e.getRowCount(),i=e.getColumnCount();if(s!==1&&i!==1||t!=null&&t.isError())return h.create(f.NA);const a=this.getMatchTypeValue(t);return a==null?h.create(f.VALUE):n.isArray()?n.map(o=>this._handleSingleObject(o,e,a)):this._handleSingleObject(n,e,a)}_handleSingleObject(n,e,t){const s=this._getSearchModeValue(t),i=e.orderSearch(n,s);if(i==null)return h.create(f.NA);if(i instanceof h)return i;const a=e.getRowCount()===1?i.column+1:i.row+1;return b.create(a)}_getSearchModeValue(n){switch(n){case 1:return xe.MIN;case 0:return xe.NORMAL;case-1:return xe.MAX}}}class Za extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i,a){if(e==null||t==null||s==null)return h.create(f.NA);if(e.isError())return e;if(t.isError())return t;if(s.isError())return s;if(i!=null&&i.isError())return i;if(a!=null&&a.isError())return a;if(!e.isReferenceObject())return h.create(f.VALUE);e=e;const o=e.getRowCount(),u=e.getColumnCount();t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject()),i?i.isReferenceObject()&&(i=i.toArrayValueObject()):i=b.create(o),a?a.isReferenceObject()&&(a=a.toArrayValueObject()):a=b.create(u);const c=Math.max(t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1,i.isArray()?i.getRowCount():1,a.isArray()?a.getRowCount():1),l=Math.max(t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1,i.isArray()?i.getColumnCount():1,a.isArray()?a.getColumnCount():1);if(t=t,s=s,i=i,a=a,c===1&&l===1)return this._handleSingleObject(e,t,s,i,a);const m=me(c,l,t,h.create(f.NA)),d=me(c,l,s,h.create(f.NA)),_=me(c,l,i,h.create(f.NA)),D=me(c,l,a,h.create(f.NA));return m.mapValue((E,A,x)=>{const w=d.get(A,x),U=_.get(A,x),$=D.get(A,x);return E.isError()?E:w.isError()?w:U.isError()?U:$.isError()?$:this._handleSingleObject(e,E,w,U,$,!0)})}_handleSingleObject(e,t,s,i,a,o=!1){const{startRow:u,startColumn:c}=e.getRangeData(),l=this.getIndexNumValue(t),m=this.getIndexNumValue(s);if(typeof l!="number"||typeof m!="number")return h.create(f.VALUE);const d=u+l,_=c+m;if(d<0||_<0)return h.create(f.REF);const D=this.getIndexNumValue(i),E=this.getIndexNumValue(a);if(typeof D!="number"||typeof E!="number")return h.create(f.VALUE);if(D===0||E===0)return h.create(f.REF);const A=D>0?d+D-1:d+D+1,x=E>0?_+E-1:_+E+1;if(A<0||x<0)return h.create(f.REF);if(o)return h.create(f.VALUE);const w=d<A?d:A,U=_<x?_:x,$=d>A?d:A,se=_>x?_:x,he={startRow:w,startColumn:U,endRow:$,endColumn:se};return this.createReferenceObject(e,he)}}class Ja extends j{calculate(n){if(n==null)return b.create(this.row+1);if(n.isError())return n;if(!n.isArray())return h.create(f.NA);const e=n.getCurrentRow(),t=n.getRowCount(),s=[];for(let a=0;a<t;a++)s.push([b.create(e+a+1)]);const i={calculateValueList:s,rowCount:t,columnCount:1,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Le.create(i)}}class Na extends j{calculate(n){if(n==null)return h.create(f.NA);if(n.isError())return n;if(n.isString()||n.isNumber()||n.isBoolean())return b.create(1);if(!n.isArray())return h.create(f.NA);const e=n.getRowCount();return b.create(e)}}class eo extends j{calculate(n,e,t,s){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);if(t.isError()||s!=null&&s.isError())return h.create(f.NA);if(s=s!=null?s:Q.create(!0),Gn(n)&&Gn(s)&&t.isArray()){n=n.isArray()?n.getFirstCell():n;const c=this.getZeroOrOneByOneDefault(s);if(c==null)return h.create(f.VALUE);let l;const m=[];return t.iterator((d,_,D)=>{if(d==null)return l=h.create(f.VALUE),!1;const E=this._handleTableArray(n,e,d,c);if(E.isError())return l=E,!1;m[_]===void 0&&(m[_]=[]),m[_][D]=E}),l||Yt(m,m.length,m[0].length,this.unitId||"",this.subUnitId||"")}const i=Math.max(n.isArray()?n.getRowCount():1,s.isArray()?s.getRowCount():1),a=Math.max(n.isArray()?n.getColumnCount():1,s.isArray()?s.getColumnCount():1),o=me(i,a,n),u=me(i,a,s);return o.map((c,l,m)=>{if(c.isError())return c;const d=u.get(l,m);if(d==null)return h.create(f.VALUE);if(d.isError())return d;const _=this.getZeroOrOneByOneDefault(d);return _==null?h.create(f.VALUE):this._handleTableArray(c,e,t,_)})}_handleTableArray(n,e,t,s){const i=this.getIndexNumValue(t);if(i instanceof h)return i;const a=e.slice(void 0,[0,1]);if(a==null)return h.create(f.VALUE);const o=e.slice(void 0,[i-1,i]);return o==null?h.create(f.REF):this._handleSingleObject(n,a,o,s)}_handleSingleObject(n,e,t,s){return s===0?this.equalSearch(n,e,t):this.binarySearch(n,e,t)}}class to extends j{calculate(n,e,t,s,i,a){if(n==null||e==null||t==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const o=e.getRowCount(),u=e.getColumnCount();if(o!==1&&u!==1)return h.create(f.VALUE);if(t.isError())return h.create(f.REF);if(!t.isArray())return h.create(f.VALUE);const c=t.getRowCount(),l=t.getColumnCount();if(o!==c&&u!==l)return h.create(f.VALUE);if(s!=null&&s.isError()||i!=null&&i.isError()||a!=null&&a.isError())return h.create(f.NA);s==null&&(s=h.create(f.NA));const m=this.getIndexNumValue(i||b.create(0));if(m instanceof h)return m;const d=this.getIndexNumValue(a||b.create(1));if(d instanceof h)return d;if(n.isArray()){let E;return o===1?E=t.slice([0,1]):E=t.slice(void 0,[0,1]),E==null?h.create(f.NA):n.map(A=>{const x=this._handleSingleObject(A,e,E,m,d);return x.isError()?s:x})}if(u===l&&o===c){const E=this._handleSingleObject(n,e,t,m,d);return E.isError()?s:E}let _=0;u===l&&(_=1);const D=this._handleExpandObject(n,e,t,m,d,_);return D==null?h.create(f.NA):D}_handleExpandObject(n,e,t,s,i,a=0){return(i===2||i===-2)&&s!==2?this.binarySearchExpand(n,e,t,a,this._getSearchModeValue(i)):s===2?this.fuzzySearchExpand(n,e,t,i!==-1,a):s===-1||s===1?this.orderSearchExpand(n,e,t,s===1?xe.MAX:xe.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?xe.MAX:xe.MIN,i===-1):this.equalSearch(n,e,t,i!==-1)}_getSearchModeValue(n){return n===-2?Ke.MAX:Ke.MIN}}class ro extends j{calculate(n,e,t,s){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return h.create(f.REF);if(!e.isArray())return h.create(f.VALUE);const i=e.getRowCount(),a=e.getColumnCount();if(i!==1&&a!==1)return h.create(f.VALUE);if(t!=null&&t.isError()||s!=null&&s.isError())return h.create(f.NA);const o=this.getIndexNumValue(t||b.create(0));if(o instanceof h)return o;const u=this.getIndexNumValue(s||b.create(1));return u instanceof h?u:n.isArray()?n.map(c=>this._handleSingleObject(c,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,F.EQUALS);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}else if(t===-1||t===1){const a=e.orderSearch(n,t===1?xe.MAX:xe.MIN,s===-1);if(a==null)return h.create(f.NA);if(a instanceof h)return a;i=e.getRowCount()===1?a.column:a.row}else{const a=e.isEqual(n);let o;if(s!==-1?o=a.getFirstTruePosition():o=a.getLastTruePosition(),o==null)return h.create(f.NA);i=e.getRowCount()===1?o.column:o.row}return i==null?h.create(f.NA):b.create(i+1)}_getSearchModeValue(n){return n===-2?Ke.MAX:Ke.MIN}}class no extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,t,s,i){if(e==null)return h.create(f.NA);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;let a=0,o=0;if(e.isValueObject())a=1,o=1;else if(e.isReferenceObject()){const{startRow:l,endRow:m,startColumn:d,endColumn:_}=e.getRangeData();a=m-l+1,o=_-d+1}else return h.create(f.VALUE);a===1&&o>1&&s==null?(s=t!=null?t:b.create(0),t=b.create(0)):(t=t!=null?t:b.create(0),s=s!=null?s:b.create(0)),i=i!=null?i:b.create(1),t.isReferenceObject()&&(t=t.toArrayValueObject()),s.isReferenceObject()&&(s=s.toArrayValueObject()),i.isReferenceObject()&&(i=i.toArrayValueObject());const u=Math.max(t.isArray()?t.getRowCount():1,s.isArray()?s.getRowCount():1,i.isArray()?i.getRowCount():1),c=Math.max(t.isArray()?t.getColumnCount():1,s.isArray()?s.getColumnCount():1,i.isArray()?i.getColumnCount():1);if(t=t,s=s,i=i,u===1&&c===1)return this._calculateSingleCell(e,t,s,i);{const l=me(u,c,t,h.create(f.NA)),m=me(u,c,s,h.create(f.NA)),d=me(u,c,i,h.create(f.NA));return l.map((_,D,E)=>{const A=m.get(D,E)||ce.create(),x=d.get(D,E)||ce.create(),w=this._calculateSingleCell(e,_,A,x);return w.isReferenceObject()?w.toArrayValueObject().getFirstCell():w})}}_calculateSingleCell(e,t,s,i){if(t.isError())return t;const a=this._getNumberValue(t);if(a===void 0||a<0)return h.create(f.VALUE);if(s.isError())return s;const o=this._getNumberValue(s);if(o===void 0||o<0)return h.create(f.VALUE);if(i.isError())return i;const u=this._getAreaNumberValue(i);return u===void 0||u<1?h.create(f.VALUE):e.isReferenceObject()?this._getReferenceObject(e,a,o,u):e.isValueObject()&&a===1&&o===1?e:h.create(f.REF)}_getNumberValue(e){if(e==null)return 0;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getAreaNumberValue(e){if(e==null)return 1;let t=0;if(e.isBoolean())e.getValue()===!0&&(t=1);else{if(e.isString())return;e.isNumber()?t=Math.floor(e.getValue()):e.isNull()&&(t=0)}return t}_getReferenceObject(e,t,s,i){const{startRow:a,endRow:o,startColumn:u,endColumn:c}=e.getRangeData();let l=0,m=0,d=0,_=0;if(t===0?(l=a,m=o):l=m=a+t-1,s===0?(d=u,_=c):d=_=u+s-1,l>o||d>c)return h.create(f.REF);const D={startRow:l,startColumn:d,endRow:m,endColumn:_};return this.createReferenceObject(e,D)}}const Ws=[[za,be.ADDRESS],[Ha,be.COLUMN],[Wa,be.COLUMNS],[no,be.INDEX],[Xa,be.INDIRECT],[Za,be.OFFSET],[Ja,be.ROW],[Na,be.ROWS],[eo,be.VLOOKUP],[Ka,be.LOOKUP],[qa,be.MATCH],[Ga,be.HLOOKUP],[to,be.XLOOKUP],[ro,be.XMATCH]];class so extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.abs())}}class io extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?new h(f.VALUE):n.acos())}}class ao extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?h.create(f.VALUE):n.acosh())}}class oo extends j{calculate(n){return n==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:n.isArray()?n.map(e=>e.isError()?e:Xn(e)):Xn(n))}}function Xn(r){let n=r.getValue();if(r.isBoolean()&&(n=n?1:0),!Number.isFinite(n))return h.create(f.VALUE);const e=Math.atan(1/Number(n));return Number.isNaN(e)?h.create(f.VALUE):b.create(e)}var we=(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))(we||{});class uo extends j{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.mod(e)))}}class co extends j{calculate(n,e){return n==null||e==null?h.create(f.NA):(n.isString()&&(n=n.convertToNumberObjectValue()),n.isError()?n:(e.isString()&&(e=e.convertToNumberObjectValue()),e.isError()?e:n.pow(e)))}}class lo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(1);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=this._multiplyArray(s)),s.isError())return s;if(e=e.multiply(s),e.isError())return e}}return e}_multiplyArray(n){let e=b.create(1);return n.iterator(t=>{if(t==null||t.isString()||t.isBoolean()||t.isNull())return!0;if(t.isError())return e=t,!1;e=e.multiply(t)}),e}}class fo extends j{constructor(){super(...arguments);S(this,"needsReferenceObject",!0)}calculate(e,...t){if(e==null)return h.create(f.NA);if(e.isError())return e;if(t.length===0)return h.create(f.NA);if(e.isReferenceObject()){const s=[];return e.iterator((i,a,o)=>{s[a]==null&&(s[a]=[]),s[a][o]=this._handleSingleObject(i,...t)}),Yt(s,s.length,s[0].length)}return this._handleSingleObject(e,...t)}_handleSingleObject(e,...t){const s=this._getIndexNumValue(e);let i;if(s instanceof h)return s;switch(s){case 1:i=this._average(!1,...t);break;case 2:i=this._count(!1,...t);break;case 3:i=this._counta(!1,...t);break;case 4:i=this._max(!1,...t);break;case 5:i=this._min(!1,...t);break;case 6:i=this._product(!1,...t);break;case 7:i=this._stdev(!1,...t);break;case 8:i=this._stdevp(!1,...t);break;case 9:i=this._sum(!1,...t);break;case 10:i=this._var(!1,...t);break;case 11:i=this._varp(!1,...t);break;case 101:i=this._average(!0,...t);break;case 102:i=this._count(!0,...t);break;case 103:i=this._counta(!0,...t);break;case 104:i=this._max(!0,...t);break;case 105:i=this._min(!0,...t);break;case 106:i=this._product(!0,...t);break;case 107:i=this._stdev(!0,...t);break;case 108:i=this._stdevp(!0,...t);break;case 109:i=this._sum(!0,...t);break;case 110:i=this._var(!0,...t);break;case 111:i=this._varp(!0,...t);break;default:i=h.create(f.VALUE)}return i}_getIndexNumValue(e){const t=e?Number(e.getValue()):0;if(Number.isNaN(t))return h.create(f.VALUE);const s=Math.floor(t);return s>=1&&s<=11||s>=101&&s<=111?s:h.create(f.VALUE)}_average(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.mean()}_count(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.count()}_counta(e,...t){let s=b.create(0);for(let i=0;i<t.length;i++){const a=t[i];if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();a.iterator((u,c)=>{if(e&&this._isRowHidden(o,c)||u==null||u.isNull())return!0;s=s.plusBy(1)})}return s}_max(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.max()}_min(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?b.create(0):s.min()}_product(e,...t){const s=this._flattenRefArray(e,...t);if(s.isError())return s;if(this._isBlankArrayObject(s))return b.create(0);let i=b.create(1);return s.iterator(a=>{i=i.multiply(a)}),i}_stdev(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std(1)}_stdevp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.std()}_sum(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:s.sum()}_var(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var(1)}_varp(e,...t){const s=this._flattenRefArray(e,...t);return s.isError()?s:this._isBlankArrayObject(s)?h.create(f.DIV_BY_ZERO):s.var()}_flattenRefArray(e,...t){const s=[];s[0]=[];for(let i=0;i<t.length;i++){const a=t[i];if(a.isError())return a;if(!a.isReferenceObject())return h.create(f.VALUE);const o=a.getRowData();let u;if(a.iterator((c,l)=>{if(e&&this._isRowHidden(o,l)||c==null||c.isNull()||c.isString()||c.isBoolean())return!0;if(c.isError())return u=c,!1;s[0].push(c)}),u!=null&&u.isError())return u}return Yt(s,1,s[0].length)}_isRowHidden(e,t){const s=e[t];return s?s.hd===C.BooleanNumber.TRUE:!1}_isBlankArrayObject(e){return e.getArrayValue()[0].length===0}}class ho extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isString()&&(s=s.convertToNumberObjectValue()),s.isError())return s;if(s.isArray()&&(s=s.sum()),e=e.plus(s),e.isError())return e}return e}}function mo(r){const n=[F.EQUALS,F.NOT_EQUAL,F.GREATER_THAN_OR_EQUAL,F.GREATER_THAN,F.LESS_THAN_OR_EQUAL,F.LESS_THAN];for(const e of n)if(r.startsWith(e)){const t=r.substring(e.length);return[e,it.create(t)]}return[F.EQUALS,it.create(r)]}function Gs(r,n,e){if(!e)if(n.isString()){const t=`${n.getValue()}`,[s,i]=mo(t);e=s,n=i}else e=F.EQUALS;return r.compare(n,e)}function go(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=me(e,t,r),i=me(e,t,n);return s.mapValue((a,o,u)=>{const c=i.get(o,u);return a!=null&&a.isError()?a:c!=null&&c.isError()?c:a!=null&&a.isBoolean()&&(c!=null&&c.isBoolean())?Lr(a.getValue()&&c.getValue()):Q.create(!1)})}class po extends j{calculate(n,e,t){return n==null||e==null||n.isError()||e.isError()||t!=null&&t.isError()?h.create(f.NA):!n.isArray()||t&&!t.isArray()?h.create(f.VALUE):e.isArray()?e.map(s=>this._handleSingleObject(n,s,t)):this._handleSingleObject(n,e,t)}_handleSingleObject(n,e,t){const s=Gs(n,e),i=t?t.slice([0,n.getRowCount()],[0,n.getColumnCount()]):n;return i?i.pick(s).sum():h.create(f.VALUE)}}class Ro extends j{calculate(n,...e){if(n==null||e.length<2||n.isError())return h.create(f.NA);if(!n.isArray()||e.length<2||e.length%2!==0||e.some((l,m)=>m%2===0&&!l.isArray()))return h.create(f.VALUE);const t=n.getRowCount(),s=n.getColumnCount();let i=0,a=0;e.forEach((l,m)=>{if(m%2===1)if(l.isArray()){const d=l;i=Math.max(i,d.getRowCount()),a=Math.max(a,d.getColumnCount())}else i=Math.max(i,1),a=Math.max(a,1)});const o=[];for(let l=0;l<e.length;l++){if(l%2===1)continue;const m=e[l],d=m.getRowCount(),_=m.getColumnCount();if(d!==t||_!==s)return me(i,a,h.create(f.NA));const D=e[l+1];me(i,a,D,h.create(f.NA)).iterator((A,x,w)=>{if(!A)return;const U=Gs(m,A);if(o[x]===void 0&&(o[x]=[]),o[x][w]===void 0){o[x][w]=U;return}o[x][w]=go(o[x][w],U)})}const u=o.map(l=>l.map(m=>n.pick(m).sum())),c={calculateValueList:u,rowCount:u.length,columnCount:u[0].length,unitId:this.unitId||"",sheetId:this.subUnitId||"",row:this.row,column:this.column};return Le.create(c)}}const Xs=[[so,we.ABS],[io,we.ACOS],[ao,we.ACOSH],[oo,we.ACOT],[uo,we.MOD],[fo,we.SUBTOTAL],[ho,we.SUM],[po,we.SUMIF],[Ro,we.SUMIFS],[co,we.POWER],[lo,we.PRODUCT]];class _o extends j{constructor(){super(...arguments);S(this,"_compareType",F.EQUALS)}setCompareType(e){this._compareType=e}calculate(e,t){return e.isError()?e:t.isError()?t:e.compare(t,this._compareType)}}class dn extends Ze{constructor(e){super("");S(this,"_values",[]);this._values=e}static create(e){return new dn(e)}isCube(){return!0}sum(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.sum())}),e}max(){let e=b.create(Number.NEGATIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isLessThan(s)&&(e=s)}),e}min(){let e=b.create(Number.POSITIVE_INFINITY);return this._values.forEach(t=>{const s=t.max();e.isGreaterThan(s)&&(e=s)}),e}count(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.count())}),e}countA(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countA())}),e}countBlank(){const e=b.create(0);return this._values.forEach(t=>{e.plus(t.countBlank())}),e}}class Eo extends j{calculate(...n){if(n.length===0)return h.create(f.VALUE);const e=[];for(let t=0;t<n.length;t++){const s=n[t];if(s.isError())return s;if(!s.isArray())return h.create(f.VALUE);e.push(s)}return dn.create(e)}}class Co extends j{calculate(n,e){return n.isError()?n:e.isError()?e:!e.isArray()&&e.getValue()===0?h.create(f.DIV_BY_ZERO):n.divided(e)}}var Ae=(r=>(r.COMPARE="COMPARE",r.DIVIDED="DIVIDED",r.MINUS="MINUS",r.MULTIPLY="MULTIPLY",r.PLUS="PLUS",r.UNION="UNION",r.CUBE="CUBE",r))(Ae||{});class yo extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.minus(e)}}class Do extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.multiply(e)}}class bo extends j{calculate(n,e){return n.isError()?n:e.isError()?e:n.plus(e)}}const Ks=[[_o,Ae.COMPARE],[Co,Ae.DIVIDED],[yo,Ae.MINUS],[Do,Ae.MULTIPLY],[bo,Ae.PLUS],[Eo,Ae.CUBE]];class So extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0),t=b.create(0);for(let s=0;s<n.length;s++){let i=n[s];if(i.isString()&&(i=i.convertToNumberObjectValue()),i.isError())return i;if(i.isArray()){if(e=e.plus(i.sum()),e.isError())return e;t=t.plus(i.count())}else i.isNull()||(e=e.plus(i),t=t.plus(b.create(1)))}return e.divided(t)}}class Ao extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){const s=n[t];s.isError()||(s.isArray()?e=e.plus(s.count()):s.isString()?s.convertToNumberObjectValue().isError()||(e=e.plus(b.create(1))):s.isNull()||(e=e.plus(b.create(1))))}return e}}class Lo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(0);for(let t=0;t<n.length;t++){let s=n[t];if(s.isError()){e=e.plus(b.create(1));continue}s.isArray()?(s=s.countA(),e=e.plus(s)):s.isNull()||(e=e.plus(b.create(1)))}return e}}var Se=(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))(Se||{});class xo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.NEGATIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if(!s.isNull()){if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.max()),s.isError())return s;e=this._validator(e,s)}}return e}_validator(n,e){return n.isLessThan(e).getValue()&&(n=e),n}}class Kn extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=b.create(Number.POSITIVE_INFINITY);for(let t=0;t<n.length;t++){let s=n[t];if((s.isString()||s.isBoolean())&&(s=s.convertToNumberObjectValue()),s.isArray()&&(s=s.min()),s.isError())return s;s.isNull()||(e=this._validator(e,s))}return e}_validator(n,e){return n.isGreaterThan(e).getValue()&&(n=e),n}}class wo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std(1)}}class Po extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.std()}}class Vo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var(1)}}class vo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);const e=this.flattenArray(n,!1);return e.isError()?e:e.var()}}const qs=[[So,Se.AVERAGE],[Ao,Se.COUNT],[xo,Se.MAX],[Kn,Se.MIN],[Kn,Se.MIN],[Lo,Se.COUNTA],[Vs,Se.STDEV_P],[vs,Se.STDEV_S],[wo,Se.STDEVA],[Po,Se.STDEVPA],[Ms,Se.VAR_P],[Os,Se.VAR_S],[Vo,Se.VARA],[vo,Se.VARPA]];class Mo extends j{calculate(...n){if(n.length===0)return h.create(f.NA);let e=0,t=0;n.forEach(i=>{if(i.isArray()){const a=i;e=Math.max(e,a.getRowCount()),t=Math.max(t,a.getColumnCount())}else e=Math.max(e,1),t=Math.max(t,1)});let s=null;for(const i of n)s=me(e,t,i,h.create(f.NA)).mapValue((o,u,c)=>{var _,D;const l=s&&s.get(u,c);if(l!=null&&l.isError())return l;if(o.isError())return o;const m=l!=null&&l.isNull()?"":(_=l==null?void 0:l.getValue())!=null?_:"",d=o!=null&&o.isNull()?"":(D=o==null?void 0:o.getValue())!=null?D:"";return on(`${m}${d}`)});return s||h.create(f.VALUE)}}var mt=(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))(mt||{});class Oo extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString();return b.create(e.length)}return h.create(f.VALUE)}}function Fo(r){let n=0;for(let e=0;e<r.length;e++){const t=r.charCodeAt(e);t>=12352&&t<=12543||t>=19968&&t<=40959||t>=44032&&t<=55215?n+=2:n+=1}return n}class Bo extends j{calculate(n){return n==null?h.create(f.NA):n.isError()?n:n.isArray()?n.mapValue(e=>this._handleSingleText(e)):this._handleSingleText(n)}_handleSingleText(n){if(n.isError())return n;if(n.isNull())return b.create(0);if(n.isString()||n.isBoolean()||n.isNumber()){const e=n.getValue().toString(),t=Fo(e);return b.create(t)}return h.create(f.VALUE)}}var Uo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ko(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Zs={exports:{}};(function(r,n){(function(e,t){r.exports=t()})(typeof self<"u"?self:Uo,function(){return function(){var e={d:function(p,g){for(var R in g)e.o(g,R)&&!e.o(p,R)&&Object.defineProperty(p,R,{enumerable:!0,get:g[R]})},o:function(p,g){return Object.prototype.hasOwnProperty.call(p,g)}},t={};e.d(t,{default:function(){return wi}});var s={1078:"af",1052:"sq",1118:"am",5121:"ar_DZ",15361:"ar_BH",3073:"ar_EG",2049:"ar_IQ",11265:"ar_JO",13313:"ar_KW",12289:"ar_LB",4097:"ar_LY",6145:"ar_MA",8193:"ar_OM",16385:"ar_QA",1025:"ar_SA",10241:"ar_SY",7169:"ar_TN",14337:"ar_AE",9217:"ar_YE",1067:"hy",1101:"as",2092:"az_AZ",1068:"az_AZ",1069:"eu",1059:"be",2117:"bn",1093:"bn_IN",5146:"bs",1026:"bg",1109:"my",1027:"ca",2052:"zh_CN",3076:"zh_HK",5124:"zh_MO",4100:"zh_SG",1028:"zh_TW",1050:"hr",1029:"cs",1030:"da",1125:"dv",2067:"nl_BE",1043:"nl_NL",1126:"bin",3081:"en_AU",10249:"en_BZ",4105:"en_CA",9225:"en_CB",2057:"en_GB",16393:"en_IN",6153:"en_IE",8201:"en_JM",5129:"en_NZ",13321:"en_PH",7177:"en_ZA",11273:"en_TT",1033:"en_US",12297:"en_ZW",1061:"et",1071:"mk",1080:"fo",1065:"fa",1124:"fil",1035:"fi",2060:"fr_BE",11276:"fr_CM",3084:"fr_CA",9228:"fr_CG",12300:"fr_CI",1036:"fr_FR",5132:"fr_LU",13324:"fr_ML",6156:"fr_MC",14348:"fr_MA",10252:"fr_SN",4108:"fr_CH",7180:"fr",1122:"fy_NL",2108:"gd_IE",1084:"gd",1110:"gl",1079:"ka",3079:"de_AT",1031:"de_DE",5127:"de_LI",4103:"de_LU",2055:"de_CH",1032:"el",1140:"gn",1095:"gu",1279:"en",1037:"he",1081:"hi",1038:"hu",1039:"is",1136:"ig_NG",1057:"id",1040:"it_IT",2064:"it_CH",1041:"ja",1099:"kn",1120:"ks",1087:"kk",1107:"km",1111:"kok",1042:"ko",1088:"ky",1108:"lo",1142:"la",1062:"lv",1063:"lt",2110:"ms_BN",1086:"ms_MY",1100:"ml",1082:"mt",1112:"mni",1153:"mi",1102:"mr",1104:"mn",2128:"mn",1121:"ne",1044:"no_NO",2068:"no_NO",1096:"or",1045:"pl",1046:"pt_BR",2070:"pt_PT",1094:"pa",1047:"rm",2072:"ro_MO",1048:"ro_RO",1049:"ru",2073:"ru_MO",1083:"se",1103:"sa",3098:"sr_SP",2074:"sr_SP",1072:"st",1074:"tn",1113:"sd",1115:"si",1051:"sk",1060:"sl",1143:"so",1070:"sb",11274:"es_AR",16394:"es_BO",13322:"es_CL",9226:"es_CO",5130:"es_CR",7178:"es_DO",12298:"es_EC",17418:"es_SV",4106:"es_GT",18442:"es_HN",2058:"es_MX",19466:"es_NI",6154:"es_PA",15370:"es_PY",10250:"es_PE",20490:"es_PR",1034:"es_ES",14346:"es_UY",8202:"es_VE",1089:"sw",2077:"sv_FI",1053:"sv_SE",1114:"syc",1064:"tg",1097:"ta",1092:"tt",1098:"te",1054:"th",1105:"bo",1073:"ts",1055:"tr",1090:"tk",1058:"uk",1056:"ur",2115:"uz_UZ",1091:"uz_UZ",1075:"ve",1066:"vi",1106:"cy",1076:"xh",1085:"yi",1077:"zu"};const i=/^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i,a={},o={group:" ",decimal:".",positive:"+",negative:"-",percent:"%",exponent:"E",nan:"NaN",infinity:"∞",ampm:["AM","PM"],mmmm6:["Muharram","Safar","Rabiʻ I","Rabiʻ II","Jumada I","Jumada II","Rajab","Shaʻban","Ramadan","Shawwal","Dhuʻl-Qiʻdah","Dhuʻl-Hijjah"],mmm6:["Muh.","Saf.","Rab. I","Rab. II","Jum. I","Jum. II","Raj.","Sha.","Ram.","Shaw.","Dhuʻl-Q.","Dhuʻl-H."],mmmm:["January","February","March","April","May","June","July","August","September","October","November","December"],mmm:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dddd:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ddd:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]};function u(p){const g=i.exec(p);if(!g)throw new SyntaxError("Malformed locale: ".concat(p));return{lang:g[1]+(g[2]?"_"+g[2]:""),language:g[1],territory:g[2]||"",codeset:g[3]||"",modifier:g[4]||""}}function c(p){if(typeof p=="number")return s[65535&p]||null;const g=parseInt(p,16);return isFinite(g)&&s[65535&g]?s[65535&g]||null:i.test(p)?p:null}function l(p){const g=c(p);let R=null;if(g){const L=u(g);R=a[L.lang]||a[L.language]||null}return R}function m(p){return Object.assign({},o,p)}function d(p,g){const R=typeof g=="object"?g:u(g);return a[R.lang]=m(p),R.language===R.lang||a[R.language]||(a[R.language]=m(p)),a[R.lang]}const _=m({group:","});function D(p,g){if(typeof p!="number")return p;if(p<0)return-D(-p,g);if(g){const R=10**(g||0)||1;return D(p*R,0)/R}return Math.round(p)}_.isDefault=!0,d({group:",",ampm:["上午","下午"],mmmm:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["周日","周一","周二","周三","周四","周五","周六"]},"zh_CN"),d({group:",",nan:"非數值",ampm:["上午","下午"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],ddd:["週日","週一","週二","週三","週四","週五","週六"]},"zh_TW"),d({group:",",ampm:["午前","午後"],mmmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],mmm:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"],dddd:["日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日"],ddd:["日","月","火","水","木","金","土"]},"ja"),d({group:",",ampm:["오전","오후"],mmmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],mmm:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],dddd:["일요일","월요일","화요일","수요일","목요일","금요일","토요일"],ddd:["일","월","화","수","목","금","토"]},"ko"),d({group:",",ampm:["ก่อนเที่ยง","หลังเที่ยง"],mmmm:["มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม"],mmm:["ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค."],dddd:["วันอาทิตย์","วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัสบดี","วันศุกร์","วันเสาร์"],ddd:["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."]},"th"),d({decimal:",",ampm:["dop.","odp."],mmmm:["ledna","února","března","dubna","května","června","července","srpna","září","října","listopadu","prosince"],mmm:["led","úno","bře","dub","kvě","čvn","čvc","srp","zář","říj","lis","pro"],dddd:["neděle","pondělí","úterý","středa","čtvrtek","pátek","sobota"],ddd:["ne","po","út","st","čt","pá","so"]},"cs"),d({group:".",decimal:",",mmmm:["januar","februar","marts","april","maj","juni","juli","august","september","oktober","november","december"],mmm:["jan.","feb.","mar.","apr.","maj","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"da"),d({group:".",decimal:",",ampm:["a.m.","p.m."],mmmm:["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"],mmm:["jan.","feb.","mrt.","apr.","mei","jun.","jul.","aug.","sep.","okt.","nov.","dec."],dddd:["zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag"],ddd:["zo","ma","di","wo","do","vr","za"]},"nl"),d({group:","},"en"),d({decimal:",",nan:"epäluku",ampm:["ap.","ip."],mmmm:["tammikuuta","helmikuuta","maaliskuuta","huhtikuuta","toukokuuta","kesäkuuta","heinäkuuta","elokuuta","syyskuuta","lokakuuta","marraskuuta","joulukuuta"],mmm:["tammik.","helmik.","maalisk.","huhtik.","toukok.","kesäk.","heinäk.","elok.","syysk.","lokak.","marrask.","jouluk."],dddd:["sunnuntaina","maanantaina","tiistaina","keskiviikkona","torstaina","perjantaina","lauantaina"],ddd:["su","ma","ti","ke","to","pe","la"]},"fi"),d({group:" ",decimal:",",mmmm:["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],mmm:["janv.","févr.","mars","avr.","mai","juin","juil.","août","sept.","oct.","nov.","déc."],dddd:["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],ddd:["dim.","lun.","mar.","mer.","jeu.","ven.","sam."]},"fr"),d({group:".",decimal:",",mmmm:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],mmm:["Jan.","Feb.","März","Apr.","Mai","Juni","Juli","Aug.","Sept.","Okt.","Nov.","Dez."],dddd:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],ddd:["So.","Mo.","Di.","Mi.","Do.","Fr.","Sa."]},"de"),d({group:".",decimal:",",ampm:["π.μ.","μ.μ."],mmmm:["Ιανουαρίου","Φεβρουαρίου","Μαρτίου","Απριλίου","Μαΐου","Ιουνίου","Ιουλίου","Αυγούστου","Σεπτεμβρίου","Οκτωβρίου","Νοεμβρίου","Δεκεμβρίου"],mmm:["Ιαν","Φεβ","Μαρ","Απρ","Μαΐ","Ιουν","Ιουλ","Αυγ","Σεπ","Οκτ","Νοε","Δεκ"],dddd:["Κυριακή","Δευτέρα","Τρίτη","Τετάρτη","Πέμπτη","Παρασκευή","Σάββατο"],ddd:["Κυρ","Δευ","Τρί","Τετ","Πέμ","Παρ","Σάβ"]},"el"),d({decimal:",",ampm:["de.","du."],mmmm:["január","február","március","április","május","június","július","augusztus","szeptember","október","november","december"],mmm:["jan.","febr.","márc.","ápr.","máj.","jún.","júl.","aug.","szept.","okt.","nov.","dec."],dddd:["vasárnap","hétfő","kedd","szerda","csütörtök","péntek","szombat"],ddd:["V","H","K","Sze","Cs","P","Szo"]},"hu"),d({group:".",decimal:",",ampm:["f.h.","e.h."],mmmm:["janúar","febrúar","mars","apríl","maí","júní","júlí","ágúst","september","október","nóvember","desember"],mmm:["jan.","feb.","mar.","apr.","maí","jún.","júl.","ágú.","sep.","okt.","nóv.","des."],dddd:["sunnudagur","mánudagur","þriðjudagur","miðvikudagur","fimmtudagur","föstudagur","laugardagur"],ddd:["sun.","mán.","þri.","mið.","fim.","fös.","lau."]},"is"),d({group:".",decimal:",",mmmm:["Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"],mmm:["Jan","Feb","Mar","Apr","Mei","Jun","Jul","Agu","Sep","Okt","Nov","Des"],dddd:["Minggu","Senin","Selasa","Rabu","Kamis","Jumat","Sabtu"],ddd:["Min","Sen","Sel","Rab","Kam","Jum","Sab"]},"id"),d({group:".",decimal:",",mmmm:["gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto","settembre","ottobre","novembre","dicembre"],mmm:["gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"],dddd:["domenica","lunedì","martedì","mercoledì","giovedì","venerdì","sabato"],ddd:["dom","lun","mar","mer","gio","ven","sab"]},"it"),d({decimal:",",ampm:["a.m.","p.m."],mmmm:["januar","februar","mars","april","mai","juni","juli","august","september","oktober","november","desember"],mmm:["jan.","feb.","mar.","apr.","mai","jun.","jul.","aug.","sep.","okt.","nov.","des."],dddd:["søndag","mandag","tirsdag","onsdag","torsdag","fredag","lørdag"],ddd:["søn.","man.","tir.","ons.","tor.","fre.","lør."]},"nb"),d({decimal:",",mmmm:["stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia"],mmm:["sty","lut","mar","kwi","maj","cze","lip","sie","wrz","paź","lis","gru"],dddd:["niedziela","poniedziałek","wtorek","środa","czwartek","piątek","sobota"],ddd:["niedz.","pon.","wt.","śr.","czw.","pt.","sob."]},"pl"),d({group:".",decimal:",",mmmm:["janeiro","fevereiro","março","abril","maio","junho","julho","agosto","setembro","outubro","novembro","dezembro"],mmm:["jan.","fev.","mar.","abr.","mai.","jun.","jul.","ago.","set.","out.","nov.","dez."],dddd:["domingo","segunda-feira","terça-feira","quarta-feira","quinta-feira","sexta-feira","sábado"],ddd:["dom.","seg.","ter.","qua.","qui.","sex.","sáb."]},"pt"),d({decimal:",",nan:"не число",mmmm:["января","февраля","марта","апреля","мая","июня","июля","августа","сентября","октября","ноября","декабря"],mmm:["янв.","февр.","мар.","апр.","мая","июн.","июл.","авг.","сент.","окт.","нояб.","дек."],dddd:["воскресенье","понедельник","вторник","среда","четверг","пятница","суббота"],ddd:["вс","пн","вт","ср","чт","пт","сб"]},"ru"),d({decimal:",",mmmm:["januára","februára","marca","apríla","mája","júna","júla","augusta","septembra","októbra","novembra","decembra"],mmm:["jan","feb","mar","apr","máj","jún","júl","aug","sep","okt","nov","dec"],dddd:["nedeľa","pondelok","utorok","streda","štvrtok","piatok","sobota"],ddd:["ne","po","ut","st","št","pi","so"]},"sk"),d({group:".",decimal:",",ampm:["a. m.","p. m."],mmmm:["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"],mmm:["ene.","feb.","mar.","abr.","may.","jun.","jul.","ago.","sept.","oct.","nov.","dic."],dddd:["domingo","lunes","martes","miércoles","jueves","viernes","sábado"],ddd:["dom.","lun.","mar.","mié.","jue.","vie.","sáb."]},"es"),d({decimal:",",ampm:["fm","em"],mmmm:["januari","februari","mars","april","maj","juni","juli","augusti","september","oktober","november","december"],mmm:["jan.","feb.","mars","apr.","maj","juni","juli","aug.","sep.","okt.","nov.","dec."],dddd:["söndag","måndag","tisdag","onsdag","torsdag","fredag","lördag"],ddd:["sön","mån","tis","ons","tors","fre","lör"]},"sv"),d({group:".",decimal:",",ampm:["ÖÖ","ÖS"],mmmm:["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık"],mmm:["Oca","Şub","Mar","Nis","May","Haz","Tem","Ağu","Eyl","Eki","Kas","Ara"],dddd:["Pazar","Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi"],ddd:["Paz","Pzt","Sal","Çar","Per","Cum","Cmt"]},"tr");function E(p,g,R){const L=p<0?-1:1,V=10**(g||2),B=10**(R||2);let v,P,y=Math.abs(p),T=0,H=0,M=0,W=1;if((p=y)%1==0)P=[p*L,1];else if(p<1e-19)P=[L,1e19];else if(p>1e19)P=[1e19*L,1];else{do if(y=1/(y-Math.floor(y)),v=W,W=W*Math.floor(y)+T,T=v,H=M,M=Math.floor(p*W+.5),M>=V||W>=B)return[L*H,T];while(Math.abs(p-M/W)>=1e-10&&y!==Math.floor(y));P=[L*M,W]}return P}const A={overflow:"######",dateErrorThrows:!1,dateErrorNumber:!0,dateSpanLarge:!0,leap1900:!0,nbsp:!0,throws:!0,invalid:"######",locale:"",ignoreTimezone:!1},x=Object.assign({},A);function w(p){if(p===null&&(p=A),p){for(const g in p)if(g in A){const R=p[g];x[g]=R==null?A[g]:R}}return{...x}}const U={"#":"",0:"0","?":" "},$={"@":"text","-":"minus","+":"plus"},se=["#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#000","#FFF","#F00","#0F0","#00F","#FF0","#F0F","#0FF","#800","#080","#008","#880","#808","#088","#CCC","#888","#99F","#936","#FFC","#CFF","#606","#F88","#06C","#CCF","#008","#F0F","#FF0","#0FF","#808","#800","#088","#00F","#0CF","#CFF","#CFC","#FF9","#9CF","#F9C","#C9F","#FC9","#36F","#3CC","#9C0","#FC0"],he=["¤","$","£","¥","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿"],de=new RegExp("["+he.join("")+"]");function q(p,g,R){return g[R+"_max"]=p.length,g[R+"_min"]=p.replace(/#/g,"").length,g}const z={};function re(p){if(!(p in z)){const g=[],R=p.replace(/^[#,]+/,"").replace(/[1-9]\d*/g,L=>"?".repeat(L.length));for(let L=0;L<R.length;L++){const V=R.charAt(L);g[L]=V in U?U[V]:V}z[p]=g.join("")}return z[p]}function Z(p,g){typeof p=="string"&&(p={type:"string",value:p=p.replace(/ /g,U["?"])}),g.push(p)}function Ve(p){const g=[],R={scale:1,percent:!1,text:!1,date:0,date_eval:!1,date_system:1,sec_decimals:0,general:!1,clock:24,int_pattern:[],frac_pattern:[],man_pattern:[],den_pattern:[],num_pattern:[],tokens:g};let L=p+"",V="int",B=!1,v=null;const P=[];let y,T,H=!1;for(;L&&!B;){if(y=/^General/i.exec(L))R.general=!0,Z({type:"general"},g);else if(V==="int"&&(y=/^[#?0]+(?:,[#?0]+)*/.exec(L))||V==="den"&&(y=/^[#?\d]+/.exec(L))||(y=/^[#?0]+/.exec(L)))R[V+"_pattern"].push(y[0]),v={type:V,num:y[0]},Z(v,g);else if((y=/^\//.exec(L))&&R[V+"_pattern"].length){if(!v)throw new SyntaxError("Missing a numerator in pattern ".concat(p));R.fractions=!0,R.num_pattern.push(R[V+"_pattern"].pop()),v.type="num",V="den",Z({type:"div"},g)}else if(y=/^,+/.exec(L)){const O=L.charAt(1)in U;T.slice(-1)in U&&(y[0].length>1||!O)?R.scale=.001**y[0].length:R.dec_fractions||Z(y[0],g)}else{if(y=/^;/.exec(L)){B=!0;break}if(y=/^[@+-]/.exec(L))y[0]==="@"&&(R.text=!0),Z({type:$[y[0]]},g);else if(y=/^(?:\[(h+|m+|s+)\])/i.exec(L)){const O=y[1].toLowerCase(),Y=O[0],K={type:"",size:0,date:1,raw:y[0],pad:O.length};Y==="h"?(K.size=16,K.type="hour-elap"):Y==="m"?(K.size=32,K.type="min-elap"):(K.size=64,K.type="sec-elap"),R.date=R.date|K.size,P.push(K),Z(K,g)}else if(y=/^(?:B2)/i.exec(L))H||(R.date_system=6);else if(y=/^(?:B1)/i.exec(L))H||(R.date_system=1);else if(y=/^(?:([hHmMsSyYbBdDegG])\1*)/.exec(L)){const O={type:"",size:0,date:1,raw:y[0]},Y=y[0].toLowerCase(),K=Y[0];if(Y==="y"||Y==="yy")O.size=2,O.type="year-short";else if(K==="y"||K==="e")O.size=2,O.type="year";else if(Y==="b"||Y==="bb")O.size=2,O.type="b-year-short";else if(K==="b")O.size=2,O.type="b-year";else if(Y==="d"||Y==="dd")O.size=8,O.type="day",O.pad=/dd/.test(Y);else if(Y==="ddd")O.size=8,O.type="weekday-short";else if(K==="d")O.size=8,O.type="weekday";else if(K==="h")O.size=16,O.type="hour",O.pad=/hh/i.test(Y);else if(K==="m"){Y.length===3?(O.size=4,O.type="monthname-short"):Y.length===5?(O.size=4,O.type="monthname-single"):Y.length>=4&&(O.size=4,O.type="monthname");const ne=P[P.length-1];!O.type&&ne&&!ne.used&&80&ne.size&&(ne.used=!0,O.size=32,O.type="min",O.pad=/mm/.test(Y)),O.type||(O.size=4,O.type="month",O.pad=/mm/.test(Y),O.indeterminate=!0)}else if(K==="s"){O.size=64,O.type="sec",O.pad=/ss/.test(Y);const ne=P[P.length-1];ne&&32&ne.size?O.used=!0:ne&&ne.indeterminate&&(delete ne.indeterminate,ne.size=32,ne.type="min",O.used=!0)}R.date=R.date|O.size,R.date_eval=!0,P.push(O),Z(O,g)}else if(y=/^(?:AM\/PM|am\/pm|A\/P)/.exec(L))R.clock=12,R.date=16|R.date,R.date_eval=!0,Z({type:"am",short:y[0]==="A/P"},g);else if(R.date&&(y=/^\.0{1,3}/i.exec(L))){const O=y[0].length-1,Y=[64,128,256,512][O];R.date=R.date|Y,R.date_eval=!0,R.sec_decimals=Math.max(R.sec_decimals,O),Z({type:"subsec",size:Y,decimals:O,date:1,raw:y[0]},g)}else if((y=/^\\(.)/.exec(L))||(y=/^"([^"]*?)"/.exec(L)))Z(y[1],g);else if(y=/^\[(<[=>]?|>=?|=)\s*(-?[.\d]+)\]/.exec(L))R.condition=[y[1],parseFloat(y[2],10)];else if(y=/^\[\$([^\]]+)\]/.exec(L)){const O=y[1].split("-"),Y=O.length<2?"":O[O.length-1],K=O[0];K&&Z(K,g);const ne=c(Y);ne&&(R.locale=ne);const oe=parseInt(Y,16);isFinite(oe)&&16711680&oe&&(oe>>16&255)===6&&(R.date_system=6),H=!0}else if(y=/^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*(\d+))\]/i.exec(L))R.color=y[2]?se[parseInt(y[2],10)]||"#000":y[1].toLowerCase();else if(!(y=/^\[(DBNum1|ENG|HIJ|JPN|TWN)\]/i.exec(L))){if(y=/^%/.exec(L))R.scale=100,R.percent=!0,Z("%",g);else if(y=/^_(\\.|.)/.exec(L))Z(" ",g);else if(y=/^\./.exec(L))Z({type:"point",value:y[0]},g),R.dec_fractions=!0,V="frac";else if(y=/^[Ee]([+-]?|(?=[0#?]))/.exec(L))R.exponential=!0,R.exp_plus=y[1]==="+",V="man",Z({type:"exp",plus:y[1]==="+"},g);else if(!(y=/^\*(\\.|.)/.exec(L))){if(y=/^[BENn[]/.exec(L))throw new SyntaxError("Unexpected char ".concat(L.charAt(0)," in pattern ").concat(p));L[0]==="("&&(R.parens=!0),y=[L[0]],Z(y[0],g)}}}T=y[0],L=L.slice(y?y[0].length:1)}if(R.pattern=p.slice(0,p.length-L.length),/^((?:\[[^\]]+\])+)(;|$)/.test(R.pattern)&&!/^\[(?:h+|m+|s+)\]/.test(R.pattern)&&Z({type:"text"},g),R.fractions&&R.dec_fractions||R.fractions&&R.exponential)throw new SyntaxError("Invalid pattern: ".concat(R.pattern));const M=R.int_pattern.join("");if(R.grouping=M.indexOf(",")>=0,R.grouping){const O=M.split(","),Y=O.length;Y===2?(R.group_pri=O[1].length,R.group_sec=R.group_pri):Y>2&&(R.group_pri=O[Y-1].length,R.group_sec=O[Y-2].length)}else R.group_pri=0,R.group_sec=0;q(M.replace(/[,]/g,""),R,"int"),q(R.frac_pattern.join(""),R,"frac"),q(R.man_pattern.join(""),R,"man");let W=R.num_pattern.join(""),ee=R.den_pattern.join("");const X=/\?/.test(ee)||/\?/.test(W);return ee=ee.replace(/\d/g,X?"?":"#"),X&&(ee=ee.replace(/#$/g,"?")),q(W,R,"num"),q(ee,R,"den"),X&&(W=W.replace(/#$/g,"?")),R.int_padding=re(R.int_pattern.join("")),R.man_padding=re(R.man_pattern.join("")),R.num_padding=re(W),R.den_padding=re(ee),R.den_pattern.length&&(R.denominator=parseInt(R.den_pattern.join("").replace(/\D/g,""),10)),R.integer=!!R.int_pattern.join("").length,R.fractions&&g.forEach((O,Y)=>{const K=g[Y+1];O.type==="string"&&K&&(K.type==="num"?O.rule="num+int":K.type==="div"?O.rule="num":K.type==="den"&&(O.rule="den"))}),R}const je=p=>{const g=p.condition;g&&g[1]<0&&(g[0]==="<"||g[0]==="<="||g[0]==="=")||p.tokens.unshift({type:"minus",volatile:!0})};function vt(p){const g=[];let R,L=!1,V=null,B=p,v=0,P=!1,y=0,T=0;do{if(P=Ve(B),(P.date||P.general)&&(P.int_pattern.length||P.frac_pattern.length||P.scale!==1||P.text))throw new Error("Illegal format");if(P.condition&&(T++,L=!0),P.text){if(V)throw new Error("Unexpected partition");V=P}P.locale&&(R=c(P.locale)),g.push(P),v=B.charAt(P.pattern.length)===";"?1:0,B=B.slice(P.pattern.length+v),y++}while(v&&y<4&&T<3);if(v)throw new Error("Unexpected partition");if(T>2)throw new Error("Unexpected condition");const H=g[3];if(H&&(H.int_pattern.length||H.frac_pattern.length||H.date))throw new Error("Unexpected partition");if(L){const M=g.length;if(M===1&&(g[1]=Ve("General"),g[1].generated=!0),M<3){const W=g[0],ee=g[1];if(je(W),ee.condition)je(ee);else{const X=W.condition;(X[0]==="="||X[1]>=0&&(X[0]===">"||X[0]===">="))&&ee.tokens.unshift({type:"minus",volatile:!0})}}else g.forEach(je)}else{if(g.length<4&&V)for(let M=0,W=g.length;M<W;M++)g[M]===V&&g.splice(M,1);if(g.length<1&&V&&(g[0]=Ve("General"),g[0].generated=!0),g.length<2){const M=Ve(g[0].pattern);M.tokens.unshift({type:"minus",volatile:!0}),M.generated=!0,g.push(M)}if(g.length<3){const M=Ve(g[0].pattern);M.generated=!0,g.push(M)}if(g.length<4)if(V)g.push(V);else{const M=Ve("@");M.generated=!0,g.push(M)}g[0].condition=[">",0],g[1].condition=["<",0],g[2].condition=null}return{pattern:p,partitions:g,locale:R}}const De=Math.floor;function _n(p){if((!(arguments.length>1&&arguments[1]!==void 0)||arguments[1])&&p>=0){if(p===0)return[1900,1,0];if(p===60)return[1900,2,29];if(p<60)return[1900,p<32?1:2,(p-1)%31+1]}let R=p+68569+2415019;const L=De(4*R/146097);R-=De((146097*L+3)/4);const V=De(4e3*(R+1)/1461001);R=R-De(1461*V/4)+31;const B=De(80*R/2447),v=R-De(2447*B/80);R=De(B/11);const P=B+2-12*R;return[0|100*(L-49)+V+R,0|P,0|v]}function gi(p){return _n(p+1462)}function pi(p){if(p===60)throw new Error("#VALUE!");if(p<=1)return[1317,8,29];if(p<60)return[1317,p<32?9:10,1+(p-2)%30];const g=10631/30,R=.1335;let L=p+466935;const V=De(L/10631);L-=10631*V;const B=De((L-R)/g);L-=De(B*g+R);const v=De((L+28.5001)/29.5);return v===13?[30*V+B,12,30]:[30*V+B,v,L-De(29.5001*v-29)]}function En(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,R=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];const L=De(p);return g===6?pi(L):g===-1?gi(L):_n(L,R)}const Kt=Math.floor,vr=86400;function qt(p,g){let R=null;if(Array.isArray(p)){const[L,V,B,v,P,y]=p;R=Date.UTC(L,V==null?0:V-1,B!=null?B:1,v||0,P||0,y||0)}else if(p instanceof Date&&(R=1*p,!g||!g.ignoreTimezone)){const L=new Date;L.setUTCFullYear(p.getFullYear(),p.getMonth(),p.getDate()),L.setUTCHours(p.getHours(),p.getMinutes(),p.getSeconds(),p.getMilliseconds()),R=1*L}if(R!=null&&isFinite(R)){const L=R/864e5;return L-(L<=-25509?-25568:-25569)}return p}function Cn(p,g){let R=0|p;const L=vr*(p-R);let V=Kt(L);L-V>.9999&&(V+=1,V===vr&&(V=0,R+=1));const B=V<0?vr+V:V,[v,P,y]=En(p,0,g&&g.leap1900),T=Kt(B/60/60)%60,H=Kt(B/60)%60,M=Kt(B)%60;if(g&&g.nativeDate){const W=new Date(0);return W.setUTCFullYear(v,P-1,y),W.setUTCHours(T,H,M),W}return[v,P,y,T,H,M]}function Ri(p){return!!(p[0]&&p[0].percent||p[1]&&p[1].percent||p[2]&&p[2].percent||p[3]&&p[3].percent)}function _i(p){return!!(p[0]&&p[0].date||p[1]&&p[1].date||p[2]&&p[2].date||p[3]&&p[3].date)}function Ei(p){const[g,R,L,V]=p;return!(g&&!g.generated||R&&!R.generated||L&&!L.generated||!V||!V.text||V.generated)}const Ci={text:15,datetime:10.8,date:10.8,time:10.8,percent:10.6,currency:10.4,grouped:10.2,scientific:6,number:4,fraction:2,general:0,error:0},yi=[["DMY",1],["DM",2],["MY",3],["MDY",4],["MD",5],["hmsa",6],["hma",7],["hms",8],["hm",9]],Di={total:1,sign:0,period:0,int:1,frac:0},Mt=(p,g)=>p.replace(/\./,g.decimal);function yn(p,g,R,L){const V=0|R;if(typeof R=="string")p.push(R);else if(R===V)p.push(Math.abs(V));else{const B=Math.abs(R);let v=B?Math.floor(Math.log10(B)):0,P=v<0?B*10**-v:B/10**v;P===10&&(P=1,v++);const y=function(H){let M=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];const W=Math.abs(H);if(!W)return Di;const ee=M&&H<0?1:0,X=Math.floor(W),O=Math.floor(Math.log10(W)+1);let Y=0,K=0;if(X!==W){Y=1;const ne=String(D(O<0?W*10**-O:W/10**O,15));let oe=ne.length,ae=!0,Ee=0;for(;Ee<=ne.length;){if(ne[Ee]==="."){oe--;break}ne[Ee]==="0"&&ae?oe--:ae=!1,Ee++}K=oe-O,K<0&&(K=0,Y=0)}return{total:ee+Math.max(O,1)+Y+K,digits:Math.max(O,0)+K,sign:ee,period:Y,int:Math.max(O,1),frac:K}}(B),T=()=>{const H=Math.abs(v);let M;M=P===1?P:D(P,5),p.push(Mt(M+"",L),L.exponent,v<0?L.negative:L.positive,H<10?"0":"",H)};if(v>=-4&&v<=-1){const H=B.toPrecision(10+v).replace(/\.?0+$/,"");p.push(Mt(H,L))}else if(v===10){const H=B.toFixed(10).slice(0,12).replace(/\.$/,"");p.push(Mt(H,L))}else if(Math.abs(v)<=9)if(y.total<=11){const H=D(B,9).toFixed(y.frac);p.push(Mt(H,L))}else v===9?p.push(Math.floor(B)):v>=0&&v<9?p.push(D(B,9-v)):T();else y.total>=12?T():Math.floor(B)===B?p.push(Math.floor(B)):p.push(Mt(D(B,9).toFixed(y.frac),L))}return p}const Ot=86400,Dn={int:"integer",frac:"fraction",man:"mantissa",num:"numerator",den:"denominator"},bn=function(p){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;const R=Math.floor(Math.log10(p));return g>1?Math.floor(R/g)*g:R};function Sn(p,g,R,L){let V="",B="",v="",P="",y="",T=0,H=0|p,M=0,W=0,ee=1,X=0,O=0,Y=0,K=0,ne=0,oe=0;const ae=L||_;if(!g.text&&isFinite(g.scale)&&g.scale!==1&&(p=function(ie){if(ie===0)return ie;const ue=Math.ceil(Math.log10(ie<0?-ie:ie)),k=10**(16-Math.floor(ue));return Math.round(ie*k)/k}(p*g.scale)),g.exponential){let ie=Math.abs(p);if(ie){const ue=10**-bn(ie,g.int_max),k=D(ie*ue,g.frac_max)/ue;T=bn(k,g.int_max)}ie/=10**T,p=p<0?-ie:ie,V+=Math.abs(T)}if(g.integer){const ie=Math.abs(D(p,g.fractions?1:g.frac_max));y+=ie<1?"":Math.floor(ie)}if(g.grouping){let ie="",ue=y.length;for(ue>g.group_pri&&(ue-=g.group_pri,ie=ae.group+y.slice(ue,ue+g.group_pri)+ie);ue>g.group_sec;)ue-=g.group_sec,ie=ae.group+y.slice(ue,ue+g.group_sec)+ie;y=ue?y.slice(0,ue)+ie:ie}g.dec_fractions&&(P=String(D(p,g.frac_max)).split(".")[1]||"");let Ee=!1;if(g.fractions){const ie=Math.abs(g.integer?p%1:p);if(ie)if(Ee=!0,isFinite(g.denominator))v+=g.denominator,B+=D(ie*g.denominator),B==="0"&&(B="",v="",Ee=!1,y||(y="0"));else{const ue=E(ie,g.integer?g.num_max:1/0,g.den_max);B+=ue[0],v+=ue[1],g.integer&&B==="0"&&(y||(y="0"),B="",v="",Ee=!1)}}if(g.date){H=Math.trunc(p);const ie=Ot*(p-H);if(M=Math.floor(ie),oe=ie-M,Math.abs(oe)<1e-6?oe=0:oe>.9999&&(oe=0,M+=1,M===Ot&&(M=0,H+=1)),oe){const ue=512&g.date||256&g.date||128&g.date;(ue===512&&oe>.9995||ue===256&&oe>.995||ue===128&&oe>.95||!ue&&oe>=.5)&&(M++,oe=0)}if(H||g.date_system){const ue=En(p,g.date_system,R.leap1900);W=ue[0],ee=ue[1],X=ue[2]}if(M){const ue=M<0?Ot+M:M;ne=Math.floor(ue)%60,K=Math.floor(ue/60)%60,Y=Math.floor(ue/60/60)%60}if(O=(6+H)%7,g.date_eval&&(Ge=p,ot=H+M/Ot,R.dateSpanLarge?Ge<-694324||ot>=35830291:Ge<0||ot>=2958466)){if(R.dateErrorThrows)throw new Error("Date out of bounds");return R.dateErrorNumber?yn(p<0?[ae.negative]:[],0,p,ae).join(""):R.overflow}}var Ge,ot;if(g.int_padding&&(y=g.int_padding.length===1?y||g.int_padding:g.int_padding.substring(0,g.int_padding.length-y.length)+y),g.num_padding&&(B=g.num_padding.length===1?B||g.num_padding:g.num_padding.substring(0,g.num_padding.length-B.length)+B),g.den_padding&&(v=g.den_padding.length===1?v||g.den_padding:v+g.den_padding.slice(v.length)),g.man_padding){const ie=g.exp_plus?"+":"";V=g.man_padding.length===1?(T<0?"-":ie)+(V||g.man_padding):(T<0?"-":ie)+g.man_padding.slice(0,g.man_padding.length-V.length)+V}const I=[];let ve=0;const Je={int:0,frac:0,man:0,num:0,den:0};for(let ie=0,ue=g.tokens.length;ie<ue;ie++){const k=g.tokens[ie],Zt=k.num?k.num.length:0;if(k.type==="string")k.rule?k.rule==="num"?Ee?I.push(k.value):(g.num_min>0||g.den_min>0)&&I.push(k.value.replace(/./g,U["?"])):k.rule==="num+int"?Ee&&y?I.push(k.value):g.den_min>0&&(y||g.num_min)&&I.push(k.value.replace(/./g,U["?"])):k.rule==="den"&&(Ee?I.push(k.value):(g.den_min>0||g.den_min>0)&&I.push(k.value.replace(/./g,U["?"]))):I.push(k.value);else if(k.type==="error")I.push(R.invalid);else if(k.type==="point")I.push(g.date?k.value:ae.decimal);else if(k.type==="general")yn(I,0,p,ae);else if(k.type==="exp")I.push(ae.exponent);else if(k.type==="minus")k.volatile&&g.date||k.volatile&&(p>=0||typeof p!="number")||(k.volatile&&!g.fractions&&(g.integer||g.dec_fractions)?(p<0&&y&&y!=="0"||P)&&I.push(ae.negative):I.push(ae.negative));else if(k.type==="plus")I.push(ae.positive);else if(k.type==="text")I.push(p);else if(k.type==="div")Ee?I.push("/"):g.num_min>0||g.den_min>0?I.push(U["?"]):I.push(U["#"]);else if(k.type==="int")if(g.int_pattern.length===1)I.push(y);else{const ge=ve?g.int_pattern.join("").length-Je.int:1/0,Et=ve===g.int_pattern.length-1?0:g.int_pattern.join("").length-(Je.int+k.num.length);I.push(y.substring(y.length-ge,y.length-Et)),ve++,Je.int+=k.num.length}else if(k.type==="frac"){const ge=Je.frac;for(let Et=0;Et<Zt;Et++)I.push(P[Et+ge]||U[k.num[Et]]);Je.frac+=Zt}else if(k.type in Dn)g[k.type+"_pattern"].length===1?(k.type==="int"&&I.push(y),k.type==="frac"&&I.push(P),k.type==="man"&&I.push(V),k.type==="num"&&I.push(B),k.type==="den"&&I.push(v)):(I.push(Dn[k.type].slice(Je[k.type],Je[k.type]+Zt)),Je[k.type]+=Zt);else if(k.type==="year")W<0&&I.push(ae.negative),I.push(String(Math.abs(W)).padStart(4,"0"));else if(k.type==="year-short"){const ge=W%100;I.push(ge<10?"0":"",ge)}else if(k.type==="month")I.push(k.pad&&ee<10?"0":"",ee);else if(k.type==="monthname-single")g.date_system===6?I.push(ae.mmmm6[ee-1].charAt(0)):I.push(ae.mmmm[ee-1].charAt(0));else if(k.type==="monthname-short")g.date_system===6?I.push(ae.mmm6[ee-1]):I.push(ae.mmm[ee-1]);else if(k.type==="monthname")g.date_system===6?I.push(ae.mmmm6[ee-1]):I.push(ae.mmmm[ee-1]);else if(k.type==="weekday-short")I.push(ae.ddd[O]);else if(k.type==="weekday")I.push(ae.dddd[O]);else if(k.type==="day")I.push(k.pad&&X<10?"0":"",X);else if(k.type==="hour"){const ge=Y%g.clock||(g.clock<24?g.clock:0);I.push(k.pad&&ge<10?"0":"",ge)}else if(k.type==="min")I.push(k.pad&&K<10?"0":"",K);else if(k.type==="sec")I.push(k.pad&&ne<10?"0":"",ne);else if(k.type==="subsec"){I.push(ae.decimal);const ge=oe.toFixed(g.sec_decimals);I.push(ge.slice(2,2+k.decimals))}else if(k.type==="am"){const ge=Y<12?0:1;k.short&&!L?I.push("AP"[ge]):I.push(ae.ampm[ge])}else if(k.type==="hour-elap"){p<0&&I.push(ae.negative);const ge=24*H+Math.floor(Math.abs(M)/3600);I.push(String(Math.abs(ge)).padStart(k.pad,"0"))}else if(k.type==="min-elap"){p<0&&I.push(ae.negative);const ge=1440*H+Math.floor(Math.abs(M)/60);I.push(String(Math.abs(ge)).padStart(k.pad,"0"))}else if(k.type==="sec-elap"){p<0&&I.push(ae.negative);const ge=H*Ot+Math.abs(M);I.push(String(Math.abs(ge)).padStart(k.pad,"0"))}else if(k.type==="b-year")I.push(W+543);else if(k.type==="b-year-short"){const ge=(W+543)%100;I.push(ge<10?"0":"",ge)}}return R.nbsp?I.join(""):I.join("").replace(/\u00a0/g," ")}function An(p,g){for(let R=0;R<3;R++){const L=g[R];if(L){let V;if(L.condition){const B=L.condition[0],v=L.condition[1];B==="="?V=p===v:B===">"?V=p>v:B==="<"?V=p<v:B===">="?V=p>=v:B==="<="?V=p<=v:B==="<>"&&(V=p!==v)}else V=!0;if(V)return L}}}const Ln=Ve("@"),xn="black",Fe={};function Be(p,g){if(p){const R=p[0];g[R]=g[R]||{},Be(p.slice(1),g[R])}else g.$=!0}["d-F-y","d-F-Y","d-M-y","d-M-Y","F-d-y","F-d-Y","F-j-y","F-j-Y","j-F-y","j-F-Y","j-M-y","j-M-Y","M-d-y","M-d-Y","M-j-y","M-j-Y","m-d-y","m-d-Y","m-j-y","m-j-Y","n-d-y","n-d-Y","n-j-y","n-j-Y","y-F-d","y-F-j","y-M-d","y-M-j","Y-F-d","Y-F-j","Y-M-d","Y-m-d","Y-M-j","Y-m-j","Y-n-d","Y-n-j","j-F","j-M","d-F","d-M","n-d","n-j","n-Y","m-d","m-j","m-Y","M-Y","M-y","F-y","F-Y","Y-M","Y-n","Y-m","Y-F","Y-M"].forEach(p=>{Be(p,Fe),Be(p+" x",Fe),Be(p+" l",Fe),Be(p+" l x",Fe),Be("l "+p,Fe),Be("l "+p+" x",Fe),Be(p+" D",Fe),Be(p+" D x",Fe),Be("D "+p,Fe),Be("D "+p+" x",Fe)});const bi={jan:1,feb:2,mar:3,apr:4,may:5,jun:6,jul:7,aug:8,sep:9,oct:10,nov:11,dec:12},Si={january:1,february:2,march:3,april:4,june:6,july:7,august:8,september:9,october:10,november:11,december:12},Ai={sunday:"l",monday:"l",tuesday:"l",wednesday:"l",thursday:"l",friday:"l",saturday:"l",sun:"D",mon:"D",tue:"D",wed:"D",thu:"D",fri:"D",sat:"D"},Li=new Date().getUTCFullYear();function wn(p){const g=new RegExp("^([\\s+%"+he.join("")+"(-]*)(((?:(?:\\d[\\d,]*)(?:\\.\\d*)?|(?:\\.\\d+)))([eE][+-]?\\d+)?)([\\s%"+he.join("")+")]*)$").exec(p);if(g){const[,R,L,V,B,v]=g;let P=1,y="",T=!1,H=!1,M=!1,W=!1,ee=!1,X=null,O=!1,Y=parseFloat(L.replace(/,/g,""));if(!isFinite(Y))return null;for(let ne=0;ne<R.length;ne++){const oe=R[ne];if(oe==="-"){if(T||H)return null;T=!0,P=-1}else if(de.test(oe)){if(ee)return null;ee=!0,X=oe}else if(oe==="("){if(H||T)return null;H=!0,P=-1}else if(oe==="%"){if(W)return null;W=!0}}for(let ne=0;ne<v.length;ne++){const oe=v[ne];if(de.test(oe)){if(ee)return null;ee=!0,X=oe,O=!0}else if(oe===")"){if(M||!H)return null;M=!0}else if(oe==="%"){if(W)return null;W=!0}}if(B){if(W||ee)return null;y="0.00E+00"}else if(W){if(ee)return null;y=V.includes(".")?"0.00%":"0%",Y*=.01}else if(ee){const ne=V.includes(".")?"#,##0.00":"#,##0";y=O?ne+X:X+ne}else V.includes(",")&&(y=V.includes(".")?"#,##0.00":"#,##0");const K={v:Y*P};return y&&(K.z=y),K}}const $e=(p,g,R)=>{const L=R.path||"",V=Object.keys(g);for(let B=0;B<V.length;B++){let v;const P=V[B];if(g[P]){if(P==="$"||P==="€")p||(v=R);else if(P==="-"){const y=/^(\s*([./-]|,\s)\s*|\s+)/.exec(p);if(y){const T=y[1]==="-"||y[1]==="/"||y[1]==="."?y[1]:" ";if(!R.sep||R.sep===T){const H=y[0].replace(/\s+/g," ");v=$e(p.slice(y[0].length),g[P],{...R,sep:T,path:L+H})}}}else if(P===" "){const y=/^[,.]?\s+/.exec(p);if(y){const T=y[0].replace(/\s+/g," ");v=$e(p.slice(y[0].length),g[P],{...R,path:L+T})}}else if(P==="j"||P==="d"){const y=/^(0?[1-9]|1\d|2\d|3[01])\b/.exec(p);y&&(v=$e(p.slice(y[0].length),g[P],{...R,day:y[0],path:L+P}))}else if(P==="n"||P==="m"){const y=/^(0?[1-9]|1[012])\b/.exec(p);y&&(v=$e(p.slice(y[0].length),g[P],{...R,month:+y[0],_mon:y[0],path:L+P}))}else if(P==="F"||P==="M"){const y=/^([a-z]{3,9})\b/i.exec(p),T=y&&(P==="F"?Si:bi)[y[0].toLowerCase()];T&&(v=$e(p.slice(y[0].length),g[P],{...R,month:T,_mon:y[0],path:L+P}))}else if(P==="l"||P==="D"){const y=/^([a-z]{3,9})\b/i.exec(p);(y&&Ai[y[0].toLowerCase()])===P&&(v=$e(p.slice(y[0].length),g[P],{...R,path:L+P}))}else if(P==="y"){const y=/^\d\d\b/.exec(p);if(y){const T=+y[0]>=30?+y[0]+1900:+y[0]+2e3;v=$e(p.slice(y[0].length),g[P],{...R,year:T,path:L+P})}}else if(P==="Y"){const y=/^\d\d\d\d\b/.exec(p);y&&(v=$e(p.slice(y[0].length),g[P],{...R,year:+y[0],path:L+P}))}else{if(P!=="x")throw new Error('Unknown date token "'.concat(P,'"'));{const y=Mr(p);y&&(v=$e("",g[P],{...R,time:y.v,tf:y.z,path:L+P}))}}if(v)return v}}};function Pn(p,g){const R=$e(p.trim(),Fe,{path:""});if(R){var L;if(R.sep==="."&&R.path.length===3)return null;const V=+((L=R.year)!==null&&L!==void 0?L:Li);if(R.day||(R.day=1),!function(P,y,T){if(T<1||y<1||y>12)return!1;if(y===2){if(T>(P%4==0&&P%100!=0||P%400==0||P===1900?29:28))return!1}else if((y===4||y===6||y===9||y===11)&&T>30||(y===1||y===3||y===5||y===7||y===8||y===10||y===12)&&T>31)return!1;return!0}(V,R.month,R.day))return null;let B=-1/0;if(V<1900)return null;V<=1900&&R.month<=2?B=25568:V<1e4&&(B=25569);const v=Date.UTC(V,R.month-1,R.day)/864e5+B+(R.time||0);if(v>=0&&v<=2958465){const P=R._mon[0]==="0"||R.day[0]==="0"||R._mon.length===2&&R.day.length===2,y=R.path.replace(/[jdlDnmMFyYx-]/g,T=>T==="j"||T==="d"?P?"dd":"d":T==="D"?"ddd":T==="l"?"dddd":T==="n"||T==="m"?P?"mm":"m":T==="M"?"mmm":T==="F"?"mmmm":T==="y"?"yy":T==="x"?R.tf||"":T==="Y"?"yyyy":T);return g&&g.nativeDate?{v:Cn(v,g),z:y}:{v,z:y}}}return null}function Mr(p){const g=/^\s*([10]?\d|2[0-4])(?::([0-5]\d|\d))?(?::([0-5]\d|\d))?(\.\d{1,10})?(?:\s*([AP])M?)?\s*$/i.exec(p);if(g){const[,R,L,V,B,v]=g;if(B&&!V||!v&&!L&&!V)return null;let P=1*(R||0);if(v){if(P>=13)return null;v[0]!=="p"&&v[0]!=="P"||(P+=12)}return{v:(60*P*60+60*(1*(L||0))+1*(V||0)+1*(B||0))/86400,z:(R.length===2?"hh":"h")+":mm"+(V?":ss":"")+(v?" AM/PM":"")}}return null}function Vn(p){return/^\s*true\s*$/i.test(p)?{v:!0}:/^\s*false\s*$/i.test(p)?{v:!1}:null}const Ft={};function xi(p,g){const{pattern:R,partitions:L,locale:V}=p,B=y=>{const T=Object.assign({},w(),g,y);return V&&(T.locale=V),T},v=(y,T)=>{const H=B(T);return function(M,W,ee){const X=l(ee.locale),O=W[3]?W[3]:Ln;if(typeof M=="boolean"&&(M=M?"TRUE":"FALSE"),M==null)return"";if(typeof M!="number")return Sn(M,O,ee,X);if(!isFinite(M)){const K=X||_;return isNaN(M)?K.nan:(M<0?K.negative:"")+K.infinity}const Y=An(M,W);return Y?Sn(M,Y,ee,X):ee.overflow}(qt(y,H),L,H)};v.color=(y,T)=>function(H,M){if(typeof H!="number"||!isFinite(H))return(M[3]?M[3].color:Ln.color)||xn;const W=An(H,M);return W&&W.color||xn}(qt(y,B(T)),L);const P=function(y){var T;let H=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null;const[M,W]=y,ee=M.frac_max,X={type:"general",isDate:_i(y),isText:Ei(y),isPercent:Ri(y),maxDecimals:M.general?9:ee,scale:(T=M.scale)!==null&&T!==void 0?T:1,color:0,parentheses:0,grouped:M.grouping?1:0,_partitions:y},O=!X.isDate&&!X.isText&&!M.error&&M.tokens.some(ae=>ae.type==="string"&&(H?ae.value===H:de.test(ae.value)));let Y="G",K=ee>=0?Math.min(15,ee):"",ne="",oe="";if(W&&W.color&&(oe="-",X.color=1),M.parens&&(ne="()",X.parentheses=1),O)Y="C",X.type="currency";else if(M.error)X.type="error",X.maxDecimals=0;else if(X.isDate){let ae=0,Ee=0,Ge="";M.tokens.forEach(I=>{const ve=I.type;/^(b-)?year/.test(ve)?(Ge+="Y",Ee++):ve.startsWith("month")?(Ge+="M",Ee++):/^(week)?day/.test(ve)?(Ge+="D",Ee++):ve!=="hour"&&ve!=="min"&&ve!=="sec"&&ve!=="am"||(Ge+=ve[0],ae++)}),X.type="date",Ee&&ae?X.type="datetime":!Ee&&ae&&(X.type="time");const ot=yi.find(I=>Ge.startsWith(I[0]));Y=ot?"D":"G",K=ot?ot[1]:""}else X.isText?(Y="G",X.type="text",K="",X.maxDecimals=0):M.general?(Y="G",X.type="general",K=""):M.fractions?(Y="G",X.type="fraction",K=""):M.exponential?(Y="S",X.type="scientific"):X.isPercent?(Y="P",X.type="percent"):M.grouping?(Y=",",X.type="grouped"):(M.int_max||ee)&&(Y="F",X.type="number");return X.code=Y+K+oe+ne,X.level=Ci[X.type],Object.freeze(X)}(L,(g||{}).currency)||new SyntaxError;return v.info=P,v.dateInfo=function(y){const[T]=y;return{year:!!(2&T.date),month:!!(4&T.date),day:!!(8&T.date),hours:!!(16&T.date),minutes:!!(32&T.date),seconds:!!(64&T.date),clockType:T.clock===12?12:24}}(L),v.isPercent=()=>!!P.isPercent,v.isDate=()=>!!P.isDate,v.isText=()=>!!P.isText,v.pattern=R,p.error&&(v.error=p.error),v.options=B,v.locale=V||g&&g.locale||"",Object.freeze(v)}function le(p,g){p||(p="General");let R=null;return Ft[p]?R=Ft[p]:(R=Object.assign({},w(),g).throws?vt(p):function(L){try{return vt(L)}catch(V){const B={tokens:[{type:"error"}],error:V.message};return{pattern:L,partitions:[B,B,B,B],error:V.message,locale:null}}}(p),R.error||(Ft[p]=R)),xi(R,g)}le.isDate=p=>le(p,{throws:!1}).isDate(),le.isPercent=p=>le(p,{throws:!1}).isPercent(),le.isText=p=>le(p,{throws:!1}).isText(),le.getInfo=(p,g)=>le(p,{...g,throws:!1}).info,le.getDateInfo=(p,g)=>le(p,{...g,throws:!1}).dateInfo,le.dateToSerial=qt,le.dateFromSerial=Cn,le.options=w,le.dec2frac=E,le.round=D,le.codeToLocale=s,le.parseLocale=u,le.getLocale=l,le.addLocale=(p,g)=>{const R=u(g);return delete Ft[R.lang],delete Ft[R.language],d(p,R)},le.format=function(p,g,R){let L=arguments.length>3&&arguments[3]!==void 0&&arguments[3];const V=R&&typeof R=="object"?R:{locale:R,throws:!L};return le(p,V)(qt(g,V),V)},le.is_date=le.isDate,le.parseNumber=wn,le.parseDate=Pn,le.parseTime=Mr,le.parseBool=Vn,le.parseValue=function(p,g){var R,L,V;return(R=(L=(V=wn(p))!==null&&V!==void 0?V:Pn(p,g))!==null&&L!==void 0?L:Mr(p))!==null&&R!==void 0?R:Vn(p)};var wi=le;return t=t.default}()})})(Zs);var To=Zs.exports,jo=To;const $o=ko(jo),Io=(r,n)=>$o.format(r,n);class Yo extends j{calculate(n,e){if(n==null||e==null)return h.create(f.NA);if(n.isError())return n;if(e.isError())return e;const t=Math.max(n.isArray()?n.getRowCount():1,e.isArray()?e.getRowCount():1),s=Math.max(n.isArray()?n.getColumnCount():1,e.isArray()?e.getColumnCount():1),i=me(t,s,n),a=me(t,s,e);return i.map((o,u,c)=>{if(o.isError()||o.isString()||o.isBoolean())return o;let l=a.get(u,c)||_e.create(" ");if(l.isError())return l;if(l.isBoolean())return h.create(f.VALUE);l.isNull()&&(l=_e.create(" "));const m=`${l.getValue()}`;o.isNull()&&(o=b.create(0));const d=o.getValue(),_=Io(m,d);return _e.create(_)})}}const Js=[[Mo,mt.CONCATENATE],[Oo,mt.LEN],[Bo,mt.LENB],[Yo,mt.TEXT]],Ns=[];var ei=(r=>r)(ei||{});const ti=[];var ri=(r=>(r.ENCODEURL="ENCODEURL",r.FILTERXML="FILTERXML",r.WEBSERVICE="WEBSERVICE",r))(ri||{});class ni extends C.Disposable{constructor(){super(...arguments);S(this,"_definedNameMap",new Map)}dispose(){this._definedNameMap.clear()}registerDefinedName(e,t,s){var a;this._definedNameMap.get(e)==null&&this._definedNameMap.set(e,new Map),(a=this._definedNameMap.get(e))==null||a.set(t,s)}removeDefinedName(e,t){var s;(s=this._definedNameMap.get(e))==null||s.delete(t)}getDefinedNameMap(e){return this._definedNameMap.get(e)}getValue(e,t){var s;return(s=this._definedNameMap.get(e))==null?void 0:s.get(t)}hasDefinedName(e){var s;return(((s=this._definedNameMap.get(e))==null?void 0:s.size)||0)!==0}}const Xt=N.createIdentifier("univer.formula.defined-names.service");var zo=Object.defineProperty,Qo=Object.getOwnPropertyDescriptor,Ho=(r,n,e,t)=>{for(var s=t>1?void 0:t?Qo(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&zo(n,e,s),s},Wo=(r,n)=>(e,t)=>n(e,t,r);exports.FormulaCurrentConfigService=class extends C.Disposable{constructor(e){super();S(this,"_unitData",{});S(this,"_arrayFormulaCellData",{});S(this,"_formulaData",{});S(this,"_sheetNameMap",{});S(this,"_forceCalculate",!1);S(this,"_dirtyRanges",[]);S(this,"_dirtyNameMap",{});S(this,"_numfmtItemMap",{});S(this,"_dirtyUnitFeatureMap",{});S(this,"_dirtyUnitOtherFormulaMap",{});S(this,"_excludedCell");S(this,"_sheetIdToNameMap",{});this._currentUniverService=e}dispose(){this._unitData={},this._formulaData={},this._arrayFormulaCellData={},this._sheetNameMap={},this._dirtyRanges=[],this._dirtyNameMap={},this._numfmtItemMap={},this._dirtyUnitFeatureMap={},this._excludedCell={},this._sheetIdToNameMap={},this._dirtyUnitOtherFormulaMap={}}getExcludedRange(){return this._excludedCell}getUnitData(){return this._unitData}getFormulaData(){return this._formulaData}getArrayFormulaCellData(){return this._arrayFormulaCellData}getSheetNameMap(){return this._sheetNameMap}isForceCalculate(){return this._forceCalculate}getDirtyRanges(){return this._dirtyRanges}getDirtyNameMap(){return this._dirtyNameMap}getNumfmtItemMap(){return this._numfmtItemMap}getDirtyUnitFeatureMap(){return this._dirtyUnitFeatureMap}getSheetName(e,t){return this._sheetIdToNameMap[e]==null?"":this._sheetIdToNameMap[e][t]||""}getDirtyUnitOtherFormulaMap(){return this._dirtyUnitOtherFormulaMap}load(e){if(e.allUnitData&&e.unitSheetNameMap)this._unitData=e.allUnitData,this._sheetNameMap=e.unitSheetNameMap;else{const{allUnitData:t,unitSheetNameMap:s}=this._loadSheetData();this._unitData=t,this._sheetNameMap=s}this._formulaData=e.formulaData,this._arrayFormulaCellData=us(e.arrayFormulaCellData),this._forceCalculate=e.forceCalculate,this._dirtyRanges=e.dirtyRanges,this._dirtyNameMap=e.dirtyNameMap,this._numfmtItemMap=e.numfmtItemMap,this._dirtyUnitFeatureMap=e.dirtyUnitFeatureMap,this._dirtyUnitOtherFormulaMap=e.dirtyUnitOtherFormulaMap,this._excludedCell=e.excludedCell,this._mergeNameMap(this._sheetNameMap,this._dirtyNameMap)}loadDirtyRangesAndExcludedCell(e,t){this._dirtyRanges=e,this._excludedCell=t,this._dirtyNameMap={}}registerUnitData(e){this._unitData=e}registerFormulaData(e){this._formulaData=e}registerSheetNameMap(e){this._sheetNameMap=e}_mergeNameMap(e,t){Object.keys(t).forEach(s=>{t[s]&&Object.keys(t[s]).forEach(i=>{e[s]==null&&(e[s]={}),e[s][t[s][i]]=i})}),this._sheetIdToNameMap={},Object.keys(e).forEach(s=>{Object.keys(e[s]).forEach(i=>{this._sheetIdToNameMap[s]==null&&(this._sheetIdToNameMap[s]={}),this._sheetIdToNameMap[s][e[s][i]]=i})})}_loadSheetData(){const e=this._currentUniverService.getAllUniverSheetsInstance(),t={},s={};for(const i of e){const a=i.getUnitId(),o=i.getSheets(),u={},c={};for(const l of o){const m=l.getSheetId(),d=l.getConfig();u[m]={cellData:new C.ObjectMatrix(d.cellData),rowCount:d.rowCount,columnCount:d.columnCount,rowData:d.rowData,columnData:d.columnData},c[l.getName()]=l.getSheetId()}t[a]=u,s[a]=c}return{allUnitData:t,unitSheetNameMap:s}}};exports.FormulaCurrentConfigService=Ho([Wo(0,C.IUniverInstanceService)],exports.FormulaCurrentConfigService);const at=N.createIdentifier("univer.formula.current-data.service");var Go=Object.defineProperty,Xo=Object.getOwnPropertyDescriptor,Ko=(r,n,e,t)=>{for(var s=t>1?void 0:t?Xo(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&&Go(n,e,s),s},qo=(r,n)=>(e,t)=>n(e,t,r),Ie=(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))(Ie||{}),yt=(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))(yt||{});exports.FormulaRuntimeService=class extends C.Disposable{constructor(e){super();S(this,"_formulaExecuteStage",0);S(this,"_stopState",!1);S(this,"_currentRow",-1);S(this,"_currentColumn",-1);S(this,"_currentRowCount",Number.NEGATIVE_INFINITY);S(this,"_currentColumnCount",Number.NEGATIVE_INFINITY);S(this,"_currentSubUnitId","");S(this,"_currentUnitId","");S(this,"_runtimeData",{});S(this,"_runtimeOtherData",{});S(this,"_unitArrayFormulaRange",{});S(this,"_runtimeArrayFormulaCellData",{});S(this,"_runtimeClearArrayFormulaCellData",{});S(this,"_numfmtItemMap",{});S(this,"_runtimeFeatureRange",{});S(this,"_runtimeFeatureCellData",{});S(this,"_functionsExecutedState",0);S(this,"_functionDefinitionPrivacyVar",new Map);S(this,"_totalFormulasToCalculate",0);S(this,"_completedFormulasCount",0);S(this,"_totalArrayFormulasToCalculate",0);S(this,"_completedArrayFormulasCount",0);S(this,"_isCycleDependency",!1);this._currentConfigService=e}get currentRow(){return this._currentRow}get currentColumn(){return this._currentColumn}get currentRowCount(){return this._currentRowCount}get currentColumnCount(){return this._currentColumnCount}get currentSubUnitId(){return this._currentSubUnitId}get currentUnitId(){return this._currentUnitId}dispose(){this.reset(),this._runtimeFeatureCellData={},this._runtimeFeatureRange={}}enableCycleDependency(){this._isCycleDependency=!0}disableCycleDependency(){this._isCycleDependency=!1}isCycleDependency(){return this._isCycleDependency}setTotalArrayFormulasToCalculate(e){this._totalArrayFormulasToCalculate=e}getTotalArrayFormulasToCalculate(){return this._totalArrayFormulasToCalculate}setCompletedArrayFormulasCount(e){this._completedArrayFormulasCount=e}getCompletedArrayFormulasCount(){return this._completedArrayFormulasCount}setTotalFormulasToCalculate(e){this._totalFormulasToCalculate=e}getTotalFormulasToCalculate(){return this._totalFormulasToCalculate}setCompletedFormulasCount(e){this._completedFormulasCount=e}getCompletedFormulasCount(){return this._completedFormulasCount}markedAsSuccessfullyExecuted(){this._functionsExecutedState=3}markedAsNoFunctionsExecuted(){this._functionsExecutedState=2}markedAsStopFunctionsExecuted(){this._functionsExecutedState=1}markedAsInitialFunctionsExecuted(){this._functionsExecutedState=0}stopExecution(){this._stopState=!0,this.setFormulaExecuteStage(0)}isStopExecution(){return this._stopState}setFormulaExecuteStage(e){this._formulaExecuteStage=e}getFormulaExecuteStage(){return this._formulaExecuteStage}reset(){this._formulaExecuteStage=0,this._runtimeData={},this._runtimeOtherData={},this._unitArrayFormulaRange={},this._numfmtItemMap={},this._runtimeArrayFormulaCellData={},this._runtimeClearArrayFormulaCellData={},this._functionDefinitionPrivacyVar.clear(),this.markedAsInitialFunctionsExecuted(),this._isCycleDependency=!1,this._totalFormulasToCalculate=0,this._completedFormulasCount=0}setCurrent(e,t,s,i,a,o){this._currentRow=e,this._currentColumn=t,this._currentRowCount=s,this._currentColumnCount=i,this._currentSubUnitId=a,this._currentUnitId=o}clearFunctionDefinitionPrivacyVar(){this._functionDefinitionPrivacyVar.clear()}registerFunctionDefinitionPrivacyVar(e,t){this._functionDefinitionPrivacyVar.set(e,t)}getFunctionDefinitionPrivacyVar(e){return this._functionDefinitionPrivacyVar.get(e)}setRuntimeOtherData(e,t){const s=this._currentSubUnitId,i=this._currentUnitId;this._runtimeOtherData[i]===void 0&&(this._runtimeOtherData[i]={});const a=this._runtimeOtherData[i];a[s]===void 0&&(a[s]={});const o=a[s];let u=[];if(t.isReferenceObject()||t.isValueObject()&&t.isArray()){const c=t,{startRow:l,startColumn:m}=c.getRangePosition();c.iterator((d,_,D)=>{const E=this._objectValueToCellValue(d),A=_-l,x=D-m;u[A]==null&&(u[A]=[]),u[A][x]=E})}else u=[[this._objectValueToCellValue(t)]];o[e]=u}setRuntimeData(e){const t=this._currentRow,s=this._currentColumn,i=this._currentRowCount,a=this.currentColumnCount,o=this._currentSubUnitId,u=this._currentUnitId;this._runtimeData[u]==null&&(this._runtimeData[u]={});const c=this._runtimeData[u];c[o]==null&&(c[o]=new C.ObjectMatrix),this._unitArrayFormulaRange[u]==null&&(this._unitArrayFormulaRange[u]={}),this._numfmtItemMap[u]==null&&(this._numfmtItemMap[u]={}),this._numfmtItemMap[u][o]==null&&(this._numfmtItemMap[u][o]={});const l=this._numfmtItemMap[u][o],m=this._unitArrayFormulaRange[u];let d=new C.ObjectMatrix;m[o]&&(d=new C.ObjectMatrix(m[o])),this._runtimeArrayFormulaCellData[u]===void 0&&(this._runtimeArrayFormulaCellData[u]={});const _=this._runtimeArrayFormulaCellData[u];_[o]==null&&(_[o]=new C.ObjectMatrix),this._runtimeClearArrayFormulaCellData[u]===void 0&&(this._runtimeClearArrayFormulaCellData[u]={});const D=this._runtimeClearArrayFormulaCellData[u];D[o]==null&&(D[o]=new C.ObjectMatrix);const E=c[o],A=_[o],x=D[o];if(e.isReferenceObject()||e.isValueObject()&&e.isArray()){const w=e,{startRow:U,startColumn:$,endRow:se,endColumn:he}=w.getRangePosition();if(U===se&&$===he){const q=w.getFirstCell(),z=this._objectValueToCellValue(q);E.setValue(t,s,z),x.setValue(t,s,z),l[t]==null&&(l[t]={}),l[t][s]=q.getPattern();return}const de={startRow:t,startColumn:s,endRow:se-U+t,endColumn:he-$+s};if(d.setValue(t,s,de),m[o]=d.getData(),this._checkIfArrayFormulaRangeHasData(u,o,t,s,de)||this._checkIfArrayFormulaExceeded(i,a,de)){const q=this._objectValueToCellValue(h.create(f.SPILL));E.setValue(t,s,q),x.setValue(t,s,q)}else{const q=h.create(f.SPILL);w.iterator((z,re,Z)=>{const Ve=this._objectValueToCellValue(z);if(re===U&&Z===$){if(z!=null&&z.isError()&&z.isEqualType(q))return x.setValue(t,s,{}),E.setValue(t,s,{...this._objectValueToCellValue(q)}),!1;E.setValue(t,s,{...Ve})}const je=re-U+t,vt=Z-$+s;A.setValue(je,vt,Ve);const De=z==null?void 0:z.getPattern();De&&(l[je]==null&&(l[je]={}),l[je][vt]=De)})}}else{const w=this._objectValueToCellValue(e);E.setValue(t,s,w),l[t]==null&&(l[t]={}),l[t][s]=e.getPattern(),x.setValue(t,s,w)}}getUnitData(){return this._runtimeData}getUnitArrayFormula(){return this._unitArrayFormulaRange}getNumfmtItemMap(){return this._numfmtItemMap}getRuntimeOtherData(){return this._runtimeOtherData}getRuntimeArrayFormulaCellData(){return this._runtimeArrayFormulaCellData}getRuntimeClearArrayFormulaCellData(){return this._runtimeClearArrayFormulaCellData}getRuntimeFeatureRange(){return this._runtimeFeatureRange}setRuntimeFeatureRange(e,t){this._runtimeFeatureRange[e]=t}getRuntimeFeatureCellData(){return this._runtimeFeatureCellData}setRuntimeFeatureCellData(e,t){this._runtimeFeatureCellData[e]=t}getAllRuntimeData(){return{unitData:this.getUnitData(),arrayFormulaRange:this.getUnitArrayFormula(),unitOtherData:this.getRuntimeOtherData(),functionsExecutedState:this._functionsExecutedState,arrayFormulaCellData:this.getRuntimeArrayFormulaCellData(),clearArrayFormulaCellData:this.getRuntimeClearArrayFormulaCellData(),numfmtItemMap:this.getNumfmtItemMap(),runtimeFeatureRange:this.getRuntimeFeatureRange(),runtimeFeatureCellData:this.getRuntimeFeatureCellData()}}getRuntimeState(){return{totalFormulasToCalculate:this.getTotalFormulasToCalculate(),completedFormulasCount:this.getCompletedFormulasCount(),totalArrayFormulasToCalculate:this.getTotalArrayFormulasToCalculate(),completedArrayFormulasCount:this.getCompletedArrayFormulasCount(),stage:this.getFormulaExecuteStage()}}_objectValueToCellValue(e){if(e==null)return{v:0,t:C.CellValueType.NUMBER};if(e.isError())return{v:e.getErrorType(),t:C.CellValueType.STRING};if(e.isValueObject()){const t=e,s=t.getValue();return t.isNumber()?{v:s,t:C.CellValueType.NUMBER}:t.isBoolean()?{v:s,t:C.CellValueType.BOOLEAN}:t.isString()&&C.isRealNum(s)?{v:s,t:C.CellValueType.FORCE_STRING}:{v:s,t:C.CellValueType.STRING}}}_checkIfArrayFormulaRangeHasData(e,t,s,i,a){var _,D,E,A,x,w,U,$,se,he,de,q;const{startRow:o,startColumn:u,endRow:c,endColumn:l}=a,m=this._currentConfigService.getUnitData(),d=(E=(D=(_=this._unitArrayFormulaRange[e])==null?void 0:_[t])==null?void 0:D[s])==null?void 0:E[i];for(let z=o;z<=c;z++)for(let re=u;re<=l;re++){if(z===s&&i===re)continue;const Z=(w=(x=(A=this._runtimeData)==null?void 0:A[e])==null?void 0:x[t])==null?void 0:w.getValue(z,re),Ve=(se=($=(U=this._runtimeArrayFormulaCellData)==null?void 0:U[e])==null?void 0:$[t])==null?void 0:se.getValue(z,re),je=(q=(de=(he=m==null?void 0:m[e])==null?void 0:he[t])==null?void 0:de.cellData)==null?void 0:q.getValue(z,re);if(!C.isNullCell(Z)||!C.isNullCell(Ve)&&!this._isInArrayFormulaRange(d,z,re)||!C.isNullCell(je))return!0}return!1}_isInArrayFormulaRange(e,t,s){if(e==null)return!1;const{startRow:i,startColumn:a,endRow:o,endColumn:u}=e;return t>=i&&t<=o&&s>=a&&s<=u}_checkIfArrayFormulaExceeded(e,t,s){return s.endRow>=e||s.endColumn>=t}_isInDirtyRange(e,t,s,i){const a=this._currentConfigService.getDirtyRanges();return a.length===0?!0:ss(a,e,t,s,i)}};exports.FormulaRuntimeService=Ko([qo(0,at)],exports.FormulaRuntimeService);const Oe=N.createIdentifier("univer.formula.runtime.service");var Zo=Object.defineProperty,Jo=Object.getOwnPropertyDescriptor,No=(r,n,e,t)=>{for(var s=t>1?void 0:t?Jo(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&&Zo(n,e,s),s},Tr=(r,n)=>(e,t)=>n(e,t,r);let At=class extends C.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:c,token:l}=u;if(c===Me.REFERENCE||c===Me.FUNCTION){const m=(i=this._definedNamesService.getDefinedNameMap(n))==null?void 0:i.get(l);m?(t+=m,s=!0):t+=l}else t+=l}return{sequenceString:t,hasDefinedName:s}}};At=No([Tr(0,Xt),Tr(1,Oe),Tr(2,N.Inject(yr))],At);var te=(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))(te||{});const ze=new Map([["ReferenceNode",7],["ValueNode",9],["OperatorNode",8],["FunctionNode",6],["LambdaNode",1],["LambdaNodeParameter",2],["Root",10],["UnionNode",3],["PrefixNode",4],["SuffixNode",5]]);class Pe extends C.Disposable{constructor(e){super();S(this,"_children",[]);S(this,"_parent");S(this,"_valueObject");S(this,"_calculateState",!1);S(this,"_async",!1);S(this,"_address",!1);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._token=e}dispose(){var e;this._children.forEach(t=>{t.dispose()}),(e=this._valueObject)==null||e.dispose(),this._parent=null}get nodeType(){return te.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(ht.SUCCESS)}serialize(){const e=this.getToken(),t=this.getChildren(),s=[],i=t.length;for(let o=0;o<i;o++){const u=t[o];s.push(u.serialize())}const a={token:e,nodeType:this.nodeType};return i>0&&(a.children=s),a}}class ye extends Pe{constructor(e){super(e);S(this,"_errorValueObject");this._errorValueObject=h.create(e)}get nodeType(){return te.ERROR}static create(e){return new ye(e)}getValue(){return this._errorValueObject}}const Qe=100;class He extends C.Disposable{get zIndex(){return 0}create(n,e,t){let s;return n instanceof J?s=n.getToken():s=n,new Pe(s)}checkAndCreateNodeType(n){}}class Wr extends Pe{get nodeType(){return te.ROOT}execute(){const e=this.getChildren()[0];e==null?this.setValue(h.create(f.VALUE)):this.setValue(e.getValue())}}class si extends He{get zIndex(){return ze.get(te.ROOT)||Qe}checkAndCreateNodeType(n){if(!(n instanceof J))return;if(n.getToken()===rt)return new Wr(rt)}}class ii extends C.Disposable{constructor(){super(...arguments);S(this,"_functionExecutors",new Map);S(this,"_functionDescriptions",new Map)}dispose(){this._functionExecutors.clear(),this._functionDescriptions.clear()}registerExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.set(s.name,s)}}getExecutors(){return this._functionExecutors}getExecutor(e){return this._functionExecutors.get(e)}hasExecutor(e){return this._functionExecutors.has(e)}unregisterExecutors(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionExecutors.delete(s)}}registerDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.set(s.functionName,s)}}getDescriptions(){return this._functionDescriptions}getDescription(e){return this._functionDescriptions.get(e)}hasDescription(e){return this._functionDescriptions.has(e)}unregisterDescriptions(...e){for(let t=0;t<e.length;t++){const s=e[t];this._functionDescriptions.delete(s)}}}const We=N.createIdentifier("univer.formula.function.service");var eu=Object.defineProperty,tu=Object.getOwnPropertyDescriptor,ru=(r,n,e,t)=>{for(var s=t>1?void 0:t?tu(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&&eu(n,e,s),s},qn=(r,n)=>(e,t)=>n(e,t,r);class hr extends Pe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return te.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===Re.MINUS?t=this._functionExecutor.calculate(b.create(0),e):this._operatorString===Re.AT?t=this._handlerAT(e):t=h.create(f.VALUE),this.setValue(t)}_handlerAT(n){if(!n.isReferenceObject())return h.create(f.VALUE);const e=n;if(e.isCell())return h.create(f.VALUE);const t=this._accessor.get(Oe),s=t.currentRow||0,i=t.currentColumn||0;return e.isRow()?e.getCellByColumn(i):e.isColumn()?e.getCellByRow(s):e.isRange()||e.isTable()?e.getCellByPosition():h.create(f.VALUE)}}let mr=class extends He{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ze.get(te.PREFIX)||Qe}checkAndCreateNodeType(r){if(!(r instanceof J))return;const n=r.getToken(),e=n.trim();if(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')return;let t="";if(e===Re.MINUS)t=Ae.MINUS;else return e===Re.AT?new hr(this._injector,e):void 0;const s=this._functionService.getExecutor(t);return s?new hr(this._injector,e,s):(console.error(`No function ${n}`),ye.create(f.NAME))}};mr=ru([qn(0,We),qn(1,N.Inject(N.Injector))],mr);function ai(r,n,e){let t,s;const i=r.slice(0,2);let a=0;if(new RegExp(Re.MINUS,"g").test(i)){const o=n.getExecutor(Ae.MINUS);t=new hr(e,Re.MINUS,o),a++}return new RegExp(Re.AT,"g").test(i)&&(s=new hr(e,Re.AT),t&&s.setParent(t),a++),a>0&&(r=r.slice(a)),{tokenTrim:r,minusPrefixNode:t,atPrefixNode:s}}var nu=Object.defineProperty,su=Object.getOwnPropertyDescriptor,iu=(r,n,e,t)=>{for(var s=t>1?void 0:t?su(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&nu(n,e,s),s},Nt=(r,n)=>(e,t)=>n(e,t,r);class au extends Pe{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 te.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(ht.SUCCESS)}execute(){const n=[],e=this.getChildren(),t=e.length;this._compatibility();for(let i=0;i<t;i++){const a=e[i].getValue();a!=null&&(a.isReferenceObject()&&!this._functionExecutor.needsReferenceObject?n.push(a.toArrayValueObject()):n.push(a))}const s=this._calculate(n);this._setRefData(s),this.setValue(s)}_compatibility(){this._lookupCompatibility()}_lookupCompatibility(){const n=this.getChildren(),e=n.length;if(!this._functionExecutor.needsExpandParams||e!==3)return;const t=n[1].getValue(),s=n[2].getValue();if(!(t!=null&&t.isReferenceObject())&&!(s!=null&&s.isReferenceObject()))return;const i=t.getRangeData(),a=s.getRangeData(),{startRow:o,startColumn:u,endRow:c,endColumn:l}=i,m=c-o+1,d=l-u+1,{startRow:_,startColumn:D,endRow:E,endColumn:A}=a,x=E-_+1,w=A-D+1;m!==x&&(a.endRow+=m-x),d!==w&&(a.endColumn+=d-w)}_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=it.create(s);else{const i=da(s);e=Le.create({calculateValueList:i,rowCount:i.length,columnCount:((t=i[0])==null?void 0:t.length)||0,unitId:"",sheetId:"",row:-1,column:-1})}}else e=this._functionExecutor.calculate(...n);return e}_setRefInfo(){const{currentUnitId:n,currentSubUnitId:e,currentRow:t,currentColumn:s}=this._runtimeService;this._functionExecutor.setRefInfo(n,e,t,s)}_setRefData(n){if(!n.isReferenceObject())return;const e=n;e.setForcedSheetId(this._currentConfigService.getSheetNameMap()),e.setUnitData(this._currentConfigService.getUnitData()),e.setArrayFormulaCellData(this._currentConfigService.getArrayFormulaCellData()),e.setRuntimeData(this._runtimeService.getUnitData()),e.setRuntimeArrayFormulaCellData(this._runtimeService.getRuntimeArrayFormulaCellData()),e.setRuntimeFeatureCellData(this._runtimeService.getRuntimeFeatureCellData())}}let dr=class extends He{constructor(r,n,e,t){super(),this._functionService=r,this._currentConfigService=n,this._runtimeService=e,this._injector=t}get zIndex(){return ze.get(te.FUNCTION)||Qe}create(r){const n=this._functionService.getExecutor(r);return n?new au(r,n,this._currentConfigService,this._runtimeService):(console.error(`No function ${r}`),ye.create(f.NAME))}checkAndCreateNodeType(r){if(typeof r=="string")return;const n=r.getToken(),{tokenTrim:e,minusPrefixNode:t,atPrefixNode:s}=ai(n.trim(),this._functionService,this._injector);if(!Number.isNaN(Number(e)))return ye.create(f.VALUE);const i=e.toUpperCase();if(this._functionService.hasExecutor(i)){const a=this.create(i);return s?a.setParent(s):t&&a.setParent(t),a}}};dr=iu([Nt(0,We),Nt(1,at),Nt(2,Oe),Nt(3,N.Inject(N.Injector))],dr);var ou=Object.defineProperty,uu=Object.getOwnPropertyDescriptor,cu=(r,n,e,t)=>{for(var s=t>1?void 0:t?uu(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&&ou(n,e,s),s},lu=(r,n)=>(e,t)=>n(e,t,r);let Lt=class extends C.Disposable{constructor(r){super(),this._runtimeService=r}dispose(){}async executeAsync(r){if(!r)return h.create(f.VALUE);await this._executeAsync(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return Promise.resolve(n)}execute(r){if(!r)return h.create(f.VALUE);this._execute(r);const n=r.getValue();if(n==null)throw new Error("node value is null");return n}executePreCalculateNode(r){return r.execute(),r.getValue()}checkAsyncNode(r){const n=[];this._checkAsyncNode(r,n);for(let e=0,t=n.length;e<t;e++)if(n[e]===!0)return!0;return!1}_checkAsyncNode(r,n){const e=r.getChildren(),t=e.length;for(let s=0;s<t;s++){const i=e[s];n.push(i.isAsync()),this._checkAsyncNode(i,n)}}async _executeAsync(r){if(this._runtimeService.isStopExecution())return Promise.resolve(ht.ERROR);const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===$t&&s.isEmptyParamFunction()){s.execute();continue}await this._executeAsync(s)}return r.nodeType===te.FUNCTION&&r.isAsync()?await r.executeAsync():r.execute(),Promise.resolve(ht.SUCCESS)}_execute(r){if(this._runtimeService.isStopExecution())return ht.ERROR;const n=r.getChildren(),e=n.length;for(let t=0;t<e;t++){const s=n[t];if(s.getToken().toUpperCase()===$t&&s.isEmptyParamFunction()){s.execute();continue}this._execute(s)}return r.execute(),ht.SUCCESS}};Lt=cu([lu(0,Oe)],Lt);function oi(r){return r instanceof J?r.getToken()===St:!1}function fu(r){return r instanceof J?r.getToken()===gs:!1}function ui(r){if(!r)return;if(r.getToken()!==Wt)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:ui(s)}class gn extends Ze{constructor(e,t,s){super(0);S(this,"_lambdaPrivacyValueMap",new Map);this._lambdaNode=e,this._interpreter=t,this._lambdaPrivacyVarKeys=s,this._lambdaPrivacyValueMap.clear()}static create(e,t,s){return new gn(e,t,s)}isLambda(){return!0}execute(...e){const t=this._lambdaPrivacyVarKeys.length;if(e.length!==t)return h.create(f.VALUE);this._setLambdaPrivacyValueMap(e),this._setLambdaNodeValue(this._lambdaNode),this._lambdaNode.setNotEmpty(!1);let s;if(this._interpreter.checkAsyncNode(this._lambdaNode))s=new _a(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()===Wt){const u=a.getLambdaParameter(),c=this._lambdaPrivacyValueMap.get(u);if(c)a.setValue(c);else{const l=a.getCurrentLambdaPrivacyVar(),m=ui(l.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 hu=Object.defineProperty,mu=Object.getOwnPropertyDescriptor,du=(r,n,e,t)=>{for(var s=t>1?void 0:t?mu(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&&hu(n,e,s),s},Zn=(r,n)=>(e,t)=>n(e,t,r);class gu extends Pe{constructor(e,t,s,i){super(e);S(this,"_isNotEmpty",!0);this._lambdaId=t,this._interpreter=s,this._lambdaPrivacyVarKeys=i}get nodeType(){return te.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(gn.create(this,this._interpreter,this._lambdaPrivacyVarKeys));else{const e=this.getChildren(),t=e.length;this.setValue(e[t-1].getValue())}}}let gr=class extends He{constructor(r,n){super(),this._runtimeService=r,this._interpreter=n}get zIndex(){return ze.get(te.LAMBDA)||Qe}create(r){const n=r.getChildren(),e=n[0];let t=n.slice(1,-1);const s=n[n.length-1];if(!(e instanceof J&&s instanceof J))return ye.create(f.NAME);if(e.getToken()===St){const o=e.getChildren();if(t.length!==o.length)return ye.create(f.VALUE)}else t=n.slice(0,-1);const i=C.Tools.generateRandomId(8),a=new Map;for(let o=0;o<t.length;o++){const u=t[o];if(u instanceof J){const c=u.getChildren()[0];u.setToken(gs),a.set(c.trim(),void 0)}else return ye.create(f.VALUE)}return this._runtimeService.registerFunctionDefinitionPrivacyVar(i,a),this._updateLambdaStatement(s,i,a),new gu(r.getToken(),i,this._interpreter,[...a.keys()])}checkAndCreateNodeType(r){if(!(!(r instanceof J)||r.getToken().trim().toUpperCase()!==$t))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(!(oi(i)&&a!==0))if(o instanceof J)this._updateTree(o,n,e);else{const u=o.trim();if(e.has(u)){const c=new J;c.setToken(Wt),c.setLambdaId(n),c.setLambdaPrivacyVar(e),c.setLambdaParameter(u),t[a]=c}}}}};gr=du([Zn(0,Oe),Zn(1,N.Inject(Lt))],gr);function ci(r){if(!r)return;if(r.getToken()!==Wt)return r;const n=r,e=n.getCurrentLambdaPrivacyVar(),t=n.getLambdaParameter();if(e)return ci(e.get(t))}class pu extends Pe{constructor(n,e,t){super(n),this._lambdaParameter=e,this._currentLambdaPrivacyVar=t}getLambdaParameter(){return this._lambdaParameter}getCurrentLambdaPrivacyVar(){return this._currentLambdaPrivacyVar}get nodeType(){return te.LAMBDA_PARAMETER}execute(){const n=ci(this._currentLambdaPrivacyVar.get(this._lambdaParameter));if(n)this.setValue(n.getValue());else{const e=this.getValue();(e==null||e.isError())&&this.setValue(h.create(f.SPILL))}}}class li extends He{get zIndex(){return ze.get(te.LAMBDA_PARAMETER)||Qe}create(n){const e=n.getFunctionDefinitionPrivacyVar(),t=n.getLambdaParameter();return e?new pu(n.getToken(),t,e):new ye(f.SPILL)}checkAndCreateNodeType(n){if(!(!(n instanceof J)||n.getToken().trim()!==Wt))return this.create(n)}}class Ru extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return te.NULL}execute(){this.setValue(ce.create())}}var _u=Object.defineProperty,Eu=Object.getOwnPropertyDescriptor,Cu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Eu(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&&_u(n,e,s),s},yu=(r,n)=>(e,t)=>n(e,t,r);class Du extends Pe{constructor(n,e){super(n),this._operatorString=n,this._functionExecutor=e}get nodeType(){return te.OPERATOR}execute(){var i,a;const n=this.getChildren();this._functionExecutor.name===Ae.COMPARE&&this._functionExecutor.setCompareType(this.getToken());let e=(i=n[0])==null?void 0:i.getValue(),t=(a=n[1])==null?void 0:a.getValue();const s=this.getToken();if((e==null||t==null)&&s!==pe.MINUS&&s!==pe.PLUS){this.setValue(h.create(f.VALUE));return}e==null&&(e=ce.create()),t==null&&(t=ce.create()),e.isReferenceObject()&&(e=e.toArrayValueObject()),t.isReferenceObject()&&(t=t.toArrayValueObject()),this.setValue(this._functionExecutor.calculate(e,t))}}let pr=class extends He{constructor(r){super(),this._functionService=r}get zIndex(){return ze.get(te.OPERATOR)||Qe}create(r){let n="";const e=r;e===pe.PLUS?n=Ae.PLUS:e===pe.MINUS?n=Ae.MINUS:e===pe.MULTIPLY?n=Ae.MULTIPLY:e===pe.DIVIDED?n=Ae.DIVIDED:e===pe.CONCATENATE?n=mt.CONCATENATE:e===pe.POWER?n=we.POWER:vi.has(e)&&(n=Ae.COMPARE);const t=this._functionService.getExecutor(n);return t?new Du(e,t):(console.error(`No function ${r}`),ye.create(f.NAME))}checkAndCreateNodeType(r){if(r instanceof J)return;const n=r.trim();if(!(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')&&lt.has(n))return this.create(n)}};pr=Cu([yu(0,We)],pr);class bu extends C.Disposable{constructor(){super(...arguments);S(this,"_tableMap",new Map);S(this,"_tableOptionMap",new Map)}dispose(){this._tableMap.clear(),this._tableOptionMap.clear()}remove(e,t){var s;(s=this._tableMap.get(e))==null||s.delete(t)}getTableMap(e){return this._tableMap.get(e)}getTableOptionMap(){return this._tableOptionMap}registerTable(e,t,s){var i;this._tableMap.get(e)==null&&this._tableMap.set(e,new Map),(i=this._tableMap.get(e))==null||i.set(t,s)}registerTableOptionMap(e,t){this._tableOptionMap.set(e,t)}}const pn=N.createIdentifier("univer.formula.super-table.service");class Su extends Vt{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),c=u.startColumn,l=u.endColumn,m=u.type;let d=-1,_=-1;const D=a.startRow,E=a.startColumn;m===ft.ALL?(d=D,_=E):m===ft.DATA?(d=D+1,_=E):m===ft.HEADERS?(d=D,_=D):m===ft.TOTALS&&(d=E,_=E),this.setRangeData({startColumn:c,endColumn:l,startRow:d,endRow:_})}isTable(){return!0}_stringToColumnData(n,e,t){n=n.substring(1,-1);const s=n.indexOf(G.COMMA);let i=-1,a=-1,o=ft.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),c=n.substring(s+1),l=this._columnHandler(c,e,!0);i=l.startColumn,a=l.endColumn,o=t.get(u),o||(o=ft.ALL)}return{startColumn:i,endColumn:a,type:o}}_columnHandler(n,e,t=!1){var o,u,c;let s=-1,i=-1;const a=n.indexOf(G.COLON);if(new RegExp(ms,"g").test(n)){const l=n.substring(0,a).substring(1,-1),m=n.substring(a+1).substring(1,-1);s=(o=e.get(l))!=null?o:-1,i=(u=e.get(m))!=null?u:-1}else t&&(n=n.substring(1,-1)),s=(c=e.get(n))!=null?c:-1,i=s;return{startColumn:s,endColumn:i}}}var Au=Object.defineProperty,Lu=Object.getOwnPropertyDescriptor,xu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Lu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Au(n,e,s),s},Bt=(r,n)=>(e,t)=>n(e,t,r);class er extends Pe{constructor(n,e,t,s=!1){super(e),this._accessor=n,this._operatorString=e,this._referenceObject=t,this._isPrepareMerge=s}get nodeType(){return te.REFERENCE}execute(){const n=this._accessor.get(at),e=this._accessor.get(Oe);this._referenceObject.setDefaultUnitId(e.currentUnitId),this._referenceObject.setDefaultSheetId(e.currentSubUnitId),this._referenceObject.setForcedSheetId(n.getSheetNameMap()),this._referenceObject.setUnitData(n.getUnitData()),this._referenceObject.setArrayFormulaCellData(n.getArrayFormulaCellData()),this._referenceObject.setRuntimeData(e.getUnitData()),this._referenceObject.setNumfmtItemData(n.getNumfmtItemMap()),this._referenceObject.setRuntimeArrayFormulaCellData(e.getRuntimeArrayFormulaCellData()),this._referenceObject.setRuntimeFeatureCellData(e.getRuntimeFeatureCellData());const{x:t,y:s}=this.getRefOffset();this._referenceObject.setRefOffset(t,s),!this._isPrepareMerge&&this._referenceObject.isExceedRange()?this.setValue(h.create(f.NAME)):this.setValue(this._referenceObject)}}let Rr=class extends He{constructor(r,n,e,t,s){super(),this._definedNamesService=r,this._superTableService=n,this._formulaRuntimeService=e,this._functionService=t,this._injector=s}get zIndex(){return ze.get(te.REFERENCE)||Qe}checkAndCreateNodeType(r){var u,c;let n=!1,e,t=!1;r instanceof J?(n=!0,e=r.getToken().trim(),((c=(u=r.getParent())==null?void 0:u.getParent())==null?void 0:c.getToken().trim())===G.COLON&&(t=!0)):e=r.trim();const{tokenTrim:s,minusPrefixNode:i,atPrefixNode:a}=ai(e,this._functionService,this._injector);if(!n&&s.charAt(0)==='"'&&s.charAt(s.length-1)==='"')return;let o;if(new RegExp(Ht).test(s))o=new er(this._injector,s,new un(s),t);else if(n&&new RegExp(fs).test(s))o=new er(this._injector,s,new cn(s),t);else if(n&&new RegExp(hs).test(s))o=new er(this._injector,s,new ln(s),t);else{const l=this._formulaRuntimeService.currentUnitId,m=this._superTableService.getTableMap(l),d=new RegExp(ms,"g"),_=s.replace(d,"");if(!n&&(m!=null&&m.has(_))){const D=d.exec(s);let E="";D&&(E=D[0]);const A=m.get(_),x=this._superTableService.getTableOptionMap();o=new er(this._injector,s,new Su(s,A,E,x))}}if(o)return a?o.setParent(a):i&&o.setParent(i),o}};Rr=xu([Bt(0,Xt),Bt(1,pn),Bt(2,Oe),Bt(3,We),Bt(4,N.Inject(N.Injector))],Rr);var wu=Object.defineProperty,Pu=Object.getOwnPropertyDescriptor,Vu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Pu(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&&wu(n,e,s),s},Jn=(r,n)=>(e,t)=>n(e,t,r);class Nn extends Pe{constructor(n,e,t){super(e),this._accessor=n,this._operatorString=e,this._functionExecutor=t}get nodeType(){return te.SUFFIX}execute(){let e=this.getChildren()[0].getValue(),t;if(e==null)throw new Error("object is null");this._operatorString===qe.PERCENTAGE?(e.isReferenceObject()&&(e=e.toArrayValueObject()),t=this._functionExecutor.calculate(e,b.create(100)),t.isNumber()&&t.setPattern("0.00%")):this._operatorString===qe.POUND?t=this._handlerPound(e):t=h.create(f.VALUE),this.setValue(t)}_handlerPound(n){var l,m,d,_;if(!n.isReferenceObject()||!n.isCell())return h.create(f.VALUE);const e=this._accessor.get(at),t=this._accessor.get(At),s=n,i=s.getRangePosition(),a=s.getUnitId(),o=s.getSheetId(),u=e.getFormulaData(),c=(_=(d=(m=(l=u==null?void 0:u[a])==null?void 0:l[o])==null?void 0:m[i.startRow])==null?void 0:d[i.startColumn])==null?void 0:_.f;return c&&t.treeBuilder(c),h.create(f.VALUE)}}let _r=class extends He{constructor(r,n){super(),this._functionService=r,this._injector=n}get zIndex(){return ze.get(te.SUFFIX)||Qe}checkAndCreateNodeType(r){if(!(r instanceof J))return;const n=r.getToken().trim();if(n.charAt(0)==='"'&&n.charAt(n.length-1)==='"')return;let e="";if(n===qe.PERCENTAGE)e=Ae.DIVIDED;else return n===qe.POUND?new Nn(this._injector,n):void 0;const t=this._functionService.getExecutor(e);return t?new Nn(this._injector,n,t):(console.error(`No function ${r}`),ye.create(f.NAME))}};_r=Vu([Jn(0,We),Jn(1,N.Inject(N.Injector))],_r);var vu=Object.defineProperty,Mu=Object.getOwnPropertyDescriptor,Ou=(r,n,e,t)=>{for(var s=t>1?void 0:t?Mu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&vu(n,e,s),s},Fu=(r,n)=>(e,t)=>n(e,t,r);class Bu extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return te.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===G.COLON?s=this._unionFunction(e,t):s=h.create(f.NAME),this.setValue(s)}_unionFunction(n,e){return n.isError()||e.isError()||!n.isReferenceObject()||!e.isReferenceObject()?h.create(f.REF):(n=n,e=e,n.isCell()&&e.isCell()||n.isRow()&&e.isRow()||n.isColumn()&&e.isColumn()?n.unionBy(e):h.create(f.REF))}}let Er=class extends He{constructor(r){super(),this._functionService=r}get zIndex(){return ze.get(te.UNION)||Qe}create(r){return new Bu(r)}checkAndCreateNodeType(r){if(!(r instanceof J))return;const e=r.getToken().trim();if(!(e.charAt(0)==='"'&&e.charAt(e.length-1)==='"')&&e===G.COLON)return this.create(e)}};Er=Ou([Fu(0,We)],Er);class Uu extends Pe{constructor(n){super(n),this._operatorString=n}get nodeType(){return te.VALUE}execute(){this.setValue(it.create(this._operatorString))}}class fi extends He{get zIndex(){return ze.get(te.VALUE)||Qe}_checkValueNode(n){if(Number.isNaN(Number(n))){const e=n.trim(),t=e.charAt(0),s=e.charAt(e.length-1);if(Qt.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===st.TRUE||i===st.FALSE)return this.create(i)}else return this.create(n)}create(n){return new Uu(n)}checkAndCreateNodeType(n){if(!(n instanceof J))return this._checkValueNode(n)}}function ku(r){let n=r;for(;n!=null&&n.getParent();)n=n.getParent();return n}var Tu=Object.defineProperty,ju=Object.getOwnPropertyDescriptor,$u=(r,n,e,t)=>{for(var s=t>1?void 0:t?ju(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Tu(n,e,s),s},Ue=(r,n)=>(e,t)=>n(e,t,r);let zt=class extends C.Disposable{constructor(n,e,t,s,i,a,o,u,c,l,m){super();S(this,"_astNodeFactoryList",[]);S(this,"_refOffsetX",0);S(this,"_refOffsetY",0);this._runtimeService=n,this._astRootNodeFactory=e,this._functionNodeFactory=t,this._lambdaNodeFactory=s,this._lambdaParameterNodeFactory=i,this._operatorNodeFactory=a,this._prefixNodeFactory=o,this._referenceNodeFactory=u,this._suffixNodeFactory=c,this._unionNodeFactory=l,this._valueNodeFactory=m,this._initializeAstNode()}dispose(){this._astNodeFactoryList.forEach(n=>{n.dispose()}),this._astNodeFactoryList=[]}parse(n,e=0,t=0){const s=new Wr(rt);return this._refOffsetX=e,this._refOffsetY=t,this._parse(n,s)}_lambdaParameterHandler(n,e){const t=e.getLambdaId(),s=new Wr(rt),i=this._runtimeService.getFunctionDefinitionPrivacyVar(t);if(!i)return!1;const a=[...i.keys()],o=n.getChildren(),u=o.length;for(let m=0;m<u;m++){const d=o[m];if(d instanceof J)this._parse(d,s);else return!1}const c=s.getChildren(),l=c.length;for(let m=0;m<l;m++){const d=c[m];i.set(a[m],d)}return s.setParent(e),e}_changeLetToLambda(n){const e=n.getChildren(),t=e.length;if(t%2!==1||t===0)return;const s=new J;s.setToken($t);const i=new J;i.setToken(St);const a=[...e];for(let u=0;u<t;u++){const c=a[u];if(!(c instanceof J))return;u%2===0?c.changeToParent(s):c.changeToParent(i)}s.addChildrenFirst(i),i.setParent(s);const o=n.getParent();return o==null||o.replaceChild(n,s),s}_parse(n,e){const t=n.getChildren(),s=t.length,i=[];let a=null;const o=n.getToken().trim().toUpperCase();if(o===$i){const l=this._changeLetToLambda(n);return l!=null?this._parse(l,e):ye.create(f.ERROR)}if(o===Xe){if(a=e,s===0)return new Ru(rt).setParent(e),a}else{if(o===St){let l=this._lambdaParameterHandler(n,e);return l===!1&&(l=ye.create(f.ERROR)),l}if(a=this._checkAstNode(n),a==null)return ye.create(f.ERROR)}const u=t[0];for(let l=0;l<s;l++){const m=t[l];if(oi(u)){if(l!==0&&l!==s-1)continue}else if(fu(m)&&l!==s-1)continue;let d=null;if(m instanceof J){if(d=this._parse(m,a),d===a)continue}else d=this._checkAstNode(m);if(d==null)return ye.create(f.NAME);if(d=ku(d),d==null)return;switch(d.nodeType){case te.ERROR:return d;case te.FUNCTION:i.push(d);break;case te.LAMBDA:i.push(d);break;case te.LAMBDA_PARAMETER:i.push(d);break;case te.OPERATOR:{const _=i.pop(),D=i.pop();D&&D.setParent(d),_&&_.setParent(d),i.push(d);break}case te.REFERENCE:d.setRefOffset(this._refOffsetX,this._refOffsetY),i.push(d);break;case te.ROOT:i.push(d);break;case te.UNION:i.push(d);break;case te.VALUE:i.push(d);break;case te.PREFIX:i.push(d);break;case te.SUFFIX:i.push(d);break}}const c=i.length;for(let l=0;l<c;l++)i[l].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(C.sortRules)}};zt=$u([Ue(0,Oe),Ue(1,N.Inject(si)),Ue(2,N.Inject(dr)),Ue(3,N.Inject(gr)),Ue(4,N.Inject(li)),Ue(5,N.Inject(pr)),Ue(6,N.Inject(mr)),Ue(7,N.Inject(Rr)),Ue(8,N.Inject(_r)),Ue(9,N.Inject(Er)),Ue(10,N.Inject(fi))],zt);class hi extends C.Disposable{constructor(){super(...arguments);S(this,"_referenceExecutorMap",new Map)}dispose(){this._referenceExecutorMap.clear()}remove(e){this._referenceExecutorMap.delete(e)}get(e){return this._referenceExecutorMap.get(e)}has(e){return this._referenceExecutorMap.has(e)}register(e,t){this._referenceExecutorMap.set(e,t)}getReferenceExecutorMap(){return this._referenceExecutorMap}}const Pr=N.createIdentifier("univer.formula.feature-calculation-manager.service");class mi extends C.Disposable{constructor(){super(...arguments);S(this,"_otherFormulaData",{})}dispose(){this._otherFormulaData={}}remove(e){var a,o,u;const{unitId:t,subUnitId:s,formulaId:i}=e;(u=(o=(a=this._otherFormulaData)==null?void 0:a[t])==null?void 0:o[s])==null||delete u[i]}get(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return(o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i]}has(e){var a,o;const{unitId:t,subUnitId:s,formulaId:i}=e;return((o=(a=this._otherFormulaData[t])==null?void 0:a[s])==null?void 0:o[i])!=null}register(e){const{unitId:t,subUnitId:s,formulaId:i,item:a}=e;this._otherFormulaData[t]||(this._otherFormulaData[t]={}),this._otherFormulaData[t][s]||(this._otherFormulaData[t][s]={}),this._otherFormulaData[t][s][i]=a}batchRegister(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{const a=s[i];if(a==null)return!0;Object.keys(a).forEach(o=>{const u=a[o];if(u==null)return!0;this.register({unitId:t,subUnitId:i,formulaId:o,item:u})})})})}batchRemove(e){Object.keys(e).forEach(t=>{const s=e[t];if(s==null)return!0;Object.keys(s).forEach(i=>{const a=s[i];if(a==null)return!0;Object.keys(a).forEach(o=>{this.remove({unitId:t,subUnitId:i,formulaId:o})})})})}getOtherFormulaData(){return this._otherFormulaData}}const Vr=N.createIdentifier("univer.formula.other-formula-manager.service");class jr extends C.Disposable{constructor(){super(...arguments);S(this,"node");S(this,"children",[]);S(this,"parents",[]);S(this,"formula","");S(this,"row",-1);S(this,"column",-1);S(this,"rowCount",Number.NEGATIVE_INFINITY);S(this,"columnCount",Number.NEGATIVE_INFINITY);S(this,"subUnitId","");S(this,"unitId","");S(this,"rangeList",[]);S(this,"formulaId");S(this,"featureId");S(this,"getDirtyData");S(this,"_state",0)}dispose(){var e;this.children.forEach(t=>{t.dispose()}),this.rangeList=[],this.parents=[],(e=this.node)==null||e.dispose()}setAdded(){this._state=1}isAdded(){return this._state===1}setSkip(){this._state=2}isSkip(){return this._state===2}inRangeData(e){const t=e.startRow,s=e.startColumn,i=e.endRow,a=e.endColumn;return!(this.row<t||this.row>i||this.column<s||this.column>a)}dependencyRange(e,t,s){var i,a;if(this.rangeList.length===0)return!1;for(let o=0,u=this.rangeList.length;o<u;o++){const c=this.rangeList[o],{unitId:l,sheetId:m,range:d}=c.gridRange;if(((i=t[l])==null?void 0:i[m])!=null)return!0;if(!e.has(l))continue;const _=e.get(l);if(!_.has(m))continue;const D=_.get(m),E=(a=s==null?void 0:s[l])==null?void 0:a[m];let{startRow:A,endRow:x,startColumn:w,endColumn:U}=d;Number.isNaN(A)&&(A=0),Number.isNaN(w)&&(w=0),Number.isNaN(x)&&(x=Number.POSITIVE_INFINITY),Number.isNaN(U)&&(U=Number.POSITIVE_INFINITY);for(const $ of D){const{startRow:se,startColumn:he,endRow:de,endColumn:q}=$;if(!(A>de||x<se||w>q||U<he)){let z=!0;if(E==null||E.forValue((re,Z)=>{if(re>=A&&re<=x&&Z>=w&&Z<=U)return z=!1,!1}),z)return!0}}}return!1}pushChildren(e){this.children.push(e),e._pushParent(this)}pushRangeList(e){this.rangeList.push(e)}dependency(e){if(this.rangeList.length===0)return!1;for(let t=0,s=this.rangeList.length;t<s;t++){const i=this.rangeList[t],a=i.gridRange.unitId,o=i.gridRange.sheetId,u=i.gridRange.range;if(e.unitId===a&&e.subUnitId===o&&e.inRangeData(u))return!0}return!1}_pushParent(e){this.parents.push(e)}}class Iu extends C.Disposable{constructor(){super(...arguments);S(this,"_cacheItems",new Map)}dispose(){this.clear()}size(){return this._cacheItems.size}add(e,t){const{token:s}=e;if(!this._cacheItems.has(s)){this._cacheItems.set(s,{unitRangeWithToken:e,treeList:[t]});return}this._cacheItems.get(s).treeList.push(t)}clear(){this._cacheItems.clear()}remove(e,t){if(!this._cacheItems.has(e))return;const s=this._cacheItems.get(e),i=s.treeList.indexOf(t);i!==-1&&s.treeList.splice(i,1)}delete(e){this._cacheItems.delete(e)}dependency(e){this._cacheItems.forEach(t=>{const{unitRangeWithToken:s,treeList:i}=t,{gridRange:a}=s,{unitId:o,sheetId:u,range:c}=a;e.unitId===o&&e.subUnitId===u&&e.inRangeData(c)&&i.forEach(l=>{if(l===e)return!0;l.pushChildren(e)})})}}var Yu=Object.defineProperty,zu=Object.getOwnPropertyDescriptor,Qu=(r,n,e,t)=>{for(var s=t>1?void 0:t?zu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Yu(n,e,s),s},ut=(r,n)=>(e,t)=>n(e,t,r);const Hu=1e5,$r=new pt(Hu);let Tt=class extends C.Disposable{constructor(n,e,t,s,i,a,o){super();S(this,"_updateRangeFlattenCache",new Map);S(this,"_dirtyUnitSheetNameMap",{});this._currentConfigService=n,this._runtimeService=e,this._otherFormulaManagerService=t,this._featureCalculationManagerService=s,this._interpreter=i,this._astTreeBuilder=a,this._lexer=o}dispose(){this._updateRangeFlattenCache.clear(),$r.clear(),this._dirtyUnitSheetNameMap={}}async generate(){this._updateRangeFlatten();const n=this._currentConfigService.getFormulaData(),e=this._otherFormulaManagerService.getOtherFormulaData(),t=this._currentConfigService.getUnitData(),{treeList:s,dependencyTreeCache:i}=await this._generateTreeList(n,e,t),a=this._getUpdateTreeListAndMakeDependency(s,i);this._checkIsCycleDependency(a)&&this._runtimeService.enableCycleDependency();const u=this._calculateRunList(a);return Promise.resolve(u)}_isCyclicUtil(n,e,t){if(!e.has(n)){e.add(n),t.add(n);for(let s=0;s<n.children.length;s++)if(!e.has(n.children[s])&&this._isCyclicUtil(n.children[s],e,t)||t.has(n.children[s]))return!0}return t.delete(n),!1}_checkIsCycleDependency(n){const e=new Set,t=new Set;for(let s=0,i=n.length;s<i;s++){const a=n[s];if(this._isCyclicUtil(a,e,t)===!0)return!0}return!1}async _generateTreeList(n,e,t){const s=Object.keys(n),i=Object.keys(e),a=[];for(const u of s){const c=n[u];if(c==null)continue;const l=Object.keys(c);for(const m of l)new C.ObjectMatrix(c[m]).forValue((_,D,E)=>{if(E==null)return!0;const{f:A,x,y:w}=E,U=this._generateAstNode(A,x,w),$=new jr,se=t[u][m];$.node=U,$.formula=A,$.unitId=u,$.subUnitId=m,$.row=_,$.column=D,$.rowCount=se.rowCount,$.columnCount=se.columnCount,a.push($)})}for(const u of i){const c=e[u];if(c==null)continue;const l=Object.keys(c);for(const m of l){const d=c[m];if(d==null)continue;const _=Object.keys(d);for(const D of _){const E=d[D],{f:A}=E,x=this._generateAstNode(A),w=new jr;w.node=x,w.formula=A,w.unitId=u,w.subUnitId=m,w.formulaId=D,a.push(w)}}}this._featureCalculationManagerService.getReferenceExecutorMap().forEach((u,c)=>{const{unitId:l,subUnitId:m,dependencyRanges:d,getDirtyData:_}=u,D=new jr;D.unitId=l,D.subUnitId=m,D.getDirtyData=_,D.featureId=c,D.rangeList=d.map(E=>({gridRange:E,token:bt({...E,sheetName:this._currentConfigService.getSheetName(E.unitId,E.sheetId)})})),a.push(D)});const o=new Iu;for(let u=0,c=a.length;u<c;u++){const l=a[u];if(this._runtimeService.setCurrent(l.row,l.column,l.rowCount,l.columnCount,l.subUnitId,l.unitId),l.node==null)continue;const m=await this._getRangeListByNode(l.node);for(let d=0,_=m.length;d<_;d++){const D=m[d];l.pushRangeList(D),o.add(D,l)}}return{treeList:a,dependencyTreeCache:o}}_updateRangeFlatten(){const n=this._currentConfigService.isForceCalculate(),e=this._currentConfigService.getDirtyRanges();if(!n){this._updateRangeFlattenCache.clear();for(let t=0;t<e.length;t++){const s=e[t],i=s.range,a=s.sheetId,o=s.unitId;this._addFlattenCache(o,a,i)}this._dirtyUnitSheetNameMap=this._currentConfigService.getDirtyNameMap()}}_generateAstNode(n,e=0,t=0){let s=$r.get(`${n}##${e}${t}`);if(s)return s;const i=this._lexer.treeBuilder(n);if(Qt.has(i))return ye.create(i);if(s=this._astTreeBuilder.parse(i,e,t),s==null)throw new Error("astNode is null");return $r.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===te.UNION||n.nodeType===te.PREFIX&&n.getToken()===Re.AT||n.nodeType===te.SUFFIX&&n.getToken()===qe.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===te.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===te.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],c=(await this._executeNode(o)).toUnitRange(),l=bt({...c,sheetName:this._currentConfigService.getSheetName(c.unitId,c.sheetId)});s.push({gridRange:c,token:l})}for(let i=0,a=t.length;i<a;i++){const o=t[i],c=(await this._executeNode(o)).toUnitRange(),l=bt({...c,sheetName:this._currentConfigService.getSheetName(c.unitId,c.sheetId)});s.push({gridRange:c,token:l})}return s}_getUpdateTreeListAndMakeDependency(n,e){const t=[],s=new Set,i=this._currentConfigService.isForceCalculate();let a=!0;e.size()>n.length&&(a=!1);for(let o=0,u=n.length;o<u;o++){const c=n[o];if(a)e.dependency(c);else for(let l=0,m=n.length;l<m;l++){const d=n[l];c!==d&&c.dependency(d)&&c.pushChildren(d)}(i||c.dependencyRange(this._updateRangeFlattenCache,this._dirtyUnitSheetNameMap,this._currentConfigService.getExcludedRange())||this._includeTree(c))&&!s.has(c)&&(t.push(c),s.add(c))}return e.dispose(),t}_includeTree(n){var l,m,d,_,D,E,A;const e=n.unitId,t=n.subUnitId,s=n.featureId;if(s!=null){const x=this._currentConfigService.getDirtyUnitFeatureMap();if(((m=(l=x==null?void 0:x[e])==null?void 0:l[t])==null?void 0:m[s])!=null)return!0}const i=n.formulaId;if(i!=null){const x=this._currentConfigService.getDirtyUnitOtherFormulaMap();if(((_=(d=x==null?void 0:x[e])==null?void 0:d[t])==null?void 0:_[i])!=null)return!0}const a=(E=(D=this._currentConfigService.getExcludedRange())==null?void 0:D[e])==null?void 0:E[t];let o=!1;if(a==null||a.forValue((x,w)=>{if(n.row===x&&n.column===w)return o=!0,!1}),o)return!1;if(((A=this._dirtyUnitSheetNameMap[e])==null?void 0:A[t])!=null)return!0;if(!this._updateRangeFlattenCache.has(e))return!1;const u=this._updateRangeFlattenCache.get(e);if(!u.has(t))return!1;const c=u.get(t);for(const x of c)if(n.inRangeData(x))return!0;return!1}_calculateRunList(n){let e=n;const t=[];for(;e.length>0;){const s=e.pop();if(s===void 0||s.isSkip())continue;if(s.isAdded()){t.push(s);continue}const i=[];for(let a=0,o=s.parents.length;a<o;a++){const u=s.parents[a];u.isAdded()||s.isSkip()||i.push(u)}i.length===0?(t.push(s),s.setSkip()):(s.setAdded(),e.push(s),e=e.concat(i))}return t.reverse()}};Tt=Qu([C.OnLifecycle(C.LifecycleStages.Rendered,Tt),ut(0,at),ut(1,Oe),ut(2,Vr),ut(3,Pr),ut(4,N.Inject(Lt)),ut(5,N.Inject(zt)),ut(6,N.Inject(At))],Tt);var Wu=Object.defineProperty,Gu=Object.getOwnPropertyDescriptor,Xu=(r,n,e,t)=>{for(var s=t>1?void 0:t?Gu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Wu(n,e,s),s},ct=(r,n)=>(e,t)=>n(e,t,r);const Ku=1;exports.CalculateFormulaService=class extends C.Disposable{constructor(e,t,s,i,a,o,u){super();S(this,"_executionStartListener$",new Or.Subject);S(this,"executionStartListener$",this._executionStartListener$.asObservable());S(this,"_executionCompleteListener$",new Or.Subject);S(this,"executionCompleteListener$",this._executionCompleteListener$.asObservable());S(this,"_executionInProgressListener$",new Or.Subject);S(this,"executionInProgressListener$",this._executionInProgressListener$.asObservable());this._configService=e,this._lexer=t,this._currentConfigService=s,this._runtimeService=i,this._formulaDependencyGenerator=a,this._interpreter=o,this._astTreeBuilder=u}dispose(){}stopFormulaExecution(){this._runtimeService.stopExecution()}setRuntimeFeatureCellData(e,t){this._runtimeService.setRuntimeFeatureCellData(e,t)}setRuntimeFeatureRange(e,t){this._runtimeService.setRuntimeFeatureRange(e,t)}async execute(e){this._executionStartListener$.next(!0),this._currentConfigService.load(e),this._runtimeService.reset();const t=this._configService.getConfig("CYCLE_REFERENCE_COUNT")||Ku;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()),Hr.clear(),Ne.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 c=new C.ObjectMatrix(o[u]);if(c==null)return!0;const l=new C.ObjectMatrix;c.forValue((m,d,_)=>{l.setValue(m,d,!0),s.push({unitId:a,sheetId:u,range:_})}),i[a]==null&&(i[a]={}),i[a][u]=l})}),Object.keys(t).forEach(a=>{const o=t[a];Object.keys(o).forEach(u=>{const c=o[u];if(c==null)return!0;Object.keys(c).forEach(l=>{const m=c[l];if(m==null)return!0;for(const d of m)s.push({unitId:u,sheetId:l,range:d})})})}),{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=>{C.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,c=o.getDirtyData;let l;if(u==null&&c==null)throw new Error("AstNode or executor is null");if(this._runtimeService.setCurrent(o.row,o.column,o.rowCount,o.columnCount,o.subUnitId,o.unitId),c!=null&&o.featureId!=null){const{runtimeCellData:m,dirtyRanges:d}=c(o);this._runtimeService.setRuntimeFeatureCellData(o.featureId,m),this._runtimeService.setRuntimeFeatureRange(o.featureId,d)}else u!=null&&(s.checkAsyncNode(u)?l=await s.executeAsync(u):l=s.execute(u),o.formulaId!=null?this._runtimeService.setRuntimeOtherData(o.formulaId,l):this._runtimeService.setRuntimeData(l));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(f).includes(s))return ye.create(s);const i=this._astTreeBuilder.parse(s);i==null||i.serialize()}};exports.CalculateFormulaService=Xu([C.OnLifecycle(C.LifecycleStages.Rendered,exports.CalculateFormulaService),ct(0,C.IConfigService),ct(1,N.Inject(At)),ct(2,at),ct(3,Oe),ct(4,N.Inject(Tt)),ct(5,N.Inject(Lt)),ct(6,N.Inject(zt))],exports.CalculateFormulaService);const Rn={id:"formula.mutation.set-numfmt-formula-data",type:C.CommandType.MUTATION,handler:(r,n)=>(r.get(exports.FormulaDataModel).updateNumfmtItemMap(n.numfmtItemMap),!0)};var qu=Object.defineProperty,Zu=Object.getOwnPropertyDescriptor,Ju=(r,n,e,t)=>{for(var s=t>1?void 0:t?Zu(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&qu(n,e,s),s},tr=(r,n)=>(e,t)=>n(e,t,r);let nr=class extends C.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===Jr.id)this._calculateFormulaService.stopFormulaExecution();else if(r.id===en.id){const e=r.params.formulaData;this._formulaDataModel.setFormulaData(e)}else if(r.id===Zr.id){const e=r.params;if(e.forceCalculation===!0)this._calculate(!0);else{const{dirtyRanges:t,dirtyNameMap:s,dirtyUnitFeatureMap:i,dirtyUnitOtherFormulaMap:a,numfmtItemMap:o}=e;this._calculate(!1,t,s,i,a,o)}}else if(r.id===lr.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={},i={}){if(n.length===0&&Object.keys(e).length===0&&Object.keys(t).length===0&&Object.keys(s).length===0&&r===!1)return;const a=this._formulaDataModel.getFormulaData(),o=this._formulaDataModel.getArrayFormulaCellData();this._calculateFormulaService.execute({formulaData:a,arrayFormulaCellData:o,forceCalculate:r,dirtyRanges:n,dirtyNameMap:e,dirtyUnitFeatureMap:t,dirtyUnitOtherFormulaMap:s,numfmtItemMap:i})}_initialExecuteFormulaListener(){this._calculateFormulaService.executionCompleteListener$.subscribe(r=>{const n=r.functionsExecutedState;switch(n){case yt.NOT_EXECUTED:break;case yt.STOP_EXECUTION:break;case yt.SUCCESS:this._applyFormula(r);break;case yt.INITIAL:break}this._commandService.executeCommand(fr.id,{functionsExecutedState:n},{onlyLocal:!0})})}_initialExecuteFormulaProcessListener(){this._calculateFormulaService.executionInProgressListener$.subscribe(r=>{this._commandService.executeCommand(fr.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(lr.id,{arrayFormulaRange:this._formulaDataModel.getArrayFormulaRange(),arrayFormulaCellData:this._formulaDataModel.getArrayFormulaCellData()},{onlyLocal:!0})),C.Tools.isEmptyObject(a)||this._commandService.executeCommand(Rn.id,{numfmtItemMap:a},{onlyLocal:!0}),this._commandService.executeCommand(Nr.id,{unitData:Ui(n),unitOtherData:e},{onlyLocal:!0})}};nr=Ju([C.OnLifecycle(C.LifecycleStages.Ready,nr),tr(0,C.ICommandService),tr(1,N.Inject(exports.CalculateFormulaService)),tr(2,C.IUniverInstanceService),tr(3,N.Inject(exports.FormulaDataModel))],nr);var Nu=Object.defineProperty,ec=Object.getOwnPropertyDescriptor,tc=(r,n,e,t)=>{for(var s=t>1?void 0:t?ec(n,e):n,i=r.length-1,a;i>=0;i--)(a=r[i])&&(s=(t?a(n,e,s):a(s))||s);return t&&s&&Nu(n,e,s),s},Ir=(r,n)=>(e,t)=>n(e,t,r);let jt=class extends C.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(){[en,lr,Zr,Jr,fr,Nr,Rn,Dr,br,Kr,qr,tn,rn,Ds,bs,nn,Gr,sn].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_registerFunctions(){const r=[...ws,...Fs,...Bs,...ks,...js,...$s,...Ys,...Qs,...Hs,...Ws,...Xs,...Ks,...qs,...Js,...Ns,...ti].concat(this._function).map(n=>{const e=n[0],t=n[1];return new e(t)});this._functionService.registerExecutors(...r)}};jt=tc([C.OnLifecycle(C.LifecycleStages.Ready,jt),Ir(1,C.ICommandService),Ir(2,N.Inject(N.Injector)),Ir(3,We)],jt);var rc=Object.defineProperty,nc=Object.getOwnPropertyDescriptor,sc=(r,n,e,t)=>{for(var s=t>1?void 0:t?nc(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&&rc(n,e,s),s},Yr=(r,n)=>(e,t)=>n(e,t,r);let sr=class extends C.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===Gr.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 ac(a,o)});this._functionService.registerExecutors(...s)}else if(r.id===sn.id){const e=r.params;if(e==null)return;const{functions:t}=e;this._functionService.unregisterExecutors(...t)}}))}};sr=sc([C.OnLifecycle(C.LifecycleStages.Ready,sr),Yr(0,C.ICommandService),Yr(1,N.Inject(exports.FormulaDataModel)),Yr(2,We)],sr);class ic extends j{isCustom(){return!0}}function ac(r,n){const e=new ic(n),t=new Function(`return ${r}`)();return e.calculateCustom=t,e}var oc=Object.defineProperty,uc=Object.getOwnPropertyDescriptor,cc=(r,n,e,t)=>{for(var s=t>1?void 0:t?uc(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&&oc(n,e,s),s},es=(r,n)=>(e,t)=>n(e,t,r);let ir=class extends C.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===Dr.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===br.id){const n=r.params;if(n==null)return;const{unitId:e,name:t}=n;this._definedNamesService.removeDefinedName(e,t)}}))}};ir=cc([C.OnLifecycle(C.LifecycleStages.Ready,ir),es(0,C.ICommandService),es(1,Xt)],ir);var lc=Object.defineProperty,fc=Object.getOwnPropertyDescriptor,hc=(r,n,e,t)=>{for(var s=t>1?void 0:t?fc(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&&lc(n,e,s),s},ts=(r,n)=>(e,t)=>n(e,t,r);let ar=class extends C.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===Kr.id){const n=r.params;if(n==null)return;const{featureId:e,calculationParam:t}=n;this._featureCalculationManagerService.register(e,t)}else if(r.id===qr.id){const n=r.params;if(n==null)return;const{featureId:e}=n;this._featureCalculationManagerService.remove(e)}}))}};ar=hc([C.OnLifecycle(C.LifecycleStages.Ready,ar),ts(0,C.ICommandService),ts(1,Pr)],ar);var mc=Object.defineProperty,dc=Object.getOwnPropertyDescriptor,gc=(r,n,e,t)=>{for(var s=t>1?void 0:t?dc(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&&mc(n,e,s),s},rs=(r,n)=>(e,t)=>n(e,t,r);let or=class extends C.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===tn.id){const n=r.params;if(n==null)return;const e={[n.unitId]:{[n.subUnitId]:n.formulaMap}};this._otherFormulaManagerService.batchRegister(e)}else if(r.id===rn.id){const n=r.params;if(n==null)return;const e={};n.formulaIdList.forEach(s=>e[s]=!0);const t={[n.unitId]:{[n.subUnitId]:e}};this._otherFormulaManagerService.batchRemove(t)}}))}};or=gc([C.OnLifecycle(C.LifecycleStages.Ready,or),rs(0,C.ICommandService),rs(1,Vr)],or);var pc=Object.defineProperty,Rc=Object.getOwnPropertyDescriptor,_c=(r,n,e,t)=>{for(var s=t>1?void 0:t?Rc(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&&pc(n,e,s),s},ns=(r,n)=>(e,t)=>n(e,t,r);let ur=class extends C.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===Dr.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===br.id){const n=r.params;if(n==null)return;const{unitId:e,tableName:t}=n;this._superTableService.remove(e,t)}else if(r.id===nn.id){const n=r.params;if(n==null)return;const{tableOption:e,tableOptionType:t}=n;this._superTableService.registerTableOptionMap(e,t)}}))}};ur=_c([C.OnLifecycle(C.LifecycleStages.Ready,ur),ns(0,C.ICommandService),ns(1,pn)],ur);class Ec extends C.Disposable{constructor(){super(...arguments);S(this,"_dirtyConversionMap",new Map)}dispose(){this._dirtyConversionMap.clear()}remove(e){this._dirtyConversionMap.delete(e)}get(e){return this._dirtyConversionMap.get(e)}has(e){return this._dirtyConversionMap.has(e)}register(e,t){this._dirtyConversionMap.set(e,t)}getDirtyConversionMap(){return this._dirtyConversionMap}}const di=N.createIdentifier("univer.formula.active-dirty-manager.service");var Cc=Object.defineProperty,yc=Object.getOwnPropertyDescriptor,Dc=(r,n,e,t)=>{for(var s=t>1?void 0:t?yc(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&&Cc(n,e,s),s},bc=(r,n)=>(e,t)=>n(e,t,r);const Sc="base-formula-engine";exports.UniverFormulaEnginePlugin=class extends C.Plugin{constructor(n,e){super(Sc),this._config=n,this._injector=e}onStarting(){this._initialize()}_initialize(){var e;const n=[[We,{useClass:ii}],[Pr,{useClass:hi}],[Xt,{useClass:ni}],[di,{useClass:Ec}],[exports.FormulaDataModel],[yr],[jt,{useFactory:()=>{var t;return this._injector.createInstance(jt,(t=this._config)==null?void 0:t.function)}}],[ar]];(e=this._config)!=null&&e.notExecuteFormula||n.push([exports.CalculateFormulaService],[Vr,{useClass:mi}],[pn,{useClass:bu}],[at,{useClass:exports.FormulaCurrentConfigService}],[Oe,{useClass:exports.FormulaRuntimeService}],[nr],[ir],[or],[ur],[sr],[Tt],[Lt],[zt],[At],[si],[dr],[gr],[li],[pr],[mr],[Rr],[_r],[Er],[fi]),n.forEach(t=>this._injector.add(t))}onReady(){this._injector.get(exports.FormulaDataModel).initFormulaData()}};exports.UniverFormulaEnginePlugin=Dc([bc(1,N.Inject(N.Injector))],exports.UniverFormulaEnginePlugin);exports.ArrayValueObject=Le;exports.BaseFunction=j;exports.BaseReferenceObject=Vt;exports.BaseValueObject=Ze;exports.BooleanValue=st;exports.BooleanValueObject=Q;exports.DefinedNamesService=ni;exports.ErrorType=f;exports.ErrorValueObject=h;exports.FUNCTION_NAMES_ARRAY=Ps;exports.FUNCTION_NAMES_COMPATIBILITY=Ct;exports.FUNCTION_NAMES_CUBE=Us;exports.FUNCTION_NAMES_DATABASE=Ts;exports.FUNCTION_NAMES_DATE=et;exports.FUNCTION_NAMES_ENGINEERING=Is;exports.FUNCTION_NAMES_FINANCIAL=zs;exports.FUNCTION_NAMES_INFORMATION=ke;exports.FUNCTION_NAMES_LOGICAL=tt;exports.FUNCTION_NAMES_LOOKUP=be;exports.FUNCTION_NAMES_MATH=we;exports.FUNCTION_NAMES_STATISTICAL=Se;exports.FUNCTION_NAMES_TEXT=mt;exports.FUNCTION_NAMES_UNIVER=ei;exports.FUNCTION_NAMES_WEB=ri;exports.FeatureCalculationManagerService=hi;exports.FormulaExecuteStageType=Ie;exports.FormulaExecutedStateType=yt;exports.FunctionService=ii;exports.FunctionType=is;exports.IActiveDirtyManagerService=di;exports.IDefinedNamesService=Xt;exports.IFeatureCalculationManagerService=Pr;exports.IFormulaCurrentConfigService=at;exports.IFormulaRuntimeService=Oe;exports.IFunctionService=We;exports.IOtherFormulaManagerService=Vr;exports.LexerNode=J;exports.LexerTreeBuilder=yr;exports.NumberValueObject=b;exports.OtherFormulaManagerService=mi;exports.RangeReferenceObject=It;exports.RegisterFunctionMutation=Gr;exports.RemoveDefinedNameMutation=br;exports.RemoveFeatureCalculationMutation=qr;exports.RemoveOtherFormulaMutation=rn;exports.RemoveSuperTableMutation=bs;exports.SetArrayFormulaDataMutation=lr;exports.SetArrayFormulaDataUndoMutationFactory=Zi;exports.SetDefinedNameMutation=Dr;exports.SetFeatureCalculationMutation=Kr;exports.SetFormulaCalculationNotificationMutation=fr;exports.SetFormulaCalculationResultMutation=Nr;exports.SetFormulaCalculationStartMutation=Zr;exports.SetFormulaCalculationStopMutation=Jr;exports.SetFormulaDataMutation=en;exports.SetNumfmtFormulaDataMutation=Rn;exports.SetOtherFormulaMutation=tn;exports.SetSuperTableMutation=Ds;exports.SetSuperTableOptionMutation=nn;exports.StringValueObject=_e;exports.UnregisterFunctionMutation=sn;exports.ValueObjectFactory=it;exports.compareToken=F;exports.convertUnitDataToRuntime=us;exports.deserializeRangeForR1C1=xs;exports.deserializeRangeWithSheet=wt;exports.functionArray=ws;exports.functionCompatibility=Fs;exports.functionCube=Bs;exports.functionDatabase=ks;exports.functionDate=js;exports.functionEngineering=$s;exports.functionFinancial=Ys;exports.functionInformation=Qs;exports.functionLogical=Hs;exports.functionLookup=Ws;exports.functionMath=Xs;exports.functionMeta=Ks;exports.functionStatistical=qs;exports.functionText=Js;exports.functionUniver=Ns;exports.functionWeb=ti;exports.generateStringWithSequence=Es;exports.getAbsoluteRefTypeWitString=Qi;exports.getAbsoluteRefTypeWithSingleString=kt;exports.includeFormulaLexerToken=os;exports.initSheetFormulaData=ys;exports.isFormulaLexerToken=Ut;exports.isInDirtyRange=ss;exports.isReferenceString=ds;exports.matchRefDrawToken=Bi;exports.matchToken=G;exports.normalizeSheetName=Fi;exports.operatorToken=pe;exports.sequenceNodeType=Me;exports.serializeRange=dt;exports.serializeRangeToRefString=bt;exports.serializeRangeWithSheet=ps;exports.serializeRangeWithSpreadsheet=Rs;