@sheetxl/sdk 0.4.13 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/cjs/17vteff17iwu-nts.cjs +15 -0
- package/browser/cjs/B1o0X3p_6PiLx4jI.cjs +7 -0
- package/browser/cjs/B339rTr1BsEIo2__.cjs +6 -0
- package/browser/cjs/B6Vc2J26WiHxBQya.cjs +13 -0
- package/browser/cjs/BKAC72r7ywoOltA0.cjs +6 -0
- package/browser/cjs/BVA-ijQaNPkp7YbF.cjs +124 -0
- package/browser/cjs/BXtVRHEodCTlDHKt.cjs +32 -0
- package/browser/cjs/Br5SOD3y14JWQxmm.cjs +6 -0
- package/browser/cjs/BsZ6vhnXHmCHlGZX.cjs +1501 -0
- package/browser/cjs/Bv5GejhVjiiKkQo4.cjs +6 -0
- package/browser/cjs/Bve-_MKdvTST-nYO.cjs +6 -0
- package/browser/cjs/C2h4aMcaEv25R8td.cjs +6 -0
- package/browser/cjs/CK47_UoX6YUMsgbq.cjs +6 -0
- package/browser/cjs/CkXszTzijjKe-x3s.cjs +6 -0
- package/browser/cjs/CnOPibl4Egdph8iO.cjs +6 -0
- package/browser/cjs/CnoRxKqF7cmfYPie.cjs +6 -0
- package/browser/cjs/CwNSe9CinOcKHt9p.cjs +6 -0
- package/browser/cjs/D-TMUgYRD9-WKuJt.cjs +6 -0
- package/browser/cjs/D65Kj_FHrWptDBz6.cjs +6 -0
- package/browser/cjs/DDwxGPgeEH75VzI6.cjs +6 -0
- package/browser/cjs/DEnI4zCWAmN4uqYL.cjs +60 -0
- package/browser/cjs/DEyIncQzUFxinblH.cjs +6 -0
- package/browser/cjs/DJwiyf8nrWTrcqsg.cjs +6 -0
- package/browser/{esm/bC-pS6WlvqHBcNXl.mjs → cjs/DN99k_K8Xt6Cxpbg.cjs} +3 -4
- package/browser/cjs/DR8AZfpEdPwolzLA.cjs +6 -0
- package/browser/cjs/DY7NS5zPRAYW9B4z.cjs +6 -0
- package/browser/cjs/DZoB22ts1B-Uo1_8.cjs +6 -0
- package/browser/cjs/HFD-Ka0JKfOFb-v8.cjs +6 -0
- package/browser/cjs/HrYBZlmkaRPlgpBr.cjs +6 -0
- package/browser/cjs/J0QRcnocFqaCEpXb.cjs +6 -0
- package/browser/cjs/dL-d0P2RzXjtzTKk.cjs +6 -0
- package/browser/cjs/f4q2aiebC4Dk2JpQ.cjs +6 -0
- package/browser/cjs/index.cjs +3 -4
- package/browser/cjs/jAhE-WFeXtkOENRt.cjs +6 -0
- package/browser/esm/1RDByGQ0b6fJxh7d.mjs +10 -0
- package/{node/esm/DLDt1F5JzQq5aKdG.mjs → browser/esm/B1J_tEX0ArjgmDxo.mjs} +1 -1
- package/browser/esm/B6bUGsiDUEqxcpxj.mjs +10 -0
- package/browser/esm/B7TVQO7b5fKHjmdS.mjs +10 -0
- package/{node/esm/CBdo244r3xwae4_o.mjs → browser/esm/B9pQrZA0Y-_hUwWi.mjs} +1 -1
- package/{node/esm/axtXmmwYm1aHBXjg.mjs → browser/esm/BUjgpjT28_Y-kidw.mjs} +1 -1
- package/{node/esm/L0bRh78pniyMZ_3v.mjs → browser/esm/Be8lmKk3pIbpatrW.mjs} +1 -1
- package/browser/esm/BqlVyzcHZSLgnGUm.mjs +10 -0
- package/browser/esm/C6ugA4r8ZBnWJ7SS.mjs +1575 -0
- package/{node/esm/tw0tbG4pvPai6vfe.mjs → browser/esm/CL7ql8UZhgDNpfsM.mjs} +1 -1
- package/{node/esm/Bq3GEYeFkbO3vHHx.mjs → browser/esm/CVlNXQ7d_YZ1bp7F.mjs} +1 -1
- package/browser/esm/C_viEPf8wfrM9XrP.mjs +472 -0
- package/{node/esm/DZl6ZagrmdiXKi9x.mjs → browser/esm/Cf9USLOKImk5ry05.mjs} +1 -1
- package/{node/esm/Bb5FApoZ10dDGlM-.mjs → browser/esm/CqsGDFsS_swdf3vs.mjs} +1 -1
- package/{node/esm/Dlftv7TykJRVk7Wx.mjs → browser/esm/D6yAkYqQpt4Mti36.mjs} +1 -1
- package/browser/esm/D8PCv7S4DISHUIuf.mjs +5651 -0
- package/{node/esm/C6FEsnCdmUvcIDzA.mjs → browser/esm/DC2efMTBtgG0Qg9v.mjs} +1 -1
- package/{node/esm/j5mlBPjSlgnHX9pH.mjs → browser/esm/DJGZqsQxGcCptrL0.mjs} +1 -1
- package/browser/esm/DJSB1iCmSRlSH8T3.mjs +820 -0
- package/browser/esm/DOkO-X1qYgsIKnNj.mjs +3974 -0
- package/{node/esm/dRD2c-s3aQJNoK6m.mjs → browser/esm/DYE2NR7zRrGqd22q.mjs} +1 -1
- package/browser/esm/{DQ6InIROOs1_L5ez.mjs → DZh5MHkoTH4JibFE.mjs} +7 -2
- package/browser/esm/DoyfObpnizfLGHs3.mjs +21 -0
- package/browser/esm/Dqvs0M5ZN2pHLCwm.mjs +24 -0
- package/{node/esm/DMhTOGJLYCiHGnjP.mjs → browser/esm/DxIixek4CImRs91l.mjs} +1 -1
- package/{node/esm/CoowIrBw0vTXnosY.mjs → browser/esm/PWnhitKV1qE65Z3V.mjs} +1 -1
- package/browser/esm/QkxRNX4E_VTO1B3P.mjs +24269 -0
- package/{node/esm/cWKERSoNy_Mo5gOQ.mjs → browser/esm/SLFayFhlPi4T8AO6.mjs} +1 -1
- package/{node/esm/DQvu2JlpO07Yqcvx.mjs → browser/esm/Sr5fscnOJ2IHKKrp.mjs} +1 -1
- package/browser/esm/WUmLxNLfFn0Ozmm-.mjs +10 -0
- package/browser/esm/favrNBo9HOjnV2Y3.mjs +29 -0
- package/browser/esm/index.mjs +84 -2
- package/browser/esm/jdkRKboN0ZTz9YBf.mjs +10 -0
- package/browser/esm/tJR0NVUIbWFQCJp0.mjs +426 -0
- package/licenses/dependencies.txt +3 -3
- package/node/esm/{DNTdUrrAs4YsX782.mjs → AfI5dmtnxoAFOc1C.mjs} +1 -1
- package/node/esm/{Dxqu9uwKDQHBrAqJ.mjs → B1E5b-6lOZJnl4aN.mjs} +2 -2
- package/{browser/cjs/DOptrVmGD_5mAjIJ.cjs → node/esm/B1J_tEX0ArjgmDxo.mjs} +5 -2
- package/node/esm/B9pQrZA0Y-_hUwWi.mjs +10 -0
- package/node/esm/{CKO3kzDC1TBjmP6a.mjs → BEvzdM3wAA2DOPpb.mjs} +1 -1
- package/node/esm/{BmkbBs1Yla2RsZ_s.mjs → BEwii9DEp24ukOxk.mjs} +1 -1
- package/node/esm/{DNLKWsIB7wfMRm8a.mjs → BRakFf60UlCdEoH2.mjs} +2 -2
- package/node/esm/BUjgpjT28_Y-kidw.mjs +10 -0
- package/node/esm/{B-cEaNMrVscFjP28.mjs → BWh89wRFsoTmi9Ib.mjs} +1 -1
- package/node/esm/{DOdqJUKquKrouyJg.mjs → Bd7nQztitF7jnRgP.mjs} +1 -1
- package/node/esm/Be8lmKk3pIbpatrW.mjs +10 -0
- package/node/esm/C9Z0bg7XW6ng3z7k.mjs +80 -0
- package/node/esm/{CsI4IQyunxqLyMWY.mjs → CBuT_Rm4rHFEv2-k.mjs} +1 -1
- package/node/esm/CL7ql8UZhgDNpfsM.mjs +10 -0
- package/node/esm/{G0slAplR6jB1csaY.mjs → CV_B2BH1zuSdWD_e.mjs} +1 -1
- package/node/esm/CVlNXQ7d_YZ1bp7F.mjs +10 -0
- package/node/esm/{BZScF0z5mvap-tCk.mjs → C_eVpG1TqI_0_Zfz.mjs} +1 -1
- package/node/esm/Cf9USLOKImk5ry05.mjs +10 -0
- package/node/esm/{moaVD3gybeaMfy_q.mjs → Cm8B2CXlnA5r12FE.mjs} +1 -1
- package/node/esm/{o47K-SM01hvIUrc0.mjs → CpNeEylJssyF4zm3.mjs} +2 -2
- package/node/esm/CqsGDFsS_swdf3vs.mjs +10 -0
- package/node/esm/D6yAkYqQpt4Mti36.mjs +10 -0
- package/node/esm/DC2efMTBtgG0Qg9v.mjs +10 -0
- package/node/esm/DJGZqsQxGcCptrL0.mjs +10 -0
- package/node/esm/DYE2NR7zRrGqd22q.mjs +10 -0
- package/node/esm/{DHJoU9KsVtSXERyd.mjs → DmxrrAcKGuZW16bw.mjs} +4 -4
- package/node/esm/DxIixek4CImRs91l.mjs +10 -0
- package/node/esm/PWnhitKV1qE65Z3V.mjs +10 -0
- package/node/esm/{n0CrIZcZCwIu-yiw.mjs → RP8av-gx71hD40p7.mjs} +1 -1
- package/node/esm/SLFayFhlPi4T8AO6.mjs +10 -0
- package/node/esm/Sr5fscnOJ2IHKKrp.mjs +10 -0
- package/node/esm/index.mjs +3434 -3183
- package/package.json +4 -4
- package/browser/cjs/99FHKXLdlCef5nfT.cjs +0 -7
- package/browser/cjs/B5eveWag0dzzgkgX.cjs +0 -7
- package/browser/cjs/BJA1_CndBCMNr53J.cjs +0 -7
- package/browser/cjs/BVE8RsCx6dH-PJ3G.cjs +0 -7
- package/browser/cjs/BbvyF-KASTBWusEs.cjs +0 -7
- package/browser/cjs/BfAJd561Nzaudhz_.cjs +0 -7
- package/browser/cjs/BlgZLqYSIZleOo8h.cjs +0 -7
- package/browser/cjs/BpoOeB751mnCS6V-.cjs +0 -7
- package/browser/cjs/CE7l7CfFaLMonVMB.cjs +0 -7
- package/browser/cjs/CHBhqMbMhjW9YdAF.cjs +0 -7
- package/browser/cjs/CIJiAsckzAZgx8n4.cjs +0 -7
- package/browser/cjs/CgOy3BgHFueAFAeL.cjs +0 -7
- package/browser/cjs/Cl0gNER1w9A58kbc.cjs +0 -13
- package/browser/cjs/CmBrJtijpbCUSPWR.cjs +0 -10
- package/browser/cjs/CuYGUMy7ROX5G_sm.cjs +0 -7
- package/browser/cjs/Czqso66RMuDka4LC.cjs +0 -7
- package/browser/cjs/D-NvwNeGLHGiv00z.cjs +0 -7
- package/browser/cjs/DHVBvApvjbLRsOju.cjs +0 -7
- package/browser/cjs/DORshTQEHNF0VHvp.cjs +0 -7
- package/browser/cjs/DRKq7WhWW37UIj1Q.cjs +0 -7
- package/browser/cjs/DhWK7BDP7ZhYYPga.cjs +0 -7
- package/browser/cjs/DpSwAPYhahtG5EKw.cjs +0 -7
- package/browser/cjs/DvioTOgF2jNUKBcT.cjs +0 -7
- package/browser/cjs/DwSf7lami5Uh2Uh6.cjs +0 -7
- package/browser/cjs/Dy6R4NfGavsHaUnQ.cjs +0 -10
- package/browser/cjs/HEI6Q0oyMX2A1gth.cjs +0 -7
- package/browser/cjs/_Lz_D28ElE-H04r8.cjs +0 -7
- package/browser/cjs/hONph4eRHAvmiEYv.cjs +0 -7
- package/browser/cjs/nQYA0VPzyPNFcvaF.cjs +0 -7
- package/browser/cjs/pPrxgr769sUGB5WL.cjs +0 -7
- package/browser/cjs/sqCd-isdKO-WsW_F.cjs +0 -7
- package/browser/cjs/xobXrowL2Qx-kWv9.cjs +0 -7
- package/browser/esm/4lHZjpF3_ugmKKui.mjs +0 -7
- package/browser/esm/67bnWHzYa5DZMY6A.mjs +0 -7
- package/browser/esm/BDYJEEaksgeY1UaE.mjs +0 -7
- package/browser/esm/BG0zhw4ripZzsL-w.mjs +0 -7
- package/browser/esm/BOfILXwwP1BW8Bsw.mjs +0 -7
- package/browser/esm/BPEwv5xX4DLnd-8o.mjs +0 -7
- package/browser/esm/BUeaoQihd7nbjV5D.mjs +0 -7
- package/browser/esm/Bb8asJ4COo3sy4Gt.mjs +0 -7
- package/browser/esm/BbJAEyq0pAF7biF-.mjs +0 -7
- package/browser/esm/BuoPWoEzsXvQsZFU.mjs +0 -7
- package/browser/esm/By_8JXNSh9nnHyBW.mjs +0 -7
- package/browser/esm/C4K5CBXvVExqCdpa.mjs +0 -7
- package/browser/esm/CKUiTXSrn9Xg_ph1.mjs +0 -10
- package/browser/esm/CLP8NgXNjnLl-iMQ.mjs +0 -7
- package/browser/esm/CVGuaXPdnO65bXE5.mjs +0 -7
- package/browser/esm/ClgHaEbC8eHvV73x.mjs +0 -7
- package/browser/esm/CoZh7nD_zQLfTNcp.mjs +0 -7
- package/browser/esm/D2jQMy8XvCDNeRaM.mjs +0 -7
- package/browser/esm/D3D_Ad9RkEvBe7Wz.mjs +0 -7
- package/browser/esm/D5dJ7VFFZvIOU2As.mjs +0 -7
- package/browser/esm/D8vW0N6EH97lDhnP.mjs +0 -7
- package/browser/esm/DB9YIl5l53cTx_qf.mjs +0 -7
- package/browser/esm/DFbUKmUyr8XjG6uR.mjs +0 -7
- package/browser/esm/DROuUTBh0ijsxsde.mjs +0 -7
- package/browser/esm/Dq1V1gMAXsC87zqO.mjs +0 -13
- package/browser/esm/Ds_YxbxItIu7PKA-.mjs +0 -7
- package/browser/esm/Ho-V23ZRWrnAVftS.mjs +0 -7
- package/browser/esm/j21djw_rEjBtpjRd.mjs +0 -7
- package/browser/esm/kXWocze33jAxVJq6.mjs +0 -10
- package/browser/esm/qi0568hNwcdjIMy6.mjs +0 -7
- package/browser/esm/yVExwiZwWE8vLSFO.mjs +0 -7
- package/node/esm/k3luU7uFD82_cpo4.mjs +0 -80
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.4.13
|
|
3
|
-
*
|
|
4
|
-
* (C) 2025-present SheetXL Inc. & Michael T. Ford
|
|
5
|
-
* License: The license can be found at https://www.sheetxl.com/license.
|
|
6
|
-
*/
|
|
7
|
-
"use strict";const t={Number:"n",String:"s",Boolean:"b",Error:"e",RichData:"r",Null:"z"};var e;exports.t=void 0,exports.n=void 0,(e=exports.t||(exports.t={})).Orientation={Column:"column",Row:"row"},e.Orientations={...e.Orientation,Both:"both"},e.Direction={Up:"up",Down:"down",Left:"left",Right:"right"},(t=>{t.Code={Parse:0,Null:1,Div0:2,Value:3,Ref:4,Name:5,Num:6,NA:7,GettingData:8,Spill:9,Connect:10,Blocked:11,Unknown:12,Field:13,Calc:14,Busy:16,Python:19,Timeout:20},t.Label={Parse:"#PARSE!",Null:"#NULL!",Div0:"#DIV/0!",Value:"#VALUE!",Ref:"#REF!",Name:"#NAME?",Num:"#NUM!",NA:"#N/A",GettingData:"#GETTING_DATA",Spill:"#SPILL!",Connect:"#CONNECT!",Blocked:"#BLOCKED!",Unknown:"#UNKNOWN!",Field:"#FIELD!",Calc:"#CALC!",Busy:"#BUSY!",Python:"#PYTHON!",Timeout:"#TIMEOUT!"};class e extends Error{constructor(t,e,r,n){super(r,n),this._label=e,this._code=t,this.details=n}static{this.code=t.Code.Unknown}get isFormulaError(){return!0}getLabel(){return this._label}getCode(){return this._code}equals(t){return!!t&&(this._code===t._code||this._code===t.code)}get[Symbol.toStringTag](){return"[FormulaError]"}toString(){return this.message||this._label}}t.Known=e;class r extends e{constructor(e,r){super(t.Code.Parse,t.Label.Parse,e,r)}static{this.code=t.Code.Parse}getDetails(){const t=this.details;return{line:t?.line??1,column:t?.column??1,offset:t?.offset??0,length:t?.length??0}}}t.Parse=r;class n extends e{constructor(e,r){super(t.Code.Null,t.Label.Null,e,r)}static{this.code=t.Code.Null}}t.Null=n;class o extends e{constructor(e,r){super(t.Code.Div0,t.Label.Div0,e,r)}static{this.code=t.Code.Div0}}t.Div0=o;class s extends e{constructor(e,r){super(t.Code.Value,t.Label.Value,e,r)}static{this.code=t.Code.Value}}t.Value=s;class i extends e{constructor(e,r){super(t.Code.Ref,t.Label.Ref,e,r)}static{this.code=t.Code.Ref}}t.Ref=i;class a extends e{constructor(e,r){super(t.Code.Name,t.Label.Name,e,r)}static{this.code=t.Code.Name}}t.Name=a;class l extends e{constructor(e,r){super(t.Code.Num,t.Label.Num,e,r)}static{this.code=t.Code.Num}}t.Num=l;class c extends e{constructor(e,r){super(t.Code.NA,t.Label.NA,e,r)}static{this.code=t.Code.NA}}t.NA=c;class h extends e{constructor(e,r){super(t.Code.GettingData,t.Label.GettingData,e,r)}static{this.code=t.Code.GettingData}}t.GettingData=h;class d extends e{constructor(e,r){super(t.Code.Spill,t.Label.Spill,e,r)}static{this.code=t.Code.Spill}}t.Spill=d;class u extends e{constructor(e,r){super(t.Code.Connect,t.Label.Connect,e,r)}static{this.code=t.Code.Connect}}t.Connect=u;class g extends e{constructor(e,r){super(t.Code.Blocked,t.Label.Blocked,e,r)}static{this.code=t.Code.Blocked}}t.Blocked=g;class p extends e{constructor(e,r){super(t.Code.Unknown,t.Label.Unknown,e,r)}static{this.code=t.Code.Unknown}}t.Unknown=p;class m extends e{constructor(e,r){super(t.Code.Field,t.Label.Field,e,r)}static{this.code=t.Code.Field}}t.Field=m;class f extends e{constructor(e,r){super(t.Code.Calc,t.Label.Calc,e,r)}static{this.code=t.Code.Calc}}t.Calc=f;class _ extends e{constructor(e,r){super(t.Code.Busy,t.Label.Busy,e,r)}static{this.code=t.Code.Busy}}t.Busy=_;class S extends e{constructor(e,r){super(t.Code.Python,t.Label.Python,e,r)}static{this.code=t.Code.Python}}t.Python=S;class w extends e{constructor(e,r){super(t.Code.Timeout,t.Label.Timeout,e,r)}static{this.code=t.Code.Timeout}}t.Timeout=w})(exports.n||(exports.n={}));const r={};r[exports.n.Code.Parse]=exports.n.Parse,r[exports.n.Code.Null]=exports.n.Null,r[exports.n.Code.Div0]=exports.n.Div0,r[exports.n.Code.Value]=exports.n.Value,r[exports.n.Code.Ref]=exports.n.Ref,r[exports.n.Code.Name]=exports.n.Name,r[exports.n.Code.Num]=exports.n.Num,r[exports.n.Code.NA]=exports.n.NA,r[exports.n.Code.GettingData]=exports.n.GettingData,r[exports.n.Code.Spill]=exports.n.Spill,r[exports.n.Code.Connect]=exports.n.Connect,r[exports.n.Code.Blocked]=exports.n.Blocked,r[exports.n.Code.Unknown]=exports.n.Unknown,r[exports.n.Code.Field]=exports.n.Field,r[exports.n.Code.Calc]=exports.n.Calc,r[exports.n.Code.Busy]=exports.n.Busy,r[exports.n.Code.Python]=exports.n.Python,r[exports.n.Code.Timeout]=exports.n.Timeout;const n=new Map,o=new Map,s=new Map,i=new Map,a=Object.keys(r);for(let t=0;t<a.length;t++){const e=a[t],l=r[e];s.set(exports.n.Label[e],l),i.set(exports.n.Code[e],l);const c=new l;n.set(c.getLabel(),c),o.set(c.getCode(),c)}const l=o.get(exports.n.Code.Unknown);var c;(c=exports.n||(exports.n={})).BuiltIn={Parse:new c.Parse,Null:new c.Null,Div0:new c.Div0,Value:new c.Value,Ref:new c.Ref,Name:new c.Name,Num:new c.Num,NA:new c.NA,GettingData:new c.GettingData,Spill:new c.Spill,Connect:new c.Connect,Blocked:new c.Blocked,Unknown:new c.Unknown,Field:new c.Field,Calc:new c.Calc,Busy:new c.Busy,Python:new c.Python,Timeout:new c.Timeout},c.getBuiltInByLabel=t=>n.get(t),c.newTypedError=(t,e,r)=>{let n;return n="string"==typeof t?s.get(t):i.get(t),n||(n=c.Unknown),new n(e,r)},c.getBuiltInById=t=>o.get(t)||l;let h=class{constructor(t){this._subscribeFn=t}subscribe(t,e,r){const n="object"==typeof t?{next:t.next||(()=>{}),error:t.error||(()=>{}),complete:t.complete||(()=>{}),unsubscribe:()=>{}}:{next:t||(()=>{}),error:e||(()=>{}),complete:r||(()=>{}),unsubscribe:()=>{}},o=this._subscribeFn(n);return n.unsubscribe=()=>{"function"==typeof o&&o()},n}},d=class{getRange(t){throw new u}getReference(t,e){throw new u}getNumberFormat(t,e){return e?.toString()??""}fromOADate(t){return new Date(t)}toOADate(t){return t.getTime()}getValueAt(t,e){return null}getEntireCoords(){return p}isValidDate(t){return(t instanceof Date||"[object Date]"===Object.prototype.toString.call(t))&&!isNaN(t.getTime())}getPosition(){return g}getFormulaAt(t,e){return null}getSpillAt(t,e){return null}getSheetIndex(t){return-1}getSheetCount(){return 1}markVolatile(){}formatResults(t){}getFunction(t){return null}getAddress(t,e){throw new u}parseAsDateTime(t,e){throw new u}getRuntime(){return m}},u=class extends Error{constructor(t="Not implemented in StubbedFormulaContext"){super(t),this.name="NotImplementedError"}};const g=Object.freeze({colIndex:0,rowIndex:0}),p=Object.freeze({colStart:0,rowStart:0,colEnd:Math.pow(2,14)-1,rowEnd:Math.pow(2,20)-1}),m={getCurrencySymbol:()=>"$",getNumberDecimalSeparator:()=>".",getNumberGroupSeparator:()=>",",isDate1904:()=>!1,getLocation:()=>"unknown",getVersion:()=>"1.0.0",getOS:()=>"unknown",getUser:()=>"unidentified",getDescription:()=>"Stubbed Formula Context"},f=new d,_={Up:"up",Down:"down",Left:"left",Right:"right"},S={TopLeft:"tl",Top:"t",TopRight:"tr",Left:"l",Center:"c",Right:"r",BottomLeft:"bl",Bottom:"b",BottomRight:"br"},w={html:"text/html",plain:"text/plain",png:"image/png"},y=Object.freeze({left:0,top:0}),x=Object.freeze({left:0,top:0,bottom:0,right:0}),C=Object.freeze({x:0,y:0,width:0,height:0}),b=Object.freeze(Object.defineProperty({__proto__:null,EmptyBounds:C,EmptyRect:x,EmptyTopLeft:y},Symbol.toStringTag,{value:"Module"})),E={Column:"column",Row:"row"},v={...E,Both:"both"},I=Object.freeze({colIndex:0,rowIndex:0}),A=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),R=(t,e)=>t.colStart===e.colStart?t.rowStart-e.rowStart:t.colStart-e.colStart,M=(t,e)=>t.rowStart===e.rowStart?t.colStart-e.colStart:t.rowStart-e.rowStart,T=(t,e)=>t.rowEnd===e.rowEnd?e.colEnd-t.colEnd:e.rowEnd-t.rowEnd,F=(t,e)=>t.colEnd===e.colEnd?e.rowEnd-t.rowEnd:e.colEnd-t.colEnd,N=(t,e)=>t.colIndex===e.colIndex?t.rowIndex-e.rowIndex:t.colIndex-e.colIndex,k=(t,e)=>t.rowIndex===e.rowIndex?t.colIndex-e.colIndex:t.rowIndex-e.rowIndex,O=(t=E.Row,e=!1)=>e?t!==E.Column?T:F:t!==E.Column?M:R,B=(t,e)=>t===e||!(!t||!e)&&t.rowIndex===e.rowIndex&&t.colIndex===e.colIndex,L=(t,e)=>t===e||!(!t||!e)&&t.rowStart===e.rowStart&&t.rowEnd===e.rowEnd&&t.colStart===e.colStart&&t.colEnd===e.colEnd,D=(t,e)=>!(!t||!e||t.colStart>e.colEnd||e.colStart>t.colEnd||t.rowStart>e.rowEnd||e.rowStart>t.rowEnd),z=(t,e)=>{if(t===e)return!0;if(!t||!e)return!1;if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!L(t[r],e[r]))return!1;return!0},P=(t,e,r)=>{if(!t&&!e)return null;if(!t)return r?e:{...e};if(!e)return r?t:{...t};const n=Math.min(t.colStart,e.colStart),o=Math.min(t.rowStart,e.rowStart),s=Math.max(t.colEnd,e.colEnd),i=Math.max(t.rowEnd,e.rowEnd);let a=r;return a?(a.colStart=n,a.rowStart=o,a.colEnd=s,a.rowEnd=i):a={colStart:n,rowStart:o,colEnd:s,rowEnd:i},a},j=(t,e)=>{if(!e||0===e.length)return t;const r={...t};for(let t=0;t<e.length;t++){const n=e[t];D(r,n)&&(r.rowStart=Math.min(r.rowStart,n.rowStart),r.colStart=Math.min(r.colStart,n.colStart),r.rowEnd=Math.max(r.rowEnd,n.rowEnd),r.colEnd=Math.max(r.colEnd,n.colEnd))}return r},H=[null,null],V=(t,e,r)=>{if(t[0].value===t[1].value)return e};function $(t,e=2,r,n=E.Row,o){let s=[...t];if(e<=0||t.length<=1)return s;let i=n===E.Column,a=0,l=!1;do{const t=s.sort(O(i?E.Row:E.Column));s=[],s.push(t[0]);const e=t.length;let c=0,h=t[0],d=h.colStart,u=h.rowStart,g=h.colEnd,p=h.rowEnd;for(let a=1;a<e;a++){const e=t[a];let m=!1;if(m=i?h&&u===e.rowStart&&p===e.rowEnd&&g+1===e.colStart:h&&d===e.colStart&&g===e.colEnd&&p+1===e.rowStart,m){let t={colStart:d,rowStart:u,colEnd:i?e.colEnd:g,rowEnd:i?p:e.rowEnd};if(void 0!==h.value&&(t.value=h.value),r){const s=o??[null,null];s[0]=h,s[1]=e,t=r(s,t,n)}if(t){s[c]=t,l=!0,h=t,d=h.colStart,u=h.rowStart,g=h.colEnd,p=h.rowEnd;continue}}s[++c]=e,h=e,d=h.colStart,u=h.rowStart,g=h.colEnd,p=h.rowEnd}a++,i=!i,1===a&&(l=!0)}while(a<e&&l&&s.length>1);return s}const U=Object.freeze(Object.defineProperty({__proto__:null,EmptyCell:I,EmptyRange:A,cellToRange:(t,e)=>{if(!t)return null;let r=e;return r||(r={...t},delete r.colIndex,delete r.rowIndex),r.colStart=t.colIndex??0,r.rowStart=t.rowIndex??0,r.colEnd=t.colIndex??0,r.rowEnd=t.rowIndex??0,r},columnFirstCellComparator:N,columnFirstRangeComparator:R,createCellComparator:(t=E.Row,e=!1)=>e?t!==E.Column?(t,e)=>t.rowIndex===e.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:(t,e)=>t.colIndex===e.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex:t!==E.Column?k:N,createConflatingRanges:(t,e=!1)=>{const r=[];let n,o,s=Number.MIN_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER;return{append:(a,l,c)=>{let h=!0;const d=void 0!==c;if(d){const r=t?t(o,c,e):o===c?c:void 0;void 0===r?h=!1:c=r}if(h&&l===i+1&&a===s)return e?n.rowEnd=l:n.colEnd=l,i=l,void(o=c);n&&r.push(n);const u=e?a:l,g=e?l:a;n={colStart:u,rowStart:g,colEnd:u,rowEnd:g},d&&(n.value=c),s=a,i=l,o=c},done:t=>(n&&(r.push(n),n=null),t?$(r,3,!0===t?V:t,e?E.Column:E.Row,H):r)}},createRangeComparator:O,defaultRange:(t,e,r)=>t?r?(r.colStart=t.colStart??e.colStart,r.rowStart=t.rowStart??e.rowStart,r.colEnd=t.colEnd??e.colEnd,r.rowEnd=t.rowEnd??e.rowEnd,r):{colStart:t.colStart??e.colStart,rowStart:t.rowStart??e.rowStart,colEnd:t.colEnd??e.colEnd,rowEnd:t.rowEnd??e.rowEnd}:e,extendRangeToIntersectingRanges:j,extendRangeToUnionRanges:(t,e)=>{if(!e||0===e.length)return t;let r=t,n=null;for(;!L(r,n);)n=r,r=j(n,e);return r},indexOfCoords:(t,e)=>{const r={colStart:t.colIndex,rowStart:t.rowIndex,colEnd:t.colIndex,rowEnd:t.rowIndex};for(let t=e.length-1;t>=0;t--)if(D(r,e[t]))return t;return-1},intersectRanges:(t,e,r)=>{if(!t)return r?e:{...e};if(!e)return r?t:{...t};if(!t&&!e)return null;if(t.rowStart>e.rowEnd||t.rowEnd<e.rowStart||t.colStart>e.colEnd||t.colEnd<e.colStart)return null;const n=Math.max(t.colStart,e.colStart),o=Math.max(t.rowStart,e.rowStart),s=Math.min(t.colEnd,e.colEnd),i=Math.min(t.rowEnd,e.rowEnd);let a=r;return a?(a.colStart=n,a.rowStart=o,a.colEnd=s,a.rowEnd=i):a={colStart:n,rowStart:o,colEnd:s,rowEnd:i},a},isCellWithinRange:(t,e)=>!(!t||!e||t.rowIndex<e.rowStart||t.rowIndex>e.rowEnd||t.colIndex<e.colStart||t.colIndex>e.colEnd),isEqualCells:B,isEqualRanges:L,isEqualRangesArrays:z,isEqualSelectionCoords:(t,e)=>t===e||!(!t||!e)&&t.rangeIndex===e.rangeIndex&&!!B(t.cell,e.cell)&&z(t.ranges,e.ranges),isRangeWithinRange:(t,e)=>!(t.rowStart<e.rowStart||t.rowEnd>e.rowEnd||t.colStart<e.colStart||t.colEnd>e.colEnd),isRangesIntersect:D,isSingleCell:t=>!!t&&t.rowEnd===t.rowStart&&t.colStart===t.colEnd,isValidRange:t=>!(!t||"number"!=typeof t.colStart||t.colStart<0||"number"!=typeof t.colEnd||t.colEnd<t.colStart||"number"!=typeof t.rowStart||t.rowStart<0||"number"!=typeof t.rowEnd||t.rowEnd<t.rowStart),mergeRangedValues:$,rowFirstCellComparator:k,rowFirstRangeComparator:M,sanitizeRange:t=>t?{colStart:t.colIndex??t.colStart??0,rowStart:t.rowIndex??t.rowStart??0,colEnd:t.colIndex??t.colEnd??0,rowEnd:t.rowIndex??t.rowEnd??0}:null,translateRange:(t,e=-t.rowStart,r=-t.colStart,n)=>n?(n.colStart=t.colStart+r,n.rowStart=t.rowStart+e,n.colEnd=t.colEnd+r,n.rowEnd=t.rowEnd+e,n):{colStart:t.colStart+r,rowStart:t.rowStart+e,colEnd:t.colEnd+r,rowEnd:t.rowEnd+e},unionRanges:P,unionRangesArrays:(t,e,r)=>{if(!t||0===t.length)return null;if(1===t.length&&!e)return t[0];let n=t[0];for(let e=1;e<t.length;e++)n=P(n,t[e],r);return e&&(n=P(n,e,r)),n}},Symbol.toStringTag,{value:"Module"}));const G="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function W(t){return function(t){return!!t&&"object"==typeof t}(t)&&!function(t){const e=Object.prototype.toString.call(t);return"[object RegExp]"===e||"[object Date]"===e||function(t){return t.$$typeof===G}(t)}(t)}function q(t,e){return!1!==e.clone&&e.isMergeableObject(t)?Y((r=t,Array.isArray(r)?[]:{}),t,e):t;var r}function J(t,e,r){return t.concat(e).map(function(t){return q(t,r)})}function X(t){return Object.keys(t).concat(function(t){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t).filter(function(e){return Object.propertyIsEnumerable.call(t,e)}):[]}(t))}function K(t,e){try{return e in t}catch(t){return!1}}function Y(t,e,r){(r=r||{}).arrayMerge=r.arrayMerge||J,r.isMergeableObject=r.isMergeableObject||W,r.cloneUnlessOtherwiseSpecified=q;const n=Array.isArray(e);return n===Array.isArray(t)?n?r.arrayMerge(t,e,r):function(t,e,r){const n={};return r.isMergeableObject(t)&&X(t).forEach(function(e){n[e]=q(t[e],r)}),X(e).forEach(function(o){(function(t,e){return K(t,e)&&!(Object.hasOwnProperty.call(t,e)&&Object.propertyIsEnumerable.call(t,e))})(t,o)||(K(t,o)&&r.isMergeableObject(e[o])?n[o]=function(t,e){if(!e.customMerge)return Y;const r=e.customMerge(t);return"function"==typeof r?r:Y}(o,r)(t[o],e[o],r):n[o]=q(e[o],r))}),n}(t,e,r):q(e,r)}Y.all=function(t,e){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce(function(t,r){return Y(t,r,e)},{})};const Z=Object.freeze([]),Q=Object.freeze({}),tt=t=>t,et=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}),rt=(t,e)=>t===e||!(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)&&t.every((t,r)=>t===e[r]),nt=t=>"object"==typeof t&&!Array.isArray(t)&&null!==t,ot=t=>"object"!=typeof t||Array.isArray(t)||null===t?t:(Object.keys(t).forEach(function(e){t[e]&&"object"==typeof t[e]?ot(t[e]):null!==t[e]&&void 0!==t[e]||delete t[e],"object"==typeof t[e]&&0===Object.keys(t[e]).length&&delete t[e]}),0===Object.keys(t).length?null:t),st=(t,e)=>!(t!==e&&!rt(t,e)&&!t.isEqual?.(e)),it=(t,e,r=st)=>{if(null==t||t===e)return null;if(!t||"object"!=typeof t||Array.isArray(t)||t.isImmutable?.())return r(t,e)?null:t;const n=Object.keys(t);if(0===n.length)return null;let o=!1;for(let s=0;s<n.length;s++){const i=n[s];null===it(t[i],e?.[i],r)&&(o=!0,delete t[i])}return o&&0===Object.keys(t).length?null:void 0},at="object"==typeof performance&&"function"==typeof performance.now?()=>performance.now():()=>Date.now(),lt=t=>null==t,ct=(t,e)=>!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top),ht=!("undefined"==typeof window||!window.document||!window.document.createElement),dt={Windows:"windows",MacOS:"macos",IOS:"ios",Linux:"linux",Android:"android",Safari:"safari",Firefox:"firefox",Node:"node",Unknown:"unknown"},ut=()=>{if(gt())return dt.Node;const t=void 0!==globalThis.navigator&&globalThis.navigator.userAgent?globalThis.navigator.userAgent.toLowerCase():"";return t?/(win32|win64|windows|wince)/i.test(t)?dt.Windows:/(macintosh|macintel|macppc|mac68k|macos)/i.test(t)?dt.MacOS:/(iphone|ipad|ipod)/i.test(t)?dt.IOS:/android/.test(t)?dt.Android:/linux/.test(t)?dt.Linux:/^((?!chrome|android|).)*safari/i.test(t)?dt.Safari:/^((?!chrome|android|Seamonkey).)*firefox/i.test(t)?dt.Firefox:dt.Unknown:dt.Unknown};function gt(){return"undefined"!=typeof process&&"node"===process.release?.name||("undefined"!=typeof process&&process.browser,!1)}const pt=(t,e=!1)=>(document.hasFocus()||e)&&(t===document.activeElement||t?.contains(document.activeElement)),mt=Object.freeze(Object.defineProperty({__proto__:null,EmptyArray:Z,EmptyObject:Q,OSType:dt,arrayMove:function(t,e,r){const n=t.slice();return n.splice(r<0?n.length+r:r,0,n.splice(e,1)[0]),n},asNumber:t=>{const e=(t=>1*t)(t);return Number.isFinite(e)?e:0},camelToPrettyCase:t=>1===t.length?t.toUpperCase():t.replace(/([A-Z])/g," $1").replace(/^./,function(t){return t.toUpperCase()}).trim(),canUseDOM:ht,cancelTimeout:t=>{cancelAnimationFrame(t.id)},castToString:t=>null==t||void 0===t?"":"string"!=typeof t?""+t:t,cloneObject:t=>lt(t)?t:JSON.parse(JSON.stringify(t)),consoleWithNoSource:(...t)=>new Promise(e=>{setTimeout(()=>{Function("console.log.apply(console, arguments)").apply(null,t),e()})}),debounce:function(t,e=300,r=!1){let n,o,s,i,a=0;function l(){let c=Date.now()-a;c<e&&c>=0?n=setTimeout(l,e-c):(n=null,r||(i=t.apply(s,o),s=o=null))}null==e&&(e=100);const c=function(){s=globalThis,o=arguments,a=Date.now();var c=r&&!n;return n||(n=setTimeout(l,e)),c&&(i=t.apply(s,o),s=o=null),i};return c.clear=function(){n&&(clearTimeout(n),n=null)},c.flush=function(){n&&(i=t.apply(s,o),s=o=null,clearTimeout(n),n=null)},c},deepEqual:function t(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;let n,o,s;if(Array.isArray(e)){if(n=e.length,n!=r.length)return!1;for(o=n;0!==o--;)if(!t(e[o],r[o]))return!1;return!0}if(e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(o of e.entries())if(!r.has(o[0]))return!1;for(o of e.entries())if(!t(o[1],r.get(o[0])))return!1;return!0}if(e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(o of e.entries())if(!r.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){if(n=e.length,n!=r.length)return!1;for(o=n;0!==o--;)if(e[o]!==r[o])return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if(s=Object.keys(e),n=s.length,n!==Object.keys(r).length)return!1;for(o=n;0!==o--;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=n;0!==o--;){let n=s[o];if(!("_owner"===n&&e.$$typeof||t(e[n],r[n])))return!1}return!0}return e!=e&&r!=r},deepFreeze:function t(e){return Object.freeze(e),Object.keys(e).forEach(r=>{"object"!=typeof e[r]||null===e[r]||Object.isFrozen(e[r])||t(e[r])}),e},deepMerge:Y,diffValues:(t,e)=>{const r={},n=Object.keys(e),o=n.length;for(let s=0;s<o;s++){const o=n[s];t[o]!==e[o]&&(void 0===t[o]?r[o]=e[o]:r[o]=t[o])}return 0===Object.keys(r).length?null:r},findEqualOrGreater:function(t,e,r=tt){let n=0,o=t.length-1;for(;n<=o;){let s=Math.floor((n+o)/2),i=r(t[s]);if(i===e)return s;i<e?n=s+1:o=s-1}return n},findEqualOrLesser:function(t,e,r=tt){let n=t.length-1,o=0;for(;n>=o;){let s=Math.floor((n+o)/2),i=r(t[s]);if(i===e)return s;i>e?n=s-1:o=s+1}return n},findNextStep:(t,e=!0,r=15,n=10,o=400)=>{const s=Math.max(t-n,0)+(e?1:-1);return Math.min(o,Math[e?"ceil":"floor"](s/r)*r+n)},getDPI:()=>{let t=1;return"object"==typeof window&&(t=window.devicePixelRatio||1),t},getFromPath:(t,e)=>{const r=e.split(".");let n=t;for(let t=0;t<r.length;t++){const e=r[t];if(!n)return null;let o=n[e];if("function"==typeof o&&(o=o.bind(n)()),!o||!nt(o))return o;n=o}return n??null},getOS:ut,hasFocus:pt,isDefined:t=>!(null==t),isEmpty:t=>null==t||""===t,isEqualArrays:rt,isEqualBounds:(t,e)=>t===e||!(t&&!e||e&&!t)&&t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height,isEqualObjectKeys:(t,e)=>{if(t===e)return!0;if(t&&!e||e&&!t)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let n=0;n<r.length;n++)if(t[r[n]]!==e[r[n]])return!1;return!0},isNode:gt,isNullOrUndefined:lt,isNumeric:t=>{const e=1*t;return Number.isFinite(e)&&"number"==typeof e},isObject:nt,isPromiseLike:t=>!!t&&"function"==typeof t.then,isRectInsideRect:(t,e)=>t.top>=e.top&&t.bottom<=e.bottom&&t.left>=e.left&&t.right<=e.right,isRectIntersect:ct,mergeContentful:(...t)=>{const e=t.length;if(e>0&&void 0!==t[e-1]&&!nt(t[e-1]))return t[e-1];let r=t[0]||{};for(let n=1;n<e;n++)r=Y(r,t[n]||{},{arrayMerge:(t,e)=>[...e]});return r},nextTick:t=>{"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(()=>{t()}):("function"==typeof setImmediate?setImmediate:setTimeout)(()=>{t()})},openFileDialog:(t="*.*")=>new Promise((e,r)=>{if(!ht)return void r("Unable to open dialog with no dom.");const n=document.createElement("input");n.type="file",n.accept=t;let o=null,s=!1;globalThis.addEventListener?.("focus",()=>{setTimeout(()=>{o||s||(s=!0,e(null))},1e3)},{once:!0,passive:!0}),n.onchange=()=>{if(o=n.files[0],o){if(s)return void console.warn("File open detected after faux cancel.",o);e(o)}},n.autofocus=!0,n.click()}),rafThrottle:t=>{let e,r=!1,n=function(){r=!1,t(e)};return function(t){e=t,e&&e.persist&&e.persist(),r||(r=!0,requestAnimationFrame(n))}},removeEmptyProperties:ot,removeEqualValues:it,removeListenerAll:t=>{if(!t)return[];for(let e=0;e<t.length;e++)t[e]&&t[e]();return[]},requestTimeout:(t,e)=>{const r=at(),n={id:requestAnimationFrame(function o(){at()-r>=e?t.call(null):n.id=requestAnimationFrame(o)})};return n},roundAccurately:(t,e=0)=>{if(null==t||!isFinite(t))return null;const r=10**e;return Number(Math.round(t*r)/r)},setToPath:(t,e,r)=>{const n=e.split(".");let o=t;if(!o)throw new Error("Can not set path to a null path.");for(let t=0;o&&t<n.length-1;t++){const e=n[t];let r=o[e];if(null==r&&(r={},o[e]=r),!nt(r))throw new Error("Can not set path to a non object path.");o=r}if("number"!=typeof r&&"boolean"!=typeof r&&"string"!=typeof r&&!nt(r))throw new Error(`Can not set path to ${r} that is not a a supported primitive.`);return o[n[n.length-1]]=r,t},splitNumber:t=>{let e=Math.abs(t);if(isNaN(e)||!isFinite(t))return null;let r=0|e,n=e-r,o=0,s=0,i=1;if(n>5e-8)for(;s<8&&Math.abs(o/i-n)>5e-8;)s++,i*=10,o=Math.round(n*i);return{ip:Math.trunc(t),fp:o,ipLength:Math.ceil(Math.log10(r+1)),fpLength:s}},subtractRect:(t,e,r=!1)=>{if(!e)return[t];if(!ct(t,e))return[];const n=[];let o=t;const s=()=>{e.top>o.top&&e.top<o.bottom&&(n.push({...o,bottom:e.top}),o={...o,top:e.top})},i=()=>{e.bottom>o.top&&e.bottom<o.bottom&&(n.push({...o,top:e.bottom}),o={...o,bottom:e.bottom})},a=()=>{e.right>o.left&&e.right<o.right&&(n.push({...o,left:e.right}),o={...o,right:e.right})},l=()=>{e.left>o.left&&e.left<o.right&&(n.push({...o,right:e.left}),o={...o,left:e.left})};return r?(l(),a(),s(),i()):(s(),i(),a(),l()),n},textToKey:t=>t.replace(/[^a-zA-Z0-9]/g,"").toLowerCase(),throttle:function(t,e){let r=null;return(...n)=>{const o=Date.now();(!r||o-r>=e)&&(r=o,t(...n))}},toSafeJSON:function t(e){if(null===e||"object"!=typeof e)return e;if("function"==typeof e.toJSON)return e.toJSON();if(Array.isArray(e))return e.map(e=>t(e));if("function"==typeof e.toString&&e.toString!==Object.prototype.toString)return e.toString();const r={};for(const n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r},transpose:t=>{if(!t)return t;const e=t.length,r=t[0].length,n=[];for(let t=0;t<r;t++)n[t]=Array(e);for(let o=0;o<e;o++)for(let e=0;e<r;e++)n[e][o]=t[o][e];return n},uuidV4:et,validEnumValue:(t,e)=>{if(!Object.values(t).includes(e))throw new Error(`Invalid type: ${e??"null"}. Must be one of: ${Object.values(e).join(", ")}.`)},whenFocus:async(t,e=!1)=>new Promise(r=>{pt(t,e)?r(!0):t.addEventListener("focusin",()=>{r(!0)},{once:!0}),t.focus()})},Symbol.toStringTag,{value:"Module"})),ft=Object.freeze(Object.defineProperty({__proto__:null,MESSAGE_ERROR_INVALID_ARG:t=>`Invalid argument: '${t}'.`},Symbol.toStringTag,{value:"Module"})),_t=t=>{const e=new Uint8Array(t),r=e.byteLength;let n="";for(let t=0;t<r;t++)n+=String.fromCharCode(e[t]);if("undefined"!=typeof window&&"function"==typeof globalThis.btoa)return globalThis.btoa(n);if("undefined"!=typeof Buffer)return Buffer.from(n,"binary").toString("base64");throw new Error("Unsupported environment")},St=t=>new Promise((e,r)=>{if(t)if("undefined"!=typeof FileReader){const n=new FileReader;n.onload=()=>{e(n.result)},n.onerror=()=>{r(n.error)},n.readAsText(t)}else if("undefined"!=typeof Buffer){const n=t=>Buffer.from(t).toString("utf-8");t.arrayBuffer().then(t=>{e(n(t))}).catch(t=>{r(t)})}else r(new Error("Unsupported environment"));else e("")}),wt=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_MIME_TYPE:"*/*",arrayBufferToBase64:_t,base64ToArrayBuffer:t=>{const e="undefined"!=typeof window&&"function"==typeof globalThis.atob?globalThis.atob(t):Buffer.from(t,"base64").toString("binary"),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);return n.buffer},blobToString:St},Symbol.toStringTag,{value:"Module"})),yt="data:image/png;base64,",xt="Unable to resolve image.",Ct=t=>new Promise(async(e,r)=>{let n=null;try{n=new Image,n.src=t,n.addEventListener("load",function(){e({width:n.naturalWidth,height:n.naturalHeight})},{once:!0}),n.addEventListener("error",function(){URL.revokeObjectURL(t),r("Invalid Image")},{once:!0}),await n.decode("sync")}catch(t){n?.src&&URL.revokeObjectURL(n.src)}n||r(xt)}),bt="image/svg+xml",Et=Object.freeze(Object.defineProperty({__proto__:null,DATA_URL_PNG_PREFIX:yt,getImageDataUrl:(t,e=1)=>new Promise(async(r,n)=>{let o=null;try{o=new Image,o.src=t,o.addEventListener("load",function(){try{const t=document.createElement("canvas");t.width=o.naturalWidth,t.height=o.naturalHeight,t.getContext("2d").drawImage(o,0,0);const n=t.toDataURL("image/png",e);r({elemImg:o,dataUrl:n})}catch(e){URL.revokeObjectURL(t),n(e)}},{once:!0}),o.addEventListener("error",function(){URL.revokeObjectURL(t),n("Invalid Image")},{once:!0}),await o.decode("sync")}catch(t){o?.src&&URL.revokeObjectURL(o.src)}o||n(xt)}),loadImageDetails:async(t,e=null)=>{let r=null;const n=async()=>{try{const n=e??"image/*",o=URL.createObjectURL(new Blob([t],{type:n})),s=await Ct(o);r={mimeType:n,naturalDimensions:s,asUrl:o}}catch(t){}},o=async()=>{try{const n=(new TextDecoder).decode(t),o=URL.createObjectURL(new Blob([n],{type:bt})),s=await Ct(o);r={mimeType:e??bt,naturalDimensions:s,asUrl:o,asSVGText:n}}catch(t){}};if(e===bt?await o():e.startsWith("image/")?await n():(await n(),r||await o()),!r)throw new Error("Failed to load image");return r}},Symbol.toStringTag,{value:"Module"}));function vt(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});let r="boolean"==typeof e.cycles&&e.cycles;const n=e.cmp&&function(t){return function(e){return function(r,n){const o={key:r,value:e[r]},s={key:n,value:e[n]};return t(o,s)}}}(e.cmp);let o=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0===e)return;if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);let s;if(Array.isArray(e)){s="[";for(let r=0;r<e.length;r++)r&&(s+=","),s+=t(e[r])||"null";return s+"]"}if(null===e)return"null";if(-1!==o.indexOf(e)){if(r)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const i=o.push(e)-1,a=Object.keys(e).sort(n&&n(e));s="";for(let r=0;r<a.length;r++){const n=a[r],o=t(e[n]);o&&(s&&(s+=","),s+=JSON.stringify(n)+":"+o)}return o.splice(i,1),"{"+s+"}"}(t)}var It;exports.ft=void 0,(It=exports.ft||(exports.ft={})).resolveTypedUpdates=(t,e,r,n)=>{if(null===t)return t;if(void 0===t)return n;let o=t;if(e?.shorthand){const n=e?.shorthand(t,r);void 0!==n&&(o=n)}if(null!==o&&e?.getSubType){const t=e.getSubType(o);t&&(e=t)}const s=e?.properties,i=e?.arrayType??!1;let a=o;if(e&&e.merge&&a&&n)a=e.merge(a,n,r);else if(i);else if(s){const t=Object.keys({...o,...n});a=null;for(let e=0;e<t.length;e++){const i=t[e];let l,c=o[i];if(void 0!==c){const t=s[i];l=t?(0,It.resolveTypedUpdates)(c,t,r,n?.[i]):c}else l=n?.[i];null!=l&&(a=a??{},a[i]=l)}}return a};class At extends Error{constructor(t,e=null){super(t,e),this.name="ChainedError",this._cause=e}get cause(){return this._cause}}class Rt extends At{constructor(t="Partial Error",e=null){super(t,e)}}class Mt extends Rt{constructor(t="Out of bounds",e=null){super(t,e),this.name="OutOfBoundsError"}}class Tt extends At{constructor(t="Partial Error",e=null){super(t,e)}}class Ft extends At{constructor(t="Null not supported",e=null){super(t,e)}}class Nt extends Error{constructor(t="Null not supported",e){super(t),this._type=e}get type(){return this._type}}class kt extends At{constructor(t="Not implemented",e=null){super(t,e)}}const Ot="The Safari browser does not support advanced copy and paste.\nCopy and paste will be limited to within the browser tab.\n\nPlease use Chrome or Edge if external copy and paste is required.",Bt="You do not have permissions to access the clipboard.\nAll copy and paste operations will be limited to the browser tab.",Lt={Safari:"The Safari browser does not support advanced copy and paste.\nCopy and paste will be limited to within the browser tab.\n\nPlease use Chrome or Edge if external copy and paste is required.",Perms:Bt,PermsWrite:ut()===dt.Safari?Ot:Bt,PermsRead:ut()===dt.Safari?Ot:Bt},Dt=async()=>new Promise(t=>{document.hasFocus()?t():globalThis.addEventListener?.("focus",()=>{t()},{once:!0}),document.activeElement.focus?.()}),zt=async(t,e,r)=>{if(ut()===dt.Safari)return await r(new Error(Lt.Safari));try{const n=async t=>{try{return await t()}catch(t){if(t.message?.includes("Document is not focused"))return!1;throw t}},o=await(globalThis?.navigator?.permissions?.query({name:t,allowWithoutGesture:!0,allowWithoutSanitization:!0}));let s=!1;if("prompt"===o.state&&(s=await n(e)),s||"granted"!==o.state||(s=await e()),!s)return await r(new Error(o.state))}catch(t){if("No valid data on clipboard"===t.message||"DataError"===t.name)return;return await r(t)}},Pt=async t=>{try{return await t.read({unsanitized:[w.html]})}catch(t){}return await t.read()},jt=async(t,e)=>{if(!t)return null;const r=await Pt(t);let n=!1;for(let t=0;!n&&r&&t<r.length;t++)if(n=r[t].types.includes(e),n)return await r[t].getType(e);return n?void 0:null};if(!globalThis.ClipboardItem){const t=(t,e)=>new Blob([e],{type:t});class e{constructor(e,r){this._items={},this._types=Object.keys(e);const n={},o=Object.keys(e);for(let r=0;r<o.length;r++){const s=o[r];let i=e[s];n[s]="string"==typeof i?t(s,i):i}this._items=n,this._presentationStyle=r?.presentationStyle??"unspecified"}get types(){return this._types}getType(t){return Promise.resolve(this._items[t])}supports(t){return!0}}globalThis.ClipboardItem=e}const Ht=async(t,e=w.html)=>new Promise(async(r,n)=>{try{const n=await jt(t,e);if(n){const t=new FileReader;t.onload=()=>{r(t.result)},t.onerror=()=>{r("")},t.readAsText(n)}else r("")}catch(t){n(t)}}),Vt=async(t,e=w.html)=>{const r=await Ht(t,e);if(!r)return null;let n=null;try{n=(new DOMParser).parseFromString(r,w.html)}catch(t){console.warn("Can't parse html from clipboard.")}return n},$t=async t=>{t&&await t.writeText("")},Ut={readBlobFromClipboard:jt,readStringFromClipboard:Ht,readHTMLFromClipboard:Vt,clearClipboard:$t},Gt="clipboard-uuid",Wt="web text/uuid",qt=t=>`<div style="display:none" ${Gt}="${t}"/>`,Jt=(t,e)=>{let r=null;try{const n=(new DOMParser).parseFromString(e,w.html);n.body.firstElementChild.setAttribute(Gt,t),r=n.getElementsByTagName("body")[0].innerHTML}catch(t){console.warn("Can't embed uuid.",t)}return r},Xt=(t,e)=>{if(!e||!t)return!1;try{const r=e.querySelectorAll(`[${Gt}="${t}"]`);if(r&&1===r.length)return!0;if(e.querySelector("parsererror"))throw new Error("We are unable to parse node");return!1}catch(t){return!1}};class Kt{constructor(t){if(void 0===t?.nativeClipboard||!0===t?.nativeClipboard)try{this._nativeClipboard=globalThis?.navigator.clipboard}catch(e){!0===t?.nativeClipboard&&console.warn("NativeClipboard option set to true but no native clipboard available.")}else this._nativeClipboard=!1===t?.nativeClipboard?null:t?.nativeClipboard;this._disableCheckOnFocus=t?.disableCheckOnFocus??!1,this._init()}async _checkForChanges(){this._nativeClipboard&&this._state&&!this._disableCheckOnFocus&&await zt("clipboard-read",async()=>{await Dt();const t=await Ht(this._nativeClipboard,Wt);if(!this._state)return!0;if(t&&t===this._state.uuid)return!0;const e=await Vt(this._nativeClipboard,w.html);return!this._state||(Xt(this._state.uuid,e)||this.clear(),!0)},async t=>{"denied"===t?.message||t.message?.includes("Document is not focused")||ut()===dt.Safari||console.warn("Unable to detect clipboard changes: ",t)})}_init(){const t=this;this._listeners=new Map,this._listenersCapture=new Map,this._state=null,this._nativeClipboard&&(this._onFocus=()=>{t._checkForChanges()},this._onBlur=()=>{globalThis.addEventListener?.("focus",t._onFocus,{once:!0})},globalThis.addEventListener?.("blur",this._onBlur),this._nativeClipboard.addEventListener("clipboardchange",e=>{t._checkForChanges()}))}async read(){if(!this._nativeClipboard)return this._state?.items??null;const t=this;return await zt("clipboard-read",async()=>{if(await Dt(),this._state?.uuid){const e=await Ht(this._nativeClipboard,Wt);if(e&&e===t._state.uuid)return!0;const r=await Vt(this._nativeClipboard,w.html);if(Xt(t._state?.uuid,r))return!0}return t._state={items:await Pt(this._nativeClipboard),uuid:null,ref:null},this.dispatchEvent(new Event("clipboardread")),!0},async t=>{this.dispatchEvent(new Event("clipboarderrorread"))}),this._state?.items??[]}async write(t){return this._write({uuid:et(),items:t,ref:null})}async _write(t){if(!this._nativeClipboard)return this._state=t,this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")),null;const e=this,r=[],n=t.uuid;let o=t.items??[];const s=()=>{e._state={uuid:n,ref:t.ref,items:r},e.dispatchEvent(new Event("clipboardwrite")),e.dispatchEvent(new Event("clipboardchange"))};await zt("clipboard-write",async()=>{await Dt(),n&&0===o.length&&(o.push(new ClipboardItem({[Wt]:new Blob([n],{type:Wt})})),o.push(new ClipboardItem({[w.html]:new Blob([qt(n)],{type:w.html})})));for(let t=0;t<Math.min(1,o.length);t++){const e=o[t];let s=e.types.indexOf(w.html),i=null;if(-1!==s){const t=await e.getType(w.html);i=await St(t),i&&(i=Jt(n,i))}if(!i&&e.types.includes(w.plain)){const t=await e.getType(w.plain);if(t){let e=null;"string"==typeof t?(console.warn("text as string",t),e=t):e=await St(t),e&&(i=`<div ${Gt}="${n}">${e}</div>`)}}if(!i&&e.types.includes(w.png)){const t=await e.getType(w.png),r=_t(await t.arrayBuffer());i=`<div ${Gt}="${n}"><img src="${yt+r}"/></div>`}!i&&n&&(i=qt(n));const a=new Blob([i??""],{type:w.html}),l={};for(let t=0;t<e.types.length;t++){const r=e.types[t];l[r]=t===s?a:e.getType(r)}i&&-1===s&&(l[w.html]=a),n&&(l[Wt]=new Blob([n],{type:Wt})),r.push(new ClipboardItem(l))}try{r&&0!==r.length?await this._nativeClipboard.write(r):await $t(this._nativeClipboard)}catch(t){t.message?.includes("Document is not focused")||console.warn("Unable to write to native clipboard: ",t)}return s(),!0},async t=>{this.dispatchEvent(new Event("clipboarderrorwrite")),s()})}async writeReference(t){if(!t)return void this.clear();let e=null;const r={};try{const e=await(t.toText?.())??null;e&&(r[w.plain]=new Blob([e??""],{type:w.plain}))}catch(t){e=t}try{const e=await(t.toHtml?.())??null;e&&(r[w.html]=new Blob([e],{type:w.html}))}catch(t){e=t,console.warn("export to html",t)}try{const e=await(t.toImage?.())??null;e&&(r[w.png]=e)}catch(t){e=t,console.warn("export to png",t)}const n=this._write({uuid:et(),ref:t,items:Object.keys(r).length>0?[new ClipboardItem(r)]:null});if(e)throw e;return n}clear(t=!1){this._state&&(this._state=null,t&&this._write({uuid:null,ref:null,items:null}),this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")))}async readReference(){return await this.read(),this._state?.ref??null}readText(){return new Promise(async(t,e)=>{const r=await this.read();let n=null;for(let t=0;!n&&r&&t<r.length;t++)r[t].types.includes(w.plain)&&(n=await r[t].getType(w.plain));if(!n)return void t("");const o=new FileReader;o.onload=()=>{t(o.result)},o.readAsText(n),o.onerror=t=>{e(t)}})}async writeText(t){const e=[new ClipboardItem({[w.plain]:new Blob([t],{type:w.plain})})];return this._write({uuid:et(),items:e,ref:null})}addEventListener(t,e,r={}){const n=r?.capture?this._listenersCapture:this._listeners;let o=n.get(t);o||(o=new Map,n.set(t,o)),o.set(e,"boolean"==typeof r?{}:r)}dispatchEvent(t){if(!t)return;const e=e=>{const r=e.get(t.type);r&&r.forEach((e,n)=>{try{"function"==typeof n?n(t):n.handleEvent&&n.handleEvent(t),e.once&&r.delete(n)}catch(t){console.warn(t)}})};return e(this._listenersCapture),e(this._listeners),!0}removeEventListener(t,e,r){const n=r?.capture?this._listenersCapture:this._listeners,o=n.get(t);o&&(o.delete(e),0===o.size&&n.delete(t))}close(){globalThis.removeEventListener?.("focus",this._onFocus),globalThis.removeEventListener?.("blur",this._onBlur)}}var Yt;(Yt=Kt||(Kt={})).ErrorMessages=Lt,Yt.Global=new Yt;class Zt{constructor(t=100){this._maxStack=t,this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._listeners=new Set}get maxStack(){return this._maxStack}undo(t=1){if(0===this._undoStack.length)return;let e=!1;try{for(let r=0;r<t&&this._undoStack.length>0;r++){const t=this._undoStack[this._undoStack.length-1];t.redo=t.undo(),this._undoStack.pop(),"function"==typeof t.redo?this._redoStack.push(t):this._redoStack=[],e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}redo(t=1){if(0===this._redoStack.length)return void(null!==this._repeatOperation&&this._repeatOperation.repeat());let e=!1;try{for(let r=0;r<t&&this._redoStack.length>0;r++){const t=this._redoStack[this._redoStack.length-1];t.redo(),this._redoStack.pop(),this._undoStack.push(t),e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}hasUndo(){return this._undoStack.length>0}getTopUndoDescription(){return 0===this._undoStack.length?null:this._undoStack[this._undoStack.length-1].description}hasRedo(){return this._redoStack.length>0||null!==this._repeatOperation}getTopRedoDescription(){return null!==this._repeatOperation?this._repeatOperation.description:0===this._redoStack.length?null:this._redoStack[this._redoStack.length-1].description}getUndoDescriptions(){if(this._undoDescriptions)return this._undoDescriptions;const t=[];for(let e=this._undoStack.length-1;e>=0;e--)t.push(this._undoStack[e].description);return this._undoDescriptions=t,this._undoDescriptions}getRedoDescriptions(){if(this._redoDescriptions)return this._redoDescriptions;const t=[];for(let e=this._redoStack.length-1;e>=0;e--)t.push(this._redoStack[e].description);return 0===t.length&&null!==this._repeatOperation&&t.push(this._repeatOperation.description),this._redoDescriptions=Object.freeze(t),this._redoDescriptions}addUndoOperation(t){const e={description:t.description,undo:t.undo,redo:null};this._undoStack.push(e),this._redoStack=[],this._undoStack.length>this._maxStack&&this._undoStack.shift(),this._notifyOnStackChange()}setRepeatableOperation(t){this._repeatOperation=t??null,this._redoStack=[],this._notifyOnStackChange()}clear(t=!0){this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._undoDescriptions=null,this._redoDescriptions=null,t&&this._notifyOnStackChange()}addListener(t){const e=this._listeners;return e.add(t),()=>{e.delete(t)}}_notifyOnStackChange(){this._undoDescriptions=null,this._redoDescriptions=null,this._listeners.forEach(t=>{t.onStackChange?.()})}}const Qt=(t,e)=>{const r=new Map;return t.forEach((t,n)=>{e.get(n)!==t&&r.set(n,t)}),r};let te=!1;class ee{constructor(t){this._record=t}getId(){return this._record.id}getDescription(){return this._record.description}getMeta(){return Object.freeze(this._record.meta)}getAuthor(){return this._record.author}getTimestamp(){return this._record.timestamp}getOperation(){return this._record.operation}}class re{constructor(t){this._listeners=new Set,this._listenersState=new Map,this._commits=new Map,this._locked=!1,this._current=null,this._pending=null,this._isSync=t?.sync??te,this._isTransient=t?.transient??!1,this._author=t?.author;const e={id:"0",description:"initial",meta:{},author:this._author,timestamp:Date.now(),states:new Map,version:0,previousId:null},r={record:e,commit:new ee(e)};this._current=r,this._cacheModel=null,this._cacheState=null,this._states=e.states,this._transactionStack=[],this._transactionOpen=!1;const n=new Map;n.set(e.id,r),this._commits=n}static{this.setDefaultSync=t=>{te=t}}getLog(t,e=100){const r=[];let n=t;do{const t=this._commits.get(n);if(!t)throw new Error(`Invalid commit id: '${n}'`);if(r.push(t.commit),n=t.record.previousId,!n)return r}while(r.length<e)}getCommitCount(){return this._commits.size}isOpenTransaction(){return this._transactionStack.length>0||this._transactionOpen}getPendingView(){const t=this._transactionStack;return t.length>0?t[0].getView():null}getState(t){const e=this._transactionStack;if(0===e.length){if(this._cacheModel===t)return this._cacheState;const e=this._states.get(t);return this._cacheModel=t,this._cacheState=e,e}return e[e.length-1].getState(t)}getCurrentCommit(){return this._pending?.commit??this._current.commit}restore(t,e){const r=this._getCommitContainer(t,e);if(this._current.commit.getId()===r.commit.getId())return r.commit;let n;e?.viewId&&"custom"!==e?.viewId||(n=r.record.viewAfter);const o=Qt(r.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,o,n,!0,!1),this._current=r,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",r,o,n,!1,!0,!0),this._notify("onCommitChange",r.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",r,r.record.states,n,!1,!0)}finally{this._transactionOpen=!1}return r.commit}revert(t,e){const r=this._getCommitContainer(t,e),n=this._commits.get(r.record.previousId);if(!n)throw new Error(`Invalid commit id: '${r.record.previousId}'`);let o;e?.viewId&&" custom"!==e?.viewId||(o=r.record.viewBefore??r.record.viewAfter);const s=Qt(n.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,s,o,!0,!1),this._current=n,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",n,s,o,!0,!1,!0),this._notify("onCommitChange",n.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",n,n.record.states,o,!0,!0)}finally{this._transactionOpen=!1}return n.commit}_getCommitContainer(t,e){const r=this._commits.get(t);if(!r)throw new Error(`Invalid commit id: '${t}'`);if(this._isTransient)throw new Error("Cannot revert transient store");if(e?.force&&this._transactionStack.length>0&&this._transactionStack[0].rollback(),0!==this._transactionStack.length)throw new Error("Open transactions.");return r}_pruneForwards(t){}beginCommit(t,e){const r=this._transactionStack,n=r.length;if(this._locked)throw console.warn("TransactionStore locked",r),new Error(`TransactionStore is locked by '${r[n-1].getDescription()}`);const o=t?.preventFurtherTransactions,s=this,i=(t,r,i)=>{const a=s._transactionStack;n!==a.length-1&&console.warn("Transaction stack out of sync",n,a.length,a),o&&(this._locked=!1),a.pop(),e?.(t,r,i),0===a.length&&(s._pending=null)};let a;if(0===r.length){const e=this._current.record,r={states:new Map,id:mt.uuidV4(),description:"string"==typeof t?t:t?.description??null,meta:{},timestamp:Date.now(),author:null,version:e.version+1,previousId:e.id,viewBefore:null,viewAfter:{},operation:t?.operation},n={record:r,commit:new ee(r)};this._pending=n,this._notify("onCommitStart",n.commit),a=new oe(this,n,e?.states,t,i)}else{a=r[r.length-1].beginTransaction(t,i)}return o&&(this._locked=!0),this._transactionStack.push(a),a}doBatch(t,e,r){let n;const o=this.beginCommit(e,r),s=this.getCurrentCommit();try{n=t?.(s);const r=()=>{o.commit(e)};if(!!n&&"function"==typeof n.then)return new Promise((t,e)=>{n.then(n=>{try{r(),t(n)}catch(t){e(t)}}).catch(t=>{o.rollback(),e(t)})});r()}catch(t){throw o.rollback(),t}return n}remove(t){return!!t}addListener(t){const e=this._listeners;return e.add(t),()=>{e.delete(t)}}addStateListener(t,e){if(!t)throw new Error("Model is required");if(!e)throw new Error("Listener is required");let r=this._listenersState.get(t);r||(r=new Set,this._listenersState.set(t,r));return r.add(e),()=>{r.delete(e),0===r.size&&this._listenersState.delete(t)}}dispatchEvents(t,e=!1){!e||this._isSync?t():setTimeout(t,0)}_commitRecord(t,e,r){let n=t.record,o=t.commit;if(!this._isTransient){if(r){const e=this._commits.get(n.previousId);if(e){n.previousId=e.record.id;const r=e.record,s=r.states;if(s){n.states.forEach((t,e)=>{s.set(e,t)})}r.viewAfter={...r.viewAfter,...n.viewAfter},r.meta={...r.meta,...n.meta},r.timestamp=n.timestamp,n=r,o=e.commit,t={record:n,commit:o}}}this._commits.set(n.id,t)}this._current=t,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,r||this._notify("onCommitChange",o),this._notifyStates("onAfterStateChange",t,e,t.record.viewAfter,!1,!1,!0),r||this._notify("onCommitEnd",o,!0)}_notifyStates(t,e,r,n,o=!1,s=!1,i=!1){const a=e.commit,l=this._listenersState;r.forEach((e,r)=>{const c=l.get(r);c&&this.dispatchEvents(()=>{c.forEach(r=>{r[t]?.(e,n,a,o,s)})},i)})}_notify(t,e,r=!1){this.dispatchEvents(()=>{this._listeners.forEach(r=>{r[t]?.(e)})},r)}}class ne{constructor(t,e){this._children=new Set,this._depth=0,this._container=null,this._closed=!1,this._container=t,e="string"==typeof e?{description:e}:e,this._description=e?.description??"",void 0!==e?.viewBefore&&(t.record.viewBefore=t.record.viewBefore&&e.viewBefore?{...t.record.viewBefore,...e.viewBefore}:e.viewBefore),void 0!==e?.viewAfter&&(t.record.viewAfter=t.record.viewAfter&&e.viewAfter?{...t.record.viewAfter,...e.viewAfter}:e.viewAfter)}getView(){return this._container.record.viewAfter??this._container.record.viewBefore}getDepth(){return this._depth}getDescription(){return this._description}getStates(){return this._states}beginTransaction(t,e){this._ensureOpen();const r=new se(this,this._container,"string"==typeof t?{description:t}:t,e);return this._children||this._children,this._children.add(r),r}updateState(t,e){this._ensureOpen();const r=this.getState(t),n="function"==typeof e?e(r):void 0===e?r:{...r,...e};if(n){let e=this._states;e||(e=new Map,this._states=e),e.set(t,n)}return n}commit(t){if(this._ensureOpen(),"string"==typeof t&&(t={description:t}),t){if(t.description&&(this._description=t.description),t.meta&&(this._meta=mt.mergeContentful(t.meta,this._meta)),void 0!==t.viewAfter){const e=this._container.record;let r=t.viewAfter;if(null===r)e.viewAfter=null;else{const t=e.viewAfter;"function"==typeof r&&(r=r(t)),e.viewAfter={...t,...r}}}if(void 0!==t.viewBefore){const e=this._container.record;let r=t.viewBefore;if(null===r)e.viewAfter=null;else{const t=e.viewBefore;"function"==typeof r&&(r=r(t)),e.viewBefore={...t,...r}}}}return this._children&&this._children.forEach(e=>{e.commit(t)}),this}isClose(){return this._closed}_ensureOpen(){if(this._closed)throw this._descriptions&&console.warn(`stack: [${this._descriptions.join(",")}]`),new Error("Transaction already closed")}_removeChild(t){this._children.delete(t),this._mergeStates(t._states)}_mergeStates(t){if(!t||0===t.size)return;let e=this._states;return e?(t.forEach((t,r)=>{const n=this.updateState(r,t);e.set(r,n)}),e):(this._states=t,t)}}class oe extends ne{constructor(t,e,r,n,o){super(e,n),this._store=t,this._prevStates=r,this._onClose=o,this._states=new Map,this._meta=e.record.meta}getId(){return this._container.commit.getId()}getParent(){return this}commit(t){const e=this._states,r=this._container,n=r.record.viewAfter;this._store._notifyStates("onBeforeCommitStart",r,e,n,!1,!1),super.commit(t),this._store._notifyStates("onBeforeCommitEnd",r,e,n,!1,!1);const o=new Map(this._prevStates);return this._states.forEach((t,e)=>{null===t?o.delete(e):o.set(e,t)}),this._states=o,this._description&&(r.record.description=this._description),this._meta&&(r.record.meta=this._meta),r.record.states=o,this._closed=!0,this._onClose?.(this,!1,t),this._store._commitRecord(r,e,t?.forceAmend??!1),this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(t=>{t.rollback()}),this._closed=!0,this._onClose?.(this,!0,null),this}updateState(t,e){const r=super.updateState(t,e);return this._states.set(t,r),r}getState(t){let e=this._states.get(t);return e||(e=this._prevStates.get(t)),e}_mergeStates(t){if(!t||0===t.size)return new Map;return super._mergeStates(t)}}class se extends ne{constructor(t,e,r,n){if(super(e,r),!t)throw new Error("Parent transaction required");this._parent=t,this._depth=this._parent.getDepth()+1,this._onClose=n}getId(){return this._parent.getId()}getParent(){return this._parent}getState(t){const e=this._states?this._states.get(t):void 0;if(void 0!==e)return e;return this._parent.getState(t)}commit(t){return super.commit(t),this._parent._removeChild(this),this._closed=!0,this._onClose?.(this,!1,t),this._parent??this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(t=>{t.rollback()}),this._parent._removeChild(this),this._closed=!0,this._onClose?.(this,!0,null),this._parent??this}}const ie=()=>{try{return"0.4.13"}catch(t){return""}},ae=()=>{try{return"Fri Aug 08 2025"}catch(t){return""}},le=`\n https://www.sheetxl.com ${ie()}`,ce="#1976d2",he=async()=>"0",de=()=>"object"==typeof window?window.location.hostname:mt.getOS(),ue=()=>"object"==typeof window?window.location.hostname:mt.getOS(),ge=()=>ue().endsWith("localhost")||"127.0.0.1"===ue(),pe=(t,e,r=126)=>((t,e,r=126)=>{let n=t.split("");for(let t=0;t<n.length;t++)n[t].charCodeAt(0)<=r&&(n[t]=String.fromCharCode((n[t].charCodeAt(0)+e)%r));return n.join("")})(t,r-e),me=t=>{let e=t;const r=e[e.length-1],n=r.charCodeAt(0)-52;if(e=e.substring(0,e.length-1),e=e.split("").reverse().join(""),e=(t=>"object"==typeof window?window.atob(t):Buffer.from(t,"base64").toString("ascii"))(e),e=e.trim(),e[e.length-1]!==r)throw new Error;e=e.substring(0,e.length-1),e=pe(e,n);try{e.startsWith("{")||(e="{"+e);const t=JSON.parse(e),r={licensee:t.l,domains:t.d,nodeId:t.n,expiry:t.e,developerCount:t.dc,cpuCount:t.cc,type:t.t};return t.f&&(r.features=t.f),r}catch(t){throw new Error("Invalid license key.")}},fe=t=>{let e=mt.EmptyArray;if(ge()||mt.isNode()){const t=ae(),r=new Date(t),n=new Date,o=864e5;Math.floor((n.getTime()-r.getTime())/o)>=120&&(e=["Evaluation period expired"])}else e=["Evaluation only"];return{licensee:()=>"Evaluation License",expiration:()=>null,domains:()=>[ue()],developerCount:()=>1,cpuCount:()=>0,type:()=>"eval",isEval:()=>!0,exceptions:()=>e,isValidFor:()=>0===e.length,isValid:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>t,getBuildVersion:ie,getBuildDate:ae}},_e={promise:null,details:null,bannerPrinted:!1,detailsPrinted:!1,licenseKey:null,keyFrom:null};let Se=!1,we=!1;const ye="cil.lxteehs".split("").reduce((t,e)=>e+t,"");const xe=new class{constructor(){this.__proto__.valueFv=null}async setLicenseKey(t,e=!1){if(!t||t.startsWith("visit ")||t.startsWith("email ")||t.startsWith("trial")||t.startsWith("eval"))return Se=!0,await this._validate(!0);if(Se=!1,!e&&_e.licenseKey){const t=await this._validate();if(t.isValid()&&!t.isEval())return t}_e.licenseKey=t,_e.keyFrom="setLicenseKey",_e.details=null,_e.promise=null;const r=await this._validate();if(!r.isValid())throw await this._print(!0),new Error("Invalid license key.");if(mt.isNode()){await(async()=>{throw new Error("setKey is not implemented in browser environment")})(0,e);if(!(await this._validate()).isValid())throw await this._print(!0),new Error("Invalid license key.")}return r}async _validate(t=!1){if(_e.promise)return _e.promise;if(this.__proto__.valueFv||(this.__proto__.valueFv=new Error("FV")),_e.promise)return _e.promise;let e=null;_e.promise=new Promise(t=>{e=t});let r,n=null;const o=async(t,e)=>{try{const n=me(e),o=await(async t=>{const e=t.domains,r=t.expiry?new Date(t.expiry):null,n=t.nodeId,o=[];if(r?isNaN(r)?o.push("Invalid expiration"):r<new Date&&o.push(`License expired on ${r.toLocaleDateString()}`):o.push("No expiration"),mt.isNode()){if(!n)return o.push("License not valid for Node.js"),o;const t=await he();t!==n&&o.push(`Invalid nodeId: ${n} does not match ${t}`)}else{if(ge())return o;if(e&&0!==e.length){let t=!1;const r=ue();for(let n=0;!t&&n<e.length;n++)t=r.endsWith(e[n]);t||o.push("Invalid domain")}else o.push("No domains specified")}return o})(n),s=((t,e,r)=>({licensee:()=>t.licensee,expiration:()=>new Date(t.expiry),domains:()=>t.domains??[],developerCount:()=>t.developerCount??1,cpuCount:()=>t.cpuCount??0,type:()=>t.type??"Community",exceptions:()=>e,isValidFor:t=>!(e?.length>0),isValid:()=>!0,isEval:()=>!1,features:()=>Object.freeze(t.features??{}),keyFrom:()=>r,getBuildVersion:ie,getBuildDate:ae}))(n,o,t);return s.exceptions().length>0&&(r=s),s}catch(e){n=t,r={licensee:()=>null,expiration:()=>null,domains:()=>[],developerCount:()=>0,cpuCount:()=>0,type:()=>"invalid",exceptions:()=>[`Invalid License key using '${n}'`],isValidFor:t=>!1,isValid:()=>!1,isEval:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>n,getBuildVersion:ie,getBuildDate:ae}}var n};_e.licenseKey&&(n=await o(_e.keyFrom,_e.licenseKey));let s=!1;if(Se&&(s=!0,n=fe("Eval License Key")),!n){if(mt.isNode()){if(!n){const t=process.env,e=t.SHEETXL_LICENSE_KEY||t.SHEETXL||t.sheetxl||t.sheetxl_license_key;e&&(n=await o("envVar",e))}if(!n){const t=await(async()=>{throw new Error("getKey is not implemented in browser environment")})();t&&(n=await o("configStore",t))}n||(s=!0)}else{if(!n)try{const t=await fetch(`./${ye}`);let e=null;if(200===t.status){const r=(await t.text()).split("\n");for(let t=0;!e&&t<r.length;t++){const n=r[t].trim();n.startsWith("#")||0===n.length||(e=n)}}if(e){const t=`fetch('./${ye}')`;n=await o(t,e)}}catch(t){}!n&&ge()&&(s=!0)}}if(!n&&s&&(n=fe("No License Key")),!n&&r&&(n=r),n||(n={licensee:()=>null,expiration:()=>null,domains:()=>[],developerCount:()=>0,cpuCount:()=>0,type:()=>null,isEval:()=>!1,exceptions:()=>["No license provided"],isValidFor:t=>!1,isValid:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>"No key",getBuildVersion:ie,getBuildDate:ae}),_e.details=n,e(n),t){if(!(_e.bannerPrinted&&_e.detailsPrinted)&&(s||n.exceptions().length>0||n.features()?.pb)){if(we)return void setTimeout(()=>{this._print(!1,!1)},8e3);await this._print(!1,!1)}}return _e.details}async _printBanner(t){_e.bannerPrinted=!0;const e=await this.getDetails();return await(async t=>{const e=t?console.log:mt.consoleWithNoSource,r=`%c\n███████╗██╗ ██╗███████╗███████╗████████╗ ██╗ ██╗██╗\n██╔════╝██║ ██║██╔════╝██╔════╝╚══██╔══╝ ╚██╗██╔╝██║\n███████╗███████║█████╗ █████╗ ██║ ╚███╔╝ ██║\n╚════██║██╔══██║██╔══╝ ██╔══╝ ██║ ██╔██╗ ██║\n███████║██║ ██║███████╗███████╗ ██║ ██╔╝ ██╗███████╗\n╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝${le}\n `;return await e(`${r}`,`font-family:monospace;color:${ce};font-size:12px;`),Promise.resolve()})(t),!_e.detailsPrinted&&(e.isEval()||e.exceptions().length>0)&&await this._printDetails(t),Promise.resolve()}async _printDetails(t=!1,e=!1,r=!1){_e.detailsPrinted=!0;const n=await this.getDetails();_e.bannerPrinted||!(n.isEval()||n.exceptions().length>0)?await(async(t,e=!1,r=!1,n=!1)=>{let o;const s=console.log,i=[`color:${ce};font-size:12px`];if(t.isEval()?(i.push(`font-family:monospace;color:${ce};font-size:12px;`),o="%cEvaluation Only",i[0]="color:#E12929;font-size:12px",o+="%c\nPlease visit https://my.sheetxl.com to register."):(o=`%cLicensee: ${t.licensee()??"Invalid License"}\n`,o+=`Expires: ${t.expiration()?.toLocaleDateString()??"Never"}`,t.domains()&&t.domains().length>0&&(o+=`\nDomains: ${t.domains().join(", ")}`),t.cpuCount()>0&&(o+=`\nCpus: ${t.cpuCount()}`)),!n&&t.exceptions().length>0){i.push("color:red;font-size:12px"),o+="\nExceptions:\n%c";for(let e=0;e<t.exceptions().length;e++)o+=` ${t.exceptions()[e]}`}return r&&(i.push("color:#FFA726;font-size:12px"),o+="%c",o+=`\nLocation: '${de()}'`,o+=`\nKeyFrom: '${t.keyFrom()}'`),await s(`${o}`,...i),Promise.resolve()})(n,t,e,r):await this._printBanner(t)}async _print(t,e){if(!t&&(_e.bannerPrinted||_e.detailsPrinted))return;_e.bannerPrinted=!0,_e.detailsPrinted=!0,await this._printBanner(t);const r=mt.isNode(),n=t||r?console.log:mt.consoleWithNoSource;r&&n(""),await this._printDetails(t,e),n("")}getDetails(){return this._validate()}print(t){return this._print(!0,t)}wasPrinted(){return _e.bannerPrinted||_e.detailsPrinted}suppressPrint(t){we=!0}async printBanner(){return this._printBanner(!0)}async printDetails(t,e){const r=await this.getDetails();return await this._printDetails(!0,t,e),r}async getNodeId(){return await he()}},Ce=(t,e)=>{const r=[];for(let n=0;n<t.length;n++){const o=t[n];r.push({x:o.x+e.x,y:o.y+e.y})}return r},be=(t,e)=>{if(!t)return{...e};if(!e)return{...t};let r=Math.min(t.x,e.x),n=Math.min(t.y,e.y);return{x:r,y:n,width:Math.max(t.width+t.x,e.width+e.x)-r,height:Math.max(t.height+t.y,e.height+e.y)-n}},Ee=t=>[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],ve=t=>{let e=Number.MAX_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER,n=Number.MIN_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER;for(let s=0;s<t.length;s++){let i=t[s];e=Math.min(e,i.x),r=Math.min(r,i.y),n=Math.max(n,i.x),o=Math.max(o,i.y)}return{x:e,y:r,width:n-e,height:o-r}},Ie=(t,e,r)=>{if(!r){const e=ve(t);r={x:e.x+e.width/2,y:e.y+e.height/2}}t=Ce(t,{x:-r.x,y:-r.y});const n=e*Math.PI/180,o=Math.sin(n),s=Math.cos(n),i=[];for(let e=0;e<t.length;e++){const r=t[e],n=s*r.x-o*r.y,a=o*r.x+s*r.y;i.push({x:n,y:a})}return t=Ce(i,{x:r.x,y:r.y})},Ae=(t,e,r,n,o,s,i,a,l=!0)=>{if(t===r&&e===n||o===i&&s===a)return!1;let c=(a-s)*(r-t)-(i-o)*(n-e);if(0===c)return!1;let h=((i-o)*(e-s)-(a-s)*(t-o))/c,d=((r-t)*(e-s)-(n-e)*(t-o))/c;return(!l||!(h<0||h>1||d<0||d>1))&&{x:t+h*(r-t),y:e+h*(n-e)}},Re=(t,e,r=!0)=>Ae(t.p1.x,t.p1.y,t.p2.x,t.p2.y,e.p1.x,e.p1.y,e.p2.x,e.p2.y,r),Me=t=>({top:{p1:t[0],p2:t[1]},left:{p1:t[3],p2:t[0]},right:{p1:t[1],p2:t[2]},bottom:{p1:t[2],p2:t[3]}}),Te=(t,e,r)=>{let n=r*Math.PI/180,o=Math.sin(n),s=Math.cos(n);return{x:t*s-e*o,y:t*o+e*s}},Fe=(t,e)=>{let r=t.p2.x-e.x,n=t.p2.y-e.y;const o=Te(r,n,90);r=o.x+e.x,n=o.y+e.y;let s=t.p1.x-e.x,i=t.p1.y-e.y;const a=Te(s,i,90);return s=a.x+e.x,i=a.y+e.y,{p1:{x:s,y:i},p2:{x:r,y:n}}},Ne=Object.freeze(Object.defineProperty({__proto__:null,angleToPoints:(t,e)=>{const r=(180-t)/180*Math.PI,n=Math.abs(e.width*Math.sin(r))+Math.abs(e.height*Math.cos(r)),o=Math.sin(r)*n/2,s=Math.cos(r)*n/2,i=e.width/2,a=e.height/2;return{x1:i-o,y1:a-s,x2:i+o,y2:a+s}},boundsToPoints:Ee,centerPoint:t=>({x:t.width/2+t.x,y:t.height/2+t.y}),clipToOuterRect:(t,e,r=0)=>{if(r<0&&(r+=360),r>90&&r<=180?r+=180:r>180&&r<=270&&(r-=180),0===r||180===r)return{height:e.height,width:e.width};if(90===r||270===r)return{height:e.width,width:e.height};let n=Ee({...e,x:0,y:0}),o=Ee({...t,x:0,y:0});o=Ce(o,{x:e.width/2-t.width/2,y:e.height/2-t.height/2}),o=Ie(o,r);let s=Me(o),i=Me(n);if(r>90){const t=Re(s.top,i.top);if(t){const e=t,r=Re(s.bottom,i.bottom,!1)||o[3];o[0]=Re(s.top,Fe(s.bottom,r),!1)||o[0],o[1]=e,o[3]=r,o[2]=Re(s.bottom,Fe(s.top,e),!1)||o[2],s=Me(o)}const e=Re(s.top,i.left);if(e){const t=e,r=Re(s.bottom,i.right,!1)||o[2];o[0]=t,o[1]=Re(s.top,Fe(s.bottom,r),!1)||o[1],o[3]=Re(s.bottom,Fe(s.top,t),!1)||o[3],o[2]=r}}else if(r<90){const t=Re(s.top,i.top);if(t){const e=t,r=Re(s.bottom,i.bottom,!1)||o[2];o[0]=e,o[1]=Re(s.top,Fe(s.bottom,r),!1)||o[1],o[3]=Re(s.bottom,Fe(s.top,e),!1)||o[3],o[2]=r,s=Me(o)}const e=Re(s.top,i.right);if(e){const t=e,r=Re(s.bottom,i.left,!1)||o[3];o[0]=Re(s.top,Fe(s.bottom,r),!1)||o[0],o[1]=t,o[3]=r,o[2]=Re(s.bottom,Fe(s.top,t),!1)||o[2]}}o=Ie(o,-r);const a=ve(o);return{width:a.width,height:a.height}},findIntersectMath:(t,e,r,n)=>{let o=Ae(t.x,t.y,e.x,e.y,5e4,0,-5e4,0);return o&&(r=Math.min(r,o.x),n=Math.max(n,o.x)),{min:r,max:n}},leastSquaresSlopeAndIntercept:t=>{let e=0,r=0,n=0,o=0,s=0,i=0,a=0,l=t.length;if(0===l)return{m:0,b:0};if(1===l)return{m:1,b:t[0]};for(let c=0;c<l;c++)i=c+1,a=t[c],null==a||isNaN(a)||(e+=i,r+=a,o+=i*i,n+=i*a,s++);const c=(s*n-e*r)/(s*o-e*e);return{m:c,b:r/s-c*e/s}},minBoundingRect:ve,rotatePoints:Ie,unionBounds:be},Symbol.toStringTag,{value:"Module"}));class ke{constructor(t,e,r){this._root=Pe,this._size=0,this._maxNodeSize=r>=4?Math.min(r,256):32,this._compare=e||ke.defaultComparator,t&&this.setPairs(t)}get size(){return this._size}get length(){return this._size}get isEmpty(){return 0===this._size}clear(){this._root=Pe,this._size=0}forEach(t,e){return void 0!==e&&(t=t.bind(e)),this.forEachPair((e,r)=>t(r,e,this))}forEachPair(t,e){const r=this.minKey(),n=this.maxKey();return this.forRange(r,n,!0,t,e)}get(t,e){return this._root.get(t,e,this)}set(t,e,r){this._root.isShared&&(this._root=this._root.clone());const n=this._root.set(t,e,r,this);return!0===n||!1===n?n:(this._root=new Le([this._root,n]),!0)}has(t){return 0!==this.forRange(t,t,!0,void 0)}delete(t){return 0!==this.editRange(t,t,!0,ke.DeleteRange)}with(t,e,r){const n=this.clone();return n.set(t,e,r)||r?n:this}withPairs(t,e){const r=this.clone();return 0!==r.setPairs(t,e)||e?r:this}withKeys(t,e){const r=this.clone();let n=!1;for(let e=0;e<t.length;e++)n=r.set(t[e],void 0,!1)||n;return e&&!n?this:r}without(t,e){return this.withoutRange(t,t,!0,e)}withoutKeys(t,e){const r=this.clone();return r.deleteKeys(t)||!e?r:this}withoutRange(t,e,r,n){const o=this.clone();return 0===o.deleteRange(t,e,r)&&n?this:o}filter(t,e){const r=this.greedyClone();let n;return r.editAll((e,r,o)=>{if(!t(e,r,o))return n=ke.DeleteValue}),!n&&e?this:r}mapValues(t){const e=this.greedyClone();return e.editAll((e,r,n)=>t(r,e,n)),e}reduce(t,e){let r,n=0,o=e;const s=this.entries(this.minKey());for(;!(r=s.next()).done;)o=t(o,r.value,n++,this);return o}entries(t,e){const r=this.findPath(t);if(void 0===r)return Oe();let{nodeQueue:n,nodeIndex:o,leaf:s}=r,i=void 0!==e?1:0,a=void 0===t?-1:s.indexOf(t,0,this._compare)-1;return Oe(()=>{t:for(;;)switch(i){case 0:if(++a<s.keys.length)return{done:!1,value:[s.keys[a],s.values[a]]};i=2;continue;case 1:if(++a<s.keys.length){const t=s.keys[a],r=s.values[a];return e?(e.done=!1,e.value[0]=t,e.value[1]=r,e):{done:!1,value:[t,r]}}i=2;case 2:for(var t=-1;;){if(++t>=n.length){i=3;continue t}if(++o[t]<n[t].length)break}for(;t>0;t--)n[t-1]=n[t][o[t]].children,o[t-1]=0;s=n[0][o[0]],a=-1,i=void 0!==e?1:0;continue;case 3:return ze}})}entriesReversed(t,e,r){if(void 0===t&&(r=void 0,void 0===(t=this.maxKey())))return Oe();let{nodeQueue:n,nodeIndex:o,leaf:s}=this.findPath(t)||this.findPath(this.maxKey());He(!n[0]||s===n[0][o[0]],"wat!");let i=s.indexOf(t,0,this._compare);!r&&i<s.keys.length&&this._compare(s.keys[i],t)<=0&&i++;let a=void 0!==e?1:0;return Oe(()=>{t:for(;;)switch(a){case 0:if(--i>=0)return{done:!1,value:[s.keys[i],s.values[i]]};a=2;continue;case 1:if(--i>=0){const t=s.keys[i],r=s.values[i];return e?(e.done=!1,e.value[0]=t,e.value[1]=r,e):{done:!1,value:[t,r]}}a=2;case 2:for(var t=-1;;){if(++t>=n.length){a=3;continue t}if(--o[t]>=0)break}for(;t>0;t--)n[t-1]=n[t][o[t]].children,o[t-1]=n[t-1].length-1;s=n[0][o[0]],i=s.keys.length,a=void 0!==e?1:0;continue;case 3:return ze}})}findPath(t){let e,r,n=this._root;if(n.isLeaf)e=je,r=je;else{e=[],r=[];for(let o=0;!n.isLeaf;o++){if(e[o]=n.children,r[o]=void 0===t?0:n.indexOf(t,0,this._compare),r[o]>=e[o].length)return;n=e[o][r[o]]}e.reverse(),r.reverse()}return{nodeQueue:e,nodeIndex:r,leaf:n}}diffAgainst(t,e,r,n){if(t._compare!==this._compare)throw new Error("SortedMap: Comparators are not the same.");if(this.isEmpty||t.isEmpty){if(this.isEmpty&&t.isEmpty)return;return this.isEmpty?void 0===r?void 0:ke.stepToEnd(ke.makeDiffCursor(t),r):void 0===e?void 0:ke.stepToEnd(ke.makeDiffCursor(this),e)}const{_compare:o}=this,s=ke.makeDiffCursor(this),i=ke.makeDiffCursor(t);let a=!0,l=!0,c=ke.compare(s,i,o);for(;a&&l;){const t=ke.compare(s,i,o),{leaf:h,internalSpine:d,levelIndices:u}=s,{leaf:g,internalSpine:p,levelIndices:m}=i;if(h||g){if(0!==c)if(0===t){if(h&&g&&n){const t=h.values[u[u.length-1]],e=g.values[m[m.length-1]];if(!Object.is(t,e)){const r=n(s.currentKey,t,e);if(r&&r.break)return r.break}}}else if(t>0){if(g&&r){const t=g.values[m[m.length-1]],e=r(i.currentKey,t);if(e&&e.break)return e.break}}else if(e&&h&&0!==c){const t=h.values[u[u.length-1]],r=e(s.currentKey,t);if(r&&r.break)return r.break}}else if(!h&&!g&&0===t){const t=d.length-1,e=p.length-1,r=d[t][u[t]];if(p[e][m[e]]===r){c=0,a=ke.step(s,!0),l=ke.step(i,!0);continue}}c=t,t<0?a=ke.step(s):l=ke.step(i)}return a&&e?ke.finishCursorWalk(s,i,o,e):l&&r?ke.finishCursorWalk(i,s,o,r):void 0}static finishCursorWalk(t,e,r,n){const o=ke.compare(t,e,r);if(0===o){if(!ke.step(t))return}else o<0&&He(!1,"cursor walk terminated early");return ke.stepToEnd(t,n)}static stepToEnd(t,e){let r=!0;for(;r;){const{leaf:n,levelIndices:o,currentKey:s}=t;if(n){const t=e(s,n.values[o[o.length-1]]);if(t&&t.break)return t.break}r=ke.step(t)}}static makeDiffCursor(t){const{_root:e,height:r}=t;return{height:r,internalSpine:[[e]],levelIndices:[0],leaf:void 0,currentKey:e.maxKey()}}static step(t,e){const{internalSpine:r,levelIndices:n,leaf:o}=t;if(!0===e||o){const s=n.length;if(!0===e||0===n[s-1]){const e=r.length;if(0===e)return!1;const o=e-1;let i=o;for(;i>=0;){if(n[i]>0)return i<s-1&&(t.leaf=void 0,n.pop()),i<o&&(t.internalSpine=r.slice(0,i+1)),t.currentKey=r[i][--n[i]].maxKey(),!0;i--}return!1}{const e=--n[s-1];return t.currentKey=o.keys[e],!0}}{const e=r.length,o=e-1,s=r[o][n[o]];if(s.isLeaf){t.leaf=s;const r=n[e]=s.values.length-1;t.currentKey=s.keys[r]}else{const o=s.children;r[e]=o;const i=o.length-1;n[e]=i,t.currentKey=o[i].maxKey()}return!0}}static compare(t,e,r){const{height:n,currentKey:o,levelIndices:s}=t,{height:i,currentKey:a,levelIndices:l}=e,c=r(a,o);if(0!==c)return c;const h=n<i?n:i;return s.length-(n-h)-(l.length-(i-h))}keys(t,e){const r=this.entries(t,e);return Oe(()=>{const t=r.next();return t.value&&(t.value=t.value[0]),t})}values(t,e){const r=this.entries(t,e);return Oe(()=>{const t=r.next();return t.value&&(t.value=t.value[1]),t})}get maxNodeSize(){return this._maxNodeSize}minKey(){return this._root.minKey()}maxKey(){return this._root.maxKey()}clone(){this._root.isShared=!0;const t=new ke(void 0,this._compare,this._maxNodeSize);return t._root=this._root,t._size=this._size,t}greedyClone(t){const e=new ke(void 0,this._compare,this._maxNodeSize);return e._root=this._root.greedyClone(t),e._size=this._size,e}toArray(t=2147483647){const e=this.minKey(),r=this.maxKey();return void 0!==e?this.getRange(e,r,!0,t):[]}keysArray(){const t=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(e,r)=>{t.push(e)}),t}valuesArray(){const t=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(e,r)=>{t.push(r)}),t}toString(){return this.toArray().toString()}setIfNotPresent(t,e){return this.set(t,e,!1)}nextHigherPair(t,e){return void 0===t?this._root.minPair(e):this._root.getPairOrNextHigher(t,this._compare,!1,e)}nextHigherKey(t,e){const r=this.nextHigherPair(t,e);return r&&r[0]}nextLowerPair(t,e){return void 0===t?this._root.maxPair(e):this._root.getPairOrNextLower(t,this._compare,!1,e)}nextLowerKey(t,e){const r=this.nextLowerPair(t,e);return r&&r[0]}getPairOrNextLower(t,e){return this._root.getPairOrNextLower(t,this._compare,!0,e)}getPairOrNextHigher(t,e){return this._root.getPairOrNextHigher(t,this._compare,!0,e)}changeIfPresent(t,e){return 0!==this.editRange(t,t,!0,(t,r)=>({value:e}))}getRange(t,e,r,n=67108863){const o=[];return this._root.forRange(t,e,r,!1,this,0,(t,e)=>(o.push([t,e]),o.length>n?ke.Break:void 0)),o}setPairs(t,e){let r=0;for(let n=0;n<t.length;n++)this.set(t[n][0],t[n][1],e)&&r++;return r}forRange(t,e,r,n,o){const s=this._root.forRange(t,e,r,!1,this,o||0,n);return"number"==typeof s?s:s.break}forEditRange(t,e,r,n,o,s){return this._root.forRange(t,e,r,n,this,s||0,o)}editRange(t,e,r,n,o){let s=this._root;s.isShared&&(this._root=s=s.clone());try{const i=s.forRange(t,e,r,!0,this,o||0,n);return"number"==typeof i?i:i.break}finally{let t;for(;s.keys.length<=1&&!s.isLeaf;)t||=s.isShared,this._root=s=0===s.keys.length?Pe:s.children[0];t&&(s.isShared=!0)}}editAll(t,e){return this.editRange(this.minKey(),this.maxKey(),!0,t,e)}deleteRange(t,e,r){return this.editRange(t,e,r,ke.DeleteRange)}deleteKeys(t){let e=0;for(let r=0;r<t.length;r++)this.delete(t[r])&&e++;return e}get height(){let t=this._root,e=-1;for(;t;)e++,t=t.isLeaf?void 0:t.children[0];return e}freeze(){const t=this;t.clear=t.set=t.editRange=function(){throw new Error("SortedMap: Attempted to modify when frozen.")}}unfreeze(){delete this.clear,delete this.set,delete this.editRange}get isFrozen(){return this.hasOwnProperty("editRange")}checkValid(){const t=this._root.checkValid(0,this,0);He(t===this.size,"size mismatch: counted ",t,"but stored",this.size)}}function Oe(t=()=>ze){const e={next:t};return Symbol&&Symbol.iterator&&(e[Symbol.iterator]=function(){return this}),e}Symbol&&Symbol.iterator&&(ke.prototype[Symbol.iterator]=ke.prototype.entries),ke.prototype.where=ke.prototype.filter,ke.prototype.setRange=ke.prototype.setPairs,ke.prototype.add=ke.prototype.set;class Be{get isLeaf(){return void 0===this.children}constructor(t=[],e){this.keys=t,this.values=e||De,this.isShared=void 0}maxKey(){return this.keys[this.keys.length-1]}indexOf(t,e,r){const n=this.keys;let o=0,s=n.length,i=s>>1;for(;o<s;){const e=r(n[i],t);if(e<0)o=i+1;else{if(!(e>0)){if(0===e)return i;if(t==t)return n.length;throw new Error("SortedMap: NaN was used as a key.")}s=i}i=o+s>>1}return i^e}minKey(){return this.keys[0]}minPair(t){if(0!==this.keys.length)return(t=t??[null,null])[0]=this.keys[0],t[1]=this.values[0],t}maxPair(t){if(0===this.keys.length)return;const e=this.keys.length-1;return(t=t??[null,null])[0]=this.keys[e],t[1]=this.values[e],t}clone(){const t=this.values,e=t===De?t:t.slice(0),r=this.keys.slice(0);return new Be(r,e)}greedyClone(t){return this.isShared&&!t?this:this.clone()}get(t,e,r){const n=this.indexOf(t,-1,r._compare);return n<0?e:this.values[n]}getPairOrNextLower(t,e,r,n){const o=this.indexOf(t,-1,e),s=o<0?~o-1:r?o:o-1;if(s>=0){const t=this.keys[s],e=this.values[s];return n?(n[0]=t,n[1]=e,n):[t,e]}}getPairOrNextHigher(t,e,r,n){const o=this.indexOf(t,-1,e),s=o<0?~o:r?o:o+1;if(s<this.keys.length){const t=this.keys[s],e=this.values[s];return n?(n[0]=t,n[1]=e,n):[t,e]}}checkValid(t,e,r){const n=this.keys.length,o=this.values.length;return He(this.values===De?n<=o:n===o,"keys/values length mismatch: depth",t,"with lengths",n,o,"and baseIndex",r),He(0===t||n>0,"empty leaf at depth",t,"and baseIndex",r),n}set(t,e,r,n){let o=this.indexOf(t,-1,n._compare);if(o<0){if(o=~o,n._size++,this.keys.length<n._maxNodeSize)return this.insertInLeaf(o,t,e,r,n);{const s=this.splitOffRightSide();let i=this;return o>this.keys.length&&(o-=this.keys.length,i=s),i.insertInLeaf(o,t,e,r,n),s}}if(!1!==r){void 0!==e&&this.reifyValues(),this.keys[o]=t;let n=e;if("function"==typeof r){const s=r(this.values[o],t,e);void 0!==s&&(n=s)}this.values[o]=n}return!1}reifyValues(){return this.values===De?this.values=this.values.slice(0,this.keys.length):this.values}insertInLeaf(t,e,r,n,o){if(this.keys.splice(t,0,e),this.values===De){for(;De.length<o._maxNodeSize;)De.push(void 0);if(void 0===r)return!0;this.values=De.slice(0,this.keys.length-1)}let s=r;if("function"==typeof n){const t=n(void 0,e,r);void 0!==t&&(s=t)}return this.values.splice(t,0,s),!0}takeFromRight(t){let e=this.values;t.values===De?e!==De&&e.push(void 0):(e=this.reifyValues(),e.push(t.values.shift())),this.keys.push(t.keys.shift())}takeFromLeft(t){let e=this.values;t.values===De?e!==De&&e.unshift(void 0):(e=this.reifyValues(),e.unshift(t.values.pop())),this.keys.unshift(t.keys.pop())}splitOffRightSide(){const t=this.keys.length>>1,e=this.keys.splice(t),r=this.values===De?De:this.values.splice(t);return new Be(e,r)}forRange(t,e,r,n,o,s,i){const a=o._compare;let l,c;if(e===t){if(!r)return s;if(c=(l=this.indexOf(t,-1,a))+1,l<0)return s}else l=this.indexOf(t,0,a),c=this.indexOf(e,-1,a),c<0?c=~c:!0===r&&c++;const h=this.keys,d=this.values;if(void 0!==i)for(let t=l;t<c;t++){const e=h[t],r=i(e,d[t],s++);if(void 0!==r){if(void 0!==r.break)return r;if(!0===n){if(e!==h[t]&&0!==o._compare(e,h[t])||!0===this.isShared)throw new Error("SortedMap: illegally changed or cloned in editRange.");r.delete?(this.keys.splice(t,1),this.values!==De&&this.values.splice(t,1),o._size--,t--,c--):r.hasOwnProperty("value")&&(d[t]=r.value)}}}else s+=c-l;return s}mergeSibling(t,e){if(this.keys.push.apply(this.keys,t.keys),this.values===De){if(t.values===De)return;this.values=this.values.slice(0,this.keys.length)}this.values.push.apply(this.values,t.reifyValues())}}class Le extends Be{constructor(t,e){if(!e){e=[];for(let r=0;r<t.length;r++)e[r]=t[r].maxKey()}super(e),this.children=t}clone(){const t=this.children.slice(0);for(let e=0;e<t.length;e++)t[e].isShared=!0;return new Le(t,this.keys.slice(0))}greedyClone(t){if(this.isShared&&!t)return this;const e=new Le(this.children.slice(0),this.keys.slice(0));for(let r=0;r<e.children.length;r++)e.children[r]=e.children[r].greedyClone(t);return e}minKey(){return this.children[0].minKey()}minPair(t){return this.children[0].minPair(t)}maxPair(t){return this.children[this.children.length-1].maxPair(t)}get(t,e,r){const n=this.indexOf(t,0,r._compare),o=this.children;return n<o.length?o[n].get(t,e,r):void 0}getPairOrNextLower(t,e,r,n){const o=this.indexOf(t,0,e),s=this.children;if(o>=s.length)return this.maxPair(n);const i=s[o].getPairOrNextLower(t,e,r,n);return void 0===i&&o>0?s[o-1].maxPair(n):i}getPairOrNextHigher(t,e,r,n){const o=this.indexOf(t,0,e),s=this.children,i=s.length;if(o>=i)return;const a=s[o].getPairOrNextHigher(t,e,r,n);return void 0===a&&o<i-1?s[o+1].minPair(n):a}checkValid(t,e,r){const n=this.keys.length,o=this.children.length;He(n===o,"keys/children length mismatch: depth",t,"lengths",n,o,"baseIndex",r),He(n>1||t>0,"internal node has length",n,"at depth",t,"baseIndex",r);let s=0,i=this.children,a=this.keys,l=0;for(let n=0;n<o;n++)s+=i[n].checkValid(t+1,e,r+s),l+=i[n].keys.length,He(s>=l,"wtf",r),He(0===n||i[n-1].constructor===i[n].constructor,"type mismatch, baseIndex:",r),i[n].maxKey()!==a[n]&&He(!1,"keys[",n,"] =",a[n],"is wrong, should be ",i[n].maxKey(),"at depth",t,"baseIndex",r),0===n||e._compare(a[n-1],a[n])<0||He(!1,"sort violation at depth",t,"index",n,"keys",a[n-1],a[n]);const c=0===l;return(c||l>e.maxNodeSize*o)&&He(!1,c?"too few":"too many","children (",l,s,") at depth",t,"maxNodeSize:",e.maxNodeSize,"children.length:",o,"baseIndex:",r),s}set(t,e,r,n){const o=this.children,s=n._maxNodeSize,i=n._compare;let a=Math.min(this.indexOf(t,0,i),o.length-1),l=o[a];if(l.isShared&&(o[a]=l=l.clone()),l.keys.length>=s){let e;a>0&&(e=o[a-1]).keys.length<s&&i(l.keys[0],t)<0?(e.isShared&&(o[a-1]=e=e.clone()),e.takeFromRight(l),this.keys[a-1]=e.maxKey()):void 0!==(e=o[a+1])&&e.keys.length<s&&i(l.maxKey(),t)<0&&(e.isShared&&(o[a+1]=e=e.clone()),e.takeFromLeft(l),this.keys[a]=o[a].maxKey())}const c=l.set(t,e,r,n);if(!1===c)return!1;if(this.keys[a]=l.maxKey(),!0===c)return!0;if(this.keys.length<s)return this.insert(a+1,c),!0;{const t=this.splitOffRightSide();let e=this;return i(c.maxKey(),this.maxKey())>0&&(e=t,a-=this.keys.length),e.insert(a+1,c),t}}insert(t,e){this.children.splice(t,0,e),this.keys.splice(t,0,e.maxKey())}splitOffRightSide(){const t=this.children.length>>1;return new Le(this.children.splice(t),this.keys.splice(t))}takeFromRight(t){this.keys.push(t.keys.shift()),this.children.push(t.children.shift())}takeFromLeft(t){this.keys.unshift(t.keys.pop()),this.children.unshift(t.children.pop())}forRange(t,e,r,n,o,s,i){const a=o._compare,l=this.keys,c=this.children;let h=this.indexOf(t,0,a),d=h,u=Math.min(e===t?h:this.indexOf(e,0,a),l.length-1);if(n){if(d<=u)try{for(;d<=u;d++){c[d].isShared&&(c[d]=c[d].clone());const a=c[d].forRange(t,e,r,n,o,s,i);if(l[d]=c[d].maxKey(),"number"!=typeof a)return a;s=a}}finally{const t=o._maxNodeSize>>1;for(h>0&&h--,d=u;d>=h;d--)c[d].keys.length<=t&&(0!==c[d].keys.length?this.tryMerge(d,o._maxNodeSize):(l.splice(d,1),c.splice(d,1)));0!==c.length&&0===c[0].keys.length&&He(!1,"emptiness bug")}}else for(;d<=u;d++){const a=c[d].forRange(t,e,r,n,o,s,i);if("number"!=typeof a)return a;s=a}return s}tryMerge(t,e){const r=this.children;return t>=0&&t+1<r.length&&r[t].keys.length+r[t+1].keys.length<=e&&(r[t].isShared&&(r[t]=r[t].clone()),r[t].mergeSibling(r[t+1],e),r.splice(t+1,1),this.keys.splice(t+1,1),this.keys[t]=r[t].maxKey(),!0)}mergeSibling(t,e){const r=this.keys.length;this.keys.push.apply(this.keys,t.keys);const n=t.children;if(this.children.push.apply(this.children,n),t.isShared&&!this.isShared)for(let t=0;t<n.length;t++)n[t].isShared=!0;this.tryMerge(r-1,e)}}const De=[],ze=Object.freeze({done:!0,value:void 0}),Pe=function(){const t=new Be;return t.isShared=!0,t}(),je=[],He=(t,...e)=>{if(!t)throw e.unshift("SortedMap:"),new Error(e.join(" "))};var Ve;(Ve=ke||(ke={})).DeleteValue=Object.freeze({delete:!0}),Ve.Break=Object.freeze({break:!0}),Ve.DeleteRange=()=>Ve.DeleteValue,Ve.EmptySortedMap=(()=>{const t=new Ve;return t.freeze(),t})(),Ve.defaultComparator=function(t,e){if(Number.isFinite(t)&&Number.isFinite(e))return t-e;let r=typeof t,n=typeof e;if(r!==n)return r<n?-1:1;if("object"===r){if(null===t)return null===e?0:-1;if(null===e)return 1;if(r=typeof(t=t.valueOf()),n=typeof(e=e.valueOf()),r!==n)return r<n?-1:1}return t<e?-1:t>e?1:t===e?0:Number.isNaN(t)?Number.isNaN(e)?0:-1:Number.isNaN(e)?1:Array.isArray(t)?0:Number.NaN},Ve.simpleComparator=function(t,e){return t>e?1:t<e?-1:0};const $e=[-1,null],Ue={done:!1,value:[-1,null]};exports.Tuple=void 0,(t=>{t.Builder=class{constructor(t,e=0,r=0){this._tuples=[],this._minors=null,this._values=null,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=0,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._offsetMajor=0,this._offsetMinor=0,this._createList=t,this._offsetMajor=e,this._offsetMinor=r}addValues(t,e,r){if(r&&r.isIList)return this.addValue(t,e,r);Array.isArray(r)||(r=[r]),this.addValue(t,e,r[0]);const n=r.length,o=this._values;for(let t=1;t<n;t++)o.push(r[t]);return this._minorIndex=this._minorIndex+o.length-1,this}addValue(t,r,n){const o=this._majorIndex,s=this._minorIndex;if(t+=this._offsetMajor,r+=this._offsetMinor,t<o||t===o&&r<=s)throw new e(`major: ${t}, minor: ${r}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);let i=this._minors;if(t!==o){if(i){this._minorMin=Math.min(this._minorMin,i[0][0]);const t=i[i.length-1];this._minorMax=Math.max(this._minorMax,t[0]+t[1].length-1)}this._minors=i=[],this._tuples.push([t,i]),this._majorIndex=t}if(n&&n.isIList){r===s+1&&o!==t&&this._values;const e=n;i.push([r,e]),r=r+e.length-1}else{let e=null;r!==s+1||o!==t?(this._values=e=[],i.push([r,e])):e=this._values,e.push(n)}return this._minorIndex=r,this}build(){const t=this._tuples;if(0===t.length)return null;const e=this._minors;this._minorMin=Math.min(this._minorMin,e[0][0]);const r=e[e.length-1];this._minorMax=Math.max(this._minorMax,r[0]+r[1].length-1);const n=this._createList;if(n){const t=e.length;for(let r=0;r<t;r++)e[r][1]=n(e[r][1])}return{tuples:t,bounds:{majorStart:t[0][0],minorStart:this._minorMin,majorEnd:t[t.length-1][0],minorEnd:this._minorMax}}}};t.TransposedBuilder=class{constructor(t,e=0,r=0){this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=0,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._offsetMajor=0,this._offsetMinor=0,this._createList=t,this._offsetMajor=e,this._offsetMinor=r,this._minors=new ke}addValues(t,e,r){Array.isArray(r)||(r=[r]);const n=r.length;for(let o=0;o<n;o++){const n=e+o;this.addValue(t,n,r[o])}return this}addValue(t,r,n){let o,s;const i=this._majorIndex;let a=this._minorIndex;if(t+=this._offsetMajor,r+=this._offsetMinor,s=this._current,t!==i){if(this._majorIndex=t,t<i)throw new e(`major: ${t}, minor: ${r}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);a=Number.MIN_SAFE_INTEGER}else if(s=this._current,r<=a)throw new e(`major: ${t}, minor: ${r}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);if(s&&s.minor===r&&(o=s.span),o)s.minor>=r&&s.next&&(this._current=s.next);else{const e=this._minors,n=s?s.next??s.prev:null;if(n){let t;const i=n.minor;n&&n.minor===r?(s=n,o=s.span):t=i>r?e.getPairOrNextHigher(r,$e):e.getPairOrNextLower(r,$e),t&&(s=t[1],t[0]===r&&(o=s.span))}if(!o){this._majorMin=Math.min(this._majorMin,t),o=[r,[[t,[]]]];const n={minor:r,span:o,prev:null,next:null};s&&(s.minor<r?(n.prev=s,n.next=s.next,s.next&&(s.next.prev=n),s.next=n):(n.prev=s.prev,n.next=s,s.prev&&(s.prev.next=n),s.prev=n)),e.set(r,n),this._current=n;const i=this._first;(!i||r<i.minor)&&(this._first=n),n.next&&(this._current=n.next)}}let l=o[1];const c=l[l.length-1];let h=c[0],d=c[1];return h+d.length!==t&&(d=[],h=t,l.push([h,d])),d.push(n),this._majorMax=Math.max(this._majorMax,t),this._minorIndex=r,this}build(){const t=[],e=this._createList,r=this._minors.entries(void 0,Ue);let n=r.next();for(;!n.done;){const o=n.value[1].span;if(e)for(let t=0;t<o.length;t++)o[t][1]=this._createList(o[t][1]);t.push(o),n=r.next()}return 0===t.length?null:{tuples:t,bounds:{majorStart:t[0][0],minorStart:this._majorMin,majorEnd:t[t.length-1][0],minorEnd:this._majorMax}}}};class e extends At{constructor(t="Out of order",e=null){super(t,e),this.name="OutOfOrderError"}}t.OutOfOrderError=e})(exports.Tuple||(exports.Tuple={}));const Ge={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function We(t){return(e={})=>{const r=e.width?String(e.width):t.defaultWidth;return t.formats[r]||t.formats[t.defaultWidth]}}const qe={date:We({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:We({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:We({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},Je={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function Xe(t){return(e,r)=>{let n;if("formatting"===(r?.context?String(r.context):"standalone")&&t.formattingValues){const e=t.defaultFormattingWidth||t.defaultWidth,o=r?.width?String(r.width):e;n=t.formattingValues[o]||t.formattingValues[e]}else{const e=t.defaultWidth,o=r?.width?String(r.width):t.defaultWidth;n=t.values[o]||t.values[e]}return n[t.argumentCallback?t.argumentCallback(e):e]}}function Ke(t){return(e,r={})=>{const n=r.width,o=n&&t.matchPatterns[n]||t.matchPatterns[t.defaultMatchWidth],s=e.match(o);if(!s)return null;const i=s[0],a=n&&t.parsePatterns[n]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(a)?function(t,e){for(let r=0;r<t.length;r++)if(e(t[r]))return r;return}(a,t=>t.test(i)):function(t,e){for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&e(t[r]))return r;return}(a,t=>t.test(i));let c;c=t.valueCallback?t.valueCallback(l):l,c=r.valueCallback?r.valueCallback(c):c;return{value:c,rest:e.slice(i.length)}}}var Ye;const Ze={code:"en-US",formatDistance:(t,e,r)=>{let n;const o=Ge[t];return n="string"==typeof o?o:1===e?o.one:o.other.replace("{{count}}",e.toString()),r?.addSuffix?r.comparison&&r.comparison>0?"in "+n:n+" ago":n},formatLong:qe,formatRelative:(t,e,r,n)=>Je[t],localize:{ordinalNumber:(t,e)=>{const r=Number(t),n=r%100;if(n>20||n<10)switch(n%10){case 1:return r+"st";case 2:return r+"nd";case 3:return r+"rd"}return r+"th"},era:Xe({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:Xe({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:t=>t-1}),month:Xe({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:Xe({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:Xe({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(Ye={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:t=>parseInt(t,10)},(t,e={})=>{const r=t.match(Ye.matchPattern);if(!r)return null;const n=r[0],o=t.match(Ye.parsePattern);if(!o)return null;let s=Ye.valueCallback?Ye.valueCallback(o[0]):o[0];return s=e.valueCallback?e.valueCallback(s):s,{value:s,rest:t.slice(n.length)}}),era:Ke({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:Ke({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:t=>t+1}),month:Ke({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:Ke({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:Ke({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}},Qe=(t,e)=>{switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},tr=(t,e)=>{switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},er={p:tr,P:(t,e)=>{const r=t.match(/(P+)(p+)?/)||[],n=r[1],o=r[2];if(!o)return Qe(t,e);let s;switch(n){case"P":s=e.dateTime({width:"short"});break;case"PP":s=e.dateTime({width:"medium"});break;case"PPP":s=e.dateTime({width:"long"});break;default:s=e.dateTime({width:"full"})}return s.replace("{{date}}",Qe(n,e)).replace("{{time}}",tr(o,e))}},rr=/^D+$/,nr=/^Y+$/,or=["D","DD","YY","YYYY"];function sr(t){return rr.test(t)}function ir(t){return nr.test(t)}function ar(t,e,r){const n=function(t,e,r){const n="Y"===t[0]?"years":"days of the month";return`Use \`${t.toLowerCase()}\` instead of \`${t}\` (in \`${e}\`) for formatting ${n} to the input \`${r}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(t,e,r);if(console.warn(n),or.includes(t))throw new RangeError(n)}const lr=Symbol.for("constructDateFrom");function cr(t,e){return"function"==typeof t?t(e):t&&"object"==typeof t&&lr in t?t[lr](e):t instanceof Date?new t.constructor(e):new Date(e)}let hr={};function dr(){return hr}function ur(t,e){return cr(e||t,t)}class gr{constructor(){this.subPriority=0}validate(t,e){return!0}}class pr extends gr{constructor(t,e,r,n,o){super(),this.value=t,this.validateValue=e,this.setValue=r,this.priority=n,o&&(this.subPriority=o)}validate(t,e){return this.validateValue(t,this.value,e)}set(t,e,r){return this.setValue(t,e,this.value,r)}}class mr extends gr{constructor(t,e){super(),this.priority=10,this.subPriority=-1,this.context=t||(t=>cr(e,t))}set(t,e){return e.timestampIsSet?t:cr(t,function(t,e){const r=function(t){return"function"==typeof t&&t.prototype?.constructor===t}(e)?new e(0):cr(e,0);return r.setFullYear(t.getFullYear(),t.getMonth(),t.getDate()),r.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),r}(t,this.context))}}let fr=class{run(t,e,r,n){const o=this.parse(t,e,r,n);return o?{setter:new pr(o.value,this.validate,this.set,this.priority,this.subPriority),rest:o.rest}:null}validate(t,e,r){return!0}};const _r=/^(1[0-2]|0?\d)/,Sr=/^(3[0-1]|[0-2]?\d)/,wr=/^\d/,yr=/^\d{1,2}/,xr=/^\d{1,3}/,Cr=/^\d{1,4}/;function br(t,e){return t?{value:e(t.value),rest:t.rest}:t}function Er(t,e){const r=e.match(t);return r?{value:parseInt(r[0],10),rest:e.slice(r[0].length)}:null}function vr(t,e){switch(t){case 1:return Er(wr,e);case 2:return Er(yr,e);case 3:return Er(xr,e);case 4:return Er(Cr,e);default:return Er(new RegExp("^\\d{1,"+t+"}"),e)}}class Ir extends fr{constructor(){super(...arguments),this.incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"],this.priority=110}parse(t,e,r){const n=t=>t-1;switch(e){case"M":return br(Er(_r,t),n);case"MM":return br(vr(2,t),n);case"Mo":return br(r.ordinalNumber(t,{unit:"month"}),n);case"MMM":return r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return r.month(t,{width:"narrow",context:"formatting"});default:return r.month(t,{width:"wide",context:"formatting"})||r.month(t,{width:"abbreviated",context:"formatting"})||r.month(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=11}set(t,e,r){return t.setMonth(r,1),t.setHours(0,0,0,0),t}}const Ar=[31,28,31,30,31,30,31,31,30,31,30,31],Rr=[31,29,31,30,31,30,31,31,30,31,30,31];function Mr(t,e,r){const n=dr(),o=r?.weekStartsOn??r?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=ur(t,r?.in),i=s.getDay(),a=7-o;return function(t,e,r){const n=ur(t,r?.in);return isNaN(e)?cr(r?.in||t,NaN):e?(n.setDate(n.getDate()+e),n):n}(s,e<0||e>6?e-(i+a)%7:((e%7+7)%7+a)%7-(i+a)%7,r)}const Tr={y:new class extends fr{constructor(){super(...arguments),this.priority=130,this.incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"]}parse(t,e,r){const n=t=>({year:t,isTwoDigitYear:"yy"===e});switch(e){case"y":return br(vr(4,t),n);case"yo":return br(r.ordinalNumber(t,{unit:"year"}),n);default:return br(vr(e.length,t),n)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,r){const n=t.getFullYear();if(r.isTwoDigitYear){const e=function(t,e){const r=e>0,n=r?e:1-e;let o;if(n<=50)o=t||100;else{const e=n+50;o=t+100*Math.trunc(e/100)-(t>=e%100?100:0)}return r?o:1-o}(r.year,n);return t.setFullYear(e,0,1),t.setHours(0,0,0,0),t}const o="era"in e&&1!==e.era?1-r.year:r.year;return t.setFullYear(o,0,1),t.setHours(0,0,0,0),t}},M:new Ir,d:new class extends fr{constructor(){super(...arguments),this.priority=90,this.subPriority=1,this.incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]}parse(t,e,r){switch(e){case"d":return Er(Sr,t);case"do":return r.ordinalNumber(t,{unit:"date"});default:return vr(e.length,t)}}validate(t,e){const r=function(t){return t%400==0||t%4==0&&t%100!=0}(t.getFullYear()),n=t.getMonth();return r?e>=1&&e<=Rr[n]:e>=1&&e<=Ar[n]}set(t,e,r){return t.setDate(r),t.setHours(0,0,0,0),t}},E:new class extends fr{constructor(){super(...arguments),this.priority=90,this.incompatibleTokens=["D","i","e","c","t","T"]}parse(t,e,r){switch(e){case"E":case"EE":case"EEE":return r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return r.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"});default:return r.day(t,{width:"wide",context:"formatting"})||r.day(t,{width:"abbreviated",context:"formatting"})||r.day(t,{width:"short",context:"formatting"})||r.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,r,n){return(t=Mr(t,r,n)).setHours(0,0,0,0),t}}},Fr=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Nr=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,kr=/^'([^]*?)'?$/,Or=/''/g,Br=/\S/,Lr=/[a-zA-Z]/;function Dr(t,e,r,n){const o=()=>cr(n?.in||r,NaN),s=Object.assign({},dr()),i=n?.locale??s.locale??Ze,a=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,l=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0;if(!e)return t?o():ur(r,n?.in);const c={firstWeekContainsDate:a,weekStartsOn:l,locale:i},h=[new mr(n?.in,r)],d=e.match(Nr).map(t=>{const e=t[0];if(e in er){return(0,er[e])(t,i.formatLong)}return t}).join("").match(Fr),u=[];for(let r of d){!n?.useAdditionalWeekYearTokens&&ir(r)&&ar(r,e,t),!n?.useAdditionalDayOfYearTokens&&sr(r)&&ar(r,e,t);const s=r[0],a=Tr[s];if(a){const{incompatibleTokens:e}=a;if(Array.isArray(e)){const t=u.find(t=>e.includes(t.token)||t.token===s);if(t)throw new RangeError(`The format string mustn't contain \`${t.fullToken}\` and \`${r}\` at the same time`)}else if("*"===a.incompatibleTokens&&u.length>0)throw new RangeError(`The format string mustn't contain \`${r}\` and any other token at the same time`);u.push({token:s,fullToken:r});const n=a.run(t,r,i.match,c);if(!n)return o();h.push(n.setter),t=n.rest}else{if(s.match(Lr))throw new RangeError("Format string contains an unescaped latin alphabet character `"+s+"`");if("''"===r?r="'":"'"===s&&(r=zr(r)),0!==t.indexOf(r))return o();t=t.slice(r.length)}}if(t.length>0&&Br.test(t))return o();const g=h.map(t=>t.priority).sort((t,e)=>e-t).filter((t,e,r)=>r.indexOf(t)===e).map(t=>h.filter(e=>e.priority===t).sort((t,e)=>e.subPriority-t.subPriority)).map(t=>t[0]);let p=ur(r,n?.in);if(isNaN(+p))return o();const m={};for(const t of g){if(!t.validate(p,c))return o();const e=t.set(p,m,c);Array.isArray(e)?(p=e[0],Object.assign(m,e[1])):p=e}return p}function zr(t){return t.match(kr)[1].replace(Or,"'")}const Pr=t=>!isNaN(t)&&("[object Date]"===Object.prototype.toString.call(t)||t instanceof Date);function jr(t,e,r){let n=t,o=t.length,s=e.length;for(var i=o;i<s;++i){const t=e[i];if("#"===t)return n;n=r?n+t:t+n}return n}function Hr(t,e){for(var r="";r.length<e;)r+=t;return r}function Vr(t){for(var e="",r=t.length-1;r>=0;)e+=t.charAt(r--);return e}function $r(t,e){var r=""+t;return r.length>=e?r:Hr("0",e-r.length)+r}function Ur(t,e){var r=""+t;return r.length>=e?r:Hr(" ",e-r.length)+r}function Gr(t,e){var r=""+t;return r.length>=e?r:r+Hr(" ",e-r.length)}var Wr=Math.pow(2,32);function qr(t,e){return t>Wr||t<-Wr?function(t,e){var r=""+Math.round(t);return r.length>=e?r:Hr("0",e-r.length)+r}(t,e):function(t,e){var r=""+t;return r.length>=e?r:Hr("0",e-r.length)+r}(Math.round(t),e)}function Jr(t,e){return e=e||0,t.length>=7+e&&103==(32|t.charCodeAt(e))&&101==(32|t.charCodeAt(e+1))&&110==(32|t.charCodeAt(e+2))&&101==(32|t.charCodeAt(e+3))&&114==(32|t.charCodeAt(e+4))&&97==(32|t.charCodeAt(e+5))&&108==(32|t.charCodeAt(e+6))}var Xr=[["Sun","Sunday"],["Mon","Monday"],["Tue","Tuesday"],["Wed","Wednesday"],["Thu","Thursday"],["Fri","Friday"],["Sat","Saturday"]],Kr=[["J","Jan","January"],["F","Feb","February"],["M","Mar","March"],["A","Apr","April"],["M","May","May"],["J","Jun","June"],["J","Jul","July"],["A","Aug","August"],["S","Sep","September"],["O","Oct","October"],["N","Nov","November"],["D","Dec","December"]],Yr={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",5:"$#,##0_);($#,##0)",6:"$#,##0_);[Red]($#,##0)",7:"$#,##0.00_);($#,##0.00)",8:"$#,##0.00_);[Red]($#,##0.00)",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yy h:mm",23:"General",24:"General",25:"General",26:"General",27:"m/d/yyyy",28:"m/d/yyyy",29:"m/d/yyyy",30:"m/d/yyyy",32:"h:mm:ss",31:"m/d/yyyy",33:"h:mm:ss",34:"h:mm:ss",35:"h:mm:ss",36:"m/d/yyyy",37:"#,##0_);(#,##0)",38:"#,##0_);[Red](#,##0)",39:"#,##0.00_);(#,##0.00)",40:"#,##0.00_);[Red](#,##0.00)",41:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',42:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)',43:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',44:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@",50:"m/d/yyyy",51:"m/d/yyyy",52:"m/d/yyyy",53:"m/d/yyyy",54:"m/d/yyyy",55:"m/d/yyyy",56:'"上午/下午 "hh"時"mm"分"ss"秒 "'},Zr={5:37,6:38,7:39,8:40,23:0,24:0,25:0,26:0,27:14,28:14,29:14,30:14,31:14,50:14,51:14,52:14,53:14,54:14,55:14,56:14,57:14,58:14,59:1,60:2,61:3,62:4,67:9,68:10,69:12,70:13,71:14,72:14,73:15,74:16,75:17,76:20,77:21,78:22,79:45,80:46,81:47,82:0},Qr={5:'"$"#,##0_);\\("$"#,##0\\)',63:'"$"#,##0_);\\("$"#,##0\\)',6:'"$"#,##0_);[Red]\\("$"#,##0\\)',64:'"$"#,##0_);[Red]\\("$"#,##0\\)',7:'"$"#,##0.00_);\\("$"#,##0.00\\)',65:'"$"#,##0.00_);\\("$"#,##0.00\\)',8:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',66:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',41:'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',42:'_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)',43:'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',44:'_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)'};function tn(t,e,r){for(var n=t<0?-1:1,o=t*n,s=0,i=1,a=0,l=1,c=0,h=0,d=Math.floor(o);c<e&&(a=(d=Math.floor(o))*i+s,h=d*c+l,!(o-d<5e-8));)o=1/(o-d),s=i,i=a,l=c,c=h;if(h>e&&(c>e?(h=l,a=s):(h=c,a=i)),!r)return[0,n*a,h];var u=Math.floor(n*a/h);return[u,n*a-u*h,h]}function en(t,e,r){if(t>2958465||t<0)return null;var n=0|t,o=Math.floor(86400*(t-n)),s=0,i=[],a={D:n,T:o,u:86400*(t-n)-o,y:0,m:0,d:0,H:0,M:0,S:0,q:0};if(Math.abs(a.u)<1e-6&&(a.u=0),e&&e.date1904&&(n+=1462),a.u>.9999&&(a.u=0,86400===++o&&(a.T=o=0,++n,++a.D)),60===n)i=r?[1317,10,29]:[1900,2,29],s=3;else if(0===n)i=r?[1317,8,29]:[1900,1,0],s=6;else{n>60&&--n;var l=new Date(1900,0,1);l.setDate(l.getDate()+n-1),i=[l.getFullYear(),l.getMonth()+1,l.getDate()],s=l.getDay(),n<60&&(s=(s+6)%7),r&&(s=function(t,e){e[0]-=581;var r=t.getDay();t<60&&(r=(r+6)%7);return r}(l,i))}return a.y=i[0],a.m=i[1],a.d=i[2],a.S=o%60,o=Math.floor(o/60),a.M=o%60,o=Math.floor(o/60),a.H=o,a.q=s,a}var rn=new Date(1899,11,31,0,0,0),nn=rn.getTime(),on=new Date(1900,2,1,0,0,0);function sn(t,e=!1){var r=t.getTime();return e?r-=1262304e5:t>=on&&(r+=864e5),(r-(nn+6e4*(t.getTimezoneOffset()-rn.getTimezoneOffset())))/864e5}function an(t){return-1===t.indexOf(".")?t:t.replace(/(?:\.0*|(\.\d*[1-9])0+)$/,"$1")}function ln(t){var e,r=Math.floor(Math.log(Math.abs(t))*Math.LOG10E);return e=r>=-4&&r<=-1?t.toPrecision(10+r):Math.abs(r)<=9?function(t){var e=t<0?12:11,r=an(t.toFixed(12));return r.length<=e||(r=t.toPrecision(10)).length<=e?r:t.toExponential(5)}(t):10===r?t.toFixed(10).substr(0,12):function(t){var e=an(t.toFixed(11));return e.length>(t<0?12:11)||"0"===e||"-0"===e?t.toPrecision(6):e}(t),an(function(t){return-1===t.indexOf("E")?t:t.replace(/(?:\.0*|(\.\d*[1-9])0+)[Ee]/,"$1E").replace(/(E[+-])(\d)$/,"$10$2")}(e.toUpperCase()))}function cn(t,e){switch(typeof t){case"string":return t;case"boolean":return t?"TRUE":"FALSE";case"number":return(0|t)===t?t.toString(10):ln(t);case"undefined":return"";case"object":if(null==t)return"";if(Pr(t))return Fn(14,sn(t,e&&e.date1904),e)}throw new Error("unsupported value in General format: "+t)}function hn(t,e,r,n){var o,s="",i=0,a=0,l=r.y,c=0;switch(t){case 98:l=r.y+543;case 121:switch(e.length){case 1:case 2:o=l%100,c=2;break;default:o=l%1e4,c=4}break;case 109:switch(e.length){case 1:case 2:o=r.m,c=e.length;break;case 3:return Kr[r.m-1][1];case 5:return Kr[r.m-1][0];default:return Kr[r.m-1][2]}break;case 100:switch(e.length){case 1:case 2:o=r.d,c=e.length;break;case 3:return Xr[r.q][0];default:return Xr[r.q][1]}break;case 104:switch(e.length){case 1:case 2:o=1+(r.H+11)%12,c=e.length;break;default:throw new Error("bad hour format: "+e)}break;case 72:switch(e.length){case 1:case 2:o=r.H,c=e.length;break;default:throw new Error("bad hour format: "+e)}break;case 77:switch(e.length){case 1:case 2:o=r.M,c=e.length;break;default:throw new Error("bad minute format: "+e)}break;case 115:if("s"!==e&&"ss"!==e&&".0"!==e&&".00"!==e&&".000"!==e)throw new Error("bad second format: "+e);return 0!==r.u||"s"!==e&&"ss"!==e?(a=n>=2?3===n?1e3:100:1===n?10:1,(i=Math.round(a*(r.S+r.u)))>=60*a&&(i=0),"s"===e?0===i?"0":""+i/a:(s=$r(i,2+n),"ss"===e?s.substr(0,2):"."+s.substr(2,e.length-1))):$r(r.S,e.length);case 90:switch(e){case"[h]":case"[hh]":o=24*r.D+r.H;break;case"[m]":case"[mm]":o=60*(24*r.D+r.H)+r.M;break;case"[s]":case"[ss]":o=60*(60*(24*r.D+r.H)+r.M)+Math.round(r.S+r.u);break;default:throw new Error("bad absolute time format: "+e)}c=3===e.length?1:2;break;case 101:o=l,c=1}return c>0?$r(o,c):""}function dn(t){if(t.length<=3)return t;for(var e=t.length%3,r=t.substr(0,e);e!==t.length;e+=3)r+=(r.length>0?",":"")+t.substr(e,3);return r}var un=/%/g;function gn(t,e){var r,n=t.indexOf("E")-t.indexOf(".")-1;if(t.match(/^#+0.0E\+0$/)){if(0===e)return"0.0E+0";if(e<0)return"-"+gn(t,-e);var o=t.indexOf(".");-1===o&&(o=t.indexOf("E"));var s=Math.floor(Math.log(e)*Math.LOG10E)%o;if(s<0&&(s+=o),-1===(r=(e/Math.pow(10,s)).toPrecision(n+1+(o+s)%o)).indexOf("e")){var i=Math.floor(Math.log(e)*Math.LOG10E);for(-1===r.indexOf(".")?r=r.charAt(0)+"."+r.substr(1)+"E+"+(i-r.length+s):r+="E+"+(i-s);"0."===r.substr(0,2);)r=(r=r.charAt(0)+r.substr(2,o)+"."+r.substr(2+o)).replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0.");r=r.replace(/\+-/,"-")}r=r.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function(t,e,r,n){return e+r+n.substr(0,(o+s)%o)+"."+n.substr(s)+"E"})}else r=e.toExponential(n);return t.match(/E\+00$/)&&r.match(/e[+-]\d$/)&&(r=r.substr(0,r.length-1)+"0"+r.charAt(r.length-1)),t.match(/E-/)&&r.match(/e\+/)&&(r=r.replace(/e\+/,"e")),r.replace("e","E")}var pn=/[0#?] (\?+)( ?)\/( ?)(\d+)/;var mn=/^([0#?]+)\.([0#?]+)/,fn=/\).*[0#]/,_n=/\(###\) ###\\?-####/;function Sn(t){var e="";let r,n=t.length;for(var o=0;o!==n;++o)switch(r=t.charAt(o),r){case"#":break;case" ":e+=" ";break;case"0":e+="0";break;case"?":e+="?";break;default:e+=String.fromCharCode(cc)}return e}function wn(t,e){var r=Math.pow(10,e);return""+Math.round(t*r)/r}function yn(t,e){var r=Math.pow(10,e);return Math.round(t*r)/r}function xn(t,e){var r=t-Math.floor(t),n=Math.pow(10,e);return e<(""+Math.round(r*n)).length?0:Math.round(r*n)}function Cn(t,e,r){if(40===t.charCodeAt(0)&&!e.match(fn)){var n=e.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");return r>=0?Cn("n",n,r):"("+Cn("n",n,-r)+")"}if(44===e.charCodeAt(e.length-1))return function(t,e,r){let n=e.length-1;for(;44===e.charCodeAt(n-1);)--n;return vn(t,e.substr(0,n),r/Math.pow(10,3*(e.length-n)))}(t,e,r);if(-1!==e.indexOf("%"))return function(t,e,r){let n=e.replace(un,""),o=e.length-n.length;return vn(t,n,r*Math.pow(10,2*o))+Hr("%",o)}(t,e,r);if(-1!==e.indexOf("E"))return gn(e,r);if(36===e.charCodeAt(0))return"$"+Cn(t,e.substr(" "===e.charAt(1)?2:1),r);var o,s,i,a,l=Math.abs(r),c=r<0?"-":"";if(e.match(/^00+$/))return c+qr(l,e.length);if(e.match(/^[#?]+$/))return"0"===(o=qr(r,0))&&(o=""),o.length>e.length?o:Sn(e.substr(0,e.length-o.length))+o;if(s=e.match(pn))return function(t,e,r){var n=parseInt(t[4],10),o=Math.round(e*n),s=Math.floor(o/n),i=o-s*n,a=n;return r+(0===s?"":""+s)+" "+(0===i?Hr(" ",t[1].length+1+t[4].length):Ur(i,t[1].length)+t[2]+"/"+t[3]+$r(a,t[4].length))}(s,l,c);if(e.match(/^#+0+$/))return c+qr(l,e.length-e.indexOf("0"));if(s=e.match(mn)){i=Math.trunc(wn(r,s[2].length));var h=function(t){if(!isFinite(t))return 0;for(var e=1,r=0;Math.round(t*e)/e!==t;)e*=10,r++;return r}(a=yn(Math.abs(i-r),s[2].length));return a=(a=""+yn(a,h)).replace(/^0\./,""),o=jr(""+Math.abs(i),s[1])+"."+jr(""+a,s[2],!0),o=-1!==e.indexOf("0.")?o:o.replace(/^0\./,"."),r<0?"-"+o:o}if(s=(e=e.replace(/^#+([0.])/,"$1")).match(/^(0*)\.(#*)$/))return c+wn(l,s[2].length).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,s[1].length?"0.":".");if(s=e.match(/^#{1,3},##0(\.?)$/))return c+dn(qr(l,0));if(s=e.match(/^#,##0\.([#0]*0)$/))return r<0?"-"+Cn(t,e,-r):dn(""+(Math.floor(r)+function(t,e){return e<(""+Math.round((t-Math.floor(t))*Math.pow(10,e))).length?1:0}(r,s[1].length)))+"."+$r(xn(r,s[1].length),s[1].length);if(s=e.match(/^#,#*,#0/))return Cn(t,e.replace(/^#,#*,/,""),r);if(s=e.match(/^([0#]+)(\\?-([0#]+))+$/))return o=Vr(Cn(t,e.replace(/[\\-]/g,""),r)),i=0,Vr(Vr(e.replace(/\\/g,"")).replace(/[0#]/g,function(t){return i<o.length?o.charAt(i++):"0"===t?"0":""}));if(e.match(_n))return"("+(o=Cn(t,"##########",r)).substr(0,3)+") "+o.substr(3,3)+"-"+o.substr(6);var d="";if(s=e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(s[4].length,7),a=tn(l,Math.pow(10,i)-1,!1),o=""+c," "===(d=vn("n",s[1],a[1])).charAt(d.length-1)&&(d=d.substr(0,d.length-1)+"0"),o+=d+s[2]+"/"+s[3],(d=Gr(a[2],i)).length<s[4].length&&(d=Sn(s[4].substr(s[4].length-d.length))+d),o+=d;if(s=e.match(/[#0?] ([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(Math.max(s[1].length,s[4].length),7),a=tn(l,Math.pow(10,i)-1,!0),c+Cn(t,e.substring(0,s.index+1),a[0])+" "+(a[1]?Ur(a[1],i)+s[2]+"/"+s[3]+Gr(a[2],i):Hr(" ",2*i+1+s[2].length+s[3].length));if(s=e.match(/^[#0?]+$/))return o=qr(r,0),e.length<=o.length?o:Sn(e.substr(0,e.length-o.length))+o;if(s=e.match(/^([#0?]+)\.([#0]+)$/)){o=""+r.toFixed(Math.min(s[2].length,10)).replace(/([^0])0+$/,"$1"),i=o.indexOf(".");var u=e.indexOf(".")-i,g=e.length-o.length-u;return Sn(e.substr(0,u)+o+e.substr(e.length-g))}if(s=e.match(/^00,000\.([#0]*0)$/))return i=xn(r,s[1].length),r<0?"-"+Cn(t,e,-r):dn(function(t){return t<2147483647&&t>-2147483648?""+(t>=0?0|t:t-1|0):""+Math.floor(t)}(r)).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function(t){return"00,"+(t.length<3?$r(0,3-t.length):"")+t})+"."+$r(i,s[1].length);switch(e){case"###,##0.00":return Cn(t,"#,##0.00",r);case"###,###":case"##,###":case"#,###":var p=dn(qr(l,0));return"0"!==p?c+p:"";case"###,###.00":return Cn(t,"###,##0.00",r).replace(/^0\./,".");case"#,###.00":return Cn(t,"#,##0.00",r).replace(/^0\./,".")}throw new Error("unsupported format |"+e+"|")}function bn(t,e){var r,n=t.indexOf("E")-t.indexOf(".")-1;if(t.match(/^#+0.0E\+0$/)){if(0===e)return"0.0E+0";if(e<0)return"-"+bn(t,-e);var o=t.indexOf(".");-1===o&&(o=t.indexOf("E"));var s=Math.floor(Math.log(e)*Math.LOG10E)%o;if(s<0&&(s+=o),!(r=(e/Math.pow(10,s)).toPrecision(n+1+(o+s)%o)).match(/[Ee]/)){var i=Math.floor(Math.log(e)*Math.LOG10E);-1===r.indexOf(".")?r=r.charAt(0)+"."+r.substr(1)+"E+"+(i-r.length+s):r+="E+"+(i-s),r=r.replace(/\+-/,"-")}r=r.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function(t,e,r,n){return e+r+n.substr(0,(o+s)%o)+"."+n.substr(s)+"E"})}else r=e.toExponential(n);return t.match(/E\+00$/)&&r.match(/e[+-]\d$/)&&(r=r.substr(0,r.length-1)+"0"+r.charAt(r.length-1)),t.match(/E-/)&&r.match(/e\+/)&&(r=r.replace(/e\+/,"e")),r.replace("e","E")}function En(t,e,r){if(40===t.charCodeAt(0)&&!e.match(fn)){var n=e.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");return r>=0?En("n",n,r):"("+En("n",n,-r)+")"}if(44===e.charCodeAt(e.length-1))return function(t,e,r){for(var n=e.length-1;44===e.charCodeAt(n-1);)--n;return vn(t,e.substr(0,n),r/Math.pow(10,3*(e.length-n)))}(t,e,r);if(-1!==e.indexOf("%"))return function(t,e,r){var n=e.replace(un,""),o=e.length-n.length;return vn(t,n,r*Math.pow(10,2*o))+Hr("%",o)}(t,e,r);if(-1!==e.indexOf("E"))return bn(e,r);if(36===e.charCodeAt(0))return"$"+En(t,e.substr(" "===e.charAt(1)?2:1),r);var o,s,i,a,l=Math.abs(r),c=r<0?"-":"";if(e.match(/^00+$/))return c+$r(l,e.length);if(e.match(/^[#?]+$/))return o=""+r,0===r&&(o=""),o.length>e.length?o:Sn(e.substr(0,e.length-o.length))+o;if(s=e.match(pn))return function(t,e,r){return r+(0===e?"":""+e)+Hr(" ",t[1].length+2+t[4].length)}(s,l,c);if(e.match(/^#+0+$/))return c+$r(l,e.length-e.indexOf("0"));if(s=e.match(mn))return o=(""+r).replace(/^([^.]+)$/,"."+Sn(s[2])).replace(/\.$/,"."+Sn(s[2])),o=$r(Math.abs(r),s[1].length)+o.replace(/\.(\d*)$/,function(t,e){return"."+e+Hr("0",Sn(s[2]).length-e.length)}),o=-1!==e.indexOf("0.")?o:o.replace(/^0\./,"."),r<0?"-"+o:o;if(e=e.replace(/^#+([0.])/,"$1"),s=e.match(/^(0*)\.(#*)$/))return c+(""+l).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,s[1].length?"0.":".");if(s=e.match(/^#{1,3},##0(\.?)$/))return c+dn(""+l);if(s=e.match(/^#,##0\.([#0]*0)$/))return r<0?"-"+En(t,e,-r):dn(""+r)+"."+Hr("0",s[1].length);if(s=e.match(/^#,#*,#0/))return En(t,e.replace(/^#,#*,/,""),r);if(s=e.match(/^([0#]+)(\\?-([0#]+))+$/))return o=Vr(En(t,e.replace(/[\\-]/g,""),r)),i=0,Vr(Vr(e.replace(/\\/g,"")).replace(/[0#]/g,function(t){return i<o.length?o.charAt(i++):"0"===t?"0":""}));if(e.match(_n))return"("+(o=En(t,"##########",r)).substr(0,3)+") "+o.substr(3,3)+"-"+o.substr(6);var h="";if(s=e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(s[4].length,7),a=tn(l,Math.pow(10,i)-1,!1),o=""+c," "===(h=vn("n",s[1],a[1])).charAt(h.length-1)&&(h=h.substr(0,h.length-1)+"0"),o+=h+s[2]+"/"+s[3],(h=Gr(a[2],i)).length<s[4].length&&(h=Sn(s[4].substr(s[4].length-h.length))+h),o+=h;if(s=e.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(Math.max(s[1].length,s[4].length),7),c+((a=tn(l,Math.pow(10,i)-1,!0))[0]||(a[1]?"":"0"))+" "+(a[1]?Ur(a[1],i)+s[2]+"/"+s[3]+Gr(a[2],i):Hr(" ",2*i+1+s[2].length+s[3].length));if(s=e.match(/^[#0?]+$/))return o=""+r,e.length<=o.length?o:Sn(e.substr(0,e.length-o.length))+o;if(s=e.match(/^([#0]+)\.([#0]+)$/)){o=""+r.toFixed(Math.min(s[2].length,10)).replace(/([^0])0+$/,"$1"),i=o.indexOf(".");var d=e.indexOf(".")-i,u=e.length-o.length-d;return Sn(e.substr(0,d)+o+e.substr(e.length-u))}if(s=e.match(/^00,000\.([#0]*0)$/))return r<0?"-"+En(t,e,-r):dn(""+r).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function(t){return"00,"+(t.length<3?$r(0,3-t.length):"")+t})+"."+$r(0,s[1].length);switch(e){case"###,###":case"##,###":case"#,###":var g=dn(""+l);return"0"!==g?c+g:"";default:if(e.match(/\.[0#?]*$/))return En(t,e.slice(0,e.lastIndexOf(".")),r)+Sn(e.slice(e.lastIndexOf(".")))}throw new Error("unsupported format |"+e+"|")}function vn(t,e,r){return(0|r)===r?En(t,e,r):Cn(t,e,r)}function In(t){var e=[],r=!1;const n=t.length;for(var o=0,s=0;o<n;++o)switch(t.charCodeAt(o)){case 34:r=!r;break;case 95:case 42:case 92:++o;break;case 59:e[e.length]=t.substr(s,o-s),s=o+1}if(e[e.length]=t.substr(s),!0===r)throw new Error("Format |"+t+"| unterminated string ");return e}var An=/\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/;function Rn(t){for(var e=0,r="",n="",o=t.length;e<o;)switch(r=t.charAt(e)){case"G":Jr(t,e)&&(e+=6),e++;break;case'"':for(;34!==t.charCodeAt(++e)&&e<t.length;);++e;break;case"\\":case"_":e+=2;break;case"@":++e;break;case"B":case"b":if("1"===t.charAt(e+1)||"2"===t.charAt(e+1))return!0;case"M":case"D":case"Y":case"H":case"S":case"E":case"m":case"d":case"y":case"h":case"s":case"e":case"g":return!0;case"A":case"a":case"上":if("A/P"===t.substr(e,3).toUpperCase())return!0;if("AM/PM"===t.substr(e,5).toUpperCase())return!0;if("上午/下午"===t.substr(e,5).toUpperCase())return!0;++e;break;case"[":for(n=r;"]"!==t.charAt(e++)&&e<t.length;)n+=t.charAt(e);if(n.match(An))return!0;break;case".":case"0":case"#":for(;e<t.length&&("0#?.,E+-%".indexOf(r=t.charAt(++e))>-1||"\\"===r&&"-"===t.charAt(e+1)&&"0#".indexOf(t.charAt(e+2))>-1););break;case"?":for(;t.charAt(++e)===r;);break;case"*":++e," "!==t.charAt(e)&&"*"!==t.charAt(e)||++e;break;case"(":case")":++e;break;case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":for(;e<t.length&&"0123456789".indexOf(t.charAt(++e))>-1;);break;default:++e}return!1}var Mn=/\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;function Tn(t,e){if(null==e)return!1;var r=parseFloat(e[2]);switch(e[1]){case"=":if(t===r)return!0;break;case">":if(t>r)return!0;break;case"<":if(t<r)return!0;break;case"<>":if(t!==r)return!0;break;case">=":if(t>=r)return!0;break;case"<=":if(t<=r)return!0}return!1}function Fn(t,e,r){null==r&&(r=mt.EmptyObject);var n="";switch(typeof t){case"string":n="m/d/yy"===t&&r.dateNF?r.dateNF:t;break;case"number":null==(n=14===t&&r.dateNF?r.dateNF:(null!=r.table?r.table:Yr)[t])&&(n=r.table&&r.table[Zr[t]]||Yr[Zr[t]]),null==n&&(n=Qr[t]||"General")}if(Jr(n,0))return cn(e,r);Pr(e)&&(e=sn(e,r.date1904));var o=function(t,e){var r=In(t),n=r.length,o=r[n-1].indexOf("@");if(-1!==o&&"\\"===r[n-1][o-1]&&(o=-1),n<4&&o>-1&&--n,r.length>4)throw new Error("We can't find right format for |"+r.join("|")+"|");if("number"!=typeof e)return[4,4===r.length||o>-1?r[r.length-1]:"@"];switch(r.length){case 1:r=o>-1?["General","General","General",r[0]]:[r[0],r[0],r[0],"@"];break;case 2:r=o>-1?[r[0],r[0],r[0],r[1]]:[r[0],r[1],r[0],"@"];break;case 3:r=o>-1?[r[0],r[1],r[0],r[2]]:[r[0],r[1],r[2],"@"]}var s=e>0?r[0]:e<0?r[1]:r[2];if(-1===r[0].indexOf("[")&&-1===r[1].indexOf("["))return[n,s];if(null!=r[0].match(/\[[=<>]/)||null!=r[1].match(/\[[=<>]/)){var i=r[0].match(Mn),a=r[1].match(Mn);return Tn(e,i)?[n,r[0]]:Tn(e,a)?[n,r[1]]:[n,r[null!=i&&null!=a?2:1]]}return[n,s]}(n,e);if(Jr(o[1]))return cn(e,r);if(!0===e)e="TRUE";else if(!1===e)e="FALSE";else if(""===e||null==e)return"";return function(t,e,r,n){var o,s,i,a=[],l="",c=0,h="",d="t",u="H";let g=t.length;for(;c<g;)switch(h=t.charAt(c)){case"G":if(!Jr(t,c))throw new Error("unrecognized character "+h+" in "+t);a[a.length]={t:"G",v:"General"},c+=7;break;case'"':for(l="";34!==(i=t.charCodeAt(++c))&&c<t.length;)l+=String.fromCharCode(i);a[a.length]={t:"t",v:l},++c;break;case"\\":var p=t.charAt(++c),m="("===p||")"===p?p:"t";a[a.length]={t:m,v:p},++c;break;case"@":a[a.length]={t:"T",v:e},++c;break;case"B":case"b":if("1"===t.charAt(c+1)||"2"===t.charAt(c+1)){if(null==o&&null==(o=en(e,r,"2"===t.charAt(c+1))))return"";a[a.length]={t:"X",v:t.substr(c,2)},d=h,c+=2;break}case"M":case"D":case"Y":case"H":case"S":case"E":h=h.toLowerCase();case"m":case"d":case"y":case"h":case"s":case"e":case"g":if(e<0)return"";if(null==o&&null==(o=en(e,r)))return"";for(l=h;++c<t.length&&t.charAt(c).toLowerCase()===h;)l+=h;"m"===h&&"h"===d.toLowerCase()&&(h="M"),"h"===h&&(h=u),a[a.length]={t:h,v:l},d=h;break;case"A":case"a":case"上":var f={t:h,v:h};if(null==o&&(o=en(e,r)),"A/P"===t.substr(c,3).toUpperCase()?(null!=o&&(f.v=o.H>=12?"P":"A"),f.t="T",u="h",c+=3):"AM/PM"===t.substr(c,5).toUpperCase()?(null!=o&&(f.v=o.H>=12?"PM":"AM"),f.t="T",c+=5,u="h"):"上午/下午"===t.substr(c,5).toUpperCase()?(null!=o&&(f.v=o.H>=12?"下午":"上午"),f.t="T",c+=5,u="h"):(f.t="t",++c),null==o&&"T"===f.t)return"";a[a.length]=f,d=h;break;case"[":for(l=h;"]"!==t.charAt(c++)&&c<t.length;)l+=t.charAt(c);if("]"!==l.slice(-1))throw new Error('unterminated "[" block: |'+l+"|");if(l.match(An)){if(null==o&&null==(o=en(e,r)))return"";a[a.length]={t:"Z",v:l.toLowerCase()},d=l.charAt(1)}else l.indexOf("$")>-1&&(l=(l.match(/\$([^-[\]]*)/)||[])[1]||"$",Rn(t)||(a[a.length]={t:"t",v:l}));break;case".":if(null!=o){for(l=h;++c<t.length&&"0"===(h=t.charAt(c));)l+=h;a[a.length]={t:"s",v:l};break}case"0":case"#":for(l=h;++c<t.length&&"0#?.,E+-%".indexOf(h=t.charAt(c))>-1;)l+=h;a[a.length]={t:"n",v:l};break;case"?":for(l=h;t.charAt(++c)===h;)l+=h;a[a.length]={t:h,v:l},d=h;break;case"*":if(++c,!(l=t.charAt(c)))throw new Error("no character specified for repeat function: "+t);a[a.length]={t:"R",v:l},++c;break;case"_":if(++c,!(l=t.charAt(c)))throw new Error("no character specified for spacing function: "+t);a[a.length]={t:"S",v:l},++c;break;case"(":case")":a[a.length]={t:1===n?"t":h,v:h},++c;break;case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":for(l=h;c<t.length&&"0123456789".indexOf(t.charAt(++c))>-1;)l+=t.charAt(c);a[a.length]={t:"D",v:l};break;case" ":a[a.length]={t:h,v:h},++c;break;case"$":a[a.length]={t:"t",v:"$"},++c;break;default:if(-1===",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(h))throw new Error("unrecognized character "+h+" in "+t);a[a.length]={t:"t",v:h},++c}var _,S=0,w=0;for(c=a.length-1,d="t";c>=0;--c)switch(a[c].t){case"h":case"H":a[c].t=u,d="h",S<1&&(S=1);break;case"s":(_=a[c].v.match(/\.0+$/))&&(w=Math.max(w,_[0].length-1)),S<3&&(S=3);case"d":case"y":case"M":case"e":d=a[c].t;break;case"m":"s"===d&&(a[c].t="M",S<2&&(S=2));break;case"X":break;case"Z":S<1&&a[c].v.match(/[Hh]/)&&(S=1),S<2&&a[c].v.match(/[Mm]/)&&(S=2),S<3&&a[c].v.match(/[Ss]/)&&(S=3)}switch(S){case 0:break;case 1:o.u>=.5&&(o.u=0,++o.S),o.S>=60&&(o.S=0,++o.M),o.M>=60&&(o.M=0,++o.H);break;case 2:o.u>=.5&&(o.u=0,++o.S),o.S>=60&&(o.S=0,++o.M)}var y,x="";for(g=a.length,c=0;c<g;++c)switch(a[c].t){case"t":case"T":case" ":case"D":break;case"X":a[c].v="",a[c].t=";";break;case"d":case"m":case"y":case"h":case"H":case"M":case"s":case"e":case"b":case"Z":a[c].v=hn(a[c].t.charCodeAt(0),a[c].v,o,w),a[c].t="t";break;case"n":case"?":for(y=c+1;null!=a[y]&&("?"===(h=a[y].t)||"D"===h||(" "===h||"t"===h)&&null!=a[y+1]&&("?"===a[y+1].t||"t"===a[y+1].t&&"/"===a[y+1].v)||"("===a[c].t&&(" "===h||"n"===h||")"===h)||"t"===h&&("/"===a[y].v||" "===a[y].v&&null!=a[y+1]&&"?"===a[y+1].t));)a[c].v+=a[y].v,a[y]={v:"",t:";"},++y;x+=a[c].v,c=y-1;break;case"G":a[c].t="t",a[c].v=cn(e,r)}var C,b,E="";if(x.length>0){40===x.charCodeAt(0)?(C=e<0&&45===x.charCodeAt(0)?-e:e,b=vn("n",x,C)):(b=vn("n",x,C=e<0&&n>1?-e:e),C<0&&a[0]&&"t"===a[0].t&&(b=b.substr(1),a[0].v="-"+a[0].v)),y=b.length-1;var v=a.length;for(g=a.length,c=0;c<g;++c)if(null!=a[c]&&"t"!==a[c].t&&a[c].v.indexOf(".")>-1){v=c;break}var I=g;if(v===g&&-1===b.indexOf("E")){for(c=a.length-1;c>=0;--c)null!=a[c]&&-1!=="n?".indexOf(a[c].t)&&(y>=a[c].v.length-1?(y-=a[c].v.length,a[c].v=b.substr(y+1,a[c].v.length)):y<0?a[c].v="":(a[c].v=b.substr(0,y+1),y=-1),a[c].t=a[c].v.indexOf("?")>=0?"N":"t",I=c);y>=0&&I<a.length&&(a[I].v=b.substr(0,y+1)+a[I].v)}else if(v!==a.length&&-1===b.indexOf("E")){for(y=b.indexOf(".")-1,c=v;c>=0;--c)if(null!=a[c]&&-1!=="n?".indexOf(a[c].t)){for(s=a[c].v.indexOf(".")>-1&&c===v?a[c].v.indexOf(".")-1:a[c].v.length-1,E=a[c].v.substr(s+1);s>=0;--s)y>=0&&("0"===a[c].v.charAt(s)||"#"===a[c].v.charAt(s)||"?"===a[c].v.charAt(s))&&(E=b.charAt(y--)+E);a[c].v=E,a[c].t=E.indexOf("?")>=0?"N":"t",I=c}for(y>=0&&I<a.length&&(a[I].v=b.substr(0,y+1)+a[I].v),y=b.indexOf(".")+1,c=v;c<a.length;++c)if(null!=a[c]&&(-1!=="n?(".indexOf(a[c].t)||c===v)){for(s=a[c].v.indexOf(".")>-1&&c===v?a[c].v.indexOf(".")+1:0,E=a[c].v.substr(0,s);s<a[c].v.length;++s)y<b.length&&(E+=b.charAt(y++));a[c].v=E,a[c].t=E.indexOf("?")>=0?"N":"t",I=c}}}for(c=0;c<g;++c)null!=a[c]&&"n?".indexOf(a[c].t)>-1&&(C=n>1&&e<0&&c>0&&"-"===a[c-1].v?-e:e,a[c].v=vn(a[c].t,a[c].v,C),a[c].t=a[c].v.indexOf("?")>=0?"N":"t");var A="";for(g=a.length,c=0;c<g;c++)if("R"===a[c].t)r?.onRepeatChar?.(A.length,a[c].v);else if("S"===a[c].t)r?.onSpacingChar?.(A.length,a[c].v),A+=r?.spacingCharacter??" ";else if("N"===a[c].t){E=a[c].v;for(var R=0;R<E.length;R++)"?"===(h=E[R])&&(r?.onDigitChar?.(A.length,h),h=r?.digitCharacter??" "),A+=h}else null!=a[c]&&(A+=a[c].v);return A}(o[1],e,r,o[0])}function Nn(t,e){if("number"!=typeof e){e=+e||-1;for(var r=0;r<392;++r)if(void 0!==Yr[r]){if(Yr[r]===t){e=r;break}}else e<0&&(e=r);e<0&&(e=391)}return Yr[e]=t,e}const kn={format:Fn,dateNumLocal:sn,load:Nn,split_fmt:In,_table:Yr,load_table:function(t){for(var e=0;392!==e;++e)void 0!==t[e]&&Nn(t[e],e)},parse_date_code:en,is_date:Rn,get_table:function(){return kn._table=Yr}},On="\\s*([-]?[0-9e]*[.]?[0-9]+)",Bn=new RegExp(`^rgb\\(${On},${On},${On}\\)$`),Ln=new RegExp(`^rgba\\(${On},${On},${On},${On}\\)$`),Dn=new RegExp(`^lrgb\\(${On},${On},${On}\\)$`),zn=new RegExp(`^lrgba\\(${On},${On},${On},${On}\\)$`),Pn=new RegExp(`^hsl\\(${On},${On},${On}\\)$`),jn=new RegExp(`^hsla\\(${On},${On},${On},${On}\\)$`),Hn=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),Vn=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),$n=new RegExp("^index(\\d+)$","i"),Un=(t,e,r)=>[parseFloat(t),parseFloat(e),parseFloat(r)],Gn=(t,e=255)=>{const r=[...t];for(var n=0;n<t.length;n++)r[n]=t[n]/e;return r},Wn=(t,e=0)=>{const r=[...t];for(var n=0;n<t.length;n++)mt.roundAccurately(t[n],e+8)%1==.5?r[n]=Math.floor(t[n]):r[n]=mt.roundAccurately(t[n],e);return r},qn=(t,e=!0)=>{const r=[...t],n=e?1:255;for(var o=0;o<t.length;o++)r[o]=Math.max(0,Math.min(n,t[o]));return r},Jn=t=>Math.max(0,Math.min(1,t)),Xn=t=>((t%=360)<0&&(t-=360),t),Kn=t=>{const e=[...t];for(var r=0;r<t.length;r++)e[r]=Zn(t[r]);return e},Yn=t=>{const e=[...t];for(var r=0;r<t.length;r++)e[r]=Qn(t[r]);return e},Zn=t=>t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),Qn=t=>t<.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,to=t=>{let e=t[0],r=t[1],n=t[2];e%=360,e/=360,r/=100,n/=100;let o=n<.5?n*(1+r):n+r-r*n,s=2*n-o;return[Math.max(0,eo(s,o,e+1/3)),Math.max(0,eo(s,o,e)),Math.max(0,eo(s,o,e-1/3))]},eo=(t,e,r)=>(r<0&&(r+=1),r>1&&(r-=1),6*r<1?t+6*(e-t)*r:2*r<1?e:3*r<2?t+6*(e-t)*(2/3-r):t),ro=t=>{let e=t[0],r=t[1],n=t[2],o=Math.min(e,Math.min(r,n)),s=Math.max(e,Math.max(r,n)),i=0;s===o?i=0:s===e?i=(60*(r-n)/(s-o)+360)%360:s===r?i=60*(n-e)/(s-o)+120:s===n&&(i=60*(e-r)/(s-o)+240);const a=(s+o)/2;let l=0;return l=s===o?0:a<=.5?(s-o)/(s+o):(s-o)/(2-s-o),[i,100*l,100*a]},no=0,oo=1,so=2,io=0,ao=1,lo=2,co=0,ho=1,uo=2,go=(t,e)=>{let r=e/100;return((t,e)=>{let r=Kn(t);r[0]=e(r[0],r),r[1]=e(r[1],r),r[2]=e(r[2],r);let n=Yn(r);return n=qn(n),n})(t,(t,e)=>t*r)},po=2.55,mo=(t,e)=>{const r=ro(t),n=r[2],o=mt.roundAccurately((s=n,(i=e)>0?(s*po*(1-i)+(255-255*(1-i)))/po:i<0?s*po*(1+i)/po:s),3);var s,i;r[2]=o;let a=to(r);return a=qn(a),a},fo=(t,e)=>{let r=Kn(t),n=e/100;for(var o=0;o<3;o++)r[o]=r[o]*n+(1-n);let s=Yn(r);return s=qn(s),s},_o=(t,e,r)=>{let n=ro(e),o=r/1;t===no&&(o=Xn(r)),n[t]=o;let s=to(n);return s=qn(s),s},So=(t,e,r)=>{let n=ro(e);if(t===no){let t=r/360;n[no]=360*(n[no]/360+t),n[no]%=360,n[no]<0&&(n[no]-=360)}else{let e=r/.1;n[t]=.1*(n[t]/.1+e)}let o=to(n);return o=qn(o),o},wo=(t,e,r)=>{let n=ro(e),o=r/100;n[t]=n[t]*o,t===no&&(n[no]=Xn(n[no]));let s=to(n);return s=qn(s),s},yo=(t,e,r,n)=>{let o=Kn(e),s=r/100;n===co?o[t]=s:n===ho?o[t]+=s:n===uo&&(o[t]*=s);let i=Yn(o);return i=qn(i),i},xo=t=>{let e=Kn(t),r=.213*e[io]+.715*e[ao]+.072*e[lo];e[0]=r,e[1]=r,e[2]=r;let n=Yn(e);return n=qn(n),n},Co=t=>{let e=ro(t);e[no]+=180,e[no]%=360,e[no]<0&&(e[no]-=360);let r=to(e);return r=qn(r),r},bo=(t,e=!0)=>{let r=e?Kn(t):[...t];const n=e?1:255;return r[0]=n-r[0],r[1]=n-r[1],r[2]=n-r[2],e&&(r=Yn(r)),r=qn(r,e),r},Eo=t=>{const e=[0,0,0];e[0]=Qn(t[0]),e[1]=Qn(t[1]),e[2]=Qn(t[2]);return qn(e)},vo=t=>{const e=[0,0,0];e[0]=Zn(t[0]),e[1]=Zn(t[1]),e[2]=Zn(t[2]);return qn(e)},Io=(t,e,r,n=null)=>{const o=t=>{let e=t.toString(16);return 1===e.length?"0"+e:e};return(null===n?"":o(Math.round(255*n)))+o(Number(t)).toUpperCase()+o(Number(e)).toUpperCase()+o(Number(r)).toUpperCase()},Ao=.2126,Ro=.7152,Mo=.0722;var To;(t=>{t.RGBA=class{constructor(t,e,r,n=1){this._private={red:t,green:e,blue:r,alpha:n}}get red(){return this._private.red}get green(){return this._private.green}get blue(){return this._private.blue}get alpha(){return this._private.alpha??1}toString(t=!0){return t&&null!==this._private.alpha?`rgba(${this.red},${this.green},${this.blue},${this.alpha})`:`rgb(${this.red},${this.green},${this.blue})`}isEqual(t){return!!t&&(t.red===this.red&&(t.green===this.green&&(t.blue===this.blue&&t.alpha===this.alpha)))}isAlmostEqual(t){if(!t)return!1;const e=1.5;return!(Math.abs(t.red-this.red)>e)&&(!(Math.abs(t.green-this.green)>e)&&(!(Math.abs(t.blue-this.blue)>e)&&!(Math.abs(t.alpha-this.alpha)>e)))}};t.HSLA=class{constructor(t,e,r,n){this._private={hue:t,sat:e,lum:r,alpha:n}}get hue(){return this._private.hue}get sat(){return this._private.sat}get lum(){return this._private.lum}get alpha(){return this._private.alpha??1}toString(t=!0){return t&&null!==this._private.alpha?`hsla(${this.hue},${this.sat},${this.lum},${this.alpha})`:`hsl(${this.hue},${this.sat},${this.lum})`}isEqual(t){return!!t&&(t.hue===this.hue&&(t.sat===this.sat&&(t.lum===this.lum&&t.alpha===this.alpha)))}isAlmostEqual(t){if(!t)return!1;const e=1.5;return!(Math.abs(t.hue-this.hue)>e)&&(!(Math.abs(t.sat-this.sat)>e)&&(!(Math.abs(t.lum-this.lum)>e)&&!(Math.abs(t.alpha-this.alpha)>e)))}};class e extends t.RGBA{toString(t=!0){return t&&null!==this._private.alpha?"#"+Io(this.red,this.green,this.blue,this.alpha??1).toUpperCase():"#"+Io(this.red,this.green,this.blue).toUpperCase()}}t.HEX=e})(To||(To={}));const Fo=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,No=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,ko=function(t){if(!t)return null;t=t.replace(Fo,function(t,e,r,n){return e+e+r+r+n+n});let e=No.exec(t);return e?new To.RGBA(parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)):null},Oo=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"],Bo=new Map;for(let t=0;t<Oo.length;t++)Bo.set(t,ko(Oo[t]));Bo.set(-4105,null),Bo.set(-4142,null),Bo.set(64,ko("000000")),Bo.set(65,ko("FFFFFF")),Bo.set(81,ko("FFFFFF"));const Lo=t=>Bo.get(t),Do={General:"General",Number:"Number",Currency:"Currency",Accounting:"Accounting",ShortDate:"Short Date",LongDate:"Long Date",MediumDate:"Medium Date",ShortTime:"Short Time",MediumTime:"Medium Time",LongTime:"Long Time",Comma:"Comma",Percentage:"Percentage",Fraction:"Fraction",Scientific:"Scientific",Text:"Text",Special:"Special",Custom:"Custom"};let zo=null;const Po=()=>zo||(zo=Intl.DateTimeFormat().resolvedOptions().locale??"en-US",zo),jo=/^\[\$-(.*?)\]/i,Ho=/^[0-9a-fA-F]+$/,Vo=kn.split_fmt,$o=(t,e,r)=>{const n=jo.exec(t);let o=Po();if(n&&n[1]){let t=n[1];Ho.test(t)||t.includes("-")}if(Go[t]&&(t=Go[t]),"number"==typeof e){const n=Uo(t,e,{locale:o,...r});if(null!==n)return n.fmt}return kn.format(t,e,r)},Uo=(t,e,r)=>{if("number"!=typeof e)return null;const n=ps(e,r?.date1904??!1),o=r?.locale??Po();let s=!1,i=t,a=-1;if(-1!==(a=i.indexOf("Short Date"))){const t=new Intl.DateTimeFormat(o).format(n);i=i.substring(0,a)+t+i.substring(a+10),s=!0}if(-1!==(a=i.indexOf("Medium Date"))){const t=kn.format(kn.get_table()[15],e,r);i=i.substring(0,a)+t+i.substring(a+11),s=!0}if(-1!==(a=i.indexOf("Long Date"))){const t=new Intl.DateTimeFormat(o,{dateStyle:"full"}).format(n);i=i.substring(0,a)+t+i.substring(a+9),s=!0}if(-1!==(a=i.indexOf("Short Time"))){const t=kn.format(kn.get_table()[20],e,r);i=i.substring(0,a)+t+i.substring(a+10),s=!0}if(-1!==(a=i.indexOf("Medium Time"))){const t=kn.format(kn.get_table()[18],e,r);i=i.substring(0,a)+t+i.substring(a+11),s=!0}if(-1!==(a=i.indexOf("Long Time"))){const t=new Intl.DateTimeFormat(o,{timeStyle:"medium"}).format(n);i=i.substring(0,a)+t+i.substring(a+9),s=!0}return s?{fmt:i,date:n}:null},Go=Object.freeze({"General Number":"General","General Date":"m/d/yyyy h:mm","Medium Date":kn.get_table()[15],"Medium Time":kn.get_table()[18],"Short Time":kn.get_table()[20],Currency:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',Fixed:kn.get_table()[2],Standard:kn.get_table()[4],Percent:kn.get_table()[10],Scientific:kn.get_table()[11],"Yes/No":'"Yes";"Yes";"No";@',"True/False":'"True";"True";"False";@',"On/Off":'"Yes";"Yes";"No";@'}),Wo=Object.freeze({black:0,white:1,red:2,green:3,blue:4,yellow:5,magenta:6,cyan:7}),qo=t=>{let e=null;if((t=t.toLowerCase()).startsWith("color")){const r=parseInt(t.substring(5));r>=0&&r<=56&&(e=`Index${r+7}`)}if(!e){const r=Wo[t];void 0!==r&&(e=Lo(r).toString())}return e},Jo="=",Xo="<>",Ko=">",Yo="<",Zo=">=",Qo="<=",ts=new Map;ts.set(Jo,(t,e)=>t===e),ts.set(Xo,(t,e)=>t!==e),ts.set(Ko,(t,e)=>t>e),ts.set(Yo,(t,e)=>t<e),ts.set(Zo,(t,e)=>t>=e),ts.set(Qo,(t,e)=>t<=e);const es=/(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow|Color[0-9]+)/i,rs=/(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)/i,ns=/\[(.*?)\]/g,os=(t,e)=>{const r={color:null,condition:null};let n=null,o=new RegExp(ns);for(;null!==(n=o.exec(t));){let e=!1,o=es.exec(n[1]);if(o){if(e=!0,r.color)throw new Error(`format error, two colors specified: '${t}' and '${r.color}'.`);r.color=qo(o[1]),r.color||console.warn("Unable to parse LegacyColor",o[1])}let s=rs.exec(n[1]);if(s){if(e=!0,r.condition)throw new Error(`Format error, two conditions specified: ' ${t}'`);r.condition={op:s[1],comp:parseFloat(s[2])}}if(!e)return r}return r.condition||(r.condition=e),r},ss=(t,e)=>{let r=(t=>{const e=[];if(!t)return e;const r=t.split(";");for(let t=0;t<r.length;t++){let n=null;2===r.length?0===t?n={op:Zo,comp:0}:1===t&&(n={op:Yo,comp:0}):3!==r.length&&4!==r.length||(n=0===t?{op:Ko,comp:0}:1===t?{op:Yo,comp:0}:2===t?{op:Jo,comp:0}:null);const o=r[t],s=os(o,n);e.push({format:o,colorAndCondition:s})}return e})(t),n=r[0].colorAndCondition;if(1===r.length&&n&&!n.condition&&n.color)return n.color;for(let t=0;t<r.length;t++){n=r[t].colorAndCondition;let o=n?.condition??void 0;if(3===t)return"string"==typeof e&&n?.color?n.color:null;if(o&&"number"==typeof e){if(ts.get(o.op)(e,o.comp))return n?.color??null}}},is=t=>{if(t===Do.MediumDate||t===Do.LongDate||t===Do.ShortDate||t===Do.MediumTime||t===Do.LongTime||t===Do.ShortTime)return!0},as=(t,e)=>t===e?0:is(t)?1:is(e)?-1:t===Do.Percentage?1:e===Do.Percentage?-1:t===Do.Currency||t===Do.Accounting?1:e===Do.Currency||e===Do.Accounting?-1:0,ls=t=>(t instanceof Date||"[object Date]"===Object.prototype.toString.call(t))&&!isNaN(t.getTime()),cs=(t,e,r)=>{return"month"===r||"months"===r||"m"===r?(n=t,12*((o=e).getUTCFullYear()-n.getUTCFullYear())+(o.getUTCMonth()-n.getUTCMonth())+(o.getUTCDate()-n.getUTCDate()<0?-1:0)):"year"===r||"years"===r||"y"===r?((t,e)=>Math.abs(e.getFullYear()-t.getFullYear()))(t,e):"day"===r||"days"===r||"d"===r?((t,e)=>Math.floor((Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())-Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()))/864e5))(t,e):void console.warn("invalid unit"+r);var n,o},hs="d",ds="m",us="y",gs=(t,e,r)=>{if("month"===r||"months"===r||"m"===r){const r=new Date(t.getTime());return new Date(r.setMonth(r.getMonth()+e))}if("year"===r||"years"===r||"y"===r){const r=new Date(t.getTime());return r.setFullYear(r.getFullYear()+e),r}if("day"===r||"days"===r||"d"===r){const r=new Date(t.getTime());return r.setDate(r.getDate()+e),r}if("hour"===r||"hours"===r||"h"===r){const r=new Date(t.getTime());return r.setHours(r.getHours()+e),r}return console.warn("invalid unit"+r),null},ps=(t,e=!1)=>{let r=kn.parse_date_code(t,{date1904:e});return r?new Date(r.y,r.m-1,r.d,r.H,r.M,r.S,Math.round(1e3*r.u)):null},ms=(t,e=!1)=>isNaN(t)?null:kn.dateNumLocal(t,e),fs=new class extends Ir{parse(t,e,r){const n=t=>t-1;switch(e){case"M":return br(Er(_r,t),n);case"MM":return br(vr(2,t),n);case"Mo":return br(r.ordinalNumber(t,{unit:"month"}),n);case"MMM":return r.month(t,{width:"abbreviated",context:"formatting"});case"MMMMM":return r.month(t,{width:"narrow",context:"formatting"});default:return r.month(t,{width:"wide",context:"formatting"})}}},_s=(t=>{let e=t,r=[];for(let t=0;t<e.length;t++){let n=e[t][0].indexOf("yyy")>-1,o=e[t][0].indexOf(".")>-1,s=e[t][0].indexOf("-")>-1;r.push({parseFormat:e[t][0],numberFormat:e[t][1],todaysYear:!n,windowYear:!0,containsDot:o,containsDash:s}),n&&r.push({parseFormat:e[t][0].replace(/yyy/g,"yyyy"),numberFormat:e[t][1],todaysYear:!1,windowYear:!1,containsDot:o,containsDash:s})}return r})([["MM-d","d-mmm"],["MM-yyy","mmm-yy"],["M-yyy","mmm-yy"],["M-d-yyy","m/d/yyyy"],["yyy-M-d","m/d/yyyy"],["yyy-d-M","m/d/yyyy"],["d.MMM","d-mmm"],["d.MMMM","d-mmm"],["d.MMM.yyy","d-mmm-yy"],["d.MMMM.yyy","d-mmm-yy"],["MMM.d","d-mmm"],["MMMM.d","d-mmm"],["MMM.yyy","mmm-yy"],["MMMM.yyy","mmm-yy"],["MMM dd, yyy","d-mmm-yy"],["MMMM dd, yyy","d-mmm-yy"],["EEE, MMMM dd, yyy","[$-x-sysdate]ddd, mmmm dd, yyyy"],["EEEE, MMMM dd, yyy","[$-x-sysdate]dddd, mmmm dd, yyyy"]]),Ss={year:0,month:1,day:0,hour:0,minute:0,second:0,millis:0},ws=(t,e=!1)=>{const r={...Ss,...t};return r.year=e?1904:1900,r.dow=-1,r.oaDateTime=((t,e=!1)=>{if(!t)return null;let r=t.day,n=t.hour;n>24&&(r+=Math.floor(n/24),n%=24),r>60&&--r;const o=new Date(t.year,t.month-1,r,n,t.minute,t.second,t.millis);return ms(o,e)})(r,e),r},ys=new RegExp("([0-9]{1,2})\\s*(P[M]?|A[M]?)\\s*$","i"),xs=new RegExp("([0-9]+)\\s*\\:$","i"),Cs=new RegExp("(\\s*[0-9]{1,2})\\s+(P[M]?|A[M]?)\\s*$","i"),bs=new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]+)?\\s*\\:","i"),Es=new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]*)?\\s*$","i"),vs=(t,e=!1,r=!1)=>{if(!t||t.trim().length<2||-1===t.indexOf(":")&&null===t.match(Cs))return null;let n=null,o=null,s=null,i=!1,a=!1,l="h:mm AM/PM",c=[],h=t,d=null;do{let t=h.indexOf(":");-1===t?(c.push(h),h=null):(c.push(h.substring(0,t+1)),h=h.substring(t+1,h.length))}while(c.length<3&&h&&h.length>0);if(h?.length>0)return null;const u=(t,e,r)=>{let i=t.match(e);if(!i)return null;null===d&&(d=t.substring(0,i.index));let a=parseInt(i[1]);if(i[2]&&null===s){if(r){let t=parseFloat(i[2].substring(1,i[2].length));isNaN(t)||(o=t)}let t=parseFloat(i[2]);isNaN(t)||(n=t),s=r}return a},g=(t,e)=>{let r=t.match(e);if(!r||3!==r.length)return null;null===d&&(d=t.substring(0,r.index)),i=!0;let n=parseInt(r[1]);return a="p"===r[2].charAt(0)||"P"===r[2].charAt(0),n};0===c[c.length-1].trim().length&&c.pop();const p=[];if(c.length>0){let t=u(c[0],xs,!1);if(null===t&&(t=g(c[0],ys)),null===t)return null;p.push(t)}if(c.length>2){let t=u(c[1],bs,!0);if(null===t&&(t=g(c[0],Cs)),null===t)return null;p.push(t)}if(c.length>1){const t=c[c.length-1];let e=u(t,bs,!1);if(null===e&&(e=u(t,Es,!1)),null===e&&(e=g(t,Cs)),null===e)return null;p.push(e)}if(null!==d&&d.length>0&&!r)return null;if(!0===s&&(2===p.length&&p.splice(1,0,0),p[2]=o||0),i){if(p[0]>12)return null;if(p[1]>=60)return null;if(p[2]>=60)return null;12===p[0]?p[0]=a?12:0:a&&(p[0]+=12)}else l=c.length>2?"h:mm:ss":"h:mm",p[0]>23&&(l="[h]:mm:ss"),null!==n&&(l="mm:ss.0"),p[1]>=60&&(l="General"),p[2]>=60&&(l="General");"General"!==l&&(1===p.length&&p.push(0),2===p.length&&(null===n?p.push(0):p.unshift(0)));let m={hour:p[0]??0,minute:p[1]??0,second:p[2]??0,millis:1e3*(n??0)};return{numberFormat:l,parsed:ws(m,e),leadingText:d}},Is={},As=(t,e=!1,r=null)=>{const n=r??Date.now(),o=new Date(n).getFullYear();let s=t.trim().replaceAll(/\s+/g," ");s=s.replaceAll(/\s*([-/])\s*/g,"$1");let i=s.replaceAll(/[-/ ]/g,"."),a=s.replaceAll(/[/]/g,"-");const l=Tr.M;Tr.M=fs;for(let t=0;t<_s.length;t++){let r=s;_s[t].containsDot?r=i:_s[t].containsDash&&(r=a);let c=Dr(r,_s[t].parseFormat,n,Is),h=kn.dateNumLocal(c,e);if(ls(c)&&(_s[t].windowYear||h>0)){if(_s[t].windowYear){let t=c.getFullYear()<=29?2e3+c.getFullYear():1900+c.getFullYear();c.setFullYear(t)}if(_s[t].todaysYear&&c.setFullYear(o),h=kn.dateNumLocal(c,e),_s[t].parseFormat.indexOf("EEE")>-1){const t=$o("ddd",h,{date1904:e});if(!r.toLowerCase().includes(t.toLowerCase()))return null}let n=_s[t].numberFormat;return Tr.M=l,{asOADate:h,asJSDate:c,numberFormat:n}}}return Tr.M=l,null};function Rs(t){if(!t)return!1;let e=t.replaceAll(/\[([^)]+)\]/g,"").toLowerCase();return e=e.replaceAll(/".*"/g,""),e=e.replaceAll(/\\./g,""),e=e.replace(/[_*]./g,""),!e.includes("time")&&!!(e.includes("d")||e.includes("m")&&!e.includes("h")&&!e.includes("s")||e.includes("y")||"short date"===e||"medium date"===e||"long date"===e)}function Ms(t){if(!t)return!1;let e=t.replaceAll(/\[([^)]+)\]/g,"").toLowerCase();return e=e.replaceAll(/".*"/g,""),e=e.replaceAll(/\\./g,""),e=e.replace(/[_*]./g,""),!e.includes("date")&&!(!e.includes("h")&&!e.includes("s")&&"short time"!==e&&"medium time"!==e&&"long time"!==e)}var Ts,Fs;exports.IText=void 0,(Ts=exports.IText||(exports.IText={})).SmallCaps={None:"none",Small:"small",All:"all"},Ts.StrikeStyle={None:"none",Single:"single",Double:"double"},exports.ITextFrame=void 0,(Fs=exports.ITextFrame||(exports.ITextFrame={})).TabStop=class{},Fs.HorizontalAlignment={General:"general",Left:"left",Center:"center",Right:"right",Justify:"justify",Distributed:"distributed",CenterContinuous:"centerContinuous",Fill:"fill"},Fs.VerticalAlignment={Top:"top",Center:"center",Bottom:"bottom",Justify:"justify",Distributed:"distributed"},Fs.Orientation={Horizontal:"horizontal",Vertical:"90",Vertical270:"270",Stacked:"stacked"},Fs.ReadingDirection={Auto:"auto",LeftToRight:"ltr",RightToLeft:"rtl"},Fs.Overflow={Visible:"visible",Wrap:"wrap",Clip:"clip",Shrink:"shrink",Ellipsis:"ellipsis"},Fs.Autofit={None:"none",Normal:"normal",Shape:"shape"},Fs.TabStopAlignment={Default:"default",Left:"left",Right:"right",Center:"center"},Fs.toCSSHorizontalTextAlign=t=>t?t.toLowerCase():null;const Ns=(t,e,r=1e3)=>{if(!t)throw new Error("A template string must be specified.");if(e(t))return t;let n=new RegExp(/\d+/,"g").exec(t),o=null,s=0;null!==n?(o=t,s=parseFloat(n[0]),isNaN(s)&&(s=0)):(s=1,o=`${t}_${s}`);let i=isNaN(s)?0:s;for(;s<i+r;)try{const t=o.replace(/\d+/g,()=>""+s++);if(e(t))return t}catch(t){}throw new Error(`Unable to find valid name for '${t}'.`)},ks=(t,e=!1)=>{if(!t||0===t.length)return t;const r=t.charAt(0);if(r>="a"&&r<="z"){const n=String.fromCharCode(r.charCodeAt(0)-32);return e?n+t.slice(1).toLowerCase():n+t.slice(1)}return t},Os=t=>{if(!t||"string"!=typeof t)return"";const e=t.split(/[\\/]/).pop()||"",r=e.lastIndexOf(".");return""===e||r<1?"":e.slice(r+1)},Bs=t=>t.toLowerCase().replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_","")),Ls=(t,e=36)=>t.substring(0,36)+(t.length>e?"…":""),Ds=t=>{if(void 0===t)return 0;let e=t.toString().split(".");return e.length<=1?0:e[1].length||0},zs=new RegExp(/^["|'|`](.*)["|'|`]$/),Ps=new RegExp("^([a-zA-Z]+:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i"),js=(t=",",e="'")=>new RegExp(`\\s*${t}\\s*(?=(?:[^${e}]*${e}[^${e}]*${e})*[^${e}]*$)`,"g"),Hs=js(),Vs=t=>t.replace(zs,"$1"),$s=(t,e="'")=>`${e}${t}${e}`,Us=(t,e=void 0,r=void 0)=>{let n=Hs;return void 0===e&&void 0===r||(n=js(e,r)),t.split(n)},Gs=t=>{let e;try{e=new URL(t)}catch(t){return!1}return("http:"===e.protocol||"https:"===e.protocol)&&Ps.test(t)},Ws=new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/i),qs=t=>!!t.toLowerCase().startsWith("mailto:")||Ws.test(t),Js=t=>((t>=26?Js((t/26|0)-1):"")+"abcdefghijklmnopqrstuvwxyz"[t%26|0]).toUpperCase(),Xs=Object.freeze(Object.defineProperty({__proto__:null,DefaultUnQuoteRegEx:Hs,camelToSnake:t=>t?t.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`):t,capitalize:ks,clampString:Ls,countDecimals:Ds,findValidTextValue:Ns,getBaseName:(t,e=!1)=>{if(!t||"string"!=typeof t)return"";const r=t.split(/[\\/]/).pop()||"";if(""===r)return"";const n=Os(r),o=0===n.length?r:r.slice(0,r.length-n.length-1);return e?ks(o,!0):o},getFileNameExtension:Os,isQuoted:t=>t&&t.length>1&&zs.test(t)&&t[0]===t[t.length-1],isValidEmail:qs,isValidHttpUrl:Gs,numberToAlphabet:Js,quote:$s,snakeToCamel:Bs,splitUnquoted:Us,unquote:Vs},Symbol.toStringTag,{value:"Module"})),Ks=(t,e,r,n=null)=>{const o=(e||11*exports.IFont.getDeviceScale())/exports.IFont.getDeviceScale(),s=n?.letterSpacing||0,i=t.length;const a=i*(.55*o)-(t.match(/[il.,;!|]/g)||[]).length*o*.15+(t.match(/[mwMW]/g)||[]).length*o*.1+(i>0?(i-1)*s:0),l=Math.ceil(1.2*o),c=Math.ceil(.8*o),h=Math.ceil(.2*o),d=Math.ceil(.45*o),u=Math.ceil(1.1*o),g=Math.max(1,Math.ceil(.08*o));return{width:a,lineHeight:l,baseline:c,lineGap:h,strikePosition:d,underlinePosition:u,strikeThickness:g,underlineThickness:g,actualBoundingBoxLeft:0,actualBoundingBoxRight:a,actualBoundingBoxAscent:c,actualBoundingBoxDescent:l-c,fontBoundingBoxAscent:c,fontBoundingBoxDescent:l-c,emHeightAscent:c,emHeightDescent:l-c,hangingBaseline:.8*c,alphabeticBaseline:c,ideographicBaseline:l}},Ys={},Zs=(t,e)=>{let r="normal";return t&&e?r="bold italic":t?r="bold":e&&(r="italic"),r},Qs=t=>t.split(",").map(t=>{const e=(t=t.trim()).indexOf(" ")>=0,r=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!r&&(t=`"${t}"`),t}).join(", "),ti=new Map,ei=new Map;let ri=null;const ni=(t,e,r,n=null)=>{const o=n?.letterSpacing||0;"undefined"==typeof window||Ys.contextMeasure||(Ys.canvasMeasure=document?document.createElement("canvas"):null,Ys.contextMeasure=Ys.canvasMeasure.getContext("2d"),Ys.contextMeasure.letterSpacing=`${o}px`,Ys.contextMeasure.textRendering="geometricPrecision",Ys.contextMeasure.textBaseline="alphabetic",Ys.contextMeasure.textAlign="left");const s=r||"calibri",i=e||11*exports.IFont.getDeviceScale(),a=n?.isBold||!1,l=n?.isItalic||!1;let c=null;if("#"===t||"0"===t||"M"===t||""===t||"_"===t||"-"===t){c=((t,e,r,n,o,s)=>t+Math.round(100*e)/100+r+n+o+s)(t,i,s,a,l,o);const e=ti.get(c);if(e)return e}if(ri&&ri.text===t&&ri.size===e&&ri.family===r&&ri.options?.isBold===n?.isBold&&ri.options?.isItalic===n?.isItalic&&ri.options?.letterSpacing===n?.letterSpacing)return ri.metrics;let h={};const d=Zs(a,l)+" "+mt.roundAccurately(i,2)+"px "+Qs(s);Ys.contextMeasure?(Ys.contextMeasure.font=d,Ys.contextMeasure.letterSpacing=`${n?.letterSpacing??0}px`,h=Ys.contextMeasure.measureText(t)):h.width=t.length*mt.roundAccurately(i/exports.IFont.getDeviceScale()*.6,2);let u=ei.get(d);if(!u&&"undefined"!=typeof window){const t=document.createElement("div");t.style.visibility="hidden",t.style.position="absolute";const e=document.createElement("span");e.textContent="Mj",e.style.fontSize="100px",e.style.fontWeight=n?.isBold?"bold":"normal",e.style.fontStyle=n?.isItalic?"italic":"normal",e.style.fontFamily=`'${s}'`,e.style.lineHeight="1.2",t.appendChild(e),document.body.appendChild(t);const r=t.getBoundingClientRect(),o=e.getBoundingClientRect();document.body.removeChild(t),Ys.contextMeasure.font=Zs(a,l)+" "+mt.roundAccurately(100,2)+"px "+Qs(s);const c=Ys.contextMeasure.measureText("M"),h=r.bottom-r.top,g=h-(c.fontBoundingBoxAscent+c.fontBoundingBoxDescent),p=c.fontBoundingBoxAscent+o.top,m=Ys.contextMeasure.measureText("_"),f=p-m.actualBoundingBoxAscent,_=Math.max(1,Math.abs(m.actualBoundingBoxAscent+m.actualBoundingBoxDescent)),S=Ys.contextMeasure.measureText("-"),w=mt.roundAccurately(p-S.actualBoundingBoxAscent+Math.max(1,.05*h,0)),y=_,x=i/100;u={lineHeight:Math.ceil(h*x),baseline:Math.ceil(p*x),lineGap:Math.ceil(g*x),strikePosition:Math.ceil(w*x),underlinePosition:Math.ceil(f*x),strikeThickness:Math.ceil(y*x),underlineThickness:Math.ceil(_*x)},Ys.contextMeasure.font=d,ei.set(d,u)}u||(u={lineHeight:Math.ceil(1.2*i),baseline:Math.ceil(i)+Math.floor(.1*i),lineGap:Math.ceil(.1*i),strikePosition:Math.ceil(.55*i)+Math.floor(.1*i),strikeThickness:1,underlinePosition:Math.ceil(1.1*i),underlineThickness:1},ei.set(d,u));const g={...h,width:h.width,...u};return null!==c&&ti.set(c,g),ri={text:t,size:e,family:r,options:n,metrics:g},g};let oi=null;const si=()=>{if(oi)return oi;try{const t=document.createElement("canvas"),e=t.getContext&&t.getContext("2d");e&&"function"==typeof e.fillText&&(oi=ni)}catch{}return oi||(console.warn("⚠️ CanvasFontMeasurer not available, falling back to SimpleFontMeasurer"),oi=Ks),oi};let ii=null;var ai;exports.IFont=void 0,(ai=exports.IFont||(exports.IFont={})).Style={Normal:"normal",Italic:"italic"},ai.Scheme={Major:"major",Minor:"minor",None:"none"},ai.UnderlineStyle={None:"none",Double:"double",DoubleAccounting:"doubleAccounting",Single:"single",SingleAccounting:"singleAccounting"},ai.VerticalAlignment={Baseline:"baseline",Sub:"sub",Super:"super"},ai.setSharedMeasurer=t=>{ii=t},ai.getSharedMeasurer=()=>ii||(ii=si(),ii),ai.getDeviceScale=()=>96/72*1,ai.getPanoseFallback=t=>{const e=[],r=t.length;for(let n=0;n<r;n+=2)e.push(parseInt(t.substring(n,n+2),16));const n=e[0],o=e[1],s=e[3];switch(n){case 2:return 9===s?"monospace":o>=2&&o<=8?"serif":"sans-serif";case 3:return"cursive";case 4:return"fantasy";case 5:return"monospace";default:return"sans-serif"}},ai.GenericName={Serif:"serif",SanSerif:"sans-serif",MonoSpace:"monospace",Cursive:"cursive",Fantasy:"fantasy",SystemUI:"system-ui",UISystem:"ui-system",UISerif:"ui-serif",UISanSerif:"ui-sans-serif",UIMonoSpace:"ui-monospace",UIRounded:"ui-rounded",Math:"math",Emoji:"emoji",Fangsong:"fangsong"};class li{constructor(t){this._private={input:t},"string"==typeof t?this._private.name=t:Object.assign(this._private,t)}toJSON(){return this._private.input}getFamily(){return this._private.name}getPitch(){return this._private.pitch}getPanose(){return this._private.panose}toString(){return"string"==typeof this._private.input?this._private.input:JSON.stringify(this._private.input)}get isIFont(){return!0}}const ci=["Arial","Arial Black","Brush Script MT","Calibri","Comic Sans MS","Courier New","Garamond","Georgia","Impact","Luminari","Palatino Linotype","Tahoma","Times New Roman","Trebuchet MS","Verdana"],hi=new Map;hi.set(exports.IFont.GenericName.Serif,["Tahoma"]),hi.set(exports.IFont.GenericName.SanSerif,["Calibri"]),hi.set(exports.IFont.GenericName.MonoSpace,["Courier New"]),hi.set(exports.IFont.GenericName.Cursive,["Comic Sans MS"]),hi.set(exports.IFont.GenericName.Fantasy,["Luminari"]),hi.set(exports.IFont.GenericName.UISystem,["Arial"]),hi.set(exports.IFont.GenericName.UISerif,["Tahoma"]),hi.set(exports.IFont.GenericName.UISanSerif,["Arial"]),hi.set(exports.IFont.GenericName.UIMonoSpace,["Courier New"]),hi.set(exports.IFont.GenericName.UIRounded,["Arial"]),hi.set(exports.IFont.GenericName.Math,[]),hi.set(exports.IFont.GenericName.Emoji,[]),hi.set(exports.IFont.GenericName.Fangsong,[]);const di=new Map;let ui=[];pi(ci);const gi=eval;function pi(t){t||pi(ci);let e=[];for(let r=0;r<t.length;r++){let n=t[r];"string"==typeof n&&(n=new li(n));let o=!0;const s="document";try{o=gi(`${s}.fonts.check('12px ${n.getFamily()}')`)}catch(t){}const i={fontRef:n,loaded:o};e.push(i),di.set(n.getFamily(),i)}ui=Object.freeze(e)}const mi=new Map,fi=Object.freeze(Object.defineProperty({__proto__:null,findBestMatch:(t,e)=>{const r=mi.get(t);if(r)return null===r.fontRef?null:r;let n=[t];e.fallbacks&&(n=n.concat(e.fallbacks));let o=null;for(let t=0;!o&&t<n.length;t++){let e=n[t];if(o=di.get(e),!o){const t=hi.get(e);if(t)for(let e=0;!o&&e<t.length;e++)o=di.get(t[e])}}return o?mi.set(t,o):mi.set(t,{fontRef:null,loaded:!1}),o},getFontList:function(){return ui},setFontList:pi},Symbol.toStringTag,{value:"Module"}));class _i{constructor(t,e,r,n=null,o=null,s=null){this._private={wrapped:!0,insets:b.EmptyRect,orientation:exports.ITextFrame.Orientation.Horizontal,autoFit:exports.ITextFrame.Autofit.None,fontScale:1,vertical:!1,columnCount:1,columnSpacing:0,verticalAlignment:exports.ITextFrame.VerticalAlignment.Center,horizontalCentered:!1,lineReduction:0,isSpaceFirstLastPara:!1,presetTextWarp:null,paragraphs:mt.EmptyArray},this._bounds=null,this._textBounds=null,this._lines=null,this._lastLayoutDims=void 0,this._lastLayout=void 0,this._private=Object.assign(this._private,t||{}),this._defaultFont=e,this._alignment=r,this._lines=n,this._bounds=Object.freeze(o),this._textBounds=Object.freeze(s)}visitParas(t){t?.visitTextFrame?.(this);const e=this.paragraphs,r=e.length;for(let n=0;n<r;n++){const o=e[n];t?.visitTextParagraph?.(o,n,r);const s=o.runs,i=s.length;for(let e=0;e<i;e++)t?.visitTextRun?.(s[e],e,i)}}visitLines(t){t?.visitTextFrame?.(this);const e=this.lines,r=e.length;for(let n=0;n<r;n++){const o=e[n];t?.visitTextLine?.(o,n,r);const s=o.runs,i=s.length;for(let e=0;e<i;e++)t?.visitTextRun?.(s[e],e,i)}}layout(t=null){return this._lastLayout&&this._lastLayoutDims?.width===t?.width&&this._lastLayoutDims?.height===t?.height||(this._lastLayout=$i(this,this._defaultFont,this._alignment,t),this._lastLayoutDims=t),this._lastLayout}clone(t){const e=t?.visitTextFrame?.(this),r=Object.assign(this._private,e||{});return delete r.bounds,new _i(r,this._defaultFont,this._alignment)}equals(t){return mt.deepEqual(this._private,t._private)}createTemporaryTextFrame(t,e){return Gi(t,this._defaultFont,this._alignment,e??this._private.wrapped)}get bounds(){if(null===this._bounds)throw new Error(Si);return this._bounds}get textBounds(){if(null===this._textBounds)throw new Error(Si);return this._textBounds}get lines(){return this._lines}get wrapped(){return this._private.wrapped}get insets(){return this._private.insets}get orientation(){return this._private.orientation}get autoFit(){return this._private.autoFit}get fontScale(){return this._private.fontScale}get vertical(){return this._private.vertical}get columnCount(){return this._private.columnCount}get columnSpacing(){return this._private.columnSpacing}get verticalAlignment(){return this._private.verticalAlignment}get horizontalCentered(){return this._private.horizontalCentered}get lineReduction(){return this._private.lineReduction}get isSpaceFirstLastPara(){return this._private.isSpaceFirstLastPara}get presetTextWarp(){return this._private.presetTextWarp}get paragraphs(){return this._private.paragraphs}}const Si="bounds can not be used until layout";class wi{static{this.NL="\n"}static{this.DefaultLineSpacing=100}static{this.DefaultTabWidth=72}}class yi{constructor(t){this._private={defaultFontSize:11,defaultTabSize:wi.DefaultTabWidth,tabOverrides:mt.EmptyArray,spacingBefore:0,spacingAfter:0,lineSpacing:wi.DefaultLineSpacing,align:exports.ITextFrame.HorizontalAlignment.Left,endParagraphSize:0,indentLevel:0,leadingIndent:0,hangingIndent:0,rightMargin:0,bullet:null},this._private=Object.assign(this._private,t||{})}clone(t){const e=t?.visitTextParagraph?.(this,0,1),r=Object.assign(this._private,e||{});return delete r.bounds,new yi(r)}equals(t){return mt.deepEqual(this._private,t._private)}get bounds(){return this._bounds}get defaultFontSize(){return this._private.defaultFontSize}get defaultTabSize(){return this._private.defaultTabSize}get tabOverrides(){return this._private.tabOverrides}get spacingBefore(){return this._private.spacingBefore}get spacingAfter(){return this._private.spacingAfter}get lineSpacing(){return this._private.lineSpacing}get align(){return this._private.align}get endParagraphSize(){return this._private.endParagraphSize}get indentLevel(){return this._private.indentLevel}get leadingIndent(){return this._private.leadingIndent}get hangingIndent(){return this._private.hangingIndent}get rightMargin(){return this._private.rightMargin}get bullet(){return this._private.bullet}get runs(){return this._private.runs}}class xi{constructor(t,e=null){this._private={text:null,fontName:"Arial",bold:!1,italic:!1,superSub:!1,fontSize:11,letterSpacing:0,kerningMin:10,smallCaps:exports.IText.SmallCaps.None,offset:0,strikeStyle:exports.IText.StrikeStyle.None},this._private={...this._private,...t},this._bounds=e}clone(t){const e=t?.visitTextRun?.(this,0,1),r=Object.assign(this._private,e||{});return delete r.bounds,new xi(r)}equals(t){return mt.deepEqual(this._private,t._private)}get bounds(){return this._bounds}get text(){return this._private.text}get fontName(){return this._private.fontName}get bold(){return this._private.bold}get italic(){return this._private.italic}get fontSize(){return this._private.fontSize}get superSub(){return this._private.superSub}get letterSpacing(){return this._private.letterSpacing}get kerningMin(){return this._private.kerningMin}get smallCaps(){return this._private.smallCaps}get offset(){return this._private.offset}get strikeStyle(){return this._private.strikeStyle}}class Ci{constructor(t,e,r){this._private={},this._private={bounds:t,baseline:e,runs:r}}get bounds(){return this._private.bounds}get baseline(){return this._private.baseline}get runs(){return this._private.runs}get bullet(){return null}}function bi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Ei,vi,Ii,Ai,Ri,Mi;function Ti(){if(Ai)return Ii;Ai=1;const t=18===new Uint8Array(new Uint32Array([305419896]).buffer)[0],e=(t,e,r)=>{let n=t[e];t[e]=t[r],t[r]=n};return Ii={swap32LE:r=>{t&&(t=>{const r=t.length;for(let n=0;n<r;n+=4)e(t,n,n+3),e(t,n+1,n+2)})(r)}},Ii}var Fi=function(){if(Mi)return Ri;Mi=1;const t=function(){if(vi)return Ei;function t(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function e(e,r){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=r,this.destLen=0,this.ltree=new t,this.dtree=new t}vi=1;var r=new t,n=new t,o=new Uint8Array(30),s=new Uint16Array(30),i=new Uint8Array(30),a=new Uint16Array(30),l=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),c=new t,h=new Uint8Array(320);function d(t,e,r,n){var o,s;for(o=0;o<r;++o)t[o]=0;for(o=0;o<30-r;++o)t[o+r]=o/r|0;for(s=n,o=0;o<30;++o)e[o]=s,s+=1<<t[o]}var u=new Uint16Array(16);function g(t,e,r,n){var o,s;for(o=0;o<16;++o)t.table[o]=0;for(o=0;o<n;++o)t.table[e[r+o]]++;for(t.table[0]=0,s=0,o=0;o<16;++o)u[o]=s,s+=t.table[o];for(o=0;o<n;++o)e[r+o]&&(t.trans[u[e[r+o]]++]=o)}function p(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=1&t.tag;return t.tag>>>=1,e}function m(t,e,r){if(!e)return r;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,n+r}function f(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=0,n=0,o=0,s=t.tag;do{n=2*n+(1&s),s>>>=1,++o,r+=e.table[o],n-=e.table[o]}while(n>=0);return t.tag=s,t.bitcount-=o,e.trans[r+n]}function _(t,e,r){var n,o,s,i,a,d;for(n=m(t,5,257),o=m(t,5,1),s=m(t,4,4),i=0;i<19;++i)h[i]=0;for(i=0;i<s;++i){var u=m(t,3,0);h[l[i]]=u}for(g(c,h,0,19),a=0;a<n+o;){var p=f(t,c);switch(p){case 16:var _=h[a-1];for(d=m(t,2,3);d;--d)h[a++]=_;break;case 17:for(d=m(t,3,3);d;--d)h[a++]=0;break;case 18:for(d=m(t,7,11);d;--d)h[a++]=0;break;default:h[a++]=p}}g(e,h,0,n),g(r,h,n,o)}function S(t,e,r){for(;;){var n,l,c,h,d=f(t,e);if(256===d)return 0;if(d<256)t.dest[t.destLen++]=d;else for(n=m(t,o[d-=257],s[d]),l=f(t,r),h=c=t.destLen-m(t,i[l],a[l]);h<c+n;++h)t.dest[t.destLen++]=t.dest[h]}}function w(t){for(var e,r;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if((e=256*(e=t.source[t.sourceIndex+1])+t.source[t.sourceIndex])!==(65535&~(256*t.source[t.sourceIndex+3]+t.source[t.sourceIndex+2])))return-3;for(t.sourceIndex+=4,r=e;r;--r)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,0}return function(t,e){var r;for(r=0;r<7;++r)t.table[r]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,r=0;r<24;++r)t.trans[r]=256+r;for(r=0;r<144;++r)t.trans[24+r]=r;for(r=0;r<8;++r)t.trans[168+r]=280+r;for(r=0;r<112;++r)t.trans[176+r]=144+r;for(r=0;r<5;++r)e.table[r]=0;for(e.table[5]=32,r=0;r<32;++r)e.trans[r]=r}(r,n),d(o,s,4,3),d(i,a,2,1),o[28]=0,s[28]=258,Ei=function(t,o){var s,i,a=new e(t,o);do{switch(s=p(a),m(a,2,0)){case 0:i=w(a);break;case 1:i=S(a,r,n);break;case 2:_(a,a.ltree,a.dtree),i=S(a,a.ltree,a.dtree);break;default:i=-3}if(0!==i)throw new Error("Data error")}while(!s);return a.destLen<a.dest.length?"function"==typeof a.dest.slice?a.dest.slice(0,a.destLen):a.dest.subarray(0,a.destLen):a.dest},Ei}(),{swap32LE:e}=Ti();return Ri=class{constructor(r){const n="function"==typeof r.readUInt32BE&&"function"==typeof r.slice;if(n||r instanceof Uint8Array){let o;if(n)this.highStart=r.readUInt32LE(0),this.errorValue=r.readUInt32LE(4),o=r.readUInt32LE(8),r=r.slice(12);else{const t=new DataView(r.buffer);this.highStart=t.getUint32(0,!0),this.errorValue=t.getUint32(4,!0),o=t.getUint32(8,!0),r=r.subarray(12)}r=t(r,new Uint8Array(o)),r=t(r,new Uint8Array(o)),e(r),this.data=new Uint32Array(r.buffer)}else({data:this.data,highStart:this.highStart,errorValue:this.errorValue}=r)}get(t){let e;return t<0||t>1114111?this.errorValue:t<55296||t>56319&&t<=65535?(e=(this.data[t>>5]<<2)+(31&t),this.data[e]):t<=65535?(e=(this.data[2048+(t-55296>>5)]<<2)+(31&t),this.data[e]):t<this.highStart?(e=this.data[2080+(t>>11)],e=this.data[e+(t>>5&63)],e=(e<<2)+(31&t),this.data[e]):this.data[this.data.length-4]}}}();const Ni=bi(Fi);var ki,Oi={};var Bi=(ki||(ki=1,function(t){var e="undefined"!=typeof Uint8Array?Uint8Array:Array,r="+".charCodeAt(0),n="/".charCodeAt(0),o="0".charCodeAt(0),s="a".charCodeAt(0),i="A".charCodeAt(0),a="-".charCodeAt(0),l="_".charCodeAt(0);function c(t){var e=t.charCodeAt(0);return e===r||e===a?62:e===n||e===l?63:e<o?-1:e<o+10?e-o+26+26:e<i+26?e-i:e<s+26?e-s+26:void 0}t.toByteArray=function(t){var r,n,o,s,i,a;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;i="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,a=new e(3*t.length/4-i),o=i>0?t.length-4:t.length;var h=0;function d(t){a[h++]=t}for(r=0,n=0;r<o;r+=4,n+=3)d((16711680&(s=c(t.charAt(r))<<18|c(t.charAt(r+1))<<12|c(t.charAt(r+2))<<6|c(t.charAt(r+3))))>>16),d((65280&s)>>8),d(255&s);return 2===i?d(255&(s=c(t.charAt(r))<<2|c(t.charAt(r+1))>>4)):1===i&&(d((s=c(t.charAt(r))<<10|c(t.charAt(r+1))<<4|c(t.charAt(r+2))>>2)>>8&255),d(255&s)),a},t.fromByteArray=function(t){var e,r,n,o=t.length%3,s="";function i(t){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(t)}function a(t){return i(t>>18&63)+i(t>>12&63)+i(t>>6&63)+i(63&t)}for(e=0,n=t.length-o;e<n;e+=3)s+=a(r=(t[e]<<16)+(t[e+1]<<8)+t[e+2]);switch(o){case 1:s+=i((r=t[t.length-1])>>2),s+=i(r<<4&63),s+="==";break;case 2:s+=i((r=(t[t.length-2]<<8)+t[t.length-1])>>10),s+=i(r>>4&63),s+=i(r<<2&63),s+="="}return s}}(Oi)),Oi);var Li={};const Di=[[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4],[0,4,4,1,1,4,4,4,4,1,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,4,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[4,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,0,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,1,1,1,1,0,0,4,2,4,1,1,1,1,1,0,1,1,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,1,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,4,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,1,1,1,1,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,1,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,1,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0]],zi=new Ni(bi(Bi).toByteArray("AAgOAAAAAAAQ4QAAAQ0P8vDtnQuMXUUZx+eyu7d7797d9m5bHoWltKVUlsjLWE0VJNigQoMVqkStEoNQQUl5GIo1KKmogEgqkKbBRki72lYabZMGKoGAjQRtJJDaCCIRiiigREBQS3z+xzOTnZ3O+3HOhd5NfpkzZx7fN9988zivu2M9hGwB28F94DnwEngd/Asc1EtIs9c/bIPDwCxwLDgezHcodyo4w5C+CCwBS8FnwSXgCnA1uFbI93XwbXAbWAfWgx+CzWAb+An4KfgFeAzsYWWfYuFz4CXwGvgb+Dfo6yNkEEwGh4CZYB44FpwI3g1OY+kfBItZOo2fB84Hy8DF4HJwNbiWpV8PVoO1LH4n2NRXyN+KcAd4kNVP9XsY4aPgcfAbsBfs6SniL4K/sPjfEf6HlanXCRkCw2BGvUh/keWfXS/CY+pFXs7x9XHmM94LTmWIeU2cgbxnS/k/B3kf86jDhU8L9V2E40vAFWAlWFUfb++NOL4F3C7JX4/4GiE+hvgWsF0oS7mXldspnN+F493gyXrh9xTav0cg3EvzgVfBG6wsmVSEkxBOBgdPGpd7JI6PnqRvJ68/xlbHof53gPeA94OzwLngk+ACsAwsByvASrAK3MB0Ws3CtQjvBJvAVrADPMDSHkb4CNijaccTwvnf4fiPEs8Lxy+D18A/QU8/xjgYBjPAbDAKTgYLwOngTHAO+EQ/8wuEF4EvsPiVCFf2+9tsFStzA8LVHuXXBsi6QyqzUYiPMR/7Mc7dAx7oL8bzw/3u/Bw8Bp4Az4AXwCtgHzsmDXP5fiF9iiVvly5d0sHngar16NKlS5cuXbp06fLmYlqHXrcd3ph4P0THUY3iXh49novju4S0tzfs5d+JPKewfAsRntZb3K9ZhOMlrO6lCC8An28U9+OuovcPcPxlVu5rCL/VmHh/iHIrzn3fIPu7SN8Axmg+8AOwEWwCm7tp3bRuWjetm5Y8bSu4B9zbKO6ZVsnORrVU3f4uXTqZ2H3sLoyx3eDXjfDndE9qyj6L838CfwVvgFpzYnof4oNgOhgBc8Fos9DrZIQLmtXPP1MmF6wGj4H+KXoWguvADkXaPil+YpuQy8Am8Ey7ODdtmJDF4HowBp4De6HDTNjhfHAHeBr0DBBy0kDxfPbcgSIusgrcWhtnJ8vL+TPix7UIOQtcBq4C28Cr4KRBnANbwSuDE+s50JgyNNFuXbp06XIgsXjIvPafjvXozKY+fVFz/z0LT1uCtKVSWbrOLWPnztG8e0Xfy7ol8XtZJi7WtG+5od2UFXQ/A12vUeS7jp27yVKHjdsU9lXB869TyNvAzt0lpP2oWbwLdjiO78bx/Sz+EMJHwK9Y/LcIfw+eZ3F67/Hl5vh9xX80J+rwX8SvRDhpgL17iPAQMHNArfPrqHPewLheI+AERV6efwV418B4nOZ/H+IfYHV8GOF5LJ3eAz0fx8sM9S0fUNud39O9CulfGZhY5huI3wzWgNvBelbHZoTbNPVpfYjKQpkHwUNgl0LWblbnk0LbbDxr0OMFpL3iqWdu9nWYPlVAWkXY39LnGdCkDbeqv1YNbfcMQ3t9oe8lzm6NH9N1ZB6Ln4BwfkJZJk7RyFnYKt6b/JDQXx9p5X+eFdqOjzM9P9MB/lUlFzr20aXIdzlY4dmn9F3YqtvoO76/2hp/D/xA5Zue88nNyL8GbFbs075X0tyUig3Qd2MCnf//HjnzpbsR3g9+1kHzzVjdnE71/qVBX9rGPUh/ysNWe1neFzvIDi5zAufV1sT0N0poR22wkFUfTOPfA4N2mbZ5fSrqOHSw+IbkSBbOGSzSRgf91/GTUWYBOB2cIZQ/G8cfBZ8CFwrnL8XxF8FKcA24jqXdiPA7Qr61OF7H4mMItwzuv2/YLth1ISt3Hzu3k4W7EH5JqPdRHD/O4k+z8A8IX5Lq3y7Z4nXE9xn6kX6vQ4bKfy+ok+hH+xf3hq9dnTTHhjKd2GmDuWA242iHMq4cC7A8kJ7i8o1+skSa7Jieo38HCWnoNjKFhdSFBxzpZ7QE6lI8N4S14aASZcryaV/WWHw66f6NHuCoxuQxmvM56GX9QMd8Q4D65ywGP+ZzRJuM+zQvx/MOS2VFeqQ4IXnH26zM9Xe6/E6D+4foAzzuajPZp8Qyw5ayZVDWuH0z0BtYRkeIDqH9KO9VbH1btd/lhNqCzvl8zeLnG0S/hnU6baHfpiuO6yy0rd+DHURo/zYF5H26j03rQsip2ndzz82u1z9N4VjWKWeb68Tedpt95HRVXp7H1R6p+/Wt4FPy/PpWwscOLRJ+PVWF/+W0iVyGzs18TIvXkOJ1Wxm66vSXz+vylenrZcj1ub439W+K8RNCGTJi2p/TJ1K23VaXr35tRpnzmjxequgfcfyk6B/TGBVlyedsNgpdd/h+W1U3P99QyFPNo1X3TwpM/WLTIWYfoBqXrv6iskHZ/RFr79R6hIyHBrH3f1nrUVnjP8SnZZ+rYtzr9Exld5MNbPNErusAPg+77u/eDOPftU9yj39TH7rezxd1LvsZQJlzkWlOirG/79zjMj/mtHUKu7vKy+3/LnXr9okyKedjX5/0He9iP/j63LwOQdarEVlfy8OO/Lqw023j6xcqmwxLiOd6heM2i9cV9LJy8jMJ23yQ+rpbfu7EQ/pXE8KYvUSqvVnb4XzZa6LrHMXHR+zcLvqWbm/Bn0/HzIs6fWPHoat8XfnDKmZGxRxeMbn2UqZ5Q94nmcZRbqqUXbZ8+lcjE+cPX11t814orvvAXNcG8vqj2vvk1MGn3anlj0bIT72v47bvE+Lc98T9b6r7AKn6j+8Duf7D0nnZx/j7Zjn0j9nbpSTndaLr9WNLivP+iN23xF7L+fqv6ZouFyb78jxVXvv5jJ9YUs9/sddO8h7KNg5jrhfaJGztT6G7KF+1d6yCmD5Kdb2fan60rSc552fZr3zeQ9DpnPp+Si5cx5Ktv2QfSzF/mMbWdOm46rFI4XstnU9xeqX4NKb7TKEdcr6pZOK3ID1k/LvFHkVczEuZLEDr499YqvqBym1aEHWgcvoYOtv0M91qQl5TfpO/in6rWx8OVpT1Wedkv3f5xom3T/xeR/6Gx6V86PWAOB4bBpqWdN+yTcVxjIyGRz/FrDGu6w/3d7kPm8StX8RyPu+uuvpNju/vTLJV37GpvoM0oZPnW87VLnL/5pDno1NoW1R6yedU6TyUv3u19a3KFnIbTLYz+ZCLP4T0tU1uivFgso0pnsJ/UtXvarNY28Xq5cvkBDrQP/E5ZaiuQwwfmTlsOiQRU1fMuqrDd/3ISSuwjOwXOfTyGUMpZIXq4GpLn3pUcdfzch2x7XO1u2uZHOPb1G6b3Xg9PH1IIWeEpJlPQtqos2EKW8b0u8rnuP1UeVLoXJb9be0uG9nnbchjU+XTszT5VeNBThPHnc5OKj1U9aj0GTHIVaGy1YhEWT4ixns00DT+XEzWn/7VAsIc63Cov3OdyhwjrnaqQqZvWKXdypRdlq+k8msZ031U+Rm4fA+3TtyeR9hwfW9G9yxDN0fZMN33F+9TE6md4hwoxumfaUzI9fN3PFT3xVV2msrQ3UsnChm6Nulk8TndpS28D3zX9tTIPsF/z7Am5OkTjm1tI1JZW74+4VgsZ0N3L1yXV3WeP5uR7TGHHdvC3JQlxybfpd22tDlk/2eofRK8TzrN/qnar/K/OUTth6I/+jAnEptNbPvFHP2gs40N3+dfMWtwqvVct7/wfd8gtQ7imifial9ZJ9/3IHLYU6eDj3+4PhsNhX+vwvcWLnu6kGfEMe8DuciPfUfGZB8X/7HJy/Gefe5n+VRGFd/wyP2ta7/LO4yh/sbLV/k9lev6kfO9Dt/5U67b1/6u/epqB1U9Me23jfHY9sscAg4tkbLl+e4/U36rJ9ddxfd6sg5vq5ice42Wpk/pb9FOJ36/W9tpv4kbC79nUbZceX8Zu6/qJ+P3WvhvA8v3reh7Jbn2d6rrNC7XNZTLma4Ba0JI9efX2uLzF5scG/w9UNU1ZxW+ymUfzELeTllXlQ1rUuhzjS5fp9c964iFBOqeSz63bU065nZKdU+mDEz3qHIjjifquw0pnb/raRtvrnsYcb46ihT3taoYz6brdNW9l6rWRnE/navdPn1XlR1km7hcz1WlH/elKuSOSvLLuE8U6m8uzwRdfcGl73VyTHuyMvzJ1Sa2cWDTP/Z63Kc94n2B1PYr24dz1JlyHLlcP+S4B6vD1c9EW4q2LWstCvUjeVy63k/LMYdUNd5D1xQfvVTzX1VjkMsUv88N8VH5fReVn/Fjn++/h6X6Q8a6b1/q3g/i/ewi0/Scs8zxXeV6mWIOUPlPzBgdFerW+bZrm2P18dnjuK6HunEp+rHvPMXbr+sHVb/lnL+pTP57jPw9Cvk3PW178JD9qChfzuvTf7Htl38L1QUf/VKu9SFjwWbTWPvFEvu7Uq76y7+31g6QlYPc669pbsm9Xur2LWI9Pu8ypfDXqm3A2z8s1FWGn4ntL9NfQu2oSlftX9uetvTtv7J8Ql4zxfXGZ3zk8PeQ9w59x2uMfqI8/q5eKh/l9cb2rwsu9rSNl06ZP2Pmxtz+rNMx93yno0n2/82rVH7rQ+y9P15H6FyRun9ViH81ATmffI7nJ5r8uXXW6enbP6b/B8/l5OifVHYLnb9S39s2zcc+Ph+rh8+eQgVPS72elzGWY/tUtbbabBpDiI7yN1q6/4th2y+ErAc5+9BVvu/7KamJbWNZeuqI/R4tRf+YyD1HmOZM1bMV3/14Sn10c0Xu+Sj1nOXb5jL73ncdy02uvlXZNde65dOHYl7Vs4KYuS6FzWLn2zJlpZqPXPVPOa5yzKOyn1VhT9lmMfdbfH7D11Wf2PXN5h9y+dD287+qxgSnaYmnIrRtIb8pJe6/Uv9OVer6Whn0zfGO/BEloZI9ojmfAlUflClDd178bTmVHVTpZXOkAlk/lb42UujmI89HH5V+cl7XtowY6vTxLVWok6UrGzoGTHN+bB+6ri05687VNpvfuvRfaP2uMlNQth1D5JjGelm/8yn+9p3p/7qk9gnfeddXZmq/Sm333PJT659Kv1zjNbZ9uv2Oi//67CV8/N1nj1DmviyXDNVeJkaeaX8UsyesYg8cu2+NvdaPfb+lLDu5tvt/")),Pi=function(t){switch(t){case 33:case 39:case 40:case 42:return 12;case 35:return 5;default:return t}},ji=function(t){switch(t){case 37:case 38:return 34;case 41:return 22;default:return t}};class Hi{constructor(t,e=!1){this.position=t,this.required=e}}Li=class{nextCodePoint(){const t=this.string.charCodeAt(this.pos++),e=this.string.charCodeAt(this.pos);return 55296<=t&&t<=56319&&56320<=e&&e<=57343?(this.pos++,1024*(t-55296)+(e-56320)+65536):t}nextCharClass(){return Pi(zi.get(this.nextCodePoint()))}getSimpleBreak(){switch(this.nextClass){case 41:return!1;case 34:case 37:case 38:return this.curClass=34,!1;case 36:return this.curClass=36,!1}return null}getPairTableBreak(t){let e=!1;switch(Di[this.curClass][this.nextClass]){case 0:e=!0;break;case 1:e=41===t;break;case 2:if(e=41===t,!e)return e=!1,e;break;case 3:if(41!==t)return e}return this.LB8a&&(e=!1),!this.LB21a||16!==this.curClass&&17!==this.curClass?this.LB21a=13===this.curClass:(e=!1,this.LB21a=!1),28===this.curClass?(this.LB30a++,2==this.LB30a&&28===this.nextClass&&(e=!0,this.LB30a=0)):this.LB30a=0,this.curClass=this.nextClass,e}nextBreak(){if(null==this.curClass){let t=this.nextCharClass();this.curClass=ji(t),this.nextClass=t,this.LB8a=31===t,this.LB30a=0}for(;this.pos<this.string.length;){this.lastPos=this.pos;const t=this.nextClass;if(this.nextClass=this.nextCharClass(),34===this.curClass||36===this.curClass&&37!==this.nextClass)return this.curClass=ji(Pi(this.nextClass)),new Hi(this.lastPos,!0);let e=this.getSimpleBreak();if(null===e&&(e=this.getPairTableBreak(t)),this.LB8a=31===this.nextClass,e)return new Hi(this.lastPos)}return this.lastPos<this.string.length?(this.lastPos=this.string.length,new Hi(this.string.length)):null}constructor(t){this.string=t,this.pos=0,this.lastPos=0,this.curClass=null,this.nextClass=null,this.LB8a=!1,this.LB21a=!1,this.LB30a=0}};class Vi{constructor(t){this._textMeasurer=t}_measureText(t){const e=this._fontSize,r=this._fontName,n=this._metricOptions;if(this._isSuperSub){const o=this._textMeasurer(t,.6*e,r,n);return{...this._textMeasurer("M",e,r,n),width:o.width}}return this._textMeasurer(t,e,r,n)}_breakWord(t,e,r){let n=0;for(;n<t.length;){let o={startPosition:this._charactersRead+n,text:"",x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},s=!1,i=0;const a=this._maxWidth;do{s=!1;const e=t.substring(n,n+i+1),r=e.replace(/\s+$/,""),l=this._measureText(r);let c=l;e.length!==r.length&&(c=this._measureText(e)),(o.x+l.width<=a||e.length<=1)&&(o.text=e,o.width=l.width,o.widthWhitespace=c.width,o.height=Math.max(o.height,l.lineHeight),o.baseline=Math.max(o.baseline,l.baseline),s=!0,i++)}while(s&&n+i<t.length);if(s){const r=t.substring(n,t.length),s=r.replace(/\s+$/,""),i=this._measureText(s);let a=i;r.length!==s.length&&(a=this._measureText(r)),e.startPosition=this._charactersRead+n,e.width=i.width,o.widthWhitespace=a.width,e.height=Math.max(e.height,i.lineHeight),e.baseline=Math.max(e.baseline,i.baseline),e.text=r}else{const t=r?.(o);if(!1===t)return!1}n+=i}}_breakWhiteSpace(t,e=null){for(;t&&this._charactersRead<t.length;){let r={startPosition:this._charactersRead,text:"",x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},n=!1;const o=this._maxWidth,s=this._indent,i=this._breaker;do{if(n=!1,0===r.startPosition&&0===r.text.length&&(r.x=s,this._lastBreak=i.nextBreak()),this._lastBreak){const s=t.substring(r.startPosition,this._lastBreak.position),a=s.replace(/\s+$/,""),l=this._measureText(a);let c=l;if(s.length!==a.length&&(c=this._measureText(s)),r.x+l.width<=o)r.text=s,r.width=l.width,r.widthWhitespace=c.width,r.height=Math.max(r.height,l.lineHeight),r.baseline=Math.max(r.baseline,l.baseline),n=!0,this._charactersRead=this._lastBreak.position;else if(0===r.text.length){!1!==this._breakWord(s,r,e)&&(n=!0,this._charactersRead=this._lastBreak.position)}(n||-1===s.indexOf("\n"))&&this._lastBreak.required&&(this._lastBreak=i.nextBreak(),n=!1)}}while(n&&(this._lastBreak=i.nextBreak()));const a=e?.(r);if(!1===a)return!1}}wrap(t,e=null){this._breaker=new Li(t),this._linesRead=[],this._charactersRead=0,this._maxXRead=0,this._maxXWhitespaceRead=0,this._maxYRead=0,this._fontName=e?.fontName??"Arial",this._fontSize=e?.fontSize??12,this._metricOptions={isBold:e?.bold??!1,isItalic:e?.italic??!1,letterSpacing:e?.letterSpacing??0},this._isSuperSub=e?.superSub??!1,this._indent=e?.indent??0,this._maxWidth=e?.maxWidth??Number.MAX_SAFE_INTEGER,this._maxWidth<=0&&(this._maxWidth=Number.MAX_SAFE_INTEGER),this._maxHeight=e?.maxHeight??Number.MAX_SAFE_INTEGER,this._maxHeight<=0&&(this._maxHeight=Number.MAX_SAFE_INTEGER);const r=t=>{if(this._linesRead.length>0){let e=this._linesRead[this._linesRead.length-1];t.y=e.y+e.height}if(t.y+t.height>this._maxHeight)return!1;this._maxXRead=Math.max(this._maxXRead,t.x+t.width),this._maxXWhitespaceRead=Math.max(this._maxXWhitespaceRead,t.x+t.widthWhitespace),this._maxYRead=Math.max(this._maxYRead,t.y+t.height),this._linesRead.push(t)};if(""===t){const e=this._measureText(t);r({startPosition:0,text:"",x:0,y:0,width:0,widthWhitespace:0,height:e.lineHeight,baseline:e.baseline})}else{this._breakWhiteSpace(t,r);if(new Li(t.charAt(t.length-1).repeat(2)).nextBreak().required){const e=this._measureText(t);r({startPosition:t.length,text:"",x:0,y:0,width:0,widthWhitespace:0,height:e.lineHeight,baseline:e.baseline})}}const n={bounds:{x:0,y:0,width:this._maxXRead,widthWhitespace:this._maxXWhitespaceRead,height:this._maxYRead},lines:this._linesRead};return this._breaker=null,this._linesRead=[],n}}const $i=(t,e,r,n=null,o=exports.IFont.getSharedMeasurer())=>{let s="",i=null,a=null;const l=t.paragraphs,c=l.length;for(let t=0;t<c;t++){const e=l[t].runs,r=e.length;for(let t=0;t<r;t++)s+=e[t].text,0===t&&(i=e[t]);0===t&&(a=l[t])}const h=t.insets??b.EmptyRect,d=new Vi(o),u=n?.width?n.width-h.right-h.left:n?.width,g=n?.height?n.height-h.bottom-h.top:null,p=d.wrap(s,{fontName:i.fontName,fontSize:i.fontSize*exports.IFont.getDeviceScale(),bold:i.bold,italic:i.italic,superSub:i.superSub,letterSpacing:i.letterSpacing,maxWidth:t.wrapped&&u?u:null,maxHeight:g});let m=[];const f=p.lines,_=f.length,S=new Array(_);for(let t=0;t<_;t++){const e=f[t],r={x:e.x,y:e.y,width:e.width,height:e.height},n=new xi({text:e.text,fontName:i.fontFamily,fontSize:i.fontSize,bold:i.bold,italic:i.italic,superSub:i.superSub,letterSpacing:i.letterSpacing},r);m.push(n),S[t]=new Ci(r,e.baseline,[n])}const w=new yi({runs:m,align:a.align});return new _i({paragraphs:[w],wrapped:t.wrapped,verticalAlignment:t.verticalAlignment},e,r,S,{x:p.bounds.x,y:p.bounds.y,width:p.bounds.widthWhitespace,height:p.bounds.height},{x:p.bounds.x,y:p.bounds.y,width:p.bounds.width,height:p.bounds.height})},Ui=t=>{let e=!1,r=!1;for(let n=0;n<t.length;n++){const o=t.charCodeAt(n);if(o>=65&&o<=90?e=!0:o>=97&&o<=122&&(r=!0),e&&r)return 0}return e?1:r?-1:0},Gi=(t,e,r,n,o=!1)=>{if(null==t)return null;const s=new xi({text:t,fontName:e.toCSS().fontFamily,fontSize:e.getSize(),bold:e.getWeight()>400,italic:e.getStyle()===exports.IFont.Style.Italic,superSub:!o&&(e.getVerticalAlignment()===exports.IFont.VerticalAlignment.Sub||e.getVerticalAlignment()===exports.IFont.VerticalAlignment.Super),letterSpacing:e.getLetterSpacing()}),i=o?exports.ITextFrame.HorizontalAlignment.Left:r.getHorizontal(),a=r.getVertical(),l=new yi({runs:[s],align:i});let c=[];c.push(new Ci(null,e.getSize(),[s]));return new _i({paragraphs:[l],wrapped:n&&(r.getOverflow()===exports.ITextFrame.Overflow.Wrap||i===exports.ITextFrame.HorizontalAlignment.Justify||i===exports.ITextFrame.HorizontalAlignment.Distributed||a===exports.ITextFrame.VerticalAlignment.Justify||a===exports.ITextFrame.VerticalAlignment.Distributed),verticalAlignment:a},e,r,c)},Wi=(t,e,r,n)=>({x:t*n-e*r,y:t*r+e*n}),qi=t=>{let e=0,r=0,n=0,o=0,s=0,i=0,a=0,l=t.length;if(0===l)return{m:0,b:0};if(1===l)return{m:1,b:t[0]};for(let c=0;c<l;c++)i=c+1,a=t[c],null==a||isNaN(a)||(e+=i,r+=a,o+=i*i,n+=i*a,s++);const c=(s*n-e*r)/(s*o-e*e);return{m:c,b:r/s-c*e/s}},Ji=(t,e)=>{if(null===e)return null;const r=mt.isObject(e);return null!=t&&r?mt.mergeContentful(t,e):r?mt.cloneObject(e):e},Xi=(t,e,r)=>null==t||"object"==typeof t&&0===Object.keys(t).length;function Ki(t,e,r,n){if(t===e)return t??null}function Yi(t){return null==t}function Zi(t,e,r=1,n){if(0===r)return{preceding:t?[...t]:[],modified:[],trailing:[]};const o=function(t,e,r=1){let n=mt.findEqualOrGreater(t,e,t=>t.max);const o=t.slice(0,n),s=[],i=[];if(!t[n])return{preceding:o,modified:s,trailing:i};for(let o=n;o<t.length;o++)e+r<t[o].min?i.push({...t[o],min:t[o].min-r,max:t[o].max-r}):e>=t[o].min?Math.max(e,t[o].max+1-r)>t[o].min&&s.push({...t[o],max:Math.max(e-1,t[o].max-r)}):e<t[o].min&&e+r<=t[o].max&&s.push({...t[o],min:Math.max(e,t[o].min-r),max:t[o].max-r});return{preceding:o,modified:s,trailing:i}}(t,e,r),s=o.preceding,i=o.trailing;let a=[];s.length>0&&a.push(s.pop()),a=a.concat(o.modified),i.length>0&&a.push(i.shift());return{preceding:s,modified:ea(a,{onMerge:Ki}).modified,trailing:i}}function Qi(t,e,r){if(!t)throw new Error("runs can not be null");if(!e)return{preceding:[],modified:t?[...t]:[],trailing:[]};const n=function(t,e,r,n,o=!1){if(!e)return{preceding:[],modified:t?[...t]:[],trailing:[]};let s,i=mt.findEqualOrGreater(t,e.min,t=>t.max),a=t.slice(0,i),l=t.slice(i),c=[],h={...e},d=l[0]||{min:e.min,max:e.max,value:void 0};s=o?(t,e,r)=>{const o=(n||Ji)(e,r,t);void 0!==o?t.value=o:delete t.value,c.push(t)}:(t,e,r)=>{const o=(n||Ji)(e??null,r,t);void 0!==o?t.value=o:delete t.value,c.push(t)};for(;l.length>=0&&h.max-h.min>=0;){if(h.min<d.min)s({min:h.min,max:Math.min(h.max,d.min-1)},void 0,h.value),h={min:d.min,max:h.max,value:h.value},d={min:h.min,max:d.max,value:d.value};else if(h.min>d.min){const t=void 0!==d.value&&r?r(d,h.min):[d.value,d.value];c.push({min:d.min,max:Math.min(h.min,d.max)-1,value:t[0]}),h={min:Math.min(h.min,d.max),max:h.max,value:h.value},d={min:h.min,max:d.max,value:t[1]}}else{const t=void 0!==d.value&&r?r(d,h.min):[d.value,d.value];s({min:d.min,max:Math.min(h.max,d.max)},t[0],h.value),h={min:Math.min(h.max,d.max)+1,max:h.max,value:h.value},d={min:Math.min(h.max,d.max)+1,max:d.max,value:t[1]}}d.min<=d.max?l[0]=d:(l=l.slice(1),d=l[0]||{min:d.min,max:h.max})}return{preceding:a,modified:c,trailing:l}}(t,e,r?.onSplit,r?.onUpdate,r?.inPlace);let o=[];n.preceding.length>0&&o.push(n.preceding.pop()),o=o.concat(n.modified),n.trailing.length>0&&o.push(n.trailing.shift());const s=function(t,e){if(!t||0===t.length)return{preceding:[],modified:t?[...t]:[],trailing:[]};const r=Math.min(t.length-1,e?.startOffset??0),n=Math.min(t.length,e?.endOffset??t.length),o=e?.cull??Yi;let s=t.slice(0,r),i=t.slice(n);const a=[];for(let e=r;e<n;e++)!0!==o(t[e].value,t[e].min,t[e].max)&&a.push(t[e]);return{preceding:s,modified:a,trailing:i}}(ea(o,{onMerge:r?.onMerge??Ki}).modified,{cull:r?.isCull||Xi});return{preceding:n.preceding,modified:s.modified,trailing:n.trailing}}function ta(t){return[...t.preceding,...t.modified,...t.trailing]}function ea(t,e){if(!t||0===t.length)return{preceding:[],modified:t?[...t]:[],trailing:[]};const r=Math.min(t.length-1,e?.startOffset??0),n=Math.min(t.length,e?.endOffset??t.length),o=e?.onMerge??Ki;let s=t.slice(0,r),i=t.slice(n);const a=[];let l={...t[r]},c=t[r]?.max||0;for(let e=r+1;e<=n;e++){const r=t[e];let n=!1;if(r&&r.min<=t[e-1].max+1)if(void 0===l.value&&void 0===r.value)n=!0;else{const t=o(l.value,r.value,l.max-l.min+1,r.max-r.min+1);void 0!==t&&(n=!0,l.value=t)}n?l.max=Math.max(c,r.max):(a.push(l),l={...t[e]},r&&(l.max=Math.max(c,r.max))),l&&(c=l.max)}return{preceding:s,modified:a,trailing:i}}function ra(t){return t?t.sort((t,e)=>{let r=t.min-e.min;return 0===r&&(r=t.max-e.max),r}):t}const na=(t,e=!1)=>{if(!t||0===t.length)return mt.EmptyArray;const r=e?t:t.sort(),n=[];let o=null;for(let t=0;t<r.length;t++){const e=r[t];o?o.max===e-1?o.max=e:(n.push(o),o={min:e,max:e}):o={min:e,max:e}}return o&&n.push(o),n},oa=(t,e)=>t?e?t||e?t.min>e.max||t.max<e.min?null:{min:Math.max(t.min,e.min),max:Math.min(t.max,e.max)}:null:{...t}:{...e},sa=t=>{const e=0===t.length;return{runs:t,run:{min:e?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,max:e?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,value:null},index:Number.MAX_SAFE_INTEGER}},ia=(t,e)=>{const r=e.run,n=r.min,o=r.max;if(t>=n&&t<=o)return r.value;let s=e.index;const i=e.runs;if(s<i.length-1&&t>o){s++;const n=i[s],o=n.min,a=n.max;if(t>=o&&t<=a)return e.index=s,r.min=o,r.max=a,r.value=n.value,r.value}if(s!==Number.MAX_SAFE_INTEGER&&s>0&&t<n){s--;const n=i[s],o=n.min,a=n.max;if(t>=o&&t<=a)return e.index=s,r.min=o,r.max=a,r.value=n.value,r.value}if(s=mt.findEqualOrGreater(i,t,t=>t.max),s===i.length)return s=i.length,e.index=s,r.min=i[s-1].max+1,r.max=Number.MAX_SAFE_INTEGER,r.value=null,null;const a=i[s],l=a.min,c=a.max;if(t>=l&&t<=c){e.index=s,r.min=l,r.max=c;const t=a.value;return r.value=t,t}return s--,e.index=s,r.min=s>=0?i[s].max+1:Number.MIN_SAFE_INTEGER,r.max=l-1,r.value=null,null},aa=function(t,e,r,n){if(0===t.length){if(null!=r||null!=n){const t=e({min:r??n,max:n??r});if(t&&t.break)return t}return}const o=r??t[0].min,s=n??t[t.length-1].max;let i=o-1,a=mt.findEqualOrGreater(t,o,t=>t.max),l=t[a];for(;l&&l.min<=s;){if(i<l.min-1){const t=e({min:Math.max(i+1,o),max:Math.min(l.min-1,s)});if(t&&t.break)return t}const r=e({...l,min:Math.max(l.min,o),max:Math.min(l.max,s)});if(r&&r.break)return r;i=l.max,l=t[++a]}if(i<s){const t=e({min:Math.min(i+1,s),max:s});if(t&&t.break)return t}},la=new RegExp("([0-9]+)$");var ca,ha;exports.AutoFill=void 0,(t=>{t.Date=class{constructor(t){this._options=t}canFill(t,e){return ls(t)}createFillAt(t,e){e={...this._options,...e};let r=0,n=this._options?.unit;n||(n=1===t.length?hs:((t,e=!1)=>{if(!t||t.length<1)return hs;let r=t;e||(r=t.slice(),r=r.sort((t,e)=>t.getTime()-e.getTime()));let n=!1,o=-1,s=-1;for(let t=0;t<r.length;t++){let e=r[t];if(t>r.length-1&&e.getTime()<r[t+1].getTime())throw new Error("Dates are expected to be sorted.");let i=12*e.getFullYear()+e.getMonth();if(i===s)return hs;s=i;let a=e.getFullYear();a>o?o=a:n=!0}return n?ds:us})(t));const o=gs(t[0],0,n);o.setHours(0,0,0,0);let s=1;e?.reverse&&(s*=-1,r*=-1);for(let e=1;e<t.length;e++){let r=cs(t[e-1],t[e],n);if(1===e)s=r;else if(r!==s)return null}return 1===t.length&&e.multiFill,t=>{const e=gs(o,s*t,n);if(0!==r){const n=0+r*t,o=n%1440,s=Math.floor(o/60),i=o%60;e.setHours(s,i,0,0);const a=Math.floor(n/1440),l=Math.floor(a/365),c=a%365,h=Math.floor(c/30),d=c%30;l>0&&e.setFullYear(e.getFullYear()+l),h>0&&e.setMonth(e.getMonth()+h),d>0&&e.setDate(e.getDate()+d)}return e}}};t.Linear=class{constructor(t){this._options=t}canFill(t,e){return"number"==typeof t||null===t}createFillAt(t,e){e={...this._options,...e};const r=qi(t),n=r.b;let o=r.m;return 1===t.length?(e.reverse&&(o=-o),e.multiFill?t=>t*o+n:null):t=>o*(t+1)+n}};const e={value:null,template:null},r={sensitivity:"accent"};t.Ordinal=class{_template(t){const e=t.match(la);if(!e)return null;const r=e[1],n=t.lastIndexOf(r);return-1===n?null:t.substring(0,n)}canFill(t,n){if(null===t)return!0;if("string"!=typeof t)return e.value=null,!1;const o=this._template(t);return o&&(void 0===n||n===e.value&&0===o.localeCompare(e.template,void 0,r))?(e.value=t,e.template=o,!0):(e.value=null,!1)}createFillAt(t,e){const r=[],n=t[0];let o=null,s=null,i=0;if(n){const t=n.match(la);if(t){o=t[1],o.startsWith("0")&&(i=o.length);const e=n.lastIndexOf(o);s=n.substring(0,e)}}const a=t.length;for(let e=0;e<a;e++){const n=t[e];let o=null;if(n){const t=n.substring(s.length,n.length);t.startsWith("0")&&(i=Math.max(i,t.length));const e=parseFloat(t);isNaN(e)||(o=e)}r.push(o)}const l=qi(r),c=l.b;let h=l.m;return 0!==h&&Number.isInteger(h)?r=>{if(null===t[r%a])return null;const n=(1===a?e.reverse?-r:r:h*(r+1))+c,o=""+Math.abs(n),l="0".repeat(Math.max(0,i-o.length))+o;return s+l}:null}};t.Copy=class{canFill(t,e){return!0}createFillAt(t,e){const r=t.length;return e=>t[e%r]??null}};const n=Object.freeze(["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]),o=Object.freeze(["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]),s=Object.freeze(["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),i=Object.freeze(["January","February","March","April","May","June","July","August","September","October","November","December"]);t.List=class{constructor(t){this._lists=[],this._map=new Map;const e=[];if(t?.customLists){const r=t.customLists;for(let t=r.length-1;t>0;t--)e.push(r[t])}e.push(i),e.push(s),e.push(o),e.push(n);const r=this._map,a=[];for(let t=0;t<e.length;t++){const n=e[t],o=[];a.push(o);for(let e=0;e<n.length;e++){const s=n[e],i=ks(s,!0),a=i.toLowerCase().trim();let l=r.get(a);l||(l=[],r.set(a,l));const c={value:i,asKey:a,major:t,minor:e};l.push(c),o.push(c)}}this._lists=Object.freeze(a)}canFill(t,e){if(null===t)return!0;if("string"!=typeof t)return!1;return!!this._map.get(t.toLowerCase().trim())}createFillAt(t,e){const r=[],n=t[0];r.push(n.toLowerCase().trim());const o=this._map.get(r[0]);let s;const i=new Map,a=new Set;for(let t=0;t<o.length;t++){const e=o[t];i.set(e.major,e)}if(t.length>1){for(let e=1;e<t.length;e++){const n=t[e].toLowerCase().trim(),o=this._map.get(n);if(!o)return null;1===e&&(s=o),r.push(n);for(let t=0;t<o.length;t++){const e=o[t].major;i.has(e)&&a.add(e)}}if(0===a.size)return null}let l=null;const c=this._lists;for(let e=0;!l&&e<c.length;e++)(1===t.length||a.has(e))&&(l=i.get(e));if(!l)return null;let h=null;for(let t=0;!h&&s&&t<s.length;t++)s[t].asKey===r[1]&&(h=s[t]);let d=!1,u=!1;const g=Ui(n);1===g?d=!0:(-1===g||-1===Ui(n[0]))&&(u=!0);const p=c[l.major];let m=l.minor,f=1;if(r.length>1){f=h.minor-l.minor;for(let t=2;t<r.length;t++)if(p[t+m].minor-p[t-1+m].minor!==f)return null}1===t.length&&e?.reverse&&(f=-f);const _=t.length,S=p.length;return e=>{if(null===t[e%_])return null;let r=(e*f+m)%S;r<0&&(r=S+r);const n=p[r].value??null;return d?n.toUpperCase():u?n.toLowerCase():n}}};t.Composite=class{constructor(t){t=Array.isArray(t)?[...t]:[t],this._fillers=t}canFill(t,e){return!0}createFillAt(t,e){const r=this._fillers;e={multiFill:t.length>1,...e};const n=t.length;let o=0,s=!1;for(let e=0;!s&&e<=n;e++)null===t[e]?o++:s=!0;let i=0;s=!1;for(let e=n-1;!s&&e>=o;e--)null===t[e]?i++:s=!0;const a=[];let l=null,c=null,h=[],d=o,u=0;const g=t=>{if(l&&l.max+1===d){const e=l.value;e.fillAt.push(t),l.max=d,e.length++,e.valuesLength++}else l={min:d,max:d,value:{fillAt:[t],start:d,length:1,valuesLength:n,blankInterval:0}};a.push(l)},p=n-i;for(d=o;d<p;){let n=t[d];if(null===n){d++;continue}c=null;let o,s=1,i=!1;for(let t=0;!i&&t<r.length+1;t++){const e=r[t];e&&(i=e.canFill(n,o),i&&(c=e))}if(!c){null!==n&&g(n),d++;continue}let l=0;u=0,o=n;do{n=t[d+s],i=c.canFill(n,o),i&&(null!==n?(o=n,l>0&&(s-l===1?u=l:l!==u&&(u=0)),l=0):l++,s++)}while(i&&d+s<p);h=[t[d]];const m=1+u,f=s-l;for(let e=m;e<f;e+=m)h.push(t[d+e]);if(h.length>0){const t=h.length,r=t+(t-1)*u,n=c.createFillAt?.(h,e)??h;a.push({min:d,max:d+r-1,value:{fillAt:n,start:d,length:r,valuesLength:t,blankInterval:u}})}d+=s}const m=sa(a);return t=>{const e=t>=0,r=Math.abs(t),o=ia(r%n,m);if(!o)return null;const s=Math.floor(r/n),i=o.length,a=o.start,l=(s+(e?1:0))*a+(s+(e?0:1))*(n-(a+i));let c=t+(e?-l:l);const h=o.blankInterval;if(0!==h){let t=c%i;if(0!==t%(1+h))return null;c=Math.floor(t/(1+h))+o.valuesLength*s}const d=o.fillAt;return"function"==typeof d?d(c):d[c%d.length]}}},t.Types={Series:new t.Composite([new t.Date,new t.Linear,new t.Ordinal,new t.List]),DateDays:new t.Date({unit:hs}),DateMonths:new t.Date({unit:ds}),DateYears:new t.Date({unit:us}),Copy:new t.Copy},t.fillTo=(t,e,r,n)=>{const o=[],s=e.length,i=t.createFillAt(e,n);for(let t=s;t<r;t++)o.push(i(t));return o}})(exports.AutoFill||(exports.AutoFill={})),exports.IPrint=void 0,exports.IPrint||(exports.IPrint={}),exports.IFill=void 0,(ca=exports.IFill||(exports.IFill={})).Type={None:"none",Solid:"solid",Gradient:"gradient",Pattern:"pattern",Image:"pattern",Background:"background",Group:"group",Custom:"custom"},ca.GradientType={Linear:"linear",Path:"path",Circular:"circular",Rect:"rect"},ca.TileMirror={None:"none",Vertical:"v",Horizontal:"h",Both:"b"},ca.BuiltInSheetPattern={None:"none",Solid:"solid",DarkGray:"darkGray",MediumGray:"mediumGray",LightGray:"lightGray",Gray0625:"gray0625",Gray125:"gray125",DarkHorizontal:"darkHorizontal",DarkVertical:"darkVertical",DarkDown:"darkDown",DarkUp:"darkUp",DarkGrid:"darkGrid",DarkTrellis:"darkTrellis",LightHorizontal:"lightHorizontal",LightVertical:"lightVertical",LightDown:"lightDown",LightUp:"lightUp",LightGrid:"lightGrid",LightTrellis:"lightTrellis",Custom:"custom"},exports.IColor=void 0,(ha=exports.IColor||(exports.IColor={})).AdjustmentType={Alpha:"alpha",AlphaOff:"alphaOff",AlphaMod:"alphaMod",Hue:"hue",Sat:"sat",Lum:"lum",HueOff:"hueOff",SatOff:"satOff",LumOff:"lumOff",HueMod:"hueMod",SatMod:"satMod",LumMod:"lumMod",Red:"red",Green:"green",Blue:"blue",RedOff:"redOff",GreenOff:"greenOff",BlueOff:"blueOff",RedMod:"redMod",GreenMod:"greenMod",BlueMod:"blueMod",Shade:"shade",Tint:"tint",ETint:"eTint",Gray:"gray",Comp:"comp",Inv:"inv",Gamma:"gamma",InvGamma:"invGamma"},ha.Named={ActiveBorder:"activeBorder",ActiveCaption:"activeCaption",CaptionText:"captionText",AppWorkspace:"appWorkspace",BtnFace:"btnFace",BtnShadow:"btnShadow",DkShadow3d:"3dDkShadow",BtnHighlight:"btnHighlight",Light3d:"3dLight",BtnText:"btnText",Background:"background",GrayText:"grayText",Highlight:"highlight",HighlightText:"highlightText",HotLight:"hotLight",InactiveBorder:"inactiveBorder",InactiveCaption:"inactiveCaption",InactiveCaptionText:"inactiveCaptionText",InfoBk:"infoBk",InfoText:"infoText",Menu:"menu",MenuText:"menuText",ScrollBar:"scrollBar",Window:"window",WindowFrame:"windowFrame",WindowText:"windowText",Transparent:"transparent",AliceBlue:"aliceBlue",AntiqueWhite:"antiqueWhite",Aqua:"aqua",Aquamarine:"aquamarine",Azure:"azure",Beige:"beige",Bisque:"bisque",Black:"black",BlanchedAlmond:"blanchedAlmond",Blue:"blue",BlueViolet:"blueViolet",Brown:"brown",BurlyWood:"burlyWood",CadetBlue:"cadetBlue",Chartreuse:"chartreuse",Chocolate:"chocolate",Coral:"coral",CornflowerBlue:"cornflowerBlue",Cornsilk:"cornsilk",Crimson:"crimson",Cyan:"cyan",DkBlue:"dkBlue",DkCyan:"dkCyan",DkGoldenrod:"dkGoldenrod",DkGray:"dkGray",DkGreen:"dkGreen",DkKhaki:"dkKhaki",DkMagenta:"dkMagenta",DkOliveGreen:"dkOliveGreen",DkOrange:"dkOrange",DkOrchid:"dkOrchid",DkRed:"dkRed",DkSalmon:"dkSalmon",DkSeaGreen:"dkSeaGreen",DkSlateBlue:"dkSlateBlue",DkSlateGray:"dkSlateGray",DkTurquoise:"dkTurquoise",DkViolet:"dkViolet",DeepPink:"deepPink",DeepSkyBlue:"deepSkyBlue",DimGray:"dimGray",DodgerBlue:"dodgerBlue",Firebrick:"firebrick",FloralWhite:"floralWhite",ForestGreen:"forestGreen",Fuchsia:"fuchsia",Gainsboro:"gainsboro",GhostWhite:"ghostWhite",Gold:"gold",Goldenrod:"goldenrod",Gray:"gray",Green:"green",GreenYellow:"greenYellow",Honeydew:"honeydew",HotPink:"hotPink",IndianRed:"indianRed",Indigo:"indigo",Ivory:"ivory",Khaki:"khaki",Lavender:"lavender",LavenderBlush:"lavenderBlush",LawnGreen:"lawnGreen",LemonChiffon:"lemonChiffon",LtBlue:"ltBlue",LtCoral:"ltCoral",LtCyan:"ltCyan",LtGoldenrodYellow:"ltGoldenrodYellow",LtGray:"ltGray",LtGreen:"ltGreen",LtPink:"ltPink",LtSalmon:"ltSalmon",LtSeaGreen:"ltSeaGreen",LtSkyBlue:"ltSkyBlue",LtSlateGray:"ltSlateGray",LtSteelBlue:"ltSteelBlue",LtYellow:"ltYellow",Lime:"lime",LimeGreen:"limeGreen",Linen:"linen",Magenta:"magenta",Maroon:"maroon",MedAquamarine:"medAquamarine",MedBlue:"medBlue",MedOrchid:"medOrchid",MedPurple:"medPurple",MedSeaGreen:"medSeaGreen",MedSlateBlue:"medSlateBlue",MedSpringGreen:"medSpringGreen",MedTurquoise:"medTurquoise",MedVioletRed:"medVioletRed",MidnightBlue:"midnightBlue",MintCream:"mintCream",MistyRose:"mistyRose",Moccasin:"moccasin",NavajoWhite:"navajoWhite",Navy:"navy",OldLace:"oldLace",Olive:"olive",OliveDrab:"oliveDrab",Orange:"orange",OrangeRed:"orangeRed",Orchid:"orchid",PaleGoldenrod:"paleGoldenrod",PaleGreen:"paleGreen",PaleTurquoise:"paleTurquoise",PaleVioletRed:"paleVioletRed",PapayaWhip:"papayaWhip",PeachPuff:"peachPuff",Peru:"peru",Pink:"pink",Plum:"plum",PowderBlue:"powderBlue",Purple:"purple",Red:"red",RosyBrown:"rosyBrown",RoyalBlue:"royalBlue",SaddleBrown:"saddleBrown",Salmon:"salmon",SandyBrown:"sandyBrown",SeaGreen:"seaGreen",SeaShell:"seaShell",Sienna:"sienna",Silver:"silver",SkyBlue:"skyBlue",SlateBlue:"slateBlue",SlateGray:"slateGray",Snow:"snow",SpringGreen:"springGreen",SteelBlue:"steelBlue",Tan:"tan",Teal:"teal",Thistle:"thistle",Tomato:"tomato",Turquoise:"turquoise",Violet:"violet",Wheat:"wheat",White:"white",WhiteSmoke:"whiteSmoke",Yellow:"yellow",YellowGreen:"yellowGreen",ButtonFace:"buttonFace",ButtonHighlight:"buttonHighlight",ButtonShadow:"buttonShadow",GradientActiveCaption:"gradientActiveCaption",GradientInactiveCaption:"gradientInactiveCaption",MenuBar:"menuBar",MenuHighlight:"menuHighlight"},ha.Scheme={Bg1:"bg1",Bg2:"bg2",Tx1:"tx1",Tx2:"tx2",Accent1:"accent1",Accent2:"accent2",Accent3:"accent3",Accent4:"accent4",Accent5:"accent5",Accent6:"accent6",Hlink:"hlink",FolHlink:"folHlink"},ha.Type={Scheme:"scheme",Named:"named",Index:"index",HSL:"hsl",RGB:"rgb",LRGB:"lrgb",Hex:"hex"};const da=[[4290032820,1,exports.IColor.Named.ActiveBorder,!0],[4288263377,2,exports.IColor.Named.ActiveCaption,!0],[4278190080,3,exports.IColor.Named.CaptionText,!0],[4289440683,4,exports.IColor.Named.AppWorkspace,!0],[4293980400,5,exports.IColor.Named.BtnFace,!0],[4285098345,6,exports.IColor.Named.BtnShadow,!0],[4278190080,7,exports.IColor.Named.DkShadow3d,!0],[4293125091,8,exports.IColor.Named.BtnHighlight,!0],[4293125091,9,exports.IColor.Named.Light3d,!0],[4278190080,10,exports.IColor.Named.BtnText,!0],[4278190080,11,exports.IColor.Named.Background,!0],[4285361517,12,exports.IColor.Named.GrayText,!0],[4281571839,13,exports.IColor.Named.Highlight,!0],[4294967295,14,exports.IColor.Named.HighlightText,!0],[4278216396,15,exports.IColor.Named.HotLight,!0],[4294244348,16,exports.IColor.Named.InactiveBorder,!0],[4290760155,17,exports.IColor.Named.InactiveCaption,!0],[4278190080,18,exports.IColor.Named.InactiveCaptionText,!0],[4294967265,19,exports.IColor.Named.InfoBk,!0],[4278190080,20,exports.IColor.Named.InfoText,!0],[4293980400,21,exports.IColor.Named.Menu,!0],[4278190080,22,exports.IColor.Named.MenuText,!0],[4291348680,23,exports.IColor.Named.ScrollBar,!0],[4294967295,24,exports.IColor.Named.Window,!0],[4284769380,25,exports.IColor.Named.WindowFrame,!0],[4278190080,26,exports.IColor.Named.WindowText,!0],[16777215,27,exports.IColor.Named.Transparent],[4293982463,28,exports.IColor.Named.AliceBlue],[4294634455,29,exports.IColor.Named.AntiqueWhite],[4278255615,30,exports.IColor.Named.Aqua],[4286578644,31,exports.IColor.Named.Aquamarine],[4293984255,32,exports.IColor.Named.Azure],[4294309340,33,exports.IColor.Named.Beige],[4294960324,34,exports.IColor.Named.Bisque],[4278190080,35,exports.IColor.Named.Black],[4294962125,36,exports.IColor.Named.BlanchedAlmond],[4278190335,37,exports.IColor.Named.Blue],[4287245282,38,exports.IColor.Named.BlueViolet],[4289014314,39,exports.IColor.Named.Brown],[4292786311,40,exports.IColor.Named.BurlyWood],[4284456608,41,exports.IColor.Named.CadetBlue],[4286578432,42,exports.IColor.Named.Chartreuse],[4291979550,43,exports.IColor.Named.Chocolate],[4294934352,44,exports.IColor.Named.Coral],[4284782061,45,exports.IColor.Named.CornflowerBlue],[4294965468,46,exports.IColor.Named.Cornsilk],[4292613180,47,exports.IColor.Named.Crimson],[4278255615,48,exports.IColor.Named.Cyan],[4278190219,49,exports.IColor.Named.DkBlue],[4278225803,50,exports.IColor.Named.DkCyan],[4290283019,51,exports.IColor.Named.DkGoldenrod],[4289309097,52,exports.IColor.Named.DkGray],[4278215680,53,exports.IColor.Named.DkGreen],[4290623339,54,exports.IColor.Named.DkKhaki],[4287299723,55,exports.IColor.Named.DkMagenta],[4283788079,56,exports.IColor.Named.DkOliveGreen],[4294937600,57,exports.IColor.Named.DkOrange],[4288230092,58,exports.IColor.Named.DkOrchid],[4287299584,59,exports.IColor.Named.DkRed],[4293498490,60,exports.IColor.Named.DkSalmon],[4287609995,61,exports.IColor.Named.DkSeaGreen],[4282924427,62,exports.IColor.Named.DkSlateBlue],[4281290575,63,exports.IColor.Named.DkSlateGray],[4278243025,64,exports.IColor.Named.DkTurquoise],[4287889619,65,exports.IColor.Named.DkViolet],[4294907027,66,exports.IColor.Named.DeepPink],[4278239231,67,exports.IColor.Named.DeepSkyBlue],[4285098345,68,exports.IColor.Named.DimGray],[4280193279,69,exports.IColor.Named.DodgerBlue],[4289864226,70,exports.IColor.Named.Firebrick],[4294966e3,71,exports.IColor.Named.FloralWhite],[4280453922,72,exports.IColor.Named.ForestGreen],[4294902015,73,exports.IColor.Named.Fuchsia],[4292664540,74,exports.IColor.Named.Gainsboro],[4294506751,75,exports.IColor.Named.GhostWhite],[4294956800,76,exports.IColor.Named.Gold],[4292519200,77,exports.IColor.Named.Goldenrod],[4286611584,78,exports.IColor.Named.Gray],[4278222848,79,exports.IColor.Named.Green],[4289593135,80,exports.IColor.Named.GreenYellow],[4293984240,81,exports.IColor.Named.Honeydew],[4294928820,82,exports.IColor.Named.HotPink],[4291648604,83,exports.IColor.Named.IndianRed],[4283105410,84,exports.IColor.Named.Indigo],[4294967280,85,exports.IColor.Named.Ivory],[4293977740,86,exports.IColor.Named.Khaki],[4293322490,87,exports.IColor.Named.Lavender],[4294963445,88,exports.IColor.Named.LavenderBlush],[4286381056,89,exports.IColor.Named.LawnGreen],[4294965965,90,exports.IColor.Named.LemonChiffon],[4289583334,91,exports.IColor.Named.LtBlue],[4293951616,92,exports.IColor.Named.LtCoral],[4292935679,93,exports.IColor.Named.LtCyan],[4294638200,94,exports.IColor.Named.LtGoldenrodYellow],[4292072403,95,exports.IColor.Named.LtGray],[4287688336,96,exports.IColor.Named.LtGreen],[4294948545,97,exports.IColor.Named.LtPink],[4294942842,98,exports.IColor.Named.LtSalmon],[4280332970,99,exports.IColor.Named.LtSeaGreen],[4287090426,100,exports.IColor.Named.LtSkyBlue],[4286023833,101,exports.IColor.Named.LtSlateGray],[4289774814,102,exports.IColor.Named.LtSteelBlue],[4294967264,103,exports.IColor.Named.LtYellow],[4278255360,104,exports.IColor.Named.Lime],[4281519410,105,exports.IColor.Named.LimeGreen],[4294635750,106,exports.IColor.Named.Linen],[4294902015,107,exports.IColor.Named.Magenta],[4286578688,108,exports.IColor.Named.Maroon],[4284927402,109,exports.IColor.Named.MedAquamarine],[4278190285,110,exports.IColor.Named.MedBlue],[4290401747,111,exports.IColor.Named.MedOrchid],[4287852763,112,exports.IColor.Named.MedPurple],[4282168177,113,exports.IColor.Named.MedSeaGreen],[4286277870,114,exports.IColor.Named.MedSlateBlue],[4278254234,115,exports.IColor.Named.MedSpringGreen],[4282962380,116,exports.IColor.Named.MedTurquoise],[4291237253,117,exports.IColor.Named.MedVioletRed],[4279834992,118,exports.IColor.Named.MidnightBlue],[4294311930,119,exports.IColor.Named.MintCream],[4294960353,120,exports.IColor.Named.MistyRose],[4294960309,121,exports.IColor.Named.Moccasin],[4294958765,122,exports.IColor.Named.NavajoWhite],[4278190208,123,exports.IColor.Named.Navy],[4294833638,124,exports.IColor.Named.OldLace],[4286611456,125,exports.IColor.Named.Olive],[4285238819,126,exports.IColor.Named.OliveDrab],[4294944e3,127,exports.IColor.Named.Orange],[4294919424,128,exports.IColor.Named.OrangeRed],[4292505814,129,exports.IColor.Named.Orchid],[4293847210,130,exports.IColor.Named.PaleGoldenrod],[4288215960,131,exports.IColor.Named.PaleGreen],[4289720046,132,exports.IColor.Named.PaleTurquoise],[4292571283,133,exports.IColor.Named.PaleVioletRed],[4294963157,134,exports.IColor.Named.PapayaWhip],[4294957753,135,exports.IColor.Named.PeachPuff],[4291659071,136,exports.IColor.Named.Peru],[4294951115,137,exports.IColor.Named.Pink],[4292714717,138,exports.IColor.Named.Plum],[4289781990,139,exports.IColor.Named.PowderBlue],[4286578816,140,exports.IColor.Named.Purple],[4294901760,141,exports.IColor.Named.Red],[4290547599,142,exports.IColor.Named.RosyBrown],[4282477025,143,exports.IColor.Named.RoyalBlue],[4287317267,144,exports.IColor.Named.SaddleBrown],[4294606962,145,exports.IColor.Named.Salmon],[4294222944,146,exports.IColor.Named.SandyBrown],[4281240407,147,exports.IColor.Named.SeaGreen],[4294964718,148,exports.IColor.Named.SeaShell],[4288696877,149,exports.IColor.Named.Sienna],[4290822336,150,exports.IColor.Named.Silver],[4287090411,151,exports.IColor.Named.SkyBlue],[4285160141,152,exports.IColor.Named.SlateBlue],[4285563024,153,exports.IColor.Named.SlateGray],[4294966010,154,exports.IColor.Named.Snow],[4278255487,155,exports.IColor.Named.SpringGreen],[4282811060,156,exports.IColor.Named.SteelBlue],[4291998860,157,exports.IColor.Named.Tan],[4278222976,158,exports.IColor.Named.Teal],[4292394968,159,exports.IColor.Named.Thistle],[4294927175,160,exports.IColor.Named.Tomato],[4282441936,161,exports.IColor.Named.Turquoise],[4293821166,162,exports.IColor.Named.Violet],[4294303411,163,exports.IColor.Named.Wheat],[4294967295,164,exports.IColor.Named.White],[4294309365,165,exports.IColor.Named.WhiteSmoke],[4294967040,166,exports.IColor.Named.Yellow],[4288335154,167,exports.IColor.Named.YellowGreen],[4293980400,168,exports.IColor.Named.ButtonFace],[4294967295,169,exports.IColor.Named.ButtonHighlight],[4288716960,170,exports.IColor.Named.ButtonShadow],[4290367978,171,exports.IColor.Named.GradientActiveCaption],[4292338930,172,exports.IColor.Named.GradientInactiveCaption],[4293980400,173,exports.IColor.Named.MenuBar],[4281571839,174,exports.IColor.Named.MenuHighlight]];const ua=new class{constructor(){this._lookupByName=new Map;for(let t=0;t<da.length;t++){const e=da[t],r=e[0],n=(r>>24&255)/255,o=r>>16&255,s=r>>8&255,i=255&r,a={id:e[1],name:e[2],rgbaColor:{r:o,g:s,b:i,a:n},system:e.length>3};this._lookupByName.set(a.name.toLowerCase(),a)}}valueOfName(t){return this._lookupByName.get(t?t.toLowerCase():"transparent")}},ga=[{scheme:exports.IColor.Scheme.Tx1,description:"First Text Color"},{scheme:exports.IColor.Scheme.Tx2,description:"Second Text Color"},{scheme:exports.IColor.Scheme.Bg1,description:"First Background Color"},{scheme:exports.IColor.Scheme.Bg2,description:"Second Background Color"},{scheme:exports.IColor.Scheme.Accent1,description:"Accent 1"},{scheme:exports.IColor.Scheme.Accent2,description:"Accent 2"},{scheme:exports.IColor.Scheme.Accent3,description:"Accent 3"},{scheme:exports.IColor.Scheme.Accent4,description:"Accent 4"},{scheme:exports.IColor.Scheme.Accent5,description:"Accent 5"},{scheme:exports.IColor.Scheme.Accent6,description:"Accent 6"},{scheme:exports.IColor.Scheme.Hlink,description:"Hyperlink"},{scheme:exports.IColor.Scheme.FolHlink,description:"Followed Hyperlink"},{scheme:"dk1",description:"Text/Background - Dark 1"},{scheme:"lt1",description:"Text/Background - Light 1"},{scheme:"dk2",description:"Text/Background - Dark 2"},{scheme:"lt2",description:"Text/Background - Light 2"}],pa=new Map;for(let t=0;t<ga.length;t++)pa.set(ga[t].scheme.toLowerCase(),ga[t]);const ma=t=>t?{srgb:[t.red/255,t.green/255,t.blue/255],alpha:void 0!==t.alpha?t.alpha:1}:null,fa=function(t,e,r,n){let o=ma((t=>{let e=ua.valueOfName(t);return e?new To.RGBA(e.rgbaColor.r,e.rgbaColor.g,e.rgbaColor.b,e.rgbaColor.a):null})(t)),s=null,i=null,a=null;if(null===o&&(l=t,pa.get(l.toLowerCase()))){if(!e)throw new Error("a scheme val was used but a schemeLookup was not provided");s=t,i=e(s),o=ma(i),a=exports.IColor.Type.Scheme}var l;if(null===o){let e=t.match(Hn)||t.match(Vn);if(e){let t,r=1;4===e.length?t=[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]:(t=[parseInt(e[2],16),parseInt(e[3],16),parseInt(e[4],16)],r=Jn(parseInt(e[1],16)/255)),t=Gn(t),t=qn(t),o={srgb:t,alpha:r},a=exports.IColor.Type.Hex}}if(null===o){let e=t.match(Bn)||t.match(Ln);if(e){let t=Un(e[1],e[2],e[3]);t=Gn(t),t=qn(t),o={srgb:t,alpha:e[4]?Jn(parseFloat(e[4])):1},a=exports.IColor.Type.RGB}}if(null===o){let e=t.match(Dn)||t.match(zn);if(e){let t=Un(e[1],e[2],e[3]);t=Gn(t,100),t=Yn(t),t=qn(t),o={srgb:t,alpha:e[4]?Jn(parseFloat(e[4])):1},a=exports.IColor.Type.LRGB}}if(null===o){let e=t.match(Pn)||t.match(jn);if(e){let t=Un(e[1],e[2],e[3]);t=to(t),t=qn(t),o={srgb:t,alpha:e[4]?Jn(parseFloat(e[4])):1},a=exports.IColor.Type.HSL}}if(null===o){let e=t.match($n);if(e){const t=parseInt(e[1]);let n=r?.(t)??Lo(t);n&&(o={srgb:[n.red/255,n.green/255,n.blue/255],alpha:n.alpha},a=exports.IColor.Type.Index)}}if(null===o)throw new Error("Not a valid color format: "+t);return{srgbAlpha:o,key:s,color:i,type:a}},_a=new Map,Sa=Object.keys(exports.IColor.AdjustmentType);for(let t=0;t<Sa.length;t++)_a.set(exports.IColor.AdjustmentType[Sa[t]].toLowerCase(),exports.IColor.AdjustmentType[Sa[t]]);const wa=new RegExp("\\s+\\s*(?![^()]*\\))|,\\s*(?![^()]*\\))"),ya=new RegExp("\\s*[,]\\s*|\\s+");let xa=null;const Ca={[exports.IColor.Scheme.Bg1]:"window",[exports.IColor.Scheme.Bg2]:"E7E6E6",[exports.IColor.Scheme.Tx1]:"windowText",[exports.IColor.Scheme.Tx2]:"44546A",[exports.IColor.Scheme.Accent1]:"4472C4",[exports.IColor.Scheme.Accent2]:"ED7D31",[exports.IColor.Scheme.Accent3]:"A5A5A5",[exports.IColor.Scheme.Accent4]:"FFC000",[exports.IColor.Scheme.Accent5]:"5B9BD5",[exports.IColor.Scheme.Accent6]:"70AD47",[exports.IColor.Scheme.Hlink]:"0563C1",[exports.IColor.Scheme.FolHlink]:"954F72"};class ba{constructor(t,e,r,n=null){let o=null,s=null;if(t instanceof ba)o=t.getVal(),t.getAdjustments()&&(s=[...t.getAdjustments()]);else if("string"==typeof t){const e=this._parse(t);o=e.val,s=e.adjs}else t?.val&&(o=t.val,s=t.adjs);if(!o)throw new Error("Unable to determine color value");this._private={val:o,adjs:s,schemeLookup:e,indexedLookup:r,parsedVal:fa(o,e,r),adjusted:null,resolved:null}}_parse(t){let e=null,r=t.toLowerCase().trim();const n=r.split(wa);if(n&&(e=n[0],r=r.substring(e.length,r.length).trim()),!e)throw new Error("no color key found");const o=[],s=r.split(ya);for(let t=0;t<s.length;t++){const e=s[t];if(!e)continue;const r=_a.get(e.toLowerCase());if(!r)throw new Error("Invalid adjustment type:"+e);let n=null;if(r===exports.IColor.AdjustmentType.Gray||r===exports.IColor.AdjustmentType.Comp||r===exports.IColor.AdjustmentType.Inv||r===exports.IColor.AdjustmentType.Gamma||r===exports.IColor.AdjustmentType.InvGamma);else{t++;const r=s[t];if(n=parseFloat(r),null==n)throw new Error(`Invalid adjustment value: missing value for'${e}'`);if(isNaN(n))throw new Error("Invalid adjustment value:"+r)}o.push({[r]:n})}return{val:e,adjs:o}}_forceDark(t=!0){this._resolve();const e=this._private.resolved;let r=[e.red,e.green,e.blue];r=((t,e)=>{e=(e%360+360)%360;const r=[1,0,0,0,1,0,0,0,1],n=Math.cos(e*Math.PI/180),o=Math.sin(e*Math.PI/180);r[0]=Ao+.7874*n-Ao*o,r[1]=Ro-Ro*n-Ro*o,r[2]=Mo-Mo*n+.9278*o,r[3]=Ao-Ao*n+.143*o,r[4]=Ro+(1-Ro)*n+.14*o,r[5]=Mo-Mo*n-.283*o,r[6]=Ao-Ao*n-.7874*o,r[7]=Ro-Ro*n+Ro*o,r[8]=Mo+.9278*n+Mo*o;const s=t=>Math.round(Math.max(0,Math.min(255,t))),i=t[0],a=t[1],l=t[2];return[s(r[0]*i+r[1]*a+r[2]*l),s(r[3]*i+r[4]*a+r[5]*l),s(r[6]*i+r[7]*a+r[8]*l)]})(r,180),r=bo(r,!1);let n=Kn(r);const o=ro(n);if(o[so]=.95*o[so],n=to(o),r=Yn(n),r=Wn(r),r=qn(r,!1),t)return new To.RGBA(r[0],r[1],r[2],e.alpha);const s=ro(Kn(r));return new To.HSLA(s[0],s[1],s[2],e.alpha)}_resolve(){if(this._private.resolved){if(!this._private.parsedVal.key)return;let t=this._private.schemeLookup(this._private.parsedVal.key);if(t===this._private.parsedVal.color||t?.isEqual(this._private.parsedVal.color))return}const t=fa(this._private.val,this._private.schemeLookup,this._private.indexedLookup,this._private.last);let e=((t,e)=>{let r=[...t.srgb],n=void 0!==t.alpha?t.alpha:1;for(var o=0;e&&o<e.length;o++){const t=e[o],s=Object.keys(t)[0],i=t[s];s===exports.IColor.AdjustmentType.Alpha?(n=i/100,n=Math.max(0,Math.min(1,n))):s===exports.IColor.AdjustmentType.AlphaOff?(n+=i/100,n=Math.max(0,Math.min(1,n))):s===exports.IColor.AdjustmentType.AlphaMod?(n*=i/100,n=Math.max(0,Math.min(1,n))):s===exports.IColor.AdjustmentType.Hue?r=_o(no,r,i):s===exports.IColor.AdjustmentType.Sat?r=_o(oo,r,i):s===exports.IColor.AdjustmentType.Lum?r=_o(so,r,i):s===exports.IColor.AdjustmentType.HueOff?r=So(no,r,i):s===exports.IColor.AdjustmentType.SatOff?r=So(oo,r,i):s===exports.IColor.AdjustmentType.LumOff?r=So(so,r,i):s===exports.IColor.AdjustmentType.HueMod?r=wo(no,r,i):s===exports.IColor.AdjustmentType.SatMod?r=wo(oo,r,i):s===exports.IColor.AdjustmentType.LumMod?r=wo(so,r,i):s===exports.IColor.AdjustmentType.Red?r=yo(io,r,i,co):s===exports.IColor.AdjustmentType.Green?r=yo(ao,r,i,co):s===exports.IColor.AdjustmentType.Blue?r=yo(lo,r,i,co):s===exports.IColor.AdjustmentType.RedOff?r=yo(io,r,i,ho):s===exports.IColor.AdjustmentType.GreenOff?r=yo(ao,r,i,ho):s===exports.IColor.AdjustmentType.BlueOff?r=yo(lo,r,i,ho):s===exports.IColor.AdjustmentType.RedMod?r=yo(io,r,i,uo):s===exports.IColor.AdjustmentType.GreenMod?r=yo(ao,r,i,uo):s===exports.IColor.AdjustmentType.BlueMod?r=yo(lo,r,i,uo):s===exports.IColor.AdjustmentType.Shade?r=go(r,i):s===exports.IColor.AdjustmentType.Tint?r=fo(r,i):s===exports.IColor.AdjustmentType.ETint?r=mo(r,i):s===exports.IColor.AdjustmentType.Gray?r=xo(r):s===exports.IColor.AdjustmentType.Comp?r=Co(r):s===exports.IColor.AdjustmentType.Inv?r=bo(r,i):s===exports.IColor.AdjustmentType.Gamma?r=Eo(r):s===exports.IColor.AdjustmentType.InvGamma?r=vo(r):console.warn("unknown adjustmentType: "+s)}return{srgb:r,alpha:n}})(t.srgbAlpha,this._private.adjs),r=((t,e=255)=>{const r=[...t];for(var n=0;n<t.length;n++)r[n]=t[n]*e;return r})(e.srgb);r=Wn(r);let n=Jn(e.alpha);this._private.adjusted=e,this._private.parsedVal=t,this._private.resolved=new To.RGBA(r[0],r[1],r[2],n)}static parse(t,e,r,n=null){if(t instanceof ba)return t;const o=t;let s=null,i=o?.trim(),a=null;try{if(!s){const t=i?.split(wa);t&&(s=t[0],i=i.substring(s.length,i.length).trim())}if(!s)throw new Error("no color found");const t=[],o=i.split(ya);for(let e=0;e<o.length;e++){const r=o[e];if(!r)continue;const n=_a.get(r.toLowerCase());if(!n)throw new Error("Invalid adjustment type:"+r);let s=null;if(n===exports.IColor.AdjustmentType.Gray||n===exports.IColor.AdjustmentType.Comp||n===exports.IColor.AdjustmentType.Inv||n===exports.IColor.AdjustmentType.Gamma||n===exports.IColor.AdjustmentType.InvGamma);else{e++;const t=o[e];if(s=parseFloat(t),null==s)throw new Error(`Invalid adjustment value: missing value for'${r}'`);if(isNaN(s))throw new Error("Invalid adjustment value:"+t)}t.push({[n]:s})}a=new ba({val:s,adjs:t},e,r,n)}catch(t){throw t}return a}static getDefaultSchemeLookup(){if(!xa){const t=new Map,e=Object.keys(Ca);for(let r=0;r<e.length;r++){const n=e[r];t.set(n.toLowerCase(),ba.parse(Ca[n],null))}xa=e=>t.get(e.toLowerCase())?.toRGBA()}return xa}isEqual(t){return t instanceof ba&&this.toString().toLowerCase()===t.toString().toLowerCase()}getVal(){return this._private.val}getAdjustments(){return this._private.adjs}adjust(t){return new ba({val:this._private.val,adjs:this._private.adjs?this._private.adjs.concat(t):t},this._private.schemeLookup,this._private.indexedLookup,this._private.last)}getType(){return this._resolve(),this._private.parsedVal.type??null}toCSS(t=!1,e=!0){const r=t?this._forceDark():this.toRGBA();return 0===r.alpha?"none":r.toString(e)}toRGBA(t=!1){return this._resolve(),t?this._forceDark():this._private.resolved}toHSLA(t=!1){if(this._resolve(),t)return this._forceDark(!1);let e=ro(this._private.adjusted.srgb);return new To.HSLA(e[0],e[1],e[2],Jn(this._private.adjusted.alpha??1))}toHex(t=!1){this._resolve();const e=t?this._forceDark():this._private.resolved;return new To.HEX(e.red,e.green,e.blue,e.alpha??1)}toBlackOrWhite(t=!1,e=157){const r=this.toRGBA(t),n=.299*r.red+.587*r.green+.114*r.blue>e;return new ba(n?"#000000":"#FFFFFF",this._private.schemeLookup,this._private.indexedLookup,this._private.last)}get[Symbol.toStringTag](){return this.toString()}toString(){let t=this._private.val;const e=this._private.adjs;for(let r=0;e&&r<e.length;r++){const n=e[r];if(!n)continue;const o=Object.keys(n)[0];t+=" "+o;const s=n[o];"number"==typeof s&&(t+=" "+s),r<e.length-1&&(t+=",")}return t}get isIColor(){return!0}}var Ea;exports.IBorder=void 0,(Ea=exports.IBorder||(exports.IBorder={})).StrokeStyle={None:"none",DashDot:"dashDot",MediumDashDot:"mediumDashDot",Dotted:"dotted",Hair:"hair",Thin:"thin",Medium:"medium",Thick:"thick",MediumDashDotDot:"mediumDashDotDot",DashDotDot:"dashDotDot",Dashed:"dashed",MediumDashed:"mediumDashed",SlantDashDot:"slantDashDot",Double:"double"},Ea.Edge={Left:"left",Top:"top",Right:"right",Bottom:"bottom",Horizontal:"horizontal",Vertical:"vertical",DiagonalUp:"diagonalUp",DiagonalDown:"diagonalDown"};const va=[],Ia=new Map,Aa=Object.freeze([[exports.IBorder.StrokeStyle.Thin,"Thin",1,null],[exports.IBorder.StrokeStyle.Hair,"Hair",1,[1,1]],[exports.IBorder.StrokeStyle.Dotted,"Dotted",1,[2,2]],[exports.IBorder.StrokeStyle.Dashed,"Dashed",1,[3,1]],[exports.IBorder.StrokeStyle.DashDot,"Dash Dot",1,[3,3,9,3]],[exports.IBorder.StrokeStyle.DashDotDot,"Dash Dot Dot",1,[3,3,3,3,9,3]],[exports.IBorder.StrokeStyle.Double,"Double",3,null],[exports.IBorder.StrokeStyle.Medium,"Medium",2,null],[exports.IBorder.StrokeStyle.MediumDashed,"Medium Dashed",2,[9,3]],[exports.IBorder.StrokeStyle.MediumDashDot,"Medium Dash Dot",2,[3,3,9,3]],[exports.IBorder.StrokeStyle.MediumDashDotDot,"Medium Dash Dot Dot",2,[3,3,3,3,9,3]],[exports.IBorder.StrokeStyle.SlantDashDot,"Slant Dash Dot",2,[5,1,11,1]],[exports.IBorder.StrokeStyle.Thick,"Thick",3,null],[exports.IBorder.StrokeStyle.None,"None",0,null]]);for(let t=0;t<Aa.length;t++){const e=Aa[t],r=e[0],n=Object.freeze({style:r,description:e[1],width:e[2],pattern:e[3]});va.push(n),Ia.set(r,n)}(t=>{t.isEqualStrokes=(t,e)=>!(t&&!e||e&&!t)&&(t===e||t.getStyle()===e.getStyle()&&t.getColor().isEqual(e.getColor())),t.oppositeEdge=e=>e===t.Edge.Left?t.Edge.Right:e===t.Edge.Right?t.Edge.Left:e===t.Edge.Top?t.Edge.Bottom:e===t.Edge.Bottom?t.Edge.Top:e,t.BuiltInDefinitionsArray=va,t.BuiltInDefinitions=Ia})(exports.IBorder||(exports.IBorder={}));const Ra={Text:"text",Repeat:"repeat",Spacing:"spacing"},Ma=t=>!(!t.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)&&!t.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)),Ta=Object.freeze({formatValue:$o,isFractionFormat:Ma,adjustDecimalPlaces:(t,e)=>{if(!t)return"";const r=(t,e)=>{let r=t||"";const n=0===r.length||r.endsWith(".")?"0":r.charAt(r.length-1);return e<0?(r=r.substring(0,Math.max(0,r.length+e)),"."===r&&(r="")):(r.startsWith(".")||(r+="."),r+=n.repeat(e)),r},n=(t,e)=>{if("General"===t)return e>0?"0"+r("",e):t;if(Ma(t))return t;let n=t,o=-1,s=-1,i=n.indexOf("E");if(i>=0&&(n=n.substring(0,i)),o=n.indexOf("."),o>=0){n=n.substring(o,n.length);let e=n&&n.match(/([.]{1}[0,#]+)/);if(!e)return t;n=e[1],s=o+n.length}else{if(e<=0)return t;o=n.lastIndexOf("0"),o<0&&(o=n.lastIndexOf("#")),o>=0&&(o+=1),s=o,n=""}return-1===o?t:(n=r(n,e),t.substring(0,o)+n+t.substring(s,t.length))},o=[];let s=Vo(t);for(let t=0;t<s.length;t++)o.push(n(s[t].trim(),e));return o.join(";")}}),Fa=kn._table,Na=t=>14===t?"Short Date":Fa[t]??null,ka=[{numberFormat:"General",formatType:Do.General,primary:1},{numberFormat:"0",formatType:Do.Number,regMatch:/^0[.]{0,1}[0]*$/,args:{decimalPlaces:0,separator:!1}},{numberFormat:"#,##0.00",formatType:Do.Number,regMatch:/^#,##0[.]{0,1}[0]*$/,primary:2,args:{decimalPlaces:2,separator:!0}},{numberFormat:"#,##0_);(#,##0)",formatType:Do.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:"#,##0_);[Red](#,##0)",formatType:Do.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:"#,##0.00_);(#,##0.00)",formatType:Do.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:"#,##0.00_);[Red](#,##0.00)",formatType:Do.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:"$#,##0.00",formatType:Do.Currency,primary:3,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:"$#,##0_);($#,##0)",formatType:Do.Currency,args:{decimalPlaces:0,currencySymbol:"$"}},{numberFormat:"$#,##0_);[Red]($#,##0)",formatType:Do.Currency,args:{decimalPlaces:0,currencySymbol:"$"}},{numberFormat:"$#,##0.00_);($#,##0.00)",formatType:Do.Currency,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:"$#,##0.00_);[Red]($#,##0.00)",formatType:Do.Currency,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',primary:4,formatType:Do.Accounting},{numberFormat:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)',formatType:Do.Accounting},{numberFormat:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',formatType:Do.Accounting},{numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',formatType:Do.Accounting},{numberFormat:"Short Date",formatType:Do.ShortDate,primary:5},{numberFormat:"d-mmm-yy",formatType:Do.MediumDate,primary:5.5},{numberFormat:"Long Date",formatType:Do.LongDate,primary:6},{numberFormat:"h:mm",formatType:Do.ShortTime,primary:7},{numberFormat:"h:mm AM/PM",formatType:Do.MediumTime,primary:7.5},{numberFormat:"Long Time",formatType:Do.LongTime,primary:8},{numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',formatType:Do.Comma,primary:9},{numberFormat:"0.00%",formatType:Do.Percentage,primary:10,args:{decimalPlaces:2},regMatch:/^^[0#?]*[.]{0,1}[0#?]*%*$/},{numberFormat:"0%",formatType:Do.Percentage,args:{decimalPlaces:0}},{numberFormat:"# ?/?",formatType:Do.Fraction,primary:11},{numberFormat:"# ??/??",formatType:Do.Fraction},{numberFormat:"0.00E+00",formatType:Do.Scientific,primary:12,args:{decimalPlaces:2},regMatch:/^[0#?]*[.]{0,1}[0#?]*E\+[0#?]*$/},{numberFormat:"##0.0E+0",formatType:Do.Custom,args:{decimalPlaces:0}},{numberFormat:"@",formatType:Do.Text,primary:13},{numberFormat:"d-mmm",formatType:Do.Custom},{numberFormat:"mmm-yy",formatType:Do.Custom},{numberFormat:"h:mm:ss",formatType:Do.Custom},{numberFormat:"m/d/yyyy h:mm",formatType:Do.Custom},{numberFormat:"mm:ss",formatType:Do.Custom},{numberFormat:"mm:ss.0",formatType:Do.Custom},{numberFormat:"[h]:mm:ss",formatType:Do.Custom}],Oa=[{numberFormat:"00000",formatType:Do.Special,primary:11},{numberFormat:"00000-0000",formatType:Do.Special},{numberFormat:"[<=9999999]###-####;(###) ###-####",formatType:Do.Special},{numberFormat:"000-00-0000",formatType:Do.Special}],Ba=new Map,La=[];for(let t=0;t<ka.length;t++){let e=ka[t].numberFormat.toLowerCase();Ba.set(e,ka[t]),ka[t].regMatch&&La.unshift(ka[t])}for(let t=0;t<Oa.length;t++){let e=Oa[t].numberFormat.toLowerCase();Ba.set(e,Oa[t])}const Da=[],za=new Map;Ba.forEach(function(t,e,r){t.primary&&(Da.push(t),za.set(mt.textToKey(t.formatType),t.numberFormat))}),Da.sort(function(t,e){return t.primary-e.primary});const Pa=Ba.get(Do.General.toLowerCase());class ja{lookupStyle(t){if(!t)return Pa;if("number"==typeof t&&(t=Na(t)),!t.toLowerCase)return console.warn("Invalid numberFormat",t),Pa;t=t.toLowerCase();let e=Ba.get(t);if(e)return e;for(let r=0;!e&&r<La.length;r++)if(La[r].regMatch){t.match(La[r].regMatch)&&(e=La[r])}return e||{numberFormat:t,formatType:Do.Custom}}lookupPrimary(){return Da}lookupDefault(t){return za.get(mt.textToKey(t))}}var Ha,Va;exports.NumberFormat=void 0,(Ha=exports.NumberFormat||(exports.NumberFormat={})).Type=Do,Ha.Parser=Ta,Ha.Styles=new ja,Ha.ParseRunType=Ra,exports.IStyle=void 0,(Va=exports.IStyle||(exports.IStyle={})).BuiltInName={Normal:"Normal",RowLevel:"RowLevel_#",ColLevel:"ColLevel_#",Comma:"Comma",Currency:"Currency",Percent:"Percent",Comma0:"Comma [0]",Currency0:"Currency [0]",Hyperlink:"Hyperlink",FollowedHyperlink:"Followed Hyperlink",Note:"Note",WarningText:"Warning Text",Unknown12:"??-12",Unknown13:"??-13",Unknown14:"??-14",Title:"Title",Heading1:"Heading 1",Heading2:"Heading 2",Heading3:"Heading 3",Heading4:"Heading 4",Input:"Input",Output:"Output",Calculation:"Calculation",CheckCell:"Check Cell",LinkedCell:"Linked Cell",Total:"Total",Good:"Good",Bad:"Bad",Neutral:"Neutral",Accent1:"Accent1",Accent1_20:"20% - Accent1",Accent1_40:"40% - Accent1",Accent1_60:"60% - Accent1",Accent2:"Accent2",Accent2_20:"20% - Accent2",Accent2_40:"40% - Accent2",Accent2_60:"60% - Accent2",Accent3:"Accent3",Accent3_20:"20% - Accent3",Accent3_40:"40% - Accent3",Accent3_60:"60% - Accent3",Accent4:"Accent4",Accent4_20:"20% - Accent4",Accent4_40:"40% - Accent4",Accent4_60:"60% - Accent4",Accent5:"Accent5",Accent5_20:"20% - Accent5",Accent5_40:"40% - Accent5",Accent5_60:"60% - Accent5",Accent6:"Accent6",Accent6_20:"20% - Accent6",Accent6_40:"40% - Accent6",Accent6_60:"60% - Accent6",ExplanatoryText:"Explanatory Text"},Va.IconSet={Arrows3:"3Arrows",ArrowsGray3:"3ArrowsGray",Flags3:"3Flags",Signs3:"3Signs",Symbols3:"3Symbols",Symbols3_2:"3Symbols2",TrafficLights3:"3TrafficLights1",TrafficLights3_2:"3TrafficLights2",Arrows4:"4Arrows",ArrowsGray4:"4ArrowsGray",Rating4:"4Rating",RedToBlack4:"4RedToBlack",TrafficLights4:"4TrafficLights",Arrows5:"5Arrows",ArrowsGray5:"5ArrowsGray",Quarters5:"5Quarters",Rating5:"5Rating"};const $a=(t,e,r,n,o)=>{const s=JSON.parse(JSON.stringify(t.definition));s.adjs||(s.adjs=[]);let i="",a=0,l=0;e>0?(l=e,a=100-e,i=`Lighter ${e}%`):e<0&&(a=100+e,i=`Darker ${-e}%`),a&&s.adjs.push({[exports.IColor.AdjustmentType.LumMod]:a}),l&&s.adjs.push({[exports.IColor.AdjustmentType.LumOff]:l});const c=new ba({val:s.val,adjs:s.adjs},r),h=c.toString();n?.set(h,c);const d=c.toRGBA().toString();return o?.set(d,c),{description:t.description+", "+i,definition:s}},Ua=(t,e,r,n)=>{let o=[];for(let s=0;s<t.length;s++){let i=[];o.push(i);const a=o=>{for(let a=0;a<o.length;a++)i.push($a(t[s],o[a],e,r,n))};let l=new ba({val:t[s].definition.val,adjs:t[s].definition.adjs},e).toHSLA().lum;a(0===l?[50,35,25,15,5]:100===l?[-5,-15,-25,-35,-50]:l<=20?[90,75,50,25,10]:l>=80?[-10,-25,-50,-75,-90]:[80,60,40,-25,-50])}return o};exports.ITheme=void 0,(exports.ITheme||(exports.ITheme={})).buildPalette=Ua,exports.IThemeCollection=void 0,(exports.IThemeCollection||(exports.IThemeCollection={})).BuiltInSearchType={BuiltIn:"builtIn",All:"all",Custom:"custom"};const Ga=[["Office","windowText","window","0E2841","E8E8E8","156082","E97132","196B24","0F9ED5","A02B93","4EA72E","467886","96607D"],["Office 2013-2022","windowText","window","44546A","E7E6E6","4472C4","ED7D31","A5A5A5","FFC000","5B9BD5","70AD47","0563C1","954F72"],["Office 2007-2010","windowText","window","1F497D","EEECE1","4F81BD","C0504D","9BBB59","8064A2","4BACC6","F79646","0000FF","800080"],["Grayscale","windowText","window","000000","F8F8F8","DDDDDD","B2B2B2","969696","808080","5F5F5F","4D4D4D","5F5F5F","919191"],["Atlas","windowText","window","454545","E0E0E0","F81B02","FC7715","AFBF41","50C49F","3B95C4","B560D4","FC5A1A","B49E74"],["Banded","2C2C2C","FFFFFF","099BDD","F2F2F2","FFC000","A5D028","08CC78","F24099","828288","F56617","005DBA","6C606A"],["Basis","000000","FFFFFF","565349","DDDDDD","A6B727","DF5327","FE9E00","418AB3","D7D447","818183","F59E00","B2B2B2"],["Berlin","windowText","window","9D360E","E7E6E6","F09415","C1B56B","4BAF73","5AA6C0","D17DF9","FA7E5C","FFAE3E","FCC77E"],["Celestial","windowText","window","18276C","EBEBEB","AC3EC1","477BD1","46B298","90BA4C","DD9D31","E25247","C573D2","CCAEE8"],["Circuit","windowText","window","134770","82FFFF","9ACD4C","FAA93A","D35940","B258D3","63A0CC","8AC4A7","B8FA56","7AF8CC"],["Damask","windowText","window","2A5B7F","ABDAFC","9EC544","50BEA3","4A9CCC","9A66CA","C54F71","DE9C3C","6BA9DA","A0BCD3"],["Depth","windowText","window","455F51","94D7E4","41AEBD","97E9D5","A2CF49","608F3D","F4DE3A","FCB11C","FBCA98","D3B86D"],["Dividend","windowText","window","3D3D3D","EBEBEB","4D1434","903163","B2324B","969FA7","66B1CE","40619D","828282","A5A5A5"],["Droplet","windowText","window","355071","AABED7","2FA3EE","4BCAAD","86C157","D99C3F","CE6633","A35DD1","56BCFE","97C5E3"],["Facet","windowText","window","2C3C43","EBEBEB","90C226","54A021","E6B91E","E76618","C42F1A","918655","99CA3C","B9D181"],["Frame","000000","FFFFFF","545454","BFBFBF","40BAD2","FAB900","90BB23","EE7008","1AB39F","D5393D","90BB23","EE7008"],["Gallery","windowText","window","454545","DFDBD5","B71E42","DE478E","BC72F0","795FAF","586EA6","6892A0","FA2B5C","BC658E"],["Integral","windowText","window","335B74","DFE3E5","1CADE4","2683C6","27CED7","42BA97","3E8853","62A39F","6B9F25","B26B02"],["Ion Boardroom","windowText","window","3B3059","EBEBEB","B31166","E33D6F","E45F3C","E9943A","9B6BF2","D53DD0","8F8F8F","A5A5A5"],["Ion","windowText","window","1E5155","EBEBEB","B01513","EA6312","E6B729","6AAC90","54849A","9E5E9B","58C1BA","9DFFCB"],["Madison","windowText","window","1F2D29","C5FAEB","A1D68B","5EC795","4DADCF","CDB756","E29C36","8EC0C1","6D9D9B","6D8583"],["Main Event","windowText","window","424242","C8C8C8","B80E0F","A6987D","7F9A71","64969F","9B75B2","80737A","F21213","B6A394"],["Mesh","windowText","window","363D46","EBEBEB","6F6F6F","BFBFA5","DCD084","E7BF5F","E9A039","CF7133","F28943","F1B76C"],["Metropolitan","windowText","window","162F33","EAF0E0","50B4C8","A8B97F","9B9256","657689","7A855D","84AC9D","2370CD","877589"],["Organic","windowText","window","212121","DADADA","83992A","3C9770","44709D","A23C33","D97828","DEB340","A8BF4D","B4CA80"],["Parallax","windowText","window","212121","CDD0D1","30ACEC","80C34F","E29D3E","D64A3B","D64787","A666E1","3085ED","82B6F4"],["Parcel","000000","FFFFFF","4A5356","E8E3CE","F6A21D","9BAFB5","C96731","9CA383","87795D","A0988C","00B0F0","738F97"],["Quotable","windowText","window","212121","636363","00C6BB","6FEBA0","B6DF5E","EFB251","EF755F","ED515C","8F8F8F","A5A5A5"],["Retrospect","000000","window","637052","CCDDEA","E48312","BD582C","865640","9B8357","C2BC80","94A088","2998E3","8C8C8C"],["Savon","windowText","window","1485A4","E3DED1","1CADE4","2683C6","27CED7","42BA97","3E8853","62A39F","F49100","739D9B"],["Slate","windowText","window","212123","DADADA","BC451B","D3BA68","BB8640","AD9277","A55A43","AD9D7B","E98052","F4B69B"],["Slice","windowText","window","146194","76DBF4","052F61","A50E82","14967C","6A9E1F","E87D37","C62324","0D2E46","356A95"],["Vapor Trail","windowText","window","454545","DADADA","DF2E28","FE801A","E9BF35","81BB42","32C7A9","4A9BDC","F0532B","F38B53"],["View","000000","FFFFFF","46464A","D6D3CC","6F6F74","92A9B9","A7B789","B9A489","8D6374","9B7362","67AABF","ABAFA5"],["Wisp","windowText","window","766F54","E3EACF","A53010","DE7E18","9F8351","728653","92AA4C","6AAC91","FB4A18","FB9318"],["Wood Type","windowText","window","696464","E9E5DC","D34817","9B2D1F","A28E6A","956251","918485","855D5D","CC9900","96A9A9"]],Wa=[["Office","Calibri Light","Calibri"],["Office 2013-2022","Calibri Light","Calibri"],["Office 2007-2010","Calibri Light","Calibri"],["Grayscale","Calibri Light","Calibri"],["Atlas","Calibri Light","Rockwell"],["Banded","Corbel","Corbel"],["Basis","Corbel","Corbel"],["Berlin","Trebuchet MS","Trebuchet MS"],["Celestial","Calibri Light","Calibri"],["Circuit","Tw Cen MT","Tw Cen MT"],["Damask","Bookman Old Style","Rockwell"],["Depth","Corbel","Corbel"],["Madison","Arial","Arial"],["Main Event","Impact","Impact"],["Mesh","Century Gothic","Century Gothic"],["Metropolitan","Calibri Light","Calibri Light"],["Organic","Garamond","Garamond"],["Parallax","Corbel","Corbel"],["Parcel","Gill Sans MT","Gill Sans MT"],["Quotable","Century Gothic","Century Gothic"],["Retrospect","Calibri Light","Calibri"],["Savon","Century Gothic","Century Gothic"],["Slate","Calisto MT","Calisto MT"],["Slice","Century Gothic","Century Gothic"],["Vapor Trail","Century Gothic","Century Gothic"],["View","Century Schoolbook","Century Schoolbook"],["Wisp","Century Gothic","Century Gothic"],["Wood Type","Rockwell Condensed","Rockwell"]],qa=[["Office","Office","Office"],["2013-2022","Office 2013-2022","Office 2013-2022"],["Atlas","Atlas","Atlas"],["Banded","Banded","Banded"],["Basis","Basis","Basis"],["Berlin","Berlin","Berlin"],["Celestial","Celestial","Celestial"],["Circuit","Circuit","Circuit"],["Damask","Damask","Damask"],["Depth","Depth","Depth"],["Dividend","Dividend","Dividend"],["Droplet","Droplet","Droplet"],["Facet","Facet","Facet"],["Frame","Frame","Frame"],["Gallery","Gallery","Gallery"],["Grayscale","Grayscale","Grayscale"],["Integral","Integral","Integral"],["Ion Boardroom","Ion Boardroom","Ion Boardroom"],["Ion","Ion","Ion"],["Madison","Madison","Madison"],["Main Event","Main Event","Main Event"],["Mesh","Mesh","Mesh"],["Metropolitan","Metropolitan","Metropolitan"],["Organic","Organic","Organic"],["Parallax","Parallax","Parallax"],["Parcel","Parcel","Parcel"],["Quotable","Quotable","Quotable"],["Retrospect","Retrospect","Retrospect"],["Savon","Savon","Savon"],["Slate","Slate","Slate"],["Slice","Slice","Slice"],["Vapor Trail","Vapor Trail","Vapor Trail"],["View","View","View"],["Wisp","Wisp","Wisp"],["Wood Type","Wood Type","Wood Type"],["Office 2007-2010","Office 2007-2010","Office 2007-2010"]],Ja="Themes is readonly. To make modifications create a new DocsThemes instance.",Xa={[exports.IColor.Scheme.Bg1]:"lt1",[exports.IColor.Scheme.Bg2]:"lt2",[exports.IColor.Scheme.Tx1]:"dk1",[exports.IColor.Scheme.Tx2]:"dk2",[exports.IColor.Scheme.Accent1]:"accent1",[exports.IColor.Scheme.Accent2]:"accent2",[exports.IColor.Scheme.Accent3]:"accent3",[exports.IColor.Scheme.Accent4]:"accent4",[exports.IColor.Scheme.Accent5]:"accent5",[exports.IColor.Scheme.Accent6]:"accent6",[exports.IColor.Scheme.Hlink]:"hlink",[exports.IColor.Scheme.FolHlink]:"folHlink"},Ka="Office",Ya=[Ka,"Calibri Light","Calibri"],Za=["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"],Qa=t=>{const e={};for(let r=0;r<t.length;r++){const n=t[r],o=n[0],s={name:o};e[o]=s;for(let t=0;t<Za.length;t++){const e=Za[t],r=n[t+1];if(!r)continue;const o=ba.parse(r);r&&(s[e]=o.toString())}}return e},tl=t=>{const e={};for(let r=0;r<t.length;r++){const n=t[r],o=n[0],s={name:o};e[o]=s,s.majorFont=n[1]??Ya[1],s.minorFont=n[2]??Ya[2]}return e},el=Qa([[Ka,"windowText","window","44546A","E7E6E6","4472C4","ED7D31","A5A5A5","FFC000","5B9BD5","70AD47","0563C1","954F72"]]),rl=tl([Ya]),nl=el[Ka],ol=rl[Ka];let sl=null;const il=new class{constructor(){this._colors={};for(let t=0;t<Za.length;t++){const e=Za[t],r=ba.parse(nl[e]);this._colors[e]=r}}getName(){return nl.name}getDk1(){return this._colors.dk1}getLt1(){return this._colors.lt1}getDk2(){return this._colors.dk2}getLt2(){return this._colors.lt2}getAccent1(){return this._colors.accent1}getAccent2(){return this._colors.accent2}getAccent3(){return this._colors.accent3}getAccent4(){return this._colors.accent4}getAccent5(){return this._colors.accent5}getAccent6(){return this._colors.accent6}getHlink(){return this._colors.hlink}getFolHlink(){return this._colors.folHlink}toJSON(){return null}};class al{constructor(t,e=il){this._delegate=e,this._fromJSON(t)}_fromJSON(t){if(this._overrides={},!t)return;const e=Object.keys(t);if(0!==e.length)for(let r=0;r<e.length;r++){const n=e[r];this._overrides[n]="name"===n?t[n]:ba.parse(t[n])}}_value(t,e){return this._overrides&&null!==this._overrides[t]&&void 0!==this._overrides[t]?this._overrides[t]:this._delegate?.[e]?.()}getName(){return this._value("name","getName")}getDk1(){return this._value("dk1","getDk1")}getLt1(){return this._value("lt1","getLt1")}getDk2(){return this._value("dk2","getDk2")}getLt2(){return this._value("lt2","getLt2")}getAccent1(){return this._value("accent1","getAccent1")}getAccent2(){return this._value("accent2","getAccent2")}getAccent3(){return this._value("accent3","getAccent3")}getAccent4(){return this._value("accent4","getAccent4")}getAccent5(){return this._value("accent5","getAccent5")}getAccent6(){return this._value("accent6","getAccent6")}getHlink(){return this._value("hlink","getHlink")}getFolHlink(){return this._value("folHlink","getFolHlink")}toJSON(){const t=mt.toSafeJSON(this._overrides),e=this.getName();return e&&(t.name=e),t}}const ll=new class{constructor(){this._colors={};for(let t=0;t<Za.length;t++){const e=Za[t],r=ba.parse(nl[e]);this._colors[e]=r}}getName(){return ol.name}getMajorFont(){return ol.majorFont}getMinorFont(){return ol.minorFont}getMajorFallbacks(){return ol.majorFallbacks}getMinorFallbacks(){return ol.minorFallbacks}};class cl{constructor(t,e=ll){this._delegate=e,this._fromJSON(t)}_fromJSON(t){if(this._overrides={},!t)return;const e=Object.keys(t);if(0!==e.length)for(let r=0;r<e.length;r++){const n=e[r];this._overrides[n]=t[n]}}_value(t,e){return this._overrides&&null!==this._overrides[t]&&void 0!==this._overrides[t]?this._overrides[t]:this._delegate?.[e]?.()}getName(){return this._value("name","getName")}getMajorFont(){return this._value("majorFont","getMajorFont")}getMinorFont(){return this._value("minorFont","getMinorFont")}getMajorFallbacks(){return this._value("majorFallbacks","getMajorFallbacks")}getMinorFallbacks(){return this._value("minorFallbacks","getMinorFallbacks")}toJSON(){const t=mt.toSafeJSON(this._overrides),e=this.getName();return e&&(t.name=e),t}}class hl{constructor(t,e=null,r=null){if(this._cacheColors=new Map,!e&&t?.name){const r=sl?sl.get(t.name.toLowerCase()):null;r&&(e=r)}if(!e&&sl&&(e=sl.get(Ka.toLowerCase())),this._name=t?.name??e?.getName(),!this._name)throw new Error("Theme must have a name.");this._builtInID=r,this._delegate=e,this._colors=new al(t?.colors,this._delegate?.getColorScheme()),this._fonts=new cl(t?.fonts,this._delegate?.getFontScheme());const n=Xa,o={},s=Object.keys(n);for(let t=0;t<s.length;t++){const e=s[t];o[e]=`get${ks(n[e])}`}o.dk1="getDk1",o.dk2="getDk2",o.lt1="getLt1",o.lt2="getLt2",o.folhlink="getFolHlink",this._colorMap=o;const i=this;this._schemeLookup=t=>{let e=i._cacheColors[t];if(e)return e;const r=i._colorMap[t];if(!r)throw new Error(`Invalid color scheme key: ${t}`);const n=i.getColorScheme();let o=n[r].bind(n)();o||(o=nl[Xa[t]??t]);return e=new ba(o).toRGBA(),i._cacheColors[t]=e,e}}get builtInID(){return this._builtInID??null}getName(){return this._name??this._delegate?.getName()??null}isCustom(){return null!==this._builtInID&&void 0!==this._builtInID}getColorScheme(){return this._colors}getFontScheme(){return this._fonts}schemeLookup(){return this._schemeLookup}parseColor(t){return ba.parse(t,this._schemeLookup)}toJSON(){const t={name:this.getName()},e=this._colors.toJSON();e&&(Object.keys(e).length>1||e.name&&e.name!==t.name)&&(t.colors=e);const r=this._fonts.toJSON();return r&&(Object.keys(r).length>1||r.name&&r.name!==t.name)&&(t.fonts=r),1===Object.keys(t).length&&t.name===Ka?null:t}}const dl=()=>{if(sl)return sl;const t=((t,e,r)=>{const n=[];for(let o=0;o<t.length;o++){const s=t[o],i=s[0],a=e[s[1]]??nl,l=r[s[2]]??ol;n.push({name:i,colors:a,fonts:l})}return n})(qa,Qa(Ga),tl(Wa)),e=new Map;for(let r=0;r<t.length;r++){const n=new hl(t[r]),o=new hl(null,n,r+1);e.set(o.getName().toLowerCase(),o)}return sl=e,e};class ul{constructor(t=null,e=!1){dl(),this._isReadOnly=e,this._customMap=new Map,this._defaultTheme=this.getByName("Office")}getDefaultTheme(){return this._defaultTheme}setDefaultTheme(t){if(this._isReadOnly)throw new Error(Ja);if(!t)throw new Error("Theme cannot be null.");const e=this.getDefaultTheme();return this.getByName(t.getName())||this.setCustomTheme(t),this._defaultTheme=t,e}getByName(t){t=t.toLowerCase();const e=this._customMap.get(t);return e||(sl.get(t)??null)}search(t){const e=t?.type??exports.IThemeCollection.BuiltInSearchType.All,r=new Map;e!==exports.IThemeCollection.BuiltInSearchType.BuiltIn&&e!==exports.IThemeCollection.BuiltInSearchType.All||sl.forEach((t,e)=>r.set(e,t)),e!==exports.IThemeCollection.BuiltInSearchType.Custom&&e!==exports.IThemeCollection.BuiltInSearchType.All||this._customMap.forEach((t,e)=>r.set(e,t)),t?.selected&&r.set(t.selected.getName().toLowerCase(),t.selected);const n=(t=>{const e=[...t];return e.sort((t,e)=>mt.isDefined(t.builtInID)&&!mt.isDefined(e.builtInID)?1:!mt.isDefined(t.builtInID)&&mt.isDefined(e.builtInID)?-1:mt.isDefined(t.builtInID)&&mt.isDefined(e.builtInID)?t.builtInID-e.builtInID:t.getName().localeCompare(e.getName())),e})(Array.from(r.values()));return n}getCount(){return this._customMap.size+sl.size}setCustomTheme(t){if(this._isReadOnly)throw new Error(Ja);const e=t.getName().toLowerCase(),r=this._customMap.get(e);return this._customMap.set(e,t),r??null}deleteCustomTheme(t){if(this._isReadOnly)throw new Error(Ja);let e=null;e="string"==typeof t?t.toLowerCase():t.getName().toLowerCase();const r=this._customMap.get(e);return this._customMap.delete(e),r??null}}exports.ITableStyle=void 0,(exports.ITableStyle||(exports.ITableStyle={})).ElementType={WholeTable:"wholeTable",FirstColumnStripe:"firstColumnStripe",SecondColumnStripe:"secondColumnStripe",FirstRowStripe:"firstRowStripe",SecondRowStripe:"secondRowStripe",LastColumn:"lastColumn",FirstColumn:"firstColumn",HeaderRow:"headerRow",TotalRow:"totalRow",FirstHeaderCell:"firstHeaderCell",LastHeaderCell:"lastHeaderCell",FirstTotalCell:"firstTotalCell",LastTotalCell:"lastTotalCell"},(exports.ITableStyle||(exports.ITableStyle={})).Empty=class{constructor(t){this._normalStyle=t}getName(){return"None"}isShownInTableStyles(){return!1}isShownInPivotStyles(){return!1}getRanged(t){return null}getProperties(){return mt.EmptyObject}isBuiltIn(){return!0}delete(){}toJSON(){return null}get isITableStyle(){return!0}},exports.IAnchored=void 0,(exports.IAnchored||(exports.IAnchored={})).Type={Absolute:"absolute",OneCell:"oneCell",TwoCell:"twoCell"};const gl="Model has been closed. No further operations are allowed.",pl="Name is required";class ml{constructor(t,e){this._listeners=new Set,this._pending=null,this._listeners=new Set,this._transactions=e??new re({transient:!0}),this._src=t;const r=this;this._transactionsRemoveListener=this._transactions?.addListener({onCommitEnd(t){const e=r._pending;if(!e)return;r._pending=null;const n=t.getId(),o=new Set;for(let t=0;t<e.length;t++){const s=e[t];s.commitId===n&&r._doNotify(s.listeners,s.removes,s.options,o)}}})}addListeners(t,e){const r=e?.transactional??this._transactions.isOpenTransaction(),n={listeners:t},o=this,s=()=>{if(!r)return void o._listeners.delete(n);const t=o._transactions.getState(o)?.listeners,e=new Set(t);e.delete(n);const s=o._transactions.beginCommit();try{s.updateState(o,{listeners:e}),s.commit({forceAmend:!0})}catch(t){throw s.rollback(),t}};if(n.remove=e?.once?s:null,r){const t=o._transactions.getState(o)?.listeners,e=new Set(t);e.add(n);const r=this._transactions.beginCommit();try{r.updateState(o,{listeners:e}),r.commit({forceAmend:!0})}catch(t){throw r.rollback(),t}}else o._listeners.add(n);return s}async _doNotify(t,e=null,r,n){const o=r?.source??this._src,s=[],i=r?.params;for(let e=0;e<t.length;e++){const r=t[e];n&&n.has(r)||(n?.add(r),s.push(r(o,i)))}let a=null;if(e&&(a=()=>{for(let t=0;t<e.length;t++)e[t]()}),r?.async)return new Promise(async(t,e)=>{try{const e=await Promise.all(s);a?.(),t(e)}catch(t){a?.(),e(t)}});a?.()}notify(t,e){let r=null,n=null;const o=e=>{e.forEach(e=>{const o=e.listeners[t];o&&(r||(r=[]),r.push(o),e.remove&&(n||(n=[]),n.push(e.remove)))})},s=e?.transactional??this._transactions.isOpenTransaction();if(s){const t=this._transactions.getState(this)?.listeners;t&&o(t)}const i=r,a=n;r=null,n=null,o(this._listeners);const l=r,c=n;if(r=null,n=null,s){if(i&&this._doNotify(i,a,e),l){let t=this._pending;return t||(this._pending=t=[]),t.push({commitId:this._transactions.getCurrentCommit().getId(),listeners:l,removes:c,options:e}),this._doNotify(l,a,e)}}else if(l)return this._doNotify(l,c,e)}close(){this._transactions.remove(this),this._transactionsRemoveListener()}}class fl{constructor(t){this._emitter=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options?.transactions??new re({transient:!0}),this._emitter=new ml(this,this._transactions),this._updateState({isDeleted:!1}),t?.json&&this._fromJSON(t.json),this._options?.setContainerReadOnlyCallback?.(()=>{e._processOnContainerReadOnly()}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,r,n){e._processStateChange(t,r,n)},onRestoreOrRevert(t,r,n){e._processRestoreOrRevert(t,r,n)}}),this._processInit()}_fromJSON(t){}isReadOnly(){return this._options.isReadOnly?.()??!1}isDeleted(){return this._getState().isDeleted??!1}getType(){return this._options.type}get isIModel(){return!0}_processTransactionDone(t){}_getDescription(){return null}_getState(){if(this._closed)throw new Error(gl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_getTransactions(){return this._transactions}_updateState(t,e,r){if(this._closed)throw new Error(gl);if(!t)return;const n=this._beginCommit(e?.description);try{n.updateState(this,t);let e=!1;if(r)for(let t=0;t<r.length;t++){const n=r[t];e=e||"onAnyChange"===n,this._emitter.notify(n)}!e&&r&&r.length>0&&this._emitter.notify("onAnyChange"),n.commit()}catch(t){throw n.rollback(),t}return this}_getEmitter(){return this._emitter}_processInit(){}_processStateChange(t,e,r){}_processRestoreOrRevert(t,e,r){this._emitter.notify("onInvalidated")}delete(t){if(this._getState().isDeleted)throw new Error("Model has been deleted.");this._options.deleteFromContainer&&this._options.deleteFromContainer?.(t),this._delete()}_delete(){const t=this._getDescription(),e="Delete",r=t?`${e} ${t}`:e,n=this._beginCommit(r);try{this._processDelete(),n.commit()}catch(t){throw n.rollback(),t}}_processOnContainerDeleted(){this._processDelete()}_processDelete(){this._updateState({isDeleted:!0},null,["onDelete"])}_processOnContainerReadOnly(){this._emitter.notify("onReadOnlyChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}beginCommit(t){return this._beginCommit(t)}doBatch(t,e){const r=this;return this._transactions.doBatch(t,"string"==typeof e?{description:e}:e,t=>{r._processTransactionDone(t)})}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}}class _l extends fl{_fromJSON(t){const e={};if(e.name=t?.name??null,!e.name)throw new Error(pl);e.comment=t?.comment??null,e.hidden=t?.hidden??!1,e.scope=t?.scope??null,this._updateState(e,{description:this._options.createDescription??"Create Item"+(e.name?` '${e.name}'`:"")})}_toJSON(){const t=this._getState(),e={name:t.name};return t.comment&&(e.comment=t.comment),t.hidden&&(e.hidden=t.hidden),t.hidden&&(e.hidden=t.hidden),e}getName(){return this._getState().name}setName(t,e){if(!t)throw new Error(pl);return this._updateState({name:t},{description:`Update Named '${t}'`,...e})}getComment(){return this._getState().comment}setComment(t,e){return this._updateState({comment:t},{description:"Set Comment",...e})}isHidden(){return this._getState().hidden}getScope(){return this._getState().scope}get isINamed(){return!0}}var Sl;exports.ISort=void 0,(exports.ISort||(exports.ISort={})).SortOn={Value:"value",FillColor:"fillColor",FontColor:"fontColor",Icon:"icon"},exports.Sort=void 0,(Sl=exports.Sort||(exports.Sort={})).CaseInsensitiveOptions={sensitivity:"base",numeric:!1},Sl.CaseSensitiveOptions={sensitivity:"case",numeric:!1},Sl.BooleanCollator=Object.freeze({type:t.Boolean,compare:(t,e,r)=>!0===t?1:-1}),Sl.StringCollator=Object.freeze({type:t.String,compare:(t,e,r)=>t.localeCompare(e,"en",r),defaultOptions:Sl.CaseInsensitiveOptions}),Sl.NumberCollator=Object.freeze({type:t.Number,compare:(t,e,r)=>t<e?-1:1}),Sl.RichDataCollator=Object.freeze({type:t.RichData,compare:(t,e,r)=>{const n=t.type.localeCompare(e.type,"en");return n}}),Sl.DefaultRangeOptions=Object.freeze({hasHeader:!1,reverse:!1,includeHidden:!1,collatorOptions:Sl.CaseInsensitiveOptions,orientation:exports.t.Orientation.Row,offset:0}),Sl.DefaultCollators=Object.freeze([Sl.BooleanCollator,Sl.StringCollator,Sl.NumberCollator,Sl.RichDataCollator]);const wl=(t,e,r,n)=>{let o;for(;!(o=t.next()).done;)try{e(o.value[1],o.value[0],r)}catch(e){if("function"!=typeof t.throw)throw e;t.throw(e)}"function"==typeof t.return&&t.return()},yl=t=>{const e=t.next.bind(t),r={next:t=>{const r=e(t);return r.done?Cl:{done:r.done,value:r.value[1]}},[Symbol.iterator]:()=>r,...t.return&&{return:t.return.bind(t)},...t.throw&&{throw:t.throw.bind(t)}};return r},xl=t=>{if(!t||0===t.length)return null;let e=Number.MAX_SAFE_INTEGER,r=-1,n=null;return(o,s=!1)=>{if(o===e)return o;false!==s&&(e=Number.MAX_SAFE_INTEGER),o!==e+(s?-1:1)&&(r=((t,e,r=!0)=>{if(!t||0===t.length)return null;let n,o=-1;return r?(o=mt.findEqualOrGreater(t,e,t=>t.max),n=t[o]):(o=mt.findEqualOrLesser(t,e,t=>t.min),n=t[o]),n?(r?e>n.max&&(o+=1,n=t[o]):e<n.min&&(o-=1,n=t[o]),n?o:-1):-1})(t,o,!s),n=t[r]);let i=o;if(s)for(;n&&i<=n.max;)i=n.min-1,n=t[--r];else for(;n&&i>=n.min;)i=n.max+1,n=t[++r];return e=i,i}},Cl=Object.freeze({done:!0,value:void 0}),bl=Object.freeze({next:()=>Cl,[Symbol.iterator]:()=>bl});var El;Object.seal({done:!1,value:void 0}),(t=>{t.isList=t=>!!t&&!!t.isIList,t.isListLike=t=>!!t&&("number"==typeof t.length&&"function"==typeof t.at),t.fromArray=(t,r,n,o)=>new e(t,r,n,o);class e{constructor(t,e,r,n){this.g=e,this.s=r;let o=t??n;if(r&&t&&!n){n=new Array(t.length);for(let e=0;e<t.length;e++){let o=t[e];n[e]=r(o,e)}o=n}this.a=o??mt.EmptyArray,e&&(this.at=t=>{t<0&&(t=o.length+t);const r=o[t];if(void 0!==r)return e(r,t)})}at(t){const e=this.a;return t<0&&(t=e.length+t),e[t]}fromArray(t){return new e(t,this.g,this.s)}get length(){return this.a.length}get isIList(){return!0}}t.ArrayList=e})(El||(El={}));class vl{constructor(t){if(this._s=null,this._r=null,this._l=0,t&&t.length>0){const e=El.isList(t)&&!Array.isArray(t)?t:new El.ArrayList(t);this._s=e,this._l=t.length}}at(t){const e=this._s;if(e)return e.at(t);const r=this._c;if(r){if(r.min<=t&&r.max>=t){const e=r.value;return e.v.at(t-r.min+e.s)}}const n=this._r,o=mt.findEqualOrGreater(n,t,t=>t.max),s=n[o];if(!s)return;const i=s.value;this._c=s;return i.v.at(t-s.min+i.s)}toArray(t=Number.MAX_SAFE_INTEGER){const e=[],r=this.entries(Ml);let n=r.next();for(;!n.done&&e.length<t;)e.push(n.value[1]),n=r.next();return e}entries(t){const e=this.length;if(0===e)return bl;let r,n,o,s=!0,i=0,a=e-1;if(t){s=!t.reverse;const e=t.bounds;e&&(i=Math.max(e.min??i,i),a=Math.min(e.max??a,a)),r=t.reuseResult??null,n=t.processSkip}const l=s?1:-1;let c=(s?i:a)-l;const h=this._s;if(h)o=t=>{if(!(t<i||t>a))return h.at(t)};else{const t=this._r;let e=s?0:t.length-1,r=t[e];const n=(n,o)=>{const s=n===e?r:t[n];if(s&&o>=s.min&&o<=s.max)return e=n,r=s,s};o=r=>{if(r<i||r>a)return;let o=n(e,r);if(o||(o=n(e+l,r)),!o){const e=mt.findEqualOrGreater(t,r,t=>t.max);o=n(e,r)}if(!o)return;const s=o.value;return s.v.at(r-o.min+s.s)}}const d={next:t=>{let h,d=c+l;return void 0!==t&&(t<0&&(t=e+t),d=t),d<i||d>a||n&&(d=n(d,!s),d<i||d>a)?Cl:(h=o(d),c=d,r?(Rl.done=!1,Rl.value[0]=d,Rl.value[1]=h,Rl):{done:!1,value:[c,h]})},[Symbol.iterator]:()=>d};return d}slice(t,e=void 0){const r=this._r??Il(this._s);if(!r)return Al;const n=this.length;if(t=Math.min(Math.max(0,t),n),(e=Math.min(Math.max(0,e??n),n))-t<=0)return Al;if(t<=0&&e>=n)return this;const o=t,s=e-1;let i=[],a=0;for(let t=0;t<r.length;t++){let e=r[t];const n=e.max;if(0===o&&n<=s){i.push(e);continue}const l=e.min;if(l>s){t=r.length;continue}if(n<o){a=n+1;continue}const c=Math.max(0,o-l),h=Math.max(0,n-s),d=h+c,u=e.value;i.push({min:l-a,max:n-d-a,value:{s:u.s+c,e:u.e-h,v:u.v}}),a+=d}const l=new vl;return l._r=i,l._l=s-o+1,l}concat(t){if(!t)return this;if(!El.isListLike(t))throw new Error("Value must be IListLike");const e=this._l;if(0===e)return t.isIReadableList?t:0===t.length?Al:new vl(t);const r=t,n=t.length;if(0===n)return this;const o=this._r??Il(this._s),s=o.slice(0,o.length-1);let i=o[o.length-1],a=i?i.min:0,l=i?i.max:0,c=i?i.value:null,h=c?c.v:null,d=c?c.e-c.s:0;const u=t=>{const e=t.s,r=t.e,n=r-e;if(n+d<Tl&&h&&h.fromArray){let n=t.v;const o=[],s=c.s,u=c.e;for(let t=s;t<=u;t++)o.push(h.at(t));for(let t=e;t<=r;t++)o.push(n.at(t));const g=h.fromArray(o);if(g)return n=g,d=n.length-1,c={s:0,e:d,v:n},i={min:a,max:a+d,value:c},l=a+d,void(h=n)}s.push(i);const o=l+1,u=o+n;i={min:o,max:u,value:t},a=o,l=u,c=i?i.value:null,h=c?c.v:null,d=c?c.e-c.s:0};if(t instanceof vl){const e=t._s;if(e)u({s:0,e:e.length-1,v:e});else{const e=t._r;for(let t=0;t<e.length;t++){u(e[t].value)}}}else u({s:0,e:n-1,v:r});s.push(i);const g=new vl,p=e+n;return 1===s.length&&0===s[0].min&&s[0].max===p-1?g._s=s[0].value.v:g._r=s,g._l=p,g}get length(){return this._l}[Symbol.iterator](){return yl(this.entries())}get isIReadableList(){return!0}get isIList(){return!0}get[Symbol.toStringTag](){return"[ImmutableList]"}toString(){const t=this.length;if(0===t)return"";let e="";for(let r=0;r<t;r++){r>0&&(e+=",");const t=this.at(r);e+=null==t?"":String(t)}return e}}const Il=t=>[{min:0,max:t.length-1,value:{s:0,e:t.length-1,v:t}}],Al=new vl,Rl=Object.seal({done:!1,value:[-1,null]}),Ml=Object.freeze({reverse:!1,bounds:{min:0,max:Number.MAX_SAFE_INTEGER},skipRuns:null,reuseResult:Rl}),Tl=4;var Fl;(t=>{const e=(t,e)=>{const r=t!==E.Row;return e?(t,e)=>{if(t===e)return 0;const n=t[0],o=t[1],s=e[1];if(o===s)return n?-1:1;const i=e[0];let a=0,l=0;if(r?(a=n?o.colEnd:o.colStart,l=i?s.colEnd:s.colStart):(a=n?o.rowEnd:o.rowStart,l=i?s.rowEnd:s.rowStart),a===l&&n!==i)return n?-1:1;if(a!==l)return l-a;let c=0,h=0;if(r?(c=n?o.colStart:o.colEnd,h=i?s.colStart:s.colEnd):(c=n?o.rowStart:o.rowEnd,h=i?s.rowStart:s.rowEnd),c===h&&n!==i)return n?-1:1;if(c!==h)return h-c;const d=t[2]??0;return(e[2]??0)-d}:(t,e)=>{if(t===e)return 0;const n=t[0],o=t[1],s=e[1];if(o===s)return n?-1:1;const i=e[0];let a=0,l=0;if(r?(a=n?o.colStart:o.colEnd,l=i?s.colStart:s.colEnd):(a=n?o.rowStart:o.rowEnd,l=i?s.rowStart:s.rowEnd),a===l&&n!==i)return n?-1:1;if(a!==l)return a-l;let c=0,h=0;if(r?(c=n?o.colEnd:o.colStart,h=i?s.colEnd:s.colStart):(c=n?o.rowEnd:o.rowStart,h=i?s.rowEnd:s.rowStart),c===h&&n!==i)return n?-1:1;if(c!==h)return c-h;return(t[2]??0)-(e[2]??0)}};class r{constructor(t,r){if(this._isColumn=!0,this._isByCell=!1,this._isReverse=!1,this._cursor=null,this._reuse=null,this._localReuse={done:!1,value:[null,null]},this._eventsMajor=null,this._eventMajorIndex=0,this._majorStart=0,this._majorEnd=0,this._eventMinorPeek=null,this._minorStart=0,this._minorEnd=0,!t||0===t.length)return;let n=E.Column,o=!1,s=!0,i=!1;r&&(n=r.orientation??E.Column,this._isColumn=s=n!==E.Row,this._isReverse=o=r.reverse??!1,this._isByCell=i=r.byCell??!1);const a=t.length,l=new Array(2*a);for(let e=0;e<a;e++){const r=t[e],n=[null,null];l[2*e]=[!0,r,e,n],l[2*e+1]=[!1,r,e,n]}l.sort(e(n,o)),this._eventsMajor=l;const c=l[0][1];this._majorStart=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,this._majorEnd=s?o?c.colEnd+1:c.colStart-1:o?c.rowEnd+1:c.rowStart-1,this._eventsMinor=new ke(null,e(s?E.Row:E.Column,o));const h=new Array(16);h.length=0,this._cursor={cell:null,range:{colStart:c.colStart,rowStart:c.rowStart,colEnd:c.colEnd,rowEnd:c.rowEnd},overlaps:h},i&&(this._cursor.cell={colIndex:o?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,rowIndex:o?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER});const d=r?.reuseIterator;d&&(this._reuse=d,d.value=this._cursor)}next(t){const e=this._isColumn,r=this._isReverse;if(t){if(!this._isByCell)throw new Error("nextCell is only supported when byCell is true");const n=U.createCellComparator(e?E.Column:E.Row,r);let o;do{const s=this._cursor,i=s.cell;if(i.colIndex!==Number.MAX_SAFE_INTEGER&&n(i,t)>=0)throw new Error("nextCell must be after the current iteration cell");if(o=this.next(),o.done)return o;const a=o.value.cell;if(n(a,t)>=0)return o;const l=s.range;if(e){const e=t.colIndex===i.colIndex;i.rowIndex=r?e?Math.max(t.rowIndex,l.rowStart):l.rowStart:e?Math.min(t.rowIndex,l.rowEnd):l.rowEnd}else{const e=t.rowIndex===i.rowIndex;i.colIndex=r?e?Math.max(t.colIndex,l.colStart):l.colStart:e?Math.min(t.colIndex,l.colEnd):l.colEnd}if(n(i,t)>=0)return a.rowIndex=i.rowIndex,a.colIndex=i.colIndex,o}while(!o.done);return o}let n=this._cursor;if(!n)return Cl;let o=this._reuse;if(!o){const t=n.cell,e=n.range,r={cell:null,range:{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd},overlaps:[...n.overlaps]};t&&(r.cell={colIndex:t.colIndex,rowIndex:t.rowIndex}),this._cursor=r,o={done:!1,value:r}}const s=o.value,i=s.range,a=s.cell,l=this._isByCell,c=r?-1:1;let h=!1;if(l){const t=a.rowIndex,n=a.colIndex,s=e?t:n,l=e?r?i.rowStart:i.rowEnd:r?i.colStart:i.colEnd;if(r?s>=l:s<=l){e?a.rowIndex=t+c:a.colIndex=n+c;if(r?s>l:s<l)return o}const d=e?a.colIndex:a.rowIndex,u=e?r?i.colStart:i.colEnd:r?i.rowStart:i.rowEnd;(r?d>u:d<u)&&(h=!0)}const d=s.overlaps;let u=this._majorStart,g=this._majorEnd,p=this._eventsMinor,m=this._minorStart,f=this._minorEnd,_=this._eventsMinorIterator,S=this._eventMinorPeek,w=S;for(;w&&!w.done;){const t=w.value[0];if(t[0])w=null;else{if(S=_.next(),S.done)d.length=0;else{const n=t[1];let s=d.length;if(s>1){const t=d.indexOf(n);-1!==t&&(d[t]=d[s-1])}if(d.length=s-1,s=d.length,s>0){const t=S.value[0],n=t[1],s=e?r?n.colStart:n.colEnd:r?n.rowStart:n.rowEnd;if(r?u>=s:u<=s){let s=!1;if(t[0]){const t=e?r?n.rowEnd:n.rowStart:r?n.colEnd:n.colStart;(r?t<f+c:t>f+c)&&(m=f+c,f=t-c,s=!0)}else{const t=e?r?n.rowStart:n.rowEnd:r?n.colStart:n.colEnd;(r?t<f:t>f)&&(m=f+c,f=t,s=!0)}if(s)return e?(i.rowStart=r?f:m,i.rowEnd=r?m:f):(i.colStart=r?f:m,i.colEnd=r?m:f),this._minorStart=m,this._minorEnd=f,this._eventMinorPeek=S,o}}}S.done&&(S=null),w=S}}if(!S)if(h){_=p.entries(void 0,this._localReuse),S=_.next(),this._eventsMinorIterator=_;const t=S.value[0][1],n=e?r?t.rowEnd:t.rowStart:r?t.colEnd:t.colStart;e?(a.colIndex=a.colIndex+c,a.rowIndex=n):(a.colIndex=n,a.rowIndex=a.rowIndex+c)}else{let t=this._eventMajorIndex;const n=this._eventsMajor,o=n.length;if(t>=o)return this._cursor=null,Cl;let s=n[t],i=s[0],h=!1;for(;!i&&!h&&s;){const o=s[1],a=e?r?o.colStart:o.colEnd:r?o.rowStart:o.rowEnd;if(r?a<g:a>g){h=!0;continue}const l=s[3];p.delete(l[0]),p.delete(l[1]),t++,s=n[t],s&&(i=s[0])}let m=p.size>0?g+c:-1;for(h=!1;i&&!h&&s;){const o=s[1];if(-1!==m){if((e?r?o.colEnd:o.colStart:r?o.rowEnd:o.rowStart)!==m){h=!0;continue}}const a=s[2],l=[!0,o,a],c=[!1,o,a],d=s[3];if(d[0]=l,d[1]=c,p.set(l,0),p.set(c,0),-1===m){m=e?r?o.colEnd:o.colStart:r?o.rowEnd:o.rowStart}if(t++,s=n[t],!s)continue;if(i=s[0],!i)continue;const u=s[1];(e?r?u.colEnd:u.colStart:r?u.rowEnd:u.rowStart)!==m&&(h=!0)}if(-1!==m&&(u=m),l&&(e?a.colIndex=u:a.rowIndex=u),this._eventMajorIndex=t,t>=o)return this._eventsMinorIterator=_,this._cursor=null,Cl;if(s){const t=s[0],n=s[1],o=e?r?n.colEnd:n.colStart:r?n.rowEnd:n.rowStart,i=e?r?n.colStart:n.colEnd:r?n.rowStart:n.rowEnd;g=t?o-c:i}d.length=0,_=p.entries(void 0,this._localReuse),S=_.next(),this._eventsMinorIterator=_}let y=S;do{const t=y.value;y=null;const n=t[0],o=n[1];if(!n[0])continue;const s=e?r?o.rowEnd:o.rowStart:r?o.colEnd:o.colStart;m!==s&&(m=s),S=_.next();const i=S.value[0],h=i[0],u=i[1],g=e?r?u.rowEnd:u.rowStart:r?u.colEnd:u.colStart;if(h&&g===m)y=S;else{const t=e?r?o.rowStart:o.rowEnd:r?o.colStart:o.colEnd,n=e?r?u.rowStart:u.rowEnd:r?u.colStart:u.colEnd;f=(r?Math.max:Math.min)(t,h?g-c:n),l&&(e?a.rowIndex=m:a.colIndex=m)}d[d.length]=Object.freeze(o)}while(y);return e?(i.colStart=r?g:u,i.colEnd=r?u:g,i.rowStart=r?f:m,i.rowEnd=r?m:f):(i.rowStart=r?g:u,i.rowEnd=r?u:g,i.colStart=r?f:m,i.colEnd=r?m:f),this._eventMinorPeek=S,this._minorStart=m,this._minorEnd=f,this._majorStart=u,this._majorEnd=g,o}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}t.IteratorInstance=r})(Fl||(Fl={}));const Nl=(t,e=_.Right,r=null)=>{if(!t)return t;if(0===t.length)return[];const n=e===_.Right,o=e===_.Left,s=e===_.Up,i=e===_.Down;return t.sort((t,e)=>{if(!t&&!e)return 0;if(t&&!e)return-1;if(e&&!t)return 1;const a=r?.(t,e)??0;return 0!==a?a:n?t.rowStart===e.rowStart?t.colStart-e.colStart:t.rowStart-e.rowStart:i?t.colStart===e.colStart?t.rowStart-e.rowStart:t.colStart-e.colStart:o?t.rowStart===e.rowStart?e.colStart-t.colStart:e.rowStart-t.rowStart:s?t.colStart===e.colStart?e.rowStart-t.rowStart:e.colStart-t.colStart:0})},kl=(t,e)=>{const r=e.min,n=t.min;if(e.max===Number.MAX_SAFE_INTEGER){const o=r,s=t.max;return n<=o&&o<=s?0:s<o?-1:n>o?1:(console.warn("coords are not inserted correctly",t,e),0)}return n-r};class Ol{constructor(t){this._runs=null,this._dataCoords=null,this._count=0,this._length=0,this._maxCoords=null,this._options=t,t?.maxCoords&&(this._maxCoords=Object.freeze({...t.maxCoords})),this._runs=new ke(void 0,kl,t?.nodeSize),this._reuseRunsIterator={done:!1,value:[null,null]},this._reuseRunsEntry=[null,null]}_validateBounds(t=Number.MIN_SAFE_INTEGER,e=Number.MAX_SAFE_INTEGER){const r=this._maxCoords,n=r?.min??Number.MIN_SAFE_INTEGER,o=r?.max??Number.MAX_SAFE_INTEGER;if(t<n||e>o)throw new Mt}entries(t){let e,r,n=Number.MIN_SAFE_INTEGER,o=Number.MAX_SAFE_INTEGER,s=!0;if(t){const i=t?.bounds;i&&(n=t.bounds?.min??Number.MIN_SAFE_INTEGER,o=t.bounds?.max??Number.MAX_SAFE_INTEGER,this._validateBounds(n,o)),s=!t.reverse,e=Bl(t.reuseResult),r=t.processSkip}const i=this._dataCoords;if(!i)return bl;n=Math.max(i.min,n),o=Math.min(i.max,o);let a=null,l=null,c=Number.MAX_SAFE_INTEGER,h=Number.MIN_SAFE_INTEGER;if(r){const t=r;r=(e,r)=>t(e+c,r)-c}const d=t=>{let e;t!==Number.MIN_SAFE_INTEGER&&t!==Number.MAX_SAFE_INTEGER&&(Ul.min=t,e=Ul),a=s?this._runs.entries(e,this._reuseRunsIterator):this._runs.entriesReversed(e,this._reuseRunsIterator),c=Number.MAX_SAFE_INTEGER,h=Number.MIN_SAFE_INTEGER,l=null},u=t=>{if(void 0!==t){if(t<c||t>h)return void(l=void 0);t-=c}if(!l)return;let r=l.next(t);if(!l)return;let n=r.value,o=n?.[1];if(r.done)return void(l=void 0);return Ll(n[0]+c,o,e)},g=t=>{let i;return i=u(t),i||(i=(t=>{let i;do{if(void 0!==t&&d(t),!a)return;if(i=a.next(),i.done)return void(a=void 0);const g=i.value,p=g[0],m=g[1],f=p.min,_=p.max,S=Math.max(f,n)-f,w=Math.max(S,Math.min(_,o))-f;Vl.bounds.min=S,Vl.bounds.max=w,Vl.reverse=!s,Vl.processSkip=r,Vl.reuseResult=e,c=f,h=_,l=m.entries(Vl);const y=u(t);if(y)return y;t=void 0}while(!i.done);a=void 0})(t),i||Cl)},p={next(t){if(void 0!==t&&(t<0||t>o))throw new Mt;return g(t)},return:t=>null,throw:t=>null};return d(s?n:o),p}runs(t){let e,r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,o=!0,s=!1;if(t){t.bounds&&(r=t.bounds?.min??Number.MIN_SAFE_INTEGER,n=t.bounds?.max??Number.MAX_SAFE_INTEGER,this._validateBounds(r,n),t.overflowRun&&(s=!0)),o=!t.reverse,e=Dl(t.reuseResult)}const i=this._dataCoords;if(!i)return bl;r=Math.max(i.min,r),n=Math.min(i.max,n);let a=null;const l=t=>{let e;t!==Number.MIN_SAFE_INTEGER&&t!==Number.MAX_SAFE_INTEGER&&(Ul.min=t,e=Ul),a=o?this._runs.entries(e,this._reuseRunsIterator):this._runs.entriesReversed(e,this._reuseRunsIterator)},c={next(t){if(void 0!==t){if(t<r||t>n)throw new Mt;l(t)}if(!a)return Cl;const i=a.next();if(i.done)return a=void 0,Cl;const c=i.value,h=c[0];let d=h;const u=d.min,g=d.max;if(o&&u>n||!o&&g<r)return Cl;let p=c[1];return s||(g>n&&(p=p.slice(0,p.length-(g-n)),d={...d},d.max=n),u<r&&(p=p.slice(r-u),d===h&&(d={...d}),d.min=r)),zl(d,p,e)},return:t=>null,throw:t=>null};return l(o?r:n),c}slice(t,e){const r=this._runs,n=r.minKey().min,o=r.maxKey().max;if(void 0===e&&(e=o+1),0===this._count||t<=n&&e-1>=o)return this.clone();const s=Math.max(n,t),i=Math.min(o,e-1),a=i-s,l=[];let c=0;ql.bounds.min=s,ql.bounds.max=i;const h=this.runs(ql);let d=h.next();for(;!d.done;){const t=d.value;let e=t[0],r=t[1];e={min:e.min-s,max:e.max-s},e.min<0&&(r=r.slice(-e.min),e.min=0),e.max>=a&&(r=r.slice(0,r.length-(e.max-a)),e.max=a),c+=r.length,l.push([e,r]),d=h.next()}const u=new Ol(this._options);return u._runs.setPairs(l),u._updateCount(c),u}concat(t){const e=this.clone();if(!t||0===t.length)return e;const r=this._runs.nextLowerPair(void 0,this._reuseRunsEntry),n=r[0],o=r[1],s=n.max+1;let i=!1,a=0;const l=[];if(t.isISparseList){const e=t.runs();let r=e.next();for(;!r.done;){const t=r.value;let c=t[0];const h={min:c.min+s,max:c.max+s};let d=t[1];if(0===c.min){i=!0,a-=o.length,d=o.concat(d);const t=n.min;h.min=t,h.max=d.length-1+t}a+=d.length,l.push([h,d]),r=e.next()}}else{const e=t.length,r={min:n.min,max:e-1+s};t=o.concat(t),i=!0,a+=e,l.push([r,t])}return i&&e._runs.delete(n),e._runs.setPairs(l),e._updateCount(a),e}toArray(t=Number.MAX_SAFE_INTEGER,e=!0){if(0===this.length)return mt.EmptyArray;const r=e?0:Number.MIN_SAFE_INTEGER,n=Math.min(this._runs.maxKey().max,t);return $l.bounds.min=Number.MIN_SAFE_INTEGER,$l.bounds.max=n,Pl(this.entries($l),e,n,r)}get isIReadableList(){return!0}get length(){return this._length}getCoords(){return this._dataCoords}clear(){this._runs.clear(),this._dataCoords=null,this._count=0,this._length=0}get isISparseList(){return!0}get isIList(){return!0}_updateCount(t){if(this._count+=t,this._lastRunsRead=void 0,this._lastListRead=void 0,this._count>0){const t=this._runs,e=Object.freeze({min:t.minKey().min,max:t.maxKey().max});this._dataCoords=e,this._length=e.max+1}else this._dataCoords=null,this._length=0}_update(t,e,r=null,n=void 0){const o=t,s=o+e-1;let i=0,a=s,l=s,c=null,h=null;Ul.min=o,Gl.min=s,(r||n)&&(Ul.min-=1,Gl.min+=1);const d=this._runs;let u=!1;if(d.editRange(Ul,Gl,!0,(t,e,r)=>{const n=t.min,d=t.max;return n<o&&d+1>=o&&(a=n,c=e),n-1<=s&&d>s&&(l=n,h=e),i-=d-n+1,u=!0,ke.DeleteValue}),r||void 0===n||(r=new vl([n])),r){let t=r;u=!0;let e=o;c&&(c=c.slice(0,o-a),t=c.concat(t),e=a),h&&(h=h.slice(s+1-l),t=t.concat(h)),i+=t.length,d.set({min:e,max:e+t.length-1},t)}else c&&(c=c.slice(0,o-a),i+=c.length,d.set({min:a,max:a+c.length-1},c)),h&&(h=h.slice(s+1-l),i+=h.length,d.set({min:s+1,max:s+h.length},h));return this._updateCount(i),u}setAt(t,e){if(void 0===t)throw new Ft;return this._validateBounds(t,t),this._update(t,1,null,e)}setRunAt(t,e){if(!e||0===e.length)return!1;if(void 0===t||!e.length)throw new Ft;const r=e.length;return this._validateBounds(t,t+r-1),this._update(t,r,e)}delete(t,e){return void 0===e&&(e=Math.max(this.getCoords().max-t+1,0)),!(e<=0)&&(this._validateBounds(t,t),this._update(t,e,null))}shift(t,e){if(0===e)return!1;let r=t,n=t;e<0&&(n=t-e-1),this._validateBounds(r,n);const o=this._runs,s=o.maxKey();if(e<0&&n>=s.max&&r<=o.minKey().min)return this._runs.clear(),this._dataCoords=null,this._count=0,this._length=0,!0;let i=0,a=r,l=n,c=null,h=null;Ul.min=a,Gl.min=s.min,e<0&&(Ul.min-=1,Gl.min+=1);let d=!1;const u=[];if(o.editRange(Ul,Gl,!0,(t,o,s)=>{const g=t.min,p=t.max;return g<r&&p+1>=r&&(a=g,c=o),(g<r||e<0)&&g-1<=n&&t.max>n&&(l=g,h=o),e>0&&g>=r||e<0&&g-1>n?u.push([{min:g+e,max:p+e},o]):i-=p-g+1,d=!0,ke.DeleteValue}),e>0){const n=c||h;n&&(c=n.slice(0,r-a),l=t+e,h=n.slice(r-a))}else c&&(c=c.slice(0,r-a)),h&&(h=h.slice(n+1-l),l=t),c&&h&&a+c.length===l&&(c=c.concat(h),h=null);return c&&c.length>0&&(i+=c.length,o.set({min:a,max:a+c.length-1},c)),h&&(i+=h.length,o.set({min:l,max:l+h.length-1},h)),u.length>0&&o.setPairs(u),this._updateCount(i),d}at(t){Ul.min=t;const e=this._lastRunsRead;if(e){const r=e.min;if(r<=t&&e.max>=t)return this._lastListRead.at(t-r)}let r,n;const o=this._runs.getPairOrNextHigher(Ul,Wl);if(o&&(r=o[0],n=o[1]),this._lastRunsRead=r,this._lastListRead=n,!(!r||t<r.min||t>r.max))return n.at(t-r.min)}[Symbol.iterator](){return yl(this.entries())}clone(){const t=new Ol(this._options);return t._runs=this._runs.clone(),t._count=this._count,t._dataCoords=this._dataCoords,t._length=this._length,t}getMaxCoords(){const t=this._maxCoords;return t||null}getCount(){return this._count}getRunsCount(){return this._runs.size}get[Symbol.toStringTag](){return"[SparseList]"}}Ol||(Ol={});const Bl=t=>"boolean"!=typeof t?(t&&!t.value&&(t.value=[-1,null]),t):!0===t?Hl:void 0,Ll=(t,e,r)=>{const n=r??{done:!1,value:[-1,null]},o=n.value;return o[0]=t,o[1]=e,n},Dl=t=>"boolean"!=typeof t?(t&&!t.value&&(t.value=[null,null]),t):!0===t?jl:void 0,zl=(t,e,r)=>{const n=r??{done:!1,value:[null,null]},o=n.value;return o[0]=t,o[1]=e,n},Pl=(t,e=!1,r=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER)=>{const o=[];let s=t.next(),i=Math.max(n,0)-1;for(;!s.done;){if(e){const t=s.value[0];for(let e=i;e<t-1;e++)o.push(void 0);i=t}o.push(s.value[1]),s=t.next()}if(e)for(let t=i;t<r;t++)o.push(void 0);return o},jl=Object.seal({done:!1,value:[{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},null]}),Hl=Object.seal({done:!1,value:[-1,null]}),Vl={reverse:!1,bounds:{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},processSkip:null,reuseResult:Hl},$l=Object.freeze({reverse:!1,bounds:{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},processSkip:null,reuseResult:Hl}),Ul={min:0,max:Number.MAX_SAFE_INTEGER},Gl={min:0,max:Number.MAX_SAFE_INTEGER},Wl=[null,null],ql={bounds:{min:0,max:0},overflowRun:!0};class Jl{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(t){return 0===this.data.children.length?[]:this._all(this.data,t??[])}isEmpty(){return 0===this.data.children.length}search(t,e){let r=this.data;if(0===r.children.length)return mt.EmptyArray;if(!ic(t,r))return mt.EmptyArray;const n=e??[],o=this.toBBox,s=[];for(;r;){const e=r.children,i=e.length,a=r.leaf;for(let r=0;r<i;r++){const i=e[r],l=a?o(i):i;ic(t,l)&&(a?n.push(i):sc(t,l)?this._all(i,n):s.push(i))}r=s.pop()}return n}collides(t){let e=this.data;if(!ic(t,e))return!1;const r=[];for(;e;){for(let n=0;n<e.children.length;n++){const o=e.children[n],s=e.leaf?this.toBBox(o):o;if(ic(t,s)){if(e.leaf||sc(t,s))return!0;r.push(o)}}e=r.pop()}return!1}load(t){if(!t||!t.length)return this;const e=this._minEntries;if(t.length<e){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let r=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===r.height)this._splitRoot(this.data,r);else{if(this.data.height<r.height){const t=this.data;this.data=r,r=t}this._insert(r,this.data.height-r.height-1,!0)}else this.data=r;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=ac([]),this}remove(t,e){if(!t)return this;let r=this.data;const n=this.toBBox(t),o=[],s=[];let i,a,l;for(;r||o.length;){if(r||(r=o.pop(),a=o[o.length-1],i=s.pop(),l=!0),r.leaf){const n=Xl(t,r.children,e);if(-1!==n)return r.children.splice(n,1),o.push(r),this._condense(o),this}l||r.leaf||!sc(r,n)?a?(i++,r=a.children[i],l=!1):r=null:(o.push(r),s.push(i),i=0,a=r,r=r.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const r=[];for(;t;)t.leaf?e.push(...t.children):r.push(...t.children),t=r.pop();return e}_build(t,e,r,n){const o=r-e+1;let s,i=this._maxEntries;if(o<=i)return s=ac(t.slice(e,r+1)),Kl(s,this.toBBox),s;n||(n=Math.ceil(Math.log(o)/Math.log(i)),i=Math.ceil(o/Math.pow(i,n-1))),s=ac([]),s.leaf=!1,s.height=n;const a=Math.ceil(o/i),l=a*Math.ceil(Math.sqrt(i));lc(t,e,r,l,this.compareMinX);for(let o=e;o<=r;o+=l){const e=Math.min(o+l-1,r);lc(t,o,e,a,this.compareMinY);for(let r=o;r<=e;r+=a){const o=Math.min(r+a-1,e);s.children.push(this._build(t,r,o,n-1))}}return Kl(s,this.toBBox),s}_chooseSubtree(t,e,r,n){for(;n.push(e),!e.leaf&&n.length-1!==r;){let r,n=1/0,o=1/0;for(let s=0;s<e.children.length;s++){const i=e.children[s],a=ec(i),l=nc(t,i)-a;l<o?(o=l,n=a<n?a:n,r=i):l===o&&a<n&&(n=a,r=i)}e=r||e.children[0]}return e}_insert(t,e,r=!1){const n=r?t:this.toBBox(t),o=[],s=this._chooseSubtree(n,this.data,e,o);for(s.children.push(t),Zl(s,n);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(n,o,e)}_split(t,e){const r=t[e],n=r.children.length,o=this._minEntries;this._chooseSplitAxis(r,o,n);const s=this._chooseSplitIndex(r,o,n),i=ac(r.children.splice(s,r.children.length-s));i.height=r.height,i.leaf=r.leaf,Kl(r,this.toBBox),Kl(i,this.toBBox),e?t[e-1].children.push(i):this._splitRoot(r,i)}_splitRoot(t,e){this.data=ac([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Kl(this.data,this.toBBox)}_chooseSplitIndex(t,e,r){let n=-1,o=1/0,s=1/0;for(let i=e;i<=r-e;i++){const e=Yl(t,0,i,this.toBBox),a=Yl(t,i,r,this.toBBox),l=oc(e,a),c=ec(e)+ec(a);l<o?(o=l,n=i,s=c<s?c:s):l===o&&c<s&&(s=c,n=i)}return n||r-e}_chooseSplitAxis(t,e,r){const n=t.leaf?this.compareMinX:Ql,o=t.leaf?this.compareMinY:tc;this._allDistMargin(t,e,r,n)<this._allDistMargin(t,e,r,o)&&t.children.sort(n)}_allDistMargin(t,e,r,n){t.children.sort(n);const o=this.toBBox,s=Yl(t,0,e,o),i=Yl(t,r-e,r,o);let a=rc(s)+rc(i);for(let n=e;n<r-e;n++){const e=t.children[n];Zl(s,t.leaf?o(e):e),a+=rc(s)}for(let n=r-e-1;n>=e;n--){const e=t.children[n];Zl(i,t.leaf?o(e):e),a+=rc(i)}return a}_adjustParentBBoxes(t,e,r){for(let n=r;n>=0;n--)Zl(e[n],t)}_condense(t){for(let e,r=t.length-1;r>=0;r--)0===t[r].children.length?r>0?(e=t[r-1].children,e.splice(e.indexOf(t[r]),1)):this.clear():Kl(t[r],this.toBBox)}}function Xl(t,e,r){if(!r)return e.indexOf(t);for(let n=0;n<e.length;n++)if(r(t,e[n]))return n;return-1}function Kl(t,e){Yl(t,0,t.children.length,e,t)}function Yl(t,e,r,n,o=null){o||(o=ac(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=e;s<r;s++){const e=t.children[s];Zl(o,t.leaf?n(e):e)}return o}function Zl(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Ql(t,e){return t.minX-e.minX}function tc(t,e){return t.minY-e.minY}function ec(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function rc(t){return t.maxX-t.minX+(t.maxY-t.minY)}function nc(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function oc(t,e){const r=Math.max(t.minX,e.minX),n=Math.max(t.minY,e.minY),o=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,o-r)*Math.max(0,s-n)}function sc(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function ic(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ac(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function lc(t,e,r,n,o){const s=[e,r];for(;s.length;){if((r=s.pop())-(e=s.pop())<=n)continue;const i=e+Math.ceil((r-e)/n/2)*n;hc(t,i,e,r,o),s.push(e,i,i,r)}}function hc(t,e,r,n,o){for(;n>r;){if(n-r>600){const s=n-r+1,i=e-r+1,a=Math.log(s),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(s-l)/s)*(i-s/2<0?-1:1);hc(t,e,Math.max(r,Math.floor(e-i*l/s+c)),Math.min(n,Math.floor(e+(s-i)*l/s+c)),o)}const s=t[e];let i=r,a=n;for(dc(t,r,e),o(t[n],s)>0&&dc(t,r,n);i<a;){for(dc(t,i,a),i++,a--;o(t[i],s)<0;)i++;for(;o(t[a],s)>0;)a--}0===o(t[r],s)?dc(t,r,a):(a++,dc(t,a,n)),a<=e&&(r=a+1),e<=a&&(n=a-1)}}function dc(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}class uc extends Jl{toBBox(t){return{minX:10*t.colStart,minY:10*t.rowStart,maxX:10*t.colEnd+5,maxY:10*t.rowEnd+5}}compareMinX(t,e){return t.colStart-e.colStart}compareMinY(t,e){return t.rowStart-e.rowStart}isEmpty(){return 0===this.data.children.length}searchRange(t,e=!1,r){if(this.isEmpty())return mt.EmptyArray;const n=this.search(this.toBBox(t),r);if(!e)return n;return n.filter(e=>e.colStart>=t.colStart&&e.rowStart>=t.rowStart&&e.colEnd<=t.colEnd&&e.rowEnd<=t.rowEnd)}}class gc{constructor(t){this._shared=null,this._rTree=null,this._cloneKey=null,this._lastMiss={colStart:Number.MAX_SAFE_INTEGER,rowStart:0,colEnd:0,rowEnd:0},this._lastSingle=null,this._lastSingleResult=null,this._options=t,this._rTree=new uc(t?.maxNodeEntries??16)}visitRanges(t,e,r=null){let n=this.search(t);r&&(n=Nl(n,r));const o=[],s=[];let i=null;const a=n.length;for(let t=0;!i&&t<a;t++){const r=n[t],a=e?.(r);a&&(!0===a.delete?s.push(r):void 0!==a.update&&(s.push(r),o.push(a.update)),a&&!0===a.break&&(i=a))}for(let t=0;t<s.length;t++)this.remove(s[t]);return this.load(o),i}getBoundingCoords(){const t=this._getReadTree().toJSON();return t&&t.children&&0!==t.children.length?{colStart:t.minX/10,rowStart:t.minY/10,colEnd:(t.maxX-5)/10,rowEnd:(t.maxY-5)/10}:null}size(){return this._getReadTree().all().length}isEmpty(){return this._getReadTree().isEmpty()}search(t,e=!1,r){const n=this._getReadTree();if(n.isEmpty())return mt.EmptyArray;let o;if(!e){if(o=this._lastMiss,o.colStart!==Number.MAX_SAFE_INTEGER&&U.isRangeWithinRange(t,o))return mt.EmptyArray;if(this._lastSingle&&U.isRangeWithinRange(t,o))return this._lastSingleResult}const s=n.searchRange(t,e,r);return e||(0===s.length?(o.colStart=t.colStart,o.rowStart=t.rowStart,o.colEnd=t.colEnd,o.rowEnd=t.rowEnd):1===s.length?(this._lastSingle=s[0],this._lastSingleResult=s):(this._lastMiss.colStart=Number.MAX_SAFE_INTEGER,this._lastSingle=null,this._lastSingleResult=null)),s}has(t){const e=this._getReadTree();return e.collides(e.toBBox(t))}all(t){return this._getReadTree().all(t)}shift(t){const e=t.range,r=t.direction,n=t.cloneIfUpdate??!1,o=t.coordValidator??null,s=t.onShift??null,i=r===_.Left||r===_.Right,a=i?E.Column:E.Row,l=r===_.Up||r===_.Left?-1:1,c=(i?e.colEnd-e.colStart+1:e.rowEnd-e.rowStart+1)*l,h=[],d=[];let u=null;const g=this.getBoundingCoords();if(!g)return this;const p=r===_.Up||r===_.Left?_.Right:_.Left,m=new Map,f=new Map,S=this._options?.updateEntryOptions,w=S?.isMergeOnShift??!1,y=S?.isSplitOnExpand??!1,x=S?.isTrailingEdge??!1,C=r===_.Left||r===_.Up,b=S?.getSplit??xc,I=S?.getShifted,A=S?.onShifted,R=S?.onRemoved,M=S?.onMerged,T=S?.onUpdated,F=A?[]:null,N=R?[]:null,k=T?[]:null;this.visitRanges({colStart:e.colStart-(i?1:0),rowStart:e.rowStart-(i?0:1),colEnd:i?g.colEnd:e.colEnd,rowEnd:i?e.rowEnd:g.rowEnd},t=>{if((i?t.colEnd<e.colStart:t.rowEnd<e.rowStart)&&!x)return;const n=bc(e,t,i?v.Column:v.Row),l=t.group;if(C&&!l&&e.colStart<=t.colStart&&e.rowStart<=t.rowStart&&e.colEnd>=t.colEnd&&e.rowEnd>=t.rowEnd){const r=Ec(t,null,{after:null,before:t,intersect:e,isSplit:n,orientation:a,amount:c},I,b,s,!1);if(void 0===r)return;if(null===r)return u=U.unionRanges(u,t),N&&N.push(t),void h.push(t)}let g={...t};r===_.Right?e.colStart<=g.colStart?(g.colStart+=c,g.colEnd+=c):g.colEnd+=c:r===_.Left?e.colStart<g.colStart?(g.colStart=Math.max(g.colStart+c,e.colStart),g.colEnd=Math.max(g.colEnd+c,g.colStart-1)):g.colEnd+=Math.max(c,e.colStart-g.colEnd-1):r===_.Down?e.rowStart<=g.rowStart?(g.rowStart+=c,g.rowEnd+=c):g.rowEnd+=c:r===_.Up&&(e.rowStart<g.rowStart?(g.rowStart=Math.max(g.rowStart+c,e.rowStart),g.rowEnd=Math.max(g.rowEnd+c,e.rowStart-1)):g.rowEnd+=Math.max(c,e.rowStart-g.rowEnd-1)),(g.colEnd<g.colStart||g.rowEnd<g.rowStart)&&(g=null);const p=Ec(t,g,{after:g,before:t,intersect:e,isSplit:n,orientation:a,amount:c},I,b,s,y&&c>0);if(void 0===p)return;const S=null===p?[g]:p,w=S.length;if(S[0]!==t||1!==w){if(o)for(let t=0;t<w;t++){const e=S[t];e&&o(e)}let e;l?(m.set(l.uuid,l),e=[],f.set(t.uuid,e)):h.push(t);for(let r=0;r<w;r++){const n=S[r];u=U.unionRanges(u,n),l?e.push(n):(d.push(n),F&&F.push(n),k&&k.push(t))}}},p);let O=null;O=n&&(h.length>0||d.length>0||f.size>0)?this.clone():this,O._updateNodes(d,h),f.size>0&&O._updateGroupedEntries(m,f);let B=mt.EmptyArray;if(w&&g&&u){let t=!0;if(c>0&&(t=i?e.rowStart>g.rowStart||e.rowEnd<g.rowEnd:e.colStart>g.colStart||e.colEnd<g.colEnd),t){const t=pc(u,U.unionRanges(g,u),i?0:1,i?1:0);M&&(B=O._mergeNodes(t,!1))}}return T&&k.length>0&&T(k),A&&F.length>0&&A(F),M&&B.length>0&&M(B),R&&N.length>0&&R(N),O}insertNonOverlapping(t,e){const r=e?.onIntersect??((t,e)=>({...t,value:e.value})),n=this.search(t),o=new Map,s=new Map,i=this._options?.updateEntryOptions,a=i?.onUpdated,l=i?.onRemoved,c=i?.onMerged,h=i?.getSplit,d=i?.getIntersect,u=i?.getUpdate;let g=null,p=null,m=null,f=function(t,e,r){const n=r?.getIntersect??fc,o=r?.getUpdate??Sc;if(0===t.length){if(n){const t=n({...e,value:null},e);e=t&&null!==t.value?{...t}:null}if(o){const t=o(e);void 0!==t&&(e=t)}return e?[e]:mt.EmptyArray}const s=r?.getSplit??mc,i=(t,e,r=!0)=>{const n=e.search(t),o=n.length;for(let a=0;a<o;a++){const o=n[a];if(U.isEqualRanges(o,t))continue;e?.remove(o);const l=_c(o,t,s,r);for(let t=0;t<l.length;t++){const r=l[t];e.insert(r),i(r,e,!1)}}},a=new gc;a.load(t),i(e,a);const l=new gc;l.load([e]);const c=a.search(e);for(let t=0;t<c.length;t++)i(c[t],l);const h=(t,e,r)=>{let o=e.search(t);console.assert(o.length<=1,"intersecting incorrect ranges");const i=o[0]??{...t,value:null};if(U.isEqualRanges(i,t)){let o=n(i,t);e.remove(i),r.insert(o)}else{e.remove(i);const o=_c(i,t,s),a=o.length;for(let s=0;s<a;s++){const i=o[s];if(U.isEqualRanges(i,t)){const e=n(i,t);r.insert(e)}else e.insert(i)}}},d=new gc,u=l.all(),g=u.length;for(let t=0;t<g;t++)h(u[t],a,d);const p=(t,e)=>{const r=t.all(),n=r.length;for(let t=0;t<n;t++){let n=r[t];if(o){const t=o(n);void 0!==t&&(n=t)}null!==n&&null!==n.value&&e.push(n)}},m=a.all();return p(d,m),m}(n,t,{getSplit:(t,e,r,n)=>{let o;return h?(o=h(t,e,r,n),o):(o=xc(t,e,r,n),o)},getIntersect:(t,e)=>{d&&(e=d(t,e));const n=r(t,e);if(void 0===n)return n;if(null===n||null===n.value){const e=t.value;e?.onRemove?.(t)}return n},getUpdate:t=>{const e=t?.group;if(e){o.set(e.uuid,e);let r=s.get(t.lastId??t.uuid);r||(r=[],s.set(t.lastId??t.uuid,r)),r.push(null===t.value?null:t)}let r=t;if(u&&(r=u(t)),r&&null!==r.value)a&&(g||(g=[]),g.push(r));else if(l&&!m){m=[];let e=r&&null===r.value?r:{...t,value:null};m.push(e)}return r}});const _=this.getBoundingCoords();if(o.size>0){const t=[],e=f.length;for(let r=0;r<e;r++){let e=f[r];e.group||t.push(e)}f=t}if(this._updateNodes(f,n,e?.onUpdates),o.size>0&&this._updateGroupedEntries(o,s),_&&!e?.noMerge){const r=pc(t,U.unionRanges(_,t)),n=this.search(r);if(n.length>1){const t=i?.getMerged??Cc;let r=n;r=wc(r,E.Column,1,t),r=wc(r,E.Row,1,t),n.length!==r.length&&(c&&r.length>0&&(p=r),this._updateNodes(r,n,e?.onUpdates))}}return g&&a(g),p&&c(p),m&&l(m),this}insertGroup(t,e){e=e??mt.uuidV4();const r=[],n=t.length;for(let o=0;o<n;o++){const n={...t[o],group:{entries:r,uuid:e,offset:o},uuid:mt.uuidV4()};r.push(n),t[o]=n}return this.load(t),this._options?.updateEntryOptions?.onGroupUpdate?.(t,e),this}createCopiedEntries(t,e,r,n,o){return vc(this,t,e,r,n,o,this._options?.updateEntryOptions?.getSplit??xc)}_updateGroupedEntries(t,e){const r=[],n=[],o=new Map,s=t.values();let i=s.next();for(;!i.done;){const t=i.value,a=t.entries,l=t.uuid,c=[];for(let t=0;t<a.length;t++){let o=a[t];r.push(o);let s=e.get(o.uuid);void 0===s&&(s=[{...o}]);for(let t=0;t<s.length;t++){let e=s[t];null!==e&&(e={...e,group:{offset:c.length,entries:c,uuid:l}},c.push(e),n.push(e))}}c.sort((t,e)=>t.group.offset-e.group.offset),o.set(l,c),i=s.next()}if(this._updateNodes(n,r),o){const t=this._options?.updateEntryOptions?.onGroupUpdate;if(t){const e=o.entries();let r=e.next();for(;!r.done;){const n=r.value[0];t(r.value[1],n),r=e.next()}}}}_copy(t,e){let r=t.rTree.all();const n=new uc(this._options?.maxNodeEntries);return e&&(r=r.concat(e)),r.length>0&&n.load(r),{refCount:1,rTree:n}}_updateNodes(t,e,r){if(!(t&&0!==t.length||e&&0!==e.length))return;const n=this._getWritableTree();if(e){const t=e.length;for(let r=0;r<t;r++)n.remove(e[r])}t.length>0&&n.load(t),r?.(t,e,this),this._options?.updateEntryOptions?.onUpdates?.(t,e,this)}_mergeNodes(t,e){const r=this.search(t,e);let n=mt.EmptyArray;if(r.length>1){const t=this._options?.updateEntryOptions.getMerged??Cc;let e=r;e.length>1&&(e=wc(e,E.Column,1,t)),e.length>1&&(e=wc(e,E.Row,1,t)),r.length!==e.length&&(n=e,this._updateNodes(e,r))}return n}_getReadTree(){return this._shared?.rTree??this._rTree}_ensureWritable(t){const e=this._shared;if(!e)return;if(e.refCount--,0===e.refCount)return this._shared=null,void(t&&this._rTree.load(t));const r=this._copy(e,t);this._shared=null,this._rTree=r.rTree}_getWritableTree(t){return this._lastMiss.colStart=Number.MAX_SAFE_INTEGER,this._lastSingle=null,this._lastSingleResult=null,this._shared?(this._ensureWritable(t),this._rTree):(t&&this._rTree.load(t),this._rTree)}remove(t,e){return t&&this._getWritableTree().remove(t,e??U.isEqualRanges),this}insert(t){return t&&this._getWritableTree().insert(t),this}load(t){return t&&t.length>0&&this._getWritableTree(t),this}clear(){return this.isEmpty()||this._getWritableTree().clear(),this}clone(t=null){if(null!==t&&this._cloneKey===t)return this;let e=this._shared;e||(e={rTree:this._rTree,refCount:1},this._shared=e),e.refCount++;const r=new gc(this._options);return r._shared=e,r._cloneKey=t,r}fromJSON(t){return this._getWritableTree().fromJSON(t),this}}const pc=(t,e=t,r=1,n=1)=>({...t,colStart:Math.max(t.colStart-r,e.colStart),rowStart:Math.max(t.rowStart-n,e.rowStart),colEnd:Math.min(t.colEnd+r,e.colEnd),rowEnd:Math.min(t.rowEnd+n,e.rowEnd)});function mc(t,e,r,n){return[{...e[0],value:t.value},{...e[0],value:t.value}]}function fc(t,e){return{...t}}function _c(t,e,r=null,n=!0){if(U.isEqualRanges(t,e))return[{...t}];const o=U.intersectRanges(t,e,Ac);if(!o)return null;const s=[],i=t.uuid;let a=t;if(a.rowStart<o.rowStart){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:o.rowStart-1};i&&(n&&(t.lastId=i),t.uuid=mt.uuidV4());const e={...a,colStart:a.colStart,rowStart:o.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(n&&(e.lastId=i),e.uuid=mt.uuidV4());const l=e.rowStart-t.rowStart;Ic[0]=t,Ic[1]=e;const c=r(a,Ic,E.Row,l);void 0!==c&&(s.push(c[0]),a=c[1])}if(a.rowEnd>o.rowEnd){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:o.rowEnd};i&&(n&&(t.lastId=i),t.uuid=mt.uuidV4());const e={...a,colStart:a.colStart,rowStart:o.rowEnd+1,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(n&&(e.lastId=i),e.uuid=mt.uuidV4());const l=e.rowStart-t.rowStart;Ic[0]=t,Ic[1]=e;const c=r(a,Ic,E.Row,l);void 0!==c&&(s.push(c[1]),a=c[0])}if(a.colStart<o.colStart){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:o.colStart-1,rowEnd:a.rowEnd};i&&(n&&(t.lastId=i),t.uuid=mt.uuidV4());const e={...a,colStart:o.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(n&&(e.lastId=i),e.uuid=mt.uuidV4());const l=e.colStart-t.colStart;Ic[0]=t,Ic[1]=e;const c=r(a,Ic,E.Column,l);void 0!==c&&(s.push(c[0]),a=c[1])}if(a.colEnd>o.colEnd){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:o.colEnd,rowEnd:a.rowEnd};i&&(n&&(t.lastId=i),t.uuid=mt.uuidV4());const e={...a,colStart:o.colEnd+1,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(n&&(e.lastId=i),e.uuid=mt.uuidV4());const l=e.colStart-t.colStart;Ic[0]=t,Ic[1]=e;const c=r(a,Ic,E.Column,l);void 0!==c&&(s.push(c[1]),a=c[0])}return a===t&&(a={...t}),s.push(a),s}function Sc(t){return null===t.value?null:t}function wc(t,e=E.Column,r=2,n,o){let s=[...t];if(r<=0||t.length<=1)return s;let i=e===E.Column,a=0,l=!1;do{const t=s.sort(U.createRangeComparator(i?E.Row:E.Column));s=[],l=!1,s.push(t[0]);for(let r=1;r<t.length;r++){const a=t[r],c=s[s.length-1];let h=!1;if(h=i?c&&c.rowStart===a.rowStart&&c.rowEnd===a.rowEnd&&c.colEnd+1===a.colStart:c&&c.colStart===a.colStart&&c.colEnd===a.colEnd&&c.rowEnd+1===a.rowStart,h){let t={...c,colEnd:i?a.colEnd:c.colEnd,rowEnd:i?c.rowEnd:a.rowEnd};if(n){const r=o??[null,null];r[0]=c,r[1]=a,t=n(r,t,e)}if(t){s[s.length-1]=t,l=!0;continue}}s.push(a)}a++,i=!i}while(a<r&&l&&s.length>1);return s}const yc=(t,e=2,r=E.Row,n,o,s)=>{if(t.length<=1)return[...t];let i=[];const a=r===E.Column,l=new Fl.IteratorInstance(t,{orientation:a?E.Row:E.Column});let c=l.next();for(;!c.done;){const t=c.value;c=l.next();const r=t.range;if(e>0){const t=i[i.length-1];let e=!1;if(e=a?t&&t.rowStart===r.rowStart&&t.rowEnd===r.rowEnd&&t.colEnd+1===r.colStart:t&&t.colStart===r.colStart&&t.colEnd===r.colEnd&&t.rowEnd+1===r.rowStart,e){let e={...t,colEnd:a?r.colEnd:t.colEnd,rowEnd:a?t.rowEnd:r.rowEnd};if(e){i[i.length-1]=e;continue}}}i.push(r)}return e>1&&(i=wc(i,a?E.Row:E.Column,e,n,s)),i};function xc(t,e,r,n){const o=t.value;if(o?.getSplit){const t=o.getSplit(e,r,n);if(void 0===t)return;e[0].value=t[0],e[1].value=t[1]}return e}function Cc(t,e,r){const n=t[0].value,o=t[1].value;if(n?.getMerged&&o){const o=n.getMerged(t[1].value,U.sanitizeRange(e),r);if(void 0===o)return;e.value=o}return e}const bc=(t,e,r=v.Both)=>{const n=r=>r?t.rowStart>e.rowStart&&t.rowStart<=e.rowEnd||t.rowEnd<e.rowEnd&&t.rowEnd>=e.rowStart:t.colStart>e.colStart&&t.colStart<=e.colEnd||t.colEnd<e.colEnd&&t.colEnd>=e.colStart;let o=r===v.Column,s=r===v.Row;return r===v.Both&&(o=s=!0),!(!o||!n(!0))||!(!s||!n(!1))};function Ec(t,e,r,n,o,s,i){const a=r.orientation===E.Column,l=r.intersect,c=(e,c)=>{let h=e.value,d=null,u=c.after;if(i){let r=null,n=0,s=0;if(a&&l.colStart>e.colStart?(r={...e,colEnd:l.colStart-1},s=c.amount):!a&&l.rowStart>e.rowStart&&(r={...e,rowEnd:l.rowStart-1},n=c.amount),r){const e=_c(t,r,o);if(e.length>1)for(let t=0;t<e.length;t++){let o=e[t];U.isEqualRanges(o,r)?(d=d??[],d.push(o)):(u=o,h=o.value,c={...c,after:{...o,colStart:o.colStart+s,rowStart:o.rowStart+n,colEnd:o.colEnd+s,rowEnd:o.rowEnd+n,uuid:mt.uuidV4()},before:o,intersect:r,isSplit:!0})}}}if(n){u=n(c.before,c.after,c)}else if(h&&h.getShifted){u=h.getShifted(c)}else c.after&&(u={...c.after,value:e.value});if(void 0!==u)return s&&(u!==c.after&&(c={...c,after:u}),s(c)),u=(e=>{if(!e){const e=t.value;return e.onRemove&&e.onRemove(U.sanitizeRange(r.before)),null}return e})(u),u&&(d=d??[],d.push(u)),d};if(r.isSplit){let n;n=a?{...t,rowStart:Math.max(l.rowStart,r.before.rowStart),rowEnd:Math.min(l.rowEnd,r.before.rowEnd)}:{...t,colStart:Math.max(l.colStart,r.before.colStart),colEnd:Math.min(l.colEnd,r.before.colEnd)};const s=_c(t,n,o),i=[];for(let t=0;t<s.length;t++){const o=s[t];if(U.isEqualRanges(o,n)){let t=null;e&&(t=a?{colStart:e.colStart,rowStart:n.rowStart,colEnd:e.colEnd,rowEnd:n.rowEnd,value:o.value}:{colStart:n.colStart,rowStart:e.rowStart,colEnd:n.colEnd,rowEnd:e.rowEnd,value:o.value});const s=c(o,{...r,before:o,after:t});if(s)for(let t=0;t<s.length;t++)i.push(s[t])}else i.push(o)}return i}return c(t,r)}const vc=(t,e,r,n,o,s,i)=>{const a=r.colEnd-r.colStart+1,l=r.rowEnd-r.rowStart+1,c=r.colStart-e.colStart,h=r.rowStart-e.rowStart,d=n?.transpose??!1;let u=1,g=1;d?(u=e.rowEnd-e.rowStart+1,g=e.colEnd-e.colStart+1):(u=e.colEnd-e.colStart+1,g=e.rowEnd-e.rowStart+1);const p=Math.ceil(a/u),m=Math.ceil(l/g),f=o??[],S=s??mt.EmptyArray,w=r.colEnd,y=r.rowEnd;return t.visitRanges(e,t=>{let o=t.value;if(!o.copyTo)return;let s=t;if(!U.isRangeWithinRange(s,e)){const t=_c(s,e,i);s=t[t.length-1]}o=s.value;let _=s.colEnd-s.colStart+1,S=s.rowEnd-s.rowStart+1,x=c+s.colStart,C=h+s.rowStart;if(d){x=s.rowStart-e.rowStart+r.colStart,C=s.colStart-e.colStart+r.rowStart;const t=_;_=S,S=t}let b=p,v=m;const I=a<=b*_,A=l<=v*S;if(I||A){const t=o?.canTile?.({colStart:x,rowStart:C,colEnd:Math.min(x+(I?a:_)-1,w),rowEnd:Math.min(C+(A?l:S)-1,y)},n);!I||!0!==t&&t!==E.Column||(_=a,b=1),!A||!0!==t&&t!==E.Row||(S=l,v=1)}for(let t=0;t<b;t++){const e=x+t*u;for(let t=0;t<v;t++){const r=C+t*g,s=Math.min(e+_-1,w),i=Math.min(r+S-1,y),a={colStart:e,rowStart:r,colEnd:s,rowEnd:i};if(e>s||r>i)continue;const l=o.copyTo(a,n);l&&f.push({...a,value:l})}}},_.Right),{inserts:f,removes:S}},Ic=[null,null],Ac={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Rc=(t=Number.MIN_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,o,s,i)=>{if(s&&(t!==Number.MIN_SAFE_INTEGER&&t<s.colStart||e!==Number.MIN_SAFE_INTEGER&&e<s.rowStart||r!==Number.MAX_SAFE_INTEGER&&r>s.colEnd||n!==Number.MAX_SAFE_INTEGER&&n>s.rowEnd))throw new Mt;return i&&(t=Math.max(i.colStart,t),e=Math.max(i.rowStart,e),r=Math.min(i.colEnd,r),n=Math.min(i.rowEnd,n),r<t||n<e)?null:(Tc.majorStart=o?t:e,Tc.majorEnd=o?r:n,Tc.minorStart=o?e:t,Tc.minorEnd=o?n:r,Tc)},Mc=(t,e,r)=>{const n={colStart:0,rowStart:0,colEnd:0,rowEnd:0};return n.colStart=e?t.majorStart:t.minorStart,n.rowStart=e?t.minorStart:t.majorStart,n.colEnd=e?t.majorEnd:t.minorEnd,n.rowEnd=e?t.minorEnd:t.majorEnd,n},Tc={majorStart:0,majorEnd:0,minorStart:0,minorEnd:0},Fc=(t,e)=>t[0]-e[0];class Nc{constructor(t,e){this._isColumn=!0,this._isReverse=!1,this._skipMajors=!1,this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=Number.MIN_SAFE_INTEGER,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=Number.MIN_SAFE_INTEGER,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._delegateMajorIndex=Number.MIN_SAFE_INTEGER,this._delegateMinorIndex=Number.MIN_SAFE_INTEGER,this._delegate=t;const r=(e.orientation??E.Column)===E.Column;this._isColumn=r,this._isReverse=e.reverse??!1,this._skipMajors=e.skipMajors??!1;const n=e.bounds,o=n.colStart,s=n.rowStart,i=n.colEnd,a=n.rowEnd;this._majorMin=r?o:s,this._majorMax=r?i:a,this._minorMin=r?s:o,this._minorMax=r?a:i,this._processMajorSkip=r?e.processColumnSkip:e.processRowSkip,this._processMinorSkip=r?e.processRowSkip:e.processColumnSkip;const l=t.next();this._delegateResult=l,this._initialize()}_initialize(){const t=this._isColumn,e=this._isReverse,r=e?-1:1;let n=e?this._majorMax:this._majorMin,o=(e?this._minorMax:this._minorMin)-r;const s=this._processMinorSkip;s&&(o=s(o,e));const i=this._processMajorSkip;i&&(n=i(n,e)),this._majorIndex=n,this._minorIndex=o;const a=this._delegateResult;if(a.done)this._delegateMajorIndex=this._majorMax,this._delegateMinorIndex=this._minorMax+r;else{const e=a.value[0];this._delegateMajorIndex=t?e.colIndex:e.rowIndex,this._delegateMinorIndex=t?e.rowIndex:e.colIndex}}next(t){void 0!==t&&(this._delegateResult=this._delegate.next(t),this._initialize());const e=this._isReverse,r=this._isColumn,n=this._majorMin,o=this._majorMax;let s=this._majorIndex,i=this._minorIndex;if(s>o||s<n)return Cl;let a=this._delegateMajorIndex,l=this._delegateMinorIndex,c=this._delegateResult.done;if(s===a&&i===l){const t=this._delegate.next();if(this._delegateResult=t,c=t.done,c)a=e?n:o,a=e?this._minorMin:this._minorMax;else{const e=t.value[0];a=r?e.colIndex:e.rowIndex,l=r?e.rowIndex:e.colIndex}this._delegateMajorIndex=a,this._delegateMinorIndex=l}const h=e?-1:1;if(this._minorIndex=i+=h,s===a&&i===l&&!c)return this._delegateResult;const d=this._processMinorSkip;if(d&&(i=d(i,e)),i>this._minorMax||i<this._minorMin){s+=h;const t=this._processMajorSkip;t&&(s=t(s,e)),this._skipMajors&&(!e&&s<a||e&&s>a)&&(s=a),this._majorIndex=s,i=e?this._minorMax:this._minorMin}if(this._minorIndex=i,s===a&&i===l&&!c)return this._delegateResult;if(s>o||s<n)return Cl;return{done:!1,value:[{colIndex:r?s:i,rowIndex:r?i:s}]}}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}class kc{constructor(t){this._isColumn=!0,this._majorSize=Number.MAX_SAFE_INTEGER,this._minorSize=Number.MAX_SAFE_INTEGER,this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=Number.MIN_SAFE_INTEGER,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=Number.MIN_SAFE_INTEGER,this._majorIndex=Number.MAX_SAFE_INTEGER,this._minorIndex=Number.MAX_SAFE_INTEGER,this._minorOffset=0,this._minorRepeat=0,this._majorOffset=-1,this._majorRepeat=1,this._pattern=[];const e=t.delegate;this._delegate=e;const r=(t.orientation??E.Column)===E.Column;this._isColumn=r;const n=t.dims,o=t.bounds,s=o.colStart,i=o.rowStart,a=o.colEnd,l=o.rowEnd;if(this._majorSize=1+(r?a-s:l-i),this._minorSize=1+(r?l-i:a-s),this._majorMin=r?s:i,this._minorMin=r?i:s,this._majorMax=(r?s+n.major:i+n.major)-1,this._minorMax=(r?i+n.minor:s+n.minor)-1,this._majorSize>this._majorMax+1||this._minorSize>this._minorMax+1)throw new Error("The dimensions must be larger than the bounds.");const c=e.next();this._nextDelegateResult=c,this._initialize()}_initialize(){const t=this._isColumn,e=this._nextDelegateResult;if(e.done)this._nextResult=Cl;else{const r=e.value[0],n=t?r.colIndex:r.rowIndex,o=t?r.rowIndex:r.colIndex,s=[[o,e.value[1]]];this._minorSpan=s,this._majorIndex=n,this._minorIndex=o,this._pattern.push([n,s]),this._nextResult=e}}next(t){if(void 0!==t)throw new kt;const e=this._nextResult,r=this._isColumn;let n=this._majorIndex,o=this._nextDelegateResult;if(!o.done){const t=o.value[0];if((r?t.colIndex:t.rowIndex)===n&&(o=this._delegate.next(),this._nextDelegateResult=o,!o.done)){const t=o.value,s=t[0],i=r?s.colIndex:s.rowIndex,a=r?s.rowIndex:s.colIndex;if(i===n)return this._minorSpan.push([a,t[1]]),this._minorOffset=this._minorSpan.length-1,this._minorIndex=a,this._nextResult=o,e}}const s=this._minorMax;let i=this._minorIndex;if(i<s){let t=this._minorOffset;t++;const o=this._minorSpan;t>=o.length&&(t=0,this._minorRepeat++);const a=o[t],l=this._minorMin;if(i=l+(a[0]-l+this._minorSize*this._minorRepeat),this._minorIndex=i,this._minorOffset=t,i<=s){const t=[{colIndex:r?n:i,rowIndex:r?i:n},a[1]];return this._nextResult={done:!1,value:t},e}}if(!o.done){const t=o.value,n=t[0],s=r?n.colIndex:n.rowIndex,i=r?n.rowIndex:n.colIndex,a=[[i,t[1]]];return this._pattern.push([s,a]),this._majorIndex=s,this._minorSpan=a,this._minorOffset=0,this._minorIndex=i,this._minorRepeat=0,this._nextResult=o,e}const a=this._majorMax;if(n<a){let t=this._majorOffset;t++;const o=this._pattern;t>=o.length&&(t=0,this._majorRepeat++);const s=o[t],l=s[1],c=l[0],h=this._majorMin;if(n=h+(s[0]-h+this._majorSize*this._majorRepeat),this._majorIndex=n,this._majorOffset=t,n<=a){this._minorSpan=l,this._minorOffset=0,i=c[0],this._minorIndex=i,this._minorRepeat=0;const t=[{colIndex:r?n:i,rowIndex:r?i:n},c[1]];return this._nextResult={done:!1,value:t},e}}return e.done||(this._nextResult=Cl),e}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}class Oc{constructor(t,e,r){this._comparator=t?.comparator??U.createCellComparator(t.orientation??E.Column,t.reverse??!1),this._iterator1=e,this._iterator2=r;const n=e.next();this._nextResult1=n;const o=r.next();this._nextResult2=o,t?.reuseResult&&(!0===t.reuseResult?this._reuseResult={done:!1,value:[void 0,void 0,void 0,void 0]}:this._reuseResult=t.reuseResult)}next(t){let e=this._nextResult1,r=this._nextResult2;if(e.done&&r.done)return e;if(e.done){const t=r;this._nextResult2=this._iterator2.next();const e=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};e.done=!1;const n=e.value,o=t.value;return n[2]=o[0],n[3]=o[1],n[0]=void 0,n[1]=void 0,e}if(r.done){const t=e;this._nextResult1=this._iterator1.next();const r=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};r.done=!1;const n=r.value,o=t.value;return n[0]=o[0],n[1]=o[1],n[2]=void 0,n[3]=void 0,r}let n=(0,this._comparator)(e.value[0],r.value[0]);if(n<0){const t=e;this._nextResult1=this._iterator1.next();const r=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};r.done=!1;const n=r.value,o=t.value;return n[0]=o[0],n[1]=o[1],n[2]=void 0,n[3]=void 0,r}if(n>0){const t=r;this._nextResult2=this._iterator2.next();const e=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};e.done=!1;const n=e.value,o=t.value;return n[2]=o[0],n[3]=o[1],n[0]=void 0,n[1]=void 0,e}this._nextResult1=this._iterator1.next(),this._nextResult2=this._iterator2.next();const o=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};o.done=!1;const s=o.value;return s[0]=e.value[0],s[1]=e.value[1],s[2]=r.value[0],s[3]=r.value[1],o}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}const Bc="Must be an array of arrays.",Lc=(t,e,r)=>{const n=e.majorStart,o=e.minorStart,s=e.majorEnd,i=[],a=e.minorEnd-o+1,l="function"==typeof t;for(let e=n;e<=s;e++){const n=new Array(a);if(l)if(r){let r=o;for(let o=0;o<a;o++)n[o]=t(r++,e)}else{let r=o;for(let o=0;o<a;o++)n[o]=t(e,r++)}else n.fill(t,0,a);const s=[[o,n]];i.push([e,s])}return{tuples:i,bounds:e}},Dc=(t,e=!1,r=null,n=!1)=>{let o=0,s=0,i=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER;if(r){o=r.majorStart??0,s=r.minorStart??0;i=(r.majorEnd??Number.MAX_SAFE_INTEGER)-o+1,a=(r.minorEnd??Number.MAX_SAFE_INTEGER)-s+1}if(e){const t=o;o=s,s=t;const e=i;i=a,a=e}if(!Array.isArray(t))throw new Error(Bc);if(t.length>i)throw new Mt;const l=e?new exports.Tuple.TransposedBuilder:new exports.Tuple.Builder;for(let e=0;e<t.length;e++){let r=t[e];if(null!=r&&0!==r.length){if(!Array.isArray(r))throw new Error(Bc);if(r.length>a)throw new Mt;if(n){let t=-1;for(let n=0;n<r.length;n++){const i=r[n];null==i?-1!==t&&(l.addValues(e+o,s+t,r.slice(t,n)),t=-1):-1===t&&(t=n)}-1!==t&&l.addValues(e+o,s+t,r.slice(t))}else l.addValues(e+o,s,r)}}return l.build()},zc=(t,e,r)=>{if(t===e)return e},Pc=(t,e,r)=>{if(t[0].value===t[1].value)return e},jc=[null,null],Hc=(t=!0,e=zc)=>{const r=[];let n,o,s=Number.MIN_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER;return{append:(a,l,c)=>{let h=!0;if(void 0!==c){const r=void 0===o?c:e(o,c,t);void 0===r?h=!1:c=r}if(h&&l===i+1&&a===s)return t?n.rowEnd=l:n.colEnd=l,i=l,void(o=c);n&&r.push(n);const d=t?a:l,u=t?l:a;n={colStart:d,rowStart:u,colEnd:d,rowEnd:u,value:c},s=a,i=l,o=c},done:(e=!1)=>(n&&(r.push(n),n=null),e?wc(r,t?E.Column:E.Row,2,Pc,jc):r)}};class Vc{constructor(t){this._major=null,this._dataCoords=null,this._count=0,this._isColumn=!0,this._lastMajor=Number.MIN_SAFE_INTEGER,this._lastMinorSpan=null,this._maxCoords=null,this._isShared=!1,this._options={orientation:E.Row,...t},this._isColumn=(t?.orientation??E.Column)===E.Column,t?.maxCoords&&(this._maxCoords=Object.freeze({colStart:Math.max(0,t.maxCoords.colStart??0),rowStart:Math.max(0,t.maxCoords.rowStart??0),colEnd:Math.min(Number.MAX_SAFE_INTEGER,t.maxCoords.colEnd??Number.MAX_SAFE_INTEGER),rowEnd:Math.min(Number.MAX_SAFE_INTEGER,t.maxCoords.rowEnd??Number.MAX_SAFE_INTEGER)})),this._createRun=t?.createRun??(t=>new vl(t)),this._optionsMinor={},this._major=new Ol({nodeSize:$c})}getRuns(t){const e=this._isColumn,r=this._maxCoords,n=this.getCoords();if(!n)return bl;const o=t?.bounds;let s,i;if(o){const t=Rc(o?.colStart??Number.MIN_SAFE_INTEGER,o?.rowStart??Number.MIN_SAFE_INTEGER,o?.colEnd??Number.MAX_SAFE_INTEGER,o?.rowEnd??Number.MAX_SAFE_INTEGER,e,r,n);if(!t)return bl;s={bounds:{min:t.majorStart,max:t.majorEnd}},i={bounds:{min:t.minorStart,max:t.minorEnd}}}const a=this._major.entries(s);let l=a.next();if(l.done)return bl;let c=l.value[0],h=l.value[1],d=h.runs(i),u=d.next();if(u.done)return bl;let g=u.value[0].min,p=u.value[1];return{[Symbol.iterator](){return this},next(){if(l.done)return Cl;const t={done:!1,value:[c,g,p]};for(u=d.next();u.done&&!l.done;)l=a.next(),l.done||(c=l.value[0],h=l.value[1],d=h.runs(i),u=d.next());return u.done||(g=u.value[0].min,p=u.value[1]),t}}}getOrientation(){return this._isColumn?E.Column:E.Row}entries(t){const e=this._isColumn;let r=e,n=!0;const o=this._maxCoords,s=this.getCoords(),i=Rc(Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,e,o,s);if(!i)return bl;let a,l,c,h=i.majorStart,d=i.majorEnd,u=i.minorStart,g=i.minorEnd,p=!1;if(t){t?.orientation&&(r=t?.orientation===E.Column,n=e===r);const i=t?.bounds;if(i){const t=Rc(i.colStart,i.rowStart,i.colEnd,i.rowEnd,e,o,s);if(!t)return bl;h=t.majorStart,d=t.majorEnd,u=t.minorStart,g=t.minorEnd}p=t.reverse??!1,c=(t=>"boolean"!=typeof t?t:!0===t?{done:!1,value:[{colIndex:-1,rowIndex:-1},null]}:void 0)(t.reuseResult),a=e?t.processColumnSkip:t.processRowSkip,a&&(p?d=a(d,p):h=a(h,p)),l=e?t.processRowSkip:t.processColumnSkip,l&&(p?g=l(d,p):u=l(u,p))}if(!s)return bl;n||h!==d||(n=!0),Jc.bounds.min=h,Jc.bounds.max=d,Jc.reverse=p,Jc.processSkip=a,Jc.reuseResult=Wc;let m=this._major.entries(Jc),f=Xc();const _=t=>{if(!t.nextActive)return;const e=e=>{const r=t.nextMinorIndex,n=t.nextMinorValue,o=t.nextActive;return e?(t.nextMinorIndex=e[0],t.nextMinorValue=e[1],t.nextActive=!0):(t.nextActive=!1,t.nextMinorIndex=p?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,t.nextMinorValue=null),t.value=n,t.minorIndex=r,t.active=o,Uc[0]=t.majorIndex,Uc[1]=r,Uc[2]=n,Uc},r=t.minorIterator;if(!r)return e();const n=r.next();return n.done&&(t.minorIterator=null),e(n.value)},S=t=>{if(m)for(;;){const e=m.next();if(e.done)return void(m=void 0);const r=e.value,n=r[1];n||console.warn("issue",n),t.majorIndex=r[0],t.active=!0,t.nextActive=!1,qc.bounds.min=u,qc.bounds.max=g,qc.reverse=p,qc.processSkip=l,qc.reuseResult=Gc;const o=n.entries(qc),s=o.next();if(!s.done){const e=s.value;return t.nextMinorIndex=e[0],t.nextMinorValue=e[1],t.minorIterator=o,t.nextActive=!0,_(t)}}};let w=null;if(n){w=()=>{let t;return t=_(f),t||(t=S(f),t||void 0)}}else{const t=p?g:u,e=p?u:g;let r,n=t,o=e,s=!0;const i=()=>{if(f.nextMajorCursor)return f=f.nextMajorCursor,f;f=r,(n<u||n>g||n===o)&&(f=null),n=o,o=e};w=()=>{for(;f;){let a=null;if(s){let e=r?Xc():f;if(a=S(e),a){r?(e.prevMajorCursor=f,f.nextMajorCursor=e,f=e):r=f,o=p?Math.max(o,f.nextMinorIndex):Math.min(o,f.nextMinorIndex);const n=f.minorIndex;n!==t&&(o=p?Math.max(o,n):Math.min(o,n),a=null)}else s=!1,i()}else{const t=f.minorIndex,s=f.nextMinorIndex;t===n?(Uc[0]=f.majorIndex,Uc[1]=t,Uc[2]=f.value,a=Uc):!p&&t>n||p&&t<n?o=p?Math.max(o,t):Math.min(o,t):!p&&s>n||p&&s<n?o=p?Math.max(o,s):Math.min(o,s):a=_(f),f.active&&(o=p?Math.max(o,f.nextMinorIndex):Math.min(o,f.nextMinorIndex)),e===n||f.active||(f.prevMajorCursor?f.prevMajorCursor.nextMajorCursor=f.nextMajorCursor:r=f.nextMajorCursor,f.nextMajorCursor&&(f.nextMajorCursor.prevMajorCursor=f.prevMajorCursor)),i()}if(a)return a}}}const y={next(t){if(t)throw new kt("Iterator with next argument is not supported.");const r=w();if(!r)return Cl;const n=((t,e,r,n,o)=>{const s=o??{done:!1,value:[{colIndex:-1,rowIndex:-1},null]},i=s.value,a=i[0];return a.colIndex=n?t:e,a.rowIndex=n?e:t,i[1]=r,s})(r[0],r[1],r[2],e,c);return n},[Symbol.iterator](){return this},return:t=>null,throw:t=>null};return y}values(t){const e=this.entries(t);let r;t?.reuseResult&&(r=!0===t.reuseResult?{done:!1,value:null}:t.reuseResult);return{next(t){const n=e.next(t);return n.done?Cl:r?(r.value=n.value[1],r):{done:!1,value:n.value[1]}},[Symbol.iterator](){return this},return:t=>null,throw:t=>null}}keys(t){const e=this.entries(t);let r;t?.reuseResult&&(r=!0===t.reuseResult?{done:!1,value:null}:t.reuseResult);return{next(t){const n=e.next(t);return n.done?Cl:r?(r.value=n.value[0],r):{done:!1,value:n.value[0]}},[Symbol.iterator](){return this},return:t=>null,throw:t=>null}}_updateMajorSpan(t,e=!1){if(!t||0===t.length)return;e&&t.sort((t,e)=>t[0]-e[0]);const r=this._major,n=t[0];let o=n[0],s=o,i=[n[1]];for(let e=1;e<t.length;e++){const n=t[e],a=n[0],l=n[1];a===s+1?i.push(l):(r.setRunAt(o,new vl(i)),o=a,i=[l]),s=a}i.length>0&&r.setRunAt(o,new vl(i))}setValues(t){if(!t)throw new Ft;if(0===t.length)return this;const e=(t=t.sort(Fc))[0][0],r=t[t.length-1][0];let n=Number.MIN_SAFE_INTEGER,o=Number.MAX_SAFE_INTEGER;const s=this._isColumn,i=this._maxCoords;if(i){const t=s?i.colStart:i.rowStart,a=s?i.colEnd:i.rowEnd;if(e<t||r>a)throw new Mt;n=s?i.rowStart:i.colStart,o=s?i.rowEnd:i.colEnd}if(!t||0===t.length)return this;let a=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER,c=0,h=e-1;const d=[],u=(t,e,r)=>{if(h===r)throw new exports.Tuple.OutOfOrderError(`Duplicate major Indices: {${r}}.`);h=r,e=e.sort(Fc),t=t.clone();let s=Number.MIN_SAFE_INTEGER;const i=e.length;for(let h=0;h<i;h++){const i=e[h],d=i[0],u=i[1],p=d+u.length-1;if(s>=d)throw new exports.Tuple.OutOfOrderError(`Overlapping minor Indices: {${r}, ${d}}.`);if(d<n||p>o)throw new Mt;if(u&&u.length>0){const e=t.getCount();t.setRunAt(d,g(u));const r=t.getCount();c+=r-e,a=Math.min(a,t.getCoords().min),l=Math.max(l,t.getCoords().max)}s=p}m++,d.push([r,t])},g=this._createRun,p=this._optionsMinor;let m=0;const f=()=>{const e=t[m],r=e[0],n=e[1],o=new Ol(p);u(o,n,r)},_=this._major;Jc.bounds.min=e,Jc.bounds.max=r,Jc.reverse=!1,Jc.processSkip=null,Jc.reuseResult=Wc;const S=_.entries(Jc);let w=S.next();for(;!w.done;){const e=w.value,r=e[0];let n=t[m],o=n[0];if(o>r)w=S.next();else{for(;o<r;)f(),n=t[m],o=n[0];if(o===r){const t=n[1],o=e[1];u(o,t,r)}w=S.next()}}for(;t[m];)f();return this._updateMajorSpan(d),this._updateCountAndCoords(c,e,a,r,l),this}_updateCountAndCoords(t,e,r,n,o,s=!1){const i=this._count+t;if(this._count=i,this._lastMajor=Number.MIN_SAFE_INTEGER,!this._dataCoords)return;const a=this._isColumn;let l=a?e:r,c=a?r:e,h=a?n:o,d=a?o:n;if(0===i)this._dataCoords=null;else{const t=this._dataCoords;t&&(l=(s?Math.max:Math.min)(l,t.colStart),c=(s?Math.max:Math.min)(c,t.rowStart),h=(s?Math.min:Math.max)(h,t.colEnd),d=(s?Math.min:Math.max)(d,t.rowEnd));const e={colStart:l,rowStart:c,colEnd:h,rowEnd:d};this._dataCoords=e}}clear(){this._major.clear(),this._dataCoords=null,this._count=0}delete(t){const e=this._count;if(!t)return this.clear(),e>0;const r=this._isColumn,n=this._maxCoords,o=this.getCoords(),s=Rc(t.colStart,t.rowStart,t.colEnd,t.rowEnd,r,n,o);if(!s||0===e)return!1;if(U.isRangeWithinRange(o,t))return this.clear(),e>0;const i=s.majorStart,a=s.majorEnd,l=s.minorStart,c=s.minorEnd;let h=r?o.colStart:o.rowStart,d=r?o.colEnd:o.rowEnd;const u=r?o.rowStart:o.colStart,g=r?o.rowEnd:o.colEnd;let p=!1,m=0;const f=this._major;if(l<=u&&c>=g){Jc.bounds.min=i,Jc.bounds.max=a;const t=f.entries(Jc);let e=t.next();for(;!e.done;){m-=e.value[1].getCount(),e=t.next()}return f.delete(i,a-i+1),this._count+=m,this._dataCoords=null,0!==m}const _=[],S=this._isShared,w=[];Jc.bounds.min=i,Jc.bounds.max=a,qc.reverse=!1,qc.processSkip=null,qc.reuseResult=Wc;const y=f.entries(Jc);let x=y.next();for(;!x.done;){const t=x.value,e=t[0];let r=t[1];const n=r.getCoords(),o=n.min,s=n.max;if(l<=o&&c>=o||l<=s&&l<=s)if((o===u&&l<=u||s===g&&c>=g)&&(p=!0),o>=l&&s<=c)_.push(e),m-=r.getCount();else{const t=r.getCount();S&&(r=r.clone(),w.push([e,r])),r.delete(l,c-l+1);m+=r.getCount()-t}x=y.next()}this._updateMajorSpan(w);const C=_.length;if(C>0){const t=na(_,!0);for(let e=0;e<t.length;e++){const r=t[e];f.delete(r.min,r.max-r.min+1)}const e=f.getCoords();if(!e)return this.clear(),!0;h=e.min,d=e.max}return p?(this._count+=m,this._dataCoords=null,!0):0===C?(this._count+=m,0!==m):(this._updateCountAndCoords(m,h,u,d,g,!0),0!==m)}shift(t,e){if(!t||!e)throw new Ft;const r=this._isColumn,n=this._maxCoords,o=e===_.Right||e===_.Down,s=e===_.Left||e===_.Right,i=Rc(t.colStart,t.rowStart,t.colEnd,t.rowEnd,r,n,t);if(!i)return!1;const a=i.majorStart,l=i.majorEnd,c=i.minorStart,h=i.minorEnd,d=this.getCoords();if(!d)return!1;const u=r?d.colStart:d.rowStart,g=r?d.colEnd:d.rowEnd,p=r?d.rowStart:d.colStart,m=r?d.rowEnd:d.colEnd,f=c<=p&&h>=m,S=r===s;if(S&&f||!S&&(a<=u&&l>=g)){if(!Rc(d.colStart,d.rowStart,d.colEnd+(o&&s?t.colEnd-t.colStart+1:0),d.rowEnd+(o&&!s?t.rowEnd-t.rowStart+1:0),r,n))return!1}if(S&&a>g||!S&&c>m)return!1;let w=S?l-a+1:h-c+1;if(!o&&(w*=-1,U.isRangeWithinRange(d,t)))return this.clear(),!0;let y=0;const x=this._major,C=[];if(Jc.bounds.min=a,Jc.bounds.max=S?Number.MAX_SAFE_INTEGER:l,qc.reverse=!o,qc.processSkip=null,qc.reuseResult=Wc,S&&f){if(!o){Jc.bounds.max=l;const t=x.entries(Jc);let e=t.next();for(;!e.done;){y-=e.value[1].getCount(),e=t.next()}}x.shift(a,w);const t=x.getCoords();return this._dataCoords=null,this._updateCountAndCoords(y,t.min,p,t.max,m),!0}let b=r?d.colStart:d.rowStart,E=r?d.colEnd:d.rowEnd,v=r?d.rowStart:d.colStart,I=r?d.rowEnd:d.colEnd;o||(v=Number.MAX_SAFE_INTEGER,I=Number.MIN_SAFE_INTEGER);let A=Number.MAX_SAFE_INTEGER;n&&(A=s?n.colEnd:n.rowEnd);const R=new Set,M=S?new Map:null,T=[],F=x.entries(Jc),N={bounds:{min:c,max:h}};let k=F.next();for(;!k.done;){const t=k.value,e=t[0],r=t[1].clone(),n=r.getCoords(),o=n.min,s=n.max;if(S&&M.set(e,r),c<=s){const t=r.getCount();S?(e>=a-w&&wl(r.runs(N),(t,r)=>{const n=r.min,o=r.max;let s=t;n-1<=h&&o>h&&(s=s.slice(0,h+1-n)),n<c&&o+1>=c&&(s=s.slice(c-n)),T.push({majorIndex:e+w,minorIndex:Math.max(n,c),run:s})}),r.delete(c,h-c+1)):r.shift(c,w);const n=r.getCount();if(0===n)R.add(e),v=Math.min(v,s),I=Math.max(I,o);else{const t=r.getCoords();if(v=Math.min(v,t.min),I=Math.max(I,t.max),I>A)throw new Mt}y+=n-t,C.push([e,r])}k=F.next()}const O=this._optionsMinor;let B=!1;for(let t=0;t<T.length;t++){const e=T[t],r=e.majorIndex,n=e.run;let o=M.get(r);o||(o=new Ol(O),M.set(r,o),C.push([r,o]),B=!0),o.setRunAt(e.minorIndex,n),y+=n.length,b=Math.min(b,r),E=Math.max(E,r),R&&R.delete(r)}if(this._updateMajorSpan(C,B),R&&R.size>0){const t=Array.from(R.values()),e=na(t);for(let t=0;t<e.length;t++){const r=e[t];x.delete(r.min,r.max-r.min+1)}const r=x.getCoords();if(!r)return this.clear(),!0;b=r.min,E=r.max}if(I!==m||v!==p)return this._count+=y,this._dataCoords=null,!0;{const t=this._count+y;this._count=t,this._dataCoords=0===t?null:Object.freeze({colStart:r?b:v,rowStart:r?v:b,colEnd:r?E:I,rowEnd:r?I:E})}return 0!==y||!U.isEqualRanges(d,this.getCoords())}getCount(){return this._count}getValueAt(t,e){const r=this._isColumn,n=r?e:t,o=r?t:e,s=this._lastMajor;let i;if(s===n&&s!==Number.MIN_SAFE_INTEGER?i=this._lastMinorSpan:(i=this._major.at(n),this._lastMajor=n,this._lastMinorSpan=i),!i)return;return i.at(o)}setValueAt(t,e,r){const n=this._isColumn,o=[n?e:t,[[n?t:e,[r]]]];this.setValues([o])}copyTo(t,e,r){if(0===this.getCount())return;const n=this.getOrientation(),o=t.getOrientation(),s=this.getRuns({bounds:r});let i=s.next();const a=U.cellToRange(e);a.colEnd=r.colEnd-r.colStart+e.colIndex,a.rowEnd=r.rowEnd-r.rowStart+e.rowIndex;const l=this._isColumn,c=this._maxCoords,h=this.getCoords();let d,u=Rc(r.colStart??Number.MIN_SAFE_INTEGER,r.rowStart??Number.MIN_SAFE_INTEGER,r.colEnd??Number.MAX_SAFE_INTEGER,r.rowEnd??Number.MAX_SAFE_INTEGER,l,c,h);u={...u};const g=o!==E.Row,p=t.getMaxCoords();d=Rc(a?.colStart??Number.MIN_SAFE_INTEGER,a?.rowStart??Number.MIN_SAFE_INTEGER,a?.colEnd??Number.MAX_SAFE_INTEGER,a?.rowEnd??Number.MAX_SAFE_INTEGER,g,p),d={...d};const m=d.majorStart-u.majorStart,f=d.minorStart-u.minorStart,_=n===o?new exports.Tuple.Builder:new exports.Tuple.TransposedBuilder;for(;!i.done;){const t=i.value[0];let e=i.value[1],r=i.value[2];e+r.length>u.minorEnd&&(r=r.slice(0,u.minorEnd-e+1)),e<u.minorStart&&(r=r.slice(u.minorStart-e),e=u.minorStart),_.addValues(t+m,e+f,r),i=s.next()}const S=_.build();t.delete(a),S&&t.setValues(S.tuples)}getCoords(){if(this._dataCoords)return this._dataCoords;if(0===this._major.getCount())return null;let t=Number.MAX_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER,n=Number.MIN_SAFE_INTEGER;const o=this._major.entries();let s=o.next();for(;!s.done;){const i=s.value,a=i[0];t=Math.min(a,t),e=Math.max(a,e);const l=i[1].getCoords();r=Math.min(l.min,r),n=Math.max(l.max,n),s=o.next()}const i=this._isColumn,a=Object.freeze({colStart:i?t:r,rowStart:i?r:t,colEnd:i?e:n,rowEnd:i?n:e});return this._dataCoords=a,a}clone(t){this._isShared=!0;const e=new Vc(this._options);return e._isShared=!0,e._major=this._major.clone(),e._dataCoords=this._dataCoords,e._count=this._count,e}cloneEmpty(t){return new Vc(this._options)}getMaxCoords(){const t=this._maxCoords;return t||null}get[Symbol.toStringTag](){let t="";const e=this.getCoords();if(e){const r=e.colEnd-e.colStart+1,n=e.rowEnd-e.rowStart+1;t=`${this.getCount()}-${this._isColumn?r:n}x${this._isColumn?n:r}`}return`[SparseGrid:${t}]`}}Vc||(Vc={});const $c=12;Object.seal({done:!1,value:null});const Uc=[-1,-1,null],Gc=Object.seal({done:!1,value:[-1,null]}),Wc=Object.seal({done:!1,value:[-1,null]}),qc={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:Gc},Jc={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:Wc},Xc=()=>({majorIndex:-1,minorIndex:-1,value:null,active:!1,nextMinorIndex:-1,nextActive:!1,nextMinorValue:null,minorIterator:null,nextMajorCursor:null,prevMajorCursor:null});class Kc{constructor(t){if(this._l=0,this._at=null,this._dt=gh.Undefined,this._a32=null,this._a64=null,this._cv=null,this._vt=null,this._vi32=null,this._vi64=null,this._vf32=null,this._vf64=null,!t)throw new Error("options is required");const e=t.length;if(this._l=e,this._dt=t.type,this._cv=t.getCoercedValue??null,e>0){t.types&&(this._at=t.types,this._vt=new Uint8Array(this._at));const e=t.values32??null;e&&(this._a32=e,this._vi32=new Int32Array(e),this._vf32=new Float32Array(e));const r=t.values64??null;if(r&&(this._a64=r,this._vf64=new Float64Array(r),this._vi64=new BigInt64Array(r)),!e&&!r)throw new Error("values32 or values64 is required")}}getConstructorOptions(){return{length:this._l,type:this._dt,types:this._at,values32:this._a32,values64:this._a64,getCoercedValue:this._cv}}at(t){if(t>>>0>=this._l)return;const e=this._vt,r=e&&e[t]||this._dt;let n,o=!1;switch(this._vi32?n=this._vi32[t]:(o=!0,n=Number(this._vi64[t])),r){case Zc:return o?Number(n):n;case Qc:return o?this._vf64[t]:this._vf32[t];case th:return!!n;case nh:case oh:return this._cv(r,o?Number(n):n);case eh:return this._vi64[o?t:n];case rh:return this._vf64[o?t:n];case ah:return Number.NaN;case lh:return Number.MAX_SAFE_INTEGER;case ch:return Number.MIN_SAFE_INTEGER;case sh:return 1/0;case ih:return-1/0;case hh:return null;case dh:case uh:return}return this._cv(r,o?Number(n):n)}toArray(t){const e=[],r=Math.max(t,this._l);for(let t=0;t<r;t++)e.push(this.at(t));return e}get length(){return this._l}get[Symbol.toStringTag](){return"[MixTypedArrayList]"}toString(){const t=this._a32,e=this._a64;let r="";t&&!e?r="32":e&&!t&&(r="64");return`{${r}${this._at?"":":SINGLE_TYPE"}}:${this._l}}`}static _createArrayBuffer(t){try{return new SharedArrayBuffer(t)}catch(t){}return new ArrayBuffer(t)}static fromArray(t,e,r,n,o=Yc){const s=t.length;if(0===s)return new Kc({type:gh.Undefined,length:s,getCoercedValue:r});let i=this._createArrayBuffer(s*Int8Array.BYTES_PER_ELEMENT),a=new Uint8Array(i),l=0,c=!1,h=ph(t[0],n);for(let e=0;e<s;e++){const r=t[e],o=ph(r,n);o!==rh&&o!==eh||l++,h!==o&&(a[e]=o,c=!0)}c||(a=null,i=null);let d,u,g,p,m,f,_,S,w=!1;l/s>o&&(w=!0,l=s),0!==l&&(g=this._createArrayBuffer(l*BigInt64Array.BYTES_PER_ELEMENT),p=new BigInt64Array(g),m=new Float64Array(g)),w?(d=p,u=m):(f=this._createArrayBuffer(s*Int32Array.BYTES_PER_ELEMENT),_=new Int32Array(f),S=new Float32Array(f),d=_,u=S);let y=h;if(w)for(let r=0;r<s;r++){const n=t[r];switch(a&&(y=a[r]||h),y){case Zc:d[r]=BigInt(n);break;case th:d[r]=BigInt(n?1:0);break;case Qc:u[r]=n;break;case eh:d[r]=n;break;case rh:u[r]=n;break;case nh:case oh:d[r]=BigInt(e?.(y,n)??0);break;default:y>127&&y<255&&(d[r]=BigInt(e?.(y,n)??0))}}else{let r=0;for(let n=0;n<s;n++){const o=t[n];switch(a&&(y=a[n]||h),y){case Zc:d[n]=o;break;case th:d[n]=o?1:0;break;case Qc:u[n]=o;break;case eh:_[n]=r,p[r]=o,r++;break;case rh:_[n]=r,m[r]=o,r++;break;case nh:case oh:d[n]=e?.(y,o)??0;break;default:y>127&&y<255&&(d[n]=e?.(y,o)??0)}}}return new Kc({length:s,types:c?i:null,type:h,values32:f,values64:g,getCoercedValue:r})}}const Yc=.1,Zc=1,Qc=2,th=3,eh=4,rh=5,nh=6,oh=7,sh=8,ih=9,ah=10,lh=11,ch=12,hh=13,dh=14,uh=127,gh={Undefined:dh},ph=(t,e)=>{switch(typeof t){case"number":const r=t;if(Number.isNaN(r))return ah;if(r===1/0)return sh;if(r===-1/0)return ih;if(Object.is(r,-0))return Qc;if(r===Number.MAX_SAFE_INTEGER)return lh;if(r===Number.MIN_SAFE_INTEGER)return ch;if(Number.isInteger(r)&&r<=2147483647&&r>=-2147483648)return Zc;return Math.fround(r)===r?Qc:rh;case"string":return nh;case"boolean":return th;case"object":if(null===t)return hh;if(t instanceof Error)return oh;if(!e)return uh;const n=e(t);if(n<128||n>255)throw new Error("Custom type must be between 128 and 255");return n;case"bigint":return eh;case"undefined":return dh;case"symbol":case"function":return uh}return uh},mh=t=>{if(!t||t.length<=1)return!1;if(2===t.length)return U.isRangesIntersect(t[0],t[1]);const e=new gc;e.load(t);for(let r=0;r<t.length;r++){if(e.search(t[r]).length>1)return!0}return!1},fh=(t,e,r)=>{const n=[];if(U.isRangesIntersect(t,e)){const o=mt.subtractRect({top:t.rowStart,left:t.colStart,bottom:t.rowEnd+1,right:t.colEnd+1},{top:e.rowStart,left:e.colStart,bottom:e.rowEnd+1,right:e.colEnd+1},r===E.Column);for(let t=0;t<o.length;t++){const e={colStart:o[t].left,rowStart:o[t].top,colEnd:o[t].right-1,rowEnd:o[t].bottom-1};n.push(e)}}else n.push(t);return n},_h=(t,e,r)=>{if(e&&t?.[0])for(let n=0;n<t.length;n++){const o=t[n];U.intersectRanges(o,e)&&r(o,!U.isRangeWithinRange(o,e),n)}},Sh=(t,e)=>{const r=t.colStart,n=t.rowStart,o=e.colStart,s=e.rowStart;return(t,e)=>{const i=t.colIndex-r,a=e.colIndex-o;if(i===a){return t.rowIndex-n-(e.rowIndex-s)}return i-a}},wh=(t,e)=>{const r=t.colStart,n=t.rowStart,o=e.colStart,s=e.rowStart;return(t,e)=>{const i=t.rowIndex-n,a=e.rowIndex-s;if(i===a){return t.colIndex-r-(e.colIndex-o)}return i-a}},yh=(t,e,r=!1,n=!1)=>{let o=e.colEnd-e.colStart+1,s=e.rowEnd-e.rowStart+1;if(n){const t=o;o=s,s=t}const i={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart+o-1,rowEnd:t.rowStart+s-1};if(r){let e=t.colStart,r=t.rowStart;return U.isSingleCell(t)?(e+=o-1,r+=s-1):(e+=t.colEnd-t.colStart,r+=t.rowEnd-t.rowStart),i.colEnd=n?r:e,i.rowEnd=n?e:r,i}const a=t.colEnd-t.colStart+1;if(a%o!==0)return i;const l=t.rowEnd-t.rowStart+1;return l%s!==0||(i.colEnd=t.colStart+a-1,i.rowEnd=t.rowStart+l-1),i};class xh{constructor(t,e){this._l=0,t&&e>0&&(this._u=t,this._l=e)}at(t){if(t>this._l||t<0||!this._u)return;const e=Math.floor(t%this._u.length);return this._u.at(e)}toArray(t){const e=[],r=this._u,n=r.length;for(let o=0;o<t;o++){const t=Math.floor(o%n);e.push(r.at(t))}return e}get length(){return this._l}get[Symbol.toStringTag](){return"[RepeatingList]"}get isIList(){return!0}}class Ch{constructor(t,e,r=null,n=!1){this._isLiteral=!1,this._values=t,this._coords=e,this._type=r,this._isLiteral=n}getValueAt(t,e,r){const n=this._coords;if(!n)return;let o=this._values.getValueAt(t+n.rowStart,e+n.colStart)??null;void 0===o&&(o=null);const s=r?.type,i=void 0!==s?s:this._type;return i&&(o=Nh(o,Rh(o,!0),i)),o}_applyBuilder(t,e,r=!1){if(!e)return t;const n=e.build();return n?(r&&(t=t.clone()),t.setValues(n.tuples),t):t}_cloneFromBuilder(t,e,r,n){if(!t)return this;const o=t.build();if(!o)return this;let s=this._values;const i=s.getOrientation(),a=(e?.orientation??i)===exports.t.Orientation.Column,l=Mc(o.bounds,a),c=this._coords??U.EmptyRange,h=Math.max(l.colEnd-l.colStart+1,r??c.colEnd-c.colStart+1),d=Math.max(l.rowEnd-l.rowStart+1,n??c.rowEnd-c.rowStart+1),u=c.colStart,g=c.rowStart,p=u+h-1,m=g+d-1;return s=s.clone(),s.setValues(o.tuples),new Ch(s,{colStart:u,rowStart:g,colEnd:p,rowEnd:m},this._type,this._isLiteral)}forEach(t,e){if(!t)return;const r=this.entries(e);let n=r.next();for(;!n.done;){const e=n.value,o=t(e.value,e.coords,this);if(o)return o.break;n=r.next()}}reduce(t,e,r){if(!t)return e;const n=this.entries(r);let o=n.next(),s=e;for(;!o.done;){const e=o.value;s=t(s,e.value,e.coords,this),o=n.next()}return s}some(t,e){if(!t)return!1;const r=this.entries(e);let n=r.next();for(;!n.done;){const e=n.value;if(t(e.value,e.coords,this))return!0;n=r.next()}return!1}every(t,e){if(!t)return!0;const r=this.entries(e);let n=r.next();for(;!n.done;){const e=n.value;if(!t(e.value,e.coords,this))return!1;n=r.next()}return!0}replace(t,e){let r;if(r=t?.isIRange?t:Dh(t,this._values,this._coords,this._type),0===this.size)return r;if(0===r.size)return this;const n=this._values.clone(),o=r._values,s=r._coords??U.EmptyRange,i=this._coords??U.EmptyRange,a=i.colStart,l=i.rowStart,c=a+(e.colIndex??0),h=l+(e.rowIndex??0);o.copyTo(n,{colIndex:c,rowIndex:h},s);const d=Math.max(this.getWidth(),r.getWidth()+(e?.colIndex??0)),u=Math.max(this.getHeight(),r.getHeight()+(e?.rowIndex??0));return new Ch(n,{colStart:a,rowStart:l,colEnd:a+d-1,rowEnd:l+ +u-1},this._type)}slice(t){if(!t)return this;const e=this._coords??U.EmptyRange,r=(t.colStart??0)+e.colStart,n=(t.rowStart??0)+e.rowStart,o={colStart:r,rowStart:n,colEnd:(t.colEnd??e.colEnd-r)+e.colStart,rowEnd:(t.rowEnd??e.rowEnd-n)+e.rowStart},s=U.intersectRanges(e,o);return new Ch(this._values,s,this._type)}resize(t,e,r=null){if(t<0||e<0)throw new Error(`Invalid resize dimensions: ${t} x ${e}`);const n=this._coords??U.EmptyRange,o=n.colEnd-n.colStart+1,s=n.rowEnd-n.rowStart+1;if(t===o&&e===s)return this;const i={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colStart+t-1,rowEnd:n.rowStart+e-1};let a=this._values;return(t>o||e>s)&&(a=a.clone(),t>o&&(bh.colStart=n.colEnd+1,bh.rowStart=n.rowStart,bh.colEnd=n.colEnd,bh.rowEnd=n.rowEnd,this._fill(a,n,r)),e>s&&(bh.colStart=n.colStart,bh.rowStart=n.rowEnd+1,bh.colEnd=n.colEnd,bh.rowEnd=n.rowEnd,this._fill(a,n,r))),new Ch(a,i,this._type)}_mergeIterators(t,e,r){const n=this._coords??U.EmptyRange,o=t._coords??U.EmptyRange,s=this._values.getOrientation(),i=r?.orientation??s,a=i!==exports.t.Orientation.Row,l=this._entries(r),c=this._entries(r),h=n.colStart,d=n.rowStart,u=h-o.colStart,g=d-o.rowStart,p=i===s?new exports.Tuple.Builder:new exports.Tuple.TransposedBuilder,m=new Oc({...r,bounds:n,comparator:(a?Sh:wh)(n,o)},l,c);let f=m.next();for(;!f.done;){const t=f.value;let r=t[1],n=t[3];const o=t[0],s=t[2],i=o?o.colIndex:s.colIndex+u,l=o?o.rowIndex:s.rowIndex+g,c=e(r,n,{colIndex:i-h,rowIndex:l-d},this),_=a?i:l,S=a?l:i;p.addValue(_,S,c),f=m.next()}return p}intersect(t,e,r){if(!t)throw new Error("Invalid range to intersect");const n=t,o=this._coords??null,s=n._coords??null;if(!U.intersectRanges(o,s))return new Ch(this._values,null,this._type);const i=this._mergeIterators(n,e,r);return this._cloneFromBuilder(i,r)}startIncrementalUpdates(t){const e=t?.orientation??exports.t.Orientation.Column,r=this._values.getOrientation(),n=(t?.orientation??r)!==exports.t.Orientation.Row,o=e===r?new exports.Tuple.Builder:new exports.Tuple.TransposedBuilder,s=this,i=this._coords??U.EmptyRange,a=i.colStart,l=i.rowStart,c=n?a:l,h=n?l:a,d={pushAt(t,e,r){const s=n?e:t,i=n?t:e;return o.addValue(s+c,i+h,r),d},pushMultipleAt(t,e,r){const s=n?e:t,i=n?t:e;return o.addValues(s+c,i+h,r),d},apply(){const e=o.build();return e?(e.bounds.majorStart=c,e.bounds.minorStart=h,s._cloneFromBuilder(o,t)):null}};return d}map(t,e){const r=this._values;if(!this._coords||0===r.getCount())return this;const n=r.getOrientation(),o=e?.orientation??n;let s;const i=this.entries(e);let a=i.next();a.done||(s=this._createTupleBuilder(o));const l=o===exports.t.Orientation.Column;for(;!a.done;){const e=a.value,r=e.coords,n=t(e.value,r,this),o=l?r.colIndex:r.rowIndex,c=l?r.rowIndex:r.colIndex;s.addValue(o,c,n),a=i.next()}return this._cloneFromBuilder(s,e)}filter(t,e){const r=this._values;if(!this._coords||0===r.getCount())return this;const n=r.getOrientation(),o=e?.orientation??n,s=this._createTupleBuilder(o),i=this.entries(e);let a=i.next();const l=o===exports.t.Orientation.Column;for(;!a.done;){const e=a.value,r=e.coords,n=e.value;if(t(n,r,this)){const t=l?r.colIndex:r.rowIndex,e=l?r.rowIndex:r.colIndex;s.addValue(t,e,n)}a=i.next()}return this._cloneFromBuilder(s,e)}broadcast(e,r,n){let o=this._coords;if(null==e)return this;let s=n?.type,i=n?.otherType??s;const a=s?Nh(null,t.Null,s):null,l=i?Nh(null,t.Null,i):null;let c;if(e.isIRange)c=e;else{const t=this._values.clone();t.setValueAt(0,0,e),c=new Ch(t,U.EmptyRange,Rh(e,!0))}const h=c,d=this.getWidth(),u=this.getHeight(),g=h.getWidth(),p=h.getHeight();let m=Math.min(d,g),f=Math.min(u,p),_=Math.max(d,g),S=Math.max(u,p);const w=n?.mismatchFill;let y=!1;if(d!==g)if(1===d)m=g;else if(1===g)m=d;else{if(!w)throw new Error(`Incompatible shapes for broadcast: width dimensions ${d} and ${g} must be equal or one must be 1`);y=!0}if(u!==p)if(1===u)f=p;else if(1===p)f=u;else{if(!w)throw new Error(`Incompatible shapes for broadcast: height dimensions ${u} and ${p} must be equal or one must be 1`);y=!0}const x=this._values.getOrientation(),C=x,b=C===exports.t.Orientation.Column;o=o??U.EmptyRange;let E,v,I=h._coords??U.EmptyRange;if(y&&(o={colStart:o.colStart,rowStart:o.rowStart,colEnd:o.colStart+m-1,rowEnd:o.rowStart+m-1},I={colStart:I.colStart,rowStart:I.rowStart,colEnd:I.colStart+m-1,rowEnd:I.rowStart+m-1}),1===d&&d<g||1===u&&u<p){const t={...o};1===d&&(t.colEnd=t.colStart),1===u&&(t.rowEnd=t.rowStart),E=new kc({delegate:this._entries({...n,orientation:C,bounds:t,reuseResult:!1}),bounds:t,orientation:C,dims:{major:b?m:f,minor:b?f:m}})}else E=this._entries({...n,orientation:C,bounds:o,reuseResult:!1});if(1===g&&g<d||1===p&&p<u){const t={...I};1===g&&(t.colEnd=t.colStart),1===p&&(t.rowEnd=t.rowStart),v=new kc({delegate:h._entries({...n,type:i??null,orientation:C,bounds:t,reuseResult:!1}),bounds:t,orientation:C,dims:{major:b?m:f,minor:b?f:m}})}else v=h._entries({...n,type:i??null,orientation:C,bounds:I,reuseResult:!1});const A=o.colStart,R=o.rowStart,M=A-I.colStart,T=R-I.rowStart,F=C===x?new exports.Tuple.Builder:new exports.Tuple.TransposedBuilder,N=new Oc({...n,bounds:o,comparator:(b?Sh:wh)(o,I)},E,v);let k,O=N.next();for(;!O.done;){const t=O.value;let e=t[1],n=t[3];const o=t[0],s=t[2],i=o?o.colIndex:s.colIndex+M,c=o?o.rowIndex:s.rowIndex+T;let h,d;e instanceof exports.n.Value?h=e:n instanceof exports.n.Value&&(h=n),d=h||r(e??a,n??l,{colIndex:i-A,rowIndex:c-R},this);const u=b?i:c,g=b?c:i;F.addValue(u,g,d),O=N.next()}if(w&&_>m||S>f){const t=this._values.clone();if(this._applyBuilder(t,F),_>m){const e=Rc(A+m,R,A+_-1,R+S-1,b),r=Lc(w,e,b);t.setValues(r.tuples)}if(S>f){const e=Rc(A,R+f,A+_-1,R+S-1,b),r=Lc(w,e,b);t.setValues(r.tuples)}k=new Ch(t,{colStart:A,rowStart:R,colEnd:A+_-1,rowEnd:R+S-1},this._type)}else k=this._cloneFromBuilder(F,n,_,S);return k}_fill(t,e,r){if(null===r)return void t.delete(e);const n=t.getOrientation()===exports.t.Orientation.Column,o=Rc(e.colStart,e.rowStart,e.colEnd,e.rowEnd,n),s=Lc(r,o,n);t.setValues(s.tuples)}_validateCoords(t){}fill(t,e){let r=this._coords;if(!r&&!e)return this;r=r??U.EmptyRange,e&&(bh.colStart=(e.colStart??0)+r.colStart,bh.rowStart=(e.rowStart??0)+r.rowStart,bh.colEnd=(e.colEnd??r.colEnd-r.colStart)+r.colStart,bh.rowEnd=(e.rowEnd??r.rowEnd-r.rowStart)+r.rowStart),this._validateCoords(bh);const n=this._values.clone();return this._fill(n,bh,t),(bh.rowEnd>r.rowEnd||bh.colEnd>r.colEnd)&&(r={colStart:r.colStart,rowStart:r.rowStart,colEnd:Math.max(r.colEnd,bh.colEnd),rowEnd:Math.max(r.rowEnd,bh.rowEnd)}),new Ch(n,r,this._type)}empty(){const t=this._values.cloneEmpty();return new Ch(t,null,this._type)}flatten(t){const e=[],r=this.values(t);let n=r.next();for(;!n.done;)e.push(n.value),n=r.next();return e}fillEmpty(t,e=1,r=1){const n=this._coords;if(!n)return this;const o=this._values;if(e<1&&r<1)throw new Error("Must be at least size of 1");const s=o.getOrientation(),i=s,a=i===exports.t.Orientation.Column,l=Math.max(this.getWidth(),e),c=Math.max(this.getHeight(),r),h=a?n.colStart:n.rowStart,d=a?n.rowStart:n.colStart,u=a?n.colStart+l-1:n.rowStart+c-1,g=a?n.rowStart+c-1:n.colStart+l-1,p=o.getRuns({bounds:{colStart:n.colStart,rowStart:n.rowStart,colEnd:a?u:g,rowEnd:a?g:u},overflowRun:!0});let m=p.next(),f=h,_=d;const S=i===s?new exports.Tuple.Builder:new exports.Tuple.TransposedBuilder;for(;!m.done;){const e=m.value,r=e[0];for(;f<r;){const e=new xh([t],g+1-_);S.addValues(f,_,e),f++,_=d}const n=e[1],o=Math.max(n,d),s=e[2],i=Math.min(n+s.length-1,g);if(_<o){const e=new xh([t],n-_);S.addValues(f,_,e)}_=i+1,i>=g?(f=r+1,_=d):f=r,m=p.next()}for(;f<=u;){const e=new xh([t],g+1-_);S.addValues(f,_,e),f++,_=d}return this._cloneFromBuilder(S,void 0,l,c)}transpose(){if(this.size<=1)return this;const t=this._values.getOrientation(),e=this._coords,r=this.getWidth(),n=this.getHeight(),o=this._entries({orientation:t===exports.t.Orientation.Column?exports.t.Orientation.Row:exports.t.Orientation.Column,bounds:e,reuseResult:!0}),s=t===exports.t.Orientation.Column,i=new exports.Tuple.Builder,a=s?e.colStart:e.rowStart,l=s?e.rowStart:e.colStart;let c=o.next();for(;!c.done;){const t=c.value,e=t[0],r=s?e.colIndex:e.rowIndex-a,n=(s?e.rowIndex:e.colIndex-l)+a,h=r+l,d=t[1];i.addValue(n,h,d),c=o.next()}return this._cloneFromBuilder(i,void 0,n,r)}values(t){const e=this.entries(t);return{[Symbol.iterator](){return this},next(){const t=e.next();return t.done?Cl:{done:!1,value:t.value.value}}}}_createTupleBuilder(t){const e=this._coords,r=this._values.getOrientation(),n=t??r,o=n!==exports.t.Orientation.Row,s=o?e.colStart:e.rowStart,i=o?e.rowStart:e.colStart;return n===r?new exports.Tuple.Builder(null,s,i):new exports.Tuple.TransposedBuilder(null,s,i)}entries(t){const e=this._coords;if(!e)return bl;const r=t?.bounds;if(t={...t,bounds:e},r){const n=(r.colStart??0)-e.colStart,o=(r.rowStart??0)-e.rowStart,s=Math.max(n+e.colStart,e.colStart),i=Math.max(o+e.rowStart,e.rowStart),a=Math.min((r.colEnd??Number.MAX_SAFE_INTEGER)-n,e.colEnd-e.colStart)+1,l=Math.min((r.rowEnd??Number.MAX_SAFE_INTEGER)-o,e.rowEnd-e.rowStart)+1;t.bounds={colStart:s,rowStart:i,colEnd:s+a-1,rowEnd:i+l-1}}const n=this._entries(t),o={[Symbol.iterator]:()=>o,next(){for(;;){let t=n.next();if(t.done)return Cl;const r=t.value,o=r[0];return{done:!1,value:{coords:{colIndex:o.colIndex-e.colStart,rowIndex:o.rowIndex-e.rowStart},value:r[1]}}}}};return o}_entries(e){if(!this._coords)return bl;let r=this._values.entries(e);const n=e?.type??this._type;let o=null;if(e?.includeEmpty&&(r=new Nc(r,e),n&&(o=Nh(null,t.Null,n))),n){const t=r,s=e.coerce??!1,i=e.includeBoolean??!1,a=e.includeMistyped??!1;r={[Symbol.iterator]:()=>r,next(){for(;;){let e=t.next();if(e.done)return Cl;const r=e.value,l=r[1];let c=l;if(null==c)c=o;else if(n&&(s||!a)){let t=Rh(c,!0),e=t!==n;if(e&&(s&&(c=Nh(c,t,n,i),e=c?.isFormulaError),e&&!a))continue}return c===l?e:{done:!1,value:[r[0],c]}}}}}return r}getValues(t){if(!this._coords)return[[]];const e={...t,includeEmpty:!0,reverse:!1,bounds:{colStart:0,rowStart:0,colEnd:this.getWidth()-1,rowEnd:this.getHeight()-1}};let r=!1;e.orientation=t?.orientation??exports.t.Orientation.Row,t&&(t.maxHeight&&(e.bounds.rowEnd=0+t.maxHeight-1),t.maxWidth&&(e.bounds.colEnd=0+t.maxWidth-1),t.trailingEmpties&&(r=t.trailingEmpties),e.orientation=t?.orientation??exports.t.Orientation.Row);const n=[];if(!r){e.includeEmpty=!1,e.reverse=!0;const t=this.entries(e).next();if(t.done)return Eh;const r=t.value.coords;e.bounds.colEnd=r.colIndex,e.bounds.rowEnd=r.rowIndex,e.includeEmpty=!0,e.reverse=!1}const o=this.entries(e),s=e.orientation!==exports.t.Orientation.Row,i=t?.onValue;let a,l=-1,c=[];for(a=o.next();!a.done;){const t=a.value,e=t.coords,r=s?e.colIndex:e.rowIndex;r!==l&&(c=[],n.push(c),l=r);let h=t.value;if(i){const t=i(h,e.rowIndex,e.colIndex,this);void 0!==t&&(h=t)}c.push(h),a=o.next()}return n}toType(t){return new Ch(this._values,this._coords,t,this._isLiteral)}getWidth(){const t=this._coords;return t?t.colEnd-t.colStart+1:0}getHeight(){const t=this._coords;return t?t.rowEnd-t.rowStart+1:0}get size(){const t=this._coords;return t?(t.colEnd-t.colStart+1)*(t.rowEnd-t.rowStart+1):0}isLiteral(){return this._isLiteral}getScalarType(){return this._type}[Symbol.iterator](){const t=this.entries();return{next(){const e=t.next();return e.done?Cl:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}get[Symbol.toStringTag](){return"[Range]"}toString(){const t=this._coords,e=t?`${t.colEnd-t.colStart+1}x${t.rowEnd-t.rowStart+1}`:exports.n.Ref.toString();let r="{";const n=this.entries({includeEmpty:!0,orientation:exports.t.Orientation.Row});let o=n.next(),s=0,i=o.value?.coords.rowIndex??0;for(;!o.done&&s<10;){const t=o.value;t.coords.rowIndex>i?(r+=";",i=t.coords.rowIndex):s>0&&(r+=","),s++;let e=t.value;"string"==typeof e?e=`"${e}"`:"boolean"==typeof e&&(e=e?"TRUE":"FALSE"),r+=e,o=n.next()}return o.done?r+="}":r+="...",`[${e}:${r}]`}get isIRange(){return!0}}const bh={colStart:Number.MIN_SAFE_INTEGER,rowStart:Number.MIN_SAFE_INTEGER,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER},Eh=Object.freeze([Object.freeze([null])]),vh=Object.freeze({colStart:0,rowStart:0,colEnd:Math.pow(2,14)-1,rowEnd:Math.pow(2,20)-1}),Ih=Object.freeze({colIndex:0,rowIndex:0}),Ah=()=>vh,Rh=(e,r=!1)=>"number"==typeof e?isNaN(e)||e===1/0||e===-1/0?t.Error:t.Number:"string"==typeof e?t.String:"boolean"==typeof e?t.Boolean:e?.isFormulaError?t.Error:null===e?t.Null:mt.isObject(e)&&e.hasOwnProperty("type")&&"string"==typeof e.type?t.RichData:r&&ls(e)?"Date":void 0===e?(console.warn("undefined"),t.Null):null,Mh=new Map([[t.Null,"any"],[t.Number,"number"],[t.String,"string"],[t.Boolean,"boolean"],[t.Error,"FormulaError"],[t.RichData,"richData"],["*","Scalar"]]),Th=new Map([["p","IReferenceRange"],["r","IRange"]]),Fh={orientation:exports.t.Orientation.Row},Nh=(e,r,n=t.Number,o=!1,s=!1)=>{if(r===n||!n)return r===t.Number&&(e=Lh(e,null,"number")),e;if(n===t.Number){switch(r){case t.Null:return 0;case t.String:let r=0;try{const t=wm(e);r=t&&"number"==typeof t.value?t.value:Number.NaN}catch(t){}return!Number.isFinite(r)||Math.abs(r)>999e305?exports.n.BuiltIn.Value:r;case t.Boolean:return o?e?1:0:exports.n.BuiltIn.Value;case"Date":return ms(e,s)??exports.n.BuiltIn.Value;case t.Error:return e}return e.toString()}if(n===t.String){switch(r){case t.Null:return"";case t.Number:return e.toString();case t.Boolean:return e?"TRUE":"FALSE";case t.Error:return e}return e}if(n===t.Boolean){switch(r){case t.Null:return 0;case t.Number:return!!e;case t.String:let r=e.trim().toUpperCase();return"TRUE"===r||"FALSE"!==r&&exports.n.BuiltIn.Value;case t.Error:return e}return exports.n.BuiltIn.Value}if("Date"===n){switch(r){case t.Number:return ps(e,s)??exports.n.BuiltIn.Value;case t.String:try{const t=As(e,s);if(t)return t.asJSDate??exports.n.BuiltIn.Value}catch(t){}return e;case t.Error:return e}return exports.n.BuiltIn.Value}return exports.n.BuiltIn.Value},kh=t=>{let e=t;for(;Array.isArray(e);){if(e.length>1)return!1;e=e[0]}return!e||(!e.isIRange||1===e.size)},Oh=(t,e,r,n,o,s=!1)=>{if(Array.isArray(r)){const i=r.length;for(let a=0;a<i;a++){let i=r[a];if(Array.isArray(i)){const r=Oh(t,e,i,n,o,s);if(s)continue;if(r instanceof exports.n.Value)return r}else{if(n){if(i=Nh(i,Rh(i,!0),n,s),s)continue;if(i instanceof exports.n.Value)return i}e.push(i)}}return}if(r&&void 0!==r.colStart){let e=t.getReference?.(r);n&&(e=e.toType(n)),r=e}if(r?.isIRange){return((t,e)=>{let r=t.next();for(;!r.done;){let n=r.value;if(n instanceof exports.n.Value)return n;e.push(n),r=t.next()}})(r.values({type:n,coerce:!0,includeMistyped:!s,...Fh}),e)}if(n){if(r=Nh(r,Rh(r,!0),n,null!==o),s)return;if(r instanceof exports.n.Value)return r}e.push(r)},Bh=(e,r,n,o,s,i)=>{if("r"===s){let t=n;return t&&t.isIReferenceRange?(o&&(t=t.toType(o)),void r.push(n)):new exports.n.Value("Cannot convert a literal to a reference.")}let a=n?.isIRange?n:null;if("l"!==s){if(a){const t=a.getValues({type:o});return void r.push(t)}{Array.isArray(n)||(n=[n]);const t=n.length,e=new Array(t);for(let r=0;r<t;r++){let t=n[r];Array.isArray(t)||(t=[t]);const s=t.length,i=new Array(s);for(let e=0;e<s;e++){let r=t[e];if(o&&(r=Nh(r,Rh(r,!0),o)),r instanceof exports.n.Value)return r;i[e]=r}e[r]=i}r.push(e)}}else{if(a)o&&a.getScalarType()!==o&&(a=a.toType(o));else try{if(!i&&(n=Lh(n),o&&(n=Nh(n,Rh(n,!0),o,!0),n?.isFormulaError&&o!==t.Error)))return r.push(n),n;a=e.getRange(n),o&&(a=a.toType(o))}catch(t){return t}r.push(a)}},Lh=(t,e,r=typeof t)=>{if("number"===r)return isNaN(t)?exports.n.BuiltIn.Num:isFinite(t)?t+=0:exports.n.BuiltIn.Div0;if(null==t)return null;if(!e)return t;if(Array.isArray(t))try{t=e.getRange(t)}catch(t){return exports.n.BuiltIn.Value}return e.isValidDate(t)?(e.formatResults("Short Date"),e.toOADate(t)):t},Dh=(t,e,r,n)=>{let o;o=Array.isArray(t)?Array.isArray(t[0])?t:[t]:[[t]],e||(e=new Vc({orientation:exports.t.Orientation.Column}));const s=e.getOrientation()===exports.t.Orientation.Column,i=Dc(o,s,Rc(r?.colStart??0,r?.rowStart??0,void 0,void 0,s),!0),a=Mc(i.bounds,s);e.setValues(i.tuples);return new Ch(e,a,n,!r)},zh=new RegExp(/^([$]?[a-zA-Z]*[$]?[0-9]*)[:]?([$]?[a-zA-Z]*[$]?[0-9]*)?$/),Ph=new RegExp(/^(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?)(:(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?))?$/,"i"),jh=new RegExp(/^(R?)(\[?[-+]?\d+\]?|\d+)?(C?)(\[?[-+]?\d+\]?|\d+)?$/,"i"),Hh=new RegExp("(?:'[^']+'|[A-Za-z0-9_\\-.]+?!)?(\\$?[A-Za-z]+\\$?\\d+(?::\\$?[A-Za-z]+\\$?\\d+)?|\\$?[A-Za-z]+:\\$?[A-Za-z]+|\\$?\\d+:\\$?\\d+)","g"),Vh=/\s+/g,$h=/"(?:[^"]|"")*"|\[[^[\]]+\]/g,Uh=/[\uE000-\uF8FF]/g,Gh="#REF!",Wh=Math.pow(2,14),qh=Math.pow(2,20);let Jh,Xh;const Kh=t=>(Jh===t||(Xh=""+(t+1),Jh=t),Xh);let Yh,Zh;const Qh=t=>{if(Yh===t)return Zh;if(Yh=t,t<0)throw new Error("invalid column "+t);let e="";for(++t;t;t=Math.floor((t-1)/26))e=String.fromCharCode((t-1)%26+65)+e;return Zh=e,Zh},td=/[^a-zA-Z0-9]/,ed=t=>{if(!t)return null;return Qh(t.colIndex)+Kh(t.rowIndex)},rd=t=>{if(!t)return Gh;const e=Qh(t.colIndex),r=Kh(t.rowIndex);return(t.$colIndex?"$"+e:e)+(t.$rowIndex?"$"+r:r)},nd=(t,e)=>{let r=t??e;var n;return r&&(r=Vs(r),r=r.replace(/'/g,"''"),n=r,td.test(n)&&(r=$s(r))),r},od=(t,e)=>t?t+(t.endsWith("!")?"":"!")+e:Gh,sd=(t,e,r=ed)=>{if(!t)return null;const n=t.colStart,o=t.rowStart,s=t.colEnd,i=t.rowEnd;if(n===s&&o===i)return r({colIndex:n,rowIndex:o});t={...e,...t};const a=n===Number.MIN_SAFE_INTEGER||e&&n<=e.colStart&&s>=e.colEnd,l=o===Number.MIN_SAFE_INTEGER||e&&o<=e.rowStart&&i>=e.rowEnd;let c=null;c=l?Qh(n):a?Kh(o):r({colIndex:n,rowIndex:o});let h=null;return h=l?Qh(s):a?Kh(i):r({colIndex:s,rowIndex:i}),c+":"+h},id=(t,e,r=rd)=>{if(!t)return Gh;const n=t.colIndex,o=t.rowIndex,s=n===Number.MIN_SAFE_INTEGER;let i=null;if(o===Number.MIN_SAFE_INTEGER?(i=Qh(n),t.$colIndex&&(i="$"+i)):s?(i=Kh(o),t.$rowIndex&&(i="$"+i)):i=r(t),t.sheetName||e){const r=nd(t.sheetName,e);i=od(r,i)}return i},ad=(t,e,r=rd)=>{if(!t)return Gh;const n=void 0!==t.rowStart&&t.rowStart===t.rowEnd;if(void 0!==t.colStart&&t.colStart===t.colEnd&&n)return r({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart});t={...e,...t};const o=e&&t.rowStart<=e.rowStart&&t.rowEnd>=e.rowEnd,s=e&&t.colStart<=e.colStart&&t.colEnd>=e.colEnd;let i=null;o?(i=Qh(t.colStart),i=t.$colStart?"$"+i:i):s?(i=Kh(t.rowStart),i=t.$rowStart?"$"+i:i):i=r({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart});let a=null;return o?(a=Qh(t.colEnd),a=t.$colEnd?"$"+a:a):s?(a=Kh(t.rowEnd),a=t.$rowEnd?"$"+a:a):a=r({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd}),i+":"+a},ld=(t,e,r=rd)=>{const n=ad(t,e,r),o=nd(t?.sheetName,e?.sheetName);return od(o,n)},cd=(t,e=!1)=>{if(!t)return null;let r=0,n=0,o=!1,s=!1;const i=t.length;for(let a=0;a<i;++a){const i=t.charCodeAt(a);if(i>=48&&i<=57){if(n=10*n+(i-48),0===r&&!e)return}else if(i>=65&&i<=90){if(r=26*r+(i-64),0!==n)return}else if(i>=97&&i<=122){if(r=26*r+(i-96),0!==n)return}else{if(36!==i)return;if(0!==r||o){if(0!==n||s)return;s=!0}else o=!0}}const a={};return e||0!==n&&0!==r?(r>0&&(a.colIndex=r-1,o&&(a.$colIndex=o)),n>0&&(a.rowIndex=n-1,(s||e&&o)&&(a.$rowIndex=s||e&&o)),a):null},hd=(t,e=vh,r=!1)=>{if(!t)return null;let n=t.toUpperCase();const o=xd(n,r);let s=null,i=null;if(o?.[1]){const t=!!o[2],e=r?_d:cd;s=e(o[1],t),i=e(o[2]??o[1],t)}if(!s&&!i)return null;if(s&&i){if(void 0===s.rowIndex&&void 0!==i.rowIndex||void 0!==s.rowIndex&&void 0===i.rowIndex)return null;if(void 0===s.colIndex&&void 0!==i.colIndex||void 0!==s.colIndex&&void 0===i.colIndex)return null}const a={};return s&&(void 0!==s.colIndex&&(a.colStart=s.colIndex),void 0!==s.rowIndex&&(a.rowStart=s.rowIndex),void 0!==s.$colIndex&&(a.$colStart=s.$colIndex),void 0!==s.$rowIndex&&(a.$rowStart=s.$rowIndex),void 0!==a?.colStart&&a?.colStart>e?.colEnd)?null:(i&&(void 0!==i.colIndex&&(a.colEnd=i.colIndex),void 0!==i.rowIndex&&(a.rowEnd=i.rowIndex),void 0!==i.$colIndex&&(a.$colEnd=i.$colIndex),void 0!==i.$rowIndex&&(a.$rowEnd=i.$rowIndex)),{...e,...a})},dd=(t,e,r=!1)=>{const n=(t=>{const e=t.lastIndexOf("!");if(-1===e)return null;let r=t.slice(0,e);return r=Vs(r),r=r.replace(/''/g,"'"),[r,t.slice(e+1)]})(t);let o;if(n){if(o=hd(n[1],e,r),!o)return null;o.sheetName=n[0]}else o=hd(t,e,r);return o||null},ud=(t,e,r=ad,n=rd)=>{if(!t||0===t.length)return null;const o=[],s=t.length;for(let i=0;i<s;i++){const s=t[i];let a=null;s?void 0!==s.rowIndex||void 0!==s.colIndex?a=n(s):void 0!==s.rowStart||void 0!==s.colStart?a=r(s,e,n):"string"==typeof s&&(a=s):a=Gh,a&&o.push(a)}return o},gd=(t,e,r=ld,n=rd)=>{const o=ud(t,e,r,n);return o?o.join(","):Gh},pd=(t,e,r,n=dd,o,s=!1)=>{if(null!==e){if("string"==typeof e){const i=n(e,r,s);if(!i){const i=o?.(e);if(i){const e=i.length;for(let a=0;a<e;a++){const e=i[a];pd(t,e,r,n,o,s)}}return}e=i}else e.isICellRange?e=e.getCoords():e.isICell&&(e=U.cellToRange(e.getCoords()));if(null!==e){if(void 0!==e.rowStart||void 0!==e.colStart||void 0!==e.colEnd||void 0!==e.rowEnd){const n=e;t.push({...r,...n})}else if(void 0!==e.rowIndex||void 0!==e.colIndex){const n=e,o={...r,...n,colStart:n.colIndex,rowStart:n.rowIndex,colEnd:n.colIndex,rowEnd:n.rowIndex};null===o.sheetName&&r.sheetName&&(o.sheetName=r.sheetName),delete o.colIndex,delete o.rowIndex,t.push(o)}}else t.push(null)}else t.push(null)},md=(t,e,r=dd,n,o=!1)=>{if(!t)return[e];let s;s="string"==typeof t?Us(t):t.isICellRanges?t.getCoords():Array.isArray(t)?t:[t];const i=[],a=s.length;for(let t=0;t<a;t++){const a=s[t];pd(i,a,e,r,n,o)}return i},fd=(t,e)=>{let r=0,n=0;const o=t.length;for(let e=0;e<o;++e){const o=t.charCodeAt(e);if(o>=48&&o<=57){if(r=10*r+(o-48),0===n)return}else if(o>=65&&o<=90){if(n=26*n+(o-64),0!==r)return}else{if(!(o>=97&&o<=122))return;if(n=26*n+(o-96),0!==r)return}}return e?(e.colIndex=n-1,e.rowIndex=r-1,e):{colIndex:n-1,rowIndex:r-1}},_d=(t,e=!1,r)=>{r?(r.colIndex=Number.MIN_SAFE_INTEGER,r.rowIndex=Number.MIN_SAFE_INTEGER,r.$colIndex=!1,r.$rowIndex=!1):r={colIndex:Number.MIN_SAFE_INTEGER,rowIndex:Number.MIN_SAFE_INTEGER,$colIndex:!1,$rowIndex:!1};const n=jh.exec(t);if(!n)return null;const o=n[1],s=n[3];if(!(e||o&&s))return null;if(o){const t=n[2];t?t&&(t.startsWith("[")?(r.rowIndex=parseInt(t.slice(1,-1)),r.$rowIndex=!1):(r.rowIndex=parseInt(t)-1,r.$rowIndex=!0)):(r.rowIndex=0,r.$rowIndex=!1)}if(s){const t=n[4];t?t.startsWith("[")?(r.colIndex=parseInt(t.slice(1,-1)),r.$colIndex=!1):(r.colIndex=parseInt(t)-1,r.$colIndex=!0):(r.colIndex=0,r.$colIndex=!1)}return r},Sd=(t,e)=>{let r=0,n=0,o=!1,s=!1;const i=t.length;for(let e=0;e<i;++e){const i=t.charCodeAt(e);i>=48&&i<=57?r=10*r+(i-48):i>=65&&i<=90?n=26*n+(i-64):i>=97&&i<=122?n=26*n+(i-96):36===i&&(0===e?o=!0:s=!0)}return n--,r--,e.colIndex=n,e.rowIndex=r,-1===r?(e.$colIndex=o,e.$rowIndex=!1,e):-1===n?(e.$colIndex=!1,e.$rowIndex=o,e):(e.$colIndex=o,e.$rowIndex=s,e)},wd=t=>{let e=0;const r=t.length;for(let n=0;n<r;++n){const r=t.charCodeAt(n);if(r>=65&&r<=90)e=26*e+(r-64);else{if(!(r>=97&&r<=122))return e-1;e=26*e+(r-96)}}return e-1},yd=(t,e)=>{let r=e;r?(r.rowStart=0,r.colStart=0,r.rowEnd=0,r.colEnd=0):r={rowStart:0,colStart:0,rowEnd:0,colEnd:0};let n=0,o=0,s=0,i=t.length;for(n=0;o<i&&(s=t.charCodeAt(o),s>96&&s<123&&(s-=32),!(s<65||s>91));++o)n=26*n+(s-64);for(r.colStart=--n,n=0;o<i;++o){let e=t.charCodeAt(o)-48;if(e<0||e>9)break;n=10*n+e}if(r.rowStart=--n,o===i||58===t.charCodeAt(++o))return r.colEnd=r.colStart,r.rowEnd=r.rowStart,r;for(n=0;o!==i&&(s=t.charCodeAt(o),s>96&&s<123&&(s-=32),!(s<65||s>91));++o)n=26*n+(s-64);for(r.colEnd=--n,n=0;o!==i;++o){let e=t.charCodeAt(o)-48;if(e<0||e>9)break;n=10*n+e}return r.rowEnd=--n,r},xd=(t,e=!1)=>{const r=t.match(e?Ph:zh);return t.endsWith(":")?null:r},Cd={rowIndex:-1,colIndex:-1,$colIndex:!1,$rowIndex:!1},bd=(t,e,r,n=Wh)=>{let o=t.lastIndexOf("!"),s="";-1!==o&&(s=t.slice(0,o)+"!",t=t.slice(o+1));let i=null;const a=()=>{let t="";const n=i.rowIndex;if(-1!==n)if(i.$rowIndex)t+=`R${n+1}`;else{const r=n-e;t+=0===r?"R":`R[${r}]`}let o="";const a=i.colIndex;if(-1!==a)if(i.$colIndex)o+=`C${a+1}`;else{const t=a-r;o+=0===t?"C":`C[${t}]`}s+=t+o};o=t.lastIndexOf(":");const l=-1!==o;if(l){const e=t.slice(0,o);t=t.slice(o+1),i=Sd(e,Cd),-1!==i.colIndex&&-1!==i.rowIndex&&(a(),s+=":")}return i=Sd(t,Cd),!l&&i.colIndex>n?t:(a(),s)},Ed=[],vd=t=>(Ed.push(t),String.fromCharCode(57344+Ed.length-1)),Id=t=>{const e=t.charCodeAt(0)-57344;return Ed[e]},Ad=(t,e,r)=>{let n="";const o=t.length;for(let s=0;s<o;s++){const o=t[s];n+="string"==typeof o?o:Md(o,e,r)}return n},Rd=(t,e)=>{let r="";const n=t.rowIndex;n!==Number.MIN_SAFE_INTEGER&&(t.$rowIndex?r+=`R${n+1}`:r+=0===n?"R":`R[${n+1}]`);let o="";const s=t.colIndex;return s!==Number.MIN_SAFE_INTEGER&&(t.$colIndex?o+=`C${s+1}`:o+=0===s?"C":`C[${s+1}]`),t.sheetName&&(r=nd(t.sheetName,e)+"!"+r),r+o},Md=(t,e,r)=>{let n="";const o=t.colIndex;o!==Number.MIN_SAFE_INTEGER&&(t.$colIndex?n+="$"+Qh(o):n+=Qh(o+r));const s=t.rowIndex;return s!==Number.MIN_SAFE_INTEGER&&(t.$rowIndex?n+="$"+Kh(s):n+=Kh(s+e)),n},Td=(t,e,r,n)=>{Ed.length=0;let o=0,s=t.replace($h,vd),i=0,a=s.replace(Hh,(t,a,l)=>{const c=bd(t,e,r);if(n){if(l>i){const t=s.slice(i,l).replace(Uh,(t,e)=>Ed[o++]);n.push(t)}const a=t.lastIndexOf(":");if(-1!==a){const o=t.slice(0,a),s=t.slice(a+1),i=bd(o,e,r),l=bd(s,e,r);n.push(_d(i,!0)??i),n.push(":"),n.push(_d(l,!0)??l)}else n.push(_d(c,!0)??c)}return i=l+t.length,c});if(n&&i<s.length){const t=s.slice(i);n.push(t.replace(Uh,(t,e)=>Ed[o++]))}return a=a.toUpperCase().replace(Vh,""),a.replace(Uh,Id)},Fd="Must specify an address.",Nd="Only a single range is allowed for this operation. Use 'getRanges' instead.",kd="Invalid range. The Range must be specified as '{ TOP_LEFT:BOTTOM_RIGHT }'.",Od=t=>`Invalid address. Can not parse ${"string"==typeof t?`'${t}' `:""}as an address or named item.`,Bd=()=>{throw new Error("Invalid range.")};class Ld{constructor(t,e,r=!1){this._c=t,this._cycleId=e,this._e=r}getCycleId(){return this._cycleId}getError(){return this._e}getCoords(){return this._c}setError(t,e){const r=this._c;return{...r,value:new Ld(r,e,t)}}getShifted(t){const e=t.after;if(!e)return null;const r=U.sanitizeRange(e);return{...r,value:new Ld(r,this._cycleId,this._e)}}getMerged(t,e,r){}getSplit(t,e){}}class Dd{constructor(t,e){this._c=t,this._o=e}getCoords(){return this._c}getOrientation(){return this._o}getShifted(t){return t.after?{...t.after,value:new Dd(t.after,this._o)}:null}getMerged(t,e,r){const n=this._o;return new Dd(e,n)}getSplit(t,e){const r=this._o;return[new Dd(t[0],r),new Dd(t[1],r)]}getState(){return this._c}}const zd=(t,e)=>{if(!t||0===t.length)return mt.EmptyArray;const r=[],n=e?exports.t.Orientation.Column:exports.t.Orientation.Row;for(let o=0;o<t.length;o++){const s=t[o],i=s[0],a=s[1];for(let t=0;t<a.length;t++){const o=a[t],s=o[0],l=o[1].length-1,c={colStart:e?i:s,rowStart:e?s:i,colEnd:e?i:s+l,rowEnd:e?s+l:i,value:new Dd({colStart:e?i:s,rowStart:e?s:i,colEnd:e?i:s+l,rowEnd:e?s+l:i},n)};r.push(c)}}return r},Pd=0,jd=1;class Hd{constructor(t,e,r){this.ref=t,this.formula=e;const n=t.colStart,o=t.rowStart;if(r){const t=r,e=t.length;for(let r=0;r<e;r++){const e=[...t[r]];t[r]=e;const s=e.length;for(let t=0;t<s;t++){const s={...e[t]};e[t]=s,s.colIndex=t+n,s.rowIndex=r+o,s.block=this}}this.calcs=t}else{const r=e.getDirectPrecedentsAt(o,n),s=r?.length??0,i=new Array(t.rowEnd-o+1),a=t.colEnd-n+1,l=i.length;for(let t=0;t<l;t++){const e=new Array(a),r=e.length;for(let i=0;i<r;i++)e[i]={block:this,colIndex:i+n,rowIndex:t+o,cycleId:0,markId:0,inDegree:0,dependents:mt.EmptyArray,inputs:0===s?mt.EmptyArray:new Array(s),precedents:0===s?mt.EmptyArray:new Array(s),dynamic:null,cachedValue:void 0,removed:!1,pending:!1,pendingPrecedents:!1,pendingPromise:null,pendingResolved:!1,state:Pd,error:void 0};i[t]=e}this.calcs=i}}toJSON(){const t=this.ref;return[sd(t),this.formula.getTextAt(t.rowStart,t.colStart)]}getCoords(){return this.ref}getShifted(t){if(!t.after)return null;const e=U.sanitizeRange(t.after),r=[...this.calcs],n=new Hd(e,this.formula,r);return{...t.after,value:n}}setReferenceAt(t,e){const r=this.formula.setReferenceAt(t,e),n=[...this.calcs];return new Hd(this.ref,r,n)}getMerged(t,e,r){const n=this.formula,o=t.formula;if(!n.isEquals(o))return;const s=this.calcs,i=t.calcs;let a;if(r===exports.t.Orientation.Row)a=[...s,...i];else{const t=s.length;a=new Array(t);for(let e=0;e<t;e++)a[e]=[...s[e],...i[e]]}return new Hd(e,n,a)}getSplit(t,e,r){const n=this.formula,o=e===exports.t.Orientation.Column;let s,i;const a=this.calcs;if(o){const t=a.length;s=new Array(t),i=new Array(t);for(let e=0;e<t;e++){const t=a[e];s[e]=t.slice(0,r),i[e]=t.slice(r)}}else s=a.slice(0,r),i=a.slice(r);return[new Hd(t[0],n,s),new Hd(t[1],n,i)]}copyTo(t,e){const r=this.formula;return new Hd(t,r)}canTile(t,e){return!0}onRemove(t){const e=t.value.calcs,r=e.length;for(let t=0;t<r;t++){const r=e[t],n=r.length;for(let t=0;t<n;t++){const e=r[t];e.pendingPromise&&(e.pendingPromise.cancelled=!0),e.removed=!0}}}}const Vd=Object.freeze({break:!0});var $d;($d||($d={})).Type={Style:"style",Table:"table",Merge:"merge",Hyperlink:"hyperlink",Comments:"comments",Unlock:"unlock",Contentful:"contentful",Conditional:"conditional",Formula:"formula",Spill:"spill",Continuous:"continuous",Pending:"pending",CalcError:"calcError"};const Ud=Object.freeze({[$d.Type.Style]:!1,[$d.Type.Table]:!1,[$d.Type.Merge]:!1,[$d.Type.Hyperlink]:!1,[$d.Type.Comments]:!1,[$d.Type.Unlock]:!1,[$d.Type.Formula]:!1,[$d.Type.Spill]:!1,[$d.Type.Pending]:!1,[$d.Type.CalcError]:!1,[$d.Type.Contentful]:!1,[$d.Type.Conditional]:!1,[$d.Type.Continuous]:!1}),Gd=Object.freeze({[$d.Type.Style]:!1,[$d.Type.Table]:!1,[$d.Type.Merge]:!1,[$d.Type.Hyperlink]:!1,[$d.Type.Comments]:!1,[$d.Type.Unlock]:!1,[$d.Type.Formula]:!1,[$d.Type.Spill]:!1,[$d.Type.Pending]:!1,[$d.Type.CalcError]:!1,[$d.Type.Conditional]:!1,[$d.Type.Continuous]:!1}),Wd=Object.freeze({[$d.Type.Style]:!1,[$d.Type.Table]:!0,[$d.Type.Merge]:!1,[$d.Type.Hyperlink]:!1,[$d.Type.Comments]:!1,[$d.Type.Unlock]:!1,[$d.Type.Formula]:!1}),qd=Object.freeze({[$d.Type.Style]:!1,[$d.Type.Table]:!1,[$d.Type.Hyperlink]:!1,[$d.Type.Comments]:!1,[$d.Type.Unlock]:!1,[$d.Type.Contentful]:!1,[$d.Type.Formula]:!1}),Jd="This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.",Xd=(t="update")=>`Unable to ${t}, this sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,Kd="The range is outside of the bounds of the sheet.",Yd="Listener can not be null",Zd="We can't insert items. The sheet is protected.",Qd=t=>`We can't create a ${t} that overlaps with another table or merge.`,tu="Overlapping ranges can not be merged.",eu="We can't insert cells because this would push values off the end of the worksheet. These cells may appear empty but they have some formatting or formulas. Delete enough rows or columns and try again.",ru="Unable to partially fill over merged cells.",nu="Unable to sort merged cells unless they are all the same size.",ou="Sheet has been closed. No further operations are allowed.",su="IteratorContext can only be used during visit.",iu="When using addresses directly from the sheet do not include the sheet name.",au=t=>`Unable to return more than ${t} values. To access values in a more scalable solution use 'ICellRange.forEach' or an iterator.`,lu="Multiple selection ranges can not be copied.",cu="Unable to determine source.",hu="When pasting before or after the cut area both areas must align.",du="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,uu=new Set,gu="object"==typeof process&&process?process:{},pu=(t,e,r,n)=>{"function"==typeof gu.emitWarning?gu.emitWarning(t,e,r,n):console.error(`[${r}] ${e}: ${t}`)};let mu=globalThis.AbortController,fu=globalThis.AbortSignal;if(void 0===mu){fu=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},mu=class{constructor(){e()}signal=new fu;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==gu.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,pu("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const _u=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),Su=t=>_u(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?wu:null:null;class wu extends Array{constructor(t){super(t),this.fill(0)}}class yu{heap;length;static#t=!1;static create(t){const e=Su(t);if(!e)return[];yu.#t=!0;const r=new yu(t,e);return yu.#t=!1,r}constructor(t,e){if(!yu.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class xu{#e;#r;#n;#o;#s;#i;#a;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#l;#c;#h;#d;#u;#g;#p;#m;#f;#_;#S;#w;#y;#x;#C;#b;#E;#v;static unsafeExposeInternals(t){return{starts:t.#y,ttls:t.#x,sizes:t.#w,keyMap:t.#h,keyList:t.#d,valList:t.#u,next:t.#g,prev:t.#p,get head(){return t.#m},get tail(){return t.#f},free:t.#_,isBackgroundFetch:e=>t.#I(e),backgroundFetch:(e,r,n,o)=>t.#A(e,r,n,o),moveToTail:e=>t.#R(e),indexes:e=>t.#M(e),rindexes:e=>t.#T(e),isStale:e=>t.#F(e)}}get max(){return this.#e}get maxSize(){return this.#r}get calculatedSize(){return this.#c}get size(){return this.#l}get fetchMethod(){return this.#i}get memoMethod(){return this.#a}get dispose(){return this.#n}get onInsert(){return this.#o}get disposeAfter(){return this.#s}constructor(t){const{max:e=0,ttl:r,ttlResolution:n=1,ttlAutopurge:o,updateAgeOnGet:s,updateAgeOnHas:i,allowStale:a,dispose:l,onInsert:c,disposeAfter:h,noDisposeOnSet:d,noUpdateTTL:u,maxSize:g=0,maxEntrySize:p=0,sizeCalculation:m,fetchMethod:f,memoMethod:_,noDeleteOnFetchRejection:S,noDeleteOnStaleGet:w,allowStaleOnFetchRejection:y,allowStaleOnFetchAbort:x,ignoreFetchAbort:C}=t;if(0!==e&&!_u(e))throw new TypeError("max option must be a nonnegative integer");const b=e?Su(e):Array;if(!b)throw new Error("invalid max value: "+e);if(this.#e=e,this.#r=g,this.maxEntrySize=p||this.#r,this.sizeCalculation=m,this.sizeCalculation){if(!this.#r&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==_&&"function"!=typeof _)throw new TypeError("memoMethod must be a function if defined");if(this.#a=_,void 0!==f&&"function"!=typeof f)throw new TypeError("fetchMethod must be a function if specified");if(this.#i=f,this.#b=!!f,this.#h=new Map,this.#d=new Array(e).fill(void 0),this.#u=new Array(e).fill(void 0),this.#g=new b(e),this.#p=new b(e),this.#m=0,this.#f=0,this.#_=yu.create(e),this.#l=0,this.#c=0,"function"==typeof l&&(this.#n=l),"function"==typeof c&&(this.#o=c),"function"==typeof h?(this.#s=h,this.#S=[]):(this.#s=void 0,this.#S=void 0),this.#C=!!this.#n,this.#v=!!this.#o,this.#E=!!this.#s,this.noDisposeOnSet=!!d,this.noUpdateTTL=!!u,this.noDeleteOnFetchRejection=!!S,this.allowStaleOnFetchRejection=!!y,this.allowStaleOnFetchAbort=!!x,this.ignoreFetchAbort=!!C,0!==this.maxEntrySize){if(0!==this.#r&&!_u(this.#r))throw new TypeError("maxSize must be a positive integer if specified");if(!_u(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#N()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!w,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!i,this.ttlResolution=_u(n)||0===n?n:1,this.ttlAutopurge=!!o,this.ttl=r||0,this.ttl){if(!_u(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#k()}if(0===this.#e&&0===this.ttl&&0===this.#r)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#r){const t="LRU_CACHE_UNBOUNDED";if((t=>!uu.has(t))(t)){uu.add(t);pu("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,xu)}}}getRemainingTTL(t){return this.#h.has(t)?1/0:0}#k(){const t=new wu(this.#e),e=new wu(this.#e);this.#x=t,this.#y=e,this.#O=(r,n,o=du.now())=>{if(e[r]=0!==n?o:0,t[r]=n,0!==n&&this.ttlAutopurge){const t=setTimeout(()=>{this.#F(r)&&this.#B(this.#d[r],"expire")},n+1);t.unref&&t.unref()}},this.#L=r=>{e[r]=0!==t[r]?du.now():0},this.#D=(o,s)=>{if(t[s]){const i=t[s],a=e[s];if(!i||!a)return;o.ttl=i,o.start=a,o.now=r||n();const l=o.now-a;o.remainingTTL=i-l}};let r=0;const n=()=>{const t=du.now();if(this.ttlResolution>0){r=t;const e=setTimeout(()=>r=0,this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=o=>{const s=this.#h.get(o);if(void 0===s)return 0;const i=t[s],a=e[s];if(!i||!a)return 1/0;return i-((r||n())-a)},this.#F=o=>{const s=e[o],i=t[o];return!!i&&!!s&&(r||n())-s>i}}#L=()=>{};#D=()=>{};#O=()=>{};#F=()=>!1;#N(){const t=new wu(this.#e);this.#c=0,this.#w=t,this.#z=e=>{this.#c-=t[e],t[e]=0},this.#P=(t,e,r,n)=>{if(this.#I(e))return 0;if(!_u(r)){if(!n)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof n)throw new TypeError("sizeCalculation must be a function");if(r=n(e,t),!_u(r))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return r},this.#j=(e,r,n)=>{if(t[e]=r,this.#r){const r=this.#r-t[e];for(;this.#c>r;)this.#H(!0)}this.#c+=t[e],n&&(n.entrySize=r,n.totalCalculatedSize=this.#c)}}#z=t=>{};#j=(t,e,r)=>{};#P=(t,e,r,n)=>{if(r||n)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#M({allowStale:t=this.allowStale}={}){if(this.#l)for(let e=this.#f;this.#V(e)&&(!t&&this.#F(e)||(yield e),e!==this.#m);)e=this.#p[e]}*#T({allowStale:t=this.allowStale}={}){if(this.#l)for(let e=this.#m;this.#V(e)&&(!t&&this.#F(e)||(yield e),e!==this.#f);)e=this.#g[e]}#V(t){return void 0!==t&&this.#h.get(this.#d[t])===t}*entries(){for(const t of this.#M())void 0===this.#u[t]||void 0===this.#d[t]||this.#I(this.#u[t])||(yield[this.#d[t],this.#u[t]])}*rentries(){for(const t of this.#T())void 0===this.#u[t]||void 0===this.#d[t]||this.#I(this.#u[t])||(yield[this.#d[t],this.#u[t]])}*keys(){for(const t of this.#M()){const e=this.#d[t];void 0===e||this.#I(this.#u[t])||(yield e)}}*rkeys(){for(const t of this.#T()){const e=this.#d[t];void 0===e||this.#I(this.#u[t])||(yield e)}}*values(){for(const t of this.#M()){void 0===this.#u[t]||this.#I(this.#u[t])||(yield this.#u[t])}}*rvalues(){for(const t of this.#T()){void 0===this.#u[t]||this.#I(this.#u[t])||(yield this.#u[t])}}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(const r of this.#M()){const n=this.#u[r],o=this.#I(n)?n.__staleWhileFetching:n;if(void 0!==o&&t(o,this.#d[r],this))return this.get(this.#d[r],e)}}forEach(t,e=this){for(const r of this.#M()){const n=this.#u[r],o=this.#I(n)?n.__staleWhileFetching:n;void 0!==o&&t.call(e,o,this.#d[r],this)}}rforEach(t,e=this){for(const r of this.#T()){const n=this.#u[r],o=this.#I(n)?n.__staleWhileFetching:n;void 0!==o&&t.call(e,o,this.#d[r],this)}}purgeStale(){let t=!1;for(const e of this.#T({allowStale:!0}))this.#F(e)&&(this.#B(this.#d[e],"expire"),t=!0);return t}info(t){const e=this.#h.get(t);if(void 0===e)return;const r=this.#u[e],n=this.#I(r)?r.__staleWhileFetching:r;if(void 0===n)return;const o={value:n};if(this.#x&&this.#y){const t=this.#x[e],r=this.#y[e];if(t&&r){const e=t-(du.now()-r);o.ttl=e,o.start=Date.now()}}return this.#w&&(o.size=this.#w[e]),o}dump(){const t=[];for(const e of this.#M({allowStale:!0})){const r=this.#d[e],n=this.#u[e],o=this.#I(n)?n.__staleWhileFetching:n;if(void 0===o||void 0===r)continue;const s={value:o};if(this.#x&&this.#y){s.ttl=this.#x[e];const t=du.now()-this.#y[e];s.start=Math.floor(Date.now()-t)}this.#w&&(s.size=this.#w[e]),t.unshift([r,s])}return t}load(t){this.clear();for(const[e,r]of t){if(r.start){const t=Date.now()-r.start;r.start=du.now()-t}this.set(e,r.value,r)}}set(t,e,r={}){if(void 0===e)return this.delete(t),this;const{ttl:n=this.ttl,start:o,noDisposeOnSet:s=this.noDisposeOnSet,sizeCalculation:i=this.sizeCalculation,status:a}=r;let{noUpdateTTL:l=this.noUpdateTTL}=r;const c=this.#P(t,e,r.size||0,i);if(this.maxEntrySize&&c>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#B(t,"set"),this;let h=0===this.#l?void 0:this.#h.get(t);if(void 0===h)h=0===this.#l?this.#f:0!==this.#_.length?this.#_.pop():this.#l===this.#e?this.#H(!1):this.#l,this.#d[h]=t,this.#u[h]=e,this.#h.set(t,h),this.#g[this.#f]=h,this.#p[h]=this.#f,this.#f=h,this.#l++,this.#j(h,c,a),a&&(a.set="add"),l=!1,this.#v&&this.#o?.(e,t,"add");else{this.#R(h);const r=this.#u[h];if(e!==r){if(this.#b&&this.#I(r)){r.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=r;void 0===e||s||(this.#C&&this.#n?.(e,t,"set"),this.#E&&this.#S?.push([e,t,"set"]))}else s||(this.#C&&this.#n?.(r,t,"set"),this.#E&&this.#S?.push([r,t,"set"]));if(this.#z(h),this.#j(h,c,a),this.#u[h]=e,a){a.set="replace";const t=r&&this.#I(r)?r.__staleWhileFetching:r;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update");this.#v&&this.onInsert?.(e,t,e===r?"update":"replace")}if(0===n||this.#x||this.#k(),this.#x&&(l||this.#O(h,n,o),a&&this.#D(a,h)),!s&&this.#E&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}return this}pop(){try{for(;this.#l;){const t=this.#u[this.#m];if(this.#H(!0),this.#I(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#E&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}}}#H(t){const e=this.#m,r=this.#d[e],n=this.#u[e];return this.#b&&this.#I(n)?n.__abortController.abort(new Error("evicted")):(this.#C||this.#E)&&(this.#C&&this.#n?.(n,r,"evict"),this.#E&&this.#S?.push([n,r,"evict"])),this.#z(e),t&&(this.#d[e]=void 0,this.#u[e]=void 0,this.#_.push(e)),1===this.#l?(this.#m=this.#f=0,this.#_.length=0):this.#m=this.#g[e],this.#h.delete(r),this.#l--,e}has(t,e={}){const{updateAgeOnHas:r=this.updateAgeOnHas,status:n}=e,o=this.#h.get(t);if(void 0!==o){const t=this.#u[o];if(this.#I(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#F(o))return r&&this.#L(o),n&&(n.has="hit",this.#D(n,o)),!0;n&&(n.has="stale",this.#D(n,o))}else n&&(n.has="miss");return!1}peek(t,e={}){const{allowStale:r=this.allowStale}=e,n=this.#h.get(t);if(void 0===n||!r&&this.#F(n))return;const o=this.#u[n];return this.#I(o)?o.__staleWhileFetching:o}#A(t,e,r,n){const o=void 0===e?void 0:this.#u[e];if(this.#I(o))return o;const s=new mu,{signal:i}=r;i?.addEventListener("abort",()=>s.abort(i.reason),{signal:s.signal});const a={signal:s.signal,options:r,context:n},l=(n,o=!1)=>{const{aborted:i}=s.signal,l=r.ignoreFetchAbort&&void 0!==n;if(r.status&&(i&&!o?(r.status.fetchAborted=!0,r.status.fetchError=s.signal.reason,l&&(r.status.fetchAbortIgnored=!0)):r.status.fetchResolved=!0),i&&!l&&!o)return c(s.signal.reason);const d=h;return this.#u[e]===h&&(void 0===n?d.__staleWhileFetching?this.#u[e]=d.__staleWhileFetching:this.#B(t,"fetch"):(r.status&&(r.status.fetchUpdated=!0),this.set(t,n,a.options))),n},c=n=>{const{aborted:o}=s.signal,i=o&&r.allowStaleOnFetchAbort,a=i||r.allowStaleOnFetchRejection,l=a||r.noDeleteOnFetchRejection,c=h;if(this.#u[e]===h){!l||void 0===c.__staleWhileFetching?this.#B(t,"fetch"):i||(this.#u[e]=c.__staleWhileFetching)}if(a)return r.status&&void 0!==c.__staleWhileFetching&&(r.status.returnedStale=!0),c.__staleWhileFetching;if(c.__returned===c)throw n};r.status&&(r.status.fetchDispatched=!0);const h=new Promise((e,n)=>{const i=this.#i?.(t,o,a);i&&i instanceof Promise&&i.then(t=>e(void 0===t?void 0:t),n),s.signal.addEventListener("abort",()=>{r.ignoreFetchAbort&&!r.allowStaleOnFetchAbort||(e(void 0),r.allowStaleOnFetchAbort&&(e=t=>l(t,!0)))})}).then(l,t=>(r.status&&(r.status.fetchRejected=!0,r.status.fetchError=t),c(t))),d=Object.assign(h,{__abortController:s,__staleWhileFetching:o,__returned:void 0});return void 0===e?(this.set(t,d,{...a.options,status:void 0}),e=this.#h.get(t)):this.#u[e]=d,d}#I(t){if(!this.#b)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof mu}async fetch(t,e={}){const{allowStale:r=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:i=this.noDisposeOnSet,size:a=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:h=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:u=this.ignoreFetchAbort,allowStaleOnFetchAbort:g=this.allowStaleOnFetchAbort,context:p,forceRefresh:m=!1,status:f,signal:_}=e;if(!this.#b)return f&&(f.fetch="get"),this.get(t,{allowStale:r,updateAgeOnGet:n,noDeleteOnStaleGet:o,status:f});const S={allowStale:r,updateAgeOnGet:n,noDeleteOnStaleGet:o,ttl:s,noDisposeOnSet:i,size:a,sizeCalculation:l,noUpdateTTL:c,noDeleteOnFetchRejection:h,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:g,ignoreFetchAbort:u,status:f,signal:_};let w=this.#h.get(t);if(void 0===w){f&&(f.fetch="miss");const e=this.#A(t,w,S,p);return e.__returned=e}{const e=this.#u[w];if(this.#I(e)){const t=r&&void 0!==e.__staleWhileFetching;return f&&(f.fetch="inflight",t&&(f.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const o=this.#F(w);if(!m&&!o)return f&&(f.fetch="hit"),this.#R(w),n&&this.#L(w),f&&this.#D(f,w),e;const s=this.#A(t,w,S,p),i=void 0!==s.__staleWhileFetching&&r;return f&&(f.fetch=o?"stale":"refresh",i&&o&&(f.returnedStale=!0)),i?s.__staleWhileFetching:s.__returned=s}}async forceFetch(t,e={}){const r=await this.fetch(t,e);if(void 0===r)throw new Error("fetch() returned undefined");return r}memo(t,e={}){const r=this.#a;if(!r)throw new Error("no memoMethod provided to constructor");const{context:n,forceRefresh:o,...s}=e,i=this.get(t,s);if(!o&&void 0!==i)return i;const a=r(t,i,{options:s,context:n});return this.set(t,a,s),a}get(t,e={}){const{allowStale:r=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:s}=e,i=this.#h.get(t);if(void 0!==i){const e=this.#u[i],a=this.#I(e);return s&&this.#D(s,i),this.#F(i)?(s&&(s.get="stale"),a?(s&&r&&void 0!==e.__staleWhileFetching&&(s.returnedStale=!0),r?e.__staleWhileFetching:void 0):(o||this.#B(t,"expire"),s&&r&&(s.returnedStale=!0),r?e:void 0)):(s&&(s.get="hit"),a?e.__staleWhileFetching:(this.#R(i),n&&this.#L(i),e))}s&&(s.get="miss")}#$(t,e){this.#p[e]=t,this.#g[t]=e}#R(t){t!==this.#f&&(t===this.#m?this.#m=this.#g[t]:this.#$(this.#p[t],this.#g[t]),this.#$(this.#f,t),this.#f=t)}delete(t){return this.#B(t,"delete")}#B(t,e){let r=!1;if(0!==this.#l){const n=this.#h.get(t);if(void 0!==n)if(r=!0,1===this.#l)this.#U(e);else{this.#z(n);const r=this.#u[n];if(this.#I(r)?r.__abortController.abort(new Error("deleted")):(this.#C||this.#E)&&(this.#C&&this.#n?.(r,t,e),this.#E&&this.#S?.push([r,t,e])),this.#h.delete(t),this.#d[n]=void 0,this.#u[n]=void 0,n===this.#f)this.#f=this.#p[n];else if(n===this.#m)this.#m=this.#g[n];else{const t=this.#p[n];this.#g[t]=this.#g[n];const e=this.#g[n];this.#p[e]=this.#p[n]}this.#l--,this.#_.push(n)}}if(this.#E&&this.#S?.length){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}return r}clear(){return this.#U("delete")}#U(t){for(const e of this.#T({allowStale:!0})){const r=this.#u[e];if(this.#I(r))r.__abortController.abort(new Error("deleted"));else{const n=this.#d[e];this.#C&&this.#n?.(r,n,t),this.#E&&this.#S?.push([r,n,t])}}if(this.#h.clear(),this.#u.fill(void 0),this.#d.fill(void 0),this.#x&&this.#y&&(this.#x.fill(0),this.#y.fill(0)),this.#w&&this.#w.fill(0),this.#m=0,this.#f=0,this.#_.length=0,this.#c=0,this.#l=0,this.#E&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}}}var Cu;exports.ICell=void 0,(Cu=exports.ICell||(exports.ICell={})).CalcStatus={Ready:"ready",Stale:"stale",Pending:"pending",Streaming:"streaming"},Cu.Content={Values:"values",Formats:"formats",Formulas:"formula",Hyperlinks:"hyperlinks",Tables:"tables",Notes:"notes",Comments:"comments",Warnings:"warnings",Errors:"errors",Merges:"merges"};class bu{constructor(t,e,r){if(!r)throw new Ft;if("string"==typeof r&&(r={address:r}),"string"!=typeof r.address)throw new Error("Invalid hyperlink");this._t=t,this._r=e,this._p=r}open(t,e){return this._r(this.getAddress(),null,t??this.getTarget(),e)}getTarget(){let t=this._p.target;if(t)return t;return this._p.address.startsWith("#")?"_self":"_blank"}getDisplayText(){return this._t()??this.getAddress()}getAddress(){return this._p.address??""}getTooltip(){return this._p.tooltip??null}get isIHyperlink(){return!0}}function Eu(t){return!/^(-?\d|--)/.test(t)}function vu(t){const e=[];let r="",n="",o=7;for(let s,i=0;s=t.charAt(i);i++)if(/[a-zA-Z\d\xa0-\uffff_-]/.test(s)&&7===o)r+=s;else if("\\"===s&&7===o)o=6;else if(" "===s&&7===o){if(""!==r){if(!Eu(r))return null;e.push(r),r=""}}else if(6===o)/[0-9a-f]/i.test(s)?(n+=s,o=8):(r+=s,o=7);else{if(8!==o)return null;/[0-9a-f]/i.test(s)&&n.length<6?n+=s:(r+=String.fromCodePoint(parseInt(n,16)),r+=s,n="",o=7)}if(""!==r){if(!Eu(r))return null;e.push(r)}return e.join(" ")}function Iu(t,e){let r=e,n="";const o={"font-family":[]};for(let e,s=0;e=t.charAt(s);s+=1)if(4!==r||'"'!==e&&"'"!==e)if(3===r&&","===e)r=4,n="";else if(4===r&&","===e){const t=vu(n);t&&o["font-family"].push(t),n=""}else if(5===r&&" "===e)/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:deg|grad|rad|turn)$/.test(n)?(o["font-style"]+=" "+n,n=""):s-=1,r=1;else if(1!==r||" "!==e&&"/"!==e)2===r&&" "===e?(/^(?:\+|-)?([0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)?$/.test(n)&&(o["line-height"]=n),r=4,n=""):n+=e;else{if(/^(?:(?:xx|x)-large|(?:xx|s)-small|small|large|medium)$/.test(n)||/^(?:larg|small)er$/.test(n)||/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)$/.test(n))r="/"===e?2:4,o["font-size"]=n;else if(/^italic$/.test(n))o["font-style"]=n;else if(/^oblique$/.test(n))o["font-style"]=n,r=5;else if(/^small-caps$/.test(n))o["font-variant"]=n;else if(/^(?:bold(?:er)?|lighter|normal)$/.test(n))o["font-weight"]=n;else if(/^[+-]?(?:[0-9]*\.)?[0-9]+(?:e[+-]?(?:0|[1-9][0-9]*))?$/.test(n)){const t=parseFloat(n);t>=1&&t<=1e3&&(o["font-weight"]=n)}else/^(?:(?:ultra|extra|semi)-)?(?:condensed|expanded)$/.test(n)&&(o["font-stretch"]=n);n=""}else{let i=s+1;do{if(i=t.indexOf(e,i)+1,!i)return null}while("\\"===t.charAt(i-2));o["font-family"].push(t.slice(s+1,i-1).replace(/\\('|")/g,"$1")),s=i-1,r=3,n=""}if(3===r&&!/^\s*$/.test(n))return null;if(4===r){const t=vu(n);t&&o["font-family"].push(t)}return o}const Au=t=>{if("string"!=typeof t)return null;let e=function(t){const e=Iu(t,4);return null!==e?e["font-family"]:null}(t);Array.isArray(e)&&0===e.length&&(e=null),e=e?{"font-family":e}:function(t){const e=Iu(t,1);return null!==e&&e["font-size"]&&e["font-family"].length?e:null}(t);let r=null,n=null,o=null;if(e){let t=e["font-family"];const s=t.shift();s&&(r=s),t.length>0&&(n=t),void 0!==e["font-size"]&&(o=e["font-size"])}return{family:r,fallbacks:n,size:o}},Ru=(t,e=!1)=>t?.toHex(e)?.toString(!1).toLowerCase()??null,Mu=t=>null==t?null:mt.roundAccurately(t,2)+"pt",Tu=(t,e)=>{let r="";const n=t&&t!==exports.IFont.UnderlineStyle.None;return e&&(r+="line-through"),n&&e&&(r+=" "),n&&(r+="underline",!0!==t&&t!==exports.IFont.UnderlineStyle.Single&&t!==exports.IFont.UnderlineStyle.SingleAccounting||(r+=" solid"),t!==exports.IFont.UnderlineStyle.Double&&t!==exports.IFont.UnderlineStyle.DoubleAccounting||(r+=" double")),r},Fu=Object.freeze({underline:exports.IFont.UnderlineStyle.None,strike:!1}),Nu=t=>t?"single"===(t=t.toLowerCase())?exports.IFont.UnderlineStyle.Single:"double"===t?exports.IFont.UnderlineStyle.Double:"single-accounting"===t||"singleaccounting"===t?exports.IFont.UnderlineStyle.SingleAccounting:"double-accounting"===t||"doubleaccounting"===t?exports.IFont.UnderlineStyle.DoubleAccounting:exports.IFont.UnderlineStyle.None:exports.IFont.UnderlineStyle.None,ku=t=>t?t.toLowerCase():null,Ou=t=>t?t===exports.ITextFrame.Overflow.Visible||t===exports.ITextFrame.Overflow.Clip||t===exports.ITextFrame.Overflow.Shrink?"nowrap":t===exports.ITextFrame.Overflow.Wrap?"normal":void 0:null,Bu=(t,e)=>{let r="";if(t&&(t.includes(" ")&&(t='"'+t+'"'),r=t),e)for(let t=0;t<e.length;t++)r.length>0&&(r+=", "),r+=e[t];return r},Lu=t=>{let e="",r=!1,n="";for(let o=0;o<t.length;o++){const s=t.charAt(o);r&&"]"!==s&&'"'!==s?e+=s:'"'===s?(e+="\\0022",r=!r):["[","]",",","#",".","@","/",":",";","-"," "].includes(s)?(e+="\\"+s,"["===s?r=!0:"]"===s&&(r=!1)):["(",")"].includes(s)?e+="_"===n?"\\"+s:"\\\\\\"+s:["$"].includes(s)?e+="\\0022"+s+"\\0022":e+=s,n=s}return'"'+e+'"'},Du="Thin",zu="Hairline",Pu="Extra Light",ju="Ultra Light",Hu="Light",Vu="Normal",$u="Regular",Uu="Medium",Gu="Semi Bold",Wu="Demi Bold",qu="Bold",Ju="Extra Bold",Xu="Ultra Bold",Ku="Black",Yu="Heavy",Zu="Extra Black",Qu="Ultra Black",tg="lighter",eg="normal",rg="bold",ng="bolder",og=new Map;og.set(mt.textToKey(Du),100),og.set(mt.textToKey(zu),100),og.set(mt.textToKey(Pu),200),og.set(mt.textToKey(ju),200),og.set(mt.textToKey(Hu),300),og.set(mt.textToKey(Vu),400),og.set(mt.textToKey($u),400),og.set(mt.textToKey(Uu),500),og.set(mt.textToKey(Gu),600),og.set(mt.textToKey(Wu),600),og.set(mt.textToKey(Vu),400),og.set(mt.textToKey(qu),700),og.set(mt.textToKey(Ju),800),og.set(mt.textToKey(Xu),800),og.set(mt.textToKey(Ku),900),og.set(mt.textToKey(Yu),900),og.set(mt.textToKey(Zu),950),og.set(mt.textToKey(Qu),950),og.set(mt.textToKey(tg),100),og.set(mt.textToKey(eg),400),og.set(mt.textToKey(rg),700),og.set(mt.textToKey(ng),700);const sg="xx-small",ig="x-small",ag="small",lg="medium",cg="large",hg="x-large",dg="xx-large",ug="xxx-large",gg="smaller",pg="larger",mg="math",fg=new RegExp("^[0-9]*[.]?[0-9]+$","g"),_g=new Map;_g.set(mt.textToKey(sg),t=>.4*t),_g.set(mt.textToKey(ig),t=>.5*t),_g.set(mt.textToKey(ag),t=>.6*t),_g.set(mt.textToKey(lg),t=>t),_g.set(mt.textToKey(cg),t=>1.1*t),_g.set(mt.textToKey(hg),t=>1.25*t),_g.set(mt.textToKey(dg),t=>1.5*t),_g.set(mt.textToKey(ug),t=>2*t),_g.set(mt.textToKey(gg),t=>.9*t),_g.set(mt.textToKey(pg),t=>1.1*t),_g.set(mt.textToKey(mg),t=>t);const Sg=(t,e=11,r="pt")=>{if(!t)return null;let n=e;t=t.trim().toLowerCase();const o="pt"===r?exports.IFont.getDeviceScale():1,s="pt"===r?1:exports.IFont.getDeviceScale();if(fg.test(t)){const e=parseFloat(t);isNaN(e)||(t=e+r)}if(t.endsWith("pt"))n=parseFloat(t.substring(0,t.length-2).trim())*s;else if(t.endsWith("px"))n=parseFloat(t.substring(0,t.length-2).trim())/o;else if(t.endsWith("em"))n=parseFloat(t.substring(0,t.length-2).trim())*e;else if(t.endsWith("rem"))n=parseFloat(t.substring(0,t.length-3).trim())*e;else if(t.endsWith("%"))n=parseFloat(t.substring(0,t.length-1).trim())/100*e;else if("string"==typeof t){const r=mt.textToKey(t),n=_g.get(r);if(n)return n(e)}return isNaN(n)?null:n},wg=new Map;wg.set(exports.IFill.BuiltInSheetPattern.None,{description:"None",cssKey:"none"}),wg.set(exports.IFill.BuiltInSheetPattern.Solid,{description:"Solid",cssKey:"solid"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkGray,{description:"75% gray",cssKey:"gray-75"}),wg.set(exports.IFill.BuiltInSheetPattern.MediumGray,{description:"50% gray",cssKey:"gray-50"}),wg.set(exports.IFill.BuiltInSheetPattern.LightGray,{description:"25% gray",cssKey:"gray-25"}),wg.set(exports.IFill.BuiltInSheetPattern.Gray125,{description:"12.5% Gray",cssKey:"gray-125"}),wg.set(exports.IFill.BuiltInSheetPattern.Gray0625,{description:"6.25% Gray",cssKey:"gray-0625"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkHorizontal,{description:"Horizontal Strip",cssKey:"horz-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkVertical,{description:"Vertical Strip",cssKey:"vert-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkDown,{description:"Reverse Diagonal Stripe",cssKey:"reverse-diag-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkUp,{description:"Diagonal Strip",cssKey:"diag-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkGrid,{description:"Diagonal Crosshatch",cssKey:"diag-cross"}),wg.set(exports.IFill.BuiltInSheetPattern.DarkTrellis,{description:"Thick Diagonal Crosshatch",cssKey:"thick-diag-cross"}),wg.set(exports.IFill.BuiltInSheetPattern.LightHorizontal,{description:"Thin Horizontal Stripe",cssKey:"thin-horz-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.LightVertical,{description:"Thin Vertical Stripe",cssKey:"thin-vert-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.LightDown,{description:"Thin Reverse Diagonal Stripe",cssKey:"thin-reverse-diag-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.LightUp,{description:"Thin Diagonal Stripe",cssKey:"thin-diag-stripe"}),wg.set(exports.IFill.BuiltInSheetPattern.LightGrid,{description:"Thin Horizontal Cross",cssKey:"thin-horz-cross"}),wg.set(exports.IFill.BuiltInSheetPattern.LightTrellis,{description:"Thin Diagonal Cross",cssKey:"thin-diag-cross"});let yg="";const xg=new Map;wg.forEach((t,e)=>{yg.length>0&&(yg+="|"),yg+="\\b"+t.cssKey+"\\b",xg.set(t.cssKey,e)});const Cg=new RegExp(`(\\s*(?:${yg}))`,"g"),bg=t=>{if(!t)return null;let e=t.toLowerCase();e=e.replace(/;/,"");let r=e.match(Cg);if(!r)return null;let n=null;r&&r.length>0&&(n=(t=>{if(!t)return null;let r=e.indexOf(t);return e=e.substring(0,r)+e.substring(r+t.length,e.length),t.trim()})(r[0])),e=e.trim();const o=e?e.trim():null;if(!n&&!o)return null;return{patternType:xg.get(n??"solid"),foreground:o??null}},Eg=(t,e=!1,r=null)=>{if(!t||!t.getStops()||t.getStops().length<1)return null;if(1===t.getStops().length)return Ru(t.getStops()[0].getColor(),e);let n="";for(let r=0;r<t.getStops().length;r++){const o=t.getStops()[r];n+=Ru(o.getColor(),e)+" "+100*(o.getOffset()??r*(t.getStops().length-1))+"%",r<t.getStops().length-1&&(n+=", ")}let o=t.getAngle()??0;if(t.getGradientType()===exports.IFill.GradientType.Path){const r=Ru(t.getStops()[0]?.getColor(),e),s=Ru((t.getStops()[1]??t.getStops()[0])?.getColor(),e),i=t.getFillTo()??{left:0,top:0,right:0,bottom:0},a=-1;let l=`${100-a}% ${100-a}%`;if(o=315,1===i.left&&1===i.right&&1===i.right&&1===i.bottom)o=135,l=`${a}% ${a}%`;else if(0!==i.top&&0!==i.bottom&&0===i.left&&0===i.right)o=225,l=`${100-a}% ${a}%`;else if(1===i.left&&0!==i.right&&0===i.top&&0===i.bottom)o=45,l=`${a}% ${100-a}%`;else if(0!==i.left&&0!==i.right&&0!==i.top&&0!==i.bottom)return`radial-gradient(${n})`;const c=70;return`conic-gradient(from ${o}deg at ${l}, ${r} 0deg, ${s} ${c/2}deg,${s} ${360-c/2}deg, ${r} 360deg)`}return`linear-gradient(${o}deg, ${n})`},vg=new Map;vg.set(exports.IBorder.StrokeStyle.None,{size:null,cssKey:"none"}),vg.set(exports.IBorder.StrokeStyle.DashDot,{size:.5,cssKey:"dot-dash"}),vg.set(exports.IBorder.StrokeStyle.DashDotDot,{size:.5,cssKey:"dot-dot-dash"}),vg.set(exports.IBorder.StrokeStyle.Dashed,{size:.5,cssKey:"dashed"}),vg.set(exports.IBorder.StrokeStyle.MediumDashed,{size:1,cssKey:"dashed"}),vg.set(exports.IBorder.StrokeStyle.Dotted,{size:.5,cssKey:"dotted"}),vg.set(exports.IBorder.StrokeStyle.MediumDashDot,{size:1,cssKey:"dot-dash"}),vg.set(exports.IBorder.StrokeStyle.MediumDashDotDot,{size:1,cssKey:"dot-dot-dash"}),vg.set(exports.IBorder.StrokeStyle.Hair,{size:.5,cssKey:"hairline"}),vg.set(exports.IBorder.StrokeStyle.Thin,{size:.5,cssKey:"solid"}),vg.set(exports.IBorder.StrokeStyle.Thick,{size:1.5,cssKey:"solid"}),vg.set(exports.IBorder.StrokeStyle.Medium,{size:1,cssKey:"solid"}),vg.set(exports.IBorder.StrokeStyle.Double,{size:2,cssKey:"double"}),vg.set(exports.IBorder.StrokeStyle.SlantDashDot,{size:1,cssKey:"dot-dash-slanted"});const Ig=t=>{if(!t)return"none";const e=vg.get(t.getStyle());if(!e)return null;if("none"===e.cssKey)return e.cssKey;let r=((t,e=!1)=>t?.toRGBA(e).toString(!1)??null)(t?.getColor());r=r?" "+r:"";return`${null!==e.size?`${e.size}pt `:""}${e.cssKey}${r}`};let Ag=[];const Rg=new Set,Mg=new Map,Tg=(t,e)=>{let r=null!==t.size?`${t.size.toString()} ${t.cssKey}`:t.cssKey;Mg.set(r,e),Rg.has(t.cssKey)||(Ag.push(t.cssKey),Rg.add(t.cssKey))};vg.forEach(Tg);const Fg=Object.keys(exports.IBorder.StrokeStyle);for(let t=0;t<Fg.length;t++){Tg({size:null,cssKey:Fg[t].toLowerCase()},exports.IBorder.StrokeStyle[Fg[t]])}Tg({size:null,cssKey:"double"},exports.IBorder.StrokeStyle.Double),Tg({size:null,cssKey:"solid"},exports.IBorder.StrokeStyle.Medium),Tg({size:null,cssKey:"hidden"},exports.IBorder.StrokeStyle.None),Ag.sort((t,e)=>e.length-t.length);let Ng="";for(let t=0;t<Ag.length;t++)Ng.length>0&&(Ng+="|"),Ng+="\\b"+Ag[t]+"\\b";const kg=new RegExp(`(\\s*(?:${Ng}))`,"g"),Og=new RegExp("(\\s*[0-9]*[.]?[0-9]+(?:pt|px){0,1})","g"),Bg=t=>{if(!t)return null;let e=t.toLowerCase(),r=e.match(kg);if(!r)return null;const n=t=>{if(!t)return null;let r=e.indexOf(t);return e=e.substring(0,r)+e.substring(r+t.length,e.length).trim(),t.trim()};let o=null;if(r&&r.length>0&&(o=n(r[0])),!o)return null;let s=null;if(r=e.match(Og),r&&r.length>0){let t=n(r[0]);s=parseFloat(t.substring(0,t.length-2))}e=e.trim();const i=e?e.trim():null;let a=null===s?o:`${s.toString()} ${o}`,l=Mg.get(a);return l||(l=Mg.get(o)),l?{color:i,style:l}:null},Lg="start",Dg="end",zg="left",Pg="right",jg="center",Hg="justify",Vg="justify-all",$g="baseline",Ug="top",Gg="middle",Wg="bottom",qg="sub",Jg="text-top",Xg="justify",Kg="distributed",Yg=new Map;Yg.set(mt.textToKey(Lg),exports.ITextFrame.HorizontalAlignment.Left),Yg.set(mt.textToKey(zg),exports.ITextFrame.HorizontalAlignment.Left),Yg.set(mt.textToKey(Dg),exports.ITextFrame.HorizontalAlignment.Right),Yg.set(mt.textToKey(Pg),exports.ITextFrame.HorizontalAlignment.Right),Yg.set(mt.textToKey(jg),exports.ITextFrame.HorizontalAlignment.Center),Yg.set(mt.textToKey(Hg),exports.ITextFrame.HorizontalAlignment.Justify),Yg.set(mt.textToKey(Vg),exports.ITextFrame.HorizontalAlignment.Justify);const Zg=new Map;Zg.set(mt.textToKey($g),exports.ITextFrame.VerticalAlignment.Bottom),Zg.set(mt.textToKey(Ug),exports.ITextFrame.VerticalAlignment.Top),Zg.set(mt.textToKey(Gg),exports.ITextFrame.VerticalAlignment.Center),Zg.set(mt.textToKey(Wg),exports.ITextFrame.VerticalAlignment.Bottom),Zg.set(mt.textToKey(qg),exports.ITextFrame.VerticalAlignment.Bottom),Zg.set(mt.textToKey(Jg),exports.ITextFrame.VerticalAlignment.Top),Zg.set(mt.textToKey(Xg),exports.ITextFrame.VerticalAlignment.Justify),Zg.set(mt.textToKey(Kg),exports.ITextFrame.VerticalAlignment.Distributed);const Qg=(t,e)=>{if(t instanceof ba)return{color:t};if("string"==typeof t)try{return{color:"none"===t||"transparent"===t?null:e(t)}}catch(t){throw t}return t},tp={shorthand:(t,e)=>{if(!t||"none"===t||"transparent"===t)return null;try{return e.parseColor(t).toString()}catch(t){console.warn("error",t)}return t},merge:(t,e,r)=>t},ep={shorthand:(t,e)=>{if("string"==typeof t&&(t=Bg(t)),!t)return null;const r={};return t.style&&(r.style=t.style),t.color&&(r.color=t.color),t.isIStroke?t.getProperties():r},properties:{color:tp}},rp={shorthand:(t,e)=>"none"===t||"transparent"===t||"object"==typeof t&&0===Object.keys(t).length?{type:exports.IFill.Type.None}:(t.getType?.(),exports.IFill.Type.None,t)},np={shorthand:(t,e)=>("object"==typeof(t=Qg(t,e.parseColor.bind(e)))&&t.color&&(t.type=exports.IFill.Type.Solid),t),merge:(t,e,r)=>t.color?t:(e?.toJSON&&(e=e.toJSON()),e?.type===exports.IFill.Type.Solid?{...e}:e?.type===exports.IFill.Type.Gradient?{type:exports.IFill.Type.Solid,color:e?.stops?.[0]?.color??r.parseColor(exports.IColor.Scheme.Bg1)}:e?.type===exports.IFill.Type.Pattern?{type:exports.IFill.Type.Solid,color:e?.foreground??r.parseColor(exports.IColor.Scheme.Bg1)}:t?{...t}:null),properties:{color:tp}},op={shorthand:(t,e)=>("object"==typeof t&&t.stops&&(t.type=exports.IFill.Type.Gradient),t),merge:(t,e,r)=>t.stops?t:(e?.toJSON&&(e=e.toJSON()),e?.type===exports.IFill.Type.Gradient?{...e}:e?.type===exports.IFill.Type.Solid?{type:exports.IFill.Type.Gradient,stops:[{offset:0,color:e?.color??exports.IColor.Scheme.Accent1},{offset:1,color:exports.IColor.Scheme.Bg1}]}:e?.type===exports.IFill.Type.Pattern?{type:exports.IFill.Type.Gradient,stops:[{offset:0,color:e?.foreground??exports.IColor.Scheme.Bg1},{offset:1,color:e?.background??exports.IColor.Scheme.Accent1}]}:t?{...t}:null),properties:{stops:{shorthand:(t,e)=>t,arrayType:{shorthand:(t,e)=>t=Qg(t,e.parseColor.bind(e)),properties:{color:tp}}}}},sp={shorthand:(t,e)=>{if("object"==typeof t){const e=t;(e.foreground||e.background||e.patternType)&&(e.type=exports.IFill.Type.Pattern,e.patternType=e.patternType??exports.IFill.BuiltInSheetPattern.Solid)}return t},merge:(t,e,r)=>{if(t.background&&t.foreground)return t;e?.toJSON&&(e=e.toJSON());const n=exports.IFill.BuiltInSheetPattern.MediumGray;return e?.type===exports.IFill.Type.Pattern?{...e,...t}:e?.type===exports.IFill.Type.Solid?{patternType:n,...t,foreground:e?.color??exports.IColor.Named.WindowText,background:exports.IColor.Scheme.Bg1}:e?.type===exports.IFill.Type.Gradient?{patternType:n,...t,foreground:e?.stops?.[0]?.color??exports.IColor.Named.WindowText,background:e?.stops?.[1]?.color??exports.IColor.Scheme.Bg1}:t?{type:exports.IFill.Type.Pattern,patternType:exports.IFill.BuiltInSheetPattern.Solid,foreground:exports.IColor.Named.WindowText,background:exports.IColor.Scheme.Bg1,...t}:null},properties:{foreground:tp,background:tp}},ip={shorthand:(t,e)=>{const r=[rp,np,op,sp];for(let n=0;n<r.length;n++){let o=r[n]?.shorthand?.(t,e);if(o?.type)return o}return t},getSubType:t=>t.type===exports.IFill.Type.None?rp:t.type===exports.IFill.Type.Solid?np:t.type===exports.IFill.Type.Gradient?op:t.type===exports.IFill.Type.Pattern?sp:null},ap={properties:{font:{shorthand:(t,e)=>{if("string"==typeof t){const e=Au(t);if(e){const t={};if(e.family&&(t.family=e.family),e.fallbacks&&(t.fallbacks=e.fallbacks),e.size&&(t.size=Sg(e.size)),Object.keys(e).length>0)return t}}return t},properties:{family:{shorthand:(t,e)=>Au(t)?.family??null},fallbacks:{shorthand:(t,e)=>{if("string"!=typeof t)return t;let r=Au(t);if(!r)return null;let n=[r.family];return r.fallbacks&&(n=n.concat(r.fallbacks)),n}},size:{shorthand:(t,e)=>{let r=t;return"string"==typeof t&&(r=Sg(t,e.getNormal().getFont().getSize())),isNaN(r)||"number"!=typeof r?null:(r=Math.max(1,Math.min(mt.roundAccurately(r,1),409)),r)}},weight:{shorthand:(t,e)=>{if("string"!=typeof t)return t;const r=(t=>{let e=400;if(e="number"==typeof t?t:parseFloat(t),!isNaN(e))return e;if("string"==typeof t){const e=mt.textToKey(t),r=og.get(e);if(r)return r}return e})(t);return isNaN(r)||"number"!=typeof r?null:r}},underline:{shorthand:(t,e)=>t?!0===t?exports.IFont.UnderlineStyle.Single:Nu(t):exports.IFont.UnderlineStyle.None}}},fill:ip,alignment:{properties:{indent:{shorthand:(t,e)=>{let r=t;return"string"==typeof t&&(r=parseFloat(t)),isNaN(r)||"number"!=typeof r?null:r}},rotation:{shorthand:(t,e)=>{let r=t;return"string"==typeof t&&(r=parseFloat(t)),isNaN(r)||"number"!=typeof r?null:(r%=360,r<0&&(r+=360),r)}}}},border:{shorthand:(t,e)=>{if("string"==typeof t){const e=Bg(t);return{left:e,right:e,top:e,bottom:e,horizontal:null,vertical:null,diagonalUp:null,diagonalDown:null}}return t.isIBorder?t.getProperties():t},properties:{top:ep,left:ep,right:ep,bottom:ep,horizontal:ep,vertical:ep,diagonalUp:ep,diagonalDown:ep}},numberFormat:{shorthand:(t,e)=>{if("string"==typeof t){let e=exports.NumberFormat.Styles.lookupDefault(t);return void 0!==e?e:t}if("number"==typeof t){return Na(t)}return null}}}},lp={properties:{style:ap}},cp=Object.freeze({displayText:"",conditionalColor:null,repeatChars:mt.EmptyArray,spacingChars:mt.EmptyArray,repeatPlaceholder:null,formattedRuns:Object.freeze({runs:mt.EmptyArray,length:0,width:0,lastRepeatIndex:-1}),canWrap:!1,asDate:null,isDateFormat:!1,isTimeFormat:!1,isDate1904:!1}),hp=(e,r,n,o,s,i=!1)=>{if(null==e)return cp;let a="",l=null,c=null,h=null;if(n===t.Error)a=e.getLabel();else if(n===t.RichData)a="(Rich Object)";else if(n===t.Boolean)a=e?"TRUE":"FALSE";else if(o)try{a=$o(o,e,{date1904:i,spacingCharacter:"",digitCharacter:"",onRepeatChar:(t,e)=>{c||(c=[]),c.push({offset:t,char:e})},onSpacingChar:(t,e)=>{h||(h=[]),h.push({offset:t,char:e})},onDigitChar:t=>{h||(h=[]),h.push({offset:t,char:"0"})}})}catch(t){}const d=Rs(o),u=Ms(o),g=d||u?ps(e,i):null;(d||u)&&parseFloat(e)<0&&(l="#",a=l.repeat(5));let p=null;const m=r.getAlignment(),f=m.getHorizontal(),_=m.getVertical(),S=m.getOverflow(),w=!(n!==t.String||f===exports.ITextFrame.HorizontalAlignment.Fill||null!==c&&0!==c.length||S!==exports.ITextFrame.Overflow.Wrap&&f!==exports.ITextFrame.HorizontalAlignment.Justify&&f!==exports.ITextFrame.HorizontalAlignment.Distributed&&_!==exports.ITextFrame.VerticalAlignment.Justify&&_!==exports.ITextFrame.VerticalAlignment.Distributed);let y=a;w||n!==t.String||(y=y.replaceAll(/\n/g,""));const x=h?.length>0||c?.length>0;if(S!==exports.ITextFrame.Overflow.Wrap||x){const t=r.getFont();let e=t.getSize();t.isSuperSub()&&(e*=t.getSuperSubScale());let n=[];for(let t=0;t<h?.length;t++){const o=h[t],s=r.measureText(o.char,e).width;n.push({...o,type:"spacing",width:s})}if(c?.length>0){const t=c[c.length-1],o=r.measureText(t.char,e).width;n.push({...t,type:"repeat",width:o})}n=n.sort((t,e)=>t.offset-e.offset);let o=[],s=0,i=0,a=-1,l=-1;const d=t=>{const n={type:"text",width:r.measureText(t,e).width,text:t};o.push(n),i+=n.width,s+=t.length};for(let t=0;t<n.length;t++){const e=n[t];if(l!==e.offset){const t=y.substring(s,e.offset);t&&d(t)}const r={type:e.type,width:e.width,text:e.char};"repeat"!==e.type?i+=r.width:a=o.length,o.push(r),l=e.offset}if(s<y.length){let t=y.substring(s,y.length);t&&d(t)}p={runs:Object.freeze(o),length:s,width:i,lastRepeatIndex:a}}const C=ss(o,e),b={displayText:a??"",conditionalColor:C?s(C):null,repeatChars:c??mt.EmptyArray,spacingChars:h??mt.EmptyArray,repeatPlaceholder:l,formattedRuns:p,canWrap:w,asDate:g,isDateFormat:d,isTimeFormat:u,isDate1904:i};return Object.freeze(b)},dp=Object.freeze({fallbacks:mt.EmptyArray,weight:400,style:exports.IFont.Style.Normal,fill:exports.IColor.Scheme.Tx1,letterSpacing:null,underline:exports.IFont.UnderlineStyle.None,strike:!1,scheme:exports.IFont.Scheme.Minor,verticalAlign:exports.IFont.VerticalAlignment.Baseline,shadow:!1,outline:!1,extend:!1}),up=Object.freeze({style:exports.IBorder.StrokeStyle.None,color:exports.IColor.Scheme.Tx1}),gp=Object.freeze({[exports.IBorder.Edge.Top]:up,[exports.IBorder.Edge.Left]:up,[exports.IBorder.Edge.Bottom]:up,[exports.IBorder.Edge.Right]:up,[exports.IBorder.Edge.Horizontal]:up,[exports.IBorder.Edge.Vertical]:up,[exports.IBorder.Edge.DiagonalUp]:up,[exports.IBorder.Edge.DiagonalDown]:up}),pp=Object.freeze({horizontal:exports.ITextFrame.HorizontalAlignment.General,vertical:exports.ITextFrame.VerticalAlignment.Bottom,indent:0,relativeIndent:0,overflow:exports.ITextFrame.Overflow.Visible,rotation:0,stacked:!1,quotePrefix:!1,justifyLastLine:!1,readingOrder:exports.ITextFrame.ReadingDirection.Auto,readingDirection:exports.ITextFrame.ReadingDirection.Auto}),mp=Object.freeze({locked:!1,formulaHidden:!1}),fp=Object.freeze({fill:{type:exports.IFill.Type.None},numberFormat:"General",alignment:pp,font:dp,border:gp,protection:mp,quotePrefix:!1,namedStyle:null}),_p=(()=>{const t=[{named:exports.IStyle.BuiltInName.Normal},{named:exports.IStyle.BuiltInName.RowLevel},{named:exports.IStyle.BuiltInName.ColLevel},{named:exports.IStyle.BuiltInName.Comma,numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)'},{named:exports.IStyle.BuiltInName.Currency,numberFormat:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'},{named:exports.IStyle.BuiltInName.Percent,numberFormat:"0%"},{named:exports.IStyle.BuiltInName.Comma0,numberFormat:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)'},{named:exports.IStyle.BuiltInName.Currency0,numberFormat:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)'},{named:exports.IStyle.BuiltInName.Hyperlink,font:{...dp,fill:exports.IColor.Scheme.Hlink,underline:exports.IFont.UnderlineStyle.Single}},{named:exports.IStyle.BuiltInName.FollowedHyperlink,font:{...dp,fill:exports.IColor.Scheme.FolHlink,underline:exports.IFont.UnderlineStyle.Single}},{named:exports.IStyle.BuiltInName.Note,fill:"FFFFFFCC",font:{...dp,style:exports.IFont.Style.Normal,fill:exports.IColor.Scheme.Tx1},border:{left:{style:exports.IBorder.StrokeStyle.Thin,color:"FFB2B2B2"},top:{style:exports.IBorder.StrokeStyle.Thin,color:"FFB2B2B2"},right:{style:exports.IBorder.StrokeStyle.Thin,color:"FFB2B2B2"},bottom:{style:exports.IBorder.StrokeStyle.Thin,color:"FFB2B2B2"}}},{named:exports.IStyle.BuiltInName.WarningText,font:{...dp,fill:"FFFF0000"}},{named:exports.IStyle.BuiltInName.Unknown12},{named:exports.IStyle.BuiltInName.Unknown13},{named:exports.IStyle.BuiltInName.Unknown14},{named:exports.IStyle.BuiltInName.Title,font:{...dp,size:18,fill:exports.IColor.Scheme.Tx2}},{named:exports.IStyle.BuiltInName.Heading1,font:{...dp,size:15,weight:"bold",fill:exports.IColor.Scheme.Tx2},border:{bottom:{style:exports.IBorder.StrokeStyle.Thick,color:exports.IColor.Scheme.Accent1}}},{named:exports.IStyle.BuiltInName.Heading2,font:{...dp,size:13,weight:"bold",fill:exports.IColor.Scheme.Tx2},border:{bottom:{style:exports.IBorder.StrokeStyle.Thick,color:"accent1 lumMod 40, lumOff 60"}}},{named:exports.IStyle.BuiltInName.Heading3,font:{...dp,weight:"bold",fill:exports.IColor.Scheme.Tx2},border:{bottom:{style:exports.IBorder.StrokeStyle.Medium,color:"accent1 lumMod 40, lumOff 60"}}},{named:exports.IStyle.BuiltInName.Heading4,font:{weight:"bold",fill:exports.IColor.Scheme.Tx2,...dp}},{named:exports.IStyle.BuiltInName.Input,fill:"FFFFCC99",font:{...dp,fill:"FF3F3F76"},border:{left:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},top:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},right:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},bottom:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"}}},{named:exports.IStyle.BuiltInName.Output,fill:"FFF2F2F2",font:{...dp,fill:"FF3F3F3F"},border:{left:{style:exports.IBorder.StrokeStyle.Thin,color:"FF3F3F3F"},top:{style:exports.IBorder.StrokeStyle.Thin,color:"FF3F3F3F"},right:{style:exports.IBorder.StrokeStyle.Thin,color:"FF3F3F3F"},bottom:{style:exports.IBorder.StrokeStyle.Thin,color:"FF3F3F3F"}}},{named:exports.IStyle.BuiltInName.Calculation,fill:"FFF2F2F2",font:{...dp,fill:"FFFA7D00"},border:{left:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},top:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},right:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"},bottom:{style:exports.IBorder.StrokeStyle.Thin,color:"FF7F7F7F"}}},{named:exports.IStyle.BuiltInName.CheckCell,fill:"FFA5A5A5",font:{...dp,fill:exports.IColor.Scheme.Bg1},border:{left:{style:exports.IBorder.StrokeStyle.Double,color:"FF3F3F3F"},top:{style:exports.IBorder.StrokeStyle.Double,color:"FF3F3F3F"},right:{style:exports.IBorder.StrokeStyle.Double,color:"FF3F3F3F"},bottom:{style:exports.IBorder.StrokeStyle.Double,color:"FF3F3F3F"}}},{named:exports.IStyle.BuiltInName.LinkedCell,font:{...dp,fill:"FFFA7D00"},border:{bottom:{style:exports.IBorder.StrokeStyle.Double,color:"FFFF8001"}}},{named:exports.IStyle.BuiltInName.Total,font:{...dp,weight:"bold",fill:exports.IColor.Scheme.Tx1},border:{top:{style:exports.IBorder.StrokeStyle.Thin,color:exports.IColor.Scheme.Accent1},bottom:{style:exports.IBorder.StrokeStyle.Double,color:exports.IColor.Scheme.Accent1}}},{named:exports.IStyle.BuiltInName.Good,fill:"FFC6EFCE",font:{...dp,fill:"FF006100"}},{named:exports.IStyle.BuiltInName.Bad,fill:"FFFFC7CE",font:{...dp,fill:"FF9C0006"}},{named:exports.IStyle.BuiltInName.Neutral,fill:"FFFFEB9C",font:{...dp,fill:"FF9C5700"}},{named:exports.IStyle.BuiltInName.Accent1},{named:exports.IStyle.BuiltInName.Accent1_20},{named:exports.IStyle.BuiltInName.Accent1_40},{named:exports.IStyle.BuiltInName.Accent1_60},{named:exports.IStyle.BuiltInName.Accent2},{named:exports.IStyle.BuiltInName.Accent2_20},{named:exports.IStyle.BuiltInName.Accent2_40},{named:exports.IStyle.BuiltInName.Accent2_60},{named:exports.IStyle.BuiltInName.Accent3},{named:exports.IStyle.BuiltInName.Accent3_20},{named:exports.IStyle.BuiltInName.Accent3_40},{named:exports.IStyle.BuiltInName.Accent3_60},{named:exports.IStyle.BuiltInName.Accent4},{named:exports.IStyle.BuiltInName.Accent4_20},{named:exports.IStyle.BuiltInName.Accent4_40},{named:exports.IStyle.BuiltInName.Accent4_60},{named:exports.IStyle.BuiltInName.Accent5},{named:exports.IStyle.BuiltInName.Accent5_20},{named:exports.IStyle.BuiltInName.Accent5_40},{named:exports.IStyle.BuiltInName.Accent5_60},{named:exports.IStyle.BuiltInName.Accent6},{named:exports.IStyle.BuiltInName.Accent6_20},{named:exports.IStyle.BuiltInName.Accent6_40},{named:exports.IStyle.BuiltInName.Accent6_60},{named:exports.IStyle.BuiltInName.ExplanatoryText,font:{...dp,style:exports.IFont.Style.Italic,fill:"FF7F7F7F"}}];for(let e=29;e<=52;e++){const r=(e-29)%4,n=Math.floor((e-29)/4);let o="";1===r?o=" lumMod 20, lumOff 80":2===r?o=" lumMod 40, lumOff 60":3===r&&(o=" lumMod 60, lumOff 40"),t[e].fill=`accent${n+1}${o}`,t[e].font={fill:0===r?exports.IColor.Scheme.Bg1:exports.IColor.Scheme.Tx1,...dp}}return mt.deepFreeze(t)})();const Sp=new class{_svgImage(t,e,r,n=8){return{backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${n}' height='${n}' viewBox='0 0 ${n} ${n}' shape-rendering='crispEdges' %3E%3Cpath d='${r}' stroke='${t}' %3E%3C/path%3E%3C/svg%3E")`,backgroundRepeat:"repeat",backgroundSize:`${n}px ${n}px`,backgroundPositionX:"0px",backgroundPositionY:"0px",backgroundPosition:""+-n,backgroundColor:e}}toCSS(t,e,r){return t&&t!==exports.IFill.BuiltInSheetPattern.None?t===exports.IFill.BuiltInSheetPattern.Solid?{background:r}:t===exports.IFill.BuiltInSheetPattern.Gray0625?this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 4.5 2.5 L 4.5 3.5 M 4.5 6.5 L 4.5 7.5",8):t===exports.IFill.BuiltInSheetPattern.LightGray?this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 0.5 2.5 L 0.5 3.5 M 2.5 -0.5 L 2.5 0.5 M 2.5 1.5 L 2.5 2.5 M 2.5 3.5 L 2.5 4.5",4):t===exports.IFill.BuiltInSheetPattern.MediumGray?this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 1.5 1.5 L 1.5 2.5 M 1.5 -0.5 L 1.5 0.5 M -0.5 -0.5 L -0.5 0.5",2):t===exports.IFill.BuiltInSheetPattern.DarkGray?this._svgImage(e,r,"M 0 0 L 0 4 M 1 1 L 1 2 M 1 3 L 1 4 M 2 0 L 2 4 M 3 0.5 L 3 1.5 M 3 2.5 L 3 3.5 M 4 0 L 4 4",4):t===exports.IFill.BuiltInSheetPattern.LightHorizontal?this._svgImage(e,r,"M 0 2 L 4 2",4):t===exports.IFill.BuiltInSheetPattern.DarkHorizontal?this._svgImage(e,r,"M 0 2 L 4 2 M 0 3 L 4 3",4):t===exports.IFill.BuiltInSheetPattern.LightVertical?this._svgImage(e,r,"M 2 0 L 2 4",4):t===exports.IFill.BuiltInSheetPattern.DarkVertical?this._svgImage(e,r,"M 2 0 L 2 4 M 3 0 L 3 4",4):t===exports.IFill.BuiltInSheetPattern.LightUp?this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5",4):t===exports.IFill.BuiltInSheetPattern.DarkUp?this._svgImage(e,r,"M 0.5 -0.5 L 0.5 1.5 M 0.5 3.5 L 0.5 4.5 M 1.5 2.5 L 1.5 4.5 M 2.5 1.5 L 2.5 3.5 M 3.5 0.5 L 3.5 2.5 M 1.5 -0.5 L 1.5 0.5",4):t===exports.IFill.BuiltInSheetPattern.LightDown?this._svgImage(e,r,"M 0.5 0 L 0.5 1 M 1.5 1 L 1.5 2 M 2.5 2 L 2.5 3 M 3.5 3 L 3.5 4",4):t===exports.IFill.BuiltInSheetPattern.DarkDown?this._svgImage(e,r,"M 0.5 -0.5 L 0.5 2 M 1.5 1 L 1.5 3 M 2.5 2 L 2.5 4 M 3.5 3 L 3.5 5 M 3.5 -0.5 L 3.5 1.0",4):t===exports.IFill.BuiltInSheetPattern.LightGrid?this._svgImage(e,r,"M 1.5 -0.5 L 1.5 4.5 M -0.5 1.5 L 4.5 1.5",4):t===exports.IFill.BuiltInSheetPattern.DarkGrid?this._svgImage(e,r,"M 0.5 -0.5 L 0.5 1.5 M 1.5 -0.5 L 1.5 1.5 M 2.5 1.5 L 2.5 3.5 M 3.5 1.5 L 3.5 3.5 M 0.5 3.5 L 0.5 4.5 M 1.5 3.5 L 1.5 4.5",4):t===exports.IFill.BuiltInSheetPattern.LightTrellis?this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5 M 1.5 1.5 L 1.5 2.5 M 3.5 3.5 L 3.5 4.5 M 3.5 -0.5 L 3.5 0.5",4):t===exports.IFill.BuiltInSheetPattern.DarkTrellis?this._svgImage(e,r,"M 0 0 L 4 0 M 0 1 L 2 1 M 0 2 L 4 2 M 2 3 L 4 3 M 0 4 L 4 4",4):(exports.IFill.BuiltInSheetPattern.Custom,this._svgImage(e,r,"M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 2.5 2.5 L 2.5 3.5 M 2.5 6.5 L 2.5 7.5 M 4.5 0.5 L 4.5 1.5 M 4.5 4.5 L 4.5 5.5 M 6.5 2.5 L 6.5 3.5 M 6.5 6.5 L 6.5 7.5",8)):{background:"none"}}},wp=(t,e,r)=>{if(void 0===e)return;if(null===e)return null;if(e.isIStyle)return e._p.getProperties();let n=null;if("function"==typeof e){n=e("function"==typeof r?r():r)}else n=e;return n};class yp{constructor(t,e){this._c=t,this._p=Object.freeze(Array.isArray(e)?e:[e??null])}value(t){const e=this._p;for(let r=e.length-1;r>=0;r--){const n=e[r];if(!n)continue;const o=n[t];if(void 0!==o)return o}}values(t){const e=this._p,r=e.length;let n;for(let o=0;o<r;o++){const r=e[o];if(!r)continue;const s=r[t];void 0!==s&&(void 0===n&&(n=[]),n.push(s))}return n}getProperties(){const t=this._p;return t?t[t.length-1]:null}toJSON(){return null}}class xp{constructor(t,e){this._c=t,this._p=Object.freeze(e)}_value(t){const e=this._p;for(let r=e.length-1;r>=0;r--){const n=e[r];if(!n)continue;const o=n[t];if(void 0!==o)return o}}_values(t){const e=this._p,r=e.length;let n;for(let o=0;o<r;o++){const r=e[o];if(!r)continue;const s=r[t];void 0!==s&&(void 0===n&&(n=[]),n.push(s))}return n}getProperties(){const t=this._p;return t?t[t.length-1]:null}toJSON(){return null}}class Cp extends xp{constructor(t,e,r){super(e,r),this._edge=t}getStyle(){return this._value("style")}getColor(){const t=this._value("color");return t?this._c.parseColor(t):null}isNone(){return this.getStyle()===exports.IBorder.StrokeStyle.None}toCSS(){const t=Ig(this);switch(this._edge){case exports.IBorder.Edge.Left:return{borderLeft:t};case exports.IBorder.Edge.Right:return{borderRight:t};case exports.IBorder.Edge.Top:return{borderTop:t};case exports.IBorder.Edge.Bottom:return{borderBottom:t};case exports.IBorder.Edge.DiagonalUp:case exports.IBorder.Edge.DiagonalDown:return{borderDiagonalUp:t}}}get isIStroke(){return!0}}class bp extends xp{getLeft(){return new Cp(exports.IBorder.Edge.Left,this._c,this._values(exports.IBorder.Edge.Left))}getRight(){return new Cp(exports.IBorder.Edge.Right,this._c,this._values(exports.IBorder.Edge.Right))}getTop(){return new Cp(exports.IBorder.Edge.Top,this._c,this._values(exports.IBorder.Edge.Top))}getBottom(){return new Cp(exports.IBorder.Edge.Bottom,this._c,this._values(exports.IBorder.Edge.Bottom))}getDiagonalUp(){return new Cp(exports.IBorder.Edge.DiagonalUp,this._c,this._values(exports.IBorder.Edge.DiagonalUp))}getDiagonalDown(){return new Cp(exports.IBorder.Edge.DiagonalDown,this._c,this._values(exports.IBorder.Edge.DiagonalDown))}isEmpty(){return!1}get isIBorder(){return!0}}class Ep extends xp{get isITextBoxAlignment(){return!0}getHorizontal(){return this._value("horizontal")}getVertical(){return this._value("vertical")}getIndent(){return this._value("indent")}getRelativeIndent(){return this._value("relativeIndent")}getOverflow(){return this._value("overflow")}getRotation(){return this._value("rotation")}getStacked(){return this._value("stacked")}getJustifyLastLine(){return this._value("justifyLastLine")}getReadingDirection(){return this._value("readingDirection")}}class vp extends xp{isEqualMeasure(t){return!!t&&(this.getFamily()===t.getFamily()&&(!!mt.isEqualArrays(this.getFallbacks(),t.getFallbacks())&&(this.getSize()===t.getSize()&&(this.getWeight()===t.getWeight()&&(this.getStyle()===t.getStyle()&&(this.getStrike()===t.getStrike()&&(this.getScheme()===t.getScheme()&&(this.getShadow()===t.getShadow()&&(this.getOutline()===t.getOutline()&&(this.getLetterSpacing()===t.getLetterSpacing()&&this.getVerticalAlignment()===t.getVerticalAlignment()))))))))))}isSuperSub(){const t=this.getVerticalAlignment();return t===exports.IFont.VerticalAlignment.Sub||t===exports.IFont.VerticalAlignment.Super}isSuperScript(){const t=this.getVerticalAlignment();return t===exports.IFont.VerticalAlignment.Sub||t===exports.IFont.VerticalAlignment.Super}getSuperSubScale(){return this.getFamily(),this.getSize(),this.getVerticalAlignment(),.6}getSuperSubShift(){return this.getFamily(),t=this.getSize(),(e=this.getVerticalAlignment())===exports.IFont.VerticalAlignment.Super?-t/3:e===exports.IFont.VerticalAlignment.Sub?t/5:0;var t,e}toCSS(t,e=1,r=!1){const n={fontFamily:Bu(this.getFamily(),this.getFallbacks()),letterSpacing:`${this.getLetterSpacing()}px`,fontWeight:this.getWeight(),fontStyle:this.getStyle(),textDecoration:Tu(this.getUnderline(),this.getStrike()),color:this.getFill().toCSS(t),fontSize:`${mt.roundAccurately(this.getSize()*exports.IFont.getDeviceScale()*e,2)}px`,textRendering:"geometricPrecision"};if(r){const r=this._c.getNormal().getFont().toCSS(t,e,!1),o=n.textDecoration,s=n.fontWeight;mt.removeEqualValues(n,r),o&&(n.textDecoration=o),s&&(n.fontWeight=s)}return n}getFamily(){return this._value("family")??this._c.getTheme().getFontScheme().getMinorFont()}getFallbacks(){let t=this._value("fallbacks")??this._c.getTheme().getFontScheme().getMinorFallbacks()??mt.EmptyArray;return"Aptos Narrow"===this.getFamily()&&(t=["Calibri",...t]),t}getSize(){return this._value("size")??this._c.getDefaultFontSize()??11}getWeight(){return this._value("weight")}getStyle(){return this._value("style")}getFill(){const t=this._value("fill");return this._c.parseColor(t??exports.IColor.Scheme.Bg1)}getLetterSpacing(){return this._value("letterSpacing")??this.getSize()/-25}getUnderline(){return this._value("underline")}getStrike(){return this._value("strike")}getScheme(){return this._value("scheme")}getVerticalAlignment(){return this._value("verticalAlign")}getShadow(){return this._value("shadow")}getOutline(){return this._value("outline")}getExtend(){return this._value("extend")}get isIStyledFont(){return!0}}const Ip=Object.freeze({background:"none"});class Ap extends xp{getType(){return exports.IFill.Type.None}toCSS(t){return Ip}toJSON(){return{type:exports.IFill.Type.None}}}class Rp extends xp{getType(){return exports.IFill.Type.Solid}getColor(){return this._c.parseColor(this._value("color")??exports.IColor.Scheme.Bg1)}toCSS(t){return{background:this.getColor().toCSS(t)}}toJSON(){return{type:exports.IFill.Type.Solid,color:this.getColor()?.toString()??null}}}class Mp extends xp{getOffset(){return this._value("offset")??0}getColor(){return this._c.parseColor(this._value("color")??exports.IColor.Scheme.Bg1)}}class Tp extends xp{getType(){return exports.IFill.Type.Gradient}getStops(){const t=this._value("stops")??[],e=[],r=this._c;for(let n=0;n<t.length;n++){const o=t[n];e.push(new Mp(r,[o]))}return e}getGradientType(){return this._value("gradientType")??exports.IFill.GradientType.Linear}getAngle(){return this._value("angle")??0}getFillTo(){return this._value("fillTo")??null}toCSS(t,e){const r=Eg(this,t,e);return r?{background:r}:null}toJSON(){const t={type:exports.IFill.Type.Gradient};if(this.getStops().length>0){let e=[];for(let t=0;t<e.length;t++)e.push({offset:e[t].offset,color:e[t].color.toString()});t.stops=e}return 0!==this.getAngle()&&(t.angle=this.getAngle()),this.getGradientType()!==exports.IFill.GradientType.Linear&&(t.gradientType=this.getGradientType()),this.getFillTo()&&(t.fillTo=this.getFillTo()),t}}class Fp extends xp{getType(){return exports.IFill.Type.Pattern}getBackground(){const t=this._value("background")??exports.IColor.Named.Window;return this._c.parseColor(t)}getForeground(){return this._c.parseColor(this._value("foreground")??exports.IColor.Scheme.Tx1)}getPatternType(){return this._value("patternType")??exports.IFill.BuiltInSheetPattern.None}toCSS(t){const e=this.getBackground().toCSS(t),r=this.getForeground().toCSS(t);return this.getPatternType()===exports.IFill.BuiltInSheetPattern.None?{background:"none"}:this.getPatternType()===exports.IFill.BuiltInSheetPattern.Solid?{background:this.getForeground().toCSS(t)}:Sp.toCSS(this.getPatternType(),r,e)}toJSON(){const t={type:exports.IFill.Type.Pattern};this.getPatternType()!==exports.IFill.BuiltInSheetPattern.None&&(t.patternType=this.getPatternType());const e=this.getForeground();e&&(t.foreground=e.toString());const r=this.getBackground();return r&&(t.background=r.toString()),t}}class Np{constructor(t){this._options=t,this._c=t.styles,this._p=new yp(t.styles,t.properties),this._hasVisibleStyling=!this.getFill()||this.getFill().getType()!==exports.IFill.Type.None||!this.getBorder().isEmpty()}hasVisibleStyling(){return this._hasVisibleStyling}isNormal(){return!1}getNamed(){const t=this._p.value("named")??exports.IStyle.BuiltInName.Normal;return this._c.getNamed(t)}createTemporaryStyle(t){const e=this._c,r=wp(0,t,this),n=this._options,o=n.range,s=n.direct.cloneWithUpdate(r);return kp(e,s,o)}measureText(t,e=this.getFont().getSize(),r,n){const o=this.getFont();r||(r=o.getFamily());let s=o.getFallbacks();"Aptos Narrow"===r&&(s=["Calibri",...s]);const i=Bu(r,s);return exports.IFont.getSharedMeasurer()(t,e*exports.IFont.getDeviceScale(),i,{isBold:o.getWeight()>400,isItalic:o.getStyle().includes("italic"),letterSpacing:o.getLetterSpacing(),...n})}createTemporaryTextFrame(t,e=!1){return Gi(t,this.getFont(),this.getAlignment(),e)}getBestFit(){if(void 0!==this._bestFit)return this._bestFit;const t=this.getInsets(),e=this.measureText("My");return this._bestFit={width:null,height:e.lineHeight+t.top+t.bottom},this._bestFit}getInsets(){if(void 0!==this._insets)return this._insets;const t=(this.getFont().getSize(),1),e=(r=this.getFont().getSize(),Math.max(2,Math.round(r<225?r/5:r/3.5)));var r;const n={top:t,left:e,bottom:t,right:e},o=this._p,s=o?.value("insets");return s&&(void 0!==s.top&&(n.top+=s.top),void 0!==s.left&&(n.left+=s.left),void 0!==s.bottom&&(n.bottom+=s.bottom),void 0!==s.right&&(n.right+=s.right)),this._insets=Object.freeze(n),this._insets}getBorder(){return new bp(this._c,this._p.values("border"))}getFont(){return new vp(this._c,this._p.values("font"))}getFill(){const t=this._p;let e=t.values("fill"),r=t.value("fill");return r.type===exports.IFill.Type.None?new Ap(this._c,e):r.type===exports.IFill.Type.Solid||!r.type&&r.color?new Rp(this._c,e):r.type===exports.IFill.Type.Gradient?new Tp(this._c,e):r.type===exports.IFill.Type.Pattern?new Fp(this._c,e):new Ap(this._c,e)}getAlignment(){return new Ep(this._c,this._p.values("alignment"))}getNumberFormat(){const t=this._p.value("numberFormat");return"number"==typeof t?Na(t):t}getQuotePrefix(){return this._p.value("quotePrefix")}get isIStyle(){return!0}}const kp=(t,e,r)=>{const n=r?.rowStart??U.EmptyCell.rowIndex,o=r?.colStart??U.EmptyCell.colIndex,s=[fp],i=t.getNormalRanged(),a=i.getPropertiesAt(n,o,null);if(a&&s.push(a),!e){return new Op({styles:t,range:r,properties:s,layerTypes:null,direct:i})}const l=e.getPropertiesAt(n,o,null);l&&s.push(l);return new Np({styles:t,range:r,properties:s,direct:e})};class Op extends Np{isNormal(){return!0}}const Bp=(t,e)=>{if(t&&!e||e&&!t)return!1;if(t===e)return!0;if(t.style!==e.style)return!1;if(t.color===e.color)return!0;let r=t.color;(t&&t.color).isIColor&&(r=t.color.toString());let n=e.color;return(e&&e.color).isIColor&&(n=e.color.toString()),r===n};class Lp{constructor(t,e,r,n){this._c=t,this._r=e,this._p=r??null,this._t=n??null,this._e=null===this._p||1===Object.keys(this._p).length&&this._p.named===exports.IStyle.BuiltInName.Normal}isEmpty(){return this._e}getProperties(){return this._p}getCoords(){return this._r}cloneWithUpdate(t){if(void 0===t)return this;const e=this._c,r=this._r,n=this._p,o=exports.ft.resolveTypedUpdates(t,ap,e,n);return new Lp(e,r,o)}copyTo(t,e){const r=this._c,n=this._r,o=t.rowStart-n.rowStart,s=t.colStart-n.colStart;let i=null;return U.isEqualRanges(n,this._t)||(i=U.translateRange(n,o,s)),new Lp(r,t,this._p,i)}canTile(t,e){return!this._p.border}_createShifted(t){return new Lp(this._c,t,this._p)}getShifted(t){return t.after?{...t.after,value:this._createShifted(U.sanitizeRange(t.after))}:null}getSplit(t,e){const r=this._c,n=this._p,o=this._r;let s=n;const i=t[0];let a=n;const l=t[1],c=n?n.border:null;if(c){const t=e===exports.t.Orientation.Column;if(t?void 0!==c.left||void 0!==c.right||void 0!==c.vertical:void 0!==c.top||void 0!==c.bottom||void 0!==c.horizontal){s={...s};const e=this._splitBorderRange(c,o,i,t);e?s.border=e:null===e&&delete s.border,a={...a};const r=this._splitBorderRange(c,o,l,t);r?a.border=r:null===r&&delete a.border}}const h=this._t;return[new Lp(r,t[0],s,h),new Lp(r,t[1],a,h)]}getMerged(t,e,r){const n=r===exports.t.Orientation.Column,o=this._p,s=t._p;if(o&&!s||s&&!o||!o&&!s)return;let i=Object.keys(o),a=Object.keys(s);if(i.length!==a.length)return;for(let t=0;t<i.length;t++){const e=i[t];if("border"===e)continue;const r=o[e],n=s[e];if(!mt.deepEqual(r,n))return}const l=o.border,c=s.border;if(l&&!c||c&&!l)return;const h=this._c;if(l||c){const r=n?exports.IBorder.Edge.Top:exports.IBorder.Edge.Left,s=n?exports.IBorder.Edge.Bottom:exports.IBorder.Edge.Right;if(!Bp(l[r],c[r])||!Bp(l[s],c[s]))return;const i=this._r,a=t._r,d=1+(n?i.rowEnd-i.rowStart:i.colEnd-i.colStart),u=1+(n?i.colEnd-i.colStart:i.rowEnd-i.rowStart),g=1+(n?a.colEnd-a.colStart:a.rowEnd-a.rowStart),p=n?exports.IBorder.Edge.Horizontal:exports.IBorder.Edge.Vertical;if(d>1&&!Bp(l[p],c[p]))return;const m=n?exports.IBorder.Edge.Right:exports.IBorder.Edge.Bottom,f=n?exports.IBorder.Edge.Left:exports.IBorder.Edge.Top;if(!Bp(l[m],c[f]))return;const _=n?exports.IBorder.Edge.Vertical:exports.IBorder.Edge.Horizontal,S=l[m];if(u>1&&!Bp(S,l[_]))return;const w=1===g?c[f]:c[_];if(g>1&&!Bp(w,c[_]))return;if(!Bp(S,w))return;const y={border:{[r]:l[r],[s]:l[s],[p]:l[p],[_]:S,[f]:l[f],[m]:c[m]}},x=exports.ft.resolveTypedUpdates(y,ap,h,o);return new Lp(h,e,x)}return new Lp(h,e,this._p)}hasTrailingEdge(){return!0}isMergeOnShift(){return!0}_splitBorderRange(t,e,r,n){const o=n?exports.IBorder.Edge.Left:exports.IBorder.Edge.Top,s=n?exports.IBorder.Edge.Right:exports.IBorder.Edge.Bottom,i=n?exports.IBorder.Edge.Vertical:exports.IBorder.Edge.Horizontal,a=n?e.colStart:e.rowStart,l=n?e.colEnd:e.rowEnd,c=n?r.colStart:r.rowStart,h=n?r.colEnd:r.rowEnd;let d={...t};return delete d[o],delete d[s],delete d[i],a===c?t[o]&&(d[o]=t[o]):t[i]&&(d[o]=t[i]),l===h?t[s]&&(d[s]=t[s]):t[i]&&(d[s]=t[i]),h-c>0&&t[i]&&(d[i]=t[i]),0===Object.keys(d).length?null:d}_localizeBorderRange(t,e,r){if(!t)return;let n=null;const o=e.rowStart,s=e.rowEnd,i=r.rowStart,a=r.rowEnd;t.top&&i===o&&(n=n??{},n.top=t.top),t.bottom&&a===s&&(n=n??{},n.bottom=t.bottom),t.horizontal&&(a-i>0&&(n=n??{},n.horizontal=t.horizontal),i>o&&(n=n??{},n.top=t.horizontal),a<s&&(n=n??{},n.bottom=t.horizontal));const l=e.colStart,c=e.colEnd,h=r.colStart,d=r.colEnd;return t.left&&h===l&&(n=n??{},n.left=t.left),t.right&&d===c&&(n=n??{},n.right=t.right),t.vertical&&(d-h>0&&(n=n??{},n.vertical=t.vertical),h>l&&(n=n??{},n.left=t.vertical),d<c&&(n=n??{},n.right=t.vertical)),n}_localizeBorder(t,e,r,n){if(!t)return;let o=null;const s=e.rowStart,i=e.rowEnd;t.top&&r===s&&(o=o??{},o.top=t.top),t.bottom&&r===i&&(o=o??{},o.bottom=t.bottom),t.horizontal&&(r>s&&(o=o??{},o.top=t.horizontal),r<i&&(o=o??{},o.bottom=t.horizontal));const a=e.colStart,l=e.colEnd;return t.left&&n===a&&(o=o??{},o.left=t.left),t.right&&n===l&&(o=o??{},o.right=t.right),t.vertical&&(n>a&&(o=o??{},o.left=t.vertical),n<l&&(o=o??{},o.right=t.vertical)),o}getPropertiesAt(t,e,r){const n=this._p;let o=n,s=null;const i=this._t;if(i){const r=this._r,n=i.colEnd-i.colStart+1,o=i.rowEnd-i.rowStart+1;e=r.colStart+(e-r.colStart+(i.colStart-r.colStart))%n,t=r.rowStart+(t-r.rowStart+(i.rowStart-r.rowStart))%o}const a=n?.font;a&&a.fill&&(s=s??this._c.getNormalRanged().getPropertiesAt(t,e,r),s&&s.font&&a.fill===s.font.fill&&(o===n&&(o={...o}),o.font={...a},delete o.font.fill));const l=n?.fill;l&&(s=s??this._c.getNormalRanged().getPropertiesAt(t,e,r),s&&mt.deepEqual(l,s.fill)&&(o===n&&(o={...o}),delete o.fill));const c=o?.border;if(c){const r=i??this._r,s=this._localizeBorder(c,r,t,e);void 0!==s&&(o===n&&(o={...o}),null===s?delete o.border:o.border=s)}return o}toJSON(){return mt.toSafeJSON(this._p)}}const Dp=Object.freeze({value:null,style:null,hyperlink:null,formula:null,type:t.Null,stringToParse:null}),zp=Object.seal({value:void 0,style:void 0,hyperlink:void 0,formula:void 0,type:void 0,stringToParse:void 0}),Pp=Object.seal({value:void 0,style:void 0,hyperlink:void 0,formula:void 0}),jp=Object.freeze({width:1,height:1}),Hp=new xu({max:1e3});const Vp=new class{isEditAllowed(){return!0}isFormulaHidden(){return!1}get isICellProtection(){return!0}},$p=(e,r,n=null,o=null,s=!1)=>{if(void 0===e)return;if(null===e)return Dp;if(e&&e.isICell){const t=e,r=zp;r.value=t.getValue();return t.getStyle().isNormal()||(r.style=t.getStyle()._p.getProperties()),r.formula=t.getFormulaText(),r.hyperlink=t.getHyperlink(),r.type=t.getType(),r}let i;void 0!==e.value||void 0!==e.style||void 0!==e.hyperlink?i=e:(i=Pp,i.value=e,i.style=void 0,i.hyperlink=void 0);const a=zp;a.type=void 0,a.value=void 0,a.style=void 0,a.formula=void 0,a.hyperlink=void 0,a.stringToParse=void 0;let l,c=i.value,h=!1;if(void 0!==i.value&&(l=Rh(c),l||(h=ls(c),h&&(l=t.Number)),!l))throw new Error("Invalid cell type. See documentation for information on valid built in cell types and creating custom cell types.");let d,u,g=null,p=null;let m;if(l===t.String){if(m=i.value,n){let t=o?.get(m);if(!t){const e=m.length,r=m.charAt(0);"="===r&&e>1?(u=m.substring(1),c=null):(t=wm(m,n),!t||"string"!=typeof t.value||"+"!==r&&"-"!==r||(u="="+m,c=null),void 0!==t&&o&&o.set(m,t))}t&&(void 0!==t.value&&(c=t.value,l=Rh(c)),void 0!==t.style&&(g=t.style),void 0!==t.hyperlink&&(d=t.hyperlink)),!s&&n.parse&&(p=m)}}else if(h){const t=n?.date1904??r.date1904;c=ms(i.value,t),g=t=>{if(!Rs(t.getNumberFormat()))return{numberFormat:"Short Date"}}}else c=i.value;let f=i.style;if(f&&f.isIStyle&&(f=f._p.getProperties()),d=i.hyperlink??d,g)if(f){const t=f;f=e=>{let r=e.createTemporaryStyle(g);return r=r.createTemporaryStyle(t),r=r._p.getProperties(),r}}else f=g;let _=!1;return void 0!==c&&(null===c?(a.value=null,a.type=t.Null):(a.value=c,a.type=l),_=!0),void 0!==f&&(a.style=f,_=!0),void 0!==d&&(a.hyperlink=d,_=!0),void 0!==u&&(a.formula=u,_=!0),s||(a.stringToParse=p,_=!0),_?(a.type=l,a):void 0},Up=(t,e,r,n)=>hp(r,e,t,e.getNumberFormat(),t=>n.styles.parseColor(t),n.date1904),Gp=(e,r,n,o,s=!1)=>{if(e===t.Null)return null;let i="";if(s)i=""+n;else{const t=Up(e,r,n,o);if(t.formattedRuns){const e=t.formattedRuns.runs;for(let t=0;t<e.length;t++){i+=e[t].text}}else i=t.displayText}return Gi(i,r.getFont(),r.getAlignment(),e===t.String,s)},Wp=(e,r)=>{const n=r.getInsets();if(e===t.Null)return n;let o=n;const s=qp(e,r),i=r.getAlignment().getIndent();if(i&&(s===exports.ITextFrame.HorizontalAlignment.Left||s===exports.ITextFrame.HorizontalAlignment.Right)){o={...n};const t=r.measureText(" ".repeat(1*i)),e=Math.min(3,Math.max(1,(26-r.getFont().getSize())/2));let a=t.width*e;s===exports.ITextFrame.HorizontalAlignment.Left?o.left+=a:s===exports.ITextFrame.HorizontalAlignment.Right&&(o.right+=a)}return Object.freeze(o)},qp=(e,r)=>{const n=r.getAlignment(),o=n.getRotation(),s=n.getHorizontal();return 0!==o&&s===exports.ITextFrame.HorizontalAlignment.General?o>0&&o<90||o>180&&o<=270?exports.ITextFrame.HorizontalAlignment.Right:exports.ITextFrame.HorizontalAlignment.Left:s===exports.ITextFrame.HorizontalAlignment.General?e===t.Null?exports.ITextFrame.HorizontalAlignment.Left:e===t.Boolean||e===t.Error?exports.ITextFrame.HorizontalAlignment.Center:"@"===r.getNumberFormat()?exports.ITextFrame.HorizontalAlignment.Left:e===t.Number?exports.ITextFrame.HorizontalAlignment.Right:exports.ITextFrame.HorizontalAlignment.Left:s},Jp=(e,r,n,o,s,i,a,l)=>{if(r===t.Null||""===o)return null;const c=e.colIndex;if(!((e,r,n=!1,o=!1)=>{if(e===t.Null)return!1;const s=r.getAlignment(),i=s.getHorizontal();if(i===exports.ITextFrame.HorizontalAlignment.CenterContinuous)return!0;if(i===exports.ITextFrame.HorizontalAlignment.Fill||i===exports.ITextFrame.HorizontalAlignment.Distributed)return!1;if(e!==t.String||s.getOverflow()!==exports.ITextFrame.Overflow.Visible)return!1;if(i===exports.ITextFrame.HorizontalAlignment.Right&&n)return!1;if(i===exports.ITextFrame.HorizontalAlignment.Center&&n&&o)return!1;if(o&&(i===exports.ITextFrame.HorizontalAlignment.General||i===exports.ITextFrame.HorizontalAlignment.Left))return!1;const a=s.getVertical();return a!==exports.ITextFrame.VerticalAlignment.Justify&&a!==exports.ITextFrame.VerticalAlignment.Distributed})(r,n,null!==s&&s.colIndex+1===c,null!==i&&i.colIndex-1===c))return null;const h=Zp(r,n,o,l),d=n.getAlignment().getHorizontal(),u=d===exports.ITextFrame.HorizontalAlignment.Fill,g=d===exports.ITextFrame.HorizontalAlignment.CenterContinuous||u;if(!h&&!g)return null;const p=(m=qp(r,n))===exports.ITextFrame.HorizontalAlignment.Center||m===exports.ITextFrame.HorizontalAlignment.CenterContinuous?S.Center:m===exports.ITextFrame.HorizontalAlignment.Right?S.Right:S.Left;var m;let f=0,_=0,w=0,y=0,x=1;if(g&&null!==o&&a.directStyle){const t=a.directStyle.getCoords();x=Math.min(l.nextContentful(e,t.colEnd),t.colEnd)-e.colIndex+1}const C=l.colHeaders,b=C.findOffset.bind(C),E=C.findIndex.bind(C);let v=b(c);const I=v;let A=b(c+x),R=A-v,M=c,T=c;const F={x:0,y:0,width:R,height:h?.height??0};const N=c-c+x;let k=h?h.width-R:0,O=F;u&&(k=0),R>0&&k>0&&(p===S.Center&&(k/=2),p!==S.Left&&p!==S.Center||(T=E(A+k),null!==i&&(T=Math.min(T,i.colIndex-1)),A=b(T),y=k,_=T-c),p!==S.Right&&p!==S.Center||(M=E(v-k),null!==s&&(M=Math.max(M,s.colIndex+1)),v=b(M),w=k,f=c-M),F.x=I-v,O.x=F.x);return{anchorBounds:F,leftIndex:f,rightIndex:_,leftOffset:w,rightOffset:y,colSpan:N,colBounds:O}};class Xp{constructor(t,e){if(this._styles=t,this._rs=e,e?.table){const t=e?.table;this._table=t.getStyle().getRanged(t)}if(e?.conditionals){this._conditionals=[];for(let t=0;t<e.conditionals.length;t++){const r=e.conditionals[t];this._conditionals.push(r)}}}getCoords(){return U.EmptyRange}getPropertiesAt(t,e,r){let n=null,o=this._rs.directStyle?.getPropertiesAt(t,e,r)??null;const s=this._styles;if(o&&o.named){const s=o.named;if(s!==exports.IStyle.BuiltInName.Normal){const o=this._styles.getNamed(s);o?n=o.getRanged().getPropertiesAt(t,e,r):console.warn(`A named styled was referenced but not found: '${s}'.`)}}let i=null;const a=this._table?.getPropertiesAt(t,e,r);a&&(i=i?exports.ft.resolveTypedUpdates(a,ap,s,i):a),n&&(i=i?exports.ft.resolveTypedUpdates(n,ap,s,i):n);const l=this._conditionals;if(l)for(let n=0;n<l.length;n++){const o=l[n].getPropertiesAt(t,e,r);o&&(i=i?exports.ft.resolveTypedUpdates(o,ap,s,i):o)}return o&&(i=i?exports.ft.resolveTypedUpdates(o,ap,s,i):o),i}cloneWithUpdate(t){return(this._rs.directStyle??this._styles.getNormalRanged()).cloneWithUpdate(t)}}const Kp=(t,e,r,n)=>{if(!r)return n.styles.getNormal();const o=n.styles;return kp(o,r?new Xp(o,r):null,e)},Yp=(e,r,n,o,s,i,a,l=null,c=Hp)=>{if(null===n)return r?r.getBestFit():null;const h=e===t.String,d=r.getFont(),u=d.getWeight(),g=d.getSize(),p=d.getFamily(),m=r.getAlignment(),f=m.getOverflow(),_=m.getRotation(),S=m.getVertical(),w=r.getNumberFormat(),y=h&&f===exports.ITextFrame.Overflow.Visible,x=h&&(f===exports.ITextFrame.Overflow.Wrap||S===exports.ITextFrame.VerticalAlignment.Justify||S===exports.ITextFrame.VerticalAlignment.Distributed),C=(l??"")+"\0"+g+p+u+w+_+y+x+i+a+(l?"":n),b=c.get(C);if(b)return b;let E=null,v=null;const I=Wp(e,r),A=I.top+I.bottom+ +ym(r);let R=!1,M=!1;a&&(M=!0,(0!==_||x)&&(M=!1));const T=M?void 0:Gp(e,r,n,o),F=I.left+I.right+2;if(T){if(e===t.Number&&"General"===w&&i){let t=n,e=mt.splitNumber(t),o="";o=Math.abs(t)>=Math.pow(10,12)||Math.abs(t)<=Math.pow(10,-12)?`0.${"0".repeat(Math.max(2,Math.min(e.ipLength,5)))}E+00`:0===Math.abs(e.ipLength)?"0.0":Math.abs(e.fpLength)>0?"0".repeat(e.ipLength)+".0":"0".repeat(e.ipLength),t<0&&(o="-"+o),o="0".repeat(o.length);const s=r.measureText(o);E=s.width,v=s.lineHeight}else{let t=null;x&&(t={width:Math.max(1,s-F)});const e=T.layout(t);E=e.bounds.width,v=e.bounds.height}if(null!==E&&(E+=F),null!==v&&(v+=A),R=e===t.String,_){R&&f===exports.ITextFrame.Overflow.Wrap&&(R=!1);const t=((t,e)=>{const{x:r,y:n,width:o,height:s}=t,i=e*Math.PI/180,a=Math.sin(i),l=Math.cos(i),c=o/2,h=s/2,d=Wi(-c,-h,a,l),u=Wi(c,-h,a,l),g=Wi(-c,h,a,l),p=Wi(c,h,a,l);let m=Math.min(d.x,u.x,g.x,p.x)+c,f=Math.max(d.x,u.x,g.x,p.x)+c,_=Math.min(d.y,u.y,g.y,p.y)+h;return{x:r+m,y:n+_,width:f-m,height:Math.max(d.y,u.y,g.y,p.y)+h-_}})({x:0,y:0,width:E,height:v},_);E=t.width,v=t.height}}else v=r.getBestFit().height;i&&R&&(E=0);const N={width:E,height:v},k=Object.freeze(N);return c.set(C,k),k},Zp=(t,e,r,n)=>{const o=Wp(t,e),s=qp(t,e);let i=o.left+o.right;s===exports.ITextFrame.HorizontalAlignment.Left?i=o.right:s===exports.ITextFrame.HorizontalAlignment.Right?i=o.left:s===exports.ITextFrame.HorizontalAlignment.Center&&(i=o.left+o.right);const a=Yp(t,e,r,n,Number.MAX_SAFE_INTEGER,!1,!1);return{width:Math.ceil(a.width-i),height:Math.ceil(a.height)}};class Qp{constructor(e,r,n=t.Null,o=null,s=null,i=null,a=null){this._options=e,this._coords=r??null,this._t=n,this._rs=s,this._v=o,this._p=i,this._n=a}isEqual(t){if(!t)return!1;if(this===t)return!0;const e=t;return!!e.isICell&&(this._v===e._v&&(!!U.isEqualCells(this._coords,t.getCoords())&&this._options.sheet===e._options?.sheet))}getCoords(){return this._coords}getA1(){const t=this._coords;return t?ad(this._options.resolveRange(t).getCoords()):Gh}getSource(){return this._options.sheet}select(t){return this._options.opener("#"+ed(this._coords),t)}getColumnFilter(){if(!this._rs)return null;let t=null;if(this._rs.table){const e=this._rs.table.getHeaderRange().getCoords();if(e&&U.isCellWithinRange(this._coords,e)){const r=this._coords.colIndex-e.colStart;t=this._rs.table.getColumnFilter(r)??null}}return t}getProtection(){return Vp}getTextOverflow(){const t=this._to;if(void 0!==t)return t;if(this._rs&&this._rs.merge)return this._to=null,null;const e=this.getStyle(),r=Jp(this._coords,this._t,e,this._v,this._p,this._n,this._rs,this._options);return null===r||0===r.leftIndex&&0===r.rightIndex&&r.colSpan<=1?(this._to=null,null):(this._to=r,this._to)}getRenderHorizontalAlignment(){return qp(this._t,this.getStyle())}isEmpty(){return null===this._v&&!this._rs}getExtrusions(){const t=this._rs;if(!t&&null===this._to)return null;if(t){const e=t.merge;if(void 0!==e)return e.getCoords()}const e=this.getTextOverflow();if(!e)return null;const r=this._coords;return{colStart:r.colIndex-e.leftIndex,rowStart:r.rowIndex,colEnd:r.colIndex+e.rightIndex+e.colSpan-1,rowEnd:r.rowIndex}}isEditAllowed(){const t=this._options;if(!t)return!0;return!t.getProtection().isLocked()||!!this._rs&&this.getProtection().isEditAllowed()}isFormulaHidden(){return!!this._options.getProtection().isLocked()&&(!!this._rs&&this.getProtection().isFormulaHidden())}isContentful(){return null!==this._v}getBestFit(t,e=!1){return void 0===t&&(t=this._options.sheet.getColumnHeaders().getSpanSize(this._coords.colIndex)??64),Yp(this._t,this.getStyle(),this._v,this._options,t,e,!1)}getInsets(){if(null===this._v)return this.getStyle().getInsets();return Wp(this._t,this.getStyle())}getTextFrame(e){let r,n;if(e&&(n=this.getFormulaText()),r=n??this._v,null===r)return null;const o=this.getStyle();return n?((e,r)=>r===t.Null?null:Gi(r,e.getFont(),e.getAlignment(),!1,!0))(o,r,this._options):Gp(this._t,o,r,this._options,e)}getValue(){return this._v}getFormula(){let t=this._rs?.formula;if(!t)return null;const e=this._coords;return e?(Array.isArray(t)&&(t=t[0]),new em(this._options,t,e)):null}getFormulaText(){let t=this._rs?.formula;if(!t)return null;const e=this._coords;if(!e)return null;return Array.isArray(t)&&(t=t[0]),"="+t.getFormulaTextAt(e.rowIndex,e.colIndex)}getCalcStatus(){const t=this._rs;return t&&t.pending?exports.ICell.CalcStatus.Pending:exports.ICell.CalcStatus.Ready}getType(){return this._t}getStyle(t=!1){if(!t&&this._styleConditional)return this._styleConditional;if(t&&this._styleSpecific)return this._styleSpecific;const e=Kp(0,U.cellToRange(this._coords),this._rs,this._options);return t?this._styleSpecific=e:this._styleConditional=e,e}createTemporaryCell(t){const e=this._options;if(null===t)return new Qp(e,this._coords,null);const r=$p(t,this._options);let n=this._rs;if(void 0!==r.style){const t=this._coords??U.EmptyCell,o=U.cellToRange(t),s=()=>Kp(0,o,this._rs,this._options),i=wp(this._options.styles,r.style,s),a=(this._rs?.directStyle??new Lp(e.styles,o)).cloneWithUpdate(i);n={...n,directStyle:a}}let o=this._t,s=this._v;return r&&void 0!==r.value&&(s=r.value,o=r.type),s===this._v&&o===this._t&&n===this._rs?this:null!==s||n?new Qp(this._options,this._coords,o,s,n):new Qp(this._options,this._coords)}_isDate1904(){return this._options.date1904}getNumberFormat(t){if(void 0!==t){const e=this._v;return hp(e,this.getStyle(),this._t,t,t=>this._options.styles.parseColor(t),this._isDate1904())}return Up(this._t,this.getStyle(),this._v,this._options)}toDate(){return this._t!==t.Number?null:this._rs?this.getNumberFormat().asDate:null}toText(t){return this.getNumberFormat(t).displayText}toTextUnformatted(e){if(e){const t=this.getFormulaText();if(t)return t}let r=this._v;return this.isSpillOverflow()&&(r=null),((e,r,n,o)=>{if(r===t.Null||null==e)return"";if(r===t.Number){const t=e,r=Rs(n),s=Ms(n);if(r||s){const n=parseFloat(e),i=n%1!=0,a=n>=1;if(n<0)return mt.castToString(e);if(!r||s||i)if(!s||r||a){const e=Uo("Short Date",t,o),r=Uo("Long Time",t,o);if(e&&r)return e.fmt+" "+r.fmt}else{const e=Uo("Long Time",t,o);if(e)return e.fmt}else{const e=Uo("Short Date",t,o);if(e)return e.fmt}}}if(r===t.Number&&n.endsWith("%")){let t=mt.roundAccurately(100*parseFloat(e));if(!isNaN(t))return t+"%"}return r===t.Boolean?e?"TRUE":"FALSE":r===t.Error?e?.getLabel?.()??exports.n.Label.Unknown:r===t.RichData?"(Rich Object)":mt.castToString(e)})(r,this._t,this.getStyle().getNumberFormat(),{date1904:this._isDate1904()})}getComments(){const t=this._rs?.comments;return t?Object.freeze(t):null}getHyperlink(){const t=this._rs?.hyperlink;return t?new bu(this.toText.bind(this),this._options.opener,t):null}getErrors(){const t=this._rs;return t&&t.calcError?[t.calcError]:mt.EmptyArray}getWarnings(){return mt.EmptyArray}getSpans(){const t=this._rs?.merge;if(!t)return jp;const e=t.getCoords();return Object.freeze({width:e.colEnd-e.colStart+1,height:e.rowEnd-e.rowStart+1})}isTopLeft(){const t=this._rs?.merge;if(!t)return!0;const e=t.getCoords();return this._coords&&this._coords.colIndex===e.colStart&&this._coords.rowIndex===e.rowStart}getSpill(){let t=this._rs?.spills;if(!t)return null;if(!this._coords)return null;Array.isArray(t)||(rm[0]=t,t=rm);let e=null;for(let r=0;!e&&r<t.length;r++){const n=t[r];n.getError()||(e=n)}return e||(e=t[0]),this._options.getRange(e.getCoords())}isSpillOverflow(){let t=this._rs?.spills;if(!t)return!1;if(!this._coords)return null;Array.isArray(t)||(rm[0]=t,t=rm);for(let e=0;e<t.length;e++){const r=t[e].getCoords();if(this._coords.colIndex===r.colStart&&this._coords.rowIndex===r.rowStart)return!1}return!0}get[Symbol.toStringTag](){return"[Cell]"}toString(){let e="{blank}";return null!==this._v&&(e=this.toTextUnformatted(),this.getType()===t.String&&(e=`'${e}'`)),`${this.getA1()} => ${e}`}get isICell(){return!0}}let tm=class extends Qp{constructor(t){super(t,null,null,null)}isEmpty(){return!0}isContentful(){return!1}toString(){return"{EMPTY CELL}"}};class em{constructor(t,e,r){this._options=t,this._entry=e,this._coords=r}getTokens(t){const e=this._coords;if(!e)return mt.EmptyArray;return this._entry.getTokensAt(e.rowIndex,e.colIndex,t)}evaluate(t){const e=this._coords;return e?this._options.calcGraph().evaluateAt(e.rowIndex,e.colIndex,t):mt.EmptyArray}toText(t){const e=this._coords;if(!e)return null;return"="+this._entry.getFormulaTextAt(e.rowIndex,e.colIndex,t)}getDirectPrecedents(){const t=this._coords;if(!t)return mt.EmptyArray;return this._options.calcGraph().getDirectPrecedentsAt(t.rowIndex,t.colIndex)}getReferences(){const t=this._coords;if(!t)return mt.EmptyArray;return this._entry.getReferencesAt(t.rowIndex,t.colIndex)}setReferenceAt(t,e){const r=this._coords;return r?(this._options.calcGraph().setReferenceAt(r.rowIndex,r.colIndex,t,e),this):mt.EmptyArray}get[Symbol.toStringTag](){return"[Formula]"}toString(){return this.toText()}}const rm=[null];let nm;const om=(t,e,r,n=!1)=>{const o=r===exports.t.Orientation.Row,s=t.length,i=new Array(s);for(let r=0;r<s;r++){const s=t[r];if(o){const t=s.colEnd-s.colStart+1;i[r]={...s,colStart:n?s.colEnd+1:s.colStart,rowStart:e.rowStart,colEnd:n?s.colEnd+t:s.colEnd,rowEnd:e.rowEnd}}else{const t=s.rowEnd-s.rowStart+1;i[r]={...s,colStart:e.colStart,rowStart:n?s.rowEnd+1:s.rowStart,colEnd:e.colEnd,rowEnd:n?s.rowEnd+t:s.rowEnd}}}return i},sm=(t,e,r)=>{const n=e,o=t.length;for(let e=0;e<o;e++){const o=t[e];if((o.rowStart<=n.rowStart&&o.rowEnd>=n.rowEnd)!==r)return!r}return r},im=(t,e,r)=>{const n=e,o=t.length;for(let e=0;e<o;e++){const o=t[e];if((o.colStart<=n.colStart&&o.colEnd>=n.colEnd)!==r)return!r}return r},am=(t,e)=>{let r=0;const n=t.length;for(let o=0;o<n;o++){const n=t[o];e===exports.t.Orientation.Column?r+=n.colEnd-n.colStart+1:r+=n.rowEnd-n.rowStart+1}return r},lm=(t,e)=>{if(e){if(t.colStart<=e.colStart&&t.colEnd>=e.colEnd)return exports.t.Orientation.Row;if(t.rowStart<=e.rowStart&&t.rowEnd>=e.rowEnd)return exports.t.Orientation.Column}return t?(t=>t.rowEnd-t.rowStart>t.colEnd-t.colStart?exports.t.Orientation.Column:exports.t.Orientation.Row)(t):exports.t.Orientation.Row},cm=()=>!1,hm=()=>!0,dm=()=>null,um=()=>bl,gm=()=>0,pm=new class extends Qp{constructor(){super(null,null)}createTemporaryCell(){return this}getType(){return t.Error}getWarnings(){return[Gh]}getStyle(t=!1){return nm||(nm=(new af).getNormal(),nm)}toString(){return`${this._coords?ed(this._coords):Gh} => ${this._v??"{blank}"}`}},mm=()=>fm,fm={forEach:()=>{},[Symbol.iterator]:um,entries:um,select:Bd,find:Bd,calculate:Bd,getCell:()=>pm,getValue:dm,setValue:Bd,setValues:Bd,updateCells:Bd,updateStyle:Bd,getCells:()=>[[pm]],getStyleUpdater:Bd,getValues:()=>[[null]],getBounds:dm,getIntersect:mm,getUnion:mm,getDifferences:Bd,getResizeBy:mm,getResizeTo:mm,getOffsetBy:mm,getOffsetTo:mm,getFixed:mm,getUsedRange:mm,getEntireRows:mm,getEntireColumns:mm,getSurrounding:Bd,getExtended:Bd,isEntireRows:cm,isEntireColumns:cm,isEntireRange:cm,getWidth:gm,getHeight:gm,size:0,sort:Bd,clear:Bd,setHyperlink:Bd,setComments:Bd,merge:Bd,unmerge:Bd,getMerges:Bd,insert:Bd,insertFrom:Bd,delete:Bd,getDefaultShiftOrientation:Bd,getDefaultSortCriteria:Bd,autoFill:Bd,autoFit:Bd,getSnapshot:Bd,copyFrom:Bd,doBatch:Bd,startIncrementalUpdates:Bd,getRowHeaders:Bd,getColumnHeaders:Bd,getCounts:Bd,getCount:gm,isContentful:cm,addListener:Bd,getColumnStart:gm,getRowStart:gm,getColumnEnd:gm,getRowEnd:gm,getRowCount:gm,getColumnCount:gm,getVisible:Bd,getCoords:dm,isEmpty:hm,toString:()=>Gh,getA1:()=>Gh,isInvalid:hm,getSource:dm,isReadOnly:hm,isICellRange:!0};function _m(t,e=null,r=null,n=Gh){return t||r?Object.freeze({...fm,getSheet:()=>t,bounds:()=>r,getA1:()=>n,toString:()=>r?sd(r,e):n}):fm}const Sm=/^[\\+-]?[0-9]*\.?[0-9]*$/,wm=(t,e,r)=>{if(void 0===t)throw new Error("A value is required to create a cell from a text.");const n=r??{value:null};if(""===(t=mt.castToString(t)).trim())return n;if("TRUE"===t.toUpperCase()||"FALSE"===t.toUpperCase())return n.value="TRUE"===t.toUpperCase(),n;if(t.startsWith("'")&&!e?.ignoreQuotePrefix)return n.style={quotePrefix:!0},n.value=t.substring(1,t.length),n;n.value=t;const o=",",s="$",i=".";let a=t.trim(),l=1,c=!1;a=(t=>{const e=new RegExp("([(]{1}([^(|^)]+)[)]{1})").exec(t);if(e?.[2]){const r=t.substring(0,e.index)+e[2].trim()+t.substring(e.index+("("+e[2]+")").length-1,t.length-1);return r.indexOf("(")>-1||r.indexOf(")")>-1?t:(c=!0,l=-1,r)}return t})(a);let h=0;a=(t=>{const e=new RegExp("[0-9]+([eE][-+]?[0-9]+)?$").exec(t);if(e?.[1]){const r=t.substring(0,t.length-e[1].length);let n=1,o=e[1].substring(1,e[1].length);if(o.startsWith("-")?(o=o.substring(1,o.length),n=-1):o.startsWith("+")&&(o=o.substring(1,o.length)),!isNaN(o))return h=o*n,r}return t})(a);let d=!1;if(a=(t=>{const e=new RegExp(`^(\\${s}[\\ ]*\\-|\\${s}[\\ ]*\\+|\\-[\\ ]*\\${s}|\\+[\\ ]*\\${s}|\\-|\\+)?`).exec(t);if(e?.[1]){const r=e?.[1].indexOf(s)>-1,n=e?.[1].indexOf("-")>-1,o=e?.[1].indexOf("+")>-1,i=(r?s:"")+t.substring(e.index+e[1].length,t.length).trim(),a=i.indexOf("-")>-1,c=i.indexOf("+")>-1;return a||c?t:(d=n||o,n&&(l=-1),i)}return t})(a),d&&(c||0===a.length))return n;let u=!1;if(a=(t=>{if(new RegExp(`^(?:\\${s}[\\ ]*)?((\\d{1,3}(${o}\\d{3})*)|(\\d*))(\\${i}|\\${i}\\d*)?(?:[\\ ]*\\%)?$`).test(a)){const e=t.replace(new RegExp(`${o}`,"g"),"");return u=e.length<t.length,e}return t})(a),a.match(Sm)&&!isNaN(a)){if(n.value=a*l,0!==h)n.value=n.value*Math.pow(10,h),n.style={numberFormat:`0${i+"0".repeat(2)}E+00`};else if(u){let t=Ds(a);n.style=t>0?{numberFormat:`#${o}##0${i+"0".repeat(2)}`}:{numberFormat:`#${o}##0`}}return n}if(a.trimEnd().endsWith("%")&&a.trimEnd().length>1){let t=a.substring(0,a.length-1);if(!isNaN(t)){n.value=t*l/100;const e=Ds(t);n.style=t=>{if(!t.getNumberFormat().includes("%"))return{numberFormat:e>0?`0${i+"0".repeat(2)}%`:"0%"}}}return n}if(a.startsWith(s)&&t.trim().length>1){let t=a.replace(s,"");if(!isNaN(t)){let e=Ds(t);n.value=t*l,n.style=t=>{if(t.getNumberFormat().includes(s))return;let r;return r=e>0?`${s}#${o}##0${i+"0".repeat(2)}_);[Red](${s}#${o}##0${i+"0".repeat(2)})`:`${s}#${o}##0_);[Red](${s}#${o}##0)`,{numberFormat:r}}}return n}let g=null,p=null;try{p=vs(t,e?.date1904,!0);let r=t;p&&(r=p.leadingText),r.trim().length>0&&(g=As(r,e?.date1904)),!g&&p?.leadingText.trim().length>0&&(p=null)}catch(t){}if(g||p){n.style=t=>{let r=t.getNumberFormat();const n=Rs(r);if(g&&n)return;const o=Ms(r);if(!p||!o){if(g&&p&&!n&&!o?r="m/d/yyyy h:mm":g&&!n?r=g.numberFormat:p&&!o&&(r=p.numberFormat),p&&p.parsed.oaDateTime>1&&(r="General"),g&&!n&&!p){const t=exports.NumberFormat.Parser.formatValue(g.numberFormat,g.asOADate,{date1904:e?.date1904}),n=Intl.DateTimeFormat().resolvedOptions().locale??"en-US";t===new Intl.DateTimeFormat(n).format(g.asJSDate)?r="Short Date":t===new Intl.DateTimeFormat(n,{dateStyle:"full"}).format(g.asJSDate)?r="Long Date":t===new Intl.DateTimeFormat(n,{timeStyle:"medium"}).format(g.asJSDate)&&(r="Long Time")}return{numberFormat:r}}};let t=0;return g&&(t+=g.asOADate),p&&(t+=p.parsed.oaDateTime),n.value=t,n}const m=exports.n.getBuiltInByLabel(t);return m?(n.value=m,n):(n.value=t,Gs(t)?n.hyperlink=t:qs(t)&&(n.hyperlink=t,n.hyperlink.toLowerCase().startsWith("mailto:")||(n.hyperlink=`mailto:${n.hyperlink}`)),n)},ym=t=>{const e=t.getFont().getUnderline()===exports.IFont.UnderlineStyle.SingleAccounting,r=t.getFont().getUnderline()===exports.IFont.UnderlineStyle.DoubleAccounting;let n=0;if(e||r){n=t.measureText("").underlineThickness+1,r?n*=2:n+=1}return n},xm=t=>{const e=[];t.getUsedRange().forEachSpan((t,r)=>{const n=r.getCoords();0===t&&e.push(n)},{includeStyles:!1});return ta(ea(e))},Cm=(t,e,r,n)=>{const o=n?.asJSDate;let s;r?s=Gd:(o||n?.includeMergeOverflow)&&(s={},o&&(s[$d.Type.Style]=!1,s[$d.Type.Table]=!1),n.includeMergeOverflow&&(s[$d.Type.Merge]=!1));const i=n?.orientation??exports.t.Orientation.Row,a=n?.maxSize??1e4,l=t({includeEmpty:!0,orientation:i,reverse:n?.reverse,excludeHidden:n?.excludeHidden,includeMergeOverflow:n?.includeMergeOverflow,includeRangeTypes:s,bounds:e,excludeCellDetails:!o}),c=i!==exports.t.Orientation.Row,h=[];let d,u=-1,g=null,p=0;for(d=l.next();!d.done;){if(p>a)throw new Error(au(a));const t=d.value,e=t.context.getCoords(),n=c?e.colIndex:e.rowIndex;n!==u&&(g=[],h.push(g),u=n);let s=t.value;if(r)s=t.context.getCell();else if(o&&null!==s&&"number"==typeof s){const e=t.context.getCell().toDate();e&&(s=e)}g.push(s),d=l.next(),p++}return h},bm=(t,e)=>t===e||!(!t||!e)&&(t.rowStart===e.rowStart&&t.rowEnd===e.rowEnd&&(t.colStart===e.colStart&&t.colEnd===e.colEnd&&(t.$rowStart===e.$rowStart&&t.$rowEnd===e.$rowEnd&&(t.$colStart===e.$colStart&&t.$colEnd===e.$colEnd)))),Em=(t,e)=>{if(!t)return;const r={...t};return e?"boolean"==typeof e?(r.$colStart=e,r.$rowStart=e,r.$colEnd=e,r.$rowEnd=e,r):("boolean"==typeof e.colStart&&(r.$colStart=e.colStart),"boolean"==typeof e.rowStart&&(r.$rowStart=e.rowStart),"boolean"==typeof e.colEnd&&(r.$colEnd=e.colEnd),"boolean"==typeof e.rowEnd&&(r.$rowEnd=e.rowEnd),r):r};class vm{constructor(e,r,n){const o=this;this.setState=t=>{const e=t[0];let n=t[1],o=t[2];if(r&&r.includeMergeOverflow&&o&&o.merge){const t=r.bounds,s=o.merge.getCoords();let i=!1;const a=s.colStart,l=s.rowStart,c=t.colStart,h=t.rowStart,d=e.colIndex,u=e.rowIndex;!i&&a<c&&l>=h&&d===c&&u===l&&(i=!0),!i&&l<h&&a>=c&&u===h&&d===a&&(i=!0),!i&&l<h&&a<c&&u===h&&d===c&&(i=!0),i&&(n=o.merge.tvTl(),o=o.merge.rsTl())}o&&0===Object.keys(o).length&&(o=null);let s=n;return void 0===n?(this._t=null,this._v=null,s=null):(this._t=Rh(s),this._v=s),this._r=o,this._p=t[3],this._n=t[4],this._c=e,s},this.clear=()=>{o._c=null},this.context={getCoords(){const t=o._c;if(!t)throw new Error(su);return t},getCell(){const t=o._c;if(!t)throw new Error(su);if(this.excludeCellDetails)throw new Error("IteratorContext can only return a cell if the forEach excludeCellDetails has not been set to false.");const e=o._r,r=o._t,s=o._v;return null!==s||e?new Qp(n,t,r,s,e,o._p,o._n):new Qp(n,t)},getType:()=>o._t,getA1(t){if(!o.context)throw new Error(su);let e=o._c;return t&&(e={...o._c,...t}),n.resolveRange(e).toString()},toJSDate(e){if(o._t!==t.Number)return null;let r=e;if(void 0===r)r=o._v;else if("number"!=typeof r)throw new Error("The arguments are not valid.");return ps(r,n.date1904)}}}}const Im=(t,e)=>{if(t||e)return t&&e?{...t,...e}:t||e},Am=(t,e,r,n=exports.t.Orientation.Row)=>{const o=t.getRange(e,{excludeHidden:n}),s=o.forEach((t,e)=>({break:e.getCoords()}),{excludeCellDetails:!0,orientation:n});if(!s)return;const i=n===exports.t.Orientation.Row,a=new Map,l=new Map,c=new Map;let h=null;const d=t.getRange(s).getMerges();let u=d.length>0?1+(i?d[0].rowEnd-d[0].rowStart:d[0].colEnd-d[0].colStart):1;const g=i?s.rowIndex:s.colIndex;if(o.forEach((t,e)=>{const r=e.getCoords(),n=i?r.colIndex:r.rowIndex,o=i?r.rowIndex:r.colIndex;if(o===g)a.set(n,t);else{if(o!==g+u)return Vd;"string"==typeof t?h=!1:null!==t&&l.set(n,t)}if(null!=h)return Vd},{orientation:n,excludeCellDetails:!0,address:e}),null===h){const t=l.entries();let e=t.next();for(;null===h&&!e.done;){const[r,n]=e.value,o=a.get(r);o&&("string"==typeof o?c.set(r,o):h=!1),e=t.next()}h=h??c.size>0}const p={colStart:s.colIndex,rowStart:s.rowIndex,colEnd:e.colEnd,rowEnd:e.rowEnd};if(p.colStart>p.colEnd||p.rowStart>p.rowEnd||U.isSingleCell(p))return null;const m=Math.min(Math.max(r?.colIndex??0,p.colStart),p.colEnd),f=Math.min(Math.max(r?.rowIndex??0,p.rowStart),p.rowEnd);return{coords:p,options:{...exports.Sort.DefaultRangeOptions,hasHeader:h,orientation:n,offset:n===exports.t.Orientation.Row?m-p.colStart:f-p.rowStart},headers:c}},Rm=(e,r,n=null)=>El.fromArray(e,(e,n)=>{const o=e?.[1];if(null==o)return null;let s=e[0]??null;switch(o){case t.String:s=r.getById(s);break;case t.Error:s=exports.n.getBuiltInById(s)}return s},(e,n)=>{const o=Rh(e);let s=e;switch(o){case t.String:s=r.add(s);break;case t.Error:s=s.getCode()}return[s,o]},n),Mm=(t,e)=>{const r=[],n=e?exports.t.Orientation.Column:exports.t.Orientation.Row,o=t.length;for(let s=0;s<o;s++){const o=t[s],i=o[0],a=o[1],l=a.length;for(let t=0;t<l;t++){const o=a[t],s=o[0],l=o[1].length-1,c={colStart:e?i:s,rowStart:e?s:i,colEnd:e?i:s+l,rowEnd:e?s+l:i,value:new Dd({colStart:e?i:s,rowStart:e?s:i,colEnd:e?i:s+l,rowEnd:e?s+l:i},n)};r.push(c)}}return r},Tm=(t,e,r=-1)=>{if(!t||0===t.length)return null;const n=1===t.length&&t[0].rowStart===t[0].rowEnd&&t[0].colStart===t[0].colEnd,o=-1===r?t.length-1:Math.min(Math.max(0,r),t.length-1);return{cell:e??{rowIndex:t[o].rowStart,colIndex:t[o].colStart},ranges:n?[]:[...t],rangeIndex:n?-1:o}},Fm=t=>{if(!t)return null;const e=[];if(t.ranges&&t.ranges.length>0){const r=Math.max(0,Math.min(t.rangeIndex??0,t.ranges.length));for(let n=r;n<t.ranges.length;n++)e.push(t.ranges[n]);for(let n=0;n<r;n++)e.push(t.ranges[n])}else t.cell&&e.push(U.cellToRange(t.cell));return e},Nm=(t,e)=>{if(!t||0===t.length)return null;let r=t.length-1;const n=t[r],o=t[0];if(!o||!o)return null;const s=1===t.length&&o.rowStart===o.rowEnd&&o.colStart===o.colEnd;return n?{cell:{rowIndex:n.rowStart,colIndex:n.colStart},ranges:s?[]:[...t],rangeIndex:s?-1:r}:null},km="Item has been closed. No further operations are allowed.";class Om{constructor(t){if(this._emitter=null,this._closed=!1,!t)throw new Error("Anchored.ConstructorOptions is required");if(this._options={...t},!this._options.initialAnchor)throw new Error("Initial anchor is required");const e=this;this._transactions=this._options.transactions??new re({transient:!0}),this._emitter=new ml(this,this._transactions),this._updateState({anchor:this._options.initialAnchor},{description:t?.createDescription??"Create Anchored Item"}),this._options.setContainerShiftCallback?.(t=>e._processContainerShift(t)),this._options.setContainerLayoutCallback?.(()=>{e._processContainerLayout()}),this._options.setContainerDeleteCallback?.(()=>{e._processContainerDelete()}),this._options.setContainerProtectionCallback?.(()=>{e._processContainerProtection()}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onBeforeCommitStart(t,r,n){e._processBeforeCommitStart(t,r,n)},onAfterStateChange(t,r,n){e._processStateChange(t,r,n),e._processAnchorCoords(),e._emitter.notify("onAnchorCoordsChange")},onRestoreOrRevert(t,r,n){e._processRestoreOrRevert(t,r,n)}})}_getEmitter(){return this._emitter}delete(t){this._options.deleteFromContainer?.(t)}getAnchorCoords(){return this._getState()?.anchor??null}getAnchorType(){return this._getState()?.anchorType??exports.IAnchored.Type.TwoCell}isProtected(){return this._options.isProtected?.()??!1}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(km);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_getTransactions(){return this._transactions}_updateState(t,e,r){if(this._closed)throw new Error(km);if(!t)return;const n=this._beginCommit(e?.description);try{n.updateState(this,t);let e=!1;if(r)for(let t=0;t<r.length;t++){const n=r[t];e=e||"onAnyChange"===n,this._emitter.notify(n)}!e&&r&&r.length>0&&this._emitter.notify("onAnyChange"),n.commit()}catch(t){throw n.rollback(),t}return this}_processContainerShift(t){let e=null;const r={anchor:t.after};return t.after||(r.isDeleted=!0,e=["onDelete"]),this._updateState(r,{description:"Update Anchor"},e),t.after}_processBeforeCommitStart(t,e,r){}_processStateChange(t,e,r){}_processRestoreOrRevert(t,e,r){this._emitter.notify("onInvalidated")}_processAnchorCoords(){}_processContainerLayout(){}_getDescription(){return null}_delete(){const t=this._getDescription(),e="Delete",r=t?`${e} ${t}`:e,n=this._beginCommit(r);try{this._processDelete(),n.commit()}catch(t){throw n.rollback(),t}}_processContainerDelete(){this._processDelete()}_processDelete(){}_processContainerProtection(){this._emitter.notify("onProtectedChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}_processClose(){this._closed=!0,this._emitter.notify("onClose"),this._transactionsRemoveListener?.()}close(){this._closed||this._processClose()}get isIAnchored(){return!0}}var Bm;exports.AddressUtils=void 0,(Bm=exports.AddressUtils||(exports.AddressUtils={})).fastStringToCol=wd,Bm.fastStringToCell=fd,Bm.fastStringToRange=yd,Bm.rangeToString=sd,Bm.cellToString=rd,Bm.normalizeA1ToR1C1=Td,Bm.resolveRelativeToA1=Ad;const Lm=(t,e)=>t.offset-e.offset,Dm=t=>{if(!t||0===t.size)return[];let e=[];return t.forEach((t,r)=>{t&&0!==Object.keys(t).length&&e.push({...t,offset:r})}),e.sort(Lm)};class zm extends Om{constructor(t){super({...t,createDescription:"Insert AutoSort"}),this._apply=t.apply,this._processUpdate=t.processUpdate,this._fromJSON(t.json)}getRange(){return this._getState().anchor}getFieldAt(t){const e=this._getState().byOffset.get(t)??null;if(!e)return null;return 0===Object.keys(e).length||1===Object.keys(e).length&&e.hasOwnProperty("offset")?null:{collatorOptions:null,...e}}insertSort(){return null}getSort(){return null}apply(t){const e=this._getState().byOffset,r=new Map(e);for(let e=0;e<t.length;e++){const n={...t[e]},o=n.offset;delete n.offset,r.set(o,n)}return this._updateState({byOffset:r},{description:"Set Sort Criteria"}),this.reapply()}setFieldAt(t,e){const r=this._getState().byOffset,n=new Map(r);return e&&Object.keys(e).length>0?n.set(t,e):n.delete(t),this._updateState({byOffset:n},{description:"Sort"}),this.reapply()}_processStateChange(t,e,r){super._processStateChange(t,e,r),this._processUpdate?.()}reapply(){const t=this._getState(),e=Dm(t.byOffset);return this._apply?.(e),this}clear(){return this._updateState({byOffset:new Map},{description:"Clear Sort"}),this.reapply()}_fromJSON(t){const e=t??{},r={byOffset:new Map};if(e.fields)for(let t=0;t<e.fields.length;t++){let n=e.fields[t];const o=n.offset;n={...e.fields[t]},delete n.offset,r.byOffset.set(o,n)}this._updateState(r,{description:"Load"})}toJSON(){const t={},e=this._getState();e.anchor&&(t.ref=exports.AddressUtils.rangeToString(e.anchor,this._options.maxRangeCoords));const r=Dm(e.byOffset);return r.length>0&&(t.fields=r),0===Object.keys(t).length?null:t}}const Pm=(t,e)=>t.offset-e.offset,jm=t=>{if(!t||0===t.size)return[];let e=[];return t.forEach((t,r)=>{t&&0!==Object.keys(t).length&&e.push({...t,offset:r})}),e.sort(Pm)},Hm=(t,e=new Map)=>{if(!t||0===t.length)return e;for(let r=0;r<t.length;r++){const n={...t[r]},o=n.offset;delete n.offset,e.set(o,n)}return e},Vm=t=>{let e=0;const r=t.entries();let n=null;do{n=r.next(),n.value?.[1]&&n.value[1].hiddenButton&&e++}while(!n.done);return e};class $m extends Om{constructor(t){super({...t,createDescription:"Insert AutoFilter"}),this._apply=t.apply,this._processUpdate=t.processUpdate,t.setFilterCoordsCallback?.(t=>{this._getState().anchor}),this._fromJSON(t.json)}getCoords(){return this._getState().anchor}getFieldAt(t){const e=this._getState().byOffset.get(t)??null;if(!e)return null;return 0===Object.keys(e).length||1===Object.keys(e).length&&e.hasOwnProperty("offset")?null:{hiddenButton:!1,criteria:mt.EmptyArray,...e}}insertSort(){return null}getSort(){return null}apply(t){const e=this._getState().byOffset,r=new Map(e);return Hm(t,r),this._updateState({byOffset:r,hiddenCount:Vm(r)},{description:"Set Filter Criteria"}),this.reapply()}setFieldAt(t,e){const r=this._getState(),n=r.anchor.colEnd-r.anchor.colStart+1;if(t<0||t>n-1)throw new Error(`Invalid range: '${t}'`);const o=r.byOffset,s=new Map(o);e&&Object.keys(e).length>0?s.set(t,e):s.delete(t);const i=!0===o.get(t)?.hiddenButton?1:0,a=!0===e?.hiddenButton?1:0;return this._updateState({byOffset:s,hiddenCount:Math.min(n,Math.max(0,r.hiddenCount+a-i))},{description:"Set Filter Criteria"}),this.reapply()}getShowFilterButton(){const t=this._getState(),e=t.anchor,r=e.colEnd-e.colStart+1;return t.hiddenCount<r}setShowFilterButton(t){const e=this.getAnchorCoords(),r=e.colEnd-e.colStart+1;let n=Array(r);const o=this._getState().byOffset,s=jm(o);for(let e=0;s&&e<s.length;e++){const r={...s[e]};n[r.offset]=r,t?delete r.hiddenButton:r.hiddenButton=!0}if(!t)for(let t=0;t<n.length;t++)n[t]||(n[t]={hiddenButton:!0});const i=new Map;for(let t=0;t<n.length;t++){const e=n[t];i.set(t,e)}return this._updateState({byOffset:i,hiddenCount:t?i.size:0},{description:(t?"Hide":"Show")+" Filter Buttons"}),this._processUpdate?.(),this}_processStateChange(t,e,r){super._processStateChange(t,e,r),this._processUpdate?.()}_processContainerShift(t){if(t.after&&t.orientation===exports.t.Orientation.Column){let e=t.intersect.colStart-t.before.colStart,r=t.amount;e<=0&&(r-=e,e=0);const n=this._getState().byOffset,o=new Map(n);if(n.forEach((t,n)=>{t&&0!==Object.keys(t).length&&(n>=e&&o.delete(n),n>e&&o.set(n+r,t))}),r>0&&this._getState().hiddenCount>0)for(let t=e;t<e+r;t++)o.set(t,{hiddenButton:!0});this._updateState({byOffset:o,hiddenCount:Vm(o),sort:null},{description:"Update Fields"})}return super._processContainerShift(t)}reapply(){const t=this._getState(),e=jm(t.byOffset);return this._apply?.(e),this}clear(){return this._updateState({byOffset:new Map,hiddenCount:0,sort:null},{description:"Set Filter Criteria"}),this.reapply()}_fromJSON(t){const e=t??{},r={byOffset:new Map,hiddenCount:0};e.fields&&(Hm(e.fields,r.byOffset),r.hiddenCount=Vm(r.byOffset)),e.sort,this._updateState(r,{description:"Load"})}toJSON(){const t={},e=this._getState();e.anchor&&(t.ref=sd(e.anchor,this._options.maxRangeCoords));const r=jm(e.byOffset);return r.length>0&&(t.fields=r),e.sort,0===Object.keys(t).length?null:t}}const Um="A table must have a least one row for the data.",Gm="Table1",Wm=Object.freeze({showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1}),qm=(t,e,r)=>{if(t.length!==e.length)return console.warn("make columns the same length"),!1;const n=new Set;for(let t=0;t<e.length;t++){const r=e[t]?.name;r&&n.add(r.toLocaleLowerCase())}for(let t=0;r&&t<r.length;t++){const e=r[t]?.name;e&&n.add(e.toLocaleLowerCase())}const o=(t,e="")=>{if(!t)return!1;const r=t.toLocaleLowerCase();return r===e||!n.has(r)};let s=1;const i=(t,e,r,n,o=1e3)=>{if(n(t,r=(r??"").trim().toLocaleLowerCase()))return t;for(;s<o;)try{const t=e+ ++s;if(n(t,r))return t}catch(t){}throw new Error(`Unable to find valid name for '${e}'.`)};let a=0;for(let r=0;r<t.length;r++){const s=t[r]?.name;if(s&&s===e[r]?.name)continue;const l=i(s,t[r]?.name||"Column",e[r]?.name,o);n.add(l.toLocaleLowerCase()),e[r]?.name!==l&&(t[r].name=l,a++)}return a>0};class Jm{constructor(t,e,r,n){this._name=t,this._filter=e,this._sort=r,this._offset=n}getName(){return this._name}getField(){return this._filter?this._filter.getFieldAt(this._offset)??null:null}setField(t){return this._filter?(this._filter.setFieldAt(this._offset,t),this):this}getSortField(){return this._sort?this._sort.getFieldAt(this._offset):null}setSortField(t){return this._sort?(this._sort.setFieldAt(this._offset,t),this):this}reapply(){return this._filter?.reapply(),this}clear(){return this._filter?.setFieldAt(this._offset,null),this._sort?.setFieldAt(this._offset,null),this}hasHiddenButton(){return this._filter?.getFieldAt(this._offset)?.hiddenButton??!1}}class Xm extends _l{constructor(t,e,r,n){super({...n,type:"namedTable"}),this._names=t,this._sheet=e,this._table=r;const o=this;this._table.addListeners({onDelete:()=>{o._options.deleteFromContainer?o._options.deleteFromContainer?.():o._delete()},onAnyChange:()=>{o._emitter.notify("onAnyChange")},onAnchorCoordsChange:()=>{o._emitter.notify("onAnyChange")}},{transactional:!0})}async select(t){return await this._table.select(t),this}getRanges(){return this._names.getRanges(this._table.getUsedRange())}getScope(){return null}getType(){return"table"}getName(){return this._table.getName()}getValue(){return this._table}}class Km extends Om{constructor(t){if(super({...t,createDescription:"Insert Table"}),this._isUpdatingHeader=!1,this._colHeadersSizeUnlistener=null,this._rowHeadersSizeUnlistener=null,this._visibleRange=null,this._isHeaderVisible=!0,this._isTotalVisible=!0,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0,this._range=null,!t.json)throw new Error("json is required");if(!t.json.ref)throw new Error("json.ref is required");const e=this;this._styles=t.styles??t.sheet?.getStyles()??new af,this._names=t.names,this._sheet=t.sheet,this._processTableUpdate=t.processTableUpdate,this._setNameOnContainer=t.setNameOnContainer,this._options={...t},this._styleCache=null,this._stylePropsCache=null,this._stylesRemoveListener=this._styles.addListeners({onTableStylesChange(){e._styleCache=null,e._stylePropsCache=null,e._getEmitter().notify("onStyleChange"),e._getEmitter().notify("onAnyChange")}});const r={...t?.json};if(t.sheet){const n=t.sheet;if(this._autoExpandRemoveListener=n.getEntireRange().addListener(t=>{if("setCells"!==t.trigger)return;if(t.isUndo)return;const r=e.getAnchorCoords();if(!r)return;let o=t.getSource().getCoords();Array.isArray(o)&&(o=o[0]);let s=null;if(o.rowStart>=r.rowStart&&o.rowEnd<=r.rowEnd&&o.colStart>=r.colStart&&o.colStart<=r.colEnd+1&&o.colEnd>r.colEnd){const t={...o,colStart:r.colEnd+1};if(n.getRange(t).isContentful()){const e={...t,rowStart:r.rowStart,rowEnd:t.rowStart-1};if(e.rowEnd-e.rowStart<0||!n.getRange(e).isContentful()){const e={...t,rowStart:t.rowEnd+1,rowEnd:r.rowEnd};(e.rowEnd-e.rowStart<0||!n.getRange(e).isContentful())&&(s={...r,colEnd:o.colEnd})}}}else if(!e.getShowTotals()&&o.colStart>=r.colStart&&o.colEnd<=r.colEnd&&o.rowStart>=r.rowStart&&o.rowStart<=r.rowEnd+1&&o.rowEnd>r.rowEnd){const t={...o,rowStart:r.rowEnd+1};if(n.getRange(t).isContentful()){const e={...t,colStart:r.colStart,colEnd:t.colStart-1};if(e.colEnd-e.colStart<0||!n.getRange(e).isContentful()){const e={...t,colStart:t.colEnd+1,colEnd:r.colEnd};(e.colEnd-e.colStart<0||!n.getRange(e).isContentful())&&(s={...r,rowEnd:o.rowEnd})}}}if(s&&n.getRange(s).getMerges().length>0&&(s=null),s&&1!==n.getTables().search({address:s}).length&&(s=null),s){const t=e._beginCommit("Table Auto Expansion");try{e.resize(s),t.commit({viewAfter:null})}catch(e){t.rollback(),console.warn("Unable to AutoExpand"),console.warn(e)}}},{transactional:!1,ignoreShifts:!0}),this._headerValueListener=()=>{if(this._isUpdatingHeader)return;const t=this._columnsFromSheet();t&&this._updateColumns(t.columns,!1,t.forceUpdate,null)},t.readSheetHeader){const t=this._columnsFromSheet();r.columns=t.columns}const o=()=>{const t=this.getAnchorCoords();let e=0,r=0;if(t&&(e=n.getColumnHeaders().findVisibleIndex(t.colEnd).min,r=n.getRowHeaders().findVisibleIndex(t.rowEnd).min),t&&(e<t.colEnd||r<t.rowEnd)){const o=n.getColumnHeaders(),s=n.getRowHeaders(),i=o.findVisibleIndex(t.colStart).max,a=s.findVisibleIndex(t.rowStart).max;this._visibleRange={colStart:i,colEnd:e,rowStart:a,rowEnd:r},this._isHeaderVisible=!s.at(t.rowStart).isHidden(),this._isTotalVisible=!s.at(t.rowEnd).isHidden(),this._isFirstColumnVisible=!o.at(t.colStart).isHidden(),this._isLastColumnVisible=!o.at(t.colEnd).isHidden()}else this._visibleRange=null,this._isHeaderVisible=!0,this._isTotalVisible=!0,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0},s={onSizesChange:()=>{o()}};this._colHeadersSizeUnlistener=n.getColumnHeaders().addListeners(s),this._rowHeadersSizeUnlistener=n.getRowHeaders().addListeners(s),o()}this._fromJSON(r),this._names&&(this._namedItem=this._createNamed(),this._namedItem&&this._names.add(this._namedItem))}getSnapshot(t){const e=this.toJSON(),r=this.getAnchorCoords(),n=this.getName(),o={...e};delete o.ref;const s=this,i=Object.freeze({...t});let a=!1;return{async copyTo(t,e){const n=t.tables,l=t.range;({...i,...e}).isCut&&!a&&(s.delete(),a=!0);const c={colStart:l.colStart,rowStart:l.rowStart,colEnd:r.colEnd-r.colStart+l.colStart,rowEnd:r.rowEnd-r.rowStart+l.rowStart};return n.add(c,{json:o,isLoad:!0,hasHeader:!0,styleName:o.styleOptions?.name??null}),c},getCoords:()=>r,getSource:()=>s,getName:()=>n,getMarkOptions:()=>i,isISnapshot:!0}}getAnchorType(){return exports.IAnchored.Type.TwoCell}getStyle(){if(this._styleCache)return this._styleCache;const t=this._getState();return t?(this._styleCache=this._styles.getTableStyle(t.styleOptions.name)??this._styles.getDefaultTableStyle(),this._styleCache):this._styles.getTableStyle(null)}addRows(t,e=1){const r={...this._getState().anchor};return r.rowEnd+=e,this._modifyTable({anchor:r},"Add Table Row"+(e>1?"s":"")),this}deleteRowsAt(t,e=1){let r={...this._getState().anchor};return r.rowEnd-=e,r.rowEnd<r.rowStart&&(r=null),this._modifyTable({anchor:r},"Delete Table Row"+(e>1?"s":"")),this}addColumn(t,e){const r=this._getState(),n={...r.anchor};n.colEnd+=1;const o=[];const s={name:`${e??r.columns[t-1]?.name??`Column${t+1}`}3`};o.push(s);const i=[...r.columns.slice(0,t),...o,...r.columns.slice(t)];return this._modifyTable({anchor:n,columns:i},"Add Table Column"),s}getColumns(){return this._getState()?.columns}convertToRange(t=Number.MAX_SAFE_INTEGER){let e=this._beginCommit("Convert to Range");try{if(this._sheet){const e=this.getAnchorCoords(),r=(e.colEnd-e.colStart+1)*(e.rowEnd-e.rowStart+1);if(r>t)throw new Error(`There are ${r} and there is a limit of ${t}.`);const n=this._sheet.getRange(e),o=n.startIncrementalUpdates({orientation:exports.t.Orientation.Column});n.forEach((t,e)=>{const r=e.getCoords(),n=e.getCell();o.pushAt(r.rowIndex,r.colIndex,{style:n.getStyle(!1)})},{includeEmpty:!0,orientation:exports.t.Orientation.Column}),o.apply()}this.delete()}catch(t){e.rollback(),e=null}return e&&e.commit(),this._sheet.getRange(this._getState()?.anchor)}resize(t,e="Resize Table"){let r=this._sheet.getRange(t).getCoords();const n=this._getState().anchor;if(n.rowStart!==r.rowStart||r.colEnd<n.colStart||r.colStart>n.colEnd)throw new Error("The top of the table must not change and the new table location must overlap with the original table.");const o=this._beginCommit(e);try{r=this._options.setContainerCoords(t),U.isEqualRanges(r,n)||this._modifyTable({anchor:r}),o.commit()}catch(t){throw console.warn(t),o.rollback(),t}return this._sheet.getRange(r)}getName(){return this._getState()?.name}setName(t){const e=this._beginCommit(`Set Table Name '${t}'`);try{this._modifyTable({name:t}),e.commit()}catch(t){throw e.rollback(),t}return this}getDescription(){return this._getState()?.description}setDescription(t){return this._modifyTable({description:t})}select(t){return this.getUsedRange().select(t)}getRange(){return this._range?this._range:this._getState()?this._range=this._sheet.getRange(this._getState().anchor):fm}_processRestoreOrRevert(t,e,r){this._styleCache=null,super._processRestoreOrRevert(t,e,r)}_processAnchorCoords(){this._range=null,super._processAnchorCoords()}getUsedRange(){const t=this._getUsedCoords();return t?this._sheet.getRange(t):fm}_getUsedCoords(){const t=this._getState(),e=t.headerRowCount,r=t.totalsRowCount,n=t.anchor;if(!n)return null;const o={...n,rowStart:n.rowStart+e,rowEnd:n.rowEnd-r};return o.rowEnd<o.rowStart||o.colEnd<o.colStart?null:o}getHeaderRange(){const t=this._getHeaderCoords();return t?this._sheet.getRange(t):fm}_getHeaderCoords(){const t=this._getState(),e=t.headerRowCount;if(e<1)return null;const r=t.anchor;return r?{...r,rowEnd:r.rowStart+e-1}:null}getTotalRange(){const t=this._getTotalCoords();return t?this._sheet.getRange(t):fm}_getTotalCoords(){const t=this._getState(),e=t.totalsRowCount;if(e<1)return null;const r=t.anchor;return r?{...r,rowStart:r.rowEnd-e+1}:null}getStyleOptions(){return this.isClosed()?Wm:this._getState()?.styleOptions}updateStyleOptions(t,e="Update Style Info"){const r=this.getStyleOptions(),n=t?{...r,...t}:Wm;return this._modifyTable({styleOptions:n},e),this._styleCache=null,this._getEmitter().notify("onStyleChange"),this}getStyleAt(t){let e=this._stylePropsCache;return e||(e=this.getStyle().getRanged(this),this._stylePropsCache=e),kp(this._styles,e,U.cellToRange(t))}getShowTotals(){const t=this._getState()?.totalsRowCount;return t>0}setShowTotals(t){return this._modifyTable({totalsRowCount:t?1:0},"Toggle Show Totals")}getShowHeaders(){const t=this._getState()?.headerRowCount;return t>0}setShowHeaders(t){return this._modifyTable({headerRowCount:t?1:0},"Toggle Show Headers")}getShowFilterButton(){const t=this.getFilter();return!!t&&t.getShowFilterButton()}setShowFilterButton(t){const e=this.getFilter();return e?(e.setShowFilterButton(t),this):this}_applyFilterAndSort(){console.log("apply Filter",this.getFilter(),this.getSort()),this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_processUpdate(){this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_createFilter(t){const e=this;return new $m({initialAnchor:this._getUsedCoords(),maxRangeCoords:this._options.maxRangeCoords,json:t,transactions:this._getTransactions(),setContainerShiftCallback(t){e._filterShiftCallback=t},setFilterCoordsCallback(t){e._filterCoordsCallback=t},deleteFromContainer:t=>{this._updateState({filter:null},{description:t?.description??"Delete Filter"}),e._processUpdate?.()},apply:t=>{e._applyFilterAndSort()},processUpdate:()=>{e._processUpdate?.()},isProtected:()=>e.isProtected()})}insertFilter(){let t=this.getFilter();return t||(t=this._createFilter(),this._updateState({filter:t},{description:"Insert Filter"}),t)}getFilter(){return this._getState()?.filter??null}_createSort(t){const e=this;return new zm({initialAnchor:this._getUsedCoords(),maxRangeCoords:this._options.maxRangeCoords,json:t,transactions:this._getTransactions(),deleteFromContainer:t=>{this._updateState({sort:null},{description:t?.description??"Delete Sort"}),e._processUpdate?.()},apply:t=>{e._applyFilterAndSort()},processUpdate:()=>{e._processUpdate?.()},isProtected:()=>e.isProtected()})}insertSort(){let t=this.getSort();return t||(t=this._createSort(),this._updateState({sort:t},{description:"Insert Sort"}),t)}getSort(){return this._getState()?.sort??null}getColumnFilter(t){const e=this.getFilter();if(!e)return null;const r=this.getSort();let n=null;return n=this._getState()?.columns[t],null===n?null:new Jm(n.name,e,r,t)}getVisibleRefRangeCoords(){return this._visibleRange?this._visibleRange:this.getAnchorCoords()}getVisibleCellCoords(t){return t&&this._visibleRange?{colIndex:Math.min(this._visibleRange.colEnd,Math.max(this._visibleRange.colStart,this._sheet.getColumnHeaders().findVisibleIndex(t.colIndex).min)),rowIndex:Math.min(this._visibleRange.rowEnd,Math.max(this._visibleRange.rowStart,this._sheet.getRowHeaders().findVisibleIndex(t.rowIndex).min))}:t}isHeaderVisible(){return this._isHeaderVisible}isTotalVisible(){return this._isTotalVisible}isFirstColumnVisible(){return this._isFirstColumnVisible}isLastColumnVisible(){return this._isLastColumnVisible}_columnsFromSheet(){const e=this._getHeaderCoords();if(!e||!this._sheet){const t=this.getAnchorCoords();return{columns:t?Array(t.colEnd-t.colStart+1).fill(null):[],forceUpdate:!0}}const r={columns:[],forceUpdate:!1};return this._sheet.getRange({...e,rowEnd:e.rowStart}).forEach((e,n)=>{const o=n.getCell();r.columns.push({name:o.toText()}),r.forceUpdate=r.forceUpdate||o.getType()!==t.String},{includeEmpty:!0}),r}_updateColumns(t,e,r=!1,n){if(this._isUpdatingHeader)return;const o=this._getHeaderCoords(),s=this._getUsedCoords(),i=[];if(s){const e=s.colEnd-s.colStart+1;for(let r=0;r<e;r++){const e=t[r];i.push({...e})}}let a=!1;const l=this._getState().columns;a=e?((t,e)=>{const r=new Set,n=t=>!!t&&!r.has(t.toLocaleLowerCase()),o=(t,e,r,n)=>n(t)?t:e+(r+1);let s=0;for(let i=0;i<t.length;i++){const a=o(t[i]?.name||e[i]?.name,t[i]?.name||"Column",s,n);r.add(a.toLocaleLowerCase()),t[i]?.name!==a&&(t[i].name=a,s++)}return s>0})(i,l):qm(i,l,n);if(!(r||l.length!==i.length||a))return;const c="Update Columns";this._isUpdatingHeader=!0;let h=this._beginCommit(c);try{if(this._updateState({columns:i},{description:c}),this._sheet&&o){const t=this._sheet.getEntireRange().startIncrementalUpdates({orientation:exports.t.Orientation.Row});for(let e=0;e<i.length;e++){const r=i[e].name;t.pushAt(o.rowStart,o.colStart+e,r)}t.apply({textParser:!1})}}catch(t){h.rollback()}return h&&h.commit(),this._isUpdatingHeader=!1,i}_processDelete(){const t=this._getState();t.headerRemoveListener?.(),this._updateState({headerRemoveListener:null}),super._processDelete()}_processFilterUpdate(){const t=this._getUsedCoords();console.log("process on Filter and Sort dataRange",t)}_processContainerShift(t){if(t.isSplit)throw new Error("We can not partially insert or remove cells as this would split a table.");const e=this._getState();if(t.after&&t.after.rowStart+e.headerRowCount>=t.after.rowEnd+1)throw new Error(Um);const r=t.orientation===exports.t.Orientation.Column;if(t.amount<0&&t.after&&!r){const e=this._getHeaderCoords();if(e&&t.intersect.rowStart<=e.rowEnd&&t.intersect.rowEnd>=e.rowStart)throw new Error("We can not remove rows that contain table headers. Remove the table header.")}const n=super._processContainerShift(t);if(r){let e=t.amount,r=t.intersect.colStart-t.before.colStart;if(r<=0&&e>0)return;r<0&&(e-=r,r=0);const n=this._getState()?.columns;let o=[...n],s=[],i=[];if(e>0){o.splice(r,0,...Array(e).fill(null)),s=[...o];const t=new Set;for(let e=0;e<n.length;e++)t.add(n[e]?.name?.toLowerCase().trim());const i=n[r-1],a=i?.name?.match(/\d+$/);let l=null,c=0;a&&(l=a.input.substring(0,a.index),c=parseInt(a[0]));for(let n=0;n<e;n++){let e={...i};s[r+n]=e;const o=l+(c+n+1);o&&!t.has(o.toLowerCase().trim())&&(e.name=o)}qm(s,o,null)}else s=o,i=s.splice(r,-e);this._updateState({columns:s},{description:"Process Columns"}),this._updateColumns(s,!1,!0,i)}else t.after||this._updateState({columns:[]},{description:"Process Columns"});return t.after||this._delete(),this._filterShiftCallback&&this._filterShiftCallback({...t,after:this._getUsedCoords()}),n}_modifyTable(t,e="Modify Table"){if(this.isClosed())throw new Error("Table has been closed. No further operations are allowed.");const r=this._getState(),n=r.anchor,o=r.headerRowCount,s=this._getHeaderCoords();let i=this._beginCommit(e);try{if(this._updateState(t),void 0!==t.name){if(!t.name)throw new Error("Table must have a name.");this._setNameOnContainer?.(t.name)}let a=t.anchor??null;if((void 0!==t.anchor||void 0!==t.headerRowCount||void 0!==t.totalsRowCount)&&void 0!==t.headerRowCount&&o!==t.headerRowCount)if(t.headerRowCount>o){const e=n.rowStart-(t.headerRowCount-o);this._sheet&&(e<this._options.maxRangeCoords.rowStart||this._sheet.getRange({...n,rowStart:e,rowEnd:n.rowStart-1}).isContentful())?(this._sheet.getRange({...n,rowStart:n.rowStart+t.headerRowCount,rowEnd:n.rowStart+t.headerRowCount}).insert(exports.t.Orientation.Row),a={...n,rowEnd:n.rowEnd+(t.headerRowCount-o)}):a={...n,rowStart:n.rowStart+(o-t.headerRowCount)}}else s&&this._sheet&&this._sheet.doBatch(()=>{this._sheet.getRange(s).clear()},{}),a={...n,rowStart:n.rowStart+(o-(t.headerRowCount??o))};if(a){let o=r.columns;const s=void 0!==t.headerRowCount&&t.headerRowCount!==r.headerRowCount||void 0!==t.totalsRowCount&&t.totalsRowCount!==r.totalsRowCount,i=a.colStart!==n.colStart||a.colEnd!==n.colEnd;let l=[];if(i){const t=[...r.columns];a.colEnd>n.colEnd?t.splice(n.colEnd+1,0,...Array(a.colEnd-n.colEnd).fill(null)):a.colEnd<n.colEnd&&(l=t.splice(a.colEnd-1,n.colEnd-a.colEnd)),a.colStart<n.colStart?t.splice(0,0,...Array(n.colStart-a.colStart).fill(null)):a.colStart>n.colStart&&(l=l.concat(t.splice(0,a.colStart-n.colStart))),o=t}if(this._options.setContainerCoords?.(a),this._updateState({anchor:a,columns:o},{description:e}),!this._getUsedCoords())throw new Error(Um);if(i||s){const t=s?{columns:o,forceUpdate:!0}:this._columnsFromSheet();t&&(this._updateColumns(t.columns,!1,t.forceUpdate,l),this._processHeaderListener())}this._filterCoordsCallback?.(a)}void 0!==t.styleOptions&&(this._styleCache=null),this._getEmitter().notify("onAnyChange"),i.commit()}catch(t){throw i.rollback(),t}return this}addListeners(t,e){return this._emitter.addListeners(t,e)}_processStateChange(t,e,r){super._processStateChange(t,e,r),this._styleCache=null,this._stylePropsCache=null,this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_processHeaderListener(){const t=this._getState();if(t.headerRemoveListener?.(),this._sheet){let t=this._getHeaderCoords();if(!t){const e=this._getUsedCoords();t={...e,rowEnd:e.rowStart}}const e=this._sheet.getRange(t).addListener(this._headerValueListener,{transactional:!0});this._updateState({headerRemoveListener:e})}}toJSON(){const t={},e=this._getState();if(!e)return null;if(e.name&&(t.name=e.name),e.anchor&&(t.ref=sd(e.anchor,this._options.maxRangeCoords)),e.description&&(t.description=e.description),1!==e.headerRowCount&&(t.headerRowCount=e.headerRowCount),0!==e.totalsRowCount&&(t.totalsRowCount=e.totalsRowCount),e.columns&&(t.columns=[...e.columns]),e.styleOptions){const r=mt.diffValues(e.styleOptions,{...Wm,name:null});r&&(t.styleOptions=r)}if(e.filter){const r=e.filter.toJSON();r&&(t.filter=r,delete t.filter.ref)}return t}_createNamed(){const t=this._sheet?.getName();return t&&this._names?new Xm(this._names,this._sheet,this,{transactions:this._getTransactions(),json:{name:this.getName()}}):null}_fromJSON(t){const e=t??{},r={headerRowCount:1,totalsRowCount:0};var n;if(e.name&&(r.name=e.name),e.ref&&(e.ref=(n=e.ref)&&"string"==typeof n?hd(n):n),this._names){const t=this._names.findValidName(r.name??Gm);r.name!==t&&(r.name=t)}r.name||(r.name=Gm),e.description&&(r.description=e.description),void 0!==e.headerRowCount&&(r.headerRowCount=e.headerRowCount),void 0!==e.totalsRowCount&&(r.totalsRowCount=e.totalsRowCount),r.columns=e.columns??mt.EmptyArray,r.styleOptions={...Wm,...e.styleOptions};const o="Insert Table";this._updateState(r,{description:o});const s=this._columnsFromSheet();s&&(r.columns=this._updateColumns(s.columns,!0,s.forceUpdate,null),delete r.columns),e.sort&&(r.sort=this._createSort(e.sort)),e.filter&&(r.filter=this._createFilter(e.filter)),this._modifyTable(r,o),this._processHeaderListener()}close(){super.close(),this.isClosed()||(this._autoExpandRemoveListener?.(),this._getState()?.headerRemoveListener?.(),this._updateState({headerRemoveListener:null},{description:"Close Table"}),this._stylesRemoveListener?.(),this._colHeadersSizeUnlistener?.(),this._rowHeadersSizeUnlistener?.())}get isITable(){return!0}}let Ym=null;const Zm="TableStyleMedium2",Qm=(t,e,r)=>{if(!t.border)return t;let n=((t,e,r)=>{if(!t)return t;let n=null;return(t.top||t.horizontal)&&(e.rowIndex!==r.rowStart||e.colIndex<r.colStart||e.colIndex>r.colEnd)&&(n=n??{...t},delete n.top,t.horizontal&&(n.top=t.horizontal)),(t.bottom||t.horizontal)&&(e.rowIndex!==r.rowEnd||e.colIndex<r.colStart||e.colIndex>r.colEnd)&&(n=n??{...t},delete n.bottom,t.horizontal&&(n.bottom=t.horizontal)),(t.left||t.vertical)&&(e.colIndex!==r.colStart||e.rowIndex<r.rowStart||e.rowIndex>r.rowEnd)&&(n=n??{...t},delete n.left,t.vertical&&(n.left=t.vertical)),(t.right||t.vertical)&&(e.colIndex!==r.colEnd||e.rowIndex<r.rowStart||e.rowIndex>r.rowEnd)&&(n=n??{...t},delete n.right,t.vertical&&(n.right=t.vertical)),t.horizontal&&(n=n??{...t},delete n.horizontal),t.vertical&&(n=n??{...t},delete n.vertical),n??t})(t.border,e,r),o=t;return n!==t.border&&(o={...t},Object.keys(n).length>0?o.border=n:delete o.border),o};class tf{constructor(t,e,r){this._table=t,this._styles=e,this._properties=r}_resolveProperties(t){const e={name:t.name},r=this._styles,n=Object.values(exports.ITableStyle.ElementType),o=n.length;for(let s=0;s<o;s++){const o=n[s],i=t[o];if(!i||!mt.isObject(i))continue;const a=exports.ft.resolveTypedUpdates(Object.freeze(i),ap,r);e[o]=a}return Object.freeze(e)}getCoords(){return this._table.getAnchorCoords()}getPropertiesAt(t,e){const r=this._table,n=this._styles,o=this._properties;rf.rowIndex=t,rf.colIndex=e;const s=r.getVisibleCellCoords(rf),i=r.getVisibleRefRangeCoords();if(!i)return null;const a=Math.max(0,i.colEnd-i.colStart)+1,l=Math.max(0,i.rowEnd-i.rowStart)+1,c=Math.max(0,s.rowIndex-i.rowStart),h=Math.max(0,s.colIndex-i.colStart),d={rowIndex:c,colIndex:h},u=r.getStyleOptions();let g={},p=!1,m=0;r.isHeaderVisible()&&(m=r.getShowHeaders()?1:0,p=m>c);let f=!1,_=0;r.isTotalVisible()&&(_=r.getShowTotals()?1:0,f=l-_<=c);let S=h===a-1&&u.showLastColumn;r.isLastColumnVisible()||(S=!1);let w=0===h&&u.showFirstColumn;r.isFirstColumnVisible()||(w=!1);const y=!p&&!f;if(o.wholeTable&&(g=o.wholeTable,g.border&&(g=Qm(g,d,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:a-1}))),y&&u.showColumnStripes){const t=o.firstColumnStripe?.size??1,e=o.secondColumnStripe?.size??1;let r=h%(t+e);const s=r<t;s||(r-=t);let i=s?o.firstColumnStripe:o.secondColumnStripe;if(i){const d={rowIndex:c,colIndex:r},u={rowStart:m,rowEnd:l-_-1,colStart:0,colEnd:Math.min(a-h,s?t:e)};s&&0===r&&h>0&&i.border?.left&&o.secondColumnStripe?.border.right&&(i={...i},i.border={...i.border},delete i.border.left),s&&r===t-1&&h<a-1&&i.border?.right&&o.secondColumnStripe?.border.left&&(i={...i},i.border={...i.border},delete i.border.right);const p=i.border?Qm(i,d,u):i;g=exports.ft.resolveTypedUpdates(p,ap,n,g)}}if(y&&u.showRowStripes){const t=m,e=o.firstRowStripe?.size??1,r=o.secondRowStripe?.size??1;let s=(c-t)%(e+r);const i=s<e;i||(s-=e);let d=i?o.firstRowStripe:o.secondRowStripe;if(d){const u={colIndex:h,rowIndex:s},p={colStart:0,colEnd:a-1,rowStart:0,rowEnd:Math.min(l-c,i?e:r)};i&&0===s&&c>t&&d.border?.top&&o.secondRowStripe?.border.bottom&&(d={...d},d.border={...d.border},delete d.border.top),i&&s===e-1&&c<l-1&&d.border?.bottom&&o.secondRowStripe?.border.top&&(d={...d},d.border={...d.border},delete d.border.bottom);const m=d.border?Qm(d,u,p):d;g=exports.ft.resolveTypedUpdates(m,ap,n,g)}}if(S&&o.lastColumn){let t=o.lastColumn;t.border&&(t=Qm(t,d,{rowStart:0,rowEnd:l-1,colStart:a-1,colEnd:a-1})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(w&&o.firstColumn){let t=o.firstColumn;t.border&&(t=Qm(t,d,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:0})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(p&&o.headerRow){let t=o.headerRow;t.border&&(t=Qm(t,d,{rowStart:0,rowEnd:m-1,colStart:0,colEnd:a-1})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(f&&o.totalRow){let t=o.totalRow;t.border&&(t=Qm(t,d,{rowStart:l-_,rowEnd:l-1,colStart:0,colEnd:a-1})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(p&&w&&o.firstHeaderCell){let t=o.firstHeaderCell;t.border&&(t=Qm(t,d,{rowStart:0,rowEnd:m-1,colStart:0,colEnd:0})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(p&&S&&o.lastHeaderCell){let t=o.lastHeaderCell;t.border&&(t=Qm(t,d,{rowStart:0,rowEnd:m-1,colStart:a-1,colEnd:a-1})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(f&&w&&o.firstTotalCell){let t=o.firstTotalCell;t.border&&(t=Qm(t,d,{rowStart:l-_,rowEnd:l-1,colStart:0,colEnd:0})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}if(f&&S&&o.lastTotalCell){let t=o.lastTotalCell;t.border&&(t=Qm(t,d,{rowStart:l-_,rowEnd:l-1,colStart:a-1,colEnd:a-1})),g=exports.ft.resolveTypedUpdates(t,ap,n,g)}return p&&o.headerRow&&r.getColumnFilter(h)&&!r.getColumnFilter(h).hasHiddenButton()&&(g.insets={right:15}),g}}class ef{constructor(t,e,r,n){this._styles=t,this._isBuiltIn=r,this._doDelete=n,this._properties=mt.deepFreeze(this._resolveProperties(e)),this.isShownInTableStyles()}_resolveProperties(t){const e={name:t.name};void 0!==t.table&&(e.table=t.table),void 0!==t.pivot&&(e.pivot=t.pivot);const r=this._styles,n=Object.values(exports.ITableStyle.ElementType),o=n.length;for(let s=0;s<o;s++){const o=n[s],i=t[o];if(!i||!mt.isObject(i))continue;const a=exports.ft.resolveTypedUpdates(Object.freeze(i),ap,r);e[o]=a}return Object.freeze(e)}delete(){if(!this._doDelete)throw new Error("Not able to delete builtin style.");this._doDelete(this._properties.name)}getRanged(t){return new tf(t,this._styles,this._properties)}getProperties(){return this._properties}getName(){return this._properties.name}isShownInTableStyles(){return!1!==this._properties.table}isShownInPivotStyles(){return this._properties.pivot??!1}isBuiltIn(){return this._isBuiltIn}toJSON(){const t=mt.cloneObject(this._properties);return t.name=this._properties.name,t}get isITableStyle(){return!0}}const rf={rowIndex:0,colIndex:0};class nf extends Lp{constructor(t,e){super(t,U.EmptyRange,e)}isEmpty(){return null===this._p}getCoords(){return this._r}cloneWithUpdate(t){if(void 0===t)return this;const e=this._c,r=this._r,n=exports.ft.resolveTypedUpdates(t,ap,e,this._p);return new Lp(e,r,n)}_createShifted(t){return new Lp(this._c,t,this._p)}getShifted(t){return t.after?{...t.after,value:this._createShifted(U.sanitizeRange(t.after))}:null}getSplit(t,e){const r=this._c,n=this._p;return[new Lp(r,t[0],n),new Lp(r,t[1],n)]}getMerged(t,e,r){const n=this._p,o=t._p;if(n&&!o||o&&!n||!n&&!o)return;let s=Object.keys(n),i=Object.keys(o);if(n.named===exports.IStyle.BuiltInName.Normal&&(s=s.filter(t=>t.toLowerCase()!==exports.IStyle.BuiltInName.Normal)),o.named===exports.IStyle.BuiltInName.Normal&&(i=i.filter(t=>t.toLowerCase()!==exports.IStyle.BuiltInName.Normal)),s.length!==i.length)return;for(let t=0;t<s.length;t++){const e=s[t],r=n[e],i=o[e];if(!mt.deepEqual(r,i))return}const a=this._c;return new Lp(a,e,this._p)}getPropertiesAt(t,e){return this._p}toJSON(){return mt.toSafeJSON(this._p)}}class of{constructor(t,e,r,n=null){this._name=e.name,this._properties=e,this._rangeStyle=new nf(t,e.style),this._doDelete=r,this._builtInID=n}getRanged(){return this._rangeStyle}getName(){return this._name}isHidden(){return this._properties.hidden??!1}getILevel(){return this._properties.iLevel??null}getBuiltInID(){return this._builtInID}delete(){this._doDelete?.(this)}toJSON(){return this._properties?mt.toSafeJSON(this._properties):null}get isINamed(){return!0}}let sf=class{constructor(t,e,r,n,o){this._state=t,this._normalJSON=e??{},this._toJSONInternal=r,this._fromJSONInternal=n,this._onLastEnd=o,this._state.openScopes.add(this),this._isClosed=!1,this._state.byJSONs.set(vt(this._normalJSON),0),this._state.byIds.set(0,this._normalJSON)}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}getElementID(t){if(this._isClosed)throw new Error("PersistScope is closed.");const e=vt(t=t??{});let r=this._state.byJSONs.get(e);return void 0!==r||(r=this._state.byJSONs.size,this._state.byJSONs.set(e,r),this._state.byIds.set(r,t)),r}getElementJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");const e=JSON.parse(JSON.stringify(t||{}));this._fromJSONInternal(e);const r=e.direct;if(r)for(let t=0;t<r.length;t++){const e=t,n=r[t],o=vt(n);this._state.byIds.set(e,n),this._state.byJSONs.set(o,e)}}toJSON(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byIds.forEach((e,r)=>{t[r]=e}),1===t.length&&t.splice(0,1),this._toJSONInternal(t)}};class af{constructor(t=null,e=null,r=11){this._emitter=null,this._normalRanged=null,this._theme=t??(new ul).getDefaultTheme(),this._defaultFontSize=r;const n=this;this._emitter=new ml(this),this._schemeLookup=t=>n._theme.schemeLookup()(t),this._indexedColors=this._fromJSONIndexedColors(e),this._indexedLookup=t=>{const e=this._indexedColors[t];return e?e.toRGBA():Lo(t)},this._initializeBuiltIns(),this._customCellStyles=new Map,this._customTableStyles=new Map,this._indexedColors=[],this._mruColors=[],this._persistCache=null}_initializeNamedStyles(t,e){for(let r=0;r<t.length;r++){const n=t[r],o={...n},s=n.named;delete o.named;const i=exports.ft.resolveTypedUpdates(o,ap,this),a=new of(this,{name:s,style:i},this._hideOrRemoveNamed.bind(this),r);s===exports.IStyle.BuiltInName.Normal&&(this._normalRanged=a.getRanged(),this._normalStyle=kp(this,null)),e.set(s.toLowerCase(),a)}}_initializeTableStyles(){const t=(()=>{if(Ym)return Ym;Ym=new Map;const t=(t,e)=>{if(0===e)return"TableStyleNone";let r="Custom";return"l"===t?r="Light":"m"===t?r="Medium":"d"===t&&(r="Dark"),`TableStyle${r}${e}`},e=(t,e=0)=>0===e?t:e>0?`${t} lumMod ${100-e}, lumOff ${e}`:e<0?`${t} lumMod ${100+e}`:void 0,r=t=>({type:exports.IFill.Type.Pattern,patternType:exports.IFill.BuiltInSheetPattern.Solid,foreground:t,background:t}),n=(t,e=!1)=>{const r={fill:t};return e&&(r.weight=700),r},o=(t,e=exports.IBorder.StrokeStyle.Thin)=>({style:e,color:t}),s=(t,e)=>{for(let r=0;r<7;r++)t.push(e(`accent${r+1}`))};let i=0,a=[];a.push(["dk1",e("bg1",-15),"dk1"]),s(a,t=>[e(t,-25),e(t,80),t]),i=1;for(let e=0;e<7;e++){const s=t("l",e+i),l=a[e][0],c=a[e][1]??l,h=a[e][2]??l;Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),border:{top:o(h),bottom:o(h)}},headerRow:{font:n(l,!0),border:{bottom:o(h)}},totalRow:{font:n(l,!0),border:{top:o(h)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{fill:r(c)},firstColumnStripe:{fill:r(c)}}))}i+=7,a=[],a.push(["dk1","dk1","lt1"]),s(a,t=>["dk1",t,"lt1"]);for(let e=0;e<7;e++){const s=t("l",e+i),l=a[e][0],c=a[e][1],h=a[e][2];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),border:{left:o(c),right:o(c),top:o(c),bottom:o(c)}},headerRow:{font:n(h,!0),fill:r(c)},totalRow:{font:n(l,!0),border:{top:o(c,exports.IBorder.StrokeStyle.Double)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{border:{top:o(c)}},secondRowStripe:{border:{top:o(c)}},firstColumnStripe:{border:{left:o(c)}},secondColumnStripe:{border:{left:o(c)}}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15)]),s(a,t=>[t,e(t,80)]);for(let e=0;e<7;e++){const s=t("l",e+i),l="dk1",c=a[e][0],h=a[e][1];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),border:{left:o(c),right:o(c),top:o(c),bottom:o(c),horizontal:o(c),vertical:o(c)}},headerRow:{font:n(l,!0)},totalRow:{font:n(l,!0),border:{top:o(c,exports.IBorder.StrokeStyle.Double)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{fill:r(h)},firstColumnStripe:{fill:r(h)}}))}i=1,a=[],a.push(["dk1","dk1",e("bg1",-15)]),s(a,t=>[t,e(t,40),e(t,80)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c="lt1",h=a[e][0],d=a[e][1],u=a[e][2];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),border:{left:o(d),right:o(d),top:o(d),bottom:o(d),horizontal:o(d)}},headerRow:{font:n(c,!0),fill:r(h)},totalRow:{font:n(l,!0),border:{top:o(h,exports.IBorder.StrokeStyle.Double)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35)]),s(a,t=>[t,e(t,80),e(t,60)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c="lt1",h=a[e][0],d=a[e][1],u=a[e][2];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),fill:r(d),border:{horizontal:o(c),vertical:o(c)}},headerRow:{font:n(c,!0),fill:r(h),border:{bottom:o(c,exports.IBorder.StrokeStyle.Thick)}},totalRow:{font:n(c,!0),fill:r(h),border:{top:o(c,exports.IBorder.StrokeStyle.Thick)}},firstColumn:{font:n(c,!0),fill:r(h)},lastColumn:{font:n(c,!0),fill:r(h)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35)]),s(a,t=>[t,e(t,80),e(t,60)]);for(let s=0;s<7;s++){const l=t("m",s+i),c="dk1",h="lt1",d=a[s][0],u=e("bg1",-15);Ym.set(l.toLocaleLowerCase(),Object.freeze({name:l,wholeTable:{font:n(c),border:{top:o(c,exports.IBorder.StrokeStyle.Medium),bottom:o(c,exports.IBorder.StrokeStyle.Medium),left:0===s?o(c,exports.IBorder.StrokeStyle.Thin):void 0,right:0===s?o(c,exports.IBorder.StrokeStyle.Thin):void 0,horizontal:0===s?o(c,exports.IBorder.StrokeStyle.Thin):void 0,vertical:0===s?o(c,exports.IBorder.StrokeStyle.Thin):void 0}},headerRow:{font:n(h,!0),fill:r(d),border:{bottom:o(c,exports.IBorder.StrokeStyle.Medium)}},totalRow:{border:{top:o(c,exports.IBorder.StrokeStyle.Double)}},firstColumn:{font:n(h,!0),fill:r(d)},lastColumn:{font:n(h,!0),fill:r(d)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35),"dk1"]),s(a,t=>[t,e(t,80),e(t,60),e(t,40)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c=a[e][0],h=a[e][1],d=a[e][2],u=a[e][3];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),fill:r(h),border:{top:o(u),right:o(u),left:o(u),bottom:o(u),vertical:o(u),horizontal:o(u)}},headerRow:{font:n(l),fill:r(h)},totalRow:{font:n(l),border:{top:o(c,exports.IBorder.StrokeStyle.Medium)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}i=1,a=[],a.push(["dk1",e("dk1",15),e("dk1",25),e("dk1",50)]),s(a,t=>["dk1",e(t,-50),e(t,-25),t]);for(let e=0;e<7;e++){const s=t("d",e+i),l="lt1",c=a[e][0],h=a[e][1],d=a[e][2],u=a[e][3];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),fill:r(u)},headerRow:{font:n(l,!0),fill:r(c),border:{bottom:o(l,exports.IBorder.StrokeStyle.Medium)}},totalRow:{font:n(l,!0),fill:r(h),border:{top:o(l,exports.IBorder.StrokeStyle.Medium)}},firstColumn:{font:n(l,!0),fill:r(d),border:{right:o(l,exports.IBorder.StrokeStyle.Medium)}},lastColumn:{font:n(l,!0),fill:r(d),border:{left:o(l,exports.IBorder.StrokeStyle.Medium)}},firstRowStripe:{fill:r(d)},firstColumnStripe:{fill:r(d)}}))}i+=7,a=[],a.push([e("bg1",-15),"dk1",e("bg1",-35)]),a.push([e("accent1",80),"accent2",e("accent1",60)]),a.push([e("accent3",80),"accent4",e("accent3",60)]),a.push([e("accent5",80),"accent6",e("accent5",60)]);for(let e=0;e<4;e++){const s=t("d",e+i),l="dk1",c="lt1",h=a[e][0],d=a[e][1],u=a[e][2];Ym.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:n(l),fill:r(h)},headerRow:{font:n(c,!0),fill:r(d)},totalRow:{font:n(l,!0),border:{top:o(l,exports.IBorder.StrokeStyle.Double)}},firstColumn:{font:n(l,!0)},lastColumn:{font:n(l,!0)},firstRowStripe:{fill:r(u)},firstColumnStripe:{fill:r(u)}}))}return Ym})(),e=new Map;return t.forEach((t,r)=>{const n=t.name.toLowerCase(),o=new ef(this,t,!0);e.set(n,o)}),e}_initializeBuiltIns(){const t=new Map;this._builtInsCellStyles=t,this._initializeNamedStyles(_p,t),this._builtInsTableStyles=this._initializeTableStyles(),this._emptyTableStyle=new exports.ITableStyle.Empty(this._normalStyle)}getNormal(){return this._normalStyle}getNormalRanged(){return this._normalRanged}setTheme(t){this._theme=t,this._emitter.notify("onThemeChange"),this._emitter.notify("onAnyChange")}getTheme(){return this._theme}setDefaultFontSize(t){this._defaultFontSize=t,this._emitter.notify("onDefaultFontChange"),this._emitter.notify("onAnyChange")}getDefaultFontSize(){return this._defaultFontSize}beginPersist(){return this._persistCache||(this._persistCache={byIds:new Map,byJSONs:new Map,openScopes:new Set}),new sf(this._persistCache,{},this._toJSONInternal.bind(this),this._fromJSONInternal.bind(this),()=>{this._persistCache=null})}getNamed(t){if(!t)return null;t=t.toLowerCase();let e=null;return this._customCellStyles&&(e=this._customCellStyles.get(t)),e||(e=this._builtInsCellStyles.get(t)),e??null}getCustomNamed(){const t=Array.from(this._customCellStyles.values());return t.sort((t,e)=>t.getName().localeCompare(e.getName())),t}setNamed(t,e=!1){if(!t||!t.name||!t.style)throw new Ft;this.validateStyleName(t.name,!1);const r=this._setCustomCellStyleInternal(t,e);return this._emitter.notify("onNamedStylesChange"),this._emitter.notify("onAnyChange"),r}_setCustomCellStyleInternal(t,e=!1,r=0){const n=t.name.toLowerCase(),o=this._builtInsCellStyles.get(n),s=o?.getBuiltInID()??null;let i=null;if(e){const t=this._customCellStyles.get(n)??o;i=t?._properties??null}const a=wp(0,t.style,this.getNormal());t={...t,style:a};const l=exports.ft.resolveTypedUpdates(t,lp,this,i),c=new of(this,l,this._hideOrRemoveNamed.bind(this),s);return l.name===exports.IStyle.BuiltInName.Normal&&(this._normalRanged=c.getRanged(),this._normalStyle=kp(this,null)),this._customCellStyles.set(n,c),c}_setCustomTableStyleInternal(t,e){const r=t.toLowerCase();let n=this._customTableStyles.get(r)??this._builtInsTableStyles.get(r);n&&(t=n.getName());const o=new ef(this,{...e,name:t},!1,this._deleteCustomTableStyle.bind(this));return this._customTableStyles.set(r,o),o}_hideOrRemoveNamed(t){let e=null;if(e="string"==typeof t?t:t?.getName?.(),!e)return!1;if(e=e.toLowerCase(),e===exports.IStyle.BuiltInName.Normal.toLowerCase())return!1;const r=this._builtInsCellStyles.get(e);let n=!1;if(r&&!r.isHidden()){const t=r.toJSON();this.setNamed({...t,hidden:!0}),n=!0}else e=e.toLowerCase(),n=this._customCellStyles.delete(e);return n&&(this._emitter.notify("onNamedStylesChange"),this._emitter.notify("onAnyChange")),n}getTableStyle(t){if(!t)return this._emptyTableStyle;let e=this._customTableStyles.get(t.toLowerCase());return e||(e=this._builtInsTableStyles.get(t.toLowerCase())),e??null}getCustomTableStyles(){const t=Array.from(this._customTableStyles.values());return t.sort((t,e)=>t.getName().localeCompare(e.getName())),t}setDefaultTableStyle(t){const e=t?.toLowerCase();return this._defaultTableStyle=this._customTableStyles.get(e)??this._builtInsTableStyles.get(e)??this._builtInsTableStyles.get(Zm.toLowerCase()),this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),t===this._defaultTableStyle.getName()}getDefaultTableStyle(){return this._defaultTableStyle||(this._defaultTableStyle=this._builtInsTableStyles.get(Zm.toLowerCase())),this._defaultTableStyle}_deleteCustomTableStyle(t){const e=this._customTableStyles.get(t?.toLowerCase());return!!e&&(this._customTableStyles.delete(t.toLowerCase()),this._defaultTableStyle?.getName()===e.getName()&&(this._defaultTableStyle=this._builtInsTableStyles.get(Zm.toLowerCase())),this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),!0)}setCustomTableStyle(t,e){const r=this._setCustomTableStyleInternal(t,e);return this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),r}validateStyleName(t,e=!1){if(!t||0===t.trim().length)throw new Error("Style name cannot be empty.");if(e&&null!==this.getNamed(t))throw new Error("Style name is already taken.")}normalize(t){if(!t)return null;const e=exports.ft.resolveTypedUpdates(t,ap,this),r=fp;let n=null;if(n=e.named?this.getNamed(e.named)?.getRanged().getPropertiesAt(0,0,null):this._normalRanged.getPropertiesAt(0,0,null),n){const t={...n};mt.removeEqualValues(e,t)}const o=this.getTheme().getFontScheme();return mt.removeEqualValues(e,{font:{size:this.getDefaultFontSize(),family:o.getMinorFont(),fallbacks:o.getMinorFallbacks()}}),mt.removeEqualValues(e,r),e}schemeLookup(){return this._schemeLookup}indexedLookup(){return this._indexedLookup}parseColor(t){return ba.parse(t,this._schemeLookup,this._indexedLookup)}recentColors(){return this._mruColors}addRecentColor(t){if(!t)return;const e=this._mruColors,r=[],n=t.toString();for(let t=0;t<e.length&&t<10;t++){e[t].toString()!==n&&r.push(e[t])}return r.unshift(t),this._mruColors=Object.freeze(r),this._mruColors}clearRecentColors(){this._mruColors=Object.freeze([])}getIndexedColors(){return this._indexedColors}setCustomIndexedColors(t){this._indexedColors=t?.length>0?[...t]:null}getCustomIndexedColors(){const t=Math.max(this._indexedColors?.length,66),e=[];for(let r=0;r<t;r++)null!==this._indexedColors[r]&&e.push(this._indexedColors[r]??new ba(Lo(r)?.toString()));return e}addListeners(t,e){return this._emitter.addListeners(t,e)}_toJSONInternal(t){const e={};t.length>0&&(e.direct=t);const r=this.getCustomNamed();let n=[];for(let t=0;t<r.length;t++){let e=r[t].toJSON();n.push(e)}n.length>0&&(e.named=n);const o={};this._defaultTableStyle&&this._defaultTableStyle.getName()!==Zm&&(o.defaultTableStyle=this._defaultTableStyle.getName());const s={},i=this.getCustomTableStyles();for(let t=0;t<i.length;t++){let e=i[t].toJSON();delete e.name,e&&Object.keys(e).length>0&&(s[i[t].getName()]=e)}if(Object.keys(s).length>0&&(o.styles=s),Object.keys(o).length>0&&(e.tables=o),this._indexedColors.length>0){e.indexedColors=[];for(let t=0;t<this._indexedColors.length;t++)e.indexedColors.push(this._indexedColors[t].toString())}if(this._mruColors.length>0){e.mruColors=[];for(let t=0;t<this._mruColors.length;t++)e.mruColors.push(this._mruColors[t].toString())}return 0===Object.keys(e).length?null:e}_fromJSONIndexedColors(t){if(!t||0===t.length)return mt.EmptyArray;const e=[];if(t?.length>0)for(let r=0;r<t.length;r++)try{e.push(this.parseColor(t[r]))}catch(e){console.warn("Unable to parse color: "+t[r])}return e}_fromJSONInternal(t){this._indexedColors=this._fromJSONIndexedColors(t.indexedColors);const e=t.named;for(let r=0;e&&r<e.length;r++)this._setCustomCellStyleInternal(t.named[r]);let r=Zm;if(this._defaultTableStyle=null,t.tables){t.tables.defaultTableStyle&&(r=t.tables.defaultTableStyle);const e=t.tables.styles?Object.keys(t.tables.styles):null;for(let r=0;e&&r<e.length;r++){const n=e[r],o=t.tables.styles[n];this._setCustomTableStyleInternal(n,o)}}this._defaultTableStyle=this.getTableStyle(r);let n=[];if(t.mruColors?.length>0)for(let e=0;e<t.mruColors.length;e++)try{n.push(this.parseColor(t.mruColors[e]))}catch(r){console.warn("Unable to parse color: "+t.mruColors[e])}this._mruColors=n}}const lf="BinaryResource must have only one initial data value.",cf="Resource is closed.";class hf{constructor(t){if(this._listeners=new Set,this._type=t.type,this._name=t?.name,t.base64){const e=t.base64;this._asArrayBufferResolve=async()=>{const t=await Promise.resolve(e);return Promise.resolve(wt.base64ToArrayBuffer(t))}}if(t.fetch){if(this._asArrayBufferResolve)throw new Error(lf);const e=t.fetch;this._asArrayBufferResolve=async()=>{let r,n=null;n="string"==typeof e?e:t.input;const o=await fetch(n,r),s=o.headers.get("Content-Type");return!this._type&&s&&(this._type=s),o.arrayBuffer()}}if(t.buffer){if(this._asArrayBufferResolve)throw new Error(lf);this._asArrayBufferResolve=async()=>{let e=null;return e="function"==typeof t.buffer?await t.buffer():t.buffer,Promise.resolve(e)}}if(t.file){if(this._asArrayBufferResolve)throw new Error(lf);this._asArrayBufferResolve=async()=>{const e=await Promise.resolve(t.file);return await e.arrayBuffer()}}if(!this._asArrayBufferResolve)throw new Error("BinaryResource must have an initial data value.");this._refs=new Set,this._isClosed=!1}getName(){return this._name}async toJSONAsync(){const t=await this.toBuffer(),e={base64:wt.arrayBufferToBase64(t)};return this._type!==wt.DEFAULT_MIME_TYPE&&(e.type=this._type),this._name&&(e.name=this._name),e}async toBuffer(){if(this._asArrayBuffer)return this._asArrayBuffer;try{this._asArrayBuffer=this._asArrayBufferResolve()}catch(t){throw t}return this._asArrayBuffer}async getType(){return this._type?this._type:(await this.toBuffer(),this._type??wt.DEFAULT_MIME_TYPE)}addReference(t){if(this._isClosed)throw new Error(cf);this._refs.add(t)}deleteReference(t){if(this._isClosed)throw new Error(cf);if(0===this._refs.size||!this._refs.has(t))return;this._refs.delete(t);const e=this;if(0===this._refs.size){const t=this._listeners;t.forEach(r=>{r.onUnload?.(e),t.delete(r)}),this._asArrayBuffer=null,this._isClosed=!0}}addUnloadListener(t){if(this._isClosed)throw new Error(cf);this._listeners.add(t)}get isIResource(){return!0}isClosed(){return this._isClosed}}let df=class{constructor(t,e,r){this._state=t,this._fromJSON=e,this._onLastEnd=r,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}toResourceId(t){if(this._isClosed)throw new Error("PersistScope is closed.");let e=this._state.byRefs.get(t);return void 0!==e||(e=this._state.byRefs.size,this._state.byRefs.set(t,e),this._state.byIds.set(e,t)),e}fromResourceId(t){return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");if(!t||0===t.length)return;const e=this._state.byRefs.size;for(let r=0;r<t.length;r++){const n=t[r],o=this._fromJSON(n);this._state.byRefs.set(o,e+r),this._state.byIds.set(e+r,o)}}toJSONAsync(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byRefs.forEach((e,r)=>{t[e]=Promise.resolve(r.toJSONAsync())}),Promise.all(t)}};class uf{constructor(){this._resources=new Set}add(t){if("string"==typeof t){let e=!1;this._resources.forEach(r=>{r.getName()===t&&(e=!0,t=r)}),e||(t=new hf({name:t,fetch:t,type:null}))}let e=null;e=t instanceof hf?t:new hf({...t});const r=this;return this._resources.has(e)||(e.addUnloadListener({onUnload:t=>{r._resources.delete(e)}}),this._resources.add(e)),e}getCount(){return this._resources.size}beginPersist(){this._persistOpen||(this._persistOpen={byRefs:new Map,byIds:new Map,openScopes:new Set});const t={},e=new Set,r=this;return new df(this._persistOpen,n=>{const o=r.add({base64:n.base64,name:n.name,type:n.type});return o.addReference(t),e.add(o),o},()=>{e.forEach(e=>{e.deleteReference(t)}),r._persistOpen=null})}}class gf{constructor(t,e,r){this._state=t,this._fromJSON=e,this._onLastEnd=r,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}add(t){if(this._isClosed)throw new Error("PersistScope is closed.");let e=this._state.byRefs.get(t);return void 0!==e||(e=this._state.byRefs.size,this._state.byRefs.set(t,e),this._state.byIds.set(e,t)),e}at(t){return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");t&&0!==t.length&&this._fromJSON(t)}toJSONAsync(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byRefs.forEach((e,r)=>{t[e]=Promise.resolve(r.toJSONAsync?r.toJSONAsync():r)}),Promise.all(t)}}class pf{constructor(){this._nextId=0,this._lastReadId=-1,this._lastReadValue=null,this._stringsByText=new Map,this._stringsById=new Map}addMultiple(t,e=!1){const r=this._stringsByText,n=this._stringsById,o=t.length;let s=this._nextId;for(let i=0;i<o;i++){const o=t[i];void 0!==r.get(o)&&e||(r.set(o,s),n.set(s,o),s++)}this._lastReadId=-1,this._nextId=s}add(t){const e=this._stringsByText,r=e.get(t);if(void 0!==r)return r;const n=this._nextId++;return e.set(t,n),this._stringsById.set(n,t),this._lastReadId=-1,n}getById(t){if(this._lastReadId===t)return this._lastReadValue;const e=this._stringsById.get(t)??null;return this._lastReadId=t,this._lastReadValue=e,e}getCount(){return this._stringsById.size}beginPersist(){this._persistOpen||(this._persistOpen={byRefs:new Map,byIds:new Map,openScopes:new Set});const t=this;return new gf(this._persistOpen,e=>(Array.isArray(e)?t.addMultiple(e):t.add(e),e),()=>{t._persistOpen=null})}}exports.IPicture=void 0,exports.IPicture||(exports.IPicture={});class mf extends fl{constructor(t){super(t),t.json&&(this._resource=t.fromResourceId(t.json.resId))}getType(){return"picture"}toJSON(t){const e={},r=t?.(this._resource);null!==r&&(e.resId=r);const n=this._getState();return n&&n.effects&&(e.effects=n.effects),e}getTypeDescription(){return"Picture"}async _asDataUrl(){if(this._dataUrl)return this._dataUrl;const t=await this.getDetails(),e=await Et.getImageDataUrl(t.asUrl());return this._dataUrl=e.dataUrl,this._dataUrl}toHtml(){return null}async toImage(){const t=(await this._asDataUrl()).substring(Et.DATA_URL_PNG_PREFIX.length),e=wt.base64ToArrayBuffer(t);return new Blob([e],{type:w.png})}async getDetails(){return this._details||(this._details=new Promise(async(t,e)=>{try{const e=await this._resource.toBuffer(),r=await this._resource.getType(),n=await Et.loadImageDetails(e,r);t({getNaturalDimensions:()=>n.naturalDimensions,asUrl:()=>n.asUrl,asSVGText:()=>n.asSVGText})}catch(t){e(t)}})),this._details}_fromDrawingJSON(t,e){this._resource?.deleteReference(this),this._resource=e?.(t.resId),this._resource.addReference(this)}_toDrawingJSON(t){const e={},r=t?.(this._resource);return null!==r&&(e.resId=r),e}_processDelete(){super._processDelete()}}exports.ICalculation=void 0,(exports.ICalculation||(exports.ICalculation={})).Status={Ready:"ready",Error:"error",Starting:"starting",Stopping:"stopping",Off:"off"};class ff extends Ch{constructor(t,e=null,r,n,o){if(super(t,r,e),this._sheetName=n||null,this._getEntireCoords=o??Ah,this._coords=_f(r,this._getEntireCoords()),!r)throw new Error("ReferenceRange requires a coords");this._validateCoords(r)}toType(t){return new ff(this._values,t,this._coords,this._sheetName,this._getEntireCoords)}getCoords(){return this._coords}get isIReferenceRange(){return!0}isLiteral(){return!1}_validateCoords(t){const e=this._getEntireCoords?.();if(e&&(t.rowStart<e.rowStart&&t.rowStart!==Number.MIN_SAFE_INTEGER||t.rowEnd>e.rowEnd&&t.rowEnd!==Number.MAX_SAFE_INTEGER||t.colStart<e.colStart&&t.colStart!==Number.MIN_SAFE_INTEGER||t.colEnd>e.colEnd&&t.colEnd!==Number.MAX_SAFE_INTEGER))throw new Mt}get[Symbol.toStringTag](){return"[ReferenceRange]"}toString(){return`${sd(this._coords,this._getEntireCoords?.())}`}}const _f=(t,e)=>{let r=t.rowStart,n=t.rowEnd,o=t.colStart,s=t.colEnd,i=!1;return o===Number.MIN_SAFE_INTEGER&&(o=e.colStart,i=!0),r===Number.MIN_SAFE_INTEGER&&(r=e.rowStart,i=!0),n===Number.MAX_SAFE_INTEGER&&(n=e.rowEnd,i=!0),s===Number.MAX_SAFE_INTEGER&&(s=e.colEnd,i=!0),i?{rowStart:r,rowEnd:n,colStart:o,colEnd:s}:t},Sf=(t,e)=>t.value?.once===e.value?.once,wf=(t,e)=>t.colStart===e.colStart&&t.rowStart===e.rowStart,yf=(t,e,r)=>!!r&&(t===r.rowStart&&e===r.colStart),xf=(t,e=0,r=0)=>{const n=t._values,o=t._coords,s=n.getRuns({bounds:o}),i=n.getOrientation()!==exports.t.Orientation.Row,a=i?o.colStart:o.rowStart,l=i?o.rowStart:o.colStart,c=new exports.Tuple.Builder(null,e,r);let h=s.next();for(;!h.done;){const t=h.value;c.addValues(t[0]-a,t[1]-l,t[2]),h=s.next()}return c.build()},Cf=(t,e,r,n,o,s,i,a,l,c,h,d,u=!1)=>{let g,p,m=null,f=o.size();void 0===d&&(d=s.getOrientation()===exports.t.Orientation.Column);const _=e?e.length:0,S=r?r.length:0;let w;const y=_+S;for(let c=0;c<y&&f>0;c++){const h=c<_?e[c]:r[c-_],d=o.search(h),u=d.length;for(let e=0;e<u;e++){const r=d[e];if(!yf(r.rowStart,r.colStart,h)){if(r.value.getError())continue;w||(w=[]),w.push(r)}o.remove(r,wf);const c=r.value;c.getCycleId()!==t&&l?.insert(r),c.getError()||(s.delete(r),n.insertNonOverlapping({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:null},{onIntersect:(t,e)=>{if(null!==t.value)return i?.push(t),m=U.unionRanges(m,t),a?.insertNonOverlapping(t),m=U.unionRanges(m,t),e}})),f--}}for(let t=0;t<_;t++){const r=e[t],o={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:null};n.insertNonOverlapping(o,{onIntersect:(t,e)=>{if(null===t.value)return;const r=U.sanitizeRange(e);return u&&a?.insertNonOverlapping(r),c?.insertNonOverlapping({...e,value:!1}),i?.push(r),m=U.unionRanges(m,r),e}}),h?.insertNonOverlapping(o,{onIntersect:(t,e)=>{if(null!==t.value)return i?.push(e),m=U.unionRanges(m,e),e},onUpdates:(t,e,r)=>{p||(p=[]);const n=t.length;for(let e=0;e<n;e++){const r=t[e];p.push(r)}g||(g=[]);const o=e.length;for(let t=0;t<o;t++){const r=e[t],n=U.sanitizeRange(r);g.push(n)}}})}const x=d?exports.t.Orientation.Column:exports.t.Orientation.Row;if(w){const e=w.length,r=new Array(e);for(let o=0;o<e;o++){const e=w[o],s=e.value.setError(!0,t);l?.insert(s),r[o]=s,m=U.unionRanges(m,e);const a={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowStart};n.insertNonOverlapping({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowStart,value:new Dd(e,x)}),i?.push(a)}o.load(r)}for(let t=0;t<S;t++){const e=U.sanitizeRange(r[t]);n.insertNonOverlapping({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:new Dd(e,x)}),u&&a?.insertNonOverlapping(e),i?.push(e),m=U.unionRanges(m,e)}return m},bf=(t,e,r)=>{if(!e)return t;const n=e.block;if(!n)return t;const o=t??[],s=e.colIndex,i=e.rowIndex;let a,l,c,h;r?(a=r.colStart,l=r.rowStart,c=r.colEnd,h=r.rowEnd):(a=s,l=i,c=s,h=i);const d={colStart:a,rowStart:l,colEnd:c,rowEnd:h,value:{blockEntry:{colStart:a,rowStart:l,colEnd:c,rowEnd:h,value:n},width:1,height:1,index:-1,$absWidth:!1,$absHeight:!1,once:e}};let u=e.dynamic;return u||(u=[],e.dynamic=u),u.push(d),o.push(d),o};class Ef{constructor(t){this._fullCalcRequired=!1,this._iterationId=0,this._cycleId=1,this._pendingInvalidations=new Set,this._emitter=null,this._isProcessingJSON=!1,this._collectDirties=(t,e=!1,r,n)=>{const o=this._formulaSpatial,s=this._precedentSpatial;let i=Df,a=0;if(e){const e=o.all();for(let r=0;r<e.length;r++){const n=e[r].value.calcs,o=n.length;for(let e=0;e<o;e++){const r=n[e],o=r.length;for(let e=0;e<o;e++){const n=r[e];n.markId!==t&&(i[a++]=n,n.markId=t,n.pending=!1,n.pendingResolved=!1,n.pendingPromise&&(n.pendingPromise.cancelled=!0))}}}}else{const e=r.length;for(let n=0;n<e;n++){const e=r[n];Kf.length=0;const l=Kf;s.search(e,!1,l),o.search(e,!1,l);const c=l.length;if(0===c)continue;const h=e.colStart,d=e.rowStart,u=e.colEnd-h,g=e.rowEnd-d;for(let e=0;e<c;e++){const r=l[e],n=r.value,o=n.blockEntry?.value??n,c=o.ref,p=c.colEnd-c.colStart,m=c.rowEnd-c.rowStart,f=r.colEnd-r.colStart-p,_=r.rowEnd-r.rowStart-m,S=n.once;if(S)S.markId<=t&&(S.removed?(s.remove(r,Sf),S.removed=!1):i[a++]=S,S.markId=t);else{let e=0,s=0,l=p,c=m;if(!n.$absHeight){const t=d-r.rowStart;s=Math.min(Math.max(t-_,0),m),c=Math.min(g+d,m)}if(!n.$absWidth){const t=h-r.colStart;e=Math.min(Math.max(t-f,0),p),l=Math.min(u+t,p)}const S=o.calcs;for(let r=s;r<=c;r++){const n=S[r];for(let r=e;r<=l;r++){const e=n[r];e.markId!==t&&(i[a++]=e,e.markId=t,e.pendingPromise&&(e.pendingPromise.cancelled=!0))}}}}}n&&n.forEach(e=>{if(Array.isArray(e)){const r=e.length;for(let n=0;n<r;n++){const r=e[n],o=r.length;for(let e=0;e<o;e++){const n=r[e];n.markId===t||n.removed||(i[a++]=n,n.markId=t,n.pendingPromise&&(n.pendingPromise.cancelled=!0))}}}else e.markId===t||e.removed||(i[a++]=e,e.markId=t,e.pendingPromise&&(e.pendingPromise.cancelled=!0))})}return i.length=a,i};const e=(t={strings:new pf,...t}).getEntireCoords??Ah;if(this._getEntireCoords=e,this._options=t,this._strings=t.strings,this._onCalculated=t?.onCalculated??(()=>{}),this._cycleId=1,this._values=new Vc({orientation:exports.t.Orientation.Column}),this._getFormulaParser=t.getFormulaParser,!this._getFormulaParser)throw new Error("Formula parser is not defined");this._latest={graph:this},this._iterationId=0;const r=this;this._formulaSpatial=new gc({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0,onUpdates:(t,e,n)=>{const o=n._cloneKey??r;if(o._isProcessingJSON)return;let s=o._notifyFormulaInsertEntries,i=o._notifyFormulaRemoveEntries;const a=o._precedentSpatial,l=e?e.length:0;if(l>0){let t=i?i.length:0;i?i.length=t+l:(i=new Array(l),o._notifyFormulaRemoveEntries=i);for(let r=0;r<l;r++){const n=e[r],o=n.value,s=o.ref;i[t+r]=s;const l=s.rowStart,c=s.colStart,h=o.formula.getDirectPrecedentsAt(l,c);if(!h)continue;const d=h.length;for(let t=0;t<d;t++){const e=h[t];if(null===e)continue;if(e instanceof exports.n.Known)continue;const r=a.search(e),o=r.length;for(let t=0;t<o;t++){const e=r[t];e.value.blockEntry.value===n.value&&a.remove(e)}}}}const c=t?t.length:0;if(c>0){const e=[];for(let r=0;r<c;r++){const n=t[r],i=n.colEnd-n.colStart,a=n.rowEnd-n.rowStart,l=n.value,c=l.formula,h=l.ref,d=h.rowStart,u=h.colStart,g=[],p=c.getDirectPrecedentsAt(d,u,!0,Tf,Ff),m=p.length;for(let t=0;t<m;t++){const r=p[t];if(r instanceof exports.n.Known)continue;const o=Tf[t],s=Ff[t],l={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd+(s?0:i),rowEnd:r.rowEnd+(o?0:a),value:{blockEntry:n,width:i+1,height:a+1,index:t,$absWidth:s,$absHeight:o,once:null}};g.push(r),e.push(l)}s||(s=[],o._notifyFormulaInsertEntries=s),s.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:{tokens:c.getTokens(),references:c.getReferences(),precedents:g}})}a.load(e)}}}}),this._contentfulSpatial=new gc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}});const n={updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}};this._precedentSpatial=new gc(n),this._volatile=new Set,this._spillSpatial=new gc(n),this._errorSpatial=new gc(n),this._pendingSpatial=new gc(n),this._invalidations=new gc,this._notifyValues=new gc,this._notifySpills=new gc,this._notifyFormats=new gc,this._notifyPending=new gc,this._calculation=t.calculation,this._clearScope()}addListeners(t,e){return this._emitter||(this._emitter=new ml(this)),this._emitter.addListeners(t,e)}shift(t){const e=t.cloneIfUpdate??!0?this.clone(this):this,r={...t};delete r.cloneIfUpdate,delete r.onShift;e._values.shift(r.range,r.direction);const n=e._contentfulSpatial;e._contentfulSpatial=n.shift(r);const o=e._spillSpatial;e._spillSpatial=o.shift(r);const s=e._formulaSpatial;if(s.isEmpty())return e;const i=t.range,a=t.direction,l=a===exports.t.Direction.Left||a===exports.t.Direction.Right;a!==exports.t.Direction.Up&&exports.t.Direction.Left,l?(i.colEnd,i.colStart):(i.rowEnd,i.rowStart),e._notifyFormulaInsertEntries,e._notifyFormulaRemoveEntries;const c=e._getEntireCoords(),h=new Map;this._precedentSpatial.visitRanges({...i,colEnd:l?c.colEnd:i.colEnd,rowEnd:l?i.rowEnd:c.rowEnd},t=>{let e=t.value;if(t.value.once)return;let r=e.blockEntry,n=h.get(r);n||(n={rows:[],cols:[],index:[]},h.set(r,n)),n.index.push(e.index)});const d=[],u=[],g=h.entries();let p=g.next();const m=(t,e,r,n)=>{let o=t.value;const s=o.formula.getReferences(),i=e.length;for(let t=0;t<i;t++){const e=s[t];if(null===e)continue;if(e instanceof exports.n.Known)continue;if("string"==typeof e)continue;e[t]}return t.value=o,t};for(;!p.done;){const[t,e]=p.value,r=t.value,n=e.rows.sort(),o=n.length,s=e.cols.sort().length,i=e.index.sort();if(u.push(t),0===o&&0===s){const e={...t};m(e,i),d.push(e),p=g.next();continue}let a=0;for(let t=0;t<o;t++){const e=n[t];if(e===a)continue;Qf[0]={colStart:r.ref.colStart,rowStart:a,colEnd:r.ref.colEnd,rowEnd:e-1,value:r},Qf[1]={colStart:r.ref.colStart,rowStart:e,colEnd:r.ref.colStart,rowEnd:r.ref.rowEnd,value:r};const o=e_(r,Qf,exports.t.Orientation.Row,e);let s=o[0];m(s,i),d.push(s),s=o[1],m(s,i),d.push(s),a=e}p=g.next()}return s._updateNodes(d,u),e._fullCalcRequired=!0,this._invalidate(d),e}clone(t){if(void 0!==t&&this._cloneKey===t)return this;const e=new Ef(this._options);e._cloneKey=t,e._values=this._values.clone(e),e._contentfulSpatial=this._contentfulSpatial.clone(e),e._formulaSpatial=this._formulaSpatial.clone(e),e._precedentSpatial=this._precedentSpatial.clone(e),e._volatile=new Set(this._volatile),e._spillSpatial=this._spillSpatial.clone(e),e._errorSpatial=this._errorSpatial.clone(e),e._pendingSpatial=this._pendingSpatial.clone(e),e._invalidations=this._invalidations.clone(e),e._notifyValues=this._notifyValues.clone(e),e._notifySpills=this._notifySpills.clone(e),e._notifyFormats=this._notifyFormats.clone(e),e._notifyPending=this._notifyPending.clone(e);const r=this._notifyFormulaInsertEntries;r&&(e._notifyFormulaInsertEntries=[...r]);const n=this._notifyFormulaRemoveEntries;n&&(e._notifyFormulaRemoveEntries=[...n]);const o=this._pendingActions;return o&&(e._pendingActions=[...o]),e._cycleId=this._cycleId,e._emitter=this._emitter,e._fullCalcRequired=this._fullCalcRequired,this._latest.graph=e,e._iterationId=this._iterationId+1,e}invalidate(t){const e=this._invalidations;if(Array.isArray(t)){const r=t.length;for(let n=0;n<r;n++){let r=t[n];"string"==typeof r&&(r=yd(r)),e.insertNonOverlapping(r)}}else{let r=t;"string"==typeof r&&(r=yd(r)),e.insertNonOverlapping(r)}}setFormulaAt(t,e){let r,n=null;return"string"==typeof t?r=yd(t,Mf):(Mf.colStart=t.colIndex,Mf.rowStart=t.rowIndex,Mf.colEnd=t.colIndex,Mf.rowEnd=t.rowIndex,r=Mf),e?n=this._setInputs(null,[{colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,value:e}]):this.delete(r),n}getFormulaAt(t,e){let r;"string"==typeof t&&(r=yd(t,Mf));const n=this._formulaSpatial.search(r);if(0===n.length)return null;const o=n[0].value;return o.formula?o.formula.getTextAt(r.rowStart,r.colStart,e):void 0}_formulaAt(t,e){Zf.colStart=e,Zf.rowStart=t,Zf.colEnd=e,Zf.rowEnd=t;const r=this._formulaSpatial.search(Zf);if(0===r.length)throw new Error(`No formula found at ${ed({rowIndex:t,colIndex:e})}`);return r[0]}getDirectPrecedentsAt(t,e,r){return this._formulaAt(t,e).value.formula.getDirectPrecedentsAt(t,e,r)}getReferencesAt(t,e){return this._formulaAt(t,e).value.formula.getReferences()}setReferenceAt(t,e,r,n){const o=this._formulaAt(t,e).value.formula.setReferenceAt(r,n).getTextAt(t,e);return this.setFormulaAt({rowIndex:t,colIndex:e},o),this}evaluateAt(t,e,r){const n=this._formulaAt(t,e),o=n.value,s=o.ref,i=s.colStart-e,a=s.rowStart-t,l=this._calculation._getContext(),c=this._calculation._getScope();return c.sheetName=this._options.getSheetName?.(),c.rowIndex=t,c.colIndex=e,c.node=o.calcs[a][i],n.value.formula.evaluate(l,r)}setInputAt(t,e){let r=null;const n="string"==typeof t?fd(t,Rf):t;if(null!==e){const t=new exports.Tuple.Builder,o=this._values.getOrientation()===exports.t.Orientation.Column,s=o?n.colIndex:n.rowIndex,i=o?n.rowIndex:n.colIndex;t.addValue(s,i,e),r=this.setInputs(t.build(),null)}else this.delete(U.cellToRange(n,Mf));return r}setInputs(t,e){return this._setInputs(t,e)}delete(t){"string"==typeof t&&(t=hd(t));const e=this._setInputs(null,[{...t,value:null}],t);return this._emitter?.notify("onInvalidate"),e.removes}_createCopySpillEntries(t,e,r,n,o){const s=n??[],i=o??[],a=e.colStart,l=e.rowStart,c=e.colEnd,h=e.rowEnd,d=r.colStart,u=r.rowStart,g=t.search(e),p=g.length;for(let t=0;t<p;t++){const e=g[t];i&&i.push(e);const r=e.rowStart,n=e.colStart;if(r<l||r>h)continue;if(n<a||n>c)continue;if(e.value.getError())continue;const o=d+(e.colEnd-n),p=u+(e.rowEnd-r),m={colStart:d,rowStart:u,colEnd:o,rowEnd:p};s.push({colStart:d,rowStart:u,colEnd:o,rowEnd:p,value:new Ld(m,0,!1)})}return{removes:i,inserts:s}}_copyCalcs(t,e,r){const n=t._formulaSpatial;if(n.isEmpty())return;const o=this._getEntireCoords(),s=o.colStart,i=o.rowStart,a=o.colEnd,l=o.rowEnd,c=n.createCopiedEntries(e,r),h=c.inserts;let d=h.length,u=0;const g=t._spillSpatial;let p=[];for(;u<d;){let t=h[u],r=t.value,n=r.ref,o=n.colStart,c=n.rowStart,m=n.colEnd,f=n.rowEnd;this._createCopySpillEntries(g,e,n,p,null);let _=r.formula.getReferences();const S=_.length;for(let e=0;e<S;e++){const u=_[e];if(!u)continue;if(u.isFormulaError)continue;if("string"==typeof u)continue;const g=u,p=g.colStart,S=g.rowStart,w=g.colEnd,y=g.rowEnd;let x=g.$colStart?p:p+o,C=g.$rowStart?S:S+c,b=g.$colEnd?w:w+m,E=g.$rowEnd?y:y+f;if(p===Number.MIN_SAFE_INTEGER&&(x=s,b=a),S===Number.MIN_SAFE_INTEGER&&(C=i,E=l),x<s||b>a||C<i||E>l){const u=s-x,g=i-C,p=a-b,S=l-E;Yf.colStart=Math.max(o,o+u),Yf.rowStart=Math.max(c,c+g),Yf.colEnd=Math.min(m,m+p),Yf.rowEnd=Math.min(f,f+S);const w=_c(t,Yf,xc);if(w){const e=w.length;t=w[e-1],r=t.value,n=r.ref,o=n.colStart,c=n.rowStart,m=n.colEnd,f=n.rowEnd;for(let t=0;t<e-1;t++){const e=w[t];h.push(e),d++}}else r=r.setReferenceAt(e,null),t.value=r,_=r.formula.getReferences()}}h[u++]=t}this._formulaSpatial._updateNodes(h,c.removes),n._mergeNodes({colStart:r.colStart-1,rowStart:r.rowStart-1,colEnd:r.colEnd+1,rowEnd:r.rowEnd+1}),p&&this._spillSpatial._updateNodes(p,[]),this._fullCalcRequired=!0,this._invalidate(h),this._invalidate(c.removes)}_moveCalcs(t,e,r){const n=t._formulaSpatial.createCopiedEntries(e,r);console.log("_moveCalcs",n,"from:",e,"to:",r);const o=this._formulaSpatial,s=(t,e,r,n)=>{let o=t.value;const s=o.formula.getReferences(),i=s.length,a=e.colStart-r.colStart,l=e.rowStart-r.rowStart,c=o.ref,h=r.colStart-c.colStart,d=r.colEnd-c.colEnd,u=r.rowStart-c.rowStart,g=r.rowEnd-c.rowEnd;for(let t=0;t<i;t++){const e=s[t];if(!e)continue;if(e.isFormulaError)continue;if("string"==typeof e)continue;const r=e,n=r.colStart,i=r.rowStart,c=r.colEnd,p=r.rowEnd;let m=a,f=l;const _=h<=n&&d>=c||n==Number.MIN_SAFE_INTEGER,S=u<=i&&g>=p||i==Number.MIN_SAFE_INTEGER;let w=!S;r.$colStart||0===m||n===Number.MIN_SAFE_INTEGER?w=!1:w||(w=n<h||n>d,w||!r.$colEnd||r.$colStart||(w=!0));let y=!_;r.$rowStart||0===f||i===Number.MIN_SAFE_INTEGER?y=!1:y||(y=i<u||i>g,w||!r.$rowEnd||r.$rowStart||(y=!0));let x=!S;r.$colEnd||0===m||i===Number.MIN_SAFE_INTEGER?x=!1:x||(x=c<h||c>d,w||!r.$colStart||r.$colEnd||(x=!0));let C=!_;r.$rowEnd||0===f||i===Number.MIN_SAFE_INTEGER?C=!1:C||(C=p<u||p>g,C||!r.$rowEnd||r.$rowStart||(C=!0));if(!(w||x||y||C))continue;const b={...r};w&&(b.colStart+=m),y&&(b.rowStart+=f),x&&(b.colEnd+=m),C&&(b.rowEnd+=f),o=o.setReferenceAt(t,b)}return t.value=o,t},i=t._spillSpatial;let a=[],l=[];const c=n.inserts,h=c.length;for(let t=0;t<h;t++){const n=c[t];this._createCopySpillEntries(i,e,n,a,l),c[t]=s(n,e,r)}o._updateNodes(n.inserts,[]),t._formulaSpatial._updateNodes([],n.removes);const d=[];a.length>0&&(this._spillSpatial._updateNodes(a,[]),t._spillSpatial._updateNodes([],l),Cf(this._cycleId,l,mt.EmptyArray,t._contentfulSpatial,i,t._values,d,t._notifyValues,t._notifySpills,t._notifyPending,t._errorSpatial,t._values.getOrientation()!==exports.t.Orientation.Row,!1)),this._fullCalcRequired=!0,this._invalidate(n.inserts),t._invalidate(d),t._invalidate(n.removes)}getSnapshot(t){const e=this,r=Object.freeze({...t});let n=r.range;"string"==typeof n&&(n=yd(n));return{async copyTo(t,o){const s=t.calcGraph;let i=t.range;"string"==typeof i&&(i=yd(i));const a=yh(i,n,o?.fitDestination,o?.transpose);return{...r,...o}.isCut?s._moveCalcs(e,n,a):s._copyCalcs(e,n,a),i},getCoords:()=>n,getSource:()=>e,getName:()=>"Calculation",getMarkOptions:()=>r,isISnapshot:!0}}autoFill(t,e){return"string"==typeof t&&(t=yd(t)),"string"==typeof e&&(e=yd(e)),this._copyCalcs(this,t,e),this}_scheduleRecalculation(t){const e=this._pendingInvalidations;if(t)if(Array.isArray(t)){const r=t.length;for(let n=0;n<r;n++)e.add(t[n])}else e.add(t);const r=this;mt.debounce(()=>{const t=r._latest.graph,n=t._volatile,o=t._cycleId;e.forEach(t=>{t.cycleId>o||n.add(t)}),e.clear(),t.calculate()},100)()}_notifyCalculated(t){const e=this,r=e._notifyValues,n=r.all();return new Promise(o=>{mt.nextTick(()=>{const s=e._cycleId;let i;let a=e._fullCalcRequired;a||("boolean"==typeof t?a=t:t&&(i=t,a=i.full??!1));const l={};let c=null;const h=n.length;if(h>0){r.clear();let t=n,o=null;for(let t=0;t<h;t++){const e=n[t],r=e.colStart,s=e.colEnd;if(r!==s){o||(o=[]);for(let t=r+1;t<=s;t++)o.push({colStart:t,rowStart:e.rowStart,colEnd:t,rowEnd:e.rowEnd});e.colEnd=r}}o&&(t=n.concat(o)),t.sort(U.columnFirstRangeComparator);const s=new exports.Tuple.Builder(t=>new vl(t));let i;const a=e._values,d=a.getOrientation()===exports.t.Orientation.Column,u=t.length;for(let e=0;e<u;e++){const r=t[e];c=U.unionRanges(c,r,Mf);const n=a.getRuns({bounds:r});let o=n.next();const l=r.colStart,h=r.rowStart,u=r.colEnd,g=r.rowEnd,p=d?h:l,m=d?u:g,f=d?g:u;let _=d?l:h,S=p;for(;!o.done;){const t=o.value,e=t[0];for(;_<e;)i||(i=[]),i.push({colStart:d?_:S,rowStart:d?S:_,colEnd:d?_:f,rowEnd:d?f:_}),_++,S=p;const r=t[1],a=t[2],l=Math.max(r,p),c=Math.min(r+a.length-1,f);s.addValues(e,l,a),S<l&&(i||(i=[]),i.push({colStart:d?e:S,rowStart:d?S:e,colEnd:d?e:l-1,rowEnd:d?l-1:e})),S=c+1,c>=f?(_=e+1,S=p):_=e,o=n.next()}for(;_<=m;)S<=f&&(i||(i=[]),i.push({colStart:d?_:S,rowStart:d?S:_,colEnd:d?_:f,rowEnd:d?f:_})),_++,S=p}const g=s.build();g&&(l.valueInserts=g),i&&(l.valueRemoves=i)}const d=e._notifyPending,u=d.all();if(u.length>0){d.clear();const t=e._pendingSpatial;let r;const n=u.length;for(let e=0;e<n;e++){const n=u[e];t.insertNonOverlapping(n,{onIntersect:(t,e)=>(r||(r=[]),r.push({...e}),c=U.unionRanges(c,e),!1===e.value&&(e.value=null),e)})}r&&r.length>0&&(l.pendingUpdates=r,c=U.unionRangesArrays(r,c,Mf))}const g=e._notifySpills,p=g.all();if(p.length>0){g.clear();const t=e._spillSpatial;let r,n,o;const i=p.length;for(let e=0;e<i;e++){const i=p[e],a=i.value;if(a.getCycleId()!==s)r||(r=[]),r.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd});else{const e=t.search(i),r=e.length;for(let t=0;t<r;t++){let r=e[t];if(yf(i.rowStart,i.colStart,r)&&a.getCycleId()===s){n||(n=[],o=new Set);const t=Qh(r.colStart)+Kh(r.rowStart);if(o.has(t))continue;o.add(t),n.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:r.value.getError()})}}}}n&&(l.spillInserts=n,c=U.unionRangesArrays(n,c,Mf)),r&&(l.spillRemoves=r,c=U.unionRangesArrays(r,c,Mf))}const m=e._notifyFormats.all();m.length>0&&(l.formatInserts=m,c=U.unionRangesArrays(m,c,Mf),e._notifyFormats.clear());const f=e._notifyFormulaInsertEntries;if(f){const t=e._formulaSpatial;for(let e=f.length-1;e>=0;e--){const r=f[e];0===t.search(r).length?f.splice(e,1):c=U.unionRanges(c,r,Mf)}l.formulaInserts=f,e._notifyFormulaInsertEntries=void 0}const _=e._notifyFormulaRemoveEntries;_&&(l.formulaRemoves=_,c=U.unionRangesArrays(_,c,Mf),e._notifyFormulaRemoveEntries=void 0),c&&(l.bounds=U.sanitizeRange(c)),0===Object.keys(l).length?l.cycleId=s-1:(l.cycleId=s,e._cycleId++),a&&(l.isFull=!0),e._fullCalcRequired=!1,e._options.onCalculated?.(l),o(l)})})}_setInputs(t,e,r){if(this._calculation.getStatus()===exports.ICalculation.Status.Starting)return this._addToPending(()=>{const n=this._setInputs(t,e,r),o={formulaInserts:n.inserts??mt.EmptyArray,formulaRemoves:n.removes??mt.EmptyArray,cycleId:this._cycleId,bounds:U.unionRanges(U.unionRangesArrays(n.inserts),U.unionRangesArrays(n.removes))};return Promise.resolve(o)}),t_;const n=this._values.getOrientation()!==exports.t.Orientation.Row,o=this._spillSpatial,s=this._errorSpatial,i=this._contentfulSpatial,a=[],l=this._formulaSpatial;let c,h,d=!l.isEmpty(),u=d?[]:null,g=this._values;if(t&&t.tuples){if(c=t.tuples,u){let e=t.bounds;if(d)if(e){const t=Mc(e,n);a.push(t)}else{const t={colStart:Number.MIN_SAFE_INTEGER,rowStart:Number.MIN_SAFE_INTEGER,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER};a.push(t)}const r={majorStart:0,minorStart:0,majorEnd:0,minorEnd:0},o=c.length;for(let t=0;t<o;t++){const e=c[t],o=e[0];r.majorStart=o,r.majorEnd=o;const s=e[1],i=s.length;for(let t=0;t<i;t++){const e=s[t];r.minorStart=e[0];const o=e[1];r.minorEnd=r.minorStart+o.length-1;const i=Mc(r,n);if(u){l.search(i).length>0&&u.push(i)}}}}h=zd(t.tuples,n)}(r||c)&&(Cf(this._cycleId,r?[r]:mt.EmptyArray,h,i,o,g,a,this._notifyValues,this._notifySpills,this._notifyPending,s,n,!1),r&&g.delete(r),c&&g.setValues(c));const p=this._calculation._getContext(),m=this._calculation._getScope();let f,_;m.sheetName=this._options.getSheetName?.();const S=this._getFormulaParser(),w=(t,e)=>{const r=t.rowStart,n=t.colStart,o={...t,value:null};if(l.insertNonOverlapping(o,{noMerge:!0,onIntersect:(t,e)=>null===t.value?null:(_||(_=[]),_.push(t),e)}),null!==e){m.rowIndex=r,m.colIndex=n;const o=S.parse(p,e),s=new Hd(t,o),i={...t,value:s};f||(f=[]),f.push(i)}},y=u?u.length:0;for(let t=0;t<y;t++)w(u[t],null);const x=e?e.length:0;for(let t=0;t<x;t++){const r=e[t],n=r.value;w(U.sanitizeRange(r),n)}const C=_?_.length:0,b=this._precedentSpatial;for(let t=0;t<C;t++){const e=_[t].value.calcs;if(e){const t=e.length;for(let r=0;r<t;r++){const t=e[r];for(let e=0;e<t.length;e++){const r=t[e];if(r.dynamic){for(let t=0;t<r.dynamic.length;t++){const e=r.dynamic[t];b.remove(e)}r.dynamic=null}}}}}e&&(l._updateNodes(f,mt.EmptyArray),Cf(this._cycleId,_,f,i,o,g,a,this._notifyValues,this._notifySpills,this._notifyPending,s,n,!0)),this._invalidate(a);return{inserts:this._notifyFormulaInsertEntries??mt.EmptyArray,removes:this._notifyFormulaRemoveEntries??mt.EmptyArray}}_invalidate(t){if(!t||0==t.length)return;const e=this._invalidations,r=wc(t,exports.t.Orientation.Column,2);for(let t=0;t<r.length;t++)e.insertNonOverlapping(r[t]);this._emitter?.notify("onInvalidate")}_markAndPlan(t,e,r){let n;Hf=0,Wf=0,qf=0,Xf=0;const o=this._precedentSpatial,s=this._formulaSpatial;$f=0,Uf=0;const i=this._cycleId,a=e.length;for(let t=0;t<a;t++){const n=e[t];n.markId!==r&&(n.markId=r,n.cycleId=i,n.inDegree=0,jf[Hf++]=n,Vf[Uf++]=n)}const l=(e,r,o)=>{(t||e.state===Pd)&&(n||(n=[]),n.push(r),t||o(e))},c=t=>{t.markId!==r&&(t.markId=r,t.cycleId=i,t.inDegree=0,jf[Hf++]=t,Vf[Uf++]=t)};for(;$f<Uf;){const t=Vf[$f++],e=t.colIndex,r=t.rowIndex;Mf.colStart=e,Mf.rowStart=r,Mf.colEnd=e,Mf.rowEnd=r;const n=o.search(Mf),s=n.length;if(0===s)t.dependents=mt.EmptyArray;else for(let t=0;t<s;t++){const o=n[t],s=o.value.once;s?l(s,o,c):Af(o,r,e,c)}}for(let t=0;t<Hf;t++){const e=jf[t],n=e.block,o=e.rowIndex,i=e.colIndex,a=n.formula.getDirectPrecedentsAt(o,i);let l=0;const c=e.precedents;for(let t=0;t<a.length;t++){const e=a[t];if(e.isFormulaError){c[t]=e;continue}{const r=e;r.calc=void 0,c[t]=r}const n=e.colStart,o=e.rowStart,i=e.colEnd,h=e.rowEnd,d=s.search(e),u=d.length;for(let t=0;t<u;t++){const s=d[t],a=s.colStart,c=s.rowStart,u=s.colEnd,g=s.rowEnd,p=Math.max(a,n),m=Math.max(c,o),f=Math.min(u,i),_=Math.min(g,h),S=s.value.calcs;for(let t=m;t<=_;t++){const n=S[t-c];for(let t=p;t<=f;t++){const o=n[t-a];o.markId===r&&(e.calc=o,l++)}}}}e.inDegree=l,0===e.inDegree&&(Gf[qf++]=e)}const h=t=>{t.markId===r&&(t.inDegree--,0===t.inDegree&&(Gf[qf++]=t))};for(;Wf<qf;){const t=Gf[Wf++];Jf[Xf++]=t;const e=t.colIndex,r=t.rowIndex;Mf.colStart=e,Mf.rowStart=r,Mf.colEnd=e,Mf.rowEnd=r;const n=o.search(Mf),s=n.length;for(let t=0;t<s;t++){const o=n[t],s=o.value.once;s?l(s,o,h):Af(o,r,e,h)}}return Xf<Hf?{completed:!1,onces:n}:{completed:!0,onces:n}}_evaluate(t){const e=this._calculation._getContext(),r=this._calculation._getScope();r.sheetName=this._options.getSheetName?.();let n=zf;n.length=0;let o=0,s=!0;const i=this._cycleId,a=this._invalidations,l=this._contentfulSpatial,c=this._notifyValues,h=this._notifySpills,d=this._precedentSpatial,u=this._spillSpatial,g=this._values,p=g.getOrientation(),m=p===exports.t.Orientation.Column;let f;r.spillSpatial=this._spillSpatial,r.values=g;const _=e.getEntireCoords.bind(e);let S;for(let w=0;w<Xf;w++){const y=Jf[w];if(y.state===jd&&i===y.cycleId){y.state=Pd;continue}if(y.dynamic){for(let t=0;t<y.dynamic.length;t++){const e=y.dynamic[t];d.remove(e)}y.dynamic=null}const x=y.block,C=y.colIndex,b=y.rowIndex;let E=t?void 0:y.cachedValue,v=y.error;!v&&E&&E.isFormulaError&&(v=E);let I=!1;const A=y.precedents;if(A){const t=A.length,e=y.inputs;for(let r=0;r<t;r++){const t=A[r],s=t.calc;if(s&&s.pending){I=!0;continue}if(t.isFormulaError){e[r]=t;continue}const i=t.colStart,a=t.rowStart,l=t.colEnd;t.rowEnd!==a||i!==l?(o>0&&(n.length=o,vf(n,g,c,m),o=0),e[r]=new ff(g,null,{...t},null,_)):e[r]=void 0===s?t:s.cachedValue}y.pendingPrecedents=I}const R=m?C:b,M=m?b:C;r.node=y,r.colIndex=C,r.rowIndex=b;const T=x.formula;let F,N;const k=y.pending;let O=k;if((I||y.pendingPromise)&&(O=!0,F=y.cachedValue??null,y.pendingPromise&&(y.pendingResolved?(y.pendingPromise=null,y.pendingResolved=!1,O=!1):(y.pendingPromise.cancelled=!0,F=void 0))),void 0===F&&(r.formula=T,r.colIndex=C,r.rowIndex=b,F=T.evaluate(e,void 0,y.inputs),r.formula=null,N=F&&F.then?F:null,O=!!N),O!==k&&(y.pending=O,f||(f=Hc(m)),f.append(R,M,O)),N&&(F=y.cachedValue??null,!N.__originator)){N.__originator=i;const t=y;Pf.add(t),t.pendingPromise=N,t.pendingResolved=!1,N.then(r=>{if(Pf.delete(t),N.cancelled)return;t.pendingPromise=N,t.pendingResolved=!0;let n=Lh(r,e);null===n&&(n=0),t.cachedValue=n,this._scheduleRecalculation(t)},t=>{})}let B=1,L=1;const D=E instanceof Ch;let z;const P=E instanceof exports.n.Spill;if(D||P){kf.colStart=C,kf.rowStart=b,kf.colEnd=C,kf.rowEnd=b;const t=u.search(kf);for(let e=0;!z&&e<t.length;e++){const r=t[e];r.colStart===C&&r.rowStart===b&&(z=r)}if(z){if(D){const t=E;B=t.getWidth(),L=t.getHeight()}const t={colStart:C,rowStart:b,colEnd:C+B-1,rowEnd:b+L-1};u.remove(z),z&&z.value.getError()||(l.insertNonOverlapping({...t,value:null}),g.delete(t),c.insertNonOverlapping(t))}}let j=1,H=1;const V=F,$=V?.isIRange;let G,W=F instanceof exports.n.Spill;if($&&V.size>1){j=V.getWidth(),H=V.getHeight();const t={colStart:C,rowStart:b,colEnd:C+j-1,rowEnd:b+H-1},r=e.getEntireCoords(),n=!U.isRangeWithinRange(t,r);if(n&&(t.colEnd=Math.min(t.colEnd,r.colEnd),t.rowEnd=Math.min(t.rowEnd,r.rowEnd)),W=n,!W){const e=l.search(t);if(W=e.length>1,!W&&1===e.length){const r=e[0],n=U.intersectRanges(t,r,Mf);(n&&(n.rowEnd!==n.rowStart||n.colStart!==n.colEnd)||n.colStart!==C||n.rowStart!==b)&&(W=!0)}}let o,s;if(W){F=exports.n.BuiltIn.Spill,j=1,H=1;o=[[R,[[M,[F]]]]],g.setValues(o),s={colStart:C,rowStart:b,colEnd:C,rowEnd:b}}else{const e=xf(V,R,M);e&&(o=e.tuples),o&&g.setValues(o),s=t}G={...t,value:new Ld(t,i,W)},u.insert(G),S=bf(S,y,t),c.insertNonOverlapping(s),a.insertNonOverlapping(s),l.insertNonOverlapping({...s,value:new Dd(s,p)})}(!U.isEqualRanges(z,G)||W||P)&&(z&&h.insert(z),G&&h.insert(G)),j===B&&H===L||(y.state=jd,a.insertNonOverlapping({colStart:C,rowStart:b,colEnd:C+Math.max(j,B)-1,rowEnd:b+Math.max(H,L)-1}),s=!1);let q=F&&F.isFormulaError?F:null;T.getError()&&(q=T.getError()),(q||v&&!t)&&(q&&!q.equals(v)||v&&v.equals(q)),y.cachedValue=F,n[o++]=y}if(r.node=null,r.colIndex=Number.MAX_SAFE_INTEGER,r.rowIndex=Number.MAX_SAFE_INTEGER,f){const t=f.done(!0);this._notifyPending.load(t)}return o>0&&(n.length=o,vf(n,g,c,m),o=0),{completed:s,dynamic:S,count:Xf}}async calculate(t){const e=this._calculation.getStatus();if(e===exports.ICalculation.Status.Starting)return void this._addToPending(()=>this.calculate(t));if(e!==exports.ICalculation.Status.Ready)return;let r=this._fullCalcRequired;r||("boolean"==typeof t?r=t:t&&(r=t.full??!1));const n=this._invalidations;if(this._formulaSpatial.isEmpty()){if(n.clear(),Pf.size>0){const t=++Bf;Pf.forEach(e=>{e.markId=t})}return this._notifyCalculated(t)}let o=r;const s=this._volatile;let i=++Bf,a=this._collectDirties(i,o,n.all(),s);if(n.clear(),s.clear(),!o&&0===a.length)return this._notifyCalculated(t);o&&this._clearCalcs();const l=this._resetScope();for(;a.length>0;){i=++Bf;const t=this._markAndPlan(o,a,i).onces;if(t){const e=this._precedentSpatial,r=t.length;for(let n=0;n<r;n++)e.remove(t[n],Sf)}a.length=0;const e=this._evaluate(o);if(e.dynamic&&this._precedentSpatial.load(e.dynamic),l.dynamicPrecedentsInserts&&(this._precedentSpatial.load(l.dynamicPrecedentsInserts),l.dynamicPrecedentsInserts=[]),l.conflatingFormats){const t=l.conflatingFormats.done(!0),e=this._notifyFormats;for(let r=0;r<t.length;r++){const n=t[r];e.insertNonOverlapping(n)}l.conflatingFormats=null}e.completed||(o=!1,i=++Bf,a=this._collectDirties(i,o,n.all(),s),n.clear())}return this._clearScope(),this._notifyCalculated(t)}_clearScope(){const t=this._calculation._getScope();t&&(t.rowIndex=0,t.colIndex=0,t.node=null,t.values=this._values,t.formulaSpatial=this._formulaSpatial,t.volatile=this._volatile,t.conflatingFormats=null,t.dynamicPrecedentsInserts=null,t.formula=null,t.getEntireCoords=Ah)}_resetScope(){const t=this._calculation._getScope();if(t)return t.rowIndex=0,t.colIndex=0,t.node=null,t.values=this._values,t.formulaSpatial=this._formulaSpatial,t.volatile=this._volatile,t.conflatingFormats=null,t.dynamicPrecedentsInserts=null,t.formula=null,t.getEntireCoords=this._getEntireCoords,t}_clearCalcs(){const t=this._values,e=this._spillSpatial,r=this._contentfulSpatial,n=e.all();for(let e=0;e<n.length;e++){const o=n[e];o.value.getError()||(t.delete(o),r.insertNonOverlapping({...o,value:null}))}e.clear(),this._errorSpatial.clear(),this._pendingSpatial.clear(),this._volatile.clear(),this._clearNotifications()}_clearNotifications(){this._invalidations.clear(),this._notifyValues.clear(),this._notifySpills.clear(),this._notifyFormats.clear(),this._notifyPending.clear()}_clearAll(){1!==this._cycleId&&this._cycleId++,Bf++,this._formulaSpatial.clear(),this._contentfulSpatial.clear(),this._pendingInvalidations.clear(),this._values.clear(),this._precedentSpatial.clear(),this._volatile.clear(),this._spillSpatial.clear(),this._errorSpatial.clear(),this._pendingSpatial.clear(),this._clearNotifications(),this._notifyFormulaInsertEntries=void 0,this._notifyFormulaRemoveEntries=void 0}_addToPending(t){let e=this._pendingActions;if(!e){this._pendingActions=e=[];const t=this;t._calculation.addListeners({onReady:()=>{(async()=>{const e=t._pendingActions,r=e.length;for(let n=0;n<r;n++){const r=e[n],o=await r.bind(t)();t._options.onCalculated?.(o)}this._pendingActions=null})()},onError:()=>{}},{once:!0})}e.push(t)}fromJSON(t){const e=this._calculation.getStatus();if(e===exports.ICalculation.Status.Starting)return void this._addToPending(()=>Promise.resolve(this.fromJSON(t)));if(e!==exports.ICalculation.Status.Ready)return;this._clearAll();const r={cycleId:0,isFull:!0};if(!t)return r;this._isProcessingJSON=!0;try{if(t.data){const e=t.data;this._values.setValues(e);const r=this._values.getOrientation()===exports.t.Orientation.Column,n=zd(e,r);this._contentfulSpatial.load(n)}const e=this._formulaSpatial,n=t.formulas;if(n){const o=t.dynamic,s=new Set;if(o){const t=o.length;for(let e=0;e<t;e++){const t=o[e],r=t[0].split(":")[0];s.add(r)}}const i=n.length,a=new Array(i),l=[],c=[],h=this._calculation._getContext(),d=this._calculation._getScope();d.colIndex=0,d.rowIndex=0;const u=this._getFormulaParser();for(let t=0;t<i;t++){const e=n[t],r=e[0],o=yd(r),i=e[1],g=o.rowStart,p=o.colStart;d.colIndex=p,d.rowIndex=g;let m=u.parse(h,i);const f=m.getDirectPrecedentsAt(g,p,!0,Tf,Ff),_=f.length;1===_&&(m=m.wrapImplicit(g,p,s));const S={...o},w=new Hd(S,m);o.value=w,a[t]=o;const y=o.rowEnd,x=o.colEnd-p,C=y-g,b=[];for(let t=0;t<_;t++){const e=f[t];if(e instanceof exports.n.Known)continue;const r=Tf[t],n=Ff[t],s={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd+(n?0:x),rowEnd:e.rowEnd+(r?0:C),value:{blockEntry:o,width:x+1,height:C+1,index:t,$absWidth:n,$absHeight:r,once:null}};b.push(e),c.push(s)}l.push({colStart:S.colStart,rowStart:S.rowStart,colEnd:S.colEnd,rowEnd:S.rowEnd,value:{tokens:m.getTokens(),references:m.getReferences(),precedents:b}})}if(e.load(a),this._precedentSpatial.load(c),l.length>0&&(r.formulaInserts=l),o){const t=[],n=[];let s;const i=this._values,a=o.length;for(let r=0;r<a;r++){const a=o[r],l=a[0],c=yd(l),h=a[1],d={...c},u=d.colStart,g=d.rowStart,p=d.colEnd,m=d.rowEnd;Nf.colStart=u,Nf.rowStart=g,Nf.colEnd=u,Nf.rowEnd=g;const f=e.search(Nf);if(1!==f.length)continue;const _=f[0].value,S=_.ref,w=_.calcs,y=g-S.rowStart,x=u-S.colStart,C=w[y][x];if(h)C.cachedValue=exports.n.BuiltIn.Spill;else{const t=new Ch(i,d);C.cachedValue=t}c.value=new Ld(d,0,h),n.push(c);const b={colStart:u,rowStart:g,colEnd:p,rowEnd:m,value:h};U.isSingleCell(b)||t.push(b),bf(s,C,d)}this._spillSpatial.load(n),this._precedentSpatial.load(s),t.length>0&&(r.spillInserts=t)}const g=t.volatile,p=g?g.length:0;if(p>0){const t=this._volatile,r=e=>{t.add(e)};for(let t=0;t<p;t++){const n=g[t],o=yd(n,Nf),s=e.search(o),i=s.length;for(let t=0;t<i;t++){const e=s[t];If(e,o,r)}}}}}catch(t){throw t}finally{this._isProcessingJSON=!1}return r}async toJSON(t=!1){const e=this._formulaSpatial.all(),r=e.length;if(0===r)return null;const n={};if(r>0){const t=new Array(r);for(let n=0;n<r;n++){const r=e[n];t[n]=r.value.toJSON()}n.formulas=t}const o=this._spillSpatial.all(),s=o.length;if(s>0){const t=this._getEntireCoords(),e=new Array(s);for(let r=0;r<s;r++){const n=o[r],s=sd(n,t);e[r]=[s,n.value.getError()]}n.dynamic=e}const i=this._volatile;if(i.size>0){const t=i.values();let e=t.next();const r=this._values.getOrientation()===exports.t.Orientation.Column,o=Hc(!0);for(;!e.done;){const n=e.value;if(Array.isArray(n))for(let t=0;t<n.length;t++){const e=n[t];for(let t=0;t<e.length;t++){const n=e[t],s=n.colIndex,i=n.rowIndex,a=r?s:i,l=r?i:s;o.append(a,l)}}else{const t=n.colIndex,e=n.rowIndex,s=r?t:e,i=r?e:t;o.append(s,i)}e=t.next()}const s=o.done(!0),a=s.length,l=new Array(a);for(let t=0;t<a;t++){const e=s[t],r=sd(e,this._getEntireCoords());l[t]=r}n.volatile=l}return n}}const vf=(t,e,r,n)=>{const o=new exports.Tuple.Builder(Of),s=Hc(n);t.sort(n?U.columnFirstCellComparator:U.rowFirstCellComparator);const i=t.length;for(let e=0;e<i;e++){const r=t[e],i=r.colIndex,a=r.rowIndex;let l=r.cachedValue;if(!l?.isIRange){const t=n?i:a,e=n?a:i;let l=r.cachedValue;o.addValue(t,e,l),s.append(t,e)}}const a=o.build();a&&a.tuples&&e.setValues(a.tuples);const l=s.done(!0);for(let t=0;t<l.length;t++){const e=l[t];r.insertNonOverlapping(e)}},If=(t,e,r)=>{const n=t.colStart,o=t.rowStart,s=t.colEnd,i=t.rowEnd,a=e.colStart,l=e.rowStart,c=e.colEnd,h=e.rowEnd,d=Math.max(n,a),u=Math.max(o,l),g=Math.min(s,c),p=Math.min(i,h),m=t.value.calcs;for(let t=u;t<=p;t++){const e=t-o,s=m[e];for(let t=d;t<=g;t++){const o=t-n;r(s[o],e,o)}}},Af=(t,e,r,n)=>{const o=t.value,s=o.$absHeight,i=o.$absWidth,a=o.width,l=o.height,c=o.blockEntry.value.calcs,h=r-t.colStart,d=e-t.rowStart,u=Math.min(Math.max(h,0),a-1),g=Math.min(Math.max(d,0),l-1);if(s||i)if(i){const t=c[g];for(let e=0;e<a;e++){n(t[e])}}else if(s)for(let t=0;t<l;t++){n(c[t][u])}else for(let t=0;t<l;t++){const e=c[t];for(let t=0;t<a;t++){n(e[t])}}else{n(c[g][u])}},Rf={rowIndex:0,colIndex:0},Mf={rowStart:0,colStart:0,rowEnd:0,colEnd:0},Tf=[],Ff=[],Nf={rowStart:0,colStart:0,rowEnd:0,colEnd:0},kf={rowStart:0,colStart:0,rowEnd:0,colEnd:0};new exports.n.Calc("Cyclical dependency");const Of=t=>new vl(t);let Bf=0;const Lf=1e4,Df=new Array(Lf),zf=new Array(Lf),Pf=new Set,jf=new Array(Lf);let Hf=0;const Vf=new Array(Lf);let $f=0,Uf=0;const Gf=new Array(Lf);let Wf=0,qf=0;const Jf=new Array(Lf);let Xf=0;const Kf=new Array(Lf),Yf={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Zf={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Qf=[null,null],t_=Object.freeze({inserts:mt.EmptyArray,removes:mt.EmptyArray});function e_(t,e,r,n){const o=t;if(o?.getSplit){const t=o.getSplit(e,r,n);if(void 0===t)return;e[0].value=t[0],e[1].value=t[1]}return e}class r_{constructor(t,e=!0){this._options={...s_,...t},this._getFunction=this._options.getFunction,this._isColumn=e}_setInstanceScope(t){this._instanceScope=t}async _initialize(){const t=await xe._validate(!0),e=o_();this._calcScope=e,this._runtime=new n_(this._options,t);const{initializeBuiltIns:r}=await Promise.resolve().then(()=>require("./Cl0gNER1w9A58kbc.cjs")),n=this;return this._builtInFunctions=Object.freeze(r(()=>n)),{builtInFunctions:this._builtInFunctions,calcScope:this._calcScope}}getBuiltInFunctions(){return this._builtInFunctions}getFunction(t){return this._builtInFunctions.get(t)??this._getFunction?.(t)}getNumberFormat(t,e){return exports.NumberFormat.Parser.formatValue(t,e,{date1904:this._options.isDate1904?.()??!1})}getEntireCoords(){return this._calcScope.getEntireCoords()}getFormulaAt(t,e){const r=this._calcScope.formulaSpatial;if(!r)return null;a_.colStart=e,a_.rowStart=t,a_.colEnd=e,a_.rowEnd=t;const n=r.search(a_);if(0===n.length)return null;return n[0].value.formula.getTextAt(t,e)??null}markVolatile(){const t=this._calcScope,e=t.volatile;e&&e.add(t.node)}formatResults(t){const e=this._calcScope,r=this._isColumn,n=r?e.colIndex:e.rowIndex,o=r?e.rowIndex:e.colIndex;e.conflatingFormats||(e.conflatingFormats=Hc(r)),e.conflatingFormats.append(n,o,t)}getSheetIndex(t){const e=this._calcScope;return void 0===t&&(t=e.sheetName),this._options.getSheetIndex?.(t)??-1}getSheetCount(){return this._options.getSheetCount?.()??1}isValidDate(t){return ls(t)}fromOADate(t){return ps(t,this._options.isDate1904?.()??!1)}toOADate(t){return ms(t,this._options.isDate1904?.()??!1)}_fromTuples(t,e=null,r=!1){if(!t)return null;const n=Mc(t.bounds,!0),o=this._calcScope,s=this._isColumn?exports.t.Orientation.Column:exports.t.Orientation.Row,i=new Vc({orientation:s,maxCoords:o.getEntireCoords()});i.setValues(t.tuples);return new Ch(i,n,e,r)}getValueAt(t,e){return this._calcScope.values.getValueAt(t,e)??null}getSpillAt(t,e){const r=this._calcScope.spillSpatial;if(!r)return null;l_.rowStart=t,l_.colStart=e,l_.rowEnd=t,l_.colEnd=e;const n=r.search(l_);if(0===n.length)return null;for(let r=0;r<n.length;r++){const o=n[r];if(o.rowStart===t&&o.colStart===e)return this.getReference(U.sanitizeRange(o))}return null}getRange(t,e){if(t?.isIRange)return t;let r;const n=Array.isArray(t);if(e=e??n,n)if(Array.isArray(t[0]))r=t;else{if(t[0]?.isIRange)throw exports.n.BuiltIn.Value;r=[t]}else r=[[t]];const o=this._isColumn,s=o?exports.t.Orientation.Column:exports.t.Orientation.Row,i=this._fromTuples(Dc(r,o,Rc(0,0,void 0,void 0,o),!0),void 0,e);if(i)return i;const a=new Vc({orientation:s,maxCoords:this._calcScope.getEntireCoords()});return new Ch(a,U.EmptyRange,void 0,e)}getPosition(){const t=this._calcScope;return{colIndex:t.colIndex,rowIndex:t.rowIndex}}getReference(t,e){if(!t)throw exports.n.BuiltIn.Ref;const r=this._calcScope,n=r.getEntireCoords;if("string"==typeof t){if(e)throw exports.n.BuiltIn.Ref;try{const r=md(t,n(),dd,()=>{throw exports.n.BuiltIn.Ref},e);if(r.length>1)throw exports.n.BuiltIn.Ref;t=r[0]}catch(t){throw exports.n.BuiltIn.Ref}}if(!t)throw exports.n.BuiltIn.Ref;const o=r.values;let s;const i=r.node;let a;if(i){const e=i.precedents;a=i_(e,t)}if(a){const e=a.calc;s=e&&e.isIReferenceRange?e.cachedValue:new ff(o,void 0,t,null,n)}else r.dynamicPrecedentsInserts=bf(r.dynamicPrecedentsInserts,i,t),s=new ff(o,void 0,t,null,n);return s}getAddress(t,e=!1){t||(t=this.getPosition());const r=this.getEntireCoords().sheetName;return void 0!==t.colIndex?((t,e,r=!1)=>r?Rd(t,e):id(t,e))(t,r,e):((t,e,r=!1)=>(r?Rd({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart,sheetName:t.sheetName},e):id({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart,sheetName:t.sheetName},e))+":"+(r?Rd({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd},null):id({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd},null)))(t,r,e)}parseAsDateTime(t,e=!1){return function(t,e=!1,r=!1){let n=t,o=vs(t,e,!0);o&&(n=o.leadingText);let s=null;if(n.trim().length>0&&(s=As(n,e),!s&&r))return null;!s&&o?.leadingText.trim().length>0&&(o=null);let i=0;return s&&(i+=s.asOADate),o&&(i+=o.parsed.oaDateTime),i}(t,this._options.isDate1904?.()??!1,e)}getRuntime(){return this._runtime}get[Symbol.toStringTag](){return"[CalculationContext]"}toString(){let t="";const e=this._instanceScope;let r;if(e&&(r=e.toString?.()),r){r&&(t=`${t}:[${r}]`)}return t}}class n_{constructor(t,e){this._options=t,this._license=e}getCurrencySymbol(){return"$"}getNumberDecimalSeparator(){return"."}getNumberGroupSeparator(){return","}isDate1904(){return this._options.isDate1904?.()??!1}getDescription(){return"Calculation Runtime"}getLocation(){return mt.isNode()?process.cwd():window.location?.href??"/"}getVersion(){try{const t="0.4.13";if(-1===t.indexOf(".env."))return`${t}`}catch(t){return"local"}}getOS(){return mt.getOS()}getUser(){return this._license?.licensee?.()??null}}const o_=()=>({rowIndex:0,colIndex:0,sheetName:null,node:null,values:null,formulaSpatial:null,spillSpatial:null,volatile:null,conflatingFormats:null,dynamicPrecedentsInserts:null,formula:null,getEntireCoords:()=>vh}),s_={getSheetIndex:t=>-1,getSheetCount:()=>1,getSheetName:()=>null,getEntireCoords:()=>vh,getNamed:(t,e)=>null,getFunction:t=>null,isDate1904:()=>!1},i_=(t,e)=>{if(!t)return;const r=t.length;if(0===r)return;const n=e.colStart,o=e.rowStart,s=e.colEnd,i=e.rowEnd;for(let e=0;e<r;e++){const r=t[e],a=r;if(void 0!==a&&(r.colStart===n&&r.rowStart===o&&r.colEnd===s&&r.rowEnd===i))return a}return null},a_={rowStart:0,colStart:0,rowEnd:0,colEnd:0},l_={rowStart:0,colStart:0,rowEnd:0,colEnd:0};class c_{_setScope(t){this._scope=t}_getScope(t=!1){const e=this._scope;if(!e&&!t)throw new Error("FunctionContext can only be used in a function.");return e}getNumberFormat(t,e){return this._getScope().getNumberFormat(t,e)}getEntireCoords(){return this._getScope().getEntireCoords()??vh}isValidDate(t){return this._getScope().isValidDate(t)}parseAsDateTime(t,e){return this._getScope().parseAsDateTime(t,e)}fromOADate(t){return this._getScope().fromOADate(t)}toOADate(t){return this._getScope().toOADate(t)}getRange(t){return this._getScope().getRange(t)}getValueAt(t,e){return this._getScope().getValueAt(t,e)}getPosition(){return this._getScope().getPosition?.()??Ih}getReference(t,e){return this._getScope().getReference(t,e)}getFormulaAt(t,e){return this._getScope().getFormulaAt?.(t,e)??null}getSpillAt(t,e){return this._getScope().getSpillAt?.(t,e)??null}getSheetIndex(t){return this._getScope().getSheetIndex?.(t)??-1}getSheetCount(){return this._getScope().getSheetCount?.()??1}markVolatile(){this._getScope().markVolatile?.()}formatResults(t){this._getScope().formatResults?.(t)}getFunction(t){return this._getScope().getFunction?.(t)??null}getAddress(t,e){return this._getScope().getAddress(t,e)}getRuntime(){return this._getScope().getRuntime()}get[Symbol.toStringTag](){return"[FormulaContext]"}toString(){const t=this._getScope();if(t){const e=t.toString?.();if(e)return e}return""+(t?"":"{NO SCOPE}")}}const h_=new c_,d_="__SHEETXL";let u_;const g_={FormulaContext:u_,ScalarType:t,IRange:exports.t,FormulaError:exports.n,Observable:h};let p_;function m_(t){u_||(u_=h_,g_.FormulaContext=u_),p_=globalThis[d_],globalThis[d_]=g_,u_._setScope(t)}function f_(){p_?(globalThis[d_]=p_,p_=void 0):delete globalThis[d_],u_&&u_._setScope(null)}var __;(__||(__={})).Context={Workbook:"workbook",Sheet:"sheet",Ranges:"ranges",Range:"range",Calculation:"calculation"};class S_{constructor(t,e,r,n=null,o=!1){this._ct=__.Context.Calculation,this._builtIn=!1,this._broadcast=!1,this._pj=null,this._json=t,this._n=t.name,this._d=new E_(t),this._ct=t.context??__.Context.Calculation;const s=t.parameters;let i;this._pj=s,e||(console.log(`TypeFunction '${t.name}' was not provided a function implementation.`),e=()=>{}),this._fn=e.bind(this),this._cf=r??y_,this._builtIn=o,i=n?"function"==typeof n?n:()=>Promise.resolve(n):w_(t),this._descFn=i;const a=s?.length??0;let l=1===a||2===a;l&&(s[0].arrayDepth>0||s[0].range)&&(l=!1),l&&2===a&&(s[1].arrayDepth>0||s[1].range)&&(l=!1),this._broadcast=l}execute(...e){const r=this._pj,n=[],o=this._cf?.();m_(o);let s=!1,i=null;const a=r?.length??0;let l,c=this._broadcast;if(c){const t=kh(e[0]);if(1===a&&t)c=!1;else if(2===a){const r=kh(e[1]);t&&r&&(c=!1)}}try{for(let l=0;!s&&l<a;l++){const a=r[l];let h=a.scalar??null;h!==t.Null&&"*"!==h||(h=null);let d=a.range??null;const u=a.rest??!1,g=a.optional??!1;let p=e[l];if(g&&null===p&&(p=void 0),void 0===p){if(g){n.push(void 0);continue}if(!g&&!u)throw l<=e.length?A_.ARGS_TOO_FEW([a.name],this._n):A_.PARAM_MISSING(a.name,this._n);if(l>=e.length){s=!0;continue}}const m=a.arrayDepth??0;let f=(a.range?2:0)+m;const _=a.rest??!1;if(_)for(;l<e.length&&!i;)void 0!==p&&(i=I_(o,n,p,h,d,m,_,f)),p=e[++l];else c&&(d="l",f=2),i=I_(o,n,p,h,d,m,_,f),s=!!i}if(i)throw i;for(;n.length>0&&void 0===n[n.length-1];)n.length--;const h=this._fn;if(c){if(1===n.length){const e=n[0];let o=r[0].scalar;o!==t.Null&&"*"!==o||(o=null),l=e.map(t=>{if(t instanceof exports.n.Known)return t;let e=t;try{e=h(e),(Array.isArray(e)||e?.isIRange)&&(e=exports.n.BuiltIn.Value)}catch(t){e=t}return e},{type:o})}if(2===n.length){const e=n[0];let o=r[0].scalar;o!==t.Null&&"*"!==o||(o=null);const s=n[1];let i=r[1].scalar;i!==t.Null&&"*"!==i||(i=null),l=e.broadcast(s,(t,e)=>{if(t instanceof exports.n.Known)return t;if(e instanceof exports.n.Known)return e;let r;try{r=h(t,e),(Array.isArray(r)||r?.isIRange)&&(r=exports.n.BuiltIn.Value)}catch(t){r=t}return r},{type:o,otherType:i})}}else l=h(...n);l=Lh(l,o)}catch(t){throw t}finally{f_()}return l}getName(){return this._n}getDeclaration(){return this._d}async getDescriptor(t){if(this._desc)return this._desc;const e=await Promise.resolve(this._descFn(t));return this._desc=new v_(this,e),this._desc}isBuiltIn(){return this._builtIn}getContext(){const t=this._ct;if("sheet"===t||"workbook"===t||"ranges"===t||"range"===t){const t=this._json;return t&&t.behavior&&t.behavior.default?"autoRun":"macro"}return"formula"}get[Symbol.toStringTag](){return"[TypedFunction]"}toString(){let t="";const e=this._pj;return e.length>0&&(t=e.map(t=>{let e=t.name;return t.rest&&(e="..."+e),t.optional&&(e+="?"),e+=": "+((t,e)=>{if(e){const r=Th.get(e)??"InvalidRange";return t?`${r}<${Mh.get(t)??"InvalidScalar"}>`:r}return Mh.get(t)??"InvalidScalar"})(t.scalar,t.range),e+="[]".repeat(t.arrayDepth),e}).join(", ")),`${this.getName()}(${t})`}get isIFunction(){return!0}get isITypedFunction(){return!0}}const w_=t=>async e=>{const r={};for(let e=0;e<t.parameters.length;e++)r[t.parameters[e].name]=mt.camelToPrettyCase(t.parameters[e].description);return{summary:mt.camelToPrettyCase(t.name),parameters:r,category:"User Defined"}},y_=()=>null;class x_{constructor(t){this._s=t.scalar,this._r=t.range??null,this._d=t.arrayDepth??0}getScalarType(){return this._s}getRangeType(){return this._r}getArrayDepth(){return this._d}}class C_ extends x_{constructor(t){super(t),this._n=t.name,this._o=t.optional??!1,this._rest=t.rest??!1,this._e=t.enums?Object.freeze(t.enums):mt.EmptyArray}getName(){return this._n}isOptional(){return this._o}isRest(){return this._rest}getEnums(){return this._e}}class b_ extends x_{constructor(t){super(t),this._a=t.async??!1,this._stream=t.stream??!1}isAsync(){return this._a}isStreaming(){return this._stream}}class E_{constructor(t){if(this._n=t.name,t.parameters){const e=t.parameters.length,r=new Array(e);for(let n=0;n<e;n++)r[n]=new C_(t.parameters[n]);this._p=Object.freeze(r)}else this._p=mt.EmptyArray;t.returnType?this._r=new b_(t.returnType):this._r=new b_({scalar:null,arrayDepth:0,range:null})}getName(){return this._n}getParameters(){return this._p}getReturnType(){return this._r}}class v_{constructor(t,e){if(this._n=e.name,this._fn=t,this._s=e.summary??mt.camelToPrettyCase(e.name),this._c=e.category??"Uncategorized",this._h=e.hidden??!1,e.links&&e.links.length>0){const t=e.links.length,r=new Array(t);for(let n=0;n<t;n++)r[n]=Object.freeze([e.links[n][0],e.links[n][1]]);this._l=Object.freeze(r)}else this._l=mt.EmptyArray;if(e.parameters)for(const t in e.parameters)if(Object.prototype.hasOwnProperty.call(e.parameters,t)){const r=e.parameters[t].description,n=e.parameters[t].example,o=e.parameters[t].defaultValue,s={};r&&(s.description=r),n&&(s.example=n),void 0!==o&&(s.defaultValue=o),Object.freeze(s)}}getName(){return this._n}getSummary(){return this._s}getCategory(){return this._c}isHidden(){return this._h}getLinks(){return this._l}getParameters(){return this._p}get[Symbol.toStringTag](){return"[Descriptor]"}toString(){const t=this._fn;return`${this.getSummary()}: ${t}`}}const I_=(t,e,r,n,o,s,i,a)=>{if(r&&void 0!==r.colStart)if(o)r=t.getReference?.(r);else{const e=r.colStart,n=r.rowStart,o=r.colEnd;r=r.rowEnd!==n||e!==o?t.getReference?.(r):t.getValueAt(n,e)}if(0===a){let t=((t,e=null,r=!1)=>{let n=t;for(;Array.isArray(n);){if(n.length>1)return r?exports.n.BuiltIn.Value:n;n=n[0]}if(n?.isIRange){if(1!==n.size)return r?exports.n.BuiltIn.Value:n;n=n.getValueAt(0,0)}return e&&(n=Nh(n,Rh(n,!0),e)),n})(r,n,!0);return t instanceof exports.n.Known?t:void e.push(t)}if(2===a)return Bh(t,e,r,n,o,Array.isArray(r));if(1===a||3===a){let s;const l=i?e:[];if(o){const e=Array.isArray(r);if(e){const i=r.length;for(let a=0;!s&&a<i;a++)s=Bh(t,l,r[a],n,o,e)}else s=Bh(t,l,r,n,o,e)}else if(3===a){let e=(t=>{let e=t,r=0;for(;Array.isArray(e);)r++,e=e[0];return e.isIRange&&(r+=2),r})(r);for(let t=e;t<2;t++)r=[r],e++;if(3===e){const e=r.length;for(let i=0;!s&&i<e;i++)s=Bh(t,l,r[i],n,o,!0)}else s=Bh(t,l,r,n,o,!0)}else s=Oh(t,l,r,n,o,null!==o);return s?.isFormulaError?s:void(i||e.push(l))}{if(!Array.isArray(r)){if(n&&(r=Nh(r,Rh(r,!0),n,!1),r?.isFormulaError))return e.push(r),r;r=[r]}const l=r.length;for(let c=0;c<l;c++){const l=[],h=I_(t,l,r[c],n,o,s,i,a-1);if(h?.isFormulaError)return h;l.length>0&&e.push(l)}}},A_={PARAM_MISSING:(t,e)=>new exports.n.NA(`Parameter ${t} is missing${e?` for ${e}`:""}.`),ARGS_TOO_FEW:(t,e)=>new exports.n.Parse(`Argument type ${t.join(", ")} is missing${e?` for ${e}`:""}.`)};class R_{constructor(t){this._emitter=null,this._readonly=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new re({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,r,n){e._emitter.notify("onCollectionChange")}}),this._emitter=new ml(this,this._transactions),this._readonly=t?.readonlyFunctions,this._initState()}search(t){const e=this._getState();if(!e)return mt.EmptyArray;const r=t?.name?t.name.toUpperCase():null,n=t?.type?t.type:null;let o;t?.category&&t.category.toUpperCase(),t?.text&&t.text;const s=(t,e)=>(!r||e===r)&&((!n||t.getContext()===n)&&(o||(o=[]),void o.push(t))),i=this._readonly;return i&&i.forEach(s),e.itemsByKey.forEach(s),o??mt.EmptyArray}getByName(t){if(!t)return null;const e=this._getState();if(!e)return null;if(!e)return mt.EmptyArray;const r=t.toUpperCase(),n=this._readonly;if(!n||!n.size)return null;let o=n.get(r);return o||(o=e.itemsByKey.get(r),o||null)}getCount(){const t=this._getState();if(!t)return 0;let e=t.itemsByKey.size;return this._readonly&&(e+=this._readonly.size),e}validateName(t){return this._validateName(t)}_validateName(t,e=!1){if(this._closed)throw new Error(gl)}add(t){if(this._closed)throw new Error(gl);if(!t)throw new Error("Item must be specified.");let e;if(t.isIFunction){const r=t,n=t._json;e=new S_(n,r._fn,()=>this._options.context,r._desc)}else{const r=t;e=new S_(r.declaration,r.execute,()=>this._options.context,r.descriptor)}const r=this._getState(),n=e.getName().toUpperCase();return r.itemsByKey.set(n,e),e}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(gl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update",r){if(!t)return;const n=this._beginCommit(e);try{n.updateState(this,t),n.commit(r)}catch(t){throw n.rollback(),t}}_initState(){this._updateState(t=>({...t,itemsByKey:new Map}),"Initialize",{forceAmend:!0})}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}}class M_ extends fl{constructor(t){super(t),this._status=exports.ICalculation.Status.Off,this._statusTransition=null,this._emitter=new ml(this)}_getContext(){return this._context}_getScope(){return this._scope}start(){return this._statusTransition||(this._statusTransition=(async()=>{if(this._status===exports.ICalculation.Status.Off)try{this._status=exports.ICalculation.Status.Starting,this._emitter.notify("onStatusChange"),this._emitter.notify("onStarting");const t=this,e=this._options,r=r=>t.getFunctions().getByName(r)??e?.getFunction?.(r),n=new r_({...e,getFunction:r});this._context=n;const o=await n._initialize(),s=o.builtInFunctions;this._functions=new R_({transactions:this._transactions,context:n,readonlyFunctions:s});const i=await Promise.resolve().then(()=>require("./DvioTOgF2jNUKBcT.cjs"));this._formulaParser=new i.FormulaParser,this._scope=o.calcScope,this._status=exports.ICalculation.Status.Ready,this._emitter.notify("onStatusChange"),this._emitter.notify("onReady")}catch(t){throw this._status=exports.ICalculation.Status.Off,this._emitter.notify("onError",t),this._emitter.notify("onStatusChange"),t}finally{this._statusTransition=null}})()),this._statusTransition}_createGraph(t){const e=this._options;return new Ef({...e,...t,getFormulaParser:()=>this._formulaParser,calculation:this})}async stop(){this._status===exports.ICalculation.Status.Ready&&(this._status=exports.ICalculation.Status.Stopping,this._emitter.notify("onStatusChange"),this._emitter.notify("onStopping"),this._status=exports.ICalculation.Status.Off,this._emitter.notify("onStatusChange"),this._emitter.notify("onStop"))}getStatus(){return this._status}getFunctions(){return this._checkReady(),this._functions}getRuntime(){return this._checkReady(),this._runtime}_checkReady(){if(this._status!==exports.ICalculation.Status.Ready)throw new Error(this._statusMessage())}_statusMessage(){switch(this._status){case exports.ICalculation.Status.Off:return"Calculation is off";case exports.ICalculation.Status.Starting:return"Calculation is starting";case exports.ICalculation.Status.Ready:return"Calculation is ready";default:return"Unknown calculation status"}}}var T_,F_;exports.ICellRange=void 0,exports.ICellRange||(exports.ICellRange={}),exports.ICellHeaderRange=void 0,exports.ICellHeaderRange||(exports.ICellHeaderRange={}),exports.IMovable=void 0,exports.IMovable||(exports.IMovable={}),exports.IAutoFilter=void 0,(T_=exports.IAutoFilter||(exports.IAutoFilter={})).NumberFilterOperatorType={Equal:"equal",GreaterThan:"greaterThan",GreaterThanOrEqual:"greaterThanOrEqual",LessThan:"lessThan",LessThanOrEqual:"lessThanOrEqual",NotEqual:"notEqual"},T_.Type={Color:"color",Custom:"custom",Dynamic:"dynamic",Items:"items",Icon:"icon",Top10:"top10"},T_.DynamicType={AboveAverage:"aboveAverage",BelowAverage:"belowAverage",LastMonth:"lastMonth",LastQuarter:"lastQuarter",LastWeek:"lastWeek",LastYear:"lastYear",M1:"M1",M2:"M2",M3:"M3",M4:"M4",M5:"M5",M6:"M6",M7:"M7",M8:"M8",M9:"M9",M10:"M10",M11:"M11",M12:"M12",NextMonth:"nextMonth",NextQuarter:"nextQuarter",NextWeek:"nextWeek",Null:"null",Q1:"Q1",Q2:"Q2",Q3:"Q3",Q4:"Q4",ThisMonth:"thisMonth",ThisQuarter:"thisQuarter",ThisWeek:"thisWeek",Today:"today",Tomorrow:"tomorrow",YearToDate:"yearToDate",Yesterday:"yesterday"},T_.DateItemGroupingType={Day:"day",Hour:"hour",Minute:"minute",Month:"month",Second:"Second",Year:"year"},exports.IConditionalFormat=void 0,(F_=exports.IConditionalFormat||(exports.IConditionalFormat={})).Type={AboveAverage:"aboveAverage",BeginsWith:"beginsWith",CellIs:"cellIs",ColorScale:"colorScale",ContainsBlanks:"containsBlanks",ContainsErrors:"containsErrors",ContainsText:"containsText",DataBar:"dataBar",DuplicateValues:"duplicateValues",EndsWith:"endsWith",Expression:"expression",IconSet:"iconSet",NotContainsBlanks:"notContainsBlanks",NotContainsErrors:"notContainsErrors",NotContainsText:"notContainsText",TimePeriod:"timePeriod",Top10:"top10",UniqueValues:"uniqueValues"},F_.OperatorType={BeginsWith:"beginsWith",Between:"between",ContainsText:"containsText",EndsWith:"endsWith",Equal:"equal",GreaterThan:"greaterThan",GreaterThanOrEqual:"greaterThanOrEqual",LessThan:"lessThan",LessThanOrEqual:"lessThanOrEqual",NotBetween:"notBetween",NotContains:"notContains",NotEqual:"notEqual"},F_.TimePeriod={Last7Days:"last7Days",LastMonth:"lastMonth",LastWeek:"lastWeek",NextMonth:"nextMonth",NextWeek:"nextWeek",ThisMonth:"thisMonth",ThisWeek:"thisWeek",Today:"today",Tomorrow:"tomorrow",Yesterday:"yesterday"},F_.ConditionalBoundsType={Formula:"formula",Max:"max",Min:"min",Num:"num",Percent:"percent",Percentile:"percentile"},exports.ISheetView=void 0,(exports.ISheetView||(exports.ISheetView={})).HeaderTextStyle={A1:"a1",Zero:"zero",One:"one"};class N_{constructor(t,e,r,n){this._mergedReading=[],this._colsReading=[],this._rowsReading=[],this._styles=t,this._topLeft=n??{rowIndex:0,colIndex:0},this._sheet=new tw({styles:this._styles,date1904:e,container:{getName:()=>r,getIndex:()=>1}}),this._cellUpdater=this._sheet.getEntireRange().startIncrementalUpdates()}applyCSSStyle(t,e){let r=!1;t.style||(t.style={},r=!0);let n=t.style,o={...e};if(e.msoIgnore){const t=e.msoIgnore.split(",");let r=Object.keys(o);for(let e=0;e<r.length;e++){const n=r[e];t.includes(n)&&delete o[n]}}const s=Au(o.fontFamily);n.font={},s&&(n.font.family=s.family,n.font.fallbacks=s.fallbacks,n.font.size=s.size),n.font.size=o.fontSize,n.font.weight=o.fontWeight,n.font.style=o.fontStyle,n.font.fill=o.color;const i=(t=>{if(!t)return Fu;let e=exports.IFont.UnderlineStyle.None,r=!1;return(t=t.toLowerCase()).includes("underline")&&(e=exports.IFont.UnderlineStyle.Single),(t.includes("line-through")||t.includes("linethrough"))&&(r=!0),{underline:e,strike:r}})(o.textDecoration);n.font.underline=i.underline,n.font.strike=i.strike,o.textUnderlineStyle&&(n.font.underline=Nu(o.textUnderlineStyle)),n.alignment={},o?.textAlign&&(n.alignment.horizontal=(t=>{const e=mt.textToKey(t);return Yg.get(e)||null})(o.textAlign)),o?.textAlign&&!n.alignment.horizontal&&"general"!==o?.textAlign&&("center-across"===o.textAlign?n.alignment.horizontal=exports.ITextFrame.HorizontalAlignment.CenterContinuous:"fill"===o.textAlign?n.alignment.horizontal=exports.ITextFrame.HorizontalAlignment.Fill:"121"===o.textAlign||"010"===o.textAlign?(n.alignment.horizontal=exports.ITextFrame.HorizontalAlignment.Distributed,n.alignment.justifyLastLine="121"===o.textAlign):console.warn("unknown text-align",o.textAlign)),o.verticalAlign&&("super"===o.verticalAlign.toLowerCase()?n.font.verticalAlign=exports.IFont.VerticalAlignment.Super:"sup"===o.verticalAlign.toLowerCase()?n.font.verticalAlign=exports.IFont.VerticalAlignment.Sub:n.alignment.vertical=(t=>{const e=mt.textToKey(t);return Zg.get(e)||null})(o.verticalAlign),n.alignment.vertical||("121"===o.verticalAlign?n.alignment.vertical=exports.ITextFrame.VerticalAlignment.Distributed:console.warn("unknown vertical-align",o.verticalAlign))),o.msoCharIndentCount&&(n.alignment.indent=o.msoCharIndentCount),o.whiteSpace&&(n.alignment.overflow="no-wrap"===o.whiteSpace||"nowrap"===o.whiteSpace?exports.ITextFrame.Overflow.Visible:exports.ITextFrame.Overflow.Wrap),"shrinktofit"===o.msoTextControl&&(n.alignment.overflow=exports.ITextFrame.Overflow.Shrink);let a=null;if(o.background?a=o.background:o.backgroundColor&&(a=o.backgroundColor),a&&(n.fill={color:a}),o.msoPattern){let t=bg(o.msoPattern);t&&(t.patternType===exports.IFill.BuiltInSheetPattern.Solid?n.fill={color:t.foreground}:t.patternType!==exports.IFill.BuiltInSheetPattern.None&&(a&&(t.background=a),n.fill=t))}void 0!==o.msoRotate&&(n.alignment.rotation=(t=>{let e=parseFloat(t);return isNaN(e)||(e%=360,e>0?e=360-e:e<0&&(e*=-1)),e})(o.msoRotate));const l=(t,e)=>{t&&(n.border||(n.border={}),n.border[t]=e)};o.border&&"none"!==o.border&&(l("top",o.border),l("left",o.border),l("right",o.border),l("bottom",o.border)),o.borderTop&&l("top",o.borderTop),o.borderLeft&&l("left",o.borderLeft),o.borderRight&&l("right",o.borderRight),o.borderBottom&&l("bottom",o.borderBottom),o.msoDiagonalUp&&l("diagonalUp",o.msoDiagonalUp),o.msoDiagonalDown&&l("diagonalDown",o.msoDiagonalDown);let c=n.numberFormat;o.msoNumberFormat&&(c=(t=>{let e=t.replace(/(\\[0-9]{4})/g,t=>String.fromCharCode(parseInt(t.replace(/\\/g,""),16)));return e=e.replace(/(\\.{1})/g,t=>t.substring(t.length-1,t.length)),e.includes("\\")&&(e=e.replace(/(\\.{1})/g,t=>t.substring(t.length-1,t.length))),e=e.replace(/^"(.*)"$/,"$1"),e})(o.msoNumberFormat),c.includes("\\")?c=null:"Fixed"===c?c=exports.NumberFormat.Styles.lookupStyle(n.numberFormat).formatType===exports.NumberFormat.Type.Number?null:exports.NumberFormat.Type.Number:"Percent"===c&&(c=exports.NumberFormat.Styles.lookupStyle(n.numberFormat).formatType===exports.NumberFormat.Type.Percentage?null:exports.NumberFormat.Type.Percentage)),c&&(n.numberFormat=c),t.style=this._styles.normalize(n),r&&0===Object.keys(t.style).length&&delete t.style}onCell(t,e,r,n,o){const s=n(o);let i={value:void 0!==e?e:r??""};if("string"==typeof i.value&&0===i.value.length&&(i.value=void 0),s&&this.applyCSSStyle(i,s),"TD"===o?.tagName.toUpperCase()){let t=i.style,e=t?.font??{};(o.querySelectorAll("s").length>0||o.querySelectorAll("strike").length>0)&&(e.strike=!0),o.querySelectorAll("sub").length>0&&(e.verticalAlign=exports.IFont.VerticalAlignment.Sub),o.querySelectorAll("sup").length>0&&(e.verticalAlign=exports.IFont.VerticalAlignment.Super),(o.querySelectorAll("b").length>0||o.querySelectorAll("strong").length>0)&&(e.weight=700),o.querySelectorAll("i").length>0&&(e.style=exports.IFont.Style.Italic),o.querySelectorAll("u").length>0&&(e.underline=exports.IFont.UnderlineStyle.Single),Object.keys(e).length>0&&(t||(t={},i.style=t),t.font||(t.font=e));const r=o.querySelectorAll("a");if(r.length>0){const t=r[0].getAttribute("href");t&&(i.hyperlink=t)}}if(!U.isSingleCell(t)){const e={rowStart:this._topLeft.rowIndex+t.rowStart,colStart:this._topLeft.colIndex+t.colStart,rowEnd:this._topLeft.rowIndex+t.rowEnd,colEnd:this._topLeft.colIndex+t.colEnd};this._mergedReading.push(e)}if((void 0!==i.value||i.style||!(Object.keys(i).length<=1))&&(this._cellUpdater.pushAt(this._topLeft.rowIndex+t.rowStart,this._topLeft.colIndex+t.colStart,i),!U.isSingleCell(t)&&s.msoIgnore)){if(s.msoIgnore.includes("colspan")){const e={};s&&this.applyCSSStyle(e,s);const r=t.colEnd-t.colStart;for(let n=1;n<=r;n++)this._cellUpdater.pushAt(this._topLeft.rowIndex+t.rowStart,this._topLeft.colIndex+t.colStart+n,e);t={...t,colEnd:t.colStart}}s.msoIgnore.includes("rowspan")&&(t={...t,rowEnd:t.rowStart})}}onNoTable(t,e,r){this.onCell({rowStart:this._topLeft.rowIndex,colStart:this._topLeft.colIndex,rowEnd:this._topLeft.rowIndex,colEnd:this._topLeft.colIndex},t,null,e,r)}onRowStart(t,e,r,n){const o=r(n);if("userset"!==o.msoHeightSource)return;let s=n.getAttribute("height")??o.height,i=null;if(s&&(i=Sg(s,this._styles.getNormal().getFont().getSize(),"px")),null===i)for(let t=0;t<n.cells.length;t++){const e=n.cells[t],o=e.getAttribute("height")??r(e).height;let s=Sg(o,this._styles.getNormal().getFont().getSize(),"px");null!==s&&(i=Math.max(s,i??0))}null!==i&&this._rowsReading.push({address:{min:this._topLeft.rowIndex+t,max:this._topLeft.rowIndex+t+e-1},update:{size:i*exports.IFont.getDeviceScale()}})}onColumn(t,e,r,n){const o=r(n);if("userset"!==o.msoWidthSource)return;let s=n.getAttribute("width")??o.width,i=null;s&&(i=Sg(s,this._styles.getNormal().getFont().getSize(),"px")),null!==i&&this._colsReading.push({address:{min:this._topLeft.colIndex+t,max:this._topLeft.colIndex+t+e-1},update:{size:i*exports.IFont.getDeviceScale()}})}onDone(){this._colsReading.length>0&&this._sheet.getColumnHeaders().updateHeaderPairs(this._colsReading),this._rowsReading.length>0&&this._sheet.getRowHeaders().updateHeaderPairs(this._rowsReading),this._sheet.doBatch(()=>{this._cellUpdater.apply()}),this._mergedReading.length>0&&this._sheet.getRanges(this._mergedReading).merge()}sheet(){return this._sheet}}let k_=!1;class O_{constructor(t,e){this._mapStylesByName=new Map,this._arrStyleNames=[],this._mapStylesByName=t,this._arrStyleNames=e}setNode(t){this._node=t}addStyle(t,e){null!=e&&(this._node?.styles||(this._node.styles=new Map),this._node.styles.set(t,e))}addAttribute(t,e){null!=e&&(this._node?.attributes||(this._node.attributes=new Map),this._node.attributes.set(t,e),"rowspan"===t.toLowerCase()&&parseInt(e)>1&&(this._node.rowspan=parseInt(e)),"colspan"===t.toLowerCase()&&parseInt(e)>1&&(this._node.colspan=parseInt(e)))}addSharedStyle(t,e){let r=this._mapStylesByName.get(t);r?r={...e}:(this._arrStyleNames.push(t),r=e),this._mapStylesByName.set(t,r)}setPlainText(t){this._node.plainText=t}setHTMLText(t){this._node.htmlText=t.replace(/(?:\r\n|\r|\n)/g,"<br>")}}const B_=t=>{const e={};if(!t)return e;t.endsWith(";")||(t+=";");const r=new RegExp(';(?=([^"]*"[^"]*")*[^"]*$)',"gsm");let n,o=0;for(;null!==(n=r.exec(t));){try{let r=t.substring(o,n.index).trim();const s=new RegExp(':(?=([^"]*"[^"]*")*[^"]*$)',"gsm");let i,a,l;for(;null!==(l=s.exec(r));)i=unescape(r.substring(0,l.index)).trim(),a=unescape(r.substring(l.index+1,r.length)).trim();null!==a&&"null"!==a&&(i&&(i=Bs(i)),e[i]=a)}catch(t){console.warn(t)}o=n.index+1}return e},L_=(t,e)=>{const r=[];if(!t)return r;const n=t.children;for(let t=0;t<n.length;t++){const o=n.item(t);if(1===o.nodeType){const t=o.tagName.toUpperCase();e.includes(t)&&r.push(o)}}return r},D_=(t,e,r)=>{try{let n=null,o=null;const s=t=>((t,e)=>{if(!t)return{};let r={},n=e.get(t.localName);n&&(r=Object.assign(r,n));const o=t.getAttribute("class");if(o){const t=e.get("."+o);t&&(r=Object.assign(r,t))}const s=t.getAttribute("style");if(s){const t=B_(s);t&&(r=Object.assign(r,t))}return t.getAttribute("align")&&!r.textAlign&&(r.textAlign=t.getAttribute("align")),r})(t,o);if(t)try{n=[];const i="P, H1, H2, H3, H4, H5, H6, PRE",a=t.querySelector("parsererror");if(a)return console.warn("error",a),!1;const l=t.querySelectorAll("html"),c=l[l.length-1];o=(t=>{const e=t.querySelectorAll("style"),r=new Map;if(e.length<=0)return r;for(let t=0;t<e.length;t++){const n=e[t].childNodes;for(let t=0;t<n.length;t++)if(n[t].nodeType===Node.TEXT_NODE){const e=new RegExp("\x3c!--(.*)--\x3e","gs");let o=n[t].textContent;const s=e.exec(n[t].textContent);if(s&&s.length>1&&(o=s[1]),o=o.replace(/^\s/,""),o?.startsWith("table")){const t=new RegExp("{(.*?)}","gs");let e,n=0;for(;null!==(e=t.exec(o));)try{const t=o.substring(n,e.index),s=B_(e[1]);r.set(t.trim(),s),n=e.index+e[0].length}catch(t){console.warn(t)}return r}}}return r})(c);const h=c.querySelectorAll("body"),d=h[h.length-1];let u=d.querySelectorAll("table");let g=u[0],p=!1;if(!g){let t=d.querySelectorAll("span");g=t[0],p=t.length>1}if(!g){g=L_(d,i)[0]}if(!g){g=L_(t,i)[0]}if("TABLE"===g?.nodeName.toUpperCase()){r.onStart?.(o);const t=g;r.onTableStart?.(s,t);const e=L_(t,"COLGROUP");for(let t=0;e&&t<e.length;t++){const n=L_(e[t],"COL");let o=0;for(let t=0;t<n.length;t++){const e=n[t],i=parseFloat(e.getAttribute("span")),a=isNaN(i)?1:i;r.onColumn?.(o,a,s,e),o+=a}}const i=t.rows;let a=0;for(let t=0;t<i.length;t++){const e=i[t],o=parseFloat(e.getAttribute("span")),l=isNaN(o)?1:o;r.onRowStart?.(a,l,s,e);const c=[];n.push(c);const h=e.cells;for(let t=0;t<h.length;t++){let e=h[t],r=!1;for(let t=0;!r&&t<e.childNodes.length;t++)if(8===e.childNodes[t].nodeType){const n=e.childNodes[t].textContent;if("[if gte vml 1]"===n);else if("[if !vml]"===n);else if("[endif]"===n){const n=e.childNodes[t+1];n?.querySelectorAll&&2===n.querySelectorAll("table, td").length&&(e=n?.querySelectorAll("table, td")[1],r=!0)}}c.push({htmlValue:e.textContent?.replace(/^"|"$/gi,""),element:e})}a+=l,r.onRowDow?.(a,l,s,e)}r.onTableDone?.(s,t)}else{if("SPAN"===g?.nodeName.toUpperCase()){const t=e?e[0]?.[0]:null,n=p&&t?t:g.textContent.replace(/^"|"$/gi,"");return r.onStart?.(o),r.onCell({colStart:0,colEnd:0,rowStart:0,rowEnd:0},e?e[0]?.[0]:null,n,s,g),r.onDone?.(),!0}if(g?.textContent){const t=g.textContent.replace(/^"|"$/gi,"");return r.onStart?.(o),r.onNoTable?.(t,s,g),r.onDone?.(),!0}}}catch(t){console.warn(t),n=null}!n||0!==n.length&&(1!==n.length||null!==n[0]&&0!==n[0].length)||(n=null);const i=e&&(0===e.length||1===e.length&&(null===e[0]||0===e[0].length));n&&i&&(e=null);const a=t=>{const r=new Set;let o=1,i=1;for(let a=0;a<Math.max(e?e.length:0,n?n.length:0);a++){let l=0,c=0,h=n&&n[a]?n[a].length:e[a]?e[a].length:0;for(;c<h;){const h=a+"-"+l;if(!r.has(h)){o=Math.max(o,l+1),i=Math.max(i,a+1);let h=null;const d=n?n[a]?.[c]?.element:void 0;if(d&&(d.getAttribute("rowspan")||d.getAttribute("colspan"))){const t=parseInt(d.getAttribute("colspan"))||1,e=parseInt(d.getAttribute("rowspan"))||1;o=Math.max(o,l+t),i=Math.max(i,a+e),h={rowStart:a,colStart:l,rowEnd:a+Math.max(0,e-1),colEnd:l+Math.max(0,t-1)};for(let n=a;n<a+e;n++)for(let e=l;e<l+t;e++)n===a&&e===l||r.add(n+"-"+e)}else h={rowStart:a,colStart:l,rowEnd:a,colEnd:l};t(h,e?e[a]?.[l]:void 0,n?n[a]?.[c]?.htmlValue:null,s,d||null),c++}l++}}};if(n&&e){let t=0,r=0;a(e=>{t=Math.max(t,e.colEnd+1),r=Math.max(r,e.rowEnd+1)}),e&&n&&(e.length!==r||e[0].length!==t)&&(console.warn("mismatched mimeTypes",e,n),e=null)}return a(r.onCell.bind(r)),r.onDone?.(),!i||null!==n}catch(t){throw console.warn(t),t}};exports.ISheet=void 0,(exports.ISheet||(exports.ISheet={})).Visibility={Visible:"visible",Hidden:"hidden",VeryHidden:"veryHidden"};class z_ extends Om{static{this.instanceCounter=0}constructor(t){if(super(t),!t.content)throw new Error("Content type is required");this._content=t.content,this._uuid=mt.uuidV4(),this._optionsMovable=t;const e=this;this._optionsMovable.setContainerZIndexCallback?.(()=>{e._processZIndex()}),this._optionsMovable.setContainerSelectionCallback?.((t,r)=>{e._processContainerSelect(t,r)}),t.json&&this._fromJSON(t.json);const r=this._content.addListeners({onDelete:()=>{e._options.deleteFromContainer&&e._options.deleteFromContainer?.()}},{transactional:!0});this._updateState({contentListenerRemove:r},null,[])}getUUID(){return this._uuid}getContent(){return this._content}_processStateChange(t,e,r){super._processStateChange(t,e,r),this._getEmitter().notify("onBoundsChange"),this._getEmitter().notify("onAnyChange")}_processZIndex(){this._getEmitter().notify("onAnyChange")}_processContainerSelect(t,e){this._getEmitter().notify("onSelectionChange")}isSelected(){return this._optionsMovable.isSelected?.()??!1}async scrollIntoView(t){return this._optionsMovable.scrollIntoView?.(t)??!1}async select(t){if(!1===await(this._optionsMovable.select?.(t)))return!1;if(!1!==t?.autoFocus){const t=await this._getEmitter().notify("onRequestFocus",{async:!0});if(!t)return!1;for(let e=0;e<t.length;e++)if(!1===t[e])return!1}return!0}unselect(){const t=this._optionsMovable.isSelected?.()??!1;return this._optionsMovable.unselect?.(),t}_clone(){const t=this.isSelected(),e=this.getZIndex(),r=this._optionsMovable.getMaxBounds,n=this._options.maxRangeCoords,o=this.getContent(),s={beginPersistResource:this._optionsMovable.beginPersistResource,getBoundsAtCoords:this._optionsMovable.getBoundsAtCoords,getCoordsAtBounds:this._optionsMovable.getCoordsAtBounds,isSelected:()=>t,getZIndex:()=>e,getMaxBounds:r,maxRangeCoords:n,transactions:new re({transient:!0}),json:this.toJSON(),initialAnchor:this.getAnchorCoords(),content:o},i=new z_(s),a=this._getState();return i._updateState({...a}),i}getSnapshot(t,e){const r=this._optionsMovable.getCoordsAtBounds(t),n=this._getState().offsets;let o=this.getAnchorCoords();if((n.br.x>0||n.br.y>0)&&(o={...o},o.colEnd-=n.br.x>0?1:0,o.rowEnd-=n.br.y>0?1:0),!U.isRangeWithinRange(o,r))return null;const s=this,i=s._clone(),a=Object.freeze({...e});let l=!1;const c={async copyTo(t,e){const r={...a,...e};return await i._doCopy(t,r),r.isCut&&!l&&(s.delete(),l=!0),t.bounds},getCoords:()=>i.getBounds(),getSource:()=>i,getName:()=>i.getName(),getMarkOptions:()=>a,toText:()=>i._toText(),toHtml:()=>i._toHtml(),toImage:()=>i._toImage(),isISnapshot:!0};return c}async _doCopy(t,e){const r=this._optionsMovable.beginPersistResource(),n=this.toJSON(r.toResourceId.bind(r));n.content.json.name=`${this.getName()} (Copy)`;const o=n.content.json;delete n.content;const s=t.movables;if(!s)throw new Error("Movables is required");const i=t.bounds??this.getBounds();try{await s.add({...n,...e,fromResourceId:r.fromResourceId.bind(r),bounds:i,type:this.getContent().getType(),json:o,description:"Copy Movable"})}finally{r.endPersist()}}_toText(){return this.getContent().toText?.()}_toHtml(){return this.getContent().toHtml?.()}_toImage(){return this.getContent().toImage?.()}setName(t){return this._updateState({name:t},{description:"Set Movable Name"},["onNameChange"]),this}getName(){return this.isClosed()?null:this._getState()?.name}setDescription(t){return this._updateState({description:t},{description:"Set Movable Description"}),this}getDescription(){return this.isClosed()?null:this._getState()?.description}setHidden(t=!1){return this._updateState({hidden:t},{description:"Set Movable Visibility"}),this}isHidden(){return this._getState()?.hidden??!1}setLockAspectRatio(t){return this._updateState({lockAspectRatio:t},{description:"Set Lock Aspect Ratio"}),this}isLockAspectRatio(){return this._getState()?.lockAspectRatio??this._optionsMovable.defaultLockAspectRatio??!1}setRotation(t=0){return this._updateState({rotation:t},{description:"Set Movable Rotation"}),this}getRotation(){return this._getState()?.rotation??0}moveToBack(){return this._optionsMovable.moveToBackOnContainer?.(),this}moveBackward(){return this._optionsMovable.moveBackwardOnContainer?.(),this}moveToFront(){return this._optionsMovable.moveToFrontOnContainer?.(),this}moveForward(){return this._optionsMovable.moveForwardOnContainer?.(),this}getZIndex(){return this._optionsMovable.getZIndex?.()??0}setBounds(t,e){if(!t)return this;let r={...this.getBounds(),...t};if(this._optionsMovable.getMaxBounds){r={x:Math.max(r.x,this._optionsMovable.getMaxBounds().x),y:Math.max(r.y,this._optionsMovable.getMaxBounds().y),width:Math.min(r.width,this._optionsMovable.getMaxBounds().width),height:Math.min(r.height,this._optionsMovable.getMaxBounds().height)}}if(r.width<0||r.height<0)throw new Mt;const n=this._updateMovableLocation({bounds:r,anchorType:exports.IAnchored.Type.Absolute}),o=this._beginCommit(e?.description??"Set Movable Bounds");return this._updateState({offsets:n.offsets,anchor:n.anchor},{description:"Update Movable Bounds"}),this._options.setContainerCoords(n.anchor),this._invalidateBounds(),o.commit(),this}_updateMovableLocation(t){let e=t.offsets??{tl:{x:0,y:0},br:{x:0,y:0}},r=t.anchor??this.getAnchorCoords(),n=t.anchorType??this.getAnchorType();const o=t.bounds??this.getBounds();if(o){if(n===exports.IAnchored.Type.Absolute){r=this._optionsMovable.getCoordsAtBounds(o);const t=this._optionsMovable.getBoundsAtCoords(r);e={...e,tl:{x:o.x-t.x,y:o.y-t.y}}}if(n===exports.IAnchored.Type.Absolute||n===exports.IAnchored.Type.OneCell){const t=this._optionsMovable.getBoundsAtCoords({rowStart:r.rowStart,colStart:r.colStart,colEnd:r.colStart,rowEnd:r.rowStart}),n=this._optionsMovable.getCoordsAtBounds({x:t.x,y:t.y,width:o.width+Math.min(t.width,e.tl.x),height:o.height+Math.min(t.height,e.tl.y)});r={...r,colEnd:n.colEnd,rowEnd:n.rowEnd};const s=this._optionsMovable.getBoundsAtCoords({colStart:r.colEnd,rowStart:r.rowEnd,colEnd:r.colEnd,rowEnd:r.rowEnd}),i=o.width-(s.x-t.x-Math.min(e?.tl.x??0,t.width)),a=o.height-(s.y-t.y-Math.min(e?.tl.y??0,t.height));e={...e,br:{x:i,y:a}}}return e!==t.offsets&&(e.br.y<=0&&(e.br={...e.br,y:0},r.rowEnd--),e.br.x<=0&&(e.br={...e.br,x:0},r.colEnd--)),{anchor:r,offsets:e}}}_calcAbsoluteBounds(t,e={tl:{x:0,y:0},br:{x:0,y:0}}){if(!t)return null;const r=this._optionsMovable.getBoundsAtCoords({rowStart:t.rowStart,colStart:t.colStart,colEnd:t.colStart,rowEnd:t.rowStart});let n=e.br.x?0:1,o=e.br.y?0:1;const s=this._optionsMovable.getBoundsAtCoords({colStart:t.colEnd+n,rowStart:t.rowEnd+o,colEnd:t.colEnd+n,rowEnd:t.rowEnd+o}),i=Math.min(r.x+(e?.tl.x??0),r.x+r.width),a=Math.min(r.y+(e?.tl.y??0),r.y+r.height);return{x:i,y:a,width:Math.min(s.x+(e?.br.x??0),s.x+s.width)-i,height:Math.min(s.y+(e?.br.y??0),s.y+s.height)-a}}getBounds(){return this._getState()?.bounds}setAnchorType(t){return mt.validEnumValue(exports.IAnchored.Type,t),this._updateState({anchorType:t},{description:"Set Movable Resize Behavior"},["onAnchorTypeChange"]),this}_processContainerShift(t){const e=this.getAnchorType(),r=this._getState()?.offsets;let n=r,o=!1;const s=t.before,i=t.orientation===exports.t.Orientation.Column,a=t.intersect,l=t.amount;let c=t.after;if(e!==exports.IAnchored.Type.Absolute){let t=i?a.colStart:a.rowStart,r=i?s.colStart:s.rowStart;e===exports.IAnchored.Type.TwoCell&&(r=i?s.colEnd:s.rowEnd),o=t<=r}if(o&&(e!==exports.IAnchored.Type.OneCell||c)||(c=s),o&&c&&l<0&&(i?(a.colStart<=s.colStart&&a.colEnd>=s.colStart&&(n={...n,tl:{...n.tl,x:0}}),n.br.x>0&&a.colStart<=s.colEnd&&a.colEnd>=s.colEnd&&(n={...n,br:{...n.br,x:0}},c={...c,colEnd:c.colEnd+1})):(a.rowStart<=s.rowStart&&a.rowEnd>=s.rowStart&&(n={...n,tl:{...n.tl,y:0}}),n.br.y>0&&a.rowStart<=s.rowEnd&&a.rowEnd>=s.rowEnd&&(n={...n,br:{...n.br,y:0}},c={...c,rowEnd:c.rowEnd+1}))),null!==c){const{offsets:t,anchor:e}=this._updateMovableLocation({anchor:c,offsets:n});n=t,c=e}let h=null;const d=this._beginCommit("Shifting Movable Bounds");try{if(r!==n||!U.isEqualRanges(s,c)){const t={offsets:n,anchor:c};this._updateState(t)}this._invalidateBounds(),h=super._processContainerShift({...t,after:c}),d.commit()}catch(t){throw d.rollback(),t}return h}_invalidateBounds(){const t=this.getAnchorCoords();if(null===t)return null;const e=this._getState()?.offsets,r=this._calcAbsoluteBounds(t,e);this._updateState({bounds:r},null,["onBoundsChange"])}_processContainerDelete(){super._processContainerDelete(),this._getState().contentListenerRemove?.(),this.getContent().delete()}_processContainerLayout(){const t=this.getAnchorCoords(),e=this._getState()?.offsets,{offsets:r,anchor:n}=this._updateMovableLocation({anchor:t,offsets:e}),o=this._beginCommit("Updating Movable Bounds");try{if(e!==r||t!==n){const t={offsets:r,anchor:n};this._updateState(t)}this._invalidateBounds(),super._processContainerLayout(),o.commit()}catch(t){throw o.rollback(),t}}_processAnchorCoords(){super._processAnchorCoords()}_fromJSON(t){const e={tl:{x:0,y:0},br:{x:0,y:0}},r={...U.EmptyRange};t.anchor&&(e.tl.x=t.anchor.tl?.x??0,e.tl.y=t.anchor.tl?.y??0,e.br.x=t.anchor.br?.x??0,e.br.y=t.anchor.br?.y??0,r.colStart=t.anchor.tl?.c??0,r.rowStart=t.anchor.tl?.r??0,r.colEnd=Math.max(r.colStart,(t.anchor.br?.c??0)+(e.br.x>0?0:-1)),r.rowEnd=Math.max(r.rowStart,(t.anchor.br?.r??0)+(e.br.y>0?0:-1)));const n=this._beginCommit("Load Movable"),o=t.content.json,s={offsets:e,name:o.name??null,description:o.name??null,hidden:o.hidden??!1,rotation:o.rotation??0,lockAspectRatio:o.lockAspect??null};t.anchorType&&(s.anchorType=t.anchorType),s.name||(s.name=`${this._content.getTypeDescription()} ${++z_.instanceCounter}`),s.bounds=this._calcAbsoluteBounds(r,e),this._updateState(s,{description:"Load Movable"}),this._optionsMovable.setContainerCoords?.(r),n.commit()}toJSON(t){const e=this._getState(),r=e.anchor,n=e.offsets,o={tl:{c:r.colStart,r:r.rowStart},br:{c:r.colEnd+(n.br.x?0:1),r:r.rowEnd+(n.br.y?0:1)}};n&&(n.tl?.x&&(o.tl.x=mt.roundAccurately(n.tl.x,1)),n.tl?.y&&(o.tl.y=mt.roundAccurately(n.tl.y,1)),n.br?.x&&(o.br.x=mt.roundAccurately(n.br.x,1)),n.br?.y&&(o.br.y=mt.roundAccurately(n.br.y,1)));const s=this._content.toJSON(t)??{},i={anchor:o,content:{type:this._content.getType(),json:s}},a=e.anchorType;return a&&a!==exports.IAnchored.Type.TwoCell&&(i.anchorType=this.getAnchorType()),e.hidden&&(i.hidden=e.hidden),e.name&&(i.name=e.name),e.description&&(i.name=e.description),void 0!==e.rotation&&0!==e.rotation&&(i.rotation=e.rotation),mt.isDefined(e.lockAspectRatio)&&e.lockAspectRatio!==this._optionsMovable.defaultLockAspectRatio&&(i.lockAspect=e.lockAspectRatio),i}get isIMovable(){return!0}}class P_{constructor(t,e,r,n,o,s){this._add=t,this._search=e,this._getCount=r,this._updateSelected=n,this._addListeners=o,this._addImage=s}async add(t){return this._add(t)}search(t){return this._search(t)}getCount(){return this._getCount()}updateSelected(t,e){return this._updateSelected(t,e)}addListeners(t,e){return this._addListeners(t,e)}addImage(t,e){return this._addImage(t,e)}}const j_={transactional:!0,ignoreDataChanges:!0};class H_ extends _l{constructor(t){super({...t,type:"namedReference"});const e=this;this._listener=t=>{const r=this._getState().ranges;let n=t.getSource(),o=!1;const s={ranges:n};if("moveCells"===t.trigger){const n=e._getState(),i=t.getTo(),a=t.getFrom(),l=[];for(let t=0;t<r.getCount();t++){const e=r.at(t);if(l.push(e.getCoords()),!e.isInvalid()){for(let r=0;r<a.getCount();r++){const n=a.at(r).getCoords(),s=e.getCoords();if(!U.isRangeWithinRange(s,n))continue;const c=i.getCoords(),h=c.colStart-n.colStart+s.colStart,d=c.rowStart-n.rowStart+s.rowStart,u={...s,colStart:h,rowStart:d,colEnd:h+(s.colEnd-s.colStart),rowEnd:d+(s.rowEnd-s.rowStart)};(1!==i.size||U.isRangeWithinRange(u,c))&&(l[t]=i.getSource().getRange(u).getCoords(),o=!0)}if(!o)return}}const c=this._options.addressToRanges(l);let h;n.removeListener?.(),c.isInvalid()||(h=c.addListener(e._listener,j_)),s.ranges=c,s.removeListener=h}this._updateState(s,null,["onRangesChange"]);const i=n.getCoords();let a=!i||0===i.length;for(let t=0;!a&&t<i.length;t++)if(!i[t]){a=!0;break}a&&e.delete()};const r=t.value;if(r&&!r.isInvalid()){const t=r.addListener(this._listener,j_);this._updateState({ranges:r,removeListener:t},null)}}setReference(t){const e=this._options.addressToRanges(t);if(e&&!e.isInvalid()){const t=this._getState();t.removeListener?.();const r=e.addListener(this._listener,j_);this._updateState({ranges:e,removeListener:r},null)}return null}async select(t){return await this._getState().ranges.select(t),this}getRanges(){return this._getState().ranges}setHidden(t=!1,e){return this._updateState({hidden:t},{description:"Set Hidden",...e},[]),this}setScope(t,e){return this._updateState({scope:t},{description:"Set Scope",...e},[]),this}getType(){return"reference"}getValue(){return this._getState().ranges}toJSON(){const t=super._toJSON();return t.ref=this._getState().ranges.toString(),t}_getDescription(){return`Named '${this.getName()}'`}_processDelete(){const t=this._getState();t&&t.removeListener?.(),super._processDelete()}}const V_="Item must be specified.",$_="Name must be a non-empty string",U_=(t,e=null)=>`Named item '${t}' already exists${e?`in scope ${e}`:""}.`,G_=t=>{const e=[];for(let r=0;r<t.getCount();r++){let n=null;try{n=t.at(r),n.isICellRange&&(n=n.getFixed(!0))}catch(t){console.warn("Invalid range",t)}e.push(n?n.toString().toLowerCase():Gh)}return e.sort(),e.join(",")},W_=/^[^a-zA-Z_\\]+$/,q_=/^[^a-zA-Z0-9_.]+$/;class J_{constructor(t){this._emitter=null,this._closed=!1,this._lastLookup=mt.EmptyArray,this._lastLookupAddress=null,this._lastLookupScope=null,this._lastLookupType=null,this._allowExtrudes=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new re({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,r,n){r?.initial||e._emitter.notify("onCollectionChange")}}),this._emitter=new ml(this,this._transactions),this._initState(),this._fromJSON(this._options?.json)}search(t){if(this.isClosed())return mt.EmptyArray;const e=this._getState();if(!e)return mt.EmptyArray;const r=e.itemsSpatial;if(r.isEmpty())return mt.EmptyArray;if(t&&t.address===this._lastLookupAddress&&t.scope===this._lastLookupScope&&t.type===this._lastLookupType&&t.allowExtrudes===this._allowExtrudes)return this._lastLookup;this._lastLookupAddress=t?.address??void 0,this._lastLookupScope=t?.scope??void 0,this._lastLookupType=t?.type??void 0,this._allowExtrudes=t?.allowExtrudes??void 0;let n=null;if(t?.address){const e=this._options.addressToRanges(t?.address);if(!e)return console.warn("invalid address",t?.address),this._lastLookup=null,null;n=e.getCoords()}let o=null;if(n){o=[];for(let t=0;t<n.length;t++){const e=r.search(n[t]);for(let t=0;t<e.length;t++)o.push(e[t])}}else o=r.all();if(!o||0===o.length)return this._lastLookup=mt.EmptyArray,mt.EmptyArray;const s=new Set,i=new Set;o.forEach(e=>{const r=e.value;if(!t?.type||r.getType()===t.type){if(n&&!t?.allowExtrudes){const t=r.getRanges?.();if(!t||0===t.getCount())return;for(let t=0;t<n.length;t++)if(!U.isRangeWithinRange(e,n[t]))return}!t?.scope||r.getScope()!==t.scope&&"all"!==t.scope?r.getScope()||i.add(r):s.add(r)}});const a=new Map;i.forEach(t=>{a.set(t.getName(),t)}),s.forEach(t=>{a.set(t.getName(),t)});let l=[];return a.forEach(t=>{l.push(t)}),l=l.sort((t,e)=>{let r=t.getType().localeCompare(e.getType());return 0!==r?r:t.getName().localeCompare(e.getName())}),this._lastLookup=l,l}lookupByRanges(t){const e=this._options.addressToRanges(t);if(!e||0===e.getCount())return null;const r=this._getState();if(!r)return null;if(0===r.itemsByKey.size)return null;const n=G_(e),o=r.itemsByFullRange.get(n);if(!o)return null;const s=[];return o.forEach(t=>{const e=r.itemsByKey.get(t);e&&s.push(e.item)}),s.length>0?s:null}getByName(t,e=!1){if(!t)return null;const r=this._getState();if(!r)return null;if(0===r.itemsByKey.size)return null;if("string"!=typeof t)return null;const n=t.toLowerCase(),o=this._options.getCurrentScope();if(!e&&o){const t=n+":"+o.toLowerCase(),e=r.itemsByKey.get(t);if(e)return e.item}const s=r.itemsByKey.get(n);return s?.item??null}getCount(){const t=this._getState();return t?t.itemsByKey.size:0}getRanges(t){const e=this._options.addressToRanges(t),r=[];for(let t=0;t<e.getCount();t++){const n=e.at(t).getFixed(!0).getCoords();r.push(n)}return this._options.addressToRanges(r)}findValidName(t,e=null,r=!1){if(!t)throw new Error("A template string must be specified.");const n=this,o=t=>{try{return n._validateName(t,e,r),!0}catch(t){}return!1};return o(t)?t:Ns(t,o)}validateName(t,e=null,r=!1){return this._validateName(t,e,r)}_validateName(t,e,r=!1){if(this._closed)throw new Error(gl);if(!t||0===t.length)throw new Error($_);if(t.length>255)throw new Error("Name must not exceed 255 characters.");if(-1!==t.indexOf(" "))throw new Error("Name must not contain any spaces.");const n=t.trim().toLowerCase(),o=n.substring(1,t.length-1);if(new RegExp(W_).test(n[0]))throw new Error("First letter must be either a letter, an underscore, or a backslash.");if(new RegExp(q_).test(o))throw new Error("Name must be either letters, numbers, periods or underscores.");if(1===n.length&&("r"===n[0]||"c"===n[0]))throw new Error("Name can not be 'r' or 'c'.");if(((t,e=qh,r=Wh,n=!1)=>{let o=xd(t,n);if(!o)return!1;if(o[2])return!1;if(!o[1])return!1;const s=Sd(t,Cd);if(!s)return!1;const i=s.rowIndex;if(i<0||i>e)return!1;const a=s.colIndex;return!(a<0||a>=r)})(t))throw new Error("Name can not be an address.");let s=t.toLowerCase()?.trim();e&&(s=s+":"+e.toLowerCase());const i=this._getState()?.itemsByKey.get(s);if(i){const n=i.item.getRanges();if(!r||n||n.getCount()>0)throw new Error(U_(t,e))}}addReference(t,e,r=!1){const n=this._options.addressToRanges(e),o=this.getByName(t);let s=null;const i=this._beginCommit(`${o&&r?"Update":"Insert"} Named '${t}'`);try{if(o){if(!r)throw new Error(U_(t));this._delete(o,{description:`Delete Named '${o.getName()}'`})}s=new H_({value:n,addressToRanges:this._options.addressToRanges,json:{name:t,ref:n.toString()},transactions:this._transactions}),this.add(s),i.commit()}catch(t){throw i.rollback(),t}return s}add(t){if(this._closed)throw new Error(gl);if(!t)throw new Error(V_);if(!t.getName||"string"==typeof t)throw new Error("Add must take a 'INamed' object. To add a string use 'addReference'.");if(this._validateName(t.getName(),t.getScope(),!1),this._options.isReadOnly?.())throw new Error("Names are read-only.");const e=this._beginCommit(`Insert Named Item '${t.getName()}'`),r=this._add([t]);if(null===r)return e.rollback(),null;const n=r.itemsByKey.get(t.getName().toLowerCase());return this._updateState(t=>({...t,...r})),e.commit(),n?.item??null}_toKey(t){let e=t.getName().toLowerCase();return e.startsWith("_xlnm.")&&(e=e.substring(6)),t.getScope()?e+":"+t.getScope().toLowerCase():e}_delete(t,e){if(!t)throw new Error(V_);if(this._closed)throw new Error(gl);const r=this._beginCommit(e?.description??`Delete Named Item '${t.getName()}'`);let n=null;try{const e=this._getState()?.itemsByKey,o=this._toKey(t);if(n=e.get(o),!n)throw new Error(`Item '${t.getName()}' does not exist.`);const s=this._cloneState();this._index(o,null,s),this._updateState(t=>({...t,...s})),r.commit()}catch(t){throw r.rollback(),t}return this._emitter.notify("onCollectionChange"),n.item}_cloneState(){const t=this._getState();return{itemsBySource:new Map(t.itemsBySource),itemsByKey:new Map(t.itemsByKey),itemsSpatial:t.itemsSpatial.clone(),itemsByFullRange:new Map(t.itemsByFullRange),itemsByPartialRange:new Map(t.itemsByPartialRange)}}_index(t,e,r){const n=r.itemsByKey.get(t);if(n){const e=n.asPartialRanges;if(e)for(let n=0;n<e.length;n++){const o=r.itemsByPartialRange.get(e[n]);if(o)if(1===o.size)r.itemsByPartialRange.delete(e[n]);else{const s=new Set(o);s.delete(t),r.itemsByPartialRange.set(e[n],s)}}const o=n.asFullRange;if(o){const e=r.itemsByFullRange.get(o);if(e)if(1===e.size)r.itemsByFullRange.delete(o);else{const n=new Set(e);n.delete(t),r.itemsByFullRange.set(o,n)}}if(n.nodes)for(let t=0;t<n.nodes.length;t++)r.itemsSpatial.remove(n.nodes[t]);n.unwatch?.(),r.itemsByKey.delete(t),r.itemsBySource.delete(n.item)}let o=null;if(e){let t=[],n=null,s=null;o=e.getRanges?.();const i=this._toKey(e);if(o){const{asFullRange:a,asPartialRanges:l,asRanges:c}=(t=>{const e=t.getCoords(),r=G_(t),n=r.split(",");return{asFullRange:r,asPartialRanges:n,asRanges:e}})(o);if(n=a,s=l,c){for(let n=0;n<l.length;n++){let o=r.itemsByPartialRange.get(l[n]);const s=o?new Set(o):new Set;s.add(i),r.itemsByPartialRange.set(l[n],s),t.push({...c[n],value:e})}if(r.itemsSpatial.load(t),a){let t=r.itemsByFullRange.get(a);const e=t?new Set(t):new Set;e.add(i),r.itemsByFullRange.set(a,e)}}}const a=this,l=e.addListeners({onDelete:t=>{a._delete(t)},onAnyChange:t=>{const e=a._beginCommit(`Update Named '${t.getName()}'`);try{const r=a._cloneState(),n=r.itemsBySource.get(t).globalKey;a._index(n,t,r),a._updateState(t=>({...t,...r})),e.commit()}catch(t){throw e.rollback(),t}}},{transactional:!0}),c={item:e,asFullRange:n,asPartialRanges:s,unwatch:l,nodes:t,globalKey:i};r.itemsByKey.set(i,c),r.itemsBySource.set(e,c)}}_add(t){if(this._closed)throw new Error(gl);const e=this._getState();if(!t)return e;const r=this._cloneState();for(let e=0;e<t.length;e++){const n=t[e];if(!n.getName())throw new Error($_);const o=this._toKey(n);try{this._index(o,n,r)}catch(t){console.warn(`Unable to add named item '${o}'.`,t)}}return r}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(gl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update"){if(!t)return;this._lastLookup=mt.EmptyArray,this._lastLookupAddress=null,this._lastLookupType=null,this._lastLookupScope=null;const r=this._beginCommit(e);try{r.updateState(this,t),r.commit()}catch(t){throw r.rollback(),t}}fromJSON(t){if(this._closed)throw new Error(gl);this._fromJSON(t)}_initState(){this._updateState(t=>({...t,items:new Set,itemsByKey:new Map,itemsSpatial:new gc,itemsByFullRange:new Map,itemsByPartialRange:new Map}))}_fromJSON(t){const e=this._beginCommit("Load Names");try{if(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];try{const t=this._options.addressToRanges(n.ref),r=new H_({value:t,addressToRanges:this._options.addressToRanges,deleteFromContainer:t=>{this._delete(r,t)},json:n,transactions:this._transactions});e.push(r)}catch(t){console.warn("Unable to load named item.",n,t.message)}}const r=this._add(e);this._updateState(t=>({...t,...r}))}e.commit({viewAfter:{initial:!0}})}catch(t){throw e.rollback(),t}}toJSON(){const t=this._getState();if(!t||0===t.itemsByKey.size)return null;const e=[],r=Array.from(t.itemsByKey.keys()).sort();for(let n=0;n<r.length;n++){const o=t.itemsByKey.get(r[n]).item,s=o.toJSON?.();s&&e.push(s)}return 0===e.length?null:e}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isNamedCollection(){return!0}}class X_ extends fl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"chart"}getDescription(){const t=this._getState()?.data;return`Chart: ${t?.types?.[0]?.type??"unknown"}`}toJSON(t){const e=this._getState();let r=null;return e&&e.data&&(r=e.data),r}getTypeDescription(){return"Chart"}}class K_ extends fl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"shape"}getDescription(){const t=this._getState()?.data;return`Shape: ${t}`}toJSON(t){const e=this._getState();let r=null;return e&&e.data&&(r=e.data),r}getTypeDescription(){return"Shape"}}class Y_ extends fl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"custom"}getDescription(){const t=this._getState()?.data;return`CustomElement: ${t}`}toJSON(t){const e=this._getState();let r=null;return e&&e.data&&(r=e.data),r}getTypeDescription(){return"CustomElement"}}const Z_=(t,e,r=!0,n=!0)=>{let o=0,s=0;if(!r&&!n)return{x:o,y:s};let i=!1,a=0;do{const a={x:e.x+o,y:e.y+s,width:0,height:0},l=t.search({bounds:a});if(i=!1,l.length>0){for(let t=0;!i&&t<l.length;t++){const e=l[t].getBounds();e.x===a.x&&e.y===a.y&&(i=!0)}i&&(o+=r?16:0,s+=n?16:0)}}while(i&&++a<100);return{x:o,y:s}};class Q_{constructor(t,e,r){this._add=t,this._get=e,this._getByName=r}add(t,e){if(!t)throw new Error(Um);return this._add(t,e)}search(t){if(t&&t.name&&0===Object.keys(t).length)return[this._getByName(t.name)];let e;t?.address&&(e=t.address);const r=this._get(e,t?.excludeHidden,t?.fullyContained);if(t?.name){const e=t.name.toLocaleLowerCase();for(let t=0;t<r.length;t++)if(r[t].getName().toLocaleLowerCase()===e)return[r[t]]}return r}getByName(t){if("string"!=typeof t)throw new Error("Get by name must take a valid name.");return this._getByName(t)}getCount(){return this._get(null,!1,!1).length}}const tS=(t,e,r)=>{if(!t)return e;let n=e;const o=r===exports.t.Direction.Right||r===exports.t.Direction.Down;for(;;){const e=t(n,!o);if(0===e)return n;o?n+=e:n-=e}},eS=Object.freeze({colIndex:0,rowIndex:0}),rS=Object.freeze([]),nS=Object.freeze({cell:U.EmptyCell,ranges:rS,rangeIndex:-1}),oS=(t,e=exports.t.Direction.Right,r,n,o,s=null)=>{if(s&&U.isEqualSelectionCoords(s,t))return t;const i=t.ranges[t.rangeIndex];if(!U.isRangesIntersect({rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},i))return t;let a={...t.cell},l=t.rangeIndex;switch(e){case exports.t.Direction.Right:a.colIndex=tS(o,a.colIndex+1,e);break;case exports.t.Direction.Left:a.colIndex=tS(o,a.colIndex-1,e);break;case exports.t.Direction.Down:a.rowIndex=tS(n,a.rowIndex+1,e);break;case exports.t.Direction.Up:a.rowIndex=tS(n,a.rowIndex-1,e)}const c=e=>{if(e){l=t.rangeIndex>=t.ranges.length-1?0:t.rangeIndex+1;const e=t.ranges[l];a={colIndex:e.colStart,rowIndex:e.rowStart}}else{l=t.rangeIndex<=0?t.ranges.length-1:t.rangeIndex-1;const e=t.ranges[l];a={colIndex:e.colEnd,rowIndex:e.rowEnd}}};if(e===exports.t.Direction.Right&&a.colIndex>i.colEnd&&a.rowIndex===i.rowEnd)c(!0);else if(e===exports.t.Direction.Left&&a.colIndex<i.colStart&&a.rowIndex===i.rowStart)c(!1);else if(e===exports.t.Direction.Down&&a.colIndex===i.colEnd&&a.rowIndex>i.rowEnd)c(!0);else if(e===exports.t.Direction.Up&&a.colIndex===i.colStart&&a.rowIndex<i.rowStart)c(!1);else{let t=a.rowIndex,r=a.colIndex;switch(e){case exports.t.Direction.Right:r>i.colEnd&&(t=tS(n,t+1,e),r=i.colStart,t>i.rowEnd&&(t=i.rowStart));break;case exports.t.Direction.Left:r<i.colStart&&(t=tS(n,t-1,e),r=i.colEnd,t<i.rowStart&&(t=i.rowEnd));break;case exports.t.Direction.Down:t>i.rowEnd&&(r=tS(o,r+1,e),t=i.rowStart,r>i.colEnd&&(r=i.colStart));break;case exports.t.Direction.Up:t<i.rowStart&&(r=tS(o,r-1,e),t=i.rowEnd,r<i.colStart&&(r=i.colEnd))}a={rowIndex:t,colIndex:r}}let h=r(a);if(!U.isRangeWithinRange(h,i)){const t=U.intersectRanges(h,i);t&&(h=t)}let d={rowStart:tS(n,h.rowStart,exports.t.Direction.Down),colStart:tS(o,h.colStart,exports.t.Direction.Right),rowEnd:tS(n,h.rowEnd,exports.t.Direction.Up),colEnd:tS(o,h.colEnd,exports.t.Direction.Left)};if(d.rowStart!==a.rowIndex||d.colStart!==a.colIndex){switch(e){case exports.t.Direction.Right:t.ranges[l].colStart===d.colStart&&t.ranges[l].colEnd===d.colEnd&&(a.rowIndex=d.rowEnd),a.colIndex=d.colEnd;break;case exports.t.Direction.Left:t.ranges[l].colStart===d.colStart&&t.ranges[l].colEnd===d.colEnd&&(a.rowIndex=d.rowStart),a.rowIndex===d.rowStart?a.colIndex=d.colStart+1:a.colIndex=d.colStart;break;case exports.t.Direction.Down:t.ranges[l].rowStart===d.rowStart&&t.ranges[l].rowEnd===d.rowEnd&&(a.colIndex=d.colEnd),a.rowIndex=d.rowEnd;break;case exports.t.Direction.Up:t.ranges[l].rowStart===d.rowStart&&t.ranges[l].rowEnd===d.rowEnd&&(a.colIndex=d.colStart),a.colIndex===d.colStart?a.rowIndex=d.rowStart+1:a.rowIndex=d.rowStart}return s&&console.warn("call recursive > 1"),oS({cell:a,ranges:t.ranges,rangeIndex:l},e,r,n,o,s??t)}return{ranges:t.ranges,cell:a,rangeIndex:l}};class sS{constructor(t){this._adjusting=null,this._emitter=null,this._coords=nS,this._sheet=t.sheet,this._emitter=new ml(this);const e=t.sheet;this._adjusting=null,this._hiddenRowsAt=(t,r)=>e.getRowHeaders().hiddenHeadersAt(t,r),this._hiddenColumnsAt=(t,r)=>e.getColumnHeaders().hiddenHeadersAt(t,r),this._getCellCoordsAsRangeCoords=t=>{const r=U.cellToRange(t);if(e.isClosed())return r;const n=e.getRange(r,{excludeHidden:!0}).getMerges();return 0===n.length?r:n[0]},this._canSelectionSpanMergedCells=t=>{const r=e.getRange(t);return r.isEntireColumns()||r.isEntireRows()},this._getMergedRanges=t=>e.getRange(t,{excludeHidden:!0}).getMerges(),this._isContentfulCell=()=>!1,this._contentfulCellFinder=(t,r,n,o,s,i)=>{const a=e.getSelectedRange().getExtended(o,t).getCoords();switch(o){case exports.t.Direction.Up:return a.rowStart;case exports.t.Direction.Down:return a.rowEnd;case exports.t.Direction.Left:return a.colStart;case exports.t.Direction.Right:return a.colEnd}},this._scrollCellCoordsIntoView=(t,r)=>e.scrollTo(t,r?{scroll:r}:void 0),this._selectionPolicy=t.selectionPolicy??"multiple",this._newSelectionMode=t.newSelectionMode??"clear"}navigate(t,e=!1,r=!1,n=0){const o=this._coords;if(!o.cell)return this;let s=o.cell,i=o.cell;if(e&&o.ranges.length>0){const e=o.ranges[o.rangeIndex],r=o.cell;switch(t){case exports.t.Direction.Up:i={rowIndex:r.rowIndex===e.rowStart?e.rowEnd:e.rowStart,colIndex:e.colEnd},s={rowIndex:r.rowIndex===e.rowStart?e.rowStart:e.rowEnd,colIndex:e.colStart};break;case exports.t.Direction.Down:i={rowIndex:r.rowIndex===e.rowEnd?e.rowStart:e.rowEnd,colIndex:e.colEnd},s={rowIndex:r.rowIndex===e.rowEnd?e.rowEnd:e.rowStart,colIndex:e.colStart};break;case exports.t.Direction.Left:i={rowIndex:e.rowEnd,colIndex:r.colIndex===e.colStart?e.colEnd:e.colStart},s={rowIndex:e.rowStart,colIndex:r.colIndex===e.colStart?e.colStart:e.colEnd};break;case exports.t.Direction.Right:i={rowIndex:e.rowEnd,colIndex:r.colIndex===e.colEnd?e.colStart:e.colEnd},s={rowIndex:e.rowStart,colIndex:r.colIndex===e.colEnd?e.colEnd:e.colStart}}}const a=this._getCellCoordsAsRangeCoords(i);let{rowStart:l,colStart:c}=a;const h=this._magicCell;if(h)switch(t){case exports.t.Direction.Up:case exports.t.Direction.Down:h.colIndex>=a.colStart&&h.colIndex<=a.colEnd&&(c=h.colIndex);break;case exports.t.Direction.Left:case exports.t.Direction.Right:h.rowIndex>=a.rowStart&&h.rowIndex<=a.rowEnd&&(l=h.rowIndex)}if(!n){const e=this._getMaxRange();switch(t){case exports.t.Direction.Up:l=tS(this._hiddenRowsAt,Math.max(a.rowStart-1,e.rowStart??0),t);break;case exports.t.Direction.Down:l=tS(this._hiddenRowsAt,Math.min(a.rowEnd+1,e.rowEnd??Number.MAX_SAFE_INTEGER),t);break;case exports.t.Direction.Left:c=tS(this._hiddenColumnsAt,Math.max(a.colStart-1,e.colStart??0),t);break;case exports.t.Direction.Right:c=tS(this._hiddenColumnsAt,Math.min(a.colEnd+1,e.colEnd??Number.MAX_SAFE_INTEGER),t)}if(r){const e=this._getMaxRange();let r=0;switch(t){case exports.t.Direction.Up:r=e.rowStart??0,l=this._contentfulCellFinder({...i,colIndex:this._coords.cell.colIndex},this._isContentfulCell,this._hiddenRowsAt,t,!1,Math.max(r,this._hiddenRowsAt(r,!1)));break;case exports.t.Direction.Down:r=e.rowEnd??Number.MAX_SAFE_INTEGER,l=this._contentfulCellFinder({...i,colIndex:this._coords.cell.colIndex},this._isContentfulCell,this._hiddenRowsAt,t,!1,Math.min(r,r-this._hiddenRowsAt(r,!0)));break;case exports.t.Direction.Left:r=e.colStart??0,c=this._contentfulCellFinder({...i,rowIndex:this._coords.cell.rowIndex},this._isContentfulCell,this._hiddenColumnsAt,t,!1,Math.max(r,this._hiddenColumnsAt(r,!1)));break;case exports.t.Direction.Right:r=e.colEnd??Number.MAX_SAFE_INTEGER,c=this._contentfulCellFinder({...i,rowIndex:this._coords.cell.rowIndex},this._isContentfulCell,this._hiddenColumnsAt,t,!1,Math.min(r,r-this._hiddenColumnsAt(r,!0)))}}}let d=null;n&&(d={});const u={rowIndex:l,colIndex:c},g=this._getCellCoordsAsRangeCoords(u),p={rowIndex:g.rowStart,colIndex:g.colStart};e||(this._magicCell=u);const m=this._firstActiveCoords,f=U.isEqualCells(m,p)&&U.isEqualCells(m,s);if(e&&!f?this.modify(p,s):this.clearAndModify(p),d)this._scrollCellCoordsIntoView(d);else{if(e&&m){const e=this._getMaxRange();if(t===exports.t.Direction.Right&&m.colIndex===e.colEnd||t===exports.t.Direction.Left&&m.colIndex===e.colStart||t===exports.t.Direction.Up&&m.rowIndex===e.rowEnd||t===exports.t.Direction.Down&&m.rowIndex===e.rowStart)return this}t===exports.t.Direction.Left||t===exports.t.Direction.Right?this._scrollCellCoordsIntoView({colStart:u.colIndex}):t!==exports.t.Direction.Up&&t!==exports.t.Direction.Down||this._scrollCellCoordsIntoView({rowStart:u.rowIndex})}return this}getCoords(){return this._coords}updateCoords(t){const e=this._coords;if(U.isEqualSelectionCoords(e,t))return;const r=((t,e,r)=>{if(!t)return nS;let n=e.cell;U.isEqualCells(n,t?.cell)||(n=Object.freeze({colIndex:Math.max(0,Math.min(t?.cell?.colIndex??e.cell?.colIndex??0)),rowIndex:Math.max(0,Math.min(t?.cell?.rowIndex??e?.cell?.rowIndex??0))}));const o=t?.ranges?[...t.ranges]:[];let s=!1;const i=o.length;let a=0===i;for(let t=0;t<i;t++){const e=o[t];o[t]=Object.freeze({colStart:Math.max(r.colStart,Math.min(e.colStart,r.colEnd)),colEnd:Math.max(r.colStart,Math.min(e.colEnd,r.colEnd)),rowStart:Math.max(r.rowStart,Math.min(e.rowStart,r.rowEnd)),rowEnd:Math.max(r.rowStart,Math.min(e.rowEnd,r.rowEnd))}),a=a||U.isCellWithinRange(n,e),s=s||Object.keys(e).length>4}let l=e?.ranges??[];!s&&U.isEqualRangesArrays(l,o)||(l=o);let c=t?.rangeIndex??e?.rangeIndex??nS.rangeIndex;if(c=Math.max(-1,Math.min(c,l.length-1)),!a){const t=l[c];let e=n.rowIndex;e<t.rowStart?e=t.rowStart:e>t.rowEnd&&(e=t.rowEnd);let r=n.rowIndex;r<t.colStart?r=t.colStart:r>t.colEnd&&(r=t.colEnd),n=Object.freeze({colIndex:r,rowIndex:e})}const h={cell:n,ranges:l,rangeIndex:c};return Object.freeze(h)})(t,this._coords,this._getMaxRange());this._coords=r;return!U.isEqualCells(r.cell,e.cell)&&this._scrollCellCoordsIntoView({colStart:r.cell.colIndex,rowStart:r.cell.rowIndex}),this._emitter.notify("onChange"),this}isEntire(){const t=this._coords;if(0===t.ranges.length)return!1;const e=this._getMaxRange();for(let r=0;r<t.ranges.length;r++){const n=t.ranges[r];if(!U.isRangeWithinRange(e,n))return!1}return!0}traverse(t=exports.t.Orientation.Row,e=!1){let r=exports.t.Direction.Right;r=t===exports.t.Orientation.Row?e?exports.t.Direction.Left:exports.t.Direction.Right:e?exports.t.Direction.Up:exports.t.Direction.Down;const n=this._coords;if(0===n.ranges.length)return this.navigate(r);const o=this._getCellCoordsAsRangeCoords(n.cell);if(U.isEqualRangesArrays([o],n.ranges))return this.navigate(r);const s=oS(n,r,this._getCellCoordsAsRangeCoords.bind(this),this._hiddenRowsAt.bind(this),this._hiddenColumnsAt.bind(this));this.updateCoords(s)}clear(){this._setSelectionRanges(rS)}modify(t,e,r){if("single"===this._selectionPolicy)return;const n=this._coords,o=this._rangesFromCellOptional(n,t,e??n.cell);if(!o)return;const s=n.rangeIndex;this._setSelectionRanges(t=>t.length?t.map((t,e)=>s===e?o:t):[o]),r&&o&&this._setSelectionCell({colIndex:o.colStart,rowIndex:o.rowStart})}append(t,e=t,r){if("multiple"!==this._selectionPolicy||!t||this._isCellOutOfBounds(t)||this._isCellOutOfBounds(e))return;const n=this._coords,o=this._cellToRangeActual(t,e);if(!o)return;const s=n.ranges.length>0?[...n.ranges]:[this._cellToRangeActual(n.cell,n.cell)];s.push(o);const i={ranges:s,cell:{rowIndex:o.rowStart,colIndex:o.colStart,...r},rangeIndex:s.length-1};U.isEqualSelectionCoords(i,n)||this.updateCoords(i)}clearAndModify(t,e,r){const n=this._coords;t={...n.cell,...t},e=e??t;const o=this._rangesFromCellOptional(n,t,e);if(!o)return;const s={rowIndex:o.rowStart,colIndex:o.colStart},i={...s,...r},a=this._newSelectionMode;"clear"===a?(this._firstActiveCoords=i,this.clear()):"modify"===a?this.modify(s):this.append(s),this._setSelectionCell(i)}setAdjusting(t){this._adjusting=t,this._emitter.notify("onAdjustingChange")}getAdjusting(){return this._adjusting}addListeners(t,e){return this._emitter.addListeners(t,e)}_setSelectionRanges(t){const e=this._coords;let r="function"==typeof t?t(e.ranges):t??rS;if(U.isEqualRangesArrays(r,e.ranges))return;let n=Math.max(r.length?0:-1,Math.min(e.rangeIndex,r.length-1)),o=e.cell;-1===n||U.isCellWithinRange(o,r[n])||(o={rowIndex:r[n].rowStart,colIndex:r[n].colStart}),1===r.length&&U.isSingleCell(r[0])&&U.isCellWithinRange(o,r[0])&&(r=[],n=-1);const s={cell:o,ranges:r,rangeIndex:n};U.isEqualSelectionCoords(s,e)||this.updateCoords(s)}_setSelectionCell(t){const e=this._coords,r=t??eS,n=this._getCellCoordsAsRangeCoords(r);if(!U.isSingleCell(n)&&0===e.ranges.length)return this.updateCoords({ranges:[n],rangeIndex:0,cell:r});if(U.isEqualCells(r,e.cell))return;let o=e.ranges,s=e.rangeIndex;1===e.ranges.length&&(U.isSingleCell(e.ranges[0])&&U.isCellWithinRange(r,e.ranges[0])||!U.isCellWithinRange(r,e.ranges[0]))&&(o=[],s=-1);const i={ranges:o,rangeIndex:s,cell:r};return U.isEqualSelectionCoords(i,e)?void 0:this.updateCoords(i)}_isCellOutOfBounds(t){const e=this._getMaxRange();return t.rowIndex<e.rowStart||t.colIndex<e.colStart||t.colIndex>e.colEnd||t.rowIndex>e.rowEnd}_cellToRangeActual(t,e){const r={rowStart:Math.min(t.rowIndex,e.rowIndex),colStart:Math.min(t.colIndex,e.colIndex),rowEnd:Math.max(t.rowIndex,e.rowIndex),colEnd:Math.max(t.colIndex,e.colIndex)};if(this._canSelectionSpanMergedCells(r))return r;const n=this._getCellCoordsAsRangeCoords(t),o=this._getCellCoordsAsRangeCoords(e),s={rowStart:Math.min(n.rowStart,o.rowStart),colStart:Math.min(n.colStart,o.colStart),rowEnd:Math.max(n.rowEnd,o.rowEnd),colEnd:Math.max(n.colEnd,o.colEnd)},i=this._getMergedRanges(s);return U.extendRangeToUnionRanges(s,i)}_rangesFromCellOptional(t,e,r){const n=t.ranges.length>0?t.ranges[t.rangeIndex]:{rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},o={rowStart:Math.min(e.rowIndex??n.rowStart,r.rowIndex??n.rowStart),colStart:Math.min(e.colIndex??n.colStart,r.colIndex??n.colStart),rowEnd:Math.max(e.rowIndex??n.rowEnd,r.rowIndex??n.rowEnd),colEnd:Math.max(e.colIndex??n.colEnd,r.colIndex??n.colEnd)},s={rowIndex:o.rowStart,colIndex:o.colStart},i={rowIndex:o.rowEnd,colIndex:o.colEnd};if(this._isCellOutOfBounds(s)||this._isCellOutOfBounds(i))return;return this._cellToRangeActual(s,i)}_getMaxRange(){return this._sheet.getEntireRange().getCoords()}toString(){let t="";return t+=`selection:[${this._sheet.getRange(this._coords.cell).toString()}`,this._coords.ranges&&this._coords.ranges.length>0&&(t+=`, ${this._sheet.getRanges(this._coords.ranges).toString()}`),void 0!==this._coords.rangeIndex&&-1!==this._coords.rangeIndex&&(t+=`, ${this._coords.rangeIndex}`),t+="]",t}}class iS{constructor(t,e){this._c=t,this._m=e}getModel(){return this._m}getCoords(){return this._c}getPropertiesAt(t,e,r){return this._m.getPropertiesAt(t,e,r)}getSplit(t){const e=this._m;return[new iS(t[0],e),new iS(t[1],e)]}}class aS extends fl{constructor(t){if(super({...t}),this._coordsCache=null,!t.json)throw new Error("json is required");this._sheet=t.sheet,this._styles=t.sheet?.getStyles()??new af,this._options={...t},t.setOnContainerCoordsChange(this._processCoordsChange.bind(this)),t.setCreateSpatial(this._createSpatial.bind(this)),this._getContainerRanges=t.getContainerRanges,this._setContainerRanges=t.setContainerRanges;const e=this;this._options.transactions.addStateListener(this,{onRestoreOrRevert(){e._coordsCache=null},onBeforeCommitEnd(){e._coordsCache=null}}),this._fromJSON({...t.json})}getRanges(){return this._getContainerRanges()}setRanges(t,e){const r=this.getRanges(),n=this._setContainerRanges(t,e);return this._processCoordsChange({before:r?.getCoords()??null,after:n?.getCoords()??null}),this}setType(t,e){return this._updateState({type:t},{description:"Set Conditional Format Type",...e}),this}getType(){return this._getState().type}setPriority(t,e){return this._updateState({priority:t},{description:"Set Priority",...e}),this}getPriority(){return this._getState().priority}setStopIfTrue(t,e){return this._updateState({stopIfTrue:t},{description:`Set Stop ${t??!1}`,...e}),this}getStopIfTrue(){return this._getState().stopIfTrue??!1}getScalar(){return this._getState().value??null}getColorScale(){return this._getState().colorScale??null}getContainsText(){return this._getState().text}getCustom(){return this._getState().formulas}getDataBar(){return this._getState().dataBar??null}getIconSet(){return this._getState().iconSet}getPresetCriteria(){return this._getState().style}getTopBottom(){return this._getState()}getSnapshot(t){this.toJSON();const e=null,r=this,n=Object.freeze({...t});let o=!1;return{async copyTo(t,s){t.conditionals;const i=t.range;({...n,...s}).isCut&&!o&&(r.delete(),o=!0);const a={colStart:i.colStart,rowStart:i.rowStart,colEnd:e.colEnd-e.colStart+i.colStart,rowEnd:e.rowEnd-e.rowStart+i.rowStart};return console.log("implement copyTo"),a},getCoords:()=>e,getSource:()=>r,getName:()=>"Conditional Format",getMarkOptions:()=>n,isISnapshot:!0}}_processRestoreOrRevert(t,e,r){super._processRestoreOrRevert(t,e,r)}_createSpatial(t){return new iS(t,this)}_processCoordsChange(t){this._coordsCache=null,t.after?this._emitter.notify("onAnyChange"):this._delete()}update(t,e){if(this.isClosed())throw new Error("Table has been closed. No further operations are allowed.");const r=this._getState(),n=this._beginCommit(e?.description??"Update Conditional Format");try{const o={...r,...t};this._updateState(o,e),this._getEmitter().notify("onAnyChange"),n.commit()}catch(t){throw n.rollback(),t}return this}_processDelete(){this._getState(),super._processDelete()}_processStateChange(t,e,r){super._processStateChange(t,e,r),this._getEmitter().notify("onAnyChange")}toJSON(){const t={},e=this._getState();if(null===e)return null;const r=this.getRanges()?.toString();return r?(t.ref=r,t.type=e.type,0!==e.priority&&(t.priority=e.priority),e.stopIfTrue&&(t.stopIfTrue=e.stopIfTrue),e.style&&(t.style=e.style),e.colorScale&&(t.colorScale=e.colorScale),e.dataBar&&(t.dataBar=e.dataBar),e.iconSet&&(t.iconSet=e.iconSet),e.aboveAverage&&(t.aboveAverage=e.aboveAverage),e.equalAverage&&(t.equalAverage=e.equalAverage),0!==e.stdDev&&(t.stdDev=e.stdDev),e.bottom&&(t.bottom=e.bottom),e.percent&&(t.percent=e.percent),0!==e.rank&&(t.rank=e.rank),e.operator&&(t.operator=e.operator),e.formulas&&(t.formulas=e.formulas),e.text&&(t.text=e.text),e.timePeriod&&(t.timePeriod=e.timePeriod),t):null}_fromJSON(t){const e={};e.type=t.type??exports.IConditionalFormat.Type.CellIs,e.priority=t.priority??0,e.stopIfTrue=t.stopIfTrue??!1,e.style=t.style??null,e.colorScale=t.colorScale??null,e.dataBar=t.dataBar??null,e.iconSet=t.iconSet??null,e.aboveAverage=t.aboveAverage??!1,e.equalAverage=t.equalAverage??!1,e.stdDev=t.stdDev??0,e.bottom=t.bottom??!1,e.percent=t.percent??!1,e.rank=t.rank??0,e.operator=t.operator??null,e.formulas=t.formulas??null,e.text=t.text??null,e.timePeriod=t.timePeriod??null,this._updateState(e,{description:"Initialize Conditional Format"})}close(){super.close(),this.isClosed()||(this._updateState({},{description:"Close Conditional"}),this._stylesRemoveListener?.())}getCoords(){return this.getRanges().getCoords()[0]}getPropertiesAt(t,e,r){let n=this._coordsCache;n||(n=this._coordsCache=this.getRanges().getCoords());let o=0,s=0;const i={rowIndex:t,colIndex:e};for(let r=0;r<n.length;r++){const a=n[r];if(U.isCellWithinRange(i,a)){const r=t-a.rowStart,n=e-a.colStart;s=o+(r*(a.colEnd-a.colStart+1)+n+1)}o+=(a.rowEnd-a.rowStart+1)*(a.colEnd-a.colStart+1)}let a={fill:{type:"solid",color:"red"}};return a.fill.color=((t,e,r,n)=>{let o=1;0!==e&&(o=t/e);const s=r[0]+o*(n[0]-r[0]),i=r[1]+o*(n[1]-r[1]),a=r[2]+o*(n[2]-r[2]);return`rgb(${Math.round(s)}, ${Math.round(i)}, ${Math.round(a)})`})(s,o,[255,255,255],[255,0,0]),a}get isIConditionalFormat(){return!0}}class lS{constructor(t,e){this._add=t,this._get=e}add(t,e){if(!t)throw new Error(Fd);return this._add(t,e)}search(t){let e;t?.address&&(e=t.address);return this._get(e,t?.excludeHidden,t?.fullyContained)}getCount(){return this._get(null,!1,!1).length}}const cS=(t,e)=>{if(e)if(e.getType()===exports.IFill.Type.Solid)t.background=Ru(e.getColor())||"none",t["mso-pattern"]="black none";else if(e.getType()===exports.IFill.Type.Pattern){const r=e;t.background=Ru(r.getBackground())||"none";const n=Ru(r.getForeground())||"";if(r.getPatternType()===exports.IFill.BuiltInSheetPattern.Solid)t["mso-pattern"]=`${t.background} none`,t.background=n;else{const e=(t=>{const e=wg.get(t);return e?.cssKey??"solid"})(r.getPatternType());t["mso-pattern"]=n+(e?" ":"")+e}}else if(e.getType()===exports.IFill.Type.Gradient){const r=e;t.background=Ru(r.getStops()?.[0]?.getColor())||"auto",t.msoGradient=Eg(r)||"auto"}};class hS{constructor(t,e){if(this._visitedStyles=new Map,this._lastStyleClassId=63,this._wroteTD=!1,!t)throw new Error("Can not create with a null sheet.");this._sheet=t,this._includeSizeInCell=e??!1,this._normalStyle=t.getStyles().getNormal()}_createCSSStyle(t){const e=this._normalStyle,r={},n=(t,e)=>t===e||!(t&&!e)&&(!(!t&&e)&&e.isEqual?.(t)),o=t.getFont(),s=e.getFont();var i;n(o.getFill(),s.getFill())||(r.color=Ru(o.getFill())),n(o.getSize(),s.getSize())||(r["font-size"]=Mu(o.getSize())),n(o.getWeight(),s.getWeight())||(r["font-weight"]=o.getWeight()),n(o.getStyle(),s.getStyle())||(r["font-style"]=o.getStyle()),n(o.getUnderline(),s.getUnderline())||(r["text-decoration"]="underline",r["text-underline-style"]=(i=o.getUnderline())===exports.IFont.UnderlineStyle.Single?"single":i===exports.IFont.UnderlineStyle.Double?"double":i===exports.IFont.UnderlineStyle.SingleAccounting?"single-accounting":i===exports.IFont.UnderlineStyle.DoubleAccounting?"double-accounting":"none"),n(o.getFamily(),s.getFamily())&&n(o.getFallbacks(),s.getFallbacks())||(r["font-family"]=Bu(o.getFamily(),o.getFallbacks())),n(t.getNumberFormat(),e.getNumberFormat())||(r["mso-number-format"]=Lu(t.getNumberFormat()));const a=t.getAlignment(),l=e.getAlignment();if(!n(a.getHorizontal(),l.getHorizontal())){const t=a.getHorizontal();t===exports.ITextFrame.HorizontalAlignment.CenterContinuous?r["text-align"]="center-across":t===exports.ITextFrame.HorizontalAlignment.Fill?r["text-align"]="fill":t===exports.ITextFrame.HorizontalAlignment.Distributed?r["text-align"]=a.getJustifyLastLine()?"121":"010":r["text-align"]=exports.ITextFrame.toCSSHorizontalTextAlign(t)}if(!n(a.getVertical(),l.getVertical())){const t=a.getVertical();t===exports.ITextFrame.VerticalAlignment.Distributed?r["vertical-align"]="121":r["vertical-align"]=ku(t)}if(!n(a.getOverflow(),l.getOverflow())){const t=a.getOverflow();r["white-space"]=Ou(t),t===exports.ITextFrame.Overflow.Shrink&&(r["mso-text-control"]="shrinktofit")}var c;n(a.getRotation(),l.getRotation())||(r["mso-rotate"]=(c=a.getRotation(),(c%=360)<0&&(c+=360),c>180?c=360-c:c>1&&(c*=-1),c)),n(a.getIndent(),l.getIndent())||(r["mso-char-indent-count"]=a.getIndent()),n(t.getFill(),s.getFill())||cS(r,t.getFill());const h=t.getBorder();return h.getTop().isNone()||(r["border-top"]=Ig(h.getTop())),h.getLeft().isNone()||(r["border-left"]=Ig(h.getLeft())),h.getRight().isNone()||(r["border-right"]=Ig(h.getRight())),h.getBottom().isNone()||(r["border-bottom"]=Ig(h.getBottom())),h.getDiagonalUp().isNone()||(r["border-mso-diagonal-up"]=Ig(h.getDiagonalUp())),h.getDiagonalDown().isNone()||(r["border-mso-diagonal-down"]=Ig(h.getDiagonalDown())),0===Object.keys(r).length?null:r}_createCSSNormalStyle(){const t=this._normalStyle,e={"padding-top":"1px","padding-left":"1px","padding-right":"1px","mso-ignore":"padding"},r=t.getFont(),n=t.getAlignment();return e.color=Ru(r.getFill()),cS(e,t.getFill()),e["font-size"]=Mu(r.getSize()),e["font-weight"]=r.getWeight(),e["font-style"]=r.getStyle(),e["text-decoration"]=Tu(r.getUnderline(),r.getStrike()),e["font-family"]=Bu(r.getFamily(),r.getFallbacks()),e["mso-font-charset"]="0",e["mso-background-source"]="auto",e["mso-number-format"]=Lu(t.getNumberFormat()),e["text-align"]=exports.ITextFrame.toCSSHorizontalTextAlign(n.getHorizontal()),e["vertical-align"]=ku(n.getVertical()),e.border="none",e["mso-pattern"]="auto",e["white-space"]=Ou(n.getOverflow()),n.getOverflow()===exports.ITextFrame.Overflow.Shrink&&(e["mso-text-control"]="shrinktofit"),e["mso-rotate"]="0",n.getIndent()>0&&(e["mso-char-indent-count"]=n.getIndent()),e["mso-protection"]="locked visible",e}onCell(t,e,r){let n;const o=t.getSpans();if(o.width>1||o.height>1){if(!t.isTopLeft())return!1;o.height>1&&r.addAttribute("rowspan",o.height),o.width>1&&r.addAttribute("colspan",o.width)}let s=t.toTextUnformatted();t.getNumberFormat().repeatPlaceholder&&(s=t.getNumberFormat().repeatPlaceholder.repeat(5)),r.setPlainText(s||"");const i=t.getStyle(),a=i.getFont();if(a.getVerticalAlignment()===exports.IFont.VerticalAlignment.Super&&(s=`<sup>${s}</sup>`),a.getVerticalAlignment()===exports.IFont.VerticalAlignment.Sub&&(s=`<sub>${s}</sub>`),a.getStrike()&&(s=`<s>${s}</s>`),t.getHyperlink()&&(s=`<a href="${t.getHyperlink().getAddress()}">${s}</a>`),r.setHTMLText(s||" "),!this._wroteTD){const t=this._createCSSNormalStyle();r.addSharedStyle("td",t),this._wroteTD=!0}let l=this._visitedStyles.get(i);if(!l){const t=this._createCSSStyle(i);t&&(l="xl"+ ++this._lastStyleClassId,this._visitedStyles.set(i,l),r.addSharedStyle("."+l,t))}if(l&&r.addAttribute("class",l),this._includeSizeInCell){const t=this._sheet.getColumnHeaders().at(e.colIndex).getSize();r.addAttribute("width",t),r.addStyle("width",mt.roundAccurately(t/exports.IFont.getDeviceScale(),2)+"pt");const n=this._sheet.getRowHeaders().at(e.rowIndex).getSize();r.addAttribute("height",n),r.addStyle("height",mt.roundAccurately(n/exports.IFont.getDeviceScale(),2)+"pt")}return n}onRow(t,e,r,n){const o=t.getSize();n.addAttribute("height",o),n.addStyle("height",mt.roundAccurately(o/exports.IFont.getDeviceScale(),2)+"pt"),t.isCustomSize()&&n.addStyle("mso-height-source","userset")}onColumn(t,e,r,n){const o=t.getSize();n.addAttribute("width",o),n.addStyle("width",mt.roundAccurately(o/exports.IFont.getDeviceScale(),2)+"pt"),t.isCustomSize()&&n.addStyle("mso-width-source","userset"),r>1&&n.addAttribute("colspan",r)}}const dS=(t,e,r)=>{const n=t.getOrientation()===E.Column,o=(n?"Column":"Row")+" Copy",s=t.getSnapshot(r);return{...s,getName:()=>o,getCoords:()=>e,copyTo:async(t,o)=>{const i=n?t.getColumnHeaders():t.getRowHeaders(),a={...r,...o};if(!0===a.includeHeaders){const t=await s.copyTo(i,a);return n?{colStart:t.min,rowStart:e.rowStart,colEnd:t.max,rowEnd:e.rowEnd}:{colStart:e.colStart,rowStart:t.min,colEnd:e.colEnd,rowEnd:t.max}}},getMarkOptions:()=>r}},uS=(t,e,r,n,o,s)=>{const i=r[0];let a,l;const c=()=>{if(void 0!==l)return;const[t,r]=((t,e)=>{const r=e.getRowHeaders(),n=e.getColumnHeaders(),o=e.getUsedRange()?.getCoords(),s=r.getUsedRange()?.getCoords(),i=n.getUsedRange()?.getCoords(),a={...U.EmptyRange,...o,colEnd:Math.max(o?.colEnd??0,i?.max??0),rowEnd:Math.max(o?.rowEnd??0,s?.max??0)},l=new Map,c=[];t.onStart?.();const h={rows:[],cols:[]},d=new O_(l,c);d.setNode(h),t.onTable?.(d,a);let u=0;n.forEachSpan((e,r)=>{const n=r.getCoords();u=u+n.max-n.min+1;const o={};d.setNode(o),t.onColumn?.(r.getCellHeader(),n.min,n.max-n.min+1,d),h.cols.push(o)},{address:a,includeEmpty:!0,includeStyles:!0});let g=0;const p=[];if(r.forEachSpan((t,e)=>{const r=e.getCoords();g=g+r.max-r.min+1,p.push({min:r.min,max:r.max,value:e.getCellHeader()})},{address:a,includeEmpty:!0,includeStyles:!0,excludeHidden:!1}),u*g>5e4){if(!k_)throw k_=!0,new Tt("Unable to write more than 50000 cells to system clipboard. Items can still be pasted within the application to but if you want to copy to another application select a smaller set of data.");return[null,null]}let m=0,f=-1,_=null;e.forEach((e,r)=>{const n=r.getCoords(),o=r.getCell();if(n.rowIndex!==f){n.rowIndex>p[m].max&&++m;const e=p[m];_={cells:[]},d.setNode(_),t.onRow?.(e.value,n.rowIndex,1,d),h.rows.push(_),f=n.rowIndex}const s={};d.setNode(s),!1!==t.onCell(o,n,d)&&_.cells.push(s)},{address:a,includeEmpty:!0,excludeHidden:!1}),t.onDone?.(),0===h.rows.length&&h.rows.push({cells:[]});const S=[];for(let t=0;t<c.length;t++){const e=c[t],r=l.get(e);S.push(e);let n="";const o=Object.keys(r);for(let t=0;t<o.length;t++){n+=" ",0===t&&(n+="{");const e=o[t];n+=`${e}:${r[e]};`,t===o.length-1?n+="}":n+="\n"}S.push(n)}const w=['<div clipboard-uuid=xxx>\n<html\n xmlns:v="urn:schemas-microsoft-com:vml"\n xmlns:o="urn:schemas-microsoft-com:office:office"\n xmlns:x="urn:schemas-microsoft-com:office:excel"\n xmlns="http://www.w3.org/TR/REC-html40"\n>'];w.push('<head>\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\n<meta name=ProgId content=Excel.Sheet>\n<meta name=Generator content="Microsoft Excel 15">'),w.push('<style>\ntable\n {mso-displayed-decimal-separator:"\\.";\n mso-displayed-thousand-separator:"\\,";}\n@page\n {margin:.75in .25in .75in .25in;\n mso-header-margin:.3in;\n mso-footer-margin:.3in;\n mso-horizontal-page-align:center;}\ntr\n {mso-height-source:auto;}\ncol\n {mso-width-source:auto;}\nbr\n {mso-data-placement:same-cell;}'),S.length>0&&w.push(S.join("\n")),w.push("</style>"),w.push("</head>"),w.push("<body>"),w.push("<table>"),w.push("\x3c!--StartFragment--\x3e");const y=t=>{let e=(t=>{let e="";return t&&t.attributes&&0!==t.attributes.length?(t.attributes.forEach((t,r)=>{e.length>0&&(e+=" "),e+=`${r}=${t}`}),e):e})(t);e.length>0&&(e=" "+e);let r=(t=>{let e="";return t&&t.styles&&0!==t.styles.length?(t.styles.forEach((t,r)=>{e.length>0&&(e+=";"),e+=r+":"+t}),e.length>0&&(e=`style='${e}'`),e):e})(t);return r.length>0&&(r=" "+r),`${e}${r}`},x=[];return h.cols?.forEach(t=>{w.push(` <col${y(t)}>`)}),h.rows.forEach(t=>{w.push(` <tr${y(t)}>`);const e=[];t.cells.forEach(t=>{w.push(` <td${y(t)}>${t.htmlText??t.plainText??""}</td>`);const r=`${mt.castToString(t.plainText??"")?.replace(/"/g,'""')}`;e.push(r)}),x.push(e.join("\t")),w.push(" </tr>")}),w.push("\x3c!--EndFragment--\x3e"),w.push("</table>"),w.push("</body>"),w.push("</html>"),w.push("</div>"),[w.join("\n"),x.join("\n").concat("\n")]})(new hS(e),e.getRange(i));a=t??null,l=r??null};return{copyTo(t,e){const r={...o,...e};return e.isCut,s(t,r)},getMarkOptions:()=>o,getSource:()=>t,getName:()=>n,getCoords:()=>i,toText:()=>(c(),l),toHtml:()=>(c(),a),toImage:()=>null,isISnapshot:!0}},gS=(t,e)=>Math.round(t*e),pS=(t,e,r)=>{const n=[],o=[];if(!t||0===t.length)return{sizes:n,hidden:o};if(!e||!r)return console.warn("_HeaderUtils:default size and scaleFactor should be available"),{sizes:n,hidden:o};let s=0,i=0,a=0,l=null,c=-2;for(let h=0;h<t.length;h++){const d=t[h],u=d.min,g=d.max;s=0===n.length?0:n[n.length-1].runningOffsetMax,n.length>0&&n[n.length-1].spanSize>0&&s++,i<d.min&&n.push({indexMin:i,indexMax:u-1,runningOffsetMin:s,runningOffsetMax:Math.round(s+(u-i)*e*r)-1,runningHiddenRuns:a,spanSize:Math.round(e*r)});const p=n.length,m=n[p-1];s=0===p?0:m.runningOffsetMax,p>0&&m.spanSize>0&&s++;let f=0;d.value.h||(f=gS(d.value?.sz??e,r));const _=0===f?0:-1;0===f&&(a+=g-u+1,c+1===u?l.max=g:(l={min:u,max:g,value:!0},o.push(l)),c=g),p>0&&m.spanSize===f&&m.indexMax+1===u?(m.indexMax=g,m.runningHiddenRuns=a,m.runningOffsetMax=m.runningOffsetMin+(g+1-m.indexMin)*f+_):n.push({indexMin:u,indexMax:g,runningOffsetMin:s,runningOffsetMax:Math.round(s+(g+1-u)*f)+_,runningHiddenRuns:a,spanSize:f}),i=g+1}return{sizes:n,hidden:o}};function mS(t,e,r){void 0!==r&&(null!==r?t[e]=r:delete t[e])}const fS=()=>{},_S=()=>0,SS=()=>!1;const wS=(t,e,r,n)=>{if(void 0!==n){if(null===n)return null;if(n?.isICellHeader){return n._headerState}if(n){const o=n,s={...r};let i,a=o.hidden,l=o.size;if(void 0!==o.size){if("function"==typeof l){const e=void 0===r?.sz?t.getDefaultSize():r?.sz*t.getScaleFactor();l=l?.(e)}if("string"==typeof l&&(l=Sg(l,e.getNormal().getFont().getSize(),"px")),"number"==typeof l){const e=t.getMinSize(),r=t.getMaxSize();if(l=Math.max(e,Math.min(mt.roundAccurately(l,e),r)),!0!==o.relativeSize){l/=t.getScaleFactor()}isNaN(l)&&(console.warn("headerSize can not be NaN"),l=void 0),0===l&&(a=!0,l=void 0),i=!o.autoSize}else null===l?(l=null,i=!o.autoSize):void 0!==l&&(console.warn("headerSize can not be type",l),l=void 0)}return mS(s,"sz",l),mS(s,"h",a),mS(s,"csz",i),0===Object.keys(s).length?null:s}}};class yS{constructor(t,e,r){this._sheetHeader=t;const n=this._sheetHeader.getSheet().getStyles();this._styles=n,this._headerState=e,this._template=r}getSize(){const t=this._headerState?.sz;return Math.round(void 0===t?this._sheetHeader.getDefaultSize():t*this._sheetHeader.getScaleFactor())}getDisplayText(){return""+this.asCell().getValue()}getOrientation(){return this._sheetHeader.getOrientation()}isHidden(){const t=this._headerState?.h;return t??!1}isCustomSize(){const t=this._headerState?.cs;return t??!1}getSheetHeader(){return this._sheetHeader}getStyle(){const t=this._headerState?.s;return t??this._styles.getNormal()}asCell(){return this._cellTemplate||(this._cellTemplate=this._sheetHeader.getSheet().createTemporaryCell({style:this.getStyle(),...this._template})),this._cellTemplate}getSizeRelative(){return this.getSize()/this._sheetHeader.getScaleFactor()}createTemporaryCellHeader(t){const e=wS(this._sheetHeader,this._sheetHeader.getSheet().getStyles(),this._headerState,t);return new yS(this._sheetHeader,e,this._template)}isEqual(t){if(!t)return!1;if(t===this)return;const e=t;if(!e.isICellHeader)return!1;const r=this._headerState,n=e._headerState;return r===n||!(r&&!n||n&&!r)&&(this.getSize()===e.getSize()&&(this.isCustomSize()===e.isCustomSize()&&(this.isHidden()===e.isHidden()&&this.getStyle()===e.getStyle())))}isEmpty(){const t=this._headerState;return!t||void 0===t.sz&&(void 0===t.csz&&(!t.cs&&(void 0===t.h&&!(!t.s||t.s!==this._styles.getNormal()||t.cs))))}get isICellHeader(){return!0}}const xS="The columns are protected. To make a change, unprotect the sheet. You might be requested to enter a password.",CS="The rows are protected. To make a change, unprotect the sheet. You might be requested to enter a password.",bS="Rows",ES="Columns";class vS{constructor(t){if(this._emitter=null,this._closed=!1,this._scaleFactor=1,this._defaultSize=-1,this._defaultCustomSize=-1,this._defaultPxSize=1,this._isColumn=!0,this._indexedSizes=[],this._indexedHidden=[],this._headerRunCoords=null,this._hasCustomFormats=!1,this._hasStyles=!1,this._hasHidden=!1,this._lastHeaderRead=null,this._readCache=null,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null,this._options={isProtected:()=>!1,getUpdateId:()=>null,scaleFactor:()=>1,defaultSize:()=>100,minSize:()=>0,maxSize:()=>500,orientation:exports.t.Orientation.Column,createCellHeader:(t,e,r)=>new yS(t,e,r),...t},!this._options.sheet)throw new Error("An ISheet must be provided");if(this._emptyHeader=this._options.createCellHeader(this,null,null),this._scaleFactor=this._options.scaleFactor(),this._defaultSize=this._options.defaultSize(),this._defaultSize<=0)throw new Error("defaultSize must be greater than 0");this._defaultPxSize=gS(this._defaultSize,this._scaleFactor);const e=this._options.orientation===exports.t.Orientation.Column;this._isColumn=e;const r=this._options.maxSheetCoords??{colStart:0,rowStart:0,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER};this._maxSheetCoords=r;const n=e?r.colEnd:r.rowEnd;this._maxDataIndex=n,this._maxRunCoords={min:0,max:n},this._maxDataRange=this.getRange(this._maxRunCoords),this._maxRangeCoords={colStart:0,rowStart:0,colEnd:e?n:0,rowEnd:e?0:n};const o=this;this._options.setContainerShiftedCallback&&this._options.setContainerShiftedCallback((t,e)=>{e<0?o._deleteHeaders(t,-e):o._insertHeaders(t,e)}),this._options.sheet&&(this._sheetRemoveListener=this._options.sheet.addListeners({onProtectionChange(){},onSelectionChange(t){o._selection=t.getSelection().getCoords(),o._selectionRuns=null},onStyleChange:()=>{},onViewChange(){const t={runs:o._headers};o._invalidSizes(),o._emitter.notify("onSizesChange",{params:t})}},{transactional:!1}),o._selection=o._options.sheet.getSelection().getCoords()),this._transactions=this._options.transactions??new re({transient:!0}),this._emitter=new ml(o,this._transactions),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t){o._lastHeaders!==t.headers&&o._onHeaderChange()}}),this.fromJSON(this._options?.json)}addListeners(t,e){return this._emitter.addListeners(t,e)}_invalidSizes(){const t=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize,e=this._options.scaleFactor();if(t!==this._defaultSize||e!==this._scaleFactor){this._defaultSize=t,this._scaleFactor=e,this._defaultPxSize=gS(t,e);const r=pS(this._headers,t,e);this._indexedSizes=r.sizes,this._indexedHidden=r.hidden,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null}}_onHeaderChange(){this._lastHeaders=null;const t=this._headers,e=this._getState();this._defaultCustomSize=e.defaultCustomSize;const r=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize;this._defaultSize=r;const n=this._scaleFactor;this._defaultPxSize=gS(r,n);const o=pS(t,r,n);this._indexedSizes=o.sizes,this._indexedHidden=o.hidden,this._lastHeaderRead=null,this._readCache=sa(this._lastHeaders),this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null;const s=this._options.sheet.getStyles().getNormal();let i=!1,a=!1,l=!1,c=-1;for(let e=t.length-1;e>=0;e--){const n=t[e],o=n.value,h=o.s,d=o.csz||o.sz!==r;-1!==c||!d&&h===s||(c=n.max),i=i||o.cs,a=a||o.s!==s,l=l||o.h||0===o.sz}c=Math.min(c??0,this._maxDataIndex);const h=Math.min(t[0]?.min??c,c);this._headerRunCoords=Object.freeze({min:h,max:c}),this._hasCustomFormats=i,this._hasStyles=a,this._hasHidden=l;const d=e.runs;this._emitter.notify("onSizesChange",{params:d})}getSheet(){return this._options.sheet}getOrientation(){return this._isColumn?exports.t.Orientation.Column:exports.t.Orientation.Row}getTextAt(t){return this._options.getTextAt?.(t)??t+""}_scanHeaders(t,e,r,n,o,s){const i=o?.min??null,a=o?.max??null,l=s?.includeEmpty??!1,c=s?.includeStyles??!1,h=s?.excludeHidden??!1,d=s?.includeSizes??!1,u=this,g=this._options.sheet.getStyles().getNormal(),p=this._defaultSize,m=this._scaleFactor,f=this._emptyHeader;let _;const S={getCoords(){if(!_)throw new Error(su);return{min:_.min,max:_.max}},getIndex:()=>_.min,getCellHeader(){if(!_)throw new Error(su);return _.value?r(u,_.value):f},getA1(t){if(!_)throw new Error(su);return this._parseHeaderRangeAddress({min:i+t,end:i+t})??_}},w=aa(e,e=>{const r=e.value;if(!l&&!r)return;let n=l;if(d&&!n&&r&&(r.csz||r.sz!==p)&&(n=!0),c&&!n&&r&&(r.s&&r.s!==g||r.cs)&&(n=!0),r&&!0===r.h&&(n=!h),!n)return;let o=p;e.value&&(o=e.value.h?0:e.value?.sz??p),o*=m,_=e;const s=t(o,S);return s&&s.break?s:void 0},i,a);return _=null,w}getRange(t,e){if(!t)throw new Error(Fd);const r=this,n=this._parseHeaderRangeAddress(t);if(n.min<0||n.max>this._maxDataIndex)return function(t){const e={getCoords:()=>null,getOrientation:()=>t.getOrientation(),toString:()=>Gh,getA1:()=>Gh,getCount:_S,getVisibleCount:_S,isEntireHeaders:SS,forEach:fS,forEachSpan:fS,forEachVisibleSpan:fS,getUsedRange:Bd,getSnapshot:Bd,updateHeaders:Bd,clear:Bd,setHidden:Bd,setSize:Bd,at:Bd,doBatch:Bd,getSheetHeader:()=>t,isICellHeaderRange:!0};return Object.freeze(e)}(this);const o=(t,o,s,i=r._options.createCellHeader)=>{let a=n;if(o?.address){const t=r._parseHeaderRangeAddress(o?.address);if(t&&(a=oa(n,t),!a))return}const l=this._scanHeaders(t,s,i,e,a,o);if(l&&l.break)return l.break},s=()=>{const t=r._isColumn?{colStart:n.min,colEnd:n.max}:{rowStart:n.min,rowEnd:n.max};return ad(t,r._maxRangeCoords)??Gh},i={getCoords:()=>n,getA1:s,toString:s,forEach:(t,e)=>{let r=Number.MAX_SAFE_INTEGER,s=null;const i={getIndex:()=>r,getCellHeader:()=>s.getCellHeader(),getA1:t=>s.getA1(t),getCoords:()=>s.getCoords()};return o((e,o)=>{s=o;for(let o=n.min;o<n.max;o++)r=o,t(e,i)},e,this._headers,()=>this.at(undefined))},forEachSpan:(t,e)=>o(t,e,this._headers),forEachVisibleSpan:(t,e)=>{const r=n?.min??null,o=n?.max??null;let s;if(s=e?.includeHidden?t(r,o):aa(this._indexedHidden,e=>{if(e.value)return;const r=t(e.min,e.max);return r&&r.break?r:void 0},r,o),s&&s.break)return s.break},updateHeaders:(t,e)=>(r.updateHeaderPairs([{address:n,update:t}],{description:e?.description??`Update ${r._isColumn?ES:bS} ${toString()}`,...e}),i),setHidden:t=>(r.setHidden(n,t),i),getUsedRange:t=>{const e=r._headerRunCoords;if(!e||e.min<0||e.max>r._maxDataIndex)return null;return oa(e,n)?r.getRange(e,t):null},getCount:()=>n.max-n.min+1,getVisibleCount:()=>r.getVisibleCount(n.min,n.max),isEntireHeaders:()=>{const t=r._maxRunCoords;return!(n.min>t.min||n.max<t.max)},getSnapshot:t=>this._getSnapshot(n,t),clear:()=>(r._clear(n),i),setSize:(t,e)=>(r.setSize(n,t,e),i),at:t=>r.at(n.min+t),getOrientation:()=>r.getOrientation(),doBatch:(t,e)=>this.doBatch(e=>t(e),e),getSheetHeader:()=>r,isICellHeaderRange:!0};return Object.freeze(i)}getSelectedRange(t){const e=(t=>{if(!t)return null;let e=U.cellToRange(t.cell);for(let r=0;r<t.ranges.length;r++)e=U.unionRanges(e,t.ranges[r]);return e})(this._options.sheet.getSelection().getCoords());return this.getRange(e,t)}getUsedRange(t){return this.getRange(this._headerRunCoords,t)}getEntireRange(t){return t?this.getRange(this._maxRangeCoords,t):this._maxDataRange}at(t){if(t<0||t>this._maxDataIndex)return this._emptyHeader;if(this._lastHeaderRead?.offset===t)return this._lastHeaderRead.header;const e=ia(t,this._readCache);if(!e)return this._emptyHeader;const r=this._options.getTextAt?.(t)??t+"",n=this._options.createCellHeader(this,e,{value:r});return this._lastHeaderRead={offset:t,header:n},n}updateHeaderPairs(t,e){if(this.isProtected())throw new Error(this._isColumn?xS:CS);return this._updatePairsInternal(t,e)}_parseHeaderRangeAddress(t){if(null==t)throw new Error("Must specify a range.");const e=((t,e,r)=>{if(null==t)return null;let n={};if("number"==typeof t)n.colStart=t,n.colEnd=t,n.rowStart=t,n.rowEnd=t;else if("string"==typeof t){if(e){if(t.match(/[0-9]+/))throw new Error("Invalid range address for header orientation")}else if(t.match(/[a-zA-Z]+/))throw new Error("Invalid range address for header orientation");let o=hd(t,r);if(!o){const e=cd(t.toUpperCase(),!0);void 0!==e?.colIndex&&(n.colStart=e.colIndex,n.colEnd=e.colIndex),void 0!==e?.rowIndex&&(n.rowStart=e.rowIndex,n.rowEnd=e.rowIndex)}n={...n,...o}}const o={min:void 0,max:void 0};return e?(o.min=t.min??t.colStart??n.colStart,o.max=t.max??t.colEnd??n.colEnd):(o.min=t.min??t.rowStart??n.rowStart,o.max=t.max??t.rowEnd??n.rowEnd),void 0===o.min||void 0===o.max?null:o})(t,this._isColumn,this._maxRangeCoords);if(!e)throw new Error("Invalid header range.");return e}update(t,e,r){if(!t)return;if(Array.isArray(t)||(t=[t]),0===t.length)return;const n=[];for(let r=0;r<t.length;r++){const o=this._parseHeaderRangeAddress(t[r]);this.getRange(o).forEachSpan((t,r)=>{const o=r.getCoords();n.push({address:o,update:e})},{includeEmpty:!0})}return this.updateHeaderPairs(n,r),this}setSize(t,e=null,r){(r?.relativeSize??!1)||"number"!=typeof e||(e+="px");const n={size:e,autoSize:r?.autoSize??!1},o=`Resize ${this._isColumn?ES:bS}`;return this.update(t,n,{description:o,...r}),this}setHidden(t,e=null){const r={hidden:e},n=`${e?"Unhide":"Hide"} ${this._isColumn?ES:bS}`;return this.update(t,r,{description:n}),this}_clear(t,e){const r="Clear "+(this._isColumn?"Column Headers":"Row Headers");this.updateHeaderPairs([{address:t,update:null}],{description:r,...e})}_getSnapshot(t,e){if(t.min<0)return mt.EmptyArray;e=Object.freeze({...e});const r=this,n=this._getState(),o=(this._isColumn?"Column":"Row")+" Headers",s={copyTo(s,i){const a={...e,...i},l=s.getCoords(),c=l.min-t.min,h=[];if(r._scanHeaders((t,e)=>{const r=e.getCoords();h.push({address:{min:r.min+c,max:r.max+c},update:e.getCellHeader()})},n.headers,r._options.createCellHeader,null,t,{includeSizes:!0,includeStyles:!0}),!a.fitDestination){let e=t.max-t.min+1,r=l.max-l.min+1,n=mt.roundAccurately(r/e);if(n>1&&r%e===0){const t=h.length;for(let r=0;r<n;r++)for(let n=0;n<t;n++){const t=h[n],o=t.address,s=(r+1)*e;h.push({address:{min:o.min+s,max:o.max+s},update:t.update})}}}if(s.doBatch(()=>{s.clear(),s.getSheetHeader()._updatePairsInternal(h)},o),a.isCut){const e=r._maxRunCoords;t.min<=e.min&&t.max>=e.max&&r._clear(t)}return l},getCoords:()=>t,toText:()=>null,toHtml:()=>null,toImage:()=>null,getSource:()=>r,getName:()=>o,isISnapshot:!0};return s}isProtected(){return this._options?.isProtected()??!1}getScaleFactor(){return this._options.scaleFactor()??1}get _headers(){return null===this._lastHeaders&&(this._lastHeaders=this._getState()?.headers),this._lastHeaders}_updatePairsInternal(t,e){if(!t||0===t.length)return null;const r=e?.skipCustomSize??!1,n=this._isColumn,o=this.getSheet().getStyles(),s=this._beginCommit({description:e?.description??`Update ${n?ES:bS}`});let i=[...this._getState().headers],a=!1,l=!1;const c=n?exports.IBorder.Edge.Top:exports.IBorder.Edge.Left;exports.IBorder.oppositeEdge(c);const h=n?exports.IBorder.Edge.Right:exports.IBorder.Edge.Bottom;exports.IBorder.oppositeEdge(h);const d=this,u=(t,e)=>{if(this.isProtected())throw new Error(this._isColumn?xS:CS);l=l||null===e,!l&&e&&(l=!!e.isICellHeader||(void 0!==e?.size||void 0!==e?.hidden)),a=a||null===e||void 0!==e?.style||e?.isICellHeader;const n={onUpdate:(t,e)=>{if(r&&t&&t.csz)return t;return wS(d,o,t,e)},onSplit:t=>[t.value,t.value],onMerge:(t,e,r,n)=>{if(!(t&&!e||!t&&e||!t&&!e)&&t.sz===e.sz&&t.csz===e.csz&&t.h===e.h&&t.cs===e.cs)return t},isCull:(t,e,r)=>void 0===t};i=ta(Qi(i,{min:t.min,max:t.max,value:e},n))},g=t.length,p=new Array(g);for(let e=0;e<g;e++){const r=t[e],n=this._parseHeaderRangeAddress(r.address);if(n.min<0||n.max>this._maxDataIndex)throw new Mt(Kd);u(n,r.update),p[e]=n}let m=!1,f=i.length;if(f>0&&0===i[0].min&&i[f-1].max===this._maxDataIndex){let t=i[0],e=!1,r=-1;for(let n=0;!e&&n<f;n++){const o=i[n],s=o.min;if(r+1!==s){e=!0;continue}const a=o.max;r=a,t.max-t.min<a-s&&(t=o)}e||(this._defaultCustomSize=t.value?.sz??-1,m=!0);const n=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize,o=[];for(let t=0;t<f;t++){const e=i[t],r=e.value;if(null===r)continue;const s=Object.keys(r);0!==s.length&&((1!==s.length||void 0===r.sz||null!==r.sz&&r.sz!==n)&&o.push(e))}i=o,f=i.length}const _=[],S=this._defaultSize;for(let t=0;t<f;t++){const e=i[t],r=e.value;if(null===r)continue;let n=!1;void 0!==r.sz&&r.sz!==S&&(n=!0),r.csz&&(n=!0),r.h&&(n=!0),r.cs&&(n=!0),n&&_.push(e)}return i=_,f=i.length,m&&d._invalidSizes(),this._updateState({headers:i,defaultCustomSize:this._defaultCustomSize,runs:p}),s.commit(),p}hasCustomFormats(){return this._hasCustomFormats}hasCustomStyles(){return this._hasStyles}hasHidden(){return this._hasHidden}getDefaultSize(){return this._defaultPxSize}getMaxSize(){return Math.ceil(this._options.maxSize()*this._options.scaleFactor())}getMinSize(){return Math.floor(this._options.minSize()*this._options.scaleFactor())}findOffset(t){return((t,e,r)=>{if(e<0)return 0;if(!t||0===t.length)return e*r;const n=t[t.length-1];if(e>n.indexMax)return n.runningOffsetMax+Math.round((e-n.indexMax-1)*r+(0!==n.spanSize?1:0));const o=1===t.length?0:mt.findEqualOrGreater(t,e,t=>t.indexMax),s=t[o],i=e-s.indexMin;return s.runningOffsetMin+i*s.spanSize})(this._indexedSizes,t,this._defaultPxSize)}findIndex(t){return Math.min(Math.max(0,((t,e,r)=>{if(!t||0===t.length)return Math.floor(e/r);const n=t[t.length-1];if(e>n.runningOffsetMax)return n.indexMax+Math.ceil((e-n.runningOffsetMax)/r);let o=1===t.length?0:mt.findEqualOrGreater(t,e,t=>t.runningOffsetMax);const s=t[o];if(0===s.spanSize)return Math.max(0,s.indexMin-1);const i=e-s.runningOffsetMin;return s.indexMin+Math.floor(i/s.spanSize)})(this._indexedSizes,t,this._defaultPxSize)),this._maxDataIndex)}findVisibleIndex(t){return this._lastVisibleRunsRead===t||(this._lastVisibleRunCoords=((t,e,r=Number.MAX_SAFE_INTEGER)=>{if(!t||0===t.length)return{min:e,max:e};let n=t.length-1,o=t[n];if(e>o.indexMax){const t=e-o.runningHiddenRuns;return{min:t,max:t}}n=1===t.length?0:mt.findEqualOrGreater(t,e,t=>t.indexMax),o=t[n];const s=0===o.spanSize?Math.max(-1,o.indexMin-1-(t[n-1]?.runningHiddenRuns??1)):e-o.runningHiddenRuns;return{min:s,max:s+Math.min(r+1,0===o.spanSize?1:0)}})(this._indexedSizes,t,this._maxDataIndex),this._lastVisibleRunsRead=t),this._lastVisibleRunCoords}getSpanSize(t,e=t+1){return this.findOffset(e)-this.findOffset(t)}getVisibleCount(t,e){if(t>e)throw new Error("Invalid arguments.");if(t<0||e>this._maxDataIndex)throw new Mt;return this._hasHidden?((t,e,r)=>{let n=r-e+1;if(0===t.length)return n;let o=t.length-1,s=t[o];if(e>s.indexMax)return n;o=1===t.length?0:mt.findEqualOrGreater(t,e,t=>t.indexMax),s=t[o];let i=s.runningHiddenRuns;if(0===s.spanSize&&e<=s.indexMax){const t=s.indexMax-s.indexMin+1;n-=Math.min(t,s.indexMax-e+1)}r>s.indexMax&&o<t.length&&(o=mt.findEqualOrGreater(t,r,t=>t.indexMax),s=t[Math.min(o,t.length-1)]);let a=s.runningHiddenRuns;if(0===s.spanSize&&s.indexMin<=r){const t=s.indexMax-s.indexMin+1;n-=Math.min(t,r-s.indexMin+1),a-=t}return n-=a-i,n})(this._indexedSizes,t,e):e-t+1}isSelectedAll(t){const e=this.getSelectedRuns();if(0===e.length)return!1;const r=mt.findEqualOrGreater(e,t,t=>t.max),n=e[r];return!(!n||t<n.min||t>n.max)&&n.value.isSelectedAll}isSelected(t){const e=this.getSelectedRuns();if(0===e.length)return!1;const r=mt.findEqualOrGreater(e,t,t=>t.max),n=e[r];return!(!n||t<n.min||t>n.max)}getSelectedRuns(){let t=this._selectionRuns;return t||(this._selection&&(t=((t,e,r)=>{let n=[];e?.ranges&&e.ranges.length>0?n=e.ranges:e?.cell&&(n=[U.cellToRange(e?.cell)]);let o=[];const s=t.getOrientation()===exports.t.Orientation.Column;for(let t=0;n&&t<n.length;t++){const e=n[t],i=s?e.colStart:e.rowStart,a=s?e.colEnd:e.rowEnd,l=s?e.rowStart:e.colStart,c=s?e.rowEnd:e.colEnd,h=s?r.rowStart:r.colStart,d=s?r.rowEnd:r.colEnd,u=l<=h&&c>=d;o=ta(Qi(o,{min:i,max:a,value:{isSelectedAll:!1}},{onUpdate:(t,e)=>{const r=Ji(t,e);return r.isSelectedAll=t?.isSelectedAll||u,r}}))}return o})(this,this._selection,this._maxSheetCoords)),t||(t=mt.EmptyArray)),this._selectionRuns=t,this._selectionRuns}hiddenHeadersAt(t,e=!1){if(0===this._indexedSizes.length)return 0;let r=1===this._indexedSizes.length?0:mt.findEqualOrGreater(this._indexedSizes,t,t=>t.indexMax),n=this._indexedSizes[r];return!n||0!==n.spanSize||n.indexMin>t||n.indexMax<t?0:e?t-n.indexMin+1:n.indexMax-t+1}_insertHeaders(t,e){if(this.isProtected())throw new Error(this._isColumn?xS:CS);if(e<=0)return;const r=this._beginCommit({description:`Insert ${this._isColumn?ES:bS}`}),n=this._getState();let o=[...n.headers];o=ta(((t,e,r=1)=>{const n=mt.findEqualOrGreater(t,e,t=>t.max),o=t.slice(0,n),s=[],i=[];if(!t[n])return{preceding:o,modified:i,trailing:s};t[n].min>=e?s.push({...t[n],min:t[n].min+r,max:t[n].max+r}):i.push({...t[n],min:t[n].min,max:t[n].max+r});for(let e=n+1;e<t.length;e++)s.push({...t[e],min:t[e].min+r,max:t[e].max+r});return{preceding:o,modified:i,trailing:s}})(o,t,e));const s=[{min:t,max:t+e}];this._updateState({headers:o,runs:ta(ea([...n?.runs??[],...s]))}),r.commit()}_deleteHeaders(t,e){if(this.isProtected())throw new Error(this._isColumn?xS:CS);const r=this._beginCommit({description:`Delete ${this._isColumn?ES:bS}`}),n=this._getState();let o=[...n.headers];o=ta(Zi(o,t,e));const s=[{min:t,max:t+e}];this._updateState({headers:o,runs:ta(ea([...n?.runs??[],...s]))}),r.commit()}beginCommit(t){return this._beginCommit("string"==typeof t?{description:t}:t)}doBatch(t,e){return this._transactions.doBatch(t,"string"==typeof e?{description:e}:{description:"Update Header",...e})}isClosed(){return this._closed}close(){this._sheetRemoveListener?.(),this._emitter.close(),this._transactionsRemoveListener?.(),this._closed=!0}_getState(){return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit(t)}_updateState(t){const e=this._transactions.beginCommit();try{e.updateState(this,t),this._onHeaderChange(),e.commit()}catch(t){throw e.rollback(),t}}fromJSON(t){const e=t||{};this._defaultCustomSize=e.defaultSize??-1,this._defaultCustomSize<=0&&(this._defaultCustomSize=-1),this._invalidSizes();const r=this._options.sheet.getStyles().beginPersist();try{const t=[],r=e.headers?e.headers.length:0,n=this._maxDataIndex;for(let o=0;o<r;o++){let r=e.headers[o];if(r.min>=n)continue;let s={min:r.min,max:Math.min(r.max,n)};const i={};void 0!==r.sz&&-1!==r.sz&&(i.sz=r.sz),void 0!==r.h&&(i.h=r.h),void 0!==r.csz&&(i.csz=r.csz),void 0!==r.cs&&(i.cs=r.cs),0===Object.keys(i).length&&(i.cs=!0),s.value=i,t.push(s)}this._updateState({headers:t,defaultCustomSize:this._defaultCustomSize})}finally{r.endPersist()}}toJSON(){if(0===this._headers.length&&-1===this._defaultCustomSize)return null;const t={headers:[]};if(-1!==this._defaultCustomSize&&(t.defaultSize=mt.roundAccurately(this._defaultCustomSize,8)),0===this._headers.length)return t;const e=this._defaultCustomSize,r=this.getSheet().getStyles().beginPersist();for(let r=0;r<this._headers.length;r++){const n=this._headers[r],o=n.value;if(!o)continue;const s={min:n.min,max:n.max};void 0!==o.sz&&o.sz!==e&&(s.sz=mt.roundAccurately(o.sz,8),void 0!==o.csz&&(s.csz=o.csz)),!0===o.h&&(s.h=o.h),Object.keys(s).length>2&&t.headers.push(s)}return r.endPersist(),t}}class IS{constructor(t,e,r){this._c=t,this._tvTl=e,this._rsTl=r}tvTl(){return this._tvTl(this._c)}rsTl(){return this._rsTl(this._c)}getCoords(){return this._c}}const AS=t=>{let e="";const r=Rd,n=t.length;for(let o=0;o<n;o++){const n=t[o];if("cell"===n.type){e+=r(n.value)}else{e+=n.value}}return e},RS=(t,e=0,r=0)=>{let n="";const o=Md,s=t.length;for(let i=0;i<s;i++){const s=t[i];if("cell"===s.type){n+=o(s.value,e,r)}else{n+=s.value}}return n};class MS{constructor(t,e,r){this._c=t,this._tokens=e,this._references=r||mt.EmptyArray}getFormulaTextAt(t,e,r=!1){return r?AS(this._tokens):RS(this._tokens,t,e)}getTokensAt(t,e,r){let n=this._tokens;return void 0!==r&&(n=((t,e)=>{const r=t.length,n=[];if(void 0===e)return mt.EmptyArray;let o=-1,s=!1;for(let i=0;!s&&i<r;i++){const r=t[i],a=r.evalIndex??Number.MAX_SAFE_INTEGER;if(-1===o){if(a!==e)continue;o=i}a>e?s=!0:n.push(r)}s=!1;for(let r=o-1;!s&&r>=0;r--){const o=t[r];(o.evalIndex??Number.MAX_SAFE_INTEGER)>e?s=!0:n.unshift(o)}return n.length>1&&"whitespace"===n[0].type&&n.shift(),n.length>1&&"whitespace"===n[n.length-1].type&&n.pop(),n})(n,r)),n=((t,e=0,r=0)=>{const n=t.length,o=new Array(n);for(let s=0;s<n;s++){const n=t[s];if("cell"!==n.type){o[s]=n;continue}const i={...n},a={...i.value};i.value=a,o[s]=i,a.colIndex===Number.MIN_SAFE_INTEGER||a.$colIndex||(a.colIndex+=r),a.rowIndex===Number.MIN_SAFE_INTEGER||a.$rowIndex||(a.rowIndex+=e)}return o})(n,t,e),n}getReferencesAt(t,e){return((t,e=0,r=0)=>{const n=t.length,o=new Array(n);for(let s=0;s<n;s++){const n=t[s];if("string"==typeof n||n instanceof exports.n.Known){o[s]=n;continue}const i={...n};o[s]=i,i.colStart===Number.MIN_SAFE_INTEGER||i.$colStart||(i.colStart+=r),i.rowStart===Number.MIN_SAFE_INTEGER||i.$rowStart||(i.rowStart+=e),i.colEnd===Number.MIN_SAFE_INTEGER||i.$colEnd||(i.colEnd+=r),i.rowEnd===Number.MIN_SAFE_INTEGER||i.$rowEnd||(i.rowEnd+=e)}return o})(this._references,t,e)}toJSON(){const t=this._c;return[sd(t),this.getFormulaTextAt(t.rowStart,t.colStart)]}getCoords(){return this._c}}class TS{constructor(t,e,r){this.groupId=t,this.uuid=e,this.noShift=r}onRemove(t){}getShifted(t){if(!t.after)return null;const e=this.noShift;return e?void 0:{...t.after,value:new TS(this.groupId,this.uuid,e)}}getSplit(t,e){}copyTo(t,e){return new TS(this.groupId,this.uuid,this.noShift)}canTile(t,e){return!1}}class FS{constructor(t,e,r,n,o,s,i,a,l,c){this.uuid=t,this.spatialsIds=e,this.isRanges=n,this.coords=r,this.sheet=o,this.generation=s,this.handler=i,this.handlerW=a,this.removeListener=l,this.options=c}delete(){this.removeListener()}createRangeEvent(t,e){const r=this;let n;const o=()=>{if(n)return n;const t=r.sheet,o=r.isRanges,s=r.coords;return e||!s||0===s.length?_m(t,t.getEntireRange().getCoords(),null,e):o?(n=t.getRanges(r.coords),n):(n=t.getRange(r.coords[0]),n)},s=t.trigger;return{getSource:o,trigger:s,isTransactional:t.isTransactional??!0,toString:()=>`SheetRangeEvent: ('${s}', ${o().toString()})`,timeStamp:t.timeStamp??Date.now()}}notify(t,e){const r=this.createRangeEvent(t,e),n=this.handler??this.handlerW.deref();try{n?.(r)}catch(t){console.warn(t)}this.options?.once&&this.removeListener()}processRemove(t){const e=this.spatialsIds,r=e.indexOf(t.value.uuid);console.assert(-1!==r,"invalid uuid");const n=this.coords,o=n.slice(0,r).concat(n.slice(r+1)),s=e.slice(0,r).concat(e.slice(r+1));return new FS(this.uuid,s,o,this.isRanges,this.sheet,this.generation,this.handler,this.handlerW,this.removeListener,this.options)}processShift(t){const e=this.spatialsIds.indexOf(t.value.uuid);console.assert(-1!==e,"invalid uuid");const r=[...this.coords];return r[e]={...r[e],...U.sanitizeRange(t)},new FS(this.uuid,this.spatialsIds,r,this.isRanges,this.sheet,this.generation,this.handler,this.handlerW,this.removeListener,this.options)}processSplit(t){}processMerge(t){}}const NS=Object.freeze({coords:U.EmptyCell,topLeft:b.EmptyTopLeft}),kS=Object.freeze({cell:U.EmptyCell,ranges:mt.EmptyArray,rangeIndex:0}),OS=Object.freeze({selection:kS,topLeft:b.EmptyTopLeft,freezePanes:NS,showRowHeaders:!0,showColumnHeaders:!0,showRowGridlines:!0,showColumnGridlines:!0,rowHeaderStyle:exports.ISheetView.HeaderTextStyle.One,columnHeaderStyle:exports.ISheetView.HeaderTextStyle.A1,showFormulas:!1,showZeros:!0,zoomScale:100,gridLineColor:null});class BS{constructor(t){if(this._emitter=null,!t?.sheet)throw new Error("SheetView requires a sheet.");const e=new ml(this);this._emitter=e,this._sheet=t.sheet,this.clear(!1),t.json&&this._fromJSON(t.json)}addListeners(t,e){return this._emitter.addListeners(t,e)}setTopLeft(t){return this._state.topLeft=Object.freeze({left:t?.left??this._state.topLeft.left,top:t?.top??this._state.topLeft.top}),this._emitter.notify("onTopLeftChange"),this}getTopLeft(){return this._state.topLeft}getFreezePanes(){return this._state.freezePanes}setFreezePanes(t){return this._state.freezePanes=this._mergeFreezePanes(t),this._emitter.notify("onFreezeSplitChange"),this}_mergeFreezePanes(t){return t?{...this._state.freezePanes,coords:{colIndex:t?.coords?.colIndex??this._state.freezePanes.coords.colIndex,rowIndex:t?.coords?.rowIndex??this._state.freezePanes.coords.rowIndex},topLeft:{left:t?.topLeft?.left??this._state.topLeft.left,top:t?.topLeft?.top??this._state.topLeft.top}}:NS}isShowRowHeaders(){return this._state.showRowHeaders}setShowRowHeaders(t){return this._state.showRowHeaders=t,this._notifyAll(),this}isShowColumnHeaders(){return this._state.showColumnHeaders}setShowColumnHeaders(t){return this._state.showColumnHeaders=t,this._notifyAll(),this}isShowRowGridlines(){return this._state.showRowGridlines}setShowRowGridlines(t){return this._state.showRowGridlines=t,this._notifyAll(),this}isShowColumnGridlines(){return this._state.showColumnGridlines}setShowColumnGridlines(t){return this._state.showColumnGridlines=t,this._notifyAll(),this}getRowHeaderStyle(){return this._state.rowHeaderStyle}setRowHeaderStyle(t){return this._state.rowHeaderStyle=t,this._notifyAll(),this}getColumnHeaderStyle(){return this._state.columnHeaderStyle}setColumnHeaderStyle(t){return this._state.columnHeaderStyle=t,this._notifyAll(),this}getZoomScale(){return this._state.zoomScale}setZoomScale(t){return this._state.zoomScale=t,this._notifyAll(),this}isShowFormulas(){return this._state.showFormulas}setShowFormulas(t){return this._state.showFormulas=t,this._notifyAll(),this}isShowZeros(){return this._state.showZeros}setShowZeros(t){return this._state.showZeros=t,this._notifyAll(),this}getGridLineColor(){return this._state.gridLineColor}setGridLineColor(t){return this._state.gridLineColor=t,this._notifyAll(),this}setRangeSelection(t){return this._state.selection=t,this._emitter.notify("onRangeSelectionChange"),this}getRangeSelection(){return this._state.selection}getMovableSelection(){return this._movableSelection}setMovableSelection(t){const e=this._movableSelection;return this._movableSelection=Object.freeze(t??[]),mt.isEqualArrays(e,this._movableSelection)||this._emitter.notify("onMovableSelectionChange"),this}selectMovables(t,e=!1){const r=new Set(this._sheet.getMovables().search());let n=null,o=!1;if(e){n=[...this._movableSelection];for(let e=t.length-1;e>=0;e--){const s=t[e];let i=n.indexOf(s);if(i!==e){if(o=!0,!r.has(s))throw new Error(`Movable ${s.getName()} not found in sheet.`);-1!==i&&n.splice(i,1),n.unshift(s)}}}else o=!mt.isEqualArrays(t,this._movableSelection),n=[...t];o&&(this._movableSelection=n,this._emitter.notify("onRangeSelectionChange"),this._emitter.notify("onMovableSelectionChange"))}unselectMovables(t){const e=this._movableSelection,r=[];for(let n=0;n<e.length;n++){const o=e[n];-1===t.indexOf(o)&&r.push(o)}return e.length!==r.length&&(this._movableSelection=r,this._emitter.notify("onRangeSelectionChange"),this._emitter.notify("onMovableSelectionChange")),this}_notifyAll(){const t=this._emitter;t.notify("onRangeSelectionChange"),t.notify("onTopLeftChange"),t.notify("onFreezeSplitChange"),t.notify("onAnyChange")}toJSON(){const t={},e=Object.keys(this._state);for(let r=0;r<e.length;r++){const n=this._state[e[r]];null!=n&&n!==OS[e[r]]&&(t[e[r]]=n)}delete t.movableSelection,delete t.gridLineColor,this._state.gridLineColor instanceof ba&&(t.gridLineColor=this._state.gridLineColor.toString()),delete t.topLeft,!this._state.topLeft||0===this._state.topLeft.left&&0===this._state.topLeft.top||(t.topLeft={left:this._state.topLeft.left??0,top:this._state.topLeft.top??0}),delete t.selection;const r=this._state.selection;if(r){let e={};!r.cell||0===r.cell.colIndex&&0===r.cell.rowIndex||(e.cell=ed(r.cell)),r.ranges&&r.ranges.length>0&&(e.ranges=ud(r.ranges),void 0!==r.rangeIndex&&-1!==r.rangeIndex&&0!==r.rangeIndex&&(e.rangeIndex=r.rangeIndex)),Object.keys(e).length>0&&(t.selection=e)}if(delete t.freezePanes,this._state.freezePanes&&(0!==this._state.freezePanes.coords.colIndex||0!==this._state.freezePanes.coords.rowIndex)){const e={};0!==this._state.freezePanes.coords.colIndex&&(e.c=this._state.freezePanes.coords.colIndex),0!==this._state.freezePanes.coords.rowIndex&&(e.r=this._state.freezePanes.coords.rowIndex),0!==this._state.freezePanes.topLeft.left&&(e.x=this._state.freezePanes.topLeft.left),0!==this._state.freezePanes.topLeft.top&&(e.y=this._state.freezePanes.topLeft.top),t.freezePanes=e}return 0===Object.keys(t).length?null:t}_fromJSON(t){let e=JSON.parse(JSON.stringify(t||{}));e?.zoomScale&&(e.zoomScale=mt.roundAccurately(parseFloat(t.zoomScale),2));const r=t=>{const r=this._sheet.getRange(t).getBounds(),n=(e.zoomScale??100)/100;return{x:r.x*n,y:r.y*n,width:r.width*n,height:r.height*n}};if("string"==typeof e?.gridLineColor&&(this._sheet?.getStyles()?e.gridLineColor=this._sheet.getStyles().parseColor(t.gridLineColor):console.warn("Style was created with no styles so gridLineColor can't be parsed.")),e.topLeft)if("string"==typeof e.topLeft){const t=r(fd(e.topLeft));e.topLeft={left:t.x,top:t.y}}else e.topLeft=Object.freeze({left:e.topLeft?.left??e?.x??0,top:e.topLeft?.top??e?.y??0});if(e.selection){let t=fd(e.selection.cell??"A1");if(e.selection.cell=t,e.selection.ranges){let r=Math.max(0,Math.min(e.selection.rangeIndex??e.selection.ranges?.length-1,e.selection.ranges?.length-1));e.selection.rangeIndex=r;let n=!1;for(let o=0;o<e.selection.ranges.length;o++){const s=yd(e.selection.ranges[o]);e.selection.ranges[o]=s,o===r&&t&&!U.isCellWithinRange(t,s)&&(n=!0)}if(n)for(let r=0;n&&r<e.selection.ranges.length;r++)U.isCellWithinRange(t,e.selection.ranges[r])&&(n=!1,e.selection.rangeIndex=r);n&&(e.selection.ranges.push(U.cellToRange(t)),e.selection.rangeIndex=e.selection.ranges.length-1)}else delete e.selection.rangeIndex}if(e.freezePanes){const t=e.freezePanes;if("string"==typeof t.coords&&(t.coords=fd(t.coords)),"string"==typeof t.topLeft){const n=fd(t.topLeft),o=r({colIndex:n.colIndex+1,rowIndex:n.rowIndex+1}),s=r({colIndex:(t?.coords?.colIndex??-1)+1,rowIndex:(t?.coords?.rowIndex??-1)+1});t.topLeft={left:0,top:0},e.topLeft||(e.topLeft={top:0,left:0}),n.colIndex>0&&(t.topLeft.left=e.topLeft?.left??0,e.topLeft.left=o.x-s.x+t.topLeft.left),n.rowIndex>0&&(t.topLeft.top=e.topLeft?.top??0,e.topLeft.top=o.y-s.y+t.topLeft.top)}e.freezePanes={coords:{colIndex:t?.coords?.colIndex??e.freezePanes?.c??0,rowIndex:t?.coords?.rowIndex??e.freezePanes?.r??0},topLeft:{left:t?.topLeft?.left??e.freezePanes?.x??0,top:t?.topLeft?.top??e.freezePanes?.y??0}}}this.update(e)}clear(t=!0){return this._state={...OS},this._movableSelection=Object.freeze([]),t&&this._notifyAll(),this}update(t){return this._state={...OS,...this._state,...t},this._state.freezePanes=this._mergeFreezePanes(this._state.freezePanes),this._state.zoomScale=Math.min(400,Math.max(10,this._state.zoomScale)),this._notifyAll(),this}get isISheetView(){return!0}}async function LS(){const{getCrypto:t}=await Promise.resolve().then(()=>require("./DOptrVmGD_5mAjIJ.cjs"));return t()}const DS=async(t,e,...r)=>{const n=zS(...r);return t.subtle.digest(e,n)},zS=(...t)=>{const e=t.reduce((t,e)=>t+e.byteLength,0),r=new Uint8Array(e);let n=0;return t.forEach(t=>{r.set(new Uint8Array(t),n),n+=t.byteLength}),r.buffer},PS=t=>{const e=new Uint8Array(t);let r="";for(let t=0;t<e.byteLength;t++)r+=String.fromCharCode(e[t]);return btoa(r)};class jS{static{this.DefaultAlgo="SHA-512"}static{this.DefaultSpinCount=1e5}static async generateSaltAndHash(t,e=jS.DefaultAlgo,r=jS.DefaultSpinCount){if(!t)return null;const n=(await LS()).getRandomValues(new Uint8Array(16)),o=PS(n.buffer);return{salt:o,hash:await jS._convertPasswordToHash(t,o,e,r)}}static async verifyPassword(t,e,r=jS.DefaultAlgo,n=jS.DefaultSpinCount){if(!t||!e)throw new Ft;return((t,e)=>{const r=t.length,n=e.length;let o=r===n?0:1;for(let s=0;s<Math.max(r,n);s++)o|=t.charCodeAt(s%r)^e.charCodeAt(s%n);return 0===o})(await jS._convertPasswordToHash(t,e.salt,r,n),e.hash)}static async _convertPasswordToHash(t,e,r,n){const o=await LS();r=r.toUpperCase();const s=(t=>{const e=new ArrayBuffer(2*t.length),r=new DataView(e);for(let e=0;e<t.length;e++)r.setUint16(2*e,t.charCodeAt(e),!0);return new Uint8Array(e)})(t),i=(t=>{const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r.buffer})(e);let a=await DS(o,r,i,s.buffer);for(let t=0;t<n;t++){const e=new Uint32Array([t]).buffer;a=await DS(o,r,a,e)}return PS(a)}}class HS{constructor(t,e=!1){this._emitter=null,this._emitter=new ml(this),this.fromJSON(t),this._isReadOnly=e}async lock(t,e,r,n){if(this._isReadOnly)return this;if(this.isLocked()&&!this._isPaused)throw new Error("Cannot lock an already locked object. Use unlock first.");try{this._validatePassword()}catch(t){throw new Error("A password is already set. Unlock first to change.")}let o;if(e){const t=await jS.generateSaltAndHash(e,r,n);o={salt:t.salt,hash:t.hash},r&&(o.algorithm=r),n&&(o.spinCount=n)}else o=null;return t=t??{},this._updateProperties(t),this._properties=t,this._password=o,this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),this}async unlock(t){if(this._isReadOnly)throw new Error("Cannot unlock a readonly workbook.");return await this._validatePassword(t),this._clearProperties(),this._password=null,this._identities=null,this._password=null,this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),this}checkPassword(t){return this._validatePassword(t)}hasPassword(){return null!==this._password}async pause(t){return this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),await this._validatePassword(t),this._password&&(this._isPaused=!0),this}resume(){return this._isPaused=!1,this}isPaused(){return this._isPaused}isLocked(){return null!==this._properties&&!this._isPaused}isReadOnly(){return this._isReadOnly}async _validatePassword(t){const e=this._password;if(!(t&&0!==t.length||e&&e.hash))return!0;if(!t)throw new Error("Password is required.");if(!await jS.verifyPassword(t,{salt:e.salt,hash:e.hash},e.algorithm,e.spinCount))throw new Error("Invalid password.");return!0}getProperties(){return this._properties}_isPropertyAllowed(t){if(this._isReadOnly)return!1;if(!this.isLocked())return!0;const e=this._properties[t];return"boolean"==typeof e&&e}_updateProperties(t){this._properties={...t,...this._properties??{}}}_clearProperties(){this._properties=null}addListeners(t,e){return this._emitter.addListeners(t,e)}fromJSON(t){this._password=null,this._identities=null,this._isPaused=!1,this._properties=null,this._fromJSON(t??null),t&&(t.password&&(this._password=t.password),t.identities&&(this._identities=t.identities))}_fromJSON(t){}_toJSON(t){return t}toJSON(){if(!this._properties)return null;let t={};return t=this._toJSON(t)??{},this._password&&(t.password=this._password),this._identities&&(t.identities=this._identities),t}}const VS=Object.freeze({selectLockedCells:!0,selectUnlockedCells:!0,autoFilter:!1,deleteColumns:!1,deleteRows:!1,formatCells:!1,formatColumns:!1,formatRows:!1,insertColumns:!1,insertHyperlinks:!1,insertRows:!1,objects:!1,pivotTables:!1,scenarios:!1,sheet:!1,sort:!1,verifier:null});class $S extends HS{isAutoFilterAllowed(){return this._isPropertyAllowed("autoFilter")}isDeleteColumnsAllowed(){return this._isPropertyAllowed("deleteColumns")}isDeleteRowsAllowed(){return this._isPropertyAllowed("deleteRows")}isFormatCellsAllowed(){return this._isPropertyAllowed("formatCells")}isFormatColumnsAllowed(){return this._isPropertyAllowed("formatColumns")}isFormatRowsAllowed(){return this._isPropertyAllowed("formatRows")}isInsertColumnsAllowed(){return this._isPropertyAllowed("insertColumns")}isInsertHyperlinksAllowed(){return this._isPropertyAllowed("insertHyperlinks")}isInsertRowsAllowed(){return this._isPropertyAllowed("insertRows")}isObjectsAllowed(){return this._isPropertyAllowed("objects")}isPivotTablesAllowed(){return this._isPropertyAllowed("pivotTables")}isScenariosAllowed(){return this._isPropertyAllowed("scenarios")}isSortAllowed(){return this._isPropertyAllowed("sort")}isSelectLockedCellsAllowed(){return!1}isSelectUnlockedCellsAllowed(){return!1}_updateProperties(t){super._updateProperties(t),this._properties=t}_clearProperties(){super._clearProperties(),this._properties=null}_fromJSON(t){super._fromJSON(t),this._properties=t}_toJSON(t){let e=this._properties;if(e){t={...t,...e};const r=Object.keys(e);for(let n=0;n<r.length;n++){const o=e[r[n]];null!=o&&o!==VS[r[n]]&&(t[r[n]]=o)}}return super._toJSON(t)}}class US{constructor(t,e,r){this._coords=Object.freeze(t),this._sheet=e,this._readOnly=r?.readOnly??null}_createRanges(t,e){let r=this._options;return e&&(r={...this._options,getOptions:Im(this._options?.getOptions,e)}),new US(t,this._sheet,r)}_createRange(t,e){let r=this._options;return e&&(r={...this._options,getOptions:Im(this._options?.getOptions,e)}),new GS(t,this._sheet,r)}_validateWrite(){const t=this._readOnly;if(t)throw new Error(t)}getCoords(){return this._coords}[Symbol.iterator](){const t=this.entries({excludeCellDetails:!0});return{next(){const e=t.next();return e.done?Cl:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}entries(t){const e=this.getCoords(),r=t?.reverse??!1;let n=r?e.length-1:0;const o=this;let s=o._createRange(e[n]),i=s.entries(t),a=i.next();return{next(){let l=a;do{if(a.done){if(n=r?n-1:n+1,n>=e.length||n<0)return a=Cl,l;s=o._createRange(e[n]),i=s.entries(t)}a=i.next()}while(a.done);return l},[Symbol.iterator](){return this}}}async select(t){const e=await this._sheet._autoSelect(t??!0,Nm(this.getCoords()));return this._createRanges(e)}calculate(){const t=this.getCoords();return this._sheet._calculate(t),this}addListener2(t,e){return this._sheet._addRangesListeners2(this.getCoords(),t,e,!0)}addListener(t,e){return this._sheet._addRangesListeners(this.getCoords(),t,e)}find(t,e){return this._sheet._find(this.getCoords(),t,e)}getFlattened(t){const e=this.getCoords();if(1===e.length)return this._createRanges(e,t);const r=t?.orientations??exports.t.Orientations.Both,n=r===exports.t.Orientations.Both,o=n?Number.MAX_SAFE_INTEGER:1,s=r===exports.t.Orientations.Row?exports.t.Orientation.Column:exports.t.Orientation.Row;let i=yc(e,o,s);if(n){const t=yc(e,o,exports.t.Orientation.Column);t.length<i.length&&(i=t)}return this._createRanges(i,t)}getVisible(t){const e=this._sheet._getVisible(this.getCoords(),t);return e&&0!==e.length?this._createRanges(e,t):null}getFixed(t){const e=[],r=this.getCoords();for(let n=0;n<r.length;n++)e.push(Em(r[n],t));return this._createRanges(e,t)}autoFit(t){return this._validateWrite(),this._sheet._autoFit(this.getCoords(),t),this}clear(t,e){return this._validateWrite(),this._sheet._clear(this.getCoords(),t,e),this}updateStyle(t,e){return this._validateWrite(),this._sheet._updateStyles(this.getCoords(),t,e),this}getStyleUpdater(){return this._sheet._getStyleUpdater(this.getCoords())}merge(t){return this._validateWrite(),this._sheet._merge(this.getCoords(),t),this}unmerge(t){return this._validateWrite(),this._sheet._unmerge(this.getCoords(),t),this}getMerges(){return this._sheet._getMerges(this.getCoords(),this._options?.excludeHidden??!1)}insert(t,e){return this._validateWrite(),this._sheet._insertCells(this.getCoords(),t,e),this}delete(t,e){return this._validateWrite(),this._sheet._deleteCells(this.getCoords(),t,e),this}async insertFrom(t,e){this._validateWrite();const r=await this._sheet._insertFrom(this.getCoords(),t,e);return r?this._createRanges([r]):null}async copyFrom(t,e){const r=await this._sheet._copyFrom(this.getCoords()[0],t,e);return r?this._createRanges([r]):null}isInvalidAny(){const t=this.getCoords();if(!t||0===t.length)return!0;for(let e=0;e<t.length;e++)if(null===t[e])return!0;return!1}getSnapshot(t){return this._sheet._getSnapshot(this.getCoords(),t)}getEntireRows(t,e){return this._createRanges(om(this.getCoords(),this._sheet._entireCoords,exports.t.Orientation.Column,t),e)}getEntireColumns(t,e){return this._createRanges(om(this.getCoords(),this._sheet._entireCoords,exports.t.Orientation.Row,t),e)}getDefaultShiftOrientation(){return this._sheet._getDefaultShiftOrientation(this.getCoords()[0])}getCount(){return this.getCoords()?.length??0}getCounts(t){return this._sheet._contentCounts(this.getCoords(),t,this._options?.excludeHidden??!1)}isContentful(){return this._sheet._isContentful(this.getCoords(),this._options?.excludeHidden??!1)}getRowCount(){return am(this.getCoords(),exports.t.Orientation.Row)}getColumnCount(){return am(this.getCoords(),exports.t.Orientation.Column)}isEntireRowsAny(){return sm(this.getCoords(),this._sheet._entireCoords,!1)}isEntireColumnsAny(){return im(this.getCoords(),this._sheet._entireCoords,!1)}isEntireRows(){return sm(this.getCoords(),this._sheet._entireCoords,!0)}isEntireColumns(){return im(this.getCoords(),this._sheet._entireCoords,!0)}isOverlapping(){return mh(this.getCoords())}at(t){const e=this.getCoords();if(t<0||t>e.length-1)throw new Mt;return this._createRange(e[t])}isReadOnly(){return null!==this._readOnly}isInvalid(){return!1}getA1(){return gd(this.getCoords(),this._sheet._entireCoords,ad,rd)}getSource(){return this._sheet}doBatch(t,e){return this._sheet.doBatch(e=>t(e),"string"==typeof e?e:{description:"Ranges Update",...e})}get[Symbol.toStringTag](){return"[SheetRanges]"}toString(){return this.getA1()}get isICellRanges(){return!0}}class GS{constructor(t,e,r){this._coords=Object.freeze(t),this._sheet=e,this._readOnly=r?.readOnly??null}getCoords(){return this._coords}_createRange(t,e){const r=this._sheet;if(!t)return _m(r,r._entireCoords);if(r._validateCoords(t),r._closed)return _m(null,r._entireCoords,t);let n=this._options;return e&&(n={...this._options,getOptions:Im(this._options?.getOptions,e)}),new GS(t,this._sheet,n)}_createRanges(t,e){let r=this._options;return e&&(r={...this._options,getOptions:Im(this._options?.getOptions,e)}),new US(t,this._sheet,r)}_deriveRanges(t,e){const r=this.getCoords();let n=r;return e&&(n=e(r),!n)?null:this._createRanges(n,t)}_deriveRange(t,e,r){if(!t)return this;let n=this._sheet._rangeToCoords(t);if(!n)return this;const o=this.getCoords();if(bm(n,o))return this;if(r){const t=r(n,o);if(!t)return this;n={...o,...t}}var s,i;return s=n,(i=o)&&(void 0===i.$colStart?delete s.$colStart:s.$colStart=i.$colStart,void 0===i.$rowStart?delete s.$rowStart:s.$rowStart=i.$rowStart,void 0===i.$colEnd?delete s.$colEnd:s.$colEnd=i.$colEnd,void 0===i.$rowEnd?delete s.$rowEnd:s.$rowEnd=i.$rowEnd),this._createRange(n,Im(this._options?.getOptions,e))}_validateMaxSize(t=5e4){const e=this.getCoords(),r=this._sheet,n=r._colHeaders.getVisibleCount(e.colStart,e.colEnd);if(r._rowHeaders.getVisibleCount(e.rowStart,e.rowEnd)*n>t)throw new Error(au(t))}[Symbol.iterator](){const t=this.entries({excludeCellDetails:!0});return{next(){const e=t.next();return e.done?Cl:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}entries(t){const e=this.getCoords();let r=e;const n=this._sheet;if(t?.address){const o=n._rangeToCoords(t?.address);if(!o)throw new Error(Od(t?.address));if(r=U.intersectRanges(o,e),!r)return bl}r.colEnd<r.colStart&&(r.colStart=e.colStart,r.colEnd=e.colEnd),r.rowEnd<r.rowStart&&(r.rowStart=e.rowStart,r.rowEnd=e.rowEnd);const o=this._options?.excludeHidden??!1;return n._cellIterator({excludeHidden:o,...t,includeRangeTypes:!t?.excludeCellDetails,bounds:r})}forEach(t,e){if(!t)return;const r=this.entries(e);let n=r.next();for(;!n.done;){const e=n.value,o=t(e.value,e.context);if(o)return o.break;n=r.next()}}_validateWrite(){const t=this._readOnly;if(t)throw new Error(t)}updateCells(t,e,r){this._validateWrite();const n=this.getCoords();r||(r=n);const o=this._sheet,s=o._isDataColumn,i={majorStart:s?n.colStart:n.rowStart,majorEnd:s?n.colEnd:n.rowEnd,minorStart:s?n.rowStart:n.colStart,minorEnd:s?n.rowEnd:n.colEnd},a=(e?.orientation??exports.t.Orientation.Row)===exports.t.Orientation.Column!==s,l=Dc(Array.isArray(t)?t:[[t]],a,i);return o._updateTuples(l,{description:e?.description??`Set ${U.isSingleCell(r)?"Cell":"Range"} ${ad(r,o._entireCoords)}`,...e},null,{isCell:!0}),this}setValue(t,e){if(Array.isArray(t))throw new Error("'setValue' expects a single value; when working with an array use 'setValue'.");return this._setValueOrValues(t,e)}setValues(t,e){if(!Array.isArray(t))throw new Error("'setValues' expects a 2d array; when working with a single value use 'setValue'.");return this._setValueOrValues(t,e)}_setValueOrValues(t,e){this._validateWrite();let r=this.getCoords(),n=this;const o=this._sheet,s=o._isDataColumn,i=(e?.orientation??exports.t.Orientation.Row)===exports.t.Orientation.Column,a=Array.isArray(t);if(e?.skipBoundsCheck&&a){const o=t;let s=Math.max(0,o.length-1),a=0;for(let t=0;t<o.length;t++)a=Math.max(a,o[t].length-1);const l=i?r.colStart:r.rowStart,c=i?r.rowStart:r.colStart,h={...r,colEnd:i?l+s:c+a,rowEnd:i?c+a:l+s};U.isEqualRanges(h,r)||(r=h,n=this._deriveRange(h,e))}const l={majorStart:s?r.colStart:r.rowStart,majorEnd:s?r.colEnd:r.rowEnd,minorStart:s?r.rowStart:r.colStart,minorEnd:s?r.rowEnd:r.colEnd},c=i!==s;let h=null;return h=a?Dc(Array.isArray(t)?t:[[t]],c,l):Lc(t,l,s),o._updateTuples(h,{description:e?.description??`Set ${U.isSingleCell(r)?"Value":"Values"} ${ad(r,o._entireCoords)}`,...e}),n}getValues(t){this._validateMaxSize(t?.maxSize);const e=this.getCoords(),r=this._sheet;return Cm(r._cellIterator.bind(this._sheet),e,!1,t)}getValue(t){const e=this.getCoords();return this._sheet._getScalar(e.rowStart,e.colStart,t?.asJSDate)}calculate(t){return this._sheet._calculate([this.getCoords()],{full:t}),this}getCells(t){this._validateMaxSize(t?.maxSize);const e=this.getCoords(),r=this._sheet;return Cm(r._cellIterator.bind(this._sheet),e,!0,t)}getCell(){const t=this.getCoords(),e=this._sheet,r=Cm(e._cellIterator.bind(this._sheet),{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart,rowEnd:t.rowStart},!0,null);return 0===r.length?e._emptyCell:r[0][0]}async select(t){const e=this._sheet,r=await e._autoSelect(t??!0,Nm([this.getCoords()]));return this._createRange(r[0])}find(t,e){return this._sheet._find([this.getCoords()],t,e)}getFixed(t){return this._createRange(Em(this.getCoords(),t))}getSurrounding(t){const e=this._sheet;return this._createRange(e._surroundingRegion(this.getCoords(),t))}getExtended(t,e){let r=null;const n=this.getCoords();switch(t){case exports.t.Direction.Up:r={colIndex:n.colStart,rowIndex:n.rowStart};break;case exports.t.Direction.Down:r={colIndex:n.colStart,rowIndex:n.rowEnd};break;case exports.t.Direction.Left:r={colIndex:n.colStart,rowIndex:n.rowStart};break;case exports.t.Direction.Right:r={colIndex:n.colEnd,rowIndex:n.rowStart}}const o=this._sheet,s=e?o._cellToCoords(e):r;if(!U.isCellWithinRange(s,n))throw new Error("Invalid cell.");let i=o._extendRange(t,s);return i=U.unionRanges(n,i),this._createRange(i)}getEntireRows(t,e){const r=this._sheet;return this._createRange(om([this.getCoords()],r._entireCoords,exports.t.Orientation.Column,t)[0],e)}getEntireColumns(t,e){const r=this._sheet;return this._createRange(om([this.getCoords()],r._entireCoords,exports.t.Orientation.Row,t)[0],e)}getRowHeaders(t){const e=this.getCoords();return this._sheet._rowHeaders.getRange(e,t)}getColumnHeaders(t){const e=this.getCoords();return this._sheet._colHeaders.getRange(e,t)}getDifferences(t,e){return this._deriveRanges(e,r=>{const n=this._sheet,o=n._rangeToCoords(t),s=fh(r,o,exports.t.Orientation.Row);return n._getVisible(s,e)})}getIntersect(t,e){return this._deriveRange(t,e,(t,e)=>U.intersectRanges(t,e))}getUnion(t,e){return this._deriveRange(t,e,(t,e)=>U.unionRanges(t,e))}getResizeTo(t,e,r){if(e=e??0,(t=t??0)<0||e<0)throw new Error("Invalid range. The Range must be at a size of at least 1x1'.");const n=this.getCoords();return this._deriveRange({colStart:n.colStart,rowStart:n.rowStart,colEnd:e+n.colStart-1,rowEnd:t+n.rowStart-1},r)}getResizeBy(t,e,r){t=t??0,e=e??0;const n=this.getCoords();return this._deriveRange({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd+e,rowEnd:n.rowEnd+t},r)}getOffsetTo(t,e,r){const n=this.getCoords(),o=e,s=t,i={colStart:o,rowStart:s,colEnd:n.colEnd-n.colStart+o,rowEnd:n.rowEnd-n.rowStart+s};return this._deriveRange(i,r)}getOffsetBy(t,e,r){const n=this.getCoords(),o=n.colStart+t,s=n.rowStart+e,i={colStart:o,rowStart:s,colEnd:n.colEnd-n.colStart+o,rowEnd:n.rowEnd-n.rowStart+s};return this._deriveRange(i,r)}getUsedRange(t){const e=this._sheet._getUsedCoords(t);if(!e)return null;const r=U.intersectRanges(e,this.getCoords());return r?this._deriveRange(r,t):null}isEmpty(){const t=this._sheet._getUsedCoords();if(!t)return!0;return!U.intersectRanges(t,this.getCoords())}getColumnStart(){return this.getCoords().colStart}getRowStart(){return this.getCoords().rowStart}getColumnEnd(){return this.getCoords().colEnd}getRowEnd(){return this.getCoords().rowEnd}getColumnCount(){const t=this.getCoords();return t.colEnd-t.colStart+1}getRowCount(){const t=this.getCoords();return t.rowEnd-t.rowStart+1}getVisible(t){return this._deriveRanges(t,e=>this._sheet._getVisible([e],t))}isContentful(t){return this._sheet._isContentful([this.getCoords()],t,this._options?.excludeHidden??!1)}getCounts(t){return this._sheet._contentCounts([this.getCoords()],t,this._options?.excludeHidden??!1)}getCount(t){return this._sheet._getCount([this.getCoords()],t,this._options?.excludeHidden??!1)}isEntireRows(){const t=this._sheet;return sm([this.getCoords()],t._entireCoords,!0)}isEntireColumns(){const t=this._sheet;return im([this.getCoords()],t._entireCoords,!0)}isEntireRange(){const t=this.getCoords(),e=this._sheet;return im([t],e._entireCoords,!0)&&sm([t],e._entireCoords,!0)}getWidth(){const t=this._coords;return t.colEnd-t.colStart+1}getHeight(){const t=this._coords;return t.rowEnd-t.rowStart+1}get size(){const t=this._coords;return t.colEnd-t.colStart+1*(t.rowEnd-t.rowStart+1)}getBounds(){return this._sheet._getBoundsAtCoords(this.getCoords())}isInvalid(){return!1}getDefaultShiftOrientation(){return this._sheet._getDefaultShiftOrientation(this.getCoords())}getDefaultSortCriteria(t,e){return this._sheet._getDefaultSortCriteria(this.getCoords(),t,e)}getMerges(){return this._sheet._getMerges([this.getCoords()],this._options?.excludeHidden??!1)}getSnapshot(t){return this._sheet._getSnapshot([this.getCoords()],t)}isReadOnly(){return null!==this._readOnly}addListener2(t,e){return this._sheet._addRangesListeners2([this.getCoords()],t,e,!1)}addListener(t,e){return this._sheet._addRangesListeners([this.getCoords()],t,e)}getSource(){return this._sheet}autoFill(t,e){this._validateWrite();const r=this._sheet,n=r._rangeToCoords(t,()=>[],!0);return r._autoFill(this.getCoords(),n,e)?this._createRange(n):this}autoFit(t){this._validateWrite();return this._sheet._autoFit([this.getCoords()],t),this}clear(t,e){this._validateWrite();return this._sheet._clear([this.getCoords()],t,e),this}setHyperlink(t,e){this._validateWrite();return this._sheet._setHyperlinks([this.getCoords()],t,e),this}setComments(t,e){this._validateWrite();return this._sheet._setComments([this.getCoords()],t,e),this}setFormula(t,e){this._validateWrite();return this._sheet._setFormula([this.getCoords()],t,e),this}updateStyle(t,e){this._validateWrite();return this._sheet._updateStyles([this.getCoords()],t,e),this}getStyleUpdater(){return this._sheet._getStyleUpdater([this.getCoords()])}merge(t){this._validateWrite();return this._sheet._merge([this.getCoords()],t),this}unmerge(t){this._validateWrite();return this._sheet._unmerge([this.getCoords()],t),this}insert(t,e){this._validateWrite();return this._sheet._insertCells([this.getCoords()],t,e),this}async insertFrom(t,e){this._validateWrite();const r=this._sheet,n=await r._insertFrom([this.getCoords()],t,e);return n?this._createRange(n):null}async copyFrom(t,e){this._validateWrite();const r=this._sheet,n=await r._copyFrom(this.getCoords(),t,e);return n?this._createRange(n):null}delete(t,e){this._validateWrite();return this._sheet._deleteCells([this.getCoords()],t,e),this}sort(t){this._validateWrite();const e=this.getCoords(),r=this._sheet._sort(e,t);return U.isEqualRanges(r,e)?this:this._createRange(r)}doBatch(t,e){return this._sheet.doBatch(e=>t(e),"string"==typeof e?e:{description:"Range Update",...e})}startIncrementalUpdates(t){return this._sheet._createIncrementalUpdater(t,this)}getA1(){const t=this._sheet;return ad(this.getCoords(),t._entireCoords)}get[Symbol.toStringTag](){return"[SheetRange]"}toString(){const t=this._sheet;return ad(this.getCoords(),t._entireCoords)}get isICellRange(){return!0}}const WS=Math.pow(2,14),qS=Math.pow(2,20),JS=t=>`${t}`,XS=t=>Qh(t),KS=t=>`${t+1}`;let YS=0;const ZS=()=>[];let QS=0;class tw{constructor(t){this._lastTransactionUUID=null,this._emitter=null,this._initializing=!0,this._emitterMovables=null,this._rangesListenerSorted=null,this._lastCellDecoded={address:null,coords:null},this._lastCellSelected={coords:null,cell:null},this._lastCellRead={coords:null,cell:null},this._lastValueRead={range:null,isDateOrTime:null},this._lastGetRangeRead={},this._lastUsedCoordsRead={coords:null,range:null},this._lastActiveRead={selection:null,range:null,ranges:null},this._lastRangeRead={address:null,range:null,ranges:null},this._isDataColumn=!0,this._isDate1904=!1,this._colHeaders=null,this._colHeadersShiftCallback=null,this._colHeadersListener=null,this._colHeadersRemoveListener=null,this._rowHeaders=null,this._rowHeadersShiftCallback=null,this._rowHeadersListener=null,this._rowHeadersRemoveListener=null,this._closed=!1;const e=Object.freeze({...t});xe._validate(!0),this._transactions=e.transactions??new re,this._ownTransactions=!e.transactions;const r=this._beginCommit({description:"New Sheet"}),n=this;try{this._entireCoords=Object.freeze({colStart:0,rowStart:0,colEnd:(e.maxColumns??WS)-1,rowEnd:(e.maxRows??qS)-1}),this._strings=e.strings??new pf,this._ownStrings=!e.strings;const t=e.styles??new af;this._styles=t,this._ownStyles=!e.styles,this._names=e.names??new J_({addressToRanges:t=>n.getRanges(t),getCurrentScope:()=>n.getName(),isReadOnly:()=>n._options.readonly??!1,transactions:n._transactions}),this._ownNames=!e.names,this._namesRemoveListener=this._names.addListeners({onCollectionChange:t=>{n._calculateFull()}},{transactional:!1}),this._calculation=e.calculation??new M_({getNamed:(t,e)=>{ew.address=t,ew.scope=e;const r=this._names.search({address:t,scope:e});return r&&0!==r.length?r[0].getRanges().getCoords():null},getSheetIndex:t=>void 0===t||t===n.getName()?1:0,getSheetCount:()=>1,isDate1904:()=>n.isDate1904(),strings:n._strings,transactions:n._transactions}),this._ownsCalculation=!e.calculation,this._normalStyleRanged=t.getNamed(exports.IStyle.BuiltInName.Normal).getRanged(),this._resources=e.resources??new uf,this._ownResources=!e.resources;const o=async()=>{this._ownsCalculation&&await this._calculation.start(),this._starting=null};this._starting=o(),e.container?.setNameChangeCallback&&e.container.setNameChangeCallback(()=>{n._emitter.notify("onNameChange");const t=this._getState().rangesListenerMap,e=new Map;t.forEach((t,r)=>{e.set(r,{beforeState:t,afterState:t})});const r=this._beginCommit({description:"Set Name"});r.updateState(n,{}),r.commit({viewAfter:{ranges:[n._entireCoords],listeners:e},forceAmend:!0}),n._calculateFull()}),e.container?.setVisibilityCallback&&e.container.setVisibilityCallback(()=>{n._emitter.notify("onVisibilityChange")}),e.container?.setIndexCallback&&e.container.setIndexCallback(()=>{n._calculateFull()}),this._movables=new P_(this._addMovable.bind(this),this._searchMovables.bind(this),()=>{const t=n._getState();return t?t.movableMapModel?.size??0:0},this._updateSelectedMovables.bind(this),(t,e)=>this._emitterMovables.addListeners(t,e),this._addImage.bind(this)),this._emitterMovables=new ml(this._movables,this._transactions),this._tables=new Q_(this._addTable.bind(this),(t,e,r)=>{const o=t?this._rangeToCoords(t):this._entireCoords;return n._getRangedEntries("tableSpatial",[o],{excludeHidden:e,fullyContained:r,onEntry:t=>t.model})},t=>{const e=n._getState();return e?e.tableMapName.get(t.toLocaleLowerCase()):null}),this._conditionals=new lS(this._addConditional.bind(this),(t,e,r)=>{const o=t?this._rangeToCoords(t):this._entireCoords,s=new Set;return n._getRangedEntries("conditionalSpatial",[o],{excludeHidden:e,fullyContained:r,onEntry:t=>{s.add(t.getModel())}}),Array.from(s)}),this._isDate1904=e.date1904??!1,this._options=e,this._emitter=new ml(this,this._transactions),this._entireRange=this.getRange(this._entireCoords),this._initState(),e?.container?.beforeFromJSON?.(this),e.json&&this._fromJSON(e.json),r.commit({viewAfter:{initial:!0,skipProtectionCheck:!0}})}catch(t){throw r.rollback(),t}this._initializing=!1}_createRange(t,e,r=null){if(!t)return _m(this,this._entireCoords);if(this._validateCoords(t),this._closed)return _m(null,this._entireCoords,t);null===r&&this._options.readonly&&(r="Readonly sheet");let n=null;return(e||r)&&(n={getOptions:e,readOnly:r}),new GS((t=>{if(!t)return null;const e={colStart:t.colIndex??t.colStart??0,rowStart:t.rowIndex??t.rowStart??0,colEnd:t.colIndex??t.colEnd??0,rowEnd:t.rowIndex??t.rowEnd??0};return(t.$colStart||t.$colIndex)&&(e.$colStart=!0),(t.$colEnd||t.$colIndex)&&(e.$colEnd=!0),(t.$rowStart||t.$rowIndex)&&(e.$rowStart=!0),(t.$rowEnd||t.$rowIndex)&&(e.$rowEnd=!0),e})(t),this,n)}_createRanges(t,e,r=null){let n=null;return null===r&&this._options.readonly&&(r="Readonly sheet"),(e||r)&&(n={getOptions:e,readOnly:r}),new US(t,this,n)}getRange(t,e){let r=!e&&t&&(void 0!==t.rowStart||"string"==typeof t);if(r)if("string"==typeof t){if(this._lastRangeRead.address===t)return this._lastRangeRead.range}else if(void 0!==t.rowStart&&bm(t,this._lastRangeRead.address))return this._lastRangeRead.range;const n=this._rangesToCoords(t);if(n.length>1)throw new Error(Nd);const o=this._createRange(n[0],e);return r&&(this._lastRangeRead.address={...t},this._lastRangeRead.range=o),o}getRanges(t,e){if(!t)throw new Error(Fd);const r=this._rangesToCoords(t);if(0===r.length)throw this._createRangeError(t);return this._createRanges(r,e)}getSelectedRange(t){const e=this.getSelection().getCoords();if(!t&&this._lastActiveRead.selection===e&&this._lastActiveRead.range)return this._lastActiveRead.range;const r=Fm(e),n=this.getRange(r[0]);return t||(this._lastActiveRead.selection=e,this._lastActiveRead.range=n,this._lastActiveRead.ranges=this.getRanges(r)),n}getSelectedRanges(t){const e=this.getSelection().getCoords();if(!t&&this._lastActiveRead.selection===e&&this._lastActiveRead.ranges)return this._lastActiveRead.ranges;const r=Fm(e),n=this.getRanges(r,t);return t||(this._lastActiveRead.selection=e,this._lastActiveRead.ranges=n,this._lastActiveRead.range=this.getRange(r[0])),n}getEntireRange(t){if(!t)return this._entireRange;return this.getRange(this._entireCoords,t)}getUsedRange(t){const e=this._getUsedCoords(),r=e?this.getRange(e,t):null;return t||(this._lastUsedCoordsRead.coords=e,this._lastUsedCoordsRead.range=r),r}_cellToCoords(t){if(this._lastCellDecoded.address===t)return this._lastCellDecoded.coords;const e=this._rangeToCoords(t);if(!e||!U.isSingleCell(e))throw new Error("Only a single cell is allowed.");const r={colIndex:e.colStart,rowIndex:e.rowStart};return this._lastCellDecoded.address=t,this._lastCellDecoded.coords=r,r}_validateCoords(t,e=Kd){if(!U.isRangeWithinRange(t,this._entireCoords))throw new Mt(e);const r=t.colStart,n=t.rowStart,o=t.colEnd,s=t.rowEnd;if(s<n||o<r)throw new Error(kd);if(!(Number.isInteger(r)&&Number.isFinite(r)&&Number.isInteger(n)&&Number.isFinite(n)&&Number.isInteger(o)&&Number.isFinite(o)&&Number.isInteger(s)&&Number.isFinite(s)))throw new Error("Invalid range. All points must be valid integers.")}_createRangeError(t){return t?new Error(Fd):new Error(Od(t))}_protectionCheck(t=null,e=null,r=null){if(t&&this._closed)return;if(!this._initializing&&this._options.readonly)throw new Error(((t="update")=>`Unable to ${t}, this sheet is readonly.`)(r));e&&!Array.isArray(e)&&(e=[e]);const n=t(e),o=this.getProtection(),s=o?.getProperties();if(s){if(0===n.length)throw new Error(Jd);if(n){const t=n.length;for(let e=0;e<t;e++){if(!0!==o[n[e]])throw new Error(Xd())}}}}_rangesToCoords(t,e=null,r=!0,n=!1){if(e&&this._closed)return mt.EmptyArray;if(null==t)return mt.EmptyArray;const o=this,s=md(t,this._entireCoords,n?hd:dd,t=>{if(r&&"string"==typeof t){const e=o.getNames()?.getByName(t);if(e)return e.getRanges().getCoords();const r=this._options.resolveRange?.(t);if(r&&r.getSource()===o)return console.warn(iu),[r.getCoords()];throw new Error(`Invalid sheet reference '${t}'.`)}}),i=s.length;for(let t=0;t<i;t++){const e=s[t];if(e){if(n){const t=e.sheetName;if(t&&t!==this.getName())throw new Error(iu)}this._validateCoords(e)}}if(!e)return s;if(0===s.length)throw this._createRangeError(t);return this._protectionCheck(e,s),s}_rangeToCoords(t,e=null,r=!0){if(!t)throw new Error(Fd);const n=e?t=>e(t):void 0,o=this._rangesToCoords(t,n,r);if(0===o.length)throw new Error(Od(t));return o[0]}_collectRanges(t,e=[],r=!0,n=this._getState(),o=!1){if(!r||0===Object.keys(r).length)return;const s=t=>!0===r||void 0!==r[t],i=(n,o,s)=>{if(!0!==r&&void 0===r[n])return;const i=o.search(t,!1),a=i.length;if(0===a)return;const l=r[n];for(let r=0;r<a;r++){const n=i[r];if(l&&!U.isRangeWithinRange(t,n))continue;const o=U.intersectRanges(t,n);let a=n.value;void 0===a&&(a=!0),e.push({...o,value:{[s]:a}})}};if(s($d.Type.Merge)&&n.mergeSpatial){const r=n.mergeSpatial.search(t),s=r.length;for(let n=0;n<s;n++){const s=r[n],i=o?s:U.intersectRanges(t,s);e.push({...i,value:{merge:s.value}})}}if(i($d.Type.Unlock,n.unlockSpatial,"unlock"),i($d.Type.Contentful,n.contentfulSpatial,"contentful"),i($d.Type.Continuous,n.continuousFillSpatial,"continuous"),i($d.Type.Hyperlink,n.hyperlinkSpatial,"hyperlink"),i($d.Type.Comments,n.commentsSpatial,"comments"),i($d.Type.Style,n.directStyleSpatial,"directStyle"),i($d.Type.Formula,n.formulaSpatial,"formula"),i($d.Type.Pending,n.pendingSpatial,"pending"),i($d.Type.CalcError,n.calcErrorsSpatial,"calcError"),i($d.Type.Spill,n.spillSpatial,"spills"),s($d.Type.Conditional)&&n.conditionalSpatial){const o=n.conditionalSpatial.search(t),s=r[$d.Type.Conditional],i=o.length;for(let r=0;r<i;r++){const n=o[r],i=U.intersectRanges(t,n);s&&!i||e.push({...i,value:{conditionals:[n.value]}})}}if(s($d.Type.Table)&&n.tableSpatial){const o=n.tableSpatial.search(t),s=r[$d.Type.Table],i=o.length;for(let r=0;r<i;r++){const n=o[r];if(s&&!U.isRangeWithinRange(t,n))continue;const i=U.intersectRanges(t,n);e.push({...i,value:{table:n.value.model}})}}}_cellIterator(t){const e=this._cellOptions,r=this._strings,n=this._cellStateIterator(t);return{next(o){const s=n.next(o);if(s.done)return Cl;const i=s.value,a=new vm(r,t,e),l=a.context;return{done:!1,value:{value:a.setState(i),context:l}}},[Symbol.iterator](){return this}}}_rangeStateIterator(t){const e=this._getState();if(!e||!t||!t.includeRangeTypes)return bl;const r=t?.bounds??this._getUsedCoords()??this._entireCoords;let n=null;!0===t.includeRangeTypes?n=Ud:mt.isObject(t.includeRangeTypes)&&(n=t.includeRangeTypes);const o=t?.excludeHidden,s=!0===o||o===exports.t.Orientation.Row,i=!0===o||o===exports.t.Orientation.Column,a=[],l=this,c={includeHidden:!i},h={min:r.colStart,max:r.colEnd},d={includeHidden:!s},u={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(u).forEachVisibleSpan((t,r)=>{this._colHeaders.getRange(h).forEachVisibleSpan((o,s)=>{l._collectRanges({rowStart:t,rowEnd:r,colStart:o,colEnd:s},a,n,e)},c)},d);const g=new Fl.IteratorInstance(a,t),p=t?.reverse??!1,m=t?.byCell;let f;const _={next:t=>{if(f=g.next(t),f.done)return Cl;const e=f.value,r=e.range,n={colIndex:r.colStart,rowIndex:r.rowStart},o={colIndex:r.colEnd,rowIndex:r.rowEnd};let s=null;m&&(s={...e.cell});const i=(t=>{if(!t)return null;let e=null;const r=t.length;for(let n=0;n<r;n++){const r=t[n].value;if(!r)continue;e||(e={...e});const o=Object.keys(r),s=o.length;for(let t=0;t<s;t++){const n=o[t],s=e[n];if(s)if(Array.isArray(s)){const t=r[n];if(Array.isArray(t)){const e=t.length;for(let r=0;r<e;r++)s.push(t[r])}else s.push(t)}else e[n]=[s,r[n]];else e[n]=r[n]}}return e})(e.overlaps);return{done:!1,value:{start:p?o:n,end:p?n:o,cell:s,intersection:i}}}};return _}_cellStateIterator(t){const e=this._getState();if(!e)return bl;const r=t?.bounds??this._entireCoords,n=t?.orientation??exports.t.Orientation.Row,o=t?.reverse??!1,s=t?.includeEmpty,i={bounds:r,orientation:n,reverse:o};let a;s&&(a={bounds:r,orientation:n,reverse:o});const l=t?.excludeHidden;if(!0===l||l===exports.t.Orientation.Row){const t=xm(this._rowHeaders);i.processRowSkip=xl(t),s&&(a.processRowSkip=xl(t))}if(!0===l||l===exports.t.Orientation.Column){const t=xm(this._colHeaders);i.processColumnSkip=xl(t),s&&(a.processRowSkip=xl(t))}const c=s||!t?.ignoreEmptyIntersections;let h=t.includeRangeTypes;!0===h&&(h=Gd);const d=this._getState().contentfulSpatial,u=h?this._rangeStateIterator({bounds:r,orientation:n,reverse:o,includeRangeTypes:h,excludeHidden:t.excludeHidden,byCell:!0}):bl,g=t?.includeMergeOverflow??!1,p=e?.cellValuesGrid??null;let m=p?p.entries(i):bl,f=m.next(),_=null,S=null,w=null;f.done||(_=f.value[0],S=f.value[1]);let y=u.next(),x=null;const C=n!==exports.t.Orientation.Row;let b;const E=U.createCellComparator(n,o);let v;if(!y.done){const t=y.value;v=t.start,x=t.intersection}b=t=>{let e=null,r=null,n=null,o=!1,s=!1;if(_&&v){const t=E(_,v);t<0?(e=_,r=S,o=!0):t>0?(e=v,n=x,s=!0):(e=_,r=S,n=x,o=!0,s=!0)}else if(_)e=_,r=S,o=!0;else{if(!v||!c)return Cl;e=v,n=x,s=!0}if(o&&(f=m.next(),f.done?_=null:(_=f.value[0],S=f.value[1])),s){const t=c?void 0:_;if(y=u.next(t),y.done)v=null,x=null;else{const t=y.value;v=t.cell,x=t.intersection}}let i=!1;const a=e.rowIndex,l=e.colIndex;C||(i=a===w?.rowIndex);let h=!1;C||(h=a===_?.rowIndex);let p=null;if(i)p=w;else if(g&&!w){uw.rowStart=a,uw.rowEnd=a,uw.colStart=l-5,uw.colEnd=l-1;const t=d.search(uw,!1);if(t.length>0){t.sort(U.columnFirstRangeComparator);const e=t[t.length-1];p={colIndex:e.colStart,rowIndex:e.rowStart}}}let b=null;if(h)b=_;else if(g&&!_){uw.colStart=l+1,uw.rowStart=a,uw.colEnd=l+5,uw.rowEnd=a;const t=d.search(uw,!1);if(t.length>0){t.sort(U.columnFirstRangeComparator);const e=t[0];b={colIndex:e.colStart,rowIndex:e.rowStart}}}return o&&(w=e),{done:!1,value:[e,r,n,p,b]}};let I={next:b,return:t=>null,throw:t=>null};return s&&(I=new Nc(I,i)),I}_indexMerges(t,e=null){if(!(t&&0!==t.length||e&&0!==e.length))return;const r=this._getState();if(!r)return;const n=this._beginCommit({description:"indexMerges"}),o=r.mergeSpatial.clone();if(e){const t=e.length;for(let r=0;r<t;r++)o.remove(e[r])}if(t){const e=qd,r=t=>this._getState().cellValuesGrid.getValueAt(t.rowStart,t.colStart),n=t=>{const r=this._getState();if(!r)return;const n=[];this._collectRanges(t,n,e,r);return{...n?.[0]??null}},s=[],i=t.length;for(let e=0;e<i;e++){const o=t[e];s.push({...o,value:new IS(o,r,n)})}o.load(s)}this._updateState({mergeSpatial:o}),n.commit()}_updateStyles(t,e,r,n=!1){const o=r?.description??"Update Style";this._protectionCheck(()=>["formatCells"],t,o);const s=this._beginCommit({description:o}),i=Tm(t);try{const o=this._getState();if(!o)return mt.EmptyArray;const a=o.directStyleSpatial,l=s.getId(),c=a.clone(l);let h=o.continuousFillSpatial;const d=!h.isEmpty();let u=null;const g=this._styles,p=t.length;for(let r=0;r<p;r++){const o=(t,e)=>{let r=null;const n=wp(0,e,()=>{if(r)return r;const e=t.getCoords();return r=kp(g,t,e),r});return t.cloneWithUpdate(n)},s=t[r],i=s.value,a=void 0!==i?i:e,l=o(new Lp(g,s),a),h=(t,e)=>{if(n&&t.value&&t.value.getProperties()?.numberFormat)return t;const r=U.sanitizeRange(t);let s=null,i=t.value;"function"==typeof a&&i?s=o(i,a):(i||(i=new Lp(g,r)),s=i.cloneWithUpdate(e.value._p??null)),s.isEmpty()&&(s=null);let l=!1;if(s){const t=s._p?.alignment?.horizontal;!t||t!==exports.ITextFrame.HorizontalAlignment.CenterContinuous&&t!==exports.ITextFrame.HorizontalAlignment.Fill||(l=!0)}return(l||d)&&(u||(u=[]),u.push({...t,value:l?s:null})),{...e,value:s}};c.insertNonOverlapping({...s,value:l},{onIntersect:h})}if(u){h=h.clone();const t=u.length;for(let e=0;e<t;e++){const t=u[e];h.insertNonOverlapping(t)}}if(this._lastUsedCoordsRead.coords=null,this._updateState({directStyleSpatial:c,continuousFillSpatial:h}),r?.autoFit){const e="boolean"==typeof r.autoFit?dw:r.autoFit;this._autoFit(t,e)}this._emitter.notify("onStyleChange"),n?s.commit({forceAmend:!0}):this._commitAndAutoSelect(s,i,r?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw s.rollback(),t}}_createIncrementalUpdater(t,e=null,r){const n=t?.orientation??exports.t.Orientation.Row,o=t?.allowUnorderedWrites??!1,s=n===exports.t.Orientation.Column,i=this._isDataColumn,a=s!==i,l=this;let c,h,d,u=a?new exports.Tuple.TransposedBuilder:new exports.Tuple.Builder,g=null;if(e){const t=e.getCoords(),r=t.colStart,n=t.rowStart,o=t.colEnd,s=t.rowEnd;g=(t,e)=>{if(t<n||t>s||e<r||e>o)throw new Mt}}s?(h=(t,e,r)=>(g?.(t,e),u.addValue(e,t,r),c),d=(t,e,r)=>(g?.(t,e+(r?.length??0)),u.addValues(e,t,r),c)):(h=(t,e,r)=>(g?.(t,e),u.addValue(t,e,r),c),d=(t,e,r)=>(g?.(t+(r?.length??0),e),u.addValues(t,e,r),c));const p=t=>{const n=u.build();return n&&l._updateTuples(n,t,null,r),e},m=!1!==o?U.createCellComparator(t?.orientation):null,f=mt.isObject(o)?o:void 0;let _=null;return c=Object.freeze({push:(t,e)=>{const r=l._cellToCoords(t);return m&&(_&&m(r,_)<=0&&(p(f),u=a?new exports.Tuple.TransposedBuilder:new exports.Tuple.Builder),_=r),h(s?r.colIndex:r.rowIndex,s?r.rowIndex:r.colIndex,e)},pushAt:h,pushMultipleAt:d,apply:p}),c}_updateTuples(t,e,r=void 0,n=null){if(!t)return;const o=n?.isCell??!1,s=n?.isHyperlink??!1,i=t.tuples,a=t.bounds,l=this._beginCommit({description:e?.description??"Update Cells"});let c=null;const h=this._isDataColumn,d=h?exports.t.Orientation.Column:exports.t.Orientation.Row,u=this.getProtection().isLocked(),g=this.getProtection().isFormatCellsAllowed(),p=this._strings,m=a.majorStart,f=a.majorEnd,_=a.minorStart,S=a.minorEnd,w={colStart:h?m:_,rowStart:h?_:m,colEnd:h?f:S,rowEnd:h?S:f},y=this;(r=r??((t,e)=>{y._validateCoords(t,e??Kd)}))(w);const x={[$d.Type.Style]:!1,[$d.Type.Table]:!1};let C=!1;u&&this._hasRangedEntries("unlockSpatial",w)&&(x[$d.Type.Unlock]=!1,C=!0),this._hasRangedEntries("mergeSpatial",w)&&(x[$d.Type.Merge]=!1,C=!0);const b=this._rangeStateIterator({bounds:w,orientation:d,includeRangeTypes:x,reuseIterator:{done:!1,value:null}});let E=b.next(),v=-1,I=-1,A=-1,R=-1,M=null;if(!E.done){const t=E.value,e=t.start,r=t.end;v=h?e.colIndex:e.rowIndex,I=h?r.colIndex:r.rowIndex,A=h?e.rowIndex:e.colIndex,R=h?r.rowIndex:r.colIndex,M=t.intersection}let T=(t,e)=>{do{if(!M||t<=A&&e<A)return null;if(t>=v&&e>=A&&t<=I&&e<=R)return M;if(E=b.next(),E.done)M=null,T=null,C=!1;else{const t=E.value;v=h?t.start.colIndex:t.start.rowIndex,I=h?t.end.colIndex:t.end.rowIndex,A=h?t.start.rowIndex:t.start.colIndex,R=h?t.end.rowIndex:t.end.colIndex,M=t.intersection}}while(M);return M};const F=l.getState(this),N=F.cellValuesGrid.clone(),k=F.calcGraph.clone(),O=F.formulaSpatial.clone(),B=F.spillSpatial.clone(),L=F.pendingSpatial.clone(),D=F.calcErrorsSpatial.clone(),z=F.contentfulSpatial.clone(),P=Hc(h),j=Hc(h,(t,e)=>{if(t===e)return e}),H=Hc(h,(t,e)=>{if(t===e)return e}),V=Hc(h,(t,e)=>{if(t===e)return e}),$=[];let U=null,G=null;if(!1!==e?.textParser){const t=e&&!0!==e.textParser?e.textParser:{};G={ignoreQuotePrefix:!1,date1904:this._isDate1904,dateNF:!1,parse:null,...t},U=new vm(p,null,this._cellOptions)}const W=[],q=this._cellOptions,J=new Map,X=Rm,K=(t,e,r)=>{const n=T?.(e,r);if(n?.merge){const t=n.merge.getCoords(),o=h?t.colStart:t.rowStart,s=h?t.rowStart:t.colStart;if(o!==e||s!==r)return}if(o&&t&&t.isICell){const n=t;if(n.isTopLeft()){const t=n.getSpans();$.push({colStart:h?e:r,rowStart:h?r:e,colEnd:(h?e:r)+t.width-1,rowEnd:(h?r:e)+t.height-1})}}let i=$p(t,q,G,J);if(void 0===i)return;const a=i.value;if(i.stringToParse){lw[0].colIndex=h?e:r,lw[0].rowIndex=h?r:e,lw[1]=a,lw[2]=n,U.setState(lw);const t=G?.parse(i.stringToParse,U.context),o=$p(t,q,G,J,!0);if(U.clear(),null===o)return o;void 0!==o&&(i={...o})}if(u){if(u&&(null===t||void 0!==i.value))throw new Error(Jd);if(!g&&void 0!==i.style)throw new Error(Jd)}if(!s){const t=i.style;void 0===t||null===t&&!o||j.append(e,r,t);const n=i.hyperlink;void 0===n||null===n&&!o||H.append(e,r,n)}const l=i.formula;return void 0===l||null===l&&!o||V.append(e,r,l),a};let Y=-1,Z=-1;try{const t=i.length;for(let e=0;e<t;e++){const t=i[e],r=t[0];if(Y>=r)throw new exports.Tuple.OutOfOrderError(`Duplicate or out of order major indices: {${r}}.`);if(Y=r,Z=Number.MIN_SAFE_INTEGER,r<m||r>f)throw new Mt("Provided major bounds is invalid");const n=t[1],s=[],a=n.length;for(let t=0;t<a;t++){const e=n[t],i=e[1],a=i.length;let l=e[0],c=l;if(Z>c)throw new exports.Tuple.OutOfOrderError(`Duplicate or out of order minor indices: {${c}}.`);if(c<_||c+a>S+1)throw new Mt("Provided minor bounds is invalid");let h=[];for(let t=0;t<a;t++){const e=i[t];let n=null;if(C||"number"!=typeof e?(C||null!==e||o)&&(n=K(e,r,c)):n=e,null==n){if(null===n&&P.append(r,c),h.length>0){const t=X(h,p);s.push([l,t]),h=[]}l=c+1}else h.push(n);c++}if(Z=c,h.length>0){const t=X(h,p);s.push([l,t]),h=null}}s.length>0&&W.push([r,s])}const r=P.done(),n=r.length;for(let t=0;t<n;t++){const e=r[t];N.delete(r[t]),z.insertNonOverlapping({...e,value:null});const n=k.delete(e);this._updateFormulaSpatial(O,null,n)}let s;W.length>0&&(N.setValues(W),s={tuples:W,bounds:a});let d,u=V.done();if(u.length>1&&(u=wc(u,exports.t.Orientation.Column,1)),s||u.length>0){const t=k.setInputs(s,u);d=this._updateFormulaSpatial(O,t.inserts,t.removes,F.directStyleSpatial)}const g=Mm(W,h),y=g.length;for(let t=0;t<y;t++)z.insertNonOverlapping(g[t]);const x=j.done();x.length>0&&this._updateStyles(x),$.length>0&&this._merge($);const b=H.done();if(b.length>0&&this._setHyperlinks(b),this._updateState({cellValuesGrid:N,contentfulSpatial:z,calcGraph:k,formulaSpatial:O,spillSpatial:B,pendingSpatial:L,calcErrorsSpatial:D}),d&&d.length>0&&this._updateStyles(d,void 0,{},!0),e?.autoFit){const t="boolean"==typeof e.autoFit?dw:e.autoFit;this._autoFit([w],t)}c={ranges:[w]},this._addEvent("data",w),this._commitAndAutoSelect(l,c,e?.autoSelect,{viewAfter:{formulas:[w],ranges:[w]}})}catch(t){throw l.rollback(),t}}_sort(t,e){"boolean"==typeof e&&(e={reverse:e});const r=e?.description??"Sort "+(e?.reverse?"Descending":"Ascending");this._protectionCheck(()=>["sort"],t,r);let n=1,o=1,s=!1;const i=this._getMerges([t]);if(i.length>0){s=!0;let e=i[0];if(n=e.colEnd-e.colStart+1,o=e.rowEnd-e.rowStart+1,(t.colEnd-t.colStart+1)%n!=0||(t.rowEnd-t.rowStart+1)%o!=0)throw new Error(nu);const r=i.length;for(let t=1;t<r;t++){const e=i[t];if(e.colEnd-e.colStart+1!==n||e.rowEnd-e.rowStart+1!==o)throw new Error(nu)}}const a=e?.orientation??exports.t.Orientation.Row,l=a===exports.t.Orientation.Row;let c=e?.offset??0,h=t;e?.hasHeader&&(h={...h},l?h.rowStart+=o:h.colStart+=n,c=Math.max(c-1,0));const d={offset:c,reverse:e?.reverse??exports.Sort.DefaultRangeOptions.reverse,collatorOptions:e?.collatorOptions??exports.Sort.DefaultRangeOptions.collatorOptions},u=l?h.colStart:h.rowStart,g=l?h.colEnd-h.colStart:h.rowEnd-h.rowStart,p=[];if(e?.fields){const t=e?.fields.length??0;for(let r=0;r<t;r++){let t=e.fields[r];"number"==typeof t&&(t={offset:t}),p.push(t)}}else p.push(d);const m=p.length;for(let t=0;t<m;t++){const e=p[t]={...d,...p[t]};if(e.offset<0||e.offset>g)throw new Mt("The sort offset is outside of the bounds of the sort.");e.offset+=u}const f=[];let _=null,S=null,w=null,y=Number.MIN_SAFE_INTEGER;p.sort((t,e)=>t.offset-e.offset);let x=null;const C=e?.includeHidden??!1;if(!C){const t=xm(l?this._rowHeaders:this._colHeaders);x=xl(t)}const b=this._cellIterator({bounds:h,orientation:a,excludeHidden:!C&&a,includeRangeTypes:{[$d.Type.Style]:!1,[$d.Type.Merge]:!1}}),E=l?o:n;let v=(l?h.rowStart:h.colStart)-E,I=b.next();for(;!I.done;){const t=I.value.context,e=t.getCell();if(s&&!e.isTopLeft()){I=b.next();continue}const r=t.getCoords(),n=l?r.rowIndex:r.colIndex,o=l?r.colIndex:r.rowIndex;if(v!==n){for(v+=E,x&&(v=x(v));v<n;)f.push(null),v+=E;S=[],w=[],_={minorIndex:n,values:S,sortValues:w},f.push(_),v=n,y=p[0].offset}for(;o>y;){const t=p[w.length];y=t?t.offset:Number.MAX_SAFE_INTEGER,o>y&&w.push(null)}o===y&&w.push(e),S.push(e),I=b.next()}if(!_)return;if(0===f.length)return;const A=new Map,R=new Map,M=e?.collators??exports.Sort.DefaultCollators,T=M.length;for(let t=0;t<T;t++)A.set(M[t].type,M[t].compare),R.set(M[t].type,t);let F=null,N=null,k=null;f.sort((t,e)=>{const r=p.length;for(let n=0;n<r;n++){const r=p[n],o=t?t.sortValues[n]:null,s=e?e.sortValues[n]:null,i=o?o.getValue():null,a=s?s.getValue():null,l=null===i,c=null===a;if(i===a)continue;if(l&&c)return 0;if(!l&&c)return-1;if(l&&!c)return 1;const h=o.getType(),d=s.getType();let u=0;if(h!==d){let t=R.get(h);u=R.get(d)-t}else{let t=N;if(F!==h){t=A.get(h),N=t,F=h;let e=R.get(d);const n=M[e].defaultOptions;k={...n,...r.collatorOptions}}u=t(i,a,k)}return r.reverse&&(u*=-1),u}return 0});const O=this._beginCommit({description:r});let B=[h];C||(B=this._getVisible(B,{orientations:l?exports.t.Orientations.Row:exports.t.Orientations.Column})),this._clear(B,void 0,void 0,!0);const L=this._createIncrementalUpdater({orientation:a});let D=l?h.rowStart:h.colStart;const z=f.length;for(let t=0;t<z;t++){const e=f[t];if(x&&(D=x(D)),e){const t=e.values,r=t.length;for(let e=0;e<r;e++){const r=t[e],n=l?D:r.getCoords().rowIndex,o=l?r.getCoords().colIndex:D;L.pushAt(n,o,r)}}D+=E}return L.apply(),O.commit(),h}_autoFill(t,e,r){const{direction:n,amount:o}=((t,e)=>{let r=exports.t.Direction.Down,n=0;const o={...t};if(e.colStart<t.colStart?(r=exports.t.Direction.Left,n=t.colStart-e.colStart,o.colStart=e.colStart):e.colEnd>t.colEnd?(r=exports.t.Direction.Right,n=e.colEnd-t.colEnd,o.colEnd=e.colEnd):e.rowStart<t.rowStart?(r=exports.t.Direction.Up,n=t.rowStart-e.rowStart,o.rowStart=e.rowStart):e.rowEnd>t.rowEnd&&(r=exports.t.Direction.Down,n=e.rowEnd-t.rowEnd,o.rowEnd=e.rowEnd),!U.isEqualRanges(o,e))throw new Error("Autofill destination must be the same as the range for 3 of the 4 edges.");return{direction:r,amount:n}})(t,e);if(o<=0)return!1;const s=n===exports.t.Direction.Up||n===exports.t.Direction.Down,i=this.getSelection().getCoords(),a=[],l=r?.previewOnly,c=r?.contentsOnly,h=r?.filler??exports.AutoFill.Types.Series,d={...r?.fillerOptions};let u=null,g=null;try{const p={...t};let m={...t};const f=[t],_=this._getMerges(f);if(_.length>0&&!U.isRangeWithinRange(U.unionRangesArrays(_),t))throw new Error(ru);const S={...m};let w=1;if(n===exports.t.Direction.Left)p.colStart=m.colStart=t.colStart-o,p.colEnd=t.colStart-1,w=0===_.length?w:t.colEnd+1-t.colStart,S.rowStart=S.rowEnd;else if(n===exports.t.Direction.Right)p.colEnd=m.colEnd=t.colEnd+o,p.colStart=t.colEnd+1,w=0===_.length?w:t.colEnd+1-t.colStart,S.rowStart=S.rowEnd;else if(n===exports.t.Direction.Up)p.rowStart=m.rowStart=t.rowStart-o,p.rowEnd=t.rowStart-1,w=0===_.length?w:t.rowEnd+1-t.rowStart,S.colStart=S.colEnd;else{if(n!==exports.t.Direction.Down)throw new Error(ft.MESSAGE_ERROR_INVALID_ARG(n));p.rowEnd=m.rowEnd=t.rowEnd+o,p.rowStart=t.rowEnd+1,w=0===_.length?w:t.rowEnd+1-t.rowStart,S.colStart=S.colEnd}if(o%w!==0)throw new Error((t=>`When filling with merged cells the amount to fill must be a multiple of the input range [${t}].`)(w));const y=s?"rowIndex":"colIndex",x=s?"colIndex":"rowIndex",C=s?t.rowEnd+1-t.rowStart:t.colEnd+1-t.colStart,b=s?t.rowStart:t.colStart,E=s?t.rowEnd:t.colEnd,v=s?e.rowStart:e.colStart,I=s?e.rowEnd:e.colEnd,A=s?n===exports.t.Direction.Down:n===exports.t.Direction.Right;A||(d.reverse=!0);const R=A?E+1:v,M=(A?I:b-1)-R+1,T=s?t.colEnd:t.rowEnd;a.push(U.unionRanges(p,t));const F=[];let N=null;l||(u=this._beginCommit({description:"Auto Fill",operation:{name:"autoFill",params:[t,e,r]}}));const k=this._cellIterator({bounds:l?S:t,reverse:!A,orientation:s?exports.t.Orientation.Column:exports.t.Orientation.Row,includeRangeTypes:{[$d.Type.Style]:!1}});let O=k.next();for(;!O.done;){const t=O.value.context,e=t.getCell(),r=t.getCoords();N?.oppositeIndex!==r[x]&&(N={oppositeIndex:r[x],lastIndex:A?b-1:E+1,values:[]},F.push(N));const n=r[y];if(A)for(let t=N.lastIndex+1;t<n;t++)N.values.push(null);else for(let t=N.lastIndex-1;t>n;t--)N.values.push(null);N.lastIndex=n;const o=e.toDate();if(o)N.values.push(o);else{let t=e.getValue();N.values.push(t)}O=k.next()}const B=F.length;for(let t=0;t<B;t++){const e=F[t].values;for(let t=e.length;t<C;t++)e.push(null)}const L=(t,e)=>{if(t.canFill(e[0],[])){const r=t.createFillAt(e,d);if(r)return r}return exports.AutoFill.Types.Copy.createFillAt(e)},D=this;if(l){const t=F[F.length-1];if(F[F.length-1]?.oppositeIndex!==T)return null;const e=L(h,t.values);return l(t=>{const r=D._rangeToCoords(t);let o;n===exports.t.Direction.Down||n===exports.t.Direction.Right?o={rowIndex:r.rowEnd,colIndex:r.colEnd}:n===exports.t.Direction.Left?o={rowIndex:r.rowEnd,colIndex:r.colStart}:n===exports.t.Direction.Up&&(o={rowIndex:r.rowStart,colIndex:r.colEnd});const i=s?o.rowIndex:o.colIndex,a={value:e(A?i-b:b-i+C-1)};let l=null;return l=c?this.createTemporaryCell(a,o):this.createTemporaryCell(null,o).createTemporaryCell(a),l}),!1}const z=this._createIncrementalUpdater({orientation:s?exports.t.Orientation.Column:exports.t.Orientation.Row}),P=F.length;F.sort((t,e)=>t.oppositeIndex-e.oppositeIndex);for(let t=0;t<P;t++){const e=t,r=L(h,F[e].values),n=F[e].oppositeIndex,o=A?C:C+M-1,i=this.isDate1904();for(let t=0;t<M;t++){let e=r(o+(A?t:-t));ls(e)&&(e=ms(e,i));const a=R+t;s?z.pushAt(a,n,e):z.pushAt(n,a,e)}}this._clear([p],r?.contentsOnly?exports.ICell.Content.Formats:void 0),z.apply();const j=this._getMerges([m]),H=U.unionRangesArrays(j);if(j.length>0&&!U.isRangeWithinRange(H,m))throw new Error(ru);if(j.length>0){const e=[],r=o/w;if(s){const o=t.rowEnd-t.rowStart+1,s=n===exports.t.Direction.Up?p.rowStart:t.rowEnd+1,i=j.length;for(let n=0;n<i;n++){const i=j[n],a=i.rowStart-t.rowStart,l=i.rowEnd-i.rowStart+1;for(let t=0;t<r;t++){const r=t*o;e.push({colStart:i.colStart,rowStart:s+r+a,colEnd:i.colEnd,rowEnd:s+r+a+l-1})}}}else{const o=t.colEnd-t.colStart+1,s=n===exports.t.Direction.Left?p.colStart:t.colEnd+1,i=j.length;for(let n=0;n<i;n++){const i=j[n],a=i.colStart-t.colStart,l=i.colEnd-i.colStart+1;for(let t=0;t<r;t++){const r=t*o;e.push({colStart:s+r+a,rowStart:i.rowStart,colEnd:s+r+a+l-1,rowEnd:i.rowEnd})}}}this._merge(e)}const V=this._getState(),$={},G={};G.directStyleSpatial=V.directStyleSpatial,G.continuousFillSpatial=V.continuousFillSpatial;let W=t,q=p;if(!A){let e=(s?m.rowEnd+1-m.rowStart:m.colEnd+1-m.colStart)%C;const r=s?"rowStart":"colStart",n=s?"rowEnd":"colEnd";0!==e&&(q={...p,[n]:Math.min(p[n],p[r]+e)},W={...t,[r]:t[n]-e+1},p[r]=p[r]+e)}const J=Object.keys(G),X=J.length;for(let t=0;t<X;t++){const e=J[t],r=G[e].createCopiedEntries(W,q),n=V[e].clone(),o=r.removes,s=o.length;for(let t=0;t<s;t++)n.remove(o[t]);n.load(r.inserts),$[e]=n}if(A){const e=this.getTables().search({address:{rowIndex:t.rowEnd,colIndex:t.colEnd}});if(1===e.length){const t=e[0],r=t.getRange().getCoords();t.resize({colStart:r.colStart,rowStart:r.rowStart,colEnd:s?r.colEnd:p.colEnd,rowEnd:s?p.rowEnd:r.rowEnd})}}const K=V.calcGraph.clone();K.autoFill(t,p),$.calcGraph=K,this._updateState($),g={...i,ranges:a},u.commit({viewBefore:{view:this.getView(),selection:Nm([t]),selectOptions:r?.autoSelect},viewAfter:{view:this.getView(),selection:g,selectOptions:r?.autoSelect}}),this._autoSelect(r?.autoSelect??!1,g)}catch(t){throw u?.rollback(),t}return!0}_setHyperlinks(t,e,r){const n=r?.description??"Set Hyperlink";this._protectionCheck(()=>["insertHyperlinks","formatCells"],t,n);const o=Nm(t),s=this._beginCommit({description:n});let i=null;try{const n=this._getState();if(!n)return mt.EmptyArray;const a=n.hyperlinkSpatial;let l=a;let c=n.directStyleSpatial.clone();const h=t.length;for(let r=0;r<h;r++){const n=t[r];let o=null;const s=n.value,h=void 0!==s?s:e;let d;if(null!==h){if(h.isIHyperlink)d={...h._j},o=h.getDisplayText();else if("string"==typeof h)d={address:h},o=h;else if(h.address){const t=h,e={...t};delete e.displayText,d=e,o=t.displayText??t.address}}else d=null;if(i=U.unionRanges(i,n),a===l&&(l=a.clone()),null!==d||a.size()>0){if(o&&e){const t=this._createIncrementalUpdater({orientation:exports.t.Orientation.Column},void 0,{isHyperlink:!0});for(let e=n.colStart;e<=n.colEnd;e++)for(let r=n.rowStart;r<=n.rowEnd;r++)t.pushAt(r,e,o);t.apply()}if(null===d)this._getRangedEntries("hyperlinkSpatial",[n],{onEntry:(t,e)=>(l.insertNonOverlapping({...e,value:d}),e.value)});else{l.insertNonOverlapping({...n,value:d});const t=this._styles,e=e=>{const r=e.value??new Lp(t,U.sanitizeRange(e));let n={...r.getPropertiesAt(0,0,null)};if(n.named){const e=t.getNamed(n.named)?.getRanged().getPropertiesAt(0,0,null);n=mt.mergeContentful(e,n)}return delete n.font,n.named=exports.IStyle.BuiltInName.Hyperlink,{...e,value:r.cloneWithUpdate(n)}};c.insertNonOverlapping({...n,value:null},{onIntersect:e})}}}this._lastUsedCoordsRead.coords=null,this._updateState({hyperlinkSpatial:l,directStyleSpatial:c}),this._commitAndAutoSelect(s,o,r?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw s.rollback(),t}}_updateFormulaSpatial(t,e,r,n){if(r){const e=r.length;for(let n=0;n<e;n++){const e=r[n];t.remove(e)}}let o;if(e){const r=[],s=e.length;for(let t=0;t<s;t++){const s=e[t],i=U.sanitizeRange(s),a=new MS(i,s.value.tokens,s.value.references);if(r.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:a}),!n)continue;const l=s.value.precedents;let c,h,d=!1;const u=l.length;for(let t=0;!d&&t<u;t++){const e=l[t],r=e.colStart;if(void 0===e.colStart)continue;const o=e.rowStart;aw.colStart=r,aw.rowStart=o,aw.colEnd=r,aw.rowEnd=o;const s=n.search(aw)[0];if(s){const t=s.value.getPropertiesAt(o,r,null),e=t?.numberFormat;if(e)if(c){h||(h=exports.NumberFormat.Styles.lookupStyle(c)?.formatType);const t=exports.NumberFormat.Styles.lookupStyle(e)?.formatType;as(t,h)>0?(h=t,c=e):d=!0}else c=e}}c&&(o||(o=[]),o.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:{numberFormat:c}}))}t.load(r)}return o}_realizeCalcedValues(t){if(!t)return;const e=this._getState();if(!e)return;const r=t.valueInserts,n=t.spillRemoves,o=t.errorRemoves,s=e.cellValuesGrid;t.isFull&&(e.calcErrorsSpatial.clear(),e.spillSpatial.clear(),e.pendingSpatial.clear());const i=t.valueRemoves;if(i){const t=e.contentfulSpatial,r=i.length;for(let e=0;e<r;e++){const r=i[e];s.delete(r),t.insertNonOverlapping({...r,value:null})}}if(n){const t=e.spillSpatial,r=n.length;for(let e=0;e<r;e++){const r=n[e];t.remove(r)}}if(o){const t=e.calcErrorsSpatial,r=o.length;for(let e=0;e<r;e++){const r=o[e];t.remove(r)}}this._updateFormulaSpatial(e.formulaSpatial,t.formulaInserts,t.formulaRemoves);const a=t.formatInserts;if(a){const t=a.length;for(let e=0;e<t;e++){const t=a[e],r={numberFormat:t.value};t.value=r}this._updateStyles(a,void 0,{autoFit:!0},!0)}if(r){const t=r.tuples;s.setValues(t);const n=this._isDataColumn,o=n?exports.t.Orientation.Column:exports.t.Orientation.Row,i=e.contentfulSpatial,a=t.length;for(let e=0;e<a;e++){const r=t[e],s=r[0],a=r[1],l=a.length;for(let t=0;t<l;t++){const e=a[t],r=e[0],l=r+e[1].length-1,c={colStart:n?s:r,rowStart:n?r:s,colEnd:n?s:l,rowEnd:n?l:s};i.insertNonOverlapping({colStart:c.colStart,rowStart:c.rowStart,colEnd:c.colEnd,rowEnd:c.rowEnd,value:new Dd(c,o)})}}}const l=t.spillInserts;if(l){const t=l.length;for(let e=0;e<t;e++){const t=l[e],r=t.value;t.value=new Ld(U.sanitizeRange(t),0,r)}e.spillSpatial.load(l)}const c=t.pendingUpdates;if(c){const t=e.pendingSpatial,r=c.length;for(let e=0;e<r;e++){const r=c[e];!1===r.value&&(r.value=null),t.insertNonOverlapping(r)}}const h=t.errorInserts;if(h){e.calcErrorsSpatial.load(h)}const d=t.formulaInserts;if(d){const t=wc(d);this._autoFit(t,dw)}if((t.bounds||t.isFull)&&!this._initializing){const e=this._rangesListenerMap;if(e.size>0){const r={isDataChange:!0,isTransactional:!1,timeStamp:Date.now(),isUndo:!1,trigger:"calc"};this._notifyRangeListeners(this._rangeListenerSpatial,e,[t.bounds??this._entireCoords],r)}(l||n)&&this._emitter.notify("onSpillsChange")}}_calculate(t,e){const r=this._getState().calcGraph;r.invalidate(t),r.calculate(e)}_calculateFull(){this._initializing||mt.debounce(()=>{this._getState()?.calcGraph.calculate({full:!0})},100)()}_setComments(t,e,r){const n=r?.description??"Set Comments",o=Nm(t),s=this._beginCommit({description:n});let i=null;try{const n=this._getState();if(!n)return mt.EmptyArray;const a=n.commentsSpatial;let l=a;const c=t.length;for(let r=0;r<c;r++){const n=t[r];let o=null;if(null!==e){let t=e;if(!t)continue;o="string"==typeof t?{content:{runs:{text:t}}}:{...t}}i=U.unionRanges(i,n),a===l&&(l=a.clone()),l.insertNonOverlapping({...n,value:o})}this._lastUsedCoordsRead.coords=null,this._updateState({commentsSpatial:l}),this._commitAndAutoSelect(s,o,r?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw s.rollback(),t}}_clear(t,e=null,r,n=!1,o=!1){let s=null,i="Clear",a=!1,l=!1,c=!1,h=!1;e===exports.ICell.Content.Formulas?(i=`${i} Formulas`,h=!0):e===exports.ICell.Content.Values?(i=`${i} Values`,h=!0):e===exports.ICell.Content.Formats?(i=`${i} Formats`,a=!0,s=["formatCells"]):e===exports.ICell.Content.Comments?(i=`${i} Comments`,c=!0):e===exports.ICell.Content.Hyperlinks?(i=`${i} Hyperlinks`,l=!0,s=["formatCells"]):(s=[],i=`${i} All`,h=!0,a=!0,l=!0,c=!0),null!==s&&this._protectionCheck(()=>s,t,r?.description??i);const d=Nm(t),u=this._beginCommit({description:r?.description??i});let g=this._getState(),p=g.cellValuesGrid,m=g.calcGraph,f=g.contentfulSpatial,_=g.formulaSpatial,S=g.spillSpatial,w=g.pendingSpatial,y=g.calcErrorsSpatial,x=g.rangesListenerSpatial2;h&&(p=p.clone(),m=m.clone(),f=f.clone(),_=_.clone(),S=S.clone(),w=w.clone(),y=y.clone());try{if(l&&this._setHyperlinks(t,null),c&&this._setComments(t,null),a&&(this._updateStyles(t,null),n||this._unmerge(t)),a||h){Cf(0,t,[],f,S,p);const r=t.length;for(let n=0;n<r;n++){const r=t[n];if(h){p.delete(r);const t={...r,value:null};f.insertNonOverlapping(t);const e=m.delete(r);this._updateFormulaSpatial(_,null,e)}const s=this.getTables().search({address:r}),i=s.length;for(let t=0;t<i;t++){const n=s[t];U.isRangeWithinRange(n.getAnchorCoords(),r)&&(e===exports.ICell.Content.Formats?n.updateStyleOptions({name:null}):n.delete())}if(a){let t=g.conditionalSpatial;t.size()>0&&(t=t.clone(u.getId()),t.insertNonOverlapping({...r,value:null},{noMerge:!0}),g=this._updateState({conditionalSpatial:t}))}if(o){const t=x.search(r),e=t.length;for(let n=0;n<e;n++){const e=t[n];U.isRangeWithinRange(e,r)&&(x===g.rangesListenerSpatial2&&(x=x.clone()),console.log("cut and move listener"),x.remove(e))}}}}this._updateState({cellValuesGrid:p,calcGraph:m,contentfulSpatial:f,formulaSpatial:_,spillSpatial:S,pendingSpatial:w,calcErrorsSpatial:y,rangesListenerSpatial2:x}),this._commitAndAutoSelect(u,d,r?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw u.rollback(),t}}_merge(t,e=null){if(this._protectionCheck(ZS,t),1===t.length&&U.isSingleCell(t[0]))return;let r=exports.t.Orientations.Both;e?.orientations?r=e?.orientations:e===exports.t.Orientations.Row?r=exports.t.Orientations.Row:e===exports.t.Orientations.Column&&(r=exports.t.Orientations.Column);const n=e?.discardMultipleValues??!1;let o=Nm(t);const s=this.getSelection().getCoords();let i=null;const a=this._beginCommit({description:e?.description??"Merge"});let l=t[0];try{const c=this._getMerges(t);if(mh(t)||c.length>0){const e=U.unionRangesArrays(c),r=U.unionRangesArrays(t);if(!(!e&&!r||e&&r&&U.isRangeWithinRange(e,r)))throw console.warn(tu,t),new Error(tu);this._unmerge(c)}const h=this._createIncrementalUpdater({orientation:exports.t.Orientation.Column}),d=[];try{const e=this._entireCoords,a=this._getState().contentfulSpatial;let c=!1;const u=t=>{const e={rowIndex:t.rowStart,colIndex:t.colStart};let r=null;if(c){let e=0;const r=a.search(t),n=r.length;for(let o=0;o<n;o++){const n=U.intersectRanges(r[o],t);if(n&&(e+=(n.rowEnd-n.rowStart+1)*(n.colEnd-n.colStart+1)),e>1)throw new Nt("Merging cells would cause some values to be discarded. Use 'discardMultipleValues' option if desired.","discardMultipleValues")}}if(r||(r=e),!U.isEqualCells(r,e)){const e=this.getRange(r).getCell();h.pushAt(t.rowStart,t.colStart,e),h.pushAt(r.rowIndex,r.colIndex,null)}d.push(t),l=U.unionRanges(l,t)},g=[...t].sort(U.createRangeComparator(exports.t.Orientation.Column)),p=g.length;for(let t=0;t<p;t++){const l=g[t];if(!U.isSingleCell(l)){if(i||!s||!U.isCellWithinRange(s.cell,l)||s.cell.rowIndex===l.rowStart&&s.cell.colIndex===l.colStart||(i={...o,cell:{rowIndex:l.rowStart,colIndex:l.colStart}}),!n){const t=a.search(l);c=t.length>0}if(this._validateOrRemoveOverlaps(l,"merge"),l.colStart<e.colStart||l.rowStart<e.rowStart||l.colEnd>e.colEnd||l.rowEnd>e.rowEnd)throw new Error("We can't merge outside of the maximum cell location.");if(r===exports.t.Orientations.Column){const t=l.rowEnd!==e.rowEnd?l.rowEnd:Math.max(1,e.rowEnd);for(let e=l.rowStart;e<=t;e++)u({...l,rowStart:e,rowEnd:e})}else if(r===exports.t.Orientations.Row){const t=l.colEnd!==e.colEnd?l.colEnd:Math.max(1,e.colEnd);for(let e=l.colStart;e<=t;e++)u({...l,colStart:e,colEnd:e})}else u(l)}}h.apply(),this._indexMerges(d),this._updateState({})}catch(t){if(t.type)throw new Nt(t.message??"Unable to merge",t.type);throw new Error(t.message??"Unable to merge")}i&&(o=i,this.getSelection().updateCoords(i)),a.commit({viewAfter:{view:this.getView(),selection:o,merges:t,ranges:t,selectOptions:e?.autoSelect}}),this._autoSelect(e?.autoSelect??!1,o)}catch(t){throw a.rollback(),t}}_unmerge(t,e){if(this._protectionCheck(ZS,t),mh(t))throw new Error("We can't unmerge intersecting ranges.");if(!this._getState())return null;const r=U.unionRangesArrays(t),n=Nm(t),o=this._beginCommit({description:e?.description??"Unmerge"}),s=o.getState(this).mergeSpatial,i=[];try{const a=t.length;for(let e=0;e<a;e++){const n=t[e],o=s.search(n),a=o.length;for(let t=0;t<a;t++){const e=o[t];if(!U.isSingleCell(n)&&!U.isRangeWithinRange(e,r))throw new Error("We can't unmerge partial cells.");i.push(e)}}if(0===i.length)return o.rollback(),null;this._indexMerges(null,i),this._commitAndAutoSelect(o,n,e?.autoSelect,{viewAfter:{merges:t,ranges:t}})}catch(t){throw o.rollback(),t}}_getMerges(t,e=!1){return 0===t.length?mt.EmptyArray:this._getRangedEntries("mergeSpatial",t,{excludeHidden:e,fullyContained:!1,onEntry:t=>t.getCoords()})}_clone(){const t={...this._options,container:null};this._ownStyles&&(t.styles=this._styles),this._ownStrings&&(t.strings=this._strings),this._ownResources&&(t.resources=this._resources),this._ownNames&&(t.names=this._names),this._ownsCalculation&&(t.calculation=this._calculation),t.transactions=new re({transient:!0});const e=new tw(t),r=this._transactions.getState(this);e._updateState(r);const n=new BS({sheet:this,json:this.getView().toJSON()});return n.selectMovables(this.getView().getMovableSelection()),e.setView(n),e}_getSnapshot(t,e){if(0===t.length)return mt.EmptyArray;const r=this._getState();if(!r)return null;e=Object.freeze({...e});const n=this._clone();n.isMarked=!0;const o=this,s=o.getView(),i="Range",a=[],l=((t,e,r,n)=>{const o=[];let s=null,i=null;const a=r&&r.length>0;if(a){const t=r.length;for(let e=0;e<t;e++){const t=r[e].getSnapshot?.(n);t&&(o.push(t),s=be(t.getCoords(),s))}}else if(e){const r=e.length;for(let a=0;a<r;a++){const r=e[a],l=t.getMovables().search({excludeHidden:!1,fullyContained:!0,address:r}),c=l.length;for(let e=0;e<c;e++){const a=l[e].getSnapshot?.(n);a&&(o.push(a),s=be(t.getRange(r).getBounds(),s),i=U.unionRanges(i,r))}}}if(0===o.length)return null;const l=()=>n.description??(1===o?.length?ks(o[0]?.getName()):"Drawings");return{copyTo:async(e,r)=>{const i={...n,...r},a=e.getSource(),c=a.getView(),h=c.getMovableSelection(),d=e.getCoords(),u=i?.isCut??!1,g=c.getMovableSelection();c.selectMovables([]);const p=a.beginCommit(i.description??`${u?"Cut":"Copy"} ${l()}`);try{let e=0,r=0;if(g.length>0&&o.length>0){let t=Number.MAX_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER;for(let e=0;e<h.length;e++){const r=h[e].getBounds();t=Math.min(r.x,t),n=Math.min(r.y,n)}let s=Number.MAX_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER;const l=o.length;for(let t=0;t<l;t++){const e=o[t].getCoords();s=Math.min(e.x,s),i=Math.min(e.y,i)}e=t-s,r=n-i;const c=o[0].getCoords(),d={...c,x:c.x+e,y:c.y+r},u=Z_(a.getMovables(),d);e+=u.x,r+=u.y}else if(s){const t=a.getRange(d).getBounds();e=t.x-s.x,r=t.y-s.y}const n=[],l=o.length;for(let t=0;t<l;t++){const s=o[t],l=s.getCoords(),c={...l,x:l.x+e,y:l.y+r};n.push(s.copyTo({movables:a.getMovables(),bounds:c},{autoSelect:{addToSelection:!0},...i}))}await Promise.all(n),p?.updateState(a,t=>t),p.commit({viewBefore:e=>({...e,view:t.getView(),movableSelection:g})})}catch(t){throw p.rollback(),t}return null},getName:l,getCoords:()=>i,getMarkOptions:()=>n,toText:()=>a?o[0].toText?.()??null:null,toHtml:()=>a?o[0].toHtml?.()??null:null,toImage:()=>a?o[0].toImage?.()??null:null,getSource:()=>t,isISnapshot:!0}})(n,t,s.getMovableSelection(),e);if(l){if(s.getMovableSelection().length>0)return l;a.push(l)}if(t.length>1)throw new Error(lu);const c={singleMerge:null};a.push({copyTo(r,o){const s={...e,...o};let i=null;if(!s.skipBlanks){const e=r.getSource(),o=r.getCoords(),l=yh(o,t[0],s?.fitDestination,s?.transpose);i=e.getRange(l);let h=!1;const d=i.getMerges();if(1===d.length&&U.isEqualRanges(d[0],o))if(U.isSingleCell(t[0]))h=!0;else{const t=(a=m)?{colIndex:a.colStart,rowIndex:a.rowStart}:null;1===n._getMerges([U.cellToRange(t)]).length&&(h=!0)}return h?(c.singleMerge=o,i.clear(s.type??exports.ICell.Content.Values)):i.clear(s.type),l}var a}});const h=n._entireCoords,d=t.length;for(let o=0;o<d;o++){const s=t[o],i=r.rangeListenerSpatial.search(s,!1),l=r.rangesListenerMap;a.push({async copyTo(e,r){if(!r.isCut)return;const o=new Set,s=i.length;for(let r=0;r<s;r++){const s=i[r].value,a=s.id;if(o.has(a))continue;const c=l.get(a);o.add(a);if(null===c.ranges[s.offset])return;const h={isTransactional:!0,isDataChange:!1,trigger:"moveCells",from:n.getRanges(t),to:e},d=n._createRangeEvent(c.ranges,h);n._notifyRangeListener2(c,d,h)}return null},getMarkOptions:()=>e,getCoords:()=>null,isISnapshot:!0})}const u={excludeHidden:!1,fullyContained:!0,onEntry:t=>t.model};for(let r=0;r<d;r++){const o=t[r],s=n._getRangedEntries("tableSpatial",[o],u),i=s.length;for(let t=0;t<i;t++){const r=s[t],i=r.getAnchorCoords(),l=i.colStart-o.colStart,c=i.rowStart-o.rowStart,h=r.getSnapshot(e);a.push({async copyTo(t,e){const r=t.getSource(),o=t.getCoords();if(n.getProtection().isLocked())return;const s={colStart:o.colStart+l,rowStart:o.rowStart+c,colEnd:o.colEnd+l,rowEnd:o.rowEnd+c};return h.copyTo({tables:r.getTables(),range:s},e)}})}}for(let r=0;r<d;r++){const n=t[r];a.push(dS(o.getColumnHeaders().getRange(n),n,Object.freeze({...e,includeHeaders:n.rowStart<=h.rowStart&&n.rowEnd>=h.rowEnd})))}for(let r=0;r<d;r++){const n=t[r];a.push(dS(o.getRowHeaders().getRange(n),n,Object.freeze({...e,includeHeaders:n.colStart<=h.colStart&&n.colEnd>=h.colEnd})))}const g=uS(o,n,t,i,e,(e,r)=>n._copyRange(o,n,t,e,r,c));a.push(g);const p=n._getState().calcGraph.getSnapshot({range:t[0]});a.push({async copyTo(t,e){const r=t.getSource(),o=t.getCoords();if(n.getProtection().isLocked())return;const s=r._getState().calcGraph;return p.copyTo({calcGraph:s,range:o},e)}});const m=t[0];return((t,e,r,n,o,s,i=null)=>{const a={async copyTo(e,n){let i=null;const a={...o,...n},l=r.beginCommit(a.description??s);try{const r=t.length;for(let n=0;n<r;n++){const r=await t[n].copyTo(e,a);r&&(i=U.unionRanges(i,r))}l.commit()}catch(t){throw l.rollback(),t}return i},getMarkOptions:()=>o,getName:()=>s,getSource:()=>e,getCoords:()=>n,toText(){let e=i?.toText?.()??null;const r=t.length;for(let n=0;!e&&n<r;n++)e=t?.[n].toText?.();return e??null},toHtml(){let e=i?.toHtml?.()??null;const r=t.length;for(let n=0;!e&&n<r;n++)e=t?.[n].toHtml?.();return e??null},toImage(){let e=i?.toImage?.()??null;const r=t.length;for(let n=0;!e&&n<r;n++)e=t?.[n].toImage?.();return e??null},isISnapshot:!0};return a})(a,o,n,m,e,i,g)}async _copyRange(t,e,r,n,o,s){if(r.length>1)throw new Error("Only a single selection is supported when using 'Insert Copy'.");if(!r||0===r.length)throw new Error("The source has no range.");const i=n.getSource();let a=n.getCoords(),l={...r[0]};const c=(o={...o}).isCut;let h=!o.type||o.type===exports.ICell.Content.Formats,d=!o.type||o.type===exports.ICell.Content.Values,u=!o.type||o.type===exports.ICell.Content.Formats||o.type===exports.ICell.Content.Hyperlinks;const g=i.getEntireRange(),p=g.getCoords(),m=[],f=[],_=[];let S=[],w=[];const y=(o.fitDestination??!1)&&!U.isSingleCell(a),x=yh(a,l,y,o.transpose);if(y&&(l={...l,colEnd:l.colStart+Math.min(x.colEnd-x.colStart,l.colEnd-l.colStart),rowEnd:l.rowStart+Math.min(x.rowEnd-x.rowStart,l.rowEnd-l.rowStart)}),!U.isRangeWithinRange(x,p))throw console.warn(x,p),new Error("We can't paste outside of the sheet bounds.");let C=null;C=o.undoRange?{view:i.getView(),selection:Nm([o.undoRange.getCoords()])}:{sheet:i,selection:Nm([x])};const b=i.getTransactions().beginCommit({description:o.description??"Paste"});try{if(!this._getState())return mt.EmptyArray;const r=new Set,n=o.transpose;let p=!((n||o.adjustCells)&&h)&&1===r.size;if(p){const t=r.values().next();p=U.isRangeWithinRange(l,t.value.getCoords())&&!bm(l,t.value.getCoords())}if(p){const t=i.getTables().search({address:x});p=0===t.length}n&&(p=!0),s.singleMerge&&(h=!1,u=!1);const y=a.colStart-l.colStart,E=a.rowStart-l.rowStart,v=o.adjustCells;let I={...Wd};if(delete I[$d.Type.Style],!h){const t=this.getProtection().isLocked();I={},t&&(I[$d.Type.Unlock]=!1)}const A=exports.t.Orientation.Column;let R;if(d){R=g.startIncrementalUpdates({orientation:o.transpose?exports.t.Orientation.Row:exports.t.Orientation.Column});const t={orientation:A,includeRangeTypes:I,bounds:l},e=new vm(this._strings,t,this._cellOptions),r=(t,r,s)=>{const i=t[0],c=e.setState(t),g=e.context,f=g.getCell(),_=f.isTopLeft();let S=E,w=y;if(n){const t=i.colIndex-l.colStart,e=i.rowIndex-l.rowStart;S=t+s+a.rowStart,w=e+r+a.colStart}else S=E+i.rowIndex+r,w=y+i.colIndex+s;let x=!1;const C={value:void 0,style:void 0,hyperlink:void 0};if(d&&(C.value=c,x=!0),h){const e=t[2];e&&(e.directStyle||e.table)&&(C.style=f.getStyle(!p),x=!0)}u&&(C.hyperlink=f.getHyperlink(),x=!0);let b=C;if(v&&_){const t=v(c,g,{rowIndex:S,colIndex:w},o);void 0!==t&&(b=t,x=!0)}if(x&&(R.pushAt(S,w,b),h)){const t=f.getSpans();(t.width>1||t.height>1)&&_&&m.push({colStart:w,rowStart:S,colEnd:w+(o.transpose?t.height:t.width)-1,rowEnd:S+(o.transpose?t.width:t.height)-1})}},i=this._cellStateIterator(t);let c={next(){const t=i.next();if(t.done)return Cl;const e=t.value[0];let r;return t.value&&(r=[e,t.value]),{done:t.done,value:r}}};if(!s.singleMerge&&!U.isEqualRanges(x,l)){const t=x.colEnd-x.colStart+1,e=x.rowEnd-x.rowStart+1;c=new kc({delegate:c,bounds:l,orientation:A,dims:{major:o.transpose?e:t,minor:o.transpose?t:e}})}let f=c.next();for(;!f.done;){const t=f.value,e=t[1],n=t[0],o=e[0];r(e,n.rowIndex-o.rowIndex,n.colIndex-o.colIndex),f=c.next()}}const M=e._getState(),T={},F={transpose:n??!1};h&&(T.directStyleSpatial=M.directStyleSpatial,T.continuousFillSpatial=M.continuousFillSpatial,T.mergeSpatial=M.mergeSpatial),c&&(t._clear([l],void 0,void 0,!1,!0),S.push(l),T.rangesListenerSpatial2=M.rangesListenerSpatial2);const N=i,k=N._getState(),O=Object.keys(T),B=O.length;for(let t=0;t<B;t++){const e=O[t],r=T[e].createCopiedEntries(l,x,F),n=k[e].clone(),o=r.removes,s=o.length;for(let t=0;t<s;t++)n.remove(o[t]);n.load(r.inserts),k[e]=n}N._updateState(k),S.push(x),w.push(x),f&&f.length>0&&N._colHeaders.updateHeaderPairs(f),_&&_.length>0&&N._rowHeaders.updateHeaderPairs(_),R?.apply(),m.length>0&&i.getRanges(m).merge(),b.commit({viewBefore:C,viewAfter:t=>({...t,view:i.getView(),selection:Nm(w),ranges:S})})}catch(t){throw console.warn(t),b.rollback(),new Error((t=>`Unable to paste: ${t}`)(t.message),{cause:t})}return U.unionRangesArrays(w)}_snapShotFromSource(t,e){if(t.isISnapshot)return t;const r=t;let n=null;if(r?.isICellRanges)throw new Error(lu);if(n=r?.isICellRange?r:this.getRange(r),n.isICellRange){const t=n;if(t.isInvalid())throw new Error(cu);return t.getSnapshot(e)}throw new Error(cu)}async _copyFrom(t,e,r){if(!e)throw new Error("Both a source and a destination are required to copy.");const n=this._snapShotFromSource(e),o="Paste",s=this._beginCommit({description:r?.description??o});let i=null;try{const e=this.getRange(t);i=await n.copyTo(e,r);const a=n.getName(),l=[i];r?.isCut&&l.push(n.getCoords()),s.commit({description:a?r?.description??`${o} ${a}`:o,viewAfter:{view:this.getView(),selection:Nm([i]),ranges:l}})}catch(t){throw s.rollback(),t}return i}_createFilter(t,e,r){const n=this;return new $m({initialAnchor:t,maxRangeCoords:this._entireCoords,json:e,transactions:this._transactions,deleteFromContainer:t=>{const e=this._beginCommit({description:t?.description??"Delete Filter"});this._updateState({filter:null}),e.commit()},apply:t=>{console.log("apply Filter",t)},processUpdate:()=>{},isProtected:()=>!n._initializing&&!n.getProtection().isAutoFilterAllowed()})}insertFilter(t){const e=this._rangeToCoords(t,()=>["autoFilter"]);let r=this.getFilter();if(r)return r;r=this._createFilter(e);const n=Nm([e]),o=this._beginCommit({description:"Insert Filter"});return this._updateState({filter:r}),o.commit({viewAfter:{ranges:[e],view:this.getView(),selection:n,selectOptions:void 0}}),r}getFilter(){return this._getState()?.filter??null}insertSort(t){return this._rangeToCoords(t,()=>["sort"]),null}getSort(){return null}_getDefaultShiftOrientation(t){return lm(t,this._entireCoords)}_getDefaultSortCriteria(t,e,r){return Am(this,t,r?this._cellToCoords(r):null,e)}async _insertFrom(t,e,r){if(!e)throw new Ft;const n=this._snapShotFromSource(e),o=n.getCoords();let s=yh(t[0],o,r?.fitDestination),i=Tm([s]),a=i;const l=r?.orientation??this._getDefaultShiftOrientation(s),c=this._beginCommit({description:r?.description??"Insert Copied Cells",autoSelect:r?.autoSelect});try{if(this._insertCells([s],l),await this._copyFrom(s,n,{...r,isCut:!1}),r.isCut){const t={...o};if(i=Tm([t]),s={...s},this===n.getSource()){if(l===exports.t.Orientation.Row){if(s.colStart<t.colStart&&s.colEnd>=t.colStart||s.colEnd>t.colEnd&&s.colStart<=t.colEnd)throw new Error(hu);if(t.colStart===s.colStart&&t.colEnd===s.colEnd){const e=t.rowEnd-t.rowStart+1;s.rowStart<=t.rowStart?(t.rowStart+=e,t.rowEnd+=e):(s.rowStart-=e,s.rowEnd-=e)}}else{if(s.rowStart<t.rowStart&&s.rowEnd>=t.rowStart||s.rowEnd>t.rowEnd&&s.rowStart<=t.rowEnd)throw new Error(hu);if(t.rowStart===s.rowStart&&t.rowEnd===s.rowEnd){const e=t.colEnd-t.colStart+1;s.colStart<=t.colStart?(t.colStart+=e,t.colEnd+=e):(s.colStart-=e,s.colEnd-=e)}}a=Tm([s])}n.getSource().getRanges([t]).delete(l)}c.commit({viewBefore:{ranges:t,view:this.getView(),selection:i,selectOptions:r?.autoSelect},viewAfter:{ranges:t,view:this.getView(),selection:a,selectOptions:r?.autoSelect}}),this._autoSelect(r?.autoSelect??!1,a)}catch(t){throw c.rollback(),t}return s}_insertCells(t,e,r,n=void 0){const o=this;n=n??((t,e)=>{o._validateCoords(t,e??eu)});const s=r?.description??"Insert Cells",i=(e??this._getDefaultShiftOrientation(t[0]))===exports.t.Orientation.Column;if(this._protectionCheck(()=>[i?"insertColumns":"insertRows"],t,s),mh(t))throw new Error("We can't insert cells with overlapping selections.");const a=this._entireCoords;let l=a.colEnd,c=a.rowEnd;const h=Nm(t),d=this._beginCommit({description:s,operation:{name:"insertCells"}}),u=d.getState(this),g=i?exports.t.Direction.Right:exports.t.Direction.Down;try{let e=u.cellValuesGrid,o=u.contentfulSpatial,s=u.unlockSpatial,p=u.mergeSpatial,m=u.directStyleSpatial,f=u.continuousFillSpatial,_=u.conditionalSpatial,S=u.hyperlinkSpatial,w=u.commentsSpatial,y=u.movableSpatial,x=u.tableSpatial,C=u.calcGraph,b=u.rangesListenerSpatial2,E=u.rangeListenerSpatial,v=u.rangesListenerMap;const I=new Map,A=Nl(t.slice(),exports.t.Direction.Left),R=A.length;for(let t=0;t<R;t++){const r=A[t];l=Math.min(l,r.colStart),c=Math.min(c,r.rowStart);const h=i?r.colEnd-r.colStart+1:r.rowEnd-r.rowStart+1,d=e.getCoords();if(d){const t={...r,colEnd:i?Math.max(r.colEnd,d?.colEnd??r.colStart)+(r.colEnd-r.colStart+1):r.colStart,rowEnd:i?r.rowStart:Math.max(r.rowEnd,d?.rowEnd??r.rowStart)+(r.rowEnd-r.rowStart+1)},s=o.search(t),a=s.length;for(let t=0;t<a;t++){const e=s[t],o={...r};i?o.colEnd=Math.max(o.colEnd,e.colEnd)+h:o.rowEnd=Math.max(o.rowEnd,e.rowEnd)+h,n(o)}e=e.clone(),e.shift(r,g),this._updateState({cellValuesGrid:e})}const R=r.colStart<=a.colStart&&r.colEnd>=a.colEnd,M=r.rowStart<=a.rowStart&&r.rowEnd>=a.rowEnd,T=(t,e,r,n)=>{let o=null;r>1&&(o=t.at(r-1));const s=n-r+1;e?.(r,s),o&&t.updateHeaderPairs([{address:{min:r,max:n},update:o}])};R&&T(this._rowHeaders,this._rowHeadersShiftCallback,r.rowStart,r.rowEnd),M&&T(this._colHeaders,this._colHeadersShiftCallback,r.colStart,r.colEnd),o=o.shift({range:r,direction:g,cloneIfUpdate:o===u.contentfulSpatial,coordValidator:n}),s=s.shift({range:r,direction:g,cloneIfUpdate:s===u.unlockSpatial,coordValidator:n}),p=p.shift({range:r,direction:g,cloneIfUpdate:p===u.mergeSpatial,coordValidator:n}),m=m.shift({range:r,direction:g,cloneIfUpdate:m===u.directStyleSpatial,coordValidator:n}),f=f.shift({range:r,direction:g,cloneIfUpdate:f===u.continuousFillSpatial,coordValidator:n}),_=_.shift({range:r,direction:g,cloneIfUpdate:_===u.conditionalSpatial,coordValidator:n}),S=S.shift({range:r,direction:g,cloneIfUpdate:S===u.hyperlinkSpatial,coordValidator:n}),w=w.shift({range:r,direction:g,cloneIfUpdate:w===u.commentsSpatial,coordValidator:n}),y=y.shift({range:r,direction:g,cloneIfUpdate:y===u.movableSpatial,coordValidator:n}),x=x.shift({range:r,direction:g,cloneIfUpdate:x===u.tableSpatial,coordValidator:n}),C=C.shift({range:r,direction:g,cloneIfUpdate:C===u.calcGraph}),E=E.shift({range:r,direction:g,cloneIfUpdate:E===u.rangeListenerSpatial,onShift:t=>{v===u.rangesListenerMap&&(v=new Map(v)),this._processListenerShift(v,I,u.rangesListenerMap,t)}}),b=b.shift({range:r,direction:g,cloneIfUpdate:b===u.rangesListenerSpatial2,coordValidator:n})}let M=u.formulaSpatial,T=u.spillSpatial,F=u.pendingSpatial;C!==u.calcGraph&&(M=M.clone(),T=T.clone(),F=F.clone()),this._updateState({contentfulSpatial:o,unlockSpatial:s,mergeSpatial:p,directStyleSpatial:m,continuousFillSpatial:f,conditionalSpatial:_,hyperlinkSpatial:S,commentsSpatial:w,movableSpatial:y,tableSpatial:x,calcGraph:C,formulaSpatial:M,spillSpatial:T,pendingSpatial:F,rangesListenerSpatial2:b,rangeListenerSpatial:E,rangesListenerMap:v}),this._commitAndAutoSelect(d,h,r?.autoSelect,{viewAfter:{ranges:A,listeners:I}})}catch(t){if(console.warn(t),d.rollback(),t instanceof Mt)throw new Error(t.message??eu);throw t}}_deleteCells(t,e,r){const n=(e??this._getDefaultShiftOrientation(t[0]))===exports.t.Orientation.Column,o=r?.description??"Delete Cells";if(this._protectionCheck(()=>[n?"deleteColumns":"deleteRows"],t,o),mh(t))throw new Error("We can't delete cells with overlapping selections.");const s=this._entireCoords;let i=s.colEnd,a=s.rowEnd;const l=n?exports.t.Direction.Left:exports.t.Direction.Up,c=Nm(t),h=this._beginCommit({description:o,operation:{name:"deleteCells"}}),d=h.getState(this);try{let e=d.cellValuesGrid,n=d.contentfulSpatial,o=d.mergeSpatial,u=d.unlockSpatial,g=d.directStyleSpatial,p=d.continuousFillSpatial,m=d.conditionalSpatial,f=d.hyperlinkSpatial,_=d.commentsSpatial,S=d.movableSpatial,w=d.movableMapModel,y=d.tableSpatial,x=d.tableMapModel,C=d.calcGraph,b=d.rangesListenerSpatial2,E=d.rangeListenerSpatial,v=d.rangesListenerMap;const I=new Map,A=Nl(t.slice(),exports.t.Direction.Left),R=A.length;for(let t=0;t<R;t++){const r=A[t];i=Math.min(i,r.colStart),a=Math.min(a,r.rowStart);e.getCoords()&&(e=e.clone(),e.shift(r,l),this._updateState({cellValuesGrid:e}));const c=r.colStart<=s.colStart&&r.colEnd>=s.colEnd,h=r.rowStart<=s.rowStart&&r.rowEnd>=s.rowEnd;c&&this._rowHeadersShiftCallback(r.rowStart,-1*(r.rowEnd-r.rowStart+1)),h&&this._colHeadersShiftCallback(r.colStart,-1*(r.colEnd-r.colStart+1)),n=n.shift({range:r,direction:l,cloneIfUpdate:n===d.contentfulSpatial}),u=u.shift({range:r,direction:l,cloneIfUpdate:u===d.unlockSpatial}),o=o.shift({range:r,direction:l,cloneIfUpdate:o===d.mergeSpatial}),g=g.shift({range:r,direction:l,cloneIfUpdate:g===d.directStyleSpatial}),p=p.shift({range:r,direction:l,cloneIfUpdate:p===d.continuousFillSpatial}),m=m.shift({range:r,direction:l,cloneIfUpdate:m===d.conditionalSpatial}),f=f.shift({range:r,direction:l,cloneIfUpdate:f===d.hyperlinkSpatial}),_=_.shift({range:r,direction:l,cloneIfUpdate:_===d.commentsSpatial}),S=S.shift({range:r,direction:l,cloneIfUpdate:S===d.movableSpatial}),y=y.shift({range:r,direction:l,cloneIfUpdate:y===d.tableSpatial}),C=C.shift({range:r,direction:l,cloneIfUpdate:C===d.calcGraph}),E=E.shift({range:r,direction:l,cloneIfUpdate:E===d.rangeListenerSpatial,onShift:t=>{v===d.rangesListenerMap&&(v=new Map(v)),this._processListenerShift(v,I,d.rangesListenerMap,t)}}),b=b.shift({range:r,direction:l,cloneIfUpdate:b===d.rangesListenerSpatial2})}this._updateState({contentfulSpatial:n,unlockSpatial:u,mergeSpatial:o,directStyleSpatial:g,continuousFillSpatial:p,conditionalSpatial:m,hyperlinkSpatial:f,commentsSpatial:_,movableSpatial:S,movableMapModel:w,tableSpatial:y,tableMapModel:x,calcGraph:C,rangesListenerSpatial2:b,rangeListenerSpatial:E,rangesListenerMap:v}),this._commitAndAutoSelect(h,c,r?.autoSelect,{viewAfter:{ranges:A,listeners:I}})}catch(t){if(h.rollback(),t instanceof Mt)throw new Error(t.message??eu);throw t}}_autoFit(e,r){if(this._closed)throw new Error(ou);r={expandOnly:!1,skipCustomSize:!1,minContent:!1,...r};const n="Autofit";let o;const s=im(e,this._entireCoords,!0),i=sm(e,this._entireCoords,!0);!s&&i?(r.orientations=r.orientations??exports.t.Orientations.Column,o=`${n} ${ES}`):!i&&s?(r.orientations=r.orientations??exports.t.Orientations.Row,o=`${n} ${bS}`):i&&s?(r.orientations=r.orientations??exports.t.Orientations.Both,o=`${n} All`):(r.orientations=r.orientations??exports.t.Orientations.Both,o=`${n}`);let a=r.orientations!==exports.t.Orientations.Row;this._colHeaders.isProtected()&&(a=!1);let l=r.orientations!==exports.t.Orientations.Column;if(this._rowHeaders.isProtected()&&(l=!1),!l&&!a)return;const c=a&&(!1===r.expandOnly||r.expandOnly===exports.t.Orientation.Row),h=l&&(!1===r.expandOnly||r.expandOnly===exports.t.Orientation.Column),d=r.minContent,u=Nm(e),g=this._beginCommit({description:r.description??o});try{let n=Number.MAX_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER,s=!1,i="",p=-1,m=!1,f=!1,_=!1,S=Number.MAX_SAFE_INTEGER,w=Number.MIN_SAFE_INTEGER;const y=this._styles.getNormal(),x=this._cellOptions,C=r.orientations===exports.t.Orientations.Row,b=new Map,E=yc(e,1);E.sort(U.createRangeComparator(exports.t.Orientation.Column));const v=E.length,I={skipCustomSize:r.skipCustomSize},A=exports.IFont.getDeviceScale(),R=this._defaultRowHeight()*A,M=(t,e=1)=>{if(0!==t&&null!==t&&!(e>1))return t=Math.max(t,R),e=>h?t:Math.max(e,t)},T=(t,e=1)=>{if(0!==t&&null!==t&&!(e>1))return e=>c?t:Math.max(e,t)};for(let e=0;e<v;e++){const r=[];let u=-1,g=!1,v=y,A=-1,R=1,F=1;const N=E[e];let k=N.colStart,O=N.rowStart,B=N.colEnd,L=N.rowEnd;const D=this._getUsedCoords();(h||c)&&D&&(k=h?D.colStart:N.colStart,O=c?D.rowStart:N.rowStart,B=h?D.colEnd:N.colEnd,L=c?D.rowEnd:N.rowEnd);const z={includeRangeTypes:{[$d.Type.Style]:!1,[$d.Type.Contentful]:!1},excludeHidden:!1,bounds:{colStart:k,rowStart:O,colEnd:B,rowEnd:L},orientation:exports.t.Orientation.Column},P=l?[]:void 0,j=a?[]:void 0,H=(t,e,r)=>{if(t>e)return null;const n=[];let o=t;const s=r?r.length:0;for(let t=0;t<s;t++){const e=r[t],s=e.min,i=e.max;if(o>=s){o=i+1;continue}const a={address:{min:o,max:s-1},update:hw};n.push(a),o=i+1}if(o<=e){const t={address:{min:o,max:e},update:hw};n.push(t)}return n},V=this._rangeStateIterator(z);let $=V.next();for(;!$.done;){const t=$.value,e=t.intersection,r=t.start,n=t.end;nw.colStart=r.colIndex,nw.rowStart=r.rowIndex,nw.colEnd=n.colIndex,nw.rowEnd=n.rowIndex;const o=U.intersectRanges(nw,N,rw),s=Kp(0,o,e,x).getBestFit();if(l){const t=Math.max(r.rowIndex,O),e={address:{min:t,max:Math.min(n.rowIndex,L)},update:{size:M(s.height),autoSize:!0}};P.push(e)}if(a){const t=Math.max(r.colIndex,k),e={address:{min:t,max:Math.min(n.colIndex,B)},update:{size:T(s.width),autoSize:!0}};j.push(e)}$=V.next()}if(j){let t=this._colHeaders.updateHeaderPairs(j,I);t=ta(ea(ra(t)));const e=H(N.colStart,N.colEnd,t);e&&this._colHeaders.updateHeaderPairs(e,I)}if(P){let t=this._rowHeaders.updateHeaderPairs(P,I);t=ta(ea(ra(t)));const e=H(N.rowStart,N.rowEnd,t);e&&this._rowHeaders.updateHeaderPairs(e,I)}const G=this._cellStateIterator({...z,includeRangeTypes:{[$d.Type.Merge]:!1,[$d.Type.Table]:!1,[$d.Type.Style]:!1},ignoreEmptyIntersections:!0});let W,q,J,X=G.next(),K=1,Y=1;for(;!X.done;){const e=X.value,a=e[0],l=e[2];let c=y;const h=l?.directStyle??null;h===W?c=q:(c=h?Kp(0,U.cellToRange(a,ow),l,x):y,q=c);let d=1,C=1;const b=l?.merge??null;if(b===J)d=K,C=Y;else{if(b){const t=b.getCoords();d=t.colEnd-t.colStart+1,C=t.rowEnd-t.rowStart+1}else d=1,C=1;K=d,Y=C}const E=a.colIndex,I=a.rowIndex,M=e[1],T=Rh(M),k=U.isCellWithinRange(a,N);let O=!1,B=!1;if(W!==h||d!==R||C!==F||T===t.String||T===t.Error||k!==g){if(O=!0,(d>1||C>1||T===t.RichData)&&(B=!0),!B&&l){const t=c.getAlignment().getHorizontal();t!==exports.ITextFrame.HorizontalAlignment.CenterContinuous&&t!==exports.ITextFrame.HorizontalAlignment.Fill||(B=!0)}B&&(O=!1)}if(W=h,J=b,(u!==E||O)&&(u!==E&&(A=this._colHeaders.getSpanSize(E)),-1!==u&&r.push({col:u,style:v,spanWidth:d,spanHeight:C,minVal:n,maxVal:o,hasZero:s,text:i,textId:p,hasFalse:f,hasTrue:m,hasEmpty:_,minRow:S,maxRow:w,colWidth:A,measureWidth:-1,measureHeight:-1,isFit:g}),u=E,v=c,g=k,R=d,F=C,n=Number.MAX_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER,s=!1,i="",p=-1,f=!1,m=!1,_=!1,S=I),w=I,!B)if(null===M)_=!0;else switch(T){case t.Number:0===M&&(s=!0),n=Math.min(n,M),o=Math.max(o,M);break;case t.String:i=M,p=M;break;case t.Error:i=M.toString(),p=-1;break;case t.Boolean:M?m=!0:f=!0}X=G.next()}-1!==u&&r.push({col:u,style:v,spanWidth:R,spanHeight:F,minVal:n,maxVal:o,hasZero:s,text:i,textId:p,hasFalse:f,hasTrue:m,hasEmpty:_,minRow:S,maxRow:w,colWidth:A,measureWidth:-1,measureHeight:-1,isFit:g});let Z=-1,Q=-1;const tt=r.length;for(let e=0;e<tt;e++){const n=r[e],o=C||!n.isFit,s=n.maxVal,i=n.style,a=n.colWidth;if(Z=0,Q=0,s!==Number.MIN_SAFE_INTEGER){const e=Yp(t.Number,i,s,x,a,d,o);Z=e.width,Q=e.height;const r=n.minVal;if(r*s<0){const e=Yp(t.Number,i,r,x,a,d,o);Z=Math.max(Z,e.width),Q=Math.max(Q,e.height)}if(n.hasZero&&0!==r&&0!==s){const e=Yp(t.Number,i,0,x,a,d,o);Z=Math.max(Z,e.width),Q=Math.max(Q,e.height)}}const l=n.text;if(l.length>0){const e=Yp(t.String,i,l,x,a,d,o,void 0,b);Z=Math.max(Z,e.width),Q=Math.max(Q,e.height)}if(n.hasTrue||n.hasFalse){const e=Yp(t.Boolean,i,!n.hasFalse,x,a,d,o);Z=Math.max(Z,e.width),Q=Math.max(Q,e.height)}if(n.hasEmpty){const e=Yp(t.Boolean,i,null,x,a,d,o);Z=Math.max(Z,e.width),Q=Math.max(Q,e.height)}n.measureWidth=Z,n.measureHeight=Q}if(a){const t=[];for(let e=0;e<tt;e++){let n=r[e];const o=n.col;let s=r[e+1],i=n.measureWidth??0;for(;s&&s.col===o;)s.measureWidth&&(i=Math.max(s.measureWidth??0,i)),e++,n=r[e],s=r[e+1];0===i&&(i=null);const a=T(i,n.spanWidth);t.push({address:{min:o,max:o},update:{size:a,autoSize:!0}})}this._colHeaders.updateHeaderPairs(t,I)}if(l){let t=1;const e={onUpdate:(e,r,n)=>{if(!(t>1))return null===e?r:Math.max(r,e)}};let n=[];for(let o=0;o<tt;o++){const s=r[o];t=s.spanHeight;n=ta(Qi(n,{min:s.minRow,max:s.maxRow,value:s.measureHeight},e))}const o=n.length,s=new Array(o);for(let t=0;t<o;t++){const e=n[t],r=M(e.value,1),o={address:{min:e.min,max:e.max},update:{size:r,autoSize:!0}};s[t]=o}this._rowHeaders.updateHeaderPairs(s,I)}}this._commitAndAutoSelect(g,u,r?.autoSelect,{viewAfter:{ranges:e}})}catch(t){throw g.rollback(),t}}_createRangeEvent(t,e){const r=this,n=()=>{const e=r._getState();return this._closed||e.deleted?_m(null):t?Array.isArray(t)?r._createRanges(t):r._createRange(t):_m(this,this._entireCoords)},o=e.trigger;return{getSource:n,getFrom:()=>e.from??null,getTo:()=>e.to??null,trigger:o,isUndo:e.isUndo??!1,isDataChange:e.isDataChange??!1,isTransactional:e.isTransactional??!0,toString:()=>`SheetRangeEvent: ('${o}', ${n().toString()})`,timeStamp:e.timeStamp??Date.now()}}_notifyAddressListeners(t,e,r,n){const o=e.entries();let s=o.next();const i=n.trigger;for(;!s.done;){const e=s.value[0];let a=s[1];if(a||(a=t.get(e)),a&&!r.has(e)){let t=!1;const o=a.options;o&&(t="address"===i?o.ignoreAddressChanges:o.ignoreDataChanges),!0!==t&&a.notify(n),r.add(e)}s=o.next()}}_notifyDataListeners(t,e,r=null,n,o){if(!t)return;const s=r.length;for(let i=0;i<s;i++){const s=r[i];if(!s)continue;const a=t.search(s),l=a.length;for(let t=0;t<l;t++){const r=a[t].value.groupId;if(!n.has(r)){const t=e.get(r);!0!==t.options?.ignoreDataChanges&&t.notify(o),n.add(r)}}}}_notifyRangeListeners(t,e,r=null,n){if(!t)return;const o=new Set;n.timeStamp||(n.timeStamp=Date.now());const s=r.length;for(let i=0;i<s;i++){const s=r[i];if(!s)continue;const a=t.search(s),l=a.length;for(let t=0;t<l;t++){const r=a[t].value.id;if(o.has(r))continue;const s=e.get(r);o.add(r);const i=s.ranges,l=i.length;for(let t=0;t<l;t++){const e=i[t],r=this._createRangeEvent(e,n);this._notifyRangeListener2(s,r,n)}}}}_notifyRangeListener2(t,e=null,r=null){const n=t.options;if(n?.ignoreDataChanges&&r?.isDataChange)return;const o=t.handler??t.handlerW.deref();if(o)try{o?.(e)}catch(t){console.warn(t)}}_notifyUsedRangeChange(){this._lastCellRead.coords=null,this._lastUsedCoordsRead.coords=null,this._emitter.notify("onUsedRangeChange")}_notifyMergeChange(){this._emitter.notify("onMergesChange")}addListeners(t,e){let r=null;if(t.onLayoutChange){const n=t,o={onSizesChange:()=>{n.onLayoutChange(this)}};r=[],r.push(this._colHeaders.addListeners(o,e)),r.push(this._rowHeaders.addListeners(o,e))}let n=this._emitter.addListeners(t,e);if(r){const t=n;n=()=>{const e=r.length;for(let t=0;t<e;t++)r[t]();t()}}return n}_addRangesListeners(t,e,r){if(this._closed)throw new Error(ou);if(!e)throw new Error(Yd);r=r?{...iw,...r}:iw;const n=r?.transactional??!1,o=this,s=YS++%Number.MAX_SAFE_INTEGER,i=()=>{let t=null,e=null;if(n){const r=o._getState();if(!r)return;t=r.rangeListenerSpatial.clone(),e=new Map(r.rangesListenerMap)}else t=o._rangeListenerSpatial,e=o._rangesListenerMap;const r=e.get(s);if(!r)return void console.log("Listener not found");const i=r.ranges,a=i.length;for(let e=0;e<a;e++){const r=U.sanitizeRange(i[e]);null!==r&&t.remove(r,(t,e)=>{if(e.value.id===s)return!0})}if(e.delete(s),n){const r=this._beginCommit({description:"Remove Range Listener"});this._updateState({rangeListenerSpatial:t,rangesListenerMap:e}),r.commit({forceAmend:!0})}},a=[...t];let l={id:s,handler:null,handlerW:null,removeListener:i,options:r,ranges:a};r?.weakly?l.handlerW=new WeakRef(e):l.handler=e;let c=null,h=null,d=null;if(n){d=this._beginCommit({description:"Add Range Listener"});const t=this._getState();c=t.rangeListenerSpatial.clone(),h=new Map(t.rangesListenerMap)}else c=o._rangeListenerSpatial,h=o._rangesListenerMap;const u=[],g=t.length;for(let e=0;e<g;e++){const n={...t[e],value:{id:s,offset:e,options:r}};u.push(n)}return c.load(u),h.set(s,l),d&&(this._updateState({rangeListenerSpatial:c,rangesListenerMap:h}),d.commit({forceAmend:!0})),i}_addRangesListeners2(t,e,r,n){if(this._closed)throw new Error(ou);if(!e)throw new Error(Yd);r=r?{...iw,...r}:iw;const o=r?.transactional??!1,s=this,i=mt.uuidV4(),a=QS++,l=()=>{let t=null,e=null;const r=s._getState();if(!r)return;t=r.rangesListenerSpatial2.clone(),e=r.rangesListenerMap2;const n=e.get(i);if(n){const o=n?.spatialsIds,s=n?.coords,a=o.length;for(let e=0;e<a;e++){const r=o[e],n=s[e];t.remove(n,(t,e)=>{if(e.value.uuid===r)return!0})}e=new Map(r.rangesListenerMap2),e.delete(i)}const l=this._beginCommit({description:"Remove Range Listener"});this._updateState({rangesListenerMap2:e}),l.commit({forceAmend:!0}),o||this._rangesListenerSorted.delete(a)};let c=null,h=this._beginCommit({description:"Add Range Listener"});const d=this._getState();c=d.rangesListenerSpatial2.clone();let u=null,g=null;r?.weakly?g=new WeakRef(e):u=e;const p=[],m=[...t];let f=[];const _=t.length;for(let e=0;e<_;e++){const n={...t[e]};m[e]=n;const o=mt.uuidV4(),s=new TS(i,o,r?.ignoreAddressChanges??!1);f.push(o);const a={...U.sanitizeRange(n),value:s};p.push(a)}c.load(p),r={...r};const S=new FS(i,f,m,n,this,a,u,g,l,r),w=new Map(d.rangesListenerMap2);return w.set(i,S),this._updateState({rangesListenerSpatial2:c,rangesListenerMap2:w}),o||this._rangesListenerSorted.set(a,S),h.commit({forceAmend:!0}),l}_getUsedCoords(t){const e=this._getState();if(!e)return null;let r=e.cellValuesGrid.getCoords();return r=U.unionRanges(e.mergeSpatial.getBoundingCoords(),r),r=U.unionRanges(e.directStyleSpatial.getBoundingCoords(),r),r=U.unionRanges(e.formulaSpatial.getBoundingCoords(),r),r=U.unionRanges(e.spillSpatial.getBoundingCoords(),r),r=U.unionRanges(e.pendingSpatial.getBoundingCoords(),r),r&&(r.colStart=Math.max(r.colStart,this._entireCoords.colStart),r.rowStart=Math.max(r.rowStart,this._entireCoords.rowStart),r.colEnd=Math.min(r.colEnd,this._entireCoords.colEnd),r.rowEnd=Math.min(r.rowEnd,this._entireCoords.rowEnd)),!r||r.rowStart>r.rowEnd||r.colStart>r.colEnd?(this._lastUsedCoordsRead.coords=null,null):(this._lastUsedCoordsRead&&this._lastUsedCoordsRead.coords&&bm(this._lastUsedCoordsRead.coords,r)||(this._lastUsedCoordsRead.coords=r,this._lastUsedCoordsRead.range=null),this._lastUsedCoordsRead.coords)}_isContentful(t,e){return!!this._contentCounts(t,void 0,e)}_getCount(t,e=!1){const r=this._contentCounts(t,cw,e);return r?r[exports.ICell.Content.Values]??0:0}_contentCounts(t,e,r){if(!e){const t=Object.keys(exports.ICell.Content),r=t.length;e=new Array(r);for(let n=0;n<r;n++){const r=t[n];e[n]=exports.ICell.Content[r]}}const n={},o=e.length;let s,i,a=!1;for(let t=0;t<o;t++){const r=e[t];r===exports.ICell.Content.Values?(n[$d.Type.Contentful]=!1,n[$d.Type.Table]=!1):r===exports.ICell.Content.Formulas?n[$d.Type.Formula]=!1:r===exports.ICell.Content.Formats?n[$d.Type.Style]=!1:r===exports.ICell.Content.Tables&&(n[$d.Type.Table]=!1,a=!0)}const l=()=>{s=new Set,i={};for(let t=0;t<o;t++){const r=e[t];i[r]=0}},c=t.length;for(let e=0;e<c;e++){const o=t[e],c=this._rangeStateIterator({includeRangeTypes:n,excludeHidden:r,bounds:o});let h=c.next();for(;!h.done;){i||l();const t=h.value,e=(t.end.colIndex-t.start.colIndex+1)*(t.end.rowIndex-t.start.rowIndex+1),r=t.intersection;if(r){r.contentful&&(i[exports.ICell.Content.Values]+=e),r.formula&&(i[exports.ICell.Content.Formulas]+=e);const t=r.table;t&&(a&&!s.has(t)&&(i[exports.ICell.Content.Tables]+=1,s.add(t)),r.contentful||(i[exports.ICell.Content.Values]+=e))}h=c.next()}}return i}getSelectedCell(){const t=this.getSelection().getCoords().cell,e=this._lastCellSelected;if(e?.cell&&U.isEqualCells(t,e.coords))return e.cell;const r=this.getRange(t).getCell();return this._lastCellSelected={coords:t,cell:r},r}find(t,e){return this.getEntireRange().find(t,e)}_find(t,e,r){if(this._closed)throw new Error(ou);if(!e)return null;const n=[...t],o=r?.orientation??exports.t.Orientation.Row,s=r?.reverse,i=!r?.disableWrap,a=r?.from?this._cellToCoords(r?.from):null;let l=null;if(a){let t=-1;for(let e=0;-1===t&&e<n.length;e++)U.isCellWithinRange(a,n[e])&&(t=e);l=U.cellToRange(a);let e=fh(n[t],l,o);e.push(l);const r=U.createRangeComparator(o,s);e.sort(r);let c=-1;const h=e.length;for(let t=0;t<h;t++){r(e[t],l)<=0&&(c=t)}n.splice(t,1,...e);const d=t+c,u=[];for(let t=0;t<=d;t++)u.push(n.shift());if(i){const t=u.length;for(let e=0;e<t;e++)n.push(u[e])}}if(0===n.length)return bl;const c=r?.fields?.includes(exports.ICell.Content.Formulas)??!1,h=r?.fields?.includes(exports.ICell.Content.Values)??!0,d=r?.matchEntireCell??!1,u=r?.matchCase??!1,g=r?.useRegex??!1,p=((t,e,r)=>{const n=e?"":"i";return r?new RegExp(t,n):new RegExp((t=>{let e=t.replace(/[|\\{}()[\]^$+.]/g,"\\$&");return e=e.replace(/~\?/g,"\\?"),e=e.replace(/~\*/g,"\\*"),e=e.replace(/~~/g,"~"),e})(t),n)})(e,u,g),m=e.length;let f=(t,e)=>{const r=t=>{if(!t)return!1;let e=!!t.match(p);return e&&d&&t.length!==m&&(e=!1),e},n=e.getCell();let o=!1;return!o&&c?o=r(n.getFormulaText()??n.toTextUnformatted(!0)):h&&(o=r(n.getNumberFormat().displayText)),o};if(r?.matchCustom){const t=r.matchCustom,e={matchCase:u,matchEntireCell:d,useRegex:g,fields:r?.fields??[exports.ICell.Content.Formulas]};let n,o,s=f;const i=()=>s(n,o);f=(r,s)=>(n=r,o=s,t(r,i,e,s))}let _=-1,S=null,w=Cl,y=!1;const x=()=>{if(w.done){if(_++,_>=n.length)return void(y=!0);S=this._cellIterator({reverse:s,orientation:o,includeRangeTypes:!1,bounds:n[_]})}if(w=S.next(),!w.done){const t=w.value;return f(t.value,t.context)}return!1};return{next:()=>{let t=null;for(;!y&&!t;)x()&&(t=w.value.context.getCell());return t?{value:t,done:!1}:Cl}}}isDate1904(){return this._isDate1904}_surroundingRegion(t,e){const r=this._getState(),n=e?.contentOnly??!1,o=this._entireCoords;if(!n){const e=r.tableSpatial.search(t);if(e.length>0){const r=e[0].value.model,n=r.getUsedRange().getCoords(),s=r.getRange().getCoords();return U.isEqualRanges(n,t)?s:U.isEqualRanges(s,t)?o:n}}const s=n?t:o,i=((t,e,r=2e4)=>{if(!e||0===e.length)return null;let n,o=!1;for(let r=0;r<e.length;r++){const s=e[r];n=U.unionRanges(n,s.getBoundingCoords()),o=o||s.search(t).length>0}if(!n)return null;const s={...U.EmptyRange},i=t;let a=o?{...t}:null;if(!a){const r=t=>{let r=[];const n=e.length;for(let o=0;o<n;o++){const n=e[o].search(t),s=n.length;r=s>0?new Array(s):void 0;for(let t=0;t<s;t++){const e=n[t];r[t]=e}}return r||mt.EmptyArray},n=r({colStart:t.colEnd,rowStart:t.rowEnd,colEnd:t.colEnd+1,rowEnd:t.rowEnd+1}),o=n.length;if(o>0){a={...t};for(let t=0;t<o;t++){const e=n[t];a.colEnd=Math.max(a.colEnd,e.colStart),a.rowEnd=Math.max(a.rowEnd,e.rowStart)}}}const l={...U.EmptyRange},c=()=>{const t=e.length;for(let r=0;r<t;r++){const t=e[r].search(s),n=t.length;for(let e=0;e<n;e++){const r=t[e];a=U.unionRanges(a,r,l)}}return a};s.colStart=t.colStart,s.rowStart=t.rowStart,s.colEnd=t.colEnd,s.rowEnd=t.rowEnd,c();const h={...a},d={...U.EmptyRange};let u=0;do{if(s.colStart=d.colStart=h.colStart,s.rowStart=d.rowStart=h.rowStart,s.colEnd=d.colEnd=h.colEnd,s.rowEnd=d.rowEnd=h.rowEnd,h.colStart>n.colStart&&(s.colStart=h.colStart-1,s.colEnd=h.colStart-1,s.rowStart=h.rowStart-1,s.rowEnd=h.rowEnd+1,c()),h.rowStart>n.rowStart&&(s.rowStart=h.rowStart-1,s.rowEnd=h.rowStart-1,s.colStart=h.colStart-1,s.colEnd=h.colEnd+1,c()),h.colEnd<n.colEnd&&(s.colStart=h.colEnd+1,s.colEnd=h.colEnd+1,s.rowStart=h.rowStart-1,s.rowEnd=h.rowEnd+1,c()),h.rowEnd<n.rowEnd&&(s.rowStart=h.rowEnd+1,s.rowEnd=h.rowEnd+1,s.colStart=h.colStart-1,s.colEnd=h.colEnd+1,c()),!a)return null;if(h.colStart=a.colStart,h.rowStart=a.rowStart,h.colEnd=a.colEnd,h.rowEnd=a.rowEnd,U.isEqualRanges(h,d))return U.isEqualRanges(i,h)?null:h;if(U.isEqualRanges(h,i))return null;if(U.isEqualRanges(h,d))return h;u++}while(u<r);return null})(t,[r.contentfulSpatial,r.mergeSpatial,r.formulaSpatial,r.spillSpatial,r.pendingSpatial]);return i||s}_extendRange(t,e){if(this._closed)throw new Error(ou);const r=this._entireCoords,n=this,o={excludeHidden:!0,onEntry:(t,e)=>e},s={excludeHidden:!0,onEntry:(t,e)=>void 0===t.tvTl()?null:e};let i;const a=n._getRangedEntries("mergeSpatial",[U.cellToRange(e)],s);a.length>0&&(i=a[0]);const l=[t=>n._getRangedEntries("mergeSpatial",t,s),t=>n._getRangedEntries("contentfulSpatial",t,o)];return((t,e,r,n,o)=>{let s,i,a,l={...e},c=U.cellToRange(l),h=n(c).length>0;if(h){let e=1,o=t===exports.t.Direction.Up||t===exports.t.Direction.Down;r&&(e+=o?r.rowEnd-r.rowStart:r.colEnd-r.colStart),t!==exports.t.Direction.Left&&t!==exports.t.Direction.Up||(e=-e),o?l.rowIndex=l.rowIndex+e:l.colIndex=l.colIndex+e,c=U.cellToRange(l),h=n(c).length>0}switch(t){case exports.t.Direction.Up:c.rowStart=Math.min(o.rowStart,c.rowStart),i=n(c).sort(U.createRangeComparator(exports.t.Orientation.Row,!0)),s=e.rowIndex,a=h?1===i.length&&s===i[0].rowStart?o.rowStart:i[0].rowStart:0===i.length?o.rowStart:i[0].rowEnd;break;case exports.t.Direction.Down:c.rowEnd=Math.max(o.rowEnd,c.rowEnd),i=n(c).sort(U.createRangeComparator(exports.t.Orientation.Row,!1)),s=e.rowIndex,a=h?1===i.length&&s===i[0].rowEnd?o.rowEnd:i[0].rowEnd:0===i.length?o.rowEnd:i[0].rowStart;break;case exports.t.Direction.Left:c.colStart=Math.min(o.colStart,c.colStart),i=n(c).sort(U.createRangeComparator(exports.t.Orientation.Column,!0)),s=e.colIndex,a=h?1===i.length&&s===i[0].colStart?o.colStart:i[0].colStart:0===i.length?o.colStart:i[0].colEnd;break;case exports.t.Direction.Right:c.colEnd=Math.max(o.colEnd,c.colEnd),i=n(c).sort(U.createRangeComparator(exports.t.Orientation.Column,!1)),s=e.colIndex,a=h?1===i.length&&s===i[0].colEnd?o.colEnd:i[0].colEnd:0===i.length?o.colEnd:i[0].colStart}if(h&&i.length>1){let e=!1;for(let r=1;!e&&r<i.length;r++){const n=i[r];switch(t){case exports.t.Direction.Up:n.rowEnd<a-1?e=!0:a=Math.min(a,n.rowStart);break;case exports.t.Direction.Down:n.rowStart>a+1?e=!0:a=Math.max(a,n.rowEnd);break;case exports.t.Direction.Left:n.colEnd<a-1?e=!0:a=Math.min(a,n.colStart);break;case exports.t.Direction.Right:n.colStart>a+1?e=!0:a=Math.max(a,n.colEnd)}}}const d=U.cellToRange(e);switch(t){case exports.t.Direction.Up:d.rowStart=a;break;case exports.t.Direction.Down:d.rowEnd=a;break;case exports.t.Direction.Left:d.colStart=a;break;case exports.t.Direction.Right:d.colEnd=a}return d})(t,e,i,t=>{const e=[],r=[t],n=l.length;for(let t=0;t<n;t++){const n=(0,l[t])(r),o=n.length;for(let t=0;t<o;t++){const r=n[t];e.push(r)}}return e},r)}_defaultFontDims(){if(this._defaultFontBoundsCache)return this._defaultFontBoundsCache;const t=this._styles.getNormal();let e=0,r=0;for(let n=0;n<=9;n++){const o=t.measureText(n.toString());e=Math.ceil(Math.max(o.width,e)),r=Math.max(o.lineHeight,r)}return this._defaultFontBoundsCache={width:e,height:r},this._defaultFontBoundsCache}getColumnWidthAsFontUnit(t){const e=Math.round(this._defaultFontDims().width),r=t/(this.getView().isShowFormulas()?2:1);if(!e||!t)return 0;let n=5;return r<n+e&&(n=r*(n/(n+e))),(r-n)/e}_defaultColWidth(){if(this._defaultColWidthCache)return this._defaultColWidthCache;const t=this._defaultFontDims()?.width||7,e=8*Math.round((8*t+5)/8);return this._defaultColWidthCache=e}_defaultRowHeight(){if(this._defaultRowHeightCache)return this._defaultRowHeightCache;let t=this._defaultFontDims();if(!t||0===t.width)return this._defaultRowHeightCache=20/exports.IFont.getDeviceScale(),this._defaultRowHeightCache;const e=this._styles.getNormal(),r=new Map;let n=t.height+2;return this._colHeaders.getUsedRange().forEachSpan((t,o)=>{const s=o.getCellHeader();s?.getStyle()!==e&&(n=Math.max((t=>{let e=r.get(t);void 0===e&&(e=t.measureText("M").lineHeight+2,r.set(t,e));return e})(s.getStyle()),n))}),this._defaultRowHeightCache=Math.round(n/exports.IFont.getDeviceScale()*4)/4,this._defaultRowHeightCache}getProtection(){return this._protection??null}async _selectSheet(t,e){if(!1===await(this._options.container?.requestSelect?.()))return!1;if(!1===e)return!0;const r={coords:t};!0!==e&&void 0!==e&&(r.scrollIntoView=e);const n=await this._emitter.notify("onRequestScrollIntoView",{params:r,async:!0});if(!n)return!1;const o=n.length;for(let t=0;t<o;t++)if(!1===n[t])return!1;return!0}async scrollTo(t,e){const r={...e,coords:t},n=await this._emitter.notify("onRequestScrollIntoView",{params:r,async:!0});if(!n)return!1;const o=n.length;for(let t=0;t<o;t++)if(!1===n[t])return!1}async _commitAndAutoSelect(t,e,r=!1,n){return n={...n,viewAfter:{view:this.getView(),selection:e,selectOptions:r,...n?.viewAfter}},t.commit(n),this._autoSelect(r,e)}async _autoSelect(t,e){if(!t)return;!0===t&&(t={autoFocus:!0,scrollIntoView:!0});const r=t?.autoFocus,n=t?.scrollIntoView,o=t?.anchor,s=this.getSelection().getCoords(),i=Fm(e??s),a=this._entireCoords,l=((t,e,r)=>{if(!t||0===t.length||!e)return mt.EmptyArray;const n=[...t];for(let t=0;t<n.length;t++){const o={...n[t]};let s=o;const i=e.search(o),a=o.rowStart<=r.rowStart&&o.rowEnd>=r.rowEnd,l=o.colStart<=r.colStart&&o.colStart>=r.colEnd;for(let t=0;t<i.length;t++){const e=i[t];a||(s.colStart=Math.min(s.colStart,e.colStart),s.colEnd=Math.max(s.colEnd,e.colEnd)),l||(s.rowStart=Math.min(s.rowStart,e.rowStart),s.rowEnd=Math.max(s.rowEnd,e.rowEnd))}n[t]=s}return n})(i,this._getState().mergeSpatial,a);let c=-1,h=null;if(!o){const t=s?.cell;for(let e=0;-1===c&&e<l.length;e++){const r=l[e];U.isCellWithinRange(t,r)&&(c=e,h=t)}}const d=Tm(l,h,c);this.getSelection().updateCoords(d);const u=d.ranges?.[d.rangeIndex]??U.cellToRange(d.cell),g=await this._selectSheet(u,n);if(!1!==n&&!1===g)return l;if(!1!==r){const t=await this._emitter.notify("onRequestFocus");if(!t)return l;const e=t.length;for(let r=0;r<e;r++)if(!1===t[r])return l}return l}getSelection(){return this._rangeSelection}getView(){return this._view}setView(t){if(this._closed)throw new Error(ou);if(!t)throw new Error("View can not be empty.");this._viewRemoveListener?.(),this._view=t,this._viewRemoveListener=t.addListeners(this._viewListener,{transactional:!1});const e=this.getSelection().getCoords();return this._rangeSelection.updateCoords(e),this._emitter.notify("onMovableSelectionChange"),this._emitter.notify("onTopLeftChange"),this._emitter.notify("onFreezeSplitChange"),this._emitter.notify("onViewChange",{source:t}),this}getTabColor(){return this._tabColor}setTabColor(t){if(this._closed)throw new Error(ou);return this._tabColor="string"==typeof t?this._styles.parseColor(t):t??null,this._emitter.notify("onTabColorChange"),this}getRowHeaders(){return this._rowHeaders}getColumnHeaders(){return this._colHeaders}async toJSON(e=!1){if(this._closed)throw new Error(ou);await this._emitter.notify("onBeforeSave",{async:!0}),await Promise.resolve(this._starting);let r={};const n=this._getState();if(!n)return r;try{const n=this._strings.beginPersist();try{if(!e){const e=[],o=this._cellStateIterator({includeRangeTypes:!1,orientation:exports.t.Orientation.Column});let s=o.next(),i=Number.MIN_SAFE_INTEGER,a=Number.MIN_SAFE_INTEGER,l=null,c=null,h=null,d=null;for(;!s.done;){const r=s.value[0],u=r.colIndex,g=r.rowIndex;u!==i&&(d&&e.push(d),l=[],h=[],d=[u,h],i=u,a=g-2),g>a+1&&(l=[],c=[g,l],h.push(c));const p=s.value[1],m=Rh(p);let f;if(m===t.Number||m===t.Boolean)f=p;else if(m===t.String){f=""+n.add(p)}else if(m===t.Error)f={t:m,v:p.getCode()};else if(m===t.RichData){const t=p,e=t.type,r=t?.toJSON?.();if(e&&r){f={t:m,v:0}}}else console.warn("error",f);l.push(f),a=g,s=o.next()}d&&e.push(d),e.length>0&&(r.data=e)}this._ownStrings&&(r.strings=await n.toJSONAsync())}catch(t){console.warn("error",t)}finally{n.endPersist()}const o=this._colHeaders.toJSON();o&&(o.headers&&o.headers.length>0&&(r.cols=o.headers),void 0!==o.defaultSize&&-1!==o.defaultSize&&(r.defaultColSize=o.defaultSize));const s=this._rowHeaders.toJSON();s&&(s.headers&&s.headers.length>0&&(r.rows=s.headers),void 0!==s.defaultSize&&-1!==s.defaultSize&&(r.defaultRowSize=s.defaultSize));const i=this.getProtection().toJSON();i&&(r.protection=i),this._view.setRangeSelection(this.getSelection().getCoords());const a=this._view.toJSON();a&&(r.view=a),this._tabColor&&(r.tabColor=this._tabColor.toString())}catch(t){console.warn(t)}const o=Nl(n.mergeSpatial.all());o.length>0&&(r.merges=ud(o));const s=Nl(n.directStyleSpatial.all());if(s.length>0){const t=this._styles.beginPersist();try{const e=[],n=s.length;for(let r=0;r<n;r++){const n=s[r],o=t.getElementID(n.value.toJSON());e.push({r:exports.AddressUtils.rangeToString(n),v:o})}if(r.directStyles=e,this._ownStyles){const e=t.toJSON();e&&Object.keys(e).length>0&&(r.styles=e)}}catch(t){console.warn(t)}finally{t.endPersist()}}const i=Nl(n.hyperlinkSpatial.all()),a=i.length;if(a>0){const t=[];for(let e=0;e<a;e++){const r=i[e];let n=r.value;t.push({r:exports.AddressUtils.rangeToString(r),v:n})}r.hyperlinks=t}const l=Nl(n.commentsSpatial.all()),c=l.length;if(c>0){const t=[];for(let e=0;e<c;e++){const r=l[e],n={...r.value};n.ref=exports.AddressUtils.rangeToString(r),t.push(n)}r.comments=t}const h=this._resources.beginPersist();try{const t=this.getMovables().search(),e=t.length;if(e>0){const n=[];for(let r=0;r<e;r++)try{const e=t[r].toJSON(h.toResourceId.bind(h));e&&n.push(e)}catch(t){console.warn("Unable to persist movable",t)}n.length>0&&(r.movables=n)}this._ownResources&&(r.resources=await h.toJSONAsync())}catch(t){console.warn(t)}finally{h.endPersist()}const d=Nl(n.tableSpatial.all()),u=d.length;if(u>0){const t=[];for(let e=0;e<u;e++){const r=d[e].value.model.toJSON();t.push(r)}r.tables=t}const g=Array.from(n.conditionalModels.values()),p=g.length;if(p>0){const t=[];for(let e=0;e<p;e++){const r=g[e].model.toJSON();t.push(r)}r.conditionals=t}const m=await n.calcGraph.toJSON(!1);if(m){const t=m.formulas;t&&(r.formulas=t);const e=m.dynamic;e&&(r.dynamicArray=e);const n=m.volatile;n&&(r.volatile=n)}return this._emitter.notify("onSave",{params:r}),r}getStyles(){return this._styles}getResources(){return this._resources}getTransactions(){return this._transactions}getStrings(){return this._strings}_searchMovables(t){const e=t?.excludeHidden??!1,r=t?.bounds,n=t?.fullyContained,o=this,s=t?.address?this._rangeToCoords(t?.address):this._entireCoords,i=this._getRangedEntries("movableSpatial",[s],{excludeHidden:e,fullyContained:n,onEntry:n=>{if(t?.type&&n.model.getContent().getType()!==t.type)return null;let s=null;if(e){if(n.model.isHidden())return null;if(s=o._getBoundsAtCoords(n.model.getAnchorCoords()),0===s.width||0===s.height)return null}if(r){s||(s=o._getBoundsAtCoords(n.model.getAnchorCoords()));const t=s,e=r;if(t.y>e.y+e.height||t.y+t.height<e.y||t.x>e.x+e.width||t.x+t.width<e.x)return null}return n.model}}),a=i.sort((t,e)=>t.getZIndex()-e.getZIndex());return a}_updateSelectedMovables(t,e){const r=this.getView().getMovableSelection();if(!r||0===r.length)return;let n="Movables";if(1===r.length){const t=r[0];n=ks(t.getContent().getType())??"Drawing"}const o=this._beginCommit({description:`${e} ${n}`});try{const e=r.length;for(let n=0;n<e;n++){t(r[n])}o.commit()}catch(t){throw o.rollback(),t}}async _addMovable(t){if(!this.getProtection().isObjectsAllowed())throw new Error(Zd);if(!t)throw new Error("No movable options provided");if(this._closed)throw new Error(ou);const e={};t?.type&&(e.content={type:t.type,json:t?.json}),t?.anchorType&&(e.anchorType=t?.anchorType),t.bounds&&(e.anchor=null);const r=this._getState().movableSpatial,n=this._beginCommit({description:t?.description??"Insert Drawing"}),o=this._createMovableEntry(e,r.size(),t.fromResourceId),s=r.clone();s.insert(o);const i=this._getState().movableMapModel,a=new Map(i),l=o.value.model;a.set(l,o),this._updateState({movableSpatial:s,movableMapModel:a}),t.bounds&&o.value.model.setBounds(t.bounds,t);let c=null,h=null;if(!1!==t?.autoSelect){c={view:this.getView(),movableSelection:this.getView().getMovableSelection()};let e=t?.autoSelect??!1;!0===e&&(e={autoFocus:!0,scrollIntoView:!0,addToSelection:!1}),e&&this.getView().selectMovables([o.value.model],e.addToSelection),h=t=>({...t,view:this.getView(),movableSelection:this.getView().getMovableSelection()})}return n.commit({viewBefore:c,viewAfter:h}),this._emitterMovables.notify("onCollectionChange"),this._emitter.notify("onMovablesChange"),o.value.model}async _addImage(t,e={type:"picture"}){if(!t)throw new Error("An image must be provided as a string or a resource option.");if(!this.getProtection().isObjectsAllowed())throw new Error(Zd);const r=this._resources.add(t),n=await r.toBuffer(),o=await r.getType(),s=this._getBoundsAtCoords(Fm(this.getSelection().getCoords())[0]),{naturalDimensions:i,asUrl:a}=await Et.loadImageDetails(n,o);URL.revokeObjectURL(a);const l={...s,...i,...e?.bounds};if(mt.isNullOrUndefined(e?.bounds?.x)||mt.isNullOrUndefined(e?.bounds?.y)){const t=Z_(this.getMovables(),l,mt.isNullOrUndefined(e?.bounds?.x),mt.isNullOrUndefined(e?.bounds?.y));l.x+=t.x,l.y+=t.y}e?.bounds&&!1!==e?.json?.lockAspect&&(mt.isNullOrUndefined(e?.bounds.width)&&mt.isDefined(e?.bounds.height)&&(l.width=l.height*i.width/i.height),mt.isNullOrUndefined(e?.bounds.height)&&mt.isDefined(e?.bounds.width)&&(l.height=l.width*i.height/i.width));const c={...e?.json,resId:0};return await this._addMovable({anchorType:exports.IAnchored.Type.OneCell,description:"Insert Image",...e,bounds:l,type:"picture",json:c,fromResourceId:t=>0!==t?(console.warn("received an unexpected resourceId",t),null):r})}getTables(){return this._tables}getConditionals(){return this._conditionals}getMovables(){return this._movables}_doPerfTest(t=1e7,e=!1){const r=Array.from({length:t},(t,e)=>e);let n,o;n=performance.now(),e&&console.profile("nativeArray");const s=[t];for(let e=0;e<t;e++)s.push(e);e&&console.profileEnd("nativeArray"),window.noLoseArray=s,o=performance.now(),console.log(`NativeArray: ${t} records in ${o-n} milliseconds`),n=performance.now(),e&&console.profile("mixedType");const i=Kc.fromArray(r);e&&console.profileEnd("mixedType"),window.noLoseList=i,o=performance.now(),console.log(`MixedTypedList: ${t} records in ${o-n} milliseconds`)}_validateOrRemoveOverlaps(t,e,r=null,n=!1){const o=this;"merge"!==e&&_h(this._getMerges([t]),t,(t,r)=>{if(r||!n)throw new Error(Qd(e));o._unmerge([t])});const s=[],i=this.getTables().search({address:t}),a=i.length;for(let t=0;t<a;t++){const e=i[t];r!==e&&s.push(e.getAnchorCoords())}_h(s,t,(t,r,o)=>{if(r||!n)throw new Error(Qd(e));i[o].delete()})}_addTable(t,e){let r=this._rangeToCoords(t,()=>["objects"]);const n=this._entireCoords;let o=e?.hasHeader;if(r.rowStart===r.rowEnd){if(r.rowEnd===n.rowEnd)throw new Error("A table must have a least two rows; one for the table header and one for data.");r.rowEnd=r.rowEnd+1}if(void 0===o){const t=Am(this,r);o=t?.options?.hasHeader??!1}const s=Nm([r]),i={...r},a=this._beginCommit({description:"Insert Table"});let l=null;try{o||(this._isContentful([r])&&this._insertCells([{...r,rowStart:r.rowStart,rowEnd:r.rowStart}],exports.t.Orientation.Row),r={...r,rowEnd:r.rowEnd+1});const t={...e?.json,ref:r};this._validateOrRemoveOverlaps(r,"table",null,!0),t.styleOptions=e?.json?.styleOptions??{},void 0===t.styleOptions.name&&(e?.styleName?t.styleOptions.name=e.styleName:void 0===e?.styleName&&(t.styleOptions.name=this._styles.getDefaultTableStyle().getName()));const n=e?.isLoad;!0!==n&&(void 0===t.filter&&(t.filter={}),void 0===t.sort&&(t.sort={}));const c=this._createTableEntry(t,o&&!n),h=this._getState(),d=h.tableSpatial.clone();d.insert(c);const u=h.tableMapModel,g=new Map(u),p=c.value.model;g.set(p,c);const m=h.tableMapName,f=new Map(m);f.set(p.getName().toLocaleLowerCase(),p),e?.clearFormatting&&this.getRange(r).updateStyle(null),l=c.value.model,this._updateState({tableSpatial:d,tableMapModel:g,tableMapName:f}),this._emitter.notify("onTablesChange"),n||this._autoFit([l.getHeaderRange().getCoords()],{expandOnly:!0});const _=Nm([r]);a.commit({viewBefore:{view:this.getView(),selection:s,ranges:[i]},viewAfter:{view:this.getView(),selection:_,ranges:[r]}})}catch(t){throw a.rollback(),t}return l}_addConditional(t,e){const r=this._rangesToCoords(t,()=>["objects"]),n=e?.autoSelect?Nm(r):null,o=[...r],s=this._beginCommit({description:e?.description??"Insert Conditional"});let i=null;try{const t={...e,ref:o},r=this._getState(),a=r.conditionalSpatial.clone(),l=new Map(r.conditionalModels),c=this._createConditionalEntries(t,a,l);this._updateState({conditionalSpatial:a,conditionalModels:l}),i=c,s.commit({viewBefore:{view:this.getView(),selection:n,ranges:o},viewAfter:{view:this.getView(),selection:n,ranges:o}}),this._autoSelect(e?.autoSelect,n)}catch(t){throw s.rollback(),t}return i}createTemporaryCell(t,e=null){if(t?.createTemporaryCell)return t;return(e?this.getRange(e).getCell():this._emptyCell).createTemporaryCell(t)}_getBoundsAtCoords(t){const e=this._rowHeaders,r=this._colHeaders,n=r.findOffset(t.colStart),o=e.findOffset(t.rowStart);return{x:n,y:o,width:r.findOffset(t.colEnd+1)-n,height:e.findOffset(t.rowEnd+1)-o}}_getCoordsAtBounds(t){const e=this._rowHeaders,r=this._colHeaders;return{colStart:r.findIndex(t.x),rowStart:e.findIndex(t.y),colEnd:r.findIndex(t.x+t.width),rowEnd:e.findIndex(t.y+t.height)}}getRangeAtBounds(t,e){if(!t)throw new Ft;const r=this._getCoordsAtBounds(t);return this.getRange(r,e)}_getVisible(t,e){if(0===t.length)return t;const r=new gc;r.load(t);const n=e?.orientations??exports.t.Orientations.Both,o=(t,e)=>{const n=r.search(t),o=n.length;for(let s=0;s<o;s++){const o=n[s],i=fh(o,t,e);r.remove(o),r.load(i)}},s=this._cellOptions.maxCoords;if(n===exports.t.Orientations.Both||n===exports.t.Orientations.Row){const e=this._rowHeaders,r=t.length;for(let n=0;n<r;n++){const r=t[n];e.getRange({min:r.rowStart,max:r.rowEnd}).forEachSpan((t,e)=>{if(0!==t)return;const r=e.getCoords();o({colStart:s.colStart,rowStart:r.min,colEnd:s.colEnd,rowEnd:r.max},exports.t.Orientation.Row)})}}if(n===exports.t.Orientations.Both||n===exports.t.Orientations.Column){const e=this._colHeaders,r=t.length;for(let n=0;n<r;n++){const r=t[n];e.getRange({min:r.colStart,max:r.colEnd}).forEachSpan((t,e)=>{if(0!==t)return;const r=e.getCoords();o({colStart:r.min,rowStart:s.rowStart,colEnd:r.max,rowEnd:s.rowEnd},exports.t.Orientation.Column)})}}return r.all()}_hasRangedEntries(t,e){const r=this._getState();if(!r)return mt.EmptyArray;const n=r[t];if(!n)throw new Error(`Invalid range key ${t}`);return!(!n||n.isEmpty())&&n.has(e)}_getRangedEntries(t,e,r){if(0===e.length)return mt.EmptyArray;const n=r?.excludeHidden??!1,o=r?.fullyContained??!1,s=r?.onEntry??null,i=this._getState();if(!i)return mt.EmptyArray;const a=i[t];if(!a)throw new Error(`Invalid range key ${t}`);if(!a||a.isEmpty())return mt.EmptyArray;const l=new Set,c=t=>{const e=t.length;for(let r=0;r<e;r++){const e=t[r];l.add(e)}},h=e.length;for(let t=0;t<h;t++){const r=e[t];if(n){if(!0===n){const t={min:r.colStart,max:r.colEnd},e={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(e).forEachVisibleSpan((e,r)=>{this._colHeaders.getRange(t).forEachVisibleSpan((t,n)=>{c(a.search({colStart:t,rowStart:e,colEnd:n,rowEnd:r},o))},sw)},sw)}else if(n===exports.t.Orientation.Column){const t={min:r.colStart,max:r.colEnd};this._colHeaders.getRange(t).forEachVisibleSpan((t,e)=>{c(a.search({colStart:t,rowStart:r.rowStart,colEnd:e,rowEnd:r.rowEnd},o))},sw)}else if(n===exports.t.Orientation.Row){const t={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(t).forEachVisibleSpan((t,e)=>{c(a.search({colStart:r.colStart,rowStart:t,colEnd:r.colEnd,rowEnd:e},o))},sw)}}else c(a.search(r,o))}if(0===l.size)return mt.EmptyArray;const d=Array.from(l.values()),u=r?.sort;u&&d.sort(U.createRangeComparator(u.orientation,u.reverse));let g=[];const p=d.length;for(let t=0;t<p;t++){let e;e=void 0,s&&(e=s(d[t].value,d[t])),void 0===e&&(e=d[t].value),null!==e&&g.push(e)}return g||(g=mt.EmptyArray),g}_processAnchorShift(t){let e=t.after;const r=U.sanitizeRange(t.after),n=U.sanitizeRange(t.before);t.after&&this._validateCoords(r,"We can't insert cells because this would push items off the end of the worksheet.");const o=t.before.value.processShiftCallback?.({...t,after:r,before:n});return o?(bm(o,r)||(e||(e=t.before),e={...e,...o}),e):e}_processListenerShift(t,e,r,n){if(n.isSplit||n.before.value.options.ignoreShifts)return[n.before];let o=null;n.after&&(o=U.intersectRanges(U.sanitizeRange(n.after),this._entireCoords),n.after,o.colStart,o.rowStart,o.colEnd,o.rowEnd);const s=n.before.value,i=s.id,a=t.get(i),l={...a},c=[...a.ranges];l.ranges=c,c[s.offset]=o?{...c[s.offset],...o}:null,t.set(i,l);const h=r.get(i);e.set(i,{beforeState:h,afterState:l})}delete(){if(this._closed)return;try{this._emitter.notify("onBeforeDelete")}catch(t){throw t instanceof Error?t:new Error(t.message??"Unable to delete.")}const t=this._beginCommit({description:`Delete Sheet '${this.getName()}'`}),e=this._getState();let r=e.rangeListenerSpatial,n=e.rangesListenerMap;const o=new Map;r=r.shift({range:this._entireCoords,direction:exports.t.Direction.Left,cloneIfUpdate:r===e.rangeListenerSpatial,onShift:t=>{n===e.rangesListenerMap&&(n=new Map(n)),this._processListenerShift(n,o,e.rangesListenerMap,t)}}),this._updateState({rangeListenerSpatial:r,rangesListenerMap:n,deleted:!0}),this._deleteCells([this._entireCoords]),this._emitter.notify("onDelete"),this._rangesListenerMap.forEach((t,e)=>{o.set(e,{beforeState:t,afterState:null})}),t.commit({viewAfter:t=>({...t,view:this.getView(),selection:this.getSelection().getCoords(),listeners:o})})}doBatch(t,e){const r=this;return e="string"==typeof e?{description:e}:{description:"Update Sheet",...e},this._transactions.doBatch(t,e,(t,n)=>{if(0===t.getDepth()&&(r._lastTransactionUUID=t.getId(),e?.autoSelect)){const e=t.getView()?.selection;e&&r._autoSelect(!0,e)}})}isClosed(){return this._closed}close(){if(this._closed)return;this._protectionRemoveListener?.(),this._protection=new $S(void 0,this._options.readonly);const t=this._getState().tableMapModel.keys();for(const e of t)e.close();this._searchMovables().forEach(t=>{t.close()}),this._emitter.notify("onClose"),this._ownResources,this._namesRemoveListener?.(),this._ownNames&&this._names.close(),this._ownsCalculation&&this._calculation.close(),this._ownStyles,this._colHeaders.close(),this._rowHeaders.close(),this._emitter.close(),this._transactionsRemoveListener?.(),this._closed=!0}beginCommit(t){if(this._closed)throw new Error(ou);return this._beginCommit("string"==typeof t?{description:t}:t)}_getState(){return this._closed?null:this._transactions.getState(this)}_beginCommit(t){const e=this;return this._transactions.beginCommit(t,t=>{0===t.getDepth()&&(e._lastTransactionUUID=t.getId())})}_updateState(t){if(!t)return;this._lastGetRangeRead=null;const e=this._transactions.beginCommit();let r;try{r=e.updateState(this,t),e.commit()}catch(t){throw e.rollback(),t}return r}_addEvent(t,e){const r=this.getTransactions().getPendingView();if(!r)return;let n=r.events;if(n||(n={},r.events=n),"address"===t){let t=n.address;if(t||(t=new Map,n.address=t),"string"==typeof e)t.set(e,null);else{const r=e;if(r.options.ignoreAddressChanges)return;t.set(r.uuid,e)}}else if("data"===t)if("string"==typeof e){let t=n.dataListeners;t||(t=new Map,n.dataListeners=t),t.set(e,null)}else{let t=n.data;t||(t=[],n.data=t),t.push(e)}}_getScalar(t,e,r=!1){const n=this._getState();let o;if(void 0===o){o=n.cellValuesGrid.getValueAt(t,e)}if(void 0===o)return null;let s=o;if(r&&"number"==typeof s){let r=!1;aw.colStart=e,aw.rowStart=t,aw.colEnd=e,aw.rowEnd=t;const o=this._lastValueRead,i=this._lastValueRead.range;if(i&&U.isRangeWithinRange(aw,i))r=o.isDateOrTime;else{const i=n.directStyleSpatial.search(aw)[0];if(i){const n=i.value.getPropertiesAt(t,e,s),a=n?.numberFormat;a&&(r=Rs(a)||Ms(a)),o.range=i,o.isDateOrTime=r}else o.range=null;r&&(s=ps(s,this._isDate1904))}}return s}getStyleUpdater(t,e){return null}_initState(){const t=this,e=()=>{t._lastCellDecoded.address=null,t._lastCellSelected.coords=null,t._lastCellRead.coords=null,t._lastValueRead.range=null,t._lastGetRangeRead={},t._lastUsedCoordsRead.coords=null,t._lastActiveRead.selection=null,t._lastRangeRead.address=null};this._transactionsRemoveListener=this._transactions.addStateListener(this,{onBeforeCommitStart(e,r,n){if(!t._initializing&&!r?.skipProtectionCheck){if(t.getProtection().isLocked())throw new Error(Jd)}},async onBeforeCommitEnd(e,r,n){if(r?.ranges){const o={isDataChange:!0,isTransactional:!0,timeStamp:n.getTimestamp(),trigger:"setCells"},s=e.rangeListenerSpatial,i=e.rangesListenerMap;t._notifyRangeListeners(s,i,r.ranges,o)}if(r?.listeners){const o={isDataChange:!1,isTransactional:!0,timeStamp:n.getTimestamp(),trigger:"shiftCells"},s=e.rangeListenerSpatial,i=e.rangesListenerMap;t._notifyRangeListeners(s,i,r.ranges,o)}},async onRestoreOrRevert(r,n,o,s){e(),t._calculateFull(),n&&(n.view===t.getView()&&n.selection&&t._autoSelect(!0,n.selection),n.movableSelection&&t.getView().selectMovables(n.movableSelection)),t._emitter.notify("onInvalidated"),t._emitterMovables.notify("onInvalidated"),t._notifyUsedRangeChange();if(t._rangesListenerMap.size>0){const e={isDataChange:!0,isTransactional:!1,timeStamp:o.getTimestamp(),isUndo:s,trigger:"invalidate"},n=r.rangeListenerSpatial,i=r.rangesListenerMap,a=new Set;i.forEach((r,o)=>{const s=r.id;if(a.has(s))return;const l=r.ranges;l&&(a.add(s),t._notifyRangeListeners(n,i,l,e))})}},async onAfterStateChange(r,n,o,s,i){e(),n&&o.getId()!==t._lastTransactionUUID&&n.view===t.getView()&&n.selection&&(s||i)&&t._autoSelect(!0,n.selection),t._lastTransactionUUID=o.getId(),n?.merges&&t._notifyMergeChange();const a=t._rangesListenerSorted;if(a.size>0){t._notifyUsedRangeChange();const e=new Set,l=r.rangesListenerMap2,c={isTransactional:!1,timeStamp:o.getTimestamp()};if((i||s)&&(c.trigger="restore",t._notifyAddressListeners(l,l,e,c),a.size>l.size)){const t=a.values();let e=t.next(),r=!1;for(;!r&&!e.done;){const n=e.value;r=l.has(n.uuid),r||(n.notify(c,"#N/A"),e=t.next())}}const h=n?.events;h&&(h.address&&(c.trigger="address",t._notifyAddressListeners(l,h.address,e,c)),h.dataListeners&&(c.trigger="data",t._notifyAddressListeners(l,h.dataListeners,e,c)),h.data&&(c.trigger="data",t._notifyDataListeners(r.rangesListenerSpatial2,r.rangesListenerMap2,h.data,e,c)))}if(n&&n.ranges&&!n.initial&&r.calcGraph.calculate(),n?.ranges){t._notifyUsedRangeChange();const e=t._rangesListenerMap;if(e.size>0){const r={isDataChange:!0,isTransactional:!1,timeStamp:o.getTimestamp(),isUndo:s,trigger:"setCells"};t._notifyRangeListeners(t._rangeListenerSpatial,e,n.ranges,r)}}},onClose(){const e=t._getState();e&&e.movableSpatial.clear()}});const r=new sS({sheet:this}),n={onChange(){t._emitter.notify("onSelectionChange")}},o=r.addListeners(n,{transactional:!1});this._rangeSelection=r,this._rangeSelectionRemoveListener=o;const s=e=>{const r=t._getState();if(!r)return;const n=r.movableSpatial,o=e.length;for(let t=0;t<o;t++){const r=n.search(e[t]),o=r.length;for(let t=0;t<o;t++){const e=r[t].value;e.processLayoutCallback?.()}}};this._colHeadersListener={onSizesChange:(e,r)=>{const n=[];if(r){const e=r.length;for(let o=0;r&&o<e;o++){const e={colStart:r[o].min,rowStart:t._entireCoords.rowStart,colEnd:t._entireCoords.colEnd,rowEnd:t._entireCoords.rowEnd};n.push(e)}}s(n)}},this._rowHeadersListener={onSizesChange:(e,r)=>{const n=[];if(r){const e=r.length;for(let o=0;o<e;o++){const e=r[o],s={colStart:t._entireCoords.colStart,rowStart:e.min,colEnd:t._entireCoords.colEnd,rowEnd:t._entireCoords.rowEnd};n.push(s)}}s(n)}};let i=new Set;const a={onTopLeftChange(){t._emitter.notify("onTopLeftChange")},onFreezeSplitChange(){t._emitter.notify("onFreezeSplitChange")},onRangeSelectionChange(){const e=t.getSelection().getCoords();t._rangeSelection.updateCoords(e)},onMovableSelectionChange(e){const r=e.getMovableSelection(),n=new Map,o=new Set,s=t._getState().movableMapModel,a=r.length;for(let t=0;t<a;t++){const e=r[t];i.has(e)?i.delete(e):n.set(e,t),o.add(e)}i.forEach(t=>{s.get(t)?.value.processSelectionCallback(!1,!1)}),n.forEach((t,e)=>{s.get(e)?.value.processSelectionCallback(!0,0===t)}),i=o,t._emitter.notify("onMovableSelectionChange")},onAnyChange(){t._emitter.notify("onViewChange")}},l=new BS({sheet:this});this._view=l,this._clearState(),this._viewRemoveListener=l.addListeners(a,{transactional:!1}),this._viewListener=a,this._colHeadersRemoveListener?.();const c=()=>Math.round(this._defaultFontDims().width);this._colHeaders=new vS({sheet:t,orientation:exports.t.Orientation.Column,maxSheetCoords:this._entireCoords,transactions:this._transactions,isProtected:()=>!t._initializing&&!t.getProtection().isFormatColumnsAllowed(),getTextAt:t=>{const e=this.getView().getColumnHeaderStyle();return e===exports.ISheetView.HeaderTextStyle.A1?XS(t):e===exports.ISheetView.HeaderTextStyle.Zero?JS(t):e===exports.ISheetView.HeaderTextStyle.One?KS(t):void 0},defaultSize:()=>{const t=this.getView().isShowFormulas()?2:1;return this._defaultColWidth()/c()*t},scaleFactor:c,maxSize:()=>255,setContainerShiftedCallback:t=>{this._colHeadersShiftCallback=t}}),this._colHeadersRemoveListener=this._colHeaders.addListeners(this._colHeadersListener,{transactional:!0}),this._rowHeadersRemoveListener?.();const h=exports.IFont.getDeviceScale();this._rowHeaders=new vS({sheet:t,orientation:exports.t.Orientation.Row,maxSheetCoords:this._entireCoords,transactions:this._transactions,isProtected:()=>!t._initializing&&!t.getProtection().isFormatRowsAllowed(),getTextAt:t=>{const e=this.getView().getRowHeaderStyle();return e===exports.ISheetView.HeaderTextStyle.One?KS(t):e===exports.ISheetView.HeaderTextStyle.Zero?JS(t):e===exports.ISheetView.HeaderTextStyle.A1?XS(t):void 0},defaultSize:()=>this._defaultRowHeight(),scaleFactor:()=>h,minSize:()=>0,maxSize:()=>409,setContainerShiftedCallback:t=>{this._rowHeadersShiftCallback=t}}),this._rowHeadersRemoveListener=this._rowHeaders.addListeners(this._rowHeadersListener,{transactional:!0}),this._defaultFontBoundsCache=null,this._defaultColWidthCache=null,this._defaultRowHeightCache=null;const d={colStart:0,rowStart:0,colEnd:0,rowEnd:0},u=[d],g={excludeHidden:!0,sort:{orientation:exports.t.Orientation.Column,reverse:!1}};this._cellOptions={resolveRange:t=>{const e=this._rangesToCoords(t);return this._createRange(e[0],null)},date1904:this._isDate1904,sheet:this,normalStyleRanged:this._normalStyleRanged,colHeaders:this._colHeaders,styles:this._styles,maxCoords:this._entireCoords,getRange:this.getRange.bind(this),getProtection:this.getProtection.bind(this),calcGraph:()=>this._getState().calcGraph,nextContentful:(e,r,n=!1)=>{d.colStart=n?r:e.colIndex+1,d.rowStart=e.rowIndex,d.colEnd=n?e.colIndex-1:r,d.rowEnd=e.rowIndex,g.sort.reverse=n;const o=t._getRangedEntries("contentfulSpatial",u,g);if(!o||0===o.length)return r;const s=o[0],i=n?s.getState().colStart:s.getState().colEnd;return n?Math.min(i+1,e.colIndex):Math.max(i-1,e.colIndex)},opener:async(t,e,r,n)=>{if(t.startsWith("#")){t=t.substring(1);const r=this._rangesToCoords(t);return await this._autoSelect(e??!0,Nm(r)),!0}return window.open(t,r??"_blank",n),!0}},this._emptyCell=new tm(this._cellOptions)}_clearState(){this._lastGetRangeRead=null,this._lastCellDecoded.address=null,this._lastCellSelected.coords=null,this._lastCellRead.coords=null,this._protectionRemoveListener?.(),this._protection=new $S(void 0,this._options.readonly),this._protectionRemoveListener=this._protection.addListeners({onChange(){if(t._closed)throw new Error(ou);t._getState().movableMapModel.forEach(t=>{t.value.processProtectionCallback?.()}),t._getState().tableMapModel.forEach(t=>{t.value.processProtectionCallback?.()}),t._emitter.notify("onProtectionChange")}}),this._stylesRemoveListener?.();const t=this;this._stylesRemoveListener=this._styles.addListeners({onAnyChange(){t._defaultColWidthCache=null,t._defaultRowHeightCache=null,t._defaultFontBoundsCache=null,t._emitter.notify("onLayoutChange"),t._emitter.notify("onStyleChange")}}),this._view.clear(!1),this._rangeListenerSpatial=new gc,this._rangesListenerMap=new Map,this._rangesListenerSorted=new ke;const e=e=>{const r=t._getState().rangesListenerSpatial2;if(r.isEmpty())return;const n=e.length;for(let o=0;o<n;o++){const n=e[o],s=r.search(n),i=s.length;for(let e=0;e<i;e++){const r=s[e].value.groupId;t._addEvent("data",r)}}},r=this._entireCoords,n=r.rowEnd,o=r.colEnd,s=this._calculation._createGraph({onCalculated(e){t._realizeCalcedValues(e)},getEntireCoords:()=>t._entireCoords,getSheetName:()=>t.getName()});s.addListeners({onStart(t){},onInvalidate:()=>{}}),this._updateState({rangesListenerSpatial2:new gc({updateEntryOptions:{onShifted:e=>{let r=t._getState().rangesListenerMap2;if(0===r.size)return;r=new Map(r);const n=e.length;for(let o=0;o<n;o++){const n=e[o],s=n.value.groupId;let i=r.get(s);i=i.processShift(n),t._addEvent("address",i),r.set(s,i)}t._updateState({rangesListenerMap2:r})},onRemoved:e=>{let r=t._getState().rangesListenerMap2;if(0===r.size)return;r=new Map(r);const n=e.length;for(let o=0;o<n;o++){const n=e[o],s=n.value.groupId;let i=r.get(s);i=i.processRemove(n),t._addEvent("address",i),r.set(s,i)}t._updateState({rangesListenerMap2:r})}}}),rangesListenerMap2:new Map,cellValuesGrid:new Vc({orientation:this._isDataColumn?exports.t.Orientation.Column:exports.t.Orientation.Row}),formulaSpatial:new gc,spillSpatial:new gc,pendingSpatial:new gc,calcErrorsSpatial:new gc,calcGraph:s,directStyleSpatial:new gc({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0,onUpdated:e,onRemoved:e}}),continuousFillSpatial:new gc({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0}}),conditionalModels:new Map,conditionalSpatial:new gc({updateEntryOptions:{onGroupUpdate(e,r){let n=t._getState().conditionalModels,o=n.get(r);if(!o)return;n=new Map(n);const s=o.spatials;o={...o},o.spatials=e,n.set(r,o),t._updateState({conditionalModels:n}),o.processCoordsChange({before:s,after:o.spatials})}}}),mergeSpatial:new gc({updateEntryOptions:{getShifted:(t,e)=>e?(e.value=new IS(U.sanitizeRange(e),t.value._tvTl,t.value._rsTl),e):null,getSplit(t,e){throw new Error("We can't insert through merges. Unmerge and try again.")},onUpdated:e,onRemoved:e}}),movableMapModel:new Map,movableSpatial:new gc({updateEntryOptions:{getShifted(e,r,n){const o=e.value.processShiftCallback?.(n);let s=null;const i=new Map(t._getState().movableMapModel),a=e.value.model;return o?(s={...o,value:{...e.value}},i.set(a,s)):i.delete(a),t._updateState({movableMapModel:i}),s}}}),hyperlinkSpatial:new gc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}}),commentsSpatial:new gc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0,onUpdated:e,onRemoved:e}}),tableMapModel:new Map,tableMapName:new Map,tableSpatial:new gc({updateEntryOptions:{getShifted(e,r,n){const o=new Map(t._getState().tableMapModel),s=e.value.model,i=e.value.processShiftCallback?.(n);let a=null;return i?(a={...i,value:{...r.value}},o.set(s,a)):o.delete(s),t._updateState({tableMapModel:o}),a}}}),filter:null,sort:null,rangeListenerSpatial:new gc,rangesListenerMap:new Map,contentfulSpatial:new gc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0,onShifted:e=>{const r=t._getState().rangesListenerSpatial2;if(0===r.size())return;const s=e.length;for(let i=0;i<s;i++){const s=e[i],a=r.search({colStart:s.colStart,rowStart:s.rowStart,colEnd:o,rowEnd:n}),l=a.length;for(let e=0;e<l;e++){const r=a[e].value.groupId;t._addEvent("data",r)}}},onRemoved:e,onUpdated:e}}),unlockSpatial:new gc({updateEntryOptions:{isMergeOnShift:!0}}),deleted:!1}),this._defaultFontBoundsCache=null,this._defaultColWidthCache=null,this._defaultRowHeightCache=null}_createTableEntry(t,e=!1){const r={model:null,processShiftCallback:null,processDeleteCallback:null,processProtectionCallback:null,currentName:null,removeListener:null};let n=null;n="string"==typeof t.ref?hd(t.ref,this._entireCoords):t.ref;const o={...n,value:r},s=this,i=()=>r.model?s._getState().tableMapModel?.get(r.model):o,a=(t,e)=>!(!U.isEqualRanges(t,e)||t.value.model!==e.value.model),l={transactions:this._transactions,sheet:this,names:this._names,readSheetHeader:e,json:t,maxRangeCoords:this._entireCoords,setNameOnContainer(t){const e=i().value;if(!e.currentName)return;if(e.currentName.toLowerCase()===t.toLowerCase())return;const r="Set Table Name";s._protectionCheck(()=>["objects"],void 0,r);const n=s._beginCommit({description:r});try{const r=s._getState()?.tableMapName,o=t.toLocaleLowerCase();if(r.has(o))throw new Error((t=>`Name must be unique: '${t}' is already in use.`)(t));const i=new Map(r);i.delete(e.currentName),e.currentName=o,i.set(o,e.model),s._updateState({tableMapName:i}),n.commit()}catch(t){throw n.rollback(),t}},setContainerCoords(t,e){if(!t)return;const r=s._rangeToCoords(t,()=>["objects"]),n=i();if(!n)return;const o=n.value.model;s._validateOrRemoveOverlaps(r,"table",o);const l=s._beginCommit({description:e?.description??"Resize Table"}),h=s._getState(),d=h.tableSpatial.clone(),u=h.tableMapModel,g=new Map(u);d.remove(n,a);const p={...n,...r};return d.insert(p),g.set(p.value.model,p),s._updateState({tableSpatial:d,tableMapModel:g}),l.commit({viewAfter:{view:s.getView(),selection:Nm([c.getAnchorCoords()])}}),r},deleteFromContainer(t){const e=i();if(!e)return;const r=e.value.model,n=t?.description??`Delete Table '${r.getName()}`;s._protectionCheck(()=>["objects"],void 0,n);const o=s._beginCommit({description:n}),l=s._getState(),c=l.tableSpatial.clone(),h=l.tableMapModel,d=new Map(h),u=l.tableMapName,g=new Map(u);c.remove(e,a),d.delete(r),g.delete(r.getName().toLocaleLowerCase()),e.value.processDeleteCallback?.(),s._updateState({tableSpatial:c,tableMapModel:d,tableMapName:g}),s._emitter.notify("onTablesChange"),o.commit({viewAfter:{sheet:s,view:s.getView(),selection:Nm([r.getAnchorCoords()])}})},setContainerDeleteCallback(t){const e=i()?.value??r;e&&(e.processDeleteCallback=t,e.removeListener?.())},isProtected:()=>!s._initializing&&s.getProtection().isLocked(),setContainerProtectionCallback(t){(i()?.value??r).processProtectionCallback=t},setContainerShiftCallback(t){(i()?.value??r).processShiftCallback=t},processTableUpdate(){s._notifyUsedRangeChange()},initialAnchor:n},c=new Km(l);return o.value.model=c,o.value.removeListener=c.addListeners({onStyleChange(t){s._emitter.notify("onStyleChange")},onDelete(t){s._emitter.notify("onStyleChange")}},{transactional:!1}),o.value.currentName=c.getName().toLocaleLowerCase(),o}_createConditionalEntries(t,e,r){const n="Conditional Format",o=()=>["objects"],s=t??{};let i=null;const a=this._entireCoords;if("string"==typeof s.ref){i=[];const t=s.ref.split(","),e=t.length;for(let r=0;r<e;r++){const e=hd(t[r],a);e&&i.push(e)}}else i=Array.isArray(s.ref)?s.ref:[s.ref];const l=this,c=mt.uuidV4(),h={model:null,removeListener:null,processCoordsChange:null,spatials:null};r.set(c,h);const d=()=>h.model?l._getState().conditionalModels.get(c):h;let u=t=>(console.log("default createSpatialEntry",t),null);const g=(t,e,r)=>{if(!h.model)return void(i=t);let n=e.spatials;if(n){const t=n.length;for(let e=0;e<t;e++)r.remove(n[e])}let o=[];if(t){const e=t.length;for(let r=0;r<e;r++){const e=t[r];o.push({...e,value:u(e)})}o.length>0&&r.insertGroup(o,c)}e.spatials=o},p=()=>{const t=d().spatials??i;return t?l.getRanges(t):null};var m;return h.model=(m={sheet:l,transactions:l._transactions,json:t,type:"conditional",setOnContainerCoordsChange:t=>{d().processCoordsChange=t},setCreateSpatial(t){u=t},setContainerRanges:(t,e)=>{const r=l._rangesToCoords(t,o);if(!h.model)return i=r,r&&r.length>0?l.getRanges(r):null;const s=l._beginCommit({description:e?.description??`Set ${n} Ranges`});let a=Nm(r);try{const t=l._getState();let n=t.conditionalSpatial;n=n.clone();let o=t.conditionalModels;o=new Map(o);let i=d();i={...i},o.set(c,i),g(r,i,n),l._updateState({conditionalSpatial:n,conditionalModels:o}),s.commit({viewBefore:{view:l.getView(),selection:Nm(p()?.getCoords())},viewAfter:{view:l.getView(),selection:a}}),l._autoSelect(e?.autoSelect,a)}catch(t){throw s.rollback(),t}return r&&r.length>0?l.getRanges(r):null},getContainerRanges:p,deleteFromContainer(t){let e=d();const r=l._beginCommit({description:t?.description??`Set ${n} Ranges`}),o=t?.autoSelect?Nm(e.spatials):void 0;try{const n=l._getState();let s=n.conditionalSpatial;s=s.clone();let i=n.conditionalModels;i=new Map(i),e={...e},g(null,e,s),i.delete(c),l._updateState({conditionalSpatial:s,conditionalModels:i}),this._commitAndAutoSelect(r,o,t?.autoSelect)}catch(t){throw r.rollback(),t}},isReadOnly:()=>!1,setContainerReadOnlyCallback(t){}},new aS({...m,createDescription:`New ${n}`})),h.removeListener=h.model.addListeners({onAnyChange(t){l._emitter.notify("onStyleChange")}},{transactional:!1}),g(i,h,e),h.model}_createMovableEntry(t,e,r){let n=null;if(t?.anchor)n={colStart:t.anchor.tl?.c??0,rowStart:t.anchor.tl?.r??0,colEnd:t.anchor.br?.c??0,rowEnd:t.anchor.br?.r??0},t.anchor.br?.x||(n.colEnd-=1),t.anchor.br?.y||(n.rowEnd-=1);else{const t=Fm(this.getSelection().getCoords())[0];n={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}const o={model:null,processShiftCallback:null,processLayoutCallback:null,processDeleteCallback:null,processZIndexCallback:null,processSelectionCallback:null,processProtectionCallback:null,zIndex:e},s={...n,value:o},i=()=>o.model?c._getState()?.movableMapModel?.get(o.model):s,a=(t,e)=>!(!U.isEqualRanges(t,e)||t.value.model!==e.value.model),l=(t,e,r=!0)=>{if(d)return;const n=i();if(!n)return;const o=e??"Update Drawing";c._protectionCheck(()=>["objects"],void 0,o);const a=c._beginCommit({description:o}),l=c._getState()?.movableSpatial,h=l.clone(),u=c._getState()?.movableMapModel,g=new Map(u);!1!==t(n,h,g)&&(c._updateState({movableSpatial:h,movableMapModel:g}),r&&(c._emitterMovables.notify("onCollectionChange",{source:c,transactional:!0}),c._emitter.notify("onMovablesChange")),a.commit({viewAfter:t=>{if(s.value.model.isSelected()&&!t?.movableSelection?.includes(s.value.model)){const e=[...t?.movableSelection??[]];return e.push(s.value.model),{...t,view:this.getView(),movableSelection:e}}}}))},c=this,h=t.content.type;let d=!0;const u=(t,e,r,n)=>{const o=r.all().sort((t,e)=>t.value.zIndex-e.value.zIndex),s=e.value.zIndex;if((t=Math.max(0,Math.min(o.length-1,t)))===s)return!1;const i=[],l=[],c=[],h=s<t,d=e=>{const r=o[e];i.push(r);const a={...r,value:{...r.value,zIndex:h?e-1:e+1}};r.value.zIndex===s&&(a.value.zIndex=t),l.push(a),n.set(a.value.model,a),c.push(a)};if(h)for(let e=s;e<=t;e++)d(e);else for(let e=s;e>=t;e--)d(e);const u=i.length;for(let t=0;t<u;t++)r.remove(i[t],a);r.load(l);const g=c.length;for(let t=0;t<g;t++)c[t].value.processZIndexCallback?.()},g=()=>c._resources.beginPersist(),p="picture"===h,m={content:null,fromResourceId:r,defaultLockAspectRatio:p,beginPersistResource:g,getMaxBounds:()=>c._getBoundsAtCoords(c._entireCoords),transactions:this._transactions,getBoundsAtCoords:c._getBoundsAtCoords.bind(c),getCoordsAtBounds:c._getCoordsAtBounds.bind(c),scrollIntoView:t=>c._selectSheet(i()?.value.model.getAnchorCoords(),t),select:async t=>{const e=i()?.value.model;if(!e)return!1;try{c.getView().selectMovables([e],t?.addToSelection)}catch(t){return console.warn(t),!1}const r=await c._selectSheet(i()?.value.model.getAnchorCoords(),t?.scrollIntoView);return!t?.scrollIntoView||!1!==r},unselect:()=>{const t=i()?.value.model;return!!t&&(c.getView().unselectMovables([t]),!0)},isSelected:()=>c.getView().getMovableSelection().includes(i()?.value.model),setContainerSelectionCallback(t){(i()?.value??o).processSelectionCallback=t},moveToBackOnContainer:()=>{l((t,e,r)=>u(0,t,e,r),"Move to Back")},moveBackwardOnContainer:()=>{l((t,e,r)=>u(t.value.zIndex-1,t,e,r),"Move Backwards")},moveForwardOnContainer(){l((t,e,r)=>u(t.value.zIndex+1,t,e,r),"Move Forward")},moveToFrontOnContainer(){l((t,e,r)=>u(e.size()-1,t,e,r),"Move To Front")},getZIndex:()=>i()?.value.zIndex??0,setContainerZIndexCallback(t){(i()?.value??o).processZIndexCallback=t},setContainerCoords(t){if(!t)return;const e=c._rangeToCoords(t,()=>["objects"]);return l((t,r,n)=>{const o={...t,...e};r.remove(t,a),r.insert(o),n.set(o.value.model,o)},"Update Drawing",!1),e},deleteFromContainer(t){const e=i();e?.value&&c.getView().unselectMovables([e.value.model]);const r=[];l((t,e,n)=>{n.delete(t.value.model),e.remove(t,a),t.value.processDeleteCallback?.(),r.push(t);const o=t.value.model.getZIndex(),s=e.all().sort((t,e)=>t.value.zIndex-e.value.zIndex),i=[],l=[],c=s.length;for(let t=o+1;t<c;t++){const e=s[t];i.push(e);const r={...e,value:{...e.value,zIndex:t-1}};l.push(r),n.set(r.value.model,r)}const h=i.length;for(let t=0;t<h;t++)e.remove(i[t],a);e.load(l)},t?.description??"Delete Drawing",!0);const n=r.length;for(let t=0;t<n;t++)r[t].value.processZIndexCallback?.()},setContainerDeleteCallback(t){(i()?.value??o).processDeleteCallback=t},isProtected:()=>!c._initializing&&!c.getProtection().isObjectsAllowed(),setContainerProtectionCallback(t){(i()?.value??o).processProtectionCallback=t},setContainerShiftCallback(t){(i()?.value??o).processShiftCallback=t},setContainerLayoutCallback(t){(i()?.value??o).processLayoutCallback=t},initialAnchor:n,maxRangeCoords:this._entireCoords,json:t},f=t.content.json,_={type:h,transactions:this._transactions,beginPersistResource:g,fromResourceId:r,defaultLockAspectRatio:p,json:f};let S=null;if("picture"===h)S=new mf(_);else if("chart"===h)S=new X_(_);else if("sp"===h||"cxnSp"===h||"grpSp"===h)S=new K_(_);else{if("graphicFrame"!==h)throw new Error((t=>`Unsupported float type: ${t}`)(h));S=new Y_(_)}return o.model=new z_({...m,content:S}),d=!1,s}_fromJSON(e){this._initializing=!0,this._emitter.notify("onBeforeLoad",{params:e}),this._clearState();const r=this._beginCommit({description:"Load Sheet",viewAfter:{initial:!0,skipProtectionCheck:!0}}),n=e||{},o=this._strings,s=o.beginPersist(),i=this._resources.beginPersist(),a=this._styles.beginPersist();try{this._ownStrings&&s.fromJSON(n.strings),this._ownResources&&i.fromJSON(n.resources),this._ownStyles&&a.fromJSON(n.styles),this._colHeaders.fromJSON({headers:n.cols,defaultSize:n.defaultColSize}),this._rowHeaders.fromJSON({headers:n.rows,defaultSize:n.defaultRowSize}),this.setView(new BS({sheet:this,json:n.view})),this._rangeSelection.updateCoords(this._view.getRangeSelection()),n.tabColor&&(this._tabColor=this._styles.parseColor(n.tabColor));let l=this._getState();const c=l.cellValuesGrid,h=l.contentfulSpatial,d=n.data,u=d?.length??0,g=Rm,p=[];if(u>0){for(let e=0;e<u;e++){let r=d[e];"string"==typeof r&&(r=JSON.parse(r));const n=r[1],s=n.length;let i;for(let e=0;e<s;e++){const r=n[e][1],s=r.length;for(let e=0;e<s;e++){let n=r[e],o=n?.t;if(void 0!==o)n=n?.v;else switch(typeof n){case"number":o=t.Number;break;case"boolean":o=t.Boolean;break;case"string":o=t.String,n=parseInt(n)}r[e]=[n,o]}i=g(null,o,r),n[e][1]=i}p.push(r)}c.setValues(p);const e=Mm(p,this._isDataColumn);h.load(e)}const m=this._entireCoords,f=l.directStyleSpatial,_=l.continuousFillSpatial,S=this._options.styles;if(e.directStyles){const t=[],r=[],n=e.directStyles,o=(e,n)=>{const o=a.getElementJSON(n),s=new Lp(S,U.sanitizeRange(e),o),i={...e,value:s};t.push(i);const l=s._p?.alignment?.horizontal;!l||l!==exports.ITextFrame.HorizontalAlignment.CenterContinuous&&l!==exports.ITextFrame.HorizontalAlignment.Fill||r.push(i)};if(Array.isArray(n)){const t=n.length;for(let e=0;e<t;e++){const t=n[e],r=t.r;o("string"==typeof r?hd(r,m):r,t.v)}}f.load(t),_.load(r)}l=this._updateState({cellValuesGrid:c,contentfulSpatial:h,directStyleSpatial:f,continuousFillSpatial:_});const w=n.merges;if(w){const t=[],e=w.length;for(let r=0;r<e;r++){const e=hd(w[r],m);t.push(e)}this._indexMerges(t)}const y=l.hyperlinkSpatial,x=n.hyperlinks;if(x){const t=x,e=[],r=t.length;for(let n=0;n<r;n++){const r=t[n];let o=r.r;o="string"==typeof o?hd(o,m):U.sanitizeRange(o);let s=r.v;"string"==typeof s&&(s={address:s}),e.push({...o,value:s})}y.load(e)}const C=l.commentsSpatial,b=n.comments;if(b){const t=b,e=[],r=t.length;for(let n=0;n<r;n++){const r=t[n];let o=r.ref;o="string"==typeof o?hd(o,m):U.sanitizeRange(o);const s={...r};delete s.ref,e.push({...o,value:s})}C.load(e)}const E=l.movableMapModel,v=l.movableSpatial;if(n.movables){const t=[],e=n.movables,r=e.length;for(let n=0;n<r;n++){const r=e[n];try{const e=this._createMovableEntry(r,n,i.fromResourceId.bind(i));E.set(e.value.model,e),t.push(e)}catch(t){console.warn("Unable to load movable",n,r,t)}}v.load(t)}const I=l.tableMapModel,A=l.tableMapName,R=l.tableSpatial,M=n.tables;if(M){const t=[],e=M.length;for(let r=0;r<e;r++){const e=M[r],n=this._createTableEntry(e),o=n.value.model;I.set(o,n),A.set(n.value.currentName,o),t.push(n)}R.load(t)}const T=l.conditionalSpatial,F=l.conditionalModels,N=n.conditionals;if(N){const t=N.length;for(let e=0;e<t;e++){const t=N[e];this._createConditionalEntries(t,T,F)}}const k=l.calcGraph,O=k.fromJSON({formulas:n.formulas,data:p,dynamic:n.dynamicArray,volatile:n.volatile});l=this._updateState({hyperlinkSpatial:y,commentsSpatial:C,movableSpatial:v,movableMapModel:E,tableSpatial:R,tableMapModel:I,tableMapName:A,conditionalSpatial:T,conditionalModels:F,calcGraph:k});const B=this._getUsedCoords();B&&this._autoFit([B],{orientations:exports.t.Orientations.Row,skipCustomSize:!0}),r.commit(),O&&this._realizeCalcedValues(O),n.protection&&this._protection.fromJSON(n.protection),this._emitter.notify("onLoad")}finally{a.endPersist(),i.endPersist(),s.endPersist()}this._initializing=!1}getName(){return this._closed?Gh:this._options.container?.getName?.()??null}setName(t){if(this._closed)throw new Error(ou);const e=this._options.container?.setName;if(!e)throw new Error("Unable to set name for sheet.");return e(t),this}getVisibility(){return this._closed?exports.ISheet.Visibility.VeryHidden:this._options.container?.getVisibility?.()??exports.ISheet.Visibility.Hidden}setVisibility(t=!0){if(this._closed)throw new Error(ou);const e=this._options.container?.setVisibility;if(!e)throw new Error("Unable to set visibility for sheet.");let r;return r=!0===t?exports.ISheet.Visibility.Visible:!1===t?exports.ISheet.Visibility.Hidden:t,e(r),this}async select(t){return await(this._options.container?.requestSelect?.(t)),this}duplicate(){return this._options.container?.duplicate?.()}setPosition(t){return this._options.container?.setPosition(t),this}getNames(){return this._names}getCalculation(){return this._calculation}get[Symbol.toStringTag](){return"[Sheet]"}toString(){const t=this.getName();return t||"(untitled sheet)"}get isISheet(){return!0}}const ew={address:null,scope:null},rw={colStart:0,rowStart:0,colEnd:0,rowEnd:0},nw={colStart:0,rowStart:0,colEnd:0,rowEnd:0},ow={colStart:0,rowStart:0,colEnd:0,rowEnd:0},sw={includeHidden:!1};Object.freeze({[exports.ICell.Content.Values]:Number.MAX_SAFE_INTEGER,[exports.ICell.Content.Formulas]:Number.MAX_SAFE_INTEGER}),Object.freeze({[exports.ICell.Content.Values]:1,[exports.ICell.Content.Formulas]:1});const iw={ignoreDataChanges:!1},aw={colStart:-1,rowStart:-1,colEnd:-1,rowEnd:-1},lw=[{colIndex:-1,rowIndex:-1},null,null,null,null],cw=[exports.ICell.Content.Values],hw={size:null,autoSize:!0},dw={skipCustomSize:!0,expandOnly:!0,minContent:!0},uw={rowStart:0,colStart:0,rowEnd:0,colEnd:0},gw={showFormulaBar:!0,showTabs:!0,tabRatio:600,showHorizontalScrollbar:!0,showVerticalScrollbar:!0,showStatusBar:!0,activeSheetId:null};class pw{constructor(t){this._emitter=null,this._emitter=new ml(this),this._state={...gw},t?.json&&this._fromJSON(t?.json)}isShowFormulaBar(){return this._state.showFormulaBar}setShowFormulaBar(t){return this._state.showFormulaBar=t,this._emitter.notify("onViewChange"),this}isShowTabs(){return this._state.showTabs}setShowTabs(t){return this._state.showTabs=t,this._emitter.notify("onViewChange"),this}getTabRatio(){return this._state.tabRatio}setTabRatio(t){return this._state.tabRatio=t,this._emitter.notify("onViewChange"),this}isShowHorizontalScrollbar(){return this._state.showHorizontalScrollbar}setShowHorizontalScrollbar(t){return this._state.showHorizontalScrollbar=t,this._emitter.notify("onViewChange"),this}isShowVerticalScrollbar(){return this._state.showVerticalScrollbar}setShowVerticalScrollbar(t){return this._state.showVerticalScrollbar=t,this._emitter.notify("onViewChange"),this}isShowStatusBar(){return this._state.showStatusBar}setShowStatusBar(t){return this._state.showStatusBar=t,this._emitter.notify("onViewChange"),this}getActiveSheetId(){return this._state.activeSheetId}setActiveSheetId(t){return this._state.activeSheetId=t,this._emitter.notify("onViewChange"),this}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){let t={};const e=Object.keys(this._state);for(let r=0;r<e.length;r++){const n=this._state[e[r]];null!=n&&n!==gw[e[r]]&&(t[e[r]]=n)}return 0===Object.keys(t).length&&(t=null),t}_fromJSON(t,e=!0){let r=t||{};this.update(r,e)}update(t,e=!0){this._state={...gw,...this._state,...t},e&&this._emitter.notify("onViewChange")}}class mw{constructor(t){this._emitter=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new re({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,r,n){e._emitter.notify("onCollectionChange")}}),this._emitter=new ml(this,this._transactions),this._initState(t?.initial)}add(t,e,r){const n=this;e&&e.addListeners({onDelete:e=>{n._updateState(e=>{if(!e.modules[t])return;const r=e.modules[t];if(r){const o={...e};return n._options.onRemove?.(t,r),n._emitter.notify("onCollectionChange"),delete o.modules[t],o}return e},"Delete Module")}},{once:!0});const o=this._getState()?.modules,s=o?.[t],i=r?.replace??!1;if(s&&!i)throw new Error(`Already existing '${t}'`);const a={...o};e?(a[t]=e,n._options.onAdd?.(t,e),this._updateState({modules:a},i?"Save Scripts":"Add Script")):(delete a[t],n._options.onRemove?.(t,null),this._updateState({modules:a},"Remove Script")),n._emitter.notify("onCollectionChange")}search(t){const e=this._getState();if(!e)return mt.EmptyArray;const r=e.modules,n=Object.keys(r),o=n.length;if(0===o)return mt.EmptyArray;const s=[],i=t?.name?t.name.toUpperCase():null;for(let t=0;t<o;t++){const e=n[t],o=r[e];let a=!0;i&&i!==e.toUpperCase()&&(a=!1),a&&s.push(o)}return s??mt.EmptyArray}getByName(t){if(!t)return null;const e=this._getState();if(!e)return null;const r=t.toUpperCase(),n=e.modules,o=Object.keys(n),s=o.length;for(let t=0;t<s;t++){const e=o[t];if(r===e)return n[e]}return null}getCount(){const t=this._getState();return t?Object.keys(t.modules).length:0}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(gl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update",r){if(!t)return;const n=this._beginCommit(e);try{n.updateState(this,t),n.commit(r)}catch(t){throw n.rollback(),t}}_initState(t){let e=t??{};this._updateState({modules:e},"Initialize",{forceAmend:!0});const r=this._options.onAdd;if(r){const t=Object.keys(e),n=t.length;for(let o=0;o<n;o++){const n=t[o];r(n,e[n])}}}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){const t=this._getState();if(!t)return mt.EmptyArray;const e=t.modules,r=Object.keys(e),n=r.length,o={};for(let t=0;t<n;t++){const n=r[t];o[n]=e[n].toJSON()}return o}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}}let fw;const _w="SheetXL",Sw=fw||(fw=mt.deepFreeze({ISheet:{Visibility:exports.ISheet.Visibility},ICell:{Content:exports.ICell.Content,CalcStatus:exports.ICell.CalcStatus},IColor:{Named:exports.IColor.Named,Scheme:exports.IColor.Scheme,Type:exports.IColor.Type,AdjustmentType:exports.IColor.AdjustmentType},Direction:_}),fw);let ww;class yw extends S_{constructor(t,e,r,n=null,o=!1){super(t,e,r,n,o)}execute(...t){const e=t[0];if(!e||!e.isIWorkbook)throw new Error(`Macro '${this.getName()}' must be called with a valid workbook as the only argument.`);const r=this._ct;try{const t=[];switch(r){case __.Context.Workbook:t.push(e);break;case __.Context.Sheet:t.push(e.getSelectedSheet());break;case __.Context.Ranges:t.push(e.getSelectedRanges());break;case __.Context.Range:t.push(e.getSelectedRange());break;default:throw new Error(`Function '${this.getName()}' is not a valid macro function.`)}const n=async(t,e)=>{const r=await e;if(void 0!==r)if(null!==r){if(Array.isArray(r)){if(Rh(r[0]?.[0]))return void t.setValues(r,{skipBoundsCheck:!0})}else if(Rh(r))return void t.setValues([[r]]);r.isICell?t.updateCells(r):r.isICellRange&&await t.copyFrom(r)}else t.clear()};let o;return(async()=>{const r=(await this.getDescriptor()).getSummary()??`Macro '${this.getName()}'`;return await e.doBatch(async()=>{try{const r=e.getSelectedRange();let s=this._cf();if(!s){s=function(t){return new Proxy(t,{set:(t,e,r)=>(console.log(`Adding property "${e}" with value:`,r),t[e]=r,!0),deleteProperty:(t,e)=>(console.log(`Deleting property "${e}"`),delete t[e])})}({})}try{m_({getPosition:()=>r.getCell().getCoords()}),ww=globalThis[_w],globalThis[_w]=Sw;const e=this._fn;o=e.call(s,...t),ww?(globalThis[_w]=ww,ww=void 0):delete globalThis[_w],f_()}catch(t){throw t}finally{f_()}await n(r,o)}catch(t){throw t}},r),{params:t,results:o}})()}catch(t){throw t}}}class xw{constructor(t){this._emitter=null;const e=t.json;if(this._json=e,!this._json)throw new Error("Module JSON is required.");this._emitter=new ml(this),this._functions=new R_({transactions:null,readonlyFunctions:t.readonlyFunctions})}getFunctions(){return this._functions}getSource(){return this._json.source}getLanguage(){return this._json.language||"typescript"}getErrors(){return null}delete(){this._emitter.notify("onDelete")}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){return this._json}}const Cw=async(t,e)=>{let r=null;try{m_(null)}catch(t){console.warn("Error setting global scope",t)}try{const e=new Function("modulePath","return import(modulePath)");r=await e(
|
|
8
|
-
/* @vite-ignore */
|
|
9
|
-
/* webpackIgnore: true */
|
|
10
|
-
`data:text/javascript,${encodeURIComponent(t.compiled)}`)}catch(t){throw new Error("Invalid Javascript module.",{cause:t})}finally{f_()}if(!e)throw new Error(`No function available for '${t.name??t.commitId}'.`);const n=e.name;let o=r[n];if(!o&&e.behavior.default&&(o=r.default),!o)throw new Error(`Found the descriptor for '${n}' but not the function. The descriptor manifest must be corrupt.`);return o},bw=async(t,e=!1)=>{const r=t?.functions,n=new Map;if(r)for(let o=0;o<r.length;o++){const s=r[o],i=s[0],a=s[1];let l,c=e?()=>{}:await Cw(t,i);l=i.context&&i.context!==__.Context.Calculation?new yw(i,c,()=>null,a):new S_(i,c,()=>null,a),n.set(i.name.toUpperCase(),l)}return new xw({json:t,readonlyFunctions:n})};class Ew{constructor(t){this._options=t,this._initState()}_initState(){}getModules(){return this._modules}async createModule(t){const e=await Promise.resolve().then(()=>require("./BpoOeB751mnCS6V-.cjs")).then(t=>t.index),r=await e.ScriptingUtils.compileTypescript(t);return r?await bw(r,t?.declarationsOnly??!1):null}addModule(t,e,r){this._modules.add(t,e,r)}executeMacro(t,e){const r=this._modules.search({name:e}),n=r.length;for(let e=0;e<n;e++){const n=r[e].getFunctions().getByName(t);if(n)return n.execute(this._options.workbook)}throw new Error(`No macro ${t} found.`)}searchFunction(t){const e=t?.name,r=t?.moduleName,n=t?.type,o=this._modules;if(!o)return mt.EmptyArray;const s=o.getCount();if(0===s)return mt.EmptyArray;if(r){const t=this._modules.search({name:r});return 0===t.length?mt.EmptyArray():t[0].getFunctions().search({name:e,type:n})}const i=this._modules.search();for(let t=0;t<s;t++){const r=i[t].getFunctions().search({name:e,type:n});if(r.length>0)return r}return mt.EmptyArray}async start(){if(this._modules)return Promise.resolve();const t=this._options?.workbook,e=this._options?.json;let r={};if(e){const t=Object.keys(e);for(let n=0;n<t.length;n++){const o=t[n],s=e[o],i=await bw(s);r[o]=i}}const n=new mw({transactions:this._options?.transactions,initial:r,onRemove:this._options?.onRemove,onAdd:this._options?.onAdd});this._modules=n;const o=n.search();if(0===o.length)return Promise.resolve(mt.EmptyArray);const s=o.length;for(let e=0;e<s;e++){const r=o[e];try{const e=r.getFunctions().search({type:"autoRun"}),n=e.length;for(let r=0;r<n;r++){const n=e[r];await n.execute(t)}}catch(t){console.error("Error executing autoRun script:",t)}}}toJSON(){const t=this._modules;if(!t)throw new Error("Scripts is initializing.");return t.toJSON()}}const vw=Object.freeze({lockStructure:!1,lockWindows:!1,lockRevision:!1,workbookPassword:null,revisionsPassword:null});class Iw extends HS{isWindowsAllowed(){return this._isPropertyAllowed("windows")}isRevisionAllowed(){return this._isPropertyAllowed("revision")}isStructureAllowed(){return this._isPropertyAllowed("structure")}_fromJSON(t){this._properties=t}_toJSON(t){let e=this._properties;if(e){t={...t,...e};const r=Object.keys(e),n=r.length;for(let o=0;o<n;o++){const n=r[o],s=e[n];null!=s&&s!==vw[n]&&(t[n]=s)}}return super._toJSON(t)}}const Aw=t=>`Invalid SheetKey: ${t}`,Rw="A workbook must contain at least one visible worksheet.",Mw="Internal error no visible sheetRefs",Tw="Workbook has been closed. No further operations are allowed.",Fw="This workbook structure is protected. To make a change, unprotect the workbook. You might be requested to enter a password.",Nw="A sheet name",kw=`${Nw} can not be blank.`,Ow=`${Nw} can not be longer than 31 characters.`,Bw=`${Nw} can not begin or end with a "'" (single quote).`;class Lw{constructor(t,e){this._add=t,this._get=e}add(t){return this._add(t)}search(t){return this._get(t?.name,t?.visibility)}getByName(t){return this._get(t)?.[0]??null}getCount(){return this._get().length}}const Dw=new RegExp(/[\\/\\*?:[\]]+/),zw=new RegExp(/\(((\d+)(?!.*\d))\)$/,"g"),Pw=t=>`Sheet${t+1}`,jw=(t,e)=>({...fm,getSource:()=>null,toString:()=>ld(t,e)}),Hw=(t,e=!1)=>{if(!t)throw new Error(kw);if(Dw.test(t)){if(!e)throw new Error((t=>`${t?`'${t}'`:Nw} can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`)(t));t=t.replace(Dw,"")}if(0===t.length)throw new Error(kw);const r=t.length;if(r>31){if(!e)throw new Error(Ow);t=t.substring(0,31)}if("'"===t.charAt(0)||"'"===t.charAt(r-1)){if(!e)throw new Error(Bw);t=t.replace(/^'|'$/g,"")}return t};class Vw extends US{constructor(t,e,r,n){super(t,e,n),this._workbook=r}getSource(){return this._workbook}_createRanges(t,e){let r=this._options;return e&&(r={...this._options,getOptions:Im(this._options?.getOptions,e)}),new Vw(t,this._sheet,this._workbook,r)}_createRange(t,e){const r=t?{...t}:null;if(!(r?this._workbook._getSheetRef(r.sheetName,exports.ISheet.Visibility.VeryHidden):null)){const t=this._workbook.getSelectedSheet();return delete r?.sheetName,jw(r,r?{sheetName:Gh,...t.getEntireRange().getCoords()}:null)}let n=this._options;return e&&(n={...this._options,getOptions:Im(this._options.getOptions,e)}),new $w(t,this._sheet,this._workbook,n)}async select(t){const e=[];let r=null;const n=this.getCoords();for(let t=0;t<n.length;t++){const o=n[t];o&&(r||(r=o.sheetName),o&&o.sheetName===r&&e.push(o))}r||(r=this._workbook.getSelectedSheet().getName());const o=this._workbook.getSheets().getByName(r);if(!o)return;const s=await o.getRanges(e).select(t),i=this._workbook._rangesAddressToCoords(s.getCoords());return this._createRanges(i,t)}addListener(t,e){if(!this.getCoords())return()=>{};const r=this._workbook._sheetToWBEvent(t);return super.addListener(r,e)}get[Symbol.toStringTag](){return"[WorkbookRanges]"}toString(){const t=this.getCoords(),e=this._sheet,r=e.getEntireRange().getCoords(),n={sheetName:e.getName(),...r};return gd(t,n,ld,rd)}}class $w extends GS{constructor(t,e,r,n){super(t,e,n),this._workbook=r}_createRanges(t,e){let r=this._options;return e&&(r={...this._options,getOptions:Im(this._options?.getOptions,e)}),new Vw(t,this._sheet,this._workbook,r)}_createRange(t,e){const r=this._sheet;if(!t)return _m(r,r._entireCoords);if(r._validateCoords(t),r._closed)return _m(null,r._entireCoords,t);let n=this._options;return e&&(n={...this._options,getOptions:Im(this._options?.getOptions,e)}),new $w(t,this._sheet,this._workbook,n)}getSource(){return this._workbook}get[Symbol.toStringTag](){return"[WorkbookRange]"}toString(){const t=this._sheet,e=t?.getEntireRange().getCoords()??null;return ld(this.getCoords(),{...e,sheetName:t.getName()})}addListener(t,e){if(!this.getCoords())return()=>{};const r=this._workbook._sheetToWBEvent(t);return super.addListener(r,e)}}class Uw{constructor(t){this._lastTransactionUUID=null,this._closed=!1,this._initializing=!0,this._emitter=null,this._names=null,this._calculation=null,this._isDate1904=!1;const e=this,r={...t},n=r.json;delete r.json,this._transactions=r.transactions??new re,this._ownTransactions=!r.transactions,this._emitter=new ml(this,this._transactions);const o=this._beginCommit({description:(n?"Open":"New")+" Workbook"});try{this._strings=r.strings??new pf,this._ownStrings=!r.strings,this._resources=r.resources??new uf,this._ownResources=!r.resources,this._createSheetName=r.createSheetNameCallback??Pw;let t=r.createSheetCallback;t||(t=t=>new tw(t)),this._sheetOnNameChange=new Map,this._sheetOnVisibilityChange=new Map,this._sheetOnIndexChange=new Map,this._createSheet=(r,n,o,s,i)=>{let a=null;const l={date1904:e.isDate1904(),readonly:e._options.readonly??!1,transactions:e._transactions,styles:e._styles,strings:e._strings,resources:e._resources,names:e._names,calculation:e._calculation,resolveRange:t=>e._options.resolveRange?.(t)??e.getRange(t),container:{beforeFromJSON:t=>{a=t,e._addSheetRef({name:n,id:r,visibility:o??exports.ISheet.Visibility.Visible,sheet:t},s)},getName:()=>{const t=e._getSheetRef(a);return t?t.name:e._createSheetName(1)},setName:t=>{e._getSheetRef(a)&&e._setSheetName(a,t)},getIndex:()=>{const t=e._getSheetRef(a);return t?e._findOffsetForId(t.id,e._getSheetRefs(exports.ISheet.Visibility.VeryHidden)):-1},setIndexCallback:t=>{e._sheetOnIndexChange.set(r,t)},setNameChangeCallback:t=>{e._sheetOnNameChange.set(r,t)},getVisibility:()=>{const t=e._getSheetRef(a);return t?t.visibility:exports.ISheet.Visibility.Visible},setVisibility:t=>{e._setSheetVisibility(a,t)},setVisibilityCallback:t=>{e._sheetOnVisibilityChange.set(r,t)},duplicate:()=>e._duplicateSheet(a),setPosition:t=>{const r=e._getSheetRef(a,exports.ISheet.Visibility.VeryHidden);return!!r&&(e._moveSheet(r,t),!0)},requestSelect:async()=>(e._setSelectedSheet(a),await this._emitter.notify("onRequestSelect",{source:e,params:a,async:!0}),e.getSelectedSheet()===a)}};return i&&(l.json=i),a=t(l,n,s,o),a},this._names=r.names??new J_({addressToRanges:t=>e.getRanges(t),getCurrentScope:()=>e.getSelectedSheet().getName(),isReadOnly:()=>e._options.readonly??!1,transactions:e._transactions}),this._ownNames=!r.names,this._calculation=r.calculation??new M_({getNamed:(t,e)=>{try{Gw.address=t,Gw.scope=e;const r=this._names.search(Gw);return r&&0!==r.length?r[0].getRanges().getCoords():null}catch(t){return null}},getSheetIndex:t=>{if(void 0===t)return e.getSelectedSheetIndex();const r=this._getSheetRefs(exports.ISheet.Visibility.Hidden);t=t.toLowerCase();for(let e=0;e<r.length;e++)if(r[e].name.toLowerCase()===t)return e;try{Gw.address=t,Gw.scope=void 0;const e=this._names.search(Gw);if(!e||0===e.length)return-1;const r=e[0].getRanges().getCoords()?.[0];let n=r?.sheetName;if(!n)return-1;const o=this._getSheetRefs(exports.ISheet.Visibility.Hidden);n=n.toLowerCase();for(let t=0;t<o.length;t++)if(o[t].name.toLowerCase()===n)return t}catch(t){return-1}return-1},getSheetCount:()=>e.getSheets().getCount(),isDate1904:()=>e.isDate1904(),strings:e._strings,transactions:e._transactions}),this._ownsCalculation=!r.calculation,this._scripts=this._createScripts(),this._ownNames=!r.names,this._options={...r};const s=async()=>{this._ownsCalculation&&await this._calculation.start(),await this._scripts.start(),this._starting=null};this._starting=s(),n?this._fromJSON(n):(this._initState(),this._addSheet(!1)),this._emitter.notify("onLoad"),o.commit()}catch(t){throw o.rollback(),t}this._sheets=new Lw(t=>e._addSheetOptions(t),(t,e)=>t?[this.getSheet(t,e)]:this._getSheets(e)),this._initializing=!1}_initState(){let t=this._getSheetRefs();for(let e=t&&t.length-1;e>=0;e--);this._isDate1904=this._options.date1904??!1,this._theme=this._options.theme??(new ul).getDefaultTheme(),this._styles=this._options?.styles??new af(this._theme),this._ownStyles=!this._options.styles,this._styles.getTheme()||this._styles.setTheme(this.getTheme()),this._activeSheetOffset=0,this.setView(new pw),this._listenerProtection?.(),this._protection=new Iw(void 0,this._options.readonly??!1),this._listenerProtection=this._protection.addListeners({onChange:t=>{e._emitter.notify("onProtectionChange")}});const e=this;this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,r,n){if(r&&void 0!==r.activeSheetId&&r.view===e.getView()&&n.getId()===e._lastTransactionUUID&&e._getSheetRef(r.activeSheetId)?.sheet.select(),r&&n.getId()!==e._lastTransactionUUID){let n=e.getView().getActiveSheetId();r.view===e.getView()&&(n=r.activeSheetId);let o=0;try{o=e._findOffsetForId(n,t.sheetRefsVisible)}catch(t){}e._activeSheetOffset=o}e._lastTransactionUUID=n.getId(),e._notifyAllChange()},onRestoreOrRevert(){e._emitter.notify("onInvalidated")}});const r=this._getState();r?.listenersSheets&&(r?.listenersSheets.forEach(t=>{t()}),r?.listenersSheets.clear()),this._updateState({sheetRefsAll:[],sheetRefsVisibleAndHidden:[],sheetRefsVisible:[],refsById:new Map,sheetsById:new Map,refsByLowerCaseName:new Map,sheetsByLowerCaseName:new Map,refsByInstance:new Map,lastId:-1,sheetsCreated:new Set,listenersSheets:new Map})}getView(){return this._view}setView(t){if(this._closed)throw new Error(Tw);if(!t)throw new Error("View can not be empty.");this._listenerWorkbookView?.();const e=this;return this._listenerWorkbookView=t.addListeners({onViewChange:t=>{const r=e._getState();this._activeSheetOffset=this._findOffsetForId(this._view.getActiveSheetId(),r.sheetRefsVisible),e._emitter.notify("onViewChange")}}),this._view=t,e._emitter.notify("onViewChange"),this}isDate1904(){return this._isDate1904}setDate1904(t){if(this._closed)throw new Error(Tw);return this._isDate1904=t,this._notifyAllChange(),this}getStyles(){return this._styles}getResources(){return this._resources}getTransactions(){return this._transactions}getStrings(){return this._strings}getTheme(){return this._theme}setTheme(t){if(this._closed)throw new Error(Tw);if(!t)throw new Error("A value must be provided.");const e=this._theme;return this._theme=t,this.getStyles().setTheme(t),this._emitter.notify("onThemeChange"),e}getSelectedSheetIndex(){return this._activeSheetOffset}getSelectedSheet(){const t=this._getSheetRef(this.getSelectedSheetIndex());return t?t?.sheet:null}getSheet(t,e=exports.ISheet.Visibility.Visible){const r=this._getSheetRef(t,e);if(!r)throw new Mt(`Sheet '${t}' not found.`);return r.sheet}getSheetAt(t,e=exports.ISheet.Visibility.Visible){const r=this._getSheetRef(t,e);if(!r)throw new Mt((t=>`No sheet found at ${t}.`)(t));return r.sheet}getSheets(){return this._sheets}_getSheets(t=exports.ISheet.Visibility.Visible){const e=this._getSheetRefs(t),r=[];for(let t=0;t<e.length;t++)r.push(e[t].sheet);return r}_getSheetRefs(t=exports.ISheet.Visibility.Visible){if(this._closed)return mt.EmptyArray;const e=this._getState();return e?t===exports.ISheet.Visibility.Visible?e.sheetRefsVisible:t===exports.ISheet.Visibility.Hidden?e.sheetRefsVisibleAndHidden:t===exports.ISheet.Visibility.VeryHidden?e.sheetRefsAll:mt.EmptyArray:[]}_getSheetRef(t,e=exports.ISheet.Visibility.Visible){if(this._closed)return null;let r=null;if("number"==typeof t){return this._getSheetRefs(e)[t]}return"string"==typeof t?r=this._getState().refsByLowerCaseName.get(t.toLowerCase()):t instanceof tw?r=this._getState().refsByInstance.get(t):t?.id&&t.sheet&&(r=this._getState().refsById.get(t.id)),r}_validateNewSheetName(t,e=!0){if(null==t)return t;if(Hw(t),e&&this._getState().sheetsByLowerCaseName.has(t.toLowerCase()))throw new Error("That name is already taken. Try a different one.");return t.substring(0,31)}findValidSheetName(t){t&&(t=Hw(t,!0));try{return((t,e)=>{try{if(e(t))return t}catch(t){}let r,n,o=zw.exec(t);for(null!==o?(r=t.substring(0,o.index),n=parseFloat(o[1])):(r=t+" ",n=1);n<256;){n++;const t="("+n+")",o=r.substring(0,31-t.length)+t;try{if(e(o))return o}catch(t){}}throw new Error(t+" is not a valid sheet name")})(t,t=>this._validateNewSheetName(t))}catch(t){return this._nextSheetName()}}isValidSheetNameCharacter(t){return!Dw.test(t)}_addSheetOptions(t){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);let e=null;t={...t,description:t?.description??"Add Sheet"};const r=this.beginCommit(t);try{e=this._addSheet(!0,t.name,t.index??null);const n=this.getView().getActiveSheetId();let o,s;if(!1!==t.autoSelect){let r=this.getView().getActiveSheetId();r=this._getSheetRef(e).id,t?.autoSelect&&(o={view:this.getView(),activeSheetId:n},s={view:this.getView(),activeSheetId:r})}if(r.commit({description:`Add Sheet '${e.getName()}'`,viewBefore:o,viewAfter:s}),!1!==t.autoSelect){const r="boolean"==typeof t.autoSelect?void 0:t.autoSelect;e.select(r)}}catch(t){throw r.rollback(),t}return e}_nextSheetName(t=null){let e=t?t.toLowerCase():null;const r=this._getState(),n=r.sheetsByLowerCaseName;if(t&&n.has(e))throw new Error((t=>`The sheet name '${t}' already exist in workbook.`)(t));e=(t=this._validateNewSheetName(t))?t.toLowerCase():null;let o=r.lastId+1;for(;!t;){const e=this._createSheetName(o),r=e.toLowerCase();n.has(r)?o++:t=e}return this._updateState({lastId:o}),t}_addSheet(t,e=null,r=null){e=this._nextSheetName(e);const n=this._getState(),o=this._createSheet(n.lastId,e,exports.ISheet.Visibility.Visible,r,null);if(!o)throw new Error(kw);return t&&this._emitter.notify("onSheetsChange"),o}_updateSheetRefStates(t){if(this._closed)throw new Error(Tw);if(!this._initializing&&!this.getProtection().isStructureAllowed())throw new Error(Fw);const e=t,r=[],n=[];for(let t=0;t<e.length;t++)e[t].visibility===exports.ISheet.Visibility.Visible?(r.push(e[t]),n.push(e[t])):e[t].visibility===exports.ISheet.Visibility.Hidden&&n.push(e[t]);this._updateState({sheetRefsAll:e,sheetRefsVisible:r,sheetRefsVisibleAndHidden:n})}_addSheetRef(t,e=null){const r=this._getState(),n=r.sheetRefsAll,o=Math.max(0,Math.min(n.length,e??n.length));let s=[...n.slice(0,o),t,...n.slice(o)];this._updateSheetRefStates(s);const i=t.sheet,a=t.name.toLowerCase(),l=new Map(r.refsById);l.set(t.id,t);const c=new Map(r.refsByLowerCaseName);c.set(a,t);const h=new Map(r.refsByInstance);h.set(i,t);const d=new Map(r.sheetsById);d.set(t.id,i);const u=new Map(r.sheetsByLowerCaseName);u.set(a,i);const g=this;let p=r.listenersSheets;if(void 0!==i){const e=i.addListeners({onBeforeDelete:t=>{g._validateDeleteSheet(t)},onDelete(t){let e=g._getSheetRef(t,exports.ISheet.Visibility.VeryHidden);if(!e)return;const r=g._beginCommit({description:`Remove Sheet ${e.name}`});try{const n=g._getState(),o=n.sheetRefsAll,s=g._findOffsetForId(e.id,o);let a=[...o];a.splice(s,1),g._updateSheetRefStates(a);const l=new Map(n.refsById);l.delete(e.id);const c=new Map(n.sheetsById);c.delete(e.id);const h=e.name.toLowerCase(),d=new Map(n.refsByLowerCaseName);d.delete(h);const u=new Map(n.sheetsByLowerCaseName);u.delete(h);const p=new Map(n.refsByInstance);p.delete(t);n.listenersSheets.get(e.id)();const m=new Map(n.listenersSheets);m.delete(e.id),g._adjustRemoveSelectionIfRequired(s,e.id),g._adjustSheetNamesIfRequired(),g._emitter.notify("onSheetsChange");const f=new Set(n.sheetsCreated);f.has(i)&&f.delete(i),g._updateState({refsById:l,sheetsById:c,refsByLowerCaseName:d,sheetsByLowerCaseName:u,refsByInstance:p,sheetsCreated:f,listenersSheets:m}),r.commit()}catch(t){throw r.rollback(),t}}});p=new Map(r.listenersSheets),p.set(t.id,e)}let m=r.lastId;-1!==m&&(m=Math.max(m,t.id)),this._updateState({lastId:m}),this._updateState({refsById:l,refsByLowerCaseName:c,refsByInstance:h,sheetsById:d,sheetsByLowerCaseName:u,listenersSheets:p}),this._adjustSheetNamesIfRequired();const f=new Set(this._getState().sheetsCreated);return f.add(t.sheet),this._updateState({sheetsCreated:f}),t}_adjustRemoveSelectionIfRequired(t,e){if(this._view.getActiveSheetId()===e){let e;const r=this._getState().sheetRefsVisible;e=t<r.length?r[t].id:r[t-1].id,this._view.setActiveSheetId(e)}}_adjustSheetNamesIfRequired(){const t=this._getState(),e=t.lastId;if(-1===e)return;let r=this._view.getActiveSheetId();null==r&&(this._view.setActiveSheetId(e),r=e);t.refsById.get(r).visibility===exports.ISheet.Visibility.Visible&&(this._activeSheetOffset=this._findOffsetForId(r,t.sheetRefsVisible))}_validateDeleteSheet(t){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);let e=this._getSheetRef(t);if(!e)throw new Error((t=>`Invalid reference for delete: ${t}`)(t));const r=this._getState().sheetRefsVisible;if(1===r.length&&r[0].id===e.id)throw new Error(Rw)}_findOffsetForId(t,e){for(let r=0;r<e.length;r++)if(e[r].id===t)return r;throw new Error(Mw)}find(t,e){if(this._closed)throw new Error(Tw);const r=this._getSheets();if(1===r.length)return r[0].find(t,e);const n=!e?.reverse;let o=e?.disableWrap??!1;const s=this.getSelectedSheetIndex();let i=s,a=r[i],l=!1;e={...e,disableWrap:!0};let c,h=a.find(t,e),d=h.next(),u=!1;if(e?.from){const t=this._rangesAddressToCoords(e?.from);c={colIndex:t[0].colStart,rowIndex:t[0].rowStart}}else c={colIndex:0,rowIndex:0};const g=U.createCellComparator(e?.orientation,e?.reverse);delete(e={...e}).from;const p=()=>{if(!u&&d.done&&(l&&i===s?u=!0:n?(i++,i>r.length-1&&(i=0,l=!0)):(i--,i<0&&(i=r.length-1,l=!0)),o&&l&&(u=!0),!u))return a=r[i],h=a.find(t,e),d=h.next(),d;if(!u&&l&&i===s&&(d.done||!d.done&&g(d.value.getCoords(),c)>=0)&&(u=!0),u)return Cl;const p=d;return d=h.next(),p};return{next:()=>{let t=p();for(;!u&&t.done;)t=p();return t}}}replace(t,e,r){let n=0,o=null;const s="function"==typeof e,i=r?.maxCount??Number.MAX_SAFE_INTEGER;let a=r.maxCount?"":"All";const l="string"==typeof e?` with '${Ls(e)}'`:"";let c=r?.description??"Replace";const h=this._transactions.beginCommit({description:c});try{let c=null,d=null,u=t.next();for(;!u.done&&n<i;){const i=u.value,a=i.getSource();a!==c&&(c=a,null!==d&&d.apply(),d=c.getEntireRange().startIncrementalUpdates({orientation:r?.orientation,allowUnorderedWrites:!0}));const l=s?e(i):e;void 0!==l&&l!==i&&(d.push(i,l),n++,o=i),u=t.next()}d?.apply(),1===n&&1===i&&o&&(a=o.getA1()),h.commit({description:r?.description??`Replace ${a}${l}`})}catch(t){throw h.rollback(),t}return{count:n,last:o}}_nextSheetIndex(t,e=this._getSheetRefs()){return 1===e.length?0:(void 0===t&&(t=this.getSelectedSheetIndex()),(t=Math.max(0,Math.min(t,e.length-1)))>=e.length-1?0:t+1)}_prevSheetIndex(t,e=this._getSheetRefs()){return 1===e.length?0:(void 0===t&&(t=this.getSelectedSheetIndex()),(t=Math.max(0,Math.min(t,e.length-1)))<=0?e.length-1:t-1)}getNextSheet(t){if(this._closed)throw new Error(Tw);const e=this._getSheetRefs();return e[this._nextSheetIndex(t,e)]?.sheet??null}getPreviousSheet(t){if(this._closed)throw new Error(Tw);const e=this._getSheetRefs();return e[this._prevSheetIndex(t,e)]?.sheet??null}async _duplicateSheet(t){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);const e=this._getSheetRefs(),r=this.getSelectedSheetIndex();let n=null;if(t){if(n=this._getSheetRef(t),!n)throw new Error(Aw(n))}else n=e[r];if(!n)return null;const o=n.sheet,s=this._strings.beginPersist(),i=this.getResources().beginPersist(),a=this.getStyles().beginPersist();let l=null;const c=this.beginCommit(`Duplicate '${o.getName()}'`);try{const t=this._getState().refsByInstance.get(o),n=await o.toJSON(),s=e.length+1,i=this.findValidSheetName(t.name),a=this._createSheet(s,i,t.visibility,r,n);this._emitter.notify("onSheetsChange"),l=a,c.commit()}catch(t){throw c.rollback(),t}finally{a.endPersist(),i.endPersist(),s.endPersist()}return l}_createRange(t,e){const r=t?{...t}:null;if(!(r?this._getSheetRef(r.sheetName,exports.ISheet.Visibility.VeryHidden):null)){const t=this.getSelectedSheet();return t?(delete r?.sheetName,jw(r,r?{sheetName:Gh,...t.getEntireRange().getCoords()}:null)):void console.warn(Mw)}const n=this.getSelectedSheet();let o=null;return e&&(o={getOptions:e}),new $w(t,n,this,o)}_createRanges(t,e){const r=this.getSelectedSheet();let n=null;return e&&(n={getOptions:e}),new Vw(t,r,this,n)}getRange(t,e){try{const r=this._rangesAddressToCoords(t);if(1!==r.length)throw new Error(Nd);return this._createRange(r[0],e)}catch(e){if(e instanceof Mt)throw new Mt(e.message);throw new Error(e.message??Od(t))}}getRanges(t,e){const r=this._rangesAddressToCoords(t);if(0===r.length)throw new Error(Od(t));return this._createRanges(r,e)}_activeRangeCoords(){const t=this.getSelectedSheet(),e=Fm(t.getSelection().getCoords()),r=t.getName(),n=[];for(let t=0;t<e.length;t++)n.push({sheetName:r,...e[t]});return n}getSelectedRange(t){return this.getRange(this._activeRangeCoords()[0],t)}getSelectedRanges(t){return this.getRanges(this._activeRangeCoords(),t)}getSelectedCell(){return this.getSelectedSheet().getSelectedCell()}_rangesAddressToCoords(t,e=!0,r=exports.ISheet.Visibility.Hidden){if(!t)throw new Error(Fd);const n=this.getSelectedSheet(),o=n?.getEntireRange().getCoords(),s={...o},i=n?.getName();if(i&&(s.sheetName=i),"string"==typeof t){const e=t.trim().toLowerCase();if("r"===e||"c"===e){const r=this.getSelectedCell().getCoords(),n={};"r"===e?n.rowStart=n.rowEnd=r.rowIndex:n.colStart=n.colEnd=r.colIndex,t=n}}const a=this,l=md(t,s,dd,t=>{if(!e)return null;if("string"==typeof t){const e=a.getNames().getByName(t);if(e)return e.getRanges()?.getCoords()}throw new Error(`Invalid sheet reference '${t}'.`)});for(let t=0;t<l.length;t++)this._validateCoords(l[t],r);return l}_validateCoords(t,e=exports.ISheet.Visibility.Visible,r=Kd){if(null===t)return;const n=this.getSheet(t.sheetName,e).getEntireRange().getCoords();if(!U.isRangeWithinRange(t,n))throw new Mt(r);if(t.rowEnd<t.rowStart||t.colEnd<t.colStart)throw new Error(kd)}_updateSheetRef(t,e){const r=this._getState();let n=[...r.sheetRefsAll];n[this._findOffsetForId(t.id,r.sheetRefsAll)]=e,this._updateSheetRefStates(n);const o=new Map(r.refsById);o.set(t.id,e);const s=t.name.toLowerCase(),i=e.name.toLowerCase(),a=new Map(r.refsByLowerCaseName);a.delete(s),a.set(i,e);const l=new Map(r.sheetsByLowerCaseName);let c=l.get(s);l.delete(s),l.set(i,c);const h=new Map(r.refsByInstance);return h.set(c,e),this._updateState({refsById:o,refsByLowerCaseName:a,sheetsByLowerCaseName:l,refsByInstance:h}),e}_setSheetName(t,e){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);const r=this._getSheetRef(t);if(!r)throw new Error(Aw(t));if(e===r.name)return r.sheet;e=this._validateNewSheetName(e);const n=Object.freeze({...r,name:e});let o=null;const s=this.beginCommit("Rename Sheet");try{const t=this._updateSheetRef(r,n);this._adjustSheetNamesIfRequired(),this._sheetOnNameChange.forEach((t,e)=>{r.id===e&&t()}),this._emitter.notify("onSheetsChange"),o=t.sheet,s.commit()}catch(t){throw s.rollback(),t}return o}_setSheetVisibility(t,e=exports.ISheet.Visibility.Visible){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);const r=this._getSheetRef(t);if(!r)return null;if(e===r.visibility)return;let n=null,o="";e===exports.ISheet.Visibility.Visible?o="Unhide Sheet":e===exports.ISheet.Visibility.Hidden?o="Hide Sheet":e===exports.ISheet.Visibility.VeryHidden&&(o="Very Hide Sheet");const s=this.beginCommit(o);try{const t=this._getState().sheetRefsVisible;if(e!==exports.ISheet.Visibility.Visible&&1===t.length&&t[0].id===r.id)throw new Error(Rw);const o={...r,visibility:e};let i=-1;e!==exports.ISheet.Visibility.Visible&&(i=this._findOffsetForId(r.id,t));const a=this._updateSheetRef(r,o);e!==exports.ISheet.Visibility.Visible&&this._adjustRemoveSelectionIfRequired(i,r.id),n=a.sheet,this._adjustSheetNamesIfRequired(),s.commit()}catch(t){throw s.rollback(),t}return this._sheetOnVisibilityChange.forEach((t,e)=>{r.id===e&&t()}),this._emitter.notify("onSheetsChange"),n}_moveSheet(t,e){if(this._closed)throw new Error(Tw);if(!this.getProtection().isStructureAllowed())throw new Error(Fw);let r=null;const n=this.beginCommit(`Move Sheet '${t.name}'`);try{const o=this._getState(),s=o.sheetRefsVisible;if(e<0||e>s.length-1)throw new Error(`Invalid to index: ${e}`);const i={view:this.getView(),activeSheetId:this.getView().getActiveSheetId()},a=o.sheetRefsAll,l=this._findOffsetForId(t.id,a),c=this._findOffsetForId(s[e].id,a);if(l===c)return;const h=a[l];let d=[...a];d.splice(l,1),d.splice(c,0,h),this._updateSheetRefStates(d),this._adjustSheetNamesIfRequired(),this._sheetOnIndexChange.forEach((t,e)=>{e>=l&&e<=c&&t()}),this._emitter.notify("onSheetsChange"),r=h.sheet,n.commit({viewBefore:i,viewAfter:{view:this.getView(),activeSheetId:this.getView().getActiveSheetId()}})}catch(t){throw n.rollback(),t}return r}_setSelectedSheet(t){if(this._closed)throw new Error(Tw);const e=this._getSheetRef(t);if(!e)throw new Error(Aw(t));let r=null;return e.visibility!==exports.ISheet.Visibility.Visible&&this._setSheetVisibility(e,exports.ISheet.Visibility.Visible),this._view.setActiveSheetId(e.id),r=e.sheet,r}getProtection(){return this._protection}getNames(){return this._names}getCalculation(){return this._calculation}getScripts(){return this._scripts??null}_notifyAllChange(){this._emitter.notify("onSheetsChange"),this._emitter.notify("onViewChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}_sheetToWBEvent(t){const e=this;return r=>{const n=()=>{const t=r.getSource();if(t.isICellRanges){const r=[...t.getCoords()];for(let e=0;e<r.length;e++){const n=r[e];!n.sheetName&&t.getSource().getName()&&(r[e]={...n,sheetName:t.getSource().getName()})}return e.getRanges(r)}if(t.isICellRange){const r=t.getCoords(),n=t.getSource().getName();return e.getRange({...r,sheetName:n})}},o={getSource:n,trigger:r.trigger,getFrom:()=>e.getRanges(r.getFrom()),getTo:()=>e.getRange(r.getTo()),isDataChange:r.isDataChange,isTransactional:r.isTransactional,isUndo:r.isUndo,toString:()=>`WorkbookRangeEvent: ('${r.trigger}', ${n().toString()})`,timeStamp:Date.now()};t(o)}}_fromJSON(t){if(this._emitter.notify("onBeforeLoad",{params:t}),this._initState(),!t.sheets||0===t.sheets.length)throw new Error(Rw);t.theme&&(this._theme=new hl(t.theme),this._styles.setTheme(this._theme));const e=this._strings.beginPersist(),r=this._resources.beginPersist(),n=this._styles.beginPersist();try{e.fromJSON(t.strings),r.fromJSON(t.resources),n.fromJSON(t.styles),t.date1904&&(this._isDate1904=!0),t.view||(t.view={});const o=t.sheets,s=o.length;let i=t.view.activeSheetId??null;null!==i&&(i=Math.min(Math.max(1,i),s));let a=null;for(let t=0;t<s;t++){const e=o[t],r=e.visibility||exports.ISheet.Visibility.Visible,n=t+1;r===exports.ISheet.Visibility.Visible?a=n:null!==i&&i===n&&(i=null),this._createSheet(n,e.name,r,void 0,e.sheet)}this._updateState({lastId:a}),t.names&&this._names.fromJSON(t.names),t.view.activeSheetId=i??a,this.setView(new pw({json:t.view})),this._adjustSheetNamesIfRequired(),this._listenerProtection?.();const l=this;this._protection=new Iw(t?.protection,this._options?.readonly),this._listenerProtection=this._protection.addListeners({onChange:t=>{l._emitter.notify("onProtectionChange",{source:t})}}),t.scripts&&(this._scripts=this._createScripts(t.scripts)),this._emitter.notify("onLoad")}finally{n.endPersist(),r.endPersist(),e.endPersist()}}_createScripts(t){return new Ew({transactions:this._transactions,json:t,workbook:this,onAdd:(t,e)=>{const r=this._calculation;r.getStatus()!==exports.ICalculation.Status.Off&&r.start().then(()=>{const t=e.getFunctions().search({type:"formula"});for(let e=0;e<t.length;e++){const r=t[e];this._calculation.getFunctions().add(r)}})},onRemove:(t,e)=>{}})}async toJSON(t=!1){if(this._closed)throw new Error(Tw);await this._emitter.notify("onBeforeSave",{async:!0});const e={sheets:[]};await Promise.resolve(this._starting);const r=this._theme.toJSON();(r?Object.keys(r).length:0)>0&&(e.theme=r);const n=this._strings.beginPersist(),o=this._resources.beginPersist(),s=this._styles.beginPersist();try{const r=this._getSheetRef(this.getSelectedSheetIndex()).id;let i=r,a=null;const l=this._getState(),c=l.sheetRefsAll,h=l.sheetsById;for(let n=0;n<c.length;n++){const o=c[n],s=n+1,l=await h.get(o.id).toJSON(t),d={name:o.name,sheet:l};o.visibility===exports.ISheet.Visibility.Visible?a=s:d.visibility=o.visibility,o.id===r&&(i=s),e.sheets.push(d)}const d=s.toJSON();d&&Object.keys(d).length>0&&(e.styles=d);const u=this.getProtection().toJSON();u&&(e.protection=u);const g=await n.toJSONAsync();g&&g.length>0&&(e.strings=g);const p=await o.toJSONAsync();p&&p.length>0&&(e.resources=p);const m=this._names.toJSON();m&&m.length>0&&(e.names=m);const f=this._view.toJSON();f&&(i!==a?f.activeSheetId=i:delete f.activeSheetId,Object.keys(f).length>0&&(e.view=f))}finally{s.endPersist(),o.endPersist(),n.endPersist()}if(this._scripts){const t=this._scripts.toJSON();t&&Object.keys(t).length>0&&(e.scripts=t)}return this._isDate1904&&(e.date1904=!0),this._emitter.notify("onSave",{params:e}),e}isClosed(){return this._closed}close(){if(this._closed)return;this._emitter.notify("onClose");const t=this._getState();t.listenersSheets.forEach(t=>{t()}),t.listenersSheets.clear();const e=t.sheetRefsAll;for(let t=e.length-1;t>=0;t--)try{e[t].sheet.close()}catch(t){console.warn("error on close",t)}this._ownResources,this._ownNames&&this._names.close(),this._ownsCalculation&&this._calculation.close(),this._ownStyles,this._transactionsRemoveListener?.(),this._closed=!0}beginCommit(t){if(this._closed)throw new Error(Tw);return this._beginCommit("string"==typeof t?{description:t}:t)}doBatch(t,e){const r=this;return e="string"==typeof e?{description:e}:{description:"Update Workbook",...e},this._transactions.doBatch(t,e,(t,e)=>{0===t.getDepth()&&(r._lastTransactionUUID=t.getId())})}_beginCommit(t){const e=this;return this._transactions.beginCommit("string"==typeof t?{description:t}:t,t=>{0===t.getDepth()&&(e._lastTransactionUUID=t.getId())})}_getState(){return this._transactions.getState(this)}_updateState(t,e="Update Workbook"){if(!t)return;const r=this._beginCommit(e);try{r.updateState(this,t),r.commit()}catch(t){throw r.rollback(),t}}get options(){return this._options}get[Symbol.toStringTag](){return"[Workbook]"}toString(){return""}get isIWorkbook(){return!0}}const Gw={address:null,scope:null};exports.Bt=Zt,exports.C=h,exports.Calculation=M_,exports.Color=ba,exports.Et=kt,exports.ExternalRangeClipboardItem=class{constructor(t,e,r,n){if(this._parsed=void 0,!t)throw new Ft("nativeItems are required.");this._native=t,this._markOptions=Object.freeze(e??{}),this._styles=r,this._isDate1904=n}getItemType(){return"range"}isCut(){return!1}toText(){return this._native?.text}toHtml(){return this._native?.html?.documentElement.outerHTML||null}toImage(){return this._native?.image}getItem(){const t=this._parsed;if(void 0===t)throw new Error("Must call 'parse()' before getItem().");if(null===t)return null;if(this._snapshot)return this._snapshot;const e=this;return this._snapshot={copyTo:(r,n)=>t.copyTo(r,{...e._markOptions,...n}),getMarkOptions:()=>e._markOptions,getName:()=>t?.getName()??"Clipboard Data",getCoords:()=>t?.getCoords?.()??null,toText:()=>e.toText(),toHtml:()=>e.toHtml(),toImage:()=>e.toImage(),getSource:()=>t?.getSource?.()??null,isISnapshot:!0},this._snapshot}async parse(){let t,e=this._native?.text,r=this._native.html;if(null===r&&e&&e.includes("<table"))try{const t=(new DOMParser).parseFromString(e,w.html),n=t.querySelector("parsererror");if(n)throw new Error("Unable to parse: "+n);r=t,e=null}catch(t){console.warn("Discovered text as html table but could could not parse.")}try{const n=new N_(this._styles,this._isDate1904,r?"HTML":"Text"),o=await Promise.resolve(e?((t,e="\t")=>new Promise((r,n)=>{Promise.resolve().then(()=>require("./D-NvwNeGLHGiv00z.cjs")).then(t=>t.papaparse_min).then(o=>{try{const n=o.parse(t,{delimiter:e}).data;n.length>1&&(0===n[n.length-1].length||1===n[n.length-1].length&&0===n[n.length-1][0].length)&&n.pop(),r(n)}catch(t){console.warn(t),n(t)}},t=>{n(t)})}))(e):[[]]);let s;if(D_(r,o,n)?(t=n.sheet(),s=t.getUsedRange()):r=null,s)return this._parsed={async copyTo(t,e){const r=await t.copyFrom(s,e);return r?.getCoords()??null},getCoords:()=>s.getCoords(),getSource:()=>t,getName:()=>t.getName()},!0}catch(t){throw t}if(!e&&!r&&this._native.image){const t=this;return this._parsed={async copyTo(e,r){const n=e.getSource(),o=await n.getMovables().addImage({buffer:t._native.image.arrayBuffer()},{type:"picture",description:"Copy Image from Clipboard"});return n.getView().selectMovables([o]),null},getName:()=>"Image"},!0}return!1}get isClipboardItem(){return!0}},exports.FormulaContext=h_,exports.GeomUtils=Ne,exports.IFontCollection=fi,exports.LicenseManager=xe,exports.Mt=Ut,exports.Picture=mf,exports.Pt=Kt,exports.RangeClipboardItem=class{constructor(t){if(!t)throw new Ft("snapshot is required.");this._snapshot=t}getItemType(){return"range"}getItem(){return this._snapshot}editMode(){return this._snapshot?.getMarkOptions().editMode??null}isCut(){return this._snapshot?.getMarkOptions().isCut??!1}getName(){return this._snapshot.getName()}toText(){return this._snapshot.toText()}toHtml(){return this._snapshot.toHtml()}toImage(){return this._snapshot.toImage()}get isClipboardItem(){return!0}},exports.Resource=hf,exports.ResourceCollection=uf,exports.Sheet=tw,exports.SimpleFontFace=li,exports.St=Nt,exports.StringCollection=pf,exports.StyleCollection=af,exports.Table=Km,exports.TextUtils=Xs,exports.Theme=hl,exports.ThemeCollection=ul,exports.TransactionStore=re,exports.TransactionUndoManager=class extends Zt{constructor(t,e=50){super(e),this._transactions=t;const r=this;t?.addListener({onCommitEnd:e=>{e.getDescription()&&r.addUndoOperation({description:e.getDescription(),undo:()=>(t.revert(e.getId()),()=>{t.restore(e.getId())})})}})}clear(){super.clear()}close(){this._removeLister()}},exports.TypedFunction=S_,exports.Workbook=Uw,exports.WorkbookView=pw,exports.a=b,exports.b=f,exports.bt=Ft,exports.coerceScalar=Nh,exports.colToString=Qh,exports.defaultGetEntireCoords=Ah,exports.dt=vt,exports.e=t,exports.e$1=S,exports.et=mt,exports.getDefaultExportFromCjs=bi,exports.gridFromArray=Dh,exports.gt=Rt,exports.ht=class{constructor(){this._resolve=null,this._result=void 0,this._handled=null,this._reject=null,this._error=void 0,this._promise=null,this._promise=new Promise((t,e)=>{this._resolve=t,this._reject=e,"resolve"===this._handled?t(this._result):"reject"===this._handled&&e(this._error)})}resolve(t){this._resolve?this._resolve(t):this._handled||(this._result=t),this._handled="resolve"}reject(t){this._reject?this._reject(t):this._handled||(this._error=t),this._handled="reject"}async wait(){await this._promise}},exports.it=wt,exports.j=U,exports.l=E,exports.m=d,exports.minCoerce=Lh,exports.mt=Tt,exports.r=w,exports.rowToString=Kh,exports.rt=ft,exports.s=v,exports.t$1=_,exports.toAbsoluteRange=(t,e,r,n)=>{let o=t.colStart,s=t.rowStart,i=t.colEnd,a=t.rowEnd;const l=t.$colStart??!1,c=t.$rowStart??!1,h=t.$colEnd??!1,d=t.$rowEnd??!1;if(l||o===Number.MIN_SAFE_INTEGER||(o+=r),c||s===Number.MIN_SAFE_INTEGER||(s+=e),h||i===Number.MAX_SAFE_INTEGER||(i+=r),d||a===Number.MAX_SAFE_INTEGER||(a+=e),o>i){const t=o;o=i,i=t}if(s>a){const t=s;s=a,a=t}let u;return n?(u=n,u.colStart=o,u.rowStart=s,u.colEnd=i,u.rowEnd=a,u.$colStart=l,u.$rowStart=c,u.$colEnd=h,u.$rowEnd=d):u={colStart:o,rowStart:s,colEnd:i,rowEnd:a,$colStart:l,$rowStart:c,$colEnd:h,$rowEnd:d},t.sheetName&&(u.sheetName=t.sheetName),u},exports.tokensToA1=RS,exports.tokensToR1C1=AS,exports.typeFromJsValue=Rh,exports.ut=Et,exports.wt=At,exports.yt=Mt;
|