@sheetxl/mcp 0.8.0-beta.20 → 0.8.0-beta.22
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/{noAnElnMhF05bfJN.js → 0jPw8-AyT6VbPuGO.js} +1 -1
- package/assets/{C7oUg84aGjYrJUc6.js → 1U3DwsqHnOBwiGWn.js} +2 -2
- package/assets/{DALP-GkmzCJdFIV9.js → 1dUPpOVZSeeylKHv.js} +1 -1
- package/assets/{TdK2ciXA5BAlGjbR.js → 3N6hsbh2WLceyO6T.js} +1 -1
- package/assets/{C3BZQ5NFwAU_ZdeQ.js → 4zyHb1mmcFfqwpjO.js} +1 -1
- package/assets/{C0MAjW1vgsw6o0fx.js → 8csqJ8aGOdnKlrLl.js} +1 -1
- package/assets/{C9w-KoMwxvouC73F.js → 91BKH9obG4IfBzhy.js} +514 -505
- package/assets/{tCavNu-Tru6yRbec.js → 9AosCdy_xtdhLjN1.js} +1 -1
- package/assets/{rtUwIBgECTX9UO_B.js → B5VTjL9m0R-Icfaz.js} +4 -4
- package/assets/{Z1zwOeCe-JTLgkxf.js → B6pXiayrnDoDbQt1.js} +57 -57
- package/assets/{DwsoGIyPuoQij_vi.js → BDq4iVyBh5lwX8pE.js} +1 -1
- package/assets/{4Za9gEGCvms62R7k.js → BHsqPfJZrdKTbPLP.js} +1 -1
- package/assets/{DPUXpIzEs1t-jBiv.js → BI5L_Ysr8s0TQxdg.js} +1 -1
- package/assets/{-qQT-DFFz0CqGx5C.js → BPZWfwUvFCLQInXN.js} +395 -395
- package/assets/{CgIHqG1qp9n1Gwm7.js → BRVEVVhj-8ZPrNyQ.js} +326 -321
- package/assets/{C9aV1SF8uCWIB4zU.js → BSdRn3B8QeJFflY6.js} +15 -15
- package/assets/{CrRJqUPbvvhnp4p4.js → BUGEQS5WdiLcI_0X.js} +1 -1
- package/assets/{DvRH46hupHUjkc7a.js → BUIjRIGTum7VuRFk.js} +1 -1
- package/assets/{CrULZhDt8uE-MR2s.js → BV49J63s68Mj6lgF.js} +1 -1
- package/assets/{DcwqgbgqPyzQxSsQ.js → BXean6K6oDUxkzyd.js} +1 -1
- package/assets/{B5UmlawoCVwHHM_e.js → BZxJKqVEO7B23XwE.js} +5 -5
- package/assets/{DYRis8fOyk2uIZ-1.js → BaaVzb7xXROiWUhT.js} +4 -4
- package/assets/{swG-DVTsez1uNW8c.js → Bf7Irm8Ua4s1T4xH.js} +1 -1
- package/assets/{BGlx7_eRiv47Hu9C.js → BgwCdHyXKQYFAl1M.js} +1 -1
- package/assets/{DNwyEanz3LqtOorY.js → Bi65BKwwiZYYZprq.js} +1 -1
- package/assets/{C46dyA4YSP1-iTSN.js → BiC09_YKQPmlUklQ.js} +1 -1
- package/assets/{CDmri0gcZxpVZfWn.js → BkqENH8xJ3_NQnD5.js} +377 -377
- package/assets/{CaOEaghQqXiA1ZzO.js → BlxrCp7d-SeM-2DW.js} +115 -115
- package/assets/{DBfBV-tvRxCLgdvs.js → BnGNMsqG5CzUzmX7.js} +4 -4
- package/assets/{u-pSumbU-rgT6eLF.js → BnK6HEqT4rf1RoOG.js} +226 -226
- package/assets/{DZ2Njh8YgfXcv7EM.js → BrfsWImwRtf54LUU.js} +1 -1
- package/assets/{BYYbglFmasE5PrS2.js → BvKzhnweVF6GhjXh.js} +1 -1
- package/assets/{BKc7zTK6ZIhcD_Wu.js → Bx592y6pyOwTS2x7.js} +1 -1
- package/assets/{BghxJxTwaebNVcIS.js → BygXDW3XTdtR38aA.js} +1 -1
- package/assets/{Bp9zuG6P6r9GEb6G.js → BzFIkeB_lheiTR7z.js} +1 -1
- package/assets/{BBm3Xjnehvx2fYj8.js → Bzp3UtK_6fqEVlV8.js} +8 -8
- package/assets/{DTXRsv2Ww7WbIwCb.js → C1PTfp7kVu3DqqZh.js} +9859 -9844
- package/assets/{CoOIn2wx6je_rMDO.js → C1yAmXrOu3iHV2cu.js} +17 -17
- package/assets/{BMH_wtFTiRj43c69.js → C4-0s3Udk3v4ytSn.js} +2 -2
- package/assets/{YG5hEr6CzWNmNJQ2.js → C7zManFR1LEJXiwb.js} +1 -1
- package/assets/{NiD8iNE47sjggYTx.js → C9wlvcFyjQA59G-_.js} +1 -1
- package/assets/{BHiZ3GtGCWUWwHqY.js → CAgQJrDxGEfoa7jn.js} +3 -3
- package/assets/{DsSlUklPSAsh9DhW.js → CGB4xgirbgEIN3tg.js} +167 -167
- package/assets/{CpfpXfCqzZumY4pf.js → CGxhgXj5qKj_Ubcp.js} +1 -1
- package/assets/{Bg8EN9R3hbeNfFyU.js → CHG9Q0uLAZdLXYVz.js} +76 -76
- package/assets/{CbTKUrroY9PQ6eTu.js → CHnaSM8aMnQ2_VWW.js} +3 -3
- package/assets/{CW2Ca6tsd0aLTz88.js → CHpBOpoM9bCvQyn0.js} +1 -1
- package/assets/{D--emvI048MvLsXl.js → CHqnRMWNpLKcAWWn.js} +1 -1
- package/assets/{93ksqLKL1o40anfw.js → CKhbbbjQ-_auMp3n.js} +1 -1
- package/assets/{BGQ1GrnQ-X16GU8k.js → COVhUB0EotytQDHg.js} +2 -2
- package/assets/{4Qlx8FuxoYbVTgNW.js → CSGN4rAf7CYnBDEa.js} +19 -19
- package/assets/{DAVN6N3srI1WMHCN.js → CSKjFDYwiwn5XNnH.js} +2 -2
- package/assets/{MpvZt7VpFWEINIT6.js → CT99WREgkKGpcDTO.js} +1 -1
- package/assets/{C9JUgNS6CrdgIcW3.js → CV729JV1mNyYCmrq.js} +1 -1
- package/assets/{CTGfmocA1WgM0_e0.js → CXk5vwFfosghrTKo.js} +485 -485
- package/assets/{DV_nCOON8Fgq5RBt.js → CXqqaFgNeUVRGvEb.js} +2 -2
- package/assets/{CLFe9HgUi_83dE3d.js → CYCqMEoWsry6_hrc.js} +1 -1
- package/assets/{I7LAF1nLmYqQwt9i.js → Cahhn5OLNqRYy-n8.js} +1 -1
- package/assets/{uMoGfJGab8mZX6eN.js → CdtVv8YQ8PTmS4dz.js} +1 -1
- package/assets/{DSy6cpdU-KNWsbSj.js → CpYgsvYMxV5SbRp3.js} +2 -2
- package/assets/{Dx_IFz5FEPKw-HC1.js → Cu4VAHfmjXWfTMPu.js} +1 -1
- package/assets/{Drmg3-gF0VJs4Yx3.js → CufFcGwo5x95LSb7.js} +1 -1
- package/assets/{B4ii9PGvnlYkSX2q.js → CwNKcoA7na7Ess3a.js} +2 -2
- package/assets/{uoUKT9hTrwZ2INHN.js → D-MsUF59BhikcNZt.js} +3 -3
- package/assets/{yDh_W6M1rvuDhFv1.js → D-N87jCOShDKTFDh.js} +1 -1
- package/assets/{CaI562iJKKOoMw8p.js → D1tShC5iBlUoT2V2.js} +1 -1
- package/assets/{eWHWPRWHX6YU8bJU.js → D89TE5n8VKre9Gmp.js} +1 -1
- package/assets/{eV0oowKJe44NBnWj.js → D8dNiNpu9_L0NjGP.js} +1 -1
- package/assets/{C9wXzrhl0dwqZgJ6.js → D9ja7F9irHf9Iovx.js} +1 -1
- package/assets/{LugZP3XHNnoiiTJO.js → DAqaOCEQLmZRjcdR.js} +1 -1
- package/assets/{D4lMEKXi13vhDJbE.js → DEOkcuqKBFyRnY18.js} +1 -1
- package/assets/{B-7inN76S1zUWSAt.js → DFQLoYLUO4TgDZPK.js} +1 -1
- package/assets/{CyOyY32LLW-Pj_L7.js → DHHYGjNwlLvja3dS.js} +1 -1
- package/assets/{_LMcVYWJksPfGVxz.js → DLbzfP7OOWhafkTq.js} +1 -1
- package/assets/{DndzARNYtmumqGnG.js → DQIQR1t3IkC9wshP.js} +1 -1
- package/assets/{8FzS1bgbz4U1QE_m.js → DRd8gdwcr3EqtGkb.js} +1 -1
- package/assets/{mYZ9Z5AKCn7zltHw.js → DawLBAaNAAmo_P3Y.js} +2 -2
- package/assets/{BEq2PSZQN7VV19RQ.js → Dbh-XVDw294AVLtl.js} +1 -1
- package/assets/{CDvP9QyhDwdm3MZn.js → DdDKDqtpIkzd-mXi.js} +2 -2
- package/assets/{CpLTCQemd_cJ4yFu.js → DdXp_iPwTOHAOvlL.js} +8 -8
- package/assets/{Xkr_4WLwk0ZPaYH2.js → DdnALoxd3b8TLNla.js} +1 -1
- package/assets/{DIntlX_ha_wRdxYj.js → DevKDvFONeJ9euEq.js} +1 -1
- package/assets/{YGYD-116vlZfzPn1.js → DgVCjvTw9Df1DV1x.js} +15 -15
- package/assets/{DnDTldUjKy0O586y.js → DgYcOz0M0pmZf9x_.js} +2 -2
- package/assets/{BieAybaOdneMdvBS.js → DmVQgN-N_HhYvakk.js} +1 -1
- package/assets/DoScYrfTJOHXe-Ko.js +199 -0
- package/assets/{wYvkLI8IeHaWTtAx.js → DrLUi6vduqDLmQjl.js} +46 -46
- package/assets/{BJYl-kvBtcnMVP8W.js → Ds5pLAwSN4lSbao6.js} +1 -1
- package/assets/{klKXcdZmbQmsK2rt.js → DsBXjYAgTUXAAWZZ.js} +1 -1
- package/assets/{Ti7kMsQ-Eo3lkfIh.js → DtvJg63vbDd6B7sD.js} +6 -6
- package/assets/{nV0eE4R3npcOHLbx.js → Dvsld01DkmiNLjfP.js} +1 -1
- package/assets/{Dlbgs8csKymbxu7r.js → DxNK3HVEzFdUou54.js} +1 -1
- package/assets/{Dv9ZDmKuxn2tQDGb.js → DzGpZ2CQ1St9BF0y.js} +1 -1
- package/assets/{CUJiePMri5kkpdA7.js → E9mta1q4VtVUusy5.js} +1 -1
- package/assets/{DzLrAy24em5k5en0.js → GGcMgq3ScY7Tv0PE.js} +3 -3
- package/assets/{q57cDvIPcIvWlh5T.js → HVwvDMZh0ZGR-hRT.js} +3 -3
- package/assets/{IDq3QQa5uRqjVJx_.js → OfjHqYH31KqC5gVM.js} +1 -1
- package/assets/{Dc2LiflUYpt0nVVk.js → OtMeAlbq6tyW5Hnc.js} +4 -4
- package/assets/{Bndiqwoh132Upow1.js → UgDy0WNXuV1sEnFW.js} +2 -2
- package/assets/{CyYbUk6pGr3NIBsy.js → VSbzBtGH0cA8VBsM.js} +33 -33
- package/assets/{Cheq-qaVWm7EaIlQ.js → VWEaItb0XvCoRiCT.js} +1 -1
- package/assets/{DMDx0fX8tHKH0DdL.js → WSiEiaP-NUEr9UaB.js} +2 -2
- package/assets/{BVdH9-49M3APSiPy.js → Z5tQQ6IW5YBjblWX.js} +1 -1
- package/assets/{Cm2WENwEZ0KMyF--.js → b-xk3WtCPBkC4E-Z.js} +2 -2
- package/assets/{ndBoGVVjmy3vkff8.js → coTH4ab6CTEzw87b.js} +2 -2
- package/assets/{hcXZqO-0tG873E-L.js → do_DTptu6c_xHJoZ.js} +2 -2
- package/assets/{B6J8XN1FRN00a_ps.js → hAVtdK6u2tlLI2cB.js} +1 -1
- package/assets/{Cirpx81bWi4G2foA.js → hhpAcu3tINDLk7Ov.js} +5 -5
- package/assets/{DsWJ-YRyuwDUuSge.js → nSzQt54CIADky_tF.js} +1 -1
- package/assets/r-pk3RNq_HjMQFqr.js +14 -0
- package/assets/{Co_ZOyp4mKmSfh0A.js → ryaMyh_8KvmXVSJd.js} +1 -1
- package/assets/{C9eaFlFi_4GmymzP.js → sYakw2x8dcnpUlsX.js} +40 -40
- package/assets/{ltqqdJxoPnLCjhBV.js → tIoHMgrZeRHWyxos.js} +3 -3
- package/assets/{B5yaBbFj2Np9Eh8b.js → tPa3RpqYRqCCCYf1.js} +1 -1
- package/assets/{PMBjuoD2MpG87dao.js → v5XZSqLd9ZV3kqcA.js} +1 -1
- package/assets/{DMMw2v0iTuBnUjMI.js → vazKaFOkHRriv7tX.js} +1 -1
- package/assets/{BItblzoSm0lN3bTV.js → wWgI0JPoe_Wv0ceW.js} +1 -1
- package/assets/{DjH6ckvISyssOSit.js → xDx1vaNa2aCMs4_e.js} +1 -1
- package/assets/{Dsjx528shW3GcGpD.js → zJoBN2CJdxEV7vdh.js} +3 -3
- package/assets/{BkhWR4P1Evw_VP5z.js → ze6Q8BiEw9RClBzZ.js} +1 -1
- package/index.js +1769 -1706
- package/lib.js +1 -1
- package/licenses/dependencies.txt +35 -35
- package/package.json +2 -2
- package/screenshot-page/assets/0buGanYjZDNd9qAK.js +39 -0
- package/screenshot-page/assets/B2oadmu_j6WfNbZ1.js +1 -0
- package/screenshot-page/assets/{BMKiUDjoabO4aG1U.js → B668_VaGrdcWRbkC.js} +1 -1
- package/screenshot-page/assets/BGWgIYge30MP6Xhz.js +48 -0
- package/screenshot-page/assets/{FjOiReLnknWbsRRr.js → BGh5K-hHzy8mSVDr.js} +19 -19
- package/screenshot-page/assets/{BuzI4z8RJGOw8BZD.js → BIQ7KK-buzeddVA9.js} +1 -1
- package/screenshot-page/assets/BPRDGSNh0kvXRFUY.js +1 -0
- package/screenshot-page/assets/{BLPyKyNun9-SHQBZ.js → BRemww1df2HKLd_k.js} +1 -1
- package/screenshot-page/assets/{CXmrXx6MZ5ApF3co.js → Bm9-R9keVK5Sx-8o.js} +1 -1
- package/screenshot-page/assets/{BOjOE9CEMSzcij2W.js → BnZX0sxceYpvtg3I.js} +2 -2
- package/screenshot-page/assets/Bv2MgCMkg3EIQ6iE.js +13 -0
- package/screenshot-page/assets/BvaiwYJ5zZ0d5NRP.js +1 -0
- package/screenshot-page/assets/CAlTfQ_Gh-dURmUc.js +1 -0
- package/screenshot-page/assets/CCFxspvs5VzbYCfl.js +1 -0
- package/screenshot-page/assets/CCqTTfzZokVHIzs2.js +1 -0
- package/screenshot-page/assets/CPs_ARK8JCyz-yZg.js +1 -0
- package/screenshot-page/assets/{B9kA0vdaFJi9iRGo.js → CQ9C0-FcDZxrgC3T.js} +4 -4
- package/screenshot-page/assets/CUeMb48Ucrm5dK5u.js +1 -0
- package/screenshot-page/assets/CcOIj8c4N9KaWnD7.js +1 -0
- package/screenshot-page/assets/CjrHeIdacavAT_Ud.js +3 -0
- package/screenshot-page/assets/{RutPv2GFWmeBiWvn.js → Cmv8bpHaTWZ7Lmbt.js} +2 -2
- package/screenshot-page/assets/CqccUqSMYlwlf2ZU.js +2 -0
- package/screenshot-page/assets/CvmImq-Kbg9srxNr.js +4 -0
- package/screenshot-page/assets/D-3wYBqe4SWdE6bx.js +2 -0
- package/screenshot-page/assets/D-FWnGDbZ9BRDzPR.js +1 -0
- package/screenshot-page/assets/D717DArr-KKL0U6R.js +1 -0
- package/screenshot-page/assets/{BnPHZ_1rjv6kQgsL.js → D8-mayyvvVE1a4JB.js} +1 -1
- package/screenshot-page/assets/DM27mE98BNk1T18I.js +1 -0
- package/screenshot-page/assets/DN-T1DyRMKvxEJSK.js +1 -0
- package/screenshot-page/assets/DRdL1GN4SP7P8lSP.js +2 -0
- package/screenshot-page/assets/DcnhaY93LQd7kVdH.js +2 -0
- package/screenshot-page/assets/{BWtLNVUXjY6EBdEt.js → DdusmeEPaU7CWT6e.js} +1 -1
- package/screenshot-page/assets/{Dkr-6Z1RJsAp9Xrv.js → DfT1DMR1b5kiyYiV.js} +1 -1
- package/screenshot-page/assets/DigI6jhjHePzLgg1.js +1 -0
- package/screenshot-page/assets/DrDLCC0R2IV5VJd7.js +1 -0
- package/screenshot-page/assets/{H_hWDMWfWmjTui7V.js → Dwv5Z_c2XS-hm-5y.js} +1 -1
- package/screenshot-page/assets/Dx0pUf3G4Oa3dGOk.js +1 -0
- package/screenshot-page/assets/JcgNMFaj_uqHSFxr.js +1 -0
- package/screenshot-page/assets/{Bf9AN5sYHaxae0vV.js → U_8_wApwfA7KmIG3.js} +11 -11
- package/screenshot-page/assets/{XiUItCqTNNEApgfa.js → WZprjN2sb7HlraOb.js} +2 -2
- package/screenshot-page/assets/{C4v6Ljs6kwQJu06t.js → adhmz3N2Kgq5eW66.js} +2 -2
- package/screenshot-page/assets/qjoaeEBxfKWCHmqK.js +2 -0
- package/screenshot-page/assets/{BUO6zT3gqK0uOOa-.js → zALFdtoGJBN6m2Bn.js} +1 -1
- package/screenshot-page/assets/zd1Z2E1NjFp2EWC7.js +5 -0
- package/screenshot-page/index.html +8 -8
- package/types/scripting-api.json +7066 -7065
- package/types/scripting.d.ts +37 -9
- package/assets/BmmIukrNOivfENgD.js +0 -199
- package/assets/CCl8x9s8Bujsew7W.js +0 -14
- package/screenshot-page/assets/1yHlU53ypZZelMPx.js +0 -1
- package/screenshot-page/assets/BQ5BNe1adYfpa2OH.js +0 -1
- package/screenshot-page/assets/BZpFWPd0PR1kPT-A.js +0 -1
- package/screenshot-page/assets/BaCs7lUeZ7NidSkP.js +0 -1
- package/screenshot-page/assets/Bh2PQ0zsoGtMKWp1.js +0 -39
- package/screenshot-page/assets/BkhZQsVlVHOiKGTJ.js +0 -1
- package/screenshot-page/assets/Bzf_upccQ2ho6mX0.js +0 -13
- package/screenshot-page/assets/C0AbuMHcIS9oy4XL.js +0 -1
- package/screenshot-page/assets/C7YRL2bVWHPIwzn_.js +0 -1
- package/screenshot-page/assets/CImp91jfSuqX0Wz-.js +0 -1
- package/screenshot-page/assets/C_vPl50T1L5HWnhv.js +0 -1
- package/screenshot-page/assets/Cv-YUArreXqhafcU.js +0 -2
- package/screenshot-page/assets/D23_69pojBfIh4nV.js +0 -5
- package/screenshot-page/assets/D2q4M3I5Jmxm85P2.js +0 -1
- package/screenshot-page/assets/D8QsCbSaWCLAYYso.js +0 -1
- package/screenshot-page/assets/DC_Hdwa9KL7xKU8u.js +0 -2
- package/screenshot-page/assets/DHtL9Iawmr2Uo5VV.js +0 -2
- package/screenshot-page/assets/DKWRl8rs3K9jBYtr.js +0 -1
- package/screenshot-page/assets/DNYWB6WNZTquqQ9v.js +0 -4
- package/screenshot-page/assets/DegZKTNqt1LRnSxY.js +0 -1
- package/screenshot-page/assets/Dhh1xqujbhLa8WFd.js +0 -1
- package/screenshot-page/assets/DllI8kZZZ5LG0Mjd.js +0 -2
- package/screenshot-page/assets/DrcpGT9FLbDzeLeG.js +0 -2
- package/screenshot-page/assets/LCjlxIt1dn3smVjX.js +0 -1
- package/screenshot-page/assets/TwKKik-YQENv52LX.js +0 -1
- package/screenshot-page/assets/XrFpPrRqQNE9AAwH.js +0 -1
- package/screenshot-page/assets/mBuOPJeUPXlKwfPZ.js +0 -48
- package/screenshot-page/assets/zSnM7GhGzLu1MM_u.js +0 -3
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BUO6zT3gqK0uOOa-.js","./HclGiUj8dZXDFmoM.js","./ChSvXfVMLxZsP9zG.js","./CQukCzhuewMuFOlO.js","./Bf9AN5sYHaxae0vV.js","./3Ls_kOvlQseMV8Q0.js","./DcrVJCyDwGKeil2U.js","./DuYb_otrRZZDq6-f.js","./nHThFXCAZFOM_npq.js","./BQnELVV0uR4T4ItQ.js","./CnXLpFE_vFrJ5Jbf.js","./zvxBjll3jnL0-vNn.js","./H_hWDMWfWmjTui7V.js","./BMKiUDjoabO4aG1U.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"./ChSvXfVMLxZsP9zG.js";import{r as c,s as l}from"./DcrVJCyDwGKeil2U.js";import{At as u,Ct as d,Gt as f,J as p,Jt as m,Yt as h,st as g}from"./DuYb_otrRZZDq6-f.js";import{a as _,c as v,i as y,l as b,n as x,t as S}from"./CQukCzhuewMuFOlO.js";import{$ as C,$i as w,$n as T,$t as E,Ai as D,An as O,At as k,C as A,Cr as j,D as M,Da as ee,Di as te,Dt as N,Ei as P,En as ne,F as re,Fr as ie,G as ae,Gi as oe,Gt as se,Hn as F,Hr as ce,I as le,In as ue,It as de,J as fe,Jn as I,Jt as pe,Kt as me,Li as he,Ma as L,N as ge,O as _e,Oa as R,Pa as ve,Pn as z,Pt as ye,Qn as be,Qr as xe,Rn as Se,Si as Ce,Sn as we,Ti as B,Tn as V,Tr as H,Tt as Te,V as Ee,Wn as De,Yi as Oe,Yt as ke,Zi as Ae,Zt as je,_ as Me,_i as Ne,_r as Pe,ai as Fe,an as Ie,ar as Le,at as Re,b as U,ca as ze,cn as Be,cr as Ve,ct as He,da as Ue,di as We,dn as Ge,dr as Ke,ea as qe,fa as Je,fn as Ye,gn as Xe,gr as Ze,gt as Qe,hn as $e,ii as et,in as tt,jr as nt,jt as rt,k as it,ka as at,ki as ot,kr as st,la as ct,li as lt,mi as ut,mn as dt,nr as ft,nt as pt,o as mt,oi as ht,on as gt,or as _t,ot as vt,p as W,pr as yt,pt as bt,q as xt,qn as St,qr as Ct,ra as wt,ri as Tt,rn as Et,sa as Dt,st as Ot,ti as kt,tn as At,tr as jt,tt as Mt,u as Nt,ui as Pt,va as Ft,vi as It,wn as Lt,wr as Rt,x as zt,xa as Bt,xt as Vt,y as Ht,ya as Ut,yn as Wt,yt as Gt,z as Kt,zt as qt}from"./Bf9AN5sYHaxae0vV.js";import{D as Jt,S as Yt,f as Xt,g as Zt,j as Qt,k as $t,m as en,r as tn,u as nn,y as rn}from"./CImp91jfSuqX0Wz-.js";import{n as an}from"./BkhZQsVlVHOiKGTJ.js";import{_ as on,a as sn,c as cn,d as ln,f as un,g as dn,h as fn,i as pn,l as mn,m as hn,o as gn,p as _n,r as vn,s as yn,t as bn,u as G}from"./BMKiUDjoabO4aG1U.js";import{a as xn,i as Sn,n as Cn,o as wn,s as Tn,t as En}from"./BnPHZ_1rjv6kQgsL.js";var Dn=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 F({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 Bt;let i=e?.bounds;if(i&&((i.colStart??0)>0||(i.rowStart??0)>0||(i.colEnd??0)<0||(i.rowEnd??0)<0))return Bt;let a=e?.axis?e.axis===n.Column:this._axis===n.Column,o=e?Kt(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?_t:(c=!0,ye(0,0,r,a,o)),[Symbol.iterator](){return this},return:e=>_t,throw:e=>_t}}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)}},On=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(kn)}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(An);return this.getSpatialAt(e.scope)?.search(e,n,r,i)??t.EmptyArray}has(e){if(!e.scope)throw Error(An);return this.getSpatialAt(e.scope)?.has(e)??!1}shift(e){if(!e?.range?.scope)throw Error(An);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(An);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(An);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(An);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(An);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(kn);if(!e.scope)throw Error(An);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(An);let t=this._mapScopeTo2Ds.get(e);return t||(t=new B(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)}},kn=`Not supported on SpatialMap3D`,An=`SpatialMap3D: a valid scope key is required`,jn=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??=j(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(`,`)})]`}},Mn=class{constructor(e){this.fn=e,this.isFunctionValue=!0}makeCallable(){let e=this.fn,t=(...t)=>{try{return e.execute(...t)}catch(e){if(Se(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?.()??``})]`}},Nn=Symbol(`sheetxl.lambda.omitted`),Pn=new WeakSet,Fn=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():nn(o.ast,r);s=It(s,o.symbols,!a,a,a?{scope:this._gridId,rowIndex:e,colIndex:t}:null);let c=a?this._displayLocale():Je;return n?be(s,this._getEntireCoords?.(),c):Dt(s,this._getEntireCoords?.(),e,t,c)}_displayLocale(){let e=this._context.getRuntime().getLocaleProfile();return Ye(Ut(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===R.Cell?s={...i[n.value]}:n.op===R.Named?s={nameId:n.node.value.nameId}:n.op===R.TableReference&&(s={table:{...n.node.value}});a[e]=s}return a}getNode(){let e=this._compiled;return e.ast?an(e.ast,e.symbols):null}getTokensAt(e,t,n){let r=this._compiled,i=n===void 0?r.getTokens():nn(r.ast,n);return i=It(i,r.symbols,!1,!0),Le(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&&Zt(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?rn(n.ast,n.getFunction):null;if(r){let i=n.ast.firstCell!==void 0;t=r.map(t=>{let r=new e(Jt(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 be(n,i)===be(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=U(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===R.Cell){let e=s[r.value];c[t]={...e}}else if(r.op===R.Named){let e=r.node.value.nameId,n=this._compiled.symbols?.resolve(W.NamedFormula,e)?.toString()??e;c[t]={nameId:n}}else if(r.op===R.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===R.Error&&(c[t]=null)}return c}getReferencesAt(e,n){let r=this.getReferences(e,n);return r.length===0?t.EmptyArray:te(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===R.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,T=-1,E=-1;if(m)S=f[0].evalIndex,C=f[1].evalIndex;else if(d.type===`cell`)S=d.evalIndex;else if(u.op===R.TableReference)T=d.evalIndex;else{if(!p)throw Error(`Invalidate reference index: ${n}`);E=d.evalIndex}let O=(...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(W.Sheet,r)?null:r}return null},A=d,j=this._compiled.ast,M=w(j,e=>{if(!e||!e.isReference)return;if(x&&e===A)return k(h);let n=e.type;if(E!==-1&&e.evalIndex===E&&n===R.Named){if(!r)return ce();if(r&&`nameId`in r){let t=r,n=this._compiled.symbols?.bind(W.NamedFormula,t.nameId)??t.nameId,i={...e};return i.value={...e.value,...t,nameId:n},i}return _?D(`:`,k(h),k(g),!0):k(h)}if(T!==-1&&e.evalIndex===T&&n===R.TableReference)return r?_?D(`:`,k(h),k(g),!0):k(h):ce();if(!r&&Yt.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=ce(void 0,void 0,O(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=D(`:`,k(h),k(g),!0)}else a=ce(void 0,void 0,O(e)),a.evalIndex=e.evalIndex;return a}});if(M===j)return this;let ee=Jt(a.runtime,a.symbols,M,!1,a.error,a.getFunction);return new e(ee,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(W.Sheet,t),o=r.transform((e,t)=>{if(!e||!e.isReference||e.type!==R.Cell||$t(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!==R.Cell||$t(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!==R.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(W.NamedFormula,r),n=t?t.toString():r,i=e.getFunction?.(n)??null;return i?new Mn(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++)Rn(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===R.Named){m[r.index]=this._resolveNamedPrecedents(r.node.value,e,n);continue}if(i===R.Error){m[r.index]=jt(r.node.value);continue}if(i===R.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:je(o,c)}else if(i===`:`||i===`.:.`||i===`:.`||i===`.:`)s=L(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?L(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=zn(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===R.Error)d=jt(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(w(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=Jt(i.getRuntime(),a.symbols,Un(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===R.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===R.Error)o[s.evalIndex]=jt(r.node.value);else if(a===R.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=Rn(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===R.Error||a.value===`@`||!r)return this;let o=_e(n)+Ie(t);if(r.has(o))return this;let s=ue(`@`,a,!0),c=Jt(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 R.Infix:{let n=e.value,r=t[o[0].evalIndex],i=t[o[1].evalIndex];if(!0===e.firstCell&&!e.isReference&&this._demandsFirstCell()&&(r=Ln(r),i=Ln(i)),(n===`+`||n===`-`)&&(r=In(a,r),typeof r==`number`&&(i=In(a,i),typeof i==`number`))){let t=n===`+`?r+i:r-i;return pe(!0===e.snapsCancellation?le(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?tn[e.value]:Xt[e.value];return l=s?s(a,r,i):y.BuiltIn.Value,l=pe(l,null),l}case R.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=St.enter();try{this._fillLazyArgs(o,s,t,i,n,r,a),!0===e.passOmitted&&Hn(o,s),l=this._callFunction(e,Vn,s),l instanceof St&&(l=l._force())}finally{St.leave(a)}}else{for(let e=0;e<s;e++)Vn[e]=t[o[e].evalIndex];!0===e.passOmitted&&Hn(o,s),l=this._callFunction(e,Vn,s)}return l}case R.Prefix:case R.Postfix:{let n=t[o[0].evalIndex];if(!0===e.firstCell&&!e.isReference&&e.value!==`@`&&this._demandsFirstCell()&&(n=Ln(n)),n&&y.isError(n))return n;let r=e.fn??=c===R.Prefix?Qt[e.value]:en[e.value];return l=r?r(a,n):y.BuiltIn.Value,l}case R.List:case R.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&&he(n.scope))return y.BuiltIn.Name}let e=!1;for(let n=0;n<s;n++)if(Ct(t[o[n].evalIndex])){e=!0;break}if(e){let e=[];for(let n=0;n<s;n++){let r=t[o[n].evalIndex];Ct(r)?e.push(...r):e.push(r)}let n=U(e.length);for(let t=0;t<e.length;t++)n[t]=e[t];return n}let n=U(s);for(let e=0;e<s;e++)n[e]=t[o[e].evalIndex];return n}case R.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===Nn?!0===e.rawFrameRead?Nn:null:r}if(i!==null&&i.has(a.slot)){let t=i.get(a.slot);return!0===e.rawFrameRead?t:(u=t)===Nn?null:u}return y.BuiltIn.Calc}return!0===e.deferredResolve?this._evaluateNamed(e.value,n,r):t[e.evalIndex]??null}case R.TableReference:return t[e.evalIndex]??null;case R.Call:{let n=t[o[0].evalIndex];return n&&y.isError(n)?n:(l=this._applyCallee(n,e,t),l)}case R.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:Ct(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];Vn[c]=!0===t?.lazyArg?s?s[c]:St.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 jn(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 jn){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===R.Empty;o.set(a.slot,s?Nn:n[r[e+1].evalIndex])}return e.owner._evaluateBody(e,o)}if(e instanceof Mn){let t=[];for(let e=1;e<r.length;e++)t.push(r[e]?.type===R.Empty?void 0:n[r[e].evalIndex]);return this._dispatchFunction(e.fn,t,t.length)}return e&&(e.isIRange||e.colStart!==void 0)?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?Nn:r)}let a=this._evaluateBody(e,i);return pe(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(Se(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;w(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;w(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(Se(e))throw e;r=Wn(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(Se(e))throw e;r=Wn(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(z(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(Se(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(Ct(e)){let t=U(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,Bn),(e=pe(e,t))===null&&(e=0)):(n=e,Pn.has(n)||(e=e.fillEmpty(0))):(e=pe(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):be(e.getTokens(),null)}get[Symbol.toStringTag](){return`[FormulaBlock]`}},In=(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,Ln=e=>typeof e==`object`&&e&&!0===e.isIRange?e.getValueAt(0,0)??null:e;function Rn(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 zn=(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=zn(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},Bn=Object.freeze({type:null}),Vn=Array(255),Hn=(e,t)=>{for(let n=0;n<t;n++)e[n]?.type===R.Empty&&(Vn[n]=Nn)},Un=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&&Un(e))),t},Wn=e=>y.isError(e)?e:e instanceof RangeError?y.BuiltIn.Num:new y.Value(e?.message,{cause:e}),Gn=Wt(4096),Kn=0,qn=()=>Gn,Jn=(e,t)=>{if(t===0)return void(e.inputsAt=-1);let n=Kn,r=n+t;if(r>Gn.length){let e=Wt(Math.max(r,2*Gn.length));for(let t=0;t<n;t++)e[t]=Gn[t];Gn=e}let i=Gn;for(let e=n;e<r;e++)i[e]=void 0;Kn=r,e.inputsAt=n},Yn=(e,t)=>{let n=e.inputsAt;return n<0?void 0:Gn[n+t]},Xn=(e,t)=>{let n=e.inputsAt;if(n<0)return;let r=Gn;for(let e=0;e<t;e++)r[n+e]=void 0},Zn=0,Qn=1,$n=4,er=32,tr=64,nr=128,K=768,q=3072,rr=12288,ir=16384,ar=32768,J=65536,or=1<<17,sr=1<<18,cr=1<<19,lr=1<<20,ur=1<<21,dr=1<<22,fr=495520,pr=0,mr=256,hr=512,gr=768,_r=0,Y=1024,vr=2048,yr=(e,t,n)=>{let r=Cr(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`&&xr(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 br(e,i,e=>e>0);case`>=`:return br(e,i,e=>e>=0);case`<`:return br(e,i,e=>e<0);case`<=`:return br(e,i,e=>e<=0);default:return()=>!1}},br=(e,t,n)=>{if(t===void 0)return()=>!1;let r=Sr(t);return i=>r(i)&&n(e.compare(i,t))},xr=(e,t,n)=>{try{return e.compare(e.parseAsNumber(t),n)===0}catch{return!1}},Sr=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)}},Cr=(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`)}},wr=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 Tr(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]}},Tr=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)}},Er=e=>e?e.id:0,Dr=(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 wr(e,r,i,a,o)},Or=class e{static create(t,n,r,i){let a=et.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 Tn().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=Dr(i,s),this._columns=Dr(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(Er(t),Er(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=wn[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(Er(n),Er(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}=xn(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=Cn(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}},kr={a0:0,a1:0,f0:!1,f1:!1},Ar={a0:0,a1:0,f0:!1,f1:!1},jr=0,Mr=0,Nr={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Pr={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Fr=[],Ir=[],Lr=[],Rr=[],zr=[],Br=[],Vr=(e,t)=>!0===t||e===-(2**53-1),Hr=(e,t)=>!0===t||e===2**53-1,Ur=(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},Wr=(e,t,n,r,i)=>(e.f0&&(t=Math.max(t,e.a0)),e.f1&&(n=Math.min(n,e.a1)),!(t>n)&&(jr=Math.max(r,e.f1?r:t-e.a1),Mr=Math.min(i,e.f0?i:n-e.a0),jr<=Mr)),Gr=(e,t,n)=>{jr=Math.max(0,e.a0+(e.f0?0:t)),Mr=Math.max(0,e.a1+(e.f1?0:n))},Kr=(e,t,n,r,i)=>{if(!Wr(kr,t,r,i.rowStart,i.rowEnd))return;let a=jr,o=Mr;Wr(Ar,e,n,i.colStart,i.colEnd)&&Fr.push(jr,a,Mr,o)},qr=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd}),Jr=e=>({touched:[qr(e)],blank:[]});function Yr(e,t,n){let r=Fr;r.length=0;let i=kr,a=Ar,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 Jr(t);let f=u??d;if(!Ur(i,r.rowStart,Vr(r.rowStart,r.$rowStart),l.rowEnd,Hr(l.rowEnd,l.$rowEnd),t.rowStart,t.rowEnd)||!Ur(a,r.colStart,Vr(r.colStart,r.$colStart),l.colEnd,Hr(l.colEnd,l.$colEnd),t.colStart,t.colEnd))return Jr(t);if(i.f0&&i.f1&&a.f0&&a.f1)continue;let p=n(f);if(p===null)return Jr(t);let m=Nr;Gr(i,t.rowStart,t.rowEnd),m.rowStart=jr,m.rowEnd=Mr,Gr(a,t.colStart,t.colEnd),m.colStart=jr,m.colEnd=Mr;let h=p.searchFormulas(m),g=h.length;for(let e=0;e<g;e++){let n=h[e];Kr(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||!Wr(i,b.rowStart,b.rowEnd,t.rowStart,t.rowEnd))continue;let x=jr,S=Mr;if(!Wr(a,b.colStart,b.colEnd,t.colStart,t.colEnd))continue;let C=jr,w=Mr,T=Pr;if(Gr(i,x,S),T.rowStart=Math.max(jr,b.rowStart),T.rowEnd=Math.min(Mr,b.rowEnd),Gr(a,C,w),T.colStart=Math.max(jr,b.colStart),T.colEnd=Math.min(Mr,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?Kr(e,n,e,i,t):Kr(n,e,i,e,t)}}return function(e,t){let n=e.length/4;if(n===0)return{touched:[],blank:[qr(t)]};let r=Ir;r.length=0;for(let e=0;e<n;e++)r.push(e);r.sort(Xr);let i=Lr;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(Qr);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=Rr;c.length=0;let l=0,u=zr,d=Br,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(Zr),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&&$r(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 zr=u,Br=d,{touched:o,blank:s}}(r,t)}var Xr=(e,t)=>Fr[4*e+1]-Fr[4*t+1],Zr=(e,t)=>Fr[4*e]-Fr[4*t],Qr=(e,t)=>e-t,$r=(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},ei=(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},ti=(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 ni(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);G(l).fixedRef=n===0&&r===0?o:{colStart:o.colStart+n,rowStart:o.rowStart+r,colEnd:o.colEnd+n,rowEnd:o.rowEnd+r}})}var ri={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},ii={colStart:0,rowStart:0,colEnd:0,rowEnd:0},ai={bounds:ii,reuseResult:!0},oi=(e,t)=>e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex,si=(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},ci={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},li=null,ui=null,di={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},fi=e=>{let t=li,n=e??ui;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=>(di.colStart=e.colStart,di.rowStart=e.rowStart,di.colEnd=e.colEnd,di.rowEnd=e.rowEnd,di.scope=n,a.search(di))}},pi=Object.freeze({tokens:Object.freeze([]),isReferenceOnly:!1}),mi=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 F({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}ii.rowStart=o,ii.rowEnd=s,ii.colStart=c,ii.colEnd=l;let d=u.entries(ai),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 At.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){Rn(s,e,t,c),i[n]=c;continue}Rn(s,e,t,ri),Rn(l,e,t,ci);let u=L(ri,ci,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;li=this._container,ui=this.gridId;try{n=Yr(this._template,this.ref,fi)}finally{li=null,ui=null}this._touched=n,this._touchedCycleId=e,this._touchedMarkId=t;let r=this.blankShared;if(r!==null&&!ei(this._blankSharedAgainst,n.blank)){let e=[];for(let t=0;t<r.length;t++)ti(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=U(r);for(let e=0;e<r;e++)a[e]=U(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=U(r.rowEnd-a+1),d=r.colEnd-i+1,f=u.length;for(let r=0;r<f;r++){let o=U(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:Zn,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=si(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:si(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=U(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=U(s);for(let t=0;t<s;t++){let n=U(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 At.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(oi);let c=new At.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[zt(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 ni(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()??pi}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}},hi=-1,gi=-2,_i=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)}},vi=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 _i(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]`}},yi=2**53,bi=(e,t)=>!0===e?.isPendingOverlay||!0===e?.isWhatIfLayer?e:t??null,xi=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 F({axis:this._axis,maxCoords:a});for(let e=0;e<r;e++)o.setValueAt(t[e],0,n[e]);return new ke(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 ot.assertUsable(`calcs`,0),r=this._container,i=r.getRuntime();this._runtime=new mt(`Calculation Runtime`,{isDate1904:()=>i.isDate1904(),isR1C1:()=>i.isR1C1(),getNow:()=>r.getNow(),getRandom:()=>i.getRandom(),getLocale:()=>i.getLocale()},n),this._calcScope=r.getScope(),this._coerceToNumber=N(this._runtime,S.Number,Ot);let{initializeFunctions:a}=await e(async()=>{let{initializeFunctions:e}=await import(`./BUO6zT3gqK0uOOa-.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 We({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(W.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 Oi(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=Pe(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 h.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(W.Sheet,n):this._calcScope.gridId,!i)return null;let a=r.getFormulas();if(!a)return null;wi.colStart=t,wi.rowStart=e,wi.colEnd=t,wi.rowEnd=e,wi.scope=i;let o=a.search(wi);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|=tr}defer(e,t){if(typeof e!=`function`)throw new y.Value(`defer needs an executor function`);let n=this._container.getDeferred?.();if(n)return qe(n.defer(e,t,Ke(),lt())),n.previous;qe(null)}formatResults(e){let t=this._calcScope.node;t&&(t.numFmt=e)}filterHidden(e,t){if(!(e?.isIReferenceRange&&e instanceof Fe))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(W.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(W.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 d(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=m(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 f({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()*yi));let n=e.gridId;if(n!==this._gridKeyId){this._gridKeyId=n;let e=n===null?null:this._container.getSymbols().resolve(W.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 H.compare(e,t,this.getRuntime().getLocaleProfile(),n)}_fromTuples(e,t=null,n=!1,r=!1){if(!e)return null;let i=Te(e.bounds,!0),a=this._container.getGrid(this._calcScope.gridId)?.getEntireCoords(),o=new F({axis:this._axis,maxCoords:a});o.setValues(e.tuples);let s=t?{type:t}:void 0;return new ke(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(W.Sheet,r),he(s))return y.BuiltIn.Ref}else s=o.gridId;if(!s)return y.BuiltIn.Ref;let l=o.node,u=l?ln(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=Yn(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=Ne(c))),i&&i.type,c}getSpillAt(e,t,n){let r=this._container,i=this._calcScope,a;a=n?r.getSymbols().bind(W.Sheet,n):i.gridId;let o=a===i.gridId?null:a,s=r.getIncrementalUpdates(a)?.spillSpatial??r.getGrid(a)?.getSpills();if(s){Ti.rowStart=e,Ti.colStart=t,Ti.rowEnd=e,Ti.colEnd=t,Ti.scope=a;let n=s.search(Ti),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 F({axis:this._axis,maxCoords:i}),o=new ke(this._runtime,a,null,void 0,!1);return e>0&&t>0&&(typeof n==`function`?(o=o.resize(e,t),o=o.map(n,Di)):Array.isArray(n)?(o=o.replace(n),o=o.resize(e,t)):o=n==null?o.resize(e,t):new ke(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 ke(this._runtime,new Dn(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($e(r,s,Gt(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 F({axis:a,maxCoords:l}),d=t?{type:t}:void 0;return new ke(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=Ce(e,r,O,()=>{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(W.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(Si(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 F({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=Ci(ln(d),e)),f!==-1){let t=Yn(d,f);if(t!=null&&t.isIReferenceRange)u=t;else if(t===void 0||l.isPendingOverlay)u=this._toReference(l,e,s,i,!1,bi(l,a));else{let n=t;n!==null&&n.isIRange&&(n=n.getValueAt(0,0));let r=new F({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,hi),u=this._toReference(l,e,s,i,!0,bi(l,a))}return u}_expandSheetSpan(e){if(typeof e!=`object`||!e||!0===e.isIRange)return null;let t=e;if(t.colStart===void 0||!he(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(Si(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 vi(e,r,o));try{let i=new Fe(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,Ei.rowIndex=this._calcScope.rowIndex,Ei.colIndex=this._calcScope.colIndex,Ei.scope=null,Ei);let n=this.getEntireCoords().scope;return e.colIndex===void 0?xt(e,n,t):Xe(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=u(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 yr(this,e,t)}createPivot(e,t,n){return Or.create(e,t,this._createSparseColumn,n)}getPivotAt(e){if(!(e instanceof Fe))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 Sn(n);let o=t.rowStart<=a.row&&t.rowEnd>=a.row&&t.colStart<=a.column&&t.colEnd>=a.column;return Sn(n,o?`blocked`:`wanted`)}return null}parseAsLiteral(e){return T(e)??ze(e)}toText(e){return ge(e,this._runtime)}getRuntime(){return this._runtime}createRichData(e,t){return Ht.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}},Si=(e,t)=>({...e,scope:t,inSheetSpan:!0}),Ci=(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},wi={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Ti={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Ei={rowIndex:0,colIndex:0,scope:null},Di=Object.freeze({includeEmpty:!0}),Oi=class extends xi{_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`)}},ki=e=>({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd});function Ai(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 ji(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=Ai(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=Ai(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 Mi=class extends Me{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={...yt},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(rt(de.results(e,`onCalculated`),this._container.getImager(this._gridId)))}:()=>{},this._values=new F({axis:v.Axis.Column,createRun:un}),this._iterationId=0,this._contentfulSpatial=new B({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}});let o={updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}};this._spillSpatial=new B(o),this._errorSpatial=new B(o),this._calcStatusSpatial=new B(o),this._circularSpatial=new B(o),this._notifyValues=new B,this._notifyBlank=null,this._notifySpillsInsert=[],this._notifySpillsRemove=[],this._notifyFormats=new B,this._notifyCalcStatus=new B,this._notifyCircular=new B,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=ki(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&&ki(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({...ki(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=wt(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,ki(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 Pi(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>Ii&&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?Gi: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;I(u,a,s,c);let f=[],p=this._container.getPrecedents().search(a),m=ft(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?Ve(_,b):ht(_,a);x&&(Xi(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=ut(()=>_,()=>{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&&(Xi(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)&&(Qi(_,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:ji(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(!Rt(i))continue;let a=o.get(i);a===void 0&&(a=Oe(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();Xi(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,Z),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}),Yi(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());Xi(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}),Yi(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=Ni.get(r);o||(o=new Map,Ni.set(r,o));let s=o.get(t);if(!s){let e=ct(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,Z),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 Vt(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++)Fi(t,n[e])||r.push(n[e]);for(let e=0;e<t.length;e++)Fi(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)??Hi}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();X.colStart=i,X.rowStart=r,X.colEnd=s,X.rowEnd=a,X.scope=c;let u=l.search(X);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===gi)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===hi){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=M(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();X.colStart=i,X.rowStart=r,X.colEnd=s,X.rowEnd=a;let l=this._gridId;X.scope=l;let u=c.search(X);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===hi&&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=Ft(t,n.rowStart+x,n.colStart+S),o=Ft(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=M(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=kt(e,e=>this._directAcrossGrids(e,!0));return t.sort(o.rowFirstRangeComparator),t}getPrecedentsAt(e){let t=kt(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(Ct(i))return e.finalizeValue(i);let a=pe(i,this._context);return a===null?0:a}return dn(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=gt(a,e,t):r&&r.colIndex!==void 0&&(a=it(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,xe(a,r,i))}_isVolatileNow(e,t){let n=this._formulaAt(e,t);if(!n?.value)return!1;let r=n.value;if(Ji(r,this._gridId,this._container))return!0;let i=r.nodeAtOrNull(e,t);return i!==null&&(i.state&tr)!==0}_formulaAt(e,t){Vi.colStart=t,Vi.rowStart=e,Vi.colEnd=t,Vi.rowEnd=e,Vi.scope=this._gridId,Wi.length=0;let n=this._container.getFormulas().search(Vi,!1,!1,Wi);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 Vt(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(W.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 mi(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;Ui.colStart=Math.max(a,a+i),Ui.rowStart=Math.max(o,o+h),Ui.colEnd=Math.min(s,s+g),Ui.rowEnd=Math.min(f,f+_);let y=ee(e,Ui,Ue);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),Xi(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=Ae(l,n,r);d&&(Xi(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;Xi(u,l,p),this._touchFormulas(p);let _=ie(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),Xi(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}),Yi(c,r,t)}c.markDirty(t)}}let b=this._values;e.values.copyTo(b,{colIndex:r.colStart,rowIndex:r.rowStart},n),ne(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),De(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 At.Builder((e,t)=>new at.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,Li);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?$i(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,Li))}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,Li))}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,Li))}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(A(a.rowStart,a.colStart,r)&&(i||r.value.getCycleId()===e)){_||(_=[],n=new Set);let e=_e(r.colStart)+Ie(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,Li))}f.length>0&&(p.formatInserts=f,m=o.unionRangesArrays(f,m??void 0,Li)),this._takeFormulaResults(p,i),p.formulaRemoves&&(m=o.unionRangesArrays(p.formulaRemoves,m??void 0,Li));let x=this._notifyBlank;x!==null&&(m=o.unionRanges(m,x,Li),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,C,w=d?[]:null;if(e&&e.tuples){x=e.tuples;let t=e.bounds;if(t?(S=Te(t,m),S.scope=a):S={colStart:-(2**53-1),rowStart:-(2**53-1),colEnd:2**53-1,rowEnd:2**53-1,scope:a},w){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=Te(e,m);o.scope=a,w&&l.search(o).length>0&&w.push(o)}}}C=E(e.tuples,m,a)}let T=(e,t)=>{e&&this._notifySpillsInsert.push(e),t&&this._notifySpillsRemove.push(t)};if(r||x){let e;r&&(e=ft(r,h,p,y,T,!1,!0,this._notifyValues,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})})),De(-1,r?[r]:t.EmptyArray,C,y,h,p,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})},this._notifyValues,T,this._notifyCalcStatus,g,m,!1,this._circularSpatial,this._calcStatusSpatial),r&&(p.delete(r),ae(g,r)),e?.(),x&&(p.setValues(x),we(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 mi(e,a,o,s,this._unanchored),u=i?.arrayFixed;u&&u.colStart===r&&u.rowStart===n&&(G(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=w?w.length:0,P;if(f>0){P=U(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 ne=i?.cloneKey??null;(N>0||f>0)&&(A=s.getFormulas().clone(ne));for(let e=0;e<N;e++)te(w[e]);for(let e=0;e<f;e++)te(P[e]);let re=k?k.length:0;if(re>0){let e=s.getDynamics(),t=null;for(let n=0;n<re;n++){let r=k[n].value,i=e.get(r);i&&(j||=s.getPrecedents().clone(ne),j.removeAll(i,Z),t||=new Map(e),t.delete(r))}t&&s.setDynamics(t)}let ie=[];if(O||k){j||=s.getPrecedents().clone(ne),Xi(A,j,O,k),M&&Qi(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,w,P):k;De(-1,t,O,y,h,p,(e,t,n,r)=>{b.push({colStart:e,rowStart:t,colEnd:n,rowEnd:r,scope:a})},this._notifyValues,T,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];ie.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];ie.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),ie}_rederivePrecedentsNow(e){let t=this._container,n=t.getPrecedents().clone();Qi(n,null,e);for(let t=0;t<e.length;t++)e[t].value.refreshPrecedents();Qi(n,e,null),t.setPrecedents(n);let r=null;for(let n=0;n<e.length;n++){let i=e[n].value;!i.unanchored&&Ji(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,Z),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=re(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]);Qi(t,null,n),e.removeAll(n,Z),e.load([r]),Qi(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();Xi(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,Z),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;we(this._errorSpatial,t,n);let r=E(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=bt(n,a).split(`:`)[0];u.add(r);let i=Ge(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=Ge(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,Ri,zi),b=h.length;b===1&&(f=f.wrapImplicit(s,c,u));let x=new mi(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=Nt(E[e],zi[e],Ri[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=Ge(l[n],a),s=r.value??`dynamic`,d=s===`error`,f=r.colStart,p=r.rowStart;Bi.colStart=f,Bi.rowStart=p,Bi.colEnd=f,Bi.rowEnd=p,Bi.scope=t;let m=i.search(Bi);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`&&(G(_).fixedRef=x,g.densify()),_.cachedValue=d?y.BuiltIn.Spill:new ke(h,u,x);let S={colStart:f,rowStart:p,colEnd:v,rowEnd:b,value:new Vt(x,0,s)};o.push(S),e.push({colStart:f,rowStart:p,colEnd:v,rowEnd:b,value:s}),se(c,_,x,gi)}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|=tr,t.block.calcOnLoad=!0},r=Array(S);for(let e=0;e<S;e++){let n=x[e],o=C(n,a);r[e]={...o};let s=i.search(o),c=s.length;for(let e=0;e<c;e++){let n=s[e];nt(n,o,t)}}this._markDirtyRegionsNow(r),b=!0}let w=this._contentfulSpatial,T=!w.isEmpty(),E=null,D={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(T){D.rowStart=t.rowStart,D.colStart=t.colStart,D.rowEnd=t.rowEnd,D.colEnd=t.colEnd;let e=w.search(D);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())&&(E??=[]).push({rowStart:t.rowStart,colStart:t.colStart,rowEnd:t.rowEnd,colEnd:t.colEnd})}if(E&&(this._markDirtyRegionsNow(E),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=tt(t,n.Column,2,qi),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=zt(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=pt(!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===Et.CalcStatus.Working);r.length>0&&t(r),g.length>0&&t(g),p=tt(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=zt(n,this.getEntireCoords());e[t]=r}c.volatile=e}return c}},Ni=new WeakMap,Pi=(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},Fi=(e,t)=>{for(let n=0;n<e.length;n++)if(o.isEqualRanges(e[n],t))return!0;return!1},Ii=8,Li={rowStart:0,colStart:0,rowEnd:0,colEnd:0},Ri=[],zi=[],Bi={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},Vi={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},X={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},Hi=Object.freeze({search:(e,n,r,i)=>i??t.EmptyArray,getBoundingRange:()=>null,isEmpty:()=>!0}),Ui={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Wi=[null],Gi=Object.freeze({full:!0}),Ki=[];function Z(e,t){return e.value===t.value}function qi(e,t){let n=e[0].value?.formula,r=e[1].value?.formula;if(n&&r&&n.isEquals(r))return t}function Ji(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 Yi(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 Xi(e,t,n,r){(n&&n.length!==0||r&&r.length!==0)&&(Qi(t,null,r),Zi(e,null,r),Zi(e,n,null),Qi(t,n,null))}function Zi(e,t,n){(t&&t.length!==0||n&&n.length!==0)&&(n&&e.removeAll(n,Z),t&&e.load(t))}function Qi(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],Z);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;X.rowStart=n.rowStart,X.colStart=n.colStart,X.rowEnd=n.rowEnd,X.colEnd=n.colEnd,X.scope=n.scope??r.scope,Ki.length=0;let i=e.search(X,!1,!1,Ki),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,Z)}}}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;oe(n,a,r),a.length>i&&(n.value.registeredPrecedents=a.slice(i))}e.load(a)}Ki.fill(null,0,10);var $i=e=>{let t=!1;if(Be.forEachLeaf(e,(e,n,r,i)=>{if(t||e instanceof Pt)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=P(e.at(r))}),!t)return e;let n=e.length,r=Array(n);for(let t=0;t<n;t++)r[t]=Ne(e.at(t));return new at.ArrayList(r)},ea=(e,t,n)=>{let r=n?.fetchedFrom;if(!e)return new Ee({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})},ta=0,na=1,ra=2,ia=3,aa=class{constructor(e,t,n,r,i,a=null,o=null,s=oa){this.state=ta,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=na,this._moved(),this._final())}reject(e){this.isOpen()&&(this.latest=y.isError(e)?e:new y.Value(`The call failed`,{cause:e}),this.state=ra,this._moved(),this._final())}onCancel(e){(this._onCancel??=[]).push(e)}get cancelled(){return this.state===ia}isOpen(){return this.state===ta}close(){let e=this.isOpen();this.state=ia;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(){Ze(),this._onMoved?.(this)}_final(){let e=this._onFinal;this._onFinal=null,e?.(this)}},oa=e=>e,sa=(e,t)=>Ht.fromJSON({type:e,data:t}),ca=(e,t)=>globalThis.fetch(e,t),la=()=>{throw Error(`getFormulaContext() needs a workbook being calculated`)},ua=()=>Promise.reject(Error(`parseText() needs a workbook being calculated`)),da=(e,t)=>ea(null,e,t),fa=class{constructor(e,t,n,r=null,i=100,a=oa,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:ha,createRichData:o?.createRichData??sa,addResource:o?.addResource??da,fetch:o?.fetch??ca,getFormulaContext:o?.getFormulaContext??la,parseText:o?.parseText??ua};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!==ia&&(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 st(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&&ga(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 aa(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){pa(t,e);continue}finally{this._setCurrent(null)}i&&typeof i.then==`function`&&i.then(void 0,e=>pa(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&&P(n.cachedValue)&&(r=n.cachedValue),r===null?void 0:r.calls[e]}},pa=(e,t)=>{for(let n of e)n.isOpen()&&n.reject(t)},ma=Symbol(`-0`),ha=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=>ga(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)?ma: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)}}))},ga=(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},_a=32768,va=(e,t)=>e*_a+t,ya=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,va(e,t))]}set(e,t,n){2*(this.size+1)>this._mask+1&&this._grow();let r=va(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/_a);if(t.getValueAt(r,e-r*_a)===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/_a),c=o-s*_a;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=Wt(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/_a),o=this._slotOf(a,r-a*_a,r);this._keys[o]=r,this._values[o]=t[n[i]],this._order[i]=o}}},ba=class{constructor(e,t,n){this._pending=new ya,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=va(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=va(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)||xa(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/_a),s=a-e*_a;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/_a),c=e-s*_a;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(va(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 xa(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 Sa={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},Ca={colStart:0,rowStart:0,colEnd:0,rowEnd:0,scope:null},wa=(e,t)=>e.rowIndex===t.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex,Ta=(e,t)=>e.colIndex===t.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex,Ea=(e,t,n)=>e.rowEnd<t?2:+(e.rowEnd===t&&e.colEnd<n),Da=(e,t,n)=>e.colEnd<n?2:+(e.colEnd===n&&e.rowEnd<t),Oa=(e,t,n,r,i,a,o,s)=>{Sa.rowStart=t,Sa.rowEnd=n,Sa.colStart=r,Sa.colEnd=i,Sa.scope=a;let c=s.search(Sa);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++))}},ka=(e,t,n)=>n===e.nodes[0].gridId&&t.rowStart<=e.rowMax&&t.rowEnd>=e.rowMin&&t.colStart<=e.colMax&&t.colEnd>=e.colMin,Aa=32768,ja=(e,t)=>e*Aa+t,Ma=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=ja(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)||xa(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/Aa),i=t-r*Aa;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?ja(i,e):ja(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(ja(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(ja(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 At.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]`}},Na=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(Pa),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 Pa(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 Fa=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;to.colStart=to.colEnd=e.colIndex,to.rowStart=to.rowEnd=e.rowIndex,to.scope=e.gridId;let r=i.search(to),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||!(Ba(i.touched,n.rowIndex,n.colIndex)||r.blankPaged&&Ba(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&&La(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&&za(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&q)!==_r)return;e.state=e.state&~K|er|hr|vr;let t=G(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,Z);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===hi&&(e.state|=tr),se(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=Ha,c=[],l=new Set,u=()=>{let e=i.build();e&&e.tuples&&(o.values.setValues(e.tuples),we(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?Ga:qa);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!==Ha&&u(),i=new At.Builder(Ia),a=pt(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=pt(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&~K|hr}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,Z),_===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,Z)}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 ke(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|=cr|ur;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;ao.rowStart=t,ao.colStart=n,ao.rowEnd=r,ao.colEnd=i,ao.scope=e;let c=this._container.getFormulas().search(ao),l=c.length,u=this._iterate!==null,d=this._container.getScope().node,f=d!==null&&(d.state&J)!==0,p=0,m=null,h=!1,g=!1,_=e=>{if(e.cycleId!==o||e.markId!==s)return void(u||(e.state&rr)===0||(a?g=!0:this._demandActive?this._markDownstream(e):m=e));let t=e.state&K;if(t!==gr||h||(this._flush?.(),h=!0,t=e.state&K),t!==mr)t===pr||t===gr?wo[p++]=e:(e.state&q)!==_r&&(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&=~J),!u||!this._demandActive)throw new hn(e);(e.state&nr)===0&&(e.state|=nr,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,_)}La(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 cn(wo,p);if(m)throw new on(m);return g}_markDownstream(e){let t=this._container.getScope().node;t&&(t.state&q)===_r&&(t.state=t.state&~q|vr,G(t).cycleGroup=this._resolveGroup(po(e)),this._addCircular(t),this._iterate&&(jo[this._iterDownstreamLength++]=t))}_onMemberRead(e){let t=e.state;if((t&q)===Y){if(this._openGroups.has(this._resolveGroup(e.ext.cycleGroup)))return void((t&nr)===0&&(e.state|=nr,Oo[this._iterHitsLength++]=e))}else if(this._sweeping&&(t&ar)===0&&e.ext.demandValue!==void 0){let t=this._container.getScope().node;if(t&&((t.state&q)===Y||(t.state&ar)!==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&q)===Y&&this._resolveGroup(n.cycleGroup)===i?(e.state=e.state&~q|Y,n.cycleGroup=i,r.cycleNext===null&&(r.cycleNext=e)):e.state|=ar,this._addIterMember(e,n.demandValue)}_addIterMember(e,t){let n=this._iterMembersLength++;if(this._iterSorted){for(;n>0&&Ka(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)=>Ka(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&q)===_r)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&K)===pr&&(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 ba(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 Ma(r,r.hasErrorIn?r:t.getGrid(e)),l.set(e,n)}return n};this._whatIf=l;try{let n=pn(t,e),r=sn({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|=tr;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;Xn(e,_n(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 Re))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 Ra(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 ve([t],o),c=Array(i-r+1);for(let e=r;e<=i;e++)c[e-r]=[e,[[a,s]]];h.setValues(c),ae(g,n),we(g,c,y);let l={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,scope:m};x.push({...l,value:new Qe(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&&ei(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]):ti(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 B).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;za(e,n.blank,t);let r=e.getDemandedBlank();if(r.length===0)return;let i=this._fallbackDirty??=new B,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 B,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&=~(K|q|er),Do[this._deferredLength++]=e}_unwindSpeculative(e,t){for(;t>0;){let n=e[t-1];if((n.state&(K|J))!==(mr|J))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&K)===pr)for(u.state&=~J,s[c++]=u;c>0;){let t=s[c-1],n=t.state&K;if(n===hr){c--;continue}let r;n===pr&&(t.state=t.state&~(K|or)|mr|er,this._addCircular(t));let u=null,d=!1;Xn(t,_n(t)),t.state&=~tr,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 cn||e instanceof hn||e instanceof on))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&J)!==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&=~nr,(t.state&K)===mr){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 cn){if((t.state&J)!==0){this._unstartPrefetched(t),c=this._unwindSpeculative(s,c-1);continue}o.retries++;let e=0,n=ln(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):(ao.rowStart=a.rowStart,ao.colStart=a.colStart,ao.rowEnd=a.rowEnd,ao.colEnd=a.colEnd,ao.scope=t.gridId,e=this._collectUnevaluated(ao,l,e))}for(let t=0;t<e;t++){let e=l[t];(e.state&(K|or))===pr&&(e.state|=J|or,s[c++]=e)}let i=u.nodes,a=u.count;for(let e=0;e<a;e++){let t=i[e];(t.state&K)===pr&&(t.state=t.state&~J|or,s[c++]=t)}continue}if(u instanceof hn){if((t.state&J)!==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&K)!==mr)continue;if((e.state&J)!==0){this._unstartPrefetched(e);continue}e.state=e.state&~(K|J)|hr;let n=mo(e);G(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 on){t.state=t.state&~(K|q|J)|hr|vr;let e=mo(t),n=G(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&q)!==vr)G(t).demandValue=r,this._pushDemand(t,r),d&&this._finalizeRepresentative(t,r,e(t.gridId),!1);else{let e=mo(t);G(t).demandValue=e,this._pushDemand(t,e),d&&this._fallbackBlank(t.block,!1)}if(t.state=t.state&~(K|J)|hr,c--,this._openGroups.size>0&&(t.state&q)===Y){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&J)===0&&(t.state&(K|q))===(mr|Y)&&(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&K)!==mr||(r&J)!==0)continue;o&&(r&q)!==Y&&this._addIterMember(t,this._valueOnGrid(t)),t.state=r&~q|Y;let i=G(t);if(o&&(r&q)===Y){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?G(l).cycleNext=t:c=t,l=t}return l&&(G(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&q)===Y){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&K)===hr&&(t.state&q)===vr&&(t.state=t.state&~K|pr)}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&q)!==Y)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|=tr}}_drainIterHits(){let e=this._iterHitsLength;for(let t=0;t<e;t++)Oo[t].state&=~nr;this._iterHitsLength=0}_demandEvaluateOne(e,t){let n=this._context,r=this._container.getScope(),i=t.block.formula,a=_n(t);for(;;){Xn(t,a),t.state&=~tr,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 cn))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&q)===Y)return!0;return!1}_addCircular(e){(e.state&ir)===0&&(e.state|=ir,To[this._circularNodesLength++]=e)}_resetCircular(){let e=this._circularNodesLength;for(let t=0;t<e;t++)To[t].state&=~ir;this._circularNodesLength=0}_trackCircular(e,t,n,r,i){let a=G(e),o=e.state&q,s=o===_r?0:a.cycleGroup;if(a.shownGroup===s&&(e.state&rr)===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===Y;(n?t.members:t.downstream).add(e),c=t.getEntry(n)}a.shownGroup=s,e.state=e.state&~rr|o<<2,t.circularConflating||=pt(i),t.circularConflating.append(n,r,c)}_cycleOf(e){let t=this._cycles.get(e);return t||(t=new Na(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 _=Ja(),v=f!==`off`&&!i&&h!==0,b=v?this._matchPlanMemo(o,e,t-1,m):null;if(b!==null&&g.closureEligible++,Kn=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&=~fr,i.ext!==null&&(i.ext.cycleGroup=0),Jn(i,_n(i)),s[r]=i}return r.length=i,a<i&&this._flagDemandAppendix(s,a,i),g.closureHits++,g.discoveryMs+=Ja()-_,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&=~fr;let i=r.ext;i!==null&&(i.cycleGroup=0),(r.planEpoch!==p||r.planId!==h||i!==null&&i.shownGroup!==0)&&(v=!1),Jn(r,_n(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&=~fr;let r=n.ext;r!==null&&(r.cycleGroup=0),(n.planEpoch!==p||n.planId!==h||r!==null&&r.shownGroup!==0)&&(v=!1),Jn(n,_n(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):(no.colStart=t,no.rowStart=n,no.colEnd=t,no.rowEnd=n,no.scope=r,i=u.search(no),a?(g.dependentsCacheHits++,$a(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;ro.colStart=a,ro.rowStart=i,ro.colEnd=s,ro.rowEnd=o,ro.scope=r;let c=u.search(ro),l=c.length;if(l>0){let r=G(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++)vn(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];yn(r,n,t,k,A,j)}}let M=Ja();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=Za;for(let n=0;n<t;n++)r[n]=e[n];r.length=t,r.sort(Ya);for(let e=0;e<t;e++)n[e]=r[e];return}if(Xa.length<r){let e=[];for(let t=0;t<r;t++)e.push(null);Xa=e}let i=Xa,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+=Ja()-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;ka(e,c,l)&&(Ea(c,a[o].rowIndex,a[o].colIndex)===0&&(e.rowFirst=!1),Da(c,a[o].rowIndex,a[o].colIndex)===0&&(e.colFirst=!1)),Oa(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;Ca.rowStart=a.rowStart,Ca.rowEnd=a.rowEnd,Ca.colStart=a.colStart,Ca.colEnd=a.colEnd;let d=o.getPrecedentsAt(c,u)[r];if(y.isError(d))return!1;let f=Math.min(Ca.rowStart,d.rowStart),p=Math.max(Ca.rowEnd,d.rowEnd),m=Math.min(Ca.colStart,d.colStart),h=Math.max(Ca.colEnd,d.colEnd),g=d.scope??t;if(f<=c&&p>=s&&m<=u&&h>=l&&g===t){let t=Ea(Ca,s,l);t!==0&&t===Ea(d,c,u)||(e.rowFirst=!1);let n=Da(Ca,s,l);n!==0&&n===Da(d,c,u)||(e.colFirst=!1)}Oa(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?wa:Ta);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+=Ja()-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&rr)===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&rr)===0||(Qo=n.ext.shownGroup)},ne=(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=ln(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(io.colStart=a,io.rowStart=o,io.colEnd=s,io.rowEnd=c,io.scope=l,u=d.search(io),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=ne(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++)vn(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 re=Ja();g.inDegreeMs+=re-M;let ie=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++)vn(e[a],n,t,r.spillRowStart,r.spillColStart,r.spillRowEnd,r.spillColEnd,ie)}let i;i=e.dependents;let a=i.length;if(a!==0)for(let e=0;e<a;e++){let r=i[e];fn(r,n,t,ie)}}if(g.kahnMs+=Ja()-re,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|=er,G(n).demandValue=void 0,e.push(n))}e.sort(qa);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|=er,G(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&&Qa(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=Ja(),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,k,A=0,j=new Map;this._overlays=j;let M=e=>this._overlayFor(e),ee=e=>{D=s.getGrid(e),E=D.getEntireCoords.bind(D),g=t(e),_=g.gridId,k=M(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=_},te=v.Axis.Column,N=te===v.Axis.Column,P=()=>{if(A>0){n(m,A),A=0;for(let e of j.values())e.reset();_!==void 0&&(g=t(_))}};this._flush=P;let ne=this._exceptTables;if(ne)for(let e=0;e<p;e++){let t=f[e];t.block.hasDataTable()&&(t.state=t.state&~K|hr,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&Qn)!==0&&e===n.cycleId){n.state&=~Qn;continue}if(ne&&n.block.hasDataTable())continue;let c=n.gridId;c!==_&&ee(c);let p=n.block,v=p.representative===n&&p.isBlankAware(e),j=n.cachedValue,ie,oe,se=!1;typeof j==`object`&&j&&(j.isIRange?ie=j:y.isError(j,y.Code.Spill)&&(oe=j,se=!0));let F=(n.state&er)!==0;F&&(n.state&K)!==hr&&(P(),this.doDemandEvaluate(e,t,this._demandBatch,P),l.gridId=c);let ce=F?null:ln(n),le=n.inputsAt;if(ce&&le>=0){let e=qn(),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=k,p=D;c&&c!==_&&(p=s.getGrid(c),p&&(l=p.getValues(),f=M(c),d=p.getEntireCoords.bind(p)));let m=p;f.intersects(i,r,o,a)&&(l=f,m=f);let h=new Fe(u,l,{...t},null,d,s.resolveScope);h._setErrorIndex(m),e[le+n]=h}}}ce&&d!==null&&d.getOpenCount()!==0&&(n.state&sr)===0&&as(ce,_,s)&&(n.state|=sr);let ue=N?i:a,de=N?a:i;l.node=n,l.colIndex=i,l.rowIndex=a,l.drawIndex=0;let fe=p.formula,I,pe=null,me=!1,he=(n.state&$n)===0?0:(n.state&dr)===0?Et.CalcStatus.Waiting:Et.CalcStatus.Working,L=he,ge=r?0:he,_e=n.ext;if(F&&!this._iterate&&(n.state&q)!==_r)_e!==null&&(_e.demandValue=void 0),I=mo(n),L=0;else{if(F){let e=_e===null?void 0:_e.demandValue;_e!==null&&(_e.demandValue=void 0),I=e===void 0?0:e}else{if(n.state=n.state&~K|mr,l.perCellRead=!1,l.positionRead=!1,(n.state&lr)!==0){n.state&=~lr;let e=this._settlePass?Va(b,S,a,i):null;if(e!==null&&e.direct){me=!0,n.state&=~(cr|ur);let t=Ne(e);t?.isIRange?(I=fe.finalizeValueForCell(t),pe=e):I=e}}if(!me){this._planStats.evaluated++,n.state&=~(tr|cr|ur);let e=l.deferCount;I=fe.evaluateAt(a,i),I=fe.finalizeValueForCell(I),(l.perCellRead||l.positionRead)&&(n.block.positionRead=!0),l.deferCount!==e&&(I=this._takeDeferred(n,I),pe=this._spillHolder,this._spillHolder=null)}}L=(n.state&ur)===0?(n.state&(sr|cr))===0?0:Et.CalcStatus.Waiting:Et.CalcStatus.Working,L!==0&&(n.state|=cr)}let R;(n.state&K)!==hr&&(n.state=n.state&~K|gr),L!==ge&&(L===0?n.state&=~($n|dr):L===Et.CalcStatus.Working?n.state|=$n|dr:n.state=(n.state|$n)&~dr,g.calcStatusConflating||(g.calcStatusConflating=pt(N)),g.calcStatusConflating.append(ue,de,L!==0&&L)),F&&k.takeDemand(a,i);let ve=n.ext,z=ve===null?null:ve.fixedRef;if(ie||oe||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,Z),!R||!R.value.getError())){let e={...o.sanitizeRange(R),scope:R.scope,value:null};x.insertNonOverlapping(e),b.delete(e),ae(O,e)}}I=this._fitCell(p,I);let ye=1,be=1,xe=I,Se=typeof I==`object`&&!!I,Ce=Se&&xe.isIRange,V,H=Se&&y.isError(I,y.Code.Spill);if(z){ye=z.colEnd-z.colStart+1,be=z.rowEnd-z.rowStart+1;let t={colStart:z.colStart,rowStart:z.rowStart,colEnd:z.colEnd,rowEnd:z.rowEnd,scope:c},r=gn(I,t,N)?.tuples;b.delete(t),r&&b.setValues(r),ae(O,t),we(O,r,N),V={...t,value:new Vt(t,e,`fixed`,null,pe)},S.insert(V),s.addDynamicPrecedent(n,t,gi),x.insertNonOverlapping({...t,value:new Qe(t,te)})}else if(Ce&&xe.size>1){ye=xe.getColumnCount(),be=xe.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+ye-1,rowEnd:r+be-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)),H=f,!H){let e=x.search(u);if(H=e.length>1,!H&&e.length===1){let t=e[0],n=o.intersectRanges(u,t,eo);!n||n.rowEnd===n.rowStart&&n.colStart===n.colEnd&&n.colStart===i&&n.rowStart===a||(H=!0)}}let p,m;if(H)I=y.BuiltIn.Spill,ye=1,be=1,p=[[ue,[[de,[I]]]]],b.setValues(p),we(O,p,N),m={colStart:i,rowStart:a,colEnd:i,rowEnd:a};else{let e=mn(xe,N?l:r,N?r:l);e&&(p=e.tuples),b.delete(u),p&&b.setValues(p),ae(O,u),we(O,p,N),m=u}let h=H?{colStart:i,rowStart:a,colEnd:i,rowEnd:a,scope:c}:u;V={...h,value:new Vt(h,e,H?`error`:`dynamic`,H||t===null?null:t,pe,H?u:null)},S.insert(V),s.addDynamicPrecedent(n,u,gi),x.insertNonOverlapping({...m,value:new Qe(m,te)})}!v||p.blankCycleId===e&&p.blankMarkId===this._passMarkId||this._finalizeRepresentative(n,I,g,L!==0||F||!0===Ce||H||z!==null||me);let Te=!1;if((R||V||H||oe)&&(Te=o.isEqualRanges(R,V),R&&T.push(R),V&&w.push(V)),V||R){let e=R??V,t=V??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),Te&&H===se||(this._invalidatePlans(),s.getPrecedents().search(r).length>0&&(n.state|=Qn,h||=new B,h.insertNonOverlapping(r)))}n.cachedValue=I,m[A++]=n;let Ee=d!==null&&d.hasHolders()?Ne(I):I;Ce||z||k.push(a,i,Ee),A>=(k.observed?Ua:Wa)&&P(),((n.state&q)!==_r||n.ext!==null&&n.ext.shownGroup!==0)&&this._trackCircular(n,g,ue,de,N);let De=n.dependents,Oe=De.length;if(Oe>0){let e=(n.state&$n)!==0,t=!this._iterate&&(n.state&q)!==_r;t&&(this._taintGroup=n.ext.cycleGroup);for(let n=0;n<Oe;n++){let r=De[n];t&&fn(r,a,i,this._taintDownstream);let o=r.value.index;o<0||(bn(r)&&($o=o,es=Ee,fn(r,a,i,rs)),e&&fn(r,a,i,is))}}}}catch(n){let r=f[re];if(n instanceof cn||n instanceof hn&&this._iterate){let i=oo;if(i.length=0,n instanceof cn)for(let e=0;e<n.count;e++)i.push(n.nodes[e]);i.push(r),P(),r.state&=~K,this.doDemandEvaluate(e,t,i,P)}else{if(!(n instanceof hn||n instanceof on))throw n;{let e=n instanceof hn;r.state=r.state&~(K|q)|er|hr|(e?Y:vr);let t=G(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,P();for(let e of j.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=Gn,t=Kn;for(let n=0;n<t;n++)e[n]=void 0;Kn=0})(),this._planStats.evaluateMs+=Ja()-a,h}},Ia=(e,t)=>new at.ArrayList(e.slice(0,t));function La(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 Ra(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),ae(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 za(e,t,n){let r=e.getDemandedBlank(),i=[];for(let e=0;e<t.length;e++)ti(t[e],r,i);i.length>0&&Ra(i,n,e.gridId)}function Ba(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 Va=(e,t,n,r)=>{let i=e.getValueAt(n,r);return P(i)?i:Mt(t,n,r)},Ha=Symbol(`unsetGridId`),Ua=1024,Wa=65536;function Ga(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 Ka(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 qa(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 Ja=()=>globalThis.performance?.now()??Date.now(),Ya=(e,t)=>e.orderIndex-t.orderIndex,Xa=[],Za=[];function Qa(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 $a(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 eo={rowStart:0,colStart:0,rowEnd:0,colEnd:0,scope:null},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},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&q)===_r?t.shownGroup:t.cycleGroup},mo=e=>Ne(e.cachedValue)??0,ho={rowStart:0,colStart:0,rowEnd:0,colEnd:0},Q=1e4,go=U(Q),_o=U(Q),vo=U(Q),yo=U(Q),bo=U(Q),xo=U(Q),So=U(Q),Co=U(Q),wo=U(Q),To=U(Q),Eo=U(Q),Do=U(Q),Oo=U(Q),ko=U(Q),Ao=U(Q),jo=U(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=U(8),qo=U(8),Jo=U(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||(Gn[r+t]=n)})(e,$o,es)},is=e=>{e.state|=sr},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:U(Q),length:0},cs={values:U(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=vt(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=vt(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(Lt(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(Lt(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=Lt(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=fe.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 At.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=Lt(r),u=l.sheetIndex>=0?l.sheetIndex:n.getSheetNames().length>0?0:-1,d=vt(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(W.Sheet,e)?.toString(),this._heldCloneKey=null,this._callbacks=e.callbacks,this._runtime=e.runtime,this._richData=e.richData??me.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 On({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),precedentSpatial:new On({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}}),dynamicByBlock:new Map,dirtySpatial:new On}),e.modelCommitId&&this.mirror(e.modelCommitId),this._context=new xi(this,v.Axis.Column,e.functions),this._deferred=new fa(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)=>Ht.fromJSON({type:e,data:t},this._richData),addResource:(e,t)=>ea(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 Fa(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=>{Pn.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 P(i)?i:Mt(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=P(v),x=b?v:Mt(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&=~($n|cr|ur|dr),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 fn(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},ae(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|=lr),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=Lt(e)?.bookId??null,l=c?null:Lt(this._externalBindings.getNameById(e)?.getScope()??``)?.bookId??null;return new Fn(s.compile(t.getRuntime(),r,i,n,this._symbols,e=>t.getFunction(e),c??l?vt(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=Rt(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=Lt(e);if(!n||n.sheetEnd===n.sheetIndex)return null;let r=[];for(let e=n.sheetIndex;e<=n.sheetEnd;e++)r.push(vt(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=tt(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 Mi({...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()??yt,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 On({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0}}),precedentSpatial:new On({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}}),dynamicByBlock:new Map,dirtySpatial:new On},$)}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:Tt(n)};case`tables`:return this.applyTables(n.changes),{cycleId:this._cycleId,commitId:Tt(n)};case`names`:return this.applyNames(n.changes),{cycleId:this._cycleId,commitId:Tt(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:Tt(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===qt.Status.Off||t===qt.Status.Error?(this.retarget(e),!1):t===qt.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 mi(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 P(a.cachedValue)&&(a.cachedValue=void 0);let l=dn(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 P(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||dt(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)&&!dt(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=>V(e,n)?ce():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(W.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||dt(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?He(e,t):ce(),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)||dt(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)&&ni(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 On;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=pt(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=tt(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};
|