@sheetxl/mcp 0.8.0-beta.24 → 0.8.0-beta.25
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/assets/{tWO-mE87mAuj1qih.js → 45FAgD1JyG2a1Rti.js} +2 -2
- package/assets/{DtVSjxL6N_7WyM8Z.js → 70weNsvW2LMx5QcW.js} +1 -1
- package/assets/{LM2rVDHdB0jVUFcT.js → APcHum0Riw3QhLBQ.js} +1 -1
- package/assets/{CM-q_J5aF6YXmjeu.js → Abkx7KJ6_X5avkR4.js} +3 -3
- package/assets/{B7lATTNffVTrDsKE.js → B0FfnXdiZxExcdjB.js} +2 -2
- package/assets/{DL8pez0eKo8arYPj.js → B6e_DsVO4i91IYEO.js} +3 -3
- package/assets/{DOSWSyKkK4eSi4PD.js → B940vbTfpMYACpDE.js} +2 -2
- package/assets/{CmkgQ5-IG0BSCM3R.js → BAowTO-7Utmg0UvM.js} +3 -3
- package/assets/{fEfisM0E2fUYKIyU.js → BBccc8pDH-6AJdoT.js} +5 -5
- package/assets/{BJwiwzwx4Bl5L4Vq.js → BD3Bc7ZHxenj4S7Q.js} +1 -1
- package/assets/{CCF6CwJ6cbeLRl23.js → BFKj2ik7h-yM6oCR.js} +1 -1
- package/assets/{DM-yGHahbfA_uarn.js → BHIi-cAKnh_sAifV.js} +1 -1
- package/assets/{2YT_wstXIH6UIigi.js → BHeXL-Lo390ZSNV0.js} +1 -1
- package/assets/{CR1aLf7CWEfPTO9a.js → BNvsIyBwweYnfUz3.js} +1 -1
- package/assets/{CnI4Nli8vtWdFKvf.js → BSJ_L1gNOejEih6N.js} +32 -32
- package/assets/{yz2PTfYm_8EGJPM5.js → BV13tLgNXZ8MDaE_.js} +1 -1
- package/assets/{suLYEZBtGUhSYeB7.js → BW8ReYzx-CEJ-lAG.js} +1 -1
- package/assets/{CIw6ZC3K9x-ccacl.js → BXxUz-sB48Z9nSFi.js} +1 -1
- package/assets/{sJVPCrgeh0U6LbAK.js → B_GZxEqqpKtEPbWC.js} +1 -1
- package/assets/{a2e_g9YI3J-lUD7-.js → Bb7ZxgjHwiKgARXs.js} +1 -1
- package/assets/{B16G2473LTkZP6Mq.js → BbfSzxx5EzAvn-_F.js} +1417 -1356
- package/assets/{DuEtCJEnG_GnJzTX.js → BktUuVP0Jew8_-ff.js} +1 -1
- package/assets/{7vPlH3_rhJxmmBvG.js → Brlza6Jd2oGGX9vB.js} +1 -1
- package/assets/{CmwNIrRssYuLN2fn.js → BtNEVWQWEp_Ie1nT.js} +490 -490
- package/assets/{ByYJTTTUuu67hDF-.js → Bwk-CZuGiTRT2ox_.js} +4 -4
- package/assets/{DIgPlkEabQdKNUQn.js → BzLwCwXsh7eXQpeK.js} +1 -1
- package/assets/{KMzONx2Ps841nJHj.js → BzU8BhgrkSoh-XJF.js} +8 -8
- package/assets/{DkQ4kxEKhKYQgfjK.js → C-FJab2sVwBbOTiA.js} +1 -1
- package/assets/{CJ2hV-9ipqOEkLSG.js → C-Vt758qtn8QeCrw.js} +1 -1
- package/assets/{9GnbVPKozgrJpeLW.js → C2kYWrsx5mg4XOES.js} +1 -1
- package/assets/{Ch9w7xFxVMrvGuC_.js → C6Vsz4e_ASJdx3LP.js} +1 -1
- package/assets/{Cxzowsi6ASdZtzeI.js → C9DvPNfuz_0hun6C.js} +1 -1
- package/assets/{xD41vsQY6h60lCqz.js → CAI8p60cuWlgnlko.js} +8 -8
- package/assets/{DRzZ4bEyLRGVOLzV.js → CCOaNx5_BfWCc9yz.js} +1 -1
- package/assets/{6CBUVbF01Bedq0e2.js → CD2yoEhIT8DyXBou.js} +57 -57
- package/assets/{CpvJUGg9ckuCIpIS.js → CDiutOsLAzu4c0Ej.js} +1 -1
- package/assets/{CT4czEKWIj1GeQN8.js → CFrOPd_UcD7qclCq.js} +1 -1
- package/assets/{B-t1q2NS61c2B8E4.js → CGS7apShLtnlmF8D.js} +1 -1
- package/assets/{BH7ctzMzOYVTGxzA.js → CGdayif_qNMtoATI.js} +1 -1
- package/assets/{CFT_tDogP98gTbh7.js → CJubVukzHBNJb_Wf.js} +93 -93
- package/assets/{b8yACuWy67eIj_j2.js → COXWiXy3DCfmXSm5.js} +1 -1
- package/assets/{DPLTGglaPovTg9e5.js → COZ-bhj463kGINFA.js} +1 -1
- package/assets/{CnKX5SPVE2iuSK42.js → CSMsn9bKgR9kWG0m.js} +1 -1
- package/assets/{DaF9L7No8h8a-cqb.js → CVWoX7wNwrZwm5XB.js} +2 -2
- package/assets/{BkekCZ17YTtd07_C.js → CX-KrjVgXM-7o--S.js} +2 -2
- package/assets/{C0uu0vLKQh0S508B.js → CYtkZMCX6dyEqjb9.js} +40 -40
- package/assets/{Xccc6oxtlSvJUDsC.js → Cb7FKT3S78r6IYHi.js} +1 -1
- package/assets/{Dhy6iU_09lrQnOAV.js → CcTDxlAqw6HuYmmm.js} +34 -34
- package/assets/CehVpkp73IfWGN_b.js +14 -0
- package/assets/{BrJd9jVVv9SQzZol.js → CfWSdzSpbErVA_1h.js} +332 -332
- package/assets/{3VycPrqi6qgLOgGY.js → Ci3R5B7bLke8NZRo.js} +6 -6
- package/assets/{DyiH3LlinD-38bG7.js → ClRgSo0axU3lAOwR.js} +1 -1
- package/assets/{DwNcvKM47ZHfvQM6.js → Cmf4eJow6AIuPH_w.js} +1 -1
- package/assets/{DczQhB3mRSUw6GCf.js → Cplall3oc-_3AhCB.js} +1 -1
- package/assets/{BPNLZ07Bu_B8Yhf1.js → Cu4ok_jTnQif8QtX.js} +1 -1
- package/assets/{D-vo2bQyAmStQmD9.js → D053O1kZ7JtMwiqh.js} +1 -1
- package/assets/{BjyXkr-CzV8mVx0t.js → D5aWcMLJ2wyLm9Ws.js} +1 -1
- package/assets/{DE7G34oYbvrfXbJ7.js → D6qQAWN_5p3FAshK.js} +338 -338
- package/assets/{BaYk1vO2hP2S3_1w.js → D7NjohknztgMLqhT.js} +2 -2
- package/assets/{BJqo8c5bFKjnq69G.js → D8cqT2lbcP5Yp1Or.js} +11 -11
- package/assets/{BkHeIMSE7-LehRCs.js → D8wjcRGgRdU34Ata.js} +1 -1
- package/assets/{DGOgx3-IyO8bjF_t.js → DAnTpFc2vx3CmP8e.js} +63 -63
- package/assets/{BWLavTnANLUerdS0.js → DB2MrmDLZ-OzVRQu.js} +2 -2
- package/assets/{CbJWbjmv4bz4ppIZ.js → DBgHcEP-FcgSHLvx.js} +335 -335
- package/assets/{DUbIxDAzW1dzrtdI.js → DFd0JAiw5dkbnULM.js} +1 -1
- package/assets/{B6caaQsfOpFEgYQ4.js → DG9KGapq8eHlcTC7.js} +1 -1
- package/assets/{Daaro0HbHkKXkBP-.js → DHCl7HWDbT3xqx8W.js} +2 -2
- package/assets/{BnNB_ejvNaLu6B3o.js → DJlQxf99HCszeCCD.js} +1 -1
- package/assets/{CFNtPYPfDPH-3BXK.js → DLW76uSURiQM07DD.js} +1 -1
- package/assets/{By1QPrSxtnRiJu0R.js → DQBqVPRLkZFb2P_x.js} +2 -2
- package/assets/{Ds4TB1hn56-RK6_f.js → DQlLgxA592HvgKzh.js} +1 -1
- package/assets/{DNSWaXblwhTtI3w7.js → DRvzD5Tkcb2OU0G2.js} +1 -1
- package/assets/{CIY_RiLu1_FmRLAA.js → DUfrvQDZKh_22F91.js} +1 -1
- package/assets/{Dk9zYXO3VoBhTdex.js → DX94YgmfoL_ngS60.js} +1 -1
- package/assets/{DJfpKncnYnrr28G0.js → DXDhH3F4N4OOigqN.js} +1 -1
- package/assets/{bv3fZLUPzd14I58C.js → DXVfJfT6ftWk5kYi.js} +495 -495
- package/assets/{Jy-_0a72nn5Iv1NK.js → DYx_I-o0yjx056Dq.js} +1 -1
- package/assets/{DFVQIZ2zZyAphhCF.js → DZBfVpnngvY9Ra3C.js} +1 -1
- package/assets/{DXCTHw-ZutNIuo_2.js → DZOzgVEOXfHTE3YC.js} +1 -1
- package/assets/{BifwlrCmEVtjh_1U.js → DZTVTdrwu05fNZk_.js} +1 -1
- package/assets/{CzRvg04_TIbwBH5C.js → DaB9iRVJj3TmKH92.js} +3 -3
- package/assets/{Dlqk7XqKnAZ8Pcj3.js → DbHVXEt9qwlb8Gou.js} +154 -155
- package/assets/{CKD460cQOgwF6uSV.js → DbXqd8hGNQEyS-s0.js} +1 -1
- package/assets/{DaHD9SY75O8wDy3p.js → DcHo7BC8Ny3hWq0j.js} +2 -2
- package/assets/{doqBmhonQlHp-1Ud.js → DcHvH_I64hbnNh9G.js} +1 -1
- package/assets/{B4uS01J0mrSJSftQ.js → DfaQvLAaU7HHPnSe.js} +66 -66
- package/assets/{76dPHG5RYA7MUV_g.js → DgE30NwKzEjZI1W6.js} +3 -3
- package/assets/{DJGYlGr2Zj7SkYqc.js → Djl7cjJyCIS_Qvbd.js} +1 -1
- package/assets/{TZnuVwhVjkOBax9F.js → DkS3EQvuEuPDvCws.js} +2 -2
- package/assets/{BxwB3iTNSE1TgHkb.js → DkT0-_t9Xgp4l-Mh.js} +1 -1
- package/assets/{B-5mBXpY9i6-eCrZ.js → DlOCT6DI5bhPtQ8j.js} +33 -33
- package/assets/{C6PNMev7cs5JLgwy.js → DpGFb3hbAT5Murcv.js} +1 -1
- package/assets/{MosMza0-rXD8uHX_.js → DunKnm-bQd0oHn9n.js} +2 -2
- package/assets/{mZt9BTEejCJZ4YK4.js → Duw8QQGcrPmesb-M.js} +1 -1
- package/assets/{D8k9de_hen-KqBWe.js → DvkgborRc2vRq8E-.js} +1 -1
- package/assets/{DPYFRLJbHGlrcrJq.js → DwmlBb640xWfAMV2.js} +2 -2
- package/assets/{7IzItpr7MkdnaAwh.js → GfAXkT_vctdRX_9f.js} +67 -67
- package/assets/{CUYQlZz5zWsUdmRy.js → H40qXR3Gazmnq4Mv.js} +1 -1
- package/assets/{B8bEJ65vQRqsfBlS.js → HLtC2gb8SfNmJU5q.js} +5 -5
- package/assets/{BrYc6PLonux_gI6b.js → H_6CBe3t27jHlBHk.js} +172 -172
- package/assets/{qc7rA-Z3a4rkVQPx.js → LQNEL4KjDxwZNwWq.js} +187 -187
- package/assets/{D6d1DKL15m52ZCuC.js → O8YGVK4vtz39jQ84.js} +1 -1
- package/assets/{BXWGS09xFG81nnIT.js → TqxFLhPz3zbgi95t.js} +1 -1
- package/assets/{Cf0zmfQYfJ7zM0Ya.js → UdhH9UX9jQ4IV11J.js} +1 -1
- package/assets/{TdDTOcC1TYhk6UuR.js → V4pGXJr6fe-CPg7i.js} +1 -1
- package/assets/{C-nA4SXN5hWHaxV6.js → V_VVW06vjWkmlbdh.js} +534 -534
- package/assets/{CEk658HeLJk2cAjM.js → VkeNTI1TMsA1ZbGz.js} +3 -3
- package/assets/{P6V3JAiRpC3BWceC.js → cTLYCAhDs2fR2ITC.js} +1 -1
- package/assets/{DGI_8HyNF0eAv0P5.js → cU78RT4WJKAp5mU_.js} +1 -1
- package/assets/{C9iFJ52KwQTePQ81.js → ckvxz2tZRlY1UPpg.js} +10295 -10253
- package/assets/{DqSBb1HmgeU7eg_i.js → eCD6fmcTsgv76IZm.js} +110 -110
- package/assets/{flby0g5gyZ9P2Wu2.js → irrAIfw6CnCOHmPE.js} +1 -1
- package/assets/{DMDTS0LH9Ke9t-3z.js → ixHQtoul8ubEJfWS.js} +12 -7
- package/assets/{D_tdoUtUe7cApQJn.js → kmiMiNIUc6rS8DG8.js} +4 -4
- package/assets/{DRq6lQLndj73WT35.js → m9BgbF-NgPIYW4kc.js} +1 -1
- package/assets/{CSXmTA6w6Pnbtqvb.js → s56uiNHMGbBV6xgZ.js} +1 -1
- package/assets/{CFWwwr74qRKOBrg9.js → u8xtjHo43n-S_O6j.js} +1 -1
- package/assets/{NAWWzA_hk4wYtsPP.js → u9le-qZ3tbYKK1kU.js} +2 -2
- package/assets/{BAVltO4Xf7lC0Xr6.js → xMi-tFxI2s6e18L1.js} +1 -1
- package/assets/{g2Nu44uuSJFMzxEV.js → xSUMX6J9-MJIGgmG.js} +2 -2
- package/index.js +124 -124
- package/lib.js +1 -1
- package/licenses/dependencies.txt +56 -56
- package/package.json +2 -2
- package/screenshot-page/assets/{C_YKEkTsGB_5gFNg.js → 0P0DnZolMnjPhiea.js} +2 -2
- package/screenshot-page/assets/3L7CY5dA_kT2UBjv.js +1 -0
- package/screenshot-page/assets/{FcTM4SB17cEX1M3X.js → 5Y11BWntgqmzo9dz.js} +1 -1
- package/screenshot-page/assets/{CXwbGzavyvYgDbWU.js → B0CDAMDdxSN4en9k.js} +1 -1
- package/screenshot-page/assets/B6UwT0pG4sQeG7fA.js +3 -0
- package/screenshot-page/assets/{BbT5KRhoeAKLzy54.js → BCmGLxQEUabeee6Q.js} +2 -2
- package/screenshot-page/assets/{DR-og7vslxlOZd8j.js → BGIujWi3UayyIWlg.js} +1 -1
- package/screenshot-page/assets/BH2IWQ-8AfNbhYZJ.js +39 -0
- package/screenshot-page/assets/BNjmzbnQlBmX-HPQ.js +1 -0
- package/screenshot-page/assets/{DcrVJCyDwGKeil2U.js → BQTLEc84Eql61S2m.js} +1 -1
- package/screenshot-page/assets/{DGkaCFHx4PsOJkFu.js → BVnzv_sY_58zEJyM.js} +1 -1
- package/screenshot-page/assets/{Cx1kZ2u_8JFV2Q8D.js → BiRVjUOUI8Qv0CE1.js} +1 -1
- package/screenshot-page/assets/{r2HZG9_SMzF3__ID.js → BkU12U7IqW7qjopk.js} +6 -6
- package/screenshot-page/assets/{D6EXAYU-ZH8hjx_7.js → Bne-AygyF1USkPAy.js} +2 -2
- package/screenshot-page/assets/{Dkf51CnZh2zPEGMd.js → BpJaTpbR_CQzXj9M.js} +1 -1
- package/screenshot-page/assets/Bs-IXwX9BKsCxwcJ.js +2 -0
- package/screenshot-page/assets/{CwCu_r0BW41uLt3P.js → Bt7fKk5ZupUuo_xD.js} +2 -2
- package/screenshot-page/assets/{DM6hr-bvWV50-Oex.js → C-2hBFk27roWkIrQ.js} +2 -2
- package/screenshot-page/assets/C7MXfx6zf_uTwcpu.js +1 -0
- package/screenshot-page/assets/CALWodHqzUTIv9le.js +5 -0
- package/screenshot-page/assets/{B-0-chiwq4MIUQy9.js → CCYEWK5QyGSnUAfh.js} +1 -1
- package/screenshot-page/assets/{Cx9eq2x1gIXGki3Q.js → CFS0h-wE9YlZRk_1.js} +1 -1
- package/screenshot-page/assets/CKdQfdZJGJFgnrr9.js +586 -0
- package/screenshot-page/assets/{BKwDvElKinpn1IK0.js → CL_hAngRQwm_KGdR.js} +1 -1
- package/screenshot-page/assets/{a3fvt1Klg1uGE7p6.js → CMryHLEhCyKGuRSW.js} +7 -7
- package/screenshot-page/assets/COL9dj40ytErlGak.js +2 -0
- package/screenshot-page/assets/{BcZPWw18bdj_ZvA9.js → CRtk9ixuBWxhPfPU.js} +1 -1
- package/screenshot-page/assets/CUQsrLir5jYpnRPM.js +1 -0
- package/screenshot-page/assets/CUgX7ETRCJsvqa2x.js +1 -0
- package/screenshot-page/assets/{C7mXat-6esc1AmRD.js → CXeDqC02BZcixiHS.js} +2 -2
- package/screenshot-page/assets/{Pt9ne0xkE2icD3Ih.js → CZaKvnrRdlLj1_X8.js} +1 -1
- package/screenshot-page/assets/CfD1bn6b-NM38iZV.js +1 -0
- package/screenshot-page/assets/{WTrYzPnMQhYDILMR.js → Ck5onwb1w_19WrtG.js} +1 -1
- package/screenshot-page/assets/{DyxJBLjUkeDuu96F.js → CltB1nb5HHSmYrNG.js} +1 -1
- package/screenshot-page/assets/{D6Yv5cc1JE7DGd6j.js → CqBSIwwGzWl8mrBe.js} +1 -1
- package/screenshot-page/assets/CvBPH5c-gnUG8Jen.js +1 -0
- package/screenshot-page/assets/{D7Yt7xmUlA6-Lq0Q.js → D-jd_TJCN7AAn125.js} +9 -9
- package/screenshot-page/assets/{ChSvXfVMLxZsP9zG.js → D4RZZdlItfrgQHcE.js} +1 -1
- package/screenshot-page/assets/{Bfq6-treWd_rRiWl.js → D53hpXNHxIgSWl80.js} +1 -1
- package/screenshot-page/assets/{J73KTOmdZGNmnq-z.js → D72Rp__0TEqJ972a.js} +1 -1
- package/screenshot-page/assets/D8EmNst-H2v0eWcf.js +1 -0
- package/screenshot-page/assets/{BTJ1NNUzHotNDiDe.js → D98PlIA4qQ_6ciCu.js} +2 -2
- package/screenshot-page/assets/{Tj3B5At0OAN3tDza.js → DACqwpSwlZka3b7s.js} +1 -1
- package/screenshot-page/assets/{CI3Z1f4amZ9G2rPD.js → DJebrQ5mu8uxpX3b.js} +1 -1
- package/screenshot-page/assets/{CSFFMEKyxEFaykqL.js → DTAKTGn53yF_B621.js} +1 -1
- package/screenshot-page/assets/{D6Ciix7JAZtdKqmj.js → DYYzsN95gWMsxOaj.js} +1 -1
- package/screenshot-page/assets/{DOVt9zHz7FQ2KUQM.js → Da_VIghRFdNrmfZT.js} +1 -1
- package/screenshot-page/assets/{clrFU8i-0wNkmbs7.js → DbnmgPTSEii4OGkB.js} +1 -1
- package/screenshot-page/assets/{0UZBKpOOsp7P-DkP.js → DdmX3djBOA6UCZtf.js} +2 -2
- package/screenshot-page/assets/{DEpn6VGd30cHEJOS.js → DfQS5zAy3pN31xNb.js} +1 -1
- package/screenshot-page/assets/{DynKB5GH-vfFMJEy.js → DkTX5ZjGNQ5SrwJa.js} +1 -1
- package/screenshot-page/assets/{Bg9UyX4yrB2mSdJt.js → DmIjTb4kKfUHxWaF.js} +23 -23
- package/screenshot-page/assets/DqOrgSpuJhQRhMoG.js +4 -0
- package/screenshot-page/assets/{BIuMiduMHSsTGacU.js → Dz_yLNMXKWGx1O6V.js} +2 -2
- package/screenshot-page/assets/{B-8IMo2f1yGNXOyz.js → GxbRmvyoKhHl0ZYY.js} +13 -8
- package/screenshot-page/assets/{FqdZRM336KMEcsbU.js → MqGbtsji4DVGCAMR.js} +1 -1
- package/screenshot-page/assets/{zvxBjll3jnL0-vNn.js → Np3jWxG724t5hLHZ.js} +2 -2
- package/screenshot-page/assets/eR9_DaySoB72PvMo.js +1 -0
- package/screenshot-page/assets/{CtiTwHzd_ZSzd3W2.js → hB5riGkPy0wXVIig.js} +1 -1
- package/screenshot-page/assets/hHvAGynpTvAb97GX.js +1 -0
- package/screenshot-page/assets/{DmDFKv_3APEWI-IY.js → jKvAZg0Tp701aw1o.js} +2 -2
- package/screenshot-page/assets/{DACSL7FA_J91Z_H7.js → jteb4n23QwBT9m_4.js} +1 -1
- package/screenshot-page/assets/mzrDp0emvkWnkXBt.js +1 -0
- package/screenshot-page/assets/x1O923k1mN-CduO_.js +1 -0
- package/screenshot-page/index.html +15 -15
- package/types/scripting-api.json +1 -1
- package/types/scripting.d.ts +1 -1
- package/assets/Dfv_T_PQVL0O3lu5.js +0 -14
- package/screenshot-page/assets/B7pXfEVkcbaMBMhc.js +0 -1
- package/screenshot-page/assets/BDRMUi2BsnBqytIq.js +0 -2
- package/screenshot-page/assets/BEjJHVSbtlsNtoq7.js +0 -3
- package/screenshot-page/assets/BPMQ22uISGOm3ymr.js +0 -1
- package/screenshot-page/assets/Bxq4FCQhyPbVhhaR.js +0 -2
- package/screenshot-page/assets/CNB6WmYfGVZjlCKV.js +0 -5
- package/screenshot-page/assets/CXeJV1BW2CVemhPE.js +0 -1
- package/screenshot-page/assets/CkxmJxdtjBIxYoMq.js +0 -1
- package/screenshot-page/assets/D43IayseD2Cy8OZo.js +0 -4
- package/screenshot-page/assets/D8KyhLvfyjLZW92H.js +0 -39
- package/screenshot-page/assets/DBxAatsD6aWk7Zb6.js +0 -586
- package/screenshot-page/assets/DMhOGCTy8V0N14gY.js +0 -1
- package/screenshot-page/assets/DSTlKGmqncM7XHeW.js +0 -1
- package/screenshot-page/assets/Dh14XQinAphjZOKC.js +0 -1
- package/screenshot-page/assets/Dt8JxbBBr2TeDflQ.js +0 -1
- package/screenshot-page/assets/Dxi-bXNjS-CpC5Qr.js +0 -1
- package/screenshot-page/assets/Oay0yGsGYgJDzy8r.js +0 -1
- package/screenshot-page/assets/QZg76Jflu3Q808W3.js +0 -1
- package/screenshot-page/assets/qFyplGXRu7IepHio.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BVnzv_sY_58zEJyM.js","./HclGiUj8dZXDFmoM.js","./D4RZZdlItfrgQHcE.js","./CQukCzhuewMuFOlO.js","./CKdQfdZJGJFgnrr9.js","./3Ls_kOvlQseMV8Q0.js","./BQTLEc84Eql61S2m.js","./COL9dj40ytErlGak.js","./nHThFXCAZFOM_npq.js","./BQnELVV0uR4T4ItQ.js","./CnXLpFE_vFrJ5Jbf.js","./Np3jWxG724t5hLHZ.js","./CRtk9ixuBWxhPfPU.js","./MqGbtsji4DVGCAMR.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{t as e}from"./HclGiUj8dZXDFmoM.js";import{I as t,L as n,R as r,W as i,Z as a,_ as o,m as s}from"./D4RZZdlItfrgQHcE.js";import{r as c,s as l}from"./BQTLEc84Eql61S2m.js";import{Gt as u,Mt as d,an as f,at as p,dt as m,i as h,qt as g}from"./COL9dj40ytErlGak.js";import{a as _,c as v,i as y,l as b,n as x,t as S}from"./CQukCzhuewMuFOlO.js";import{A as C,Ai as w,An as T,Bi as E,Cn as D,D as O,Dr as k,Dt as A,En as j,Et as M,F as ee,Fn as te,Ft as N,Gr as P,Hi as F,Hn as ne,I as re,Ii as ie,Ir as ae,Jn as oe,Jr as se,K as ce,Lr as le,Mi as ue,Mt as de,Na as fe,Nn as pe,Oa as me,Oi as he,On as ge,Or as I,Pi as _e,Qi as ve,Qn as ye,Qt as be,R as xe,Rr as Se,S as L,Sa as R,Ta as Ce,Tr as z,U as we,Un as Te,Ur as Ee,V as De,Vr as Oe,Wi as B,Wr as V,Xi as ke,Xr as Ae,Xt as je,Y as Me,Yt as Ne,Z as Pe,Zn as Fe,_a as Ie,_r as Le,_t as Re,ba as ze,d as Be,da as H,dn as Ve,dr as He,ea as Ue,en as We,et as Ge,fa as Ke,fn as qe,ft as U,g as Je,ga as Ye,gt as Xe,i as Ze,ia as Qe,ir as $e,it as et,ja as tt,ji as nt,jr as rt,jt as it,k as at,ka as ot,ki as st,kt as ct,li as lt,mn as ut,mr as dt,mt as ft,nn as pt,nt as mt,o as ht,oi as gt,or as _t,pa as vt,pr as yt,qn as bt,qt as xt,r as St,ri as Ct,rn as wt,rr as Tt,rt as Et,sa as Dt,si as Ot,sn as kt,sr as At,st as jt,tn as Mt,tt as Nt,ua as Pt,un as Ft,ur as It,ut as Lt,v as Rt,wt as zt,xa as Bt,xt as Vt,y as Ht,ya as Ut,yi as Wt,yn as Gt,yr as Kt,zn as qt,zt as Jt}from"./CKdQfdZJGJFgnrr9.js";import{a as Yt,i as Xt,n as Zt,o as Qt,s as $t,t as en}from"./DbnmgPTSEii4OGkB.js";import{D as tn,S as nn,f as rn,g as an,j as on,k as sn,m as cn,r as ln,u as un,y as dn}from"./CvBPH5c-gnUG8Jen.js";import{n as fn}from"./CUQsrLir5jYpnRPM.js";import{_ as pn,a as mn,c as hn,d as gn,f as _n,g as vn,h as yn,i as bn,l as xn,m as Sn,o as Cn,p as wn,r as Tn,s as En,t as Dn,u as W}from"./MqGbtsji4DVGCAMR.js";var On=class e{constructor(e,t){this._grid=null,this._value=e,this._axis=t?.axis??n.Row,this._maxCoords=t?.maxCoords}_materialize(){let e=this._grid;if(!e){e=new D({axis:this._axis,maxCoords:this._maxCoords});let t=this._value;t!=null&&e.setValueAt(0,0,t),this._grid=e}return e}getValueAt(e,t){let n=this._grid;return n?n.getValueAt(e,t):e===0&&t===0?this._value:void 0}getCount(){let e=this._grid;return e?e.getCount():this._value==null?0:1}getCoords(){let e=this._grid;return e?e.getCoords():this.getCount()===0?null:{colStart:0,rowStart:0,colEnd:0,rowEnd:0}}getAxis(){return this._axis}getMaxCoords(){return this._maxCoords??null}clone(t){let n=this._grid;return n?n.clone(t):new e(this._value,{axis:this._axis,maxCoords:this._maxCoords})}cloneEmpty(e){return this._materialize().cloneEmpty(e)}setValues(e){return this._materialize().setValues(e),this}setValueAt(e,t,n){this._materialize().setValueAt(e,t,n)}getValues(e){return this._materialize().getValues(e)}entries(e){let t=this._grid;if(t)return t.entries(e);if(e?.processRowSkip||e?.processColumnSkip)return this._materialize().entries(e);let r=this._value;if(r==null)return At;let i=e?.bounds;if(i&&((i.colStart??0)>0||(i.rowStart??0)>0||(i.colEnd??0)<0||(i.rowEnd??0)<0))return At;let a=e?.axis?e.axis===n.Column:this._axis===n.Column,o=e?ct(e.reuseResult):void 0,s=this,c=!1,l=null;return{next:t=>l?l.next(t):t?(l=s._materialize().entries(e),l.next(t)):c?ot:(c=!0,Vt(0,0,r,a,o)),[Symbol.iterator](){return this},return:e=>ot,throw:e=>ot}}keys(e){return this._materialize().keys(e)}values(e){return this._materialize().values(e)}getRuns(e){return this._materialize().getRuns(e)}delete(e){return this._materialize().delete(e)}clear(){this._materialize().clear()}shift(e,t){return this._materialize().shift(e,t)}copyTo(e,t,n){this._materialize().copyTo(e,t,n)}},kn=class e{constructor(e){this._mapScopeTo2Ds=new Map,this._cloneKey=null,this._last2DKey=void 0,this._last2DMap=void 0,this._options=e,this._options2D=e;let t=e?.updateEntryOptions?.onUpdates;t&&(this._options2D={...e},this._options2D.updateEntryOptions={...e.updateEntryOptions},this._options2D.updateEntryOptions.onUpdates=(e,n,r)=>{t(e,n,this)})}all3D(e){e||=[];let t=e.length,n=this._mapScopeTo2Ds;for(let[r,i]of n){i.all(e);let n=e.length;for(let i=t;i<n;i++){let t=e[i];t.scope||(t={...t},t.scope=r,e[i]=t)}t=n}return e}getSpatialAt(e){if(e===this._last2DKey)return this._last2DMap;let t=this._mapScopeTo2Ds.get(e);return this._last2DKey=e,this._last2DMap=t,t}getScopeEntries(){return this._mapScopeTo2Ds.entries()}getScopeKeys(){return this._mapScopeTo2Ds.keys()}getScopeValues(){return this._mapScopeTo2Ds.values()}getBoundingRange(){throw Error(An)}isEmpty(){for(let e of this._mapScopeTo2Ds.values())if(!e.isEmpty())return!1;return!0}search(e,n=!1,r=!1,i){if(!e.scope)throw Error(jn);return this.getSpatialAt(e.scope)?.search(e,n,r,i)??t.EmptyArray}has(e){if(!e.scope)throw Error(jn);return this.getSpatialAt(e.scope)?.has(e)??!1}shift(e){if(!e?.range?.scope)throw Error(jn);let t=this.getSpatialAt(e?.range?.scope),n=t?.shift(e),r=this;return n!==t&&(r=this.clone(),r._mapScopeTo2Ds.set(this._last2DKey,n)),r}insertNonOverlapping(e,t){return this._getOrCreate2D(e.scope)?.insertNonOverlapping(e,t),this}createCopiedEntries(e,n,r,i,a){let o=e.scope;if(!o)throw Error(jn);let s=this.getSpatialAt(o)?.createCopiedEntries(e,n,r,i,a)??{inserts:t.EmptyArray,removes:t.EmptyArray},c=s.inserts,l=c?c.length:0;for(let e=0;e<l;e++){let t=c[e];t.scope||=o}let u=s.removes,d=u?u.length:0;for(let e=0;e<d;e++){let t=u[e];t.scope||=o}return s}remove(e,t){if(!e.scope)throw Error(jn);let n=this.getSpatialAt(e.scope);return n?.remove(e,t),this._cleanupEmpty2D(this._last2DKey,n),this}removeAll(e,t){let n=e?e.length:0;if(n===0)return this;let r=new Map,i,a;for(let t=0;t<n;t++){let n=e[t],o=n.scope;if(!o)throw Error(jn);o!==i&&(i=o,a=r.get(o),a||r.set(o,a=[])),a.push(n)}for(let[e,n]of r){let r=this.getSpatialAt(e);r&&(r.removeAll(n,t),this._cleanupEmpty2D(e,r))}return this}insert(e){return this._getOrCreate2D(e.scope).insert(e),this}load(e){let t=e?e.length:0;if(t===0)return this;let n=new Map,r,i;for(let a=0;a<t;a++){let t=e[a],o=t.scope;if(!o)throw Error(jn);o!==r&&(r=o,i=n.get(o),i||n.set(o,i=[])),i.push(t)}for(let[e,t]of n)this._getOrCreate2D(e).load(t);return this}delete(e){if(!e)throw Error(An);if(!e.scope)throw Error(jn);let t=this.getSpatialAt(e.scope);return t?.delete(e),this._cleanupEmpty2D(this._last2DKey,t),this}clone(e=null){let t=this._createClone(this._options);if(t._cloneKey=e,e!==null&&this._cloneKey===e)return t._mapScopeTo2Ds=this._mapScopeTo2Ds,t;let n=new Map;for(let[t,r]of this._mapScopeTo2Ds)n.set(t,r.clone(e));return t._mapScopeTo2Ds=n,t}_getOrCreate2D(e){if(!e)throw Error(jn);let t=this._mapScopeTo2Ds.get(e);return t||(t=new k(this._options2D),this._mapScopeTo2Ds.set(e,t),this._last2DKey=e,this._last2DMap=t),t}_cleanupEmpty2D(e,t){t?.isEmpty()&&(this._mapScopeTo2Ds.delete(e),this._last2DKey===e&&(this._last2DKey=void 0,this._last2DMap=void 0))}_createClone(t){return new e(t)}},An=`Not supported on SpatialMap3D`,jn=`SpatialMap3D: a valid scope key is required`,Mn=class{constructor(e,t,n,r,i,a,o,s){this.params=e,this.body=t,this.owner=n,this.compiled=r,this.regs=i,this.frame=a,this.anchorRow=o,this.anchorCol=s,this.isFunctionValue=!0,this._asFunction=null,this.active=0}makeCallable(){let e=this.params,t=e.length;for(;t>0&&e[t-1].optional;)t--;let n=(...e)=>this.owner._applyValues(this,e);return n.isLambdaCallable=!0,n.checkArity=n=>n>=t&&n<=e.length,n.paramCount=e.length,n}_function(){return this._asFunction??=ht(this)}execute(...e){return this._function().execute(...e)}getName(){return``}getDeclaration(){return this._function().getDeclaration()}getDescriptor(e){return this._function().getDescriptor(e)}isBuiltIn(){return!1}isLambda(){return!0}getContext(){return null}get isIFunction(){return!0}get[Symbol.toStringTag](){return`[LambdaValue(${this.params.map(e=>e.name).join(`,`)})]`}},Nn=class{constructor(e){this.fn=e,this.isFunctionValue=!0}makeCallable(){let e=this.fn,t=(...t)=>{try{return e.execute(...t)}catch(e){if(Ge(e))throw e;return y.isError(e)?e:new y.Value(e?.message,{cause:e})}};return t.isLambdaCallable=!0,t.checkArity=()=>!0,t.paramCount=-1,t}execute(...e){return this.fn.execute(...e)}getName(){return this.fn.getName()}getDeclaration(){return this.fn.getDeclaration()}getDescriptor(e){return this.fn.getDescriptor(e)}isBuiltIn(){return this.fn.isBuiltIn()}isLambda(){return this.fn.isLambda()}getContext(){return this.fn.getContext()}get isIFunction(){return!0}get[Symbol.toStringTag](){return`[FunctionValue(${this.fn.getName?.()??``})]`}},Pn=Symbol(`sheetxl.lambda.omitted`),Fn=new WeakSet,In=class e{constructor(e,t,n,r,i,a){this._gridId=null,this._resolvers=null,this._precedentTemplate=void 0,this._positionVariants=void 0,this._record=null,this._formatReferences=null,this._compiled=e,this._context=t,this._calcScope=n,this._gridId=r,this._getEntireCoords=i,this._resolvers=a??null}getTextAt(e,t,n=!1,r,i){let a=i===`display`,o=this._compiled;if(o.error&&!o.ast)return o.error.input;let s=r===void 0?o.getTokens():un(o.ast,r);s=ae(s,o.symbols,!a,a,a?{scope:this._gridId,rowIndex:e,colIndex:t}:null);let c=a?this._displayLocale():Ht;return n?me(s,this._getEntireCoords?.(),c):_t(s,this._getEntireCoords?.(),e,t,c)}_displayLocale(){let e=this._context.getRuntime().getLocaleProfile();return Ie($e(e.decimal))}getRecord(){let e=this._record;if(e)return e;let t=this._compiled,n=t.error,r;if(n){let e=n.cause;r={input:n.input,message:String(e?.message??``),unparsed:!t.ast,details:e instanceof y.Parse?e.getDetails():void 0}}let i={tokens:t.getTokens(),isReferenceOnly:t.isReferenceOnly};r&&(i.error=r);let a=this._recordReferences();return a&&(i.references=a),this._record=i}_recordReferences(){let e=this._compiled,t=e.referenceIndices,n=t.length;if(n===0)return null;let r=e.referencesExecute,i=e.referencesRelative,a=Array(n);for(let e=0;e<n;e++){let n=r[t[e]],o=n.inputs,s=null;if(o&&o.length===2){let e=i[r[o[0]].value],t=i[r[o[1]].value];s={colStart:e.colStart,rowStart:e.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,$colStart:e.$colStart,$rowStart:e.$rowStart,$colEnd:t.$colEnd,$rowEnd:t.$rowEnd,scope:e.scope}}else n.node.type===H.Cell?s={...i[n.value]}:n.op===H.Named?s={nameId:n.node.value.nameId}:n.op===H.TableReference&&(s={table:{...n.node.value}});a[e]=s}return a}getNode(){let e=this._compiled;return e.ast?fn(e.ast,e.symbols):null}getTokensAt(e,t,n){let r=this._compiled,i=n===void 0?r.getTokens():un(r.ast,n);return i=ae(i,r.symbols,!1,!0),wt(i,e,t)}getError(){return this._compiled.error??null}getNamedIds(){return this._compiled?.namedIds??t.EmptyArray}getReferencedSymbolIds(){return this._compiled?.symbolIds??t.EmptyArray}hasTotals(){return this._compiled?.hasTotals??!1}hasPivotData(){return this._compiled?.hasPivotData??!1}hasDataTable(){return this._compiled?.hasDataTable??!1}hasVolatile(){return this._compiled?.hasVolatile??!1}isBlankCacheable(e=!1){let t=this._compiled;return!!t&&(e?t.isBlankCacheableArray:t.isBlankCacheable)}demandFirstCell(){let e=this._compiled;e?.ast&&an(e.ast,e.getFunction)}getPositionVariants(){let t=this._positionVariants;if(t!==void 0)return t;t=null;let n=this._compiled,r=n&&!n.error&&n.ast?dn(n.ast,n.getFunction):null;if(r){let i=n.ast.firstCell!==void 0;t=r.map(t=>{let r=new e(tn(n.runtime,n.symbols,t,!1,null,n.getFunction),this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers);return i&&r.demandFirstCell(),r})}return this._positionVariants=t,t}isReferenceOnly(){return this._compiled.isReferenceOnly}isEquals(t){if(!(t&&t instanceof e))return!1;if(this===t)return!0;let n=this._compiled.getTokens(),r=t._compiled.getTokens();if(n.length!==r.length)return!1;let i=this._context.getEntireCoords();return me(n,i)===me(r,i)}getReferences(e,n){let r=this._compiled,i=r.referenceIndices,a=i.length;if(a===0)return t.EmptyArray;let o=r.referencesExecute,s=r.referencesRelative,c=C(a);for(let t=0;t<a;t++){let r=o[i[t]],a=r.inputs;if(a&&a.length===2){let e=s[o[a[0]].value],n=s[o[a[1]].value];c[t]={colStart:e.colStart,rowStart:e.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,$colStart:e.$colStart,$rowStart:e.$rowStart,$colEnd:n.$colEnd,$rowEnd:n.$rowEnd,scope:e.scope}}else if(r.node.type===H.Cell){let e=s[r.value];c[t]={...e}}else if(r.op===H.Named){let e=r.node.value.nameId,n=this._compiled.symbols?.resolve(U.NamedFormula,e)?.toString()??e;c[t]={nameId:n}}else if(r.op===H.TableReference){let i=r.node.value,a=this._resolveStructuredRef(i,e,n);!a||y.isError(a)?c[t]=null:c[t]={...a,tableId:i.tableId}}else r.op===H.Error&&(c[t]=null)}return c}getReferencesAt(e,n){let r=this.getReferences(e,n);return r.length===0?t.EmptyArray:Oe(r,e,n)}getFormatReferences(){let e=this._formatReferences;if(e)return e;let n,r=this._compiled.formatReferenceIndices,i=r.length;if(i===0)n=t.EmptyArray;else{let e=this.getReferences(0,0);n=[];for(let t=0;t<i;t++){let i=e[r[t]];i&&i.colStart!==void 0&&n.push(i)}n.length===0&&(n=t.EmptyArray)}return this._formatReferences=n,n}getReferenceAt(e,t,n){let r=this.getReferences(e,t);return n>=0&&n<r.length?r[n]:null}setReferenceAt(n,r,i){let a=this._compiled,s=a.referenceIndices;if(s.length===0)return null;let c=a.referencesExecute;n<0&&(n=s.length+n);let l=s[n];if(l===void 0)throw Error(`Invalid reference index: ${n}`);let u=c[l],d=u.node,f=d.inputs??t.EmptyArray,p=u.op===H.Named,m=f.length===2,h,g,_=!1;r&&y.isError(r)&&(r=null),r&&`nameId`in r&&!p&&(r=null);let v=r&&`nameId`in r?null:r,b=!!v&&v.colIndex!==void 0;if(v){if(b){let e=v;h={colIndex:e.colIndex,rowIndex:e.rowIndex,$colIndex:e.$colIndex??!1,$rowIndex:e.$rowIndex??!1},e.scope&&(h.scope=e.scope),_=!1}else{let e=v;h={colIndex:e.colStart,rowIndex:e.rowStart,$colIndex:e.$colStart??!1,$rowIndex:e.$rowStart??!1},e.scope&&(h.scope=e.scope),_=m||!o.isSingleCell(e),_&&(g={colIndex:e.colEnd,rowIndex:e.rowEnd,$colIndex:e.$colEnd??!1,$rowIndex:e.$rowEnd??!1},e.colEnd===2**53-1&&(g.colIndex=-(2**53-1)),e.rowEnd===2**53-1&&(g.rowIndex=-(2**53-1)))}}let x=b&&m,S=-1,C=-1,w=-1,T=-1;if(m)S=f[0].evalIndex,C=f[1].evalIndex;else if(d.type===`cell`)S=d.evalIndex;else if(u.op===H.TableReference)w=d.evalIndex;else{if(!p)throw Error(`Invalidate reference index: ${n}`);T=d.evalIndex}let E=(...e)=>{if(i?.scopeDeleted)return null;let t=this._compiled.symbols;for(let n=0;n<e.length;n++){let r=e[n]?.value?.scope;if(r)return t&&!t.resolve(U.Sheet,r)?null:r}return null},D=d,O=this._compiled.ast,k=gt(O,e=>{if(!e||!e.isReference)return;if(x&&e===D)return L(h);let n=e.type;if(T!==-1&&e.evalIndex===T&&n===H.Named){if(!r)return F();if(r&&`nameId`in r){let t=r,n=this._compiled.symbols?.bind(U.NamedFormula,t.nameId)??t.nameId,i={...e};return i.value={...e.value,...t,nameId:n},i}return _?Et(`:`,L(h),L(g),!0):L(h)}if(w!==-1&&e.evalIndex===w&&n===H.TableReference)return r?_?Et(`:`,L(h),L(g),!0):L(h):F();if(!r&&nn.includes(e.value)){let n=e.inputs??t.EmptyArray,r=n[0],i=n[1],a=r.evalIndex===S,o=i.evalIndex===C;if(a||o){let t=F(void 0,void 0,E(r,i));return t.evalIndex=e.evalIndex,t}}if(n!==`cell`&&n!==`error`)return;let i=e.evalIndex,a,o=i===S;if((o||i===C)&&!x){if(r){if(m===_){let t=o?h:g;a={...e},a.value=t,a.image=null}else a=Et(`:`,L(h),L(g),!0)}else a=F(void 0,void 0,E(e)),a.evalIndex=e.evalIndex;return a}});if(k===O)return this;let A=tn(a.runtime,a.symbols,k,!1,a.error,a.getFunction);return new e(A,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}reanchorReferences(t,n){let r=this._compiled,i=this._gridId,a=this._compiled.symbols.bind(U.Sheet,t),o=r.transform((e,t)=>{if(!e||!e.isReference||e.type!==H.Cell||sn(t)&&t.inputs?.[0]!==e)return;let r,o=e.value.scope;return(!o||n&&o===i)&&(r={...e},r.value={...r.value},r.value.scope=a),r});return r===o&&a===i?this:new e(o,this._context,this._calcScope,i,this._getEntireCoords,this._resolvers)}replaceScopeIds(t,n){if(t===n)return this;let r=this._compiled,i=r.transform((e,r)=>{if(!e||!e.isReference||e.type!==H.Cell||sn(r)&&r.inputs?.[0]!==e||e.value.scope!==t)return;let i={...e};return i.value={...i.value},i.value.scope=n,i});return r===i?this:new e(i,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}replaceTableReferences(t,n){let r=this._compiled,i=r.transform(e=>{if(e?.type!==H.TableReference)return;let r=e.value;if(typeof r!=`object`||r?.tableId!==t)return;let i=n(r);return i?(i.evalIndex=e.evalIndex,i):void 0});return r===i?this:new e(i,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}_evaluateNamed(e,t,n){let r=e.nameId,i=this._calcScope;if(i.activeNames.has(r))return y.BuiltIn.Ref;let a=this._resolvers?.getNamedFormulaBlock?.(r);if(!a){let e=this._compiled,t=e.symbols?.resolve(U.NamedFormula,r),n=t?t.toString():r,i=e.getFunction?.(n)??null;return i?new Nn(i):y.BuiltIn.Name}let o=i.gridId,s=i.rowIndex,c=i.colIndex;i.activeNames.add(r),i.depth++;try{return a.evaluateAt(t,n)}finally{i.depth--,i.activeNames.delete(r),i.gridId=o,i.rowIndex=s,i.colIndex=c}}_resolveNamedPrecedents(e,n,r){let i=e.nameId,a=this._calcScope;if(a.activeNames.has(i))return t.EmptyArray;let o=this._resolvers?.getNamedFormulaBlock?.(i);if(!o)return y.BuiltIn.Name;a.activeNames.add(i);try{return o.resolvedPrecedentsAt(n,r)}finally{a.activeNames.delete(i)}}_resolveStructuredRef(e,t,n,r){let i=this._resolvers?.getStructureReferenceCoords;return i?i(e,t,n,this._gridId):y.BuiltIn.Name}resolvedPrecedentsAt(e,n,r=!1,i,a){let o=this._compiled,s=o.referencesRoot,c=s.length;if(c===0)return t.EmptyArray;let l=o.referencesRelative,u=o.referencesAbsolute,d=l.length;for(let t=0;t<d;t++)zn(l[t],e,n,u[t]);let f=o.referencesExecute,p=f.length,m=[];for(let t=0;t<p;t++){let r=f[t],i=r.op;if(!i){let e=u[r.value];m[r.index]=e;continue}if(i===H.Named){m[r.index]=this._resolveNamedPrecedents(r.node.value,e,n);continue}if(i===H.Error){m[r.index]=Ee(r.node.value);continue}if(i===H.TableReference){let t=r.node.value,i;t&&(i=this._resolveStructuredRef(t,e,n)),i||=y.BuiltIn.Ref,m[r.index]=i;continue}if(i===`@`||i===`#`){let e=m[r.inputs[0]];m[r.index]=e===void 0?y.BuiltIn.Value:e;continue}let a=r.inputs;if(!a)continue;let o=m[a[0]];if(o===void 0){m[r.index]=y.BuiltIn.Value;continue}if(y.isError(o)){m[r.index]=o;continue}let s,c=m[a[1]];if(c!==void 0){if(y.isError(c))m[r.index]=c;else{if(i===` `){let e=o.scope?c.scope?null:o.scope:c.scope;s=e&&this._gridId&&e!==this._gridId?y.BuiltIn.Value:jt(o,c)}else if(i===`:`||i===`.:.`||i===`:.`||i===`.:`)s=xt(o,c);else if(i===`,`){let e=a.length;for(let t=0;t<e;t++){let e=m[a[t]];e===void 0||Array.isArray(e)||y.isError(e)||(s=s?xt(s,e):e)}}m[r.index]=s??y.BuiltIn.Null}}else m[r.index]=y.BuiltIn.Value}let h=[],g=0;for(let e=0;e<c;e++)g=Bn(s[e],f,m,h,g,i,a);return h}getPrecedentTemplate(){let e=this._precedentTemplate;if(e!==void 0)return e;e=null;let t=this._compiled,n=t.referencesRoot,r=t.referencesExecute,i=t.referencesRelative,a=n.length,o=Array(a),s=Array(a),c=Array(a),l=Array(a),u=!0;for(let e=0;e<a&&u;e++){let t=r[n[e]];if(t===void 0){u=!1;break}let a=t.op,d,f=null;if(a){if(a===H.Error)d=Ee(t.node.value);else if(a===`:`||a===`.:.`||a===`:.`||a===`.:`){let e=t.inputs;if(e&&e.length===2){let t=r[e[0]],n=r[e[1]];t===void 0||t.op||n===void 0||n.op||(d=i[t.value],f=i[n.value]??null,f===null&&(d=void 0))}}}else d=i[t.value];if(d===void 0){u=!1;break}o[e]=d,s[e]=f,c[e]=!!t.hasVerticalAbs,l[e]=!!t.hasHorizontalAbs}return u&&(e={relative:o,second:s,verticalAbs:c,horizontalAbs:l}),this._precedentTemplate=e,e}evaluateAt(e,t,n){let r=this._calcScope;r.rowIndex=e,r.colIndex=t,r.gridId=this._gridId;let i=this._context,a=this._compiled;if(n!==void 0){let r;if(gt(a.ast,e=>{e.evalIndex===n&&(r=e)}),!r)throw Error(`Invalid evalIndex: ${n}`);if(a.bindings.length>0&&!a.error){this.evaluateAt(e,t);let i=a.evaluations;return i[n]??(!0===r.inLazy?this._valueOfLazy(r,i,null,e,t):void 0)}a=tn(i.getRuntime(),a.symbols,Wn(r),!1)}if(a.error)return a.error.cause;a.hasVolatile&&r.node&&i._markVolatile();let o=a.evaluations,s=a.executions;a.bindings;let c=a.referencesExecute,l=a.referencesRelative,u=a.referencesAbsolute,d=c.length;for(let n=0;n<d;n++){let r=c[n],a=r.op,s=r.node;if(a){if(a===H.Named){if(r.node.deferredResolve)o[r.node.evalIndex]=null;else{let n=r.node.value;o[r.node.evalIndex]=this._evaluateNamed(n,e,t)}}else if(a===H.Error)o[s.evalIndex]=Ee(r.node.value);else if(a===H.TableReference){let n=r.node.value,a;a=n?this._resolveStructuredRef(n,e,t):y.BuiltIn.Ref,y.isError(a)||a?.colStart===void 0?o[s.evalIndex]=a??y.BuiltIn.Ref:o[s.evalIndex]=i.getReference(a)}else a===`structured`&&(o[s.evalIndex]=null)}else{let n=zn(l[r.value],e,t,u[r.value]);o[s.evalIndex]=n}}return this._runList(s,o,e,t,null),o[a.ast.evalIndex]}wrapImplicit(t,n,r){let i=this._compiled,a=i.ast;if(!a||!a.isReference||a.type===`cell`||a.type===H.Error||a.value===`@`||!r)return this;let o=Mt(n)+ze(t);if(r.has(o))return this;let s=Pe(`@`,a,!0),c=tn(i.runtime,i.symbols,s,!1,i.error,i.getFunction);return new e(c,this._context,this._calcScope,this._gridId,this._getEntireCoords,this._resolvers)}_executeNode(e,t,n,r,i=null){let a=this._context,o=e.inputs,s=o?o.length:0,c=e.type,l;switch(c){case H.Infix:{let n=e.value,r=t[o[0].evalIndex],i=t[o[1].evalIndex];if(!0===e.firstCell&&!e.isReference&&this._demandsFirstCell()&&(r=Rn(r),i=Rn(i)),(n===`+`||n===`-`)&&(r=Ln(a,r),typeof r==`number`&&(i=Ln(a,i),typeof i==`number`))){let t=n===`+`?r+i:r-i;return Ft(!0===e.snapsCancellation?M(t,r):t,null)}if(!e.isReference){if(r&&y.isError(r))return r;if(i&&y.isError(i))return i}let s=e.fn??=!0===e.snapsCancellation?ln[e.value]:rn[e.value];return l=s?s(a,r,i):y.BuiltIn.Value,l=Ft(l,null),l}case H.Function:{let a=e.binder;if(a!==void 0)return a.kind===`let`?t[o[s-1].evalIndex]:this._createLambdaValue(e,t,i,n,r);if(!0===e.hasLazyArgs){let a=j.enter();try{this._fillLazyArgs(o,s,t,i,n,r,a),!0===e.passOmitted&&Un(o,s),l=this._callFunction(e,Hn,s),l instanceof j&&(l=l._force())}finally{j.leave(a)}}else{for(let e=0;e<s;e++)Hn[e]=t[o[e].evalIndex];!0===e.passOmitted&&Un(o,s),l=this._callFunction(e,Hn,s)}return l}case H.Prefix:case H.Postfix:{let n=t[o[0].evalIndex];if(!0===e.firstCell&&!e.isReference&&e.value!==`@`&&this._demandsFirstCell()&&(n=Rn(n)),n&&y.isError(n))return n;let r=e.fn??=c===H.Prefix?on[e.value]:cn[e.value];return l=r?r(a,n):y.BuiltIn.Value,l}case H.List:case H.Paren:{if(s===1)return t[o[0].evalIndex];for(let e=0;e<s;e++){let n=t[o[e].evalIndex];if(typeof n==`object`&&n&&ye(n.scope))return y.BuiltIn.Name}let e=!1;for(let n=0;n<s;n++)if(De(t[o[n].evalIndex])){e=!0;break}if(e){let e=[];for(let n=0;n<s;n++){let r=t[o[n].evalIndex];De(r)?e.push(...r):e.push(r)}let n=C(e.length);for(let t=0;t<e.length;t++)n[t]=e[t];return n}let n=C(s);for(let e=0;e<s;e++)n[e]=t[o[e].evalIndex];return n}case H.Named:{let a=e.binding;if(a!==void 0){let n=this._compiled.bindings[a.slot];if(n>=0){let r=t[n];return r===void 0||r===Pn?!0===e.rawFrameRead?Pn:null:r}if(i!==null&&i.has(a.slot)){let t=i.get(a.slot);return!0===e.rawFrameRead?t:(u=t)===Pn?null:u}return y.BuiltIn.Calc}return!0===e.deferredResolve?this._evaluateNamed(e.value,n,r):t[e.evalIndex]??null}case H.TableReference:return t[e.evalIndex]??null;case H.Call:{let n=t[o[0].evalIndex];return n&&y.isError(n)?n:(l=this._applyCallee(n,e,t),l)}case H.Empty:return}var u}_fillLazyArgs(e,t,n,r,i,a,o){let s,c=!1;for(let r=0;r<t;r++){let t=e[r];if(!0===t?.lazyArg)continue;let i=n[t.evalIndex];!c&&(!0===i?.isIRange?i.size>1:De(i))&&(c=!0)}if(c){s=[];for(let o=0;o<t;o++){let t=e[o];!0===t?.lazyArg&&(s[o]=this._evaluateSubtree(t,n,r,i,a))}}for(let c=0;c<t;c++){let t=e[c];Hn[c]=!0===t?.lazyArg?s?s[c]:j.deferred(o,c,this,t,n,r,i,a):n[t.evalIndex]}}_createLambdaValue(e,t,n,r,i){let a=e.inputs,o=[];for(let e=0;e<a.length-1;e++){let t=a[e];t?.binding?.declaration&&o.push({slot:t.binding.slot,name:t.value.nameId,optional:!0===t.binding.optional})}return new Mn(o,a[a.length-1],this,this._compiled,t.slice(),n,r,i)}_applyCallee(e,t,n){if(e?.isIRange&&!e.isIReferenceRange&&e.size===1&&(e=e.getValueAt(0,0))&&y.isError(e))return e;let r=t.inputs,i=r.length-1;if(e instanceof Mn){let t=e.params,a=t.length;for(;a>0&&t[a-1].optional;)a--;if(i>t.length||i<a)return y.BuiltIn.Value;let o=new Map(e.frame??void 0);for(let e=0;e<t.length;e++){let a=t[e],s=e>=i||r[e+1]?.type===H.Empty;o.set(a.slot,s?Pn:n[r[e+1].evalIndex])}return e.owner._evaluateBody(e,o)}if(e instanceof Nn){let t=[];for(let e=1;e<r.length;e++)t.push(r[e]?.type===H.Empty?void 0:n[r[e].evalIndex]);return this._dispatchFunction(e.fn,t,t.length)}return e&&(e.isIRange||e.colStart!==void 0)||typeof e==`boolean`?y.BuiltIn.Ref:y.BuiltIn.Value}_applyValues(e,t){let n=e.params,r=n.length;for(;r>0&&n[r-1].optional;)r--;if(t.length>n.length||t.length<r)return y.BuiltIn.Value;let i=new Map(e.frame??void 0);for(let e=0;e<n.length;e++){let r=e<t.length?t[e]:void 0;i.set(n[e].slot,r===void 0?Pn:r)}let a=this._evaluateBody(e,i);return Ft(a,this._context)}_evaluateBody(e,t){let n=this._calcScope;if(n.depth>=512)return y.BuiltIn.Num;n.depth++;let r=e.active===0?e.regs:e.regs.slice();e.active++;try{return this._evaluateSubtree(e.body,r,t,e.anchorRow,e.anchorCol)}finally{n.depth--,e.active--}}_valueOfLazy(e,t,n,r,i){let a=this._evaluateSubtree(e,t,n,r,i);return typeof a==`object`&&a&&a.colStart!==void 0&&!0!==a.isIRange?this._context.getReference(a):a}_evaluateSubtree(e,t,n,r,i){try{let a=e.deferred??this._listWithin(e);return this._runList(a,t,r,i,n),t[e.evalIndex]}catch(e){if(y.isError(e))return e;if(Ge(e))throw e;return e instanceof RangeError?y.BuiltIn.Num:new y.Value(e?.message,{cause:e})}}_runList(e,t,n,r,i){let a=e.length;for(let o=0;o<a;o++){let a=e[o];t[a.evalIndex]=this._executeNode(a,t,n,r,i)}}_listWithin(e){let t;gt(this._compiled.ast,(n,r,i)=>{if(n===e){for(let e=i.length-1;e>=0;e--)if(i[e].deferred!==void 0){t=i[e];break}}});let n=new Set;gt(e,e=>{n.add(e)});let r=t?.deferred?.filter(e=>n.has(e))??[];return e.deferred=r,r}_demandsFirstCell(){let e=this._calcScope.node;return e!==null&&e.block.arrayFirstCell}_callFunction(e,t,n){let r=this._context,i=e.cacheFn??null;if(i&&e.cacheFnStamp!==void 0){let t=r._getFunctionStamp();e.cacheFnStamp!==t&&(i=null)}if(!i){if(i=r.getFunction(e.value),!i)return y.BuiltIn.Name;e.cacheFn=i,e.cacheFnStamp=i.isBuiltIn()?void 0:r._getFunctionStamp()}let a=this._calcScope,o=a.implicitIntersect,s=a.firstCell;a.implicitIntersect=!0===e.implicitIntersect,a.firstCell=!0===e.firstCell&&a.node!==null&&a.node.block.arrayFirstCell;let c=a.deferCount,l;try{l=this._dispatchFunction(i,t,n)}finally{a.implicitIntersect=o,a.firstCell=s}return a.deferCount!==c&&a.depth===0&&e===this._compiled.ast&&(a.deferRoot=!0),l}_dispatchFunction(e,t,n){let r,i=this._calcScope.deferCount,a=e._cfp;if(a){a.argsValues=t,a.argsLength=n;try{r=e.execute()}catch(e){if(Ge(e))throw e;r=Gn(e)}a.argsValues=null,a.argsLength=0}else try{switch(n){case 0:r=e.execute();break;case 1:r=e.execute(t[0]);break;case 2:r=e.execute(t[0],t[1]);break;case 3:r=e.execute(t[0],t[1],t[2]);break;case 4:r=e.execute(t[0],t[1],t[2],t[3]);break;case 5:r=e.execute(t[0],t[1],t[2],t[3],t[4]);break;default:let i=[];for(let e=0;e<n;e++)i.push(t[e]);r=e.execute(...i)}}catch(e){if(Ge(e))throw e;r=Gn(e)}let o=this._calcScope;if(o.deferCount!==i){let e=o.deferServed;return o.deferServed=null,e!==null&&e.latest!==void 0&&o.deferCount===i+1?e.latest:r===void 0?null:r}return r===void 0?new y.Parse:r}finalizeValue(e){let t=this._context;if(pe(e)||x(e))return y.BuiltIn.Calc;if(e&&e.colStart!==void 0)try{if(e.scope){let n=t.getReference(e);if(y.isError(n))return n}e=t.getValueAt(e.rowStart,e.colStart,e.scope)}catch(e){if(Ge(e))throw e;return y.isError(e)?e:new y.Value(e?.message,{cause:e})}if(Array.isArray(e)&&e.isSheetSpan)return y.BuiltIn.Ref;if(Array.isArray(e)){if(De(e)){let t=C(e.length);for(let n=0;n<e.length;n++)t[n]=this.finalizeValue(e[n]);return t}if(e.length===1&&Array.isArray(e[0])&&e[0].length===1)e=e[0][0];else try{e=t.getRange(e)}catch{e=y.BuiltIn.Value}}var n;return e?.isIRange?e.size<=1?(e=e.size===0?null:e.getValueAt(0,0,Vn),(e=Ft(e,t))===null&&(e=0)):(n=e,Fn.has(n)||(e=e.fillEmpty(0))):(e=Ft(e,t))===null&&(e=0),e}finalizeValueForCell(e){let t=this.finalizeValue(e);return Array.isArray(t)?y.BuiltIn.Value:t}toString(){let e=this._compiled;if(e.error)return e.error.toString();let t=this._calcScope;return t?.node?this.getTextAt(t.node.rowIndex,t.node.colIndex):me(e.getTokens(),null)}get[Symbol.toStringTag](){return`[FormulaBlock]`}},Ln=(e,t)=>typeof t==`object`&&t&&t.colStart!==void 0&&t.rowStart===t.rowEnd&&t.colStart===t.colEnd?e.getValueAt(t.rowStart,t.colStart,t.scope):t,Rn=e=>typeof e==`object`&&e&&!0===e.isIRange?e.getValueAt(0,0)??null:e;function zn(e,t,n,r){let i=e.colStart,a=e.rowStart,o=e.colEnd,s=e.rowEnd,c=e.$colStart??!1,l=e.$rowStart??!1,u=e.$colEnd??!1,d=e.$rowEnd??!1;if(c||i===-(2**53-1)||(i+=n),l||a===-(2**53-1)||(a+=t),u||o===2**53-1||(o+=n),d||s===2**53-1||(s+=t),i>o){let e=i;i=o,o=e}if(a>s){let e=a;a=s,s=e}let f=r;return f.colStart=i,f.rowStart=a,f.colEnd=o,f.rowEnd=s,f.scope=e.scope??null,f}var Bn=(e,t,n,r,i,a,o)=>{let s=t[e],c=s?.inputs;if(s?.op===`,`&&c){let e=c.length;for(let s=0;s<e;s++)i=Bn(c[s],t,n,r,i,a,o);return i}let l=s===void 0?y.BuiltIn.Value:n[e]??y.BuiltIn.Value;if(Array.isArray(l)){let e=l.length;for(let t=0;t<e;t++){let e=l[t];r[i]=e?.rowStart===void 0?e:{...e},a&&(a[i]=!(!e?.$rowStart&&!e?.$rowEnd)),o&&(o[i]=!(!e?.$colStart&&!e?.$colEnd)),i++}return i}let u=!!s?.hasVerticalAbs,d=!!s?.hasHorizontalAbs;if(l?.rowStart!==void 0){let e={...l};u&&(e.$rowStart=e.$rowEnd=!0),d&&(e.$colStart=e.$colEnd=!0),r[i]=e}else r[i]=l;return a&&(a[i]=u),o&&(o[i]=d),i+1},Vn=Object.freeze({type:null}),Hn=Array(255),Un=(e,t)=>{for(let n=0;n<t;n++)e[n]?.type===H.Empty&&(Hn[n]=Pn)},Wn=e=>{let t={...e};return delete t.inLazy,delete t.lazyArg,delete t.hasLazyArgs,delete t.deferred,e.inputs&&(t.inputs=e.inputs.map(e=>e&&Wn(e))),t},Gn=e=>y.isError(e)?e:e instanceof RangeError?y.BuiltIn.Num:new y.Value(e?.message,{cause:e}),Kn=mt(4096),qn=0,Jn=()=>Kn,Yn=(e,t)=>{if(t===0)return void(e.inputsAt=-1);let n=qn,r=n+t;if(r>Kn.length){let e=mt(Math.max(r,2*Kn.length));for(let t=0;t<n;t++)e[t]=Kn[t];Kn=e}let i=Kn;for(let e=n;e<r;e++)i[e]=void 0;qn=r,e.inputsAt=n},Xn=(e,t)=>{let n=e.inputsAt;return n<0?void 0:Kn[n+t]},Zn=(e,t)=>{let n=e.inputsAt;if(n<0)return;let r=Kn;for(let e=0;e<t;e++)r[n+e]=void 0},Qn=0,$n=1,er=4,tr=32,nr=64,rr=128,G=768,K=3072,ir=12288,ar=16384,or=32768,q=65536,sr=1<<17,cr=1<<18,lr=1<<19,ur=1<<20,dr=1<<21,fr=1<<22,pr=495520,mr=0,hr=256,gr=512,_r=768,vr=0,J=1024,yr=2048,br=(e,t,n)=>{let r=wr(e,t,n?.anchor===`start`),i=r.value;switch(r.op){case`prefix`:{let t=i;if(t===``)return e=>typeof e==`string`;let n=t.length;return r=>typeof r==`string`&&r.length>=n&&e.compare(r.slice(0,n),t)===0}case`wc`:{let e=i,t=r.match;return n=>typeof n==`string`?t===e.test(n):!t}case`=`:return i===void 0?e=>e==null:i===``?e=>e==null||e===``:typeof i==`string`?t=>typeof t==`string`&&e.compare(t,i)===0:y.isError(i)?e=>!!y.isError(e)&&e.equals(i):typeof i==`number`?t=>typeof t==`number`?e.compare(t,i)===0:typeof t==`string`&&Sr(e,t,i):e=>e===i;case`<>`:return i===void 0?e=>e!=null:typeof i==`string`?t=>typeof t!=`string`||e.compare(t,i)!==0:y.isError(i)?e=>!y.isError(e)||!e.equals(i):typeof i==`number`?t=>typeof t!=`number`||e.compare(t,i)!==0:e=>e!==i;case`>`:return xr(e,i,e=>e>0);case`>=`:return xr(e,i,e=>e>=0);case`<`:return xr(e,i,e=>e<0);case`<=`:return xr(e,i,e=>e<=0);default:return()=>!1}},xr=(e,t,n)=>{if(t===void 0)return()=>!1;let r=Cr(t);return i=>r(i)&&n(e.compare(i,t))},Sr=(e,t,n)=>{try{return e.compare(e.parseAsNumber(t),n)===0}catch{return!1}},Cr=e=>{switch(typeof e){case`string`:return e=>typeof e==`string`;case`number`:return e=>typeof e==`number`;case`boolean`:return e=>typeof e==`boolean`;default:return e=>y.isError(e)}},wr=(e,t,n=!1)=>{let r=typeof t;if(r===`string`){let r=t,i=e.parseAsLiteral(r);if(i!==void 0)return{op:`=`,value:i};let a=r.match(/^(<>|>=|<=|>|<|=)([\s\S]*)$/);if(a!==null){let t=a[1],n=a[2];if(n===``)return{op:t,value:void 0};let r;if(typeof n==`string`)try{r=e.parseAsNumber(n)}catch{}if(r===void 0){let i=e.parseAsLiteral(n);if(i!==void 0)r=i;else if(r=n,(t===`=`||t===`<>`)&&b.isWildCard(r))return{op:`wc`,value:b.toRegex(r,`i`,!0),match:t===`=`}}return{op:t,value:r}}try{let t=e.parseAsNumber(r);if(t!==void 0)return{op:`=`,value:t}}catch{}return b.isWildCard(r)?{op:`wc`,value:b.toRegex(r,`i`,!n||`start`),match:!0}:{op:n?`prefix`:`=`,value:t}}return r===`boolean`||r===`number`||y.isError(t)?{op:`=`,value:t}:t==null?{op:`=`,value:0}:{op:`err`,value:new y.Value(`Criteria.parse: type ${typeof t} not support`)}},Tr=class{constructor(e,t,n,r,i){this._groups=[],this._children=null,this._keyRows=[],this._keys=e,this._parents=t,this._levels=n,this._firsts=r,this._sizes=i}getRoot(){return this.group(0)}getGroupCount(){return this._levels.length}group(e){return this._groups[e]??=new Er(this,e)}levelOf(e){return this._levels[e]}parentOf(e){return e===0?null:this.group(this._parents[e])}childrenOf(e){if(!this._children){let e=Array(this._levels.length);for(let t=0;t<e.length;t++)e[t]=[];for(let t=1;t<e.length;t++)e[this._parents[t]].push(this.group(t));this._children=e}return this._children[e]??[]}keysOf(e){let t=this._keyRows[e];if(!t){let n=this._levels[e];t=n!==0&&this._keys?[...this.keysOf(this._parents[e]),this._keys.getValueAt(this._firsts[e],n-1)??null]:[],this._keyRows[e]=t}return t}sizeOf(e){return this._sizes[e]}firstRecordOf(e){return this._firsts[e]}},Er=class{constructor(e,t){this._tree=e,this.id=t}getLevel(){return this._tree.levelOf(this.id)}getParent(){return this._tree.parentOf(this.id)}getChildren(){return this._tree.childrenOf(this.id)}getKeys(){return this._tree.keysOf(this.id)}getSize(){return this._tree.sizeOf(this.id)}getFirstRecord(){return this._tree.firstRecordOf(this.id)}},Dr=e=>e?e.id:0,Or=(e,t)=>{let n=t.length/5,r=new Uint32Array(n),i=new Uint32Array(n),a=new Uint32Array(n),o=new Uint32Array(n);for(let e=0;e<n;e++){let n=5*e;r[e]=t[n],i[e]=t[n+2],a[e]=t[n+3],o[e]=t[n+4]}return new Tr(e,r,i,a,o)},kr=class e{static create(t,n,r,i){let a=A.peek();if(!a)throw Error(`The sdk WebAssembly is not loaded.`);let o=(t??n)?.getRowCount()??0;if((t?.getColumnCount()??0)>32||(n?.getColumnCount()??0)>32)throw y.BuiltIn.Value;let s=new a.PivotRequest(o),c=e._addFields(s,t,!0),l=e._addFields(s,n,!1),u=i?.filter?s.add_filter():-1,d=a.wasm_memory().buffer;if(e._fillFields(d,t,c,o),e._fillFields(d,n,l,o),u!==-1){let e=new Uint32Array(d,u,2*Math.ceil(o/64));for(let t of i.filter.entries()){let n=t.value,r=t.coords.rowIndex;r<o&&(!0===n||typeof n==`number`&&n!==0)&&(e[r>>>5]|=1<<(31&r))}}let f;try{f=s.compute(0,!1)}catch{throw s.free(),y.BuiltIn.Value}return new e(a,s,f,o,t,n,r)}static _addFields(e,t,n){let r=[],i=t?t.getColumnCount():0;for(let t=0;t<i;t++)r.push(n?e.add_row_field():e.add_column_field());return r}static _fillFields(e,t,n,r){for(let i=0;i<n.length;i++){let a=n.length===1?t:t.slice({colStart:i,colEnd:i});new $t().fill(a,new Uint32Array(e,n[i],r))}}constructor(e,t,n,r,i,a,o){this._cellsByColumn=new Map,this._errors=new en,this._values=new Map,this._leafCount=0,this._withRecords=null,this._wasm=e,this._request=t,this._result=n,this._n=r,this._createColumn=o;let s=n.row_nodes();this._rows=Or(i,s),this._columns=Or(a,n.column_nodes()),this._recordCount=s.length>0?s[4]:0}getRecordCount(){return this._recordCount}getRows(){return this._rows}getColumns(){return this._columns}getMembers(e,t,n){this._withRecords||=(this._request.clear_measures(),this._request.compute(0,!0));let r=this._withRecords.cell(Dr(t),Dr(n));return r===4294967295?null:((e,t,n)=>{let r=t.length,i=[],a=[];for(let n=0;n<r;n++){let r=e.getValueAt(t[n],0);r!=null&&(i.push(n),a.push(r))}return n(r,i,a,a.length)})(e,this._withRecords.records(r),this._createColumn)}getAggregate(e,t,n,r){if(!t.isBuiltIn())return;let i=Qt[t.getName().toUpperCase()];if(i===void 0)return;let a=this._values.get(e);if(a===void 0&&(a=this._addValues(e),this._values.set(e,a)),a===null||i>=7&&!a.numeric)return;let o=this._cell(Dr(n),Dr(r));return o===4294967295?null:(a.results[i]??=this._run(a.leaf,i))[o]}_cell(e,t){let n=this._cellsByColumn.get(t);return n||(n=this._result.row_cells(t),this._cellsByColumn.set(t,n)),n[e]??4294967295}_buffer(){return this._wasm.wasm_memory().buffer}_addValues(e){let t=this._n;if(e.getColumnCount()!==1||e.getRowCount()!==t)return null;let n=this._request.add_values(127),r=this._leafCount++,i=this._buffer(),a={doubles:new Float64Array(i,n,t),ints:new Int32Array(i,n,2*t),types:new Uint8Array(i,n+8*t,t)},{ok:o,numeric:s}=Yt(e,a,this._errors);return o?{leaf:r,numeric:s,results:[]}:null}_run(e,t){let n=this._request;n.clear_measures(),n.add_measure(e,t);let r=n.compute(0,!1),i=r.values(0),a=Zt(this._buffer(),i,this._errors),o=r.cell_count(),s=Array(o);for(let e=0;e<o;e++)s[e]=a(e);return i.free(),r.free(),s}},Ar={a0:0,a1:0,f0:!1,f1:!1},jr={a0:0,a1:0,f0:!1,f1:!1},Mr=0,Nr=0,Pr={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Fr={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Ir=[],Lr=[],Rr=[],zr=[],Br=[],Vr=[],Hr=(e,t)=>!0===t||e===-(2**53-1),Ur=(e,t)=>!0===t||e===2**53-1,Wr=(e,t,n,r,i,a,o)=>{if(n===i){if(t>r){let e=t;t=r,r=e}}else if(n?r+a<t:t+o>r)return!1;return e.a0=t,e.a1=r,e.f0=n,e.f1=i,!0},Gr=(e,t,n,r,i)=>(e.f0&&(t=Math.max(t,e.a0)),e.f1&&(n=Math.min(n,e.a1)),!(t>n)&&(Mr=Math.max(r,e.f1?r:t-e.a1),Nr=Math.min(i,e.f0?i:n-e.a0),Mr<=Nr)),Kr=(e,t,n)=>{Mr=Math.max(0,e.a0+(e.f0?0:t)),Nr=Math.max(0,e.a1+(e.f1?0:n))},qr=(e,t,n,r,i)=>{if(!Gr(Ar,t,r,i.rowStart,i.rowEnd))return;let a=Mr,o=Nr;Gr(jr,e,n,i.colStart,i.colEnd)&&Ir.push(Mr,a,Nr,o)},Jr=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}),Yr=e=>({touched:[Jr(e)],blank:[]});function Xr(e,t,n){let r=Ir;r.length=0;let i=Ar,a=jr,o=e.relative,s=e.second,c=o.length;for(let e=0;e<c;e++){let r=o[e];if(y.isError(r))continue;let c=s[e],l=c??r,u=r.scope??null,d=c===null?null:c.scope??null;if(u!==null&&d!==null&&u!==d)return Yr(t);let f=u??d;if(!Wr(i,r.rowStart,Hr(r.rowStart,r.$rowStart),l.rowEnd,Ur(l.rowEnd,l.$rowEnd),t.rowStart,t.rowEnd)||!Wr(a,r.colStart,Hr(r.colStart,r.$colStart),l.colEnd,Ur(l.colEnd,l.$colEnd),t.colStart,t.colEnd))return Yr(t);if(i.f0&&i.f1&&a.f0&&a.f1)continue;let p=n(f);if(p===null)return Yr(t);let m=Pr;Kr(i,t.rowStart,t.rowEnd),m.rowStart=Mr,m.rowEnd=Nr,Kr(a,t.colStart,t.colEnd),m.colStart=Mr,m.colEnd=Nr;let h=p.searchFormulas(m),g=h.length;for(let e=0;e<g;e++){let n=h[e];qr(Math.max(n.colStart,m.colStart),Math.max(n.rowStart,m.rowStart),Math.min(n.colEnd,m.colEnd),Math.min(n.rowEnd,m.rowEnd),t)}let _=p.values,b=_.getCoords();if(!b||!Gr(i,b.rowStart,b.rowEnd,t.rowStart,t.rowEnd))continue;let x=Mr,S=Nr;if(!Gr(a,b.colStart,b.colEnd,t.colStart,t.colEnd))continue;let C=Mr,w=Nr,T=Fr;if(Kr(i,x,S),T.rowStart=Math.max(Mr,b.rowStart),T.rowEnd=Math.min(Nr,b.rowEnd),Kr(a,C,w),T.colStart=Math.max(Mr,b.colStart),T.colEnd=Math.min(Nr,b.colEnd),T.colStart>T.colEnd||T.rowStart>T.rowEnd)continue;let E=(_.getAxis?.()??v.Axis.Row)===v.Axis.Column,D=_.getRuns({bounds:T}),O=D.next();for(;!O.done;){let[e,n,r]=O.value;O=D.next();let i=n+r.length-1;E?qr(e,n,e,i,t):qr(n,e,i,e,t)}}return function(e,t){let n=e.length/4;if(n===0)return{touched:[],blank:[Jr(t)]};let r=Lr;r.length=0;for(let e=0;e<n;e++)r.push(e);r.sort(Zr);let i=Rr;i.length=0,i.push(t.rowStart,t.rowEnd+1);for(let t=0;t<n;t++)i.push(e[4*t+1],e[4*t+3]+1);i.sort($r);let a=0;for(let e=0;e<i.length;e++)a!==0&&i[e]===i[a-1]||(i[a++]=i[e]);i.length=a;let o=[],s=[],c=zr;c.length=0;let l=0,u=Br,d=Vr,f=!1,p=0,m=0,h=a-1;for(let a=0;a<h;a++){let h=i[a],g=i[a+1]-1;for(;l<n&&e[4*r[l]+1]<=h;)c.push(r[l++]);let _=0;for(let t=0;t<c.length;t++)e[4*c[t]+3]>=h&&(c[_++]=c[t]);c.length=_,c.sort(Qr),u.length=0;for(let t=0;t<_;t++){let n=4*c[t],r=e[n],i=e[n+2],a=u.length-1;a>=0&&r<=u[a]+1?i>u[a]&&(u[a]=i):u.push(r,i)}if(f&&ei(d,u)){for(let e=p;e<o.length;e++)o[e].rowEnd=g;for(let e=m;e<s.length;e++)s[e].rowEnd=g;continue}p=o.length,m=s.length;let v=t.colStart;for(let e=0;e<u.length;e+=2){let t=u[e],n=u[e+1];t>v&&s.push({colStart:v,rowStart:h,colEnd:t-1,rowEnd:g}),o.push({colStart:t,rowStart:h,colEnd:n,rowEnd:g}),v=n+1}v<=t.colEnd&&s.push({colStart:v,rowStart:h,colEnd:t.colEnd,rowEnd:g});let y=d;d=u,u=y,f=!0}return Br=u,Vr=d,{touched:o,blank:s}}(r,t)}var Zr=(e,t)=>Ir[4*e+1]-Ir[4*t+1],Qr=(e,t)=>Ir[4*e]-Ir[4*t],$r=(e,t)=>e-t,ei=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},ti=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.rowStart!==i.rowStart||r.rowEnd!==i.rowEnd||r.colStart!==i.colStart||r.colEnd!==i.colEnd)return!1}return!0},ni=(e,t,n)=>{let r=n.length;n.push(e);for(let e=0;e<t.length&&n.length>r;e++){let i=t[e];for(let e=n.length-1;e>=r;e--){let t=n[e];if(i.rowStart>t.rowEnd||i.rowEnd<t.rowStart||i.colStart>t.colEnd||i.colEnd<t.colStart)continue;n.splice(e,1);let r=Math.max(t.rowStart,i.rowStart),a=Math.min(t.rowEnd,i.rowEnd);i.rowStart>t.rowStart&&n.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:i.rowStart-1}),i.rowEnd<t.rowEnd&&n.push({colStart:t.colStart,rowStart:i.rowEnd+1,colEnd:t.colEnd,rowEnd:t.rowEnd}),i.colStart>t.colStart&&n.push({colStart:t.colStart,rowStart:r,colEnd:i.colStart-1,rowEnd:a}),i.colEnd<t.colEnd&&n.push({colStart:i.colEnd+1,rowStart:r,colEnd:t.colEnd,rowEnd:a})}}};function ri(e,t,n=0,r=0){let i=t.ref;e.forEachNode(e=>{let a=e.ext,o=a===null?null:a.fixedRef;if(!o)return;let s=e.rowIndex+r,c=e.colIndex+n;if(s<i.rowStart||s>i.rowEnd||c<i.colStart||c>i.colEnd)return;let l=t.nodeAt(s,c);W(l).fixedRef=n===0&&r===0?o:{colStart:o.colStart+n,rowStart:o.rowStart+r,colEnd:o.colEnd+n,rowEnd:o.rowEnd+r}})}var ii={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},ai={colStart:0,rowStart:0,colEnd:0,rowEnd:0},oi={bounds:ai,reuseResult:!0},si=(e,t)=>e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex,ci=(e,t,n)=>e===null||t===0&&n===0?e:{colStart:e.colStart+n,rowStart:e.rowStart+t,colEnd:e.colEnd+n,rowEnd:e.rowEnd+t},li={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},ui=null,di=null,fi={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},pi=e=>{let t=ui,n=e??di;if(n===null)return null;let r=t.getGrid(n);if(r===null)return null;let i=r.getShadowOf();if(i!==null&&i!==n){if(r=t.getGrid(i),r===null)return null;n=i}let a=t.getFormulas();return{values:r.getValues(),searchFormulas:e=>(fi.colStart=e.colStart,fi.rowStart=e.rowStart,fi.colEnd=e.colEnd,fi.rowEnd=e.rowEnd,fi.scope=n,a.search(fi))}},mi=Object.freeze({tokens:Object.freeze([]),isReferenceOnly:!1}),hi=class e{setBlankShared(e){this.blankShared=e,this._blankSharedAgainst=e}constructor(e,t,n,r,i,a){this._nodes=null,this._sparse=!1,this._anchor=null,this.registeredPrecedents=null,this.fromLoad=!1,this.calcOnLoad=!1,this.paramLength=0,this._scratch=null,this._scratchCoords=null,this._scratchRow=-1,this._scratchCol=-1,this._touched=null,this._touchedCycleId=-1,this._touchedMarkId=-1,this._touchedMintedCycleId=-1,this._touchedMintedMarkId=-1,this.representative=null,this.blankValue=void 0,this.blankCycleId=-1,this.blankMarkId=-1,this.blankShared=null,this._blankSharedAgainst=null,this.blankRefused=!1,this.blankPaged=!1,this.blankFallbackCycleId=-1,this.uncalculated=!1,this.positionRead=!1,this.ref=e,this.gridId=t,this._container=r,this.formula=n,this.unanchored=i;let o=t!==null&&!0===r.getGrid(t)?.isArrayFirstCell();this.arrayFirstCell=o,o&&n!==null&&n.demandFirstCell();let s=n?n.getPrecedentTemplate():null;this._template=s;let c=n!==null&&s!==null&&n.isBlankCacheable(o)&&(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1)>64;this._sparse=c,this.calcs=null,c?this.paramLength=s.relative.length:a||(this.paramLength=s===null?n?.resolvedPrecedentsAt(e.rowStart,e.colStart)?.length??0:s.relative.length),a&&this._adopt(a,!0)}getNodeSource(){return[{block:this,originRow:0,originCol:0}]}isSparse(){return this._sparse}getAnchorNode(){let e=this._anchor;if(e!==null)return e;let t=this.ref,n=t.rowStart,r=t.colStart;if(this._sparse){let t=this._nodes??this._newSparseStore();e=t.getValueAt(n,r)??null,e===null&&(e=this._newNode(n,r,this.gridId,null),t.setValueAt(n,r,e))}else e=this.calcs===null?this._newNode(n,r,this.gridId,this._freshPrecedents(n,r)):this.calcs[0][0];return this._anchor=e,e}nodeAtOrNull(e,t){let n=this.ref;if(e<n.rowStart||e>n.rowEnd||t<n.colStart||t>n.colEnd)return null;let r=this._nodes;if(r!==null)return r.getValueAt(e,t)??null;let i=this.calcs;if(i!==null)return i[e-n.rowStart][t-n.colStart];let a=this._anchor;return a!==null&&a.rowIndex===e&&a.colIndex===t?a:null}nodeAt(e,t){let n=this.ref;if(e===n.rowStart&&t===n.colStart)return this.getAnchorNode();if(!this._sparse)return(this.calcs??this._mintDense())[e-n.rowStart][t-n.colStart];let r=this._nodes??this._newSparseStore(),i=r.getValueAt(e,t);return i===void 0&&(i=this._newNode(e,t,this.gridId,null),r.setValueAt(e,t,i)),i}_newSparseStore(){let e=new D({axis:v.Axis.Column}),t=this._anchor;return t!==null&&e.setValueAt(t.rowIndex,t.colIndex,t),this._nodes=e,e}_mintDense(){let e=this._createCalcs(this.formula,this.gridId,this.ref),t=this._anchor;return t===null?this._anchor=e[0][0]:e[0][0]=t,this.calcs=e,e}_freshPrecedents(e,n){if(this._template!==null)return null;let r=this.formula;return r===null||this.paramLength===0?t.EmptyArray:r.resolvedPrecedentsAt(e,n)}refreshPrecedents(){if(this._template!==null)return;let e=this.ref;this.paramLength=this.formula?.resolvedPrecedentsAt(e.rowStart,e.colStart)?.length??0,this.forEachNode(e=>{e.precedents=this._freshPrecedents(e.rowIndex,e.colIndex)})}release(){let e=this._anchor;e!==null&&e.block!==this&&(this._anchor=this._copyNode(e,this.ref.rowStart,this.ref.colStart)),this.calcs=null,this._nodes=null,this.representative=null,this._touchedMintedCycleId=-1,this._touchedMintedMarkId=-1}forEachNodeIn(e,t,n,r,i){let a=this.ref,o=Math.max(e,a.rowStart),s=Math.min(t,a.rowEnd);if(o>s)return;let c=Math.max(n,a.colStart),l=Math.min(r,a.colEnd);if(c>l)return;let u=this._nodes;if(u===null){let e=this.calcs;if(e===null){let e=this._anchor;e!==null&&e.rowIndex>=o&&e.rowIndex<=s&&e.colIndex>=c&&e.colIndex<=l&&i(e);return}let t=a.rowStart,n=a.colStart;for(let r=o;r<=s;r++){let a=e[r-t];for(let e=c;e<=l;e++)i(a[e-n])}return}if(o===s&&c===l){let e=u.getValueAt(o,c);e!==void 0&&i(e);return}ai.rowStart=o,ai.rowEnd=s,ai.colStart=c,ai.colEnd=l;let d=u.entries(oi),f=d.next();for(;!f.done;){let e=f.value[1];f=d.next(),i(e)}}mintNodesIn(e,t,n,r,i){if(this._sparse){let i=this._nodes??this._newSparseStore(),a=this.ref,o=Math.max(e,a.rowStart),s=Math.min(t,a.rowEnd),c=Math.max(n,a.colStart),l=Math.min(r,a.colEnd);if(o>s||c>l)return;let u=this.gridId,d=null;for(let e=c;e<=l;e++)for(let t=o;t<=s;t++)i.getValueAt(t,e)===void 0&&(d===null&&(d=new Lt.Builder),d.pushAt(e,t,this._newNode(t,e,u,null)));if(d!==null){let e=d.build();e&&i.setValues(e.tuples)}}else this.calcs===null&&this._mintDense();this.forEachNodeIn(e,t,n,r,i)}forEachNode(e){let t=this.ref;this.forEachNodeIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,e)}getPrecedentsAt(e,t){let n=this._template,r=this._scratchCoords,i=this._scratch;if(r===null||i===null){let e=n.relative.length;r=Array(e),i=Array(e);for(let t=0;t<e;t++){let e={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null};n.verticalAbs[t]&&(e.$rowStart=e.$rowEnd=!0),n.horizontalAbs[t]&&(e.$colStart=e.$colEnd=!0),r[t]=e}this._scratchCoords=r,this._scratch=i}else if(this._scratchRow===e&&this._scratchCol===t)return i;let a=n.relative,o=n.second,s=a.length;for(let n=0;n<s;n++){let s=a[n];if(y.isError(s)){i[n]=s;continue}let c=r[n],l=o[n];if(l===null){zn(s,e,t,c),i[n]=c;continue}zn(s,e,t,ii),zn(l,e,t,li);let u=xt(ii,li,c);i[n]=u??y.BuiltIn.Null}return this._scratchRow=e,this._scratchCol=t,i}isBlankAware(e){if(this.blankRefused||this.blankFallbackCycleId===e||this._template===null)return!1;let t=this.ref;if(t.rowEnd===t.rowStart&&t.colEnd===t.colStart)return!1;let n=this.formula;if(n===null||!n.isBlankCacheable(this.arrayFirstCell))return!1;let r=this.getAnchorNode().ext;return r===null||r.fixedRef===null}getTouched(e,t){let n=this._touched;if(n!==null&&this._touchedCycleId===e&&this._touchedMarkId===t)return n;ui=this._container,di=this.gridId;try{n=Xr(this._template,this.ref,pi)}finally{ui=null,di=null}this._touched=n,this._touchedCycleId=e,this._touchedMarkId=t;let r=this.blankShared;if(r!==null&&!ti(this._blankSharedAgainst,n.blank)){let e=[];for(let t=0;t<r.length;t++)ni(r[t],n.touched,e);this.blankShared=e,this._blankSharedAgainst=n.blank}let i=n.blank;if(i.length===0||this.blankPaged)this.representative=null;else{let e=i[0];this.representative=this.nodeAt(e.rowStart,e.colStart)}return n}forEachTouchedNode(e,t,n){let r=this.getTouched(e,t),i=this._touchedMintedCycleId===e&&this._touchedMintedMarkId===t,a=r.touched;for(let e=0;e<a.length;e++){let t=a[e];i?this.forEachNodeIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,n):this.mintNodesIn(t.rowStart,t.rowEnd,t.colStart,t.colEnd,n)}this._touchedMintedCycleId=e,this._touchedMintedMarkId=t;let o=this.representative;o!==null&&n(o)}getTouchedCached(){return this._touched}getBlankRegion(){let e=this._touched;return this.blankRefused||e===null||e.blank.length===0?null:this.blankPaged?{value:void 0,rects:e.blank,paged:!0}:this.blankCycleId===-1?null:{value:this.blankValue,rects:e.blank}}getDemandedBlank(){let e=this._touched,t=[];if(e===null)return t;let n=this._container.getGrid(this.gridId)?.getDemanded()??null;if(!n||n.length===0)return t;let r=e.blank;for(let e=0;e<r.length;e++){let i=r[e];for(let e=0;e<n.length;e++){let r=n[e],a=Math.max(i.rowStart,r.rowStart),o=Math.min(i.rowEnd,r.rowEnd),s=Math.max(i.colStart,r.colStart),c=Math.min(i.colEnd,r.colEnd);a<=o&&s<=c&&t.push({colStart:s,rowStart:a,colEnd:c,rowEnd:o})}}return t}getBlankValueWithin(e){let t=this.getBlankRegion();if(t===null||t.paged)return null;let n=this.ref;return e.rowStart<n.rowStart||e.rowEnd>n.rowEnd||e.colStart<n.colStart||e.colEnd>n.colEnd?null:t.value??null}densify(){if(!this._sparse||(this._sparse=!1,this._nodes===null))return;let e=this.ref,t=e.rowStart,n=e.colStart,r=e.rowEnd-t+1,i=e.colEnd-n+1,a=C(r);for(let e=0;e<r;e++)a[e]=C(i);this.forEachNode(e=>{a[e.rowIndex-t][e.colIndex-n]=e});let o=this.gridId;for(let e=0;e<r;e++){let r=a[e];for(let a=0;a<i;a++)r[a]===null&&(r[a]=this._newNode(e+t,a+n,o,null))}this.calcs=a,this._nodes=null}_createCalcs(e,n,r){let i=r.colStart,a=r.rowStart;if(!e)return[[this._newNode(a,i,n,t.EmptyArray)]];let o=this._template,s=o!==null,c=s?null:e.resolvedPrecedentsAt(a,i),l=s?o.relative.length:c?.length??0;this.paramLength=l;let u=C(r.rowEnd-a+1),d=r.colEnd-i+1,f=u.length;for(let r=0;r<f;r++){let o=C(d),f=o.length;for(let u=0;u<f;u++){let d=r+a,f=u+i,p=s?null:l===0?t.EmptyArray:r===0&&u===0?c:e.resolvedPrecedentsAt(d,f);o[u]=this._newNode(d,f,n,p)}u[r]=o}return u}_newNode(e,n,r,i){return{block:this,gridId:r,colIndex:n,rowIndex:e,cycleId:0,markId:0,inDegree:0,orderIndex:-1,planId:0,planEpoch:0,dependentsEpoch:0,dependents:t.EmptyArray,inputsAt:-1,precedents:i,cachedValue:void 0,numFmt:null,state:Qn,ext:null}}_takePrecedents(e,n,r){if(this._template!==null)return null;if(this.paramLength===0)return t.EmptyArray;let i=this.ref;return e===i.rowStart&&n===i.colStart&&r?r:this.formula.resolvedPrecedentsAt(e,n)}_adopt(e,t){let n=this.ref;if(this._sparse)this._takeSparse(e),this._anchor=this._nodes?.getValueAt(n.rowStart,n.colStart)??null;else{let t=this._takeDense(e);this.calcs=t,this._anchor=t[0][0]}for(let n=0;n<e.length;n++){let r=e[n].block;r.uncalculated&&(this.uncalculated=!0),r.positionRead&&(this.positionRead=!0),t&&r.release()}}_adoptNode(e,n,r,i){let a=e.ext;return a!==null&&(a.spillDependents=t.EmptyArray,a.spillRowEnd=-1,a.spillColEnd=-1,a.fixedRef=ci(a.fixedRef,n-e.rowIndex,r-e.colIndex)),e.block=this,e.gridId=this.gridId,e.rowIndex=n,e.colIndex=r,e.inputsAt=-1,e.precedents=i,e.orderIndex=-1,e.planId=0,e.planEpoch=0,e.dependentsEpoch=0,e.dependents=t.EmptyArray,e}_copyNode(e,n,r){let i={...e};i.block=this,i.gridId=this.gridId,i.rowIndex=n,i.colIndex=r,i.inputsAt=-1,i.precedents=this._freshPrecedents(n,r),i.orderIndex=-1,i.planId=0,i.planEpoch=0,i.dependentsEpoch=0,i.dependents=t.EmptyArray;let a=e.ext;return a!==null&&(i.ext={spillDependents:t.EmptyArray,spillRowStart:-1,spillColStart:-1,spillRowEnd:-1,spillColEnd:-1,fixedRef:ci(a.fixedRef,n-e.rowIndex,r-e.colIndex),demandValue:a.demandValue,cycleGroup:a.cycleGroup,cycleNext:a.cycleNext,shownGroup:a.shownGroup}),i}_sourceNodeAt(e,t,n){for(let r=0;r<e.length;r++){let i=e[r],a=i.block.ref,o=i.block.nodeAtOrNull(a.rowStart+i.originRow+t,a.colStart+i.originCol+n);if(o!==null)return o}return null}_takeDense(e){let t=this.formula,n=this.ref,r=n.rowStart,i=n.colStart,a=this._template!==null,o=a?null:t.resolvedPrecedentsAt(r,i);this.paramLength=a?this._template.relative.length:o?.length??0;let s=n.rowEnd-r+1,c=n.colEnd-i+1,l=null;if(e.length===1){let t=e[0],n=t.block.ref,r=t.block.calcs;if(r!==null&&r.length===n.rowEnd-n.rowStart+1){let e=t.originRow,i=t.originCol;if(i===0&&n.colEnd-n.colStart+1===c)l=e===0&&r.length===s?r:r.slice(e,e+s);else{l=C(s);for(let t=0;t<s;t++)l[t]=r[t+e].slice(i,i+c)}}}if(l!==null){for(let e=0;e<s;e++){let t=l[e],n=e+r;for(let e=0;e<c;e++){let r=e+i;this._adoptNode(t[e],n,r,this._takePrecedents(n,r,o))}}return l}let u=this.gridId,d=C(s);for(let t=0;t<s;t++){let n=C(c);d[t]=n;let a=t+r;for(let r=0;r<c;r++){let s=r+i,c=this._takePrecedents(a,s,o),l=this._sourceNodeAt(e,t,r);n[r]=l===null?this._newNode(a,s,u,c):this._adoptNode(l,a,s,c)}}return d}_takeSparse(e){let t=this.ref,n=t.rowStart,r=t.colStart,i=t.rowEnd-n+1,a=t.colEnd-r+1,o=e.length===1?e[0]:null;if(o!==null&&o.block.calcs===null){let e=o.block,s=e.ref,c=e._nodes;if(c!==null&&o.originRow===0&&o.originCol===0&&s.rowStart===n&&s.colStart===r&&s.rowEnd===t.rowEnd&&s.colEnd===t.colEnd)return e._nodes=null,this._nodes=c,void this.forEachNode(e=>{this._adoptNode(e,e.rowIndex,e.colIndex,null)});let l=s.rowStart+o.originRow,u=s.colStart+o.originCol,d=n-l,f=r-u,p=new Lt.Builder;e.forEachNodeIn(l,l+i-1,u,u+a-1,e=>{let t=e.rowIndex+d,n=e.colIndex+f;this._adoptNode(e,t,n,null),p.pushAt(n,t,e)});let m=p.build();m&&(this._nodes??this._newSparseStore()).setValues(m.tuples);return}let s=[];for(let t=0;t<e.length;t++){let o=e[t],c=o.block.ref,l=n-c.rowStart-o.originRow,u=r-c.colStart-o.originCol;o.block.forEachNode(e=>{let t=e.rowIndex+l,o=e.colIndex+u,c=t-n,d=o-r;c<0||c>=i||d<0||d>=a||s.push(this._adoptNode(e,t,o,null))})}if(s.length===0)return;s.sort(si);let c=new Lt.Builder;for(let e=0;e<s.length;e++){let t=s[e];e>0&&s[e-1].rowIndex===t.rowIndex&&s[e-1].colIndex===t.colIndex||c.pushAt(t.colIndex,t.rowIndex,t)}let l=c.build();l&&(this._nodes??this._newSparseStore()).setValues(l.tuples)}toJSON(e=!1,t=this.ref){let n=t;return[tt(n),this.formula.getTextAt(n.rowStart,n.colStart,e)]}getCoords(){return this.ref}getShifted(t){if(!t.after)return null;let n=o.sanitizeRange(t.after),r=t.axis!==v.Axis.Row,i=t.amount,a=t.intersect,s=a.colStart,c=a.rowStart,l=a.colEnd,u=a.rowEnd,d=r?i:0,f=r?0:i,p=this.ref,m=n,h=this._container.getGrid(this.gridId)?.getEntireCoords(),g=this.formula,_=g.getReferences(p.rowStart,p.colStart);for(let e=0;e<_.length;e++){let t=_[e];if(t===null||`nameId`in t||`tableId`in t||y.isError(t))continue;let n=t,a=n.scope!=null&&n.scope!==this.gridId,o=n.colStart===-(2**53-1),v=n.rowStart===-(2**53-1),b=n,x=n.$colStart?n.colStart:p.colStart+n.colStart,S=n.$rowStart?n.rowStart:p.rowStart+n.rowStart;if(!a&&x>l&&!n.$colStart&&!n.$colEnd)continue;let C=n.$colEnd?n.colEnd:p.colStart+n.colEnd,w=n.$rowEnd?n.rowEnd:p.rowStart+n.rowEnd;if(a)d===0||o||(n.$colStart||(b={...n},b.colStart=x-m.colStart),n.$colEnd||(b=b===n?{...n}:b,b.colEnd=C-m.colStart)),f===0||v||(n.$rowStart||(b=b===n?{...n}:b,b.rowStart=S-m.rowStart),n.$rowEnd||(b=b===n?{...n}:b,b.rowEnd=w-m.rowStart)),b!==n&&(g=g.setReferenceAt(e,b));else{if(i<0){if(r){if(x>=s&&C<=l){g=g.setReferenceAt(e,null);continue}}else if(S>=c&&w<=u){g=g.setReferenceAt(e,null);continue}}d===0||o||(n.$colStart?x>=s&&(b=b===n?{...n}:b,b.colStart+=d,x=b.colStart):x<s?(b=b===n?{...n}:b,b.colStart=x-m.colStart,x=m.colStart+b.colStart):d<0&&x<=l&&(b=b===n?{...n}:b,x=Math.max(s,x+d),b.colStart=x-m.colStart,x=m.colStart+b.colStart),n.$colEnd?C>=s&&(b=b===n?{...n}:b,b.colEnd+=d,C=b.colEnd):C<s?(b=b===n?{...n}:b,b.colEnd=C-m.colStart,C=m.colStart+b.colEnd):d<0&&C<=l&&(b=b===n?{...n}:b,C=Math.max(s-1,C+d),b.colEnd=C-m.colStart,C=m.colStart+b.colEnd)),f===0||v||(n.$rowStart?S>=c&&(b=b===n?{...n}:b,b.rowStart+=f,S=b.rowStart):S<c?(b=b===n?{...n}:b,b.rowStart=S-m.rowStart,S=m.rowStart+b.rowStart):f<0&&S<=u&&(b=b===n?{...n}:b,S=Math.max(c,S+f),b.rowStart=S-m.rowStart,S=m.rowStart+b.rowStart),n.$rowEnd?w>=c&&(b=b===n?{...n}:b,b.rowEnd+=f,w=b.rowEnd):w<c?(b=b===n?{...n}:b,b.rowEnd=w-m.rowStart,w=m.rowStart+b.rowEnd):f<0&&w<=u&&(b=b===n?{...n}:b,w=Math.max(c-1,w+f),b.rowEnd=w-m.rowStart,w=m.rowStart+b.rowEnd)),b!==n&&((C<x||w<S||h&&(!o&&(x<h.colStart||C>h.colEnd)||!v&&(S<h.rowStart||w>h.rowEnd)))&&(b=y.BuiltIn.Ref),g=g.setReferenceAt(e,b))}}let b=new e(n,this.gridId,g,this._container,this.unanchored,this.getNodeSource());return{...t.after,value:b}}getMerged(t,n,r){let i=this.formula,a=t.formula;if(!i.isEquals(a))return;let o=this.ref,s=[{block:this,originRow:0,originCol:0},r===v.Axis.Row?{block:t,originRow:-(o.rowEnd-o.rowStart+1),originCol:0}:{block:t,originRow:0,originCol:-(o.colEnd-o.colStart+1)}];return new e(n,this.gridId,i,this._container,this.unanchored,s)}getSplit(t,n,r){let i=this.formula,a=n===v.Axis.Column,o=new e(t[0],this.gridId,i,this._container,this.unanchored),s=new e(t[1],this.gridId,i,this._container,this.unanchored);return o._adopt([{block:this,originRow:0,originCol:0}],!1),s._adopt([{block:this,originRow:a?0:r,originCol:a?r:0}],!1),this.release(),[o,s]}copyTo(t,n){let r=this.formula,i=n?.cutFrom;if(i){let e=this.ref,n=e.colStart-t.colStart,a=e.rowStart-t.rowStart,o=r.getReferences(e.rowStart,e.colStart);for(let t=0;t<o.length;t++){let s=o?o[t]:null;if(!s||`nameId`in s||y.isError(s))continue;let c=s,l,u=c.$colStart?c.colStart:e.colStart+c.colStart,d=c.$rowStart?c.rowStart:e.rowStart+c.rowStart,f=c.$colEnd?c.colEnd:e.colEnd+c.colEnd,p=c.$rowEnd?c.rowEnd:e.rowEnd+c.rowEnd,m=c.scope!=null&&c.scope!==this.gridId,h=!m&&d>=i.rowStart&&p<=i.rowEnd,g=!m&&u>=i.colStart&&f<=i.colEnd;n!==0&&(c.$colStart||h&&u>=i.colStart&&u<=i.colEnd||(l??={...c},l.colStart+=n),c.$colEnd||h&&f>=i.colStart&&f<=i.colEnd||(l??={...c},l.colEnd+=n)),a!==0&&(c.$rowStart||g&&d>=i.rowStart&&d<=i.rowEnd||(l??={...c},l.rowStart+=a),c.$rowEnd||g&&p>=i.rowStart&&p<=i.rowEnd||(l??={...c},l.rowEnd+=a)),l&&(r=r.setReferenceAt(t,l))}}let a=new e(t,this.gridId,r,this._container,this.unanchored);return ri(this,a,t.colStart-this.ref.colStart,t.rowStart-this.ref.rowStart),{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:t.scope,value:a}}canTile(e,t){return!0}onRemove(e){e.value.release()}evaluateAt(e,t,n){return this.formula?.evaluateAt(e,t,n)??y.BuiltIn.NA}finalizeValue(e){return this.formula?.finalizeValue(e)??e}finalizeValueForCell(e){return this.formula?.finalizeValueForCell(e)??e}getTokensAt(e,n,r){return this.formula?.getTokensAt(e,n,r)??t.EmptyArray}getTextAt(e,t,n,r,i){return this.formula?.getTextAt(e,t,n,r,i)??``}getNode(){return this.formula?.getNode()??null}resolvedPrecedentsAt(e,n,r,i,a){return this.formula?.resolvedPrecedentsAt(e,n,r,i,a)??t.EmptyArray}getPrecedentTemplate(){return this._template}getReferences(e,n){return this.formula?.getReferences(e,n)??t.EmptyArray}getReferencesAt(e,n){return this.formula?.getReferencesAt(e,n)??t.EmptyArray}getFormatReferences(){return this.formula?.getFormatReferences()??t.EmptyArray}getReferenceAt(e,t,n){return this.formula?.getReferenceAt(e,t,n)??null}setReferenceAt(t,n,r){let i=this.ref;if(n&&!y.isError(n)&&!(`nameId`in n)){let e=n,t=i.colStart,r=i.rowStart,a=e.$colStart?e.colStart:t+e.colStart,o=e.$rowStart?e.rowStart:r+e.rowStart,s=e.$colEnd?e.colEnd:t+e.colEnd,c=e.$rowEnd?e.rowEnd:r+e.rowEnd;if(s<a||c<o)n=null;else{let t=this._container.getGrid(this.gridId)?.getEntireCoords(),r=e.colStart===-(2**53-1),i=e.rowStart===-(2**53-1);t&&(!r&&(a<t.colStart||s>t.colEnd)||!i&&(o<t.rowStart||c>t.rowEnd))&&(n=null)}}let a=this.formula.setReferenceAt(t,n,r);return new e(i,this.gridId,a,this._container,this.unanchored,this.getNodeSource())}remint(){return new e(this.ref,this.gridId,this.formula,this._container,this.unanchored,this.getNodeSource())}reanchorReferences(t,n){let r=this.formula,i=r.reanchorReferences(t,n);return r===i&&this.gridId===t?this:new e(this.ref,t,i,this._container,this.unanchored,this.getNodeSource())}replaceScopeIds(t,n){let r=this.formula,i=r.replaceScopeIds(t,n);return r===i?this:new e(this.ref,this.gridId,i,this._container,this.unanchored,this.getNodeSource())}wrapImplicit(t,n,r){let i=this.formula,a=i.wrapImplicit(t,n,r);return i===a?this:new e(this.ref,this.gridId,a,this._container,this.unanchored,this.getNodeSource())}getError(){return this.formula?.getError()??null}getRecord(){return this.formula?.getRecord()??mi}getNamedIds(){return this.formula?.getNamedIds()??t.EmptyArray}getReferencedSymbolIds(){return this.formula?.getReferencedSymbolIds()??t.EmptyArray}hasTotals(){return this.formula?.hasTotals()??!1}hasPivotData(){return this.formula?.hasPivotData()??!1}hasDataTable(){return this.formula?.hasDataTable()??!1}hasVolatile(){return this.formula?.hasVolatile()??!1}isBlankCacheable(e=this.arrayFirstCell){return this.formula?.isBlankCacheable(e)??!1}demandFirstCell(){this.formula?.demandFirstCell()}getPositionVariants(){return this.formula?.getPositionVariants()??null}isReferenceOnly(){return this.formula?.isReferenceOnly()??!1}isEquals(e){return this.formula?.isEquals(e)??!1}},gi=-1,_i=-2,vi=class{constructor(e,t,n,r,i,a,o,s){this._cursor=-1,this._onRead=e,this._gridId=t,this._rowStart=n,this._colStart=r,this._rowEnd=i,this._colEnd=a,this._byColumn=o,this._reverse=s;let c=i-n+1,l=a-r+1;this._minorCount=o?c:l,this._total=c*l}reach(e,t){if(e<this._rowStart||e>this._rowEnd||t<this._colStart||t>this._colEnd)return void this._onRead(this._gridId,e,t,e,t);let n=this._byColumn?(t-this._colStart)*this._minorCount+(e-this._rowStart):(e-this._rowStart)*this._minorCount+(t-this._colStart);this._advance(this._reverse?this._total-1-n:n)}clampMinor(e){let t=this._byColumn?this._rowStart:this._colStart,n=this._byColumn?this._rowEnd:this._colEnd;return e<t?t:e>n?n:e}finish(){this._advance(this._total-1)}_advance(e){let t=this._cursor+1;if(e<t)return;this._cursor=e;let n=this._reverse?this._total-1-e:t,r=this._reverse?this._total-1-t:e,i=this._minorCount,a=Math.floor(n/i),o=n-a*i,s=Math.floor(r/i),c=r-s*i;a===s?this._report(a,o,a,c):(this._report(a,o,a,i-1),s-a>1&&this._report(a+1,0,s-1,i-1),this._report(s,0,s,c))}_report(e,t,n,r){this._byColumn?this._onRead(this._gridId,this._rowStart+t,this._colStart+e,this._rowStart+r,this._colStart+n):this._onRead(this._gridId,this._rowStart+e,this._colStart+t,this._rowStart+n,this._colStart+r)}},yi=class e{static{this.created=0}constructor(t,n,r){this.observesReads=!0,this._inner=t,this._gridId=n,this._onRead=r,e.created++}getInner(){return this._inner}_resolveBounds(e){let t=this._inner,n=e?.rowStart,r=e?.colStart,i=e?.rowEnd,a=e?.colEnd;if(n===void 0||r===void 0||i===void 0||a===void 0||n===-(2**53-1)||r===-(2**53-1)||i===2**53-1||a===2**53-1){let e=t.getMaxCoords?.()??t.getCoords();if(!e)return null;n!==void 0&&n!==-(2**53-1)||(n=e.rowStart),r!==void 0&&r!==-(2**53-1)||(r=e.colStart),i!==void 0&&i!==2**53-1||(i=e.rowEnd),a!==void 0&&a!==2**53-1||(a=e.colEnd)}return{rowStart:n,colStart:r,rowEnd:i,colEnd:a}}_reportBounds(e){let t=this._resolveBounds(e);t!==null&&this._onRead(this._gridId,t.rowStart,t.colStart,t.rowEnd,t.colEnd)}_openSweep(e,t,n){let r=this._resolveBounds(e);return r===null?null:this._onRead(this._gridId,r.rowStart,r.colStart,r.rowEnd,r.colEnd,!0)?new vi(this._onRead,this._gridId,r.rowStart,r.colStart,r.rowEnd,r.colEnd,(t??this._inner.getAxis?.())===v.Axis.Column,!0===n):null}getValueAt(e,t){return this._onRead(this._gridId,e,t,e,t),this._inner.getValueAt(e,t)}getRuns(e){let t=this._openSweep(e?.bounds,void 0,!1),n=this._inner.getRuns(e);if(t===null)return n;let r=this._inner.getAxis?.()===v.Axis.Column,i={[Symbol.iterator]:()=>i,next:()=>{let e=n.next();if(e.done)return t.finish(),e;let[i,a,o]=e.value,s=t.clampMinor(a+o.length-1);return r?t.reach(s,i):t.reach(i,s),e},return:e=>n.return?n.return(e):{done:!0,value:e}};return i}entries(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse),n=this._inner.entries(e);if(t===null)return n;let r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);if(r.done)return t.finish(),r;let i=r.value[0];return t.reach(i.rowIndex,i.colIndex),r},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}values(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse);if(t===null)return this._inner.values(e);let n=this._inner.entries(e),r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);if(r.done)return t.finish(),{done:!0,value:void 0};let i=r.value[0];return t.reach(i.rowIndex,i.colIndex),{done:!1,value:r.value[1]}},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}keys(e){let t=this._openSweep(e?.bounds,e?.axis,e?.reverse),n=this._inner.keys(e);if(t===null)return n;let r={[Symbol.iterator]:()=>r,next:e=>{let r=n.next(e);return r.done?(t.finish(),r):(t.reach(r.value.rowIndex,r.value.colIndex),r)},return:e=>n.return?n.return(e):{done:!0,value:e}};return r}getValues(e){return this._reportBounds(e),this._inner.getValues(e)}copyTo(e,t,n){this._reportBounds(n),this._inner.copyTo(e,t,n)}getAxis(){return this._inner.getAxis()}getCount(){return this._inner.getCount()}getCoords(){return this._inner.getCoords()}getMaxCoords(){return this._inner.getMaxCoords?.()??null}clone(e){return this._inner.clone(e)}cloneEmpty(e){return this._inner.cloneEmpty(e)}setValues(e){return this._inner.setValues(e),this}setValueAt(e,t,n){this._inner.setValueAt(e,t,n)}delete(e){return this._inner.delete?.(e)??!1}clear(){this._inner.clear?.()}shift(e,t){return this._inner.shift?.(e,t)??!1}get[Symbol.toStringTag](){return`[ReadObservedGrid]`}},bi=2**53,xi=(e,t)=>!0===e?.isPendingOverlay||!0===e?.isWhatIfLayer?e:t??null,Si=class n{constructor(e,t=v.Axis.Column,n){this._passSeed=0,this._passCycleId=-1,this._gridKey=0,this._gridKeyId=null,this._onRead=null,this._dynamicRead=null,this._createSparseColumn=(e,t,n,r)=>{if(e===0)return this.createRange();let i=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),a=i&&e>i.rowEnd+1?{...i,rowEnd:e-1}:i,o=new D({axis:this._axis,maxCoords:a});for(let e=0;e<r;e++)o.setValueAt(t[e],0,n[e]);return new Ve(this._runtime,o,{colStart:0,rowStart:0,colEnd:0,rowEnd:e-1})},this._container=e,this._axis=t,this._functionProviders=n,this._positionRead=()=>{this._calcScope.positionRead=!0}}_setInstanceScope(e){this._instanceScope=e}_setReadHook(e){this._onRead=e}_setDynamicReadHook(e){this._dynamicRead=e}_takeReadHooks(){let e=[this._onRead,this._dynamicRead];return this._onRead=null,this._dynamicRead=null,e}_restoreReadHooks(e){this._onRead=e[0],this._dynamicRead=e[1]}_gridIdOfReference(e){return e?this._gridIdOf(e):this._calcScope.gridId}_evaluateWhatIf(e){return this._calcScope.node?this._container.evaluateWhatIf(e):null}async _initialize(t){let n=await nt.assertUsable(`calcs`,0),r=this._container,i=r.getRuntime();this._runtime=new Jt(`Calculation Runtime`,{isDate1904:()=>i.isDate1904(),isR1C1:()=>i.isR1C1(),getNow:()=>r.getNow(),getRandom:()=>i.getRandom(),getLocale:()=>i.getLocale()},n),this._calcScope=r.getScope(),this._coerceToNumber=Re(this._runtime,S.Number,te);let{initializeFunctions:a}=await e(async()=>{let{initializeFunctions:e}=await import(`./BVnzv_sY_58zEJyM.js`);return{initializeFunctions:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13]),import.meta.url),o=this,s=Object.freeze(a(()=>o,this._functionProviders)),c=new yt({transactions:t??new l({transient:!0}),context:this,readonlyFunctions:s,createScopedContext:e=>o._createScoped(e)});return this._functions=c,{functions:c}}_createScoped(e){let t=this._container,r=t.getSymbols().bind(U.Sheet,e);if(!r||!t.getGrid(r))return null;let i=new n(t,this._axis,this._functionProviders);return i._runtime=this._runtime,i._functions=this._functions,i._coerceToNumber=this._coerceToNumber,i._instanceScope=this._instanceScope,i._calcScope={gridId:r,rowIndex:0,colIndex:0,node:null,depth:0,activeNames:new Set,implicitIntersect:!1,firstCell:!1,perCellRead:!1,positionRead:!1,drawIndex:0,deferCount:0,deferOrdinal:0,deferRoot:!1,deferServed:null},i}_createCellFree(){let e=new ki(this._container,this._axis,this._functionProviders);return e._runtime=this._runtime,e._functions=this._functions,e._coerceToNumber=this._coerceToNumber,e._instanceScope=this._instanceScope,e._calcScope={gridId:null,rowIndex:0,colIndex:0,node:null,depth:0,activeNames:new Set,implicitIntersect:!1,firstCell:!1,perCellRead:!1,positionRead:!1,drawIndex:0,deferCount:0,deferOrdinal:0,deferRoot:!1,deferServed:null},e}getFunction(e){let t=st(e);if(t!==void 0){let e=this._functions.getByName(t);if(e&&!e.isLambda())return e}let n=this._functions.getByName(e);return n?.isLambda()?null:n}_getFunctionStamp(){return this._functions._getStamp()}getNumberFormat(e,t){return f.getEngine().format(e,t,{date1904:this.getRuntime().isDate1904(),locale:this.getRuntime().getLocale()}).text}getEntireCoords(){return this._container.getGrid(this._calcScope.gridId)?.getEntireCoords()}getFormulaAt(e,t,n){let r=this._container,i;if(this._calcScope.perCellRead=!0,i=n?r.getSymbols().bind(U.Sheet,n):this._calcScope.gridId,!i)return null;let a=r.getFormulas();if(!a)return null;Ti.colStart=t,Ti.rowStart=e,Ti.colEnd=t,Ti.rowEnd=e,Ti.scope=i;let o=a.search(Ti);return o.length===0?null:o[0].value.formula.getTextAt(e,t,!1,void 0,void 0,`display`)??null}_markVolatile(){let e=this._container.getVolatiles();if(!e)return;let t=this._calcScope.node;e.add(t),t.state|=nr}defer(e,t){if(typeof e!=`function`)throw new y.Value(`defer needs an executor function`);let n=this._container.getDeferred?.();if(n)return Ot(n.defer(e,t,ke(),It())),n.previous;Ot(null)}formatResults(e){let t=this._calcScope.node;t&&(t.numFmt=e)}filterHidden(e,t){if(!(e?.isIReferenceRange&&e instanceof lt))return e;let n=e.getCoords(),r=this._gridIdOf(n),i=r?this._container.getGrid(r):null;if(!i||t?.onlyWhileFiltered&&!i.isFiltered())return e;let a=t?.axes,o=a===v.AxisSelection.Column?null:i.getHiddenSkip(v.Axis.Row,n.rowStart,n.rowEnd),s=a===v.AxisSelection.Column||a===v.AxisSelection.Both?i.getHiddenSkip(v.Axis.Column,n.colStart,n.colEnd):null;return o||s?e.clone({processRowSkip:o??void 0,processColumnSkip:s??void 0}):e}_gridIdOf(e){return e.scope?this._container.getSymbols().bind(U.Sheet,e.scope):this._calcScope.gridId}filterTotals(e){let t=e;if(!t?.isIReferenceRange)return e;let n=t.getCoords(),r=this._container.getFormulas();if(!r||r.isEmpty())return e;let i=r.search({rowStart:n.rowStart,rowEnd:n.rowEnd,colStart:n.colStart,colEnd:n.colEnd,scope:this._gridIdOf(n)}),a=null;for(let e=0;e<i.length;e++){let t=i[e].value;if(!t?.hasTotals())continue;let r=t.ref;(a??=[]).push({rowStart:r.rowStart-n.rowStart,rowEnd:r.rowEnd-n.rowStart,colStart:r.colStart-n.colStart,colEnd:r.colEnd-n.colStart})}if(!a)return e;let o=a.length;return e.filter((e,t)=>{let n=t.rowIndex,r=t.colIndex;for(let e=0;e<o;e++){let t=a[e];if(n>=t.rowStart&&n<=t.rowEnd&&r>=t.colStart&&r<=t.colEnd)return!1}return!0})}getSheetIndex(e){let t;if(this._calcScope.perCellRead=!0,typeof e==`string`)t=e;else{let n=e?.getCoords()?.scope;if(n)t=n;else{let e=this._container.getSymbols().resolve(U.Sheet,this._calcScope.gridId);t=e?e.getName?e.getName()??void 0:e.toString():void 0}}return this._container.getSheetIndex?.(t)??-1}getSheetCount(){return this._container.getSheetCount?.()??1}isValidDate(e,t=!1){return p(e,t)}fromSerialDate(e,t=!1){return m(t?Math.floor(e):e,this.getRuntime().isDate1904())}toSerialDate(e,t=!1){let n=g(e,this.getRuntime().isDate1904());return t?Math.floor(n):n}getDateParts(e,t){let n=u(e,this.getRuntime().isDate1904(),t);if(n===null)throw y.BuiltIn.Num;return n}getSerialDate(e,t,n,r=0,i=0,a=0,o=0){return d({year:e,month:t,day:n,hour:r,minute:i,second:a,millis:o,dow:-1,serial:0},this.getRuntime().isDate1904())}getNow(){return g(new Date(this.getRuntime().getNow()),this.getRuntime().isDate1904())}getRandom(){let e=this._calcScope;e.perCellRead=!0;let t=e.drawIndex++;if(t===0){let t=this._container.getCycleId();t!==this._passCycleId&&(this._passCycleId=t,this._passSeed=Math.floor(this.getRuntime().getRandom()*bi));let n=e.gridId;if(n!==this._gridKeyId){this._gridKeyId=n;let e=n===null?null:this._container.getSymbols().resolve(U.Sheet,n),t=e?.getName?e.getName():null;this._gridKey=t?r(t):0}}return i(this._passSeed,this._gridKey,e.rowIndex,e.colIndex,t)}compare(e,t,n){return Ze.compare(e,t,this.getRuntime().getLocaleProfile(),n)}_fromTuples(e,t=null,n=!1,r=!1){if(!e)return null;let i=ft(e.bounds,!0),a=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),o=new D({axis:this._axis,maxCoords:a});o.setValues(e.tuples);let s=t?{type:t}:void 0;return new Ve(this._runtime,o,i,s,n,r)}getValueAt(e,n,r=null,i){let a=this._container,o=this._calcScope,s,c;if(r){if(s=a.getSymbols().bind(U.Sheet,r),ye(s))return y.BuiltIn.Ref}else s=o.gridId;if(!s)return y.BuiltIn.Ref;let l=o.node,u=l?gn(l):t.EmptyArray,d=u.length;for(let t=0;t<d;t++){let r=u[t];if(!r||y.isError(r))continue;let a=r;if(e<a.rowStart||e>a.rowEnd||n<a.colStart||n>a.colEnd||a.scope&&s!==a.scope)continue;let o=Xn(l,t);if(o!==void 0){if(o!==null&&o.isIRange){let t=o,r=e-a.rowStart,s=n-a.colStart;r>=0&&s>=0&&r<t.getRowCount()&&s<t.getColumnCount()&&(c=t.getValueAt(r,s,i))}else c=o}break}return c===void 0&&(this._onRead?.(s,e,n,e,n),c=a.getGridValues(s)?.getValueAt(e,n)??null,a.getDeferred?.()?.hasHolders()&&(c=he(c))),i&&i.type,c}getSpillAt(e,t,n){let r=this._container,i=this._calcScope,a;a=n?r.getSymbols().bind(U.Sheet,n):i.gridId;let o=a===i.gridId?null:a,s=r.getIncrementalUpdates(a)?.spillSpatial??r.getGrid(a)?.getSpills();if(s){Ei.rowStart=e,Ei.colStart=t,Ei.rowEnd=e,Ei.colEnd=t,Ei.scope=a;let n=s.search(Ei),r=n.length;for(let i=0;i<r;i++){let r=n[i];if(r.value.isAnchor(e,t))return this.getReference({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:o})}if(r>0)return null}return this.getFormulaAt(e,t,n)===null?null:this.getReference({colStart:t,rowStart:e,colEnd:t,rowEnd:e,scope:o})}createRange(e=0,t=0,n=null){let r=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),i=r&&(e>r.rowEnd+1||t>r.colEnd+1)?{...r,rowEnd:Math.max(r.rowEnd,e-1),colEnd:Math.max(r.colEnd,t-1)}:r,a=new D({axis:this._axis,maxCoords:i}),o=new Ve(this._runtime,a,null,void 0,!1);return e>0&&t>0&&(typeof n==`function`?(o=o.resize(e,t),o=o.map(n,Oi)):Array.isArray(n)?(o=o.replace(n),o=o.resize(e,t)):o=n==null?o.resize(e,t):new Ve(this._runtime,a,{colStart:0,rowStart:0,colEnd:t-1,rowEnd:e-1},void 0,!1,!1,n)),o}flattenAreas(e){if(!Array.isArray(e))return e;let t=[];for(let n=0;n<e.length;n++){let r=e[n],{rows:i,columns:a}=r.getShape();for(let e=0;e<i;e++)for(let n=0;n<a;n++)t.push(r.getValueAt(e,n))}return this.createRange(t.length,1,(e,n)=>t[n.rowIndex])}getRange(e,t=null,n=!1){if(e===null)return null;if(e?.isIRange){if(t!==e.getType()||n!==e._isLiteralArray()){let r=typeof t==`string`?{type:t}:t;return e.clone(r,n,e._isDirectScalarBox())}return e}let r,i=Array.isArray(e);if(n??=i,!i&&e!==void 0){let r=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords();return new Ve(this._runtime,new On(e,{axis:this._axis,maxCoords:r}),{colStart:0,rowStart:0,colEnd:0,rowEnd:0},t?{type:t}:void 0,n,!0)}if(Array.isArray(e[0]))r=e;else{if(e[0]?.isIRange)throw y.BuiltIn.Value;r=[e]}let a=this._axis,s=a===v.Axis.Column,c=this._fromTuples(ee(r,s,se(0,0,void 0,void 0,s),!0),t,n,!i);if(c)return c;let l=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),u=new D({axis:a,maxCoords:l}),d=t?{type:t}:void 0;return new Ve(this._runtime,u,o.EmptyRange,d,n)}getRow(){let e=this._calcScope;return e.positionRead=!0,e.rowIndex}getColumn(){let e=this._calcScope;return e.positionRead=!0,e.colIndex}isImplicitIntersect(){let e=this._calcScope;return!e.node?.ext?.fixedRef&&!e.node?.block.arrayFirstCell&&e.implicitIntersect}_takeFirstCell(){let e=this._calcScope,t=e.firstCell;return e.firstCell=!1,t}getReference(e,t){if(!e)throw y.BuiltIn.Ref;let n=this._calcScope,r=this._container,i=n.gridId,a=r.getGrid(i),o=a?.getShadowOf();if(o&&o!==i){let e=r.getGrid(o);e&&(i=o,a=e)}let s=a?.getEntireCoords.bind(a);if(typeof e==`string`){let r=s?.(),i;try{let n=Fe(e,r,T,()=>{throw y.BuiltIn.Ref},t);if(n.length>1)throw y.BuiltIn.Ref;i=n[0]}catch{throw y.BuiltIn.Ref}if(t){let e=n.rowIndex,t=n.colIndex;if(i={rowStart:i.$rowStart?i.rowStart:i.rowStart+e,rowEnd:i.$rowEnd?i.rowEnd:i.rowEnd+e,colStart:i.$colStart?i.colStart:i.colStart+t,colEnd:i.$colEnd?i.colEnd:i.colEnd+t,scope:i.scope},i.rowStart<0||i.colStart<0||i.rowEnd<0||i.colEnd<0||r&&(i.rowEnd>r.rowEnd||i.colEnd>r.colEnd))throw y.BuiltIn.Ref}i.rowStart>i.rowEnd&&(i={...i,rowStart:i.rowEnd,rowEnd:i.rowStart}),i.colStart>i.colEnd&&(i={...i,colStart:i.colEnd,colEnd:i.colStart}),e=i}else e||={colStart:n.colIndex,rowStart:n.rowIndex,colEnd:n.colIndex,rowEnd:n.rowIndex};if(!e)throw y.BuiltIn.Ref;let c=e.scope;if(c){if(c=r.getSymbols().bind(U.Sheet,e.scope),!c)return y.BuiltIn.Ref;let t=r.getSheetSpanIds?.(c)??null;if(t){if(r.isGridless?.(t[0])||r.isGridless?.(t[t.length-1]))return y.BuiltIn.Name;let n=[];for(let r=0;r<t.length;r++)n.push(this.getReference(Ci(e,t[r])));return n.isSheetSpan=!0,n}if(c!==e.scope&&((e={...e}).scope=c),e.inSheetSpan){let t={rowStart:e.rowStart,colStart:e.colStart,rowEnd:e.rowEnd,colEnd:e.colEnd,scope:c};if(r.isGridless?.(c)){let e=new D({axis:this._axis});return this._toReference(e,t,void 0,c,!1,null)}e=t}if(c!==i){if(i=c,a=r.getGrid(i),!a)return y.BuiltIn.Ref;s=a?.getEntireCoords.bind(a)}}let l=r.getGridValues(i),u,d=n.node,f=-1;if(d&&(f=wi(gn(d),e)),f!==-1){let t=Xn(d,f);if(t!=null&&t.isIReferenceRange)u=t;else if(t===void 0||l.isPendingOverlay)u=this._toReference(l,e,s,i,!1,xi(l,a));else{let n=t;n!==null&&n.isIRange&&(n=n.getValueAt(0,0));let r=new D({axis:this._axis,maxCoords:s?.()});if(n!==null){let t=this._axis===v.Axis.Column,i=t?e.colStart:e.rowStart,a=t?e.rowStart:e.colStart;r.setValues([[i,[[a,[n]]]]])}u=this._toReference(r,e,s,i,!1,null)}}else{let t=e.scope?e:{...e,scope:i};r.addDynamicPrecedent(d,t,gi),u=this._toReference(l,e,s,i,!0,xi(l,a))}return u}_expandSheetSpan(e){if(typeof e!=`object`||!e||!0===e.isIRange)return null;let t=e;if(t.colStart===void 0||!ye(t.scope))return null;let n=this._container,r=n.getSheetSpanIds?.(t.scope)??null;if(!r||n.isGridless?.(r[0])||n.isGridless?.(r[r.length-1]))return null;let i=[];for(let e=0;e<r.length;e++)i.push(Ci(t,r[e]));return i.isSheetSpan=!0,i}getResizedReference(e,t,n){let r=this._gridIdOf(e),i=r?this._container.getGrid(r)?.getEntireCoords():void 0,a=e.rowStart+t-1,o=e.colStart+n-1;return this.getReference({rowStart:e.rowStart,rowEnd:i?Math.min(a,i.rowEnd):a,colStart:e.colStart,colEnd:i?Math.min(o,i.colEnd):o,scope:e.scope})}_toReference(e,t,n,r,i,a){let o=this._onRead??(i?this._dynamicRead:null);o&&(e=new yi(e,r,o));try{let i=new lt(this._runtime,e,t,void 0,n,this._container.resolveScope);return i._setCoordsReadHook(this._positionRead),a!==null&&i._setErrorIndex(o===null?a:{hasErrorIn:e=>(o(r,e.rowStart,e.colStart,e.rowEnd,e.colEnd),a.hasErrorIn(e))}),i}catch(e){throw e instanceof s?y.BuiltIn.Ref:e}}getAddress(e,t=!1){e||=(this._calcScope.positionRead=!0,Di.rowIndex=this._calcScope.rowIndex,Di.colIndex=this._calcScope.colIndex,Di.scope=null,Di);let n=this.getEntireCoords().scope;return e.colIndex===void 0?ut(e,n,t):re(e,n,t)}parseAsSerialDate(e,t){if(e===void 0)return;if(typeof e==`number`)return e;if(y.isError(e))throw e;if(typeof e!=`string`)throw y.BuiltIn.Value;let n=h(this._runtime,e,t);if(n===null)throw y.BuiltIn.Value;return n}parseAsDate(e,t){if(e!==void 0){if(y.isError(e))throw e;if(typeof e==`number`)return this.fromSerialDate(e);if(typeof e==`string`)return this.fromSerialDate(this.parseAsSerialDate(e,t));if(e instanceof Date)return e;throw y.BuiltIn.Value}}parseAsNumber(e,t){if(e===void 0)return;if(typeof e==`number`)return e;if(y.isError(e))throw e;if(typeof e!=`string`)throw y.BuiltIn.Value;let n=this._coerceToNumber(e,S.String,t);if(typeof n!=`number`)throw y.BuiltIn.Value;return n}createCriteria(e,t){return br(this,e,t)}createPivot(e,t,n){return kr.create(e,t,this._createSparseColumn,n)}getPivotAt(e){if(!(e instanceof lt))return null;let t=e.getCoords(),n=this._gridIdOf(t),r=(n?this._container.getGrid(n):null)?.getPivots();if(!r)return null;for(let e=0;e<r.length;e++){let n=r[e],i=n.range;if(t.rowStart>i.rowEnd||t.rowEnd<i.rowStart||t.colStart>i.colEnd||t.colEnd<i.colStart)continue;let a=n.block?.anchor;if(!a||!n.block.blocked)return Xt(n);let o=t.rowStart<=a.row&&t.rowEnd>=a.row&&t.colStart<=a.column&&t.colEnd>=a.column;return Xt(n,o?`blocked`:`wanted`)}return null}parseAsLiteral(e){return le(e)??bt(e)}toText(e){return P(e,this._runtime)}getRuntime(){return this._runtime}createRichData(e,t){return Ct.fromJSON({type:e,data:t},this._container.getRichDataContext?.())}getArgs(){return _.getArgs()}get[Symbol.toStringTag](){return`[CalculationContext]`}toString(){let e=``,t=this._instanceScope,n;return t&&(n=t.toString?.()),n&&n&&(e=`${e}:[${n}]`),e}},Ci=(e,t)=>({...e,scope:t,inSheetSpan:!0}),wi=(e,t)=>{if(!e)return-1;let n=e.length;if(n===0)return-1;let r=t.colStart,i=t.rowStart,a=t.colEnd,o=t.rowEnd,s=t.scope;for(let t=0;t<n;t++){let n=e[t];if(n!=null&&!(y.isError(n)||n.colStart!==r||n.rowStart!==i||n.colEnd!==a||n.rowEnd!==o||s&&n.scope!==s))return t}return-1},Ti={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Ei={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Di={rowIndex:0,colIndex:0,scope:null},Oi=Object.freeze({includeEmpty:!0}),ki=class extends Si{_noCell(e){return Error(`${e}() needs the cell being evaluated, and a deferred executor has none.`)}getRow(){throw this._noCell(`getRow`)}getColumn(){throw this._noCell(`getColumn`)}isImplicitIntersect(){throw this._noCell(`isImplicitIntersect`)}getEntireCoords(){throw this._noCell(`getEntireCoords`)}getReference(e,t){throw this._noCell(`getReference`)}getResizedReference(e,t,n){throw this._noCell(`getResizedReference`)}getValueAt(e,t,n,r){throw this._noCell(`getValueAt`)}getFormulaAt(e,t,n){throw this._noCell(`getFormulaAt`)}getSpillAt(e,t,n){throw this._noCell(`getSpillAt`)}getAddress(e,t=!1){if(!e)throw this._noCell(`getAddress`);return super.getAddress(e,t)}getSheetIndex(e){if(typeof e!=`string`)throw this._noCell(`getSheetIndex`);return super.getSheetIndex(e)}formatResults(e){throw this._noCell(`formatResults`)}getRandom(){throw this._noCell(`getRandom`)}defer(e,t){throw this._noCell(`defer`)}},Ai=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd});function ji(e,t,n,r,i,a,o,s){if(n===-(2**53-1))return[e,t];let c=e,l=t;if(i){if(n>s)return null}else l=Math.min(l,s-n);if(a){if(r<o)return null}else c=Math.max(c,o-r);return c<=l?[c,l]:null}function Mi(e,t,n){let r=e.ref,i=e.formula,a=i?i.getReferences(r.rowStart,r.colStart)[t]:null;if(!a||`nameId`in a||`tableId`in a||y.isError(a))return r;let o=a,s=ji(r.rowStart,r.rowEnd,o.rowStart,o.rowEnd,!0===o.$rowStart,!0===o.$rowEnd,n.rowStart,n.rowEnd);if(s===null)return null;let c=ji(r.colStart,r.colEnd,o.colStart,o.colEnd,!0===o.$colStart,!0===o.$colEnd,n.colStart,n.colEnd);return c===null?null:{rowStart:s[0],rowEnd:s[1],colStart:c[0],colEnd:c[1]}}var Ni=class extends Xe{constructor(e){let n=(e={...e}).container;super({id:e.uuid||`gen`+t.uuidV4(),send:(e,t,r)=>n.sendRequest(e,t,r),calculation:e.calculation}),this._touchedOthers=null,this._iterationId=0,this._resized=null,this._hiddenRows=null,this._hiddenColumns=null,this._filtered=!1,this._pivots=null,this._demanded=[],this._isProcessingJSON=!1,this._snapshots=null,this._options=e,this._context=e.context,this._container=e.container;let r={...Se},i=e.getEntireCoords??(()=>r);if(this._getEntireCoords=i,this._unanchored=!0===e.unanchored,this._shadowOf=e.shadowOf??null,this._arrayFirstCell=!0===e.arrayFirstCell,this._paged=!0===e.paged,!this._context||!this._container)throw Error(`Invalid Options`);let a=e?.onCalculated;this._onCalculated=a?e=>{a(Be(ce.results(e,`onCalculated`),this._container.getImager(this._gridId)))}:()=>{},this._values=new D({axis:v.Axis.Column,createRun:_n}),this._iterationId=0,this._contentfulSpatial=new k({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}});let o={updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}};this._spillSpatial=new k(o),this._errorSpatial=new k(o),this._calcStatusSpatial=new k(o),this._circularSpatial=new k(o),this._notifyValues=new k,this._notifyBlank=null,this._notifySpillsInsert=[],this._notifySpillsRemove=[],this._notifyFormats=new k,this._notifyCalcStatus=new k,this._notifyCircular=new k,this._touchedFormulas=[],this._container.registerGrid(this),this._publishMaps()}_land(e,t){return this._container.landRequest(e,()=>(e!==void 0&&this._versionMaps(e),t()))}_versionMaps(e){this._values=this._values.clone(e),this._contentfulSpatial=this._contentfulSpatial.clone(e),this._spillSpatial=this._spillSpatial.clone(e),this._errorSpatial=this._errorSpatial.clone(e),this._calcStatusSpatial=this._calcStatusSpatial.clone(e),this._circularSpatial=this._circularSpatial.clone(e),this._publishMaps()}_publishMaps(){this._container.setGridMaps(this._gridId,{values:this._values,contentful:this._contentfulSpatial,spills:this._spillSpatial,errors:this._errorSpatial,calcStatus:this._calcStatusSpatial,circular:this._circularSpatial,entireCoords:this._resized,hiddenRows:this._hiddenRows,hiddenColumns:this._hiddenColumns,filtered:this._filtered,pivots:this._pivots})}_adoptMaps(e){this._values=e.values,this._contentfulSpatial=e.contentful,this._spillSpatial=e.spills,this._errorSpatial=e.errors,this._calcStatusSpatial=e.calcStatus,this._circularSpatial=e.circular,this._resized=e.entireCoords??null,this._hiddenRows=e.hiddenRows??null,this._hiddenColumns=e.hiddenColumns??null,this._filtered=e.filtered??!1,this._pivots=e.pivots??null}_touchFormulas(e){if(!e)return;let t=this._gridId,n=this._container;for(let r=0;r<e.length;r++){let i=e[r],a=i.scope??t,o=a===t?this:n.getGrid(a),s=Ai(i);o?._touchedFormulas.push(s),o&&o!==this&&o._holdsBody()&&(this._touchedOthers??=new Set).add(o),n.recordTouched(a,[s])}}_takeFormulaResults(e,t=!1){let n=this._container.getFormulas().getSpatialAt(this._gridId);if(t){this._touchedFormulas=[];let t=n?.all();return t&&t.length>0&&(e.formulaInserts=this._formulaRecords(t)),e}let r=this._touchedFormulas;if(r.length===0)return e;this._touchedFormulas=[];let i=r;if(r.length>1){let e=[...r].sort((e,t)=>(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1)-(e.rowEnd-e.rowStart+1)*(e.colEnd-e.colStart+1));i=[];for(let t=0;t<e.length;t++){let n=e[t],r=!1;for(let e=0;e<i.length&&!r;e++)r=o.isRangeWithinRange(n,i[e]);r||i.push(n)}}if(e.formulaRemoves=i,n){let t=new Set,r=[];for(let e=0;e<i.length;e++){let a=n.search(i[e]);for(let e=0;e<a.length;e++){let n=a[e],i=n.value;t.has(i)||(t.add(i),r.push(n))}}r.length>0&&(e.formulaInserts=this._formulaRecords(r))}if(!e.isFull){let t=o.unionRangesArrays(i,e.bounds??void 0);e.bounds=t&&Ai(t)}return e}_formulaRecords(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r.value?.formula;i&&t.push({...Ai(r),value:i.getRecord()})}return t}_mutationResults(e){let t=this._takeFormulaResults({cycleId:this._container.getCycleId()});return e!==void 0&&(t.commitId=e),t}_apply(e,t,n=!1){let r=this._applyNow(e,t,n),i=this._touchedOthers;if(i){this._touchedOthers=null;let e=r instanceof Promise?void 0:r.commitId;for(let t of i)t._pushTouched(e)}return r}_holdsBody(){return this._shadowOf!==null||this._unanchored||this._arrayFirstCell}_pushTouched(e){if(this._touchedFormulas.length===0)return;let t=this._takeFormulaResults({cycleId:this._container.getCycleId()});e!==void 0&&(t.commitId=e),this._onCalculated(t)}_applyNow(e,t,n){switch(e.type){case`seed`:{let n=this._land(t,()=>this._seedNow(e.json,e.options));return this._onCalculated(n),n}case`setInputs`:{let r=this._container.getHeldCloneKey?.()??null,i=r===null?e.options:{...e.options,cloneKey:n?r:e.options?.cloneKey??r};return this._land(t,()=>(this._setInputsNow(e.values,e.formulas,e.deleteRange,i),this._mutationResults(i?.commitId)))}case`shift`:return this._land(t,()=>this._shiftNow(e.options));case`autoFill`:return this._land(t,()=>this._autoFillNow(e.template,e.destination,e.commitId));case`snapshot`:return this._captureSnapshot(e.snapshotId),{cycleId:this._container.getCycleId()};case`copyTo`:{let n=this._container.getGrid(e.sourceGridId)?._snapshots?.get(e.snapshotId);if(!n)return{cycleId:this._container.getCycleId(),commitId:e.commitId};let r=ne(e.destination,e.coords,e.fitDestination,e.transpose);return r.scope=this._gridId,this._land(t,()=>{e.isCut?this._moveTo(n,e.coords,r):this._copyTo(n,e.coords,r);let t=this._mutationResults(e.commitId);return t.bounds=o.unionRanges(t.bounds??null,Ai(e.destination)),t})}case`delete`:return this._land(t,()=>this._deleteNow()),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`calculate`:return this._calculateNow(e.full),{cycleId:this._container.getCycleId()};case`markDirty`:return this._markDirtyRegionsNow(e.coords),{cycleId:this._container.getCycleId()};case`demand`:return this._demandNow(e.rects),{cycleId:this._container.getCycleId()};case`revert`:return this._revertNow(e.options);case`close`:return this._detach(),{cycleId:this._container.getCycleId()};case`resize`:return this._land(t,()=>{this._resized=e.entireCoords,this._publishMaps()}),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`hidden`:return Fi(this.getHiddenRuns(e.axis),e.runs)||this._land(t,()=>this._setHiddenNow(e.axis,e.runs)),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`filtered`:return this._filtered!==e.filtered&&this._land(t,()=>this._setFilteredNow(e.filtered)),{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};case`pivots`:{let r=e.pivots.length>0?e.pivots:null;if(r===this._pivots)return{cycleId:this._container.getCycleId(),commitId:e.options?.commitId};let i=this._container.getHeldCloneKey?.()??e.options?.cloneKey??null;return this._land(t,()=>this._setPivotsNow(r,i)),this._notifyCalculated(this._container.getCycleId(),!1,n?null:e.options?.commitId)}case`setReference`:return this._setReferenceNow(e.row,e.column,e.index,e.precedent===`#REF!`?y.BuiltIn.Ref:e.precedent);case`setReferenceMode`:return this._setReferenceModeNow(e.row,e.column,e.index,e.side,e.mode);case`toJSON`:return{cycleId:this._container.getCycleId(),answer:this._toJSONNow(e.options)};case`evaluate`:{let t=this._container.getCycleId();return Promise.resolve(this._evaluateNow(e.row,e.column,e.evalIndex,e.coerce)).then(e=>({cycleId:t,answer:e}))}case`graph`:return{cycleId:this._container.getCycleId(),answer:this._graphNeighborsNow(e.coords,e.kind,e.direct)};case`isVolatile`:return{cycleId:this._container.getCycleId(),answer:this._isVolatileNow(e.row,e.column)};case`setBody`:{let r=e.body,i=this._land(t,()=>{let e=r.coords,t=this._container.createFormulaBlock(r.scopeGridId,this._context,r.expression,r.authoredAt.rowIndex,r.authoredAt.colIndex).reanchorReferences(r.scopeGridId).getTextAt(e.rowStart,e.colStart);return this._setInputsNow(null,[{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:t}],void 0,{cloneKey:this._container.getHeldCloneKey?.()??void 0}),this._mutationResults(void 0)});return r.recompile&&this._container.recompileNamed(this._gridId,r.recompile===`load`),n?(this._onCalculated(i),{cycleId:i.cycleId}):i}}}_captureSnapshot(e){let t=this._container,n=this._snapshots??=new Map;n.set(e,{calcGrid:this,values:this._values.clone(),spillSpatial:this._spillSpatial.clone(),formulaSpatial:t.getFormulas(),precedentSpatial:t.getPrecedents(),volatile:t.getVolatiles()}),n.size>Li&&n.delete(n.keys().next().value)}beginUpdates(){return{gridId:this._gridId,values:this._values,spillSpatial:this._spillSpatial,errorSpatial:this._errorSpatial,calcStatusSpatial:this._calcStatusSpatial,circularSpatial:this._circularSpatial,contentfulSpatial:this._contentfulSpatial,notifyValues:this._notifyValues,notifyBlank:e=>this._addNotifyBlank(e),notifySpillsInsert:this._notifySpillsInsert,notifySpillsRemove:this._notifySpillsRemove,notifyFormats:this._notifyFormats,notifyCalcStatus:this._notifyCalcStatus,notifyCircular:this._notifyCircular,calcStatusConflating:null,circularConflating:null,errorRemovesConflating:null,errorInsertsConflating:null,formatsConflating:null,done:(e,t)=>this._notifyCalculated(e,t)}}_addNotifyBlank(e){let t=this._notifyBlank;t===null?this._notifyBlank={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}:(e.colStart<t.colStart&&(t.colStart=e.colStart),e.rowStart<t.rowStart&&(t.rowStart=e.rowStart),e.colEnd>t.colEnd&&(t.colEnd=e.colEnd),e.rowEnd>t.rowEnd&&(t.rowEnd=e.rowEnd))}_calculateNow(e){return this._container.calculateGrid(this._gridId,e?Ki:void 0)}_shiftNow(e){let t=this,n=this.getId(),r={...e};r.range={...r.range},r.range.scope=n,delete r.onShift;let i=t._values,a=r.range,o=r.direction,s=o===v.Direction.Left||o===v.Direction.Right,c=o===v.Direction.Down||o===v.Direction.Right,l=c?1:-1,u=t._spillSpatial,d=t._contentfulSpatial;Ce(u,a,s,c);let f=[],p=this._container.getPrecedents().search(a),m=be(a,u,i,d,void 0,!1,!1,void 0,(e,t,r,i)=>{f.push({colStart:e,rowStart:t,colEnd:r,rowEnd:i,scope:n})});i.shift(r.range,r.direction),r.onUpdates=(e,n)=>{t._notifySpillsRemove.push(...n),t._notifySpillsInsert.push(...e)},t._spillSpatial=u.shift(r),delete r.onUpdates,t._contentfulSpatial=d.shift(r),t._errorSpatial=t._errorSpatial.shift(r),t._calcStatusSpatial=t._calcStatusSpatial.shift(r);let h=t._container,g=h.getFormulas().clone(),_=h.getPrecedents().clone(),y=this.getEntireCoords(),b={colStart:a.colStart,rowStart:a.rowStart,colEnd:s&&l===1?y.colEnd:a.colEnd,rowEnd:s||l!==1?a.rowEnd:y.rowEnd,scope:n},x=c?Ue(_,b):dt(_,a);x&&(Zi(g,_,x.formulas.inserts,x.formulas.removes),t._touchFormulas(x.formulas.removes),t._touchFormulas(x.formulas.inserts));let S=s?a.colEnd-a.colStart+1:a.rowEnd-a.rowStart+1,C=S*l,w={colStart:a.colStart,rowStart:a.rowStart,colEnd:s?y.colEnd:a.colEnd,rowEnd:s?a.rowEnd:y.rowEnd,scope:n},T,E=rt(()=>_,()=>{let e=h.getDynamics();return T=new Map(e),T},w,{colIndex:s?C:0,rowIndex:s?0:C,scope:n},c?void 0:a),D,O;E&&(Zi(g,_,E.formulas.inserts,E.formulas.removes),t._touchFormulas(E.formulas.removes),t._touchFormulas(E.formulas.inserts)),r.onUpdates=(e,t)=>{D=e,O=t},g.shift(r),(D||O)&&($i(_,D,O),t._touchFormulas(O),t._touchFormulas(D)),h.setFormulas(g),h.setPrecedents(_),T&&h.setDynamics(T),h.bumpCalcEpochs(!0),m?.(c,s?0:C,s?C:0);let k=s?a.colStart:a.rowStart,A=s?a.colEnd:a.rowEnd,j=(e,t=e.ref)=>{let r=e.gridId;r&&h.getGrid(r)&&(e.unanchored?h.invalidateNamed(r):((e,t)=>{let r=s?e.colStart:e.rowStart,i=s?e.colEnd:e.rowEnd;if(t===n&&i>=k){if(c)r>=k&&(r+=S),i+=S;else if(r=r>A?r-S:Math.min(r,k),i=i>A?i-S:k-1,i<r)return}f.push(s?{colStart:r,rowStart:e.rowStart,colEnd:i,rowEnd:e.rowEnd,scope:t}:{colStart:e.colStart,rowStart:r,colEnd:e.colEnd,rowEnd:i,scope:t})})(t,r))};for(let e=0;e<p.length;e++){let t=p[e].value,n=t.formulaEntry.value,r=t.index<0||n.unanchored?n.ref:Mi(n,t.index,a);r!==null&&j(n,r)}let M=E?.dynamicDependents;for(let e=0;e<(M?.length??0);e++)j(M[e].value);let ee=E?.formulas.inserts;for(let e=0;e<(ee?.length??0);e++){let t=ee[e];t.scope!==n&&j(t.value)}for(let e=0;e<(D?.length??0);e++){let t=D[e];t.value.positionRead&&f.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:n})}return f.length>0&&h.markDirty(f),t._mutationResults(e.commitId)}_removeNow(e){return this._setInputsNow(null,[{...e,scope:this._gridId,value:null}],{...e,scope:this._gridId})}_autoFillNow(e,t,n){let r=this._gridId,i=this._container,a={calcGrid:this,values:this._values.clone(),spillSpatial:this._spillSpatial.clone(),formulaSpatial:i.getFormulas(),precedentSpatial:i.getPrecedents(),volatile:i.getVolatiles()};return this._copyTo(a,{...e,scope:r},{...t,scope:r}),this._mutationResults(n)}_replaceSheetSpans(e,t,n){let r=this._container,i=r.getFormulas(),a=i.all3D(),o=new Map,s=[],c=[];for(let r=0;r<a.length;r++){let i=a[r],l=i.value,u=l.getReferencedSymbolIds(),d=l;for(let r=0;r<u.length;r++){let i=u[r];if(!Wt(i))continue;let a=o.get(i);a===void 0&&(a=B(i,e,t,n)??null,o.set(i,a)),a!==null&&(d=d.replaceScopeIds(i,a))}d!==l&&(s.push(i),c.push({...i,value:d}))}if(c.length===0)return;let l=i.clone(),u=r.getPrecedents().clone();Zi(l,u,c,s);let d=r.getDynamics(),f=null;for(let e=0;e<s.length;e++){let t=s[e].value,n=d.get(t);n&&(f??=new Map(d),u.removeAll(n,X),f.delete(t))}r.setFormulas(l),r.setPrecedents(u),f&&r.setDynamics(f),this._touchFormulas(s),this._touchFormulas(c);let p=[];for(let e=0;e<c.length;e++){let t=c[e].value;p.push({...t.ref,scope:t.gridId}),Xi(r,t,p)}r.markDirty(p)}_deleteNow(){let e=this._container,t=e.getSheetIds?.();if(t){let e=this._gridId;this._replaceSheetSpans(t,t.filter(t=>t!==e))}let n=e.getFormulas(),r=e.getPrecedents(),i=n,a=r,o=this._gridId,s=[];if(i.getSpatialAt(o)&&(i=i.clone(),i.getSpatialAt(o).clear()),a.getSpatialAt(o)){a=a.clone();let t=a.getSpatialAt(o),n=new Map,r=new Map,c=t.all();for(let e=0;e<c.length;e++){let t=c[e].value,i=t.formulaEntry;if(i.scope!==o){let e=t.index,a=i;n.set(a,a);let o=r.get(a)??a;o={...o},o.value=o.value.setReferenceAt(e,null,{scopeDeleted:!0}),r.set(a,o)}}if(t.clear(),r.size>0||n.size>0){let t=Array.from(r.values()),o=Array.from(n.values());Zi(i,a,t,o),this._touchFormulas(o),this._touchFormulas(t);for(let n=0;n<t.length;n++){let r=t[n];s.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd,scope:r.scope}),Xi(e,r.value,s)}}}i!==n&&e.setFormulas(i),a!==r&&e.setPrecedents(a),s.length>0&&e.markDirty(s),this._container.unregisterGrid(this._gridId)}_detach(){let e=this._container,t=this._gridId,n=e.getPrecedents(),r=[];if(n.getSpatialAt(t)){let i=n.clone(),a=i.getSpatialAt(t),o=a.all(),s=new Set;for(let e=0;e<o.length;e++){let n=o[e].value.formulaEntry;n.scope===t||s.has(n)||(s.add(n),r.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:n.scope}))}a.clear(),e.setPrecedents(i)}r.length>0&&e.markDirty(r),e.unregisterGrid(t)}_markDirtyRegionsNow(e){let t=this._gridId,n=Array(e.length);for(let r=0;r<e.length;r++){let i=e[r];n[r]=i.scope===t?i:{...i,scope:i.scope??t}}this._container.markDirty(n)}getHiddenRuns(e){return e===v.Axis.Column?this._hiddenColumns:this._hiddenRows}isFiltered(){return this._filtered}getPivots(){return this._pivots}getHiddenSkip(e,t,n){let r=this.getHiddenRuns(e);if(!r)return null;let i=0,a=r.length;for(;i<a;){let e=i+a>>>1;r[e].max<t?i=e+1:a=e}if(i===r.length||r[i].min>n)return null;let o=Pi.get(r);o||(o=new Map,Pi.set(r,o));let s=o.get(t);if(!s){let e=oe(r);s=t===0?e:(n,r)=>e(n+t,r)-t,o.set(t,s)}return s}_setHiddenNow(e,t){let n=t.length>0?t:null;e===v.Axis.Column?this._hiddenColumns=n:this._hiddenRows=n,this._publishMaps(),this._markTotals()}_setFilteredNow(e){this._filtered=e,this._publishMaps(),this._markTotals()}_setPivotsNow(e,t=null){let n=this._pivots;this._pivots=e,this._placePivots(n,e,t),this._publishMaps(),this._markFormulas(e=>e.hasPivotData())}_placePivots(e,t,n=null){let r=this._gridId,i=this._spillSpatial,a=i.isEmpty()?[]:i.all().filter(e=>e.value.getKind()===`pivot`);for(let e of a)i.remove(e,X),this._notifySpillsRemove.push(e);let o=this._container.getCycleId();for(let e of t??[]){let t=e.block;if(!t||t.blocked)continue;let n={...e.range,scope:r},a={rows:t.anchor.row-n.rowStart,columns:t.anchor.column-n.colStart},s={...n,value:new de(n,o,`pivot`,a)};i.insert(s),this._notifySpillsInsert.push(s)}}_markTotals(){this._markFormulas(e=>e.hasTotals())}_markFormulas(e){let t=this._container,n=[];for(let r of t.getFormulas().getScopeValues()){let t=r.all();for(let r=0;r<t.length;r++){let i=t[r];i.value&&e(i.value)&&n.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,scope:i.scope})}}n.length!==0&&(t.markDirty(n),t.requestCalculateGrid(this._gridId))}getShadowOf(){return this._shadowOf}isArrayFirstCell(){return this._arrayFirstCell}isPaged(){return this._paged}getDemanded(){return this._demanded}_demandNow(e){if(!this._paged)return;let t=this._demanded,n=Array(e.length);for(let t=0;t<e.length;t++){let r=e[t];n[t]={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd}}this._demanded=n;let r=[];for(let e=0;e<n.length;e++)Ii(t,n[e])||r.push(n[e]);for(let e=0;e<t.length;e++)Ii(n,t[e])||r.push(t[e]);r.length>0&&this._markDirtyRegionsNow(r)}getEntireCoords(){return this._resized??this._getEntireCoords()}hasErrorIn(e){return this._errorSpatial.has(e)}getBoundingRange(){let e=null;return e=o.unionRanges(this._values.getCoords(),e),e=o.unionRanges(this._container.getFormulas().getSpatialAt(this._gridId)?.getBoundingRange(),e),e}getValues(){return this._values}getDirtyRegions(){return this._container.getDirtyGrid(this._gridId)}getFormulas(){return this._container.getFormulas().getSpatialAt(this._gridId)??Ui}getSpills(){return this._spillSpatial}_revertNow(e){let t=this._container.revertTo(e.commitId,this._gridId);if(t)for(let e=0;e<t.length;e++)this._touchedFormulas.push({...t[e],scope:this._gridId});let n=this._takeFormulaResults({cycleId:this._container.getCycleId()});return n.commitId=e.commitId,n}getDirectDependentsAt(e){let r=e.rowStart,i=e.colStart,a=e.rowEnd,s=e.colEnd,c=this._gridId,l=this._container.getPrecedents();Y.colStart=i,Y.rowStart=r,Y.colEnd=s,Y.rowEnd=a,Y.scope=c;let u=l.search(Y);if(u.length===0)return t.EmptyArray;let d=[];for(let e=0;e<u.length;e++){let t=u[e],n=t.value;if(n.index===_i)continue;let o=n.formulaEntry,l=r-t.rowStart,f=i-t.colStart,p=a-t.rowStart,m=s-t.colStart,h=o.rowEnd-o.rowStart,g=o.colEnd-o.colStart,_=n.formulaBlockHeight-1,v=n.formulaBlockWidth-1,y;if(n.index===gi){let e=o.value,t=e.ref;y={rowStart:t.rowStart,rowEnd:t.rowEnd,colStart:t.colStart,colEnd:t.colEnd,scope:c===e.gridId?void 0:e.gridId??void 0}}else if(h>_||g>v)y={rowStart:o.rowStart,rowEnd:o.rowEnd,colStart:o.colStart,colEnd:o.colEnd,scope:c===o.scope?void 0:o.scope};else{let e=t.rowEnd-t.rowStart-_,r=t.colEnd-t.colStart-v,i=n.$absRowEnd?0:Math.max(0,l-e),a=n.$absRowStart?_:Math.min(p,_),s=n.$absColEnd?0:Math.max(0,f-r),u=n.$absColStart?v:Math.min(m,v);y={rowStart:o.rowStart+i,rowEnd:o.rowStart+a,colStart:o.colStart+s,colEnd:o.colStart+u,scope:c===o.scope?void 0:o.scope}}this._pushWithSpills(d,y)}return d=We(d,2,n.Row),d.sort(o.rowFirstRangeComparator),d}_pushWithSpills(e,t){e.push(t);let n=t.scope&&t.scope!==this._gridId?this._container.getGrid(t.scope)??null:this;if(!n)return;let r=n._spillSpatial.search({rowStart:t.rowStart,colStart:t.colStart,rowEnd:t.rowEnd,colEnd:t.colEnd});for(let n=0;n<r.length;n++){let i=r[n],a=i.value.getAnchor();a.row<t.rowStart||a.row>t.rowEnd||a.column<t.colStart||a.column>t.colEnd||i.rowEnd===i.rowStart&&i.colEnd===i.colStart||e.push({rowStart:i.rowStart,rowEnd:i.rowEnd,colStart:i.colStart,colEnd:i.colEnd,scope:t.scope})}}getDirectPrecedentsAt(e){let r=e.rowStart,i=e.colStart,a=e.rowEnd,s=e.colEnd,c=this._container.getFormulas();Y.colStart=i,Y.rowStart=r,Y.colEnd=s,Y.rowEnd=a;let l=this._gridId;Y.scope=l;let u=c.search(Y);if(u.length===0)return t.EmptyArray;let d=this.getEntireCoords(),f=null,p=e=>{if(!e||e===l)return d;f??=new Map;let t=f.get(e);return t||(t=this._container.getGrid(e)?.getEntireCoords()??d,f.set(e,t)),t},m=[];for(let e=0;e<u.length;e++){let t=u[e],n=t,o=this._container.getDynamics().get(n.value);if(o)for(let e=0;e<o.length;e++){let t=o[e];t.value.index===gi&&m.push({rowStart:t.rowStart,rowEnd:t.rowEnd,colStart:t.colStart,colEnd:t.colEnd,scope:t.scope===l?void 0:t.scope})}let c=n.value.formula.getReferences(r,i);if(!c)continue;let d=r-t.rowStart,f=i-t.colStart,h=a-t.rowStart,g=s-t.colStart,_=n.rowEnd-n.rowStart,v=n.colEnd-n.colStart,y=t.rowEnd-t.rowStart-_,b=t.colEnd-t.colStart-v,x=Math.max(0,d-y),S=Math.max(0,f-b),C=Math.min(h,_),w=Math.min(g,v),T=[];for(let e=0;e<c.length;e++){let t=c[e];if(t?.colStart===void 0)continue;let r=t.scope,i=p(r),a=Tt(t,n.rowStart+x,n.colStart+S),o=Tt(t,n.rowStart+C,n.colStart+w),s={colStart:Math.max(Math.min(a.colStart,o.colStart),i.colStart),rowStart:Math.max(Math.min(a.rowStart,o.rowStart),i.rowStart),colEnd:Math.min(Math.max(a.colEnd,o.colEnd),i.colEnd),rowEnd:Math.min(Math.max(a.rowEnd,o.rowEnd),i.rowEnd),scope:r===l?void 0:r};T.push(s)}m.push(...T)}return m=We(m,2,n.Row),m.sort(o.rowFirstRangeComparator),m}_directAcrossGrids(e,n){let r=this._gridId,i=e.scope,a=i&&i!==r?this._container.getGrid(i)??null:this;if(!a)return t.EmptyArray;let o=n?a.getDirectDependentsAt(e):a.getDirectPrecedentsAt(e);if(a===this||o.length===0)return o;let s=Array(o.length);for(let e=0;e<o.length;e++){let t=o[e],n=t.scope??a._gridId;s[e]=n===r?{...t,scope:void 0}:{...t,scope:n}}return s}getDependentsAt(e){let t=zt(e,e=>this._directAcrossGrids(e,!0));return t.sort(o.rowFirstRangeComparator),t}getPrecedentsAt(e){let t=zt(e,e=>this._directAcrossGrids(e,!1));return t.sort(o.rowFirstRangeComparator),t}_graphNeighborsNow(e,t,n){let r=t===`precedents`?n?this.getDirectPrecedentsAt(e):this.getPrecedentsAt(e):n?this.getDirectDependentsAt(e):this.getDependentsAt(e),i=this._container;if(t===`precedents`){let t=this.getNamedReferencesAt(e),n=[];for(let e=0;e<t.length;e++){let r=i.getNamedNodeInfo(t[e]);r&&n.push(r)}return{cells:r,names:n}}let a=[],o=[],s=new Set;for(let e=0;e<r.length;e++){let t=r[e],n=t.scope;if(!n){a.push(t);continue}if(s.has(n))continue;let c=i.getNamedNodeInfo(n,!0);c?(s.add(n),o.push(c)):a.push(t)}return{cells:a,names:o}}getNamedReferencesAt(e){let n=this.getFormulas().search(e),r=n.length;if(r===0)return t.EmptyArray;let i=new Set;for(let e=0;e<r;e++){let t=n[e].value?.getNamedIds();if(t)for(let e=0;e<t.length;e++)i.add(t[e])}return i.size>0?[...i]:t.EmptyArray}_blankRegion(){let e=this._container.getFormulas().getSpatialAt(this._gridId)?.all(),t=e&&e.length>0?e[0]:null,n=t?.value?.getBlankRegion()??null;if(!t||!n)return null;let r=Array(n.rects.length);for(let e=0;e<r.length;e++){let t=n.rects[e];r[e]={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}let i={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd};if(!n.paged)return{value:n.value,rects:r,extent:i};let a=this._demanded,o=Array(a.length);for(let e=0;e<a.length;e++){let t=a[e];o[e]={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}return{value:void 0,rects:r,extent:i,paged:!0,evaluated:o}}getFormulaBlockAt(e,t){let n=this._formulaAt(e,t);return n?n.value.formula:null}getReferencesAt(e,n){let r=this._formulaAt(e,n);return r?r.value.formula.getReferencesAt(e,n):t.EmptyArray}_evaluateNow(e,t,n,r){let i=this._formulaAt(e,t);if(!i)return null;let a=i.value.formula,o=this._container.getScope();o.node=null;let s=o.deferCount;try{return this._evaluateBlockNow(a,e,t,n,r)}finally{if(o.deferCount!==s){let e=this._container.getDeferred?.();e?.endEvaluation(),e?.flush()}}}_evaluateBlockNow(e,t,n,r,i){if(i===`scalar`){let i=e.evaluateAt(t,n,r);if(i&&i.colStart!==void 0)i=e.finalizeValue(i);else if(De(i))return e.finalizeValue(i);let a=Ft(i,this._context);return a===null?0:a}return vn(e.finalizeValue(e.evaluateAt(t,n,r)))}_setReferenceNow(e,t,n,r){let i=this._formulaAt(e,t),a=r;r&&r.colStart!==void 0?a=Bt(a,e,t):r&&r.colIndex!==void 0&&(a=pt(a,e,t));let o=i.value.formula.setReferenceAt(n,a).getTextAt(e,t);return this._land(void 0,()=>{o?this._setInputsNow(null,[{colStart:t,rowStart:e,colEnd:t,rowEnd:e,scope:this._gridId,value:o}]):this._removeNow({colStart:t,rowStart:e,colEnd:t,rowEnd:e})}),this._mutationResults(void 0)}_setReferenceModeNow(e,t,n,r,i){let a=this.getReferencesAt(e,t)[n];if(!a||`nameId`in a)throw Error(`Reference at index ${n} is not a cell reference and cannot have its style changed.`);return this._setReferenceNow(e,t,n,V(a,r,i))}_isVolatileNow(e,t){let n=this._formulaAt(e,t);if(!n?.value)return!1;let r=n.value;if(Yi(r,this._gridId,this._container))return!0;let i=r.nodeAtOrNull(e,t);return i!==null&&(i.state&nr)!==0}_formulaAt(e,t){Hi.colStart=t,Hi.rowStart=e,Hi.colEnd=t,Hi.rowEnd=e,Hi.scope=this._gridId,Gi.length=0;let n=this._container.getFormulas().search(Hi,!1,!1,Gi);return n.length===0?null:n[0]}_createCopySpillEntries(e,t,n,r,i){let a=r??[],o=i??[],s=t.colStart,c=t.rowStart,l=t.colEnd,u=t.rowEnd,d=n.colStart,f=n.rowStart,p=e.search(t),m=p.length;for(let e=0;e<m;e++){let t=p[e];o&&o.push(t);let n=t.rowStart,r=t.colStart;if(n<c||n>u||r<s||r>l||t.value.getError())continue;let i=d+(t.colEnd-r),m=f+(t.rowEnd-n),h={colStart:d,rowStart:f,colEnd:i,rowEnd:m};a.push({colStart:d,rowStart:f,colEnd:i,rowEnd:m,value:new de(h,0,t.value.getKind())})}return{removes:o,inserts:a}}_reanchorFormulas(e,t,n,r){let i=e?e.length:0;if(i===0)return;let a=this._container,o=n??this._gridId,s=n==null?t??o:o,c=a.getScope();c.gridId=s;let l=t?a.getSymbols().resolve(U.Sheet,t)?.toString():void 0,u=this._context;for(let n=0;n<i;n++){let i=e[n],d=i.value,f=d.ref,p=d.formula.getTextAt(f.rowStart,f.colStart);c.colIndex=f.colStart,c.rowIndex=f.rowStart;let m=a.createFormulaBlock(s,u,p,f.rowStart,f.colStart);t&&(m=m.reanchorReferences(l,r));let h=new hi(f,o,m,a,d.unanchored,d.getNodeSource());i.scope=o,i.value=h}}_copyTo(e,t,n){let r=e.calcGrid.getId(),i=this._gridId,a=e.formulaSpatial,o=a.getSpatialAt(r);if(!o||o.isEmpty())return;let s=this.getEntireCoords(),c=s.colStart,l=s.rowStart,u=s.colEnd,d=s.rowEnd,f=a.createCopiedEntries(t,n),p=f.inserts,m=p.length;if(m===0&&(f.removes?.length??0)===0)return;let h=0,g=e.spillSpatial,_=[];for(;h<m;){let e=p[h];e.scope=i;let n=e.value,r=n.ref,a=r.colStart,o=r.rowStart,s=r.colEnd,f=r.rowEnd;this._createCopySpillEntries(g,t,r,_,null);let v=n.formula.getReferences(o,a),y=v.length;for(let t=0;t<y;t++){let i=v[t];if(!i||`nameId`in i||`tableId`in i)continue;let h=i,g=h.colStart,_=h.rowStart,y=h.colEnd,b=h.rowEnd,x=h.$colStart?g:g+a,S=h.$rowStart?_:_+o,C=h.$colEnd?y:y+s,w=h.$rowEnd?b:b+f;if(g===-(2**53-1)&&(x=c,C=u),_===-(2**53-1)&&(S=l,w=d),x<c||C>u||S<l||w>d){let i=c-x,h=l-S,g=u-C,_=d-w;Wi.colStart=Math.max(a,a+i),Wi.rowStart=Math.max(o,o+h),Wi.colEnd=Math.min(s,s+g),Wi.rowEnd=Math.min(f,f+_);let y=Pt(e,Wi,Rt);if(y){let t=y.length;e=y[t-1],n=e.value,r=n.ref,a=r.colStart,o=r.rowStart,s=r.colEnd,f=r.rowEnd;for(let e=0;e<t-1;e++){let t=y[e];p.push(t),m++}}else n=n.setReferenceAt(t,null),e.value=n,v=n.formula.getReferences(o,a)}}p[h++]=e}let v=this._container,y=v.getFormulas().clone(),b=v.getPrecedents().clone();v.setFormulas(y),v.setPrecedents(b),i!==r&&this._reanchorFormulas(p,void 0,i),Zi(y,b,p,f.removes),this._touchFormulas(f.removes),this._touchFormulas(p),_&&this._spillSpatial._updateNodes(_,[]),v.markDirty([{...n,scope:i}])}_moveTo(e,n,r){let i=e.calcGrid,a=i.getId(),s=e.formulaSpatial;this._removeNow(r);let c=this._container,l=c.getPrecedents().clone(),u=c.getFormulas().clone();c.setPrecedents(l),c.setFormulas(u);let d=z(l,n,r);d&&(Zi(u,l,d.formulas.inserts,d.formulas.removes),this._touchFormulas(d.formulas.removes),this._touchFormulas(d.formulas.inserts));let f={cutFrom:n},p=s.createCopiedEntries(n,r,f).inserts,m=p.length,h=this._gridId;if(h!==a){let e=r.colStart-n.colStart,t=r.rowStart-n.rowStart,i=[],s=[];for(let r=0;r<m;r++){let c=p[r],l=c.value,u=l.ref,d=l.formula.resolvedPrecedentsAt(u.rowStart,u.colStart),f=!0,m=d?d.length:0;for(let r=0;r<m;r++){let i=d[r];if(y.isError(i)){f=!1;break}let s=i.scope??h,c;if(s===h)c={colStart:i.colStart-e,rowStart:i.rowStart-t,colEnd:i.colEnd-e,rowEnd:i.rowEnd-t};else{if(s!==a){f=!1;break}c=i}if(!o.isRangeWithinRange(c,n)){f=!1;break}}f?s.push(c):i.push(c)}if(s.length>0){this._reanchorFormulas(s);for(let e of s){let t=e.value.replaceScopeIds(a,h);t!==e.value&&(e.value=t)}}i.length>0&&this._reanchorFormulas(i,a)}let g;Zi(u,l,p),this._touchFormulas(p);let _=Te(l,()=>{let e=c.getDynamics();return g=new Map(e),g},n,r);if(g&&c.setDynamics(g),_){let e=_.edged??t.EmptyArray,i=e.length>0?_.formulas.inserts.filter(t=>!e.includes(t)):_.formulas.inserts;if(n.scope!==r.scope&&i.length>0&&this._reanchorFormulas(i,r.scope,n.scope,!0),Zi(u,l,_.formulas.inserts,_.formulas.removes),this._touchFormulas(_.formulas.removes),this._touchFormulas(_.formulas.inserts),e.length>0){let t=[];for(let n=0;n<e.length;n++){let r=e[n].value;t.push({...r.ref,scope:r.gridId}),Xi(c,r,t)}c.markDirty(t)}}let b=this._values;e.values.copyTo(b,{colIndex:r.colStart,rowIndex:r.rowStart},n),et(this._errorSpatial,b,r);let x=e.spillSpatial,S=[],C=[];for(let e=0;e<m;e++){let t=p[e];this._createCopySpillEntries(x,n,t,S,C)}let w=[];S.length>0&&(this._spillSpatial._updateNodes(S,[]),i._spillSpatial._updateNodes([],C),St(c.getCycleId(),C,t.EmptyArray,i._contentfulSpatial,i._spillSpatial,i._values,(e,t,n,r)=>{w.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:h})},i._notifyValues,(e,t)=>{e&&this._notifySpillsInsert.push(e),t&&this._notifySpillsRemove.push(t)},i._notifyCalcStatus,i._errorSpatial,i._values.getAxis()!==v.Axis.Row,!1,i._circularSpatial));let T=this.getEntireCoords();c.markDirty([{...T,scope:this._gridId}])}_notifyCalculated(e,t,n){let r,i=!1;i||(typeof t==`boolean`?i=t:t&&(r=t,i=r.full??!1));let a=this._notifyValues,s=a.all(),c=this._notifyCalcStatus.all([]);c.length>0&&this._notifyCalcStatus.clear();let l=this._notifyCircular.all([]),u,d;l.length>0&&this._notifyCircular.clear(),i?u=this._spillSpatial.all():(u=this._notifySpillsInsert,d=this._notifySpillsRemove),this._notifySpillsInsert=[],this._notifySpillsRemove=[];let f=this._notifyFormats.all();f.length>0&&this._notifyFormats.clear();let p={},m=null,h=s.length;if(h>0){a.clear();let e=s,t=null;for(let e=0;e<h;e++){let n=s[e],r=n.colStart,i=n.colEnd;if(r!==i){t||=[];for(let e=r+1;e<=i;e++)t.push({colStart:e,rowStart:n.rowStart,colEnd:e,rowEnd:n.rowEnd});n.colEnd=r}}t&&(e=s.concat(t)),e.sort(o.columnFirstRangeComparator);let n=new Lt.Builder((e,t)=>new Ke.ArrayList(e.slice(0,t))),r,i=!0===this._container.getDeferred?.()?.hasHolders(),c=this._values,l=c.getAxis()===v.Axis.Column,u=e.length;for(let t=0;t<u;t++){let a=e[t];m=o.unionRanges(m,a,Ri);let s=c.getRuns({bounds:a}),u=s.next(),d=a.colStart,f=a.rowStart,p=a.colEnd,h=a.rowEnd,g=l?f:d,_=l?p:h,v=l?h:p,y=l?d:f,b=g;for(;!u.done;){let e=u.value,t=e[0];for(;y<t;)r||=[],r.push({colStart:l?y:b,rowStart:l?b:y,colEnd:l?y:v,rowEnd:l?v:y}),y++,b=g;let a=e[1],o=e[2],c=Math.max(a,g),d=Math.min(a+o.length-1,v);n.pushMultipleAt(t,c,i?ea(o):o),b<c&&(r||=[],r.push({colStart:l?t:b,rowStart:l?b:t,colEnd:l?t:c-1,rowEnd:l?c-1:t})),b=d+1,d>=v?(y=t+1,b=g):y=t,u=s.next()}for(;y<=_;)b<=v&&(r||=[],r.push({colStart:l?y:b,rowStart:l?b:y,colEnd:l?y:v,rowEnd:l?v:y})),y++,b=g}let d=n.build();d&&(p.valueInserts=d),r&&(p.valueRemoves=r)}if(c.length>0){let e=this._calcStatusSpatial,t,n=c.length;for(let r=0;r<n;r++){let n=c[r];e.insertNonOverlapping(n,{onIntersect:(e,n)=>(t||=[],t.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:n.value}),m=o.unionRanges(m,n),!1===n.value&&(n.value=null),n)})}t&&t.length>0&&(p.calcStatusUpdates=t,m=o.unionRangesArrays(t,m??void 0,Ri))}if(l.length>0){let e=this._circularSpatial,t,n=l.length;for(let r=0;r<n;r++){let n=l[r];e.insertNonOverlapping(n,{onIntersect:(e,n)=>{t||=[];let r=!1===n.value;return t.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:r?null:n.value}),m=o.unionRanges(m,n),r&&(n.value=null),n}})}t&&t.length>0&&(p.circularUpdates=t,m=o.unionRangesArrays(t,m??void 0,Ri))}let g,_,y=d?d.length:0;if(y>0){g=[];for(let e=0;e<y;e++){let t=d[e],n=t.value?.getBlockedCoords()??t;g.push({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd})}g&&(p.spillRemoves=g,m=o.unionRangesArrays(g,m??void 0,Ri))}let b=u.length;if(b>0){let t=this._spillSpatial,n;for(let r=b-1;r>=0;r--){let a=u[r],o=a.value;if(!i&&o.getCycleId()!==e)continue;let s=t.search(a),c=s.length;for(let t=0;t<c;t++){let r=s[t];if(xe(a.rowStart,a.colStart,r)&&(i||r.value.getCycleId()===e)){_||(_=[],n=new Set);let e=Mt(r.colStart)+ze(r.rowStart);if(n.has(e))continue;n.add(e);let t=r.value.getBlockedCoords()??a;_.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,value:r.value.getKind()})}}}_&&(p.spillInserts=_,m=o.unionRangesArrays(_,m??void 0,Ri))}f.length>0&&(p.formatInserts=f,m=o.unionRangesArrays(f,m??void 0,Ri)),this._takeFormulaResults(p,i),p.formulaRemoves&&(m=o.unionRangesArrays(p.formulaRemoves,m??void 0,Ri));let x=this._notifyBlank;x!==null&&(m=o.unionRanges(m,x,Ri),this._notifyBlank=null),m&&(p.bounds={colStart:m.colStart,rowStart:m.rowStart,colEnd:m.colEnd,rowEnd:m.rowEnd}),p.cycleId=Object.keys(p).length===0?e-1:e,i&&(p.isFull=!0);let S=n===void 0?this._container.getCalculatedCommitId():n;return S!==null&&(p.commitId=S),this._holdsBody()&&(p.blankRegion=this._blankRegion()),this._onCalculated(p),Promise.resolve(p)}_setInputsNow(e,n,r,i){let a=this._gridId,s=this._container,c=this._context,l=s.getFormulas(),u=l.getSpatialAt(a),d=!!u&&!u.isEmpty(),f=n?n.length:0,p=this._values,m=p.getAxis()!==v.Axis.Row,h=this._spillSpatial,g=this._errorSpatial,_=this._notifyCalcStatus.size(),y=this._contentfulSpatial,b=[],x,S,w,T=d?[]:null;if(e&&e.tuples){x=e.tuples;let t=e.bounds;if(t?(S=ft(t,m),S.scope=a):S={colStart:-(2**53-1),rowStart:-(2**53-1),colEnd:2**53-1,rowEnd:2**53-1,scope:a},T){d&&b.push(S);let e={majorStart:0,minorStart:0,majorEnd:0,minorEnd:0},t=x.length;for(let n=0;n<t;n++){let t=x[n],r=t[0];e.majorStart=r,e.majorEnd=r;let i=t[1],o=i.length;for(let t=0;t<o;t++){let n=i[t];e.minorStart=n[0];let r=n[1];e.minorEnd=e.minorStart+r.length-1;let o=ft(e,m);o.scope=a,T&&l.search(o).length>0&&T.push(o)}}}w=Je(e.tuples,m,a)}let E=(e,t)=>{e&&this._notifySpillsInsert.push(e),t&&this._notifySpillsRemove.push(t)};if(r||x){let e;r&&(e=be(r,h,p,y,E,!1,!0,this._notifyValues,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})})),St(-1,r?[r]:t.EmptyArray,w,y,h,p,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})},this._notifyValues,E,this._notifyCalcStatus,g,m,!1,this._circularSpatial,this._calcStatusSpatial),r&&(p.delete(r),_e(g,r)),e?.(),x&&(p.setValues(x),qe(g,x,m))}let D=s.getScope(),O,k,A,j,M,ee=(e,t)=>{let n=e.rowStart,r=e.colStart;D&&(D.rowIndex=n,D.colIndex=r);let o=s.createFormulaBlock(a,c,t,n,r),l=new hi(e,a,o,s,this._unanchored),u=i?.arrayFixed;u&&u.colStart===r&&u.rowStart===n&&(W(l.getAnchorNode()).fixedRef={colStart:u.colStart,rowStart:u.rowStart,colEnd:u.colEnd,rowEnd:u.rowEnd},l.densify());let d={...e,scope:a,value:l};O||=[],O.push(d)},te=e=>{let t={...e,scope:a,value:null};A.insertNonOverlapping(t,{noMerge:!0,onUpdates(e,t,n){k||=[];for(let e=0;e<t.length;e++){let n=t[e];if(k.push(n),M)for(let e=M.length-1;e>=0;e--)M[e].value===n.value&&M.splice(e,1)}let r=e?e.length:0;for(let t=0;t<r;t++){let n=e[t];n.value!==null&&(M||=[],M.push(n))}}})},N=T?T.length:0,P;if(f>0){P=C(f);for(let e=0;e<f;e++){let t=n[e],r=t.value,i=o.sanitizeRange(t);P[e]=i,r!==null&&ee(i,r)}}let F=i?.cloneKey??null;(N>0||f>0)&&(A=s.getFormulas().clone(F));for(let e=0;e<N;e++)te(T[e]);for(let e=0;e<f;e++)te(P[e]);let ne=k?k.length:0;if(ne>0){let e=s.getDynamics(),t=null;for(let n=0;n<ne;n++){let r=k[n].value,i=e.get(r);i&&(j||=s.getPrecedents().clone(F),j.removeAll(i,X),t||=new Map(e),t.delete(r))}t&&s.setDynamics(t)}let re=[];if(O||k){j||=s.getPrecedents().clone(F),Zi(A,j,O,k),M&&$i(j,M,null);let e=O?this._joinInserted(A,j,O,e=>{b.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,scope:a})}):null;this._touchFormulas(k),this._touchFormulas(O),this._touchFormulas(M),this._touchFormulas(e);let t=M?function(e,...t){let n=[];if(!e)return n;for(let r=0;r<e.length;r++){let i=e[r];for(let e=0;e<t.length;e++){let r=t[e];if(r)for(let e=0;e<r.length;e++){let t=o.intersectRanges(i,r[e]);t&&n.push({...t,scope:i.scope})}}}return n}(k,T,P):k;St(-1,t,O,y,h,p,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})},this._notifyValues,E,this._notifyCalcStatus,g,m,!0,this._circularSpatial,this._calcStatusSpatial)}if(j&&s.setPrecedents(j),A&&(O||k||M)&&s.setFormulas(A),O)for(let e=0;e<O.length;e++){let t=O[e];re.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:a})}if(k)for(let e=0;e<k.length;e++){let t=k[e];re.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:a})}return this._notifyCalcStatus.size()!==_&&(s.getDeferred?.()?.noteRepaint(a),s.requestCalculateGrid(a)),b.length>0&&s.markDirty(b),re}_rederivePrecedentsNow(e){let t=this._container,n=t.getPrecedents().clone();$i(n,null,e);for(let t=0;t<e.length;t++)e[t].value.refreshPrecedents();$i(n,e,null),t.setPrecedents(n);let r=null;for(let n=0;n<e.length;n++){let i=e[n].value;!i.unanchored&&Yi(i,this._gridId,t)&&(r??=[]).push({...i.ref,scope:this._gridId})}r&&t.markDirty(r)}_joinInserted(e,t,n,r){let i=this._container,a=i.getDynamics(),o=a,s=this._calcStatusSpatial,c=e=>{let t=e.value;return!!t.formula&&!t.getAnchorNode().ext?.fixedRef},l=t=>e.search(t),u=e=>{let t=l(e);for(let n=0;n<t.length;n++)if(t[n].value===e.value)return!0;return!1},d=!1,f=e=>{let n=e.value,r=a.get(n);r&&(t.removeAll(r,X),a===o&&(a=new Map(a)),a.delete(n),d=!0),!d&&!s.isEmpty()&&s.search(e).length>0&&(d=!0)},p=null;for(let i=0;i<n.length;i++){let a=n[i];if(!c(a)||!u(a))continue;d=!1;let o=kt(l,a,(e,t,n,r)=>{if(!c(e)||!c(t))return;let i={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd};return e.value.getMerged(t.value,i,r)},(n,r)=>{for(let e=0;e<n.length;e++)f(n[e]);$i(t,null,n),e.removeAll(n,X),e.load([r]),$i(t,[r],null)});o!==a&&((p??=[]).push(o),d&&r(o))}return a!==o&&i.setDynamics(a),p}_clearAll(){this._contentfulSpatial.clear(),this._values.clear(),this._spillSpatial.clear(),this._errorSpatial.clear(),this._calcStatusSpatial.clear(),this._circularSpatial.clear(),this._notifyValues.clear(),this._notifyBlank=null,this._notifySpillsInsert=[],this._notifySpillsRemove=[],this._notifyFormats.clear(),this._notifyCalcStatus.clear(),this._touchedFormulas=[]}_clearFormulas(){let e=this._container,t=this._gridId,n=e.getFormulas().getSpatialAt(t)?.all();if(!n||n.length===0)return;let r=e.getFormulas().clone(),i=e.getPrecedents().clone();Zi(r,i,[],n);let a=e.getDynamics(),o=null;for(let e=0;e<n.length;e++){let t=n[e].value,r=a.get(t);r&&(o??=new Map(a),i.removeAll(r,X),o.delete(t))}e.setFormulas(r),e.setPrecedents(i),o&&e.setDynamics(o),e.bumpCalcEpochs(!0);let s=e.getVolatiles();if(s&&s.size>0)for(let e of Array.from(s))e.gridId===t&&s.delete(e)}_seedNow(e,t){this._clearFormulas(),this._clearAll();let n=e?.hiddenRows?.length?e.hiddenRows:null,r=e?.hiddenColumns?.length?e.hiddenColumns:null,i=e?.filtered??!1,a=e?.pivots?.length?e.pivots:null,o=e?.entireCoords??this._resized;n===this._hiddenRows&&r===this._hiddenColumns&&i===this._filtered&&a===this._pivots&&o===this._resized||(this._hiddenRows=n,this._hiddenColumns=r,this._filtered=i,this._pivots=a,this._resized=o,this._publishMaps());let s={cycleId:0,isFull:!0};if(!e)return s;this._isProcessingJSON=!0;let c=t?.full??!1;try{if(e.data){let t=e.data;this._values.setValues(t);let n=this._values.getAxis()===v.Axis.Column;qe(this._errorSpatial,t,n);let r=Je(t,n,this._gridId);this._contentfulSpatial.load(r)}let t=this._gridId,n=this._container,r=n.getPrecedents(),i=n.getFormulas(),a={...this.getEntireCoords(),scope:t},o=e.formulas;if(o){let l=e.formulaArray,u=new Set,d=new Set;if(l){let e=l.length;for(let t=0;t<e;t++){let e=l[t],n=e[0],r=we(n,a).split(`:`)[0];u.add(r);let i=Ye(e,a);i&&d.add(`${i.rowStart},${i.colStart}`)}}let f=o.length,p=Array(f),m=[],h=n.getRuntime(),g=this._context,_=n.getScope();_.colIndex=0,_.rowIndex=0,_.gridId=t;let v=n.isLegacyIntersect();for(let e=0;e<f;e++){let r=Ye(o[e],a);r.scope=t;let i=r.value,s=r.rowStart,c=r.colStart;_.colIndex=c,_.rowIndex=s;let l=v&&!(d.size>0&&d.has(`${s},${c}`)),f=n.createFormulaBlock(t,g,i,s,c,void 0,l),h=f.resolvedPrecedentsAt(s,c,!0,zi,Bi),b=h.length;b===1&&(f=f.wrapImplicit(s,c,u));let x=new hi(r,t,f,n,this._unanchored);x.fromLoad=!0,r.value=x,p[e]=r;let S=r.rowEnd,C=r.colEnd-c,w=S-s,T=[],E=f.getReferences(s,c);for(let e=0;e<b;e++){let n=h[e];if(y.isError(n))continue;let i=ve(E[e],Bi[e],zi[e]),a=i.$absColEnd,o=i.$absRowEnd,s={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd+(a?0:C),rowEnd:n.rowEnd+(o?0:w),scope:n.scope??t,value:{formulaEntry:r,formulaBlockWidth:C+1,formulaBlockHeight:w+1,index:e,$absColStart:i.$absColStart,$absColEnd:a,$absRowStart:i.$absRowStart,$absRowEnd:o}};T.push(n),m.push(s)}}if(i.load(p),r.load(m),n.bumpCalcEpochs(!0),s.formulaInserts=this._formulaRecords(p),l){let e=[],o=[],c=new Map,u=this._values,d=l.length;for(let n=0;n<d;n++){let r=Ye(l[n],a),s=r.value??`dynamic`,d=s===`error`,f=r.colStart,p=r.rowStart;Vi.colStart=f,Vi.rowStart=p,Vi.colEnd=f,Vi.rowEnd=p,Vi.scope=t;let m=i.search(Vi);if(m.length!==1)continue;let g=m[0].value,_=g.nodeAt(p,f),v=r.colEnd,b=r.rowEnd,x={colStart:f,rowStart:p,colEnd:v,rowEnd:b};s===`fixed`&&(W(_).fixedRef=x,g.densify()),_.cachedValue=d?y.BuiltIn.Spill:new Ve(h,u,x);let S={colStart:f,rowStart:p,colEnd:v,rowEnd:b,value:new de(x,0,s)};o.push(S),e.push({colStart:f,rowStart:p,colEnd:v,rowEnd:b,value:s}),Kt(c,_,x,_i)}if(this._spillSpatial.load(o),c.size>0){r.load(Array.from(c.values()).flat()),n.bumpCalcEpochs(!1);let e=new Map(n.getDynamics());for(let[t,n]of c)e.set(t,n);n.setDynamics(e)}e.length>0&&(s.spillInserts=e)}let b=!1,x=e.volatile,S=x?x.length:0;if(S>0){let e=n.getVolatiles(),t=t=>{e.add(t),t.state|=nr,t.block.calcOnLoad=!0},r=Array(S);for(let e=0;e<S;e++){let n=x[e],o=O(n,a);r[e]={...o};let s=i.search(o),c=s.length;for(let e=0;e<c;e++){let n=s[e];Dt(n,o,t)}}this._markDirtyRegionsNow(r),b=!0}let C=this._contentfulSpatial,w=!C.isEmpty(),T=null,E={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:t};for(let e=0;e<f;e++){let t=p[e];if(!t)continue;let n=(t.rowEnd-t.rowStart+1)*(t.colEnd-t.colStart+1),r=0;if(w){E.rowStart=t.rowStart,E.colStart=t.colStart,E.rowEnd=t.rowEnd,E.colEnd=t.colEnd;let e=C.search(E);for(let n=0;n<e.length;n++){let i=e[n];r+=(Math.min(i.rowEnd,t.rowEnd)-Math.max(i.rowStart,t.rowStart)+1)*(Math.min(i.colEnd,t.colEnd)-Math.max(i.colStart,t.colStart)+1)}}let i=r<n&&!this._isSavedSpill(t);i&&(t.value.uncalculated=!0),(i||t.value?.getError())&&(T??=[]).push({rowStart:t.rowStart,colStart:t.colStart,rowEnd:t.rowEnd,colEnd:t.colEnd})}if(T&&(this._markDirtyRegionsNow(T),b=!0),c&&f>0){let e=Array(f);for(let t=0;t<f;t++){let n=p[t];e[t]={rowStart:n.rowStart,colStart:n.colStart,rowEnd:n.rowEnd,colEnd:n.colEnd}}this._markDirtyRegionsNow(e),b=!0}b&&(n.isLoading()?n.requestCalculateGrid(t):this.calculate())}}catch(e){throw e}finally{this._isProcessingJSON=!1}return s}_isSavedSpill(e){let t={rowStart:e.rowStart,colStart:e.colStart,rowEnd:e.rowStart,colEnd:e.colStart},n=this._spillSpatial.search(t);for(let e=0;e<n.length;e++){let r=n[e];if(r.rowStart===t.rowStart&&r.colStart===t.colStart)return this._contentfulSpatial.search({rowStart:r.rowStart,colStart:r.colStart,rowEnd:r.rowEnd,colEnd:r.colEnd,scope:this._gridId}).length>0}return!1}_toJSONNow(e){let t=this._container.getFormulas().getSpatialAt(this._gridId)?.all(),r=t?t.length:0;r>0&&(t=Ut(t,n.Column,2,Ji),t.sort(o.rowFirstRangeComparator)),r=t?t.length:0;let i=this._hiddenRows,a=this._hiddenColumns,s=this._filtered;if(r===0&&!i&&!a&&!s)return null;let c={};i&&(c.hiddenRows=i),a&&(c.hiddenColumns=a),s&&(c.filtered=!0);let l=this._spillSpatial.all().filter(e=>e.value.getKind()!==`pivot`),u=l.length;if(u>1&&l.sort(o.rowFirstRangeComparator),r>0){let e=Array(r);for(let n=0;n<r;n++){let r=t[n];e[n]=r.value.toJSON(!1,r)}c.formulas=e}if(u>0){let e=this.getEntireCoords(),t=Array(u);for(let n=0;n<u;n++){let r=l[n],i=tt(r,e);t[n]=[i,r.value.getKind()]}c.formulaArray=t}let d=this._container.getVolatiles(),f=this._gridId,p=null;if(d.size>0){let e=d.values(),t=e.next(),n=this._values.getAxis()===v.Axis.Column,r=ue(!0);for(;!t.done;){let i=t.value;if(t=e.next(),i.gridId!==f||i.ext!==null&&i.ext.shownGroup!==0)continue;let a=i.colIndex,o=i.rowIndex,s=n?a:o,c=n?o:a;r.append(s,c)}p=r.done(!0)}let m=this._circularSpatial,h=this._calcStatusSpatial,g=l.filter(e=>e.value.getError());if(!m.isEmpty()||!h.isEmpty()||g.length>0){let e=p?p.slice():[],t=t=>{for(let n=0;n<t.length;n++){let r=t[n];e.push({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd})}};m.isEmpty()||t(m.all());let r=h.isEmpty()?[]:h.all().filter(e=>e.value===vt.CalcStatus.Working);r.length>0&&t(r),g.length>0&&t(g),p=Ut(e,n.Column,2)}let _=p?p.length:0;if(_>0){let e=Array(_);for(let t=0;t<_;t++){let n=p[t],r=tt(n,this.getEntireCoords());e[t]=r}c.volatile=e}return c}},Pi=new WeakMap,Fi=(e,t)=>{let n=e?.length??0;if(n!==(t?.length??0))return!1;for(let r=0;r<n;r++)if(e[r].min!==t[r].min||e[r].max!==t[r].max)return!1;return!0},Ii=(e,t)=>{for(let n=0;n<e.length;n++)if(o.isEqualRanges(e[n],t))return!0;return!1},Li=8,Ri={rowStart:0,colStart:0,rowEnd:0,colEnd:0},zi=[],Bi=[],Vi={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},Hi={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},Y={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Ui=Object.freeze({search:(e,n,r,i)=>i??t.EmptyArray,getBoundingRange:()=>null,isEmpty:()=>!0}),Wi={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Gi=[null],Ki=Object.freeze({full:!0}),qi=[];function X(e,t){return e.value===t.value}function Ji(e,t){let n=e[0].value?.formula,r=e[1].value?.formula;if(n&&r&&n.isEquals(r))return t}function Yi(e,t,n){let r=[e],i=new Set([t]);for(let e=0;e<r.length;e++){let t=r[e];if(t.hasVolatile())return!0;let a=t.getNamedIds();for(let e=0;e<a.length;e++){let t=a[e];if(i.has(t))continue;i.add(t);let o=n.getGrid(t)?.getFormulaBlockAt(0,0);o&&r.push(o)}}return!1}function Xi(e,t,n){let r=t.gridId;if(!r||!e.getNamedNodeInfo(r))return;let i=[r,...e.getNamedDependentNames(r)];for(let t=0;t<i.length;t++){let r=e.getNamedDependents(i[t]);for(let e=0;e<r.length;e++)n.push({...r[e]})}}function Zi(e,t,n,r){(n&&n.length!==0||r&&r.length!==0)&&($i(t,null,r),Qi(e,null,r),Qi(e,n,null),$i(t,n,null))}function Qi(e,t,n){(t&&t.length!==0||n&&n.length!==0)&&(n&&e.removeAll(n,X),t&&e.load(t))}function $i(e,t,n){let r=n?n.length:0;for(let t=0;t<r;t++){let r=n[t],i=r.value,a=i.registeredPrecedents;if(a){for(let t=0;t<a.length;t++)e.remove(a[t],X);i.registeredPrecedents=null}let o=i.ref,s=o.rowStart,c=o.colStart,l=i.formula.resolvedPrecedentsAt(s,c);if(!l)continue;let u=l.length;for(let t=0;t<u;t++){let n=l[t];if(n===null||y.isError(n))continue;Y.rowStart=n.rowStart,Y.colStart=n.colStart,Y.rowEnd=n.rowEnd,Y.colEnd=n.colEnd,Y.scope=n.scope??r.scope,qi.length=0;let i=e.search(Y,!1,!1,qi),a=i.length;for(let t=0;t<a;t++){let n=i[t],a=n.value.formulaEntry;a&&a.value===r.value&&n.value.index>=0&&e.remove(n,X)}}}let i=t?t.length:0;if(i===0)return;let a=[];for(let e=0;e<i;e++){let n=t[e],r=[],i=a.length;E(n,a,r),a.length>i&&(n.value.registeredPrecedents=a.slice(i))}e.load(a)}qi.fill(null,0,10);var ea=e=>{let t=!1;if(R.forEachLeaf(e,(e,n,r,i)=>{if(t||e instanceof He)return;let a=n+i-r;!0===e.isIRepeatingList&&(a=Math.min(a,n+e.getPeriod()-1));for(let r=n;!t&&r<=a;r++)t=I(e.at(r))}),!t)return e;let n=e.length,r=Array(n);for(let t=0;t<n;t++)r[t]=he(e.at(t));return new Ke.ArrayList(r)},ta=(e,t,n)=>{let r=n?.fetchedFrom;if(!e)return new it({source:{buffer:t},fetchedFrom:r});if(r){for(let t of e.getItems())if(t.getFetchedFrom()===r&&!t.isClosed())return t}return e.add({source:{buffer:t},fetchedFrom:r})},na=0,ra=1,ia=2,aa=3,oa=class{constructor(e,t,n,r,i,a=null,o=null,s=sa){this.state=na,this.latest=void 0,this._onCancel=null,this.id=e,this.executor=t,this.payload=n,this.site=r,this.owner=i,this._onMoved=a,this._onFinal=o,this._normalize=s}resolve(e,t){this.isOpen()&&(this.latest=e===void 0?null:this._normalize(e,t),this.state=ra,this._moved(),this._final())}reject(e){this.isOpen()&&(this.latest=y.isError(e)?e:new y.Value(`The call failed`,{cause:e}),this.state=ia,this._moved(),this._final())}onCancel(e){(this._onCancel??=[]).push(e)}get cancelled(){return this.state===aa}isOpen(){return this.state===na}close(){let e=this.isOpen();this.state=aa;let t=this._onCancel;if(this._onCancel=null,e&&t)for(let e of t)try{e()}catch(e){console.warn(`A deferred call's onCancel threw`,e)}}_moved(){Qe(),this._onMoved?.(this)}_final(){let e=this._onFinal;this._onFinal=null,e?.(this)}},sa=e=>e,ca=(e,t)=>Ct.fromJSON({type:e,data:t}),la=(e,t)=>globalThis.fetch(e,t),ua=()=>{throw Error(`getFormulaContext() needs a workbook being calculated`)},da=()=>Promise.reject(Error(`parseText() needs a workbook being calculated`)),fa=(e,t)=>ta(null,e,t),pa=class{constructor(e,t,n,r=null,i=100,a=sa,o,s=null){this._nextId=1,this._calls=new Map,this._holders=!1,this._current=[],this._made=[],this._batch=new Map,this._states=new Map,this._moved=new Set,this._settleTimer=null,this._settledAt=0,this._repaintGrids=new Set,this._settleDirty=[],this._serving=!1,this._external=!1,this.previous=void 0,this._waiters=new Set,this._scope=e,this._onCountsChange=s,this._heldAt=t,this._getRandom=n,this._onSettle=r,this._settleWindow=i,this._normalize=a;let c=this._moved;this._onMoved=e=>{c.add(e),this._requestSettle()};let l=this._states,u=null;this._deferContext={getRandom:()=>this._getRandom(),getState:e=>{let t=u;if(l.has(t))return l.get(t);let n=e();return l.set(t,n),n},byPayload:ga,createRichData:o?.createRichData??ca,addResource:o?.addResource??fa,fetch:o?.fetch??la,getFormulaContext:o?.getFormulaContext??ua,parseText:o?.parseText??da};let d=this._deferContext.fetch;this._reloadContext={...this._deferContext,fetch:(e,t)=>d(e,{...t,cache:`reload`})},this._setCurrent=e=>{u=e};let f=this._calls;this._onFinal=e=>{f.delete(e.id),this._wake()}}getOpenCount(){return this._calls.size}getCallsOf(e){let t=[];for(let n of this._calls.values())n.owner?.gridId===e&&t.push(n);return t}hasSettleWork(){return this._settleTimer!==null||this._moved.size>0||this._settleDirty.length>0}whenChanged(e){return new Promise(t=>{let n=this._waiters,r=()=>{clearTimeout(i),n.delete(r),t()},i=setTimeout(r,Math.max(0,e));n.add(r)})}_wake(){if(this._waiters.size===0)return;let e=Array.from(this._waiters);this._waiters.clear();for(let t=0;t<e.length;t++)e[t]()}cancel(e){let t=[];for(let n of this._calls.values()){let r=n.owner;(!0===e||r!==null&&this._coversCell(e,r.gridId??null,r.rowIndex,r.colIndex))&&t.push(n)}return this.closeCalls(t),t}closeCalls(e){let t=!1;for(let n of e)n.state!==aa&&(this._calls.delete(n.id),this._moved.delete(n),n.close(),t=!0);t&&(this._wake(),this._onCountsChange?.())}hasHolders(){return this._holders}getCall(e){return this._calls.get(e)}takeMoved(){let e=Array.from(this._moved);return this._moved.clear(),e}noteRepaint(e){this._repaintGrids.add(e)}addSettleDirty(e){for(let t=0;t<e.length;t++)this._settleDirty.push(e[t])}takeSettleDirty(){if(this._settleDirty.length===0)return this._settleDirty;let e=this._settleDirty;return this._settleDirty=[],e}takeRepaintGrids(){if(this._repaintGrids.size===0)return[];let e=Array.from(this._repaintGrids);return this._repaintGrids.clear(),e}_requestSettle(){if(this._settleTimer!==null||this._onSettle===null)return;let e=Math.max(0,this._settleWindow-(Date.now()-this._settledAt));this._settleTimer=setTimeout(()=>{this._settleTimer=null,this._settledAt=Date.now(),this._onSettle?.(),this._wake(),this._onCountsChange?.()},e)}newHolder(e,t){return this._holders=!0,new Le(e,t.calls,t.direct)}defer(e,t,n=null,r=!1){let i=this._scope,a=i.deferOrdinal++;i.deferCount++;let o=this._siteCall(a),s=o!==void 0&&_a(o.payload,t)&&(n===null?o.executor===e:o.site===n);if(this.previous=s?o.latest:void 0,s&&!r&&(this._serving||o.isOpen()))return this._current[a]=o,i.deferServed=o,i.node!==null&&(o.owner=i.node),o;i.deferServed=null;let c=new oa(this._nextId++,e,t,n,i.node,this._onMoved,this._onFinal,this._normalize);return this._calls.set(c.id,c),this._batchFor(e).push(c),this._current[a]=c,this._made.push(c),null}endEvaluation(){let e=this._scope,t=e.deferOrdinal,n=e.deferRoot&&t===1;e.deferOrdinal=0,e.deferRoot=!1,e.deferServed=null;let r=this._current.slice(0,t);return this._current.length=0,this._made.length=0,{calls:r,direct:n}}abandonEvaluation(){this._scope.deferOrdinal=0,this._scope.deferRoot=!1,this._scope.deferServed=null;for(let e of this._made){this._calls.delete(e.id);let t=this._batch.get(e.executor),n=t?t.indexOf(e):-1;n>=0&&t.splice(n,1)}this._current.length=0,this._made.length=0}flush(){let e=this._external?this._reloadContext:this._deferContext;this._serving=!1,this._external=!1;let t=this._batch;if(t.size!==0){this._batch=new Map,this._onCountsChange?.();for(let[n,r]of t){let t=r.filter(e=>e.isOpen());if(t.length===0)continue;let i;this._setCurrent(n);try{i=n(t,e)}catch(e){ma(t,e);continue}finally{this._setCurrent(null)}i&&typeof i.then==`function`&&i.then(void 0,e=>ma(t,e))}}}close(){this._settleTimer!==null&&(clearTimeout(this._settleTimer),this._settleTimer=null),this._moved.clear(),this._repaintGrids.clear(),this._settleDirty=[],this._batch.clear();let e=Array.from(this._calls.values());this._calls.clear(),this._current.length=0,this._made.length=0,this._states.clear();for(let t of e)t.close();this._wake(),e.length>0&&this._onCountsChange?.()}setServing(e){this._serving=e}setExternal(e){this._external=e}_coversCell(e,t,n,r){return!0===e||t!==null&&(typeof e==`string`?t===e:t===e.scope&&n>=e.rowStart&&n<=e.rowEnd&&r>=e.colStart&&r<=e.colEnd)}_batchFor(e){let t=this._batch.get(e);return t||this._batch.set(e,t=[]),t}_siteCall(e){let t=this._scope,n=t.node;if(!n||!this._holders||!t.gridId)return;let r=this._heldAt(t.gridId,t.rowIndex,t.colIndex);return r===null&&I(n.cachedValue)&&(r=n.cachedValue),r===null?void 0:r.calls[e]}},ma=(e,t)=>{for(let n of e)n.isOpen()&&n.reject(t)},ha=Symbol(`-0`),ga=async(e,t)=>{let n=new Map,r=[],i=[];for(let t of e){let e=t.payload;if(typeof e==`object`&&e){let n=r.find(t=>_a(t.payload,e));if(n)n.group.push(t);else{let n={payload:e,group:[t]};r.push(n),i.push(n)}continue}let a=Object.is(e,-0)?ha:e,o=n.get(a);if(o)o.push(t);else{let r={payload:e,group:[t]};n.set(a,r.group),i.push(r)}}await Promise.all(i.map(async({payload:e,group:n})=>{try{await t(e,n)}catch(e){for(let t of n)t.reject(e)}}))},_a=(e,t)=>{if(Object.is(e,t))return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`)return!1;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(Object.getPrototypeOf(e)!==Object.prototype||Object.getPrototypeOf(t)!==Object.prototype))return!1;let r=Object.keys(e),i=Object.keys(t);if(r.length!==i.length)return!1;for(let n of r)if(!Object.prototype.hasOwnProperty.call(t,n)||!Object.is(e[n],t[n]))return!1;return!0},va=32768,ya=(e,t)=>e*va+t,ba=class{constructor(){this.size=0,this._keys=new Float64Array,this._values=[],this._order=new Int32Array,this._mask=-1}_slotOf(e,t,n){let r=this._keys,i=this._mask,a=e+Math.imul(t,2654435761)&i;for(let e=r[a];e!==n&&e!==-1;e=r[a])a=a+1&i;return a}get(e,t){if(this.size!==0)return this._values[this._slotOf(e,t,ya(e,t))]}set(e,t,n){2*(this.size+1)>this._mask+1&&this._grow();let r=ya(e,t),i=this._slotOf(e,t,r),a=this._values[i];return a===void 0&&(this._keys[i]=r,this._order[this.size++]=i),this._values[i]=n,a}clear(){let e=this._order,t=this._keys,n=this._values;for(let r=0;r<this.size;r++){let i=e[r];t[i]=-1,n[i]=void 0}this.size=0}anyAbsentFrom(e,t){for(let n=e;n<this.size;n++){let e=this._keys[this._order[n]],r=Math.floor(e/va);if(t.getValueAt(r,e-r*va)===void 0)return!0}return!1}hasErrorIn(e,t,n,r){for(let i=0;i<this.size;i++){let a=this._order[i];if(!y.isError(this._values[a]))continue;let o=this._keys[a],s=Math.floor(o/va),c=o-s*va;if(s>=e&&s<=n&&c>=t&&c<=r)return!0}return!1}_grow(){let e=this._keys,t=this._values,n=this._order,r=this.size,i=Math.max(64,2*(this._mask+1));this._keys=new Float64Array(i).fill(-1),this._values=mt(i),this._order=new Int32Array(i),this._mask=i-1;for(let i=0;i<r;i++){let r=e[n[i]],a=Math.floor(r/va),o=this._slotOf(a,r-a*va,r);this._keys[o]=r,this._values[o]=t[n[i]],this._order[i]=o}}},xa=class{constructor(e,t,n){this._pending=new ba,this._unobserved=0,this.observed=!1,this._errors=0,this._uncovered=!1,this._coverChecked=0,this._substitutedFrom=0,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1,this._demand=new Map,this._demandErrors=0,this._demandRowStart=2**53-1,this._demandRowEnd=-1,this._demandColStart=2**53-1,this._demandColEnd=-1,this._anyRowStart=2**53-1,this._anyRowEnd=-1,this._anyColStart=2**53-1,this._anyColEnd=-1,this._inner=e,this._committed=t,this._flush=n,this._isColumn=e.getAxis()===v.Axis.Column}get isPendingOverlay(){return!0}getInner(){return this._inner}get size(){return this._pending.size+this._unobserved}get demandSize(){return this._demand.size}push(e,t,n){if(this.observed){let r=this._pending.set(e,t,n??null);r!==void 0&&y.isError(r)&&this._errors--,y.isError(n)&&this._errors++}else this._unobserved++;e<this._rowStart&&(this._rowStart=e),e>this._rowEnd&&(this._rowEnd=e),t<this._colStart&&(this._colStart=t),t>this._colEnd&&(this._colEnd=t),this._growAny(e,t)}pushDemand(e,t,n){n??=null;let r=ya(e,t),i=this._demand,a=i.get(r);a!==void 0&&y.isError(a)&&this._demandErrors--,y.isError(n)&&this._demandErrors++,i.set(r,n),this._inner.getValueAt(e,t)===void 0&&this._inner.setValueAt(e,t,n),e<this._demandRowStart&&(this._demandRowStart=e),e>this._demandRowEnd&&(this._demandRowEnd=e),t<this._demandColStart&&(this._demandColStart=t),t>this._demandColEnd&&(this._demandColEnd=t),this._growAny(e,t)}takeDemand(e,t){let n=this._demand;if(n.size===0)return;let r=ya(e,t),i=n.get(r);i!==void 0&&(y.isError(i)&&this._demandErrors--,n.delete(r),n.size===0&&this._resetDemand())}commitDemand(){this._demand.size!==0&&(this._writeDemandIn(null),this._demand.clear(),this._resetDemand())}reset(){this.size!==0&&(this._unobserved=0,this._pending.clear(),this._errors=0,this._uncovered=!1,this._coverChecked=0,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1,this._resetAny())}_resetDemand(){this._demandErrors=0,this._demandRowStart=2**53-1,this._demandRowEnd=-1,this._demandColStart=2**53-1,this._demandColEnd=-1,this._resetAny()}_growAny(e,t){e<this._anyRowStart&&(this._anyRowStart=e),e>this._anyRowEnd&&(this._anyRowEnd=e),t<this._anyColStart&&(this._anyColStart=t),t>this._anyColEnd&&(this._anyColEnd=t)}_resetAny(){this._anyRowStart=Math.min(this._rowStart,this._demandRowStart),this._anyRowEnd=Math.max(this._rowEnd,this._demandRowEnd),this._anyColStart=Math.min(this._colStart,this._demandColStart),this._anyColEnd=Math.max(this._colEnd,this._demandColEnd)}observe(){this.observed||(this.observed=!0,this._unobserved>0&&this._flush())}intersects(e,t,n,r){return e<=this._anyRowEnd&&n>=this._anyRowStart&&t<=this._anyColEnd&&r>=this._anyColStart}_pendingIntersects(e,t,n,r){return e<=this._rowEnd&&n>=this._rowStart&&t<=this._colEnd&&r>=this._colStart}hasErrorIn(e){let t=e.rowStart,n=e.colStart,r=e.rowEnd,i=e.colEnd;return this._unobserved>0&&this._pendingIntersects(t,n,r,i)&&this.observe(),this._committed.hasErrorIn(e)?!this.intersects(t,n,r,i)||Sa(this,e):!!(this._errors>0&&this._pendingIntersects(t,n,r,i)&&this._pending.hasErrorIn(t,n,r,i))||this._demandErrors>0&&t<=this._demandRowEnd&&r>=this._demandRowStart&&n<=this._demandColEnd&&i>=this._demandColStart&&function(e,t,n,r,i){for(let[a,o]of e){if(!y.isError(o))continue;let e=Math.floor(a/va),s=a-e*va;if(e>=t&&e<=r&&s>=n&&s<=i)return!0}return!1}(this._demand,t,n,r,i)}_boundsIntersect(e){return!e||this._pendingIntersects(e.rowStart??-(2**53-1),e.colStart??-(2**53-1),e.rowEnd??2**53-1,e.colEnd??2**53-1)}_writeDemandIn(e){if(this._demand.size===0)return;let t=e?.rowStart??-(2**53-1),n=e?.colStart??-(2**53-1),r=e?.rowEnd??2**53-1,i=e?.colEnd??2**53-1;if(t>this._demandRowEnd||r<this._demandRowStart||n>this._demandColEnd||i<this._demandColStart)return;let a=this._inner;for(let[e,o]of this._demand){let s=Math.floor(e/va),c=e-s*va;s>=t&&s<=r&&c>=n&&c<=i&&a.setValueAt(s,c,o)}}_layered(e,t){let n=this._pending.get(e,t);return n===void 0?this._demand.size>0?this._demand.get(ya(e,t)):void 0:n}_coverFor(e){if(!this._boundsIntersect(e))return;this.observe();let t=this._pending;!this._uncovered&&this._coverChecked<t.size&&(this._uncovered=t.anyAbsentFrom(this._coverChecked,this._inner),this._coverChecked=t.size),this._uncovered&&this._flush()}_flushIfPendingIn(e){this.size>0&&this._boundsIntersect(e)&&this._flush(),this._writeDemandIn(e)}_inBounds(e,t){return e>=this._anyRowStart&&e<=this._anyRowEnd&&t>=this._anyColStart&&t<=this._anyColEnd}_isEmpty(){return this._pending.size===0&&this._demand.size===0}_substituteRun(e,t,n,r,i){let a=this._isColumn,o=a?this._anyColStart:this._anyRowStart,s=a?this._anyColEnd:this._anyRowEnd;if(e<o||e>s)return n;let c=Math.max(t,r),l=Math.min(t+n.length-1,i),u=Math.max(c,a?this._anyRowStart:this._anyColStart),d=Math.min(l,a?this._anyRowEnd:this._anyColEnd),f=null;for(let r=u;r<=d;r++){let i=a?this._layered(r,e):this._layered(e,r);if(i!==void 0){if(f===null){let e=l-c+1,r=c-t;f=Array(e);for(let t=0;t<e;t++)f[t]=n.at(r+t);this._substitutedFrom=c}f[r-c]=i}}return f??n}getValueAt(e,t){if(this._inBounds(e,t)){this._unobserved>0&&this._pendingIntersects(e,t,e,t)&&this.observe();let n=this._layered(e,t);if(n!==void 0)return n}return this._inner.getValueAt(e,t)}getRuns(e){this._coverFor(e?.bounds);let t=this._inner.getRuns(e);if(this._isEmpty())return t;let n=e?.bounds,r=(this._isColumn?n?.rowStart:n?.colStart)??-(2**53-1),i=(this._isColumn?n?.rowEnd:n?.colEnd)??2**53-1,a={[Symbol.iterator]:()=>a,next:()=>{let e=t.next();if(e.done)return e;let n=e.value,a=this._substituteRun(n[0],n[1],n[2],r,i);return a===n[2]?e:{done:!1,value:[n[0],this._substitutedFrom,a]}}};return a}entries(e){this._coverFor(e?.bounds);let t=this._inner.entries(e);if(this._isEmpty())return t;let n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);if(n.done)return n;let r=n.value,i=r[0];if(this._inBounds(i.rowIndex,i.colIndex)){let e=this._layered(i.rowIndex,i.colIndex);e!==void 0&&(r[1]=e)}return n}};return n}values(e){if(this._coverFor(e?.bounds),this._isEmpty())return this._inner.values(e);let t=this.entries(e),n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);return n.done?{done:!0,value:void 0}:{done:!1,value:n.value[1]}}};return n}keys(e){return this._coverFor(e?.bounds),this._inner.keys(e)}getValues(e){return this._flushIfPendingIn(e),this._inner.getValues(e)}copyTo(e,t,n){this._flushIfPendingIn(n),this._inner.copyTo(e,t,n)}getAxis(){return this._inner.getAxis()}getCount(){return this._coverFor(null),this._inner.getCount()}getCoords(){return this._coverFor(null),this._inner.getCoords()}getMaxCoords(){return this._inner.getMaxCoords?.()??null}clone(e){return this._flush(),this._writeDemandIn(null),this._inner.clone(e)}cloneEmpty(e){return this._inner.cloneEmpty(e)}setValues(e){return this._commitAll(),this._inner.setValues(e),this}setValueAt(e,t,n){this._commitAll(),this._inner.setValueAt(e,t,n)}delete(e){return this._commitAll(),this._inner.delete?.(e)??!1}clear(){this._commitAll(),this._inner.clear?.()}shift(e,t){return this._commitAll(),this._inner.shift?.(e,t)??!1}_commitAll(){this._flush(),this.commitDemand()}get[Symbol.toStringTag](){return`[PendingOverlayGrid]`}};function Sa(e,t){let n=e.values({bounds:t});for(let e=n.next();!e.done;e=n.next())if(y.isError(e.value))return!0;return!1}var Ca={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},wa={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},Ta=(e,t)=>e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex,Ea=(e,t)=>e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex,Da=(e,t,n)=>e.rowEnd<t?2:+(e.rowEnd===t&&e.colEnd<n),Oa=(e,t,n)=>e.colEnd<n?2:+(e.colEnd===n&&e.rowEnd<t),ka=(e,t,n,r,i,a,o,s)=>{Ca.rowStart=t,Ca.rowEnd=n,Ca.colStart=r,Ca.colEnd=i,Ca.scope=a;let c=s.search(Ca);for(let a=0;a<c.length;a++){let s=o.get(c[a].value);s!==void 0&&s!==e&&(t>s.rowMax||n<s.rowMin||r>s.colMax||i<s.colMin||(s.readers.push(e),e.waitingOn++))}},Aa=(e,t,n)=>n===e.nodes[0].gridId&&t.rowStart<=e.rowMax&&t.rowEnd>=e.rowMin&&t.colStart<=e.colMax&&t.colEnd>=e.colMin,ja=32768,Ma=(e,t)=>e*ja+t,Na=class{constructor(e,t){this._map=new Map,this._errors=0,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1,this._inner=e,this._committed=t,this._isColumn=e.getAxis()===v.Axis.Column}get isWhatIfLayer(){return!0}getInner(){return this._inner}get size(){return this._map.size}set(e,t,n){let r=Ma(e,t),i=this._map,a=i.get(r);a!==void 0&&y.isError(a)&&this._errors--,y.isError(n)&&this._errors++,i.set(r,n??null),e<this._rowStart&&(this._rowStart=e),e>this._rowEnd&&(this._rowEnd=e),t<this._colStart&&(this._colStart=t),t>this._colEnd&&(this._colEnd=t)}clear(){this._map.size!==0&&(this._map.clear(),this._errors=0,this._rowStart=2**53-1,this._rowEnd=-1,this._colStart=2**53-1,this._colEnd=-1)}intersects(e,t,n,r){return e<=this._rowEnd&&n>=this._rowStart&&t<=this._colEnd&&r>=this._colStart}hasErrorIn(e){if(this._committed.hasErrorIn(e)&&(!this.intersects(e.rowStart,e.colStart,e.rowEnd,e.colEnd)||Sa(this,e)))return!0;if(this._errors===0||!this.intersects(e.rowStart,e.colStart,e.rowEnd,e.colEnd))return!1;for(let[t,n]of this._map){if(!y.isError(n))continue;let r=Math.floor(t/ja),i=t-r*ja;if(r>=e.rowStart&&r<=e.rowEnd&&i>=e.colStart&&i<=e.colEnd)return!0}return!1}_inBounds(e,t){return e>=this._rowStart&&e<=this._rowEnd&&t>=this._colStart&&t<=this._colEnd}_substituteRun(e,t,n){let r=this._isColumn,i=r?this._colStart:this._rowStart,a=r?this._colEnd:this._rowEnd;if(e<i||e>a)return n;let o=r?this._rowStart:this._colStart,s=r?this._rowEnd:this._colEnd,c=n.length,l=t+c-1;if(l<o||t>s)return n;let u=Math.max(t,o),d=Math.min(l,s),f=null,p=this._map;for(let i=u;i<=d;i++){let a=p.get(r?Ma(i,e):Ma(e,i));if(a!==void 0){if(f===null){f=Array(c);for(let e=0;e<c;e++)f[e]=n.at(e)}f[i-t]=a}}return f??n}getValueAt(e,t){if(this._inBounds(e,t)){let n=this._map.get(Ma(e,t));if(n!==void 0)return n}return this._inner.getValueAt(e,t)}getRuns(e){let t=this._inner.getRuns(e);if(this._map.size===0)return t;let n={[Symbol.iterator]:()=>n,next:()=>{let e=t.next();if(e.done)return e;let n=e.value,r=this._substituteRun(n[0],n[1],n[2]);return r===n[2]?e:{done:!1,value:[n[0],n[1],r]}}};return n}entries(e){let t=this._inner.entries(e);if(this._map.size===0)return t;let n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);if(n.done)return n;let r=n.value,i=r[0];if(this._inBounds(i.rowIndex,i.colIndex)){let e=this._map.get(Ma(i.rowIndex,i.colIndex));e!==void 0&&(r[1]=e)}return n}};return n}values(e){if(this._map.size===0)return this._inner.values(e);let t=this.entries(e),n={[Symbol.iterator]:()=>n,next:e=>{let n=t.next(e);return n.done?{done:!0,value:void 0}:{done:!1,value:n.value[1]}}};return n}keys(e){return this._inner.keys(e)}getValues(e){let t=this.getRuns(e?{bounds:e}:void 0),n=t.next();if(n.done)return null;let r=new Lt.Builder;for(;!n.done;)r.pushMultipleAt(n.value[0],n.value[1],n.value[2]),n=t.next();return r.build()}copyTo(e,t,n){let r=this.getValues(n);if(!r)return;let i=this._isColumn,a=r.tuples,o=t.rowIndex-n.rowStart,s=t.colIndex-n.colStart;for(let t=0;t<a.length;t++){let n=a[t][0],r=a[t][1];for(let t=0;t<r.length;t++){let a=r[t][0],c=r[t][1];for(let t=0;t<c.length;t++){let r=(i?a+t:n)+o,l=(i?n:a+t)+s;e.setValueAt(r,l,c.at(t))}}}}getAxis(){return this._inner.getAxis()}getCount(){return this._inner.getCount()}getCoords(){return this._inner.getCoords()}getMaxCoords(){return this._inner.getMaxCoords?.()??null}clone(e){throw Error(`A what-if layer is not cloned.`)}cloneEmpty(e){return this._inner.cloneEmpty(e)}setValues(e){throw Error(`A what-if layer is read-only.`)}setValueAt(e,t,n){throw Error(`A what-if layer is read-only.`)}delete(e){throw Error(`A what-if layer is read-only.`)}shift(e,t){throw Error(`A what-if layer is read-only.`)}get[Symbol.toStringTag](){return`[WhatIfLayer]`}},Pa=class{constructor(e,t){this.members=new Set,this.downstream=new Set,this._memberEntry=null,this._downstreamEntry=null,this._iteration=null,this._host=e,this._cycleId=t}getCycleId(){return this._cycleId}isEmpty(){return this.members.size===0&&this.downstream.size===0}getEntry(e){return e?(this._memberEntry||={cycle:this,kind:`member`},this._memberEntry):(this._downstreamEntry||={cycle:this,kind:`downstream`},this._downstreamEntry)}setIteration(e){this._iteration=e}getRepresentative(){let e=this._liveMembers();return e.length>0?this._toCoords(e[0]):null}getMembers(){return this._liveMembers().map(e=>this._toCoords(e))}getMemberCount(){return this._countLive(this.members)}getDownstreamCount(){return this._countLive(this.downstream)}isMember(e){return this._memberAt(e)!==null}getPath(e){let t=this._memberAt(e);if(!t)return[];let n=this.members,r=[t],i=t.ext.cycleNext;for(;i&&i!==t&&r.length<n.size&&n.has(i)&&this._host.isLiveNode(i);)r.push(i),i=i.ext.cycleNext;return r.map(e=>this._toCoords(e))}_memberAt(e){for(let t of this.members)if(t.rowIndex===e.rowIndex&&t.colIndex===e.colIndex&&this._host.isLiveNode(t)&&(e.scope===void 0||e.scope===this._scopeOf(t)))return t;return null}isIterative(){return this._iteration!==null}isConverged(){return this._iteration?.converged??!1}getIterationCount(){return this._iteration?.iterationCount??0}getLastChange(){return this._iteration?.lastChange??0}getPreviousChange(){return this._iteration?.previousChange??NaN}_liveMembers(){let e=[];for(let t of this.members)this._host.isLiveNode(t)&&e.push(t);return e.sort(Fa),e}_countLive(e){let t=0;for(let n of e)this._host.isLiveNode(n)&&t++;return t}_scopeOf(e){return(e.gridId?this._host.resolveScope(e.gridId):void 0)??null}_toCoords(e){return{rowIndex:e.rowIndex,colIndex:e.colIndex,scope:this._scopeOf(e)}}};function Fa(e,t){return e.gridId===t.gridId?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.gridId===null?-1:t.gridId===null?1:e.gridId.localeCompare(t.gridId)}var Ia=class{constructor(e,t){this._circularNodesLength=0,this._demandBatch=[],this._taintGroup=0,this._iterate=null,this._demandActive=!1,this._iterHitsLength=0,this._iterMembersLength=0,this._iterDownstreamLength=0,this._openGroups=new Map,this._groupAlias=new Map,this._sweeping=!1,this._iterSorted=!1,this._sweepIndex=-1,this._deferredLength=0,this._passActive=!1,this._settlePass=!1,this._loadPass=!1,this._spillHolder=null,this._passCycleId=0,this._passMarkId=0,this._flush=null,this._overlays=null,this._whatIf=null,this._exceptTables=!1,this._skippedTables=new Set,this._fallbackDirty=null,this._cycles=new Map,this._cycleGroupNext=0,this._cycleEpoch=0,this._demandStats={evaluations:0,retries:0},this._planStats={formulaCacheHits:0,formulaCacheMisses:0,passes:0,fastEligible:0,fastHits:0,closureEligible:0,closureHits:0,stampedPlans:0,blockOrdered:0,closureAssertFailures:0,planAssertFailures:0,dependentsAssertFailures:0,dependentsCacheHits:0,dependentsCacheMisses:0,evaluated:0,discoveryMs:0,inDegreeMs:0,kahnMs:0,evaluateMs:0},this.planCacheMode=`on`,this._planIdNext=0,this._lastPlanId=0,this._lastStampedLength=0,this._lastStampedOrderedLength=0,this._planMemos=[{seeds:[],seedsLength:0,plan:[],planLength:0,epoch:-1,used:0,cycleFree:!1,cycleEpoch:-1,demandStart:0},{seeds:[],seedsLength:0,plan:[],planLength:0,epoch:-1,used:0,cycleFree:!1,cycleEpoch:-1,demandStart:0}],this._planMemoClock=0,this._gridUpdates=null,this._addDynamicPrecedent=null,this.doCollectVolatileCalcs=(e,t,n,r,i)=>{let a=r.values,o=r.length;if(!n||n.size===0)return o;let s=o,c=new Map,l=n=>{n.markId=t,n.cycleId=e,a[s++]=n};return n.forEach(n=>{if(n.markId===t&&n.cycleId===e||!(e=>{let t=e.block;if(!t||t.unanchored)return!1;let n=c.get(t);if(n!==void 0)return n;no.colStart=no.colEnd=e.colIndex,no.rowStart=no.rowEnd=e.rowIndex,no.scope=e.gridId;let r=i.search(no),a=!1;for(let e=0;!a&&e<r.length;e++)a=r[e].value===t;return c.set(t,a),a})(n))return;let r=n.block;if(r.isBlankAware(e)){let i=r.getTouched(e,t),a=r.representative;if(a===null||a.markId===t&&a.cycleId===e||l(a),n===a||!(Va(i.touched,n.rowIndex,n.colIndex)||r.blankPaged&&Va(r.getDemandedBlank(),n.rowIndex,n.colIndex)))return}l(n)}),r.length=s,s},this.doCollectDirtyCalcs=(e,t,n,r,i,a,o)=>{let s=r.values,c=r.length,l=n=>{n.cycleId===e&&n.markId===t||(s[c++]=n,n.markId=t,n.cycleId=e)},u=(n,r,i,a,o)=>{if(n.unanchored)return;let s=n.ref;if(n.isBlankAware(e)){let c=n.getTouched(e,t),u=c.touched,f=u.length;for(let e=0;e<f;e++){let t=u[e],c=Math.max(r,t.rowStart-s.rowStart),d=Math.min(i,t.rowEnd-s.rowStart);if(c>d)continue;let f=Math.max(a,t.colStart-s.colStart),p=Math.min(o,t.colEnd-s.colStart);f>p||n.mintNodesIn(s.rowStart+c,s.rowStart+d,s.colStart+f,s.colStart+p,l)}if(n.blankPaged)return void d(n,r,i,a,o);let p=n.representative;p!==null&&Ra(c.blank,s,r,i,a,o)&&l(p)}else n.mintNodesIn(s.rowStart+r,s.rowStart+i,s.colStart+a,s.colStart+o,l)},d=(e,t,n,r,i)=>{let a=e.ref,o=a.rowStart+t,s=a.rowStart+n,c=a.colStart+r,u=a.colStart+i,d=e.getDemandedBlank();for(let t=0;t<d.length;t++){let n=d[t],r=Math.max(o,n.rowStart),i=Math.min(s,n.rowEnd),a=Math.max(c,n.colStart),f=Math.min(u,n.colEnd);r<=i&&a<=f&&e.mintNodesIn(r,i,a,f,l)}let f=e.getTouchedCached().blank,p=[];for(let e=0;e<f.length;e++){let t=f[e],n=Math.max(o,t.rowStart),r=Math.min(s,t.rowEnd),i=Math.max(c,t.colStart),a=Math.min(u,t.colEnd);n<=r&&i<=a&&p.push({colStart:i,rowStart:n,colEnd:a,rowEnd:r})}if(p.length===0)return;let m=this._container.getIncrementalUpdates(e.gridId);m&&Ba(e,p,m)},f=e=>{let t=e.ref;u(e,0,t.rowEnd-t.rowStart,0,t.colEnd-t.colStart)},p=n.length;for(let e=0;e<p;e++){let t=n[e];xo.length=0;let r=xo;a.search(t,!1,!1,r);let s=r.length;i.search(t,!1,!1,r);let c=r.length;if(c===0)continue;let l=t.colStart,d=t.rowStart,p=t.colEnd-l,m=t.rowEnd-d;for(let e=0;e<s;e++){let t=r[e],n=t.value;if(n.index<0){o.push(t),f(n.formulaEntry.value);continue}let i=n.formulaEntry.value,a=i.ref,s=a.colEnd-a.colStart,c=a.rowEnd-a.rowStart,h=t.colEnd-t.colStart-s,g=t.rowEnd-t.rowStart-c,_=0,v=c,y=0,b=s,x=d-t.rowStart,S=l-t.colStart;n.$absRowEnd||(_=Math.min(Math.max(x-g,0),c)),n.$absRowStart||(v=Math.min(x+m,c)),n.$absColEnd||(y=Math.min(Math.max(S-h,0),s)),n.$absColStart||(b=Math.min(p+S,s)),u(i,_,v,y,b)}for(let e=s;e<c;e++){let t=r[e],n=t.value,i=n.ref,a=i.colEnd-i.colStart,o=i.rowEnd-i.rowStart,s=d-t.rowStart,c=l-t.colStart;u(n,Math.min(Math.max(s,0),o),Math.min(s+m,o),Math.min(Math.max(c,0),a),Math.min(p+c,a))}}return r.length=c,c},this._container=e,this._context=t,this._cycleHost={isLiveNode:e=>this.isLiveNode(e),resolveScope:t=>e.resolveScope(t)},this._passHook=(e,t,n,r,i,a)=>this._onPassRead(e,t,n,r,i,!0===a),this._taintDownstream=e=>{if((e.state&K)!==vr)return;e.state=e.state&~G|tr|gr|yr;let t=W(e);t.cycleGroup=this._taintGroup,t.demandValue=mo(e),this._addCircular(e)}}execute(e,t,n){let{isFullCalc:r,calcCoords:i,gridId:a,scopeGridId:o}=t,s=!0===t.settle,{gridsAll:c,formulaSpatial:l,dirtySpatial:u,oldVolatiles:d}=n,f=this._container,p=e=>f.getIncrementalUpdates(e),m=f.getPrecedents(),h=m,g=f.getDynamics(),_=g,v=new Map;this._gridUpdates=v,this._resetCircular(),this._iterate=t.iterate??null,this._exceptTables=!0===t.exceptTables,this._skippedTables.clear(),this._context._setDynamicReadHook(this._passHook),this._passActive=!0,this._settlePass=s,this._loadPass=!0===t.load;let y=[],b=new Set,x=()=>{if(y.length!==0){h===m&&(h=h.clone()),h.removeAll(y,X);for(let e=0;e<y.length;e++)b.add(y[e].value.formulaEntry.value);y.length=0}},S=1,C=ss;C.length=0,r||s||(this.doCollectVolatileCalcs(e,S,d,C,l),d.clear());let w=f.getDeferred?.();w?.setServing(s),w?.setExternal(!0===t.external);let T=w?w.takeSettleDirty():null;if(T!==null&&T.length>0){for(let e=0;e<T.length;e++){let t=T[e].scope;c.has(t)&&p(t)}this.doCollectDirtyCalcs(e,S,T,C,l,h,y)}if(!s){if(i)c.get(i.scope??a)&&this.doCollectDirtyCalcs(e,S,[i],C,l,h,y);else{let t=o&&c.has(o)?o:null,n=t?[t]:r?c.keys():u.getScopeKeys(),i=[],a=!1;for(let e of n){let n=c.get(e);if(n&&(p(e),!n._unanchored)){if(r){let t={...n.getEntireCoords()};t.scope=e,i.push(t)}else a||(a=!0,u.all3D(i),t&&(i=i.filter(t=>t.scope===e)))}}this.doCollectDirtyCalcs(e,S,i,C,l,h,y)}}if(w){let e=w.takeRepaintGrids();for(let t=0;t<e.length;t++)c.has(e[t])&&p(e[t])}if(v.size===0&&C.length===0)return w?.setServing(!1),w?.setExternal(!1),this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,null;if(C.length===0)return this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,{precedentSpatial:h,dynamicByBlock:_,lastUpdates:new Map(v)};let E=new Map;this._addDynamicPrecedent=(e,t,n)=>{e?.block&&(f.getScope().perCellRead=!0,n===gi&&(e.state|=nr),Kt(E,e,t,n))};let D=new Map,O=(e,t)=>{(function(e,t,n,r){if(t===0)return;let i,a,o,s=Ua,c=[],l=new Set,u=()=>{let e=i.build();e&&e.tuples&&(o.values.setValues(e.tuples),qe(o.errorSpatial,e.tuples,r));let t=a.done(!0);for(let e=0;e<t.length;e++){let n=t[e];o.notifyValues.insertNonOverlapping(n)}let n=o.calcStatusConflating;if(n){let e=n.done(!0);o.notifyCalcStatus.load(e),o.calcStatusConflating=null}let s=o.circularConflating;if(s){let e=s.done(!0);o.notifyCircular.load(e),o.circularConflating=null}let l=o.formatsConflating;if(l){let e=l.done(!0);o.notifyFormats.load(e),o.formatsConflating=null}c.length>0&&(o.notifyFormats.load(c),c=[])};e.length=t,e.sort(r?Ka:Ja);for(let d=0;d<t;d++){let t=e[d],f=t.colIndex,p=t.rowIndex,m=t.gridId;m||console.log(`nodeGridId is null`,t),m!==s&&(s!==Ua&&u(),i=new Lt.Builder(La),a=ue(r),s=m,o=n(m));let h=r?f:p,g=r?p:f,_=t.cachedValue;_?.isIRange||(i.pushAt(h,g,_),a.append(h,g));let v=t.block,y=t.numFmt;t.numFmt=null;let b=v.getFormatReferences();if(b.length>0){if(!l.has(v)){l.add(v);let e=v.ref;c.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:{references:b,fallback:y}})}}else y!==null&&(o.formatsConflating||(o.formatsConflating=ue(r)),o.formatsConflating.append(h,g,y))}u()})(e,t,p,!0);for(let n=0;n<t;n++){let t=e[n];t.state=t.state&~G|gr}for(let[e,t]of v)D.set(e,t);v.clear()},k=r,A=cs;A.length=0;let j=0,M=!1;do{++S,x(),this.doMarkAndPlan(e,S,C,A);let t=this.doEvaluate(e,p,O,k,A);M=t!==void 0,M&&(k=!1,++S,C.length=0,this.doCollectDirtyCalcs(e,S,t.all(),C,l,h,y),j>200&&(++S,x(),this.doMarkAndPlan(e,S,C,A,!0),this.doEvaluate(e,p,O,!1,A),this._hasCycle()||console.error(`Too many iterations, possible cycle or leak`),M=!1)),j++}while(M);for(let e of b){if(E.has(e))continue;let t=_.get(e);t&&(h.removeAll(t,X),_===g&&(_=new Map(_)),_.delete(e))}if(E.size>0){if(function(e,t,n){for(let t of n)if(!e.has(t))return!1;for(let[n,r]of e){let e=t.get(n);if(!e||e.length!==r.length)return!1;for(let t=0;t<r.length;t++){let n=r[t],i=n.value.index,a=!1;for(let t=0;t<e.length;t++){let r=e[t];if(r.value.index===i){a=r.scope===n.scope&&r.colStart===n.colStart&&r.rowStart===n.rowStart&&r.colEnd===n.colEnd&&r.rowEnd===n.rowEnd;break}}if(!a)return!1}}return!0}(E,g,b))h=m,_=g,E.clear();else{h===m&&(h=h.clone()),_===g&&(_=new Map(_));for(let e of E.keys()){let t=_.get(e);t&&h.removeAll(t,X)}h.load(Array.from(E.values()).flat());for(let[e,t]of E)_.set(e,t);E.clear()}}return this._gridUpdates=null,this._addDynamicPrecedent=null,this._context._setDynamicReadHook(null),this._passActive=!1,f.getDeferred?.()?.flush(),{precedentSpatial:h,dynamicByBlock:_,lastUpdates:D,skippedTables:this._takeSkippedTables()}}_savedAnswer(e){let t=e.block;if(!t.fromLoad||t.calcOnLoad)return;let n=this._container.getGrid(e.gridId);if(!n||n._isVolatileNow(e.rowIndex,e.colIndex))return;let r=e.cachedValue;if(r?.isIRange&&r.size>1){if(t.uncalculated)return;let i=e.rowIndex,a=e.colIndex;return new Ve(this._container.getRuntime(),n.getValues().clone(),{rowStart:i,colStart:a,rowEnd:i+r.getRowCount()-1,colEnd:a+r.getColumnCount()-1})}let i=n.getValues().getValueAt(e.rowIndex,e.colIndex);return i==null||y.isError(i,y.Code.Busy)||y.isError(i,y.Code.Spill)?void 0:i}_takeDeferred(e,t){let n=this._container.getDeferred?.();if(this._spillHolder=null,!n)return t;let r=this._loadPass?this._savedAnswer(e):void 0;if(r!==void 0)return n.abandonEvaluation(),r;let i=n.endEvaluation(),a=i.calls;if(a.length===0)return t;for(let t=0;t<a.length;t++)if(a[t].isOpen()){e.state|=lr|dr;break}let o=n.newHolder(t,i);return Array.isArray(t)||t?.isIRange?(this._spillHolder=o,t):o}_takeSkippedTables(){let e=this._skippedTables;if(this._exceptTables=!1,e.size===0)return;let t=[];for(let n of e)t.push({rowStart:n.rowIndex,colStart:n.colIndex,rowEnd:n.rowIndex,colEnd:n.colIndex,scope:n.gridId});return e.clear(),t}_onPassRead(e,t,n,r,i,a=!1){if(!this._passActive)return!1;let o=this._passCycleId,s=this._passMarkId;Z.rowStart=t,Z.colStart=n,Z.rowEnd=r,Z.colEnd=i,Z.scope=e;let c=this._container.getFormulas().search(Z),l=c.length,u=this._iterate!==null,d=this._container.getScope().node,f=d!==null&&(d.state&q)!==0,p=0,m=null,h=!1,g=!1,_=e=>{if(e.cycleId!==o||e.markId!==s)return void(u||(e.state&ir)===0||(a?g=!0:this._demandActive?this._markDownstream(e):m=e));let t=e.state&G;if(t!==_r||h||(this._flush?.(),h=!0,t=e.state&G),t!==hr)t===mr||t===_r?wo[p++]=e:(e.state&K)!==vr&&(a?g=!0:u&&this._demandActive?this._onMemberRead(e):u||this._demandActive?this._markDownstream(e):m=e);else if(a)g=!0;else{if(f||(e.state&=~q),!u||!this._demandActive)throw new Sn(e);(e.state&rr)===0&&(e.state|=rr,Oo[this._iterHitsLength++]=e)}};for(let e=0;e<l;e++){let a=c[e],l=a.value,u=Math.max(a.rowStart,t),d=Math.min(a.rowEnd,r),f=Math.max(a.colStart,n),p=Math.min(a.colEnd,i),m=l.representative;if(m!==null&&m.cycleId===o&&m.markId===s&&l.isBlankAware(o)){let e=l.getTouchedCached(),t=e.touched;for(let e=0;e<t.length;e++){let n=t[e],r=Math.max(u,n.rowStart),i=Math.min(d,n.rowEnd);if(r>i)continue;let a=Math.max(f,n.colStart),o=Math.min(p,n.colEnd);a>o||l.forEachNodeIn(r,i,a,o,_)}Ra(e.blank,a,u-a.rowStart,d-a.rowStart,f-a.colStart,p-a.colStart)&&_(m)}else l.forEachNodeIn(u,d,f,p,_)}if(p>0)throw new hn(wo,p);if(m)throw new pn(m);return g}_markDownstream(e){let t=this._container.getScope().node;t&&(t.state&K)===vr&&(t.state=t.state&~K|yr,W(t).cycleGroup=this._resolveGroup(po(e)),this._addCircular(t),this._iterate&&(jo[this._iterDownstreamLength++]=t))}_onMemberRead(e){let t=e.state;if((t&K)===J){if(this._openGroups.has(this._resolveGroup(e.ext.cycleGroup)))return void((t&rr)===0&&(e.state|=rr,Oo[this._iterHitsLength++]=e))}else if(this._sweeping&&(t&or)===0&&e.ext.demandValue!==void 0){let t=this._container.getScope().node;if(t&&((t.state&K)===J||(t.state&or)!==0))return void this._sweepAlong(e,t)}this._markDownstream(e)}_sweepAlong(e,t){let n=e.ext,r=t.ext,i=this._resolveGroup(r.cycleGroup);(t.state&K)===J&&this._resolveGroup(n.cycleGroup)===i?(e.state=e.state&~K|J,n.cycleGroup=i,r.cycleNext===null&&(r.cycleNext=e)):e.state|=or,this._addIterMember(e,n.demandValue)}_addIterMember(e,t){let n=this._iterMembersLength++;if(this._iterSorted){for(;n>0&&qa(ko[n-1],e)>0;)ko[n]=ko[n-1],Ao[n]=Ao[n-1],n--;n<=this._sweepIndex&&this._sweepIndex++}ko[n]=e,Ao[n]=t}_sortIterMembers(){this._iterSorted=!0;let e=this._iterMembersLength;if(e<2)return;let t=Array(e);for(let n=0;n<e;n++)t[n]=n;t.sort((e,t)=>qa(ko[e],ko[t]));let n=Array(e),r=Array(e);for(let i=0;i<e;i++)n[i]=ko[t[i]],r[i]=Ao[t[i]];for(let t=0;t<e;t++)ko[t]=n[t],Ao[t]=r[t]}_resolveGroup(e){let t=this._groupAlias;if(t.size===0)return e;let n=t.get(e);for(;n!==void 0;)e=n,n=t.get(e);return e}_settleGroups(){if(this._groupAlias.size===0)return;let e=this._circularNodesLength;for(let t=0;t<e;t++){let e=To[t];if((e.state&K)===vr)continue;let n=e.ext;n.cycleGroup=this._resolveGroup(n.cycleGroup)}this._groupAlias.clear()}_collectUnevaluated(e,t,n){let r=this._passCycleId,i=this._passMarkId,a=this._container.getFormulas().search(e),o=a.length;for(let s=0;s<o;s++)a[s].value.forEachNodeIn(e.rowStart,e.rowEnd,e.colStart,e.colEnd,e=>{e.cycleId===r&&e.markId===i&&(e.state&G)===mr&&(t[n++]=e)});return n}doDemandEvaluate(e,t,n,r){if(n.length===0)return;let i=this._container.getScope();this._demandActive=!0,this._iterMembersLength=0,this._iterDownstreamLength=0,this._iterSorted=!1;try{this._demandRun(t,n,n.length),this._settleGroups(),this._iterate&&this._iterMembersLength>0&&this._demandSweep(t)}finally{this._demandActive=!1,this._sweeping=!1,this._sweepIndex=-1,this._openGroups.clear(),this._settleGroups(),this._iterHitsLength>0&&this._drainIterHits(),i.node=null,i.colIndex=2**53-1,i.rowIndex=2**53-1}}_pushDemand(e,t){let n=t?.isIRange?t.getValueAt(0,0)??0:t;this._overlayFor(e.gridId).pushDemand(e.rowIndex,e.colIndex,n)}_overlayFor(e){let t=this._overlays,n=t.get(e);if(n===void 0){let r=this._flush,i=this._container;n=new xa(i.getIncrementalUpdates(e).values,i.getGrid(e),()=>r?.()),t.set(e,n)}return n}evaluateWhatIf(e){let t=this._container,n=this._context,r=t.getScope(),i=r.node,a={...r},o=n._takeReadHooks(),s=this._addDynamicPrecedent;this._addDynamicPrecedent=null;let c=this._whatIf,l=new Map,u=e=>{let n=l.get(e);if(n===void 0){this._whatIf=c;let r=t.getGridValues(e);this._whatIf=l,n=new Na(r,r.hasErrorIn?r:t.getGrid(e)),l.set(e,n)}return n};this._whatIf=l;try{let n=bn(t,e),r=mn({container:t,evaluate:e=>this._evaluateWhatIf(e),layerFor:u},e,n),a=t.getVolatiles();if(i&&a){for(let e=0;e<n.length;e++)if(a.has(n[e])){a.add(i),i.state|=nr;break}}return r}finally{this._whatIf=c,this._addDynamicPrecedent=s,n._restoreReadHooks(o);let e=r.deferCount;Object.assign(r,a),r.deferCount=e}}_evaluateWhatIf(e){let t=e.block,n=t.formula;if(!n)return e.cachedValue??null;let r=this._container.getScope(),i;Zn(e,wn(e)),r.gridId=e.gridId,r.node=e,r.rowIndex=e.rowIndex,r.colIndex=e.colIndex,r.drawIndex=0;try{let t=r.deferCount;i=n.finalizeValueForCell(n.evaluateAt(e.rowIndex,e.colIndex)),r.deferCount!==t&&(i=this._takeDeferred(e,i))}catch(t){if(!(t instanceof ie))throw t;i=e.cachedValue??null}return this._fitCell(t,i)}_fitCell(e,t){return e.arrayFirstCell&&typeof t==`object`&&t&&!0===t.isIRange?t.getValueAt(0,0)??0:t}_isPositionFree(e,t){let n=e.block.getPositionVariants();if(n===null)return!1;let r=this._container.getScope(),i=r.node,a=r.gridId,o=r.rowIndex,s=r.colIndex;try{for(let i=0;i<n.length;i++){let a=n[i];r.node=e,r.drawIndex=0,r.perCellRead=!1,r.positionRead=!1;let o=r.deferCount,s=a.evaluateAt(e.rowIndex,e.colIndex);if(r.deferCount!==o)return this._container.getDeferred?.()?.abandonEvaluation(),!1;if(r.perCellRead||r.positionRead||this._fitCell(e.block,a.finalizeValueForCell(s))!==t)return!1}return!0}catch{return!1}finally{r.node=i,r.gridId=a,r.rowIndex=o,r.colIndex=s,r.perCellRead=!1,r.positionRead=!0}}_finalizeRepresentative(e,t,n,r){let i=e.block,a=this._passCycleId,o=this._passMarkId;if(i.blankCycleId===a&&i.blankMarkId===o)return;let s=this._container.getScope(),c=s.perCellRead,l=!(r||c||t&&t.isIRange),u=!1;if(l&&s.positionRead&&(u=!this._isPositionFree(e,t),l=!u),!l)return u&&!c&&this._container.getGrid(e.gridId)?.isPaged()?void this._pageBlank(i,n):void this._fallbackBlank(i,c||u);let d=i.blankShared,f=i.blankValue;i.blankValue=t,i.blankCycleId=a,i.blankMarkId=o;let p=i.getTouchedCached().blank,m=e.gridId,h=n.values,g=n.errorSpatial,_=this._container.getGrid(m);if(_!==null&&_.getShadowOf()!==null)return void za(p,n,m);let y=h.getAxis()===v.Axis.Column,b=y?v.Axis.Column:v.Axis.Row,x=so,S=co;for(let e=0;e<p.length;e++){let n=p[e],r=y?n.colStart:n.rowStart,i=y?n.colEnd:n.rowEnd,a=y?n.rowStart:n.colStart,o=y?n.rowEnd-n.rowStart+1:n.colEnd-n.colStart+1,s=new je([t],o),c=Array(i-r+1);for(let e=r;e<=i;e++)c[e-r]=[e,[[a,s]]];h.setValues(c),_e(g,n),qe(g,c,y);let l={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:m};x.push({...l,value:new fe(l,b)}),S.push(l)}n.contentfulSpatial.insertAllNonOverlapping(x),n.notifyValues.insertAllNonOverlapping(S),x.length=0,S.length=0,i.setBlankShared(p),this._dirtyBlankReaders(m,p,f===t?d:null)}_dirtyBlankReaders(e,t,n){if(n!==null&&ti(t,n))return;let r=this._container.getPrecedents(),i=uo,a=fo;a.scope=e;for(let e=0;e<t.length;e++)n===null?i.push(t[e]):ni(t[e],n,i);for(let t=0;t<i.length;t++){let n=i[t];a.colStart=n.colStart,a.rowStart=n.rowStart,a.colEnd=n.colEnd,a.rowEnd=n.rowEnd,r.search(a).length!==0&&(this._fallbackDirty??=new k).insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:e})}i.length=0}_pageBlank(e,t){e.blankPaged=!0,e.representative=null,e.setBlankShared(null);let n=e.getTouchedCached();if(n===null||n.blank.length===0)return;Ba(e,n.blank,t);let r=e.getDemandedBlank();if(r.length===0)return;let i=this._fallbackDirty??=new k,a=e.gridId,o=lo;for(let e=0;e<r.length;e++){let t=r[e];o.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:a})}i.insertAllNonOverlapping(o),o.length=0}_fallbackBlank(e,t){t?(e.blankRefused=!0,e.densify()):e.blankFallbackCycleId=this._passCycleId,e.setBlankShared(null);let n=e.getTouchedCached();if(n===null)return;let r=n.blank;if(r.length===0)return;let i=this._fallbackDirty??=new k,a=e.gridId,o=lo;for(let e=0;e<r.length;e++){let t=r[e];o.push({colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd,scope:a})}i.insertAllNonOverlapping(o),o.length=0}_valueOnGrid(e){return this._overlayFor(e.gridId).getValueAt(e.rowIndex,e.colIndex)??(e.block.uncalculated?``:null)}_unstartPrefetched(e){e.state&=~(G|K|tr),Do[this._deferredLength++]=e}_unwindSpeculative(e,t){for(;t>0;){let n=e[t-1];if((n.state&(G|q))!==(hr|q))break;this._unstartPrefetched(n),t--}return t}_demandRun(e,t,n){let r=this._container,i=this._context,a=r.getScope(),o=this._demandStats,s=So,c=0,l=Co;this._deferredLength=0;for(let r=0;;r++){let u;if(r<n)u=t[r];else{if(!(this._deferredLength>0))break;u=Do[--this._deferredLength]}if((u.state&G)===mr)for(u.state&=~q,s[c++]=u;c>0;){let t=s[c-1],n=t.state&G;if(n===gr){c--;continue}let r;n===mr&&(t.state=t.state&~(G|sr)|hr|tr,this._addCircular(t));let u=null,d=!1;Zn(t,wn(t)),t.state&=~nr,a.node=t,a.gridId=t.gridId,a.rowIndex=t.rowIndex,a.colIndex=t.colIndex,a.drawIndex=0,o.evaluations++,d=t.block.representative===t&&t.block.isBlankAware(this._passCycleId),a.perCellRead=!1,a.positionRead=!1,i._setReadHook(this._passHook);try{let e=t.block.formula,n=a.deferCount;r=e.evaluateAt(t.rowIndex,t.colIndex),r=this._fitCell(t.block,e.finalizeValueForCell(r)),a.deferCount!==n&&(r=this._takeDeferred(t,r)),r?.isIRange&&r.getValueAt(0,0)}catch(e){if(!(e instanceof hn||e instanceof Sn||e instanceof pn))throw e;u=e}finally{i._setReadHook(null)}(a.perCellRead||a.positionRead)&&(t.block.positionRead=!0);let f=this._iterHitsLength;if(f>0&&(t.state&q)!==0)this._drainIterHits(),this._unstartPrefetched(t),c=this._unwindSpeculative(s,c-1);else{if(f>0){for(let e=0;e<f;e++){let t=Oo[e];if(t.state&=~rr,(t.state&G)===hr){this._markCycleSlice(s,c,t,null);continue}let n=this._openGroups.get(this._resolveGroup(t.ext.cycleGroup));n===void 0?this._markDownstream(t):this._markCycleSlice(s,c,s[n],t)}this._iterHitsLength=0}if(u instanceof hn){if((t.state&q)!==0){this._unstartPrefetched(t),c=this._unwindSpeculative(s,c-1);continue}o.retries++;let e=0,n=gn(t),r=n.length;for(let i=0;i<r;i++){let r=n[i];if(y.isError(r))continue;let a=r;a.scope?e=this._collectUnevaluated(a,l,e):(Z.rowStart=a.rowStart,Z.colStart=a.colStart,Z.rowEnd=a.rowEnd,Z.colEnd=a.colEnd,Z.scope=t.gridId,e=this._collectUnevaluated(Z,l,e))}for(let t=0;t<e;t++){let e=l[t];(e.state&(G|sr))===mr&&(e.state|=q|sr,s[c++]=e)}let i=u.nodes,a=u.count;for(let e=0;e<a;e++){let t=i[e];(t.state&G)===mr&&(t.state=t.state&~q|sr,s[c++]=t)}continue}if(u instanceof Sn){if((t.state&q)!==0){this._unstartPrefetched(t),c=this._unwindSpeculative(s,c-1);continue}let e=this._markCycleSlice(s,c,u.node,null);for(let t=e;t<c;t++){let e=s[t];if((e.state&G)!==hr)continue;if((e.state&q)!==0){this._unstartPrefetched(e);continue}e.state=e.state&~(G|q)|gr;let n=mo(e);W(e).demandValue=n,this._pushDemand(e,n);let r=e.block;r.representative===e&&r.isBlankAware(this._passCycleId)&&this._fallbackBlank(r,!1)}c=e;continue}if(u instanceof pn){t.state=t.state&~(G|K|q)|gr|yr;let e=mo(t),n=W(t);n.cycleGroup=po(u.node),n.demandValue=e,this._pushDemand(t,e),d&&this._fallbackBlank(t.block,!1),c--;continue}if(this._iterate||(t.state&K)!==yr)W(t).demandValue=r,this._pushDemand(t,r),d&&this._finalizeRepresentative(t,r,e(t.gridId),!1);else{let e=mo(t);W(t).demandValue=e,this._pushDemand(t,e),d&&this._fallbackBlank(t.block,!1)}if(t.state=t.state&~(G|q)|gr,c--,this._openGroups.size>0&&(t.state&K)===J){let e=this._resolveGroup(t.ext.cycleGroup);this._openGroups.get(e)===c&&this._openGroups.delete(e)}}}}}_markCycleSlice(e,t,n,r){let i=t-1;for(;i>=0&&e[i]!==n;)i--;i<0&&(i=t-1);let a=0;for(let n=i;n<t&&a===0;n++){let t=e[n];(t.state&q)===0&&(t.state&(G|K))===(hr|J)&&(a=this._resolveGroup(t.ext.cycleGroup))}a===0&&(a=++this._cycleGroupNext);let o=this._iterate!==null,s=i;if(o){let e=this._openGroups.get(a);e!==void 0&&e<s&&(s=e)}let c=null,l=null;for(let n=i;n<t;n++){let t=e[n],r=t.state;if((r&G)!==hr||(r&q)!==0)continue;o&&(r&K)!==J&&this._addIterMember(t,this._valueOnGrid(t)),t.state=r&~K|J;let i=W(t);if(o&&(r&K)===J){let e=this._resolveGroup(i.cycleGroup);if(e!==a){let t=this._openGroups.get(e);t!==void 0&&(t<s&&(s=t),this._openGroups.delete(e)),this._groupAlias.set(e,a)}}i.cycleGroup=a,l?W(l).cycleNext=t:c=t,l=t}return l&&(W(l).cycleNext=r??c),o&&this._openGroups.set(a,s),i}_demandSweep(e){let t=this._iterate,n=ko,r=t.maxIteration,i=t.maxChange;this._sortIterMembers();for(let e=0;e<this._iterMembersLength;e++){let t=n[e],r=t.ext,i=Ao[e];r.demandValue=i,this._pushDemand(t,i)}let a=0,o=!1,s=0;for(this._sweeping=!0,this._sweepIndex=0;this._sweepIndex<this._iterMembersLength;){let t=n[this._sweepIndex],r=t.ext;if(r.demandValue===null){let n=this._demandEvaluateOne(e,t);r.demandValue=n,this._pushDemand(t,n)}this._sweepIndex++}this._sweepIndex=-1;let c=new Map,l=new Map,u=new Map;for(;a<r;){let t=0;c.clear();let r=this._iterMembersLength;for(this._sweepIndex=0;this._sweepIndex<this._iterMembersLength;){let r=n[this._sweepIndex],i=r.ext,a=i.demandValue,o=this._demandEvaluateOne(e,r);i.demandValue=o,this._pushDemand(r,o);let s=os(a,o);if(s>t&&(t=s),(r.state&K)===J){let e=i.cycleGroup,t=c.get(e);(t===void 0||s>t)&&c.set(e,s)}this._sweepIndex++}this._sweepIndex=-1,a++,s=t;let d=u;if(u=l,l=c,c=d,this._iterMembersLength===r&&t<i){o=!0;break}}this._sweeping=!1;let d=jo,f=this._iterDownstreamLength;for(let e=0;e<f;e++){let t=d[e];(t.state&G)===gr&&(t.state&K)===yr&&(t.state=t.state&~G|mr)}this._demandRun(e,d,f),this._settleGroups();let p=new Map,m=this._container.getVolatiles(),h=this._iterMembersLength;for(let e=0;e<h;e++){let t=n[e];if((t.state&K)!==J)continue;let r=t.ext.cycleGroup,i=p.get(r);i===void 0&&(i={converged:o,iterationCount:a,lastChange:l.get(r)??s,previousChange:u.get(r)??NaN},p.set(r,i),this._cycleOf(r).setIteration(i)),m?.add(t),t.state|=nr}}_drainIterHits(){let e=this._iterHitsLength;for(let t=0;t<e;t++)Oo[t].state&=~rr;this._iterHitsLength=0}_demandEvaluateOne(e,t){let n=this._context,r=this._container.getScope(),i=t.block.formula,a=wn(t);for(;;){Zn(t,a),t.state&=~nr,r.node=t,r.gridId=t.gridId,r.rowIndex=t.rowIndex,r.colIndex=t.colIndex,r.drawIndex=0,this._demandStats.evaluations++;let o,s=null;n._setReadHook(this._passHook);try{let e=r.deferCount;o=this._fitCell(t.block,i.finalizeValueForCell(i.evaluateAt(t.rowIndex,t.colIndex))),r.deferCount!==e&&(o=this._takeDeferred(t,o)),o?.isIRange&&o.getValueAt(0,0)}catch(e){if(!(e instanceof hn))throw e;s=e}finally{n._setReadHook(null)}if(this._iterHitsLength>0&&this._drainIterHits(),!s)return o;this._demandStats.retries++;let c=s.nodes,l=s.count;for(let e=0;e<l;e++)Eo[e]=c[e];this._demandRun(e,Eo,l)}}getCycleCells(){let e=[];for(let t of this._cycles.values())for(let n of[t.members,t.downstream])for(let t of n)t.gridId&&this.isLiveNode(t)&&e.push({rowStart:t.rowIndex,rowEnd:t.rowIndex,colStart:t.colIndex,colEnd:t.colIndex,scope:t.gridId});return e}_hasCycle(){let e=To,t=this._circularNodesLength;for(let n=0;n<t;n++)if((e[n].state&K)===J)return!0;return!1}_addCircular(e){(e.state&ar)===0&&(e.state|=ar,To[this._circularNodesLength++]=e)}_resetCircular(){let e=this._circularNodesLength;for(let t=0;t<e;t++)To[t].state&=~ar;this._circularNodesLength=0}_trackCircular(e,t,n,r,i){let a=W(e),o=e.state&K,s=o===vr?0:a.cycleGroup;if(a.shownGroup===s&&(e.state&ir)===o<<2)return;if(this._cycleEpoch++,a.shownGroup!==0){let t=this._cycles.get(a.shownGroup);t&&(t.members.delete(e),t.downstream.delete(e),t.isEmpty()&&this._cycles.delete(a.shownGroup))}let c=!1;if(s!==0){let t=this._cycleOf(s),n=o===J;(n?t.members:t.downstream).add(e),c=t.getEntry(n)}a.shownGroup=s,e.state=e.state&~ir|o<<2,t.circularConflating||=ue(i),t.circularConflating.append(n,r,c)}_cycleOf(e){let t=this._cycles.get(e);return t||(t=new Pa(this._cycleHost,e),this._cycles.set(e,t)),t}isLiveNode(e){let t=e.gridId;if(!t)return!1;let n=e.rowIndex,r=e.colIndex,i=this._container.getFormulas().search({colStart:r,colEnd:r,rowStart:n,rowEnd:n,scope:t});for(let t=0;t<i.length;t++)if(i[t].value.nodeAtOrNull(n,r)===e)return!0;return!1}getCircularNodes(){return To.slice(0,this._circularNodesLength)}getDemandStats(){return{...this._demandStats,...this._planStats}}resetStats(){let e=this._demandStats;for(let t in e)e[t]=0;let t=this._planStats;for(let e in t)t[e]=0}doMarkAndPlan(e,t,n,r,i=!1){let a=n.values,o=n.length,s=r.values,c=0;this._passCycleId=e,this._passMarkId=t;let l=this._container,u=l.getPrecedents(),d=l.getFormulas(),f=this.planCacheMode,{staticEpoch:p,precedentEpoch:m}=l.getCalcEpochs(),h=this._lastPlanId,g=this._planStats;g.passes++;let _=Ya(),v=f!==`off`&&!i&&h!==0,b=v?this._matchPlanMemo(o,e,t-1,m):null;if(b!==null&&g.closureEligible++,qn=0,b!==null&&f===`on`){let n=b.plan,i=b.planLength,a=b.demandStart;for(let r=0;r<i;r++){let i=n[r];i.markId=t,i.cycleId=e,i.inDegree=0,i.state&=~pr,i.ext!==null&&(i.ext.cycleGroup=0),Yn(i,wn(i)),s[r]=i}return r.length=i,a<i&&this._flagDemandAppendix(s,a,i),g.closureHits++,g.discoveryMs+=Ya()-_,a===i}let x=0,S=0,C=0,w=0,T=0,E=0,D=0,O=0;for(let n=0;n<o;n++){let r=a[n];if(r.cycleId===e&&r.markId===t)continue;r.markId=t,r.cycleId=e,r.inDegree=0,r.state&=~pr;let i=r.ext;i!==null&&(i.cycleGroup=0),(r.planEpoch!==p||r.planId!==h||i!==null&&i.shownGroup!==0)&&(v=!1),Yn(r,wn(r)),_o[x++]=r,yo[O++]=r}let k=n=>{if(n.cycleId===e&&n.markId===t)return;n.markId=t,n.cycleId=e,n.inDegree=0,n.state&=~pr;let r=n.ext;r!==null&&(r.cycleGroup=0),(n.planEpoch!==p||n.planId!==h||r!==null&&r.shownGroup!==0)&&(v=!1),Yn(n,wn(n)),_o[x++]=n,yo[O++]=n},A=(n,r,i,a,o,s)=>{if(n.unanchored)return;let c=n.ref;r<=c.rowStart&&i>=c.rowEnd&&a<=c.colStart&&o>=c.colEnd&&n.isBlankAware(e)?n.forEachTouchedNode(e,t,s):n.mintNodesIn(r,i,a,o,s)},j=new Map;for(;D<O;){let e=yo[D++],t=e.colIndex,n=e.rowIndex,r=e.gridId,i,a=f!==`off`&&e.dependentsEpoch===m;a&&f===`on`?(g.dependentsCacheHits++,i=e.dependents):(ro.colStart=t,ro.rowStart=n,ro.colEnd=t,ro.rowEnd=n,ro.scope=r,i=u.search(ro),a?(g.dependentsCacheHits++,eo(e.dependents,i)||(g.dependentsAssertFailures++,console.error(`CalcExecutor: stale dependents cache at`,r,n,t))):(g.dependentsCacheMisses++,f!==`off`&&(e.dependentsEpoch=m))),e.dependents=i;let o=e.ext;if(o!==null&&(o.spillDependents=No,o.spillRowStart=-1,o.spillColStart=-1,o.spillRowEnd=-1,o.spillColEnd=-1),zo(e)){let i=Io,a=Lo,o=Po,s=Fo;io.colStart=a,io.rowStart=i,io.colEnd=s,io.rowEnd=o,io.scope=r;let c=u.search(io),l=c.length;if(l>0){let r=W(e);r.spillDependents=c,r.spillRowStart=i,r.spillColStart=a,r.spillRowEnd=o,r.spillColEnd=s,vo[S++]=e;for(let e=0;e<l;e++)Tn(c[e],n,t,i,a,o,s,k,A)}}let s=i.length;if(s!==0)for(let e=0;e<s;e++){let r=i[e];En(r,n,t,k,A,j)}}let M=Ya();if(g.discoveryMs+=M-_,v&&g.fastEligible++,b!==null){let n=b.plan,r=b.planLength===x;for(let i=0;r&&i<x;i++){let a=n[i];r=a.cycleId===e&&a.markId===t}r||(g.closureAssertFailures++,console.error(`CalcExecutor: whole-closure reuse would have planned a different affected set`))}if(v&&f===`on`){(function(e,t,n,r){if(8*t<r){let r=Qa;for(let n=0;n<t;n++)r[n]=e[n];r.length=t,r.sort(Xa);for(let e=0;e<t;e++)n[e]=r[e];return}if(Za.length<r){let e=[];for(let t=0;t<r;t++)e.push(null);Za=e}let i=Za,a=r,o=-1;for(let n=0;n<t;n++){let t=e[n],r=t.orderIndex;i[r]=t,r<a&&(a=r),r>o&&(o=r)}let s=0;for(let e=a;e<=o;e++){let t=i[e];t!==null&&(i[e]=null,n[s++]=t)}})(_o,x,s,this._lastStampedLength),r.length=x;let e=x,t=this._lastStampedOrderedLength;for(;e>0&&s[e-1].orderIndex>=t;)e--;return e<x&&this._flagDemandAppendix(s,e,x),this._rememberPlan(a,o,s,x,m,e),g.fastHits++,g.kahnMs+=Ya()-M,e===x}if(f===`on`&&!i&&j.size>0&&S===0&&x>=Wo&&this._cycles.size===0&&function(e,t,n,r){let i=new Map,a=null;for(let n=0;n<t;n++){let t=e[n],r=t.block;a!==null&&a.block===r||(a=i.get(r)??null,a===null&&(a={block:r,nodes:[],rowMin:t.rowIndex,rowMax:t.rowIndex,colMin:t.colIndex,colMax:t.colIndex,waitingOn:0,readers:[],rowFirst:!0,colFirst:!0},i.set(r,a))),a.nodes.push(t),t.rowIndex<a.rowMin&&(a.rowMin=t.rowIndex),t.rowIndex>a.rowMax&&(a.rowMax=t.rowIndex),t.colIndex<a.colMin&&(a.colMin=t.colIndex),t.colIndex>a.colMax&&(a.colMax=t.colIndex)}for(let e of i.values()){let t=e.nodes[0].gridId,r=!1,a=e.nodes;for(let o=0;o<a.length;o++){let s=a[o].precedents;if(s!==null)for(let r=0;r<s.length;r++){let c=s[r];if(y.isError(c))continue;let l=c.scope??t;Aa(e,c,l)&&(Da(c,a[o].rowIndex,a[o].colIndex)===0&&(e.rowFirst=!1),Oa(c,a[o].rowIndex,a[o].colIndex)===0&&(e.colFirst=!1)),ka(e,c.rowStart,c.rowEnd,c.colStart,c.colEnd,l,i,n)}else r=!0}if(!r)continue;let{block:o,rowMin:s,rowMax:c,colMin:l,colMax:u}=e,d=o.paramLength;for(let r=0;r<d;r++){let a=o.getPrecedentsAt(s,l)[r];if(y.isError(a))continue;wa.rowStart=a.rowStart,wa.rowEnd=a.rowEnd,wa.colStart=a.colStart,wa.colEnd=a.colEnd;let d=o.getPrecedentsAt(c,u)[r];if(y.isError(d))return!1;let f=Math.min(wa.rowStart,d.rowStart),p=Math.max(wa.rowEnd,d.rowEnd),m=Math.min(wa.colStart,d.colStart),h=Math.max(wa.colEnd,d.colEnd),g=d.scope??t;if(f<=c&&p>=s&&m<=u&&h>=l&&g===t){let t=Da(wa,s,l);t!==0&&t===Da(d,c,u)||(e.rowFirst=!1);let n=Oa(wa,s,l);n!==0&&n===Oa(d,c,u)||(e.colFirst=!1)}ka(e,f,p,m,h,g,i,n)}}let o=[];for(let e of i.values()){if(!e.rowFirst&&!e.colFirst)return!1;e.waitingOn===0&&o.push(e)}let s=0;for(let e=0;e<o.length;e++){let t=o[e],n=t.nodes;n.sort(t.rowFirst?Ta:Ea);for(let e=0;e<n.length;e++)r[s++]=n[e];let i=t.readers;for(let e=0;e<i.length;e++)--i[e].waitingOn===0&&o.push(i[e])}return o.length===i.size}(_o,x,d,s))return r.length=x,this._stampPlan(s,x,x,p),this._rememberPlan(a,o,s,x,m),g.blockOrdered++,g.kahnMs+=Ya()-M,!0;let ee=e=>{g.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would invert a static edge at`,e.gridId,e.rowIndex,e.colIndex),v=!1},te=n=>{n.cycleId===e&&n.markId===t?(Vo++,v&&n.orderIndex>=Bo.orderIndex&&ee(Bo)):this._iterate||(n.state&ir)===0||(this._taintGroup=n.ext.shownGroup,this._taintDownstream(Bo))},N=null,P=n=>{n.cycleId===e&&n.markId===t?(Xo++,n.orderIndex>Zo&&(Zo=n.orderIndex)):Qo!==null||this._iterate||(n.state&ir)===0||(Qo=n.ext.shownGroup)},F=(e,t,n,r,i)=>{N===null&&(N=new Map);let a=N.get(e);a===void 0&&(a={rects:[],next:0},N.set(e,a));let o=a.rects;for(let e=0;e<o.length;e++){let a=o[e];if(a.rowFrom===t&&a.rowTo===n&&a.colFrom===r&&a.colTo===i)return a}let s;return Xo=0,Zo=-1,Qo=null,e.forEachNodeIn(t,n,r,i,P),o.length<Uo?(s={rowFrom:t,rowTo:n,colFrom:r,colTo:i,count:0,maxOrder:-1,shownGroup:null},o.push(s)):(s=o[a.next],a.next=(a.next+1)%Uo,s.rowFrom=t,s.rowTo=n,s.colFrom=r,s.colTo=i),s.count=Xo,s.maxOrder=Zo,s.shownGroup=Qo,s};for(let e=0;e<x;e++){let t=_o[e],n=gn(t),r=n.length,i=0;for(let e=0;e<r;e++){let r=n[e];if(y.isError(r))continue;let a=r.colStart,o=r.rowStart,s=r.colEnd,c=r.rowEnd,l=r.scope??t.gridId,u,f=e&Go,p=Ko[f];if(p!==null&&qo[f]===l&&a>=p.colStart&&s<=p.colEnd&&o>=p.rowStart&&c<=p.rowEnd)Mo[0]=p,u=Mo,T++;else{if(Jo[f]===l&&Yo[f].colStart===a&&Yo[f].colEnd===s&&Yo[f].rowStart===o&&Yo[f].rowEnd===c){T++;continue}if(ao.colStart=a,ao.rowStart=o,ao.colEnd=s,ao.rowEnd=c,ao.scope=l,u=d.search(ao),E++,u.length===1){let e=u[0];e.colEnd>e.colStart||e.rowEnd>e.rowStart?(Ko[f]=e,qo[f]=l):Ko[f]=null}else if(Ko[f]=null,u.length===0){let e=Yo[f];e.colStart=a,e.colEnd=s,e.rowStart=o,e.rowEnd=c,Jo[f]=l}}let m=u.length;for(let e=0;e<m;e++){let n=u[e],r=n.colStart,l=n.rowStart,d=n.colEnd,f=n.rowEnd,p=Math.max(r,a),m=Math.max(l,o),h=Math.min(d,s),g=Math.min(f,c);if((g-m+1)*(h-p+1)>=Ho){let e=F(n.value,m,g,p,h);i+=e.count,v&&e.maxOrder>=t.orderIndex&&ee(t),e.shownGroup!==null&&(this._taintGroup=e.shownGroup,this._taintDownstream(t))}else Bo=t,Vo=i,n.value.forEachNodeIn(m,g,p,h,te),i=Vo}}t.inDegree=i,S===0&&t.inDegree===0&&(bo[w++]=t)}if(Ko.fill(null),Jo.fill(null),S>0){let n=vo[0],r=r=>{r.cycleId===e&&r.markId===t&&(r.inDegree++,v&&n.orderIndex>=r.orderIndex&&(g.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would invert a spill body edge at`,r.gridId,r.rowIndex,r.colIndex),v=!1))};for(let e=0;e<S;e++){let t=vo[e];n=t;let i=t.ext,a=i.spillDependents,o=a.length;for(let e=0;e<o;e++)Tn(a[e],t.rowIndex,t.colIndex,i.spillRowStart,i.spillColStart,i.spillRowEnd,i.spillColEnd,r)}for(let e=0;e<x;e++){let t=_o[e];t.inDegree===0&&(bo[w++]=t)}}g.formulaCacheHits+=T,g.formulaCacheMisses+=E;let ne=Ya();g.inDegreeMs+=ne-M;let re=n=>{n.cycleId===e&&n.markId===t&&(n.inDegree--,n.inDegree===0&&(bo[w++]=n))};for(;C<w;){let e=bo[C++];s[c++]=e;let t=e.colIndex,n=e.rowIndex,r=e.ext;if(r!==null){let e=r.spillDependents,i=e.length;for(let a=0;a<i;a++)Tn(e[a],n,t,r.spillRowStart,r.spillColStart,r.spillRowEnd,r.spillColEnd,re)}let i;i=e.dependents;let a=i.length;if(a!==0)for(let e=0;e<a;e++){let r=i[e];yn(r,n,t,re)}}if(g.kahnMs+=Ya()-ne,i||c<x){if(v){let e=this._lastStampedOrderedLength;for(let t=0;t<x;t++){let n=_o[t];if(n.inDegree>0&&n.orderIndex<e){g.planAssertFailures++,console.error(`CalcExecutor: order-stamp fast path would have missed an unorderable subset`);break}}}let e=this._demandBatch;e.length=0,i&&(c=0);for(let t=0;t<x;t++){let n=_o[t];(i||n.inDegree>0)&&(n.state|=tr,W(n).demandValue=void 0,e.push(n))}e.sort(Ja);let t=e.length,n=c;for(let n=0;n<t;n++){let t=e[n];s[c++]=t,this._addCircular(t)}return r.length=c,i?(this._planMemos[0].epoch=-1,this._planMemos[1].epoch=-1):f!==`off`&&(v||this._stampPlan(s,c,n,p),this._rememberPlan(a,o,s,c,m,n)),!1}return r.length=c,f===`off`||v||this._stampPlan(s,c,c,p),f!==`off`&&this._rememberPlan(a,o,s,c,m),!0}_stampPlan(e,t,n,r){let i=++this._planIdNext;this._lastPlanId=i;for(let n=0;n<t;n++){let t=e[n];t.orderIndex=n,t.planId=i,t.planEpoch=r}this._lastStampedLength=t,this._lastStampedOrderedLength=n,this._planStats.stampedPlans++}_flagDemandAppendix(e,t,n){let r=this._demandBatch;r.length=0;for(let i=t;i<n;i++){let t=e[i];t.state|=tr,W(t).demandValue=void 0,r.push(t),this._addCircular(t)}}_invalidatePlans(){this._lastPlanId=0,this._planMemos[0].epoch=-1,this._planMemos[1].epoch=-1}_matchPlanMemo(e,t,n,r){let i=this._planMemos,a=this._cycleEpoch;for(let o=0;o<2;o++){let s=i[o];if(s.epoch===r&&s.seedsLength===e&&s.cycleFree&&s.cycleEpoch===a&&$a(s.seeds,s.seedsLength,e,t,n))return s.used=++this._planMemoClock,s}return null}_rememberPlan(e,t,n,r,i,a=r){let o=this._planMemos,s=o[0],c=o[1],l=s.epoch===i?c.epoch===i&&s.used<=c.used?s:c:s;l.used=++this._planMemoClock;let u=l.seeds;for(let n=0;n<t;n++)u[n]=e[n];u.length=t,l.seedsLength=t;let d=l.plan,f=!0;for(let e=0;e<r;e++){let t=n[e];d[e]=t;let r=t.ext;r!==null&&r.shownGroup!==0&&(f=!1)}d.length=r,l.planLength=r,l.epoch=i,l.cycleFree=f,l.cycleEpoch=this._cycleEpoch,l.demandStart=a}doEvaluate(e,t,n,r,i){let a=Ya(),s=this._container,c=this._context,l=s.getScope(),u=c.getRuntime(),d=s.getDeferred?.()??null,f=i.values,p=i.length;ts=this._passCycleId,ns=this._passMarkId;let m=go,h,g,_,b,x,S,C,w,T,E,D,O,A,j=0,M=new Map;this._overlays=M;let ee=e=>this._overlayFor(e),te=e=>{D=s.getGrid(e),E=D.getEntireCoords.bind(D),g=t(e),_=g.gridId,A=ee(e),b=g.values,O=g.errorSpatial,x=g.contentfulSpatial,S=g.spillSpatial,C=g.notifyValues,w=g.notifySpillsInsert,T=g.notifySpillsRemove,g.notifyFormats,g.notifyCalcStatus,l.gridId=_},N=v.Axis.Column,P=N===v.Axis.Column,F=()=>{if(j>0){n(m,j),j=0;for(let e of M.values())e.reset();_!==void 0&&(g=t(_))}};this._flush=F;let ne=this._exceptTables;if(ne)for(let e=0;e<p;e++){let t=f[e];t.block.hasDataTable()&&(t.state=t.state&~G|gr,this._skippedTables.add(t))}let re=0;for(;re<p;)try{for(;re<p;re++){let n=f[re],i=n.colIndex,a=n.rowIndex;if((n.state&$n)!==0&&e===n.cycleId){n.state&=~$n;continue}if(ne&&n.block.hasDataTable())continue;let c=n.gridId;c!==_&&te(c);let p=n.block,v=p.representative===n&&p.isBlankAware(e),M=n.cachedValue,ie,ae,oe=!1;typeof M==`object`&&M&&(M.isIRange?ie=M:y.isError(M,y.Code.Spill)&&(ae=M,oe=!0));let se=(n.state&tr)!==0;se&&(n.state&G)!==gr&&(F(),this.doDemandEvaluate(e,t,this._demandBatch,F),l.gridId=c);let ce=se?null:gn(n),le=n.inputsAt;if(ce&&le>=0){let e=Jn(),t=ce.length;for(let n=0;n<t;n++){let t=ce[n];if(y.isError(t)){e[le+n]=t;continue}let r=t.colStart,i=t.rowStart,a=t.colEnd,o=t.rowEnd;if(o!==i||r!==a){let c=t.scope,l=b,d=E,f=A,p=D;c&&c!==_&&(p=s.getGrid(c),p&&(l=p.getValues(),f=ee(c),d=p.getEntireCoords.bind(p)));let m=p;f.intersects(i,r,o,a)&&(l=f,m=f);let h=new lt(u,l,{...t},null,d,s.resolveScope);h._setErrorIndex(m),e[le+n]=h}}}ce&&d!==null&&d.getOpenCount()!==0&&(n.state&cr)===0&&as(ce,_,s)&&(n.state|=cr);let pe=P?i:a,me=P?a:i;l.node=n,l.colIndex=i,l.rowIndex=a,l.drawIndex=0;let ge=p.formula,I,ve=null,ye=!1,be=(n.state&er)===0?0:(n.state&fr)===0?vt.CalcStatus.Waiting:vt.CalcStatus.Working,xe=be,Se=r?0:be,L=n.ext;if(se&&!this._iterate&&(n.state&K)!==vr)L!==null&&(L.demandValue=void 0),I=mo(n),xe=0;else{if(se){let e=L===null?void 0:L.demandValue;L!==null&&(L.demandValue=void 0),I=e===void 0?0:e}else{if(n.state=n.state&~G|hr,l.perCellRead=!1,l.positionRead=!1,(n.state&ur)!==0){n.state&=~ur;let e=this._settlePass?Ha(b,S,a,i):null;if(e!==null&&e.direct){ye=!0,n.state&=~(lr|dr);let t=he(e);t?.isIRange?(I=ge.finalizeValueForCell(t),ve=e):I=e}}if(!ye){this._planStats.evaluated++,n.state&=~(nr|lr|dr);let e=l.deferCount;I=ge.evaluateAt(a,i),I=ge.finalizeValueForCell(I),(l.perCellRead||l.positionRead)&&(n.block.positionRead=!0),l.deferCount!==e&&(I=this._takeDeferred(n,I),ve=this._spillHolder,this._spillHolder=null)}}xe=(n.state&dr)===0?(n.state&(cr|lr))===0?0:vt.CalcStatus.Waiting:vt.CalcStatus.Working,xe!==0&&(n.state|=lr)}let R;(n.state&G)!==gr&&(n.state=n.state&~G|_r),xe!==Se&&(xe===0?n.state&=~(er|fr):xe===vt.CalcStatus.Working?n.state|=er|fr:n.state=(n.state|er)&~fr,g.calcStatusConflating||(g.calcStatusConflating=ue(P)),g.calcStatusConflating.append(pe,me,xe!==0&&xe)),se&&A.takeDemand(a,i);let Ce=n.ext,z=Ce===null?null:Ce.fixedRef;if(ie||ae||z){ho.colStart=i,ho.rowStart=a,ho.colEnd=i,ho.rowEnd=a;let e=S.search(ho);for(let t=0;!R&&t<e.length;t++){let n=e[t];n.value.isAnchor(a,i)&&n.value.getKind()!==`pivot`&&(R=n)}if(R&&(S.remove(R,X),!R||!R.value.getError())){let e={...o.sanitizeRange(R),scope:R.scope,value:null};x.insertNonOverlapping(e),b.delete(e),_e(O,e)}}I=this._fitCell(p,I);let we=1,Te=1,Ee=I,De=typeof I==`object`&&!!I,Oe=De&&Ee.isIRange,B,V=De&&y.isError(I,y.Code.Spill);if(z){we=z.colEnd-z.colStart+1,Te=z.rowEnd-z.rowStart+1;let t={colStart:z.colStart,rowStart:z.rowStart,colEnd:z.colEnd,rowEnd:z.rowEnd,scope:c},r=Cn(I,t,P)?.tuples;b.delete(t),r&&b.setValues(r),_e(O,t),qe(O,r,P),B={...t,value:new de(t,e,`fixed`,null,ve)},S.insert(B),s.addDynamicPrecedent(n,t,_i),x.insertNonOverlapping({...t,value:new fe(t,N)})}else if(Oe&&Ee.size>1){we=Ee.getColumnCount(),Te=Ee.getRowCount();let t=Ro(n),r=t===null?a:a-t.rows,l=t===null?i:i-t.columns,u={colStart:l,rowStart:r,colEnd:l+we-1,rowEnd:r+Te-1,scope:c},d=E(),f=!o.isRangeWithinRange(u,d);if(f&&(u.colEnd=Math.min(u.colEnd,d.colEnd),u.rowEnd=Math.min(u.rowEnd,d.rowEnd)),V=f,!V){let e=x.search(u);if(V=e.length>1,!V&&e.length===1){let t=e[0],n=o.intersectRanges(u,t,to);!n||n.rowEnd===n.rowStart&&n.colStart===n.colEnd&&n.colStart===i&&n.rowStart===a||(V=!0)}}let p,m;if(V)I=y.BuiltIn.Spill,we=1,Te=1,p=[[pe,[[me,[I]]]]],b.setValues(p),qe(O,p,P),m={colStart:i,rowStart:a,colEnd:i,rowEnd:a};else{let e=xn(Ee,P?l:r,P?r:l);e&&(p=e.tuples),b.delete(u),p&&b.setValues(p),_e(O,u),qe(O,p,P),m=u}let h=V?{colStart:i,rowStart:a,colEnd:i,rowEnd:a,scope:c}:u;B={...h,value:new de(h,e,V?`error`:`dynamic`,V||t===null?null:t,ve,V?u:null)},S.insert(B),s.addDynamicPrecedent(n,u,_i),x.insertNonOverlapping({...m,value:new fe(m,N)})}!v||p.blankCycleId===e&&p.blankMarkId===this._passMarkId||this._finalizeRepresentative(n,I,g,xe!==0||se||!0===Oe||V||z!==null||ye);let ke=!1;if((R||B||V||ae)&&(ke=o.isEqualRanges(R,B),R&&T.push(R),B&&w.push(B)),B||R){let e=R??B,t=B??R,r={colStart:Math.min(i,e.colStart,t.colStart),rowStart:Math.min(a,e.rowStart,t.rowStart),colEnd:Math.max(i,e.colEnd,t.colEnd),rowEnd:Math.max(a,e.rowEnd,t.rowEnd),scope:c};C.insertNonOverlapping(r),ke&&V===oe||(this._invalidatePlans(),s.getPrecedents().search(r).length>0&&(n.state|=$n,h||=new k,h.insertNonOverlapping(r)))}n.cachedValue=I,m[j++]=n;let Ae=d!==null&&d.hasHolders()?he(I):I;Oe||z||A.push(a,i,Ae),j>=(A.observed?Wa:Ga)&&F(),((n.state&K)!==vr||n.ext!==null&&n.ext.shownGroup!==0)&&this._trackCircular(n,g,pe,me,P);let je=n.dependents,Me=je.length;if(Me>0){let e=(n.state&er)!==0,t=!this._iterate&&(n.state&K)!==vr;t&&(this._taintGroup=n.ext.cycleGroup);for(let n=0;n<Me;n++){let r=je[n];t&&yn(r,a,i,this._taintDownstream);let o=r.value.index;o<0||(Dn(r)&&($o=o,es=Ae,yn(r,a,i,rs)),e&&yn(r,a,i,is))}}}}catch(n){let r=f[re];if(n instanceof hn||n instanceof Sn&&this._iterate){let i=oo;if(i.length=0,n instanceof hn)for(let e=0;e<n.count;e++)i.push(n.nodes[e]);i.push(r),F(),r.state&=~G,this.doDemandEvaluate(e,t,i,F)}else{if(!(n instanceof Sn||n instanceof pn))throw n;{let e=n instanceof Sn;r.state=r.state&~(G|K)|tr|gr|(e?J:yr);let t=W(r);t.demandValue=mo(r),t.cycleGroup=e?++this._cycleGroupNext:po(n.node),e&&(t.cycleNext=r),this._addCircular(r)}}l.gridId=r.gridId}l.node=null,l.colIndex=2**53-1,l.rowIndex=2**53-1,F();for(let e of M.values())e.commitDemand();this._flush=null,this._overlays=null;let ie=this._fallbackDirty;return ie!==null&&(this._fallbackDirty=null,h?h.insertAllNonOverlapping(ie.all()):h=ie),(()=>{let e=Kn,t=qn;for(let n=0;n<t;n++)e[n]=void 0;qn=0})(),this._planStats.evaluateMs+=Ya()-a,h}},La=(e,t)=>new Ke.ArrayList(e.slice(0,t));function Ra(e,t,n,r,i,a){let o=t.rowStart+n,s=t.rowStart+r,c=t.colStart+i,l=t.colStart+a;for(let t=0;t<e.length;t++){let n=e[t];if(n.rowStart<=s&&n.rowEnd>=o&&n.colStart<=l&&n.colEnd>=c)return!0}return!1}function za(e,t,n){let r=t.values,i=t.errorSpatial,a=so,o=co;for(let s=0;s<e.length;s++){let c=e[s];r.delete(c),_e(i,c);let l={colStart:c.colStart,rowStart:c.rowStart,colEnd:c.colEnd,rowEnd:c.rowEnd,scope:n};a.push({...l,value:null}),o.push(l),t.notifyBlank(c)}t.contentfulSpatial.insertAllNonOverlapping(a),t.notifyValues.insertAllNonOverlapping(o),a.length=0,o.length=0}function Ba(e,t,n){let r=e.getDemandedBlank(),i=[];for(let e=0;e<t.length;e++)ni(t[e],r,i);i.length>0&&za(i,n,e.gridId)}function Va(e,t,n){for(let r=0;r<e.length;r++){let i=e[r];if(t>=i.rowStart&&t<=i.rowEnd&&n>=i.colStart&&n<=i.colEnd)return!0}return!1}var Ha=(e,t,n,r)=>{let i=e.getValueAt(n,r);return I(i)?i:Ne(t,n,r)},Ua=Symbol(`unsetGridId`),Wa=1024,Ga=65536;function Ka(e,t){return e.scope===t.scope?e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex:e.scope===null?-1:t.scope===null?1:e.scope.localeCompare(t.scope)}function qa(e,t){return e.gridId===t.gridId?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.gridId===null?-1:t.gridId===null?1:e.gridId<t.gridId?-1:1}function Ja(e,t){return e.scope===t.scope?e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:e.scope===null?-1:t.scope===null?1:e.scope.localeCompare(t.scope)}var Ya=()=>globalThis.performance?.now()??Date.now(),Xa=(e,t)=>e.orderIndex-t.orderIndex,Za=[],Qa=[];function $a(e,t,n,r,i){if(t!==n)return!1;for(let n=0;n<t;n++){let t=e[n];if(t.cycleId!==r||t.markId!==i)return!1}return!0}function eo(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;let n=!0;for(let r=0;r<e.length&&n;r++)n=e[r].value===t[r].value;if(n)return!0;let r=new Set;for(let t=0;t<e.length;t++)r.add(e[t].value);for(let e=0;e<t.length;e++)if(!r.has(t[e].value))return!1;return!0}var to={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},no={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},ro={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},io={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},ao={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Z={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},oo=[null],so=[],co=[],lo=[],uo=[],fo={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},po=e=>{let t=e.ext;return t===null?0:(e.state&K)===vr?t.shownGroup:t.cycleGroup},mo=e=>he(e.cachedValue)??0,ho={rowStart:0,colStart:0,rowEnd:0,colEnd:0},Q=1e4,go=C(Q),_o=C(Q),vo=C(Q),yo=C(Q),bo=C(Q),xo=C(Q),So=C(Q),Co=C(Q),wo=C(Q),To=C(Q),Eo=C(Q),Do=C(Q),Oo=C(Q),ko=C(Q),Ao=C(Q),jo=C(Q),Mo=[null],No=[],Po=-1,Fo=-1,Io=-1,Lo=-1;function Ro(e){let t=e.block.formula;return t!==null&&t.getSpillOrigin!==void 0?t.getSpillOrigin():null}function zo(e){let t=e.ext,n=t===null?null:t.fixedRef;if(n!==null)return Io=e.rowIndex,Lo=e.colIndex,Po=n.rowEnd,Fo=n.colEnd,n.rowEnd>e.rowIndex||n.colEnd>e.colIndex;let r=e.cachedValue;if(!r?.isIRange)return!1;let i=Ro(e);return Io=i===null?e.rowIndex:e.rowIndex-i.rows,Lo=i===null?e.colIndex:e.colIndex-i.columns,Po=Io+r.getRowCount()-1,Fo=Lo+r.getColumnCount()-1,Po>Io||Fo>Lo}var Bo=null,Vo=0,Ho=64,Uo=4,Wo=1024,Go=7,Ko=C(8),qo=C(8),Jo=C(8),Yo=Array.from({length:8},()=>({colStart:0,colEnd:0,rowStart:0,rowEnd:0})),Xo=0,Zo=-1,Qo=null,$o=-1,es=void 0,ts=0,ns=0,rs=e=>{e.cycleId===ts&&e.markId===ns&&((e,t,n)=>{let r=e.inputsAt;r<0||(Kn[r+t]=n)})(e,$o,es)},is=e=>{e.state|=cr},as=(e,t,n)=>{for(let r=0;r<e.length;r++){let i=e[r];if(!i||y.isError(i))continue;let a=n.getGrid(i.scope??t)?._calcStatusSpatial;if(!a)continue;let o=a.search(i);for(let e=0;e<o.length;e++)if(o[e].value)return!0}return!1};function os(e,t){let n=e??0,r=t??0;if(typeof n==`number`&&typeof r==`number`){let e=Math.abs(r-n);return e==e?e:1/0}return n===r?0:1/0}var ss={values:C(Q),length:0},cs={values:C(Q),length:0},ls=class{constructor(e){this._namesByKey=new Map,this._namesById=new Map,this._hostsById=new Map,this._loadedData=new Map,this._options=e}sync(e=!1){let{books:t,getGrid:n,unregisterGrid:r}=this._options,i=this._options.holdsGrids?.()??!0,a=new Set,o=new Set,s=new Set,c=t.getItems();for(let t=0;t<c.length;t++){let l=c[t],u=l.getId(),d=l.getSheetNames();for(let e=0;e<d.length;e++){let t=Me(u,e);a.add(t),i&&(n(t)?this._loadedData.get(t)!==(l.getSheetData(e)?.data??null)&&(r(t),this._registerSheet(l,e,t),s.add(u)):(this._registerSheet(l,e,t),s.add(u)))}let f=l.getDefinedNames();for(let t=0;t<f.length;t++){let n=f[t];if(!n.name)continue;let r=n.sheetIndex,i=Me(u,r!==void 0&&r>=0&&r<d.length?r:-1),a=us(i,n.name);o.add(a);let c=this._namesByKey.get(a);if(c){if(c.refersTo!==(n.refersTo??``)){c.refersTo=n.refersTo??``;let e=this._hostsById.get(c.getId());e&&this._queueBody(c.getId(),e,l,i,c.refersTo,!1),s.add(u)}}else this._registerName(l,i,n,e),s.add(u)}}for(let e of this._registeredSheetGrids())a.has(e)||(r(e),this._loadedData.delete(e),s.add(Nt(e).bookId));for(let[e,t]of this._namesByKey){if(o.has(e))continue;this._namesByKey.delete(e),this._namesById.delete(t.getId());let n=this._hostsById.get(t.getId());this._hostsById.delete(t.getId()),n?.setPlaceholder(y.BuiltIn.Name.toString()),s.add(Nt(t.getScope()).bookId)}return s}getNameByScope(e,t){return this._namesByKey.get(us(t,e))??null}getNameById(e){return this._namesById.get(e)??null}_registeredSheetGrids(){let e=[];for(let t of this._options.gridIds()){let n=Nt(t);n&&n.sheetIndex>=0&&e.push(t)}return e}_registerSheet(e,t,n){let r=this._options.createGrid(n),i=e.getSheetData(t)?.data??null;this._loadedData.set(n,i);let a=function(e){if(!e||e.length===0)return null;let t=[];for(let n=0;n<e.length;n++){let[r,i]=e[n];for(let e=0;e<i.length;e++){let[n,a]=i[e],o=a.length;for(let e=0;e<o;e++){let i=Gt.fromJSONValue(a.at(e));i!=null&&t.push({col:n+e,row:r,value:i})}}}if(t.length===0)return null;t.sort((e,t)=>e.col-t.col||e.row-t.row);let n=new Lt.Builder;for(let e=0;e<t.length;e++)n.pushAt(t[e].col,t[e].row,t[e].value);return n.build()?.tuples??null}(i);a&&r._seedNow({data:a})}_registerName(e,t,n,r){let{bindNameId:i,createHost:a}=this._options,o=i(n.name,t),s={getId:()=>o,getName:()=>n.name,getScope:()=>t,refersTo:n.refersTo??``};this._namesByKey.set(us(t,n.name),s),this._namesById.set(o,s);let c=a(o);this._hostsById.set(o,c),this._queueBody(o,c,e,t,s.refersTo,r)}_queueBody(e,t,n,r,i,a){let{queue:o,recompileNamed:s}=this._options,c=i.trim();c.startsWith(`=`)&&(c=c.substring(1)),c||=y.BuiltIn.Ref.toString();let l=Nt(r),u=l.sheetIndex>=0?l.sheetIndex:n.getSheetNames().length>0?0:-1,d=Me(l.bookId,u);o(async()=>{this._hostsById.get(e)===t&&t.setBody({coords:ds,expression:c,authoredAt:fs,scopeGridId:d})&&(a||s(e))})}},us=(e,t)=>e+`::`+t.toLowerCase(),ds=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),fs=Object.freeze({rowIndex:0,colIndex:0}),ps=class extends c{constructor(e){super({transactions:new l({maxCommits:vs})}),this._cellFreeContext=null,this._calcScope={rowIndex:0,colIndex:0,gridId:null,node:null,depth:0,activeNames:new Set,implicitIntersect:!1,firstCell:!1,perCellRead:!1,positionRead:!1,drawIndex:0,deferCount:0,deferOrdinal:0,deferRoot:!1,deferServed:null},this._cycleId=0,this._staticEpoch=1,this._precedentEpoch=1,this._epochSeenFormulas=null,this._epochSeenPrecedents=null,this._epochSeenDynamics=null,this._volatiles=new Set,this._calculatedCommitId=null,this._calculatedEngineId=null,this._holdsGrids=!1,this._engineIds=new Map,this._landingOf=new Map,this._mirroredId=null,this._lastRevert=null,this._symbolIndex=null,this._symbolIndexOf=null,this._sheetsDerived=null,this._tablesDerived=null,this._namesDerived=null,this._collecting=null,this._recompileNamedPending=null,this._recompileLoadedPending=null,this._invalidateNamedPending=null,this.resolveScope=e=>this._symbols.resolve(U.Sheet,e)?.toString(),this._heldCloneKey=null,this._callbacks=e.callbacks,this._runtime=e.runtime,this._richData=e.richData??qt.DetachedContext,this._symbols=e.symbols,this._resolvers=e.resolvers,this._getSheetIndex=e.getSheetIndex??null,this._legacyIntersect=!0===e.legacyIntersect,this._gridOptions=e.gridOptions??{},this._calculation=e.calculation;let t=e.replica;this._updateState({gridsAll:new Map,gridMaps:new Map,sheets:t?.sheets??new Map,gridless:t?.gridless??Ss,tables:t?.tables??new Map,names:t?.names??new Map,formulaSpatial:new kn({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),precedentSpatial:new kn({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}}),dynamicByBlock:new Map,dirtySpatial:new kn}),e.modelCommitId&&this.mirror(e.modelCommitId),this._context=new Si(this,v.Axis.Column,e.functions),this._deferred=new pa(this._calcScope,(e,t,n)=>this._holderAt(e,t,n),()=>this._runtime.getRandom(),()=>this._settle(),void 0,(e,t)=>this._normalizeResult(e,t),{createRichData:(e,t)=>Ct.fromJSON({type:e,data:t},this._richData),addResource:(e,t)=>ta(this._richData.resources,e,t),fetch:e.fetch,getFormulaContext:()=>(this._cellFreeContext??=this._context._createCellFree(),this._cellFreeContext),parseText:e.parseText},()=>this._callbacks.onPendingChange());let n=this._callbacks;this._calcExecutor=new Ia(this,this._context),e.planCacheMode&&(this._calcExecutor.planCacheMode=e.planCacheMode),this._externalBindings=new ls({books:e.books,createGrid:e=>this.createBackendGrid({uuid:e}),unregisterGrid:e=>{let t=this.getGrid(e);t?t._detach():this.unregisterGrid(e)},getGrid:e=>this.getGrid(e),gridIds:()=>this._gridsAll().keys(),createHost:e=>n.createHost(e),holdsGrids:()=>this._holdsGrids,bindNameId:(e,t)=>n.bindNameId(e,t),queue:e=>n.whenSafe(e,!0),recompileNamed:e=>this.recompileNamed(e)})}initialize(){return this._context._initialize()}getContext(){return this._context}getRuntime(){return this._runtime}getRichDataContext(){return this._richData}getScope(){return this._calcScope}getDeferred(){return this._deferred}_settle(){this.isClosed()||this._settleNow()}cancelAsync(e){let t=this._deferred.cancel(e);if(t.length===0)return null;let n=this._calcExecutor,r=new Map;for(let e=0;e<t.length;e++){let i=t[e],a=i.owner;if(a===null||!n.isLiveNode(a))continue;let o=a.gridId,s=this._holderAt(o,a.rowIndex,a.colIndex);if(s===null||s.calls.indexOf(i)<0)continue;let c=r.get(o);if(!c){let e=this.getGrid(o);c=new hs(!e||e.getValues().getAxis()===v.Axis.Column),r.set(o,c)}c.add(a.rowIndex,a.colIndex)}let i=[];for(let[e,t]of r){let n=t.done();for(let t=0;t<n.length;t++)i.push({...n[t],scope:e})}return i.length===0?null:(this._deferred.addSettleDirty(i),this._callbacks.calculate(void 0,void 0,!0))}_normalizeResult(e,t){let n=e;if(Array.isArray(n))try{n=this._context.getRange(n)}catch(e){return new y.Value(`The result is not a rectangular array`,{cause:e})}return n?.isIRange&&n.size<=1?n.size===0?null:n.getValueAt(0,0):(t?.keepBlanks&&n?.isIRange&&(e=>{Fn.add(e)})(n),n)}_holderAt(e,t,n){let r=this.getGrid(e);if(!r)return null;let i=r.getValues().getValueAt(t,n);return I(i)?i:Ne(r.getSpills(),t,n)}_settleNow(){let e=this._deferred,t=e.takeMoved();if(t.length===0)return;let n=this._getState(),r=n.precedentSpatial,i=this._calcExecutor,a=new Map,o=[],s=(e,t)=>{let r=e.get(t);if(!r){let i=n.gridsAll.get(t);r=new hs(!i||i.getValues().getAxis()===v.Axis.Column),e.set(t,r)}return r},c=new Map,l=new Set,u=[],d=e=>{l.add(e),s(a,e.gridId).add(e.rowIndex,e.colIndex)};for(let e=0;e<t.length;e++){let f=t[e],p=f.owner;if(p===null||!i.isLiveNode(p))continue;let m=p.gridId,h=n.gridsAll.get(m);if(!h)continue;let g=p.rowIndex,_=p.colIndex,v=h.getValues().getValueAt(g,_),b=I(v),x=b?v:Ne(h.getSpills(),g,_);if(x===null||x.calls.indexOf(f)<0)continue;if(!x.direct){l.add(p),s(a,m).add(g,_);continue}if(!b||f.latest?.isIRange){u.push(p);continue}let S=c.get(m);S||c.set(m,S={grid:h,runs:s(new Map,m),errors:new Map}),S.runs.add(g,_);let C=f.latest;if(y.isError(C)){let e=C.getLabel(),t={colStart:_,rowStart:g,colEnd:_,rowEnd:g},n=S.errors.get(e);n?n.push(t):S.errors.set(e,[t])}p.state&=~(er|lr|dr|fr),ms.colStart=_,ms.colEnd=_,ms.rowStart=g,ms.rowEnd=g,ms.scope=m;let w=r.search(ms);for(let e=0;e<w.length;e++){let t=w[e],n=t.value;if(n.index<0){let e=n.formulaEntry.value;o.push({...e.ref,scope:e.gridId})}else yn(t,g,_,d)}}for(let[t,n]of c){let r=n.grid.beginUpdates(),i=n.runs.done();r.notifyValues.load(i);let a=Array(i.length);for(let e=0;e<i.length;e++){let t=i[e];r.calcStatusSpatial.insertNonOverlapping({...t,value:null}),a[e]={...t,value:!1},_e(r.errorSpatial,t)}r.notifyCalcStatus.load(a);for(let[e,t]of n.errors)r.errorSpatial.load(_s(t).map(t=>({...t,value:e})));e.noteRepaint(t)}for(let e=0;e<u.length;e++){let t=u[e];l.has(t)||(t.state|=ur),s(a,t.gridId).add(t.rowIndex,t.colIndex)}let f=o;for(let[e,t]of a){let n=t.done();for(let t=0;t<n.length;t++)f.push({...n[t],scope:e})}f.length>0&&e.addSettleDirty(f),this._callbacks.calculate(void 0,void 0,!0)}createFormulaBlock(e,t,n,r,i,a,o){let s=this._callbacks.getCompiler(a);if(!s)throw Error(`The calculation engine has not started; nothing can compile yet.`);let c=Nt(e)?.bookId??null,l=c?null:Nt(this._externalBindings.getNameById(e)?.getScope()??``)?.bookId??null;return new In(s.compile(t.getRuntime(),r,i,n,this._symbols,e=>t.getFunction(e),c??l?Me(c??l,-1):this.getSheetName(e),o,c?{book:c}:void 0),t,this._calcScope,e,()=>this.getGrid(e)?.getEntireCoords()??null,this._resolvers)}getSymbols(){return this._symbols}getSheetIndex(e){if(e===void 0)return this._getSheetIndex?.()??-1;let t=this.getSheetIdByName(e);return t===null?this._getSheetIndex?.(e)??-1:this.getSheetIds().indexOf(t)}getSheetCount(){return this._getState().sheets.size}getSheetIds(){return this._sheetsCache().ids}getSheetSpanIds(e){let t=Wt(e);if(t){let e=this.getSheetIds(),n=e.indexOf(t[0]),r=e.indexOf(t[1]);return n===-1||r===-1?null:e.slice(Math.min(n,r),Math.max(n,r)+1)}let n=Nt(e);if(!n||n.sheetEnd===n.sheetIndex)return null;let r=[];for(let e=n.sheetIndex;e<=n.sheetEnd;e++)r.push(Me(n.bookId,e));return r}getFormulas(){return this._getState().formulaSpatial}setFormulas(e){this._amendState({formulaSpatial:e},$)}getPrecedents(){return this._getState().precedentSpatial}setPrecedents(e){this._amendState({precedentSpatial:e},$)}getDynamics(){return this._getState().dynamicByBlock}setDynamics(e){this._amendState({dynamicByBlock:e},$)}addDynamicPrecedent(e,t,n){this._calcExecutor._addDynamicPrecedent?.(e,t,n)}evaluateWhatIf(e){return this._calcExecutor.evaluateWhatIf(e)}getVolatiles(){return this._volatiles}isLegacyIntersect(){return this._legacyIntersect}getGridValues(e){let t=this._calcExecutor._whatIf?.get(e);if(t)return t;let n=this._calcExecutor._overlays?.get(e);if(n)return n;let r=this._calcExecutor._gridUpdates?.get(e);if(r)return r.values;let i=this._gridsAll().get(e);return i?i.getValues():(console.warn(`invalid gridId for updates`,e),null)}getIncrementalUpdates(e){let t=this._calcExecutor._gridUpdates;if(!t)return null;let n=t.get(e);if(!n){let r=this.getGrid(e);if(!r)return console.warn(`invalid gridId for updates`,e),null;n=r.beginUpdates(),t.set(e,n)}return n}registerGrid(e){this._writeGridsAll(t=>{t.set(e.getId(),e)})}unregisterGrid(e){this._writeGridsAll(t=>{t.delete(e)})}_gridsAll(){return this._collecting?.gridsAll??this._getState().gridsAll}_writeGridsAll(e){let t=this._collecting;if(t)return void e(t.gridsAll??=new Map(this._getState().gridsAll));let n=new Map(this._getState().gridsAll);e(n),this._amendState({gridsAll:n},$)}_writeGridMaps(e){let t=this._collecting;if(t)return void e(t.gridMaps??=new Map(this._getState().gridMaps));let n=new Map(this._getState().gridMaps);e(n),this._amendState({gridMaps:n},$)}_collectingGrids(e){if(this._collecting)return e();this._collecting={gridsAll:null,gridMaps:null,touched:null};let n=this._heldCloneKey===null;n&&(this._heldCloneKey=t.uuidV4());try{return e()}finally{n&&(this._heldCloneKey=null);let e=this._collecting;this._collecting=null;let t={};e.gridsAll&&(t.gridsAll=e.gridsAll),e.gridMaps&&(t.gridMaps=e.gridMaps),(e.gridsAll||e.gridMaps)&&this._amendState(t,$);let r=e.touched,i=r?this._getTransactions().getPendingTransaction():null;r&&i&&i.setIntent(ys,e=>{let t={...e??{}};for(let[e,n]of r)t[e]=t[e]?[...t[e],...n]:n;return t})}}getGrid(e){return this.isClosed()?null:this._gridsAll().get(e)??null}markDirty(e){let t=this._getState(),n=t.dirtySpatial.clone(this._heldCloneKey),r=t.precedentSpatial,i=t.formulaSpatial,a=!1,o=Ut(e,v.Axis.Column,2);for(let e=0;e<o.length;e++){let t=o[e];(r?.has(t)||i?.has(t))&&(a=!0,n.insertNonOverlapping(t))}return a&&(this._amendState({dirtySpatial:n},$),this._callbacks.onDirty()),a}getDirtyGrid(e){return this._getState().dirtySpatial.getSpatialAt(e)}calculateGrid(e,t){return this._callbacks.calculate(t,e)}requestCalculateGrid(e){this._callbacks.owePass(e)}getCycleId(){return this._cycleId}getCalculatedCommitId(){return this._calculatedCommitId}landRequest(e,t){if(e??=this._modelLanding()??void 0,e===void 0)return t();let n=this._getTransactions(),r=n.getCurrentCommit(!1).getId();if(this._engineIds.has(e)||e===r||n.getPendingTransaction()!==null)return n.amend(r,t);let i=n.beginCommit(),a;try{a=t(),i.commit()}catch(e){throw i.rollback(),e}let o=n.getCurrentCommit(!1).getId();return this._engineIds.set(e,o),o!==r&&this._landingOf.set(o,e),a}sendRequest(e,t,n){return this._callbacks.sendRequest(e,t,n)}getImager(e){return this._callbacks.getImager(e)}setGridMaps(e,t){this._writeGridMaps(n=>{n.set(e,t)})}recordTouched(e,t){if(t.length===0)return;let n=this._collecting;if(n){let r=n.touched??=new Map,i=r.get(e);i?i.push(...t):r.set(e,[...t])}else this._recordTouchedNow(e,t)}_recordTouchedNow(e,t){let n=this._getTransactions().getPendingTransaction();n&&n.setIntent(ys,n=>{let r={...n??{}};return r[e]=[...r[e]??[],...t],r})}revertTo(e,t){return this.restoreTo(e)?.get(t)??null}getCalcEpochs(){let e=this._getState();return e.formulaSpatial!==this._epochSeenFormulas&&(this._epochSeenFormulas=e.formulaSpatial,this._staticEpoch++,this._precedentEpoch++),e.precedentSpatial!==this._epochSeenPrecedents&&(this._epochSeenPrecedents=e.precedentSpatial,this._precedentEpoch++),e.dynamicByBlock!==this._epochSeenDynamics&&(this._epochSeenDynamics=e.dynamicByBlock,this._precedentEpoch++),{staticEpoch:this._staticEpoch,precedentEpoch:this._precedentEpoch}}bumpCalcEpochs(e){e&&this._staticEpoch++,this._precedentEpoch++}getNow(){return this._runtime.getNow()}whenSafe(e){this._callbacks.whenSafe(e,!1)}isLoading(){return this._callbacks.isLoading()}recompileNamed(e,t=!1){if(t){let t=this._recompileLoadedPending;t?t.add(e):(this._recompileLoadedPending=new Set([e]),this._callbacks.whenSafe(async()=>{let e=this._recompileLoadedPending;this._recompileLoadedPending=null,e&&this.recompileReferencing(e,!0)},!1));return}let n=this._recompileNamedPending;n?n.add(e):(this._recompileNamedPending=new Set([e]),this._callbacks.whenSafe(async()=>{let e=this._recompileNamedPending;this._recompileNamedPending=null,e&&this.recompileReferencing(e)},!1))}invalidateNamed(e){let t=this._invalidateNamedPending;t?t.add(e):(this._invalidateNamedPending=new Set([e]),this._callbacks.whenSafe(async()=>{let e=this._invalidateNamedPending;this._invalidateNamedPending=null,e&&this.markDirtyReferencing(e)},!1))}getNamedNodeInfo(e,t){return t&&this.getNamedDependents(e).length===0?null:this._callbacks.getNameNodeInfo(e)}getNamedDependents(e){return this.getSymbolDependents(e)}getNamedDependentNames(e){let t=new Set,n=[e];for(let e=0;e<n.length;e++){let r=this.getNamedDependents(n[e]);for(let e=0;e<r.length;e++){let i=r[e].scope;i&&!t.has(i)&&this._callbacks.isDefinedName(i)&&(t.add(i),n.push(i))}}return t}_nameGraphNow(e,n,r){let i=[],a=new Set,s=(e,t)=>{i.push({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,scope:t})};if(n===`precedents`){let n=[e],i=new Set(n);for(let e=0;e<n.length;e++){let c=this.getGrid(n[e]);if(!c)continue;let l=r?c.getDirectPrecedentsAt(o.EmptyRange):c.getPrecedentsAt(o.EmptyRange);for(let e=0;e<l.length;e++)l[e].scope&&s(l[e],l[e].scope);let u=c.getFormulaBlockAt(0,0)?.getNamedIds()??t.EmptyArray;for(let e=0;e<u.length;e++){let t=u[e];this.getNamedNodeInfo(t)&&(a.add(t),r||i.has(t)||(i.add(t),n.push(t)))}}}else{let n=new Set(this.getSheetIds()),i=e=>{if(n.has(e))return e;let t=this.getGrid(e)?.getShadowOf()??null;return t!==null&&n.has(t)?t:null},o=[e],c=new Set(o),l=e=>{a.add(e),c.has(e)||(c.add(e),o.push(e))},u=e=>{l(e);for(let t of this.getNamedDependentNames(e))l(t)};if(!r)for(let t of this.getNamedDependentNames(e))l(t);for(let e=0;e<o.length;e++){let n=this.getNamedDependents(o[e]);for(let e=0;e<n.length;e++){let o=n[e],c=o.scope;if(!c)continue;let l=i(c);if(l===null){r&&a.add(c);continue}if(s(o,l),r||l!==c)continue;let d=this.getGrid(c)?.getDependentsAt(o)??t.EmptyArray;for(let e=0;e<d.length;e++){let t=d[e],n=i(t.scope??c);n===null?t.scope&&u(t.scope):s(t,n)}}}}let c=[];for(let e of a){let t=this.getNamedNodeInfo(e);t&&c.push(t)}return{cells:i,names:c}}createBackendGrid(e){let t=new Ni({...this._gridOptions,...e,context:this._context,container:this,calculation:this._calculation});return this._writeGridsAll(e=>{e.set(t.getId(),t)}),t}createEngineGrid(e){let t=e.id,n=e.sizeOf,r=e.entireCoords,i=n===void 0?r?()=>r:void 0:()=>this.getGrid(n)?.getEntireCoords()??Se,a=this._callbacks;return this.createBackendGrid({uuid:t,shadowOf:e.shadowOf,unanchored:e.unanchored,arrayFirstCell:e.arrayFirstCell,paged:e.paged,getEntireCoords:i,onCalculated:e=>{a.onCalculated(t,e)}})}open(){this._holdsGrids=!0,this._externalBindings.sync(!0)}drop(){this._holdsGrids=!1,this._volatiles.clear(),this._deferred.close(),this._amendState({gridsAll:new Map,gridMaps:new Map,formulaSpatial:new kn({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),precedentSpatial:new kn({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}}),dynamicByBlock:new Map,dirtySpatial:new kn},$)}getGrids(){return this._gridsAll()}syncExternalBooks(e=!1){return this._externalBindings.sync(e)}getExternalName(e){return this._externalBindings.getNameById(e)}getExternalNameByScope(e,t){return this._externalBindings.getNameByScope(e,t)}apply(e,t,n,r=!1){switch(n.type){case`sheets`:return this.applySheets(n.sheets),{cycleId:this._cycleId,commitId:Ae(n)};case`tables`:return this.applyTables(n.changes),{cycleId:this._cycleId,commitId:Ae(n)};case`names`:return this.applyNames(n.changes),{cycleId:this._cycleId,commitId:Ae(n)};case`nameGraph`:return{cycleId:this._cycleId,answer:this._nameGraphNow(n.nameId,n.kind,n.direct)};case`rollback`:return this.rollbackSavepoint(n.savepointId),{cycleId:this._cycleId};case`create`:return this.createEngineGrid(n.spec),{cycleId:this._cycleId};case`requestPass`:return{cycleId:this._cycleId}}let i=this.getGrid(e);return i?r?i._apply(n,this.getCurrentCommitId(),!0):i._apply(n,t):{cycleId:this._cycleId,commitId:Ae(n)}}applyHeld(e,n){let r=this._getTransactions(),i=r.getCurrentCommit(!1).getId();this._heldCloneKey=t.uuidV4();try{return r.amend(i,()=>this._collectingGrids(()=>this._applyHeldNow(e,n)))}finally{this._heldCloneKey=null}}getHeldCloneKey(){return this._heldCloneKey}_applyHeldNow(e,t){let n=e=>e.type===`create`?0:e.type===`setBody`&&!0===e.body.priority?1:2,r=[];for(let t=0;t<3;t++)for(let i=0;i<e.length;i++)n(e[i].request)===t&&r.push(i);let i=null,a=null;for(let t=0;t<e.length;t++){let n=e[t].request;if(!e[t].dead){if(n.type===`sheets`)(i??=[]).push(...n.sheets);else if(n.type===`tables`)for(let[e,t]of n.changes)t&&!a?.has(e)&&(a??=new Map).set(e,t)}}i&&this.enterSheets(i),a&&this.enterTables(a);let o=[];for(let n=0;n<r.length;n++){let i=r[n],a=e[i],s=a.request;if(a.dead&&s.type!==`create`){let e=s.type===`rollback`||s.type===`requestPass`;o.push({index:i,response:e?{cycleId:this._cycleId}:{cycleId:this._cycleId,commitId:a.commitId}})}else{s.type===`seed`&&s.options?.full&&!t&&(s={...s,options:{...s.options,full:!1}});try{o.push({index:i,response:this.apply(a.gridId,void 0,s,!0)})}catch(e){o.push({index:i,error:e,failed:!0})}}}return o}followRestore(e,t){return t===N.Status.Off||t===N.Status.Error?(this.retarget(e),!1):t===N.Status.Running?this.holdsModelCommit(e)?(this.restoreTo(e),!1):(this.retarget(e),!0):(this.restoreTo(e)!==null||this.holdsModelCommit(e)||this.retarget(e),!1)}rebuild(e){this.drop(),this.setReplica(e),this.open()}compileTemporary(e,n){let{rowIndex:r,colIndex:i,target:a}=n,s=this._context,c=n.gridId,l=null;n.virtual&&(l=c,c=`temporary`,this.getGrid(c)||this.registerGrid(this.createBackendGrid({uuid:c})));let u=this.getGrids().get(c);if(!u)return null;let d=c,f=this._calcScope;f.colIndex=i,f.rowIndex=r,f.gridId=d;let p=this.createFormulaBlock(l??d,s,e,r,i,a),m=new hi(o.EmptyRange,d,p,this,!0);return{block:p,calcGrid:u,gridId:d,evaluate:(e,t,n)=>{let a=m.getAnchorNode();f.colIndex=i,f.rowIndex=r,f.gridId=d,a.gridId=d,a.colIndex=i,a.rowIndex=r,f.node=a;let o=f.deferCount,c;this._deferred.setServing(!0);try{c=e.evaluateAt(r,i,t)}finally{this._deferred.setServing(!1)}if(f.deferCount!==o){let e=this._deferred,t=e.endEvaluation();a.cachedValue=t.calls.length>0?e.newHolder(c,t):void 0,e.flush()}else I(a.cachedValue)&&(a.cachedValue=void 0);let l=vn(e.finalizeValue(c));return l===null&&(l=0),!n||l?.isIRange||Array.isArray(l)?l:s.createRange(1,1,l)},getCalls:()=>{let e=m.getAnchorNode().cachedValue;return I(e)?e.calls:t.EmptyArray}}}toStoredText(e,t,n,r){return this.createFormulaBlock(e,this._context,t,n,r).getTextAt(n,r)}getSymbolDependents(e){return this._getSymbolIndex().get(e)??bs}_getSymbolIndex(){let e=this._getState().formulaSpatial;if(this._symbolIndexOf!==e||!this._symbolIndex){let t=new Map,n=e.all3D();for(let e=0;e<n.length;e++){let r=n[e].value;if(r.gridId==null||at(r.gridId)||this._externalBindings.getNameById(r.gridId))continue;let i=r.getReferencedSymbolIds();if(i.length===0)continue;let a=r.ref,o={rowStart:a.rowStart,colStart:a.colStart,rowEnd:a.rowEnd,colEnd:a.colEnd,scope:r.gridId};for(let e=0;e<i.length;e++){let n=t.get(i[e]);n?n.push(o):t.set(i[e],[o])}}this._symbolIndex=t,this._symbolIndexOf=e}return this._symbolIndex}_namedTargets(e){let t=new Set(e);for(let n of e)for(let e of this.getNamedDependentNames(n))t.add(e);return t}markDirtyReferencing(e){if(e.size===0)return!1;let t=this._namedTargets(e),n=this._getState().formulaSpatial.all3D(),r=[];for(let e=0;e<n.length;e++){let i=n[e].value;if(i.gridId==null)continue;let a=i.getReferencedSymbolIds();for(let e=0;e<a.length;e++)if(t.has(a[e])){r.push({...i.ref,scope:i.gridId});break}}return r.length!==0&&(this.markDirty(r),!0)}recompileReferencing(e,t=!1){if(e.size===0)return;let n=this._callbacks,r=this._namedTargets(e),i=[];for(let t of e){let e=n.getTable(t);e&&i.push([t,e])}let a=null,o=this._getState().formulaSpatial.all3D();for(let e=0;e<o.length;e++){let s=o[e].value,c=s.getReferencedSymbolIds(),l=!1;for(let e=0;e<c.length&&!l;e++)l=r.has(c[e]);if(!l)continue;let u=s.ref,d=s.formula,f=s.gridId;if(t&&f!=null&&(s.fromLoad||n.isDefinedName(f))){let t=(a??=new Map).get(f);t?t.push(o[e]):a.set(f,[o[e]]);continue}let p=f!=null&&!n.isDefinedName(f)&&!at(f)&&!this._externalBindings.getNameById(f);if(d&&p)for(let e=0;e<i.length;e++){let[t,n]=i[e];c.includes(t)&&(d=d.replaceTableReferences(t,e=>w(e,n)?F():null))}let m=d&&d!==s.formula?d.getTextAt(u.rowStart,u.colStart):s.getTextAt(u.rowStart,u.colStart);this._writeBlockText(s,m)}if(a)for(let[e,t]of a)this.getGrid(e)?._rederivePrecedentsNow(t)}refitTableRows(e,t,n,r,i){let a=this._symbols.bind(U.Sheet,e);if(!a)return;let s=this._getState().precedentSpatial.search({colStart:t.colStart,rowStart:n.rowStart,colEnd:t.colEnd,rowEnd:n.rowEnd,scope:a}),c=null;for(let e=0;e<s.length;e++){let t=s[e].value;if(t.index<0)continue;let n=t.formulaEntry.value,r=n.gridId;if(r==null||at(r)||this._externalBindings.getNameById(r))continue;let i=(c??=new Map).get(n);i?i.includes(t.index)||i.push(t.index):c.set(n,[t.index])}if(!c)return;let l=(e,t,n,r,i)=>{if(t)return e===n?[r,i]:null;let a=n-e;return a>=r&&a<=i?[a,a]:null},u=(e,t,n,r,i,a)=>{if(t)return(r?e>=n:e<=n)?[i,a]:null;let o=r?Math.max(i,n-e):i,s=r?a:Math.min(a,n-e);return o<=s?[o,s]:null},d=(e,t)=>{if(!e||!t)return null;let n=Math.max(e[0],t[0]),r=Math.min(e[1],t[1]);return n<=r?[n,r]:null};for(let[e,s]of c){let c=e.ref,f=(c.rowStart!==c.rowEnd||c.colStart!==c.colEnd)&&(e.getAnchorNode().ext?.fixedRef??null)!==null,p=[];for(let o=0;o<s.length;o++){let m=s[o],h=e.getReferenceAt(c.rowStart,c.colStart,m);if(!h||h.colStart===void 0||h.scope&&h.scope!==a)continue;let g=e=>({...h,rowStart:h.rowStart+(e?i.rowStart-n.rowStart:0),rowEnd:h.rowEnd+(i.rowEnd-n.rowEnd)}),_=c.rowStart,v=f?c.rowStart:c.rowEnd,y=c.colStart,b=f?c.colStart:c.colEnd,x=d(u(h.colStart,h.$colStart,t.colStart,!0,y,b),u(h.colEnd,h.$colEnd,t.colEnd,!1,y,b));if(!x)continue;let S=l(h.rowEnd,h.$rowEnd,n.rowEnd,_,v);if(S)for(let e of r===null?[n.rowStart]:[n.rowStart,r]){let t=d(S,l(h.rowStart,h.$rowStart,e,_,v));t&&p.push({coords:f?c:{rowStart:t[0],rowEnd:t[1],colStart:x[0],colEnd:x[1]},index:m,refitted:g(e===n.rowStart)})}}if(p.length===0)continue;let m=new Set,h=new Set;for(let e=0;e<p.length;e++){let t=p[e].coords;m.add(t.rowStart).add(t.rowEnd+1),h.add(t.colStart).add(t.colEnd+1)}let g=Array.from(m).sort((e,t)=>e-t),_=Array.from(h).sort((e,t)=>e-t);for(let t=0;t<g.length-1;t++)for(let n=0;n<_.length-1;n++){let r={rowStart:g[t],rowEnd:g[t+1]-1,colStart:_[n],colEnd:_[n+1]-1},i=e.formula,a=i;for(let e=0;e<p.length;e++)o.isRangeWithinRange(r,p[e].coords)&&(a=a.setReferenceAt(p[e].index,p[e].refitted));a!==i&&this._writeBlockText(e,a.getTextAt(r.rowStart,r.colStart),r)}}}rewriteTableReferences(e,t){let n=e=>t?ge(e,t):F(),r=this._callbacks,i=this._getState().formulaSpatial.all3D();for(let t=0;t<i.length;t++){let a=i[t].value,o=a.gridId;if(o==null||!a.getReferencedSymbolIds().includes(e)||r.isDefinedName(o)||at(o)||this._externalBindings.getNameById(o))continue;let s=a.formula,c=s?.replaceTableReferences(e,n);if(!c||c===s)continue;let l=a.ref;this._writeBlockText(a,c.getTextAt(l.rowStart,l.colStart))}}_writeBlockText(e,t,n=e.ref){let r=this.getGrid(e.gridId);if(!r)return;let i=n;if(e.unanchored&&this.invalidateNamed(e.gridId),this._callbacks.rewriteHost(e.gridId,i,t))return;r._setInputsNow(null,[{...i,value:t}]);let a=this._getState().formulaSpatial.search({...i,scope:e.gridId});for(let t=0;t<a.length;t++){let n=a[t].value;n!==e&&o.isEqualRanges(n.ref,i)&&ri(e,n)}}hasDirty(){return!this._getState().dirtySpatial.isEmpty()}runPass(e,t){let n=this._getState(),r=!0===t.settle,i=!r&&(t.full??n.isFullCalcRequired),{gridId:a,calcCoords:o}=t,s=this._getTransactions().getCurrentCommit().getId();if(a&&!i&&!o&&s===this._calculatedEngineId&&n.dirtySpatial.isEmpty())return;this._calculatedEngineId=s,this._calculatedCommitId=t.openOperationId??this._mirroredId??s;let c=r?new Set:this._volatiles;r||(this._volatiles=new Set);let l=++this._cycleId,u=this._calcExecutor.execute(l,{isFullCalc:i,calcCoords:o,gridId:a,scopeGridId:e?.scope,settle:r,external:!0===t.external,load:!0===t.load,iterate:t.iterate,exceptTables:!0===t.exceptTables&&!i},{gridsAll:n.gridsAll,formulaSpatial:n.formulaSpatial,dirtySpatial:n.dirtySpatial,oldVolatiles:c});if(!u)return;let d=r||!!o,f=!o&&e?.scope&&n.gridsAll.has(e.scope)?e.scope:null,p;d?p=n.dirtySpatial:f?(p=n.dirtySpatial.clone(),p.getSpatialAt(f)?.clear()):p=new kn;let m=u.skippedTables;if(m){p===n.dirtySpatial&&(p=p.clone());for(let e=0;e<m.length;e++)p.insertNonOverlapping(m[e])}this._amendState({precedentSpatial:u.precedentSpatial,dynamicByBlock:u.dynamicByBlock,dirtySpatial:p,isFullCalcRequired:!(!d&&!f)&&n.isFullCalcRequired},$);for(let t of u.lastUpdates.values())t.done(l,e)}async calculateGrids(e){let t=this._getState(),n=t.gridsAll,r=e?n.keys():t.dirtySpatial.getScopeKeys(),i=[];for(let e of r){let t=n.get(e);t&&i.push(t._calculateNow())}await Promise.all(i)}getCycleCells(){return this._calcExecutor.getCycleCells()}getDemandStats(){return this._calcExecutor.getDemandStats()}resetStats(){this._calcExecutor.resetStats()}getPlanCacheMode(){return this._calcExecutor.planCacheMode}setPlanCacheMode(e){this._calcExecutor.planCacheMode=e}getSheets(){return this._getState().sheets}getTables(){return this._getState().tables}getNames(){return this._getState().names}setReplica(e){this._amendState({sheets:e.sheets,gridless:e.gridless??Ss,tables:e.tables,names:e.names},$)}applySheets(e){let t=this._getState().sheets,n=new Map;for(let t=0;t<e.length;t++)n.set(e[t][0],e[t][1]);let r=!1,i=0,a=Array.from(n.keys());for(let[e,o]of t){if(n.has(e)&&(n.get(e)!==o||a[i]!==e)){r=!0;break}i++}this._amendState({sheets:n,gridless:Cs(e)},$);let o=this._callbacks;r&&o.whenSafe(()=>o.calculate(xs),!1)}enterSheets(e){let t=this._getState().sheets,n=null,r=null;for(let[i,a,o]of e)t.has(i)||n?.has(i)||((n??=new Map(t)).set(i,a),o&&(r??=new Set(this._getState().gridless)).add(i));n&&this._amendState(r?{sheets:n,gridless:r}:{sheets:n},$)}enterTables(e){let t=this._getState().tables,n=null;for(let[r,i]of e)t.has(r)||(n??=new Map(t)).set(r,i);n&&this._amendState({tables:n},$)}applyTables(e){let t=new Map(this._getState().tables);for(let n=0;n<e.length;n++){let[r,i]=e[n];i?t.set(r,i):t.delete(r)}this._amendState({tables:t},$),this._callbacks.onSymbolsChanged(`tables`)}applyNames(e){let t=new Map(this._getState().names);for(let n=0;n<e.length;n++){let[r,i]=e[n];i?t.set(r,i):t.delete(r)}this._amendState({names:t},$),this._callbacks.onSymbolsChanged(`names`)}getReplicaTables(){let e=this._getState()?.tables;if(!e)return null;let t=this._tablesDerived;if(!t||t.of!==e){let n=new Map;for(let[t,r]of e)n.set(r[0].toLowerCase(),t);t=this._tablesDerived={of:e,idByName:n}}return t}getReplicaNames(){let e=this._getState()?.names;if(!e)return null;let t=this._namesDerived;if(!t||t.of!==e){let n=new Map;for(let[t,r]of e){let e=r[0].toLowerCase(),i=n.get(e);i?i.push(t):n.set(e,[t])}t=this._namesDerived={of:e,idsByName:n}}return t}getReplicaNameId(e,t){let n=this.getReplicaNames(),r=n?.idsByName.get(e.toLowerCase());if(!r)return;let i,a,o=null;t&&(o=this._getState().sheets.has(t)?t:this._sheetsCache().idByName.get(t.toLowerCase())??t);for(let e=0;e<r.length;e++){let t=n.of.get(r[e])[1];if(t!==null){if(o!==null&&t===o)return r[e];a??=r[e]}else i??=r[e]}return t?i:i??a}getSheetIdByName(e){return this._sheetsCache().idByName.get(e.toLowerCase())??null}isGridless(e){return this._getState().gridless.has(e)}getSheetName(e){return this._getState().sheets.get(e)??null}_sheetsCache(){let e=this._getState().sheets,t=this._sheetsDerived;if(!t||t.of!==e){let n=[],r=new Map;for(let[t,i]of e)n.push(t),i!==null&&r.set(i.toLowerCase(),t);t=this._sheetsDerived={of:e,ids:n,idByName:r}}return t}getCommitTimestamp(){return this._getTransactions().getCurrentCommit().getTimestamp()}getCurrentCommitId(){return this._getTransactions().getCurrentCommit(!1).getId()}mirror(e){if(this.isClosed())return;let t=this._getTransactions();if(t.getPendingTransaction()===null){let n=t.beginCommit();n.updateState(this._id,{...this._getState(),mirrorOf:e}),n.commit()}let n=t.getCurrentCommit(!1).getId();this._engineIds.set(e,n),this._landingOf.get(n)===void 0&&this._landingOf.set(n,e),this._mirroredId=e,this._engineIds.size>2*vs&&this._sweepLandings()}retarget(e){this._mirroredId=e,this._lastRevert=null}holdsModelCommit(e){let t=this._engineIds.get(e);return t!==void 0&&this._holdsEngineCommit(t)}dropLanding(e){let t=this._engineIds.get(e);t!==void 0&&(this._engineIds.delete(e),this._landingOf.get(t)===e&&this._landingOf.delete(t))}forgetEarlierLandings(){let e=this._mirroredId;if(this._engineIds.clear(),this._landingOf.clear(),this._lastRevert=null,e===null)return;let t=this._getTransactions().getCurrentCommit(!1).getId();this._engineIds.set(e,t),this._landingOf.set(t,e)}foldPhantom(e){let t=this._getTransactions(),n=`${e}:`,r=(e,t)=>{let n={...e,...t},r=e?.[ys],i=t?.[ys];if(r&&i){let e={...r};for(let t of Object.keys(i))e[t]=[...e[t]??[],...i[t]];n[ys]=e}return n};for(;;){let e=t.getTipCommit().getId(),i=this._landingOf.get(e);if(i===void 0||!i.startsWith(n)||!t._squashTip(r))break;this._landingOf.delete(e),this._engineIds.delete(i)}this._engineIds.delete(`${e}:0`),this._lastRevert=null}restoreTo(e){let t=this._getTransactions(),n=this._engineIds.get(e);if(n===void 0)return null;if(!this._holdsEngineCommit(n))return this.dropLanding(e),null;let r=t.getCurrentCommit(!1).getId(),i=this._lastRevert;if(i&&i.commitId===e&&r===n)return i.regions;if(r===n)return this._mirroredId=e,null;let a=(e,n)=>{let r=t.getLog(e,2**53-1),i=[];for(let e=0;e<r.length;e++){if(r[e].getId()===n)return i;i.push(r[e])}return null},o=a(r,n)??a(n,r),s=new Map;if(o)for(let e=0;e<o.length;e++){let t=o[e].getIntents()?.[ys];if(t)for(let e of Object.keys(t))s.set(e,[...s.get(e)??[],...t[e]])}t.restore(n),this._mirroredId=e,this._lastRevert={commitId:e,regions:s};let c=[];return s.forEach((e,t)=>{for(let n=0;n<e.length;n++)c.push({...e[n],scope:t})}),c.length>0&&this.markDirty(c),s}rollbackSavepoint(e){let t=this._getTransactions(),n=this._engineIds.get(e);if(n===void 0||(this._engineIds.delete(e),this._landingOf.get(n)!==e))return;let r=e.slice(0,e.lastIndexOf(`:`)+1),i=t.getLog(t.getCurrentCommit(!1).getId(),2**53-1),a=[];for(let t=0;t<i.length;t++){let o=i[t],s=this._landingOf.get(o.getId());if(s===void 0||!s.startsWith(r))return void console.warn(`a rolled-back savepoint is not the engine's latest commit`,e);if(a.push(o),o.getId()===n)break}if(a[a.length-1]?.getId()!==n)return;t.revert(n),this._lastRevert=null;let o=[];for(let e=0;e<a.length;e++){let t=a[e].getId();this._engineIds.delete(this._landingOf.get(t)),this._landingOf.delete(t);let n=a[e].getIntents()?.[ys];if(n)for(let e of Object.keys(n)){let t=n[e];for(let n=0;n<t.length;n++)o.push({...t[n],scope:e})}}o.length>0&&this.markDirty(o)}_holdsEngineCommit(e){return this._getTransactions().getStateAt(e,this._id)!==void 0}_sweepLandings(){let e=this._getTransactions(),t=new Set,n=e.getLog(e.getTipCommit().getId(),2**53-1);for(let e=0;e<n.length;e++)t.add(n[e].getId());this._engineIds.forEach((e,n)=>{t.has(e)||this._engineIds.delete(n)}),this._landingOf.forEach((e,n)=>{t.has(n)||this._landingOf.delete(n)})}_modelLanding(){return this._getTransactions().getPendingTransaction()===null?this._callbacks.getModelLanding():null}_updateState(e,t,n){return this._amendState(e,t,n)}_amendState(e,t,n){let r=this._modelLanding();return r===null?super._amendState(e,t,n):this.landRequest(r,()=>super._amendState(e,t,n))}_processRestoreOrRevert(e,t){super._processRestoreOrRevert(e,t),e.gridMaps.forEach((t,n)=>{e.gridsAll.get(n)?._adoptMaps(t)}),this._callbacks.onRestored()}get[Symbol.toStringTag](){return`[CalcBackend]`}toString(){return`CalcBackend`}},ms={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:void 0},hs=class{constructor(e){this._unordered=null,this._lastMajor=-1,this._lastMinor=-1,this._isColumn=e,this._conflating=ue(e)}add(e,t){let n=this._unordered;if(n!==null)return void n.push({colStart:t,rowStart:e,colEnd:t,rowEnd:e});let r=this._isColumn?t:e,i=this._isColumn?e:t;if(r>this._lastMajor||r===this._lastMajor&&i>this._lastMinor)return this._conflating.append(r,i),this._lastMajor=r,void(this._lastMinor=i);this._unordered=this._conflating.done(!0).map(gs),this._unordered.push({colStart:t,rowStart:e,colEnd:t,rowEnd:e})}done(){let e=this._unordered;return e===null?this._conflating.done(!0).map(gs):_s(e)}},gs=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}),_s=e=>{let t=Ut(e,v.Axis.Column,2),n=Array(t.length);for(let e=0;e<t.length;e++){let r=t[e];n[e]={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd,rowEnd:r.rowEnd}}return n},vs=4e3,ys=`calc.touched`,bs=Object.freeze([]),xs=Object.freeze({full:!0}),$=Object.freeze({description:a(`op.updateCalculations`)}),Ss=new Set,Cs=e=>{let t=null;for(let n=0;n<e.length;n++)e[n][2]&&(t??=new Set).add(e[n][0]);return t??Ss};export{ps as CalcBackend};
|