@sheetxl/sdk 0.4.10 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/browser/cjs/39ybckEYrSwofEL8.cjs +7 -0
  2. package/browser/cjs/7F9Y23ZviM83MrLB.cjs +7 -0
  3. package/browser/cjs/9OWmR6t6tmtR3HKs.cjs +7 -0
  4. package/browser/cjs/AoftwE84s7sGV4YJ.cjs +7 -0
  5. package/browser/cjs/BJZM9I81r8nRPehZ.cjs +7 -0
  6. package/browser/cjs/BLHJddfDq44WHNs6.cjs +7 -0
  7. package/browser/cjs/BdbcopQNFs0VAYoZ.cjs +7 -0
  8. package/browser/cjs/C2McR1ZSNpfPMaI1.cjs +7 -0
  9. package/browser/cjs/CAC1euA3bA1IpMhZ.cjs +7 -0
  10. package/browser/cjs/CDwPpmyZAYF_aBaX.cjs +7 -0
  11. package/browser/cjs/CP2yuwDM2Fzm2bQy.cjs +7 -0
  12. package/browser/cjs/CSn-hMrEUwFcYpBT.cjs +13 -0
  13. package/browser/cjs/CeuXJMoeKjSnby5j.cjs +7 -0
  14. package/browser/cjs/Ch5W6IQIqcVy3CUV.cjs +10 -0
  15. package/browser/cjs/CtaH9jllSQmzD2AZ.cjs +7 -0
  16. package/browser/cjs/Ctw9E_2VE0l2P6Yk.cjs +7 -0
  17. package/browser/cjs/Czl-z-_3jRiufzFq.cjs +7 -0
  18. package/browser/cjs/D-HLMUqMDuHV5fFD.cjs +7 -0
  19. package/browser/cjs/D5pK8FbUHJmgHMVR.cjs +7 -0
  20. package/browser/cjs/DA7BmT8kgTnFcBps.cjs +7 -0
  21. package/browser/cjs/DBBaD9qGTCHmDZzt.cjs +7 -0
  22. package/browser/cjs/DD24B_zQQtT3iqLe.cjs +7 -0
  23. package/browser/cjs/DKwnqzohEhfP9-D8.cjs +7 -0
  24. package/browser/cjs/DO-igV-beWuURc9q.cjs +7 -0
  25. package/browser/cjs/DR2yNdWmKOx4XEn_.cjs +7 -0
  26. package/browser/cjs/D_PNelhiuhC_pYQe.cjs +7 -0
  27. package/{node/esm/Dk3ABmYKlVup4l-u.mjs → browser/cjs/Dg4inQb_qTGcwKWj.cjs} +2 -5
  28. package/browser/cjs/KlMBkdsOI1TbINZi.cjs +7 -0
  29. package/browser/cjs/Me1cXPMFZnMqu9Ni.cjs +10 -0
  30. package/browser/cjs/P1V-5yUNwU9r5yLw.cjs +7 -0
  31. package/browser/cjs/Vkjfeba56sx1eWi0.cjs +7 -0
  32. package/browser/cjs/dwUVhGNDSgZfRm3P.cjs +7 -0
  33. package/browser/cjs/index.cjs +4 -3
  34. package/browser/cjs/txLIAZHRWIU9kf0I.cjs +7 -0
  35. package/browser/esm/30SRICLt1PAxlGS8.mjs +7 -0
  36. package/browser/esm/{CsPZhcz5eLf-CbkJ.mjs → 9jeiH8SVL_ZJYLxo.mjs} +2 -7
  37. package/browser/esm/B-xoX7KIAUytU1_U.mjs +7 -0
  38. package/browser/esm/B_bzVKesE_JRp6EW.mjs +7 -0
  39. package/browser/esm/BbO1W_XgpJnqTSty.mjs +7 -0
  40. package/browser/esm/BngRU84kl6oeKeYG.mjs +7 -0
  41. package/browser/esm/BuJVzVii6s-ETLFo.mjs +7 -0
  42. package/browser/esm/ByHA0yF73W3Lubv1.mjs +13 -0
  43. package/browser/esm/C9XmeyBj3CidGuuQ.mjs +7 -0
  44. package/browser/esm/CGlSMtRCaIAn2kcK.mjs +7 -0
  45. package/browser/esm/CNZEHpuUipSLJnir.mjs +7 -0
  46. package/browser/esm/CUDgLpRqpHPjfaCi.mjs +7 -0
  47. package/browser/esm/ChB6ZgoNr49oUuh9.mjs +7 -0
  48. package/browser/esm/D0HYMuygnYvY7Atx.mjs +7 -0
  49. package/browser/esm/D1PWaFTHEZfGGXTb.mjs +7 -0
  50. package/browser/esm/D2zmZcBdOoyixeUA.mjs +7 -0
  51. package/browser/esm/D525g_2eyexUf3Zf.mjs +7 -0
  52. package/browser/esm/DMJw8DmfeX6u2glN.mjs +7 -0
  53. package/browser/esm/DfHQEyIlLlv5P49Q.mjs +7 -0
  54. package/browser/esm/Dhvtq8jHg8BxOR0C.mjs +7 -0
  55. package/browser/esm/DkPPc6PpShDjAHJV.mjs +7 -0
  56. package/browser/esm/DqEqprkW8poZvfjh.mjs +7 -0
  57. package/browser/esm/DtSj65a0yyYL8HUw.mjs +7 -0
  58. package/browser/esm/Dw0Okzcg5hIcHUcc.mjs +7 -0
  59. package/browser/esm/Dzo7yK5H2NRkocTa.mjs +7 -0
  60. package/browser/esm/G_2bOLOa20d7iobX.mjs +7 -0
  61. package/browser/esm/MRXgg6FvbB08Ze4M.mjs +7 -0
  62. package/browser/esm/SePiM6uWrcY09dym.mjs +7 -0
  63. package/browser/esm/eCZnrKI7SxPgdErZ.mjs +7 -0
  64. package/browser/esm/index.mjs +2 -84
  65. package/browser/esm/nE8H93zlwoi3F8Ii.mjs +10 -0
  66. package/browser/esm/ui3SG2ZyuCKIR0An.mjs +7 -0
  67. package/browser/esm/vk7TdrD0zPqtT8_n.mjs +7 -0
  68. package/browser/esm/yM_d2jrPPN_EupI0.mjs +10 -0
  69. package/licenses/dependencies.txt +3 -3
  70. package/{browser/esm/70MScShy9oEFZGC-.mjs → node/esm/BJvhZja9zXr81ch6.mjs} +1 -1
  71. package/node/esm/{YqgO5dqnNDu6tJAq.mjs → BK_7sJa3fTDIKVsK.mjs} +2 -2
  72. package/node/esm/{CdbncxwuP2LcomiC.mjs → BPhIhbwKpbuhJ5n5.mjs} +1 -1
  73. package/node/esm/{BYw54CVi5Zykf7P_.mjs → BQb_TIMVKb4ap8qn.mjs} +1 -1
  74. package/node/esm/{B2GPpiwGDiHZ4Mnx.mjs → BW1-l-HQdvRTQ7Bm.mjs} +4 -4
  75. package/{browser/esm/Dk3ABmYKlVup4l-u.mjs → node/esm/Bkj8joA7ej1p4iQv.mjs} +1 -1
  76. package/node/esm/{BD4U7piuPUWGdmvF.mjs → BnQS3_N8ZEyMLfgn.mjs} +1 -1
  77. package/node/esm/{CYs7VtVLEbhMy_iG.mjs → Bs1vmYEblngyWvkW.mjs} +1 -1
  78. package/node/esm/{BWm5puKy7haAGpHu.mjs → BtDgmaUXSuZwZauR.mjs} +2 -2
  79. package/node/esm/{Blozz9cX9jUqOnkK.mjs → C2nQBB-2yJ1qfKsG.mjs} +1 -1
  80. package/node/esm/{mkuXwkQcdkBHUMsY.mjs → CEBBIejO4nn_eoLE.mjs} +1 -1
  81. package/{browser/esm/3AEwlfYXdvg1zUXm.mjs → node/esm/CEBaRGnJ6Pau61Z3.mjs} +1 -1
  82. package/node/esm/{CxkMMFqIme5dCX9o.mjs → CSr4e1I9DtTv2w79.mjs} +1 -1
  83. package/node/esm/CWUmgm7_b5VypIPN.mjs +80 -0
  84. package/node/esm/{BW04nsyJWeVHBcFW.mjs → Cb2A-sSxQbrq7_st.mjs} +1 -1
  85. package/node/esm/{DQwOIKwLzYjUwPmT.mjs → CfSD4cLmkg0FqnhQ.mjs} +1 -1
  86. package/node/esm/{C8OHYChkHQk2jVzy.mjs → ChgW0mo5gCgLQ4qn.mjs} +1 -1
  87. package/node/esm/{Br_wraXbAu-VOj0p.mjs → Cl6j-EVdzk8MvmYu.mjs} +1 -1
  88. package/node/esm/{CXhWG2Dg31l6Mo8r.mjs → Cvzp8bwJnKvjvZSp.mjs} +1 -1
  89. package/node/esm/{BJgxNxKnNgVBP4Hp.mjs → D-7D30G3TPv5yZHW.mjs} +1 -1
  90. package/node/esm/{0OTV9xpta6cm7Yx6.mjs → DPWAK-dKa7BGHzhV.mjs} +1 -1
  91. package/{browser/esm/DbezlvRyCGtHZgSZ.mjs → node/esm/DaA9EfLaa4eAL5v5.mjs} +1 -1
  92. package/{browser/esm/sUZorY3sws86BcMb.mjs → node/esm/DdQQdRO6WRU-o7fW.mjs} +1 -1
  93. package/{browser/esm/BLET1HFCb5u0-_Eo.mjs → node/esm/DqzaLjnlgJ73P6fj.mjs} +1 -1
  94. package/node/esm/{DXj8p7NZndUJBRAj.mjs → KTvP9pq_hIePsIcs.mjs} +1 -1
  95. package/node/esm/{Dq32tysuLIKWEFO_.mjs → R6sbyZ3F8U46a2pT.mjs} +1 -1
  96. package/node/esm/{DrU-yP_Fb9i7w1lb.mjs → RjYTditNvvkkhvec.mjs} +1 -1
  97. package/{browser/esm/CCcaxwoCKpK91TYc.mjs → node/esm/Ru2U-PXJ-wtFJVIi.mjs} +1 -1
  98. package/{browser/esm/CA504N_MgS6GSFmG.mjs → node/esm/_50UNzbNjsJJ5JeA.mjs} +1 -1
  99. package/node/esm/{Cyb9hq0LVkNm7yoj.mjs → ebMdiumtVWrujqaH.mjs} +1 -1
  100. package/node/esm/index.mjs +8 -8
  101. package/node/esm/{BelMCqHHX_Ln7ik4.mjs → wYdBXNtyuqNnNqw7.mjs} +2 -2
  102. package/package.json +4 -4
  103. package/browser/cjs/-4uKwgMCs2uA4zYY.cjs +0 -6
  104. package/browser/cjs/23Opade9fWTWmOw5.cjs +0 -6
  105. package/browser/cjs/6SNZR9WEya-Mi0Ec.cjs +0 -1501
  106. package/browser/cjs/7lk46bEggXm0Adux.cjs +0 -6
  107. package/browser/cjs/B0U3u9iqqnQvnw_Z.cjs +0 -6
  108. package/browser/cjs/BEQPlpKfeBPKELfa.cjs +0 -6
  109. package/browser/cjs/BKdxsyIZAckH_1Rs.cjs +0 -6
  110. package/browser/cjs/BKu_2G3LBpnvF7WK.cjs +0 -6
  111. package/browser/cjs/BTWYrYyq7P04Hhgy.cjs +0 -6
  112. package/browser/cjs/BVgdgozKIof0HqZa.cjs +0 -6
  113. package/browser/cjs/BXi-7ztAEss53BNW.cjs +0 -6
  114. package/browser/cjs/BzzSS21ndAnpHnTK.cjs +0 -6
  115. package/browser/cjs/C-JX44FribP4xuCm.cjs +0 -6
  116. package/browser/cjs/C12NQkp7rKKeLgpL.cjs +0 -60
  117. package/browser/cjs/CIisU9Fr1gqlOapx.cjs +0 -13
  118. package/browser/cjs/CRjnB0UGZizopxIy.cjs +0 -7
  119. package/browser/cjs/CfmxldeTiQsDhe4k.cjs +0 -6
  120. package/browser/cjs/CrkVZFNUXb_YVEfl.cjs +0 -6
  121. package/browser/cjs/Csmvu-Gg7GIET2fx.cjs +0 -124
  122. package/browser/cjs/D5kea7N3qYrpyi6Z.cjs +0 -6
  123. package/browser/cjs/DDPVADUPfi4JqKY9.cjs +0 -15
  124. package/browser/cjs/DJSDSOdIMakiUL9U.cjs +0 -6
  125. package/browser/cjs/DgJG2zU2CpBE2JKD.cjs +0 -6
  126. package/browser/cjs/DqHT7AmlwwAApU0v.cjs +0 -32
  127. package/browser/cjs/DqdKJmCBZ3tiiTyS.cjs +0 -6
  128. package/browser/cjs/Dy_w3ejsXCUjhwLi.cjs +0 -6
  129. package/browser/cjs/EAjldglgyKcpKzX6.cjs +0 -6
  130. package/browser/cjs/QraWsiDLYuP865Pt.cjs +0 -6
  131. package/browser/cjs/TMXcSm2F77kJ6GbS.cjs +0 -6
  132. package/browser/cjs/g9Un0PdQLp8LcMP-.cjs +0 -6
  133. package/browser/cjs/hNHT5yLsXAZ-mS5K.cjs +0 -6
  134. package/browser/cjs/o_FLjAWENTjXcsuZ.cjs +0 -6
  135. package/browser/cjs/rBPqKMZ7T6poaL7T.cjs +0 -6
  136. package/browser/esm/3-pvLx1jF0RJ56jT.mjs +0 -472
  137. package/browser/esm/3kB3KaOgV-3ox4C3.mjs +0 -426
  138. package/browser/esm/BJgxNxKnNgVBP4Hp.mjs +0 -10
  139. package/browser/esm/BO-YRuEp35GIVL4O.mjs +0 -10
  140. package/browser/esm/BOL-jxmJyje4-Hxe.mjs +0 -10
  141. package/browser/esm/BSFibAPQFeBovPl3.mjs +0 -10
  142. package/browser/esm/BW04nsyJWeVHBcFW.mjs +0 -10
  143. package/browser/esm/BaGFns-M8bCUjgnc.mjs +0 -3974
  144. package/browser/esm/BifIJRmeTJJLYCr-.mjs +0 -24
  145. package/browser/esm/Br_wraXbAu-VOj0p.mjs +0 -10
  146. package/browser/esm/BvE9cJg2esqHIr98.mjs +0 -10
  147. package/browser/esm/CMO8yX7mxIaFV5GC.mjs +0 -820
  148. package/browser/esm/Cqf8ZomeNI_0U-UD.mjs +0 -29
  149. package/browser/esm/DQwOIKwLzYjUwPmT.mjs +0 -10
  150. package/browser/esm/DXj8p7NZndUJBRAj.mjs +0 -10
  151. package/browser/esm/DcPcMjMOmfyIGaSN.mjs +0 -1575
  152. package/browser/esm/DhqkybSwX2wqkqcf.mjs +0 -24009
  153. package/browser/esm/DpJLw2aGOg6yuBjH.mjs +0 -10
  154. package/browser/esm/Dq32tysuLIKWEFO_.mjs +0 -10
  155. package/browser/esm/DrU-yP_Fb9i7w1lb.mjs +0 -10
  156. package/browser/esm/WY6tkuqX7I-Tw85_.mjs +0 -5651
  157. package/browser/esm/mkuXwkQcdkBHUMsY.mjs +0 -10
  158. package/browser/esm/skZ-cAv6270PFv3k.mjs +0 -10
  159. package/browser/esm/xUdz3zy_nz-hMfhq.mjs +0 -21
  160. package/node/esm/3AEwlfYXdvg1zUXm.mjs +0 -10
  161. package/node/esm/70MScShy9oEFZGC-.mjs +0 -10
  162. package/node/esm/BLET1HFCb5u0-_Eo.mjs +0 -10
  163. package/node/esm/CA504N_MgS6GSFmG.mjs +0 -10
  164. package/node/esm/CCcaxwoCKpK91TYc.mjs +0 -10
  165. package/node/esm/CSgS-BWwvF8YA6gv.mjs +0 -80
  166. package/node/esm/DbezlvRyCGtHZgSZ.mjs +0 -10
  167. package/node/esm/sUZorY3sws86BcMb.mjs +0 -10
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license @sheetxl/sdk - SDK - A high-performance, embeddable spreadsheet engine. - v0.4.12
3
+ *
4
+ * (C) 2025-present SheetXL Inc. & Michael T. Ford
5
+ * License: The license can be found at https://www.sheetxl.com/license.
6
+ */
7
+ const t={Number:"n",String:"s",Boolean:"b",Error:"e",RichData:"r",Null:"z"};var e,n,r;(n=e||(e={})).Orientation={Column:"column",Row:"row"},n.Orientations={...n.Orientation,Both:"both"},n.Direction={Up:"up",Down:"down",Left:"left",Right:"right"},(t=>{t.Code={Parse:0,Null:1,Div0:2,Value:3,Ref:4,Name:5,Num:6,NA:7,GettingData:8,Spill:9,Connect:10,Blocked:11,Unknown:12,Field:13,Calc:14,Busy:16,Python:19,Timeout:20},t.Label={Parse:"#PARSE!",Null:"#NULL!",Div0:"#DIV/0!",Value:"#VALUE!",Ref:"#REF!",Name:"#NAME?",Num:"#NUM!",NA:"#N/A",GettingData:"#GETTING_DATA",Spill:"#SPILL!",Connect:"#CONNECT!",Blocked:"#BLOCKED!",Unknown:"#UNKNOWN!",Field:"#FIELD!",Calc:"#CALC!",Busy:"#BUSY!",Python:"#PYTHON!",Timeout:"#TIMEOUT!"};class e extends Error{constructor(t,e,n,r){super(n,r),this._label=e,this._code=t,this.details=r}static{this.code=t.Code.Unknown}get isFormulaError(){return!0}getLabel(){return this._label}getCode(){return this._code}equals(t){return!!t&&(this._code===t._code||this._code===t.code)}get[Symbol.toStringTag](){return"[FormulaError]"}toString(){return this.message||this._label}}t.Known=e;class n extends e{constructor(e,n){super(t.Code.Parse,t.Label.Parse,e,n)}static{this.code=t.Code.Parse}getDetails(){const t=this.details;return{line:t?.line??1,column:t?.column??1,offset:t?.offset??0,length:t?.length??0}}}t.Parse=n;class r extends e{constructor(e,n){super(t.Code.Null,t.Label.Null,e,n)}static{this.code=t.Code.Null}}t.Null=r;class o extends e{constructor(e,n){super(t.Code.Div0,t.Label.Div0,e,n)}static{this.code=t.Code.Div0}}t.Div0=o;class s extends e{constructor(e,n){super(t.Code.Value,t.Label.Value,e,n)}static{this.code=t.Code.Value}}t.Value=s;class i extends e{constructor(e,n){super(t.Code.Ref,t.Label.Ref,e,n)}static{this.code=t.Code.Ref}}t.Ref=i;class a extends e{constructor(e,n){super(t.Code.Name,t.Label.Name,e,n)}static{this.code=t.Code.Name}}t.Name=a;class l extends e{constructor(e,n){super(t.Code.Num,t.Label.Num,e,n)}static{this.code=t.Code.Num}}t.Num=l;class c extends e{constructor(e,n){super(t.Code.NA,t.Label.NA,e,n)}static{this.code=t.Code.NA}}t.NA=c;class h extends e{constructor(e,n){super(t.Code.GettingData,t.Label.GettingData,e,n)}static{this.code=t.Code.GettingData}}t.GettingData=h;class u extends e{constructor(e,n){super(t.Code.Spill,t.Label.Spill,e,n)}static{this.code=t.Code.Spill}}t.Spill=u;class d extends e{constructor(e,n){super(t.Code.Connect,t.Label.Connect,e,n)}static{this.code=t.Code.Connect}}t.Connect=d;class g extends e{constructor(e,n){super(t.Code.Blocked,t.Label.Blocked,e,n)}static{this.code=t.Code.Blocked}}t.Blocked=g;class m extends e{constructor(e,n){super(t.Code.Unknown,t.Label.Unknown,e,n)}static{this.code=t.Code.Unknown}}t.Unknown=m;class f extends e{constructor(e,n){super(t.Code.Field,t.Label.Field,e,n)}static{this.code=t.Code.Field}}t.Field=f;class p extends e{constructor(e,n){super(t.Code.Calc,t.Label.Calc,e,n)}static{this.code=t.Code.Calc}}t.Calc=p;class _ extends e{constructor(e,n){super(t.Code.Busy,t.Label.Busy,e,n)}static{this.code=t.Code.Busy}}t.Busy=_;class S extends e{constructor(e,n){super(t.Code.Python,t.Label.Python,e,n)}static{this.code=t.Code.Python}}t.Python=S;class w extends e{constructor(e,n){super(t.Code.Timeout,t.Label.Timeout,e,n)}static{this.code=t.Code.Timeout}}t.Timeout=w})(r||(r={}));const o={};o[r.Code.Parse]=r.Parse,o[r.Code.Null]=r.Null,o[r.Code.Div0]=r.Div0,o[r.Code.Value]=r.Value,o[r.Code.Ref]=r.Ref,o[r.Code.Name]=r.Name,o[r.Code.Num]=r.Num,o[r.Code.NA]=r.NA,o[r.Code.GettingData]=r.GettingData,o[r.Code.Spill]=r.Spill,o[r.Code.Connect]=r.Connect,o[r.Code.Blocked]=r.Blocked,o[r.Code.Unknown]=r.Unknown,o[r.Code.Field]=r.Field,o[r.Code.Calc]=r.Calc,o[r.Code.Busy]=r.Busy,o[r.Code.Python]=r.Python,o[r.Code.Timeout]=r.Timeout;const s=new Map,i=new Map,a=new Map,l=new Map,c=Object.keys(o);for(let t=0;t<c.length;t++){const e=c[t],n=o[e];a.set(r.Label[e],n),l.set(r.Code[e],n);const h=new n;s.set(h.getLabel(),h),i.set(h.getCode(),h)}const h=i.get(r.Code.Unknown);var u;(u=r||(r={})).BuiltIn={Parse:new u.Parse,Null:new u.Null,Div0:new u.Div0,Value:new u.Value,Ref:new u.Ref,Name:new u.Name,Num:new u.Num,NA:new u.NA,GettingData:new u.GettingData,Spill:new u.Spill,Connect:new u.Connect,Blocked:new u.Blocked,Unknown:new u.Unknown,Field:new u.Field,Calc:new u.Calc,Busy:new u.Busy,Python:new u.Python,Timeout:new u.Timeout},u.getBuiltInByLabel=t=>s.get(t),u.newTypedError=(t,e,n)=>{let r;return r="string"==typeof t?a.get(t):l.get(t),r||(r=u.Unknown),new r(e,n)},u.getBuiltInById=t=>i.get(t)||h;let d=class{constructor(t){this._subscribeFn=t}subscribe(t,e,n){const r="object"==typeof t?{next:t.next||(()=>{}),error:t.error||(()=>{}),complete:t.complete||(()=>{}),unsubscribe:()=>{}}:{next:t||(()=>{}),error:e||(()=>{}),complete:n||(()=>{}),unsubscribe:()=>{}},o=this._subscribeFn(r);return r.unsubscribe=()=>{"function"==typeof o&&o()},r}},g=class{getRange(t){throw new m}getReference(t,e){throw new m}getNumberFormat(t,e){return e?.toString()??""}fromOADate(t){return new Date(t)}toOADate(t){return t.getTime()}getValueAt(t,e){return null}getEntireCoords(){return p}isValidDate(t){return(t instanceof Date||"[object Date]"===Object.prototype.toString.call(t))&&!isNaN(t.getTime())}getPosition(){return f}getFormulaAt(t,e){return null}getSpillAt(t,e){return null}getSheetIndex(t){return-1}getSheetCount(){return 1}markVolatile(){}formatResults(t){}getFunction(t){return null}getAddress(t,e){throw new m}parseAsDateTime(t,e){throw new m}getRuntime(){return _}},m=class extends Error{constructor(t="Not implemented in StubbedFormulaContext"){super(t),this.name="NotImplementedError"}};const f=Object.freeze({colIndex:0,rowIndex:0}),p=Object.freeze({colStart:0,rowStart:0,colEnd:Math.pow(2,14)-1,rowEnd:Math.pow(2,20)-1}),_={getCurrencySymbol:()=>"$",getNumberDecimalSeparator:()=>".",getNumberGroupSeparator:()=>",",isDate1904:()=>!1,getLocation:()=>"unknown",getVersion:()=>"1.0.0",getOS:()=>"unknown",getUser:()=>"unidentified",getDescription:()=>"Stubbed Formula Context"},S=new g,w={Up:"up",Down:"down",Left:"left",Right:"right"},y={TopLeft:"tl",Top:"t",TopRight:"tr",Left:"l",Center:"c",Right:"r",BottomLeft:"bl",Bottom:"b",BottomRight:"br"},E={html:"text/html",plain:"text/plain",png:"image/png"},b=Object.freeze({left:0,top:0}),v=Object.freeze({left:0,top:0,bottom:0,right:0}),C=Object.freeze({x:0,y:0,width:0,height:0}),x=Object.freeze(Object.defineProperty({__proto__:null,EmptyBounds:C,EmptyRect:v,EmptyTopLeft:b},Symbol.toStringTag,{value:"Module"})),I={Column:"column",Row:"row"},A={...I,Both:"both"},R=Object.freeze({colIndex:0,rowIndex:0}),M=Object.freeze({colStart:0,rowStart:0,colEnd:0,rowEnd:0}),T=(t,e)=>t.colStart===e.colStart?t.rowStart-e.rowStart:t.colStart-e.colStart,N=(t,e)=>t.rowStart===e.rowStart?t.colStart-e.colStart:t.rowStart-e.rowStart,F=(t,e)=>t.rowEnd===e.rowEnd?e.colEnd-t.colEnd:e.rowEnd-t.rowEnd,k=(t,e)=>t.colEnd===e.colEnd?e.rowEnd-t.rowEnd:e.colEnd-t.colEnd,O=(t,e)=>t.colIndex===e.colIndex?t.rowIndex-e.rowIndex:t.colIndex-e.colIndex,L=(t,e)=>t.rowIndex===e.rowIndex?t.colIndex-e.colIndex:t.rowIndex-e.rowIndex,D=(t=I.Row,e=!1)=>e?t!==I.Column?F:k:t!==I.Column?N:T,B=(t,e)=>t===e||!(!t||!e)&&t.rowIndex===e.rowIndex&&t.colIndex===e.colIndex,z=(t,e)=>t===e||!(!t||!e)&&t.rowStart===e.rowStart&&t.rowEnd===e.rowEnd&&t.colStart===e.colStart&&t.colEnd===e.colEnd,P=(t,e)=>!(!t||!e||t.colStart>e.colEnd||e.colStart>t.colEnd||t.rowStart>e.rowEnd||e.rowStart>t.rowEnd),j=(t,e)=>{if(t===e)return!0;if(!t||!e)return!1;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!z(t[n],e[n]))return!1;return!0},H=(t,e,n)=>{if(!t&&!e)return null;if(!t)return n?e:{...e};if(!e)return n?t:{...t};const r=Math.min(t.colStart,e.colStart),o=Math.min(t.rowStart,e.rowStart),s=Math.max(t.colEnd,e.colEnd),i=Math.max(t.rowEnd,e.rowEnd);let a=n;return a?(a.colStart=r,a.rowStart=o,a.colEnd=s,a.rowEnd=i):a={colStart:r,rowStart:o,colEnd:s,rowEnd:i},a},V=(t,e)=>{if(!e||0===e.length)return t;const n={...t};for(let t=0;t<e.length;t++){const r=e[t];P(n,r)&&(n.rowStart=Math.min(n.rowStart,r.rowStart),n.colStart=Math.min(n.colStart,r.colStart),n.rowEnd=Math.max(n.rowEnd,r.rowEnd),n.colEnd=Math.max(n.colEnd,r.colEnd))}return n},$=[null,null],U=(t,e,n)=>{if(t[0].value===t[1].value)return e};function G(t,e=2,n,r=I.Row,o){let s=[...t];if(e<=0||t.length<=1)return s;let i=r===I.Column,a=0,l=!1;do{const t=s.sort(D(i?I.Row:I.Column));s=[],s.push(t[0]);const e=t.length;let c=0,h=t[0],u=h.colStart,d=h.rowStart,g=h.colEnd,m=h.rowEnd;for(let a=1;a<e;a++){const e=t[a];let f=!1;if(f=i?h&&d===e.rowStart&&m===e.rowEnd&&g+1===e.colStart:h&&u===e.colStart&&g===e.colEnd&&m+1===e.rowStart,f){let t={colStart:u,rowStart:d,colEnd:i?e.colEnd:g,rowEnd:i?m:e.rowEnd};if(void 0!==h.value&&(t.value=h.value),n){const s=o??[null,null];s[0]=h,s[1]=e,t=n(s,t,r)}if(t){s[c]=t,l=!0,h=t,u=h.colStart,d=h.rowStart,g=h.colEnd,m=h.rowEnd;continue}}s[++c]=e,h=e,u=h.colStart,d=h.rowStart,g=h.colEnd,m=h.rowEnd}a++,i=!i,1===a&&(l=!0)}while(a<e&&l&&s.length>1);return s}const W=Object.freeze(Object.defineProperty({__proto__:null,EmptyCell:R,EmptyRange:M,cellToRange:(t,e)=>{if(!t)return null;let n=e;return n||(n={...t},delete n.colIndex,delete n.rowIndex),n.colStart=t.colIndex??0,n.rowStart=t.rowIndex??0,n.colEnd=t.colIndex??0,n.rowEnd=t.rowIndex??0,n},columnFirstCellComparator:O,columnFirstRangeComparator:T,createCellComparator:(t=I.Row,e=!1)=>e?t!==I.Column?(t,e)=>t.rowIndex===e.rowIndex?e.colIndex-t.colIndex:e.rowIndex-t.rowIndex:(t,e)=>t.colIndex===e.colIndex?e.rowIndex-t.rowIndex:e.colIndex-t.colIndex:t!==I.Column?L:O,createConflatingRanges:(t,e=!1)=>{const n=[];let r,o,s=Number.MIN_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER;return{append:(a,l,c)=>{let h=!0;const u=void 0!==c;if(u){const n=t?t(o,c,e):o===c?c:void 0;void 0===n?h=!1:c=n}if(h&&l===i+1&&a===s)return e?r.rowEnd=l:r.colEnd=l,i=l,void(o=c);r&&n.push(r);const d=e?a:l,g=e?l:a;r={colStart:d,rowStart:g,colEnd:d,rowEnd:g},u&&(r.value=c),s=a,i=l,o=c},done:t=>(r&&(n.push(r),r=null),t?G(n,3,!0===t?U:t,e?I.Column:I.Row,$):n)}},createRangeComparator:D,defaultRange:(t,e,n)=>t?n?(n.colStart=t.colStart??e.colStart,n.rowStart=t.rowStart??e.rowStart,n.colEnd=t.colEnd??e.colEnd,n.rowEnd=t.rowEnd??e.rowEnd,n):{colStart:t.colStart??e.colStart,rowStart:t.rowStart??e.rowStart,colEnd:t.colEnd??e.colEnd,rowEnd:t.rowEnd??e.rowEnd}:e,extendRangeToIntersectingRanges:V,extendRangeToUnionRanges:(t,e)=>{if(!e||0===e.length)return t;let n=t,r=null;for(;!z(n,r);)r=n,n=V(r,e);return n},indexOfCoords:(t,e)=>{const n={colStart:t.colIndex,rowStart:t.rowIndex,colEnd:t.colIndex,rowEnd:t.rowIndex};for(let t=e.length-1;t>=0;t--)if(P(n,e[t]))return t;return-1},intersectRanges:(t,e,n)=>{if(!t)return n?e:{...e};if(!e)return n?t:{...t};if(!t&&!e)return null;if(t.rowStart>e.rowEnd||t.rowEnd<e.rowStart||t.colStart>e.colEnd||t.colEnd<e.colStart)return null;const r=Math.max(t.colStart,e.colStart),o=Math.max(t.rowStart,e.rowStart),s=Math.min(t.colEnd,e.colEnd),i=Math.min(t.rowEnd,e.rowEnd);let a=n;return a?(a.colStart=r,a.rowStart=o,a.colEnd=s,a.rowEnd=i):a={colStart:r,rowStart:o,colEnd:s,rowEnd:i},a},isCellWithinRange:(t,e)=>!(!t||!e||t.rowIndex<e.rowStart||t.rowIndex>e.rowEnd||t.colIndex<e.colStart||t.colIndex>e.colEnd),isEqualCells:B,isEqualRanges:z,isEqualRangesArrays:j,isEqualSelectionCoords:(t,e)=>t===e||!(!t||!e)&&t.rangeIndex===e.rangeIndex&&!!B(t.cell,e.cell)&&j(t.ranges,e.ranges),isRangeWithinRange:(t,e)=>!(t.rowStart<e.rowStart||t.rowEnd>e.rowEnd||t.colStart<e.colStart||t.colEnd>e.colEnd),isRangesIntersect:P,isSingleCell:t=>!!t&&t.rowEnd===t.rowStart&&t.colStart===t.colEnd,isValidRange:t=>!(!t||"number"!=typeof t.colStart||t.colStart<0||"number"!=typeof t.colEnd||t.colEnd<t.colStart||"number"!=typeof t.rowStart||t.rowStart<0||"number"!=typeof t.rowEnd||t.rowEnd<t.rowStart),mergeRangedValues:G,rowFirstCellComparator:L,rowFirstRangeComparator:N,sanitizeRange:t=>t?{colStart:t.colIndex??t.colStart??0,rowStart:t.rowIndex??t.rowStart??0,colEnd:t.colIndex??t.colEnd??0,rowEnd:t.rowIndex??t.rowEnd??0}:null,translateRange:(t,e=-t.rowStart,n=-t.colStart,r)=>r?(r.colStart=t.colStart+n,r.rowStart=t.rowStart+e,r.colEnd=t.colEnd+n,r.rowEnd=t.rowEnd+e,r):{colStart:t.colStart+n,rowStart:t.rowStart+e,colEnd:t.colEnd+n,rowEnd:t.rowEnd+e},unionRanges:H,unionRangesArrays:(t,e,n)=>{if(!t||0===t.length)return null;if(1===t.length&&!e)return t[0];let r=t[0];for(let e=1;e<t.length;e++)r=H(r,t[e],n);return e&&(r=H(r,e,n)),r}},Symbol.toStringTag,{value:"Module"}));const q="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function J(t){return function(t){return!!t&&"object"==typeof t}(t)&&!function(t){const e=Object.prototype.toString.call(t);return"[object RegExp]"===e||"[object Date]"===e||function(t){return t.$$typeof===q}(t)}(t)}function X(t,e){return!1!==e.clone&&e.isMergeableObject(t)?Q((n=t,Array.isArray(n)?[]:{}),t,e):t;var n}function K(t,e,n){return t.concat(e).map(function(t){return X(t,n)})}function Y(t){return Object.keys(t).concat(function(t){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t).filter(function(e){return Object.propertyIsEnumerable.call(t,e)}):[]}(t))}function Z(t,e){try{return e in t}catch(t){return!1}}function Q(t,e,n){(n=n||{}).arrayMerge=n.arrayMerge||K,n.isMergeableObject=n.isMergeableObject||J,n.cloneUnlessOtherwiseSpecified=X;const r=Array.isArray(e);return r===Array.isArray(t)?r?n.arrayMerge(t,e,n):function(t,e,n){const r={};return n.isMergeableObject(t)&&Y(t).forEach(function(e){r[e]=X(t[e],n)}),Y(e).forEach(function(o){(function(t,e){return Z(t,e)&&!(Object.hasOwnProperty.call(t,e)&&Object.propertyIsEnumerable.call(t,e))})(t,o)||(Z(t,o)&&n.isMergeableObject(e[o])?r[o]=function(t,e){if(!e.customMerge)return Q;const n=e.customMerge(t);return"function"==typeof n?n:Q}(o,n)(t[o],e[o],n):r[o]=X(e[o],n))}),r}(t,e,n):X(e,n)}Q.all=function(t,e){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce(function(t,n){return Q(t,n,e)},{})};const tt=Object.freeze([]),et=Object.freeze({}),nt=t=>t,rt=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}),ot=(t,e)=>t===e||!(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)&&t.every((t,n)=>t===e[n]),st=t=>"object"==typeof t&&!Array.isArray(t)&&null!==t,it=t=>"object"!=typeof t||Array.isArray(t)||null===t?t:(Object.keys(t).forEach(function(e){t[e]&&"object"==typeof t[e]?it(t[e]):null!==t[e]&&void 0!==t[e]||delete t[e],"object"==typeof t[e]&&0===Object.keys(t[e]).length&&delete t[e]}),0===Object.keys(t).length?null:t),at=(t,e)=>!(t!==e&&!ot(t,e)&&!t.isEqual?.(e)),lt=(t,e,n=at)=>{if(null==t||t===e)return null;if(!t||"object"!=typeof t||Array.isArray(t)||t.isImmutable?.())return n(t,e)?null:t;const r=Object.keys(t);if(0===r.length)return null;let o=!1;for(let s=0;s<r.length;s++){const i=r[s];null===lt(t[i],e?.[i],n)&&(o=!0,delete t[i])}return o&&0===Object.keys(t).length?null:void 0},ct="object"==typeof performance&&"function"==typeof performance.now?()=>performance.now():()=>Date.now(),ht=t=>null==t,ut=(t,e)=>!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top),dt=!("undefined"==typeof window||!window.document||!window.document.createElement),gt={Windows:"windows",MacOS:"macos",IOS:"ios",Linux:"linux",Android:"android",Safari:"safari",Firefox:"firefox",Node:"node",Unknown:"unknown"},mt=()=>{if(ft())return gt.Node;const t=void 0!==globalThis.navigator&&globalThis.navigator.userAgent?globalThis.navigator.userAgent.toLowerCase():"";return t?/(win32|win64|windows|wince)/i.test(t)?gt.Windows:/(macintosh|macintel|macppc|mac68k|macos)/i.test(t)?gt.MacOS:/(iphone|ipad|ipod)/i.test(t)?gt.IOS:/android/.test(t)?gt.Android:/linux/.test(t)?gt.Linux:/^((?!chrome|android|).)*safari/i.test(t)?gt.Safari:/^((?!chrome|android|Seamonkey).)*firefox/i.test(t)?gt.Firefox:gt.Unknown:gt.Unknown};function ft(){return"undefined"!=typeof process&&"node"===process.release?.name||("undefined"!=typeof process&&process.browser,!1)}const pt=(t,e=!1)=>(document.hasFocus()||e)&&(t===document.activeElement||t?.contains(document.activeElement)),_t=Object.freeze(Object.defineProperty({__proto__:null,EmptyArray:tt,EmptyObject:et,OSType:gt,arrayMove:function(t,e,n){const r=t.slice();return r.splice(n<0?r.length+n:n,0,r.splice(e,1)[0]),r},asNumber:t=>{const e=(t=>1*t)(t);return Number.isFinite(e)?e:0},camelToPrettyCase:t=>1===t.length?t.toUpperCase():t.replace(/([A-Z])/g," $1").replace(/^./,function(t){return t.toUpperCase()}).trim(),canUseDOM:dt,cancelTimeout:t=>{cancelAnimationFrame(t.id)},castToString:t=>null==t||void 0===t?"":"string"!=typeof t?""+t:t,cloneObject:t=>ht(t)?t:JSON.parse(JSON.stringify(t)),consoleWithNoSource:(...t)=>new Promise(e=>{setTimeout(()=>{Function("console.log.apply(console, arguments)").apply(null,t),e()})}),debounce:function(t,e=300,n=!1){let r,o,s,i,a=0;function l(){let c=Date.now()-a;c<e&&c>=0?r=setTimeout(l,e-c):(r=null,n||(i=t.apply(s,o),s=o=null))}null==e&&(e=100);const c=function(){s=globalThis,o=arguments,a=Date.now();var c=n&&!r;return r||(r=setTimeout(l,e)),c&&(i=t.apply(s,o),s=o=null),i};return c.clear=function(){r&&(clearTimeout(r),r=null)},c.flush=function(){r&&(i=t.apply(s,o),s=o=null,clearTimeout(r),r=null)},c},deepEqual:function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;let r,o,s;if(Array.isArray(e)){if(r=e.length,r!=n.length)return!1;for(o=r;0!==o--;)if(!t(e[o],n[o]))return!1;return!0}if(e instanceof Map&&n instanceof Map){if(e.size!==n.size)return!1;for(o of e.entries())if(!n.has(o[0]))return!1;for(o of e.entries())if(!t(o[1],n.get(o[0])))return!1;return!0}if(e instanceof Set&&n instanceof Set){if(e.size!==n.size)return!1;for(o of e.entries())if(!n.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(n)){if(r=e.length,r!=n.length)return!1;for(o=r;0!==o--;)if(e[o]!==n[o])return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if(s=Object.keys(e),r=s.length,r!==Object.keys(n).length)return!1;for(o=r;0!==o--;)if(!Object.prototype.hasOwnProperty.call(n,s[o]))return!1;for(o=r;0!==o--;){let r=s[o];if(!("_owner"===r&&e.$$typeof||t(e[r],n[r])))return!1}return!0}return e!=e&&n!=n},deepFreeze:function t(e){return Object.freeze(e),Object.keys(e).forEach(n=>{"object"!=typeof e[n]||null===e[n]||Object.isFrozen(e[n])||t(e[n])}),e},deepMerge:Q,diffValues:(t,e)=>{const n={},r=Object.keys(e),o=r.length;for(let s=0;s<o;s++){const o=r[s];t[o]!==e[o]&&(void 0===t[o]?n[o]=e[o]:n[o]=t[o])}return 0===Object.keys(n).length?null:n},findEqualOrGreater:function(t,e,n=nt){let r=0,o=t.length-1;for(;r<=o;){let s=Math.floor((r+o)/2),i=n(t[s]);if(i===e)return s;i<e?r=s+1:o=s-1}return r},findEqualOrLesser:function(t,e,n=nt){let r=t.length-1,o=0;for(;r>=o;){let s=Math.floor((r+o)/2),i=n(t[s]);if(i===e)return s;i>e?r=s-1:o=s+1}return r},findNextStep:(t,e=!0,n=15,r=10,o=400)=>{const s=Math.max(t-r,0)+(e?1:-1);return Math.min(o,Math[e?"ceil":"floor"](s/n)*n+r)},getDPI:()=>{let t=1;return"object"==typeof window&&(t=window.devicePixelRatio||1),t},getFromPath:(t,e)=>{const n=e.split(".");let r=t;for(let t=0;t<n.length;t++){const e=n[t];if(!r)return null;let o=r[e];if("function"==typeof o&&(o=o.bind(r)()),!o||!st(o))return o;r=o}return r??null},getOS:mt,hasFocus:pt,isDefined:t=>!(null==t),isEmpty:t=>null==t||""===t,isEqualArrays:ot,isEqualBounds:(t,e)=>t===e||!(t&&!e||e&&!t)&&t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height,isEqualObjectKeys:(t,e)=>{if(t===e)return!0;if(t&&!e||e&&!t)return!1;const n=Object.keys(t);if(n.length!==Object.keys(e).length)return!1;for(let r=0;r<n.length;r++)if(t[n[r]]!==e[n[r]])return!1;return!0},isNode:ft,isNullOrUndefined:ht,isNumeric:t=>{const e=1*t;return Number.isFinite(e)&&"number"==typeof e},isObject:st,isPromiseLike:t=>!!t&&"function"==typeof t.then,isRectInsideRect:(t,e)=>t.top>=e.top&&t.bottom<=e.bottom&&t.left>=e.left&&t.right<=e.right,isRectIntersect:ut,mergeContentful:(...t)=>{const e=t.length;if(e>0&&void 0!==t[e-1]&&!st(t[e-1]))return t[e-1];let n=t[0]||{};for(let r=1;r<e;r++)n=Q(n,t[r]||{},{arrayMerge:(t,e)=>[...e]});return n},nextTick:t=>{"undefined"!=typeof window&&"function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(()=>{t()}):("function"==typeof setImmediate?setImmediate:setTimeout)(()=>{t()})},openFileDialog:(t="*.*")=>new Promise((e,n)=>{if(!dt)return void n("Unable to open dialog with no dom.");const r=document.createElement("input");r.type="file",r.accept=t;let o=null,s=!1;globalThis.addEventListener?.("focus",()=>{setTimeout(()=>{o||s||(s=!0,e(null))},1e3)},{once:!0,passive:!0}),r.onchange=()=>{if(o=r.files[0],o){if(s)return void console.warn("File open detected after faux cancel.",o);e(o)}},r.autofocus=!0,r.click()}),rafThrottle:t=>{let e,n=!1,r=function(){n=!1,t(e)};return function(t){e=t,e&&e.persist&&e.persist(),n||(n=!0,requestAnimationFrame(r))}},removeEmptyProperties:it,removeEqualValues:lt,removeListenerAll:t=>{if(!t)return[];for(let e=0;e<t.length;e++)t[e]&&t[e]();return[]},requestTimeout:(t,e)=>{const n=ct(),r={id:requestAnimationFrame(function o(){ct()-n>=e?t.call(null):r.id=requestAnimationFrame(o)})};return r},roundAccurately:(t,e=0)=>{if(null==t||!isFinite(t))return null;const n=10**e;return Number(Math.round(t*n)/n)},setToPath:(t,e,n)=>{const r=e.split(".");let o=t;if(!o)throw new Error("Can not set path to a null path.");for(let t=0;o&&t<r.length-1;t++){const e=r[t];let n=o[e];if(null==n&&(n={},o[e]=n),!st(n))throw new Error("Can not set path to a non object path.");o=n}if("number"!=typeof n&&"boolean"!=typeof n&&"string"!=typeof n&&!st(n))throw new Error(`Can not set path to ${n} that is not a a supported primitive.`);return o[r[r.length-1]]=n,t},splitNumber:t=>{let e=Math.abs(t);if(isNaN(e)||!isFinite(t))return null;let n=0|e,r=e-n,o=0,s=0,i=1;if(r>5e-8)for(;s<8&&Math.abs(o/i-r)>5e-8;)s++,i*=10,o=Math.round(r*i);return{ip:Math.trunc(t),fp:o,ipLength:Math.ceil(Math.log10(n+1)),fpLength:s}},subtractRect:(t,e,n=!1)=>{if(!e)return[t];if(!ut(t,e))return[];const r=[];let o=t;const s=()=>{e.top>o.top&&e.top<o.bottom&&(r.push({...o,bottom:e.top}),o={...o,top:e.top})},i=()=>{e.bottom>o.top&&e.bottom<o.bottom&&(r.push({...o,top:e.bottom}),o={...o,bottom:e.bottom})},a=()=>{e.right>o.left&&e.right<o.right&&(r.push({...o,left:e.right}),o={...o,right:e.right})},l=()=>{e.left>o.left&&e.left<o.right&&(r.push({...o,right:e.left}),o={...o,left:e.left})};return n?(l(),a(),s(),i()):(s(),i(),a(),l()),r},textToKey:t=>t.replace(/[^a-zA-Z0-9]/g,"").toLowerCase(),throttle:function(t,e){let n=null;return(...r)=>{const o=Date.now();(!n||o-n>=e)&&(n=o,t(...r))}},toSafeJSON:function t(e){if(null===e||"object"!=typeof e)return e;if("function"==typeof e.toJSON)return e.toJSON();if(Array.isArray(e))return e.map(e=>t(e));if("function"==typeof e.toString&&e.toString!==Object.prototype.toString)return e.toString();const n={};for(const r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n},transpose:t=>{if(!t)return t;const e=t.length,n=t[0].length,r=[];for(let t=0;t<n;t++)r[t]=Array(e);for(let o=0;o<e;o++)for(let e=0;e<n;e++)r[e][o]=t[o][e];return r},uuidV4:rt,validEnumValue:(t,e)=>{if(!Object.values(t).includes(e))throw new Error(`Invalid type: ${e??"null"}. Must be one of: ${Object.values(e).join(", ")}.`)},whenFocus:async(t,e=!1)=>new Promise(n=>{pt(t,e)?n(!0):t.addEventListener("focusin",()=>{n(!0)},{once:!0}),t.focus()})},Symbol.toStringTag,{value:"Module"})),St=Object.freeze(Object.defineProperty({__proto__:null,MESSAGE_ERROR_INVALID_ARG:t=>`Invalid argument: '${t}'.`},Symbol.toStringTag,{value:"Module"})),wt=t=>{const e=new Uint8Array(t),n=e.byteLength;let r="";for(let t=0;t<n;t++)r+=String.fromCharCode(e[t]);if("undefined"!=typeof window&&"function"==typeof globalThis.btoa)return globalThis.btoa(r);if("undefined"!=typeof Buffer)return Buffer.from(r,"binary").toString("base64");throw new Error("Unsupported environment")},yt=t=>new Promise((e,n)=>{if(t)if("undefined"!=typeof FileReader){const r=new FileReader;r.onload=()=>{e(r.result)},r.onerror=()=>{n(r.error)},r.readAsText(t)}else if("undefined"!=typeof Buffer){const r=t=>Buffer.from(t).toString("utf-8");t.arrayBuffer().then(t=>{e(r(t))}).catch(t=>{n(t)})}else n(new Error("Unsupported environment"));else e("")}),Et=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_MIME_TYPE:"*/*",arrayBufferToBase64:wt,base64ToArrayBuffer:t=>{const e="undefined"!=typeof window&&"function"==typeof globalThis.atob?globalThis.atob(t):Buffer.from(t,"base64").toString("binary"),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer},blobToString:yt},Symbol.toStringTag,{value:"Module"})),bt="data:image/png;base64,",vt="Unable to resolve image.",Ct=t=>new Promise(async(e,n)=>{let r=null;try{r=new Image,r.src=t,r.addEventListener("load",function(){e({width:r.naturalWidth,height:r.naturalHeight})},{once:!0}),r.addEventListener("error",function(){URL.revokeObjectURL(t),n("Invalid Image")},{once:!0}),await r.decode("sync")}catch(t){r?.src&&URL.revokeObjectURL(r.src)}r||n(vt)}),xt="image/svg+xml",It=Object.freeze(Object.defineProperty({__proto__:null,DATA_URL_PNG_PREFIX:bt,getImageDataUrl:(t,e=1)=>new Promise(async(n,r)=>{let o=null;try{o=new Image,o.src=t,o.addEventListener("load",function(){try{const t=document.createElement("canvas");t.width=o.naturalWidth,t.height=o.naturalHeight,t.getContext("2d").drawImage(o,0,0);const r=t.toDataURL("image/png",e);n({elemImg:o,dataUrl:r})}catch(e){URL.revokeObjectURL(t),r(e)}},{once:!0}),o.addEventListener("error",function(){URL.revokeObjectURL(t),r("Invalid Image")},{once:!0}),await o.decode("sync")}catch(t){o?.src&&URL.revokeObjectURL(o.src)}o||r(vt)}),loadImageDetails:async(t,e=null)=>{let n=null;const r=async()=>{try{const r=e??"image/*",o=URL.createObjectURL(new Blob([t],{type:r})),s=await Ct(o);n={mimeType:r,naturalDimensions:s,asUrl:o}}catch(t){}},o=async()=>{try{const r=(new TextDecoder).decode(t),o=URL.createObjectURL(new Blob([r],{type:xt})),s=await Ct(o);n={mimeType:e??xt,naturalDimensions:s,asUrl:o,asSVGText:r}}catch(t){}};if(e===xt?await o():e.startsWith("image/")?await r():(await r(),n||await o()),!n)throw new Error("Failed to load image");return n}},Symbol.toStringTag,{value:"Module"}));function At(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});let n="boolean"==typeof e.cycles&&e.cycles;const r=e.cmp&&function(t){return function(e){return function(n,r){const o={key:n,value:e[n]},s={key:r,value:e[r]};return t(o,s)}}}(e.cmp);let o=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0===e)return;if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);let s;if(Array.isArray(e)){s="[";for(let n=0;n<e.length;n++)n&&(s+=","),s+=t(e[n])||"null";return s+"]"}if(null===e)return"null";if(-1!==o.indexOf(e)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const i=o.push(e)-1,a=Object.keys(e).sort(r&&r(e));s="";for(let n=0;n<a.length;n++){const r=a[n],o=t(e[r]);o&&(s&&(s+=","),s+=JSON.stringify(r)+":"+o)}return o.splice(i,1),"{"+s+"}"}(t)}class Rt{constructor(){this._resolve=null,this._result=void 0,this._handled=null,this._reject=null,this._error=void 0,this._promise=null,this._promise=new Promise((t,e)=>{this._resolve=t,this._reject=e,"resolve"===this._handled?t(this._result):"reject"===this._handled&&e(this._error)})}resolve(t){this._resolve?this._resolve(t):this._handled||(this._result=t),this._handled="resolve"}reject(t){this._reject?this._reject(t):this._handled||(this._error=t),this._handled="reject"}async wait(){await this._promise}}var Mt,Tt;(Tt=Mt||(Mt={})).resolveTypedUpdates=(t,e,n,r)=>{if(null===t)return t;if(void 0===t)return r;let o=t;if(e?.shorthand){const r=e?.shorthand(t,n);void 0!==r&&(o=r)}if(null!==o&&e?.getSubType){const t=e.getSubType(o);t&&(e=t)}const s=e?.properties,i=e?.arrayType??!1;let a=o;if(e&&e.merge&&a&&r)a=e.merge(a,r,n);else if(i);else if(s){const t=Object.keys({...o,...r});a=null;for(let e=0;e<t.length;e++){const i=t[e];let l,c=o[i];if(void 0!==c){const t=s[i];l=t?(0,Tt.resolveTypedUpdates)(c,t,n,r?.[i]):c}else l=r?.[i];null!=l&&(a=a??{},a[i]=l)}}return a};class Nt extends Error{constructor(t,e=null){super(t,e),this.name="ChainedError",this._cause=e}get cause(){return this._cause}}class Ft extends Nt{constructor(t="Partial Error",e=null){super(t,e)}}class kt extends Ft{constructor(t="Out of bounds",e=null){super(t,e),this.name="OutOfBoundsError"}}class Ot extends Nt{constructor(t="Partial Error",e=null){super(t,e)}}class Lt extends Nt{constructor(t="Null not supported",e=null){super(t,e)}}class Dt extends Error{constructor(t="Null not supported",e){super(t),this._type=e}get type(){return this._type}}class Bt extends Nt{constructor(t="Not implemented",e=null){super(t,e)}}const zt="The Safari browser does not support advanced copy and paste.\nCopy and paste will be limited to within the browser tab.\n\nPlease use Chrome or Edge if external copy and paste is required.",Pt="You do not have permissions to access the clipboard.\nAll copy and paste operations will be limited to the browser tab.",jt={Safari:"The Safari browser does not support advanced copy and paste.\nCopy and paste will be limited to within the browser tab.\n\nPlease use Chrome or Edge if external copy and paste is required.",Perms:Pt,PermsWrite:mt()===gt.Safari?zt:Pt,PermsRead:mt()===gt.Safari?zt:Pt},Ht=async()=>new Promise(t=>{document.hasFocus()?t():globalThis.addEventListener?.("focus",()=>{t()},{once:!0}),document.activeElement.focus?.()}),Vt=async(t,e,n)=>{if(mt()===gt.Safari)return await n(new Error(jt.Safari));try{const r=async t=>{try{return await t()}catch(t){if(t.message?.includes("Document is not focused"))return!1;throw t}},o=await(globalThis?.navigator?.permissions?.query({name:t,allowWithoutGesture:!0,allowWithoutSanitization:!0}));let s=!1;if("prompt"===o.state&&(s=await r(e)),s||"granted"!==o.state||(s=await e()),!s)return await n(new Error(o.state))}catch(t){if("No valid data on clipboard"===t.message||"DataError"===t.name)return;return await n(t)}},$t=async t=>{try{return await t.read({unsanitized:[E.html]})}catch(t){}return await t.read()},Ut=async(t,e)=>{if(!t)return null;const n=await $t(t);let r=!1;for(let t=0;!r&&n&&t<n.length;t++)if(r=n[t].types.includes(e),r)return await n[t].getType(e);return r?void 0:null};if(!globalThis.ClipboardItem){const t=(t,e)=>new Blob([e],{type:t});class e{constructor(e,n){this._items={},this._types=Object.keys(e);const r={},o=Object.keys(e);for(let n=0;n<o.length;n++){const s=o[n];let i=e[s];r[s]="string"==typeof i?t(s,i):i}this._items=r,this._presentationStyle=n?.presentationStyle??"unspecified"}get types(){return this._types}getType(t){return Promise.resolve(this._items[t])}supports(t){return!0}}globalThis.ClipboardItem=e}const Gt=async(t,e=E.html)=>new Promise(async(n,r)=>{try{const r=await Ut(t,e);if(r){const t=new FileReader;t.onload=()=>{n(t.result)},t.onerror=()=>{n("")},t.readAsText(r)}else n("")}catch(t){r(t)}}),Wt=async(t,e=E.html)=>{const n=await Gt(t,e);if(!n)return null;let r=null;try{r=(new DOMParser).parseFromString(n,E.html)}catch(t){console.warn("Can't parse html from clipboard.")}return r},qt=async t=>{t&&await t.writeText("")},Jt={readBlobFromClipboard:Ut,readStringFromClipboard:Gt,readHTMLFromClipboard:Wt,clearClipboard:qt},Xt="clipboard-uuid",Kt="web text/uuid",Yt=t=>`<div style="display:none" ${Xt}="${t}"/>`,Zt=(t,e)=>{let n=null;try{const r=(new DOMParser).parseFromString(e,E.html);r.body.firstElementChild.setAttribute(Xt,t),n=r.getElementsByTagName("body")[0].innerHTML}catch(t){console.warn("Can't embed uuid.",t)}return n},Qt=(t,e)=>{if(!e||!t)return!1;try{const n=e.querySelectorAll(`[${Xt}="${t}"]`);if(n&&1===n.length)return!0;if(e.querySelector("parsererror"))throw new Error("We are unable to parse node");return!1}catch(t){return!1}};class te{constructor(t){if(void 0===t?.nativeClipboard||!0===t?.nativeClipboard)try{this._nativeClipboard=globalThis?.navigator.clipboard}catch(e){!0===t?.nativeClipboard&&console.warn("NativeClipboard option set to true but no native clipboard available.")}else this._nativeClipboard=!1===t?.nativeClipboard?null:t?.nativeClipboard;this._disableCheckOnFocus=t?.disableCheckOnFocus??!1,this._init()}async _checkForChanges(){this._nativeClipboard&&this._state&&!this._disableCheckOnFocus&&await Vt("clipboard-read",async()=>{await Ht();const t=await Gt(this._nativeClipboard,Kt);if(!this._state)return!0;if(t&&t===this._state.uuid)return!0;const e=await Wt(this._nativeClipboard,E.html);return!this._state||(Qt(this._state.uuid,e)||this.clear(),!0)},async t=>{"denied"===t?.message||t.message?.includes("Document is not focused")||mt()===gt.Safari||console.warn("Unable to detect clipboard changes: ",t)})}_init(){const t=this;this._listeners=new Map,this._listenersCapture=new Map,this._state=null,this._nativeClipboard&&(this._onFocus=()=>{t._checkForChanges()},this._onBlur=()=>{globalThis.addEventListener?.("focus",t._onFocus,{once:!0})},globalThis.addEventListener?.("blur",this._onBlur),this._nativeClipboard.addEventListener("clipboardchange",e=>{t._checkForChanges()}))}async read(){if(!this._nativeClipboard)return this._state?.items??null;const t=this;return await Vt("clipboard-read",async()=>{if(await Ht(),this._state?.uuid){const e=await Gt(this._nativeClipboard,Kt);if(e&&e===t._state.uuid)return!0;const n=await Wt(this._nativeClipboard,E.html);if(Qt(t._state?.uuid,n))return!0}return t._state={items:await $t(this._nativeClipboard),uuid:null,ref:null},this.dispatchEvent(new Event("clipboardread")),!0},async t=>{this.dispatchEvent(new Event("clipboarderrorread"))}),this._state?.items??[]}async write(t){return this._write({uuid:rt(),items:t,ref:null})}async _write(t){if(!this._nativeClipboard)return this._state=t,this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")),null;const e=this,n=[],r=t.uuid;let o=t.items??[];const s=()=>{e._state={uuid:r,ref:t.ref,items:n},e.dispatchEvent(new Event("clipboardwrite")),e.dispatchEvent(new Event("clipboardchange"))};await Vt("clipboard-write",async()=>{await Ht(),r&&0===o.length&&(o.push(new ClipboardItem({[Kt]:new Blob([r],{type:Kt})})),o.push(new ClipboardItem({[E.html]:new Blob([Yt(r)],{type:E.html})})));for(let t=0;t<Math.min(1,o.length);t++){const e=o[t];let s=e.types.indexOf(E.html),i=null;if(-1!==s){const t=await e.getType(E.html);i=await yt(t),i&&(i=Zt(r,i))}if(!i&&e.types.includes(E.plain)){const t=await e.getType(E.plain);if(t){let e=null;"string"==typeof t?(console.warn("text as string",t),e=t):e=await yt(t),e&&(i=`<div ${Xt}="${r}">${e}</div>`)}}if(!i&&e.types.includes(E.png)){const t=await e.getType(E.png),n=wt(await t.arrayBuffer());i=`<div ${Xt}="${r}"><img src="${bt+n}"/></div>`}!i&&r&&(i=Yt(r));const a=new Blob([i??""],{type:E.html}),l={};for(let t=0;t<e.types.length;t++){const n=e.types[t];l[n]=t===s?a:e.getType(n)}i&&-1===s&&(l[E.html]=a),r&&(l[Kt]=new Blob([r],{type:Kt})),n.push(new ClipboardItem(l))}try{n&&0!==n.length?await this._nativeClipboard.write(n):await qt(this._nativeClipboard)}catch(t){t.message?.includes("Document is not focused")||console.warn("Unable to write to native clipboard: ",t)}return s(),!0},async t=>{this.dispatchEvent(new Event("clipboarderrorwrite")),s()})}async writeReference(t){if(!t)return void this.clear();let e=null;const n={};try{const e=await(t.toText?.())??null;e&&(n[E.plain]=new Blob([e??""],{type:E.plain}))}catch(t){e=t}try{const e=await(t.toHtml?.())??null;e&&(n[E.html]=new Blob([e],{type:E.html}))}catch(t){e=t,console.warn("export to html",t)}try{const e=await(t.toImage?.())??null;e&&(n[E.png]=e)}catch(t){e=t,console.warn("export to png",t)}const r=this._write({uuid:rt(),ref:t,items:Object.keys(n).length>0?[new ClipboardItem(n)]:null});if(e)throw e;return r}clear(t=!1){this._state&&(this._state=null,t&&this._write({uuid:null,ref:null,items:null}),this.dispatchEvent(new Event("clipboardwrite")),this.dispatchEvent(new Event("clipboardchange")))}async readReference(){return await this.read(),this._state?.ref??null}readText(){return new Promise(async(t,e)=>{const n=await this.read();let r=null;for(let t=0;!r&&n&&t<n.length;t++)n[t].types.includes(E.plain)&&(r=await n[t].getType(E.plain));if(!r)return void t("");const o=new FileReader;o.onload=()=>{t(o.result)},o.readAsText(r),o.onerror=t=>{e(t)}})}async writeText(t){const e=[new ClipboardItem({[E.plain]:new Blob([t],{type:E.plain})})];return this._write({uuid:rt(),items:e,ref:null})}addEventListener(t,e,n={}){const r=n?.capture?this._listenersCapture:this._listeners;let o=r.get(t);o||(o=new Map,r.set(t,o)),o.set(e,"boolean"==typeof n?{}:n)}dispatchEvent(t){if(!t)return;const e=e=>{const n=e.get(t.type);n&&n.forEach((e,r)=>{try{"function"==typeof r?r(t):r.handleEvent&&r.handleEvent(t),e.once&&n.delete(r)}catch(t){console.warn(t)}})};return e(this._listenersCapture),e(this._listeners),!0}removeEventListener(t,e,n){const r=n?.capture?this._listenersCapture:this._listeners,o=r.get(t);o&&(o.delete(e),0===o.size&&r.delete(t))}close(){globalThis.removeEventListener?.("focus",this._onFocus),globalThis.removeEventListener?.("blur",this._onBlur)}}var ee;(ee=te||(te={})).ErrorMessages=jt,ee.Global=new ee;class ne{constructor(t=100){this._maxStack=t,this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._listeners=new Set}get maxStack(){return this._maxStack}undo(t=1){if(0===this._undoStack.length)return;let e=!1;try{for(let n=0;n<t&&this._undoStack.length>0;n++){const t=this._undoStack[this._undoStack.length-1];t.redo=t.undo(),this._undoStack.pop(),"function"==typeof t.redo?this._redoStack.push(t):this._redoStack=[],e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}redo(t=1){if(0===this._redoStack.length)return void(null!==this._repeatOperation&&this._repeatOperation.repeat());let e=!1;try{for(let n=0;n<t&&this._redoStack.length>0;n++){const t=this._redoStack[this._redoStack.length-1];t.redo(),this._redoStack.pop(),this._undoStack.push(t),e=!0}}catch(t){throw t}finally{e&&this._notifyOnStackChange()}}hasUndo(){return this._undoStack.length>0}getTopUndoDescription(){return 0===this._undoStack.length?null:this._undoStack[this._undoStack.length-1].description}hasRedo(){return this._redoStack.length>0||null!==this._repeatOperation}getTopRedoDescription(){return null!==this._repeatOperation?this._repeatOperation.description:0===this._redoStack.length?null:this._redoStack[this._redoStack.length-1].description}getUndoDescriptions(){if(this._undoDescriptions)return this._undoDescriptions;const t=[];for(let e=this._undoStack.length-1;e>=0;e--)t.push(this._undoStack[e].description);return this._undoDescriptions=t,this._undoDescriptions}getRedoDescriptions(){if(this._redoDescriptions)return this._redoDescriptions;const t=[];for(let e=this._redoStack.length-1;e>=0;e--)t.push(this._redoStack[e].description);return 0===t.length&&null!==this._repeatOperation&&t.push(this._repeatOperation.description),this._redoDescriptions=Object.freeze(t),this._redoDescriptions}addUndoOperation(t){const e={description:t.description,undo:t.undo,redo:null};this._undoStack.push(e),this._redoStack=[],this._undoStack.length>this._maxStack&&this._undoStack.shift(),this._notifyOnStackChange()}setRepeatableOperation(t){this._repeatOperation=t??null,this._redoStack=[],this._notifyOnStackChange()}clear(t=!0){this._undoStack=[],this._redoStack=[],this._repeatOperation=null,this._undoDescriptions=null,this._redoDescriptions=null,t&&this._notifyOnStackChange()}addListener(t){const e=this._listeners;return e.add(t),()=>{e.delete(t)}}_notifyOnStackChange(){this._undoDescriptions=null,this._redoDescriptions=null,this._listeners.forEach(t=>{t.onStackChange?.()})}}const re=(t,e)=>{const n=new Map;return t.forEach((t,r)=>{e.get(r)!==t&&n.set(r,t)}),n};let oe=!1;class se{constructor(t){this._record=t}getId(){return this._record.id}getDescription(){return this._record.description}getMeta(){return Object.freeze(this._record.meta)}getAuthor(){return this._record.author}getTimestamp(){return this._record.timestamp}getOperation(){return this._record.operation}}class ie{constructor(t){this._listeners=new Set,this._listenersState=new Map,this._commits=new Map,this._locked=!1,this._current=null,this._pending=null,this._isSync=t?.sync??oe,this._isTransient=t?.transient??!1,this._author=t?.author;const e={id:"0",description:"initial",meta:{},author:this._author,timestamp:Date.now(),states:new Map,version:0,previousId:null},n={record:e,commit:new se(e)};this._current=n,this._cacheModel=null,this._cacheState=null,this._states=e.states,this._transactionStack=[],this._transactionOpen=!1;const r=new Map;r.set(e.id,n),this._commits=r}static{this.setDefaultSync=t=>{oe=t}}getLog(t,e=100){const n=[];let r=t;do{const t=this._commits.get(r);if(!t)throw new Error(`Invalid commit id: '${r}'`);if(n.push(t.commit),r=t.record.previousId,!r)return n}while(n.length<e)}getCommitCount(){return this._commits.size}isOpenTransaction(){return this._transactionStack.length>0||this._transactionOpen}getPendingView(){const t=this._transactionStack;return t.length>0?t[0].getView():null}getState(t){const e=this._transactionStack;if(0===e.length){if(this._cacheModel===t)return this._cacheState;const e=this._states.get(t);return this._cacheModel=t,this._cacheState=e,e}return e[e.length-1].getState(t)}getCurrentCommit(){return this._pending?.commit??this._current.commit}restore(t,e){const n=this._getCommitContainer(t,e);if(this._current.commit.getId()===n.commit.getId())return n.commit;let r;e?.viewId&&"custom"!==e?.viewId||(r=n.record.viewAfter);const o=re(n.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,o,r,!0,!1),this._current=n,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",n,o,r,!1,!0,!0),this._notify("onCommitChange",n.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",n,n.record.states,r,!1,!0)}finally{this._transactionOpen=!1}return n.commit}revert(t,e){const n=this._getCommitContainer(t,e),r=this._commits.get(n.record.previousId);if(!r)throw new Error(`Invalid commit id: '${n.record.previousId}'`);let o;e?.viewId&&" custom"!==e?.viewId||(o=n.record.viewBefore??n.record.viewAfter);const s=re(r.record.states,this._current.record.states);this._notifyStates("onBeforeCommitStart",this._current,s,o,!0,!1),this._current=r,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,this._notifyStates("onAfterStateChange",r,s,o,!0,!1,!0),this._notify("onCommitChange",r.commit,!0),this._transactionOpen=!0;try{this._notifyStates("onRestoreOrRevert",r,r.record.states,o,!0,!0)}finally{this._transactionOpen=!1}return r.commit}_getCommitContainer(t,e){const n=this._commits.get(t);if(!n)throw new Error(`Invalid commit id: '${t}'`);if(this._isTransient)throw new Error("Cannot revert transient store");if(e?.force&&this._transactionStack.length>0&&this._transactionStack[0].rollback(),0!==this._transactionStack.length)throw new Error("Open transactions.");return n}_pruneForwards(t){}beginCommit(t,e){const n=this._transactionStack,r=n.length;if(this._locked)throw console.warn("TransactionStore locked",n),new Error(`TransactionStore is locked by '${n[r-1].getDescription()}`);const o=t?.preventFurtherTransactions,s=this,i=(t,n,i)=>{const a=s._transactionStack;r!==a.length-1&&console.warn("Transaction stack out of sync",r,a.length,a),o&&(this._locked=!1),a.pop(),e?.(t,n,i),0===a.length&&(s._pending=null)};let a;if(0===n.length){const e=this._current.record,n={states:new Map,id:_t.uuidV4(),description:"string"==typeof t?t:t?.description??null,meta:{},timestamp:Date.now(),author:null,version:e.version+1,previousId:e.id,viewBefore:null,viewAfter:{},operation:t?.operation},r={record:n,commit:new se(n)};this._pending=r,this._notify("onCommitStart",r.commit),a=new le(this,r,e?.states,t,i)}else{a=n[n.length-1].beginTransaction(t,i)}return o&&(this._locked=!0),this._transactionStack.push(a),a}doBatch(t,e,n){let r;const o=this.beginCommit(e,n),s=this.getCurrentCommit();try{r=t?.(s);const n=()=>{o.commit(e)};if(!!r&&"function"==typeof r.then)return new Promise((t,e)=>{r.then(r=>{try{n(),t(r)}catch(t){e(t)}}).catch(t=>{o.rollback(),e(t)})});n()}catch(t){throw o.rollback(),t}return r}remove(t){return!!t}addListener(t){const e=this._listeners;return e.add(t),()=>{e.delete(t)}}addStateListener(t,e){if(!t)throw new Error("Model is required");if(!e)throw new Error("Listener is required");let n=this._listenersState.get(t);n||(n=new Set,this._listenersState.set(t,n));return n.add(e),()=>{n.delete(e),0===n.size&&this._listenersState.delete(t)}}dispatchEvents(t,e=!1){!e||this._isSync?t():setTimeout(t,0)}_commitRecord(t,e,n){let r=t.record,o=t.commit;if(!this._isTransient){if(n){const e=this._commits.get(r.previousId);if(e){r.previousId=e.record.id;const n=e.record,s=n.states;if(s){r.states.forEach((t,e)=>{s.set(e,t)})}n.viewAfter={...n.viewAfter,...r.viewAfter},n.meta={...n.meta,...r.meta},n.timestamp=r.timestamp,r=n,o=e.commit,t={record:r,commit:o}}}this._commits.set(r.id,t)}this._current=t,this._states=this._current.record.states,this._cacheModel=null,this._cacheState=null,n||this._notify("onCommitChange",o),this._notifyStates("onAfterStateChange",t,e,t.record.viewAfter,!1,!1,!0),n||this._notify("onCommitEnd",o,!0)}_notifyStates(t,e,n,r,o=!1,s=!1,i=!1){const a=e.commit,l=this._listenersState;n.forEach((e,n)=>{const c=l.get(n);c&&this.dispatchEvents(()=>{c.forEach(n=>{n[t]?.(e,r,a,o,s)})},i)})}_notify(t,e,n=!1){this.dispatchEvents(()=>{this._listeners.forEach(n=>{n[t]?.(e)})},n)}}class ae{constructor(t,e){this._children=new Set,this._depth=0,this._container=null,this._closed=!1,this._container=t,e="string"==typeof e?{description:e}:e,this._description=e?.description??"",void 0!==e?.viewBefore&&(t.record.viewBefore=t.record.viewBefore&&e.viewBefore?{...t.record.viewBefore,...e.viewBefore}:e.viewBefore),void 0!==e?.viewAfter&&(t.record.viewAfter=t.record.viewAfter&&e.viewAfter?{...t.record.viewAfter,...e.viewAfter}:e.viewAfter)}getView(){return this._container.record.viewAfter??this._container.record.viewBefore}getDepth(){return this._depth}getDescription(){return this._description}getStates(){return this._states}beginTransaction(t,e){this._ensureOpen();const n=new ce(this,this._container,"string"==typeof t?{description:t}:t,e);return this._children||this._children,this._children.add(n),n}updateState(t,e){this._ensureOpen();const n=this.getState(t),r="function"==typeof e?e(n):void 0===e?n:{...n,...e};if(r){let e=this._states;e||(e=new Map,this._states=e),e.set(t,r)}return r}commit(t){if(this._ensureOpen(),"string"==typeof t&&(t={description:t}),t){if(t.description&&(this._description=t.description),t.meta&&(this._meta=_t.mergeContentful(t.meta,this._meta)),void 0!==t.viewAfter){const e=this._container.record;let n=t.viewAfter;if(null===n)e.viewAfter=null;else{const t=e.viewAfter;"function"==typeof n&&(n=n(t)),e.viewAfter={...t,...n}}}if(void 0!==t.viewBefore){const e=this._container.record;let n=t.viewBefore;if(null===n)e.viewAfter=null;else{const t=e.viewBefore;"function"==typeof n&&(n=n(t)),e.viewBefore={...t,...n}}}}return this._children&&this._children.forEach(e=>{e.commit(t)}),this}isClose(){return this._closed}_ensureOpen(){if(this._closed)throw this._descriptions&&console.warn(`stack: [${this._descriptions.join(",")}]`),new Error("Transaction already closed")}_removeChild(t){this._children.delete(t),this._mergeStates(t._states)}_mergeStates(t){if(!t||0===t.size)return;let e=this._states;return e?(t.forEach((t,n)=>{const r=this.updateState(n,t);e.set(n,r)}),e):(this._states=t,t)}}class le extends ae{constructor(t,e,n,r,o){super(e,r),this._store=t,this._prevStates=n,this._onClose=o,this._states=new Map,this._meta=e.record.meta}getId(){return this._container.commit.getId()}getParent(){return this}commit(t){const e=this._states,n=this._container,r=n.record.viewAfter;this._store._notifyStates("onBeforeCommitStart",n,e,r,!1,!1),super.commit(t),this._store._notifyStates("onBeforeCommitEnd",n,e,r,!1,!1);const o=new Map(this._prevStates);return this._states.forEach((t,e)=>{null===t?o.delete(e):o.set(e,t)}),this._states=o,this._description&&(n.record.description=this._description),this._meta&&(n.record.meta=this._meta),n.record.states=o,this._closed=!0,this._onClose?.(this,!1,t),this._store._commitRecord(n,e,t?.forceAmend??!1),this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(t=>{t.rollback()}),this._closed=!0,this._onClose?.(this,!0,null),this}updateState(t,e){const n=super.updateState(t,e);return this._states.set(t,n),n}getState(t){let e=this._states.get(t);return e||(e=this._prevStates.get(t)),e}_mergeStates(t){if(!t||0===t.size)return new Map;return super._mergeStates(t)}}class ce extends ae{constructor(t,e,n,r){if(super(e,n),!t)throw new Error("Parent transaction required");this._parent=t,this._depth=this._parent.getDepth()+1,this._onClose=r}getId(){return this._parent.getId()}getParent(){return this._parent}getState(t){const e=this._states?this._states.get(t):void 0;if(void 0!==e)return e;return this._parent.getState(t)}commit(t){return super.commit(t),this._parent._removeChild(this),this._closed=!0,this._onClose?.(this,!1,t),this._parent??this}rollback(){return this._ensureOpen(),this._children&&this._children.forEach(t=>{t.rollback()}),this._parent._removeChild(this),this._closed=!0,this._onClose?.(this,!0,null),this._parent??this}}class he extends ne{constructor(t,e=50){super(e),this._transactions=t;const n=this;t?.addListener({onCommitEnd:e=>{e.getDescription()&&n.addUndoOperation({description:e.getDescription(),undo:()=>(t.revert(e.getId()),()=>{t.restore(e.getId())})})}})}clear(){super.clear()}close(){this._removeLister()}}const ue=()=>{try{return"0.4.12"}catch(t){return""}},de=()=>{try{return"Fri Aug 08 2025"}catch(t){return""}},ge=`\n https://www.sheetxl.com ${ue()}`,me="#1976d2",fe=async()=>"0",pe=()=>"object"==typeof window?window.location.hostname:_t.getOS(),_e=()=>"object"==typeof window?window.location.hostname:_t.getOS(),Se=()=>_e().endsWith("localhost")||"127.0.0.1"===_e(),we=(t,e,n=126)=>((t,e,n=126)=>{let r=t.split("");for(let t=0;t<r.length;t++)r[t].charCodeAt(0)<=n&&(r[t]=String.fromCharCode((r[t].charCodeAt(0)+e)%n));return r.join("")})(t,n-e),ye=t=>{let e=t;const n=e[e.length-1],r=n.charCodeAt(0)-52;if(e=e.substring(0,e.length-1),e=e.split("").reverse().join(""),e=(t=>"object"==typeof window?window.atob(t):Buffer.from(t,"base64").toString("ascii"))(e),e=e.trim(),e[e.length-1]!==n)throw new Error;e=e.substring(0,e.length-1),e=we(e,r);try{e.startsWith("{")||(e="{"+e);const t=JSON.parse(e),n={licensee:t.l,domains:t.d,nodeId:t.n,expiry:t.e,developerCount:t.dc,cpuCount:t.cc,type:t.t};return t.f&&(n.features=t.f),n}catch(t){throw new Error("Invalid license key.")}},Ee=t=>{const e=de(),n=new Date(e),r=new Date,o=Math.floor((r.getTime()-n.getTime())/864e5)>=120;return{licensee:()=>"Evaluation License",expiration:()=>null,domains:()=>[_e()],developerCount:()=>1,cpuCount:()=>0,type:()=>"eval",isEval:()=>!0,exceptions:()=>o?["Evaluation period expired"]:[],isValidFor:()=>!o,isValid:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>t,getBuildVersion:ue,getBuildDate:de}},be={promise:null,details:null,bannerPrinted:!1,detailsPrinted:!1,licenseKey:null,keyFrom:null};let ve=!1,Ce=!1;const xe="cil.lxteehs".split("").reduce((t,e)=>e+t,"");const Ie=new class{constructor(){this.__proto__.valueFv=null}async setLicenseKey(t,e=!1){if(!t||t.startsWith("visit ")||t.startsWith("email ")||t.startsWith("trial")||t.startsWith("eval"))return ve=!0,await this._validate(!0);if(ve=!1,!e&&be.licenseKey){const t=await this._validate();if(t.isValid()&&!t.isEval())return t}be.licenseKey=t,be.keyFrom="setLicenseKey",be.details=null,be.promise=null;const n=await this._validate();if(!n.isValid())throw await this._print(!0),new Error("Invalid license key.");if(_t.isNode()){await(async()=>{throw new Error("setKey is not implemented in browser environment")})(0,e);if(!(await this._validate()).isValid())throw await this._print(!0),new Error("Invalid license key.")}return n}async _validate(t=!1){if(be.promise)return be.promise;if(this.__proto__.valueFv||(this.__proto__.valueFv=new Error("FV")),be.promise)return be.promise;let e=null;be.promise=new Promise(t=>{e=t});let n,r=null;const o=async(t,e)=>{try{const r=ye(e),o=await(async t=>{const e=t.domains,n=t.expiry?new Date(t.expiry):null,r=t.nodeId,o=[];if(n?isNaN(n)?o.push("Invalid expiration"):n<new Date&&o.push(`License expired on ${n.toLocaleDateString()}`):o.push("No expiration"),_t.isNode()){if(!r)return o.push("License not valid for Node.js"),o;const t=await fe();t!==r&&o.push(`Invalid nodeId: ${r} does not match ${t}`)}else{if(Se())return o;if(e&&0!==e.length){let t=!1;const n=_e();for(let r=0;!t&&r<e.length;r++)t=n.endsWith(e[r]);t||o.push("Invalid domain")}else o.push("No domains specified")}return o})(r),s=((t,e,n)=>({licensee:()=>t.licensee,expiration:()=>new Date(t.expiry),domains:()=>t.domains??[],developerCount:()=>t.developerCount??1,cpuCount:()=>t.cpuCount??0,type:()=>t.type??"Community",exceptions:()=>e,isValidFor:t=>!(e?.length>0),isValid:()=>!0,isEval:()=>!1,features:()=>Object.freeze(t.features??{}),keyFrom:()=>n,getBuildVersion:ue,getBuildDate:de}))(r,o,t);return s.exceptions().length>0&&(n=s),s}catch(e){r=t,n={licensee:()=>null,expiration:()=>null,domains:()=>[],developerCount:()=>0,cpuCount:()=>0,type:()=>"invalid",exceptions:()=>[`Invalid License key using '${r}'`],isValidFor:t=>!1,isValid:()=>!1,isEval:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>r,getBuildVersion:ue,getBuildDate:de}}var r};be.licenseKey&&(r=await o(be.keyFrom,be.licenseKey));let s=!1;if(ve&&(s=!0,r=Ee("Eval License Key")),!r){if(_t.isNode()){if(!r){const t=process.env,e=t.SHEETXL_LICENSE_KEY||t.SHEETXL||t.sheetxl||t.sheetxl_license_key;e&&(r=await o("envVar",e))}if(!r){const t=await(async()=>{throw new Error("getKey is not implemented in browser environment")})();t&&(r=await o("configStore",t))}r||(s=!0)}else{if(!r)try{const t=await fetch(`./${xe}`);let e=null;if(200===t.status){const n=(await t.text()).split("\n");for(let t=0;!e&&t<n.length;t++){const r=n[t].trim();r.startsWith("#")||0===r.length||(e=r)}}if(e){const t=`fetch('./${xe}')`;r=await o(t,e)}}catch(t){}!r&&Se()&&(s=!0)}}if(!r&&s&&(r=Ee("No License Key")),!r&&n&&(r=n),r||(r={licensee:()=>null,expiration:()=>null,domains:()=>[],developerCount:()=>0,cpuCount:()=>0,type:()=>null,isEval:()=>!1,exceptions:()=>["No license provided"],isValidFor:t=>!1,isValid:()=>!1,features:()=>Object.freeze({}),keyFrom:()=>"No key",getBuildVersion:ue,getBuildDate:de}),be.details=r,e(r),t){if(!(be.bannerPrinted&&be.detailsPrinted)&&(s||r.exceptions().length>0||r.features()?.pb)){if(Ce)return void setTimeout(()=>{this._print(!1,!1)},8e3);await this._print(!1,!1)}}return be.details}async _printBanner(t){be.bannerPrinted=!0;const e=await this.getDetails();return await(async t=>{const e=t?console.log:_t.consoleWithNoSource,n=`%c\n███████╗██╗ ██╗███████╗███████╗████████╗ ██╗ ██╗██╗\n██╔════╝██║ ██║██╔════╝██╔════╝╚══██╔══╝ ╚██╗██╔╝██║\n███████╗███████║█████╗ █████╗ ██║ ╚███╔╝ ██║\n╚════██║██╔══██║██╔══╝ ██╔══╝ ██║ ██╔██╗ ██║\n███████║██║ ██║███████╗███████╗ ██║ ██╔╝ ██╗███████╗\n╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝${ge}\n `;return await e(`${n}`,`font-family:monospace;color:${me};font-size:12px;`),Promise.resolve()})(t),!be.detailsPrinted&&(e.isEval()||e.exceptions().length>0)&&await this._printDetails(t),Promise.resolve()}async _printDetails(t=!1,e=!1,n=!1){be.detailsPrinted=!0;const r=await this.getDetails();be.bannerPrinted||!(r.isEval()||r.exceptions().length>0)?await(async(t,e=!1,n=!1,r=!1)=>{let o;const s=console.log,i=[`color:${me};font-size:12px`];if(t.isEval()?(i.push(`font-family:monospace;color:${me};font-size:12px;`),o="%cEvaluation Only",i[0]="color:#E12929;font-size:12px",o+="%c\nPlease visit https://my.sheetxl.com to register."):(o=`%cLicensee: ${t.licensee()??"Invalid License"}\n`,o+=`Expires: ${t.expiration()?.toLocaleDateString()??"Never"}`,t.domains()&&t.domains().length>0&&(o+=`\nDomains: ${t.domains().join(", ")}`),t.cpuCount()>0&&(o+=`\nCpus: ${t.cpuCount()}`)),!r&&t.exceptions().length>0){i.push("color:red;font-size:12px"),o+="\nExceptions:\n%c";for(let e=0;e<t.exceptions().length;e++)o+=` ${t.exceptions()[e]}`}return n&&(i.push("color:#FFA726;font-size:12px"),o+="%c",o+=`\nLocation: '${pe()}'`,o+=`\nKeyFrom: '${t.keyFrom()}'`),await s(`${o}`,...i),Promise.resolve()})(r,t,e,n):await this._printBanner(t)}async _print(t,e){if(!t&&(be.bannerPrinted||be.detailsPrinted))return;be.bannerPrinted=!0,be.detailsPrinted=!0,await this._printBanner(t);const n=_t.isNode(),r=t||n?console.log:_t.consoleWithNoSource;n&&r(""),await this._printDetails(t,e),r("")}getDetails(){return this._validate()}print(t){return this._print(!0,t)}wasPrinted(){return be.bannerPrinted||be.detailsPrinted}suppressPrint(t){Ce=!0}async printBanner(){return this._printBanner(!0)}async printDetails(t,e){const n=await this.getDetails();return await this._printDetails(!0,t,e),n}async getNodeId(){return await fe()}},Ae=(t,e)=>{const n=[];for(let r=0;r<t.length;r++){const o=t[r];n.push({x:o.x+e.x,y:o.y+e.y})}return n},Re=(t,e)=>{if(!t)return{...e};if(!e)return{...t};let n=Math.min(t.x,e.x),r=Math.min(t.y,e.y);return{x:n,y:r,width:Math.max(t.width+t.x,e.width+e.x)-n,height:Math.max(t.height+t.y,e.height+e.y)-r}},Me=t=>[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],Te=t=>{let e=Number.MAX_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,r=Number.MIN_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER;for(let s=0;s<t.length;s++){let i=t[s];e=Math.min(e,i.x),n=Math.min(n,i.y),r=Math.max(r,i.x),o=Math.max(o,i.y)}return{x:e,y:n,width:r-e,height:o-n}},Ne=(t,e,n)=>{if(!n){const e=Te(t);n={x:e.x+e.width/2,y:e.y+e.height/2}}t=Ae(t,{x:-n.x,y:-n.y});const r=e*Math.PI/180,o=Math.sin(r),s=Math.cos(r),i=[];for(let e=0;e<t.length;e++){const n=t[e],r=s*n.x-o*n.y,a=o*n.x+s*n.y;i.push({x:r,y:a})}return t=Ae(i,{x:n.x,y:n.y})},Fe=(t,e,n,r,o,s,i,a,l=!0)=>{if(t===n&&e===r||o===i&&s===a)return!1;let c=(a-s)*(n-t)-(i-o)*(r-e);if(0===c)return!1;let h=((i-o)*(e-s)-(a-s)*(t-o))/c,u=((n-t)*(e-s)-(r-e)*(t-o))/c;return(!l||!(h<0||h>1||u<0||u>1))&&{x:t+h*(n-t),y:e+h*(r-e)}},ke=(t,e,n=!0)=>Fe(t.p1.x,t.p1.y,t.p2.x,t.p2.y,e.p1.x,e.p1.y,e.p2.x,e.p2.y,n),Oe=t=>({top:{p1:t[0],p2:t[1]},left:{p1:t[3],p2:t[0]},right:{p1:t[1],p2:t[2]},bottom:{p1:t[2],p2:t[3]}}),Le=(t,e,n)=>{let r=n*Math.PI/180,o=Math.sin(r),s=Math.cos(r);return{x:t*s-e*o,y:t*o+e*s}},De=(t,e)=>{let n=t.p2.x-e.x,r=t.p2.y-e.y;const o=Le(n,r,90);n=o.x+e.x,r=o.y+e.y;let s=t.p1.x-e.x,i=t.p1.y-e.y;const a=Le(s,i,90);return s=a.x+e.x,i=a.y+e.y,{p1:{x:s,y:i},p2:{x:n,y:r}}},Be=Object.freeze(Object.defineProperty({__proto__:null,angleToPoints:(t,e)=>{const n=(180-t)/180*Math.PI,r=Math.abs(e.width*Math.sin(n))+Math.abs(e.height*Math.cos(n)),o=Math.sin(n)*r/2,s=Math.cos(n)*r/2,i=e.width/2,a=e.height/2;return{x1:i-o,y1:a-s,x2:i+o,y2:a+s}},boundsToPoints:Me,centerPoint:t=>({x:t.width/2+t.x,y:t.height/2+t.y}),clipToOuterRect:(t,e,n=0)=>{if(n<0&&(n+=360),n>90&&n<=180?n+=180:n>180&&n<=270&&(n-=180),0===n||180===n)return{height:e.height,width:e.width};if(90===n||270===n)return{height:e.width,width:e.height};let r=Me({...e,x:0,y:0}),o=Me({...t,x:0,y:0});o=Ae(o,{x:e.width/2-t.width/2,y:e.height/2-t.height/2}),o=Ne(o,n);let s=Oe(o),i=Oe(r);if(n>90){const t=ke(s.top,i.top);if(t){const e=t,n=ke(s.bottom,i.bottom,!1)||o[3];o[0]=ke(s.top,De(s.bottom,n),!1)||o[0],o[1]=e,o[3]=n,o[2]=ke(s.bottom,De(s.top,e),!1)||o[2],s=Oe(o)}const e=ke(s.top,i.left);if(e){const t=e,n=ke(s.bottom,i.right,!1)||o[2];o[0]=t,o[1]=ke(s.top,De(s.bottom,n),!1)||o[1],o[3]=ke(s.bottom,De(s.top,t),!1)||o[3],o[2]=n}}else if(n<90){const t=ke(s.top,i.top);if(t){const e=t,n=ke(s.bottom,i.bottom,!1)||o[2];o[0]=e,o[1]=ke(s.top,De(s.bottom,n),!1)||o[1],o[3]=ke(s.bottom,De(s.top,e),!1)||o[3],o[2]=n,s=Oe(o)}const e=ke(s.top,i.right);if(e){const t=e,n=ke(s.bottom,i.left,!1)||o[3];o[0]=ke(s.top,De(s.bottom,n),!1)||o[0],o[1]=t,o[3]=n,o[2]=ke(s.bottom,De(s.top,t),!1)||o[2]}}o=Ne(o,-n);const a=Te(o);return{width:a.width,height:a.height}},findIntersectMath:(t,e,n,r)=>{let o=Fe(t.x,t.y,e.x,e.y,5e4,0,-5e4,0);return o&&(n=Math.min(n,o.x),r=Math.max(r,o.x)),{min:n,max:r}},leastSquaresSlopeAndIntercept:t=>{let e=0,n=0,r=0,o=0,s=0,i=0,a=0,l=t.length;if(0===l)return{m:0,b:0};if(1===l)return{m:1,b:t[0]};for(let c=0;c<l;c++)i=c+1,a=t[c],null==a||isNaN(a)||(e+=i,n+=a,o+=i*i,r+=i*a,s++);const c=(s*r-e*n)/(s*o-e*e);return{m:c,b:n/s-c*e/s}},minBoundingRect:Te,rotatePoints:Ne,unionBounds:Re},Symbol.toStringTag,{value:"Module"}));class ze{constructor(t,e,n){this._root=Ue,this._size=0,this._maxNodeSize=n>=4?Math.min(n,256):32,this._compare=e||ze.defaultComparator,t&&this.setPairs(t)}get size(){return this._size}get length(){return this._size}get isEmpty(){return 0===this._size}clear(){this._root=Ue,this._size=0}forEach(t,e){return void 0!==e&&(t=t.bind(e)),this.forEachPair((e,n)=>t(n,e,this))}forEachPair(t,e){const n=this.minKey(),r=this.maxKey();return this.forRange(n,r,!0,t,e)}get(t,e){return this._root.get(t,e,this)}set(t,e,n){this._root.isShared&&(this._root=this._root.clone());const r=this._root.set(t,e,n,this);return!0===r||!1===r?r:(this._root=new He([this._root,r]),!0)}has(t){return 0!==this.forRange(t,t,!0,void 0)}delete(t){return 0!==this.editRange(t,t,!0,ze.DeleteRange)}with(t,e,n){const r=this.clone();return r.set(t,e,n)||n?r:this}withPairs(t,e){const n=this.clone();return 0!==n.setPairs(t,e)||e?n:this}withKeys(t,e){const n=this.clone();let r=!1;for(let e=0;e<t.length;e++)r=n.set(t[e],void 0,!1)||r;return e&&!r?this:n}without(t,e){return this.withoutRange(t,t,!0,e)}withoutKeys(t,e){const n=this.clone();return n.deleteKeys(t)||!e?n:this}withoutRange(t,e,n,r){const o=this.clone();return 0===o.deleteRange(t,e,n)&&r?this:o}filter(t,e){const n=this.greedyClone();let r;return n.editAll((e,n,o)=>{if(!t(e,n,o))return r=ze.DeleteValue}),!r&&e?this:n}mapValues(t){const e=this.greedyClone();return e.editAll((e,n,r)=>t(n,e,r)),e}reduce(t,e){let n,r=0,o=e;const s=this.entries(this.minKey());for(;!(n=s.next()).done;)o=t(o,n.value,r++,this);return o}entries(t,e){const n=this.findPath(t);if(void 0===n)return Pe();let{nodeQueue:r,nodeIndex:o,leaf:s}=n,i=void 0!==e?1:0,a=void 0===t?-1:s.indexOf(t,0,this._compare)-1;return Pe(()=>{t:for(;;)switch(i){case 0:if(++a<s.keys.length)return{done:!1,value:[s.keys[a],s.values[a]]};i=2;continue;case 1:if(++a<s.keys.length){const t=s.keys[a],n=s.values[a];return e?(e.done=!1,e.value[0]=t,e.value[1]=n,e):{done:!1,value:[t,n]}}i=2;case 2:for(var t=-1;;){if(++t>=r.length){i=3;continue t}if(++o[t]<r[t].length)break}for(;t>0;t--)r[t-1]=r[t][o[t]].children,o[t-1]=0;s=r[0][o[0]],a=-1,i=void 0!==e?1:0;continue;case 3:return $e}})}entriesReversed(t,e,n){if(void 0===t&&(n=void 0,void 0===(t=this.maxKey())))return Pe();let{nodeQueue:r,nodeIndex:o,leaf:s}=this.findPath(t)||this.findPath(this.maxKey());We(!r[0]||s===r[0][o[0]],"wat!");let i=s.indexOf(t,0,this._compare);!n&&i<s.keys.length&&this._compare(s.keys[i],t)<=0&&i++;let a=void 0!==e?1:0;return Pe(()=>{t:for(;;)switch(a){case 0:if(--i>=0)return{done:!1,value:[s.keys[i],s.values[i]]};a=2;continue;case 1:if(--i>=0){const t=s.keys[i],n=s.values[i];return e?(e.done=!1,e.value[0]=t,e.value[1]=n,e):{done:!1,value:[t,n]}}a=2;case 2:for(var t=-1;;){if(++t>=r.length){a=3;continue t}if(--o[t]>=0)break}for(;t>0;t--)r[t-1]=r[t][o[t]].children,o[t-1]=r[t-1].length-1;s=r[0][o[0]],i=s.keys.length,a=void 0!==e?1:0;continue;case 3:return $e}})}findPath(t){let e,n,r=this._root;if(r.isLeaf)e=Ge,n=Ge;else{e=[],n=[];for(let o=0;!r.isLeaf;o++){if(e[o]=r.children,n[o]=void 0===t?0:r.indexOf(t,0,this._compare),n[o]>=e[o].length)return;r=e[o][n[o]]}e.reverse(),n.reverse()}return{nodeQueue:e,nodeIndex:n,leaf:r}}diffAgainst(t,e,n,r){if(t._compare!==this._compare)throw new Error("SortedMap: Comparators are not the same.");if(this.isEmpty||t.isEmpty){if(this.isEmpty&&t.isEmpty)return;return this.isEmpty?void 0===n?void 0:ze.stepToEnd(ze.makeDiffCursor(t),n):void 0===e?void 0:ze.stepToEnd(ze.makeDiffCursor(this),e)}const{_compare:o}=this,s=ze.makeDiffCursor(this),i=ze.makeDiffCursor(t);let a=!0,l=!0,c=ze.compare(s,i,o);for(;a&&l;){const t=ze.compare(s,i,o),{leaf:h,internalSpine:u,levelIndices:d}=s,{leaf:g,internalSpine:m,levelIndices:f}=i;if(h||g){if(0!==c)if(0===t){if(h&&g&&r){const t=h.values[d[d.length-1]],e=g.values[f[f.length-1]];if(!Object.is(t,e)){const n=r(s.currentKey,t,e);if(n&&n.break)return n.break}}}else if(t>0){if(g&&n){const t=g.values[f[f.length-1]],e=n(i.currentKey,t);if(e&&e.break)return e.break}}else if(e&&h&&0!==c){const t=h.values[d[d.length-1]],n=e(s.currentKey,t);if(n&&n.break)return n.break}}else if(!h&&!g&&0===t){const t=u.length-1,e=m.length-1,n=u[t][d[t]];if(m[e][f[e]]===n){c=0,a=ze.step(s,!0),l=ze.step(i,!0);continue}}c=t,t<0?a=ze.step(s):l=ze.step(i)}return a&&e?ze.finishCursorWalk(s,i,o,e):l&&n?ze.finishCursorWalk(i,s,o,n):void 0}static finishCursorWalk(t,e,n,r){const o=ze.compare(t,e,n);if(0===o){if(!ze.step(t))return}else o<0&&We(!1,"cursor walk terminated early");return ze.stepToEnd(t,r)}static stepToEnd(t,e){let n=!0;for(;n;){const{leaf:r,levelIndices:o,currentKey:s}=t;if(r){const t=e(s,r.values[o[o.length-1]]);if(t&&t.break)return t.break}n=ze.step(t)}}static makeDiffCursor(t){const{_root:e,height:n}=t;return{height:n,internalSpine:[[e]],levelIndices:[0],leaf:void 0,currentKey:e.maxKey()}}static step(t,e){const{internalSpine:n,levelIndices:r,leaf:o}=t;if(!0===e||o){const s=r.length;if(!0===e||0===r[s-1]){const e=n.length;if(0===e)return!1;const o=e-1;let i=o;for(;i>=0;){if(r[i]>0)return i<s-1&&(t.leaf=void 0,r.pop()),i<o&&(t.internalSpine=n.slice(0,i+1)),t.currentKey=n[i][--r[i]].maxKey(),!0;i--}return!1}{const e=--r[s-1];return t.currentKey=o.keys[e],!0}}{const e=n.length,o=e-1,s=n[o][r[o]];if(s.isLeaf){t.leaf=s;const n=r[e]=s.values.length-1;t.currentKey=s.keys[n]}else{const o=s.children;n[e]=o;const i=o.length-1;r[e]=i,t.currentKey=o[i].maxKey()}return!0}}static compare(t,e,n){const{height:r,currentKey:o,levelIndices:s}=t,{height:i,currentKey:a,levelIndices:l}=e,c=n(a,o);if(0!==c)return c;const h=r<i?r:i;return s.length-(r-h)-(l.length-(i-h))}keys(t,e){const n=this.entries(t,e);return Pe(()=>{const t=n.next();return t.value&&(t.value=t.value[0]),t})}values(t,e){const n=this.entries(t,e);return Pe(()=>{const t=n.next();return t.value&&(t.value=t.value[1]),t})}get maxNodeSize(){return this._maxNodeSize}minKey(){return this._root.minKey()}maxKey(){return this._root.maxKey()}clone(){this._root.isShared=!0;const t=new ze(void 0,this._compare,this._maxNodeSize);return t._root=this._root,t._size=this._size,t}greedyClone(t){const e=new ze(void 0,this._compare,this._maxNodeSize);return e._root=this._root.greedyClone(t),e._size=this._size,e}toArray(t=2147483647){const e=this.minKey(),n=this.maxKey();return void 0!==e?this.getRange(e,n,!0,t):[]}keysArray(){const t=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(e,n)=>{t.push(e)}),t}valuesArray(){const t=[];return this._root.forRange(this.minKey(),this.maxKey(),!0,!1,this,0,(e,n)=>{t.push(n)}),t}toString(){return this.toArray().toString()}setIfNotPresent(t,e){return this.set(t,e,!1)}nextHigherPair(t,e){return void 0===t?this._root.minPair(e):this._root.getPairOrNextHigher(t,this._compare,!1,e)}nextHigherKey(t,e){const n=this.nextHigherPair(t,e);return n&&n[0]}nextLowerPair(t,e){return void 0===t?this._root.maxPair(e):this._root.getPairOrNextLower(t,this._compare,!1,e)}nextLowerKey(t,e){const n=this.nextLowerPair(t,e);return n&&n[0]}getPairOrNextLower(t,e){return this._root.getPairOrNextLower(t,this._compare,!0,e)}getPairOrNextHigher(t,e){return this._root.getPairOrNextHigher(t,this._compare,!0,e)}changeIfPresent(t,e){return 0!==this.editRange(t,t,!0,(t,n)=>({value:e}))}getRange(t,e,n,r=67108863){const o=[];return this._root.forRange(t,e,n,!1,this,0,(t,e)=>(o.push([t,e]),o.length>r?ze.Break:void 0)),o}setPairs(t,e){let n=0;for(let r=0;r<t.length;r++)this.set(t[r][0],t[r][1],e)&&n++;return n}forRange(t,e,n,r,o){const s=this._root.forRange(t,e,n,!1,this,o||0,r);return"number"==typeof s?s:s.break}forEditRange(t,e,n,r,o,s){return this._root.forRange(t,e,n,r,this,s||0,o)}editRange(t,e,n,r,o){let s=this._root;s.isShared&&(this._root=s=s.clone());try{const i=s.forRange(t,e,n,!0,this,o||0,r);return"number"==typeof i?i:i.break}finally{let t;for(;s.keys.length<=1&&!s.isLeaf;)t||=s.isShared,this._root=s=0===s.keys.length?Ue:s.children[0];t&&(s.isShared=!0)}}editAll(t,e){return this.editRange(this.minKey(),this.maxKey(),!0,t,e)}deleteRange(t,e,n){return this.editRange(t,e,n,ze.DeleteRange)}deleteKeys(t){let e=0;for(let n=0;n<t.length;n++)this.delete(t[n])&&e++;return e}get height(){let t=this._root,e=-1;for(;t;)e++,t=t.isLeaf?void 0:t.children[0];return e}freeze(){const t=this;t.clear=t.set=t.editRange=function(){throw new Error("SortedMap: Attempted to modify when frozen.")}}unfreeze(){delete this.clear,delete this.set,delete this.editRange}get isFrozen(){return this.hasOwnProperty("editRange")}checkValid(){const t=this._root.checkValid(0,this,0);We(t===this.size,"size mismatch: counted ",t,"but stored",this.size)}}function Pe(t=()=>$e){const e={next:t};return Symbol&&Symbol.iterator&&(e[Symbol.iterator]=function(){return this}),e}Symbol&&Symbol.iterator&&(ze.prototype[Symbol.iterator]=ze.prototype.entries),ze.prototype.where=ze.prototype.filter,ze.prototype.setRange=ze.prototype.setPairs,ze.prototype.add=ze.prototype.set;class je{get isLeaf(){return void 0===this.children}constructor(t=[],e){this.keys=t,this.values=e||Ve,this.isShared=void 0}maxKey(){return this.keys[this.keys.length-1]}indexOf(t,e,n){const r=this.keys;let o=0,s=r.length,i=s>>1;for(;o<s;){const e=n(r[i],t);if(e<0)o=i+1;else{if(!(e>0)){if(0===e)return i;if(t==t)return r.length;throw new Error("SortedMap: NaN was used as a key.")}s=i}i=o+s>>1}return i^e}minKey(){return this.keys[0]}minPair(t){if(0!==this.keys.length)return(t=t??[null,null])[0]=this.keys[0],t[1]=this.values[0],t}maxPair(t){if(0===this.keys.length)return;const e=this.keys.length-1;return(t=t??[null,null])[0]=this.keys[e],t[1]=this.values[e],t}clone(){const t=this.values,e=t===Ve?t:t.slice(0),n=this.keys.slice(0);return new je(n,e)}greedyClone(t){return this.isShared&&!t?this:this.clone()}get(t,e,n){const r=this.indexOf(t,-1,n._compare);return r<0?e:this.values[r]}getPairOrNextLower(t,e,n,r){const o=this.indexOf(t,-1,e),s=o<0?~o-1:n?o:o-1;if(s>=0){const t=this.keys[s],e=this.values[s];return r?(r[0]=t,r[1]=e,r):[t,e]}}getPairOrNextHigher(t,e,n,r){const o=this.indexOf(t,-1,e),s=o<0?~o:n?o:o+1;if(s<this.keys.length){const t=this.keys[s],e=this.values[s];return r?(r[0]=t,r[1]=e,r):[t,e]}}checkValid(t,e,n){const r=this.keys.length,o=this.values.length;return We(this.values===Ve?r<=o:r===o,"keys/values length mismatch: depth",t,"with lengths",r,o,"and baseIndex",n),We(0===t||r>0,"empty leaf at depth",t,"and baseIndex",n),r}set(t,e,n,r){let o=this.indexOf(t,-1,r._compare);if(o<0){if(o=~o,r._size++,this.keys.length<r._maxNodeSize)return this.insertInLeaf(o,t,e,n,r);{const s=this.splitOffRightSide();let i=this;return o>this.keys.length&&(o-=this.keys.length,i=s),i.insertInLeaf(o,t,e,n,r),s}}if(!1!==n){void 0!==e&&this.reifyValues(),this.keys[o]=t;let r=e;if("function"==typeof n){const s=n(this.values[o],t,e);void 0!==s&&(r=s)}this.values[o]=r}return!1}reifyValues(){return this.values===Ve?this.values=this.values.slice(0,this.keys.length):this.values}insertInLeaf(t,e,n,r,o){if(this.keys.splice(t,0,e),this.values===Ve){for(;Ve.length<o._maxNodeSize;)Ve.push(void 0);if(void 0===n)return!0;this.values=Ve.slice(0,this.keys.length-1)}let s=n;if("function"==typeof r){const t=r(void 0,e,n);void 0!==t&&(s=t)}return this.values.splice(t,0,s),!0}takeFromRight(t){let e=this.values;t.values===Ve?e!==Ve&&e.push(void 0):(e=this.reifyValues(),e.push(t.values.shift())),this.keys.push(t.keys.shift())}takeFromLeft(t){let e=this.values;t.values===Ve?e!==Ve&&e.unshift(void 0):(e=this.reifyValues(),e.unshift(t.values.pop())),this.keys.unshift(t.keys.pop())}splitOffRightSide(){const t=this.keys.length>>1,e=this.keys.splice(t),n=this.values===Ve?Ve:this.values.splice(t);return new je(e,n)}forRange(t,e,n,r,o,s,i){const a=o._compare;let l,c;if(e===t){if(!n)return s;if(c=(l=this.indexOf(t,-1,a))+1,l<0)return s}else l=this.indexOf(t,0,a),c=this.indexOf(e,-1,a),c<0?c=~c:!0===n&&c++;const h=this.keys,u=this.values;if(void 0!==i)for(let t=l;t<c;t++){const e=h[t],n=i(e,u[t],s++);if(void 0!==n){if(void 0!==n.break)return n;if(!0===r){if(e!==h[t]&&0!==o._compare(e,h[t])||!0===this.isShared)throw new Error("SortedMap: illegally changed or cloned in editRange.");n.delete?(this.keys.splice(t,1),this.values!==Ve&&this.values.splice(t,1),o._size--,t--,c--):n.hasOwnProperty("value")&&(u[t]=n.value)}}}else s+=c-l;return s}mergeSibling(t,e){if(this.keys.push.apply(this.keys,t.keys),this.values===Ve){if(t.values===Ve)return;this.values=this.values.slice(0,this.keys.length)}this.values.push.apply(this.values,t.reifyValues())}}class He extends je{constructor(t,e){if(!e){e=[];for(let n=0;n<t.length;n++)e[n]=t[n].maxKey()}super(e),this.children=t}clone(){const t=this.children.slice(0);for(let e=0;e<t.length;e++)t[e].isShared=!0;return new He(t,this.keys.slice(0))}greedyClone(t){if(this.isShared&&!t)return this;const e=new He(this.children.slice(0),this.keys.slice(0));for(let n=0;n<e.children.length;n++)e.children[n]=e.children[n].greedyClone(t);return e}minKey(){return this.children[0].minKey()}minPair(t){return this.children[0].minPair(t)}maxPair(t){return this.children[this.children.length-1].maxPair(t)}get(t,e,n){const r=this.indexOf(t,0,n._compare),o=this.children;return r<o.length?o[r].get(t,e,n):void 0}getPairOrNextLower(t,e,n,r){const o=this.indexOf(t,0,e),s=this.children;if(o>=s.length)return this.maxPair(r);const i=s[o].getPairOrNextLower(t,e,n,r);return void 0===i&&o>0?s[o-1].maxPair(r):i}getPairOrNextHigher(t,e,n,r){const o=this.indexOf(t,0,e),s=this.children,i=s.length;if(o>=i)return;const a=s[o].getPairOrNextHigher(t,e,n,r);return void 0===a&&o<i-1?s[o+1].minPair(r):a}checkValid(t,e,n){const r=this.keys.length,o=this.children.length;We(r===o,"keys/children length mismatch: depth",t,"lengths",r,o,"baseIndex",n),We(r>1||t>0,"internal node has length",r,"at depth",t,"baseIndex",n);let s=0,i=this.children,a=this.keys,l=0;for(let r=0;r<o;r++)s+=i[r].checkValid(t+1,e,n+s),l+=i[r].keys.length,We(s>=l,"wtf",n),We(0===r||i[r-1].constructor===i[r].constructor,"type mismatch, baseIndex:",n),i[r].maxKey()!==a[r]&&We(!1,"keys[",r,"] =",a[r],"is wrong, should be ",i[r].maxKey(),"at depth",t,"baseIndex",n),0===r||e._compare(a[r-1],a[r])<0||We(!1,"sort violation at depth",t,"index",r,"keys",a[r-1],a[r]);const c=0===l;return(c||l>e.maxNodeSize*o)&&We(!1,c?"too few":"too many","children (",l,s,") at depth",t,"maxNodeSize:",e.maxNodeSize,"children.length:",o,"baseIndex:",n),s}set(t,e,n,r){const o=this.children,s=r._maxNodeSize,i=r._compare;let a=Math.min(this.indexOf(t,0,i),o.length-1),l=o[a];if(l.isShared&&(o[a]=l=l.clone()),l.keys.length>=s){let e;a>0&&(e=o[a-1]).keys.length<s&&i(l.keys[0],t)<0?(e.isShared&&(o[a-1]=e=e.clone()),e.takeFromRight(l),this.keys[a-1]=e.maxKey()):void 0!==(e=o[a+1])&&e.keys.length<s&&i(l.maxKey(),t)<0&&(e.isShared&&(o[a+1]=e=e.clone()),e.takeFromLeft(l),this.keys[a]=o[a].maxKey())}const c=l.set(t,e,n,r);if(!1===c)return!1;if(this.keys[a]=l.maxKey(),!0===c)return!0;if(this.keys.length<s)return this.insert(a+1,c),!0;{const t=this.splitOffRightSide();let e=this;return i(c.maxKey(),this.maxKey())>0&&(e=t,a-=this.keys.length),e.insert(a+1,c),t}}insert(t,e){this.children.splice(t,0,e),this.keys.splice(t,0,e.maxKey())}splitOffRightSide(){const t=this.children.length>>1;return new He(this.children.splice(t),this.keys.splice(t))}takeFromRight(t){this.keys.push(t.keys.shift()),this.children.push(t.children.shift())}takeFromLeft(t){this.keys.unshift(t.keys.pop()),this.children.unshift(t.children.pop())}forRange(t,e,n,r,o,s,i){const a=o._compare,l=this.keys,c=this.children;let h=this.indexOf(t,0,a),u=h,d=Math.min(e===t?h:this.indexOf(e,0,a),l.length-1);if(r){if(u<=d)try{for(;u<=d;u++){c[u].isShared&&(c[u]=c[u].clone());const a=c[u].forRange(t,e,n,r,o,s,i);if(l[u]=c[u].maxKey(),"number"!=typeof a)return a;s=a}}finally{const t=o._maxNodeSize>>1;for(h>0&&h--,u=d;u>=h;u--)c[u].keys.length<=t&&(0!==c[u].keys.length?this.tryMerge(u,o._maxNodeSize):(l.splice(u,1),c.splice(u,1)));0!==c.length&&0===c[0].keys.length&&We(!1,"emptiness bug")}}else for(;u<=d;u++){const a=c[u].forRange(t,e,n,r,o,s,i);if("number"!=typeof a)return a;s=a}return s}tryMerge(t,e){const n=this.children;return t>=0&&t+1<n.length&&n[t].keys.length+n[t+1].keys.length<=e&&(n[t].isShared&&(n[t]=n[t].clone()),n[t].mergeSibling(n[t+1],e),n.splice(t+1,1),this.keys.splice(t+1,1),this.keys[t]=n[t].maxKey(),!0)}mergeSibling(t,e){const n=this.keys.length;this.keys.push.apply(this.keys,t.keys);const r=t.children;if(this.children.push.apply(this.children,r),t.isShared&&!this.isShared)for(let t=0;t<r.length;t++)r[t].isShared=!0;this.tryMerge(n-1,e)}}const Ve=[],$e=Object.freeze({done:!0,value:void 0}),Ue=function(){const t=new je;return t.isShared=!0,t}(),Ge=[],We=(t,...e)=>{if(!t)throw e.unshift("SortedMap:"),new Error(e.join(" "))};var qe;(qe=ze||(ze={})).DeleteValue=Object.freeze({delete:!0}),qe.Break=Object.freeze({break:!0}),qe.DeleteRange=()=>qe.DeleteValue,qe.EmptySortedMap=(()=>{const t=new qe;return t.freeze(),t})(),qe.defaultComparator=function(t,e){if(Number.isFinite(t)&&Number.isFinite(e))return t-e;let n=typeof t,r=typeof e;if(n!==r)return n<r?-1:1;if("object"===n){if(null===t)return null===e?0:-1;if(null===e)return 1;if(n=typeof(t=t.valueOf()),r=typeof(e=e.valueOf()),n!==r)return n<r?-1:1}return t<e?-1:t>e?1:t===e?0:Number.isNaN(t)?Number.isNaN(e)?0:-1:Number.isNaN(e)?1:Array.isArray(t)?0:Number.NaN},qe.simpleComparator=function(t,e){return t>e?1:t<e?-1:0};const Je=[-1,null],Xe={done:!1,value:[-1,null]};var Ke;(t=>{t.Builder=class{constructor(t,e=0,n=0){this._tuples=[],this._minors=null,this._values=null,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=0,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._offsetMajor=0,this._offsetMinor=0,this._createList=t,this._offsetMajor=e,this._offsetMinor=n}addValues(t,e,n){if(n&&n.isIList)return this.addValue(t,e,n);Array.isArray(n)||(n=[n]),this.addValue(t,e,n[0]);const r=n.length,o=this._values;for(let t=1;t<r;t++)o.push(n[t]);return this._minorIndex=this._minorIndex+o.length-1,this}addValue(t,n,r){const o=this._majorIndex,s=this._minorIndex;if(t+=this._offsetMajor,n+=this._offsetMinor,t<o||t===o&&n<=s)throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);let i=this._minors;if(t!==o){if(i){this._minorMin=Math.min(this._minorMin,i[0][0]);const t=i[i.length-1];this._minorMax=Math.max(this._minorMax,t[0]+t[1].length-1)}this._minors=i=[],this._tuples.push([t,i]),this._majorIndex=t}if(r&&r.isIList){n===s+1&&o!==t&&this._values;const e=r;i.push([n,e]),n=n+e.length-1}else{let e=null;n!==s+1||o!==t?(this._values=e=[],i.push([n,e])):e=this._values,e.push(r)}return this._minorIndex=n,this}build(){const t=this._tuples;if(0===t.length)return null;const e=this._minors;this._minorMin=Math.min(this._minorMin,e[0][0]);const n=e[e.length-1];this._minorMax=Math.max(this._minorMax,n[0]+n[1].length-1);const r=this._createList;if(r){const t=e.length;for(let n=0;n<t;n++)e[n][1]=r(e[n][1])}return{tuples:t,bounds:{majorStart:t[0][0],minorStart:this._minorMin,majorEnd:t[t.length-1][0],minorEnd:this._minorMax}}}};t.TransposedBuilder=class{constructor(t,e=0,n=0){this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=0,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._offsetMajor=0,this._offsetMinor=0,this._createList=t,this._offsetMajor=e,this._offsetMinor=n,this._minors=new ze}addValues(t,e,n){Array.isArray(n)||(n=[n]);const r=n.length;for(let o=0;o<r;o++){const r=e+o;this.addValue(t,r,n[o])}return this}addValue(t,n,r){let o,s;const i=this._majorIndex;let a=this._minorIndex;if(t+=this._offsetMajor,n+=this._offsetMinor,s=this._current,t!==i){if(this._majorIndex=t,t<i)throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);a=Number.MIN_SAFE_INTEGER}else if(s=this._current,n<=a)throw new e(`major: ${t}, minor: ${n}, prevMajor: ${this._majorIndex}, prevMinor: ${this._minorIndex}`);if(s&&s.minor===n&&(o=s.span),o)s.minor>=n&&s.next&&(this._current=s.next);else{const e=this._minors,r=s?s.next??s.prev:null;if(r){let t;const i=r.minor;r&&r.minor===n?(s=r,o=s.span):t=i>n?e.getPairOrNextHigher(n,Je):e.getPairOrNextLower(n,Je),t&&(s=t[1],t[0]===n&&(o=s.span))}if(!o){this._majorMin=Math.min(this._majorMin,t),o=[n,[[t,[]]]];const r={minor:n,span:o,prev:null,next:null};s&&(s.minor<n?(r.prev=s,r.next=s.next,s.next&&(s.next.prev=r),s.next=r):(r.prev=s.prev,r.next=s,s.prev&&(s.prev.next=r),s.prev=r)),e.set(n,r),this._current=r;const i=this._first;(!i||n<i.minor)&&(this._first=r),r.next&&(this._current=r.next)}}let l=o[1];const c=l[l.length-1];let h=c[0],u=c[1];return h+u.length!==t&&(u=[],h=t,l.push([h,u])),u.push(r),this._majorMax=Math.max(this._majorMax,t),this._minorIndex=n,this}build(){const t=[],e=this._createList,n=this._minors.entries(void 0,Xe);let r=n.next();for(;!r.done;){const o=r.value[1].span;if(e)for(let t=0;t<o.length;t++)o[t][1]=this._createList(o[t][1]);t.push(o),r=n.next()}return 0===t.length?null:{tuples:t,bounds:{majorStart:t[0][0],minorStart:this._majorMin,majorEnd:t[t.length-1][0],minorEnd:this._majorMax}}}};class e extends Nt{constructor(t="Out of order",e=null){super(t,e),this.name="OutOfOrderError"}}t.OutOfOrderError=e})(Ke||(Ke={}));const Ye={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function Ze(t){return(e={})=>{const n=e.width?String(e.width):t.defaultWidth;return t.formats[n]||t.formats[t.defaultWidth]}}const Qe={date:Ze({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:Ze({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:Ze({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},tn={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function en(t){return(e,n)=>{let r;if("formatting"===(n?.context?String(n.context):"standalone")&&t.formattingValues){const e=t.defaultFormattingWidth||t.defaultWidth,o=n?.width?String(n.width):e;r=t.formattingValues[o]||t.formattingValues[e]}else{const e=t.defaultWidth,o=n?.width?String(n.width):t.defaultWidth;r=t.values[o]||t.values[e]}return r[t.argumentCallback?t.argumentCallback(e):e]}}function nn(t){return(e,n={})=>{const r=n.width,o=r&&t.matchPatterns[r]||t.matchPatterns[t.defaultMatchWidth],s=e.match(o);if(!s)return null;const i=s[0],a=r&&t.parsePatterns[r]||t.parsePatterns[t.defaultParseWidth],l=Array.isArray(a)?function(t,e){for(let n=0;n<t.length;n++)if(e(t[n]))return n;return}(a,t=>t.test(i)):function(t,e){for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return n;return}(a,t=>t.test(i));let c;c=t.valueCallback?t.valueCallback(l):l,c=n.valueCallback?n.valueCallback(c):c;return{value:c,rest:e.slice(i.length)}}}var rn;const on={code:"en-US",formatDistance:(t,e,n)=>{let r;const o=Ye[t];return r="string"==typeof o?o:1===e?o.one:o.other.replace("{{count}}",e.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r},formatLong:Qe,formatRelative:(t,e,n,r)=>tn[t],localize:{ordinalNumber:(t,e)=>{const n=Number(t),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:en({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:en({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:t=>t-1}),month:en({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:en({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:en({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})},match:{ordinalNumber:(rn={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:t=>parseInt(t,10)},(t,e={})=>{const n=t.match(rn.matchPattern);if(!n)return null;const r=n[0],o=t.match(rn.parsePattern);if(!o)return null;let s=rn.valueCallback?rn.valueCallback(o[0]):o[0];return s=e.valueCallback?e.valueCallback(s):s,{value:s,rest:t.slice(r.length)}}),era:nn({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:nn({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:t=>t+1}),month:nn({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:nn({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:nn({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})},options:{weekStartsOn:0,firstWeekContainsDate:1}},sn=(t,e)=>{switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},an=(t,e)=>{switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},ln={p:an,P:(t,e)=>{const n=t.match(/(P+)(p+)?/)||[],r=n[1],o=n[2];if(!o)return sn(t,e);let s;switch(r){case"P":s=e.dateTime({width:"short"});break;case"PP":s=e.dateTime({width:"medium"});break;case"PPP":s=e.dateTime({width:"long"});break;default:s=e.dateTime({width:"full"})}return s.replace("{{date}}",sn(r,e)).replace("{{time}}",an(o,e))}},cn=/^D+$/,hn=/^Y+$/,un=["D","DD","YY","YYYY"];function dn(t){return cn.test(t)}function gn(t){return hn.test(t)}function mn(t,e,n){const r=function(t,e,n){const r="Y"===t[0]?"years":"days of the month";return`Use \`${t.toLowerCase()}\` instead of \`${t}\` (in \`${e}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(t,e,n);if(console.warn(r),un.includes(t))throw new RangeError(r)}const fn=Symbol.for("constructDateFrom");function pn(t,e){return"function"==typeof t?t(e):t&&"object"==typeof t&&fn in t?t[fn](e):t instanceof Date?new t.constructor(e):new Date(e)}let _n={};function Sn(){return _n}function wn(t,e){return pn(e||t,t)}class yn{constructor(){this.subPriority=0}validate(t,e){return!0}}class En extends yn{constructor(t,e,n,r,o){super(),this.value=t,this.validateValue=e,this.setValue=n,this.priority=r,o&&(this.subPriority=o)}validate(t,e){return this.validateValue(t,this.value,e)}set(t,e,n){return this.setValue(t,e,this.value,n)}}class bn extends yn{constructor(t,e){super(),this.priority=10,this.subPriority=-1,this.context=t||(t=>pn(e,t))}set(t,e){return e.timestampIsSet?t:pn(t,function(t,e){const n=function(t){return"function"==typeof t&&t.prototype?.constructor===t}(e)?new e(0):pn(e,0);return n.setFullYear(t.getFullYear(),t.getMonth(),t.getDate()),n.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),n}(t,this.context))}}let vn=class{run(t,e,n,r){const o=this.parse(t,e,n,r);return o?{setter:new En(o.value,this.validate,this.set,this.priority,this.subPriority),rest:o.rest}:null}validate(t,e,n){return!0}};const Cn=/^(1[0-2]|0?\d)/,xn=/^(3[0-1]|[0-2]?\d)/,In=/^\d/,An=/^\d{1,2}/,Rn=/^\d{1,3}/,Mn=/^\d{1,4}/;function Tn(t,e){return t?{value:e(t.value),rest:t.rest}:t}function Nn(t,e){const n=e.match(t);return n?{value:parseInt(n[0],10),rest:e.slice(n[0].length)}:null}function Fn(t,e){switch(t){case 1:return Nn(In,e);case 2:return Nn(An,e);case 3:return Nn(Rn,e);case 4:return Nn(Mn,e);default:return Nn(new RegExp("^\\d{1,"+t+"}"),e)}}class kn extends vn{constructor(){super(...arguments),this.incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"],this.priority=110}parse(t,e,n){const r=t=>t-1;switch(e){case"M":return Tn(Nn(Cn,t),r);case"MM":return Tn(Fn(2,t),r);case"Mo":return Tn(n.ordinalNumber(t,{unit:"month"}),r);case"MMM":return n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return n.month(t,{width:"narrow",context:"formatting"});default:return n.month(t,{width:"wide",context:"formatting"})||n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.setMonth(n,1),t.setHours(0,0,0,0),t}}const On=[31,28,31,30,31,30,31,31,30,31,30,31],Ln=[31,29,31,30,31,30,31,31,30,31,30,31];function Dn(t,e,n){const r=Sn(),o=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,s=wn(t,n?.in),i=s.getDay(),a=7-o;return function(t,e,n){const r=wn(t,n?.in);return isNaN(e)?pn(n?.in||t,NaN):e?(r.setDate(r.getDate()+e),r):r}(s,e<0||e>6?e-(i+a)%7:((e%7+7)%7+a)%7-(i+a)%7,n)}const Bn={y:new class extends vn{constructor(){super(...arguments),this.priority=130,this.incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"]}parse(t,e,n){const r=t=>({year:t,isTwoDigitYear:"yy"===e});switch(e){case"y":return Tn(Fn(4,t),r);case"yo":return Tn(n.ordinalNumber(t,{unit:"year"}),r);default:return Tn(Fn(e.length,t),r)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,n){const r=t.getFullYear();if(n.isTwoDigitYear){const e=function(t,e){const n=e>0,r=n?e:1-e;let o;if(r<=50)o=t||100;else{const e=r+50;o=t+100*Math.trunc(e/100)-(t>=e%100?100:0)}return n?o:1-o}(n.year,r);return t.setFullYear(e,0,1),t.setHours(0,0,0,0),t}const o="era"in e&&1!==e.era?1-n.year:n.year;return t.setFullYear(o,0,1),t.setHours(0,0,0,0),t}},M:new kn,d:new class extends vn{constructor(){super(...arguments),this.priority=90,this.subPriority=1,this.incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]}parse(t,e,n){switch(e){case"d":return Nn(xn,t);case"do":return n.ordinalNumber(t,{unit:"date"});default:return Fn(e.length,t)}}validate(t,e){const n=function(t){return t%400==0||t%4==0&&t%100!=0}(t.getFullYear()),r=t.getMonth();return n?e>=1&&e<=Ln[r]:e>=1&&e<=On[r]}set(t,e,n){return t.setDate(n),t.setHours(0,0,0,0),t}},E:new class extends vn{constructor(){super(...arguments),this.priority=90,this.incompatibleTokens=["D","i","e","c","t","T"]}parse(t,e,n){switch(e){case"E":case"EE":case"EEE":return n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return n.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});default:return n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,r){return(t=Dn(t,n,r)).setHours(0,0,0,0),t}}},zn=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Pn=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,jn=/^'([^]*?)'?$/,Hn=/''/g,Vn=/\S/,$n=/[a-zA-Z]/;function Un(t,e,n,r){const o=()=>pn(r?.in||n,NaN),s=Object.assign({},Sn()),i=r?.locale??s.locale??on,a=r?.firstWeekContainsDate??r?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,l=r?.weekStartsOn??r?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0;if(!e)return t?o():wn(n,r?.in);const c={firstWeekContainsDate:a,weekStartsOn:l,locale:i},h=[new bn(r?.in,n)],u=e.match(Pn).map(t=>{const e=t[0];if(e in ln){return(0,ln[e])(t,i.formatLong)}return t}).join("").match(zn),d=[];for(let n of u){!r?.useAdditionalWeekYearTokens&&gn(n)&&mn(n,e,t),!r?.useAdditionalDayOfYearTokens&&dn(n)&&mn(n,e,t);const s=n[0],a=Bn[s];if(a){const{incompatibleTokens:e}=a;if(Array.isArray(e)){const t=d.find(t=>e.includes(t.token)||t.token===s);if(t)throw new RangeError(`The format string mustn't contain \`${t.fullToken}\` and \`${n}\` at the same time`)}else if("*"===a.incompatibleTokens&&d.length>0)throw new RangeError(`The format string mustn't contain \`${n}\` and any other token at the same time`);d.push({token:s,fullToken:n});const r=a.run(t,n,i.match,c);if(!r)return o();h.push(r.setter),t=r.rest}else{if(s.match($n))throw new RangeError("Format string contains an unescaped latin alphabet character `"+s+"`");if("''"===n?n="'":"'"===s&&(n=Gn(n)),0!==t.indexOf(n))return o();t=t.slice(n.length)}}if(t.length>0&&Vn.test(t))return o();const g=h.map(t=>t.priority).sort((t,e)=>e-t).filter((t,e,n)=>n.indexOf(t)===e).map(t=>h.filter(e=>e.priority===t).sort((t,e)=>e.subPriority-t.subPriority)).map(t=>t[0]);let m=wn(n,r?.in);if(isNaN(+m))return o();const f={};for(const t of g){if(!t.validate(m,c))return o();const e=t.set(m,f,c);Array.isArray(e)?(m=e[0],Object.assign(f,e[1])):m=e}return m}function Gn(t){return t.match(jn)[1].replace(Hn,"'")}const Wn=t=>!isNaN(t)&&("[object Date]"===Object.prototype.toString.call(t)||t instanceof Date);function qn(t,e,n){let r=t,o=t.length,s=e.length;for(var i=o;i<s;++i){const t=e[i];if("#"===t)return r;r=n?r+t:t+r}return r}function Jn(t,e){for(var n="";n.length<e;)n+=t;return n}function Xn(t){for(var e="",n=t.length-1;n>=0;)e+=t.charAt(n--);return e}function Kn(t,e){var n=""+t;return n.length>=e?n:Jn("0",e-n.length)+n}function Yn(t,e){var n=""+t;return n.length>=e?n:Jn(" ",e-n.length)+n}function Zn(t,e){var n=""+t;return n.length>=e?n:n+Jn(" ",e-n.length)}var Qn=Math.pow(2,32);function tr(t,e){return t>Qn||t<-Qn?function(t,e){var n=""+Math.round(t);return n.length>=e?n:Jn("0",e-n.length)+n}(t,e):function(t,e){var n=""+t;return n.length>=e?n:Jn("0",e-n.length)+n}(Math.round(t),e)}function er(t,e){return e=e||0,t.length>=7+e&&103==(32|t.charCodeAt(e))&&101==(32|t.charCodeAt(e+1))&&110==(32|t.charCodeAt(e+2))&&101==(32|t.charCodeAt(e+3))&&114==(32|t.charCodeAt(e+4))&&97==(32|t.charCodeAt(e+5))&&108==(32|t.charCodeAt(e+6))}var nr=[["Sun","Sunday"],["Mon","Monday"],["Tue","Tuesday"],["Wed","Wednesday"],["Thu","Thursday"],["Fri","Friday"],["Sat","Saturday"]],rr=[["J","Jan","January"],["F","Feb","February"],["M","Mar","March"],["A","Apr","April"],["M","May","May"],["J","Jun","June"],["J","Jul","July"],["A","Aug","August"],["S","Sep","September"],["O","Oct","October"],["N","Nov","November"],["D","Dec","December"]],or={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",5:"$#,##0_);($#,##0)",6:"$#,##0_);[Red]($#,##0)",7:"$#,##0.00_);($#,##0.00)",8:"$#,##0.00_);[Red]($#,##0.00)",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yy",15:"d-mmm-yy",16:"d-mmm",17:"mmm-yy",18:"h:mm AM/PM",19:"h:mm:ss AM/PM",20:"h:mm",21:"h:mm:ss",22:"m/d/yy h:mm",23:"General",24:"General",25:"General",26:"General",27:"m/d/yyyy",28:"m/d/yyyy",29:"m/d/yyyy",30:"m/d/yyyy",32:"h:mm:ss",31:"m/d/yyyy",33:"h:mm:ss",34:"h:mm:ss",35:"h:mm:ss",36:"m/d/yyyy",37:"#,##0_);(#,##0)",38:"#,##0_);[Red](#,##0)",39:"#,##0.00_);(#,##0.00)",40:"#,##0.00_);[Red](#,##0.00)",41:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',42:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)',43:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',44:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@",50:"m/d/yyyy",51:"m/d/yyyy",52:"m/d/yyyy",53:"m/d/yyyy",54:"m/d/yyyy",55:"m/d/yyyy",56:'"上午/下午 "hh"時"mm"分"ss"秒 "'},sr={5:37,6:38,7:39,8:40,23:0,24:0,25:0,26:0,27:14,28:14,29:14,30:14,31:14,50:14,51:14,52:14,53:14,54:14,55:14,56:14,57:14,58:14,59:1,60:2,61:3,62:4,67:9,68:10,69:12,70:13,71:14,72:14,73:15,74:16,75:17,76:20,77:21,78:22,79:45,80:46,81:47,82:0},ir={5:'"$"#,##0_);\\("$"#,##0\\)',63:'"$"#,##0_);\\("$"#,##0\\)',6:'"$"#,##0_);[Red]\\("$"#,##0\\)',64:'"$"#,##0_);[Red]\\("$"#,##0\\)',7:'"$"#,##0.00_);\\("$"#,##0.00\\)',65:'"$"#,##0.00_);\\("$"#,##0.00\\)',8:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',66:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',41:'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',42:'_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)',43:'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',44:'_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)'};function ar(t,e,n){for(var r=t<0?-1:1,o=t*r,s=0,i=1,a=0,l=1,c=0,h=0,u=Math.floor(o);c<e&&(a=(u=Math.floor(o))*i+s,h=u*c+l,!(o-u<5e-8));)o=1/(o-u),s=i,i=a,l=c,c=h;if(h>e&&(c>e?(h=l,a=s):(h=c,a=i)),!n)return[0,r*a,h];var d=Math.floor(r*a/h);return[d,r*a-d*h,h]}function lr(t,e,n){if(t>2958465||t<0)return null;var r=0|t,o=Math.floor(86400*(t-r)),s=0,i=[],a={D:r,T:o,u:86400*(t-r)-o,y:0,m:0,d:0,H:0,M:0,S:0,q:0};if(Math.abs(a.u)<1e-6&&(a.u=0),e&&e.date1904&&(r+=1462),a.u>.9999&&(a.u=0,86400===++o&&(a.T=o=0,++r,++a.D)),60===r)i=n?[1317,10,29]:[1900,2,29],s=3;else if(0===r)i=n?[1317,8,29]:[1900,1,0],s=6;else{r>60&&--r;var l=new Date(1900,0,1);l.setDate(l.getDate()+r-1),i=[l.getFullYear(),l.getMonth()+1,l.getDate()],s=l.getDay(),r<60&&(s=(s+6)%7),n&&(s=function(t,e){e[0]-=581;var n=t.getDay();t<60&&(n=(n+6)%7);return n}(l,i))}return a.y=i[0],a.m=i[1],a.d=i[2],a.S=o%60,o=Math.floor(o/60),a.M=o%60,o=Math.floor(o/60),a.H=o,a.q=s,a}var cr=new Date(1899,11,31,0,0,0),hr=cr.getTime(),ur=new Date(1900,2,1,0,0,0);function dr(t,e=!1){var n=t.getTime();return e?n-=1262304e5:t>=ur&&(n+=864e5),(n-(hr+6e4*(t.getTimezoneOffset()-cr.getTimezoneOffset())))/864e5}function gr(t){return-1===t.indexOf(".")?t:t.replace(/(?:\.0*|(\.\d*[1-9])0+)$/,"$1")}function mr(t){var e,n=Math.floor(Math.log(Math.abs(t))*Math.LOG10E);return e=n>=-4&&n<=-1?t.toPrecision(10+n):Math.abs(n)<=9?function(t){var e=t<0?12:11,n=gr(t.toFixed(12));return n.length<=e||(n=t.toPrecision(10)).length<=e?n:t.toExponential(5)}(t):10===n?t.toFixed(10).substr(0,12):function(t){var e=gr(t.toFixed(11));return e.length>(t<0?12:11)||"0"===e||"-0"===e?t.toPrecision(6):e}(t),gr(function(t){return-1===t.indexOf("E")?t:t.replace(/(?:\.0*|(\.\d*[1-9])0+)[Ee]/,"$1E").replace(/(E[+-])(\d)$/,"$10$2")}(e.toUpperCase()))}function fr(t,e){switch(typeof t){case"string":return t;case"boolean":return t?"TRUE":"FALSE";case"number":return(0|t)===t?t.toString(10):mr(t);case"undefined":return"";case"object":if(null==t)return"";if(Wn(t))return Br(14,dr(t,e&&e.date1904),e)}throw new Error("unsupported value in General format: "+t)}function pr(t,e,n,r){var o,s="",i=0,a=0,l=n.y,c=0;switch(t){case 98:l=n.y+543;case 121:switch(e.length){case 1:case 2:o=l%100,c=2;break;default:o=l%1e4,c=4}break;case 109:switch(e.length){case 1:case 2:o=n.m,c=e.length;break;case 3:return rr[n.m-1][1];case 5:return rr[n.m-1][0];default:return rr[n.m-1][2]}break;case 100:switch(e.length){case 1:case 2:o=n.d,c=e.length;break;case 3:return nr[n.q][0];default:return nr[n.q][1]}break;case 104:switch(e.length){case 1:case 2:o=1+(n.H+11)%12,c=e.length;break;default:throw new Error("bad hour format: "+e)}break;case 72:switch(e.length){case 1:case 2:o=n.H,c=e.length;break;default:throw new Error("bad hour format: "+e)}break;case 77:switch(e.length){case 1:case 2:o=n.M,c=e.length;break;default:throw new Error("bad minute format: "+e)}break;case 115:if("s"!==e&&"ss"!==e&&".0"!==e&&".00"!==e&&".000"!==e)throw new Error("bad second format: "+e);return 0!==n.u||"s"!==e&&"ss"!==e?(a=r>=2?3===r?1e3:100:1===r?10:1,(i=Math.round(a*(n.S+n.u)))>=60*a&&(i=0),"s"===e?0===i?"0":""+i/a:(s=Kn(i,2+r),"ss"===e?s.substr(0,2):"."+s.substr(2,e.length-1))):Kn(n.S,e.length);case 90:switch(e){case"[h]":case"[hh]":o=24*n.D+n.H;break;case"[m]":case"[mm]":o=60*(24*n.D+n.H)+n.M;break;case"[s]":case"[ss]":o=60*(60*(24*n.D+n.H)+n.M)+Math.round(n.S+n.u);break;default:throw new Error("bad absolute time format: "+e)}c=3===e.length?1:2;break;case 101:o=l,c=1}return c>0?Kn(o,c):""}function _r(t){if(t.length<=3)return t;for(var e=t.length%3,n=t.substr(0,e);e!==t.length;e+=3)n+=(n.length>0?",":"")+t.substr(e,3);return n}var Sr=/%/g;function wr(t,e){var n,r=t.indexOf("E")-t.indexOf(".")-1;if(t.match(/^#+0.0E\+0$/)){if(0===e)return"0.0E+0";if(e<0)return"-"+wr(t,-e);var o=t.indexOf(".");-1===o&&(o=t.indexOf("E"));var s=Math.floor(Math.log(e)*Math.LOG10E)%o;if(s<0&&(s+=o),-1===(n=(e/Math.pow(10,s)).toPrecision(r+1+(o+s)%o)).indexOf("e")){var i=Math.floor(Math.log(e)*Math.LOG10E);for(-1===n.indexOf(".")?n=n.charAt(0)+"."+n.substr(1)+"E+"+(i-n.length+s):n+="E+"+(i-s);"0."===n.substr(0,2);)n=(n=n.charAt(0)+n.substr(2,o)+"."+n.substr(2+o)).replace(/^0+([1-9])/,"$1").replace(/^0+\./,"0.");n=n.replace(/\+-/,"-")}n=n.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function(t,e,n,r){return e+n+r.substr(0,(o+s)%o)+"."+r.substr(s)+"E"})}else n=e.toExponential(r);return t.match(/E\+00$/)&&n.match(/e[+-]\d$/)&&(n=n.substr(0,n.length-1)+"0"+n.charAt(n.length-1)),t.match(/E-/)&&n.match(/e\+/)&&(n=n.replace(/e\+/,"e")),n.replace("e","E")}var yr=/[0#?] (\?+)( ?)\/( ?)(\d+)/;var Er=/^([0#?]+)\.([0#?]+)/,br=/\).*[0#]/,vr=/\(###\) ###\\?-####/;function Cr(t){var e="";let n,r=t.length;for(var o=0;o!==r;++o)switch(n=t.charAt(o),n){case"#":break;case" ":e+=" ";break;case"0":e+="0";break;case"?":e+="?";break;default:e+=String.fromCharCode(cc)}return e}function xr(t,e){var n=Math.pow(10,e);return""+Math.round(t*n)/n}function Ir(t,e){var n=Math.pow(10,e);return Math.round(t*n)/n}function Ar(t,e){var n=t-Math.floor(t),r=Math.pow(10,e);return e<(""+Math.round(n*r)).length?0:Math.round(n*r)}function Rr(t,e,n){if(40===t.charCodeAt(0)&&!e.match(br)){var r=e.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");return n>=0?Rr("n",r,n):"("+Rr("n",r,-n)+")"}if(44===e.charCodeAt(e.length-1))return function(t,e,n){let r=e.length-1;for(;44===e.charCodeAt(r-1);)--r;return Nr(t,e.substr(0,r),n/Math.pow(10,3*(e.length-r)))}(t,e,n);if(-1!==e.indexOf("%"))return function(t,e,n){let r=e.replace(Sr,""),o=e.length-r.length;return Nr(t,r,n*Math.pow(10,2*o))+Jn("%",o)}(t,e,n);if(-1!==e.indexOf("E"))return wr(e,n);if(36===e.charCodeAt(0))return"$"+Rr(t,e.substr(" "===e.charAt(1)?2:1),n);var o,s,i,a,l=Math.abs(n),c=n<0?"-":"";if(e.match(/^00+$/))return c+tr(l,e.length);if(e.match(/^[#?]+$/))return"0"===(o=tr(n,0))&&(o=""),o.length>e.length?o:Cr(e.substr(0,e.length-o.length))+o;if(s=e.match(yr))return function(t,e,n){var r=parseInt(t[4],10),o=Math.round(e*r),s=Math.floor(o/r),i=o-s*r,a=r;return n+(0===s?"":""+s)+" "+(0===i?Jn(" ",t[1].length+1+t[4].length):Yn(i,t[1].length)+t[2]+"/"+t[3]+Kn(a,t[4].length))}(s,l,c);if(e.match(/^#+0+$/))return c+tr(l,e.length-e.indexOf("0"));if(s=e.match(Er)){i=Math.trunc(xr(n,s[2].length));var h=function(t){if(!isFinite(t))return 0;for(var e=1,n=0;Math.round(t*e)/e!==t;)e*=10,n++;return n}(a=Ir(Math.abs(i-n),s[2].length));return a=(a=""+Ir(a,h)).replace(/^0\./,""),o=qn(""+Math.abs(i),s[1])+"."+qn(""+a,s[2],!0),o=-1!==e.indexOf("0.")?o:o.replace(/^0\./,"."),n<0?"-"+o:o}if(s=(e=e.replace(/^#+([0.])/,"$1")).match(/^(0*)\.(#*)$/))return c+xr(l,s[2].length).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,s[1].length?"0.":".");if(s=e.match(/^#{1,3},##0(\.?)$/))return c+_r(tr(l,0));if(s=e.match(/^#,##0\.([#0]*0)$/))return n<0?"-"+Rr(t,e,-n):_r(""+(Math.floor(n)+function(t,e){return e<(""+Math.round((t-Math.floor(t))*Math.pow(10,e))).length?1:0}(n,s[1].length)))+"."+Kn(Ar(n,s[1].length),s[1].length);if(s=e.match(/^#,#*,#0/))return Rr(t,e.replace(/^#,#*,/,""),n);if(s=e.match(/^([0#]+)(\\?-([0#]+))+$/))return o=Xn(Rr(t,e.replace(/[\\-]/g,""),n)),i=0,Xn(Xn(e.replace(/\\/g,"")).replace(/[0#]/g,function(t){return i<o.length?o.charAt(i++):"0"===t?"0":""}));if(e.match(vr))return"("+(o=Rr(t,"##########",n)).substr(0,3)+") "+o.substr(3,3)+"-"+o.substr(6);var u="";if(s=e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(s[4].length,7),a=ar(l,Math.pow(10,i)-1,!1),o=""+c," "===(u=Nr("n",s[1],a[1])).charAt(u.length-1)&&(u=u.substr(0,u.length-1)+"0"),o+=u+s[2]+"/"+s[3],(u=Zn(a[2],i)).length<s[4].length&&(u=Cr(s[4].substr(s[4].length-u.length))+u),o+=u;if(s=e.match(/[#0?] ([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(Math.max(s[1].length,s[4].length),7),a=ar(l,Math.pow(10,i)-1,!0),c+Rr(t,e.substring(0,s.index+1),a[0])+" "+(a[1]?Yn(a[1],i)+s[2]+"/"+s[3]+Zn(a[2],i):Jn(" ",2*i+1+s[2].length+s[3].length));if(s=e.match(/^[#0?]+$/))return o=tr(n,0),e.length<=o.length?o:Cr(e.substr(0,e.length-o.length))+o;if(s=e.match(/^([#0?]+)\.([#0]+)$/)){o=""+n.toFixed(Math.min(s[2].length,10)).replace(/([^0])0+$/,"$1"),i=o.indexOf(".");var d=e.indexOf(".")-i,g=e.length-o.length-d;return Cr(e.substr(0,d)+o+e.substr(e.length-g))}if(s=e.match(/^00,000\.([#0]*0)$/))return i=Ar(n,s[1].length),n<0?"-"+Rr(t,e,-n):_r(function(t){return t<2147483647&&t>-2147483648?""+(t>=0?0|t:t-1|0):""+Math.floor(t)}(n)).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function(t){return"00,"+(t.length<3?Kn(0,3-t.length):"")+t})+"."+Kn(i,s[1].length);switch(e){case"###,##0.00":return Rr(t,"#,##0.00",n);case"###,###":case"##,###":case"#,###":var m=_r(tr(l,0));return"0"!==m?c+m:"";case"###,###.00":return Rr(t,"###,##0.00",n).replace(/^0\./,".");case"#,###.00":return Rr(t,"#,##0.00",n).replace(/^0\./,".")}throw new Error("unsupported format |"+e+"|")}function Mr(t,e){var n,r=t.indexOf("E")-t.indexOf(".")-1;if(t.match(/^#+0.0E\+0$/)){if(0===e)return"0.0E+0";if(e<0)return"-"+Mr(t,-e);var o=t.indexOf(".");-1===o&&(o=t.indexOf("E"));var s=Math.floor(Math.log(e)*Math.LOG10E)%o;if(s<0&&(s+=o),!(n=(e/Math.pow(10,s)).toPrecision(r+1+(o+s)%o)).match(/[Ee]/)){var i=Math.floor(Math.log(e)*Math.LOG10E);-1===n.indexOf(".")?n=n.charAt(0)+"."+n.substr(1)+"E+"+(i-n.length+s):n+="E+"+(i-s),n=n.replace(/\+-/,"-")}n=n.replace(/^([+-]?)(\d*)\.(\d*)[Ee]/,function(t,e,n,r){return e+n+r.substr(0,(o+s)%o)+"."+r.substr(s)+"E"})}else n=e.toExponential(r);return t.match(/E\+00$/)&&n.match(/e[+-]\d$/)&&(n=n.substr(0,n.length-1)+"0"+n.charAt(n.length-1)),t.match(/E-/)&&n.match(/e\+/)&&(n=n.replace(/e\+/,"e")),n.replace("e","E")}function Tr(t,e,n){if(40===t.charCodeAt(0)&&!e.match(br)){var r=e.replace(/\( */,"").replace(/ \)/,"").replace(/\)/,"");return n>=0?Tr("n",r,n):"("+Tr("n",r,-n)+")"}if(44===e.charCodeAt(e.length-1))return function(t,e,n){for(var r=e.length-1;44===e.charCodeAt(r-1);)--r;return Nr(t,e.substr(0,r),n/Math.pow(10,3*(e.length-r)))}(t,e,n);if(-1!==e.indexOf("%"))return function(t,e,n){var r=e.replace(Sr,""),o=e.length-r.length;return Nr(t,r,n*Math.pow(10,2*o))+Jn("%",o)}(t,e,n);if(-1!==e.indexOf("E"))return Mr(e,n);if(36===e.charCodeAt(0))return"$"+Tr(t,e.substr(" "===e.charAt(1)?2:1),n);var o,s,i,a,l=Math.abs(n),c=n<0?"-":"";if(e.match(/^00+$/))return c+Kn(l,e.length);if(e.match(/^[#?]+$/))return o=""+n,0===n&&(o=""),o.length>e.length?o:Cr(e.substr(0,e.length-o.length))+o;if(s=e.match(yr))return function(t,e,n){return n+(0===e?"":""+e)+Jn(" ",t[1].length+2+t[4].length)}(s,l,c);if(e.match(/^#+0+$/))return c+Kn(l,e.length-e.indexOf("0"));if(s=e.match(Er))return o=(""+n).replace(/^([^.]+)$/,"."+Cr(s[2])).replace(/\.$/,"."+Cr(s[2])),o=Kn(Math.abs(n),s[1].length)+o.replace(/\.(\d*)$/,function(t,e){return"."+e+Jn("0",Cr(s[2]).length-e.length)}),o=-1!==e.indexOf("0.")?o:o.replace(/^0\./,"."),n<0?"-"+o:o;if(e=e.replace(/^#+([0.])/,"$1"),s=e.match(/^(0*)\.(#*)$/))return c+(""+l).replace(/\.(\d*[1-9])0*$/,".$1").replace(/^(-?\d*)$/,"$1.").replace(/^0\./,s[1].length?"0.":".");if(s=e.match(/^#{1,3},##0(\.?)$/))return c+_r(""+l);if(s=e.match(/^#,##0\.([#0]*0)$/))return n<0?"-"+Tr(t,e,-n):_r(""+n)+"."+Jn("0",s[1].length);if(s=e.match(/^#,#*,#0/))return Tr(t,e.replace(/^#,#*,/,""),n);if(s=e.match(/^([0#]+)(\\?-([0#]+))+$/))return o=Xn(Tr(t,e.replace(/[\\-]/g,""),n)),i=0,Xn(Xn(e.replace(/\\/g,"")).replace(/[0#]/g,function(t){return i<o.length?o.charAt(i++):"0"===t?"0":""}));if(e.match(vr))return"("+(o=Tr(t,"##########",n)).substr(0,3)+") "+o.substr(3,3)+"-"+o.substr(6);var h="";if(s=e.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(s[4].length,7),a=ar(l,Math.pow(10,i)-1,!1),o=""+c," "===(h=Nr("n",s[1],a[1])).charAt(h.length-1)&&(h=h.substr(0,h.length-1)+"0"),o+=h+s[2]+"/"+s[3],(h=Zn(a[2],i)).length<s[4].length&&(h=Cr(s[4].substr(s[4].length-h.length))+h),o+=h;if(s=e.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/))return i=Math.min(Math.max(s[1].length,s[4].length),7),c+((a=ar(l,Math.pow(10,i)-1,!0))[0]||(a[1]?"":"0"))+" "+(a[1]?Yn(a[1],i)+s[2]+"/"+s[3]+Zn(a[2],i):Jn(" ",2*i+1+s[2].length+s[3].length));if(s=e.match(/^[#0?]+$/))return o=""+n,e.length<=o.length?o:Cr(e.substr(0,e.length-o.length))+o;if(s=e.match(/^([#0]+)\.([#0]+)$/)){o=""+n.toFixed(Math.min(s[2].length,10)).replace(/([^0])0+$/,"$1"),i=o.indexOf(".");var u=e.indexOf(".")-i,d=e.length-o.length-u;return Cr(e.substr(0,u)+o+e.substr(e.length-d))}if(s=e.match(/^00,000\.([#0]*0)$/))return n<0?"-"+Tr(t,e,-n):_r(""+n).replace(/^\d,\d{3}$/,"0$&").replace(/^\d*$/,function(t){return"00,"+(t.length<3?Kn(0,3-t.length):"")+t})+"."+Kn(0,s[1].length);switch(e){case"###,###":case"##,###":case"#,###":var g=_r(""+l);return"0"!==g?c+g:"";default:if(e.match(/\.[0#?]*$/))return Tr(t,e.slice(0,e.lastIndexOf(".")),n)+Cr(e.slice(e.lastIndexOf(".")))}throw new Error("unsupported format |"+e+"|")}function Nr(t,e,n){return(0|n)===n?Tr(t,e,n):Rr(t,e,n)}function Fr(t){var e=[],n=!1;const r=t.length;for(var o=0,s=0;o<r;++o)switch(t.charCodeAt(o)){case 34:n=!n;break;case 95:case 42:case 92:++o;break;case 59:e[e.length]=t.substr(s,o-s),s=o+1}if(e[e.length]=t.substr(s),!0===n)throw new Error("Format |"+t+"| unterminated string ");return e}var kr=/\[[HhMmSs\u0E0A\u0E19\u0E17]*\]/;function Or(t){for(var e=0,n="",r="",o=t.length;e<o;)switch(n=t.charAt(e)){case"G":er(t,e)&&(e+=6),e++;break;case'"':for(;34!==t.charCodeAt(++e)&&e<t.length;);++e;break;case"\\":case"_":e+=2;break;case"@":++e;break;case"B":case"b":if("1"===t.charAt(e+1)||"2"===t.charAt(e+1))return!0;case"M":case"D":case"Y":case"H":case"S":case"E":case"m":case"d":case"y":case"h":case"s":case"e":case"g":return!0;case"A":case"a":case"上":if("A/P"===t.substr(e,3).toUpperCase())return!0;if("AM/PM"===t.substr(e,5).toUpperCase())return!0;if("上午/下午"===t.substr(e,5).toUpperCase())return!0;++e;break;case"[":for(r=n;"]"!==t.charAt(e++)&&e<t.length;)r+=t.charAt(e);if(r.match(kr))return!0;break;case".":case"0":case"#":for(;e<t.length&&("0#?.,E+-%".indexOf(n=t.charAt(++e))>-1||"\\"===n&&"-"===t.charAt(e+1)&&"0#".indexOf(t.charAt(e+2))>-1););break;case"?":for(;t.charAt(++e)===n;);break;case"*":++e," "!==t.charAt(e)&&"*"!==t.charAt(e)||++e;break;case"(":case")":++e;break;case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":for(;e<t.length&&"0123456789".indexOf(t.charAt(++e))>-1;);break;default:++e}return!1}var Lr=/\[(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)\]/;function Dr(t,e){if(null==e)return!1;var n=parseFloat(e[2]);switch(e[1]){case"=":if(t===n)return!0;break;case">":if(t>n)return!0;break;case"<":if(t<n)return!0;break;case"<>":if(t!==n)return!0;break;case">=":if(t>=n)return!0;break;case"<=":if(t<=n)return!0}return!1}function Br(t,e,n){null==n&&(n=_t.EmptyObject);var r="";switch(typeof t){case"string":r="m/d/yy"===t&&n.dateNF?n.dateNF:t;break;case"number":null==(r=14===t&&n.dateNF?n.dateNF:(null!=n.table?n.table:or)[t])&&(r=n.table&&n.table[sr[t]]||or[sr[t]]),null==r&&(r=ir[t]||"General")}if(er(r,0))return fr(e,n);Wn(e)&&(e=dr(e,n.date1904));var o=function(t,e){var n=Fr(t),r=n.length,o=n[r-1].indexOf("@");if(-1!==o&&"\\"===n[r-1][o-1]&&(o=-1),r<4&&o>-1&&--r,n.length>4)throw new Error("We can't find right format for |"+n.join("|")+"|");if("number"!=typeof e)return[4,4===n.length||o>-1?n[n.length-1]:"@"];switch(n.length){case 1:n=o>-1?["General","General","General",n[0]]:[n[0],n[0],n[0],"@"];break;case 2:n=o>-1?[n[0],n[0],n[0],n[1]]:[n[0],n[1],n[0],"@"];break;case 3:n=o>-1?[n[0],n[1],n[0],n[2]]:[n[0],n[1],n[2],"@"]}var s=e>0?n[0]:e<0?n[1]:n[2];if(-1===n[0].indexOf("[")&&-1===n[1].indexOf("["))return[r,s];if(null!=n[0].match(/\[[=<>]/)||null!=n[1].match(/\[[=<>]/)){var i=n[0].match(Lr),a=n[1].match(Lr);return Dr(e,i)?[r,n[0]]:Dr(e,a)?[r,n[1]]:[r,n[null!=i&&null!=a?2:1]]}return[r,s]}(r,e);if(er(o[1]))return fr(e,n);if(!0===e)e="TRUE";else if(!1===e)e="FALSE";else if(""===e||null==e)return"";return function(t,e,n,r){var o,s,i,a=[],l="",c=0,h="",u="t",d="H";let g=t.length;for(;c<g;)switch(h=t.charAt(c)){case"G":if(!er(t,c))throw new Error("unrecognized character "+h+" in "+t);a[a.length]={t:"G",v:"General"},c+=7;break;case'"':for(l="";34!==(i=t.charCodeAt(++c))&&c<t.length;)l+=String.fromCharCode(i);a[a.length]={t:"t",v:l},++c;break;case"\\":var m=t.charAt(++c),f="("===m||")"===m?m:"t";a[a.length]={t:f,v:m},++c;break;case"@":a[a.length]={t:"T",v:e},++c;break;case"B":case"b":if("1"===t.charAt(c+1)||"2"===t.charAt(c+1)){if(null==o&&null==(o=lr(e,n,"2"===t.charAt(c+1))))return"";a[a.length]={t:"X",v:t.substr(c,2)},u=h,c+=2;break}case"M":case"D":case"Y":case"H":case"S":case"E":h=h.toLowerCase();case"m":case"d":case"y":case"h":case"s":case"e":case"g":if(e<0)return"";if(null==o&&null==(o=lr(e,n)))return"";for(l=h;++c<t.length&&t.charAt(c).toLowerCase()===h;)l+=h;"m"===h&&"h"===u.toLowerCase()&&(h="M"),"h"===h&&(h=d),a[a.length]={t:h,v:l},u=h;break;case"A":case"a":case"上":var p={t:h,v:h};if(null==o&&(o=lr(e,n)),"A/P"===t.substr(c,3).toUpperCase()?(null!=o&&(p.v=o.H>=12?"P":"A"),p.t="T",d="h",c+=3):"AM/PM"===t.substr(c,5).toUpperCase()?(null!=o&&(p.v=o.H>=12?"PM":"AM"),p.t="T",c+=5,d="h"):"上午/下午"===t.substr(c,5).toUpperCase()?(null!=o&&(p.v=o.H>=12?"下午":"上午"),p.t="T",c+=5,d="h"):(p.t="t",++c),null==o&&"T"===p.t)return"";a[a.length]=p,u=h;break;case"[":for(l=h;"]"!==t.charAt(c++)&&c<t.length;)l+=t.charAt(c);if("]"!==l.slice(-1))throw new Error('unterminated "[" block: |'+l+"|");if(l.match(kr)){if(null==o&&null==(o=lr(e,n)))return"";a[a.length]={t:"Z",v:l.toLowerCase()},u=l.charAt(1)}else l.indexOf("$")>-1&&(l=(l.match(/\$([^-[\]]*)/)||[])[1]||"$",Or(t)||(a[a.length]={t:"t",v:l}));break;case".":if(null!=o){for(l=h;++c<t.length&&"0"===(h=t.charAt(c));)l+=h;a[a.length]={t:"s",v:l};break}case"0":case"#":for(l=h;++c<t.length&&"0#?.,E+-%".indexOf(h=t.charAt(c))>-1;)l+=h;a[a.length]={t:"n",v:l};break;case"?":for(l=h;t.charAt(++c)===h;)l+=h;a[a.length]={t:h,v:l},u=h;break;case"*":if(++c,!(l=t.charAt(c)))throw new Error("no character specified for repeat function: "+t);a[a.length]={t:"R",v:l},++c;break;case"_":if(++c,!(l=t.charAt(c)))throw new Error("no character specified for spacing function: "+t);a[a.length]={t:"S",v:l},++c;break;case"(":case")":a[a.length]={t:1===r?"t":h,v:h},++c;break;case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":for(l=h;c<t.length&&"0123456789".indexOf(t.charAt(++c))>-1;)l+=t.charAt(c);a[a.length]={t:"D",v:l};break;case" ":a[a.length]={t:h,v:h},++c;break;case"$":a[a.length]={t:"t",v:"$"},++c;break;default:if(-1===",$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(h))throw new Error("unrecognized character "+h+" in "+t);a[a.length]={t:"t",v:h},++c}var _,S=0,w=0;for(c=a.length-1,u="t";c>=0;--c)switch(a[c].t){case"h":case"H":a[c].t=d,u="h",S<1&&(S=1);break;case"s":(_=a[c].v.match(/\.0+$/))&&(w=Math.max(w,_[0].length-1)),S<3&&(S=3);case"d":case"y":case"M":case"e":u=a[c].t;break;case"m":"s"===u&&(a[c].t="M",S<2&&(S=2));break;case"X":break;case"Z":S<1&&a[c].v.match(/[Hh]/)&&(S=1),S<2&&a[c].v.match(/[Mm]/)&&(S=2),S<3&&a[c].v.match(/[Ss]/)&&(S=3)}switch(S){case 0:break;case 1:o.u>=.5&&(o.u=0,++o.S),o.S>=60&&(o.S=0,++o.M),o.M>=60&&(o.M=0,++o.H);break;case 2:o.u>=.5&&(o.u=0,++o.S),o.S>=60&&(o.S=0,++o.M)}var y,E="";for(g=a.length,c=0;c<g;++c)switch(a[c].t){case"t":case"T":case" ":case"D":break;case"X":a[c].v="",a[c].t=";";break;case"d":case"m":case"y":case"h":case"H":case"M":case"s":case"e":case"b":case"Z":a[c].v=pr(a[c].t.charCodeAt(0),a[c].v,o,w),a[c].t="t";break;case"n":case"?":for(y=c+1;null!=a[y]&&("?"===(h=a[y].t)||"D"===h||(" "===h||"t"===h)&&null!=a[y+1]&&("?"===a[y+1].t||"t"===a[y+1].t&&"/"===a[y+1].v)||"("===a[c].t&&(" "===h||"n"===h||")"===h)||"t"===h&&("/"===a[y].v||" "===a[y].v&&null!=a[y+1]&&"?"===a[y+1].t));)a[c].v+=a[y].v,a[y]={v:"",t:";"},++y;E+=a[c].v,c=y-1;break;case"G":a[c].t="t",a[c].v=fr(e,n)}var b,v,C="";if(E.length>0){40===E.charCodeAt(0)?(b=e<0&&45===E.charCodeAt(0)?-e:e,v=Nr("n",E,b)):(v=Nr("n",E,b=e<0&&r>1?-e:e),b<0&&a[0]&&"t"===a[0].t&&(v=v.substr(1),a[0].v="-"+a[0].v)),y=v.length-1;var x=a.length;for(g=a.length,c=0;c<g;++c)if(null!=a[c]&&"t"!==a[c].t&&a[c].v.indexOf(".")>-1){x=c;break}var I=g;if(x===g&&-1===v.indexOf("E")){for(c=a.length-1;c>=0;--c)null!=a[c]&&-1!=="n?".indexOf(a[c].t)&&(y>=a[c].v.length-1?(y-=a[c].v.length,a[c].v=v.substr(y+1,a[c].v.length)):y<0?a[c].v="":(a[c].v=v.substr(0,y+1),y=-1),a[c].t=a[c].v.indexOf("?")>=0?"N":"t",I=c);y>=0&&I<a.length&&(a[I].v=v.substr(0,y+1)+a[I].v)}else if(x!==a.length&&-1===v.indexOf("E")){for(y=v.indexOf(".")-1,c=x;c>=0;--c)if(null!=a[c]&&-1!=="n?".indexOf(a[c].t)){for(s=a[c].v.indexOf(".")>-1&&c===x?a[c].v.indexOf(".")-1:a[c].v.length-1,C=a[c].v.substr(s+1);s>=0;--s)y>=0&&("0"===a[c].v.charAt(s)||"#"===a[c].v.charAt(s)||"?"===a[c].v.charAt(s))&&(C=v.charAt(y--)+C);a[c].v=C,a[c].t=C.indexOf("?")>=0?"N":"t",I=c}for(y>=0&&I<a.length&&(a[I].v=v.substr(0,y+1)+a[I].v),y=v.indexOf(".")+1,c=x;c<a.length;++c)if(null!=a[c]&&(-1!=="n?(".indexOf(a[c].t)||c===x)){for(s=a[c].v.indexOf(".")>-1&&c===x?a[c].v.indexOf(".")+1:0,C=a[c].v.substr(0,s);s<a[c].v.length;++s)y<v.length&&(C+=v.charAt(y++));a[c].v=C,a[c].t=C.indexOf("?")>=0?"N":"t",I=c}}}for(c=0;c<g;++c)null!=a[c]&&"n?".indexOf(a[c].t)>-1&&(b=r>1&&e<0&&c>0&&"-"===a[c-1].v?-e:e,a[c].v=Nr(a[c].t,a[c].v,b),a[c].t=a[c].v.indexOf("?")>=0?"N":"t");var A="";for(g=a.length,c=0;c<g;c++)if("R"===a[c].t)n?.onRepeatChar?.(A.length,a[c].v);else if("S"===a[c].t)n?.onSpacingChar?.(A.length,a[c].v),A+=n?.spacingCharacter??" ";else if("N"===a[c].t){C=a[c].v;for(var R=0;R<C.length;R++)"?"===(h=C[R])&&(n?.onDigitChar?.(A.length,h),h=n?.digitCharacter??" "),A+=h}else null!=a[c]&&(A+=a[c].v);return A}(o[1],e,n,o[0])}function zr(t,e){if("number"!=typeof e){e=+e||-1;for(var n=0;n<392;++n)if(void 0!==or[n]){if(or[n]===t){e=n;break}}else e<0&&(e=n);e<0&&(e=391)}return or[e]=t,e}const Pr={format:Br,dateNumLocal:dr,load:zr,split_fmt:Fr,_table:or,load_table:function(t){for(var e=0;392!==e;++e)void 0!==t[e]&&zr(t[e],e)},parse_date_code:lr,is_date:Or,get_table:function(){return Pr._table=or}},jr="\\s*([-]?[0-9e]*[.]?[0-9]+)",Hr=new RegExp(`^rgb\\(${jr},${jr},${jr}\\)$`),Vr=new RegExp(`^rgba\\(${jr},${jr},${jr},${jr}\\)$`),$r=new RegExp(`^lrgb\\(${jr},${jr},${jr}\\)$`),Ur=new RegExp(`^lrgba\\(${jr},${jr},${jr},${jr}\\)$`),Gr=new RegExp(`^hsl\\(${jr},${jr},${jr}\\)$`),Wr=new RegExp(`^hsla\\(${jr},${jr},${jr},${jr}\\)$`),qr=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),Jr=new RegExp(/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/),Xr=new RegExp("^index(\\d+)$","i"),Kr=(t,e,n)=>[parseFloat(t),parseFloat(e),parseFloat(n)],Yr=(t,e=255)=>{const n=[...t];for(var r=0;r<t.length;r++)n[r]=t[r]/e;return n},Zr=(t,e=0)=>{const n=[...t];for(var r=0;r<t.length;r++)_t.roundAccurately(t[r],e+8)%1==.5?n[r]=Math.floor(t[r]):n[r]=_t.roundAccurately(t[r],e);return n},Qr=(t,e=!0)=>{const n=[...t],r=e?1:255;for(var o=0;o<t.length;o++)n[o]=Math.max(0,Math.min(r,t[o]));return n},to=t=>Math.max(0,Math.min(1,t)),eo=t=>((t%=360)<0&&(t-=360),t),no=t=>{const e=[...t];for(var n=0;n<t.length;n++)e[n]=oo(t[n]);return e},ro=t=>{const e=[...t];for(var n=0;n<t.length;n++)e[n]=so(t[n]);return e},oo=t=>t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4),so=t=>t<.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,io=t=>{let e=t[0],n=t[1],r=t[2];e%=360,e/=360,n/=100,r/=100;let o=r<.5?r*(1+n):r+n-n*r,s=2*r-o;return[Math.max(0,ao(s,o,e+1/3)),Math.max(0,ao(s,o,e)),Math.max(0,ao(s,o,e-1/3))]},ao=(t,e,n)=>(n<0&&(n+=1),n>1&&(n-=1),6*n<1?t+6*(e-t)*n:2*n<1?e:3*n<2?t+6*(e-t)*(2/3-n):t),lo=t=>{let e=t[0],n=t[1],r=t[2],o=Math.min(e,Math.min(n,r)),s=Math.max(e,Math.max(n,r)),i=0;s===o?i=0:s===e?i=(60*(n-r)/(s-o)+360)%360:s===n?i=60*(r-e)/(s-o)+120:s===r&&(i=60*(e-n)/(s-o)+240);const a=(s+o)/2;let l=0;return l=s===o?0:a<=.5?(s-o)/(s+o):(s-o)/(2-s-o),[i,100*l,100*a]},co=0,ho=1,uo=2,go=0,mo=1,fo=2,po=0,_o=1,So=2,wo=(t,e)=>{let n=e/100;return((t,e)=>{let n=no(t);n[0]=e(n[0],n),n[1]=e(n[1],n),n[2]=e(n[2],n);let r=ro(n);return r=Qr(r),r})(t,(t,e)=>t*n)},yo=2.55,Eo=(t,e)=>{const n=lo(t),r=n[2],o=_t.roundAccurately((s=r,(i=e)>0?(s*yo*(1-i)+(255-255*(1-i)))/yo:i<0?s*yo*(1+i)/yo:s),3);var s,i;n[2]=o;let a=io(n);return a=Qr(a),a},bo=(t,e)=>{let n=no(t),r=e/100;for(var o=0;o<3;o++)n[o]=n[o]*r+(1-r);let s=ro(n);return s=Qr(s),s},vo=(t,e,n)=>{let r=lo(e),o=n/1;t===co&&(o=eo(n)),r[t]=o;let s=io(r);return s=Qr(s),s},Co=(t,e,n)=>{let r=lo(e);if(t===co){let t=n/360;r[co]=360*(r[co]/360+t),r[co]%=360,r[co]<0&&(r[co]-=360)}else{let e=n/.1;r[t]=.1*(r[t]/.1+e)}let o=io(r);return o=Qr(o),o},xo=(t,e,n)=>{let r=lo(e),o=n/100;r[t]=r[t]*o,t===co&&(r[co]=eo(r[co]));let s=io(r);return s=Qr(s),s},Io=(t,e,n,r)=>{let o=no(e),s=n/100;r===po?o[t]=s:r===_o?o[t]+=s:r===So&&(o[t]*=s);let i=ro(o);return i=Qr(i),i},Ao=t=>{let e=no(t),n=.213*e[go]+.715*e[mo]+.072*e[fo];e[0]=n,e[1]=n,e[2]=n;let r=ro(e);return r=Qr(r),r},Ro=t=>{let e=lo(t);e[co]+=180,e[co]%=360,e[co]<0&&(e[co]-=360);let n=io(e);return n=Qr(n),n},Mo=(t,e=!0)=>{let n=e?no(t):[...t];const r=e?1:255;return n[0]=r-n[0],n[1]=r-n[1],n[2]=r-n[2],e&&(n=ro(n)),n=Qr(n,e),n},To=t=>{const e=[0,0,0];e[0]=so(t[0]),e[1]=so(t[1]),e[2]=so(t[2]);return Qr(e)},No=t=>{const e=[0,0,0];e[0]=oo(t[0]),e[1]=oo(t[1]),e[2]=oo(t[2]);return Qr(e)},Fo=(t,e,n,r=null)=>{const o=t=>{let e=t.toString(16);return 1===e.length?"0"+e:e};return(null===r?"":o(Math.round(255*r)))+o(Number(t)).toUpperCase()+o(Number(e)).toUpperCase()+o(Number(n)).toUpperCase()},ko=.2126,Oo=.7152,Lo=.0722;var Do;(t=>{t.RGBA=class{constructor(t,e,n,r=1){this._private={red:t,green:e,blue:n,alpha:r}}get red(){return this._private.red}get green(){return this._private.green}get blue(){return this._private.blue}get alpha(){return this._private.alpha??1}toString(t=!0){return t&&null!==this._private.alpha?`rgba(${this.red},${this.green},${this.blue},${this.alpha})`:`rgb(${this.red},${this.green},${this.blue})`}isEqual(t){return!!t&&(t.red===this.red&&(t.green===this.green&&(t.blue===this.blue&&t.alpha===this.alpha)))}isAlmostEqual(t){if(!t)return!1;const e=1.5;return!(Math.abs(t.red-this.red)>e)&&(!(Math.abs(t.green-this.green)>e)&&(!(Math.abs(t.blue-this.blue)>e)&&!(Math.abs(t.alpha-this.alpha)>e)))}};t.HSLA=class{constructor(t,e,n,r){this._private={hue:t,sat:e,lum:n,alpha:r}}get hue(){return this._private.hue}get sat(){return this._private.sat}get lum(){return this._private.lum}get alpha(){return this._private.alpha??1}toString(t=!0){return t&&null!==this._private.alpha?`hsla(${this.hue},${this.sat},${this.lum},${this.alpha})`:`hsl(${this.hue},${this.sat},${this.lum})`}isEqual(t){return!!t&&(t.hue===this.hue&&(t.sat===this.sat&&(t.lum===this.lum&&t.alpha===this.alpha)))}isAlmostEqual(t){if(!t)return!1;const e=1.5;return!(Math.abs(t.hue-this.hue)>e)&&(!(Math.abs(t.sat-this.sat)>e)&&(!(Math.abs(t.lum-this.lum)>e)&&!(Math.abs(t.alpha-this.alpha)>e)))}};class e extends t.RGBA{toString(t=!0){return t&&null!==this._private.alpha?"#"+Fo(this.red,this.green,this.blue,this.alpha??1).toUpperCase():"#"+Fo(this.red,this.green,this.blue).toUpperCase()}}t.HEX=e})(Do||(Do={}));const Bo=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,zo=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,Po=function(t){if(!t)return null;t=t.replace(Bo,function(t,e,n,r){return e+e+n+n+r+r});let e=zo.exec(t);return e?new Do.RGBA(parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)):null},jo=["000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","000000","FFFFFF","FF0000","00FF00","0000FF","FFFF00","FF00FF","00FFFF","800000","008000","000080","808000","800080","008080","C0C0C0","808080","9999FF","993366","FFFFCC","CCFFFF","660066","FF8080","0066CC","CCCCFF","000080","FF00FF","FFFF00","00FFFF","800080","800000","008080","0000FF","00CCFF","CCFFFF","CCFFCC","FFFF99","99CCFF","FF99CC","CC99FF","FFCC99","3366FF","33CCCC","99CC00","FFCC00","FF9900","FF6600","666699","969696","003366","339966","003300","333300","993300","993366","333399","333333"],Ho=new Map;for(let t=0;t<jo.length;t++)Ho.set(t,Po(jo[t]));Ho.set(-4105,null),Ho.set(-4142,null),Ho.set(64,Po("000000")),Ho.set(65,Po("FFFFFF")),Ho.set(81,Po("FFFFFF"));const Vo=t=>Ho.get(t),$o={General:"General",Number:"Number",Currency:"Currency",Accounting:"Accounting",ShortDate:"Short Date",LongDate:"Long Date",MediumDate:"Medium Date",ShortTime:"Short Time",MediumTime:"Medium Time",LongTime:"Long Time",Comma:"Comma",Percentage:"Percentage",Fraction:"Fraction",Scientific:"Scientific",Text:"Text",Special:"Special",Custom:"Custom"};let Uo=null;const Go=()=>Uo||(Uo=Intl.DateTimeFormat().resolvedOptions().locale??"en-US",Uo),Wo=/^\[\$-(.*?)\]/i,qo=/^[0-9a-fA-F]+$/,Jo=Pr.split_fmt,Xo=(t,e,n)=>{const r=Wo.exec(t);let o=Go();if(r&&r[1]){let t=r[1];qo.test(t)||t.includes("-")}if(Yo[t]&&(t=Yo[t]),"number"==typeof e){const r=Ko(t,e,{locale:o,...n});if(null!==r)return r.fmt}return Pr.format(t,e,n)},Ko=(t,e,n)=>{if("number"!=typeof e)return null;const r=ys(e,n?.date1904??!1),o=n?.locale??Go();let s=!1,i=t,a=-1;if(-1!==(a=i.indexOf("Short Date"))){const t=new Intl.DateTimeFormat(o).format(r);i=i.substring(0,a)+t+i.substring(a+10),s=!0}if(-1!==(a=i.indexOf("Medium Date"))){const t=Pr.format(Pr.get_table()[15],e,n);i=i.substring(0,a)+t+i.substring(a+11),s=!0}if(-1!==(a=i.indexOf("Long Date"))){const t=new Intl.DateTimeFormat(o,{dateStyle:"full"}).format(r);i=i.substring(0,a)+t+i.substring(a+9),s=!0}if(-1!==(a=i.indexOf("Short Time"))){const t=Pr.format(Pr.get_table()[20],e,n);i=i.substring(0,a)+t+i.substring(a+10),s=!0}if(-1!==(a=i.indexOf("Medium Time"))){const t=Pr.format(Pr.get_table()[18],e,n);i=i.substring(0,a)+t+i.substring(a+11),s=!0}if(-1!==(a=i.indexOf("Long Time"))){const t=new Intl.DateTimeFormat(o,{timeStyle:"medium"}).format(r);i=i.substring(0,a)+t+i.substring(a+9),s=!0}return s?{fmt:i,date:r}:null},Yo=Object.freeze({"General Number":"General","General Date":"m/d/yyyy h:mm","Medium Date":Pr.get_table()[15],"Medium Time":Pr.get_table()[18],"Short Time":Pr.get_table()[20],Currency:'"$"#,##0.00_);[Red]\\("$"#,##0.00\\)',Fixed:Pr.get_table()[2],Standard:Pr.get_table()[4],Percent:Pr.get_table()[10],Scientific:Pr.get_table()[11],"Yes/No":'"Yes";"Yes";"No";@',"True/False":'"True";"True";"False";@',"On/Off":'"Yes";"Yes";"No";@'}),Zo=Object.freeze({black:0,white:1,red:2,green:3,blue:4,yellow:5,magenta:6,cyan:7}),Qo=t=>{let e=null;if((t=t.toLowerCase()).startsWith("color")){const n=parseInt(t.substring(5));n>=0&&n<=56&&(e=`Index${n+7}`)}if(!e){const n=Zo[t];void 0!==n&&(e=Vo(n).toString())}return e},ts="=",es="<>",ns=">",rs="<",os=">=",ss="<=",is=new Map;is.set(ts,(t,e)=>t===e),is.set(es,(t,e)=>t!==e),is.set(ns,(t,e)=>t>e),is.set(rs,(t,e)=>t<e),is.set(os,(t,e)=>t>=e),is.set(ss,(t,e)=>t<=e);const as=/(Black|Blue|Cyan|Green|Magenta|Red|White|Yellow|Color[0-9]+)/i,ls=/(=|>[=]?|<[>=]?)(-?\d+(?:\.\d*)?)/i,cs=/\[(.*?)\]/g,hs=(t,e)=>{const n={color:null,condition:null};let r=null,o=new RegExp(cs);for(;null!==(r=o.exec(t));){let e=!1,o=as.exec(r[1]);if(o){if(e=!0,n.color)throw new Error(`format error, two colors specified: '${t}' and '${n.color}'.`);n.color=Qo(o[1]),n.color||console.warn("Unable to parse LegacyColor",o[1])}let s=ls.exec(r[1]);if(s){if(e=!0,n.condition)throw new Error(`Format error, two conditions specified: ' ${t}'`);n.condition={op:s[1],comp:parseFloat(s[2])}}if(!e)return n}return n.condition||(n.condition=e),n},us=(t,e)=>{let n=(t=>{const e=[];if(!t)return e;const n=t.split(";");for(let t=0;t<n.length;t++){let r=null;2===n.length?0===t?r={op:os,comp:0}:1===t&&(r={op:rs,comp:0}):3!==n.length&&4!==n.length||(r=0===t?{op:ns,comp:0}:1===t?{op:rs,comp:0}:2===t?{op:ts,comp:0}:null);const o=n[t],s=hs(o,r);e.push({format:o,colorAndCondition:s})}return e})(t),r=n[0].colorAndCondition;if(1===n.length&&r&&!r.condition&&r.color)return r.color;for(let t=0;t<n.length;t++){r=n[t].colorAndCondition;let o=r?.condition??void 0;if(3===t)return"string"==typeof e&&r?.color?r.color:null;if(o&&"number"==typeof e){if(is.get(o.op)(e,o.comp))return r?.color??null}}},ds=t=>{if(t===$o.MediumDate||t===$o.LongDate||t===$o.ShortDate||t===$o.MediumTime||t===$o.LongTime||t===$o.ShortTime)return!0},gs=(t,e)=>t===e?0:ds(t)?1:ds(e)?-1:t===$o.Percentage?1:e===$o.Percentage?-1:t===$o.Currency||t===$o.Accounting?1:e===$o.Currency||e===$o.Accounting?-1:0,ms=t=>(t instanceof Date||"[object Date]"===Object.prototype.toString.call(t))&&!isNaN(t.getTime()),fs=(t,e,n)=>{return"month"===n||"months"===n||"m"===n?(r=t,12*((o=e).getUTCFullYear()-r.getUTCFullYear())+(o.getUTCMonth()-r.getUTCMonth())+(o.getUTCDate()-r.getUTCDate()<0?-1:0)):"year"===n||"years"===n||"y"===n?((t,e)=>Math.abs(e.getFullYear()-t.getFullYear()))(t,e):"day"===n||"days"===n||"d"===n?((t,e)=>Math.floor((Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())-Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()))/864e5))(t,e):void console.warn("invalid unit"+n);var r,o},ps="d",_s="m",Ss="y",ws=(t,e,n)=>{if("month"===n||"months"===n||"m"===n){const n=new Date(t.getTime());return new Date(n.setMonth(n.getMonth()+e))}if("year"===n||"years"===n||"y"===n){const n=new Date(t.getTime());return n.setFullYear(n.getFullYear()+e),n}if("day"===n||"days"===n||"d"===n){const n=new Date(t.getTime());return n.setDate(n.getDate()+e),n}if("hour"===n||"hours"===n||"h"===n){const n=new Date(t.getTime());return n.setHours(n.getHours()+e),n}return console.warn("invalid unit"+n),null},ys=(t,e=!1)=>{let n=Pr.parse_date_code(t,{date1904:e});return n?new Date(n.y,n.m-1,n.d,n.H,n.M,n.S,Math.round(1e3*n.u)):null},Es=(t,e=!1)=>isNaN(t)?null:Pr.dateNumLocal(t,e),bs=new class extends kn{parse(t,e,n){const r=t=>t-1;switch(e){case"M":return Tn(Nn(Cn,t),r);case"MM":return Tn(Fn(2,t),r);case"Mo":return Tn(n.ordinalNumber(t,{unit:"month"}),r);case"MMM":return n.month(t,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(t,{width:"narrow",context:"formatting"});default:return n.month(t,{width:"wide",context:"formatting"})}}},vs=(t=>{let e=t,n=[];for(let t=0;t<e.length;t++){let r=e[t][0].indexOf("yyy")>-1,o=e[t][0].indexOf(".")>-1,s=e[t][0].indexOf("-")>-1;n.push({parseFormat:e[t][0],numberFormat:e[t][1],todaysYear:!r,windowYear:!0,containsDot:o,containsDash:s}),r&&n.push({parseFormat:e[t][0].replace(/yyy/g,"yyyy"),numberFormat:e[t][1],todaysYear:!1,windowYear:!1,containsDot:o,containsDash:s})}return n})([["MM-d","d-mmm"],["MM-yyy","mmm-yy"],["M-yyy","mmm-yy"],["M-d-yyy","m/d/yyyy"],["yyy-M-d","m/d/yyyy"],["yyy-d-M","m/d/yyyy"],["d.MMM","d-mmm"],["d.MMMM","d-mmm"],["d.MMM.yyy","d-mmm-yy"],["d.MMMM.yyy","d-mmm-yy"],["MMM.d","d-mmm"],["MMMM.d","d-mmm"],["MMM.yyy","mmm-yy"],["MMMM.yyy","mmm-yy"],["MMM dd, yyy","d-mmm-yy"],["MMMM dd, yyy","d-mmm-yy"],["EEE, MMMM dd, yyy","[$-x-sysdate]ddd, mmmm dd, yyyy"],["EEEE, MMMM dd, yyy","[$-x-sysdate]dddd, mmmm dd, yyyy"]]),Cs={year:0,month:1,day:0,hour:0,minute:0,second:0,millis:0},xs=(t,e=!1)=>{const n={...Cs,...t};return n.year=e?1904:1900,n.dow=-1,n.oaDateTime=((t,e=!1)=>{if(!t)return null;let n=t.day,r=t.hour;r>24&&(n+=Math.floor(r/24),r%=24),n>60&&--n;const o=new Date(t.year,t.month-1,n,r,t.minute,t.second,t.millis);return Es(o,e)})(n,e),n},Is=new RegExp("([0-9]{1,2})\\s*(P[M]?|A[M]?)\\s*$","i"),As=new RegExp("([0-9]+)\\s*\\:$","i"),Rs=new RegExp("(\\s*[0-9]{1,2})\\s+(P[M]?|A[M]?)\\s*$","i"),Ms=new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]+)?\\s*\\:","i"),Ts=new RegExp("(\\s*[0-9]{1,4})\\s*([\\.]{1}\\s*[0-9]*)?\\s*$","i"),Ns=(t,e=!1,n=!1)=>{if(!t||t.trim().length<2||-1===t.indexOf(":")&&null===t.match(Rs))return null;let r=null,o=null,s=null,i=!1,a=!1,l="h:mm AM/PM",c=[],h=t,u=null;do{let t=h.indexOf(":");-1===t?(c.push(h),h=null):(c.push(h.substring(0,t+1)),h=h.substring(t+1,h.length))}while(c.length<3&&h&&h.length>0);if(h?.length>0)return null;const d=(t,e,n)=>{let i=t.match(e);if(!i)return null;null===u&&(u=t.substring(0,i.index));let a=parseInt(i[1]);if(i[2]&&null===s){if(n){let t=parseFloat(i[2].substring(1,i[2].length));isNaN(t)||(o=t)}let t=parseFloat(i[2]);isNaN(t)||(r=t),s=n}return a},g=(t,e)=>{let n=t.match(e);if(!n||3!==n.length)return null;null===u&&(u=t.substring(0,n.index)),i=!0;let r=parseInt(n[1]);return a="p"===n[2].charAt(0)||"P"===n[2].charAt(0),r};0===c[c.length-1].trim().length&&c.pop();const m=[];if(c.length>0){let t=d(c[0],As,!1);if(null===t&&(t=g(c[0],Is)),null===t)return null;m.push(t)}if(c.length>2){let t=d(c[1],Ms,!0);if(null===t&&(t=g(c[0],Rs)),null===t)return null;m.push(t)}if(c.length>1){const t=c[c.length-1];let e=d(t,Ms,!1);if(null===e&&(e=d(t,Ts,!1)),null===e&&(e=g(t,Rs)),null===e)return null;m.push(e)}if(null!==u&&u.length>0&&!n)return null;if(!0===s&&(2===m.length&&m.splice(1,0,0),m[2]=o||0),i){if(m[0]>12)return null;if(m[1]>=60)return null;if(m[2]>=60)return null;12===m[0]?m[0]=a?12:0:a&&(m[0]+=12)}else l=c.length>2?"h:mm:ss":"h:mm",m[0]>23&&(l="[h]:mm:ss"),null!==r&&(l="mm:ss.0"),m[1]>=60&&(l="General"),m[2]>=60&&(l="General");"General"!==l&&(1===m.length&&m.push(0),2===m.length&&(null===r?m.push(0):m.unshift(0)));let f={hour:m[0]??0,minute:m[1]??0,second:m[2]??0,millis:1e3*(r??0)};return{numberFormat:l,parsed:xs(f,e),leadingText:u}},Fs={},ks=(t,e=!1,n=null)=>{const r=n??Date.now(),o=new Date(r).getFullYear();let s=t.trim().replaceAll(/\s+/g," ");s=s.replaceAll(/\s*([-/])\s*/g,"$1");let i=s.replaceAll(/[-/ ]/g,"."),a=s.replaceAll(/[/]/g,"-");const l=Bn.M;Bn.M=bs;for(let t=0;t<vs.length;t++){let n=s;vs[t].containsDot?n=i:vs[t].containsDash&&(n=a);let c=Un(n,vs[t].parseFormat,r,Fs),h=Pr.dateNumLocal(c,e);if(ms(c)&&(vs[t].windowYear||h>0)){if(vs[t].windowYear){let t=c.getFullYear()<=29?2e3+c.getFullYear():1900+c.getFullYear();c.setFullYear(t)}if(vs[t].todaysYear&&c.setFullYear(o),h=Pr.dateNumLocal(c,e),vs[t].parseFormat.indexOf("EEE")>-1){const t=Xo("ddd",h,{date1904:e});if(!n.toLowerCase().includes(t.toLowerCase()))return null}let r=vs[t].numberFormat;return Bn.M=l,{asOADate:h,asJSDate:c,numberFormat:r}}}return Bn.M=l,null};function Os(t){if(!t)return!1;let e=t.replaceAll(/\[([^)]+)\]/g,"").toLowerCase();return e=e.replaceAll(/".*"/g,""),e=e.replaceAll(/\\./g,""),e=e.replace(/[_*]./g,""),!e.includes("time")&&!!(e.includes("d")||e.includes("m")&&!e.includes("h")&&!e.includes("s")||e.includes("y")||"short date"===e||"medium date"===e||"long date"===e)}function Ls(t){if(!t)return!1;let e=t.replaceAll(/\[([^)]+)\]/g,"").toLowerCase();return e=e.replaceAll(/".*"/g,""),e=e.replaceAll(/\\./g,""),e=e.replace(/[_*]./g,""),!e.includes("date")&&!(!e.includes("h")&&!e.includes("s")&&"short time"!==e&&"medium time"!==e&&"long time"!==e)}var Ds,Bs,zs,Ps;(Bs=Ds||(Ds={})).SmallCaps={None:"none",Small:"small",All:"all"},Bs.StrikeStyle={None:"none",Single:"single",Double:"double"},(Ps=zs||(zs={})).TabStop=class{},Ps.HorizontalAlignment={General:"general",Left:"left",Center:"center",Right:"right",Justify:"justify",Distributed:"distributed",CenterContinuous:"centerContinuous",Fill:"fill"},Ps.VerticalAlignment={Top:"top",Center:"center",Bottom:"bottom",Justify:"justify",Distributed:"distributed"},Ps.Orientation={Horizontal:"horizontal",Vertical:"90",Vertical270:"270",Stacked:"stacked"},Ps.ReadingDirection={Auto:"auto",LeftToRight:"ltr",RightToLeft:"rtl"},Ps.Overflow={Visible:"visible",Wrap:"wrap",Clip:"clip",Shrink:"shrink",Ellipsis:"ellipsis"},Ps.Autofit={None:"none",Normal:"normal",Shape:"shape"},Ps.TabStopAlignment={Default:"default",Left:"left",Right:"right",Center:"center"},Ps.toCSSHorizontalTextAlign=t=>t?t.toLowerCase():null;const js=(t,e,n=1e3)=>{if(!t)throw new Error("A template string must be specified.");if(e(t))return t;let r=new RegExp(/\d+/,"g").exec(t),o=null,s=0;null!==r?(o=t,s=parseFloat(r[0]),isNaN(s)&&(s=0)):(s=1,o=`${t}_${s}`);let i=isNaN(s)?0:s;for(;s<i+n;)try{const t=o.replace(/\d+/g,()=>""+s++);if(e(t))return t}catch(t){}throw new Error(`Unable to find valid name for '${t}'.`)},Hs=(t,e=!1)=>{if(!t||0===t.length)return t;const n=t.charAt(0);if(n>="a"&&n<="z"){const r=String.fromCharCode(n.charCodeAt(0)-32);return e?r+t.slice(1).toLowerCase():r+t.slice(1)}return t},Vs=t=>{if(!t||"string"!=typeof t)return"";const e=t.split(/[\\/]/).pop()||"",n=e.lastIndexOf(".");return""===e||n<1?"":e.slice(n+1)},$s=t=>t.toLowerCase().replace(/([-_][a-z])/g,t=>t.toUpperCase().replace("-","").replace("_","")),Us=(t,e=36)=>t.substring(0,36)+(t.length>e?"…":""),Gs=t=>{if(void 0===t)return 0;let e=t.toString().split(".");return e.length<=1?0:e[1].length||0},Ws=new RegExp(/^["|'|`](.*)["|'|`]$/),qs=new RegExp("^([a-zA-Z]+:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i"),Js=(t=",",e="'")=>new RegExp(`\\s*${t}\\s*(?=(?:[^${e}]*${e}[^${e}]*${e})*[^${e}]*$)`,"g"),Xs=Js(),Ks=t=>t.replace(Ws,"$1"),Ys=(t,e="'")=>`${e}${t}${e}`,Zs=(t,e=void 0,n=void 0)=>{let r=Xs;return void 0===e&&void 0===n||(r=Js(e,n)),t.split(r)},Qs=t=>{let e;try{e=new URL(t)}catch(t){return!1}return("http:"===e.protocol||"https:"===e.protocol)&&qs.test(t)},ti=new RegExp(/^[^\s@]+@[^\s@]+\.[^\s@]+$/i),ei=t=>!!t.toLowerCase().startsWith("mailto:")||ti.test(t),ni=t=>((t>=26?ni((t/26|0)-1):"")+"abcdefghijklmnopqrstuvwxyz"[t%26|0]).toUpperCase(),ri=Object.freeze(Object.defineProperty({__proto__:null,DefaultUnQuoteRegEx:Xs,camelToSnake:t=>t?t.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`):t,capitalize:Hs,clampString:Us,countDecimals:Gs,findValidTextValue:js,getBaseName:(t,e=!1)=>{if(!t||"string"!=typeof t)return"";const n=t.split(/[\\/]/).pop()||"";if(""===n)return"";const r=Vs(n),o=0===r.length?n:n.slice(0,n.length-r.length-1);return e?Hs(o,!0):o},getFileNameExtension:Vs,isQuoted:t=>t&&t.length>1&&Ws.test(t)&&t[0]===t[t.length-1],isValidEmail:ei,isValidHttpUrl:Qs,numberToAlphabet:ni,quote:Ys,snakeToCamel:$s,splitUnquoted:Zs,unquote:Ks},Symbol.toStringTag,{value:"Module"})),oi=(t,e,n,r=null)=>{const o=(e||11*fi.getDeviceScale())/fi.getDeviceScale(),s=r?.letterSpacing||0,i=t.length;const a=i*(.55*o)-(t.match(/[il.,;!|]/g)||[]).length*o*.15+(t.match(/[mwMW]/g)||[]).length*o*.1+(i>0?(i-1)*s:0),l=Math.ceil(1.2*o),c=Math.ceil(.8*o),h=Math.ceil(.2*o),u=Math.ceil(.45*o),d=Math.ceil(1.1*o),g=Math.max(1,Math.ceil(.08*o));return{width:a,lineHeight:l,baseline:c,lineGap:h,strikePosition:u,underlinePosition:d,strikeThickness:g,underlineThickness:g,actualBoundingBoxLeft:0,actualBoundingBoxRight:a,actualBoundingBoxAscent:c,actualBoundingBoxDescent:l-c,fontBoundingBoxAscent:c,fontBoundingBoxDescent:l-c,emHeightAscent:c,emHeightDescent:l-c,hangingBaseline:.8*c,alphabeticBaseline:c,ideographicBaseline:l}},si={},ii=(t,e)=>{let n="normal";return t&&e?n="bold italic":t?n="bold":e&&(n="italic"),n},ai=t=>t.split(",").map(t=>{const e=(t=t.trim()).indexOf(" ")>=0,n=t.indexOf('"')>=0||t.indexOf("'")>=0;return e&&!n&&(t=`"${t}"`),t}).join(", "),li=new Map,ci=new Map;let hi=null;const ui=(t,e,n,r=null)=>{const o=r?.letterSpacing||0;"undefined"==typeof window||si.contextMeasure||(si.canvasMeasure=document?document.createElement("canvas"):null,si.contextMeasure=si.canvasMeasure.getContext("2d"),si.contextMeasure.letterSpacing=`${o}px`,si.contextMeasure.textRendering="geometricPrecision",si.contextMeasure.textBaseline="alphabetic",si.contextMeasure.textAlign="left");const s=n||"calibri",i=e||11*fi.getDeviceScale(),a=r?.isBold||!1,l=r?.isItalic||!1;let c=null;if("#"===t||"0"===t||"M"===t||""===t||"_"===t||"-"===t){c=((t,e,n,r,o,s)=>t+Math.round(100*e)/100+n+r+o+s)(t,i,s,a,l,o);const e=li.get(c);if(e)return e}if(hi&&hi.text===t&&hi.size===e&&hi.family===n&&hi.options?.isBold===r?.isBold&&hi.options?.isItalic===r?.isItalic&&hi.options?.letterSpacing===r?.letterSpacing)return hi.metrics;let h={};const u=ii(a,l)+" "+_t.roundAccurately(i,2)+"px "+ai(s);si.contextMeasure?(si.contextMeasure.font=u,si.contextMeasure.letterSpacing=`${r?.letterSpacing??0}px`,h=si.contextMeasure.measureText(t)):h.width=t.length*_t.roundAccurately(i/fi.getDeviceScale()*.6,2);let d=ci.get(u);if(!d&&"undefined"!=typeof window){const t=document.createElement("div");t.style.visibility="hidden",t.style.position="absolute";const e=document.createElement("span");e.textContent="Mj",e.style.fontSize="100px",e.style.fontWeight=r?.isBold?"bold":"normal",e.style.fontStyle=r?.isItalic?"italic":"normal",e.style.fontFamily=`'${s}'`,e.style.lineHeight="1.2",t.appendChild(e),document.body.appendChild(t);const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();document.body.removeChild(t),si.contextMeasure.font=ii(a,l)+" "+_t.roundAccurately(100,2)+"px "+ai(s);const c=si.contextMeasure.measureText("M"),h=n.bottom-n.top,g=h-(c.fontBoundingBoxAscent+c.fontBoundingBoxDescent),m=c.fontBoundingBoxAscent+o.top,f=si.contextMeasure.measureText("_"),p=m-f.actualBoundingBoxAscent,_=Math.max(1,Math.abs(f.actualBoundingBoxAscent+f.actualBoundingBoxDescent)),S=si.contextMeasure.measureText("-"),w=_t.roundAccurately(m-S.actualBoundingBoxAscent+Math.max(1,.05*h,0)),y=_,E=i/100;d={lineHeight:Math.ceil(h*E),baseline:Math.ceil(m*E),lineGap:Math.ceil(g*E),strikePosition:Math.ceil(w*E),underlinePosition:Math.ceil(p*E),strikeThickness:Math.ceil(y*E),underlineThickness:Math.ceil(_*E)},si.contextMeasure.font=u,ci.set(u,d)}d||(d={lineHeight:Math.ceil(1.2*i),baseline:Math.ceil(i)+Math.floor(.1*i),lineGap:Math.ceil(.1*i),strikePosition:Math.ceil(.55*i)+Math.floor(.1*i),strikeThickness:1,underlinePosition:Math.ceil(1.1*i),underlineThickness:1},ci.set(u,d));const g={...h,width:h.width,...d};return null!==c&&li.set(c,g),hi={text:t,size:e,family:n,options:r,metrics:g},g};let di=null;const gi=()=>{if(di)return di;try{const t=document.createElement("canvas"),e=t.getContext&&t.getContext("2d");e&&"function"==typeof e.fillText&&(di=ui)}catch{}return di||(console.warn("⚠️ CanvasFontMeasurer not available, falling back to SimpleFontMeasurer"),di=oi),di};let mi=null;var fi,pi;(pi=fi||(fi={})).Style={Normal:"normal",Italic:"italic"},pi.Scheme={Major:"major",Minor:"minor",None:"none"},pi.UnderlineStyle={None:"none",Double:"double",DoubleAccounting:"doubleAccounting",Single:"single",SingleAccounting:"singleAccounting"},pi.VerticalAlignment={Baseline:"baseline",Sub:"sub",Super:"super"},pi.setSharedMeasurer=t=>{mi=t},pi.getSharedMeasurer=()=>mi||(mi=gi(),mi),pi.getDeviceScale=()=>96/72*1,pi.getPanoseFallback=t=>{const e=[],n=t.length;for(let r=0;r<n;r+=2)e.push(parseInt(t.substring(r,r+2),16));const r=e[0],o=e[1],s=e[3];switch(r){case 2:return 9===s?"monospace":o>=2&&o<=8?"serif":"sans-serif";case 3:return"cursive";case 4:return"fantasy";case 5:return"monospace";default:return"sans-serif"}},pi.GenericName={Serif:"serif",SanSerif:"sans-serif",MonoSpace:"monospace",Cursive:"cursive",Fantasy:"fantasy",SystemUI:"system-ui",UISystem:"ui-system",UISerif:"ui-serif",UISanSerif:"ui-sans-serif",UIMonoSpace:"ui-monospace",UIRounded:"ui-rounded",Math:"math",Emoji:"emoji",Fangsong:"fangsong"};class _i{constructor(t){this._private={input:t},"string"==typeof t?this._private.name=t:Object.assign(this._private,t)}toJSON(){return this._private.input}getFamily(){return this._private.name}getPitch(){return this._private.pitch}getPanose(){return this._private.panose}toString(){return"string"==typeof this._private.input?this._private.input:JSON.stringify(this._private.input)}get isIFont(){return!0}}const Si=["Arial","Arial Black","Brush Script MT","Calibri","Comic Sans MS","Courier New","Garamond","Georgia","Impact","Luminari","Palatino Linotype","Tahoma","Times New Roman","Trebuchet MS","Verdana"],wi=new Map;wi.set(fi.GenericName.Serif,["Tahoma"]),wi.set(fi.GenericName.SanSerif,["Calibri"]),wi.set(fi.GenericName.MonoSpace,["Courier New"]),wi.set(fi.GenericName.Cursive,["Comic Sans MS"]),wi.set(fi.GenericName.Fantasy,["Luminari"]),wi.set(fi.GenericName.UISystem,["Arial"]),wi.set(fi.GenericName.UISerif,["Tahoma"]),wi.set(fi.GenericName.UISanSerif,["Arial"]),wi.set(fi.GenericName.UIMonoSpace,["Courier New"]),wi.set(fi.GenericName.UIRounded,["Arial"]),wi.set(fi.GenericName.Math,[]),wi.set(fi.GenericName.Emoji,[]),wi.set(fi.GenericName.Fangsong,[]);const yi=new Map;let Ei=[];vi(Si);const bi=eval;function vi(t){t||vi(Si);let e=[];for(let n=0;n<t.length;n++){let r=t[n];"string"==typeof r&&(r=new _i(r));let o=!0;const s="document";try{o=bi(`${s}.fonts.check('12px ${r.getFamily()}')`)}catch(t){}const i={fontRef:r,loaded:o};e.push(i),yi.set(r.getFamily(),i)}Ei=Object.freeze(e)}const Ci=new Map,xi=Object.freeze(Object.defineProperty({__proto__:null,findBestMatch:(t,e)=>{const n=Ci.get(t);if(n)return null===n.fontRef?null:n;let r=[t];e.fallbacks&&(r=r.concat(e.fallbacks));let o=null;for(let t=0;!o&&t<r.length;t++){let e=r[t];if(o=yi.get(e),!o){const t=wi.get(e);if(t)for(let e=0;!o&&e<t.length;e++)o=yi.get(t[e])}}return o?Ci.set(t,o):Ci.set(t,{fontRef:null,loaded:!1}),o},getFontList:function(){return Ei},setFontList:vi},Symbol.toStringTag,{value:"Module"}));class Ii{constructor(t,e,n,r=null,o=null,s=null){this._private={wrapped:!0,insets:x.EmptyRect,orientation:zs.Orientation.Horizontal,autoFit:zs.Autofit.None,fontScale:1,vertical:!1,columnCount:1,columnSpacing:0,verticalAlignment:zs.VerticalAlignment.Center,horizontalCentered:!1,lineReduction:0,isSpaceFirstLastPara:!1,presetTextWarp:null,paragraphs:_t.EmptyArray},this._bounds=null,this._textBounds=null,this._lines=null,this._lastLayoutDims=void 0,this._lastLayout=void 0,this._private=Object.assign(this._private,t||{}),this._defaultFont=e,this._alignment=n,this._lines=r,this._bounds=Object.freeze(o),this._textBounds=Object.freeze(s)}visitParas(t){t?.visitTextFrame?.(this);const e=this.paragraphs,n=e.length;for(let r=0;r<n;r++){const o=e[r];t?.visitTextParagraph?.(o,r,n);const s=o.runs,i=s.length;for(let e=0;e<i;e++)t?.visitTextRun?.(s[e],e,i)}}visitLines(t){t?.visitTextFrame?.(this);const e=this.lines,n=e.length;for(let r=0;r<n;r++){const o=e[r];t?.visitTextLine?.(o,r,n);const s=o.runs,i=s.length;for(let e=0;e<i;e++)t?.visitTextRun?.(s[e],e,i)}}layout(t=null){return this._lastLayout&&this._lastLayoutDims?.width===t?.width&&this._lastLayoutDims?.height===t?.height||(this._lastLayout=Zi(this,this._defaultFont,this._alignment,t),this._lastLayoutDims=t),this._lastLayout}clone(t){const e=t?.visitTextFrame?.(this),n=Object.assign(this._private,e||{});return delete n.bounds,new Ii(n,this._defaultFont,this._alignment)}equals(t){return _t.deepEqual(this._private,t._private)}createTemporaryTextFrame(t,e){return ta(t,this._defaultFont,this._alignment,e??this._private.wrapped)}get bounds(){if(null===this._bounds)throw new Error(Ai);return this._bounds}get textBounds(){if(null===this._textBounds)throw new Error(Ai);return this._textBounds}get lines(){return this._lines}get wrapped(){return this._private.wrapped}get insets(){return this._private.insets}get orientation(){return this._private.orientation}get autoFit(){return this._private.autoFit}get fontScale(){return this._private.fontScale}get vertical(){return this._private.vertical}get columnCount(){return this._private.columnCount}get columnSpacing(){return this._private.columnSpacing}get verticalAlignment(){return this._private.verticalAlignment}get horizontalCentered(){return this._private.horizontalCentered}get lineReduction(){return this._private.lineReduction}get isSpaceFirstLastPara(){return this._private.isSpaceFirstLastPara}get presetTextWarp(){return this._private.presetTextWarp}get paragraphs(){return this._private.paragraphs}}const Ai="bounds can not be used until layout";class Ri{static{this.NL="\n"}static{this.DefaultLineSpacing=100}static{this.DefaultTabWidth=72}}class Mi{constructor(t){this._private={defaultFontSize:11,defaultTabSize:Ri.DefaultTabWidth,tabOverrides:_t.EmptyArray,spacingBefore:0,spacingAfter:0,lineSpacing:Ri.DefaultLineSpacing,align:zs.HorizontalAlignment.Left,endParagraphSize:0,indentLevel:0,leadingIndent:0,hangingIndent:0,rightMargin:0,bullet:null},this._private=Object.assign(this._private,t||{})}clone(t){const e=t?.visitTextParagraph?.(this,0,1),n=Object.assign(this._private,e||{});return delete n.bounds,new Mi(n)}equals(t){return _t.deepEqual(this._private,t._private)}get bounds(){return this._bounds}get defaultFontSize(){return this._private.defaultFontSize}get defaultTabSize(){return this._private.defaultTabSize}get tabOverrides(){return this._private.tabOverrides}get spacingBefore(){return this._private.spacingBefore}get spacingAfter(){return this._private.spacingAfter}get lineSpacing(){return this._private.lineSpacing}get align(){return this._private.align}get endParagraphSize(){return this._private.endParagraphSize}get indentLevel(){return this._private.indentLevel}get leadingIndent(){return this._private.leadingIndent}get hangingIndent(){return this._private.hangingIndent}get rightMargin(){return this._private.rightMargin}get bullet(){return this._private.bullet}get runs(){return this._private.runs}}class Ti{constructor(t,e=null){this._private={text:null,fontName:"Arial",bold:!1,italic:!1,superSub:!1,fontSize:11,letterSpacing:0,kerningMin:10,smallCaps:Ds.SmallCaps.None,offset:0,strikeStyle:Ds.StrikeStyle.None},this._private={...this._private,...t},this._bounds=e}clone(t){const e=t?.visitTextRun?.(this,0,1),n=Object.assign(this._private,e||{});return delete n.bounds,new Ti(n)}equals(t){return _t.deepEqual(this._private,t._private)}get bounds(){return this._bounds}get text(){return this._private.text}get fontName(){return this._private.fontName}get bold(){return this._private.bold}get italic(){return this._private.italic}get fontSize(){return this._private.fontSize}get superSub(){return this._private.superSub}get letterSpacing(){return this._private.letterSpacing}get kerningMin(){return this._private.kerningMin}get smallCaps(){return this._private.smallCaps}get offset(){return this._private.offset}get strikeStyle(){return this._private.strikeStyle}}class Ni{constructor(t,e,n){this._private={},this._private={bounds:t,baseline:e,runs:n}}get bounds(){return this._private.bounds}get baseline(){return this._private.baseline}get runs(){return this._private.runs}get bullet(){return null}}function Fi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var ki,Oi,Li,Di,Bi,zi;function Pi(){if(Di)return Li;Di=1;const t=18===new Uint8Array(new Uint32Array([305419896]).buffer)[0],e=(t,e,n)=>{let r=t[e];t[e]=t[n],t[n]=r};return Li={swap32LE:n=>{t&&(t=>{const n=t.length;for(let r=0;r<n;r+=4)e(t,r,r+3),e(t,r+1,r+2)})(n)}},Li}var ji=function(){if(zi)return Bi;zi=1;const t=function(){if(Oi)return ki;function t(){this.table=new Uint16Array(16),this.trans=new Uint16Array(288)}function e(e,n){this.source=e,this.sourceIndex=0,this.tag=0,this.bitcount=0,this.dest=n,this.destLen=0,this.ltree=new t,this.dtree=new t}Oi=1;var n=new t,r=new t,o=new Uint8Array(30),s=new Uint16Array(30),i=new Uint8Array(30),a=new Uint16Array(30),l=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),c=new t,h=new Uint8Array(320);function u(t,e,n,r){var o,s;for(o=0;o<n;++o)t[o]=0;for(o=0;o<30-n;++o)t[o+n]=o/n|0;for(s=r,o=0;o<30;++o)e[o]=s,s+=1<<t[o]}var d=new Uint16Array(16);function g(t,e,n,r){var o,s;for(o=0;o<16;++o)t.table[o]=0;for(o=0;o<r;++o)t.table[e[n+o]]++;for(t.table[0]=0,s=0,o=0;o<16;++o)d[o]=s,s+=t.table[o];for(o=0;o<r;++o)e[n+o]&&(t.trans[d[e[n+o]]++]=o)}function m(t){t.bitcount--||(t.tag=t.source[t.sourceIndex++],t.bitcount=7);var e=1&t.tag;return t.tag>>>=1,e}function f(t,e,n){if(!e)return n;for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var r=t.tag&65535>>>16-e;return t.tag>>>=e,t.bitcount-=e,r+n}function p(t,e){for(;t.bitcount<24;)t.tag|=t.source[t.sourceIndex++]<<t.bitcount,t.bitcount+=8;var n=0,r=0,o=0,s=t.tag;do{r=2*r+(1&s),s>>>=1,++o,n+=e.table[o],r-=e.table[o]}while(r>=0);return t.tag=s,t.bitcount-=o,e.trans[n+r]}function _(t,e,n){var r,o,s,i,a,u;for(r=f(t,5,257),o=f(t,5,1),s=f(t,4,4),i=0;i<19;++i)h[i]=0;for(i=0;i<s;++i){var d=f(t,3,0);h[l[i]]=d}for(g(c,h,0,19),a=0;a<r+o;){var m=p(t,c);switch(m){case 16:var _=h[a-1];for(u=f(t,2,3);u;--u)h[a++]=_;break;case 17:for(u=f(t,3,3);u;--u)h[a++]=0;break;case 18:for(u=f(t,7,11);u;--u)h[a++]=0;break;default:h[a++]=m}}g(e,h,0,r),g(n,h,r,o)}function S(t,e,n){for(;;){var r,l,c,h,u=p(t,e);if(256===u)return 0;if(u<256)t.dest[t.destLen++]=u;else for(r=f(t,o[u-=257],s[u]),l=p(t,n),h=c=t.destLen-f(t,i[l],a[l]);h<c+r;++h)t.dest[t.destLen++]=t.dest[h]}}function w(t){for(var e,n;t.bitcount>8;)t.sourceIndex--,t.bitcount-=8;if((e=256*(e=t.source[t.sourceIndex+1])+t.source[t.sourceIndex])!==(65535&~(256*t.source[t.sourceIndex+3]+t.source[t.sourceIndex+2])))return-3;for(t.sourceIndex+=4,n=e;n;--n)t.dest[t.destLen++]=t.source[t.sourceIndex++];return t.bitcount=0,0}return function(t,e){var n;for(n=0;n<7;++n)t.table[n]=0;for(t.table[7]=24,t.table[8]=152,t.table[9]=112,n=0;n<24;++n)t.trans[n]=256+n;for(n=0;n<144;++n)t.trans[24+n]=n;for(n=0;n<8;++n)t.trans[168+n]=280+n;for(n=0;n<112;++n)t.trans[176+n]=144+n;for(n=0;n<5;++n)e.table[n]=0;for(e.table[5]=32,n=0;n<32;++n)e.trans[n]=n}(n,r),u(o,s,4,3),u(i,a,2,1),o[28]=0,s[28]=258,ki=function(t,o){var s,i,a=new e(t,o);do{switch(s=m(a),f(a,2,0)){case 0:i=w(a);break;case 1:i=S(a,n,r);break;case 2:_(a,a.ltree,a.dtree),i=S(a,a.ltree,a.dtree);break;default:i=-3}if(0!==i)throw new Error("Data error")}while(!s);return a.destLen<a.dest.length?"function"==typeof a.dest.slice?a.dest.slice(0,a.destLen):a.dest.subarray(0,a.destLen):a.dest},ki}(),{swap32LE:e}=Pi();return Bi=class{constructor(n){const r="function"==typeof n.readUInt32BE&&"function"==typeof n.slice;if(r||n instanceof Uint8Array){let o;if(r)this.highStart=n.readUInt32LE(0),this.errorValue=n.readUInt32LE(4),o=n.readUInt32LE(8),n=n.slice(12);else{const t=new DataView(n.buffer);this.highStart=t.getUint32(0,!0),this.errorValue=t.getUint32(4,!0),o=t.getUint32(8,!0),n=n.subarray(12)}n=t(n,new Uint8Array(o)),n=t(n,new Uint8Array(o)),e(n),this.data=new Uint32Array(n.buffer)}else({data:this.data,highStart:this.highStart,errorValue:this.errorValue}=n)}get(t){let e;return t<0||t>1114111?this.errorValue:t<55296||t>56319&&t<=65535?(e=(this.data[t>>5]<<2)+(31&t),this.data[e]):t<=65535?(e=(this.data[2048+(t-55296>>5)]<<2)+(31&t),this.data[e]):t<this.highStart?(e=this.data[2080+(t>>11)],e=this.data[e+(t>>5&63)],e=(e<<2)+(31&t),this.data[e]):this.data[this.data.length-4]}}}();const Hi=Fi(ji);var Vi,$i={};var Ui=(Vi||(Vi=1,function(t){var e="undefined"!=typeof Uint8Array?Uint8Array:Array,n="+".charCodeAt(0),r="/".charCodeAt(0),o="0".charCodeAt(0),s="a".charCodeAt(0),i="A".charCodeAt(0),a="-".charCodeAt(0),l="_".charCodeAt(0);function c(t){var e=t.charCodeAt(0);return e===n||e===a?62:e===r||e===l?63:e<o?-1:e<o+10?e-o+26+26:e<i+26?e-i:e<s+26?e-s+26:void 0}t.toByteArray=function(t){var n,r,o,s,i,a;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;i="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,a=new e(3*t.length/4-i),o=i>0?t.length-4:t.length;var h=0;function u(t){a[h++]=t}for(n=0,r=0;n<o;n+=4,r+=3)u((16711680&(s=c(t.charAt(n))<<18|c(t.charAt(n+1))<<12|c(t.charAt(n+2))<<6|c(t.charAt(n+3))))>>16),u((65280&s)>>8),u(255&s);return 2===i?u(255&(s=c(t.charAt(n))<<2|c(t.charAt(n+1))>>4)):1===i&&(u((s=c(t.charAt(n))<<10|c(t.charAt(n+1))<<4|c(t.charAt(n+2))>>2)>>8&255),u(255&s)),a},t.fromByteArray=function(t){var e,n,r,o=t.length%3,s="";function i(t){return"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(t)}function a(t){return i(t>>18&63)+i(t>>12&63)+i(t>>6&63)+i(63&t)}for(e=0,r=t.length-o;e<r;e+=3)s+=a(n=(t[e]<<16)+(t[e+1]<<8)+t[e+2]);switch(o){case 1:s+=i((n=t[t.length-1])>>2),s+=i(n<<4&63),s+="==";break;case 2:s+=i((n=(t[t.length-2]<<8)+t[t.length-1])>>10),s+=i(n>>4&63),s+=i(n<<2&63),s+="="}return s}}($i)),$i);var Gi={};const Wi=[[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,4,4,4,4,4,4,4,4,4,4],[0,4,4,1,1,4,4,4,4,1,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,4,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[4,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,0,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,1,1,1,1,0,0,4,2,4,1,1,1,1,1,0,1,1,1,0],[1,4,4,1,1,1,4,4,4,0,0,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,1,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,0,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,4,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,1,1,4,2,4,1,1,1,1,1,1,1,1,1,1],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,1,1,1,1,0,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,1,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,1,0,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,0,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,1,0,0,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,1,1,0],[0,4,4,1,1,1,4,4,4,0,1,0,0,0,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[1,4,4,1,1,1,4,4,4,1,1,1,1,1,0,1,1,1,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0],[0,4,4,1,1,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,4,2,4,0,0,0,0,0,0,0,0,1,0]],qi=new Hi(Fi(Ui).toByteArray("AAgOAAAAAAAQ4QAAAQ0P8vDtnQuMXUUZx+eyu7d7797d9m5bHoWltKVUlsjLWE0VJNigQoMVqkStEoNQQUl5GIo1KKmogEgqkKbBRki72lYabZMGKoGAjQRtJJDaCCIRiiigREBQS3z+xzOTnZ3O+3HOhd5NfpkzZx7fN9988zivu2M9hGwB28F94DnwEngd/Asc1EtIs9c/bIPDwCxwLDgezHcodyo4w5C+CCwBS8FnwSXgCnA1uFbI93XwbXAbWAfWgx+CzWAb+An4KfgFeAzsYWWfYuFz4CXwGvgb+Dfo6yNkEEwGh4CZYB44FpwI3g1OY+kfBItZOo2fB84Hy8DF4HJwNbiWpV8PVoO1LH4n2NRXyN+KcAd4kNVP9XsY4aPgcfAbsBfs6SniL4K/sPjfEf6HlanXCRkCw2BGvUh/keWfXS/CY+pFXs7x9XHmM94LTmWIeU2cgbxnS/k/B3kf86jDhU8L9V2E40vAFWAlWFUfb++NOL4F3C7JX4/4GiE+hvgWsF0oS7mXldspnN+F493gyXrh9xTav0cg3EvzgVfBG6wsmVSEkxBOBgdPGpd7JI6PnqRvJ68/xlbHof53gPeA94OzwLngk+ACsAwsByvASrAK3MB0Ws3CtQjvBJvAVrADPMDSHkb4CNijaccTwvnf4fiPEs8Lxy+D18A/QU8/xjgYBjPAbDAKTgYLwOngTHAO+EQ/8wuEF4EvsPiVCFf2+9tsFStzA8LVHuXXBsi6QyqzUYiPMR/7Mc7dAx7oL8bzw/3u/Bw8Bp4Az4AXwCtgHzsmDXP5fiF9iiVvly5d0sHngar16NKlS5cuXbp06fLmYlqHXrcd3ph4P0THUY3iXh49novju4S0tzfs5d+JPKewfAsRntZb3K9ZhOMlrO6lCC8An28U9+OuovcPcPxlVu5rCL/VmHh/iHIrzn3fIPu7SN8Axmg+8AOwEWwCm7tp3bRuWjetm5Y8bSu4B9zbKO6ZVsnORrVU3f4uXTqZ2H3sLoyx3eDXjfDndE9qyj6L838CfwVvgFpzYnof4oNgOhgBc8Fos9DrZIQLmtXPP1MmF6wGj4H+KXoWguvADkXaPil+YpuQy8Am8Ey7ODdtmJDF4HowBp4De6HDTNjhfHAHeBr0DBBy0kDxfPbcgSIusgrcWhtnJ8vL+TPix7UIOQtcBq4C28Cr4KRBnANbwSuDE+s50JgyNNFuXbp06XIgsXjIvPafjvXozKY+fVFz/z0LT1uCtKVSWbrOLWPnztG8e0Xfy7ol8XtZJi7WtG+5od2UFXQ/A12vUeS7jp27yVKHjdsU9lXB869TyNvAzt0lpP2oWbwLdjiO78bx/Sz+EMJHwK9Y/LcIfw+eZ3F67/Hl5vh9xX80J+rwX8SvRDhpgL17iPAQMHNArfPrqHPewLheI+AERV6efwV418B4nOZ/H+IfYHV8GOF5LJ3eAz0fx8sM9S0fUNud39O9CulfGZhY5huI3wzWgNvBelbHZoTbNPVpfYjKQpkHwUNgl0LWblbnk0LbbDxr0OMFpL3iqWdu9nWYPlVAWkXY39LnGdCkDbeqv1YNbfcMQ3t9oe8lzm6NH9N1ZB6Ln4BwfkJZJk7RyFnYKt6b/JDQXx9p5X+eFdqOjzM9P9MB/lUlFzr20aXIdzlY4dmn9F3YqtvoO76/2hp/D/xA5Zue88nNyL8GbFbs075X0tyUig3Qd2MCnf//HjnzpbsR3g9+1kHzzVjdnE71/qVBX9rGPUh/ysNWe1neFzvIDi5zAufV1sT0N0poR22wkFUfTOPfA4N2mbZ5fSrqOHSw+IbkSBbOGSzSRgf91/GTUWYBOB2cIZQ/G8cfBZ8CFwrnL8XxF8FKcA24jqXdiPA7Qr61OF7H4mMItwzuv2/YLth1ISt3Hzu3k4W7EH5JqPdRHD/O4k+z8A8IX5Lq3y7Z4nXE9xn6kX6vQ4bKfy+ok+hH+xf3hq9dnTTHhjKd2GmDuWA242iHMq4cC7A8kJ7i8o1+skSa7Jieo38HCWnoNjKFhdSFBxzpZ7QE6lI8N4S14aASZcryaV/WWHw66f6NHuCoxuQxmvM56GX9QMd8Q4D65ywGP+ZzRJuM+zQvx/MOS2VFeqQ4IXnH26zM9Xe6/E6D+4foAzzuajPZp8Qyw5ayZVDWuH0z0BtYRkeIDqH9KO9VbH1btd/lhNqCzvl8zeLnG0S/hnU6baHfpiuO6yy0rd+DHURo/zYF5H26j03rQsip2ndzz82u1z9N4VjWKWeb68Tedpt95HRVXp7H1R6p+/Wt4FPy/PpWwscOLRJ+PVWF/+W0iVyGzs18TIvXkOJ1Wxm66vSXz+vylenrZcj1ub439W+K8RNCGTJi2p/TJ1K23VaXr35tRpnzmjxequgfcfyk6B/TGBVlyedsNgpdd/h+W1U3P99QyFPNo1X3TwpM/WLTIWYfoBqXrv6iskHZ/RFr79R6hIyHBrH3f1nrUVnjP8SnZZ+rYtzr9Exld5MNbPNErusAPg+77u/eDOPftU9yj39TH7rezxd1LvsZQJlzkWlOirG/79zjMj/mtHUKu7vKy+3/LnXr9okyKedjX5/0He9iP/j63LwOQdarEVlfy8OO/Lqw023j6xcqmwxLiOd6heM2i9cV9LJy8jMJ23yQ+rpbfu7EQ/pXE8KYvUSqvVnb4XzZa6LrHMXHR+zcLvqWbm/Bn0/HzIs6fWPHoat8XfnDKmZGxRxeMbn2UqZ5Q94nmcZRbqqUXbZ8+lcjE+cPX11t814orvvAXNcG8vqj2vvk1MGn3anlj0bIT72v47bvE+Lc98T9b6r7AKn6j+8Duf7D0nnZx/j7Zjn0j9nbpSTndaLr9WNLivP+iN23xF7L+fqv6ZouFyb78jxVXvv5jJ9YUs9/sddO8h7KNg5jrhfaJGztT6G7KF+1d6yCmD5Kdb2fan60rSc552fZr3zeQ9DpnPp+Si5cx5Ktv2QfSzF/mMbWdOm46rFI4XstnU9xeqX4NKb7TKEdcr6pZOK3ID1k/LvFHkVczEuZLEDr499YqvqBym1aEHWgcvoYOtv0M91qQl5TfpO/in6rWx8OVpT1Wedkv3f5xom3T/xeR/6Gx6V86PWAOB4bBpqWdN+yTcVxjIyGRz/FrDGu6w/3d7kPm8StX8RyPu+uuvpNju/vTLJV37GpvoM0oZPnW87VLnL/5pDno1NoW1R6yedU6TyUv3u19a3KFnIbTLYz+ZCLP4T0tU1uivFgso0pnsJ/UtXvarNY28Xq5cvkBDrQP/E5ZaiuQwwfmTlsOiQRU1fMuqrDd/3ISSuwjOwXOfTyGUMpZIXq4GpLn3pUcdfzch2x7XO1u2uZHOPb1G6b3Xg9PH1IIWeEpJlPQtqos2EKW8b0u8rnuP1UeVLoXJb9be0uG9nnbchjU+XTszT5VeNBThPHnc5OKj1U9aj0GTHIVaGy1YhEWT4ixns00DT+XEzWn/7VAsIc63Cov3OdyhwjrnaqQqZvWKXdypRdlq+k8msZ031U+Rm4fA+3TtyeR9hwfW9G9yxDN0fZMN33F+9TE6md4hwoxumfaUzI9fN3PFT3xVV2msrQ3UsnChm6Nulk8TndpS28D3zX9tTIPsF/z7Am5OkTjm1tI1JZW74+4VgsZ0N3L1yXV3WeP5uR7TGHHdvC3JQlxybfpd22tDlk/2eofRK8TzrN/qnar/K/OUTth6I/+jAnEptNbPvFHP2gs40N3+dfMWtwqvVct7/wfd8gtQ7imifial9ZJ9/3IHLYU6eDj3+4PhsNhX+vwvcWLnu6kGfEMe8DuciPfUfGZB8X/7HJy/Gefe5n+VRGFd/wyP2ta7/LO4yh/sbLV/k9lev6kfO9Dt/5U67b1/6u/epqB1U9Me23jfHY9sscAg4tkbLl+e4/U36rJ9ddxfd6sg5vq5ice42Wpk/pb9FOJ36/W9tpv4kbC79nUbZceX8Zu6/qJ+P3WvhvA8v3reh7Jbn2d6rrNC7XNZTLma4Ba0JI9efX2uLzF5scG/w9UNU1ZxW+ymUfzELeTllXlQ1rUuhzjS5fp9c964iFBOqeSz63bU065nZKdU+mDEz3qHIjjifquw0pnb/raRtvrnsYcb46ihT3taoYz6brdNW9l6rWRnE/navdPn1XlR1km7hcz1WlH/elKuSOSvLLuE8U6m8uzwRdfcGl73VyTHuyMvzJ1Sa2cWDTP/Z63Kc94n2B1PYr24dz1JlyHLlcP+S4B6vD1c9EW4q2LWstCvUjeVy63k/LMYdUNd5D1xQfvVTzX1VjkMsUv88N8VH5fReVn/Fjn++/h6X6Q8a6b1/q3g/i/ewi0/Scs8zxXeV6mWIOUPlPzBgdFerW+bZrm2P18dnjuK6HunEp+rHvPMXbr+sHVb/lnL+pTP57jPw9Cvk3PW178JD9qChfzuvTf7Htl38L1QUf/VKu9SFjwWbTWPvFEvu7Uq76y7+31g6QlYPc669pbsm9Xur2LWI9Pu8ypfDXqm3A2z8s1FWGn4ntL9NfQu2oSlftX9uetvTtv7J8Ql4zxfXGZ3zk8PeQ9w59x2uMfqI8/q5eKh/l9cb2rwsu9rSNl06ZP2Pmxtz+rNMx93yno0n2/82rVH7rQ+y9P15H6FyRun9ViH81ATmffI7nJ5r8uXXW6enbP6b/B8/l5OifVHYLnb9S39s2zcc+Ph+rh8+eQgVPS72elzGWY/tUtbbabBpDiI7yN1q6/4th2y+ErAc5+9BVvu/7KamJbWNZeuqI/R4tRf+YyD1HmOZM1bMV3/14Sn10c0Xu+Sj1nOXb5jL73ncdy02uvlXZNde65dOHYl7Vs4KYuS6FzWLn2zJlpZqPXPVPOa5yzKOyn1VhT9lmMfdbfH7D11Wf2PXN5h9y+dD287+qxgSnaYmnIrRtIb8pJe6/Uv9OVer6Whn0zfGO/BEloZI9ojmfAlUflClDd178bTmVHVTpZXOkAlk/lb42UujmI89HH5V+cl7XtowY6vTxLVWok6UrGzoGTHN+bB+6ri05687VNpvfuvRfaP2uMlNQth1D5JjGelm/8yn+9p3p/7qk9gnfeddXZmq/Sm333PJT659Kv1zjNbZ9uv2Oi//67CV8/N1nj1DmviyXDNVeJkaeaX8UsyesYg8cu2+NvdaPfb+lLDu5tvt/")),Ji=function(t){switch(t){case 33:case 39:case 40:case 42:return 12;case 35:return 5;default:return t}},Xi=function(t){switch(t){case 37:case 38:return 34;case 41:return 22;default:return t}};class Ki{constructor(t,e=!1){this.position=t,this.required=e}}Gi=class{nextCodePoint(){const t=this.string.charCodeAt(this.pos++),e=this.string.charCodeAt(this.pos);return 55296<=t&&t<=56319&&56320<=e&&e<=57343?(this.pos++,1024*(t-55296)+(e-56320)+65536):t}nextCharClass(){return Ji(qi.get(this.nextCodePoint()))}getSimpleBreak(){switch(this.nextClass){case 41:return!1;case 34:case 37:case 38:return this.curClass=34,!1;case 36:return this.curClass=36,!1}return null}getPairTableBreak(t){let e=!1;switch(Wi[this.curClass][this.nextClass]){case 0:e=!0;break;case 1:e=41===t;break;case 2:if(e=41===t,!e)return e=!1,e;break;case 3:if(41!==t)return e}return this.LB8a&&(e=!1),!this.LB21a||16!==this.curClass&&17!==this.curClass?this.LB21a=13===this.curClass:(e=!1,this.LB21a=!1),28===this.curClass?(this.LB30a++,2==this.LB30a&&28===this.nextClass&&(e=!0,this.LB30a=0)):this.LB30a=0,this.curClass=this.nextClass,e}nextBreak(){if(null==this.curClass){let t=this.nextCharClass();this.curClass=Xi(t),this.nextClass=t,this.LB8a=31===t,this.LB30a=0}for(;this.pos<this.string.length;){this.lastPos=this.pos;const t=this.nextClass;if(this.nextClass=this.nextCharClass(),34===this.curClass||36===this.curClass&&37!==this.nextClass)return this.curClass=Xi(Ji(this.nextClass)),new Ki(this.lastPos,!0);let e=this.getSimpleBreak();if(null===e&&(e=this.getPairTableBreak(t)),this.LB8a=31===this.nextClass,e)return new Ki(this.lastPos)}return this.lastPos<this.string.length?(this.lastPos=this.string.length,new Ki(this.string.length)):null}constructor(t){this.string=t,this.pos=0,this.lastPos=0,this.curClass=null,this.nextClass=null,this.LB8a=!1,this.LB21a=!1,this.LB30a=0}};class Yi{constructor(t){this._textMeasurer=t}_measureText(t){const e=this._fontSize,n=this._fontName,r=this._metricOptions;if(this._isSuperSub){const o=this._textMeasurer(t,.6*e,n,r);return{...this._textMeasurer("M",e,n,r),width:o.width}}return this._textMeasurer(t,e,n,r)}_breakWord(t,e,n){let r=0;for(;r<t.length;){let o={startPosition:this._charactersRead+r,text:"",x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},s=!1,i=0;const a=this._maxWidth;do{s=!1;const e=t.substring(r,r+i+1),n=e.replace(/\s+$/,""),l=this._measureText(n);let c=l;e.length!==n.length&&(c=this._measureText(e)),(o.x+l.width<=a||e.length<=1)&&(o.text=e,o.width=l.width,o.widthWhitespace=c.width,o.height=Math.max(o.height,l.lineHeight),o.baseline=Math.max(o.baseline,l.baseline),s=!0,i++)}while(s&&r+i<t.length);if(s){const n=t.substring(r,t.length),s=n.replace(/\s+$/,""),i=this._measureText(s);let a=i;n.length!==s.length&&(a=this._measureText(n)),e.startPosition=this._charactersRead+r,e.width=i.width,o.widthWhitespace=a.width,e.height=Math.max(e.height,i.lineHeight),e.baseline=Math.max(e.baseline,i.baseline),e.text=n}else{const t=n?.(o);if(!1===t)return!1}r+=i}}_breakWhiteSpace(t,e=null){for(;t&&this._charactersRead<t.length;){let n={startPosition:this._charactersRead,text:"",x:0,y:0,width:0,widthWhitespace:0,height:0,baseline:0},r=!1;const o=this._maxWidth,s=this._indent,i=this._breaker;do{if(r=!1,0===n.startPosition&&0===n.text.length&&(n.x=s,this._lastBreak=i.nextBreak()),this._lastBreak){const s=t.substring(n.startPosition,this._lastBreak.position),a=s.replace(/\s+$/,""),l=this._measureText(a);let c=l;if(s.length!==a.length&&(c=this._measureText(s)),n.x+l.width<=o)n.text=s,n.width=l.width,n.widthWhitespace=c.width,n.height=Math.max(n.height,l.lineHeight),n.baseline=Math.max(n.baseline,l.baseline),r=!0,this._charactersRead=this._lastBreak.position;else if(0===n.text.length){!1!==this._breakWord(s,n,e)&&(r=!0,this._charactersRead=this._lastBreak.position)}(r||-1===s.indexOf("\n"))&&this._lastBreak.required&&(this._lastBreak=i.nextBreak(),r=!1)}}while(r&&(this._lastBreak=i.nextBreak()));const a=e?.(n);if(!1===a)return!1}}wrap(t,e=null){this._breaker=new Gi(t),this._linesRead=[],this._charactersRead=0,this._maxXRead=0,this._maxXWhitespaceRead=0,this._maxYRead=0,this._fontName=e?.fontName??"Arial",this._fontSize=e?.fontSize??12,this._metricOptions={isBold:e?.bold??!1,isItalic:e?.italic??!1,letterSpacing:e?.letterSpacing??0},this._isSuperSub=e?.superSub??!1,this._indent=e?.indent??0,this._maxWidth=e?.maxWidth??Number.MAX_SAFE_INTEGER,this._maxWidth<=0&&(this._maxWidth=Number.MAX_SAFE_INTEGER),this._maxHeight=e?.maxHeight??Number.MAX_SAFE_INTEGER,this._maxHeight<=0&&(this._maxHeight=Number.MAX_SAFE_INTEGER);const n=t=>{if(this._linesRead.length>0){let e=this._linesRead[this._linesRead.length-1];t.y=e.y+e.height}if(t.y+t.height>this._maxHeight)return!1;this._maxXRead=Math.max(this._maxXRead,t.x+t.width),this._maxXWhitespaceRead=Math.max(this._maxXWhitespaceRead,t.x+t.widthWhitespace),this._maxYRead=Math.max(this._maxYRead,t.y+t.height),this._linesRead.push(t)};if(""===t){const e=this._measureText(t);n({startPosition:0,text:"",x:0,y:0,width:0,widthWhitespace:0,height:e.lineHeight,baseline:e.baseline})}else{this._breakWhiteSpace(t,n);if(new Gi(t.charAt(t.length-1).repeat(2)).nextBreak().required){const e=this._measureText(t);n({startPosition:t.length,text:"",x:0,y:0,width:0,widthWhitespace:0,height:e.lineHeight,baseline:e.baseline})}}const r={bounds:{x:0,y:0,width:this._maxXRead,widthWhitespace:this._maxXWhitespaceRead,height:this._maxYRead},lines:this._linesRead};return this._breaker=null,this._linesRead=[],r}}const Zi=(t,e,n,r=null,o=fi.getSharedMeasurer())=>{let s="",i=null,a=null;const l=t.paragraphs,c=l.length;for(let t=0;t<c;t++){const e=l[t].runs,n=e.length;for(let t=0;t<n;t++)s+=e[t].text,0===t&&(i=e[t]);0===t&&(a=l[t])}const h=t.insets??x.EmptyRect,u=new Yi(o),d=r?.width?r.width-h.right-h.left:r?.width,g=r?.height?r.height-h.bottom-h.top:null,m=u.wrap(s,{fontName:i.fontName,fontSize:i.fontSize*fi.getDeviceScale(),bold:i.bold,italic:i.italic,superSub:i.superSub,letterSpacing:i.letterSpacing,maxWidth:t.wrapped&&d?d:null,maxHeight:g});let f=[];const p=m.lines,_=p.length,S=new Array(_);for(let t=0;t<_;t++){const e=p[t],n={x:e.x,y:e.y,width:e.width,height:e.height},r=new Ti({text:e.text,fontName:i.fontFamily,fontSize:i.fontSize,bold:i.bold,italic:i.italic,superSub:i.superSub,letterSpacing:i.letterSpacing},n);f.push(r),S[t]=new Ni(n,e.baseline,[r])}const w=new Mi({runs:f,align:a.align});return new Ii({paragraphs:[w],wrapped:t.wrapped,verticalAlignment:t.verticalAlignment},e,n,S,{x:m.bounds.x,y:m.bounds.y,width:m.bounds.widthWhitespace,height:m.bounds.height},{x:m.bounds.x,y:m.bounds.y,width:m.bounds.width,height:m.bounds.height})},Qi=t=>{let e=!1,n=!1;for(let r=0;r<t.length;r++){const o=t.charCodeAt(r);if(o>=65&&o<=90?e=!0:o>=97&&o<=122&&(n=!0),e&&n)return 0}return e?1:n?-1:0},ta=(t,e,n,r,o=!1)=>{if(null==t)return null;const s=new Ti({text:t,fontName:e.toCSS().fontFamily,fontSize:e.getSize(),bold:e.getWeight()>400,italic:e.getStyle()===fi.Style.Italic,superSub:!o&&(e.getVerticalAlignment()===fi.VerticalAlignment.Sub||e.getVerticalAlignment()===fi.VerticalAlignment.Super),letterSpacing:e.getLetterSpacing()}),i=o?zs.HorizontalAlignment.Left:n.getHorizontal(),a=n.getVertical(),l=new Mi({runs:[s],align:i});let c=[];c.push(new Ni(null,e.getSize(),[s]));return new Ii({paragraphs:[l],wrapped:r&&(n.getOverflow()===zs.Overflow.Wrap||i===zs.HorizontalAlignment.Justify||i===zs.HorizontalAlignment.Distributed||a===zs.VerticalAlignment.Justify||a===zs.VerticalAlignment.Distributed),verticalAlignment:a},e,n,c)},ea=(t,e,n,r)=>({x:t*r-e*n,y:t*n+e*r}),na=t=>{let e=0,n=0,r=0,o=0,s=0,i=0,a=0,l=t.length;if(0===l)return{m:0,b:0};if(1===l)return{m:1,b:t[0]};for(let c=0;c<l;c++)i=c+1,a=t[c],null==a||isNaN(a)||(e+=i,n+=a,o+=i*i,r+=i*a,s++);const c=(s*r-e*n)/(s*o-e*e);return{m:c,b:n/s-c*e/s}},ra=(t,e)=>{if(null===e)return null;const n=_t.isObject(e);return null!=t&&n?_t.mergeContentful(t,e):n?_t.cloneObject(e):e},oa=(t,e,n)=>null==t||"object"==typeof t&&0===Object.keys(t).length;function sa(t,e,n,r){if(t===e)return t??null}function ia(t){return null==t}function aa(t,e,n=1,r){if(0===n)return{preceding:t?[...t]:[],modified:[],trailing:[]};const o=function(t,e,n=1){let r=_t.findEqualOrGreater(t,e,t=>t.max);const o=t.slice(0,r),s=[],i=[];if(!t[r])return{preceding:o,modified:s,trailing:i};for(let o=r;o<t.length;o++)e+n<t[o].min?i.push({...t[o],min:t[o].min-n,max:t[o].max-n}):e>=t[o].min?Math.max(e,t[o].max+1-n)>t[o].min&&s.push({...t[o],max:Math.max(e-1,t[o].max-n)}):e<t[o].min&&e+n<=t[o].max&&s.push({...t[o],min:Math.max(e,t[o].min-n),max:t[o].max-n});return{preceding:o,modified:s,trailing:i}}(t,e,n),s=o.preceding,i=o.trailing;let a=[];s.length>0&&a.push(s.pop()),a=a.concat(o.modified),i.length>0&&a.push(i.shift());return{preceding:s,modified:ha(a,{onMerge:sa}).modified,trailing:i}}function la(t,e,n){if(!t)throw new Error("runs can not be null");if(!e)return{preceding:[],modified:t?[...t]:[],trailing:[]};const r=function(t,e,n,r,o=!1){if(!e)return{preceding:[],modified:t?[...t]:[],trailing:[]};let s,i=_t.findEqualOrGreater(t,e.min,t=>t.max),a=t.slice(0,i),l=t.slice(i),c=[],h={...e},u=l[0]||{min:e.min,max:e.max,value:void 0};s=o?(t,e,n)=>{const o=(r||ra)(e,n,t);void 0!==o?t.value=o:delete t.value,c.push(t)}:(t,e,n)=>{const o=(r||ra)(e??null,n,t);void 0!==o?t.value=o:delete t.value,c.push(t)};for(;l.length>=0&&h.max-h.min>=0;){if(h.min<u.min)s({min:h.min,max:Math.min(h.max,u.min-1)},void 0,h.value),h={min:u.min,max:h.max,value:h.value},u={min:h.min,max:u.max,value:u.value};else if(h.min>u.min){const t=void 0!==u.value&&n?n(u,h.min):[u.value,u.value];c.push({min:u.min,max:Math.min(h.min,u.max)-1,value:t[0]}),h={min:Math.min(h.min,u.max),max:h.max,value:h.value},u={min:h.min,max:u.max,value:t[1]}}else{const t=void 0!==u.value&&n?n(u,h.min):[u.value,u.value];s({min:u.min,max:Math.min(h.max,u.max)},t[0],h.value),h={min:Math.min(h.max,u.max)+1,max:h.max,value:h.value},u={min:Math.min(h.max,u.max)+1,max:u.max,value:t[1]}}u.min<=u.max?l[0]=u:(l=l.slice(1),u=l[0]||{min:u.min,max:h.max})}return{preceding:a,modified:c,trailing:l}}(t,e,n?.onSplit,n?.onUpdate,n?.inPlace);let o=[];r.preceding.length>0&&o.push(r.preceding.pop()),o=o.concat(r.modified),r.trailing.length>0&&o.push(r.trailing.shift());const s=function(t,e){if(!t||0===t.length)return{preceding:[],modified:t?[...t]:[],trailing:[]};const n=Math.min(t.length-1,e?.startOffset??0),r=Math.min(t.length,e?.endOffset??t.length),o=e?.cull??ia;let s=t.slice(0,n),i=t.slice(r);const a=[];for(let e=n;e<r;e++)!0!==o(t[e].value,t[e].min,t[e].max)&&a.push(t[e]);return{preceding:s,modified:a,trailing:i}}(ha(o,{onMerge:n?.onMerge??sa}).modified,{cull:n?.isCull||oa});return{preceding:r.preceding,modified:s.modified,trailing:r.trailing}}function ca(t){return[...t.preceding,...t.modified,...t.trailing]}function ha(t,e){if(!t||0===t.length)return{preceding:[],modified:t?[...t]:[],trailing:[]};const n=Math.min(t.length-1,e?.startOffset??0),r=Math.min(t.length,e?.endOffset??t.length),o=e?.onMerge??sa;let s=t.slice(0,n),i=t.slice(r);const a=[];let l={...t[n]},c=t[n]?.max||0;for(let e=n+1;e<=r;e++){const n=t[e];let r=!1;if(n&&n.min<=t[e-1].max+1)if(void 0===l.value&&void 0===n.value)r=!0;else{const t=o(l.value,n.value,l.max-l.min+1,n.max-n.min+1);void 0!==t&&(r=!0,l.value=t)}r?l.max=Math.max(c,n.max):(a.push(l),l={...t[e]},n&&(l.max=Math.max(c,n.max))),l&&(c=l.max)}return{preceding:s,modified:a,trailing:i}}function ua(t){return t?t.sort((t,e)=>{let n=t.min-e.min;return 0===n&&(n=t.max-e.max),n}):t}const da=(t,e=!1)=>{if(!t||0===t.length)return _t.EmptyArray;const n=e?t:t.sort(),r=[];let o=null;for(let t=0;t<n.length;t++){const e=n[t];o?o.max===e-1?o.max=e:(r.push(o),o={min:e,max:e}):o={min:e,max:e}}return o&&r.push(o),r},ga=(t,e)=>t?e?t||e?t.min>e.max||t.max<e.min?null:{min:Math.max(t.min,e.min),max:Math.min(t.max,e.max)}:null:{...t}:{...e},ma=t=>{const e=0===t.length;return{runs:t,run:{min:e?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,max:e?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,value:null},index:Number.MAX_SAFE_INTEGER}},fa=(t,e)=>{const n=e.run,r=n.min,o=n.max;if(t>=r&&t<=o)return n.value;let s=e.index;const i=e.runs;if(s<i.length-1&&t>o){s++;const r=i[s],o=r.min,a=r.max;if(t>=o&&t<=a)return e.index=s,n.min=o,n.max=a,n.value=r.value,n.value}if(s!==Number.MAX_SAFE_INTEGER&&s>0&&t<r){s--;const r=i[s],o=r.min,a=r.max;if(t>=o&&t<=a)return e.index=s,n.min=o,n.max=a,n.value=r.value,n.value}if(s=_t.findEqualOrGreater(i,t,t=>t.max),s===i.length)return s=i.length,e.index=s,n.min=i[s-1].max+1,n.max=Number.MAX_SAFE_INTEGER,n.value=null,null;const a=i[s],l=a.min,c=a.max;if(t>=l&&t<=c){e.index=s,n.min=l,n.max=c;const t=a.value;return n.value=t,t}return s--,e.index=s,n.min=s>=0?i[s].max+1:Number.MIN_SAFE_INTEGER,n.max=l-1,n.value=null,null},pa=function(t,e,n,r){if(0===t.length){if(null!=n||null!=r){const t=e({min:n??r,max:r??n});if(t&&t.break)return t}return}const o=n??t[0].min,s=r??t[t.length-1].max;let i=o-1,a=_t.findEqualOrGreater(t,o,t=>t.max),l=t[a];for(;l&&l.min<=s;){if(i<l.min-1){const t=e({min:Math.max(i+1,o),max:Math.min(l.min-1,s)});if(t&&t.break)return t}const n=e({...l,min:Math.max(l.min,o),max:Math.min(l.max,s)});if(n&&n.break)return n;i=l.max,l=t[++a]}if(i<s){const t=e({min:Math.min(i+1,s),max:s});if(t&&t.break)return t}},_a=new RegExp("([0-9]+)$");var Sa,wa,ya,Ea,ba,va;(t=>{t.Date=class{constructor(t){this._options=t}canFill(t,e){return ms(t)}createFillAt(t,e){e={...this._options,...e};let n=0,r=this._options?.unit;r||(r=1===t.length?ps:((t,e=!1)=>{if(!t||t.length<1)return ps;let n=t;e||(n=t.slice(),n=n.sort((t,e)=>t.getTime()-e.getTime()));let r=!1,o=-1,s=-1;for(let t=0;t<n.length;t++){let e=n[t];if(t>n.length-1&&e.getTime()<n[t+1].getTime())throw new Error("Dates are expected to be sorted.");let i=12*e.getFullYear()+e.getMonth();if(i===s)return ps;s=i;let a=e.getFullYear();a>o?o=a:r=!0}return r?_s:Ss})(t));const o=ws(t[0],0,r);o.setHours(0,0,0,0);let s=1;e?.reverse&&(s*=-1,n*=-1);for(let e=1;e<t.length;e++){let n=fs(t[e-1],t[e],r);if(1===e)s=n;else if(n!==s)return null}return 1===t.length&&e.multiFill,t=>{const e=ws(o,s*t,r);if(0!==n){const r=0+n*t,o=r%1440,s=Math.floor(o/60),i=o%60;e.setHours(s,i,0,0);const a=Math.floor(r/1440),l=Math.floor(a/365),c=a%365,h=Math.floor(c/30),u=c%30;l>0&&e.setFullYear(e.getFullYear()+l),h>0&&e.setMonth(e.getMonth()+h),u>0&&e.setDate(e.getDate()+u)}return e}}};t.Linear=class{constructor(t){this._options=t}canFill(t,e){return"number"==typeof t||null===t}createFillAt(t,e){e={...this._options,...e};const n=na(t),r=n.b;let o=n.m;return 1===t.length?(e.reverse&&(o=-o),e.multiFill?t=>t*o+r:null):t=>o*(t+1)+r}};const e={value:null,template:null},n={sensitivity:"accent"};t.Ordinal=class{_template(t){const e=t.match(_a);if(!e)return null;const n=e[1],r=t.lastIndexOf(n);return-1===r?null:t.substring(0,r)}canFill(t,r){if(null===t)return!0;if("string"!=typeof t)return e.value=null,!1;const o=this._template(t);return o&&(void 0===r||r===e.value&&0===o.localeCompare(e.template,void 0,n))?(e.value=t,e.template=o,!0):(e.value=null,!1)}createFillAt(t,e){const n=[],r=t[0];let o=null,s=null,i=0;if(r){const t=r.match(_a);if(t){o=t[1],o.startsWith("0")&&(i=o.length);const e=r.lastIndexOf(o);s=r.substring(0,e)}}const a=t.length;for(let e=0;e<a;e++){const r=t[e];let o=null;if(r){const t=r.substring(s.length,r.length);t.startsWith("0")&&(i=Math.max(i,t.length));const e=parseFloat(t);isNaN(e)||(o=e)}n.push(o)}const l=na(n),c=l.b;let h=l.m;return 0!==h&&Number.isInteger(h)?n=>{if(null===t[n%a])return null;const r=(1===a?e.reverse?-n:n:h*(n+1))+c,o=""+Math.abs(r),l="0".repeat(Math.max(0,i-o.length))+o;return s+l}:null}};t.Copy=class{canFill(t,e){return!0}createFillAt(t,e){const n=t.length;return e=>t[e%n]??null}};const r=Object.freeze(["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]),o=Object.freeze(["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]),s=Object.freeze(["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),i=Object.freeze(["January","February","March","April","May","June","July","August","September","October","November","December"]);t.List=class{constructor(t){this._lists=[],this._map=new Map;const e=[];if(t?.customLists){const n=t.customLists;for(let t=n.length-1;t>0;t--)e.push(n[t])}e.push(i),e.push(s),e.push(o),e.push(r);const n=this._map,a=[];for(let t=0;t<e.length;t++){const r=e[t],o=[];a.push(o);for(let e=0;e<r.length;e++){const s=r[e],i=Hs(s,!0),a=i.toLowerCase().trim();let l=n.get(a);l||(l=[],n.set(a,l));const c={value:i,asKey:a,major:t,minor:e};l.push(c),o.push(c)}}this._lists=Object.freeze(a)}canFill(t,e){if(null===t)return!0;if("string"!=typeof t)return!1;return!!this._map.get(t.toLowerCase().trim())}createFillAt(t,e){const n=[],r=t[0];n.push(r.toLowerCase().trim());const o=this._map.get(n[0]);let s;const i=new Map,a=new Set;for(let t=0;t<o.length;t++){const e=o[t];i.set(e.major,e)}if(t.length>1){for(let e=1;e<t.length;e++){const r=t[e].toLowerCase().trim(),o=this._map.get(r);if(!o)return null;1===e&&(s=o),n.push(r);for(let t=0;t<o.length;t++){const e=o[t].major;i.has(e)&&a.add(e)}}if(0===a.size)return null}let l=null;const c=this._lists;for(let e=0;!l&&e<c.length;e++)(1===t.length||a.has(e))&&(l=i.get(e));if(!l)return null;let h=null;for(let t=0;!h&&s&&t<s.length;t++)s[t].asKey===n[1]&&(h=s[t]);let u=!1,d=!1;const g=Qi(r);1===g?u=!0:(-1===g||-1===Qi(r[0]))&&(d=!0);const m=c[l.major];let f=l.minor,p=1;if(n.length>1){p=h.minor-l.minor;for(let t=2;t<n.length;t++)if(m[t+f].minor-m[t-1+f].minor!==p)return null}1===t.length&&e?.reverse&&(p=-p);const _=t.length,S=m.length;return e=>{if(null===t[e%_])return null;let n=(e*p+f)%S;n<0&&(n=S+n);const r=m[n].value??null;return u?r.toUpperCase():d?r.toLowerCase():r}}};t.Composite=class{constructor(t){t=Array.isArray(t)?[...t]:[t],this._fillers=t}canFill(t,e){return!0}createFillAt(t,e){const n=this._fillers;e={multiFill:t.length>1,...e};const r=t.length;let o=0,s=!1;for(let e=0;!s&&e<=r;e++)null===t[e]?o++:s=!0;let i=0;s=!1;for(let e=r-1;!s&&e>=o;e--)null===t[e]?i++:s=!0;const a=[];let l=null,c=null,h=[],u=o,d=0;const g=t=>{if(l&&l.max+1===u){const e=l.value;e.fillAt.push(t),l.max=u,e.length++,e.valuesLength++}else l={min:u,max:u,value:{fillAt:[t],start:u,length:1,valuesLength:r,blankInterval:0}};a.push(l)},m=r-i;for(u=o;u<m;){let r=t[u];if(null===r){u++;continue}c=null;let o,s=1,i=!1;for(let t=0;!i&&t<n.length+1;t++){const e=n[t];e&&(i=e.canFill(r,o),i&&(c=e))}if(!c){null!==r&&g(r),u++;continue}let l=0;d=0,o=r;do{r=t[u+s],i=c.canFill(r,o),i&&(null!==r?(o=r,l>0&&(s-l===1?d=l:l!==d&&(d=0)),l=0):l++,s++)}while(i&&u+s<m);h=[t[u]];const f=1+d,p=s-l;for(let e=f;e<p;e+=f)h.push(t[u+e]);if(h.length>0){const t=h.length,n=t+(t-1)*d,r=c.createFillAt?.(h,e)??h;a.push({min:u,max:u+n-1,value:{fillAt:r,start:u,length:n,valuesLength:t,blankInterval:d}})}u+=s}const f=ma(a);return t=>{const e=t>=0,n=Math.abs(t),o=fa(n%r,f);if(!o)return null;const s=Math.floor(n/r),i=o.length,a=o.start,l=(s+(e?1:0))*a+(s+(e?0:1))*(r-(a+i));let c=t+(e?-l:l);const h=o.blankInterval;if(0!==h){let t=c%i;if(0!==t%(1+h))return null;c=Math.floor(t/(1+h))+o.valuesLength*s}const u=o.fillAt;return"function"==typeof u?u(c):u[c%u.length]}}},t.Types={Series:new t.Composite([new t.Date,new t.Linear,new t.Ordinal,new t.List]),DateDays:new t.Date({unit:ps}),DateMonths:new t.Date({unit:_s}),DateYears:new t.Date({unit:Ss}),Copy:new t.Copy},t.fillTo=(t,e,n,r)=>{const o=[],s=e.length,i=t.createFillAt(e,r);for(let t=s;t<n;t++)o.push(i(t));return o}})(Sa||(Sa={})),wa||(wa={}),(Ea=ya||(ya={})).Type={None:"none",Solid:"solid",Gradient:"gradient",Pattern:"pattern",Image:"pattern",Background:"background",Group:"group",Custom:"custom"},Ea.GradientType={Linear:"linear",Path:"path",Circular:"circular",Rect:"rect"},Ea.TileMirror={None:"none",Vertical:"v",Horizontal:"h",Both:"b"},Ea.BuiltInSheetPattern={None:"none",Solid:"solid",DarkGray:"darkGray",MediumGray:"mediumGray",LightGray:"lightGray",Gray0625:"gray0625",Gray125:"gray125",DarkHorizontal:"darkHorizontal",DarkVertical:"darkVertical",DarkDown:"darkDown",DarkUp:"darkUp",DarkGrid:"darkGrid",DarkTrellis:"darkTrellis",LightHorizontal:"lightHorizontal",LightVertical:"lightVertical",LightDown:"lightDown",LightUp:"lightUp",LightGrid:"lightGrid",LightTrellis:"lightTrellis",Custom:"custom"},(va=ba||(ba={})).AdjustmentType={Alpha:"alpha",AlphaOff:"alphaOff",AlphaMod:"alphaMod",Hue:"hue",Sat:"sat",Lum:"lum",HueOff:"hueOff",SatOff:"satOff",LumOff:"lumOff",HueMod:"hueMod",SatMod:"satMod",LumMod:"lumMod",Red:"red",Green:"green",Blue:"blue",RedOff:"redOff",GreenOff:"greenOff",BlueOff:"blueOff",RedMod:"redMod",GreenMod:"greenMod",BlueMod:"blueMod",Shade:"shade",Tint:"tint",ETint:"eTint",Gray:"gray",Comp:"comp",Inv:"inv",Gamma:"gamma",InvGamma:"invGamma"},va.Named={ActiveBorder:"activeBorder",ActiveCaption:"activeCaption",CaptionText:"captionText",AppWorkspace:"appWorkspace",BtnFace:"btnFace",BtnShadow:"btnShadow",DkShadow3d:"3dDkShadow",BtnHighlight:"btnHighlight",Light3d:"3dLight",BtnText:"btnText",Background:"background",GrayText:"grayText",Highlight:"highlight",HighlightText:"highlightText",HotLight:"hotLight",InactiveBorder:"inactiveBorder",InactiveCaption:"inactiveCaption",InactiveCaptionText:"inactiveCaptionText",InfoBk:"infoBk",InfoText:"infoText",Menu:"menu",MenuText:"menuText",ScrollBar:"scrollBar",Window:"window",WindowFrame:"windowFrame",WindowText:"windowText",Transparent:"transparent",AliceBlue:"aliceBlue",AntiqueWhite:"antiqueWhite",Aqua:"aqua",Aquamarine:"aquamarine",Azure:"azure",Beige:"beige",Bisque:"bisque",Black:"black",BlanchedAlmond:"blanchedAlmond",Blue:"blue",BlueViolet:"blueViolet",Brown:"brown",BurlyWood:"burlyWood",CadetBlue:"cadetBlue",Chartreuse:"chartreuse",Chocolate:"chocolate",Coral:"coral",CornflowerBlue:"cornflowerBlue",Cornsilk:"cornsilk",Crimson:"crimson",Cyan:"cyan",DkBlue:"dkBlue",DkCyan:"dkCyan",DkGoldenrod:"dkGoldenrod",DkGray:"dkGray",DkGreen:"dkGreen",DkKhaki:"dkKhaki",DkMagenta:"dkMagenta",DkOliveGreen:"dkOliveGreen",DkOrange:"dkOrange",DkOrchid:"dkOrchid",DkRed:"dkRed",DkSalmon:"dkSalmon",DkSeaGreen:"dkSeaGreen",DkSlateBlue:"dkSlateBlue",DkSlateGray:"dkSlateGray",DkTurquoise:"dkTurquoise",DkViolet:"dkViolet",DeepPink:"deepPink",DeepSkyBlue:"deepSkyBlue",DimGray:"dimGray",DodgerBlue:"dodgerBlue",Firebrick:"firebrick",FloralWhite:"floralWhite",ForestGreen:"forestGreen",Fuchsia:"fuchsia",Gainsboro:"gainsboro",GhostWhite:"ghostWhite",Gold:"gold",Goldenrod:"goldenrod",Gray:"gray",Green:"green",GreenYellow:"greenYellow",Honeydew:"honeydew",HotPink:"hotPink",IndianRed:"indianRed",Indigo:"indigo",Ivory:"ivory",Khaki:"khaki",Lavender:"lavender",LavenderBlush:"lavenderBlush",LawnGreen:"lawnGreen",LemonChiffon:"lemonChiffon",LtBlue:"ltBlue",LtCoral:"ltCoral",LtCyan:"ltCyan",LtGoldenrodYellow:"ltGoldenrodYellow",LtGray:"ltGray",LtGreen:"ltGreen",LtPink:"ltPink",LtSalmon:"ltSalmon",LtSeaGreen:"ltSeaGreen",LtSkyBlue:"ltSkyBlue",LtSlateGray:"ltSlateGray",LtSteelBlue:"ltSteelBlue",LtYellow:"ltYellow",Lime:"lime",LimeGreen:"limeGreen",Linen:"linen",Magenta:"magenta",Maroon:"maroon",MedAquamarine:"medAquamarine",MedBlue:"medBlue",MedOrchid:"medOrchid",MedPurple:"medPurple",MedSeaGreen:"medSeaGreen",MedSlateBlue:"medSlateBlue",MedSpringGreen:"medSpringGreen",MedTurquoise:"medTurquoise",MedVioletRed:"medVioletRed",MidnightBlue:"midnightBlue",MintCream:"mintCream",MistyRose:"mistyRose",Moccasin:"moccasin",NavajoWhite:"navajoWhite",Navy:"navy",OldLace:"oldLace",Olive:"olive",OliveDrab:"oliveDrab",Orange:"orange",OrangeRed:"orangeRed",Orchid:"orchid",PaleGoldenrod:"paleGoldenrod",PaleGreen:"paleGreen",PaleTurquoise:"paleTurquoise",PaleVioletRed:"paleVioletRed",PapayaWhip:"papayaWhip",PeachPuff:"peachPuff",Peru:"peru",Pink:"pink",Plum:"plum",PowderBlue:"powderBlue",Purple:"purple",Red:"red",RosyBrown:"rosyBrown",RoyalBlue:"royalBlue",SaddleBrown:"saddleBrown",Salmon:"salmon",SandyBrown:"sandyBrown",SeaGreen:"seaGreen",SeaShell:"seaShell",Sienna:"sienna",Silver:"silver",SkyBlue:"skyBlue",SlateBlue:"slateBlue",SlateGray:"slateGray",Snow:"snow",SpringGreen:"springGreen",SteelBlue:"steelBlue",Tan:"tan",Teal:"teal",Thistle:"thistle",Tomato:"tomato",Turquoise:"turquoise",Violet:"violet",Wheat:"wheat",White:"white",WhiteSmoke:"whiteSmoke",Yellow:"yellow",YellowGreen:"yellowGreen",ButtonFace:"buttonFace",ButtonHighlight:"buttonHighlight",ButtonShadow:"buttonShadow",GradientActiveCaption:"gradientActiveCaption",GradientInactiveCaption:"gradientInactiveCaption",MenuBar:"menuBar",MenuHighlight:"menuHighlight"},va.Scheme={Bg1:"bg1",Bg2:"bg2",Tx1:"tx1",Tx2:"tx2",Accent1:"accent1",Accent2:"accent2",Accent3:"accent3",Accent4:"accent4",Accent5:"accent5",Accent6:"accent6",Hlink:"hlink",FolHlink:"folHlink"},va.Type={Scheme:"scheme",Named:"named",Index:"index",HSL:"hsl",RGB:"rgb",LRGB:"lrgb",Hex:"hex"};const Ca=[[4290032820,1,ba.Named.ActiveBorder,!0],[4288263377,2,ba.Named.ActiveCaption,!0],[4278190080,3,ba.Named.CaptionText,!0],[4289440683,4,ba.Named.AppWorkspace,!0],[4293980400,5,ba.Named.BtnFace,!0],[4285098345,6,ba.Named.BtnShadow,!0],[4278190080,7,ba.Named.DkShadow3d,!0],[4293125091,8,ba.Named.BtnHighlight,!0],[4293125091,9,ba.Named.Light3d,!0],[4278190080,10,ba.Named.BtnText,!0],[4278190080,11,ba.Named.Background,!0],[4285361517,12,ba.Named.GrayText,!0],[4281571839,13,ba.Named.Highlight,!0],[4294967295,14,ba.Named.HighlightText,!0],[4278216396,15,ba.Named.HotLight,!0],[4294244348,16,ba.Named.InactiveBorder,!0],[4290760155,17,ba.Named.InactiveCaption,!0],[4278190080,18,ba.Named.InactiveCaptionText,!0],[4294967265,19,ba.Named.InfoBk,!0],[4278190080,20,ba.Named.InfoText,!0],[4293980400,21,ba.Named.Menu,!0],[4278190080,22,ba.Named.MenuText,!0],[4291348680,23,ba.Named.ScrollBar,!0],[4294967295,24,ba.Named.Window,!0],[4284769380,25,ba.Named.WindowFrame,!0],[4278190080,26,ba.Named.WindowText,!0],[16777215,27,ba.Named.Transparent],[4293982463,28,ba.Named.AliceBlue],[4294634455,29,ba.Named.AntiqueWhite],[4278255615,30,ba.Named.Aqua],[4286578644,31,ba.Named.Aquamarine],[4293984255,32,ba.Named.Azure],[4294309340,33,ba.Named.Beige],[4294960324,34,ba.Named.Bisque],[4278190080,35,ba.Named.Black],[4294962125,36,ba.Named.BlanchedAlmond],[4278190335,37,ba.Named.Blue],[4287245282,38,ba.Named.BlueViolet],[4289014314,39,ba.Named.Brown],[4292786311,40,ba.Named.BurlyWood],[4284456608,41,ba.Named.CadetBlue],[4286578432,42,ba.Named.Chartreuse],[4291979550,43,ba.Named.Chocolate],[4294934352,44,ba.Named.Coral],[4284782061,45,ba.Named.CornflowerBlue],[4294965468,46,ba.Named.Cornsilk],[4292613180,47,ba.Named.Crimson],[4278255615,48,ba.Named.Cyan],[4278190219,49,ba.Named.DkBlue],[4278225803,50,ba.Named.DkCyan],[4290283019,51,ba.Named.DkGoldenrod],[4289309097,52,ba.Named.DkGray],[4278215680,53,ba.Named.DkGreen],[4290623339,54,ba.Named.DkKhaki],[4287299723,55,ba.Named.DkMagenta],[4283788079,56,ba.Named.DkOliveGreen],[4294937600,57,ba.Named.DkOrange],[4288230092,58,ba.Named.DkOrchid],[4287299584,59,ba.Named.DkRed],[4293498490,60,ba.Named.DkSalmon],[4287609995,61,ba.Named.DkSeaGreen],[4282924427,62,ba.Named.DkSlateBlue],[4281290575,63,ba.Named.DkSlateGray],[4278243025,64,ba.Named.DkTurquoise],[4287889619,65,ba.Named.DkViolet],[4294907027,66,ba.Named.DeepPink],[4278239231,67,ba.Named.DeepSkyBlue],[4285098345,68,ba.Named.DimGray],[4280193279,69,ba.Named.DodgerBlue],[4289864226,70,ba.Named.Firebrick],[4294966e3,71,ba.Named.FloralWhite],[4280453922,72,ba.Named.ForestGreen],[4294902015,73,ba.Named.Fuchsia],[4292664540,74,ba.Named.Gainsboro],[4294506751,75,ba.Named.GhostWhite],[4294956800,76,ba.Named.Gold],[4292519200,77,ba.Named.Goldenrod],[4286611584,78,ba.Named.Gray],[4278222848,79,ba.Named.Green],[4289593135,80,ba.Named.GreenYellow],[4293984240,81,ba.Named.Honeydew],[4294928820,82,ba.Named.HotPink],[4291648604,83,ba.Named.IndianRed],[4283105410,84,ba.Named.Indigo],[4294967280,85,ba.Named.Ivory],[4293977740,86,ba.Named.Khaki],[4293322490,87,ba.Named.Lavender],[4294963445,88,ba.Named.LavenderBlush],[4286381056,89,ba.Named.LawnGreen],[4294965965,90,ba.Named.LemonChiffon],[4289583334,91,ba.Named.LtBlue],[4293951616,92,ba.Named.LtCoral],[4292935679,93,ba.Named.LtCyan],[4294638200,94,ba.Named.LtGoldenrodYellow],[4292072403,95,ba.Named.LtGray],[4287688336,96,ba.Named.LtGreen],[4294948545,97,ba.Named.LtPink],[4294942842,98,ba.Named.LtSalmon],[4280332970,99,ba.Named.LtSeaGreen],[4287090426,100,ba.Named.LtSkyBlue],[4286023833,101,ba.Named.LtSlateGray],[4289774814,102,ba.Named.LtSteelBlue],[4294967264,103,ba.Named.LtYellow],[4278255360,104,ba.Named.Lime],[4281519410,105,ba.Named.LimeGreen],[4294635750,106,ba.Named.Linen],[4294902015,107,ba.Named.Magenta],[4286578688,108,ba.Named.Maroon],[4284927402,109,ba.Named.MedAquamarine],[4278190285,110,ba.Named.MedBlue],[4290401747,111,ba.Named.MedOrchid],[4287852763,112,ba.Named.MedPurple],[4282168177,113,ba.Named.MedSeaGreen],[4286277870,114,ba.Named.MedSlateBlue],[4278254234,115,ba.Named.MedSpringGreen],[4282962380,116,ba.Named.MedTurquoise],[4291237253,117,ba.Named.MedVioletRed],[4279834992,118,ba.Named.MidnightBlue],[4294311930,119,ba.Named.MintCream],[4294960353,120,ba.Named.MistyRose],[4294960309,121,ba.Named.Moccasin],[4294958765,122,ba.Named.NavajoWhite],[4278190208,123,ba.Named.Navy],[4294833638,124,ba.Named.OldLace],[4286611456,125,ba.Named.Olive],[4285238819,126,ba.Named.OliveDrab],[4294944e3,127,ba.Named.Orange],[4294919424,128,ba.Named.OrangeRed],[4292505814,129,ba.Named.Orchid],[4293847210,130,ba.Named.PaleGoldenrod],[4288215960,131,ba.Named.PaleGreen],[4289720046,132,ba.Named.PaleTurquoise],[4292571283,133,ba.Named.PaleVioletRed],[4294963157,134,ba.Named.PapayaWhip],[4294957753,135,ba.Named.PeachPuff],[4291659071,136,ba.Named.Peru],[4294951115,137,ba.Named.Pink],[4292714717,138,ba.Named.Plum],[4289781990,139,ba.Named.PowderBlue],[4286578816,140,ba.Named.Purple],[4294901760,141,ba.Named.Red],[4290547599,142,ba.Named.RosyBrown],[4282477025,143,ba.Named.RoyalBlue],[4287317267,144,ba.Named.SaddleBrown],[4294606962,145,ba.Named.Salmon],[4294222944,146,ba.Named.SandyBrown],[4281240407,147,ba.Named.SeaGreen],[4294964718,148,ba.Named.SeaShell],[4288696877,149,ba.Named.Sienna],[4290822336,150,ba.Named.Silver],[4287090411,151,ba.Named.SkyBlue],[4285160141,152,ba.Named.SlateBlue],[4285563024,153,ba.Named.SlateGray],[4294966010,154,ba.Named.Snow],[4278255487,155,ba.Named.SpringGreen],[4282811060,156,ba.Named.SteelBlue],[4291998860,157,ba.Named.Tan],[4278222976,158,ba.Named.Teal],[4292394968,159,ba.Named.Thistle],[4294927175,160,ba.Named.Tomato],[4282441936,161,ba.Named.Turquoise],[4293821166,162,ba.Named.Violet],[4294303411,163,ba.Named.Wheat],[4294967295,164,ba.Named.White],[4294309365,165,ba.Named.WhiteSmoke],[4294967040,166,ba.Named.Yellow],[4288335154,167,ba.Named.YellowGreen],[4293980400,168,ba.Named.ButtonFace],[4294967295,169,ba.Named.ButtonHighlight],[4288716960,170,ba.Named.ButtonShadow],[4290367978,171,ba.Named.GradientActiveCaption],[4292338930,172,ba.Named.GradientInactiveCaption],[4293980400,173,ba.Named.MenuBar],[4281571839,174,ba.Named.MenuHighlight]];const xa=new class{constructor(){this._lookupByName=new Map;for(let t=0;t<Ca.length;t++){const e=Ca[t],n=e[0],r=(n>>24&255)/255,o=n>>16&255,s=n>>8&255,i=255&n,a={id:e[1],name:e[2],rgbaColor:{r:o,g:s,b:i,a:r},system:e.length>3};this._lookupByName.set(a.name.toLowerCase(),a)}}valueOfName(t){return this._lookupByName.get(t?t.toLowerCase():"transparent")}},Ia=[{scheme:ba.Scheme.Tx1,description:"First Text Color"},{scheme:ba.Scheme.Tx2,description:"Second Text Color"},{scheme:ba.Scheme.Bg1,description:"First Background Color"},{scheme:ba.Scheme.Bg2,description:"Second Background Color"},{scheme:ba.Scheme.Accent1,description:"Accent 1"},{scheme:ba.Scheme.Accent2,description:"Accent 2"},{scheme:ba.Scheme.Accent3,description:"Accent 3"},{scheme:ba.Scheme.Accent4,description:"Accent 4"},{scheme:ba.Scheme.Accent5,description:"Accent 5"},{scheme:ba.Scheme.Accent6,description:"Accent 6"},{scheme:ba.Scheme.Hlink,description:"Hyperlink"},{scheme:ba.Scheme.FolHlink,description:"Followed Hyperlink"},{scheme:"dk1",description:"Text/Background - Dark 1"},{scheme:"lt1",description:"Text/Background - Light 1"},{scheme:"dk2",description:"Text/Background - Dark 2"},{scheme:"lt2",description:"Text/Background - Light 2"}],Aa=new Map;for(let t=0;t<Ia.length;t++)Aa.set(Ia[t].scheme.toLowerCase(),Ia[t]);const Ra=t=>t?{srgb:[t.red/255,t.green/255,t.blue/255],alpha:void 0!==t.alpha?t.alpha:1}:null,Ma=function(t,e,n,r){let o=Ra((t=>{let e=xa.valueOfName(t);return e?new Do.RGBA(e.rgbaColor.r,e.rgbaColor.g,e.rgbaColor.b,e.rgbaColor.a):null})(t)),s=null,i=null,a=null;if(null===o&&(l=t,Aa.get(l.toLowerCase()))){if(!e)throw new Error("a scheme val was used but a schemeLookup was not provided");s=t,i=e(s),o=Ra(i),a=ba.Type.Scheme}var l;if(null===o){let e=t.match(qr)||t.match(Jr);if(e){let t,n=1;4===e.length?t=[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]:(t=[parseInt(e[2],16),parseInt(e[3],16),parseInt(e[4],16)],n=to(parseInt(e[1],16)/255)),t=Yr(t),t=Qr(t),o={srgb:t,alpha:n},a=ba.Type.Hex}}if(null===o){let e=t.match(Hr)||t.match(Vr);if(e){let t=Kr(e[1],e[2],e[3]);t=Yr(t),t=Qr(t),o={srgb:t,alpha:e[4]?to(parseFloat(e[4])):1},a=ba.Type.RGB}}if(null===o){let e=t.match($r)||t.match(Ur);if(e){let t=Kr(e[1],e[2],e[3]);t=Yr(t,100),t=ro(t),t=Qr(t),o={srgb:t,alpha:e[4]?to(parseFloat(e[4])):1},a=ba.Type.LRGB}}if(null===o){let e=t.match(Gr)||t.match(Wr);if(e){let t=Kr(e[1],e[2],e[3]);t=io(t),t=Qr(t),o={srgb:t,alpha:e[4]?to(parseFloat(e[4])):1},a=ba.Type.HSL}}if(null===o){let e=t.match(Xr);if(e){const t=parseInt(e[1]);let r=n?.(t)??Vo(t);r&&(o={srgb:[r.red/255,r.green/255,r.blue/255],alpha:r.alpha},a=ba.Type.Index)}}if(null===o)throw new Error("Not a valid color format: "+t);return{srgbAlpha:o,key:s,color:i,type:a}},Ta=new Map,Na=Object.keys(ba.AdjustmentType);for(let t=0;t<Na.length;t++)Ta.set(ba.AdjustmentType[Na[t]].toLowerCase(),ba.AdjustmentType[Na[t]]);const Fa=new RegExp("\\s+\\s*(?![^()]*\\))|,\\s*(?![^()]*\\))"),ka=new RegExp("\\s*[,]\\s*|\\s+");let Oa=null;const La={[ba.Scheme.Bg1]:"window",[ba.Scheme.Bg2]:"E7E6E6",[ba.Scheme.Tx1]:"windowText",[ba.Scheme.Tx2]:"44546A",[ba.Scheme.Accent1]:"4472C4",[ba.Scheme.Accent2]:"ED7D31",[ba.Scheme.Accent3]:"A5A5A5",[ba.Scheme.Accent4]:"FFC000",[ba.Scheme.Accent5]:"5B9BD5",[ba.Scheme.Accent6]:"70AD47",[ba.Scheme.Hlink]:"0563C1",[ba.Scheme.FolHlink]:"954F72"};class Da{constructor(t,e,n,r=null){let o=null,s=null;if(t instanceof Da)o=t.getVal(),t.getAdjustments()&&(s=[...t.getAdjustments()]);else if("string"==typeof t){const e=this._parse(t);o=e.val,s=e.adjs}else t?.val&&(o=t.val,s=t.adjs);if(!o)throw new Error("Unable to determine color value");this._private={val:o,adjs:s,schemeLookup:e,indexedLookup:n,parsedVal:Ma(o,e,n),adjusted:null,resolved:null}}_parse(t){let e=null,n=t.toLowerCase().trim();const r=n.split(Fa);if(r&&(e=r[0],n=n.substring(e.length,n.length).trim()),!e)throw new Error("no color key found");const o=[],s=n.split(ka);for(let t=0;t<s.length;t++){const e=s[t];if(!e)continue;const n=Ta.get(e.toLowerCase());if(!n)throw new Error("Invalid adjustment type:"+e);let r=null;if(n===ba.AdjustmentType.Gray||n===ba.AdjustmentType.Comp||n===ba.AdjustmentType.Inv||n===ba.AdjustmentType.Gamma||n===ba.AdjustmentType.InvGamma);else{t++;const n=s[t];if(r=parseFloat(n),null==r)throw new Error(`Invalid adjustment value: missing value for'${e}'`);if(isNaN(r))throw new Error("Invalid adjustment value:"+n)}o.push({[n]:r})}return{val:e,adjs:o}}_forceDark(t=!0){this._resolve();const e=this._private.resolved;let n=[e.red,e.green,e.blue];n=((t,e)=>{e=(e%360+360)%360;const n=[1,0,0,0,1,0,0,0,1],r=Math.cos(e*Math.PI/180),o=Math.sin(e*Math.PI/180);n[0]=ko+.7874*r-ko*o,n[1]=Oo-Oo*r-Oo*o,n[2]=Lo-Lo*r+.9278*o,n[3]=ko-ko*r+.143*o,n[4]=Oo+(1-Oo)*r+.14*o,n[5]=Lo-Lo*r-.283*o,n[6]=ko-ko*r-.7874*o,n[7]=Oo-Oo*r+Oo*o,n[8]=Lo+.9278*r+Lo*o;const s=t=>Math.round(Math.max(0,Math.min(255,t))),i=t[0],a=t[1],l=t[2];return[s(n[0]*i+n[1]*a+n[2]*l),s(n[3]*i+n[4]*a+n[5]*l),s(n[6]*i+n[7]*a+n[8]*l)]})(n,180),n=Mo(n,!1);let r=no(n);const o=lo(r);if(o[uo]=.95*o[uo],r=io(o),n=ro(r),n=Zr(n),n=Qr(n,!1),t)return new Do.RGBA(n[0],n[1],n[2],e.alpha);const s=lo(no(n));return new Do.HSLA(s[0],s[1],s[2],e.alpha)}_resolve(){if(this._private.resolved){if(!this._private.parsedVal.key)return;let t=this._private.schemeLookup(this._private.parsedVal.key);if(t===this._private.parsedVal.color||t?.isEqual(this._private.parsedVal.color))return}const t=Ma(this._private.val,this._private.schemeLookup,this._private.indexedLookup,this._private.last);let e=((t,e)=>{let n=[...t.srgb],r=void 0!==t.alpha?t.alpha:1;for(var o=0;e&&o<e.length;o++){const t=e[o],s=Object.keys(t)[0],i=t[s];s===ba.AdjustmentType.Alpha?(r=i/100,r=Math.max(0,Math.min(1,r))):s===ba.AdjustmentType.AlphaOff?(r+=i/100,r=Math.max(0,Math.min(1,r))):s===ba.AdjustmentType.AlphaMod?(r*=i/100,r=Math.max(0,Math.min(1,r))):s===ba.AdjustmentType.Hue?n=vo(co,n,i):s===ba.AdjustmentType.Sat?n=vo(ho,n,i):s===ba.AdjustmentType.Lum?n=vo(uo,n,i):s===ba.AdjustmentType.HueOff?n=Co(co,n,i):s===ba.AdjustmentType.SatOff?n=Co(ho,n,i):s===ba.AdjustmentType.LumOff?n=Co(uo,n,i):s===ba.AdjustmentType.HueMod?n=xo(co,n,i):s===ba.AdjustmentType.SatMod?n=xo(ho,n,i):s===ba.AdjustmentType.LumMod?n=xo(uo,n,i):s===ba.AdjustmentType.Red?n=Io(go,n,i,po):s===ba.AdjustmentType.Green?n=Io(mo,n,i,po):s===ba.AdjustmentType.Blue?n=Io(fo,n,i,po):s===ba.AdjustmentType.RedOff?n=Io(go,n,i,_o):s===ba.AdjustmentType.GreenOff?n=Io(mo,n,i,_o):s===ba.AdjustmentType.BlueOff?n=Io(fo,n,i,_o):s===ba.AdjustmentType.RedMod?n=Io(go,n,i,So):s===ba.AdjustmentType.GreenMod?n=Io(mo,n,i,So):s===ba.AdjustmentType.BlueMod?n=Io(fo,n,i,So):s===ba.AdjustmentType.Shade?n=wo(n,i):s===ba.AdjustmentType.Tint?n=bo(n,i):s===ba.AdjustmentType.ETint?n=Eo(n,i):s===ba.AdjustmentType.Gray?n=Ao(n):s===ba.AdjustmentType.Comp?n=Ro(n):s===ba.AdjustmentType.Inv?n=Mo(n,i):s===ba.AdjustmentType.Gamma?n=To(n):s===ba.AdjustmentType.InvGamma?n=No(n):console.warn("unknown adjustmentType: "+s)}return{srgb:n,alpha:r}})(t.srgbAlpha,this._private.adjs),n=((t,e=255)=>{const n=[...t];for(var r=0;r<t.length;r++)n[r]=t[r]*e;return n})(e.srgb);n=Zr(n);let r=to(e.alpha);this._private.adjusted=e,this._private.parsedVal=t,this._private.resolved=new Do.RGBA(n[0],n[1],n[2],r)}static parse(t,e,n,r=null){if(t instanceof Da)return t;const o=t;let s=null,i=o?.trim(),a=null;try{if(!s){const t=i?.split(Fa);t&&(s=t[0],i=i.substring(s.length,i.length).trim())}if(!s)throw new Error("no color found");const t=[],o=i.split(ka);for(let e=0;e<o.length;e++){const n=o[e];if(!n)continue;const r=Ta.get(n.toLowerCase());if(!r)throw new Error("Invalid adjustment type:"+n);let s=null;if(r===ba.AdjustmentType.Gray||r===ba.AdjustmentType.Comp||r===ba.AdjustmentType.Inv||r===ba.AdjustmentType.Gamma||r===ba.AdjustmentType.InvGamma);else{e++;const t=o[e];if(s=parseFloat(t),null==s)throw new Error(`Invalid adjustment value: missing value for'${n}'`);if(isNaN(s))throw new Error("Invalid adjustment value:"+t)}t.push({[r]:s})}a=new Da({val:s,adjs:t},e,n,r)}catch(t){throw t}return a}static getDefaultSchemeLookup(){if(!Oa){const t=new Map,e=Object.keys(La);for(let n=0;n<e.length;n++){const r=e[n];t.set(r.toLowerCase(),Da.parse(La[r],null))}Oa=e=>t.get(e.toLowerCase())?.toRGBA()}return Oa}isEqual(t){return t instanceof Da&&this.toString().toLowerCase()===t.toString().toLowerCase()}getVal(){return this._private.val}getAdjustments(){return this._private.adjs}adjust(t){return new Da({val:this._private.val,adjs:this._private.adjs?this._private.adjs.concat(t):t},this._private.schemeLookup,this._private.indexedLookup,this._private.last)}getType(){return this._resolve(),this._private.parsedVal.type??null}toCSS(t=!1,e=!0){const n=t?this._forceDark():this.toRGBA();return 0===n.alpha?"none":n.toString(e)}toRGBA(t=!1){return this._resolve(),t?this._forceDark():this._private.resolved}toHSLA(t=!1){if(this._resolve(),t)return this._forceDark(!1);let e=lo(this._private.adjusted.srgb);return new Do.HSLA(e[0],e[1],e[2],to(this._private.adjusted.alpha??1))}toHex(t=!1){this._resolve();const e=t?this._forceDark():this._private.resolved;return new Do.HEX(e.red,e.green,e.blue,e.alpha??1)}toBlackOrWhite(t=!1,e=157){const n=this.toRGBA(t),r=.299*n.red+.587*n.green+.114*n.blue>e;return new Da(r?"#000000":"#FFFFFF",this._private.schemeLookup,this._private.indexedLookup,this._private.last)}get[Symbol.toStringTag](){return this.toString()}toString(){let t=this._private.val;const e=this._private.adjs;for(let n=0;e&&n<e.length;n++){const r=e[n];if(!r)continue;const o=Object.keys(r)[0];t+=" "+o;const s=r[o];"number"==typeof s&&(t+=" "+s),n<e.length-1&&(t+=",")}return t}get isIColor(){return!0}}var Ba,za;(za=Ba||(Ba={})).StrokeStyle={None:"none",DashDot:"dashDot",MediumDashDot:"mediumDashDot",Dotted:"dotted",Hair:"hair",Thin:"thin",Medium:"medium",Thick:"thick",MediumDashDotDot:"mediumDashDotDot",DashDotDot:"dashDotDot",Dashed:"dashed",MediumDashed:"mediumDashed",SlantDashDot:"slantDashDot",Double:"double"},za.Edge={Left:"left",Top:"top",Right:"right",Bottom:"bottom",Horizontal:"horizontal",Vertical:"vertical",DiagonalUp:"diagonalUp",DiagonalDown:"diagonalDown"};const Pa=[],ja=new Map,Ha=Object.freeze([[Ba.StrokeStyle.Thin,"Thin",1,null],[Ba.StrokeStyle.Hair,"Hair",1,[1,1]],[Ba.StrokeStyle.Dotted,"Dotted",1,[2,2]],[Ba.StrokeStyle.Dashed,"Dashed",1,[3,1]],[Ba.StrokeStyle.DashDot,"Dash Dot",1,[3,3,9,3]],[Ba.StrokeStyle.DashDotDot,"Dash Dot Dot",1,[3,3,3,3,9,3]],[Ba.StrokeStyle.Double,"Double",3,null],[Ba.StrokeStyle.Medium,"Medium",2,null],[Ba.StrokeStyle.MediumDashed,"Medium Dashed",2,[9,3]],[Ba.StrokeStyle.MediumDashDot,"Medium Dash Dot",2,[3,3,9,3]],[Ba.StrokeStyle.MediumDashDotDot,"Medium Dash Dot Dot",2,[3,3,3,3,9,3]],[Ba.StrokeStyle.SlantDashDot,"Slant Dash Dot",2,[5,1,11,1]],[Ba.StrokeStyle.Thick,"Thick",3,null],[Ba.StrokeStyle.None,"None",0,null]]);for(let t=0;t<Ha.length;t++){const e=Ha[t],n=e[0],r=Object.freeze({style:n,description:e[1],width:e[2],pattern:e[3]});Pa.push(r),ja.set(n,r)}(t=>{t.isEqualStrokes=(t,e)=>!(t&&!e||e&&!t)&&(t===e||t.getStyle()===e.getStyle()&&t.getColor().isEqual(e.getColor())),t.oppositeEdge=e=>e===t.Edge.Left?t.Edge.Right:e===t.Edge.Right?t.Edge.Left:e===t.Edge.Top?t.Edge.Bottom:e===t.Edge.Bottom?t.Edge.Top:e,t.BuiltInDefinitionsArray=Pa,t.BuiltInDefinitions=ja})(Ba||(Ba={}));const Va={Text:"text",Repeat:"repeat",Spacing:"spacing"},$a=t=>!(!t.match(/^([#0?]+)( ?)\/( ?)([#0?]+)/)&&!t.match(/^# ([#0?]+)( ?)\/( ?)([#0?]+)/)),Ua=Object.freeze({formatValue:Xo,isFractionFormat:$a,adjustDecimalPlaces:(t,e)=>{if(!t)return"";const n=(t,e)=>{let n=t||"";const r=0===n.length||n.endsWith(".")?"0":n.charAt(n.length-1);return e<0?(n=n.substring(0,Math.max(0,n.length+e)),"."===n&&(n="")):(n.startsWith(".")||(n+="."),n+=r.repeat(e)),n},r=(t,e)=>{if("General"===t)return e>0?"0"+n("",e):t;if($a(t))return t;let r=t,o=-1,s=-1,i=r.indexOf("E");if(i>=0&&(r=r.substring(0,i)),o=r.indexOf("."),o>=0){r=r.substring(o,r.length);let e=r&&r.match(/([.]{1}[0,#]+)/);if(!e)return t;r=e[1],s=o+r.length}else{if(e<=0)return t;o=r.lastIndexOf("0"),o<0&&(o=r.lastIndexOf("#")),o>=0&&(o+=1),s=o,r=""}return-1===o?t:(r=n(r,e),t.substring(0,o)+r+t.substring(s,t.length))},o=[];let s=Jo(t);for(let t=0;t<s.length;t++)o.push(r(s[t].trim(),e));return o.join(";")}}),Ga=Pr._table,Wa=t=>14===t?"Short Date":Ga[t]??null,qa=[{numberFormat:"General",formatType:$o.General,primary:1},{numberFormat:"0",formatType:$o.Number,regMatch:/^0[.]{0,1}[0]*$/,args:{decimalPlaces:0,separator:!1}},{numberFormat:"#,##0.00",formatType:$o.Number,regMatch:/^#,##0[.]{0,1}[0]*$/,primary:2,args:{decimalPlaces:2,separator:!0}},{numberFormat:"#,##0_);(#,##0)",formatType:$o.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:"#,##0_);[Red](#,##0)",formatType:$o.Number,args:{decimalPlaces:0,separator:!0}},{numberFormat:"#,##0.00_);(#,##0.00)",formatType:$o.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:"#,##0.00_);[Red](#,##0.00)",formatType:$o.Number,args:{decimalPlaces:2,separator:!0}},{numberFormat:"$#,##0.00",formatType:$o.Currency,primary:3,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:"$#,##0_);($#,##0)",formatType:$o.Currency,args:{decimalPlaces:0,currencySymbol:"$"}},{numberFormat:"$#,##0_);[Red]($#,##0)",formatType:$o.Currency,args:{decimalPlaces:0,currencySymbol:"$"}},{numberFormat:"$#,##0.00_);($#,##0.00)",formatType:$o.Currency,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:"$#,##0.00_);[Red]($#,##0.00)",formatType:$o.Currency,args:{decimalPlaces:2,currencySymbol:"$"}},{numberFormat:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',primary:4,formatType:$o.Accounting},{numberFormat:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)',formatType:$o.Accounting},{numberFormat:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',formatType:$o.Accounting},{numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',formatType:$o.Accounting},{numberFormat:"Short Date",formatType:$o.ShortDate,primary:5},{numberFormat:"d-mmm-yy",formatType:$o.MediumDate,primary:5.5},{numberFormat:"Long Date",formatType:$o.LongDate,primary:6},{numberFormat:"h:mm",formatType:$o.ShortTime,primary:7},{numberFormat:"h:mm AM/PM",formatType:$o.MediumTime,primary:7.5},{numberFormat:"Long Time",formatType:$o.LongTime,primary:8},{numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',formatType:$o.Comma,primary:9},{numberFormat:"0.00%",formatType:$o.Percentage,primary:10,args:{decimalPlaces:2},regMatch:/^^[0#?]*[.]{0,1}[0#?]*%*$/},{numberFormat:"0%",formatType:$o.Percentage,args:{decimalPlaces:0}},{numberFormat:"# ?/?",formatType:$o.Fraction,primary:11},{numberFormat:"# ??/??",formatType:$o.Fraction},{numberFormat:"0.00E+00",formatType:$o.Scientific,primary:12,args:{decimalPlaces:2},regMatch:/^[0#?]*[.]{0,1}[0#?]*E\+[0#?]*$/},{numberFormat:"##0.0E+0",formatType:$o.Custom,args:{decimalPlaces:0}},{numberFormat:"@",formatType:$o.Text,primary:13},{numberFormat:"d-mmm",formatType:$o.Custom},{numberFormat:"mmm-yy",formatType:$o.Custom},{numberFormat:"h:mm:ss",formatType:$o.Custom},{numberFormat:"m/d/yyyy h:mm",formatType:$o.Custom},{numberFormat:"mm:ss",formatType:$o.Custom},{numberFormat:"mm:ss.0",formatType:$o.Custom},{numberFormat:"[h]:mm:ss",formatType:$o.Custom}],Ja=[{numberFormat:"00000",formatType:$o.Special,primary:11},{numberFormat:"00000-0000",formatType:$o.Special},{numberFormat:"[<=9999999]###-####;(###) ###-####",formatType:$o.Special},{numberFormat:"000-00-0000",formatType:$o.Special}],Xa=new Map,Ka=[];for(let t=0;t<qa.length;t++){let e=qa[t].numberFormat.toLowerCase();Xa.set(e,qa[t]),qa[t].regMatch&&Ka.unshift(qa[t])}for(let t=0;t<Ja.length;t++){let e=Ja[t].numberFormat.toLowerCase();Xa.set(e,Ja[t])}const Ya=[],Za=new Map;Xa.forEach(function(t,e,n){t.primary&&(Ya.push(t),Za.set(_t.textToKey(t.formatType),t.numberFormat))}),Ya.sort(function(t,e){return t.primary-e.primary});const Qa=Xa.get($o.General.toLowerCase());class tl{lookupStyle(t){if(!t)return Qa;if("number"==typeof t&&(t=Wa(t)),!t.toLowerCase)return console.warn("Invalid numberFormat",t),Qa;t=t.toLowerCase();let e=Xa.get(t);if(e)return e;for(let n=0;!e&&n<Ka.length;n++)if(Ka[n].regMatch){t.match(Ka[n].regMatch)&&(e=Ka[n])}return e||{numberFormat:t,formatType:$o.Custom}}lookupPrimary(){return Ya}lookupDefault(t){return Za.get(_t.textToKey(t))}}var el,nl,rl,ol;(nl=el||(el={})).Type=$o,nl.Parser=Ua,nl.Styles=new tl,nl.ParseRunType=Va,(ol=rl||(rl={})).BuiltInName={Normal:"Normal",RowLevel:"RowLevel_#",ColLevel:"ColLevel_#",Comma:"Comma",Currency:"Currency",Percent:"Percent",Comma0:"Comma [0]",Currency0:"Currency [0]",Hyperlink:"Hyperlink",FollowedHyperlink:"Followed Hyperlink",Note:"Note",WarningText:"Warning Text",Unknown12:"??-12",Unknown13:"??-13",Unknown14:"??-14",Title:"Title",Heading1:"Heading 1",Heading2:"Heading 2",Heading3:"Heading 3",Heading4:"Heading 4",Input:"Input",Output:"Output",Calculation:"Calculation",CheckCell:"Check Cell",LinkedCell:"Linked Cell",Total:"Total",Good:"Good",Bad:"Bad",Neutral:"Neutral",Accent1:"Accent1",Accent1_20:"20% - Accent1",Accent1_40:"40% - Accent1",Accent1_60:"60% - Accent1",Accent2:"Accent2",Accent2_20:"20% - Accent2",Accent2_40:"40% - Accent2",Accent2_60:"60% - Accent2",Accent3:"Accent3",Accent3_20:"20% - Accent3",Accent3_40:"40% - Accent3",Accent3_60:"60% - Accent3",Accent4:"Accent4",Accent4_20:"20% - Accent4",Accent4_40:"40% - Accent4",Accent4_60:"60% - Accent4",Accent5:"Accent5",Accent5_20:"20% - Accent5",Accent5_40:"40% - Accent5",Accent5_60:"60% - Accent5",Accent6:"Accent6",Accent6_20:"20% - Accent6",Accent6_40:"40% - Accent6",Accent6_60:"60% - Accent6",ExplanatoryText:"Explanatory Text"},ol.IconSet={Arrows3:"3Arrows",ArrowsGray3:"3ArrowsGray",Flags3:"3Flags",Signs3:"3Signs",Symbols3:"3Symbols",Symbols3_2:"3Symbols2",TrafficLights3:"3TrafficLights1",TrafficLights3_2:"3TrafficLights2",Arrows4:"4Arrows",ArrowsGray4:"4ArrowsGray",Rating4:"4Rating",RedToBlack4:"4RedToBlack",TrafficLights4:"4TrafficLights",Arrows5:"5Arrows",ArrowsGray5:"5ArrowsGray",Quarters5:"5Quarters",Rating5:"5Rating"};const sl=(t,e,n,r,o)=>{const s=JSON.parse(JSON.stringify(t.definition));s.adjs||(s.adjs=[]);let i="",a=0,l=0;e>0?(l=e,a=100-e,i=`Lighter ${e}%`):e<0&&(a=100+e,i=`Darker ${-e}%`),a&&s.adjs.push({[ba.AdjustmentType.LumMod]:a}),l&&s.adjs.push({[ba.AdjustmentType.LumOff]:l});const c=new Da({val:s.val,adjs:s.adjs},n),h=c.toString();r?.set(h,c);const u=c.toRGBA().toString();return o?.set(u,c),{description:t.description+", "+i,definition:s}},il=(t,e,n,r)=>{let o=[];for(let s=0;s<t.length;s++){let i=[];o.push(i);const a=o=>{for(let a=0;a<o.length;a++)i.push(sl(t[s],o[a],e,n,r))};let l=new Da({val:t[s].definition.val,adjs:t[s].definition.adjs},e).toHSLA().lum;a(0===l?[50,35,25,15,5]:100===l?[-5,-15,-25,-35,-50]:l<=20?[90,75,50,25,10]:l>=80?[-10,-25,-50,-75,-90]:[80,60,40,-25,-50])}return o};var al,ll;(al||(al={})).buildPalette=il,(ll||(ll={})).BuiltInSearchType={BuiltIn:"builtIn",All:"all",Custom:"custom"};const cl=[["Office","windowText","window","0E2841","E8E8E8","156082","E97132","196B24","0F9ED5","A02B93","4EA72E","467886","96607D"],["Office 2013-2022","windowText","window","44546A","E7E6E6","4472C4","ED7D31","A5A5A5","FFC000","5B9BD5","70AD47","0563C1","954F72"],["Office 2007-2010","windowText","window","1F497D","EEECE1","4F81BD","C0504D","9BBB59","8064A2","4BACC6","F79646","0000FF","800080"],["Grayscale","windowText","window","000000","F8F8F8","DDDDDD","B2B2B2","969696","808080","5F5F5F","4D4D4D","5F5F5F","919191"],["Atlas","windowText","window","454545","E0E0E0","F81B02","FC7715","AFBF41","50C49F","3B95C4","B560D4","FC5A1A","B49E74"],["Banded","2C2C2C","FFFFFF","099BDD","F2F2F2","FFC000","A5D028","08CC78","F24099","828288","F56617","005DBA","6C606A"],["Basis","000000","FFFFFF","565349","DDDDDD","A6B727","DF5327","FE9E00","418AB3","D7D447","818183","F59E00","B2B2B2"],["Berlin","windowText","window","9D360E","E7E6E6","F09415","C1B56B","4BAF73","5AA6C0","D17DF9","FA7E5C","FFAE3E","FCC77E"],["Celestial","windowText","window","18276C","EBEBEB","AC3EC1","477BD1","46B298","90BA4C","DD9D31","E25247","C573D2","CCAEE8"],["Circuit","windowText","window","134770","82FFFF","9ACD4C","FAA93A","D35940","B258D3","63A0CC","8AC4A7","B8FA56","7AF8CC"],["Damask","windowText","window","2A5B7F","ABDAFC","9EC544","50BEA3","4A9CCC","9A66CA","C54F71","DE9C3C","6BA9DA","A0BCD3"],["Depth","windowText","window","455F51","94D7E4","41AEBD","97E9D5","A2CF49","608F3D","F4DE3A","FCB11C","FBCA98","D3B86D"],["Dividend","windowText","window","3D3D3D","EBEBEB","4D1434","903163","B2324B","969FA7","66B1CE","40619D","828282","A5A5A5"],["Droplet","windowText","window","355071","AABED7","2FA3EE","4BCAAD","86C157","D99C3F","CE6633","A35DD1","56BCFE","97C5E3"],["Facet","windowText","window","2C3C43","EBEBEB","90C226","54A021","E6B91E","E76618","C42F1A","918655","99CA3C","B9D181"],["Frame","000000","FFFFFF","545454","BFBFBF","40BAD2","FAB900","90BB23","EE7008","1AB39F","D5393D","90BB23","EE7008"],["Gallery","windowText","window","454545","DFDBD5","B71E42","DE478E","BC72F0","795FAF","586EA6","6892A0","FA2B5C","BC658E"],["Integral","windowText","window","335B74","DFE3E5","1CADE4","2683C6","27CED7","42BA97","3E8853","62A39F","6B9F25","B26B02"],["Ion Boardroom","windowText","window","3B3059","EBEBEB","B31166","E33D6F","E45F3C","E9943A","9B6BF2","D53DD0","8F8F8F","A5A5A5"],["Ion","windowText","window","1E5155","EBEBEB","B01513","EA6312","E6B729","6AAC90","54849A","9E5E9B","58C1BA","9DFFCB"],["Madison","windowText","window","1F2D29","C5FAEB","A1D68B","5EC795","4DADCF","CDB756","E29C36","8EC0C1","6D9D9B","6D8583"],["Main Event","windowText","window","424242","C8C8C8","B80E0F","A6987D","7F9A71","64969F","9B75B2","80737A","F21213","B6A394"],["Mesh","windowText","window","363D46","EBEBEB","6F6F6F","BFBFA5","DCD084","E7BF5F","E9A039","CF7133","F28943","F1B76C"],["Metropolitan","windowText","window","162F33","EAF0E0","50B4C8","A8B97F","9B9256","657689","7A855D","84AC9D","2370CD","877589"],["Organic","windowText","window","212121","DADADA","83992A","3C9770","44709D","A23C33","D97828","DEB340","A8BF4D","B4CA80"],["Parallax","windowText","window","212121","CDD0D1","30ACEC","80C34F","E29D3E","D64A3B","D64787","A666E1","3085ED","82B6F4"],["Parcel","000000","FFFFFF","4A5356","E8E3CE","F6A21D","9BAFB5","C96731","9CA383","87795D","A0988C","00B0F0","738F97"],["Quotable","windowText","window","212121","636363","00C6BB","6FEBA0","B6DF5E","EFB251","EF755F","ED515C","8F8F8F","A5A5A5"],["Retrospect","000000","window","637052","CCDDEA","E48312","BD582C","865640","9B8357","C2BC80","94A088","2998E3","8C8C8C"],["Savon","windowText","window","1485A4","E3DED1","1CADE4","2683C6","27CED7","42BA97","3E8853","62A39F","F49100","739D9B"],["Slate","windowText","window","212123","DADADA","BC451B","D3BA68","BB8640","AD9277","A55A43","AD9D7B","E98052","F4B69B"],["Slice","windowText","window","146194","76DBF4","052F61","A50E82","14967C","6A9E1F","E87D37","C62324","0D2E46","356A95"],["Vapor Trail","windowText","window","454545","DADADA","DF2E28","FE801A","E9BF35","81BB42","32C7A9","4A9BDC","F0532B","F38B53"],["View","000000","FFFFFF","46464A","D6D3CC","6F6F74","92A9B9","A7B789","B9A489","8D6374","9B7362","67AABF","ABAFA5"],["Wisp","windowText","window","766F54","E3EACF","A53010","DE7E18","9F8351","728653","92AA4C","6AAC91","FB4A18","FB9318"],["Wood Type","windowText","window","696464","E9E5DC","D34817","9B2D1F","A28E6A","956251","918485","855D5D","CC9900","96A9A9"]],hl=[["Office","Calibri Light","Calibri"],["Office 2013-2022","Calibri Light","Calibri"],["Office 2007-2010","Calibri Light","Calibri"],["Grayscale","Calibri Light","Calibri"],["Atlas","Calibri Light","Rockwell"],["Banded","Corbel","Corbel"],["Basis","Corbel","Corbel"],["Berlin","Trebuchet MS","Trebuchet MS"],["Celestial","Calibri Light","Calibri"],["Circuit","Tw Cen MT","Tw Cen MT"],["Damask","Bookman Old Style","Rockwell"],["Depth","Corbel","Corbel"],["Madison","Arial","Arial"],["Main Event","Impact","Impact"],["Mesh","Century Gothic","Century Gothic"],["Metropolitan","Calibri Light","Calibri Light"],["Organic","Garamond","Garamond"],["Parallax","Corbel","Corbel"],["Parcel","Gill Sans MT","Gill Sans MT"],["Quotable","Century Gothic","Century Gothic"],["Retrospect","Calibri Light","Calibri"],["Savon","Century Gothic","Century Gothic"],["Slate","Calisto MT","Calisto MT"],["Slice","Century Gothic","Century Gothic"],["Vapor Trail","Century Gothic","Century Gothic"],["View","Century Schoolbook","Century Schoolbook"],["Wisp","Century Gothic","Century Gothic"],["Wood Type","Rockwell Condensed","Rockwell"]],ul=[["Office","Office","Office"],["2013-2022","Office 2013-2022","Office 2013-2022"],["Atlas","Atlas","Atlas"],["Banded","Banded","Banded"],["Basis","Basis","Basis"],["Berlin","Berlin","Berlin"],["Celestial","Celestial","Celestial"],["Circuit","Circuit","Circuit"],["Damask","Damask","Damask"],["Depth","Depth","Depth"],["Dividend","Dividend","Dividend"],["Droplet","Droplet","Droplet"],["Facet","Facet","Facet"],["Frame","Frame","Frame"],["Gallery","Gallery","Gallery"],["Grayscale","Grayscale","Grayscale"],["Integral","Integral","Integral"],["Ion Boardroom","Ion Boardroom","Ion Boardroom"],["Ion","Ion","Ion"],["Madison","Madison","Madison"],["Main Event","Main Event","Main Event"],["Mesh","Mesh","Mesh"],["Metropolitan","Metropolitan","Metropolitan"],["Organic","Organic","Organic"],["Parallax","Parallax","Parallax"],["Parcel","Parcel","Parcel"],["Quotable","Quotable","Quotable"],["Retrospect","Retrospect","Retrospect"],["Savon","Savon","Savon"],["Slate","Slate","Slate"],["Slice","Slice","Slice"],["Vapor Trail","Vapor Trail","Vapor Trail"],["View","View","View"],["Wisp","Wisp","Wisp"],["Wood Type","Wood Type","Wood Type"],["Office 2007-2010","Office 2007-2010","Office 2007-2010"]],dl="Themes is readonly. To make modifications create a new DocsThemes instance.",gl={[ba.Scheme.Bg1]:"lt1",[ba.Scheme.Bg2]:"lt2",[ba.Scheme.Tx1]:"dk1",[ba.Scheme.Tx2]:"dk2",[ba.Scheme.Accent1]:"accent1",[ba.Scheme.Accent2]:"accent2",[ba.Scheme.Accent3]:"accent3",[ba.Scheme.Accent4]:"accent4",[ba.Scheme.Accent5]:"accent5",[ba.Scheme.Accent6]:"accent6",[ba.Scheme.Hlink]:"hlink",[ba.Scheme.FolHlink]:"folHlink"},ml="Office",fl=[ml,"Calibri Light","Calibri"],pl=["dk1","lt1","dk2","lt2","accent1","accent2","accent3","accent4","accent5","accent6","hlink","folHlink"],_l=t=>{const e={};for(let n=0;n<t.length;n++){const r=t[n],o=r[0],s={name:o};e[o]=s;for(let t=0;t<pl.length;t++){const e=pl[t],n=r[t+1];if(!n)continue;const o=Da.parse(n);n&&(s[e]=o.toString())}}return e},Sl=t=>{const e={};for(let n=0;n<t.length;n++){const r=t[n],o=r[0],s={name:o};e[o]=s,s.majorFont=r[1]??fl[1],s.minorFont=r[2]??fl[2]}return e},wl=_l([[ml,"windowText","window","44546A","E7E6E6","4472C4","ED7D31","A5A5A5","FFC000","5B9BD5","70AD47","0563C1","954F72"]]),yl=Sl([fl]),El=wl[ml],bl=yl[ml];let vl=null;const Cl=new class{constructor(){this._colors={};for(let t=0;t<pl.length;t++){const e=pl[t],n=Da.parse(El[e]);this._colors[e]=n}}getName(){return El.name}getDk1(){return this._colors.dk1}getLt1(){return this._colors.lt1}getDk2(){return this._colors.dk2}getLt2(){return this._colors.lt2}getAccent1(){return this._colors.accent1}getAccent2(){return this._colors.accent2}getAccent3(){return this._colors.accent3}getAccent4(){return this._colors.accent4}getAccent5(){return this._colors.accent5}getAccent6(){return this._colors.accent6}getHlink(){return this._colors.hlink}getFolHlink(){return this._colors.folHlink}toJSON(){return null}};class xl{constructor(t,e=Cl){this._delegate=e,this._fromJSON(t)}_fromJSON(t){if(this._overrides={},!t)return;const e=Object.keys(t);if(0!==e.length)for(let n=0;n<e.length;n++){const r=e[n];this._overrides[r]="name"===r?t[r]:Da.parse(t[r])}}_value(t,e){return this._overrides&&null!==this._overrides[t]&&void 0!==this._overrides[t]?this._overrides[t]:this._delegate?.[e]?.()}getName(){return this._value("name","getName")}getDk1(){return this._value("dk1","getDk1")}getLt1(){return this._value("lt1","getLt1")}getDk2(){return this._value("dk2","getDk2")}getLt2(){return this._value("lt2","getLt2")}getAccent1(){return this._value("accent1","getAccent1")}getAccent2(){return this._value("accent2","getAccent2")}getAccent3(){return this._value("accent3","getAccent3")}getAccent4(){return this._value("accent4","getAccent4")}getAccent5(){return this._value("accent5","getAccent5")}getAccent6(){return this._value("accent6","getAccent6")}getHlink(){return this._value("hlink","getHlink")}getFolHlink(){return this._value("folHlink","getFolHlink")}toJSON(){const t=_t.toSafeJSON(this._overrides),e=this.getName();return e&&(t.name=e),t}}const Il=new class{constructor(){this._colors={};for(let t=0;t<pl.length;t++){const e=pl[t],n=Da.parse(El[e]);this._colors[e]=n}}getName(){return bl.name}getMajorFont(){return bl.majorFont}getMinorFont(){return bl.minorFont}getMajorFallbacks(){return bl.majorFallbacks}getMinorFallbacks(){return bl.minorFallbacks}};class Al{constructor(t,e=Il){this._delegate=e,this._fromJSON(t)}_fromJSON(t){if(this._overrides={},!t)return;const e=Object.keys(t);if(0!==e.length)for(let n=0;n<e.length;n++){const r=e[n];this._overrides[r]=t[r]}}_value(t,e){return this._overrides&&null!==this._overrides[t]&&void 0!==this._overrides[t]?this._overrides[t]:this._delegate?.[e]?.()}getName(){return this._value("name","getName")}getMajorFont(){return this._value("majorFont","getMajorFont")}getMinorFont(){return this._value("minorFont","getMinorFont")}getMajorFallbacks(){return this._value("majorFallbacks","getMajorFallbacks")}getMinorFallbacks(){return this._value("minorFallbacks","getMinorFallbacks")}toJSON(){const t=_t.toSafeJSON(this._overrides),e=this.getName();return e&&(t.name=e),t}}class Rl{constructor(t,e=null,n=null){if(this._cacheColors=new Map,!e&&t?.name){const n=vl?vl.get(t.name.toLowerCase()):null;n&&(e=n)}if(!e&&vl&&(e=vl.get(ml.toLowerCase())),this._name=t?.name??e?.getName(),!this._name)throw new Error("Theme must have a name.");this._builtInID=n,this._delegate=e,this._colors=new xl(t?.colors,this._delegate?.getColorScheme()),this._fonts=new Al(t?.fonts,this._delegate?.getFontScheme());const r=gl,o={},s=Object.keys(r);for(let t=0;t<s.length;t++){const e=s[t];o[e]=`get${Hs(r[e])}`}o.dk1="getDk1",o.dk2="getDk2",o.lt1="getLt1",o.lt2="getLt2",o.folhlink="getFolHlink",this._colorMap=o;const i=this;this._schemeLookup=t=>{let e=i._cacheColors[t];if(e)return e;const n=i._colorMap[t];if(!n)throw new Error(`Invalid color scheme key: ${t}`);const r=i.getColorScheme();let o=r[n].bind(r)();o||(o=El[gl[t]??t]);return e=new Da(o).toRGBA(),i._cacheColors[t]=e,e}}get builtInID(){return this._builtInID??null}getName(){return this._name??this._delegate?.getName()??null}isCustom(){return null!==this._builtInID&&void 0!==this._builtInID}getColorScheme(){return this._colors}getFontScheme(){return this._fonts}schemeLookup(){return this._schemeLookup}parseColor(t){return Da.parse(t,this._schemeLookup)}toJSON(){const t={name:this.getName()},e=this._colors.toJSON();e&&(Object.keys(e).length>1||e.name&&e.name!==t.name)&&(t.colors=e);const n=this._fonts.toJSON();return n&&(Object.keys(n).length>1||n.name&&n.name!==t.name)&&(t.fonts=n),1===Object.keys(t).length&&t.name===ml?null:t}}const Ml=()=>{if(vl)return vl;const t=((t,e,n)=>{const r=[];for(let o=0;o<t.length;o++){const s=t[o],i=s[0],a=e[s[1]]??El,l=n[s[2]]??bl;r.push({name:i,colors:a,fonts:l})}return r})(ul,_l(cl),Sl(hl)),e=new Map;for(let n=0;n<t.length;n++){const r=new Rl(t[n]),o=new Rl(null,r,n+1);e.set(o.getName().toLowerCase(),o)}return vl=e,e};class Tl{constructor(t=null,e=!1){Ml(),this._isReadOnly=e,this._customMap=new Map,this._defaultTheme=this.getByName("Office")}getDefaultTheme(){return this._defaultTheme}setDefaultTheme(t){if(this._isReadOnly)throw new Error(dl);if(!t)throw new Error("Theme cannot be null.");const e=this.getDefaultTheme();return this.getByName(t.getName())||this.setCustomTheme(t),this._defaultTheme=t,e}getByName(t){t=t.toLowerCase();const e=this._customMap.get(t);return e||(vl.get(t)??null)}search(t){const e=t?.type??ll.BuiltInSearchType.All,n=new Map;e!==ll.BuiltInSearchType.BuiltIn&&e!==ll.BuiltInSearchType.All||vl.forEach((t,e)=>n.set(e,t)),e!==ll.BuiltInSearchType.Custom&&e!==ll.BuiltInSearchType.All||this._customMap.forEach((t,e)=>n.set(e,t)),t?.selected&&n.set(t.selected.getName().toLowerCase(),t.selected);const r=(t=>{const e=[...t];return e.sort((t,e)=>_t.isDefined(t.builtInID)&&!_t.isDefined(e.builtInID)?1:!_t.isDefined(t.builtInID)&&_t.isDefined(e.builtInID)?-1:_t.isDefined(t.builtInID)&&_t.isDefined(e.builtInID)?t.builtInID-e.builtInID:t.getName().localeCompare(e.getName())),e})(Array.from(n.values()));return r}getCount(){return this._customMap.size+vl.size}setCustomTheme(t){if(this._isReadOnly)throw new Error(dl);const e=t.getName().toLowerCase(),n=this._customMap.get(e);return this._customMap.set(e,t),n??null}deleteCustomTheme(t){if(this._isReadOnly)throw new Error(dl);let e=null;e="string"==typeof t?t.toLowerCase():t.getName().toLowerCase();const n=this._customMap.get(e);return this._customMap.delete(e),n??null}}var Nl,Fl;(Nl||(Nl={})).ElementType={WholeTable:"wholeTable",FirstColumnStripe:"firstColumnStripe",SecondColumnStripe:"secondColumnStripe",FirstRowStripe:"firstRowStripe",SecondRowStripe:"secondRowStripe",LastColumn:"lastColumn",FirstColumn:"firstColumn",HeaderRow:"headerRow",TotalRow:"totalRow",FirstHeaderCell:"firstHeaderCell",LastHeaderCell:"lastHeaderCell",FirstTotalCell:"firstTotalCell",LastTotalCell:"lastTotalCell"},(Nl||(Nl={})).Empty=class{constructor(t){this._normalStyle=t}getName(){return"None"}isShownInTableStyles(){return!1}isShownInPivotStyles(){return!1}getRanged(t){return null}getProperties(){return _t.EmptyObject}isBuiltIn(){return!0}delete(){}toJSON(){return null}get isITableStyle(){return!0}},(Fl||(Fl={})).Type={Absolute:"absolute",OneCell:"oneCell",TwoCell:"twoCell"};const kl="Model has been closed. No further operations are allowed.",Ol="Name is required";class Ll{constructor(t,e){this._listeners=new Set,this._pending=null,this._listeners=new Set,this._transactions=e??new ie({transient:!0}),this._src=t;const n=this;this._transactionsRemoveListener=this._transactions?.addListener({onCommitEnd(t){const e=n._pending;if(!e)return;n._pending=null;const r=t.getId(),o=new Set;for(let t=0;t<e.length;t++){const s=e[t];s.commitId===r&&n._doNotify(s.listeners,s.removes,s.options,o)}}})}addListeners(t,e){const n=e?.transactional??this._transactions.isOpenTransaction(),r={listeners:t},o=this,s=()=>{if(!n)return void o._listeners.delete(r);const t=o._transactions.getState(o)?.listeners,e=new Set(t);e.delete(r);const s=o._transactions.beginCommit();try{s.updateState(o,{listeners:e}),s.commit({forceAmend:!0})}catch(t){throw s.rollback(),t}};if(r.remove=e?.once?s:null,n){const t=o._transactions.getState(o)?.listeners,e=new Set(t);e.add(r);const n=this._transactions.beginCommit();try{n.updateState(o,{listeners:e}),n.commit({forceAmend:!0})}catch(t){throw n.rollback(),t}}else o._listeners.add(r);return s}async _doNotify(t,e=null,n,r){const o=n?.source??this._src,s=[],i=n?.params;for(let e=0;e<t.length;e++){const n=t[e];r&&r.has(n)||(r?.add(n),s.push(n(o,i)))}let a=null;if(e&&(a=()=>{for(let t=0;t<e.length;t++)e[t]()}),n?.async)return new Promise(async(t,e)=>{try{const e=await Promise.all(s);a?.(),t(e)}catch(t){a?.(),e(t)}});a?.()}notify(t,e){let n=null,r=null;const o=e=>{e.forEach(e=>{const o=e.listeners[t];o&&(n||(n=[]),n.push(o),e.remove&&(r||(r=[]),r.push(e.remove)))})},s=e?.transactional??this._transactions.isOpenTransaction();if(s){const t=this._transactions.getState(this)?.listeners;t&&o(t)}const i=n,a=r;n=null,r=null,o(this._listeners);const l=n,c=r;if(n=null,r=null,s){if(i&&this._doNotify(i,a,e),l){let t=this._pending;return t||(this._pending=t=[]),t.push({commitId:this._transactions.getCurrentCommit().getId(),listeners:l,removes:c,options:e}),this._doNotify(l,a,e)}}else if(l)return this._doNotify(l,c,e)}close(){this._transactions.remove(this),this._transactionsRemoveListener()}}class Dl{constructor(t){this._emitter=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options?.transactions??new ie({transient:!0}),this._emitter=new Ll(this,this._transactions),this._updateState({isDeleted:!1}),t?.json&&this._fromJSON(t.json),this._options?.setContainerReadOnlyCallback?.(()=>{e._processOnContainerReadOnly()}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,n,r){e._processStateChange(t,n,r)},onRestoreOrRevert(t,n,r){e._processRestoreOrRevert(t,n,r)}}),this._processInit()}_fromJSON(t){}isReadOnly(){return this._options.isReadOnly?.()??!1}isDeleted(){return this._getState().isDeleted??!1}getType(){return this._options.type}get isIModel(){return!0}_processTransactionDone(t){}_getDescription(){return null}_getState(){if(this._closed)throw new Error(kl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_getTransactions(){return this._transactions}_updateState(t,e,n){if(this._closed)throw new Error(kl);if(!t)return;const r=this._beginCommit(e?.description);try{r.updateState(this,t);let e=!1;if(n)for(let t=0;t<n.length;t++){const r=n[t];e=e||"onAnyChange"===r,this._emitter.notify(r)}!e&&n&&n.length>0&&this._emitter.notify("onAnyChange"),r.commit()}catch(t){throw r.rollback(),t}return this}_getEmitter(){return this._emitter}_processInit(){}_processStateChange(t,e,n){}_processRestoreOrRevert(t,e,n){this._emitter.notify("onInvalidated")}delete(t){if(this._getState().isDeleted)throw new Error("Model has been deleted.");this._options.deleteFromContainer&&this._options.deleteFromContainer?.(t),this._delete()}_delete(){const t=this._getDescription(),e="Delete",n=t?`${e} ${t}`:e,r=this._beginCommit(n);try{this._processDelete(),r.commit()}catch(t){throw r.rollback(),t}}_processOnContainerDeleted(){this._processDelete()}_processDelete(){this._updateState({isDeleted:!0},null,["onDelete"])}_processOnContainerReadOnly(){this._emitter.notify("onReadOnlyChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}beginCommit(t){return this._beginCommit(t)}doBatch(t,e){const n=this;return this._transactions.doBatch(t,"string"==typeof e?{description:e}:e,t=>{n._processTransactionDone(t)})}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}}class Bl extends Dl{_fromJSON(t){const e={};if(e.name=t?.name??null,!e.name)throw new Error(Ol);e.comment=t?.comment??null,e.hidden=t?.hidden??!1,e.scope=t?.scope??null,this._updateState(e,{description:this._options.createDescription??"Create Item"+(e.name?` '${e.name}'`:"")})}_toJSON(){const t=this._getState(),e={name:t.name};return t.comment&&(e.comment=t.comment),t.hidden&&(e.hidden=t.hidden),t.hidden&&(e.hidden=t.hidden),e}getName(){return this._getState().name}setName(t,e){if(!t)throw new Error(Ol);return this._updateState({name:t},{description:`Update Named '${t}'`,...e})}getComment(){return this._getState().comment}setComment(t,e){return this._updateState({comment:t},{description:"Set Comment",...e})}isHidden(){return this._getState().hidden}getScope(){return this._getState().scope}get isINamed(){return!0}}var zl,Pl,jl;(zl||(zl={})).SortOn={Value:"value",FillColor:"fillColor",FontColor:"fontColor",Icon:"icon"},(jl=Pl||(Pl={})).CaseInsensitiveOptions={sensitivity:"base",numeric:!1},jl.CaseSensitiveOptions={sensitivity:"case",numeric:!1},jl.BooleanCollator=Object.freeze({type:t.Boolean,compare:(t,e,n)=>!0===t?1:-1}),jl.StringCollator=Object.freeze({type:t.String,compare:(t,e,n)=>t.localeCompare(e,"en",n),defaultOptions:jl.CaseInsensitiveOptions}),jl.NumberCollator=Object.freeze({type:t.Number,compare:(t,e,n)=>t<e?-1:1}),jl.RichDataCollator=Object.freeze({type:t.RichData,compare:(t,e,n)=>{const r=t.type.localeCompare(e.type,"en");return r}}),jl.DefaultRangeOptions=Object.freeze({hasHeader:!1,reverse:!1,includeHidden:!1,collatorOptions:jl.CaseInsensitiveOptions,orientation:e.Orientation.Row,offset:0}),jl.DefaultCollators=Object.freeze([jl.BooleanCollator,jl.StringCollator,jl.NumberCollator,jl.RichDataCollator]);const Hl=(t,e,n,r)=>{let o;for(;!(o=t.next()).done;)try{e(o.value[1],o.value[0],n)}catch(e){if("function"!=typeof t.throw)throw e;t.throw(e)}"function"==typeof t.return&&t.return()},Vl=t=>{const e=t.next.bind(t),n={next:t=>{const n=e(t);return n.done?Ul:{done:n.done,value:n.value[1]}},[Symbol.iterator]:()=>n,...t.return&&{return:t.return.bind(t)},...t.throw&&{throw:t.throw.bind(t)}};return n},$l=t=>{if(!t||0===t.length)return null;let e=Number.MAX_SAFE_INTEGER,n=-1,r=null;return(o,s=!1)=>{if(o===e)return o;false!==s&&(e=Number.MAX_SAFE_INTEGER),o!==e+(s?-1:1)&&(n=((t,e,n=!0)=>{if(!t||0===t.length)return null;let r,o=-1;return n?(o=_t.findEqualOrGreater(t,e,t=>t.max),r=t[o]):(o=_t.findEqualOrLesser(t,e,t=>t.min),r=t[o]),r?(n?e>r.max&&(o+=1,r=t[o]):e<r.min&&(o-=1,r=t[o]),r?o:-1):-1})(t,o,!s),r=t[n]);let i=o;if(s)for(;r&&i<=r.max;)i=r.min-1,r=t[--n];else for(;r&&i>=r.min;)i=r.max+1,r=t[++n];return e=i,i}},Ul=Object.freeze({done:!0,value:void 0}),Gl=Object.freeze({next:()=>Ul,[Symbol.iterator]:()=>Gl});var Wl;Object.seal({done:!1,value:void 0}),(t=>{t.isList=t=>!!t&&!!t.isIList,t.isListLike=t=>!!t&&("number"==typeof t.length&&"function"==typeof t.at),t.fromArray=(t,n,r,o)=>new e(t,n,r,o);class e{constructor(t,e,n,r){this.g=e,this.s=n;let o=t??r;if(n&&t&&!r){r=new Array(t.length);for(let e=0;e<t.length;e++){let o=t[e];r[e]=n(o,e)}o=r}this.a=o??_t.EmptyArray,e&&(this.at=t=>{t<0&&(t=o.length+t);const n=o[t];if(void 0!==n)return e(n,t)})}at(t){const e=this.a;return t<0&&(t=e.length+t),e[t]}fromArray(t){return new e(t,this.g,this.s)}get length(){return this.a.length}get isIList(){return!0}}t.ArrayList=e})(Wl||(Wl={}));class ql{constructor(t){if(this._s=null,this._r=null,this._l=0,t&&t.length>0){const e=Wl.isList(t)&&!Array.isArray(t)?t:new Wl.ArrayList(t);this._s=e,this._l=t.length}}at(t){const e=this._s;if(e)return e.at(t);const n=this._c;if(n){if(n.min<=t&&n.max>=t){const e=n.value;return e.v.at(t-n.min+e.s)}}const r=this._r,o=_t.findEqualOrGreater(r,t,t=>t.max),s=r[o];if(!s)return;const i=s.value;this._c=s;return i.v.at(t-s.min+i.s)}toArray(t=Number.MAX_SAFE_INTEGER){const e=[],n=this.entries(Yl);let r=n.next();for(;!r.done&&e.length<t;)e.push(r.value[1]),r=n.next();return e}entries(t){const e=this.length;if(0===e)return Gl;let n,r,o,s=!0,i=0,a=e-1;if(t){s=!t.reverse;const e=t.bounds;e&&(i=Math.max(e.min??i,i),a=Math.min(e.max??a,a)),n=t.reuseResult??null,r=t.processSkip}const l=s?1:-1;let c=(s?i:a)-l;const h=this._s;if(h)o=t=>{if(!(t<i||t>a))return h.at(t)};else{const t=this._r;let e=s?0:t.length-1,n=t[e];const r=(r,o)=>{const s=r===e?n:t[r];if(s&&o>=s.min&&o<=s.max)return e=r,n=s,s};o=n=>{if(n<i||n>a)return;let o=r(e,n);if(o||(o=r(e+l,n)),!o){const e=_t.findEqualOrGreater(t,n,t=>t.max);o=r(e,n)}if(!o)return;const s=o.value;return s.v.at(n-o.min+s.s)}}const u={next:t=>{let h,u=c+l;return void 0!==t&&(t<0&&(t=e+t),u=t),u<i||u>a||r&&(u=r(u,!s),u<i||u>a)?Ul:(h=o(u),c=u,n?(Kl.done=!1,Kl.value[0]=u,Kl.value[1]=h,Kl):{done:!1,value:[c,h]})},[Symbol.iterator]:()=>u};return u}slice(t,e=void 0){const n=this._r??Jl(this._s);if(!n)return Xl;const r=this.length;if(t=Math.min(Math.max(0,t),r),(e=Math.min(Math.max(0,e??r),r))-t<=0)return Xl;if(t<=0&&e>=r)return this;const o=t,s=e-1;let i=[],a=0;for(let t=0;t<n.length;t++){let e=n[t];const r=e.max;if(0===o&&r<=s){i.push(e);continue}const l=e.min;if(l>s){t=n.length;continue}if(r<o){a=r+1;continue}const c=Math.max(0,o-l),h=Math.max(0,r-s),u=h+c,d=e.value;i.push({min:l-a,max:r-u-a,value:{s:d.s+c,e:d.e-h,v:d.v}}),a+=u}const l=new ql;return l._r=i,l._l=s-o+1,l}concat(t){if(!t)return this;if(!Wl.isListLike(t))throw new Error("Value must be IListLike");const e=this._l;if(0===e)return t.isIReadableList?t:0===t.length?Xl:new ql(t);const n=t,r=t.length;if(0===r)return this;const o=this._r??Jl(this._s),s=o.slice(0,o.length-1);let i=o[o.length-1],a=i?i.min:0,l=i?i.max:0,c=i?i.value:null,h=c?c.v:null,u=c?c.e-c.s:0;const d=t=>{const e=t.s,n=t.e,r=n-e;if(r+u<Zl&&h&&h.fromArray){let r=t.v;const o=[],s=c.s,d=c.e;for(let t=s;t<=d;t++)o.push(h.at(t));for(let t=e;t<=n;t++)o.push(r.at(t));const g=h.fromArray(o);if(g)return r=g,u=r.length-1,c={s:0,e:u,v:r},i={min:a,max:a+u,value:c},l=a+u,void(h=r)}s.push(i);const o=l+1,d=o+r;i={min:o,max:d,value:t},a=o,l=d,c=i?i.value:null,h=c?c.v:null,u=c?c.e-c.s:0};if(t instanceof ql){const e=t._s;if(e)d({s:0,e:e.length-1,v:e});else{const e=t._r;for(let t=0;t<e.length;t++){d(e[t].value)}}}else d({s:0,e:r-1,v:n});s.push(i);const g=new ql,m=e+r;return 1===s.length&&0===s[0].min&&s[0].max===m-1?g._s=s[0].value.v:g._r=s,g._l=m,g}get length(){return this._l}[Symbol.iterator](){return Vl(this.entries())}get isIReadableList(){return!0}get isIList(){return!0}get[Symbol.toStringTag](){return"[ImmutableList]"}toString(){const t=this.length;if(0===t)return"";let e="";for(let n=0;n<t;n++){n>0&&(e+=",");const t=this.at(n);e+=null==t?"":String(t)}return e}}const Jl=t=>[{min:0,max:t.length-1,value:{s:0,e:t.length-1,v:t}}],Xl=new ql,Kl=Object.seal({done:!1,value:[-1,null]}),Yl=Object.freeze({reverse:!1,bounds:{min:0,max:Number.MAX_SAFE_INTEGER},skipRuns:null,reuseResult:Kl}),Zl=4;var Ql;(t=>{const e=(t,e)=>{const n=t!==I.Row;return e?(t,e)=>{if(t===e)return 0;const r=t[0],o=t[1],s=e[1];if(o===s)return r?-1:1;const i=e[0];let a=0,l=0;if(n?(a=r?o.colEnd:o.colStart,l=i?s.colEnd:s.colStart):(a=r?o.rowEnd:o.rowStart,l=i?s.rowEnd:s.rowStart),a===l&&r!==i)return r?-1:1;if(a!==l)return l-a;let c=0,h=0;if(n?(c=r?o.colStart:o.colEnd,h=i?s.colStart:s.colEnd):(c=r?o.rowStart:o.rowEnd,h=i?s.rowStart:s.rowEnd),c===h&&r!==i)return r?-1:1;if(c!==h)return h-c;const u=t[2]??0;return(e[2]??0)-u}:(t,e)=>{if(t===e)return 0;const r=t[0],o=t[1],s=e[1];if(o===s)return r?-1:1;const i=e[0];let a=0,l=0;if(n?(a=r?o.colStart:o.colEnd,l=i?s.colStart:s.colEnd):(a=r?o.rowStart:o.rowEnd,l=i?s.rowStart:s.rowEnd),a===l&&r!==i)return r?-1:1;if(a!==l)return a-l;let c=0,h=0;if(n?(c=r?o.colEnd:o.colStart,h=i?s.colEnd:s.colStart):(c=r?o.rowEnd:o.rowStart,h=i?s.rowEnd:s.rowStart),c===h&&r!==i)return r?-1:1;if(c!==h)return c-h;return(t[2]??0)-(e[2]??0)}};class n{constructor(t,n){if(this._isColumn=!0,this._isByCell=!1,this._isReverse=!1,this._cursor=null,this._reuse=null,this._localReuse={done:!1,value:[null,null]},this._eventsMajor=null,this._eventMajorIndex=0,this._majorStart=0,this._majorEnd=0,this._eventMinorPeek=null,this._minorStart=0,this._minorEnd=0,!t||0===t.length)return;let r=I.Column,o=!1,s=!0,i=!1;n&&(r=n.orientation??I.Column,this._isColumn=s=r!==I.Row,this._isReverse=o=n.reverse??!1,this._isByCell=i=n.byCell??!1);const a=t.length,l=new Array(2*a);for(let e=0;e<a;e++){const n=t[e],r=[null,null];l[2*e]=[!0,n,e,r],l[2*e+1]=[!1,n,e,r]}l.sort(e(r,o)),this._eventsMajor=l;const c=l[0][1];this._majorStart=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,this._majorEnd=s?o?c.colEnd+1:c.colStart-1:o?c.rowEnd+1:c.rowStart-1,this._eventsMinor=new ze(null,e(s?I.Row:I.Column,o));const h=new Array(16);h.length=0,this._cursor={cell:null,range:{colStart:c.colStart,rowStart:c.rowStart,colEnd:c.colEnd,rowEnd:c.rowEnd},overlaps:h},i&&(this._cursor.cell={colIndex:o?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,rowIndex:o?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER});const u=n?.reuseIterator;u&&(this._reuse=u,u.value=this._cursor)}next(t){const e=this._isColumn,n=this._isReverse;if(t){if(!this._isByCell)throw new Error("nextCell is only supported when byCell is true");const r=W.createCellComparator(e?I.Column:I.Row,n);let o;do{const s=this._cursor,i=s.cell;if(i.colIndex!==Number.MAX_SAFE_INTEGER&&r(i,t)>=0)throw new Error("nextCell must be after the current iteration cell");if(o=this.next(),o.done)return o;const a=o.value.cell;if(r(a,t)>=0)return o;const l=s.range;if(e){const e=t.colIndex===i.colIndex;i.rowIndex=n?e?Math.max(t.rowIndex,l.rowStart):l.rowStart:e?Math.min(t.rowIndex,l.rowEnd):l.rowEnd}else{const e=t.rowIndex===i.rowIndex;i.colIndex=n?e?Math.max(t.colIndex,l.colStart):l.colStart:e?Math.min(t.colIndex,l.colEnd):l.colEnd}if(r(i,t)>=0)return a.rowIndex=i.rowIndex,a.colIndex=i.colIndex,o}while(!o.done);return o}let r=this._cursor;if(!r)return Ul;let o=this._reuse;if(!o){const t=r.cell,e=r.range,n={cell:null,range:{colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd},overlaps:[...r.overlaps]};t&&(n.cell={colIndex:t.colIndex,rowIndex:t.rowIndex}),this._cursor=n,o={done:!1,value:n}}const s=o.value,i=s.range,a=s.cell,l=this._isByCell,c=n?-1:1;let h=!1;if(l){const t=a.rowIndex,r=a.colIndex,s=e?t:r,l=e?n?i.rowStart:i.rowEnd:n?i.colStart:i.colEnd;if(n?s>=l:s<=l){e?a.rowIndex=t+c:a.colIndex=r+c;if(n?s>l:s<l)return o}const u=e?a.colIndex:a.rowIndex,d=e?n?i.colStart:i.colEnd:n?i.rowStart:i.rowEnd;(n?u>d:u<d)&&(h=!0)}const u=s.overlaps;let d=this._majorStart,g=this._majorEnd,m=this._eventsMinor,f=this._minorStart,p=this._minorEnd,_=this._eventsMinorIterator,S=this._eventMinorPeek,w=S;for(;w&&!w.done;){const t=w.value[0];if(t[0])w=null;else{if(S=_.next(),S.done)u.length=0;else{const r=t[1];let s=u.length;if(s>1){const t=u.indexOf(r);-1!==t&&(u[t]=u[s-1])}if(u.length=s-1,s=u.length,s>0){const t=S.value[0],r=t[1],s=e?n?r.colStart:r.colEnd:n?r.rowStart:r.rowEnd;if(n?d>=s:d<=s){let s=!1;if(t[0]){const t=e?n?r.rowEnd:r.rowStart:n?r.colEnd:r.colStart;(n?t<p+c:t>p+c)&&(f=p+c,p=t-c,s=!0)}else{const t=e?n?r.rowStart:r.rowEnd:n?r.colStart:r.colEnd;(n?t<p:t>p)&&(f=p+c,p=t,s=!0)}if(s)return e?(i.rowStart=n?p:f,i.rowEnd=n?f:p):(i.colStart=n?p:f,i.colEnd=n?f:p),this._minorStart=f,this._minorEnd=p,this._eventMinorPeek=S,o}}}S.done&&(S=null),w=S}}if(!S)if(h){_=m.entries(void 0,this._localReuse),S=_.next(),this._eventsMinorIterator=_;const t=S.value[0][1],r=e?n?t.rowEnd:t.rowStart:n?t.colEnd:t.colStart;e?(a.colIndex=a.colIndex+c,a.rowIndex=r):(a.colIndex=r,a.rowIndex=a.rowIndex+c)}else{let t=this._eventMajorIndex;const r=this._eventsMajor,o=r.length;if(t>=o)return this._cursor=null,Ul;let s=r[t],i=s[0],h=!1;for(;!i&&!h&&s;){const o=s[1],a=e?n?o.colStart:o.colEnd:n?o.rowStart:o.rowEnd;if(n?a<g:a>g){h=!0;continue}const l=s[3];m.delete(l[0]),m.delete(l[1]),t++,s=r[t],s&&(i=s[0])}let f=m.size>0?g+c:-1;for(h=!1;i&&!h&&s;){const o=s[1];if(-1!==f){if((e?n?o.colEnd:o.colStart:n?o.rowEnd:o.rowStart)!==f){h=!0;continue}}const a=s[2],l=[!0,o,a],c=[!1,o,a],u=s[3];if(u[0]=l,u[1]=c,m.set(l,0),m.set(c,0),-1===f){f=e?n?o.colEnd:o.colStart:n?o.rowEnd:o.rowStart}if(t++,s=r[t],!s)continue;if(i=s[0],!i)continue;const d=s[1];(e?n?d.colEnd:d.colStart:n?d.rowEnd:d.rowStart)!==f&&(h=!0)}if(-1!==f&&(d=f),l&&(e?a.colIndex=d:a.rowIndex=d),this._eventMajorIndex=t,t>=o)return this._eventsMinorIterator=_,this._cursor=null,Ul;if(s){const t=s[0],r=s[1],o=e?n?r.colEnd:r.colStart:n?r.rowEnd:r.rowStart,i=e?n?r.colStart:r.colEnd:n?r.rowStart:r.rowEnd;g=t?o-c:i}u.length=0,_=m.entries(void 0,this._localReuse),S=_.next(),this._eventsMinorIterator=_}let y=S;do{const t=y.value;y=null;const r=t[0],o=r[1];if(!r[0])continue;const s=e?n?o.rowEnd:o.rowStart:n?o.colEnd:o.colStart;f!==s&&(f=s),S=_.next();const i=S.value[0],h=i[0],d=i[1],g=e?n?d.rowEnd:d.rowStart:n?d.colEnd:d.colStart;if(h&&g===f)y=S;else{const t=e?n?o.rowStart:o.rowEnd:n?o.colStart:o.colEnd,r=e?n?d.rowStart:d.rowEnd:n?d.colStart:d.colEnd;p=(n?Math.max:Math.min)(t,h?g-c:r),l&&(e?a.rowIndex=f:a.colIndex=f)}u[u.length]=Object.freeze(o)}while(y);return e?(i.colStart=n?g:d,i.colEnd=n?d:g,i.rowStart=n?p:f,i.rowEnd=n?f:p):(i.rowStart=n?g:d,i.rowEnd=n?d:g,i.colStart=n?p:f,i.colEnd=n?f:p),this._eventMinorPeek=S,this._minorStart=f,this._minorEnd=p,this._majorStart=d,this._majorEnd=g,o}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}t.IteratorInstance=n})(Ql||(Ql={}));const tc=(t,e=w.Right,n=null)=>{if(!t)return t;if(0===t.length)return[];const r=e===w.Right,o=e===w.Left,s=e===w.Up,i=e===w.Down;return t.sort((t,e)=>{if(!t&&!e)return 0;if(t&&!e)return-1;if(e&&!t)return 1;const a=n?.(t,e)??0;return 0!==a?a:r?t.rowStart===e.rowStart?t.colStart-e.colStart:t.rowStart-e.rowStart:i?t.colStart===e.colStart?t.rowStart-e.rowStart:t.colStart-e.colStart:o?t.rowStart===e.rowStart?e.colStart-t.colStart:e.rowStart-t.rowStart:s?t.colStart===e.colStart?e.rowStart-t.rowStart:e.colStart-t.colStart:0})},ec=(t,e)=>{const n=e.min,r=t.min;if(e.max===Number.MAX_SAFE_INTEGER){const o=n,s=t.max;return r<=o&&o<=s?0:s<o?-1:r>o?1:(console.warn("coords are not inserted correctly",t,e),0)}return r-n};class nc{constructor(t){this._runs=null,this._dataCoords=null,this._count=0,this._length=0,this._maxCoords=null,this._options=t,t?.maxCoords&&(this._maxCoords=Object.freeze({...t.maxCoords})),this._runs=new ze(void 0,ec,t?.nodeSize),this._reuseRunsIterator={done:!1,value:[null,null]},this._reuseRunsEntry=[null,null]}_validateBounds(t=Number.MIN_SAFE_INTEGER,e=Number.MAX_SAFE_INTEGER){const n=this._maxCoords,r=n?.min??Number.MIN_SAFE_INTEGER,o=n?.max??Number.MAX_SAFE_INTEGER;if(t<r||e>o)throw new kt}entries(t){let e,n,r=Number.MIN_SAFE_INTEGER,o=Number.MAX_SAFE_INTEGER,s=!0;if(t){const i=t?.bounds;i&&(r=t.bounds?.min??Number.MIN_SAFE_INTEGER,o=t.bounds?.max??Number.MAX_SAFE_INTEGER,this._validateBounds(r,o)),s=!t.reverse,e=rc(t.reuseResult),n=t.processSkip}const i=this._dataCoords;if(!i)return Gl;r=Math.max(i.min,r),o=Math.min(i.max,o);let a=null,l=null,c=Number.MAX_SAFE_INTEGER,h=Number.MIN_SAFE_INTEGER;if(n){const t=n;n=(e,n)=>t(e+c,n)-c}const u=t=>{let e;t!==Number.MIN_SAFE_INTEGER&&t!==Number.MAX_SAFE_INTEGER&&(gc.min=t,e=gc),a=s?this._runs.entries(e,this._reuseRunsIterator):this._runs.entriesReversed(e,this._reuseRunsIterator),c=Number.MAX_SAFE_INTEGER,h=Number.MIN_SAFE_INTEGER,l=null},d=t=>{if(void 0!==t){if(t<c||t>h)return void(l=void 0);t-=c}if(!l)return;let n=l.next(t);if(!l)return;let r=n.value,o=r?.[1];if(n.done)return void(l=void 0);return oc(r[0]+c,o,e)},g=t=>{let i;return i=d(t),i||(i=(t=>{let i;do{if(void 0!==t&&u(t),!a)return;if(i=a.next(),i.done)return void(a=void 0);const g=i.value,m=g[0],f=g[1],p=m.min,_=m.max,S=Math.max(p,r)-p,w=Math.max(S,Math.min(_,o))-p;uc.bounds.min=S,uc.bounds.max=w,uc.reverse=!s,uc.processSkip=n,uc.reuseResult=e,c=p,h=_,l=f.entries(uc);const y=d(t);if(y)return y;t=void 0}while(!i.done);a=void 0})(t),i||Ul)},m={next(t){if(void 0!==t&&(t<0||t>o))throw new kt;return g(t)},return:t=>null,throw:t=>null};return u(s?r:o),m}runs(t){let e,n=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER,o=!0,s=!1;if(t){t.bounds&&(n=t.bounds?.min??Number.MIN_SAFE_INTEGER,r=t.bounds?.max??Number.MAX_SAFE_INTEGER,this._validateBounds(n,r),t.overflowRun&&(s=!0)),o=!t.reverse,e=sc(t.reuseResult)}const i=this._dataCoords;if(!i)return Gl;n=Math.max(i.min,n),r=Math.min(i.max,r);let a=null;const l=t=>{let e;t!==Number.MIN_SAFE_INTEGER&&t!==Number.MAX_SAFE_INTEGER&&(gc.min=t,e=gc),a=o?this._runs.entries(e,this._reuseRunsIterator):this._runs.entriesReversed(e,this._reuseRunsIterator)},c={next(t){if(void 0!==t){if(t<n||t>r)throw new kt;l(t)}if(!a)return Ul;const i=a.next();if(i.done)return a=void 0,Ul;const c=i.value,h=c[0];let u=h;const d=u.min,g=u.max;if(o&&d>r||!o&&g<n)return Ul;let m=c[1];return s||(g>r&&(m=m.slice(0,m.length-(g-r)),u={...u},u.max=r),d<n&&(m=m.slice(n-d),u===h&&(u={...u}),u.min=n)),ic(u,m,e)},return:t=>null,throw:t=>null};return l(o?n:r),c}slice(t,e){const n=this._runs,r=n.minKey().min,o=n.maxKey().max;if(void 0===e&&(e=o+1),0===this._count||t<=r&&e-1>=o)return this.clone();const s=Math.max(r,t),i=Math.min(o,e-1),a=i-s,l=[];let c=0;pc.bounds.min=s,pc.bounds.max=i;const h=this.runs(pc);let u=h.next();for(;!u.done;){const t=u.value;let e=t[0],n=t[1];e={min:e.min-s,max:e.max-s},e.min<0&&(n=n.slice(-e.min),e.min=0),e.max>=a&&(n=n.slice(0,n.length-(e.max-a)),e.max=a),c+=n.length,l.push([e,n]),u=h.next()}const d=new nc(this._options);return d._runs.setPairs(l),d._updateCount(c),d}concat(t){const e=this.clone();if(!t||0===t.length)return e;const n=this._runs.nextLowerPair(void 0,this._reuseRunsEntry),r=n[0],o=n[1],s=r.max+1;let i=!1,a=0;const l=[];if(t.isISparseList){const e=t.runs();let n=e.next();for(;!n.done;){const t=n.value;let c=t[0];const h={min:c.min+s,max:c.max+s};let u=t[1];if(0===c.min){i=!0,a-=o.length,u=o.concat(u);const t=r.min;h.min=t,h.max=u.length-1+t}a+=u.length,l.push([h,u]),n=e.next()}}else{const e=t.length,n={min:r.min,max:e-1+s};t=o.concat(t),i=!0,a+=e,l.push([n,t])}return i&&e._runs.delete(r),e._runs.setPairs(l),e._updateCount(a),e}toArray(t=Number.MAX_SAFE_INTEGER,e=!0){if(0===this.length)return _t.EmptyArray;const n=e?0:Number.MIN_SAFE_INTEGER,r=Math.min(this._runs.maxKey().max,t);return dc.bounds.min=Number.MIN_SAFE_INTEGER,dc.bounds.max=r,ac(this.entries(dc),e,r,n)}get isIReadableList(){return!0}get length(){return this._length}getCoords(){return this._dataCoords}clear(){this._runs.clear(),this._dataCoords=null,this._count=0,this._length=0}get isISparseList(){return!0}get isIList(){return!0}_updateCount(t){if(this._count+=t,this._lastRunsRead=void 0,this._lastListRead=void 0,this._count>0){const t=this._runs,e=Object.freeze({min:t.minKey().min,max:t.maxKey().max});this._dataCoords=e,this._length=e.max+1}else this._dataCoords=null,this._length=0}_update(t,e,n=null,r=void 0){const o=t,s=o+e-1;let i=0,a=s,l=s,c=null,h=null;gc.min=o,mc.min=s,(n||r)&&(gc.min-=1,mc.min+=1);const u=this._runs;let d=!1;if(u.editRange(gc,mc,!0,(t,e,n)=>{const r=t.min,u=t.max;return r<o&&u+1>=o&&(a=r,c=e),r-1<=s&&u>s&&(l=r,h=e),i-=u-r+1,d=!0,ze.DeleteValue}),n||void 0===r||(n=new ql([r])),n){let t=n;d=!0;let e=o;c&&(c=c.slice(0,o-a),t=c.concat(t),e=a),h&&(h=h.slice(s+1-l),t=t.concat(h)),i+=t.length,u.set({min:e,max:e+t.length-1},t)}else c&&(c=c.slice(0,o-a),i+=c.length,u.set({min:a,max:a+c.length-1},c)),h&&(h=h.slice(s+1-l),i+=h.length,u.set({min:s+1,max:s+h.length},h));return this._updateCount(i),d}setAt(t,e){if(void 0===t)throw new Lt;return this._validateBounds(t,t),this._update(t,1,null,e)}setRunAt(t,e){if(!e||0===e.length)return!1;if(void 0===t||!e.length)throw new Lt;const n=e.length;return this._validateBounds(t,t+n-1),this._update(t,n,e)}delete(t,e){return void 0===e&&(e=Math.max(this.getCoords().max-t+1,0)),!(e<=0)&&(this._validateBounds(t,t),this._update(t,e,null))}shift(t,e){if(0===e)return!1;let n=t,r=t;e<0&&(r=t-e-1),this._validateBounds(n,r);const o=this._runs,s=o.maxKey();if(e<0&&r>=s.max&&n<=o.minKey().min)return this._runs.clear(),this._dataCoords=null,this._count=0,this._length=0,!0;let i=0,a=n,l=r,c=null,h=null;gc.min=a,mc.min=s.min,e<0&&(gc.min-=1,mc.min+=1);let u=!1;const d=[];if(o.editRange(gc,mc,!0,(t,o,s)=>{const g=t.min,m=t.max;return g<n&&m+1>=n&&(a=g,c=o),(g<n||e<0)&&g-1<=r&&t.max>r&&(l=g,h=o),e>0&&g>=n||e<0&&g-1>r?d.push([{min:g+e,max:m+e},o]):i-=m-g+1,u=!0,ze.DeleteValue}),e>0){const r=c||h;r&&(c=r.slice(0,n-a),l=t+e,h=r.slice(n-a))}else c&&(c=c.slice(0,n-a)),h&&(h=h.slice(r+1-l),l=t),c&&h&&a+c.length===l&&(c=c.concat(h),h=null);return c&&c.length>0&&(i+=c.length,o.set({min:a,max:a+c.length-1},c)),h&&(i+=h.length,o.set({min:l,max:l+h.length-1},h)),d.length>0&&o.setPairs(d),this._updateCount(i),u}at(t){gc.min=t;const e=this._lastRunsRead;if(e){const n=e.min;if(n<=t&&e.max>=t)return this._lastListRead.at(t-n)}let n,r;const o=this._runs.getPairOrNextHigher(gc,fc);if(o&&(n=o[0],r=o[1]),this._lastRunsRead=n,this._lastListRead=r,!(!n||t<n.min||t>n.max))return r.at(t-n.min)}[Symbol.iterator](){return Vl(this.entries())}clone(){const t=new nc(this._options);return t._runs=this._runs.clone(),t._count=this._count,t._dataCoords=this._dataCoords,t._length=this._length,t}getMaxCoords(){const t=this._maxCoords;return t||null}getCount(){return this._count}getRunsCount(){return this._runs.size}get[Symbol.toStringTag](){return"[SparseList]"}}nc||(nc={});const rc=t=>"boolean"!=typeof t?(t&&!t.value&&(t.value=[-1,null]),t):!0===t?hc:void 0,oc=(t,e,n)=>{const r=n??{done:!1,value:[-1,null]},o=r.value;return o[0]=t,o[1]=e,r},sc=t=>"boolean"!=typeof t?(t&&!t.value&&(t.value=[null,null]),t):!0===t?lc:void 0,ic=(t,e,n)=>{const r=n??{done:!1,value:[null,null]},o=r.value;return o[0]=t,o[1]=e,r},ac=(t,e=!1,n=Number.MIN_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER)=>{const o=[];let s=t.next(),i=Math.max(r,0)-1;for(;!s.done;){if(e){const t=s.value[0];for(let e=i;e<t-1;e++)o.push(void 0);i=t}o.push(s.value[1]),s=t.next()}if(e)for(let t=i;t<n;t++)o.push(void 0);return o},lc=Object.seal({done:!1,value:[{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},null]}),hc=Object.seal({done:!1,value:[-1,null]}),uc={reverse:!1,bounds:{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},processSkip:null,reuseResult:hc},dc=Object.freeze({reverse:!1,bounds:{min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER},processSkip:null,reuseResult:hc}),gc={min:0,max:Number.MAX_SAFE_INTEGER},mc={min:0,max:Number.MAX_SAFE_INTEGER},fc=[null,null],pc={bounds:{min:0,max:0},overflowRun:!0};class _c{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),this.clear()}all(t){return 0===this.data.children.length?[]:this._all(this.data,t??[])}isEmpty(){return 0===this.data.children.length}search(t,e){let n=this.data;if(0===n.children.length)return _t.EmptyArray;if(!Mc(t,n))return _t.EmptyArray;const r=e??[],o=this.toBBox,s=[];for(;n;){const e=n.children,i=e.length,a=n.leaf;for(let n=0;n<i;n++){const i=e[n],l=a?o(i):i;Mc(t,l)&&(a?r.push(i):Rc(t,l)?this._all(i,r):s.push(i))}n=s.pop()}return r}collides(t){let e=this.data;if(!Mc(t,e))return!1;const n=[];for(;e;){for(let r=0;r<e.children.length;r++){const o=e.children[r],s=e.leaf?this.toBBox(o):o;if(Mc(t,s)){if(e.leaf||Rc(t,s))return!0;n.push(o)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;const e=this._minEntries;if(t.length<e){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const t=this.data;this.data=n,n=t}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Tc([]),this}remove(t,e){if(!t)return this;let n=this.data;const r=this.toBBox(t),o=[],s=[];let i,a,l;for(;n||o.length;){if(n||(n=o.pop(),a=o[o.length-1],i=s.pop(),l=!0),n.leaf){const r=Sc(t,n.children,e);if(-1!==r)return n.children.splice(r,1),o.push(n),this._condense(o),this}l||n.leaf||!Rc(n,r)?a?(i++,n=a.children[i],l=!1):n=null:(o.push(n),s.push(i),i=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}_build(t,e,n,r){const o=n-e+1;let s,i=this._maxEntries;if(o<=i)return s=Tc(t.slice(e,n+1)),wc(s,this.toBBox),s;r||(r=Math.ceil(Math.log(o)/Math.log(i)),i=Math.ceil(o/Math.pow(i,r-1))),s=Tc([]),s.leaf=!1,s.height=r;const a=Math.ceil(o/i),l=a*Math.ceil(Math.sqrt(i));Nc(t,e,n,l,this.compareMinX);for(let o=e;o<=n;o+=l){const e=Math.min(o+l-1,n);Nc(t,o,e,a,this.compareMinY);for(let n=o;n<=e;n+=a){const o=Math.min(n+a-1,e);s.children.push(this._build(t,n,o,r-1))}}return wc(s,this.toBBox),s}_chooseSubtree(t,e,n,r){for(;r.push(e),!e.leaf&&r.length-1!==n;){let n,r=1/0,o=1/0;for(let s=0;s<e.children.length;s++){const i=e.children[s],a=Cc(i),l=Ic(t,i)-a;l<o?(o=l,r=a<r?a:r,n=i):l===o&&a<r&&(r=a,n=i)}e=n||e.children[0]}return e}_insert(t,e,n=!1){const r=n?t:this.toBBox(t),o=[],s=this._chooseSubtree(r,this.data,e,o);for(s.children.push(t),Ec(s,r);e>=0&&o[e].children.length>this._maxEntries;)this._split(o,e),e--;this._adjustParentBBoxes(r,o,e)}_split(t,e){const n=t[e],r=n.children.length,o=this._minEntries;this._chooseSplitAxis(n,o,r);const s=this._chooseSplitIndex(n,o,r),i=Tc(n.children.splice(s,n.children.length-s));i.height=n.height,i.leaf=n.leaf,wc(n,this.toBBox),wc(i,this.toBBox),e?t[e-1].children.push(i):this._splitRoot(n,i)}_splitRoot(t,e){this.data=Tc([t,e]),this.data.height=t.height+1,this.data.leaf=!1,wc(this.data,this.toBBox)}_chooseSplitIndex(t,e,n){let r=-1,o=1/0,s=1/0;for(let i=e;i<=n-e;i++){const e=yc(t,0,i,this.toBBox),a=yc(t,i,n,this.toBBox),l=Ac(e,a),c=Cc(e)+Cc(a);l<o?(o=l,r=i,s=c<s?c:s):l===o&&c<s&&(s=c,r=i)}return r||n-e}_chooseSplitAxis(t,e,n){const r=t.leaf?this.compareMinX:bc,o=t.leaf?this.compareMinY:vc;this._allDistMargin(t,e,n,r)<this._allDistMargin(t,e,n,o)&&t.children.sort(r)}_allDistMargin(t,e,n,r){t.children.sort(r);const o=this.toBBox,s=yc(t,0,e,o),i=yc(t,n-e,n,o);let a=xc(s)+xc(i);for(let r=e;r<n-e;r++){const e=t.children[r];Ec(s,t.leaf?o(e):e),a+=xc(s)}for(let r=n-e-1;r>=e;r--){const e=t.children[r];Ec(i,t.leaf?o(e):e),a+=xc(i)}return a}_adjustParentBBoxes(t,e,n){for(let r=n;r>=0;r--)Ec(e[r],t)}_condense(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():wc(t[n],this.toBBox)}}function Sc(t,e,n){if(!n)return e.indexOf(t);for(let r=0;r<e.length;r++)if(n(t,e[r]))return r;return-1}function wc(t,e){yc(t,0,t.children.length,e,t)}function yc(t,e,n,r,o=null){o||(o=Tc(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=e;s<n;s++){const e=t.children[s];Ec(o,t.leaf?r(e):e)}return o}function Ec(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function bc(t,e){return t.minX-e.minX}function vc(t,e){return t.minY-e.minY}function Cc(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function xc(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Ic(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function Ac(t,e){const n=Math.max(t.minX,e.minX),r=Math.max(t.minY,e.minY),o=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,o-n)*Math.max(0,s-r)}function Rc(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Mc(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Tc(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Nc(t,e,n,r,o){const s=[e,n];for(;s.length;){if((n=s.pop())-(e=s.pop())<=r)continue;const i=e+Math.ceil((n-e)/r/2)*r;Fc(t,i,e,n,o),s.push(e,i,i,n)}}function Fc(t,e,n,r,o){for(;r>n;){if(r-n>600){const s=r-n+1,i=e-n+1,a=Math.log(s),l=.5*Math.exp(2*a/3),c=.5*Math.sqrt(a*l*(s-l)/s)*(i-s/2<0?-1:1);Fc(t,e,Math.max(n,Math.floor(e-i*l/s+c)),Math.min(r,Math.floor(e+(s-i)*l/s+c)),o)}const s=t[e];let i=n,a=r;for(kc(t,n,e),o(t[r],s)>0&&kc(t,n,r);i<a;){for(kc(t,i,a),i++,a--;o(t[i],s)<0;)i++;for(;o(t[a],s)>0;)a--}0===o(t[n],s)?kc(t,n,a):(a++,kc(t,a,r)),a<=e&&(n=a+1),e<=a&&(r=a-1)}}function kc(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}class Oc extends _c{toBBox(t){return{minX:10*t.colStart,minY:10*t.rowStart,maxX:10*t.colEnd+5,maxY:10*t.rowEnd+5}}compareMinX(t,e){return t.colStart-e.colStart}compareMinY(t,e){return t.rowStart-e.rowStart}isEmpty(){return 0===this.data.children.length}searchRange(t,e=!1,n){if(this.isEmpty())return _t.EmptyArray;const r=this.search(this.toBBox(t),n);if(!e)return r;return r.filter(e=>e.colStart>=t.colStart&&e.rowStart>=t.rowStart&&e.colEnd<=t.colEnd&&e.rowEnd<=t.rowEnd)}}class Lc{constructor(t){this._shared=null,this._rTree=null,this._cloneKey=null,this._lastMiss={colStart:Number.MAX_SAFE_INTEGER,rowStart:0,colEnd:0,rowEnd:0},this._lastSingle=null,this._lastSingleResult=null,this._options=t,this._rTree=new Oc(t?.maxNodeEntries??16)}visitRanges(t,e,n=null){let r=this.search(t);n&&(r=tc(r,n));const o=[],s=[];let i=null;const a=r.length;for(let t=0;!i&&t<a;t++){const n=r[t],a=e?.(n);a&&(!0===a.delete?s.push(n):void 0!==a.update&&(s.push(n),o.push(a.update)),a&&!0===a.break&&(i=a))}for(let t=0;t<s.length;t++)this.remove(s[t]);return this.load(o),i}getBoundingCoords(){const t=this._getReadTree().toJSON();return t&&t.children&&0!==t.children.length?{colStart:t.minX/10,rowStart:t.minY/10,colEnd:(t.maxX-5)/10,rowEnd:(t.maxY-5)/10}:null}size(){return this._getReadTree().all().length}isEmpty(){return this._getReadTree().isEmpty()}search(t,e=!1,n){const r=this._getReadTree();if(r.isEmpty())return _t.EmptyArray;let o;if(!e){if(o=this._lastMiss,o.colStart!==Number.MAX_SAFE_INTEGER&&W.isRangeWithinRange(t,o))return _t.EmptyArray;if(this._lastSingle&&W.isRangeWithinRange(t,o))return this._lastSingleResult}const s=r.searchRange(t,e,n);return e||(0===s.length?(o.colStart=t.colStart,o.rowStart=t.rowStart,o.colEnd=t.colEnd,o.rowEnd=t.rowEnd):1===s.length?(this._lastSingle=s[0],this._lastSingleResult=s):(this._lastMiss.colStart=Number.MAX_SAFE_INTEGER,this._lastSingle=null,this._lastSingleResult=null)),s}has(t){const e=this._getReadTree();return e.collides(e.toBBox(t))}all(t){return this._getReadTree().all(t)}shift(t){const e=t.range,n=t.direction,r=t.cloneIfUpdate??!1,o=t.coordValidator??null,s=t.onShift??null,i=n===w.Left||n===w.Right,a=i?I.Column:I.Row,l=n===w.Up||n===w.Left?-1:1,c=(i?e.colEnd-e.colStart+1:e.rowEnd-e.rowStart+1)*l,h=[],u=[];let d=null;const g=this.getBoundingCoords();if(!g)return this;const m=n===w.Up||n===w.Left?w.Right:w.Left,f=new Map,p=new Map,_=this._options?.updateEntryOptions,S=_?.isMergeOnShift??!1,y=_?.isSplitOnExpand??!1,E=_?.isTrailingEdge??!1,b=n===w.Left||n===w.Up,v=_?.getSplit??$c,C=_?.getShifted,x=_?.onShifted,R=_?.onRemoved,M=_?.onMerged,T=_?.onUpdated,N=x?[]:null,F=R?[]:null,k=T?[]:null;this.visitRanges({colStart:e.colStart-(i?1:0),rowStart:e.rowStart-(i?0:1),colEnd:i?g.colEnd:e.colEnd,rowEnd:i?e.rowEnd:g.rowEnd},t=>{if((i?t.colEnd<e.colStart:t.rowEnd<e.rowStart)&&!E)return;const r=Gc(e,t,i?A.Column:A.Row),l=t.group;if(b&&!l&&e.colStart<=t.colStart&&e.rowStart<=t.rowStart&&e.colEnd>=t.colEnd&&e.rowEnd>=t.rowEnd){const n=Wc(t,null,{after:null,before:t,intersect:e,isSplit:r,orientation:a,amount:c},C,v,s,!1);if(void 0===n)return;if(null===n)return d=W.unionRanges(d,t),F&&F.push(t),void h.push(t)}let g={...t};n===w.Right?e.colStart<=g.colStart?(g.colStart+=c,g.colEnd+=c):g.colEnd+=c:n===w.Left?e.colStart<g.colStart?(g.colStart=Math.max(g.colStart+c,e.colStart),g.colEnd=Math.max(g.colEnd+c,g.colStart-1)):g.colEnd+=Math.max(c,e.colStart-g.colEnd-1):n===w.Down?e.rowStart<=g.rowStart?(g.rowStart+=c,g.rowEnd+=c):g.rowEnd+=c:n===w.Up&&(e.rowStart<g.rowStart?(g.rowStart=Math.max(g.rowStart+c,e.rowStart),g.rowEnd=Math.max(g.rowEnd+c,e.rowStart-1)):g.rowEnd+=Math.max(c,e.rowStart-g.rowEnd-1)),(g.colEnd<g.colStart||g.rowEnd<g.rowStart)&&(g=null);const m=Wc(t,g,{after:g,before:t,intersect:e,isSplit:r,orientation:a,amount:c},C,v,s,y&&c>0);if(void 0===m)return;const _=null===m?[g]:m,S=_.length;if(_[0]!==t||1!==S){if(o)for(let t=0;t<S;t++){const e=_[t];e&&o(e)}let e;l?(f.set(l.uuid,l),e=[],p.set(t.uuid,e)):h.push(t);for(let n=0;n<S;n++){const r=_[n];d=W.unionRanges(d,r),l?e.push(r):(u.push(r),N&&N.push(r),k&&k.push(t))}}},m);let O=null;O=r&&(h.length>0||u.length>0||p.size>0)?this.clone():this,O._updateNodes(u,h),p.size>0&&O._updateGroupedEntries(f,p);let L=_t.EmptyArray;if(S&&g&&d){let t=!0;if(c>0&&(t=i?e.rowStart>g.rowStart||e.rowEnd<g.rowEnd:e.colStart>g.colStart||e.colEnd<g.colEnd),t){const t=Dc(d,W.unionRanges(g,d),i?0:1,i?1:0);M&&(L=O._mergeNodes(t,!1))}}return T&&k.length>0&&T(k),x&&N.length>0&&x(N),M&&L.length>0&&M(L),R&&F.length>0&&R(F),O}insertNonOverlapping(t,e){const n=e?.onIntersect??((t,e)=>({...t,value:e.value})),r=this.search(t),o=new Map,s=new Map,i=this._options?.updateEntryOptions,a=i?.onUpdated,l=i?.onRemoved,c=i?.onMerged,h=i?.getSplit,u=i?.getIntersect,d=i?.getUpdate;let g=null,m=null,f=null,p=function(t,e,n){const r=n?.getIntersect??zc,o=n?.getUpdate??jc;if(0===t.length){if(r){const t=r({...e,value:null},e);e=t&&null!==t.value?{...t}:null}if(o){const t=o(e);void 0!==t&&(e=t)}return e?[e]:_t.EmptyArray}const s=n?.getSplit??Bc,i=(t,e,n=!0)=>{const r=e.search(t),o=r.length;for(let a=0;a<o;a++){const o=r[a];if(W.isEqualRanges(o,t))continue;e?.remove(o);const l=Pc(o,t,s,n);for(let t=0;t<l.length;t++){const n=l[t];e.insert(n),i(n,e,!1)}}},a=new Lc;a.load(t),i(e,a);const l=new Lc;l.load([e]);const c=a.search(e);for(let t=0;t<c.length;t++)i(c[t],l);const h=(t,e,n)=>{let o=e.search(t);console.assert(o.length<=1,"intersecting incorrect ranges");const i=o[0]??{...t,value:null};if(W.isEqualRanges(i,t)){let o=r(i,t);e.remove(i),n.insert(o)}else{e.remove(i);const o=Pc(i,t,s),a=o.length;for(let s=0;s<a;s++){const i=o[s];if(W.isEqualRanges(i,t)){const e=r(i,t);n.insert(e)}else e.insert(i)}}},u=new Lc,d=l.all(),g=d.length;for(let t=0;t<g;t++)h(d[t],a,u);const m=(t,e)=>{const n=t.all(),r=n.length;for(let t=0;t<r;t++){let r=n[t];if(o){const t=o(r);void 0!==t&&(r=t)}null!==r&&null!==r.value&&e.push(r)}},f=a.all();return m(u,f),f}(r,t,{getSplit:(t,e,n,r)=>{let o;return h?(o=h(t,e,n,r),o):(o=$c(t,e,n,r),o)},getIntersect:(t,e)=>{u&&(e=u(t,e));const r=n(t,e);if(void 0===r)return r;if(null===r||null===r.value){const e=t.value;e?.onRemove?.(t)}return r},getUpdate:t=>{const e=t?.group;if(e){o.set(e.uuid,e);let n=s.get(t.lastId??t.uuid);n||(n=[],s.set(t.lastId??t.uuid,n)),n.push(null===t.value?null:t)}let n=t;if(d&&(n=d(t)),n&&null!==n.value)a&&(g||(g=[]),g.push(n));else if(l&&!f){f=[];let e=n&&null===n.value?n:{...t,value:null};f.push(e)}return n}});const _=this.getBoundingCoords();if(o.size>0){const t=[],e=p.length;for(let n=0;n<e;n++){let e=p[n];e.group||t.push(e)}p=t}if(this._updateNodes(p,r,e?.onUpdates),o.size>0&&this._updateGroupedEntries(o,s),_&&!e?.noMerge){const n=Dc(t,W.unionRanges(_,t)),r=this.search(n);if(r.length>1){const t=i?.getMerged??Uc;let n=r;n=Hc(n,I.Column,1,t),n=Hc(n,I.Row,1,t),r.length!==n.length&&(c&&n.length>0&&(m=n),this._updateNodes(n,r,e?.onUpdates))}}return g&&a(g),m&&c(m),f&&l(f),this}insertGroup(t,e){e=e??_t.uuidV4();const n=[],r=t.length;for(let o=0;o<r;o++){const r={...t[o],group:{entries:n,uuid:e,offset:o},uuid:_t.uuidV4()};n.push(r),t[o]=r}return this.load(t),this._options?.updateEntryOptions?.onGroupUpdate?.(t,e),this}createCopiedEntries(t,e,n,r,o){return qc(this,t,e,n,r,o,this._options?.updateEntryOptions?.getSplit??$c)}_updateGroupedEntries(t,e){const n=[],r=[],o=new Map,s=t.values();let i=s.next();for(;!i.done;){const t=i.value,a=t.entries,l=t.uuid,c=[];for(let t=0;t<a.length;t++){let o=a[t];n.push(o);let s=e.get(o.uuid);void 0===s&&(s=[{...o}]);for(let t=0;t<s.length;t++){let e=s[t];null!==e&&(e={...e,group:{offset:c.length,entries:c,uuid:l}},c.push(e),r.push(e))}}c.sort((t,e)=>t.group.offset-e.group.offset),o.set(l,c),i=s.next()}if(this._updateNodes(r,n),o){const t=this._options?.updateEntryOptions?.onGroupUpdate;if(t){const e=o.entries();let n=e.next();for(;!n.done;){const r=n.value[0];t(n.value[1],r),n=e.next()}}}}_copy(t,e){let n=t.rTree.all();const r=new Oc(this._options?.maxNodeEntries);return e&&(n=n.concat(e)),n.length>0&&r.load(n),{refCount:1,rTree:r}}_updateNodes(t,e,n){if(!(t&&0!==t.length||e&&0!==e.length))return;const r=this._getWritableTree();if(e){const t=e.length;for(let n=0;n<t;n++)r.remove(e[n])}t.length>0&&r.load(t),n?.(t,e,this),this._options?.updateEntryOptions?.onUpdates?.(t,e,this)}_mergeNodes(t,e){const n=this.search(t,e);let r=_t.EmptyArray;if(n.length>1){const t=this._options?.updateEntryOptions.getMerged??Uc;let e=n;e.length>1&&(e=Hc(e,I.Column,1,t)),e.length>1&&(e=Hc(e,I.Row,1,t)),n.length!==e.length&&(r=e,this._updateNodes(e,n))}return r}_getReadTree(){return this._shared?.rTree??this._rTree}_ensureWritable(t){const e=this._shared;if(!e)return;if(e.refCount--,0===e.refCount)return this._shared=null,void(t&&this._rTree.load(t));const n=this._copy(e,t);this._shared=null,this._rTree=n.rTree}_getWritableTree(t){return this._lastMiss.colStart=Number.MAX_SAFE_INTEGER,this._lastSingle=null,this._lastSingleResult=null,this._shared?(this._ensureWritable(t),this._rTree):(t&&this._rTree.load(t),this._rTree)}remove(t,e){return t&&this._getWritableTree().remove(t,e??W.isEqualRanges),this}insert(t){return t&&this._getWritableTree().insert(t),this}load(t){return t&&t.length>0&&this._getWritableTree(t),this}clear(){return this.isEmpty()||this._getWritableTree().clear(),this}clone(t=null){if(null!==t&&this._cloneKey===t)return this;let e=this._shared;e||(e={rTree:this._rTree,refCount:1},this._shared=e),e.refCount++;const n=new Lc(this._options);return n._shared=e,n._cloneKey=t,n}fromJSON(t){return this._getWritableTree().fromJSON(t),this}}const Dc=(t,e=t,n=1,r=1)=>({...t,colStart:Math.max(t.colStart-n,e.colStart),rowStart:Math.max(t.rowStart-r,e.rowStart),colEnd:Math.min(t.colEnd+n,e.colEnd),rowEnd:Math.min(t.rowEnd+r,e.rowEnd)});function Bc(t,e,n,r){return[{...e[0],value:t.value},{...e[0],value:t.value}]}function zc(t,e){return{...t}}function Pc(t,e,n=null,r=!0){if(W.isEqualRanges(t,e))return[{...t}];const o=W.intersectRanges(t,e,Xc);if(!o)return null;const s=[],i=t.uuid;let a=t;if(a.rowStart<o.rowStart){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:o.rowStart-1};i&&(r&&(t.lastId=i),t.uuid=_t.uuidV4());const e={...a,colStart:a.colStart,rowStart:o.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(r&&(e.lastId=i),e.uuid=_t.uuidV4());const l=e.rowStart-t.rowStart;Jc[0]=t,Jc[1]=e;const c=n(a,Jc,I.Row,l);void 0!==c&&(s.push(c[0]),a=c[1])}if(a.rowEnd>o.rowEnd){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:o.rowEnd};i&&(r&&(t.lastId=i),t.uuid=_t.uuidV4());const e={...a,colStart:a.colStart,rowStart:o.rowEnd+1,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(r&&(e.lastId=i),e.uuid=_t.uuidV4());const l=e.rowStart-t.rowStart;Jc[0]=t,Jc[1]=e;const c=n(a,Jc,I.Row,l);void 0!==c&&(s.push(c[1]),a=c[0])}if(a.colStart<o.colStart){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:o.colStart-1,rowEnd:a.rowEnd};i&&(r&&(t.lastId=i),t.uuid=_t.uuidV4());const e={...a,colStart:o.colStart,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(r&&(e.lastId=i),e.uuid=_t.uuidV4());const l=e.colStart-t.colStart;Jc[0]=t,Jc[1]=e;const c=n(a,Jc,I.Column,l);void 0!==c&&(s.push(c[0]),a=c[1])}if(a.colEnd>o.colEnd){const t={...a,colStart:a.colStart,rowStart:a.rowStart,colEnd:o.colEnd,rowEnd:a.rowEnd};i&&(r&&(t.lastId=i),t.uuid=_t.uuidV4());const e={...a,colStart:o.colEnd+1,rowStart:a.rowStart,colEnd:a.colEnd,rowEnd:a.rowEnd};i&&(r&&(e.lastId=i),e.uuid=_t.uuidV4());const l=e.colStart-t.colStart;Jc[0]=t,Jc[1]=e;const c=n(a,Jc,I.Column,l);void 0!==c&&(s.push(c[1]),a=c[0])}return a===t&&(a={...t}),s.push(a),s}function jc(t){return null===t.value?null:t}function Hc(t,e=I.Column,n=2,r,o){let s=[...t];if(n<=0||t.length<=1)return s;let i=e===I.Column,a=0,l=!1;do{const t=s.sort(W.createRangeComparator(i?I.Row:I.Column));s=[],l=!1,s.push(t[0]);for(let n=1;n<t.length;n++){const a=t[n],c=s[s.length-1];let h=!1;if(h=i?c&&c.rowStart===a.rowStart&&c.rowEnd===a.rowEnd&&c.colEnd+1===a.colStart:c&&c.colStart===a.colStart&&c.colEnd===a.colEnd&&c.rowEnd+1===a.rowStart,h){let t={...c,colEnd:i?a.colEnd:c.colEnd,rowEnd:i?c.rowEnd:a.rowEnd};if(r){const n=o??[null,null];n[0]=c,n[1]=a,t=r(n,t,e)}if(t){s[s.length-1]=t,l=!0;continue}}s.push(a)}a++,i=!i}while(a<n&&l&&s.length>1);return s}const Vc=(t,e=2,n=I.Row,r,o,s)=>{if(t.length<=1)return[...t];let i=[];const a=n===I.Column,l=new Ql.IteratorInstance(t,{orientation:a?I.Row:I.Column});let c=l.next();for(;!c.done;){const t=c.value;c=l.next();const n=t.range;if(e>0){const t=i[i.length-1];let e=!1;if(e=a?t&&t.rowStart===n.rowStart&&t.rowEnd===n.rowEnd&&t.colEnd+1===n.colStart:t&&t.colStart===n.colStart&&t.colEnd===n.colEnd&&t.rowEnd+1===n.rowStart,e){let e={...t,colEnd:a?n.colEnd:t.colEnd,rowEnd:a?t.rowEnd:n.rowEnd};if(e){i[i.length-1]=e;continue}}}i.push(n)}return e>1&&(i=Hc(i,a?I.Row:I.Column,e,r,s)),i};function $c(t,e,n,r){const o=t.value;if(o?.getSplit){const t=o.getSplit(e,n,r);if(void 0===t)return;e[0].value=t[0],e[1].value=t[1]}return e}function Uc(t,e,n){const r=t[0].value,o=t[1].value;if(r?.getMerged&&o){const o=r.getMerged(t[1].value,W.sanitizeRange(e),n);if(void 0===o)return;e.value=o}return e}const Gc=(t,e,n=A.Both)=>{const r=n=>n?t.rowStart>e.rowStart&&t.rowStart<=e.rowEnd||t.rowEnd<e.rowEnd&&t.rowEnd>=e.rowStart:t.colStart>e.colStart&&t.colStart<=e.colEnd||t.colEnd<e.colEnd&&t.colEnd>=e.colStart;let o=n===A.Column,s=n===A.Row;return n===A.Both&&(o=s=!0),!(!o||!r(!0))||!(!s||!r(!1))};function Wc(t,e,n,r,o,s,i){const a=n.orientation===I.Column,l=n.intersect,c=(e,c)=>{let h=e.value,u=null,d=c.after;if(i){let n=null,r=0,s=0;if(a&&l.colStart>e.colStart?(n={...e,colEnd:l.colStart-1},s=c.amount):!a&&l.rowStart>e.rowStart&&(n={...e,rowEnd:l.rowStart-1},r=c.amount),n){const e=Pc(t,n,o);if(e.length>1)for(let t=0;t<e.length;t++){let o=e[t];W.isEqualRanges(o,n)?(u=u??[],u.push(o)):(d=o,h=o.value,c={...c,after:{...o,colStart:o.colStart+s,rowStart:o.rowStart+r,colEnd:o.colEnd+s,rowEnd:o.rowEnd+r,uuid:_t.uuidV4()},before:o,intersect:n,isSplit:!0})}}}if(r){d=r(c.before,c.after,c)}else if(h&&h.getShifted){d=h.getShifted(c)}else c.after&&(d={...c.after,value:e.value});if(void 0!==d)return s&&(d!==c.after&&(c={...c,after:d}),s(c)),d=(e=>{if(!e){const e=t.value;return e.onRemove&&e.onRemove(W.sanitizeRange(n.before)),null}return e})(d),d&&(u=u??[],u.push(d)),u};if(n.isSplit){let r;r=a?{...t,rowStart:Math.max(l.rowStart,n.before.rowStart),rowEnd:Math.min(l.rowEnd,n.before.rowEnd)}:{...t,colStart:Math.max(l.colStart,n.before.colStart),colEnd:Math.min(l.colEnd,n.before.colEnd)};const s=Pc(t,r,o),i=[];for(let t=0;t<s.length;t++){const o=s[t];if(W.isEqualRanges(o,r)){let t=null;e&&(t=a?{colStart:e.colStart,rowStart:r.rowStart,colEnd:e.colEnd,rowEnd:r.rowEnd,value:o.value}:{colStart:r.colStart,rowStart:e.rowStart,colEnd:r.colEnd,rowEnd:e.rowEnd,value:o.value});const s=c(o,{...n,before:o,after:t});if(s)for(let t=0;t<s.length;t++)i.push(s[t])}else i.push(o)}return i}return c(t,n)}const qc=(t,e,n,r,o,s,i)=>{const a=n.colEnd-n.colStart+1,l=n.rowEnd-n.rowStart+1,c=n.colStart-e.colStart,h=n.rowStart-e.rowStart,u=r?.transpose??!1;let d=1,g=1;u?(d=e.rowEnd-e.rowStart+1,g=e.colEnd-e.colStart+1):(d=e.colEnd-e.colStart+1,g=e.rowEnd-e.rowStart+1);const m=Math.ceil(a/d),f=Math.ceil(l/g),p=o??[],_=s??_t.EmptyArray,S=n.colEnd,y=n.rowEnd;return t.visitRanges(e,t=>{let o=t.value;if(!o.copyTo)return;let s=t;if(!W.isRangeWithinRange(s,e)){const t=Pc(s,e,i);s=t[t.length-1]}o=s.value;let _=s.colEnd-s.colStart+1,w=s.rowEnd-s.rowStart+1,E=c+s.colStart,b=h+s.rowStart;if(u){E=s.rowStart-e.rowStart+n.colStart,b=s.colStart-e.colStart+n.rowStart;const t=_;_=w,w=t}let v=m,C=f;const x=a<=v*_,A=l<=C*w;if(x||A){const t=o?.canTile?.({colStart:E,rowStart:b,colEnd:Math.min(E+(x?a:_)-1,S),rowEnd:Math.min(b+(A?l:w)-1,y)},r);!x||!0!==t&&t!==I.Column||(_=a,v=1),!A||!0!==t&&t!==I.Row||(w=l,C=1)}for(let t=0;t<v;t++){const e=E+t*d;for(let t=0;t<C;t++){const n=b+t*g,s=Math.min(e+_-1,S),i=Math.min(n+w-1,y),a={colStart:e,rowStart:n,colEnd:s,rowEnd:i};if(e>s||n>i)continue;const l=o.copyTo(a,r);l&&p.push({...a,value:l})}}},w.Right),{inserts:p,removes:_}},Jc=[null,null],Xc={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Kc=(t=Number.MIN_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER,o,s,i)=>{if(s&&(t!==Number.MIN_SAFE_INTEGER&&t<s.colStart||e!==Number.MIN_SAFE_INTEGER&&e<s.rowStart||n!==Number.MAX_SAFE_INTEGER&&n>s.colEnd||r!==Number.MAX_SAFE_INTEGER&&r>s.rowEnd))throw new kt;return i&&(t=Math.max(i.colStart,t),e=Math.max(i.rowStart,e),n=Math.min(i.colEnd,n),r=Math.min(i.rowEnd,r),n<t||r<e)?null:(Zc.majorStart=o?t:e,Zc.majorEnd=o?n:r,Zc.minorStart=o?e:t,Zc.minorEnd=o?r:n,Zc)},Yc=(t,e,n)=>{const r={colStart:0,rowStart:0,colEnd:0,rowEnd:0};return r.colStart=e?t.majorStart:t.minorStart,r.rowStart=e?t.minorStart:t.majorStart,r.colEnd=e?t.majorEnd:t.minorEnd,r.rowEnd=e?t.minorEnd:t.majorEnd,r},Zc={majorStart:0,majorEnd:0,minorStart:0,minorEnd:0},Qc=(t,e)=>t[0]-e[0];class th{constructor(t,e){this._isColumn=!0,this._isReverse=!1,this._skipMajors=!1,this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=Number.MIN_SAFE_INTEGER,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=Number.MIN_SAFE_INTEGER,this._majorIndex=Number.MIN_SAFE_INTEGER,this._minorIndex=Number.MIN_SAFE_INTEGER,this._delegateMajorIndex=Number.MIN_SAFE_INTEGER,this._delegateMinorIndex=Number.MIN_SAFE_INTEGER,this._delegate=t;const n=(e.orientation??I.Column)===I.Column;this._isColumn=n,this._isReverse=e.reverse??!1,this._skipMajors=e.skipMajors??!1;const r=e.bounds,o=r.colStart,s=r.rowStart,i=r.colEnd,a=r.rowEnd;this._majorMin=n?o:s,this._majorMax=n?i:a,this._minorMin=n?s:o,this._minorMax=n?a:i,this._processMajorSkip=n?e.processColumnSkip:e.processRowSkip,this._processMinorSkip=n?e.processRowSkip:e.processColumnSkip;const l=t.next();this._delegateResult=l,this._initialize()}_initialize(){const t=this._isColumn,e=this._isReverse,n=e?-1:1;let r=e?this._majorMax:this._majorMin,o=(e?this._minorMax:this._minorMin)-n;const s=this._processMinorSkip;s&&(o=s(o,e));const i=this._processMajorSkip;i&&(r=i(r,e)),this._majorIndex=r,this._minorIndex=o;const a=this._delegateResult;if(a.done)this._delegateMajorIndex=this._majorMax,this._delegateMinorIndex=this._minorMax+n;else{const e=a.value[0];this._delegateMajorIndex=t?e.colIndex:e.rowIndex,this._delegateMinorIndex=t?e.rowIndex:e.colIndex}}next(t){void 0!==t&&(this._delegateResult=this._delegate.next(t),this._initialize());const e=this._isReverse,n=this._isColumn,r=this._majorMin,o=this._majorMax;let s=this._majorIndex,i=this._minorIndex;if(s>o||s<r)return Ul;let a=this._delegateMajorIndex,l=this._delegateMinorIndex,c=this._delegateResult.done;if(s===a&&i===l){const t=this._delegate.next();if(this._delegateResult=t,c=t.done,c)a=e?r:o,a=e?this._minorMin:this._minorMax;else{const e=t.value[0];a=n?e.colIndex:e.rowIndex,l=n?e.rowIndex:e.colIndex}this._delegateMajorIndex=a,this._delegateMinorIndex=l}const h=e?-1:1;if(this._minorIndex=i+=h,s===a&&i===l&&!c)return this._delegateResult;const u=this._processMinorSkip;if(u&&(i=u(i,e)),i>this._minorMax||i<this._minorMin){s+=h;const t=this._processMajorSkip;t&&(s=t(s,e)),this._skipMajors&&(!e&&s<a||e&&s>a)&&(s=a),this._majorIndex=s,i=e?this._minorMax:this._minorMin}if(this._minorIndex=i,s===a&&i===l&&!c)return this._delegateResult;if(s>o||s<r)return Ul;return{done:!1,value:[{colIndex:n?s:i,rowIndex:n?i:s}]}}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}class eh{constructor(t){this._isColumn=!0,this._majorSize=Number.MAX_SAFE_INTEGER,this._minorSize=Number.MAX_SAFE_INTEGER,this._majorMin=Number.MAX_SAFE_INTEGER,this._majorMax=Number.MIN_SAFE_INTEGER,this._minorMin=Number.MAX_SAFE_INTEGER,this._minorMax=Number.MIN_SAFE_INTEGER,this._majorIndex=Number.MAX_SAFE_INTEGER,this._minorIndex=Number.MAX_SAFE_INTEGER,this._minorOffset=0,this._minorRepeat=0,this._majorOffset=-1,this._majorRepeat=1,this._pattern=[];const e=t.delegate;this._delegate=e;const n=(t.orientation??I.Column)===I.Column;this._isColumn=n;const r=t.dims,o=t.bounds,s=o.colStart,i=o.rowStart,a=o.colEnd,l=o.rowEnd;if(this._majorSize=1+(n?a-s:l-i),this._minorSize=1+(n?l-i:a-s),this._majorMin=n?s:i,this._minorMin=n?i:s,this._majorMax=(n?s+r.major:i+r.major)-1,this._minorMax=(n?i+r.minor:s+r.minor)-1,this._majorSize>this._majorMax+1||this._minorSize>this._minorMax+1)throw new Error("The dimensions must be larger than the bounds.");const c=e.next();this._nextDelegateResult=c,this._initialize()}_initialize(){const t=this._isColumn,e=this._nextDelegateResult;if(e.done)this._nextResult=Ul;else{const n=e.value[0],r=t?n.colIndex:n.rowIndex,o=t?n.rowIndex:n.colIndex,s=[[o,e.value[1]]];this._minorSpan=s,this._majorIndex=r,this._minorIndex=o,this._pattern.push([r,s]),this._nextResult=e}}next(t){if(void 0!==t)throw new Bt;const e=this._nextResult,n=this._isColumn;let r=this._majorIndex,o=this._nextDelegateResult;if(!o.done){const t=o.value[0];if((n?t.colIndex:t.rowIndex)===r&&(o=this._delegate.next(),this._nextDelegateResult=o,!o.done)){const t=o.value,s=t[0],i=n?s.colIndex:s.rowIndex,a=n?s.rowIndex:s.colIndex;if(i===r)return this._minorSpan.push([a,t[1]]),this._minorOffset=this._minorSpan.length-1,this._minorIndex=a,this._nextResult=o,e}}const s=this._minorMax;let i=this._minorIndex;if(i<s){let t=this._minorOffset;t++;const o=this._minorSpan;t>=o.length&&(t=0,this._minorRepeat++);const a=o[t],l=this._minorMin;if(i=l+(a[0]-l+this._minorSize*this._minorRepeat),this._minorIndex=i,this._minorOffset=t,i<=s){const t=[{colIndex:n?r:i,rowIndex:n?i:r},a[1]];return this._nextResult={done:!1,value:t},e}}if(!o.done){const t=o.value,r=t[0],s=n?r.colIndex:r.rowIndex,i=n?r.rowIndex:r.colIndex,a=[[i,t[1]]];return this._pattern.push([s,a]),this._majorIndex=s,this._minorSpan=a,this._minorOffset=0,this._minorIndex=i,this._minorRepeat=0,this._nextResult=o,e}const a=this._majorMax;if(r<a){let t=this._majorOffset;t++;const o=this._pattern;t>=o.length&&(t=0,this._majorRepeat++);const s=o[t],l=s[1],c=l[0],h=this._majorMin;if(r=h+(s[0]-h+this._majorSize*this._majorRepeat),this._majorIndex=r,this._majorOffset=t,r<=a){this._minorSpan=l,this._minorOffset=0,i=c[0],this._minorIndex=i,this._minorRepeat=0;const t=[{colIndex:n?r:i,rowIndex:n?i:r},c[1]];return this._nextResult={done:!1,value:t},e}}return e.done||(this._nextResult=Ul),e}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}class nh{constructor(t,e,n){this._comparator=t?.comparator??W.createCellComparator(t.orientation??I.Column,t.reverse??!1),this._iterator1=e,this._iterator2=n;const r=e.next();this._nextResult1=r;const o=n.next();this._nextResult2=o,t?.reuseResult&&(!0===t.reuseResult?this._reuseResult={done:!1,value:[void 0,void 0,void 0,void 0]}:this._reuseResult=t.reuseResult)}next(t){let e=this._nextResult1,n=this._nextResult2;if(e.done&&n.done)return e;if(e.done){const t=n;this._nextResult2=this._iterator2.next();const e=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};e.done=!1;const r=e.value,o=t.value;return r[2]=o[0],r[3]=o[1],r[0]=void 0,r[1]=void 0,e}if(n.done){const t=e;this._nextResult1=this._iterator1.next();const n=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};n.done=!1;const r=n.value,o=t.value;return r[0]=o[0],r[1]=o[1],r[2]=void 0,r[3]=void 0,n}let r=(0,this._comparator)(e.value[0],n.value[0]);if(r<0){const t=e;this._nextResult1=this._iterator1.next();const n=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};n.done=!1;const r=n.value,o=t.value;return r[0]=o[0],r[1]=o[1],r[2]=void 0,r[3]=void 0,n}if(r>0){const t=n;this._nextResult2=this._iterator2.next();const e=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};e.done=!1;const r=e.value,o=t.value;return r[2]=o[0],r[3]=o[1],r[0]=void 0,r[1]=void 0,e}this._nextResult1=this._iterator1.next(),this._nextResult2=this._iterator2.next();const o=this._reuseResult??{done:!1,value:[void 0,void 0,void 0,void 0]};o.done=!1;const s=o.value;return s[0]=e.value[0],s[1]=e.value[1],s[2]=n.value[0],s[3]=n.value[1],o}return(t){return null}throw(t){return null}[Symbol.iterator](){return this}}const rh="Must be an array of arrays.",oh=(t,e,n)=>{const r=e.majorStart,o=e.minorStart,s=e.majorEnd,i=[],a=e.minorEnd-o+1,l="function"==typeof t;for(let e=r;e<=s;e++){const r=new Array(a);if(l)if(n){let n=o;for(let o=0;o<a;o++)r[o]=t(n++,e)}else{let n=o;for(let o=0;o<a;o++)r[o]=t(e,n++)}else r.fill(t,0,a);const s=[[o,r]];i.push([e,s])}return{tuples:i,bounds:e}},sh=(t,e=!1,n=null,r=!1)=>{let o=0,s=0,i=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER;if(n){o=n.majorStart??0,s=n.minorStart??0;i=(n.majorEnd??Number.MAX_SAFE_INTEGER)-o+1,a=(n.minorEnd??Number.MAX_SAFE_INTEGER)-s+1}if(e){const t=o;o=s,s=t;const e=i;i=a,a=e}if(!Array.isArray(t))throw new Error(rh);if(t.length>i)throw new kt;const l=e?new Ke.TransposedBuilder:new Ke.Builder;for(let e=0;e<t.length;e++){let n=t[e];if(null!=n&&0!==n.length){if(!Array.isArray(n))throw new Error(rh);if(n.length>a)throw new kt;if(r){let t=-1;for(let r=0;r<n.length;r++){const i=n[r];null==i?-1!==t&&(l.addValues(e+o,s+t,n.slice(t,r)),t=-1):-1===t&&(t=r)}-1!==t&&l.addValues(e+o,s+t,n.slice(t))}else l.addValues(e+o,s,n)}}return l.build()},ih=(t,e,n)=>{if(t===e)return e},ah=(t,e,n)=>{if(t[0].value===t[1].value)return e},lh=[null,null],ch=(t=!0,e=ih)=>{const n=[];let r,o,s=Number.MIN_SAFE_INTEGER,i=Number.MIN_SAFE_INTEGER;return{append:(a,l,c)=>{let h=!0;if(void 0!==c){const n=void 0===o?c:e(o,c,t);void 0===n?h=!1:c=n}if(h&&l===i+1&&a===s)return t?r.rowEnd=l:r.colEnd=l,i=l,void(o=c);r&&n.push(r);const u=t?a:l,d=t?l:a;r={colStart:u,rowStart:d,colEnd:u,rowEnd:d,value:c},s=a,i=l,o=c},done:(e=!1)=>(r&&(n.push(r),r=null),e?Hc(n,t?I.Column:I.Row,2,ah,lh):n)}};class hh{constructor(t){this._major=null,this._dataCoords=null,this._count=0,this._isColumn=!0,this._lastMajor=Number.MIN_SAFE_INTEGER,this._lastMinorSpan=null,this._maxCoords=null,this._isShared=!1,this._options={orientation:I.Row,...t},this._isColumn=(t?.orientation??I.Column)===I.Column,t?.maxCoords&&(this._maxCoords=Object.freeze({colStart:Math.max(0,t.maxCoords.colStart??0),rowStart:Math.max(0,t.maxCoords.rowStart??0),colEnd:Math.min(Number.MAX_SAFE_INTEGER,t.maxCoords.colEnd??Number.MAX_SAFE_INTEGER),rowEnd:Math.min(Number.MAX_SAFE_INTEGER,t.maxCoords.rowEnd??Number.MAX_SAFE_INTEGER)})),this._createRun=t?.createRun??(t=>new ql(t)),this._optionsMinor={},this._major=new nc({nodeSize:uh})}getRuns(t){const e=this._isColumn,n=this._maxCoords,r=this.getCoords();if(!r)return Gl;const o=t?.bounds;let s,i;if(o){const t=Kc(o?.colStart??Number.MIN_SAFE_INTEGER,o?.rowStart??Number.MIN_SAFE_INTEGER,o?.colEnd??Number.MAX_SAFE_INTEGER,o?.rowEnd??Number.MAX_SAFE_INTEGER,e,n,r);if(!t)return Gl;s={bounds:{min:t.majorStart,max:t.majorEnd}},i={bounds:{min:t.minorStart,max:t.minorEnd}}}const a=this._major.entries(s);let l=a.next();if(l.done)return Gl;let c=l.value[0],h=l.value[1],u=h.runs(i),d=u.next();if(d.done)return Gl;let g=d.value[0].min,m=d.value[1];return{[Symbol.iterator](){return this},next(){if(l.done)return Ul;const t={done:!1,value:[c,g,m]};for(d=u.next();d.done&&!l.done;)l=a.next(),l.done||(c=l.value[0],h=l.value[1],u=h.runs(i),d=u.next());return d.done||(g=d.value[0].min,m=d.value[1]),t}}}getOrientation(){return this._isColumn?I.Column:I.Row}entries(t){const e=this._isColumn;let n=e,r=!0;const o=this._maxCoords,s=this.getCoords(),i=Kc(Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,e,o,s);if(!i)return Gl;let a,l,c,h=i.majorStart,u=i.majorEnd,d=i.minorStart,g=i.minorEnd,m=!1;if(t){t?.orientation&&(n=t?.orientation===I.Column,r=e===n);const i=t?.bounds;if(i){const t=Kc(i.colStart,i.rowStart,i.colEnd,i.rowEnd,e,o,s);if(!t)return Gl;h=t.majorStart,u=t.majorEnd,d=t.minorStart,g=t.minorEnd}m=t.reverse??!1,c=(t=>"boolean"!=typeof t?t:!0===t?{done:!1,value:[{colIndex:-1,rowIndex:-1},null]}:void 0)(t.reuseResult),a=e?t.processColumnSkip:t.processRowSkip,a&&(m?u=a(u,m):h=a(h,m)),l=e?t.processRowSkip:t.processColumnSkip,l&&(m?g=l(u,m):d=l(d,m))}if(!s)return Gl;r||h!==u||(r=!0),ph.bounds.min=h,ph.bounds.max=u,ph.reverse=m,ph.processSkip=a,ph.reuseResult=mh;let f=this._major.entries(ph),p=_h();const _=t=>{if(!t.nextActive)return;const e=e=>{const n=t.nextMinorIndex,r=t.nextMinorValue,o=t.nextActive;return e?(t.nextMinorIndex=e[0],t.nextMinorValue=e[1],t.nextActive=!0):(t.nextActive=!1,t.nextMinorIndex=m?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,t.nextMinorValue=null),t.value=r,t.minorIndex=n,t.active=o,dh[0]=t.majorIndex,dh[1]=n,dh[2]=r,dh},n=t.minorIterator;if(!n)return e();const r=n.next();return r.done&&(t.minorIterator=null),e(r.value)},S=t=>{if(f)for(;;){const e=f.next();if(e.done)return void(f=void 0);const n=e.value,r=n[1];r||console.warn("issue",r),t.majorIndex=n[0],t.active=!0,t.nextActive=!1,fh.bounds.min=d,fh.bounds.max=g,fh.reverse=m,fh.processSkip=l,fh.reuseResult=gh;const o=r.entries(fh),s=o.next();if(!s.done){const e=s.value;return t.nextMinorIndex=e[0],t.nextMinorValue=e[1],t.minorIterator=o,t.nextActive=!0,_(t)}}};let w=null;if(r){w=()=>{let t;return t=_(p),t||(t=S(p),t||void 0)}}else{const t=m?g:d,e=m?d:g;let n,r=t,o=e,s=!0;const i=()=>{if(p.nextMajorCursor)return p=p.nextMajorCursor,p;p=n,(r<d||r>g||r===o)&&(p=null),r=o,o=e};w=()=>{for(;p;){let a=null;if(s){let e=n?_h():p;if(a=S(e),a){n?(e.prevMajorCursor=p,p.nextMajorCursor=e,p=e):n=p,o=m?Math.max(o,p.nextMinorIndex):Math.min(o,p.nextMinorIndex);const r=p.minorIndex;r!==t&&(o=m?Math.max(o,r):Math.min(o,r),a=null)}else s=!1,i()}else{const t=p.minorIndex,s=p.nextMinorIndex;t===r?(dh[0]=p.majorIndex,dh[1]=t,dh[2]=p.value,a=dh):!m&&t>r||m&&t<r?o=m?Math.max(o,t):Math.min(o,t):!m&&s>r||m&&s<r?o=m?Math.max(o,s):Math.min(o,s):a=_(p),p.active&&(o=m?Math.max(o,p.nextMinorIndex):Math.min(o,p.nextMinorIndex)),e===r||p.active||(p.prevMajorCursor?p.prevMajorCursor.nextMajorCursor=p.nextMajorCursor:n=p.nextMajorCursor,p.nextMajorCursor&&(p.nextMajorCursor.prevMajorCursor=p.prevMajorCursor)),i()}if(a)return a}}}const y={next(t){if(t)throw new Bt("Iterator with next argument is not supported.");const n=w();if(!n)return Ul;const r=((t,e,n,r,o)=>{const s=o??{done:!1,value:[{colIndex:-1,rowIndex:-1},null]},i=s.value,a=i[0];return a.colIndex=r?t:e,a.rowIndex=r?e:t,i[1]=n,s})(n[0],n[1],n[2],e,c);return r},[Symbol.iterator](){return this},return:t=>null,throw:t=>null};return y}values(t){const e=this.entries(t);let n;t?.reuseResult&&(n=!0===t.reuseResult?{done:!1,value:null}:t.reuseResult);return{next(t){const r=e.next(t);return r.done?Ul:n?(n.value=r.value[1],n):{done:!1,value:r.value[1]}},[Symbol.iterator](){return this},return:t=>null,throw:t=>null}}keys(t){const e=this.entries(t);let n;t?.reuseResult&&(n=!0===t.reuseResult?{done:!1,value:null}:t.reuseResult);return{next(t){const r=e.next(t);return r.done?Ul:n?(n.value=r.value[0],n):{done:!1,value:r.value[0]}},[Symbol.iterator](){return this},return:t=>null,throw:t=>null}}_updateMajorSpan(t,e=!1){if(!t||0===t.length)return;e&&t.sort((t,e)=>t[0]-e[0]);const n=this._major,r=t[0];let o=r[0],s=o,i=[r[1]];for(let e=1;e<t.length;e++){const r=t[e],a=r[0],l=r[1];a===s+1?i.push(l):(n.setRunAt(o,new ql(i)),o=a,i=[l]),s=a}i.length>0&&n.setRunAt(o,new ql(i))}setValues(t){if(!t)throw new Lt;if(0===t.length)return this;const e=(t=t.sort(Qc))[0][0],n=t[t.length-1][0];let r=Number.MIN_SAFE_INTEGER,o=Number.MAX_SAFE_INTEGER;const s=this._isColumn,i=this._maxCoords;if(i){const t=s?i.colStart:i.rowStart,a=s?i.colEnd:i.rowEnd;if(e<t||n>a)throw new kt;r=s?i.rowStart:i.colStart,o=s?i.rowEnd:i.colEnd}if(!t||0===t.length)return this;let a=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER,c=0,h=e-1;const u=[],d=(t,e,n)=>{if(h===n)throw new Ke.OutOfOrderError(`Duplicate major Indices: {${n}}.`);h=n,e=e.sort(Qc),t=t.clone();let s=Number.MIN_SAFE_INTEGER;const i=e.length;for(let h=0;h<i;h++){const i=e[h],u=i[0],d=i[1],m=u+d.length-1;if(s>=u)throw new Ke.OutOfOrderError(`Overlapping minor Indices: {${n}, ${u}}.`);if(u<r||m>o)throw new kt;if(d&&d.length>0){const e=t.getCount();t.setRunAt(u,g(d));const n=t.getCount();c+=n-e,a=Math.min(a,t.getCoords().min),l=Math.max(l,t.getCoords().max)}s=m}f++,u.push([n,t])},g=this._createRun,m=this._optionsMinor;let f=0;const p=()=>{const e=t[f],n=e[0],r=e[1],o=new nc(m);d(o,r,n)},_=this._major;ph.bounds.min=e,ph.bounds.max=n,ph.reverse=!1,ph.processSkip=null,ph.reuseResult=mh;const S=_.entries(ph);let w=S.next();for(;!w.done;){const e=w.value,n=e[0];let r=t[f],o=r[0];if(o>n)w=S.next();else{for(;o<n;)p(),r=t[f],o=r[0];if(o===n){const t=r[1],o=e[1];d(o,t,n)}w=S.next()}}for(;t[f];)p();return this._updateMajorSpan(u),this._updateCountAndCoords(c,e,a,n,l),this}_updateCountAndCoords(t,e,n,r,o,s=!1){const i=this._count+t;if(this._count=i,this._lastMajor=Number.MIN_SAFE_INTEGER,!this._dataCoords)return;const a=this._isColumn;let l=a?e:n,c=a?n:e,h=a?r:o,u=a?o:r;if(0===i)this._dataCoords=null;else{const t=this._dataCoords;t&&(l=(s?Math.max:Math.min)(l,t.colStart),c=(s?Math.max:Math.min)(c,t.rowStart),h=(s?Math.min:Math.max)(h,t.colEnd),u=(s?Math.min:Math.max)(u,t.rowEnd));const e={colStart:l,rowStart:c,colEnd:h,rowEnd:u};this._dataCoords=e}}clear(){this._major.clear(),this._dataCoords=null,this._count=0}delete(t){const e=this._count;if(!t)return this.clear(),e>0;const n=this._isColumn,r=this._maxCoords,o=this.getCoords(),s=Kc(t.colStart,t.rowStart,t.colEnd,t.rowEnd,n,r,o);if(!s||0===e)return!1;if(W.isRangeWithinRange(o,t))return this.clear(),e>0;const i=s.majorStart,a=s.majorEnd,l=s.minorStart,c=s.minorEnd;let h=n?o.colStart:o.rowStart,u=n?o.colEnd:o.rowEnd;const d=n?o.rowStart:o.colStart,g=n?o.rowEnd:o.colEnd;let m=!1,f=0;const p=this._major;if(l<=d&&c>=g){ph.bounds.min=i,ph.bounds.max=a;const t=p.entries(ph);let e=t.next();for(;!e.done;){f-=e.value[1].getCount(),e=t.next()}return p.delete(i,a-i+1),this._count+=f,this._dataCoords=null,0!==f}const _=[],S=this._isShared,w=[];ph.bounds.min=i,ph.bounds.max=a,fh.reverse=!1,fh.processSkip=null,fh.reuseResult=mh;const y=p.entries(ph);let E=y.next();for(;!E.done;){const t=E.value,e=t[0];let n=t[1];const r=n.getCoords(),o=r.min,s=r.max;if(l<=o&&c>=o||l<=s&&l<=s)if((o===d&&l<=d||s===g&&c>=g)&&(m=!0),o>=l&&s<=c)_.push(e),f-=n.getCount();else{const t=n.getCount();S&&(n=n.clone(),w.push([e,n])),n.delete(l,c-l+1);f+=n.getCount()-t}E=y.next()}this._updateMajorSpan(w);const b=_.length;if(b>0){const t=da(_,!0);for(let e=0;e<t.length;e++){const n=t[e];p.delete(n.min,n.max-n.min+1)}const e=p.getCoords();if(!e)return this.clear(),!0;h=e.min,u=e.max}return m?(this._count+=f,this._dataCoords=null,!0):0===b?(this._count+=f,0!==f):(this._updateCountAndCoords(f,h,d,u,g,!0),0!==f)}shift(t,e){if(!t||!e)throw new Lt;const n=this._isColumn,r=this._maxCoords,o=e===w.Right||e===w.Down,s=e===w.Left||e===w.Right,i=Kc(t.colStart,t.rowStart,t.colEnd,t.rowEnd,n,r,t);if(!i)return!1;const a=i.majorStart,l=i.majorEnd,c=i.minorStart,h=i.minorEnd,u=this.getCoords();if(!u)return!1;const d=n?u.colStart:u.rowStart,g=n?u.colEnd:u.rowEnd,m=n?u.rowStart:u.colStart,f=n?u.rowEnd:u.colEnd,p=c<=m&&h>=f,_=n===s;if(_&&p||!_&&(a<=d&&l>=g)){if(!Kc(u.colStart,u.rowStart,u.colEnd+(o&&s?t.colEnd-t.colStart+1:0),u.rowEnd+(o&&!s?t.rowEnd-t.rowStart+1:0),n,r))return!1}if(_&&a>g||!_&&c>f)return!1;let S=_?l-a+1:h-c+1;if(!o&&(S*=-1,W.isRangeWithinRange(u,t)))return this.clear(),!0;let y=0;const E=this._major,b=[];if(ph.bounds.min=a,ph.bounds.max=_?Number.MAX_SAFE_INTEGER:l,fh.reverse=!o,fh.processSkip=null,fh.reuseResult=mh,_&&p){if(!o){ph.bounds.max=l;const t=E.entries(ph);let e=t.next();for(;!e.done;){y-=e.value[1].getCount(),e=t.next()}}E.shift(a,S);const t=E.getCoords();return this._dataCoords=null,this._updateCountAndCoords(y,t.min,m,t.max,f),!0}let v=n?u.colStart:u.rowStart,C=n?u.colEnd:u.rowEnd,x=n?u.rowStart:u.colStart,I=n?u.rowEnd:u.colEnd;o||(x=Number.MAX_SAFE_INTEGER,I=Number.MIN_SAFE_INTEGER);let A=Number.MAX_SAFE_INTEGER;r&&(A=s?r.colEnd:r.rowEnd);const R=new Set,M=_?new Map:null,T=[],N=E.entries(ph),F={bounds:{min:c,max:h}};let k=N.next();for(;!k.done;){const t=k.value,e=t[0],n=t[1].clone(),r=n.getCoords(),o=r.min,s=r.max;if(_&&M.set(e,n),c<=s){const t=n.getCount();_?(e>=a-S&&Hl(n.runs(F),(t,n)=>{const r=n.min,o=n.max;let s=t;r-1<=h&&o>h&&(s=s.slice(0,h+1-r)),r<c&&o+1>=c&&(s=s.slice(c-r)),T.push({majorIndex:e+S,minorIndex:Math.max(r,c),run:s})}),n.delete(c,h-c+1)):n.shift(c,S);const r=n.getCount();if(0===r)R.add(e),x=Math.min(x,s),I=Math.max(I,o);else{const t=n.getCoords();if(x=Math.min(x,t.min),I=Math.max(I,t.max),I>A)throw new kt}y+=r-t,b.push([e,n])}k=N.next()}const O=this._optionsMinor;let L=!1;for(let t=0;t<T.length;t++){const e=T[t],n=e.majorIndex,r=e.run;let o=M.get(n);o||(o=new nc(O),M.set(n,o),b.push([n,o]),L=!0),o.setRunAt(e.minorIndex,r),y+=r.length,v=Math.min(v,n),C=Math.max(C,n),R&&R.delete(n)}if(this._updateMajorSpan(b,L),R&&R.size>0){const t=Array.from(R.values()),e=da(t);for(let t=0;t<e.length;t++){const n=e[t];E.delete(n.min,n.max-n.min+1)}const n=E.getCoords();if(!n)return this.clear(),!0;v=n.min,C=n.max}if(I!==f||x!==m)return this._count+=y,this._dataCoords=null,!0;{const t=this._count+y;this._count=t,this._dataCoords=0===t?null:Object.freeze({colStart:n?v:x,rowStart:n?x:v,colEnd:n?C:I,rowEnd:n?I:C})}return 0!==y||!W.isEqualRanges(u,this.getCoords())}getCount(){return this._count}getValueAt(t,e){const n=this._isColumn,r=n?e:t,o=n?t:e,s=this._lastMajor;let i;if(s===r&&s!==Number.MIN_SAFE_INTEGER?i=this._lastMinorSpan:(i=this._major.at(r),this._lastMajor=r,this._lastMinorSpan=i),!i)return;return i.at(o)}setValueAt(t,e,n){const r=this._isColumn,o=[r?e:t,[[r?t:e,[n]]]];this.setValues([o])}copyTo(t,e,n){if(0===this.getCount())return;const r=this.getOrientation(),o=t.getOrientation(),s=this.getRuns({bounds:n});let i=s.next();const a=W.cellToRange(e);a.colEnd=n.colEnd-n.colStart+e.colIndex,a.rowEnd=n.rowEnd-n.rowStart+e.rowIndex;const l=this._isColumn,c=this._maxCoords,h=this.getCoords();let u,d=Kc(n.colStart??Number.MIN_SAFE_INTEGER,n.rowStart??Number.MIN_SAFE_INTEGER,n.colEnd??Number.MAX_SAFE_INTEGER,n.rowEnd??Number.MAX_SAFE_INTEGER,l,c,h);d={...d};const g=o!==I.Row,m=t.getMaxCoords();u=Kc(a?.colStart??Number.MIN_SAFE_INTEGER,a?.rowStart??Number.MIN_SAFE_INTEGER,a?.colEnd??Number.MAX_SAFE_INTEGER,a?.rowEnd??Number.MAX_SAFE_INTEGER,g,m),u={...u};const f=u.majorStart-d.majorStart,p=u.minorStart-d.minorStart,_=r===o?new Ke.Builder:new Ke.TransposedBuilder;for(;!i.done;){const t=i.value[0];let e=i.value[1],n=i.value[2];e+n.length>d.minorEnd&&(n=n.slice(0,d.minorEnd-e+1)),e<d.minorStart&&(n=n.slice(d.minorStart-e),e=d.minorStart),_.addValues(t+f,e+p,n),i=s.next()}const S=_.build();t.delete(a),S&&t.setValues(S.tuples)}getCoords(){if(this._dataCoords)return this._dataCoords;if(0===this._major.getCount())return null;let t=Number.MAX_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,r=Number.MIN_SAFE_INTEGER;const o=this._major.entries();let s=o.next();for(;!s.done;){const i=s.value,a=i[0];t=Math.min(a,t),e=Math.max(a,e);const l=i[1].getCoords();n=Math.min(l.min,n),r=Math.max(l.max,r),s=o.next()}const i=this._isColumn,a=Object.freeze({colStart:i?t:n,rowStart:i?n:t,colEnd:i?e:r,rowEnd:i?r:e});return this._dataCoords=a,a}clone(t){this._isShared=!0;const e=new hh(this._options);return e._isShared=!0,e._major=this._major.clone(),e._dataCoords=this._dataCoords,e._count=this._count,e}cloneEmpty(t){return new hh(this._options)}getMaxCoords(){const t=this._maxCoords;return t||null}get[Symbol.toStringTag](){let t="";const e=this.getCoords();if(e){const n=e.colEnd-e.colStart+1,r=e.rowEnd-e.rowStart+1;t=`${this.getCount()}-${this._isColumn?n:r}x${this._isColumn?r:n}`}return`[SparseGrid:${t}]`}}hh||(hh={});const uh=12;Object.seal({done:!1,value:null});const dh=[-1,-1,null],gh=Object.seal({done:!1,value:[-1,null]}),mh=Object.seal({done:!1,value:[-1,null]}),fh={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:gh},ph={bounds:{min:-1,max:-1},reverse:!1,processSkip:null,reuseResult:mh},_h=()=>({majorIndex:-1,minorIndex:-1,value:null,active:!1,nextMinorIndex:-1,nextActive:!1,nextMinorValue:null,minorIterator:null,nextMajorCursor:null,prevMajorCursor:null});class Sh{constructor(t){if(this._l=0,this._at=null,this._dt=Lh.Undefined,this._a32=null,this._a64=null,this._cv=null,this._vt=null,this._vi32=null,this._vi64=null,this._vf32=null,this._vf64=null,!t)throw new Error("options is required");const e=t.length;if(this._l=e,this._dt=t.type,this._cv=t.getCoercedValue??null,e>0){t.types&&(this._at=t.types,this._vt=new Uint8Array(this._at));const e=t.values32??null;e&&(this._a32=e,this._vi32=new Int32Array(e),this._vf32=new Float32Array(e));const n=t.values64??null;if(n&&(this._a64=n,this._vf64=new Float64Array(n),this._vi64=new BigInt64Array(n)),!e&&!n)throw new Error("values32 or values64 is required")}}getConstructorOptions(){return{length:this._l,type:this._dt,types:this._at,values32:this._a32,values64:this._a64,getCoercedValue:this._cv}}at(t){if(t>>>0>=this._l)return;const e=this._vt,n=e&&e[t]||this._dt;let r,o=!1;switch(this._vi32?r=this._vi32[t]:(o=!0,r=Number(this._vi64[t])),n){case yh:return o?Number(r):r;case Eh:return o?this._vf64[t]:this._vf32[t];case bh:return!!r;case xh:case Ih:return this._cv(n,o?Number(r):r);case vh:return this._vi64[o?t:r];case Ch:return this._vf64[o?t:r];case Mh:return Number.NaN;case Th:return Number.MAX_SAFE_INTEGER;case Nh:return Number.MIN_SAFE_INTEGER;case Ah:return 1/0;case Rh:return-1/0;case Fh:return null;case kh:case Oh:return}return this._cv(n,o?Number(r):r)}toArray(t){const e=[],n=Math.max(t,this._l);for(let t=0;t<n;t++)e.push(this.at(t));return e}get length(){return this._l}get[Symbol.toStringTag](){return"[MixTypedArrayList]"}toString(){const t=this._a32,e=this._a64;let n="";t&&!e?n="32":e&&!t&&(n="64");return`{${n}${this._at?"":":SINGLE_TYPE"}}:${this._l}}`}static _createArrayBuffer(t){try{return new SharedArrayBuffer(t)}catch(t){}return new ArrayBuffer(t)}static fromArray(t,e,n,r,o=wh){const s=t.length;if(0===s)return new Sh({type:Lh.Undefined,length:s,getCoercedValue:n});let i=this._createArrayBuffer(s*Int8Array.BYTES_PER_ELEMENT),a=new Uint8Array(i),l=0,c=!1,h=Dh(t[0],r);for(let e=0;e<s;e++){const n=t[e],o=Dh(n,r);o!==Ch&&o!==vh||l++,h!==o&&(a[e]=o,c=!0)}c||(a=null,i=null);let u,d,g,m,f,p,_,S,w=!1;l/s>o&&(w=!0,l=s),0!==l&&(g=this._createArrayBuffer(l*BigInt64Array.BYTES_PER_ELEMENT),m=new BigInt64Array(g),f=new Float64Array(g)),w?(u=m,d=f):(p=this._createArrayBuffer(s*Int32Array.BYTES_PER_ELEMENT),_=new Int32Array(p),S=new Float32Array(p),u=_,d=S);let y=h;if(w)for(let n=0;n<s;n++){const r=t[n];switch(a&&(y=a[n]||h),y){case yh:u[n]=BigInt(r);break;case bh:u[n]=BigInt(r?1:0);break;case Eh:d[n]=r;break;case vh:u[n]=r;break;case Ch:d[n]=r;break;case xh:case Ih:u[n]=BigInt(e?.(y,r)??0);break;default:y>127&&y<255&&(u[n]=BigInt(e?.(y,r)??0))}}else{let n=0;for(let r=0;r<s;r++){const o=t[r];switch(a&&(y=a[r]||h),y){case yh:u[r]=o;break;case bh:u[r]=o?1:0;break;case Eh:d[r]=o;break;case vh:_[r]=n,m[n]=o,n++;break;case Ch:_[r]=n,f[n]=o,n++;break;case xh:case Ih:u[r]=e?.(y,o)??0;break;default:y>127&&y<255&&(u[r]=e?.(y,o)??0)}}}return new Sh({length:s,types:c?i:null,type:h,values32:p,values64:g,getCoercedValue:n})}}const wh=.1,yh=1,Eh=2,bh=3,vh=4,Ch=5,xh=6,Ih=7,Ah=8,Rh=9,Mh=10,Th=11,Nh=12,Fh=13,kh=14,Oh=127,Lh={Undefined:kh},Dh=(t,e)=>{switch(typeof t){case"number":const n=t;if(Number.isNaN(n))return Mh;if(n===1/0)return Ah;if(n===-1/0)return Rh;if(Object.is(n,-0))return Eh;if(n===Number.MAX_SAFE_INTEGER)return Th;if(n===Number.MIN_SAFE_INTEGER)return Nh;if(Number.isInteger(n)&&n<=2147483647&&n>=-2147483648)return yh;return Math.fround(n)===n?Eh:Ch;case"string":return xh;case"boolean":return bh;case"object":if(null===t)return Fh;if(t instanceof Error)return Ih;if(!e)return Oh;const r=e(t);if(r<128||r>255)throw new Error("Custom type must be between 128 and 255");return r;case"bigint":return vh;case"undefined":return kh;case"symbol":case"function":return Oh}return Oh},Bh=t=>{if(!t||t.length<=1)return!1;if(2===t.length)return W.isRangesIntersect(t[0],t[1]);const e=new Lc;e.load(t);for(let n=0;n<t.length;n++){if(e.search(t[n]).length>1)return!0}return!1},zh=(t,e,n)=>{const r=[];if(W.isRangesIntersect(t,e)){const o=_t.subtractRect({top:t.rowStart,left:t.colStart,bottom:t.rowEnd+1,right:t.colEnd+1},{top:e.rowStart,left:e.colStart,bottom:e.rowEnd+1,right:e.colEnd+1},n===I.Column);for(let t=0;t<o.length;t++){const e={colStart:o[t].left,rowStart:o[t].top,colEnd:o[t].right-1,rowEnd:o[t].bottom-1};r.push(e)}}else r.push(t);return r},Ph=(t,e,n)=>{if(e&&t?.[0])for(let r=0;r<t.length;r++){const o=t[r];W.intersectRanges(o,e)&&n(o,!W.isRangeWithinRange(o,e),r)}},jh=(t,e)=>{const n=t.colStart,r=t.rowStart,o=e.colStart,s=e.rowStart;return(t,e)=>{const i=t.colIndex-n,a=e.colIndex-o;if(i===a){return t.rowIndex-r-(e.rowIndex-s)}return i-a}},Hh=(t,e)=>{const n=t.colStart,r=t.rowStart,o=e.colStart,s=e.rowStart;return(t,e)=>{const i=t.rowIndex-r,a=e.rowIndex-s;if(i===a){return t.colIndex-n-(e.colIndex-o)}return i-a}},Vh=(t,e,n=!1,r=!1)=>{let o=e.colEnd-e.colStart+1,s=e.rowEnd-e.rowStart+1;if(r){const t=o;o=s,s=t}const i={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart+o-1,rowEnd:t.rowStart+s-1};if(n){let e=t.colStart,n=t.rowStart;return W.isSingleCell(t)?(e+=o-1,n+=s-1):(e+=t.colEnd-t.colStart,n+=t.rowEnd-t.rowStart),i.colEnd=r?n:e,i.rowEnd=r?e:n,i}const a=t.colEnd-t.colStart+1;if(a%o!==0)return i;const l=t.rowEnd-t.rowStart+1;return l%s!==0||(i.colEnd=t.colStart+a-1,i.rowEnd=t.rowStart+l-1),i};class $h{constructor(t,e){this._l=0,t&&e>0&&(this._u=t,this._l=e)}at(t){if(t>this._l||t<0||!this._u)return;const e=Math.floor(t%this._u.length);return this._u.at(e)}toArray(t){const e=[],n=this._u,r=n.length;for(let o=0;o<t;o++){const t=Math.floor(o%r);e.push(n.at(t))}return e}get length(){return this._l}get[Symbol.toStringTag](){return"[RepeatingList]"}get isIList(){return!0}}class Uh{constructor(t,e,n=null,r=!1){this._isLiteral=!1,this._values=t,this._coords=e,this._type=n,this._isLiteral=r}getValueAt(t,e,n){const r=this._coords;if(!r)return;let o=this._values.getValueAt(t+r.rowStart,e+r.colStart)??null;void 0===o&&(o=null);const s=n?.type,i=void 0!==s?s:this._type;return i&&(o=tu(o,Kh(o,!0),i)),o}_applyBuilder(t,e,n=!1){if(!e)return t;const r=e.build();return r?(n&&(t=t.clone()),t.setValues(r.tuples),t):t}_cloneFromBuilder(t,n,r,o){if(!t)return this;const s=t.build();if(!s)return this;let i=this._values;const a=i.getOrientation(),l=(n?.orientation??a)===e.Orientation.Column,c=Yc(s.bounds,l),h=this._coords??W.EmptyRange,u=Math.max(c.colEnd-c.colStart+1,r??h.colEnd-h.colStart+1),d=Math.max(c.rowEnd-c.rowStart+1,o??h.rowEnd-h.rowStart+1),g=h.colStart,m=h.rowStart,f=g+u-1,p=m+d-1;return i=i.clone(),i.setValues(s.tuples),new Uh(i,{colStart:g,rowStart:m,colEnd:f,rowEnd:p},this._type,this._isLiteral)}forEach(t,e){if(!t)return;const n=this.entries(e);let r=n.next();for(;!r.done;){const e=r.value,o=t(e.value,e.coords,this);if(o)return o.break;r=n.next()}}reduce(t,e,n){if(!t)return e;const r=this.entries(n);let o=r.next(),s=e;for(;!o.done;){const e=o.value;s=t(s,e.value,e.coords,this),o=r.next()}return s}some(t,e){if(!t)return!1;const n=this.entries(e);let r=n.next();for(;!r.done;){const e=r.value;if(t(e.value,e.coords,this))return!0;r=n.next()}return!1}every(t,e){if(!t)return!0;const n=this.entries(e);let r=n.next();for(;!r.done;){const e=r.value;if(!t(e.value,e.coords,this))return!1;r=n.next()}return!0}replace(t,e){let n;if(n=t?.isIRange?t:su(t,this._values,this._coords,this._type),0===this.size)return n;if(0===n.size)return this;const r=this._values.clone(),o=n._values,s=n._coords??W.EmptyRange,i=this._coords??W.EmptyRange,a=i.colStart,l=i.rowStart,c=a+(e.colIndex??0),h=l+(e.rowIndex??0);o.copyTo(r,{colIndex:c,rowIndex:h},s);const u=Math.max(this.getWidth(),n.getWidth()+(e?.colIndex??0)),d=Math.max(this.getHeight(),n.getHeight()+(e?.rowIndex??0));return new Uh(r,{colStart:a,rowStart:l,colEnd:a+u-1,rowEnd:l+ +d-1},this._type)}slice(t){if(!t)return this;const e=this._coords??W.EmptyRange,n=(t.colStart??0)+e.colStart,r=(t.rowStart??0)+e.rowStart,o={colStart:n,rowStart:r,colEnd:(t.colEnd??e.colEnd-n)+e.colStart,rowEnd:(t.rowEnd??e.rowEnd-r)+e.rowStart},s=W.intersectRanges(e,o);return new Uh(this._values,s,this._type)}resize(t,e,n=null){if(t<0||e<0)throw new Error(`Invalid resize dimensions: ${t} x ${e}`);const r=this._coords??W.EmptyRange,o=r.colEnd-r.colStart+1,s=r.rowEnd-r.rowStart+1;if(t===o&&e===s)return this;const i={colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colStart+t-1,rowEnd:r.rowStart+e-1};let a=this._values;return(t>o||e>s)&&(a=a.clone(),t>o&&(Gh.colStart=r.colEnd+1,Gh.rowStart=r.rowStart,Gh.colEnd=r.colEnd,Gh.rowEnd=r.rowEnd,this._fill(a,r,n)),e>s&&(Gh.colStart=r.colStart,Gh.rowStart=r.rowEnd+1,Gh.colEnd=r.colEnd,Gh.rowEnd=r.rowEnd,this._fill(a,r,n))),new Uh(a,i,this._type)}_mergeIterators(t,n,r){const o=this._coords??W.EmptyRange,s=t._coords??W.EmptyRange,i=this._values.getOrientation(),a=r?.orientation??i,l=a!==e.Orientation.Row,c=this._entries(r),h=this._entries(r),u=o.colStart,d=o.rowStart,g=u-s.colStart,m=d-s.rowStart,f=a===i?new Ke.Builder:new Ke.TransposedBuilder,p=new nh({...r,bounds:o,comparator:(l?jh:Hh)(o,s)},c,h);let _=p.next();for(;!_.done;){const t=_.value;let e=t[1],r=t[3];const o=t[0],s=t[2],i=o?o.colIndex:s.colIndex+g,a=o?o.rowIndex:s.rowIndex+m,c=n(e,r,{colIndex:i-u,rowIndex:a-d},this),h=l?i:a,S=l?a:i;f.addValue(h,S,c),_=p.next()}return f}intersect(t,e,n){if(!t)throw new Error("Invalid range to intersect");const r=t,o=this._coords??null,s=r._coords??null;if(!W.intersectRanges(o,s))return new Uh(this._values,null,this._type);const i=this._mergeIterators(r,e,n);return this._cloneFromBuilder(i,n)}startIncrementalUpdates(t){const n=t?.orientation??e.Orientation.Column,r=this._values.getOrientation(),o=(t?.orientation??r)!==e.Orientation.Row,s=n===r?new Ke.Builder:new Ke.TransposedBuilder,i=this,a=this._coords??W.EmptyRange,l=a.colStart,c=a.rowStart,h=o?l:c,u=o?c:l,d={pushAt(t,e,n){const r=o?e:t,i=o?t:e;return s.addValue(r+h,i+u,n),d},pushMultipleAt(t,e,n){const r=o?e:t,i=o?t:e;return s.addValues(r+h,i+u,n),d},apply(){const e=s.build();return e?(e.bounds.majorStart=h,e.bounds.minorStart=u,i._cloneFromBuilder(s,t)):null}};return d}map(t,n){const r=this._values;if(!this._coords||0===r.getCount())return this;const o=r.getOrientation(),s=n?.orientation??o;let i;const a=this.entries(n);let l=a.next();l.done||(i=this._createTupleBuilder(s));const c=s===e.Orientation.Column;for(;!l.done;){const e=l.value,n=e.coords,r=t(e.value,n,this),o=c?n.colIndex:n.rowIndex,s=c?n.rowIndex:n.colIndex;i.addValue(o,s,r),l=a.next()}return this._cloneFromBuilder(i,n)}filter(t,n){const r=this._values;if(!this._coords||0===r.getCount())return this;const o=r.getOrientation(),s=n?.orientation??o,i=this._createTupleBuilder(s),a=this.entries(n);let l=a.next();const c=s===e.Orientation.Column;for(;!l.done;){const e=l.value,n=e.coords,r=e.value;if(t(r,n,this)){const t=c?n.colIndex:n.rowIndex,e=c?n.rowIndex:n.colIndex;i.addValue(t,e,r)}l=a.next()}return this._cloneFromBuilder(i,n)}broadcast(n,o,s){let i=this._coords;if(null==n)return this;let a=s?.type,l=s?.otherType??a;const c=a?tu(null,t.Null,a):null,h=l?tu(null,t.Null,l):null;let u;if(n.isIRange)u=n;else{const t=this._values.clone();t.setValueAt(0,0,n),u=new Uh(t,W.EmptyRange,Kh(n,!0))}const d=u,g=this.getWidth(),m=this.getHeight(),f=d.getWidth(),p=d.getHeight();let _=Math.min(g,f),S=Math.min(m,p),w=Math.max(g,f),y=Math.max(m,p);const E=s?.mismatchFill;let b=!1;if(g!==f)if(1===g)_=f;else if(1===f)_=g;else{if(!E)throw new Error(`Incompatible shapes for broadcast: width dimensions ${g} and ${f} must be equal or one must be 1`);b=!0}if(m!==p)if(1===m)S=p;else if(1===p)S=m;else{if(!E)throw new Error(`Incompatible shapes for broadcast: height dimensions ${m} and ${p} must be equal or one must be 1`);b=!0}const v=this._values.getOrientation(),C=v,x=C===e.Orientation.Column;i=i??W.EmptyRange;let I,A,R=d._coords??W.EmptyRange;if(b&&(i={colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colStart+_-1,rowEnd:i.rowStart+_-1},R={colStart:R.colStart,rowStart:R.rowStart,colEnd:R.colStart+_-1,rowEnd:R.rowStart+_-1}),1===g&&g<f||1===m&&m<p){const t={...i};1===g&&(t.colEnd=t.colStart),1===m&&(t.rowEnd=t.rowStart),I=new eh({delegate:this._entries({...s,orientation:C,bounds:t,reuseResult:!1}),bounds:t,orientation:C,dims:{major:x?_:S,minor:x?S:_}})}else I=this._entries({...s,orientation:C,bounds:i,reuseResult:!1});if(1===f&&f<g||1===p&&p<m){const t={...R};1===f&&(t.colEnd=t.colStart),1===p&&(t.rowEnd=t.rowStart),A=new eh({delegate:d._entries({...s,type:l??null,orientation:C,bounds:t,reuseResult:!1}),bounds:t,orientation:C,dims:{major:x?_:S,minor:x?S:_}})}else A=d._entries({...s,type:l??null,orientation:C,bounds:R,reuseResult:!1});const M=i.colStart,T=i.rowStart,N=M-R.colStart,F=T-R.rowStart,k=C===v?new Ke.Builder:new Ke.TransposedBuilder,O=new nh({...s,bounds:i,comparator:(x?jh:Hh)(i,R)},I,A);let L,D=O.next();for(;!D.done;){const t=D.value;let e=t[1],n=t[3];const s=t[0],i=t[2],a=s?s.colIndex:i.colIndex+N,l=s?s.rowIndex:i.rowIndex+F;let u,d;e instanceof r.Value?u=e:n instanceof r.Value&&(u=n),d=u||o(e??c,n??h,{colIndex:a-M,rowIndex:l-T},this);const g=x?a:l,m=x?l:a;k.addValue(g,m,d),D=O.next()}if(E&&w>_||y>S){const t=this._values.clone();if(this._applyBuilder(t,k),w>_){const e=Kc(M+_,T,M+w-1,T+y-1,x),n=oh(E,e,x);t.setValues(n.tuples)}if(y>S){const e=Kc(M,T+S,M+w-1,T+y-1,x),n=oh(E,e,x);t.setValues(n.tuples)}L=new Uh(t,{colStart:M,rowStart:T,colEnd:M+w-1,rowEnd:T+y-1},this._type)}else L=this._cloneFromBuilder(k,s,w,y);return L}_fill(t,n,r){if(null===r)return void t.delete(n);const o=t.getOrientation()===e.Orientation.Column,s=Kc(n.colStart,n.rowStart,n.colEnd,n.rowEnd,o),i=oh(r,s,o);t.setValues(i.tuples)}_validateCoords(t){}fill(t,e){let n=this._coords;if(!n&&!e)return this;n=n??W.EmptyRange,e&&(Gh.colStart=(e.colStart??0)+n.colStart,Gh.rowStart=(e.rowStart??0)+n.rowStart,Gh.colEnd=(e.colEnd??n.colEnd-n.colStart)+n.colStart,Gh.rowEnd=(e.rowEnd??n.rowEnd-n.rowStart)+n.rowStart),this._validateCoords(Gh);const r=this._values.clone();return this._fill(r,Gh,t),(Gh.rowEnd>n.rowEnd||Gh.colEnd>n.colEnd)&&(n={colStart:n.colStart,rowStart:n.rowStart,colEnd:Math.max(n.colEnd,Gh.colEnd),rowEnd:Math.max(n.rowEnd,Gh.rowEnd)}),new Uh(r,n,this._type)}empty(){const t=this._values.cloneEmpty();return new Uh(t,null,this._type)}flatten(t){const e=[],n=this.values(t);let r=n.next();for(;!r.done;)e.push(r.value),r=n.next();return e}fillEmpty(t,n=1,r=1){const o=this._coords;if(!o)return this;const s=this._values;if(n<1&&r<1)throw new Error("Must be at least size of 1");const i=s.getOrientation(),a=i,l=a===e.Orientation.Column,c=Math.max(this.getWidth(),n),h=Math.max(this.getHeight(),r),u=l?o.colStart:o.rowStart,d=l?o.rowStart:o.colStart,g=l?o.colStart+c-1:o.rowStart+h-1,m=l?o.rowStart+h-1:o.colStart+c-1,f=s.getRuns({bounds:{colStart:o.colStart,rowStart:o.rowStart,colEnd:l?g:m,rowEnd:l?m:g},overflowRun:!0});let p=f.next(),_=u,S=d;const w=a===i?new Ke.Builder:new Ke.TransposedBuilder;for(;!p.done;){const e=p.value,n=e[0];for(;_<n;){const e=new $h([t],m+1-S);w.addValues(_,S,e),_++,S=d}const r=e[1],o=Math.max(r,d),s=e[2],i=Math.min(r+s.length-1,m);if(S<o){const e=new $h([t],r-S);w.addValues(_,S,e)}S=i+1,i>=m?(_=n+1,S=d):_=n,p=f.next()}for(;_<=g;){const e=new $h([t],m+1-S);w.addValues(_,S,e),_++,S=d}return this._cloneFromBuilder(w,void 0,c,h)}transpose(){if(this.size<=1)return this;const t=this._values.getOrientation(),n=this._coords,r=this.getWidth(),o=this.getHeight(),s=this._entries({orientation:t===e.Orientation.Column?e.Orientation.Row:e.Orientation.Column,bounds:n,reuseResult:!0}),i=t===e.Orientation.Column,a=new Ke.Builder,l=i?n.colStart:n.rowStart,c=i?n.rowStart:n.colStart;let h=s.next();for(;!h.done;){const t=h.value,e=t[0],n=i?e.colIndex:e.rowIndex-l,r=(i?e.rowIndex:e.colIndex-c)+l,o=n+c,u=t[1];a.addValue(r,o,u),h=s.next()}return this._cloneFromBuilder(a,void 0,o,r)}values(t){const e=this.entries(t);return{[Symbol.iterator](){return this},next(){const t=e.next();return t.done?Ul:{done:!1,value:t.value.value}}}}_createTupleBuilder(t){const n=this._coords,r=this._values.getOrientation(),o=t??r,s=o!==e.Orientation.Row,i=s?n.colStart:n.rowStart,a=s?n.rowStart:n.colStart;return o===r?new Ke.Builder(null,i,a):new Ke.TransposedBuilder(null,i,a)}entries(t){const e=this._coords;if(!e)return Gl;const n=t?.bounds;if(t={...t,bounds:e},n){const r=(n.colStart??0)-e.colStart,o=(n.rowStart??0)-e.rowStart,s=Math.max(r+e.colStart,e.colStart),i=Math.max(o+e.rowStart,e.rowStart),a=Math.min((n.colEnd??Number.MAX_SAFE_INTEGER)-r,e.colEnd-e.colStart)+1,l=Math.min((n.rowEnd??Number.MAX_SAFE_INTEGER)-o,e.rowEnd-e.rowStart)+1;t.bounds={colStart:s,rowStart:i,colEnd:s+a-1,rowEnd:i+l-1}}const r=this._entries(t),o={[Symbol.iterator]:()=>o,next(){for(;;){let t=r.next();if(t.done)return Ul;const n=t.value,o=n[0];return{done:!1,value:{coords:{colIndex:o.colIndex-e.colStart,rowIndex:o.rowIndex-e.rowStart},value:n[1]}}}}};return o}_entries(e){if(!this._coords)return Gl;let n=this._values.entries(e);const r=e?.type??this._type;let o=null;if(e?.includeEmpty&&(n=new th(n,e),r&&(o=tu(null,t.Null,r))),r){const t=n,s=e.coerce??!1,i=e.includeBoolean??!1,a=e.includeMistyped??!1;n={[Symbol.iterator]:()=>n,next(){for(;;){let e=t.next();if(e.done)return Ul;const n=e.value,l=n[1];let c=l;if(null==c)c=o;else if(r&&(s||!a)){let t=Kh(c,!0),e=t!==r;if(e&&(s&&(c=tu(c,t,r,i),e=c?.isFormulaError),e&&!a))continue}return c===l?e:{done:!1,value:[n[0],c]}}}}}return n}getValues(t){if(!this._coords)return[[]];const n={...t,includeEmpty:!0,reverse:!1,bounds:{colStart:0,rowStart:0,colEnd:this.getWidth()-1,rowEnd:this.getHeight()-1}};let r=!1;n.orientation=t?.orientation??e.Orientation.Row,t&&(t.maxHeight&&(n.bounds.rowEnd=0+t.maxHeight-1),t.maxWidth&&(n.bounds.colEnd=0+t.maxWidth-1),t.trailingEmpties&&(r=t.trailingEmpties),n.orientation=t?.orientation??e.Orientation.Row);const o=[];if(!r){n.includeEmpty=!1,n.reverse=!0;const t=this.entries(n).next();if(t.done)return Wh;const e=t.value.coords;n.bounds.colEnd=e.colIndex,n.bounds.rowEnd=e.rowIndex,n.includeEmpty=!0,n.reverse=!1}const s=this.entries(n),i=n.orientation!==e.Orientation.Row,a=t?.onValue;let l,c=-1,h=[];for(l=s.next();!l.done;){const t=l.value,e=t.coords,n=i?e.colIndex:e.rowIndex;n!==c&&(h=[],o.push(h),c=n);let r=t.value;if(a){const t=a(r,e.rowIndex,e.colIndex,this);void 0!==t&&(r=t)}h.push(r),l=s.next()}return o}toType(t){return new Uh(this._values,this._coords,t,this._isLiteral)}getWidth(){const t=this._coords;return t?t.colEnd-t.colStart+1:0}getHeight(){const t=this._coords;return t?t.rowEnd-t.rowStart+1:0}get size(){const t=this._coords;return t?(t.colEnd-t.colStart+1)*(t.rowEnd-t.rowStart+1):0}isLiteral(){return this._isLiteral}getScalarType(){return this._type}[Symbol.iterator](){const t=this.entries();return{next(){const e=t.next();return e.done?Ul:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}get[Symbol.toStringTag](){return"[Range]"}toString(){const t=this._coords,n=t?`${t.colEnd-t.colStart+1}x${t.rowEnd-t.rowStart+1}`:r.Ref.toString();let o="{";const s=this.entries({includeEmpty:!0,orientation:e.Orientation.Row});let i=s.next(),a=0,l=i.value?.coords.rowIndex??0;for(;!i.done&&a<10;){const t=i.value;t.coords.rowIndex>l?(o+=";",l=t.coords.rowIndex):a>0&&(o+=","),a++;let e=t.value;"string"==typeof e?e=`"${e}"`:"boolean"==typeof e&&(e=e?"TRUE":"FALSE"),o+=e,i=s.next()}return i.done?o+="}":o+="...",`[${n}:${o}]`}get isIRange(){return!0}}const Gh={colStart:Number.MIN_SAFE_INTEGER,rowStart:Number.MIN_SAFE_INTEGER,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER},Wh=Object.freeze([Object.freeze([null])]),qh=Object.freeze({colStart:0,rowStart:0,colEnd:Math.pow(2,14)-1,rowEnd:Math.pow(2,20)-1}),Jh=Object.freeze({colIndex:0,rowIndex:0}),Xh=()=>qh,Kh=(e,n=!1)=>"number"==typeof e?isNaN(e)||e===1/0||e===-1/0?t.Error:t.Number:"string"==typeof e?t.String:"boolean"==typeof e?t.Boolean:e?.isFormulaError?t.Error:null===e?t.Null:_t.isObject(e)&&e.hasOwnProperty("type")&&"string"==typeof e.type?t.RichData:n&&ms(e)?"Date":void 0===e?(console.warn("undefined"),t.Null):null,Yh=new Map([[t.Null,"any"],[t.Number,"number"],[t.String,"string"],[t.Boolean,"boolean"],[t.Error,"FormulaError"],[t.RichData,"richData"],["*","Scalar"]]),Zh=new Map([["p","IReferenceRange"],["r","IRange"]]),Qh={orientation:e.Orientation.Row},tu=(e,n,o=t.Number,s=!1,i=!1)=>{if(n===o||!o)return n===t.Number&&(e=ou(e,null,"number")),e;if(o===t.Number){switch(n){case t.Null:return 0;case t.String:let n=0;try{const t=Uf(e);n=t&&"number"==typeof t.value?t.value:Number.NaN}catch(t){}return!Number.isFinite(n)||Math.abs(n)>999e305?r.BuiltIn.Value:n;case t.Boolean:return s?e?1:0:r.BuiltIn.Value;case"Date":return Es(e,i)??r.BuiltIn.Value;case t.Error:return e}return e.toString()}if(o===t.String){switch(n){case t.Null:return"";case t.Number:return e.toString();case t.Boolean:return e?"TRUE":"FALSE";case t.Error:return e}return e}if(o===t.Boolean){switch(n){case t.Null:return 0;case t.Number:return!!e;case t.String:let n=e.trim().toUpperCase();return"TRUE"===n||"FALSE"!==n&&r.BuiltIn.Value;case t.Error:return e}return r.BuiltIn.Value}if("Date"===o){switch(n){case t.Number:return ys(e,i)??r.BuiltIn.Value;case t.String:try{const t=ks(e,i);if(t)return t.asJSDate??r.BuiltIn.Value}catch(t){}return e;case t.Error:return e}return r.BuiltIn.Value}return r.BuiltIn.Value},eu=t=>{let e=t;for(;Array.isArray(e);){if(e.length>1)return!1;e=e[0]}return!e||(!e.isIRange||1===e.size)},nu=(t,e,n,o,s,i=!1)=>{if(Array.isArray(n)){const a=n.length;for(let l=0;l<a;l++){let a=n[l];if(Array.isArray(a)){const n=nu(t,e,a,o,s,i);if(i)continue;if(n instanceof r.Value)return n}else{if(o){if(a=tu(a,Kh(a,!0),o,i),i)continue;if(a instanceof r.Value)return a}e.push(a)}}return}if(n&&void 0!==n.colStart){let e=t.getReference?.(n);o&&(e=e.toType(o)),n=e}if(n?.isIRange){return((t,e)=>{let n=t.next();for(;!n.done;){let o=n.value;if(o instanceof r.Value)return o;e.push(o),n=t.next()}})(n.values({type:o,coerce:!0,includeMistyped:!i,...Qh}),e)}if(o){if(n=tu(n,Kh(n,!0),o,null!==s),i)return;if(n instanceof r.Value)return n}e.push(n)},ru=(e,n,o,s,i,a)=>{if("r"===i){let t=o;return t&&t.isIReferenceRange?(s&&(t=t.toType(s)),void n.push(o)):new r.Value("Cannot convert a literal to a reference.")}let l=o?.isIRange?o:null;if("l"!==i){if(l){const t=l.getValues({type:s});return void n.push(t)}{Array.isArray(o)||(o=[o]);const t=o.length,e=new Array(t);for(let n=0;n<t;n++){let t=o[n];Array.isArray(t)||(t=[t]);const i=t.length,a=new Array(i);for(let e=0;e<i;e++){let n=t[e];if(s&&(n=tu(n,Kh(n,!0),s)),n instanceof r.Value)return n;a[e]=n}e[n]=a}n.push(e)}}else{if(l)s&&l.getScalarType()!==s&&(l=l.toType(s));else try{if(!a&&(o=ou(o),s&&(o=tu(o,Kh(o,!0),s,!0),o?.isFormulaError&&s!==t.Error)))return n.push(o),o;l=e.getRange(o),s&&(l=l.toType(s))}catch(t){return t}n.push(l)}},ou=(t,e,n=typeof t)=>{if("number"===n)return isNaN(t)?r.BuiltIn.Num:isFinite(t)?t+=0:r.BuiltIn.Div0;if(null==t)return null;if(!e)return t;if(Array.isArray(t))try{t=e.getRange(t)}catch(t){return r.BuiltIn.Value}return e.isValidDate(t)?(e.formatResults("Short Date"),e.toOADate(t)):t},su=(t,n,r,o)=>{let s;s=Array.isArray(t)?Array.isArray(t[0])?t:[t]:[[t]],n||(n=new hh({orientation:e.Orientation.Column}));const i=n.getOrientation()===e.Orientation.Column,a=sh(s,i,Kc(r?.colStart??0,r?.rowStart??0,void 0,void 0,i),!0),l=Yc(a.bounds,i);n.setValues(a.tuples);return new Uh(n,l,o,!r)},iu=new RegExp(/^([$]?[a-zA-Z]*[$]?[0-9]*)[:]?([$]?[a-zA-Z]*[$]?[0-9]*)?$/),au=new RegExp(/^(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?)(:(R(?:\[?[-+]?\d+\]?|\d+)?C(?:\[?[-+]?\d+\]?|\d+)?))?$/,"i"),lu=new RegExp(/^(R?)(\[?[-+]?\d+\]?|\d+)?(C?)(\[?[-+]?\d+\]?|\d+)?$/,"i"),cu=new RegExp("(?:'[^']+'|[A-Za-z0-9_\\-.]+?!)?(\\$?[A-Za-z]+\\$?\\d+(?::\\$?[A-Za-z]+\\$?\\d+)?|\\$?[A-Za-z]+:\\$?[A-Za-z]+|\\$?\\d+:\\$?\\d+)","g"),hu=/\s+/g,uu=/"(?:[^"]|"")*"|\[[^[\]]+\]/g,du=/[\uE000-\uF8FF]/g,gu="#REF!",mu=Math.pow(2,14),fu=Math.pow(2,20);let pu,_u;const Su=t=>(pu===t||(_u=""+(t+1),pu=t),_u);let wu,yu;const Eu=t=>{if(wu===t)return yu;if(wu=t,t<0)throw new Error("invalid column "+t);let e="";for(++t;t;t=Math.floor((t-1)/26))e=String.fromCharCode((t-1)%26+65)+e;return yu=e,yu},bu=/[^a-zA-Z0-9]/,vu=t=>{if(!t)return null;return Eu(t.colIndex)+Su(t.rowIndex)},Cu=t=>{if(!t)return gu;const e=Eu(t.colIndex),n=Su(t.rowIndex);return(t.$colIndex?"$"+e:e)+(t.$rowIndex?"$"+n:n)},xu=(t,e)=>{let n=t??e;var r;return n&&(n=Ks(n),n=n.replace(/'/g,"''"),r=n,bu.test(r)&&(n=Ys(n))),n},Iu=(t,e)=>t?t+(t.endsWith("!")?"":"!")+e:gu,Au=(t,e,n=vu)=>{if(!t)return null;const r=t.colStart,o=t.rowStart,s=t.colEnd,i=t.rowEnd;if(r===s&&o===i)return n({colIndex:r,rowIndex:o});t={...e,...t};const a=r===Number.MIN_SAFE_INTEGER||e&&r<=e.colStart&&s>=e.colEnd,l=o===Number.MIN_SAFE_INTEGER||e&&o<=e.rowStart&&i>=e.rowEnd;let c=null;c=l?Eu(r):a?Su(o):n({colIndex:r,rowIndex:o});let h=null;return h=l?Eu(s):a?Su(i):n({colIndex:s,rowIndex:i}),c+":"+h},Ru=(t,e,n=Cu)=>{if(!t)return gu;const r=t.colIndex,o=t.rowIndex,s=r===Number.MIN_SAFE_INTEGER;let i=null;if(o===Number.MIN_SAFE_INTEGER?(i=Eu(r),t.$colIndex&&(i="$"+i)):s?(i=Su(o),t.$rowIndex&&(i="$"+i)):i=n(t),t.sheetName||e){const n=xu(t.sheetName,e);i=Iu(n,i)}return i},Mu=(t,e,n=Cu)=>{if(!t)return gu;const r=void 0!==t.rowStart&&t.rowStart===t.rowEnd;if(void 0!==t.colStart&&t.colStart===t.colEnd&&r)return n({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart});t={...e,...t};const o=e&&t.rowStart<=e.rowStart&&t.rowEnd>=e.rowEnd,s=e&&t.colStart<=e.colStart&&t.colEnd>=e.colEnd;let i=null;o?(i=Eu(t.colStart),i=t.$colStart?"$"+i:i):s?(i=Su(t.rowStart),i=t.$rowStart?"$"+i:i):i=n({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart});let a=null;return o?(a=Eu(t.colEnd),a=t.$colEnd?"$"+a:a):s?(a=Su(t.rowEnd),a=t.$rowEnd?"$"+a:a):a=n({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd}),i+":"+a},Tu=(t,e,n=Cu)=>{const r=Mu(t,e,n),o=xu(t?.sheetName,e?.sheetName);return Iu(o,r)},Nu=(t,e=!1)=>{if(!t)return null;let n=0,r=0,o=!1,s=!1;const i=t.length;for(let a=0;a<i;++a){const i=t.charCodeAt(a);if(i>=48&&i<=57){if(r=10*r+(i-48),0===n&&!e)return}else if(i>=65&&i<=90){if(n=26*n+(i-64),0!==r)return}else if(i>=97&&i<=122){if(n=26*n+(i-96),0!==r)return}else{if(36!==i)return;if(0!==n||o){if(0!==r||s)return;s=!0}else o=!0}}const a={};return e||0!==r&&0!==n?(n>0&&(a.colIndex=n-1,o&&(a.$colIndex=o)),r>0&&(a.rowIndex=r-1,(s||e&&o)&&(a.$rowIndex=s||e&&o)),a):null},Fu=(t,e=qh,n=!1)=>{if(!t)return null;let r=t.toUpperCase();const o=$u(r,n);let s=null,i=null;if(o?.[1]){const t=!!o[2],e=n?Pu:Nu;s=e(o[1],t),i=e(o[2]??o[1],t)}if(!s&&!i)return null;if(s&&i){if(void 0===s.rowIndex&&void 0!==i.rowIndex||void 0!==s.rowIndex&&void 0===i.rowIndex)return null;if(void 0===s.colIndex&&void 0!==i.colIndex||void 0!==s.colIndex&&void 0===i.colIndex)return null}const a={};return s&&(void 0!==s.colIndex&&(a.colStart=s.colIndex),void 0!==s.rowIndex&&(a.rowStart=s.rowIndex),void 0!==s.$colIndex&&(a.$colStart=s.$colIndex),void 0!==s.$rowIndex&&(a.$rowStart=s.$rowIndex),void 0!==a?.colStart&&a?.colStart>e?.colEnd)?null:(i&&(void 0!==i.colIndex&&(a.colEnd=i.colIndex),void 0!==i.rowIndex&&(a.rowEnd=i.rowIndex),void 0!==i.$colIndex&&(a.$colEnd=i.$colIndex),void 0!==i.$rowIndex&&(a.$rowEnd=i.$rowIndex)),{...e,...a})},ku=(t,e,n=!1)=>{const r=(t=>{const e=t.lastIndexOf("!");if(-1===e)return null;let n=t.slice(0,e);return n=Ks(n),n=n.replace(/''/g,"'"),[n,t.slice(e+1)]})(t);let o;if(r){if(o=Fu(r[1],e,n),!o)return null;o.sheetName=r[0]}else o=Fu(t,e,n);return o||null},Ou=(t,e,n=Mu,r=Cu)=>{if(!t||0===t.length)return null;const o=[],s=t.length;for(let i=0;i<s;i++){const s=t[i];let a=null;s?void 0!==s.rowIndex||void 0!==s.colIndex?a=r(s):void 0!==s.rowStart||void 0!==s.colStart?a=n(s,e,r):"string"==typeof s&&(a=s):a=gu,a&&o.push(a)}return o},Lu=(t,e,n=Tu,r=Cu)=>{const o=Ou(t,e,n,r);return o?o.join(","):gu},Du=(t,e,n,r=ku,o,s=!1)=>{if(null!==e){if("string"==typeof e){const i=r(e,n,s);if(!i){const i=o?.(e);if(i){const e=i.length;for(let a=0;a<e;a++){const e=i[a];Du(t,e,n,r,o,s)}}return}e=i}else e.isICellRange?e=e.getCoords():e.isICell&&(e=W.cellToRange(e.getCoords()));if(null!==e){if(void 0!==e.rowStart||void 0!==e.colStart||void 0!==e.colEnd||void 0!==e.rowEnd){const r=e;t.push({...n,...r})}else if(void 0!==e.rowIndex||void 0!==e.colIndex){const r=e,o={...n,...r,colStart:r.colIndex,rowStart:r.rowIndex,colEnd:r.colIndex,rowEnd:r.rowIndex};null===o.sheetName&&n.sheetName&&(o.sheetName=n.sheetName),delete o.colIndex,delete o.rowIndex,t.push(o)}}else t.push(null)}else t.push(null)},Bu=(t,e,n=ku,r,o=!1)=>{if(!t)return[e];let s;s="string"==typeof t?Zs(t):t.isICellRanges?t.getCoords():Array.isArray(t)?t:[t];const i=[],a=s.length;for(let t=0;t<a;t++){const a=s[t];Du(i,a,e,n,r,o)}return i},zu=(t,e)=>{let n=0,r=0;const o=t.length;for(let e=0;e<o;++e){const o=t.charCodeAt(e);if(o>=48&&o<=57){if(n=10*n+(o-48),0===r)return}else if(o>=65&&o<=90){if(r=26*r+(o-64),0!==n)return}else{if(!(o>=97&&o<=122))return;if(r=26*r+(o-96),0!==n)return}}return e?(e.colIndex=r-1,e.rowIndex=n-1,e):{colIndex:r-1,rowIndex:n-1}},Pu=(t,e=!1,n)=>{n?(n.colIndex=Number.MIN_SAFE_INTEGER,n.rowIndex=Number.MIN_SAFE_INTEGER,n.$colIndex=!1,n.$rowIndex=!1):n={colIndex:Number.MIN_SAFE_INTEGER,rowIndex:Number.MIN_SAFE_INTEGER,$colIndex:!1,$rowIndex:!1};const r=lu.exec(t);if(!r)return null;const o=r[1],s=r[3];if(!(e||o&&s))return null;if(o){const t=r[2];t?t&&(t.startsWith("[")?(n.rowIndex=parseInt(t.slice(1,-1)),n.$rowIndex=!1):(n.rowIndex=parseInt(t)-1,n.$rowIndex=!0)):(n.rowIndex=0,n.$rowIndex=!1)}if(s){const t=r[4];t?t.startsWith("[")?(n.colIndex=parseInt(t.slice(1,-1)),n.$colIndex=!1):(n.colIndex=parseInt(t)-1,n.$colIndex=!0):(n.colIndex=0,n.$colIndex=!1)}return n},ju=(t,e)=>{let n=0,r=0,o=!1,s=!1;const i=t.length;for(let e=0;e<i;++e){const i=t.charCodeAt(e);i>=48&&i<=57?n=10*n+(i-48):i>=65&&i<=90?r=26*r+(i-64):i>=97&&i<=122?r=26*r+(i-96):36===i&&(0===e?o=!0:s=!0)}return r--,n--,e.colIndex=r,e.rowIndex=n,-1===n?(e.$colIndex=o,e.$rowIndex=!1,e):-1===r?(e.$colIndex=!1,e.$rowIndex=o,e):(e.$colIndex=o,e.$rowIndex=s,e)},Hu=t=>{let e=0;const n=t.length;for(let r=0;r<n;++r){const n=t.charCodeAt(r);if(n>=65&&n<=90)e=26*e+(n-64);else{if(!(n>=97&&n<=122))return e-1;e=26*e+(n-96)}}return e-1},Vu=(t,e)=>{let n=e;n?(n.rowStart=0,n.colStart=0,n.rowEnd=0,n.colEnd=0):n={rowStart:0,colStart:0,rowEnd:0,colEnd:0};let r=0,o=0,s=0,i=t.length;for(r=0;o<i&&(s=t.charCodeAt(o),s>96&&s<123&&(s-=32),!(s<65||s>91));++o)r=26*r+(s-64);for(n.colStart=--r,r=0;o<i;++o){let e=t.charCodeAt(o)-48;if(e<0||e>9)break;r=10*r+e}if(n.rowStart=--r,o===i||58===t.charCodeAt(++o))return n.colEnd=n.colStart,n.rowEnd=n.rowStart,n;for(r=0;o!==i&&(s=t.charCodeAt(o),s>96&&s<123&&(s-=32),!(s<65||s>91));++o)r=26*r+(s-64);for(n.colEnd=--r,r=0;o!==i;++o){let e=t.charCodeAt(o)-48;if(e<0||e>9)break;r=10*r+e}return n.rowEnd=--r,n},$u=(t,e=!1)=>{const n=t.match(e?au:iu);return t.endsWith(":")?null:n},Uu={rowIndex:-1,colIndex:-1,$colIndex:!1,$rowIndex:!1},Gu=(t,e,n,r=mu)=>{let o=t.lastIndexOf("!"),s="";-1!==o&&(s=t.slice(0,o)+"!",t=t.slice(o+1));let i=null;const a=()=>{let t="";const r=i.rowIndex;if(-1!==r)if(i.$rowIndex)t+=`R${r+1}`;else{const n=r-e;t+=0===n?"R":`R[${n}]`}let o="";const a=i.colIndex;if(-1!==a)if(i.$colIndex)o+=`C${a+1}`;else{const t=a-n;o+=0===t?"C":`C[${t}]`}s+=t+o};o=t.lastIndexOf(":");const l=-1!==o;if(l){const e=t.slice(0,o);t=t.slice(o+1),i=ju(e,Uu),-1!==i.colIndex&&-1!==i.rowIndex&&(a(),s+=":")}return i=ju(t,Uu),!l&&i.colIndex>r?t:(a(),s)},Wu=[],qu=t=>(Wu.push(t),String.fromCharCode(57344+Wu.length-1)),Ju=t=>{const e=t.charCodeAt(0)-57344;return Wu[e]},Xu=(t,e,n)=>{let r="";const o=t.length;for(let s=0;s<o;s++){const o=t[s];r+="string"==typeof o?o:Yu(o,e,n)}return r},Ku=(t,e)=>{let n="";const r=t.rowIndex;r!==Number.MIN_SAFE_INTEGER&&(t.$rowIndex?n+=`R${r+1}`:n+=0===r?"R":`R[${r+1}]`);let o="";const s=t.colIndex;return s!==Number.MIN_SAFE_INTEGER&&(t.$colIndex?o+=`C${s+1}`:o+=0===s?"C":`C[${s+1}]`),t.sheetName&&(n=xu(t.sheetName,e)+"!"+n),n+o},Yu=(t,e,n)=>{let r="";const o=t.colIndex;o!==Number.MIN_SAFE_INTEGER&&(t.$colIndex?r+="$"+Eu(o):r+=Eu(o+n));const s=t.rowIndex;return s!==Number.MIN_SAFE_INTEGER&&(t.$rowIndex?r+="$"+Su(s):r+=Su(s+e)),r},Zu=(t,e,n,r)=>{let o=t.colStart,s=t.rowStart,i=t.colEnd,a=t.rowEnd;const l=t.$colStart??!1,c=t.$rowStart??!1,h=t.$colEnd??!1,u=t.$rowEnd??!1;if(l||o===Number.MIN_SAFE_INTEGER||(o+=n),c||s===Number.MIN_SAFE_INTEGER||(s+=e),h||i===Number.MAX_SAFE_INTEGER||(i+=n),u||a===Number.MAX_SAFE_INTEGER||(a+=e),o>i){const t=o;o=i,i=t}if(s>a){const t=s;s=a,a=t}let d;return r?(d=r,d.colStart=o,d.rowStart=s,d.colEnd=i,d.rowEnd=a,d.$colStart=l,d.$rowStart=c,d.$colEnd=h,d.$rowEnd=u):d={colStart:o,rowStart:s,colEnd:i,rowEnd:a,$colStart:l,$rowStart:c,$colEnd:h,$rowEnd:u},t.sheetName&&(d.sheetName=t.sheetName),d},Qu=(t,e,n,r)=>{Wu.length=0;let o=0,s=t.replace(uu,qu),i=0,a=s.replace(cu,(t,a,l)=>{const c=Gu(t,e,n);if(r){if(l>i){const t=s.slice(i,l).replace(du,(t,e)=>Wu[o++]);r.push(t)}const a=t.lastIndexOf(":");if(-1!==a){const o=t.slice(0,a),s=t.slice(a+1),i=Gu(o,e,n),l=Gu(s,e,n);r.push(Pu(i,!0)??i),r.push(":"),r.push(Pu(l,!0)??l)}else r.push(Pu(c,!0)??c)}return i=l+t.length,c});if(r&&i<s.length){const t=s.slice(i);r.push(t.replace(du,(t,e)=>Wu[o++]))}return a=a.toUpperCase().replace(hu,""),a.replace(du,Ju)},td="Must specify an address.",ed="Only a single range is allowed for this operation. Use 'getRanges' instead.",nd="Invalid range. The Range must be specified as '{ TOP_LEFT:BOTTOM_RIGHT }'.",rd=t=>`Invalid address. Can not parse ${"string"==typeof t?`'${t}' `:""}as an address or named item.`,od=()=>{throw new Error("Invalid range.")};class sd{constructor(t,e,n=!1){this._c=t,this._cycleId=e,this._e=n}getCycleId(){return this._cycleId}getError(){return this._e}getCoords(){return this._c}setError(t,e){const n=this._c;return{...n,value:new sd(n,e,t)}}getShifted(t){const e=t.after;if(!e)return null;const n=W.sanitizeRange(e);return{...n,value:new sd(n,this._cycleId,this._e)}}getMerged(t,e,n){}getSplit(t,e){}}class id{constructor(t,e){this._c=t,this._o=e}getCoords(){return this._c}getOrientation(){return this._o}getShifted(t){return t.after?{...t.after,value:new id(t.after,this._o)}:null}getMerged(t,e,n){const r=this._o;return new id(e,r)}getSplit(t,e){const n=this._o;return[new id(t[0],n),new id(t[1],n)]}getState(){return this._c}}const ad=(t,n)=>{if(!t||0===t.length)return _t.EmptyArray;const r=[],o=n?e.Orientation.Column:e.Orientation.Row;for(let e=0;e<t.length;e++){const s=t[e],i=s[0],a=s[1];for(let t=0;t<a.length;t++){const e=a[t],s=e[0],l=e[1].length-1,c={colStart:n?i:s,rowStart:n?s:i,colEnd:n?i:s+l,rowEnd:n?s+l:i,value:new id({colStart:n?i:s,rowStart:n?s:i,colEnd:n?i:s+l,rowEnd:n?s+l:i},o)};r.push(c)}}return r},ld=0,cd=1;class hd{constructor(t,e,n){this.ref=t,this.formula=e;const r=t.colStart,o=t.rowStart;if(n){const t=n,e=t.length;for(let n=0;n<e;n++){const e=[...t[n]];t[n]=e;const s=e.length;for(let t=0;t<s;t++){const s={...e[t]};e[t]=s,s.colIndex=t+r,s.rowIndex=n+o,s.block=this}}this.calcs=t}else{const n=e.getDirectPrecedentsAt(o,r),s=n?.length??0,i=new Array(t.rowEnd-o+1),a=t.colEnd-r+1,l=i.length;for(let t=0;t<l;t++){const e=new Array(a),n=e.length;for(let i=0;i<n;i++)e[i]={block:this,colIndex:i+r,rowIndex:t+o,cycleId:0,markId:0,inDegree:0,dependents:_t.EmptyArray,inputs:0===s?_t.EmptyArray:new Array(s),precedents:0===s?_t.EmptyArray:new Array(s),dynamic:null,cachedValue:void 0,removed:!1,pending:!1,pendingPrecedents:!1,pendingPromise:null,pendingResolved:!1,state:ld,error:void 0};i[t]=e}this.calcs=i}}toJSON(){const t=this.ref;return[Au(t),this.formula.getTextAt(t.rowStart,t.colStart)]}getCoords(){return this.ref}getShifted(t){if(!t.after)return null;const e=W.sanitizeRange(t.after),n=[...this.calcs],r=new hd(e,this.formula,n);return{...t.after,value:r}}setReferenceAt(t,e){const n=this.formula.setReferenceAt(t,e),r=[...this.calcs];return new hd(this.ref,n,r)}getMerged(t,n,r){const o=this.formula,s=t.formula;if(!o.isEquals(s))return;const i=this.calcs,a=t.calcs;let l;if(r===e.Orientation.Row)l=[...i,...a];else{const t=i.length;l=new Array(t);for(let e=0;e<t;e++)l[e]=[...i[e],...a[e]]}return new hd(n,o,l)}getSplit(t,n,r){const o=this.formula,s=n===e.Orientation.Column;let i,a;const l=this.calcs;if(s){const t=l.length;i=new Array(t),a=new Array(t);for(let e=0;e<t;e++){const t=l[e];i[e]=t.slice(0,r),a[e]=t.slice(r)}}else i=l.slice(0,r),a=l.slice(r);return[new hd(t[0],o,i),new hd(t[1],o,a)]}copyTo(t,e){const n=this.formula;return new hd(t,n)}canTile(t,e){return!0}onRemove(t){const e=t.value.calcs,n=e.length;for(let t=0;t<n;t++){const n=e[t],r=n.length;for(let t=0;t<r;t++){const e=n[t];e.pendingPromise&&(e.pendingPromise.cancelled=!0),e.removed=!0}}}}const ud=Object.freeze({break:!0});var dd;(dd||(dd={})).Type={Style:"style",Table:"table",Merge:"merge",Hyperlink:"hyperlink",Comments:"comments",Unlock:"unlock",Contentful:"contentful",Conditional:"conditional",Formula:"formula",Spill:"spill",Continuous:"continuous",Pending:"pending",CalcError:"calcError"};const gd=Object.freeze({[dd.Type.Style]:!1,[dd.Type.Table]:!1,[dd.Type.Merge]:!1,[dd.Type.Hyperlink]:!1,[dd.Type.Comments]:!1,[dd.Type.Unlock]:!1,[dd.Type.Formula]:!1,[dd.Type.Spill]:!1,[dd.Type.Pending]:!1,[dd.Type.CalcError]:!1,[dd.Type.Contentful]:!1,[dd.Type.Conditional]:!1,[dd.Type.Continuous]:!1}),md=Object.freeze({[dd.Type.Style]:!1,[dd.Type.Table]:!1,[dd.Type.Merge]:!1,[dd.Type.Hyperlink]:!1,[dd.Type.Comments]:!1,[dd.Type.Unlock]:!1,[dd.Type.Formula]:!1,[dd.Type.Spill]:!1,[dd.Type.Pending]:!1,[dd.Type.CalcError]:!1,[dd.Type.Conditional]:!1,[dd.Type.Continuous]:!1}),fd=Object.freeze({[dd.Type.Style]:!1,[dd.Type.Table]:!0,[dd.Type.Merge]:!1,[dd.Type.Hyperlink]:!1,[dd.Type.Comments]:!1,[dd.Type.Unlock]:!1,[dd.Type.Formula]:!1}),pd=Object.freeze({[dd.Type.Style]:!1,[dd.Type.Table]:!1,[dd.Type.Hyperlink]:!1,[dd.Type.Comments]:!1,[dd.Type.Unlock]:!1,[dd.Type.Contentful]:!1,[dd.Type.Formula]:!1}),_d="This sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.",Sd=(t="update")=>`Unable to ${t}, this sheet is protected. To make a change, unprotect the sheet. You might be requested to enter a password.`,wd="The range is outside of the bounds of the sheet.",yd="Listener can not be null",Ed="We can't insert items. The sheet is protected.",bd=t=>`We can't create a ${t} that overlaps with another table or merge.`,vd="Overlapping ranges can not be merged.",Cd="We can't insert cells because this would push values off the end of the worksheet. These cells may appear empty but they have some formatting or formulas. Delete enough rows or columns and try again.",xd="Unable to partially fill over merged cells.",Id="Unable to sort merged cells unless they are all the same size.",Ad="Sheet has been closed. No further operations are allowed.",Rd="IteratorContext can only be used during visit.",Md="When using addresses directly from the sheet do not include the sheet name.",Td=t=>`Unable to return more than ${t} values. To access values in a more scalable solution use 'ICellRange.forEach' or an iterator.`,Nd="Multiple selection ranges can not be copied.",Fd="Unable to determine source.",kd="When pasting before or after the cut area both areas must align.",Od="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,Ld=new Set,Dd="object"==typeof process&&process?process:{},Bd=(t,e,n,r)=>{"function"==typeof Dd.emitWarning?Dd.emitWarning(t,e,n,r):console.error(`[${n}] ${e}: ${t}`)};let zd=globalThis.AbortController,Pd=globalThis.AbortSignal;if(void 0===zd){Pd=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(t,e){this._onabort.push(e)}},zd=class{constructor(){e()}signal=new Pd;abort(t){if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);this.signal.onabort?.(t)}}};let t="1"!==Dd.env?.LRU_CACHE_IGNORE_AC_WARNING;const e=()=>{t&&(t=!1,Bd("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const jd=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),Hd=t=>jd(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?Vd:null:null;class Vd extends Array{constructor(t){super(t),this.fill(0)}}class $d{heap;length;static#t=!1;static create(t){const e=Hd(t);if(!e)return[];$d.#t=!0;const n=new $d(t,e);return $d.#t=!1,n}constructor(t,e){if(!$d.#t)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new e(t),this.length=0}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}}class Ud{#e;#n;#r;#o;#s;#i;#a;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#l;#c;#h;#u;#d;#g;#m;#f;#p;#_;#S;#w;#y;#E;#b;#v;#C;#x;static unsafeExposeInternals(t){return{starts:t.#y,ttls:t.#E,sizes:t.#w,keyMap:t.#h,keyList:t.#u,valList:t.#d,next:t.#g,prev:t.#m,get head(){return t.#f},get tail(){return t.#p},free:t.#_,isBackgroundFetch:e=>t.#I(e),backgroundFetch:(e,n,r,o)=>t.#A(e,n,r,o),moveToTail:e=>t.#R(e),indexes:e=>t.#M(e),rindexes:e=>t.#T(e),isStale:e=>t.#N(e)}}get max(){return this.#e}get maxSize(){return this.#n}get calculatedSize(){return this.#c}get size(){return this.#l}get fetchMethod(){return this.#i}get memoMethod(){return this.#a}get dispose(){return this.#r}get onInsert(){return this.#o}get disposeAfter(){return this.#s}constructor(t){const{max:e=0,ttl:n,ttlResolution:r=1,ttlAutopurge:o,updateAgeOnGet:s,updateAgeOnHas:i,allowStale:a,dispose:l,onInsert:c,disposeAfter:h,noDisposeOnSet:u,noUpdateTTL:d,maxSize:g=0,maxEntrySize:m=0,sizeCalculation:f,fetchMethod:p,memoMethod:_,noDeleteOnFetchRejection:S,noDeleteOnStaleGet:w,allowStaleOnFetchRejection:y,allowStaleOnFetchAbort:E,ignoreFetchAbort:b}=t;if(0!==e&&!jd(e))throw new TypeError("max option must be a nonnegative integer");const v=e?Hd(e):Array;if(!v)throw new Error("invalid max value: "+e);if(this.#e=e,this.#n=g,this.maxEntrySize=m||this.#n,this.sizeCalculation=f,this.sizeCalculation){if(!this.#n&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==_&&"function"!=typeof _)throw new TypeError("memoMethod must be a function if defined");if(this.#a=_,void 0!==p&&"function"!=typeof p)throw new TypeError("fetchMethod must be a function if specified");if(this.#i=p,this.#v=!!p,this.#h=new Map,this.#u=new Array(e).fill(void 0),this.#d=new Array(e).fill(void 0),this.#g=new v(e),this.#m=new v(e),this.#f=0,this.#p=0,this.#_=$d.create(e),this.#l=0,this.#c=0,"function"==typeof l&&(this.#r=l),"function"==typeof c&&(this.#o=c),"function"==typeof h?(this.#s=h,this.#S=[]):(this.#s=void 0,this.#S=void 0),this.#b=!!this.#r,this.#x=!!this.#o,this.#C=!!this.#s,this.noDisposeOnSet=!!u,this.noUpdateTTL=!!d,this.noDeleteOnFetchRejection=!!S,this.allowStaleOnFetchRejection=!!y,this.allowStaleOnFetchAbort=!!E,this.ignoreFetchAbort=!!b,0!==this.maxEntrySize){if(0!==this.#n&&!jd(this.#n))throw new TypeError("maxSize must be a positive integer if specified");if(!jd(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#F()}if(this.allowStale=!!a,this.noDeleteOnStaleGet=!!w,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!i,this.ttlResolution=jd(r)||0===r?r:1,this.ttlAutopurge=!!o,this.ttl=n||0,this.ttl){if(!jd(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#k()}if(0===this.#e&&0===this.ttl&&0===this.#n)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#n){const t="LRU_CACHE_UNBOUNDED";if((t=>!Ld.has(t))(t)){Ld.add(t);Bd("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,Ud)}}}getRemainingTTL(t){return this.#h.has(t)?1/0:0}#k(){const t=new Vd(this.#e),e=new Vd(this.#e);this.#E=t,this.#y=e,this.#O=(n,r,o=Od.now())=>{if(e[n]=0!==r?o:0,t[n]=r,0!==r&&this.ttlAutopurge){const t=setTimeout(()=>{this.#N(n)&&this.#L(this.#u[n],"expire")},r+1);t.unref&&t.unref()}},this.#D=n=>{e[n]=0!==t[n]?Od.now():0},this.#B=(o,s)=>{if(t[s]){const i=t[s],a=e[s];if(!i||!a)return;o.ttl=i,o.start=a,o.now=n||r();const l=o.now-a;o.remainingTTL=i-l}};let n=0;const r=()=>{const t=Od.now();if(this.ttlResolution>0){n=t;const e=setTimeout(()=>n=0,this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=o=>{const s=this.#h.get(o);if(void 0===s)return 0;const i=t[s],a=e[s];if(!i||!a)return 1/0;return i-((n||r())-a)},this.#N=o=>{const s=e[o],i=t[o];return!!i&&!!s&&(n||r())-s>i}}#D=()=>{};#B=()=>{};#O=()=>{};#N=()=>!1;#F(){const t=new Vd(this.#e);this.#c=0,this.#w=t,this.#z=e=>{this.#c-=t[e],t[e]=0},this.#P=(t,e,n,r)=>{if(this.#I(e))return 0;if(!jd(n)){if(!r)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof r)throw new TypeError("sizeCalculation must be a function");if(n=r(e,t),!jd(n))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return n},this.#j=(e,n,r)=>{if(t[e]=n,this.#n){const n=this.#n-t[e];for(;this.#c>n;)this.#H(!0)}this.#c+=t[e],r&&(r.entrySize=n,r.totalCalculatedSize=this.#c)}}#z=t=>{};#j=(t,e,n)=>{};#P=(t,e,n,r)=>{if(n||r)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#M({allowStale:t=this.allowStale}={}){if(this.#l)for(let e=this.#p;this.#V(e)&&(!t&&this.#N(e)||(yield e),e!==this.#f);)e=this.#m[e]}*#T({allowStale:t=this.allowStale}={}){if(this.#l)for(let e=this.#f;this.#V(e)&&(!t&&this.#N(e)||(yield e),e!==this.#p);)e=this.#g[e]}#V(t){return void 0!==t&&this.#h.get(this.#u[t])===t}*entries(){for(const t of this.#M())void 0===this.#d[t]||void 0===this.#u[t]||this.#I(this.#d[t])||(yield[this.#u[t],this.#d[t]])}*rentries(){for(const t of this.#T())void 0===this.#d[t]||void 0===this.#u[t]||this.#I(this.#d[t])||(yield[this.#u[t],this.#d[t]])}*keys(){for(const t of this.#M()){const e=this.#u[t];void 0===e||this.#I(this.#d[t])||(yield e)}}*rkeys(){for(const t of this.#T()){const e=this.#u[t];void 0===e||this.#I(this.#d[t])||(yield e)}}*values(){for(const t of this.#M()){void 0===this.#d[t]||this.#I(this.#d[t])||(yield this.#d[t])}}*rvalues(){for(const t of this.#T()){void 0===this.#d[t]||this.#I(this.#d[t])||(yield this.#d[t])}}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(t,e={}){for(const n of this.#M()){const r=this.#d[n],o=this.#I(r)?r.__staleWhileFetching:r;if(void 0!==o&&t(o,this.#u[n],this))return this.get(this.#u[n],e)}}forEach(t,e=this){for(const n of this.#M()){const r=this.#d[n],o=this.#I(r)?r.__staleWhileFetching:r;void 0!==o&&t.call(e,o,this.#u[n],this)}}rforEach(t,e=this){for(const n of this.#T()){const r=this.#d[n],o=this.#I(r)?r.__staleWhileFetching:r;void 0!==o&&t.call(e,o,this.#u[n],this)}}purgeStale(){let t=!1;for(const e of this.#T({allowStale:!0}))this.#N(e)&&(this.#L(this.#u[e],"expire"),t=!0);return t}info(t){const e=this.#h.get(t);if(void 0===e)return;const n=this.#d[e],r=this.#I(n)?n.__staleWhileFetching:n;if(void 0===r)return;const o={value:r};if(this.#E&&this.#y){const t=this.#E[e],n=this.#y[e];if(t&&n){const e=t-(Od.now()-n);o.ttl=e,o.start=Date.now()}}return this.#w&&(o.size=this.#w[e]),o}dump(){const t=[];for(const e of this.#M({allowStale:!0})){const n=this.#u[e],r=this.#d[e],o=this.#I(r)?r.__staleWhileFetching:r;if(void 0===o||void 0===n)continue;const s={value:o};if(this.#E&&this.#y){s.ttl=this.#E[e];const t=Od.now()-this.#y[e];s.start=Math.floor(Date.now()-t)}this.#w&&(s.size=this.#w[e]),t.unshift([n,s])}return t}load(t){this.clear();for(const[e,n]of t){if(n.start){const t=Date.now()-n.start;n.start=Od.now()-t}this.set(e,n.value,n)}}set(t,e,n={}){if(void 0===e)return this.delete(t),this;const{ttl:r=this.ttl,start:o,noDisposeOnSet:s=this.noDisposeOnSet,sizeCalculation:i=this.sizeCalculation,status:a}=n;let{noUpdateTTL:l=this.noUpdateTTL}=n;const c=this.#P(t,e,n.size||0,i);if(this.maxEntrySize&&c>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#L(t,"set"),this;let h=0===this.#l?void 0:this.#h.get(t);if(void 0===h)h=0===this.#l?this.#p:0!==this.#_.length?this.#_.pop():this.#l===this.#e?this.#H(!1):this.#l,this.#u[h]=t,this.#d[h]=e,this.#h.set(t,h),this.#g[this.#p]=h,this.#m[h]=this.#p,this.#p=h,this.#l++,this.#j(h,c,a),a&&(a.set="add"),l=!1,this.#x&&this.#o?.(e,t,"add");else{this.#R(h);const n=this.#d[h];if(e!==n){if(this.#v&&this.#I(n)){n.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=n;void 0===e||s||(this.#b&&this.#r?.(e,t,"set"),this.#C&&this.#S?.push([e,t,"set"]))}else s||(this.#b&&this.#r?.(n,t,"set"),this.#C&&this.#S?.push([n,t,"set"]));if(this.#z(h),this.#j(h,c,a),this.#d[h]=e,a){a.set="replace";const t=n&&this.#I(n)?n.__staleWhileFetching:n;void 0!==t&&(a.oldValue=t)}}else a&&(a.set="update");this.#x&&this.onInsert?.(e,t,e===n?"update":"replace")}if(0===r||this.#E||this.#k(),this.#E&&(l||this.#O(h,r,o),a&&this.#B(a,h)),!s&&this.#C&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}return this}pop(){try{for(;this.#l;){const t=this.#d[this.#f];if(this.#H(!0),this.#I(t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(this.#C&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}}}#H(t){const e=this.#f,n=this.#u[e],r=this.#d[e];return this.#v&&this.#I(r)?r.__abortController.abort(new Error("evicted")):(this.#b||this.#C)&&(this.#b&&this.#r?.(r,n,"evict"),this.#C&&this.#S?.push([r,n,"evict"])),this.#z(e),t&&(this.#u[e]=void 0,this.#d[e]=void 0,this.#_.push(e)),1===this.#l?(this.#f=this.#p=0,this.#_.length=0):this.#f=this.#g[e],this.#h.delete(n),this.#l--,e}has(t,e={}){const{updateAgeOnHas:n=this.updateAgeOnHas,status:r}=e,o=this.#h.get(t);if(void 0!==o){const t=this.#d[o];if(this.#I(t)&&void 0===t.__staleWhileFetching)return!1;if(!this.#N(o))return n&&this.#D(o),r&&(r.has="hit",this.#B(r,o)),!0;r&&(r.has="stale",this.#B(r,o))}else r&&(r.has="miss");return!1}peek(t,e={}){const{allowStale:n=this.allowStale}=e,r=this.#h.get(t);if(void 0===r||!n&&this.#N(r))return;const o=this.#d[r];return this.#I(o)?o.__staleWhileFetching:o}#A(t,e,n,r){const o=void 0===e?void 0:this.#d[e];if(this.#I(o))return o;const s=new zd,{signal:i}=n;i?.addEventListener("abort",()=>s.abort(i.reason),{signal:s.signal});const a={signal:s.signal,options:n,context:r},l=(r,o=!1)=>{const{aborted:i}=s.signal,l=n.ignoreFetchAbort&&void 0!==r;if(n.status&&(i&&!o?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,l&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),i&&!l&&!o)return c(s.signal.reason);const u=h;return this.#d[e]===h&&(void 0===r?u.__staleWhileFetching?this.#d[e]=u.__staleWhileFetching:this.#L(t,"fetch"):(n.status&&(n.status.fetchUpdated=!0),this.set(t,r,a.options))),r},c=r=>{const{aborted:o}=s.signal,i=o&&n.allowStaleOnFetchAbort,a=i||n.allowStaleOnFetchRejection,l=a||n.noDeleteOnFetchRejection,c=h;if(this.#d[e]===h){!l||void 0===c.__staleWhileFetching?this.#L(t,"fetch"):i||(this.#d[e]=c.__staleWhileFetching)}if(a)return n.status&&void 0!==c.__staleWhileFetching&&(n.status.returnedStale=!0),c.__staleWhileFetching;if(c.__returned===c)throw r};n.status&&(n.status.fetchDispatched=!0);const h=new Promise((e,r)=>{const i=this.#i?.(t,o,a);i&&i instanceof Promise&&i.then(t=>e(void 0===t?void 0:t),r),s.signal.addEventListener("abort",()=>{n.ignoreFetchAbort&&!n.allowStaleOnFetchAbort||(e(void 0),n.allowStaleOnFetchAbort&&(e=t=>l(t,!0)))})}).then(l,t=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=t),c(t))),u=Object.assign(h,{__abortController:s,__staleWhileFetching:o,__returned:void 0});return void 0===e?(this.set(t,u,{...a.options,status:void 0}),e=this.#h.get(t)):this.#d[e]=u,u}#I(t){if(!this.#v)return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof zd}async fetch(t,e={}){const{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:i=this.noDisposeOnSet,size:a=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:h=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:u=this.allowStaleOnFetchRejection,ignoreFetchAbort:d=this.ignoreFetchAbort,allowStaleOnFetchAbort:g=this.allowStaleOnFetchAbort,context:m,forceRefresh:f=!1,status:p,signal:_}=e;if(!this.#v)return p&&(p.fetch="get"),this.get(t,{allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:o,status:p});const S={allowStale:n,updateAgeOnGet:r,noDeleteOnStaleGet:o,ttl:s,noDisposeOnSet:i,size:a,sizeCalculation:l,noUpdateTTL:c,noDeleteOnFetchRejection:h,allowStaleOnFetchRejection:u,allowStaleOnFetchAbort:g,ignoreFetchAbort:d,status:p,signal:_};let w=this.#h.get(t);if(void 0===w){p&&(p.fetch="miss");const e=this.#A(t,w,S,m);return e.__returned=e}{const e=this.#d[w];if(this.#I(e)){const t=n&&void 0!==e.__staleWhileFetching;return p&&(p.fetch="inflight",t&&(p.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const o=this.#N(w);if(!f&&!o)return p&&(p.fetch="hit"),this.#R(w),r&&this.#D(w),p&&this.#B(p,w),e;const s=this.#A(t,w,S,m),i=void 0!==s.__staleWhileFetching&&n;return p&&(p.fetch=o?"stale":"refresh",i&&o&&(p.returnedStale=!0)),i?s.__staleWhileFetching:s.__returned=s}}async forceFetch(t,e={}){const n=await this.fetch(t,e);if(void 0===n)throw new Error("fetch() returned undefined");return n}memo(t,e={}){const n=this.#a;if(!n)throw new Error("no memoMethod provided to constructor");const{context:r,forceRefresh:o,...s}=e,i=this.get(t,s);if(!o&&void 0!==i)return i;const a=n(t,i,{options:s,context:r});return this.set(t,a,s),a}get(t,e={}){const{allowStale:n=this.allowStale,updateAgeOnGet:r=this.updateAgeOnGet,noDeleteOnStaleGet:o=this.noDeleteOnStaleGet,status:s}=e,i=this.#h.get(t);if(void 0!==i){const e=this.#d[i],a=this.#I(e);return s&&this.#B(s,i),this.#N(i)?(s&&(s.get="stale"),a?(s&&n&&void 0!==e.__staleWhileFetching&&(s.returnedStale=!0),n?e.__staleWhileFetching:void 0):(o||this.#L(t,"expire"),s&&n&&(s.returnedStale=!0),n?e:void 0)):(s&&(s.get="hit"),a?e.__staleWhileFetching:(this.#R(i),r&&this.#D(i),e))}s&&(s.get="miss")}#$(t,e){this.#m[e]=t,this.#g[t]=e}#R(t){t!==this.#p&&(t===this.#f?this.#f=this.#g[t]:this.#$(this.#m[t],this.#g[t]),this.#$(this.#p,t),this.#p=t)}delete(t){return this.#L(t,"delete")}#L(t,e){let n=!1;if(0!==this.#l){const r=this.#h.get(t);if(void 0!==r)if(n=!0,1===this.#l)this.#U(e);else{this.#z(r);const n=this.#d[r];if(this.#I(n)?n.__abortController.abort(new Error("deleted")):(this.#b||this.#C)&&(this.#b&&this.#r?.(n,t,e),this.#C&&this.#S?.push([n,t,e])),this.#h.delete(t),this.#u[r]=void 0,this.#d[r]=void 0,r===this.#p)this.#p=this.#m[r];else if(r===this.#f)this.#f=this.#g[r];else{const t=this.#m[r];this.#g[t]=this.#g[r];const e=this.#g[r];this.#m[e]=this.#m[r]}this.#l--,this.#_.push(r)}}if(this.#C&&this.#S?.length){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}return n}clear(){return this.#U("delete")}#U(t){for(const e of this.#T({allowStale:!0})){const n=this.#d[e];if(this.#I(n))n.__abortController.abort(new Error("deleted"));else{const r=this.#u[e];this.#b&&this.#r?.(n,r,t),this.#C&&this.#S?.push([n,r,t])}}if(this.#h.clear(),this.#d.fill(void 0),this.#u.fill(void 0),this.#E&&this.#y&&(this.#E.fill(0),this.#y.fill(0)),this.#w&&this.#w.fill(0),this.#f=0,this.#p=0,this.#_.length=0,this.#c=0,this.#l=0,this.#C&&this.#S){const t=this.#S;let e;for(;e=t?.shift();)this.#s?.(...e)}}}var Gd,Wd;(Wd=Gd||(Gd={})).CalcStatus={Ready:"ready",Stale:"stale",Pending:"pending",Streaming:"streaming"},Wd.Content={Values:"values",Formats:"formats",Formulas:"formula",Hyperlinks:"hyperlinks",Tables:"tables",Notes:"notes",Comments:"comments",Warnings:"warnings",Errors:"errors",Merges:"merges"};class qd{constructor(t,e,n){if(!n)throw new Lt;if("string"==typeof n&&(n={address:n}),"string"!=typeof n.address)throw new Error("Invalid hyperlink");this._t=t,this._r=e,this._p=n}open(t,e){return this._r(this.getAddress(),null,t??this.getTarget(),e)}getTarget(){let t=this._p.target;if(t)return t;return this._p.address.startsWith("#")?"_self":"_blank"}getDisplayText(){return this._t()??this.getAddress()}getAddress(){return this._p.address??""}getTooltip(){return this._p.tooltip??null}get isIHyperlink(){return!0}}function Jd(t){return!/^(-?\d|--)/.test(t)}function Xd(t){const e=[];let n="",r="",o=7;for(let s,i=0;s=t.charAt(i);i++)if(/[a-zA-Z\d\xa0-\uffff_-]/.test(s)&&7===o)n+=s;else if("\\"===s&&7===o)o=6;else if(" "===s&&7===o){if(""!==n){if(!Jd(n))return null;e.push(n),n=""}}else if(6===o)/[0-9a-f]/i.test(s)?(r+=s,o=8):(n+=s,o=7);else{if(8!==o)return null;/[0-9a-f]/i.test(s)&&r.length<6?r+=s:(n+=String.fromCodePoint(parseInt(r,16)),n+=s,r="",o=7)}if(""!==n){if(!Jd(n))return null;e.push(n)}return e.join(" ")}function Kd(t,e){let n=e,r="";const o={"font-family":[]};for(let e,s=0;e=t.charAt(s);s+=1)if(4!==n||'"'!==e&&"'"!==e)if(3===n&&","===e)n=4,r="";else if(4===n&&","===e){const t=Xd(r);t&&o["font-family"].push(t),r=""}else if(5===n&&" "===e)/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:deg|grad|rad|turn)$/.test(r)?(o["font-style"]+=" "+r,r=""):s-=1,n=1;else if(1!==n||" "!==e&&"/"!==e)2===n&&" "===e?(/^(?:\+|-)?([0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)?$/.test(r)&&(o["line-height"]=r),n=4,r=""):r+=e;else{if(/^(?:(?:xx|x)-large|(?:xx|s)-small|small|large|medium)$/.test(r)||/^(?:larg|small)er$/.test(r)||/^(?:\+|-)?(?:[0-9]*\.)?[0-9]+(?:em|ex|ch|rem|vh|vw|vmin|vmax|px|mm|cm|in|pt|pc|%)$/.test(r))n="/"===e?2:4,o["font-size"]=r;else if(/^italic$/.test(r))o["font-style"]=r;else if(/^oblique$/.test(r))o["font-style"]=r,n=5;else if(/^small-caps$/.test(r))o["font-variant"]=r;else if(/^(?:bold(?:er)?|lighter|normal)$/.test(r))o["font-weight"]=r;else if(/^[+-]?(?:[0-9]*\.)?[0-9]+(?:e[+-]?(?:0|[1-9][0-9]*))?$/.test(r)){const t=parseFloat(r);t>=1&&t<=1e3&&(o["font-weight"]=r)}else/^(?:(?:ultra|extra|semi)-)?(?:condensed|expanded)$/.test(r)&&(o["font-stretch"]=r);r=""}else{let i=s+1;do{if(i=t.indexOf(e,i)+1,!i)return null}while("\\"===t.charAt(i-2));o["font-family"].push(t.slice(s+1,i-1).replace(/\\('|")/g,"$1")),s=i-1,n=3,r=""}if(3===n&&!/^\s*$/.test(r))return null;if(4===n){const t=Xd(r);t&&o["font-family"].push(t)}return o}const Yd=t=>{if("string"!=typeof t)return null;let e=function(t){const e=Kd(t,4);return null!==e?e["font-family"]:null}(t);Array.isArray(e)&&0===e.length&&(e=null),e=e?{"font-family":e}:function(t){const e=Kd(t,1);return null!==e&&e["font-size"]&&e["font-family"].length?e:null}(t);let n=null,r=null,o=null;if(e){let t=e["font-family"];const s=t.shift();s&&(n=s),t.length>0&&(r=t),void 0!==e["font-size"]&&(o=e["font-size"])}return{family:n,fallbacks:r,size:o}},Zd=(t,e=!1)=>t?.toHex(e)?.toString(!1).toLowerCase()??null,Qd=t=>null==t?null:_t.roundAccurately(t,2)+"pt",tg=(t,e)=>{let n="";const r=t&&t!==fi.UnderlineStyle.None;return e&&(n+="line-through"),r&&e&&(n+=" "),r&&(n+="underline",!0!==t&&t!==fi.UnderlineStyle.Single&&t!==fi.UnderlineStyle.SingleAccounting||(n+=" solid"),t!==fi.UnderlineStyle.Double&&t!==fi.UnderlineStyle.DoubleAccounting||(n+=" double")),n},eg=Object.freeze({underline:fi.UnderlineStyle.None,strike:!1}),ng=t=>t?"single"===(t=t.toLowerCase())?fi.UnderlineStyle.Single:"double"===t?fi.UnderlineStyle.Double:"single-accounting"===t||"singleaccounting"===t?fi.UnderlineStyle.SingleAccounting:"double-accounting"===t||"doubleaccounting"===t?fi.UnderlineStyle.DoubleAccounting:fi.UnderlineStyle.None:fi.UnderlineStyle.None,rg=t=>t?t.toLowerCase():null,og=t=>t?t===zs.Overflow.Visible||t===zs.Overflow.Clip||t===zs.Overflow.Shrink?"nowrap":t===zs.Overflow.Wrap?"normal":void 0:null,sg=(t,e)=>{let n="";if(t&&(t.includes(" ")&&(t='"'+t+'"'),n=t),e)for(let t=0;t<e.length;t++)n.length>0&&(n+=", "),n+=e[t];return n},ig=t=>{let e="",n=!1,r="";for(let o=0;o<t.length;o++){const s=t.charAt(o);n&&"]"!==s&&'"'!==s?e+=s:'"'===s?(e+="\\0022",n=!n):["[","]",",","#",".","@","/",":",";","-"," "].includes(s)?(e+="\\"+s,"["===s?n=!0:"]"===s&&(n=!1)):["(",")"].includes(s)?e+="_"===r?"\\"+s:"\\\\\\"+s:["$"].includes(s)?e+="\\0022"+s+"\\0022":e+=s,r=s}return'"'+e+'"'},ag="Thin",lg="Hairline",cg="Extra Light",hg="Ultra Light",ug="Light",dg="Normal",gg="Regular",mg="Medium",fg="Semi Bold",pg="Demi Bold",_g="Bold",Sg="Extra Bold",wg="Ultra Bold",yg="Black",Eg="Heavy",bg="Extra Black",vg="Ultra Black",Cg="lighter",xg="normal",Ig="bold",Ag="bolder",Rg=new Map;Rg.set(_t.textToKey(ag),100),Rg.set(_t.textToKey(lg),100),Rg.set(_t.textToKey(cg),200),Rg.set(_t.textToKey(hg),200),Rg.set(_t.textToKey(ug),300),Rg.set(_t.textToKey(dg),400),Rg.set(_t.textToKey(gg),400),Rg.set(_t.textToKey(mg),500),Rg.set(_t.textToKey(fg),600),Rg.set(_t.textToKey(pg),600),Rg.set(_t.textToKey(dg),400),Rg.set(_t.textToKey(_g),700),Rg.set(_t.textToKey(Sg),800),Rg.set(_t.textToKey(wg),800),Rg.set(_t.textToKey(yg),900),Rg.set(_t.textToKey(Eg),900),Rg.set(_t.textToKey(bg),950),Rg.set(_t.textToKey(vg),950),Rg.set(_t.textToKey(Cg),100),Rg.set(_t.textToKey(xg),400),Rg.set(_t.textToKey(Ig),700),Rg.set(_t.textToKey(Ag),700);const Mg="xx-small",Tg="x-small",Ng="small",Fg="medium",kg="large",Og="x-large",Lg="xx-large",Dg="xxx-large",Bg="smaller",zg="larger",Pg="math",jg=new RegExp("^[0-9]*[.]?[0-9]+$","g"),Hg=new Map;Hg.set(_t.textToKey(Mg),t=>.4*t),Hg.set(_t.textToKey(Tg),t=>.5*t),Hg.set(_t.textToKey(Ng),t=>.6*t),Hg.set(_t.textToKey(Fg),t=>t),Hg.set(_t.textToKey(kg),t=>1.1*t),Hg.set(_t.textToKey(Og),t=>1.25*t),Hg.set(_t.textToKey(Lg),t=>1.5*t),Hg.set(_t.textToKey(Dg),t=>2*t),Hg.set(_t.textToKey(Bg),t=>.9*t),Hg.set(_t.textToKey(zg),t=>1.1*t),Hg.set(_t.textToKey(Pg),t=>t);const Vg=(t,e=11,n="pt")=>{if(!t)return null;let r=e;t=t.trim().toLowerCase();const o="pt"===n?fi.getDeviceScale():1,s="pt"===n?1:fi.getDeviceScale();if(jg.test(t)){const e=parseFloat(t);isNaN(e)||(t=e+n)}if(t.endsWith("pt"))r=parseFloat(t.substring(0,t.length-2).trim())*s;else if(t.endsWith("px"))r=parseFloat(t.substring(0,t.length-2).trim())/o;else if(t.endsWith("em"))r=parseFloat(t.substring(0,t.length-2).trim())*e;else if(t.endsWith("rem"))r=parseFloat(t.substring(0,t.length-3).trim())*e;else if(t.endsWith("%"))r=parseFloat(t.substring(0,t.length-1).trim())/100*e;else if("string"==typeof t){const n=_t.textToKey(t),r=Hg.get(n);if(r)return r(e)}return isNaN(r)?null:r},$g=new Map;$g.set(ya.BuiltInSheetPattern.None,{description:"None",cssKey:"none"}),$g.set(ya.BuiltInSheetPattern.Solid,{description:"Solid",cssKey:"solid"}),$g.set(ya.BuiltInSheetPattern.DarkGray,{description:"75% gray",cssKey:"gray-75"}),$g.set(ya.BuiltInSheetPattern.MediumGray,{description:"50% gray",cssKey:"gray-50"}),$g.set(ya.BuiltInSheetPattern.LightGray,{description:"25% gray",cssKey:"gray-25"}),$g.set(ya.BuiltInSheetPattern.Gray125,{description:"12.5% Gray",cssKey:"gray-125"}),$g.set(ya.BuiltInSheetPattern.Gray0625,{description:"6.25% Gray",cssKey:"gray-0625"}),$g.set(ya.BuiltInSheetPattern.DarkHorizontal,{description:"Horizontal Strip",cssKey:"horz-stripe"}),$g.set(ya.BuiltInSheetPattern.DarkVertical,{description:"Vertical Strip",cssKey:"vert-stripe"}),$g.set(ya.BuiltInSheetPattern.DarkDown,{description:"Reverse Diagonal Stripe",cssKey:"reverse-diag-stripe"}),$g.set(ya.BuiltInSheetPattern.DarkUp,{description:"Diagonal Strip",cssKey:"diag-stripe"}),$g.set(ya.BuiltInSheetPattern.DarkGrid,{description:"Diagonal Crosshatch",cssKey:"diag-cross"}),$g.set(ya.BuiltInSheetPattern.DarkTrellis,{description:"Thick Diagonal Crosshatch",cssKey:"thick-diag-cross"}),$g.set(ya.BuiltInSheetPattern.LightHorizontal,{description:"Thin Horizontal Stripe",cssKey:"thin-horz-stripe"}),$g.set(ya.BuiltInSheetPattern.LightVertical,{description:"Thin Vertical Stripe",cssKey:"thin-vert-stripe"}),$g.set(ya.BuiltInSheetPattern.LightDown,{description:"Thin Reverse Diagonal Stripe",cssKey:"thin-reverse-diag-stripe"}),$g.set(ya.BuiltInSheetPattern.LightUp,{description:"Thin Diagonal Stripe",cssKey:"thin-diag-stripe"}),$g.set(ya.BuiltInSheetPattern.LightGrid,{description:"Thin Horizontal Cross",cssKey:"thin-horz-cross"}),$g.set(ya.BuiltInSheetPattern.LightTrellis,{description:"Thin Diagonal Cross",cssKey:"thin-diag-cross"});let Ug="";const Gg=new Map;$g.forEach((t,e)=>{Ug.length>0&&(Ug+="|"),Ug+="\\b"+t.cssKey+"\\b",Gg.set(t.cssKey,e)});const Wg=new RegExp(`(\\s*(?:${Ug}))`,"g"),qg=t=>{if(!t)return null;let e=t.toLowerCase();e=e.replace(/;/,"");let n=e.match(Wg);if(!n)return null;let r=null;n&&n.length>0&&(r=(t=>{if(!t)return null;let n=e.indexOf(t);return e=e.substring(0,n)+e.substring(n+t.length,e.length),t.trim()})(n[0])),e=e.trim();const o=e?e.trim():null;if(!r&&!o)return null;return{patternType:Gg.get(r??"solid"),foreground:o??null}},Jg=(t,e=!1,n=null)=>{if(!t||!t.getStops()||t.getStops().length<1)return null;if(1===t.getStops().length)return Zd(t.getStops()[0].getColor(),e);let r="";for(let n=0;n<t.getStops().length;n++){const o=t.getStops()[n];r+=Zd(o.getColor(),e)+" "+100*(o.getOffset()??n*(t.getStops().length-1))+"%",n<t.getStops().length-1&&(r+=", ")}let o=t.getAngle()??0;if(t.getGradientType()===ya.GradientType.Path){const n=Zd(t.getStops()[0]?.getColor(),e),s=Zd((t.getStops()[1]??t.getStops()[0])?.getColor(),e),i=t.getFillTo()??{left:0,top:0,right:0,bottom:0},a=-1;let l=`${100-a}% ${100-a}%`;if(o=315,1===i.left&&1===i.right&&1===i.right&&1===i.bottom)o=135,l=`${a}% ${a}%`;else if(0!==i.top&&0!==i.bottom&&0===i.left&&0===i.right)o=225,l=`${100-a}% ${a}%`;else if(1===i.left&&0!==i.right&&0===i.top&&0===i.bottom)o=45,l=`${a}% ${100-a}%`;else if(0!==i.left&&0!==i.right&&0!==i.top&&0!==i.bottom)return`radial-gradient(${r})`;const c=70;return`conic-gradient(from ${o}deg at ${l}, ${n} 0deg, ${s} ${c/2}deg,${s} ${360-c/2}deg, ${n} 360deg)`}return`linear-gradient(${o}deg, ${r})`},Xg=new Map;Xg.set(Ba.StrokeStyle.None,{size:null,cssKey:"none"}),Xg.set(Ba.StrokeStyle.DashDot,{size:.5,cssKey:"dot-dash"}),Xg.set(Ba.StrokeStyle.DashDotDot,{size:.5,cssKey:"dot-dot-dash"}),Xg.set(Ba.StrokeStyle.Dashed,{size:.5,cssKey:"dashed"}),Xg.set(Ba.StrokeStyle.MediumDashed,{size:1,cssKey:"dashed"}),Xg.set(Ba.StrokeStyle.Dotted,{size:.5,cssKey:"dotted"}),Xg.set(Ba.StrokeStyle.MediumDashDot,{size:1,cssKey:"dot-dash"}),Xg.set(Ba.StrokeStyle.MediumDashDotDot,{size:1,cssKey:"dot-dot-dash"}),Xg.set(Ba.StrokeStyle.Hair,{size:.5,cssKey:"hairline"}),Xg.set(Ba.StrokeStyle.Thin,{size:.5,cssKey:"solid"}),Xg.set(Ba.StrokeStyle.Thick,{size:1.5,cssKey:"solid"}),Xg.set(Ba.StrokeStyle.Medium,{size:1,cssKey:"solid"}),Xg.set(Ba.StrokeStyle.Double,{size:2,cssKey:"double"}),Xg.set(Ba.StrokeStyle.SlantDashDot,{size:1,cssKey:"dot-dash-slanted"});const Kg=t=>{if(!t)return"none";const e=Xg.get(t.getStyle());if(!e)return null;if("none"===e.cssKey)return e.cssKey;let n=((t,e=!1)=>t?.toRGBA(e).toString(!1)??null)(t?.getColor());n=n?" "+n:"";return`${null!==e.size?`${e.size}pt `:""}${e.cssKey}${n}`};let Yg=[];const Zg=new Set,Qg=new Map,tm=(t,e)=>{let n=null!==t.size?`${t.size.toString()} ${t.cssKey}`:t.cssKey;Qg.set(n,e),Zg.has(t.cssKey)||(Yg.push(t.cssKey),Zg.add(t.cssKey))};Xg.forEach(tm);const em=Object.keys(Ba.StrokeStyle);for(let t=0;t<em.length;t++){tm({size:null,cssKey:em[t].toLowerCase()},Ba.StrokeStyle[em[t]])}tm({size:null,cssKey:"double"},Ba.StrokeStyle.Double),tm({size:null,cssKey:"solid"},Ba.StrokeStyle.Medium),tm({size:null,cssKey:"hidden"},Ba.StrokeStyle.None),Yg.sort((t,e)=>e.length-t.length);let nm="";for(let t=0;t<Yg.length;t++)nm.length>0&&(nm+="|"),nm+="\\b"+Yg[t]+"\\b";const rm=new RegExp(`(\\s*(?:${nm}))`,"g"),om=new RegExp("(\\s*[0-9]*[.]?[0-9]+(?:pt|px){0,1})","g"),sm=t=>{if(!t)return null;let e=t.toLowerCase(),n=e.match(rm);if(!n)return null;const r=t=>{if(!t)return null;let n=e.indexOf(t);return e=e.substring(0,n)+e.substring(n+t.length,e.length).trim(),t.trim()};let o=null;if(n&&n.length>0&&(o=r(n[0])),!o)return null;let s=null;if(n=e.match(om),n&&n.length>0){let t=r(n[0]);s=parseFloat(t.substring(0,t.length-2))}e=e.trim();const i=e?e.trim():null;let a=null===s?o:`${s.toString()} ${o}`,l=Qg.get(a);return l||(l=Qg.get(o)),l?{color:i,style:l}:null},im="start",am="end",lm="left",cm="right",hm="center",um="justify",dm="justify-all",gm="baseline",mm="top",fm="middle",pm="bottom",_m="sub",Sm="text-top",wm="justify",ym="distributed",Em=new Map;Em.set(_t.textToKey(im),zs.HorizontalAlignment.Left),Em.set(_t.textToKey(lm),zs.HorizontalAlignment.Left),Em.set(_t.textToKey(am),zs.HorizontalAlignment.Right),Em.set(_t.textToKey(cm),zs.HorizontalAlignment.Right),Em.set(_t.textToKey(hm),zs.HorizontalAlignment.Center),Em.set(_t.textToKey(um),zs.HorizontalAlignment.Justify),Em.set(_t.textToKey(dm),zs.HorizontalAlignment.Justify);const bm=new Map;bm.set(_t.textToKey(gm),zs.VerticalAlignment.Bottom),bm.set(_t.textToKey(mm),zs.VerticalAlignment.Top),bm.set(_t.textToKey(fm),zs.VerticalAlignment.Center),bm.set(_t.textToKey(pm),zs.VerticalAlignment.Bottom),bm.set(_t.textToKey(_m),zs.VerticalAlignment.Bottom),bm.set(_t.textToKey(Sm),zs.VerticalAlignment.Top),bm.set(_t.textToKey(wm),zs.VerticalAlignment.Justify),bm.set(_t.textToKey(ym),zs.VerticalAlignment.Distributed);const vm=(t,e)=>{if(t instanceof Da)return{color:t};if("string"==typeof t)try{return{color:"none"===t||"transparent"===t?null:e(t)}}catch(t){throw t}return t},Cm={shorthand:(t,e)=>{if(!t||"none"===t||"transparent"===t)return null;try{return e.parseColor(t).toString()}catch(t){console.warn("error",t)}return t},merge:(t,e,n)=>t},xm={shorthand:(t,e)=>{if("string"==typeof t&&(t=sm(t)),!t)return null;const n={};return t.style&&(n.style=t.style),t.color&&(n.color=t.color),t.isIStroke?t.getProperties():n},properties:{color:Cm}},Im={shorthand:(t,e)=>"none"===t||"transparent"===t||"object"==typeof t&&0===Object.keys(t).length?{type:ya.Type.None}:(t.getType?.(),ya.Type.None,t)},Am={shorthand:(t,e)=>("object"==typeof(t=vm(t,e.parseColor.bind(e)))&&t.color&&(t.type=ya.Type.Solid),t),merge:(t,e,n)=>t.color?t:(e?.toJSON&&(e=e.toJSON()),e?.type===ya.Type.Solid?{...e}:e?.type===ya.Type.Gradient?{type:ya.Type.Solid,color:e?.stops?.[0]?.color??n.parseColor(ba.Scheme.Bg1)}:e?.type===ya.Type.Pattern?{type:ya.Type.Solid,color:e?.foreground??n.parseColor(ba.Scheme.Bg1)}:t?{...t}:null),properties:{color:Cm}},Rm={shorthand:(t,e)=>("object"==typeof t&&t.stops&&(t.type=ya.Type.Gradient),t),merge:(t,e,n)=>t.stops?t:(e?.toJSON&&(e=e.toJSON()),e?.type===ya.Type.Gradient?{...e}:e?.type===ya.Type.Solid?{type:ya.Type.Gradient,stops:[{offset:0,color:e?.color??ba.Scheme.Accent1},{offset:1,color:ba.Scheme.Bg1}]}:e?.type===ya.Type.Pattern?{type:ya.Type.Gradient,stops:[{offset:0,color:e?.foreground??ba.Scheme.Bg1},{offset:1,color:e?.background??ba.Scheme.Accent1}]}:t?{...t}:null),properties:{stops:{shorthand:(t,e)=>t,arrayType:{shorthand:(t,e)=>t=vm(t,e.parseColor.bind(e)),properties:{color:Cm}}}}},Mm={shorthand:(t,e)=>{if("object"==typeof t){const e=t;(e.foreground||e.background||e.patternType)&&(e.type=ya.Type.Pattern,e.patternType=e.patternType??ya.BuiltInSheetPattern.Solid)}return t},merge:(t,e,n)=>{if(t.background&&t.foreground)return t;e?.toJSON&&(e=e.toJSON());const r=ya.BuiltInSheetPattern.MediumGray;return e?.type===ya.Type.Pattern?{...e,...t}:e?.type===ya.Type.Solid?{patternType:r,...t,foreground:e?.color??ba.Named.WindowText,background:ba.Scheme.Bg1}:e?.type===ya.Type.Gradient?{patternType:r,...t,foreground:e?.stops?.[0]?.color??ba.Named.WindowText,background:e?.stops?.[1]?.color??ba.Scheme.Bg1}:t?{type:ya.Type.Pattern,patternType:ya.BuiltInSheetPattern.Solid,foreground:ba.Named.WindowText,background:ba.Scheme.Bg1,...t}:null},properties:{foreground:Cm,background:Cm}},Tm={shorthand:(t,e)=>{const n=[Im,Am,Rm,Mm];for(let r=0;r<n.length;r++){let o=n[r]?.shorthand?.(t,e);if(o?.type)return o}return t},getSubType:t=>t.type===ya.Type.None?Im:t.type===ya.Type.Solid?Am:t.type===ya.Type.Gradient?Rm:t.type===ya.Type.Pattern?Mm:null},Nm={properties:{font:{shorthand:(t,e)=>{if("string"==typeof t){const e=Yd(t);if(e){const t={};if(e.family&&(t.family=e.family),e.fallbacks&&(t.fallbacks=e.fallbacks),e.size&&(t.size=Vg(e.size)),Object.keys(e).length>0)return t}}return t},properties:{family:{shorthand:(t,e)=>Yd(t)?.family??null},fallbacks:{shorthand:(t,e)=>{if("string"!=typeof t)return t;let n=Yd(t);if(!n)return null;let r=[n.family];return n.fallbacks&&(r=r.concat(n.fallbacks)),r}},size:{shorthand:(t,e)=>{let n=t;return"string"==typeof t&&(n=Vg(t,e.getNormal().getFont().getSize())),isNaN(n)||"number"!=typeof n?null:(n=Math.max(1,Math.min(_t.roundAccurately(n,1),409)),n)}},weight:{shorthand:(t,e)=>{if("string"!=typeof t)return t;const n=(t=>{let e=400;if(e="number"==typeof t?t:parseFloat(t),!isNaN(e))return e;if("string"==typeof t){const e=_t.textToKey(t),n=Rg.get(e);if(n)return n}return e})(t);return isNaN(n)||"number"!=typeof n?null:n}},underline:{shorthand:(t,e)=>t?!0===t?fi.UnderlineStyle.Single:ng(t):fi.UnderlineStyle.None}}},fill:Tm,alignment:{properties:{indent:{shorthand:(t,e)=>{let n=t;return"string"==typeof t&&(n=parseFloat(t)),isNaN(n)||"number"!=typeof n?null:n}},rotation:{shorthand:(t,e)=>{let n=t;return"string"==typeof t&&(n=parseFloat(t)),isNaN(n)||"number"!=typeof n?null:(n%=360,n<0&&(n+=360),n)}}}},border:{shorthand:(t,e)=>{if("string"==typeof t){const e=sm(t);return{left:e,right:e,top:e,bottom:e,horizontal:null,vertical:null,diagonalUp:null,diagonalDown:null}}return t.isIBorder?t.getProperties():t},properties:{top:xm,left:xm,right:xm,bottom:xm,horizontal:xm,vertical:xm,diagonalUp:xm,diagonalDown:xm}},numberFormat:{shorthand:(t,e)=>{if("string"==typeof t){let e=el.Styles.lookupDefault(t);return void 0!==e?e:t}if("number"==typeof t){return Wa(t)}return null}}}},Fm={properties:{style:Nm}},km=Object.freeze({displayText:"",conditionalColor:null,repeatChars:_t.EmptyArray,spacingChars:_t.EmptyArray,repeatPlaceholder:null,formattedRuns:Object.freeze({runs:_t.EmptyArray,length:0,width:0,lastRepeatIndex:-1}),canWrap:!1,asDate:null,isDateFormat:!1,isTimeFormat:!1,isDate1904:!1}),Om=(e,n,r,o,s,i=!1)=>{if(null==e)return km;let a="",l=null,c=null,h=null;if(r===t.Error)a=e.getLabel();else if(r===t.RichData)a="(Rich Object)";else if(r===t.Boolean)a=e?"TRUE":"FALSE";else if(o)try{a=Xo(o,e,{date1904:i,spacingCharacter:"",digitCharacter:"",onRepeatChar:(t,e)=>{c||(c=[]),c.push({offset:t,char:e})},onSpacingChar:(t,e)=>{h||(h=[]),h.push({offset:t,char:e})},onDigitChar:t=>{h||(h=[]),h.push({offset:t,char:"0"})}})}catch(t){}const u=Os(o),d=Ls(o),g=u||d?ys(e,i):null;(u||d)&&parseFloat(e)<0&&(l="#",a=l.repeat(5));let m=null;const f=n.getAlignment(),p=f.getHorizontal(),_=f.getVertical(),S=f.getOverflow(),w=!(r!==t.String||p===zs.HorizontalAlignment.Fill||null!==c&&0!==c.length||S!==zs.Overflow.Wrap&&p!==zs.HorizontalAlignment.Justify&&p!==zs.HorizontalAlignment.Distributed&&_!==zs.VerticalAlignment.Justify&&_!==zs.VerticalAlignment.Distributed);let y=a;w||r!==t.String||(y=y.replaceAll(/\n/g,""));const E=h?.length>0||c?.length>0;if(S!==zs.Overflow.Wrap||E){const t=n.getFont();let e=t.getSize();t.isSuperSub()&&(e*=t.getSuperSubScale());let r=[];for(let t=0;t<h?.length;t++){const o=h[t],s=n.measureText(o.char,e).width;r.push({...o,type:"spacing",width:s})}if(c?.length>0){const t=c[c.length-1],o=n.measureText(t.char,e).width;r.push({...t,type:"repeat",width:o})}r=r.sort((t,e)=>t.offset-e.offset);let o=[],s=0,i=0,a=-1,l=-1;const u=t=>{const r={type:"text",width:n.measureText(t,e).width,text:t};o.push(r),i+=r.width,s+=t.length};for(let t=0;t<r.length;t++){const e=r[t];if(l!==e.offset){const t=y.substring(s,e.offset);t&&u(t)}const n={type:e.type,width:e.width,text:e.char};"repeat"!==e.type?i+=n.width:a=o.length,o.push(n),l=e.offset}if(s<y.length){let t=y.substring(s,y.length);t&&u(t)}m={runs:Object.freeze(o),length:s,width:i,lastRepeatIndex:a}}const b=us(o,e),v={displayText:a??"",conditionalColor:b?s(b):null,repeatChars:c??_t.EmptyArray,spacingChars:h??_t.EmptyArray,repeatPlaceholder:l,formattedRuns:m,canWrap:w,asDate:g,isDateFormat:u,isTimeFormat:d,isDate1904:i};return Object.freeze(v)},Lm=Object.freeze({fallbacks:_t.EmptyArray,weight:400,style:fi.Style.Normal,fill:ba.Scheme.Tx1,letterSpacing:null,underline:fi.UnderlineStyle.None,strike:!1,scheme:fi.Scheme.Minor,verticalAlign:fi.VerticalAlignment.Baseline,shadow:!1,outline:!1,extend:!1}),Dm=Object.freeze({style:Ba.StrokeStyle.None,color:ba.Scheme.Tx1}),Bm=Object.freeze({[Ba.Edge.Top]:Dm,[Ba.Edge.Left]:Dm,[Ba.Edge.Bottom]:Dm,[Ba.Edge.Right]:Dm,[Ba.Edge.Horizontal]:Dm,[Ba.Edge.Vertical]:Dm,[Ba.Edge.DiagonalUp]:Dm,[Ba.Edge.DiagonalDown]:Dm}),zm=Object.freeze({horizontal:zs.HorizontalAlignment.General,vertical:zs.VerticalAlignment.Bottom,indent:0,relativeIndent:0,overflow:zs.Overflow.Visible,rotation:0,stacked:!1,quotePrefix:!1,justifyLastLine:!1,readingOrder:zs.ReadingDirection.Auto,readingDirection:zs.ReadingDirection.Auto}),Pm=Object.freeze({locked:!1,formulaHidden:!1}),jm=Object.freeze({fill:{type:ya.Type.None},numberFormat:"General",alignment:zm,font:Lm,border:Bm,protection:Pm,quotePrefix:!1,namedStyle:null}),Hm=(()=>{const t=[{named:rl.BuiltInName.Normal},{named:rl.BuiltInName.RowLevel},{named:rl.BuiltInName.ColLevel},{named:rl.BuiltInName.Comma,numberFormat:'_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)'},{named:rl.BuiltInName.Currency,numberFormat:'_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'},{named:rl.BuiltInName.Percent,numberFormat:"0%"},{named:rl.BuiltInName.Comma0,numberFormat:'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)'},{named:rl.BuiltInName.Currency0,numberFormat:'_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)'},{named:rl.BuiltInName.Hyperlink,font:{...Lm,fill:ba.Scheme.Hlink,underline:fi.UnderlineStyle.Single}},{named:rl.BuiltInName.FollowedHyperlink,font:{...Lm,fill:ba.Scheme.FolHlink,underline:fi.UnderlineStyle.Single}},{named:rl.BuiltInName.Note,fill:"FFFFFFCC",font:{...Lm,style:fi.Style.Normal,fill:ba.Scheme.Tx1},border:{left:{style:Ba.StrokeStyle.Thin,color:"FFB2B2B2"},top:{style:Ba.StrokeStyle.Thin,color:"FFB2B2B2"},right:{style:Ba.StrokeStyle.Thin,color:"FFB2B2B2"},bottom:{style:Ba.StrokeStyle.Thin,color:"FFB2B2B2"}}},{named:rl.BuiltInName.WarningText,font:{...Lm,fill:"FFFF0000"}},{named:rl.BuiltInName.Unknown12},{named:rl.BuiltInName.Unknown13},{named:rl.BuiltInName.Unknown14},{named:rl.BuiltInName.Title,font:{...Lm,size:18,fill:ba.Scheme.Tx2}},{named:rl.BuiltInName.Heading1,font:{...Lm,size:15,weight:"bold",fill:ba.Scheme.Tx2},border:{bottom:{style:Ba.StrokeStyle.Thick,color:ba.Scheme.Accent1}}},{named:rl.BuiltInName.Heading2,font:{...Lm,size:13,weight:"bold",fill:ba.Scheme.Tx2},border:{bottom:{style:Ba.StrokeStyle.Thick,color:"accent1 lumMod 40, lumOff 60"}}},{named:rl.BuiltInName.Heading3,font:{...Lm,weight:"bold",fill:ba.Scheme.Tx2},border:{bottom:{style:Ba.StrokeStyle.Medium,color:"accent1 lumMod 40, lumOff 60"}}},{named:rl.BuiltInName.Heading4,font:{weight:"bold",fill:ba.Scheme.Tx2,...Lm}},{named:rl.BuiltInName.Input,fill:"FFFFCC99",font:{...Lm,fill:"FF3F3F76"},border:{left:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},top:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},right:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},bottom:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"}}},{named:rl.BuiltInName.Output,fill:"FFF2F2F2",font:{...Lm,fill:"FF3F3F3F"},border:{left:{style:Ba.StrokeStyle.Thin,color:"FF3F3F3F"},top:{style:Ba.StrokeStyle.Thin,color:"FF3F3F3F"},right:{style:Ba.StrokeStyle.Thin,color:"FF3F3F3F"},bottom:{style:Ba.StrokeStyle.Thin,color:"FF3F3F3F"}}},{named:rl.BuiltInName.Calculation,fill:"FFF2F2F2",font:{...Lm,fill:"FFFA7D00"},border:{left:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},top:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},right:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"},bottom:{style:Ba.StrokeStyle.Thin,color:"FF7F7F7F"}}},{named:rl.BuiltInName.CheckCell,fill:"FFA5A5A5",font:{...Lm,fill:ba.Scheme.Bg1},border:{left:{style:Ba.StrokeStyle.Double,color:"FF3F3F3F"},top:{style:Ba.StrokeStyle.Double,color:"FF3F3F3F"},right:{style:Ba.StrokeStyle.Double,color:"FF3F3F3F"},bottom:{style:Ba.StrokeStyle.Double,color:"FF3F3F3F"}}},{named:rl.BuiltInName.LinkedCell,font:{...Lm,fill:"FFFA7D00"},border:{bottom:{style:Ba.StrokeStyle.Double,color:"FFFF8001"}}},{named:rl.BuiltInName.Total,font:{...Lm,weight:"bold",fill:ba.Scheme.Tx1},border:{top:{style:Ba.StrokeStyle.Thin,color:ba.Scheme.Accent1},bottom:{style:Ba.StrokeStyle.Double,color:ba.Scheme.Accent1}}},{named:rl.BuiltInName.Good,fill:"FFC6EFCE",font:{...Lm,fill:"FF006100"}},{named:rl.BuiltInName.Bad,fill:"FFFFC7CE",font:{...Lm,fill:"FF9C0006"}},{named:rl.BuiltInName.Neutral,fill:"FFFFEB9C",font:{...Lm,fill:"FF9C5700"}},{named:rl.BuiltInName.Accent1},{named:rl.BuiltInName.Accent1_20},{named:rl.BuiltInName.Accent1_40},{named:rl.BuiltInName.Accent1_60},{named:rl.BuiltInName.Accent2},{named:rl.BuiltInName.Accent2_20},{named:rl.BuiltInName.Accent2_40},{named:rl.BuiltInName.Accent2_60},{named:rl.BuiltInName.Accent3},{named:rl.BuiltInName.Accent3_20},{named:rl.BuiltInName.Accent3_40},{named:rl.BuiltInName.Accent3_60},{named:rl.BuiltInName.Accent4},{named:rl.BuiltInName.Accent4_20},{named:rl.BuiltInName.Accent4_40},{named:rl.BuiltInName.Accent4_60},{named:rl.BuiltInName.Accent5},{named:rl.BuiltInName.Accent5_20},{named:rl.BuiltInName.Accent5_40},{named:rl.BuiltInName.Accent5_60},{named:rl.BuiltInName.Accent6},{named:rl.BuiltInName.Accent6_20},{named:rl.BuiltInName.Accent6_40},{named:rl.BuiltInName.Accent6_60},{named:rl.BuiltInName.ExplanatoryText,font:{...Lm,style:fi.Style.Italic,fill:"FF7F7F7F"}}];for(let e=29;e<=52;e++){const n=(e-29)%4,r=Math.floor((e-29)/4);let o="";1===n?o=" lumMod 20, lumOff 80":2===n?o=" lumMod 40, lumOff 60":3===n&&(o=" lumMod 60, lumOff 40"),t[e].fill=`accent${r+1}${o}`,t[e].font={fill:0===n?ba.Scheme.Bg1:ba.Scheme.Tx1,...Lm}}return _t.deepFreeze(t)})();const Vm=new class{_svgImage(t,e,n,r=8){return{backgroundImage:`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='${r}' height='${r}' viewBox='0 0 ${r} ${r}' shape-rendering='crispEdges' %3E%3Cpath d='${n}' stroke='${t}' %3E%3C/path%3E%3C/svg%3E")`,backgroundRepeat:"repeat",backgroundSize:`${r}px ${r}px`,backgroundPositionX:"0px",backgroundPositionY:"0px",backgroundPosition:""+-r,backgroundColor:e}}toCSS(t,e,n){return t&&t!==ya.BuiltInSheetPattern.None?t===ya.BuiltInSheetPattern.Solid?{background:n}:t===ya.BuiltInSheetPattern.Gray0625?this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 4.5 2.5 L 4.5 3.5 M 4.5 6.5 L 4.5 7.5",8):t===ya.BuiltInSheetPattern.LightGray?this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 0.5 2.5 L 0.5 3.5 M 2.5 -0.5 L 2.5 0.5 M 2.5 1.5 L 2.5 2.5 M 2.5 3.5 L 2.5 4.5",4):t===ya.BuiltInSheetPattern.MediumGray?this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 1.5 1.5 L 1.5 2.5 M 1.5 -0.5 L 1.5 0.5 M -0.5 -0.5 L -0.5 0.5",2):t===ya.BuiltInSheetPattern.DarkGray?this._svgImage(e,n,"M 0 0 L 0 4 M 1 1 L 1 2 M 1 3 L 1 4 M 2 0 L 2 4 M 3 0.5 L 3 1.5 M 3 2.5 L 3 3.5 M 4 0 L 4 4",4):t===ya.BuiltInSheetPattern.LightHorizontal?this._svgImage(e,n,"M 0 2 L 4 2",4):t===ya.BuiltInSheetPattern.DarkHorizontal?this._svgImage(e,n,"M 0 2 L 4 2 M 0 3 L 4 3",4):t===ya.BuiltInSheetPattern.LightVertical?this._svgImage(e,n,"M 2 0 L 2 4",4):t===ya.BuiltInSheetPattern.DarkVertical?this._svgImage(e,n,"M 2 0 L 2 4 M 3 0 L 3 4",4):t===ya.BuiltInSheetPattern.LightUp?this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5",4):t===ya.BuiltInSheetPattern.DarkUp?this._svgImage(e,n,"M 0.5 -0.5 L 0.5 1.5 M 0.5 3.5 L 0.5 4.5 M 1.5 2.5 L 1.5 4.5 M 2.5 1.5 L 2.5 3.5 M 3.5 0.5 L 3.5 2.5 M 1.5 -0.5 L 1.5 0.5",4):t===ya.BuiltInSheetPattern.LightDown?this._svgImage(e,n,"M 0.5 0 L 0.5 1 M 1.5 1 L 1.5 2 M 2.5 2 L 2.5 3 M 3.5 3 L 3.5 4",4):t===ya.BuiltInSheetPattern.DarkDown?this._svgImage(e,n,"M 0.5 -0.5 L 0.5 2 M 1.5 1 L 1.5 3 M 2.5 2 L 2.5 4 M 3.5 3 L 3.5 5 M 3.5 -0.5 L 3.5 1.0",4):t===ya.BuiltInSheetPattern.LightGrid?this._svgImage(e,n,"M 1.5 -0.5 L 1.5 4.5 M -0.5 1.5 L 4.5 1.5",4):t===ya.BuiltInSheetPattern.DarkGrid?this._svgImage(e,n,"M 0.5 -0.5 L 0.5 1.5 M 1.5 -0.5 L 1.5 1.5 M 2.5 1.5 L 2.5 3.5 M 3.5 1.5 L 3.5 3.5 M 0.5 3.5 L 0.5 4.5 M 1.5 3.5 L 1.5 4.5",4):t===ya.BuiltInSheetPattern.LightTrellis?this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 1.5 3.5 L 1.5 4.5 M 1.5 -0.5 L 1.5 0.5 M 2.5 2.5 L 2.5 3.5 M 3.5 1.5 L 3.5 2.5 M 1.5 1.5 L 1.5 2.5 M 3.5 3.5 L 3.5 4.5 M 3.5 -0.5 L 3.5 0.5",4):t===ya.BuiltInSheetPattern.DarkTrellis?this._svgImage(e,n,"M 0 0 L 4 0 M 0 1 L 2 1 M 0 2 L 4 2 M 2 3 L 4 3 M 0 4 L 4 4",4):(ya.BuiltInSheetPattern.Custom,this._svgImage(e,n,"M 0.5 0.5 L 0.5 1.5 M 0.5 4.5 L 0.5 5.5 M 2.5 2.5 L 2.5 3.5 M 2.5 6.5 L 2.5 7.5 M 4.5 0.5 L 4.5 1.5 M 4.5 4.5 L 4.5 5.5 M 6.5 2.5 L 6.5 3.5 M 6.5 6.5 L 6.5 7.5",8)):{background:"none"}}},$m=(t,e,n)=>{if(void 0===e)return;if(null===e)return null;if(e.isIStyle)return e._p.getProperties();let r=null;if("function"==typeof e){r=e("function"==typeof n?n():n)}else r=e;return r};class Um{constructor(t,e){this._c=t,this._p=Object.freeze(Array.isArray(e)?e:[e??null])}value(t){const e=this._p;for(let n=e.length-1;n>=0;n--){const r=e[n];if(!r)continue;const o=r[t];if(void 0!==o)return o}}values(t){const e=this._p,n=e.length;let r;for(let o=0;o<n;o++){const n=e[o];if(!n)continue;const s=n[t];void 0!==s&&(void 0===r&&(r=[]),r.push(s))}return r}getProperties(){const t=this._p;return t?t[t.length-1]:null}toJSON(){return null}}class Gm{constructor(t,e){this._c=t,this._p=Object.freeze(e)}_value(t){const e=this._p;for(let n=e.length-1;n>=0;n--){const r=e[n];if(!r)continue;const o=r[t];if(void 0!==o)return o}}_values(t){const e=this._p,n=e.length;let r;for(let o=0;o<n;o++){const n=e[o];if(!n)continue;const s=n[t];void 0!==s&&(void 0===r&&(r=[]),r.push(s))}return r}getProperties(){const t=this._p;return t?t[t.length-1]:null}toJSON(){return null}}class Wm extends Gm{constructor(t,e,n){super(e,n),this._edge=t}getStyle(){return this._value("style")}getColor(){const t=this._value("color");return t?this._c.parseColor(t):null}isNone(){return this.getStyle()===Ba.StrokeStyle.None}toCSS(){const t=Kg(this);switch(this._edge){case Ba.Edge.Left:return{borderLeft:t};case Ba.Edge.Right:return{borderRight:t};case Ba.Edge.Top:return{borderTop:t};case Ba.Edge.Bottom:return{borderBottom:t};case Ba.Edge.DiagonalUp:case Ba.Edge.DiagonalDown:return{borderDiagonalUp:t}}}get isIStroke(){return!0}}class qm extends Gm{getLeft(){return new Wm(Ba.Edge.Left,this._c,this._values(Ba.Edge.Left))}getRight(){return new Wm(Ba.Edge.Right,this._c,this._values(Ba.Edge.Right))}getTop(){return new Wm(Ba.Edge.Top,this._c,this._values(Ba.Edge.Top))}getBottom(){return new Wm(Ba.Edge.Bottom,this._c,this._values(Ba.Edge.Bottom))}getDiagonalUp(){return new Wm(Ba.Edge.DiagonalUp,this._c,this._values(Ba.Edge.DiagonalUp))}getDiagonalDown(){return new Wm(Ba.Edge.DiagonalDown,this._c,this._values(Ba.Edge.DiagonalDown))}isEmpty(){return!1}get isIBorder(){return!0}}class Jm extends Gm{get isITextBoxAlignment(){return!0}getHorizontal(){return this._value("horizontal")}getVertical(){return this._value("vertical")}getIndent(){return this._value("indent")}getRelativeIndent(){return this._value("relativeIndent")}getOverflow(){return this._value("overflow")}getRotation(){return this._value("rotation")}getStacked(){return this._value("stacked")}getJustifyLastLine(){return this._value("justifyLastLine")}getReadingDirection(){return this._value("readingDirection")}}class Xm extends Gm{isEqualMeasure(t){return!!t&&(this.getFamily()===t.getFamily()&&(!!_t.isEqualArrays(this.getFallbacks(),t.getFallbacks())&&(this.getSize()===t.getSize()&&(this.getWeight()===t.getWeight()&&(this.getStyle()===t.getStyle()&&(this.getStrike()===t.getStrike()&&(this.getScheme()===t.getScheme()&&(this.getShadow()===t.getShadow()&&(this.getOutline()===t.getOutline()&&(this.getLetterSpacing()===t.getLetterSpacing()&&this.getVerticalAlignment()===t.getVerticalAlignment()))))))))))}isSuperSub(){const t=this.getVerticalAlignment();return t===fi.VerticalAlignment.Sub||t===fi.VerticalAlignment.Super}isSuperScript(){const t=this.getVerticalAlignment();return t===fi.VerticalAlignment.Sub||t===fi.VerticalAlignment.Super}getSuperSubScale(){return this.getFamily(),this.getSize(),this.getVerticalAlignment(),.6}getSuperSubShift(){return this.getFamily(),t=this.getSize(),(e=this.getVerticalAlignment())===fi.VerticalAlignment.Super?-t/3:e===fi.VerticalAlignment.Sub?t/5:0;var t,e}toCSS(t,e=1,n=!1){const r={fontFamily:sg(this.getFamily(),this.getFallbacks()),letterSpacing:`${this.getLetterSpacing()}px`,fontWeight:this.getWeight(),fontStyle:this.getStyle(),textDecoration:tg(this.getUnderline(),this.getStrike()),color:this.getFill().toCSS(t),fontSize:`${_t.roundAccurately(this.getSize()*fi.getDeviceScale()*e,2)}px`,textRendering:"geometricPrecision"};if(n){const n=this._c.getNormal().getFont().toCSS(t,e,!1),o=r.textDecoration,s=r.fontWeight;_t.removeEqualValues(r,n),o&&(r.textDecoration=o),s&&(r.fontWeight=s)}return r}getFamily(){return this._value("family")??this._c.getTheme().getFontScheme().getMinorFont()}getFallbacks(){let t=this._value("fallbacks")??this._c.getTheme().getFontScheme().getMinorFallbacks()??_t.EmptyArray;return"Aptos Narrow"===this.getFamily()&&(t=["Calibri",...t]),t}getSize(){return this._value("size")??this._c.getDefaultFontSize()??11}getWeight(){return this._value("weight")}getStyle(){return this._value("style")}getFill(){const t=this._value("fill");return this._c.parseColor(t??ba.Scheme.Bg1)}getLetterSpacing(){return this._value("letterSpacing")??this.getSize()/-25}getUnderline(){return this._value("underline")}getStrike(){return this._value("strike")}getScheme(){return this._value("scheme")}getVerticalAlignment(){return this._value("verticalAlign")}getShadow(){return this._value("shadow")}getOutline(){return this._value("outline")}getExtend(){return this._value("extend")}get isIStyledFont(){return!0}}const Km=Object.freeze({background:"none"});class Ym extends Gm{getType(){return ya.Type.None}toCSS(t){return Km}toJSON(){return{type:ya.Type.None}}}class Zm extends Gm{getType(){return ya.Type.Solid}getColor(){return this._c.parseColor(this._value("color")??ba.Scheme.Bg1)}toCSS(t){return{background:this.getColor().toCSS(t)}}toJSON(){return{type:ya.Type.Solid,color:this.getColor()?.toString()??null}}}class Qm extends Gm{getOffset(){return this._value("offset")??0}getColor(){return this._c.parseColor(this._value("color")??ba.Scheme.Bg1)}}class tf extends Gm{getType(){return ya.Type.Gradient}getStops(){const t=this._value("stops")??[],e=[],n=this._c;for(let r=0;r<t.length;r++){const o=t[r];e.push(new Qm(n,[o]))}return e}getGradientType(){return this._value("gradientType")??ya.GradientType.Linear}getAngle(){return this._value("angle")??0}getFillTo(){return this._value("fillTo")??null}toCSS(t,e){const n=Jg(this,t,e);return n?{background:n}:null}toJSON(){const t={type:ya.Type.Gradient};if(this.getStops().length>0){let e=[];for(let t=0;t<e.length;t++)e.push({offset:e[t].offset,color:e[t].color.toString()});t.stops=e}return 0!==this.getAngle()&&(t.angle=this.getAngle()),this.getGradientType()!==ya.GradientType.Linear&&(t.gradientType=this.getGradientType()),this.getFillTo()&&(t.fillTo=this.getFillTo()),t}}class ef extends Gm{getType(){return ya.Type.Pattern}getBackground(){const t=this._value("background")??ba.Named.Window;return this._c.parseColor(t)}getForeground(){return this._c.parseColor(this._value("foreground")??ba.Scheme.Tx1)}getPatternType(){return this._value("patternType")??ya.BuiltInSheetPattern.None}toCSS(t){const e=this.getBackground().toCSS(t),n=this.getForeground().toCSS(t);return this.getPatternType()===ya.BuiltInSheetPattern.None?{background:"none"}:this.getPatternType()===ya.BuiltInSheetPattern.Solid?{background:this.getForeground().toCSS(t)}:Vm.toCSS(this.getPatternType(),n,e)}toJSON(){const t={type:ya.Type.Pattern};this.getPatternType()!==ya.BuiltInSheetPattern.None&&(t.patternType=this.getPatternType());const e=this.getForeground();e&&(t.foreground=e.toString());const n=this.getBackground();return n&&(t.background=n.toString()),t}}class nf{constructor(t){this._options=t,this._c=t.styles,this._p=new Um(t.styles,t.properties),this._hasVisibleStyling=!this.getFill()||this.getFill().getType()!==ya.Type.None||!this.getBorder().isEmpty()}hasVisibleStyling(){return this._hasVisibleStyling}isNormal(){return!1}getNamed(){const t=this._p.value("named")??rl.BuiltInName.Normal;return this._c.getNamed(t)}createTemporaryStyle(t){const e=this._c,n=$m(0,t,this),r=this._options,o=r.range,s=r.direct.cloneWithUpdate(n);return rf(e,s,o)}measureText(t,e=this.getFont().getSize(),n,r){const o=this.getFont();n||(n=o.getFamily());let s=o.getFallbacks();"Aptos Narrow"===n&&(s=["Calibri",...s]);const i=sg(n,s);return fi.getSharedMeasurer()(t,e*fi.getDeviceScale(),i,{isBold:o.getWeight()>400,isItalic:o.getStyle().includes("italic"),letterSpacing:o.getLetterSpacing(),...r})}createTemporaryTextFrame(t,e=!1){return ta(t,this.getFont(),this.getAlignment(),e)}getBestFit(){if(void 0!==this._bestFit)return this._bestFit;const t=this.getInsets(),e=this.measureText("My");return this._bestFit={width:null,height:e.lineHeight+t.top+t.bottom},this._bestFit}getInsets(){if(void 0!==this._insets)return this._insets;const t=(this.getFont().getSize(),1),e=(n=this.getFont().getSize(),Math.max(2,Math.round(n<225?n/5:n/3.5)));var n;const r={top:t,left:e,bottom:t,right:e},o=this._p,s=o?.value("insets");return s&&(void 0!==s.top&&(r.top+=s.top),void 0!==s.left&&(r.left+=s.left),void 0!==s.bottom&&(r.bottom+=s.bottom),void 0!==s.right&&(r.right+=s.right)),this._insets=Object.freeze(r),this._insets}getBorder(){return new qm(this._c,this._p.values("border"))}getFont(){return new Xm(this._c,this._p.values("font"))}getFill(){const t=this._p;let e=t.values("fill"),n=t.value("fill");return n.type===ya.Type.None?new Ym(this._c,e):n.type===ya.Type.Solid||!n.type&&n.color?new Zm(this._c,e):n.type===ya.Type.Gradient?new tf(this._c,e):n.type===ya.Type.Pattern?new ef(this._c,e):new Ym(this._c,e)}getAlignment(){return new Jm(this._c,this._p.values("alignment"))}getNumberFormat(){const t=this._p.value("numberFormat");return"number"==typeof t?Wa(t):t}getQuotePrefix(){return this._p.value("quotePrefix")}get isIStyle(){return!0}}const rf=(t,e,n)=>{const r=n?.rowStart??W.EmptyCell.rowIndex,o=n?.colStart??W.EmptyCell.colIndex,s=[jm],i=t.getNormalRanged(),a=i.getPropertiesAt(r,o,null);if(a&&s.push(a),!e){return new of({styles:t,range:n,properties:s,layerTypes:null,direct:i})}const l=e.getPropertiesAt(r,o,null);l&&s.push(l);return new nf({styles:t,range:n,properties:s,direct:e})};class of extends nf{isNormal(){return!0}}const sf=(t,e)=>{if(t&&!e||e&&!t)return!1;if(t===e)return!0;if(t.style!==e.style)return!1;if(t.color===e.color)return!0;let n=t.color;(t&&t.color).isIColor&&(n=t.color.toString());let r=e.color;return(e&&e.color).isIColor&&(r=e.color.toString()),n===r};class af{constructor(t,e,n,r){this._c=t,this._r=e,this._p=n??null,this._t=r??null,this._e=null===this._p||1===Object.keys(this._p).length&&this._p.named===rl.BuiltInName.Normal}isEmpty(){return this._e}getProperties(){return this._p}getCoords(){return this._r}cloneWithUpdate(t){if(void 0===t)return this;const e=this._c,n=this._r,r=this._p,o=Mt.resolveTypedUpdates(t,Nm,e,r);return new af(e,n,o)}copyTo(t,e){const n=this._c,r=this._r,o=t.rowStart-r.rowStart,s=t.colStart-r.colStart;let i=null;return W.isEqualRanges(r,this._t)||(i=W.translateRange(r,o,s)),new af(n,t,this._p,i)}canTile(t,e){return!this._p.border}_createShifted(t){return new af(this._c,t,this._p)}getShifted(t){return t.after?{...t.after,value:this._createShifted(W.sanitizeRange(t.after))}:null}getSplit(t,n){const r=this._c,o=this._p,s=this._r;let i=o;const a=t[0];let l=o;const c=t[1],h=o?o.border:null;if(h){const t=n===e.Orientation.Column;if(t?void 0!==h.left||void 0!==h.right||void 0!==h.vertical:void 0!==h.top||void 0!==h.bottom||void 0!==h.horizontal){i={...i};const e=this._splitBorderRange(h,s,a,t);e?i.border=e:null===e&&delete i.border,l={...l};const n=this._splitBorderRange(h,s,c,t);n?l.border=n:null===n&&delete l.border}}const u=this._t;return[new af(r,t[0],i,u),new af(r,t[1],l,u)]}getMerged(t,n,r){const o=r===e.Orientation.Column,s=this._p,i=t._p;if(s&&!i||i&&!s||!s&&!i)return;let a=Object.keys(s),l=Object.keys(i);if(a.length!==l.length)return;for(let t=0;t<a.length;t++){const e=a[t];if("border"===e)continue;const n=s[e],r=i[e];if(!_t.deepEqual(n,r))return}const c=s.border,h=i.border;if(c&&!h||h&&!c)return;const u=this._c;if(c||h){const e=o?Ba.Edge.Top:Ba.Edge.Left,r=o?Ba.Edge.Bottom:Ba.Edge.Right;if(!sf(c[e],h[e])||!sf(c[r],h[r]))return;const i=this._r,a=t._r,l=1+(o?i.rowEnd-i.rowStart:i.colEnd-i.colStart),d=1+(o?i.colEnd-i.colStart:i.rowEnd-i.rowStart),g=1+(o?a.colEnd-a.colStart:a.rowEnd-a.rowStart),m=o?Ba.Edge.Horizontal:Ba.Edge.Vertical;if(l>1&&!sf(c[m],h[m]))return;const f=o?Ba.Edge.Right:Ba.Edge.Bottom,p=o?Ba.Edge.Left:Ba.Edge.Top;if(!sf(c[f],h[p]))return;const _=o?Ba.Edge.Vertical:Ba.Edge.Horizontal,S=c[f];if(d>1&&!sf(S,c[_]))return;const w=1===g?h[p]:h[_];if(g>1&&!sf(w,h[_]))return;if(!sf(S,w))return;const y={border:{[e]:c[e],[r]:c[r],[m]:c[m],[_]:S,[p]:c[p],[f]:h[f]}},E=Mt.resolveTypedUpdates(y,Nm,u,s);return new af(u,n,E)}return new af(u,n,this._p)}hasTrailingEdge(){return!0}isMergeOnShift(){return!0}_splitBorderRange(t,e,n,r){const o=r?Ba.Edge.Left:Ba.Edge.Top,s=r?Ba.Edge.Right:Ba.Edge.Bottom,i=r?Ba.Edge.Vertical:Ba.Edge.Horizontal,a=r?e.colStart:e.rowStart,l=r?e.colEnd:e.rowEnd,c=r?n.colStart:n.rowStart,h=r?n.colEnd:n.rowEnd;let u={...t};return delete u[o],delete u[s],delete u[i],a===c?t[o]&&(u[o]=t[o]):t[i]&&(u[o]=t[i]),l===h?t[s]&&(u[s]=t[s]):t[i]&&(u[s]=t[i]),h-c>0&&t[i]&&(u[i]=t[i]),0===Object.keys(u).length?null:u}_localizeBorderRange(t,e,n){if(!t)return;let r=null;const o=e.rowStart,s=e.rowEnd,i=n.rowStart,a=n.rowEnd;t.top&&i===o&&(r=r??{},r.top=t.top),t.bottom&&a===s&&(r=r??{},r.bottom=t.bottom),t.horizontal&&(a-i>0&&(r=r??{},r.horizontal=t.horizontal),i>o&&(r=r??{},r.top=t.horizontal),a<s&&(r=r??{},r.bottom=t.horizontal));const l=e.colStart,c=e.colEnd,h=n.colStart,u=n.colEnd;return t.left&&h===l&&(r=r??{},r.left=t.left),t.right&&u===c&&(r=r??{},r.right=t.right),t.vertical&&(u-h>0&&(r=r??{},r.vertical=t.vertical),h>l&&(r=r??{},r.left=t.vertical),u<c&&(r=r??{},r.right=t.vertical)),r}_localizeBorder(t,e,n,r){if(!t)return;let o=null;const s=e.rowStart,i=e.rowEnd;t.top&&n===s&&(o=o??{},o.top=t.top),t.bottom&&n===i&&(o=o??{},o.bottom=t.bottom),t.horizontal&&(n>s&&(o=o??{},o.top=t.horizontal),n<i&&(o=o??{},o.bottom=t.horizontal));const a=e.colStart,l=e.colEnd;return t.left&&r===a&&(o=o??{},o.left=t.left),t.right&&r===l&&(o=o??{},o.right=t.right),t.vertical&&(r>a&&(o=o??{},o.left=t.vertical),r<l&&(o=o??{},o.right=t.vertical)),o}getPropertiesAt(t,e,n){const r=this._p;let o=r,s=null;const i=this._t;if(i){const n=this._r,r=i.colEnd-i.colStart+1,o=i.rowEnd-i.rowStart+1;e=n.colStart+(e-n.colStart+(i.colStart-n.colStart))%r,t=n.rowStart+(t-n.rowStart+(i.rowStart-n.rowStart))%o}const a=r?.font;a&&a.fill&&(s=s??this._c.getNormalRanged().getPropertiesAt(t,e,n),s&&s.font&&a.fill===s.font.fill&&(o===r&&(o={...o}),o.font={...a},delete o.font.fill));const l=r?.fill;l&&(s=s??this._c.getNormalRanged().getPropertiesAt(t,e,n),s&&_t.deepEqual(l,s.fill)&&(o===r&&(o={...o}),delete o.fill));const c=o?.border;if(c){const n=i??this._r,s=this._localizeBorder(c,n,t,e);void 0!==s&&(o===r&&(o={...o}),null===s?delete o.border:o.border=s)}return o}toJSON(){return _t.toSafeJSON(this._p)}}const lf=Object.freeze({value:null,style:null,hyperlink:null,formula:null,type:t.Null,stringToParse:null}),cf=Object.seal({value:void 0,style:void 0,hyperlink:void 0,formula:void 0,type:void 0,stringToParse:void 0}),hf=Object.seal({value:void 0,style:void 0,hyperlink:void 0,formula:void 0}),uf=Object.freeze({width:1,height:1}),df=new Ud({max:1e3});const gf=new class{isEditAllowed(){return!0}isFormulaHidden(){return!1}get isICellProtection(){return!0}},mf=(e,n,r=null,o=null,s=!1)=>{if(void 0===e)return;if(null===e)return lf;if(e&&e.isICell){const t=e,n=cf;n.value=t.getValue();return t.getStyle().isNormal()||(n.style=t.getStyle()._p.getProperties()),n.formula=t.getFormulaText(),n.hyperlink=t.getHyperlink(),n.type=t.getType(),n}let i;void 0!==e.value||void 0!==e.style||void 0!==e.hyperlink?i=e:(i=hf,i.value=e,i.style=void 0,i.hyperlink=void 0);const a=cf;a.type=void 0,a.value=void 0,a.style=void 0,a.formula=void 0,a.hyperlink=void 0,a.stringToParse=void 0;let l,c=i.value,h=!1;if(void 0!==i.value&&(l=Kh(c),l||(h=ms(c),h&&(l=t.Number)),!l))throw new Error("Invalid cell type. See documentation for information on valid built in cell types and creating custom cell types.");let u,d,g=null,m=null;let f;if(l===t.String){if(f=i.value,r){let t=o?.get(f);if(!t){const e=f.length,n=f.charAt(0);"="===n&&e>1?(d=f.substring(1),c=null):(t=Uf(f,r),!t||"string"!=typeof t.value||"+"!==n&&"-"!==n||(d="="+f,c=null),void 0!==t&&o&&o.set(f,t))}t&&(void 0!==t.value&&(c=t.value,l=Kh(c)),void 0!==t.style&&(g=t.style),void 0!==t.hyperlink&&(u=t.hyperlink)),!s&&r.parse&&(m=f)}}else if(h){const t=r?.date1904??n.date1904;c=Es(i.value,t),g=t=>{if(!Os(t.getNumberFormat()))return{numberFormat:"Short Date"}}}else c=i.value;let p=i.style;if(p&&p.isIStyle&&(p=p._p.getProperties()),u=i.hyperlink??u,g)if(p){const t=p;p=e=>{let n=e.createTemporaryStyle(g);return n=n.createTemporaryStyle(t),n=n._p.getProperties(),n}}else p=g;let _=!1;return void 0!==c&&(null===c?(a.value=null,a.type=t.Null):(a.value=c,a.type=l),_=!0),void 0!==p&&(a.style=p,_=!0),void 0!==u&&(a.hyperlink=u,_=!0),void 0!==d&&(a.formula=d,_=!0),s||(a.stringToParse=m,_=!0),_?(a.type=l,a):void 0},ff=(t,e,n,r)=>Om(n,e,t,e.getNumberFormat(),t=>r.styles.parseColor(t),r.date1904),pf=(e,n,r,o,s=!1)=>{if(e===t.Null)return null;let i="";if(s)i=""+r;else{const t=ff(e,n,r,o);if(t.formattedRuns){const e=t.formattedRuns.runs;for(let t=0;t<e.length;t++){i+=e[t].text}}else i=t.displayText}return ta(i,n.getFont(),n.getAlignment(),e===t.String,s)},_f=(e,n)=>{const r=n.getInsets();if(e===t.Null)return r;let o=r;const s=Sf(e,n),i=n.getAlignment().getIndent();if(i&&(s===zs.HorizontalAlignment.Left||s===zs.HorizontalAlignment.Right)){o={...r};const t=n.measureText(" ".repeat(1*i)),e=Math.min(3,Math.max(1,(26-n.getFont().getSize())/2));let a=t.width*e;s===zs.HorizontalAlignment.Left?o.left+=a:s===zs.HorizontalAlignment.Right&&(o.right+=a)}return Object.freeze(o)},Sf=(e,n)=>{const r=n.getAlignment(),o=r.getRotation(),s=r.getHorizontal();return 0!==o&&s===zs.HorizontalAlignment.General?o>0&&o<90||o>180&&o<=270?zs.HorizontalAlignment.Right:zs.HorizontalAlignment.Left:s===zs.HorizontalAlignment.General?e===t.Null?zs.HorizontalAlignment.Left:e===t.Boolean||e===t.Error?zs.HorizontalAlignment.Center:"@"===n.getNumberFormat()?zs.HorizontalAlignment.Left:e===t.Number?zs.HorizontalAlignment.Right:zs.HorizontalAlignment.Left:s},wf=(e,n,r,o,s,i,a,l)=>{if(n===t.Null||""===o)return null;const c=e.colIndex;if(!((e,n,r=!1,o=!1)=>{if(e===t.Null)return!1;const s=n.getAlignment(),i=s.getHorizontal();if(i===zs.HorizontalAlignment.CenterContinuous)return!0;if(i===zs.HorizontalAlignment.Fill||i===zs.HorizontalAlignment.Distributed)return!1;if(e!==t.String||s.getOverflow()!==zs.Overflow.Visible)return!1;if(i===zs.HorizontalAlignment.Right&&r)return!1;if(i===zs.HorizontalAlignment.Center&&r&&o)return!1;if(o&&(i===zs.HorizontalAlignment.General||i===zs.HorizontalAlignment.Left))return!1;const a=s.getVertical();return a!==zs.VerticalAlignment.Justify&&a!==zs.VerticalAlignment.Distributed})(n,r,null!==s&&s.colIndex+1===c,null!==i&&i.colIndex-1===c))return null;const h=vf(n,r,o,l),u=r.getAlignment().getHorizontal(),d=u===zs.HorizontalAlignment.Fill,g=u===zs.HorizontalAlignment.CenterContinuous||d;if(!h&&!g)return null;const m=(f=Sf(n,r))===zs.HorizontalAlignment.Center||f===zs.HorizontalAlignment.CenterContinuous?y.Center:f===zs.HorizontalAlignment.Right?y.Right:y.Left;var f;let p=0,_=0,S=0,w=0,E=1;if(g&&null!==o&&a.directStyle){const t=a.directStyle.getCoords();E=Math.min(l.nextContentful(e,t.colEnd),t.colEnd)-e.colIndex+1}const b=l.colHeaders,v=b.findOffset.bind(b),C=b.findIndex.bind(b);let x=v(c);const I=x;let A=v(c+E),R=A-x,M=c,T=c;const N={x:0,y:0,width:R,height:h?.height??0};const F=c-c+E;let k=h?h.width-R:0,O=N;d&&(k=0),R>0&&k>0&&(m===y.Center&&(k/=2),m!==y.Left&&m!==y.Center||(T=C(A+k),null!==i&&(T=Math.min(T,i.colIndex-1)),A=v(T),w=k,_=T-c),m!==y.Right&&m!==y.Center||(M=C(x-k),null!==s&&(M=Math.max(M,s.colIndex+1)),x=v(M),S=k,p=c-M),N.x=I-x,O.x=N.x);return{anchorBounds:N,leftIndex:p,rightIndex:_,leftOffset:S,rightOffset:w,colSpan:F,colBounds:O}};class yf{constructor(t,e){if(this._styles=t,this._rs=e,e?.table){const t=e?.table;this._table=t.getStyle().getRanged(t)}if(e?.conditionals){this._conditionals=[];for(let t=0;t<e.conditionals.length;t++){const n=e.conditionals[t];this._conditionals.push(n)}}}getCoords(){return W.EmptyRange}getPropertiesAt(t,e,n){let r=null,o=this._rs.directStyle?.getPropertiesAt(t,e,n)??null;const s=this._styles;if(o&&o.named){const s=o.named;if(s!==rl.BuiltInName.Normal){const o=this._styles.getNamed(s);o?r=o.getRanged().getPropertiesAt(t,e,n):console.warn(`A named styled was referenced but not found: '${s}'.`)}}let i=null;const a=this._table?.getPropertiesAt(t,e,n);a&&(i=i?Mt.resolveTypedUpdates(a,Nm,s,i):a),r&&(i=i?Mt.resolveTypedUpdates(r,Nm,s,i):r);const l=this._conditionals;if(l)for(let r=0;r<l.length;r++){const o=l[r].getPropertiesAt(t,e,n);o&&(i=i?Mt.resolveTypedUpdates(o,Nm,s,i):o)}return o&&(i=i?Mt.resolveTypedUpdates(o,Nm,s,i):o),i}cloneWithUpdate(t){return(this._rs.directStyle??this._styles.getNormalRanged()).cloneWithUpdate(t)}}const Ef=(t,e,n,r)=>{if(!n)return r.styles.getNormal();const o=r.styles;return rf(o,n?new yf(o,n):null,e)},bf=(e,n,r,o,s,i,a,l=null,c=df)=>{if(null===r)return n?n.getBestFit():null;const h=e===t.String,u=n.getFont(),d=u.getWeight(),g=u.getSize(),m=u.getFamily(),f=n.getAlignment(),p=f.getOverflow(),_=f.getRotation(),S=f.getVertical(),w=n.getNumberFormat(),y=h&&p===zs.Overflow.Visible,E=h&&(p===zs.Overflow.Wrap||S===zs.VerticalAlignment.Justify||S===zs.VerticalAlignment.Distributed),b=(l??"")+"\0"+g+m+d+w+_+y+E+i+a+(l?"":r),v=c.get(b);if(v)return v;let C=null,x=null;const I=_f(e,n),A=I.top+I.bottom+ +Gf(n);let R=!1,M=!1;a&&(M=!0,(0!==_||E)&&(M=!1));const T=M?void 0:pf(e,n,r,o),N=I.left+I.right+2;if(T){if(e===t.Number&&"General"===w&&i){let t=r,e=_t.splitNumber(t),o="";o=Math.abs(t)>=Math.pow(10,12)||Math.abs(t)<=Math.pow(10,-12)?`0.${"0".repeat(Math.max(2,Math.min(e.ipLength,5)))}E+00`:0===Math.abs(e.ipLength)?"0.0":Math.abs(e.fpLength)>0?"0".repeat(e.ipLength)+".0":"0".repeat(e.ipLength),t<0&&(o="-"+o),o="0".repeat(o.length);const s=n.measureText(o);C=s.width,x=s.lineHeight}else{let t=null;E&&(t={width:Math.max(1,s-N)});const e=T.layout(t);C=e.bounds.width,x=e.bounds.height}if(null!==C&&(C+=N),null!==x&&(x+=A),R=e===t.String,_){R&&p===zs.Overflow.Wrap&&(R=!1);const t=((t,e)=>{const{x:n,y:r,width:o,height:s}=t,i=e*Math.PI/180,a=Math.sin(i),l=Math.cos(i),c=o/2,h=s/2,u=ea(-c,-h,a,l),d=ea(c,-h,a,l),g=ea(-c,h,a,l),m=ea(c,h,a,l);let f=Math.min(u.x,d.x,g.x,m.x)+c,p=Math.max(u.x,d.x,g.x,m.x)+c,_=Math.min(u.y,d.y,g.y,m.y)+h;return{x:n+f,y:r+_,width:p-f,height:Math.max(u.y,d.y,g.y,m.y)+h-_}})({x:0,y:0,width:C,height:x},_);C=t.width,x=t.height}}else x=n.getBestFit().height;i&&R&&(C=0);const F={width:C,height:x},k=Object.freeze(F);return c.set(b,k),k},vf=(t,e,n,r)=>{const o=_f(t,e),s=Sf(t,e);let i=o.left+o.right;s===zs.HorizontalAlignment.Left?i=o.right:s===zs.HorizontalAlignment.Right?i=o.left:s===zs.HorizontalAlignment.Center&&(i=o.left+o.right);const a=bf(t,e,n,r,Number.MAX_SAFE_INTEGER,!1,!1);return{width:Math.ceil(a.width-i),height:Math.ceil(a.height)}};class Cf{constructor(e,n,r=t.Null,o=null,s=null,i=null,a=null){this._options=e,this._coords=n??null,this._t=r,this._rs=s,this._v=o,this._p=i,this._n=a}isEqual(t){if(!t)return!1;if(this===t)return!0;const e=t;return!!e.isICell&&(this._v===e._v&&(!!W.isEqualCells(this._coords,t.getCoords())&&this._options.sheet===e._options?.sheet))}getCoords(){return this._coords}getA1(){const t=this._coords;return t?Mu(this._options.resolveRange(t).getCoords()):gu}getSource(){return this._options.sheet}select(t){return this._options.opener("#"+vu(this._coords),t)}getColumnFilter(){if(!this._rs)return null;let t=null;if(this._rs.table){const e=this._rs.table.getHeaderRange().getCoords();if(e&&W.isCellWithinRange(this._coords,e)){const n=this._coords.colIndex-e.colStart;t=this._rs.table.getColumnFilter(n)??null}}return t}getProtection(){return gf}getTextOverflow(){const t=this._to;if(void 0!==t)return t;if(this._rs&&this._rs.merge)return this._to=null,null;const e=this.getStyle(),n=wf(this._coords,this._t,e,this._v,this._p,this._n,this._rs,this._options);return null===n||0===n.leftIndex&&0===n.rightIndex&&n.colSpan<=1?(this._to=null,null):(this._to=n,this._to)}getRenderHorizontalAlignment(){return Sf(this._t,this.getStyle())}isEmpty(){return null===this._v&&!this._rs}getExtrusions(){const t=this._rs;if(!t&&null===this._to)return null;if(t){const e=t.merge;if(void 0!==e)return e.getCoords()}const e=this.getTextOverflow();if(!e)return null;const n=this._coords;return{colStart:n.colIndex-e.leftIndex,rowStart:n.rowIndex,colEnd:n.colIndex+e.rightIndex+e.colSpan-1,rowEnd:n.rowIndex}}isEditAllowed(){const t=this._options;if(!t)return!0;return!t.getProtection().isLocked()||!!this._rs&&this.getProtection().isEditAllowed()}isFormulaHidden(){return!!this._options.getProtection().isLocked()&&(!!this._rs&&this.getProtection().isFormulaHidden())}isContentful(){return null!==this._v}getBestFit(t,e=!1){return void 0===t&&(t=this._options.sheet.getColumnHeaders().getSpanSize(this._coords.colIndex)??64),bf(this._t,this.getStyle(),this._v,this._options,t,e,!1)}getInsets(){if(null===this._v)return this.getStyle().getInsets();return _f(this._t,this.getStyle())}getTextFrame(e){let n,r;if(e&&(r=this.getFormulaText()),n=r??this._v,null===n)return null;const o=this.getStyle();return r?((e,n)=>n===t.Null?null:ta(n,e.getFont(),e.getAlignment(),!1,!0))(o,n,this._options):pf(this._t,o,n,this._options,e)}getValue(){return this._v}getFormula(){let t=this._rs?.formula;if(!t)return null;const e=this._coords;return e?(Array.isArray(t)&&(t=t[0]),new If(this._options,t,e)):null}getFormulaText(){let t=this._rs?.formula;if(!t)return null;const e=this._coords;if(!e)return null;return Array.isArray(t)&&(t=t[0]),"="+t.getFormulaTextAt(e.rowIndex,e.colIndex)}getCalcStatus(){const t=this._rs;return t&&t.pending?Gd.CalcStatus.Pending:Gd.CalcStatus.Ready}getType(){return this._t}getStyle(t=!1){if(!t&&this._styleConditional)return this._styleConditional;if(t&&this._styleSpecific)return this._styleSpecific;const e=Ef(0,W.cellToRange(this._coords),this._rs,this._options);return t?this._styleSpecific=e:this._styleConditional=e,e}createTemporaryCell(t){const e=this._options;if(null===t)return new Cf(e,this._coords,null);const n=mf(t,this._options);let r=this._rs;if(void 0!==n.style){const t=this._coords??W.EmptyCell,o=W.cellToRange(t),s=()=>Ef(0,o,this._rs,this._options),i=$m(this._options.styles,n.style,s),a=(this._rs?.directStyle??new af(e.styles,o)).cloneWithUpdate(i);r={...r,directStyle:a}}let o=this._t,s=this._v;return n&&void 0!==n.value&&(s=n.value,o=n.type),s===this._v&&o===this._t&&r===this._rs?this:null!==s||r?new Cf(this._options,this._coords,o,s,r):new Cf(this._options,this._coords)}_isDate1904(){return this._options.date1904}getNumberFormat(t){if(void 0!==t){const e=this._v;return Om(e,this.getStyle(),this._t,t,t=>this._options.styles.parseColor(t),this._isDate1904())}return ff(this._t,this.getStyle(),this._v,this._options)}toDate(){return this._t!==t.Number?null:this._rs?this.getNumberFormat().asDate:null}toText(t){return this.getNumberFormat(t).displayText}toTextUnformatted(e){if(e){const t=this.getFormulaText();if(t)return t}let n=this._v;return this.isSpillOverflow()&&(n=null),((e,n,o,s)=>{if(n===t.Null||null==e)return"";if(n===t.Number){const t=e,n=Os(o),r=Ls(o);if(n||r){const o=parseFloat(e),i=o%1!=0,a=o>=1;if(o<0)return _t.castToString(e);if(!n||r||i)if(!r||n||a){const e=Ko("Short Date",t,s),n=Ko("Long Time",t,s);if(e&&n)return e.fmt+" "+n.fmt}else{const e=Ko("Long Time",t,s);if(e)return e.fmt}else{const e=Ko("Short Date",t,s);if(e)return e.fmt}}}if(n===t.Number&&o.endsWith("%")){let t=_t.roundAccurately(100*parseFloat(e));if(!isNaN(t))return t+"%"}return n===t.Boolean?e?"TRUE":"FALSE":n===t.Error?e?.getLabel?.()??r.Label.Unknown:n===t.RichData?"(Rich Object)":_t.castToString(e)})(n,this._t,this.getStyle().getNumberFormat(),{date1904:this._isDate1904()})}getComments(){const t=this._rs?.comments;return t?Object.freeze(t):null}getHyperlink(){const t=this._rs?.hyperlink;return t?new qd(this.toText.bind(this),this._options.opener,t):null}getErrors(){const t=this._rs;return t&&t.calcError?[t.calcError]:_t.EmptyArray}getWarnings(){return _t.EmptyArray}getSpans(){const t=this._rs?.merge;if(!t)return uf;const e=t.getCoords();return Object.freeze({width:e.colEnd-e.colStart+1,height:e.rowEnd-e.rowStart+1})}isTopLeft(){const t=this._rs?.merge;if(!t)return!0;const e=t.getCoords();return this._coords&&this._coords.colIndex===e.colStart&&this._coords.rowIndex===e.rowStart}getSpill(){let t=this._rs?.spills;if(!t)return null;if(!this._coords)return null;Array.isArray(t)||(Af[0]=t,t=Af);let e=null;for(let n=0;!e&&n<t.length;n++){const r=t[n];r.getError()||(e=r)}return e||(e=t[0]),this._options.getRange(e.getCoords())}isSpillOverflow(){let t=this._rs?.spills;if(!t)return!1;if(!this._coords)return null;Array.isArray(t)||(Af[0]=t,t=Af);for(let e=0;e<t.length;e++){const n=t[e].getCoords();if(this._coords.colIndex===n.colStart&&this._coords.rowIndex===n.rowStart)return!1}return!0}get[Symbol.toStringTag](){return"[Cell]"}toString(){let e="{blank}";return null!==this._v&&(e=this.toTextUnformatted(),this.getType()===t.String&&(e=`'${e}'`)),`${this.getA1()} => ${e}`}get isICell(){return!0}}let xf=class extends Cf{constructor(t){super(t,null,null,null)}isEmpty(){return!0}isContentful(){return!1}toString(){return"{EMPTY CELL}"}};class If{constructor(t,e,n){this._options=t,this._entry=e,this._coords=n}getTokens(t){const e=this._coords;if(!e)return _t.EmptyArray;return this._entry.getTokensAt(e.rowIndex,e.colIndex,t)}evaluate(t){const e=this._coords;return e?this._options.calcGraph().evaluateAt(e.rowIndex,e.colIndex,t):_t.EmptyArray}toText(t){const e=this._coords;if(!e)return null;return"="+this._entry.getFormulaTextAt(e.rowIndex,e.colIndex,t)}getDirectPrecedents(){const t=this._coords;if(!t)return _t.EmptyArray;return this._options.calcGraph().getDirectPrecedentsAt(t.rowIndex,t.colIndex)}getReferences(){const t=this._coords;if(!t)return _t.EmptyArray;return this._entry.getReferencesAt(t.rowIndex,t.colIndex)}setReferenceAt(t,e){const n=this._coords;return n?(this._options.calcGraph().setReferenceAt(n.rowIndex,n.colIndex,t,e),this):_t.EmptyArray}get[Symbol.toStringTag](){return"[Formula]"}toString(){return this.toText()}}const Af=[null];let Rf;const Mf=(t,n,r,o=!1)=>{const s=r===e.Orientation.Row,i=t.length,a=new Array(i);for(let e=0;e<i;e++){const r=t[e];if(s){const t=r.colEnd-r.colStart+1;a[e]={...r,colStart:o?r.colEnd+1:r.colStart,rowStart:n.rowStart,colEnd:o?r.colEnd+t:r.colEnd,rowEnd:n.rowEnd}}else{const t=r.rowEnd-r.rowStart+1;a[e]={...r,colStart:n.colStart,rowStart:o?r.rowEnd+1:r.rowStart,colEnd:n.colEnd,rowEnd:o?r.rowEnd+t:r.rowEnd}}}return a},Tf=(t,e,n)=>{const r=e,o=t.length;for(let e=0;e<o;e++){const o=t[e];if((o.rowStart<=r.rowStart&&o.rowEnd>=r.rowEnd)!==n)return!n}return n},Nf=(t,e,n)=>{const r=e,o=t.length;for(let e=0;e<o;e++){const o=t[e];if((o.colStart<=r.colStart&&o.colEnd>=r.colEnd)!==n)return!n}return n},Ff=(t,n)=>{let r=0;const o=t.length;for(let s=0;s<o;s++){const o=t[s];n===e.Orientation.Column?r+=o.colEnd-o.colStart+1:r+=o.rowEnd-o.rowStart+1}return r},kf=(t,n)=>{if(n){if(t.colStart<=n.colStart&&t.colEnd>=n.colEnd)return e.Orientation.Row;if(t.rowStart<=n.rowStart&&t.rowEnd>=n.rowEnd)return e.Orientation.Column}return t?(t=>t.rowEnd-t.rowStart>t.colEnd-t.colStart?e.Orientation.Column:e.Orientation.Row)(t):e.Orientation.Row},Of=()=>!1,Lf=()=>!0,Df=()=>null,Bf=()=>Gl,zf=()=>0,Pf=new class extends Cf{constructor(){super(null,null)}createTemporaryCell(){return this}getType(){return t.Error}getWarnings(){return[gu]}getStyle(t=!1){return Rf||(Rf=(new Fp).getNormal(),Rf)}toString(){return`${this._coords?vu(this._coords):gu} => ${this._v??"{blank}"}`}},jf=()=>Hf,Hf={forEach:()=>{},[Symbol.iterator]:Bf,entries:Bf,select:od,find:od,calculate:od,getCell:()=>Pf,getValue:Df,setValue:od,setValues:od,updateCells:od,updateStyle:od,getCells:()=>[[Pf]],getStyleUpdater:od,getValues:()=>[[null]],getBounds:Df,getIntersect:jf,getUnion:jf,getDifferences:od,getResizeBy:jf,getResizeTo:jf,getOffsetBy:jf,getOffsetTo:jf,getFixed:jf,getUsedRange:jf,getEntireRows:jf,getEntireColumns:jf,getSurrounding:od,getExtended:od,isEntireRows:Of,isEntireColumns:Of,isEntireRange:Of,getWidth:zf,getHeight:zf,size:0,sort:od,clear:od,setHyperlink:od,setComments:od,merge:od,unmerge:od,getMerges:od,insert:od,insertFrom:od,delete:od,getDefaultShiftOrientation:od,getDefaultSortCriteria:od,autoFill:od,autoFit:od,getSnapshot:od,copyFrom:od,doBatch:od,startIncrementalUpdates:od,getRowHeaders:od,getColumnHeaders:od,getCounts:od,getCount:zf,isContentful:Of,addListener:od,getColumnStart:zf,getRowStart:zf,getColumnEnd:zf,getRowEnd:zf,getRowCount:zf,getColumnCount:zf,getVisible:od,getCoords:Df,isEmpty:Lf,toString:()=>gu,getA1:()=>gu,isInvalid:Lf,getSource:Df,isReadOnly:Lf,isICellRange:!0};function Vf(t,e=null,n=null,r=gu){return t||n?Object.freeze({...Hf,getSheet:()=>t,bounds:()=>n,getA1:()=>r,toString:()=>n?Au(n,e):r}):Hf}const $f=/^[\\+-]?[0-9]*\.?[0-9]*$/,Uf=(t,e,n)=>{if(void 0===t)throw new Error("A value is required to create a cell from a text.");const o=n??{value:null};if(""===(t=_t.castToString(t)).trim())return o;if("TRUE"===t.toUpperCase()||"FALSE"===t.toUpperCase())return o.value="TRUE"===t.toUpperCase(),o;if(t.startsWith("'")&&!e?.ignoreQuotePrefix)return o.style={quotePrefix:!0},o.value=t.substring(1,t.length),o;o.value=t;const s=",",i="$",a=".";let l=t.trim(),c=1,h=!1;l=(t=>{const e=new RegExp("([(]{1}([^(|^)]+)[)]{1})").exec(t);if(e?.[2]){const n=t.substring(0,e.index)+e[2].trim()+t.substring(e.index+("("+e[2]+")").length-1,t.length-1);return n.indexOf("(")>-1||n.indexOf(")")>-1?t:(h=!0,c=-1,n)}return t})(l);let u=0;l=(t=>{const e=new RegExp("[0-9]+([eE][-+]?[0-9]+)?$").exec(t);if(e?.[1]){const n=t.substring(0,t.length-e[1].length);let r=1,o=e[1].substring(1,e[1].length);if(o.startsWith("-")?(o=o.substring(1,o.length),r=-1):o.startsWith("+")&&(o=o.substring(1,o.length)),!isNaN(o))return u=o*r,n}return t})(l);let d=!1;if(l=(t=>{const e=new RegExp(`^(\\${i}[\\ ]*\\-|\\${i}[\\ ]*\\+|\\-[\\ ]*\\${i}|\\+[\\ ]*\\${i}|\\-|\\+)?`).exec(t);if(e?.[1]){const n=e?.[1].indexOf(i)>-1,r=e?.[1].indexOf("-")>-1,o=e?.[1].indexOf("+")>-1,s=(n?i:"")+t.substring(e.index+e[1].length,t.length).trim(),a=s.indexOf("-")>-1,l=s.indexOf("+")>-1;return a||l?t:(d=r||o,r&&(c=-1),s)}return t})(l),d&&(h||0===l.length))return o;let g=!1;if(l=(t=>{if(new RegExp(`^(?:\\${i}[\\ ]*)?((\\d{1,3}(${s}\\d{3})*)|(\\d*))(\\${a}|\\${a}\\d*)?(?:[\\ ]*\\%)?$`).test(l)){const e=t.replace(new RegExp(`${s}`,"g"),"");return g=e.length<t.length,e}return t})(l),l.match($f)&&!isNaN(l)){if(o.value=l*c,0!==u)o.value=o.value*Math.pow(10,u),o.style={numberFormat:`0${a+"0".repeat(2)}E+00`};else if(g){let t=Gs(l);o.style=t>0?{numberFormat:`#${s}##0${a+"0".repeat(2)}`}:{numberFormat:`#${s}##0`}}return o}if(l.trimEnd().endsWith("%")&&l.trimEnd().length>1){let t=l.substring(0,l.length-1);if(!isNaN(t)){o.value=t*c/100;const e=Gs(t);o.style=t=>{if(!t.getNumberFormat().includes("%"))return{numberFormat:e>0?`0${a+"0".repeat(2)}%`:"0%"}}}return o}if(l.startsWith(i)&&t.trim().length>1){let t=l.replace(i,"");if(!isNaN(t)){let e=Gs(t);o.value=t*c,o.style=t=>{if(t.getNumberFormat().includes(i))return;let n;return n=e>0?`${i}#${s}##0${a+"0".repeat(2)}_);[Red](${i}#${s}##0${a+"0".repeat(2)})`:`${i}#${s}##0_);[Red](${i}#${s}##0)`,{numberFormat:n}}}return o}let m=null,f=null;try{f=Ns(t,e?.date1904,!0);let n=t;f&&(n=f.leadingText),n.trim().length>0&&(m=ks(n,e?.date1904)),!m&&f?.leadingText.trim().length>0&&(f=null)}catch(t){}if(m||f){o.style=t=>{let n=t.getNumberFormat();const r=Os(n);if(m&&r)return;const o=Ls(n);if(!f||!o){if(m&&f&&!r&&!o?n="m/d/yyyy h:mm":m&&!r?n=m.numberFormat:f&&!o&&(n=f.numberFormat),f&&f.parsed.oaDateTime>1&&(n="General"),m&&!r&&!f){const t=el.Parser.formatValue(m.numberFormat,m.asOADate,{date1904:e?.date1904}),r=Intl.DateTimeFormat().resolvedOptions().locale??"en-US";t===new Intl.DateTimeFormat(r).format(m.asJSDate)?n="Short Date":t===new Intl.DateTimeFormat(r,{dateStyle:"full"}).format(m.asJSDate)?n="Long Date":t===new Intl.DateTimeFormat(r,{timeStyle:"medium"}).format(m.asJSDate)&&(n="Long Time")}return{numberFormat:n}}};let t=0;return m&&(t+=m.asOADate),f&&(t+=f.parsed.oaDateTime),o.value=t,o}const p=r.getBuiltInByLabel(t);return p?(o.value=p,o):(o.value=t,Qs(t)?o.hyperlink=t:ei(t)&&(o.hyperlink=t,o.hyperlink.toLowerCase().startsWith("mailto:")||(o.hyperlink=`mailto:${o.hyperlink}`)),o)},Gf=t=>{const e=t.getFont().getUnderline()===fi.UnderlineStyle.SingleAccounting,n=t.getFont().getUnderline()===fi.UnderlineStyle.DoubleAccounting;let r=0;if(e||n){r=t.measureText("").underlineThickness+1,n?r*=2:r+=1}return r},Wf=t=>{const e=[];t.getUsedRange().forEachSpan((t,n)=>{const r=n.getCoords();0===t&&e.push(r)},{includeStyles:!1});return ca(ha(e))},qf=(t,n,r,o)=>{const s=o?.asJSDate;let i;r?i=md:(s||o?.includeMergeOverflow)&&(i={},s&&(i[dd.Type.Style]=!1,i[dd.Type.Table]=!1),o.includeMergeOverflow&&(i[dd.Type.Merge]=!1));const a=o?.orientation??e.Orientation.Row,l=o?.maxSize??1e4,c=t({includeEmpty:!0,orientation:a,reverse:o?.reverse,excludeHidden:o?.excludeHidden,includeMergeOverflow:o?.includeMergeOverflow,includeRangeTypes:i,bounds:n,excludeCellDetails:!s}),h=a!==e.Orientation.Row,u=[];let d,g=-1,m=null,f=0;for(d=c.next();!d.done;){if(f>l)throw new Error(Td(l));const t=d.value,e=t.context.getCoords(),n=h?e.colIndex:e.rowIndex;n!==g&&(m=[],u.push(m),g=n);let o=t.value;if(r)o=t.context.getCell();else if(s&&null!==o&&"number"==typeof o){const e=t.context.getCell().toDate();e&&(o=e)}m.push(o),d=c.next(),f++}return u},Jf=(t,e)=>t===e||!(!t||!e)&&(t.rowStart===e.rowStart&&t.rowEnd===e.rowEnd&&(t.colStart===e.colStart&&t.colEnd===e.colEnd&&(t.$rowStart===e.$rowStart&&t.$rowEnd===e.$rowEnd&&(t.$colStart===e.$colStart&&t.$colEnd===e.$colEnd)))),Xf=(t,e)=>{if(!t)return;const n={...t};return e?"boolean"==typeof e?(n.$colStart=e,n.$rowStart=e,n.$colEnd=e,n.$rowEnd=e,n):("boolean"==typeof e.colStart&&(n.$colStart=e.colStart),"boolean"==typeof e.rowStart&&(n.$rowStart=e.rowStart),"boolean"==typeof e.colEnd&&(n.$colEnd=e.colEnd),"boolean"==typeof e.rowEnd&&(n.$rowEnd=e.rowEnd),n):n};class Kf{constructor(e,n,r){const o=this;this.setState=t=>{const e=t[0];let r=t[1],o=t[2];if(n&&n.includeMergeOverflow&&o&&o.merge){const t=n.bounds,s=o.merge.getCoords();let i=!1;const a=s.colStart,l=s.rowStart,c=t.colStart,h=t.rowStart,u=e.colIndex,d=e.rowIndex;!i&&a<c&&l>=h&&u===c&&d===l&&(i=!0),!i&&l<h&&a>=c&&d===h&&u===a&&(i=!0),!i&&l<h&&a<c&&d===h&&u===c&&(i=!0),i&&(r=o.merge.tvTl(),o=o.merge.rsTl())}o&&0===Object.keys(o).length&&(o=null);let s=r;return void 0===r?(this._t=null,this._v=null,s=null):(this._t=Kh(s),this._v=s),this._r=o,this._p=t[3],this._n=t[4],this._c=e,s},this.clear=()=>{o._c=null},this.context={getCoords(){const t=o._c;if(!t)throw new Error(Rd);return t},getCell(){const t=o._c;if(!t)throw new Error(Rd);if(this.excludeCellDetails)throw new Error("IteratorContext can only return a cell if the forEach excludeCellDetails has not been set to false.");const e=o._r,n=o._t,s=o._v;return null!==s||e?new Cf(r,t,n,s,e,o._p,o._n):new Cf(r,t)},getType:()=>o._t,getA1(t){if(!o.context)throw new Error(Rd);let e=o._c;return t&&(e={...o._c,...t}),r.resolveRange(e).toString()},toJSDate(e){if(o._t!==t.Number)return null;let n=e;if(void 0===n)n=o._v;else if("number"!=typeof n)throw new Error("The arguments are not valid.");return ys(n,r.date1904)}}}}const Yf=(t,e)=>{if(t||e)return t&&e?{...t,...e}:t||e},Zf=(t,n,r,o=e.Orientation.Row)=>{const s=t.getRange(n,{excludeHidden:o}),i=s.forEach((t,e)=>({break:e.getCoords()}),{excludeCellDetails:!0,orientation:o});if(!i)return;const a=o===e.Orientation.Row,l=new Map,c=new Map,h=new Map;let u=null;const d=t.getRange(i).getMerges();let g=d.length>0?1+(a?d[0].rowEnd-d[0].rowStart:d[0].colEnd-d[0].colStart):1;const m=a?i.rowIndex:i.colIndex;if(s.forEach((t,e)=>{const n=e.getCoords(),r=a?n.colIndex:n.rowIndex,o=a?n.rowIndex:n.colIndex;if(o===m)l.set(r,t);else{if(o!==m+g)return ud;"string"==typeof t?u=!1:null!==t&&c.set(r,t)}if(null!=u)return ud},{orientation:o,excludeCellDetails:!0,address:n}),null===u){const t=c.entries();let e=t.next();for(;null===u&&!e.done;){const[n,r]=e.value,o=l.get(n);o&&("string"==typeof o?h.set(n,o):u=!1),e=t.next()}u=u??h.size>0}const f={colStart:i.colIndex,rowStart:i.rowIndex,colEnd:n.colEnd,rowEnd:n.rowEnd};if(f.colStart>f.colEnd||f.rowStart>f.rowEnd||W.isSingleCell(f))return null;const p=Math.min(Math.max(r?.colIndex??0,f.colStart),f.colEnd),_=Math.min(Math.max(r?.rowIndex??0,f.rowStart),f.rowEnd);return{coords:f,options:{...Pl.DefaultRangeOptions,hasHeader:u,orientation:o,offset:o===e.Orientation.Row?p-f.colStart:_-f.rowStart},headers:h}},Qf=(e,n,o=null)=>Wl.fromArray(e,(e,o)=>{const s=e?.[1];if(null==s)return null;let i=e[0]??null;switch(s){case t.String:i=n.getById(i);break;case t.Error:i=r.getBuiltInById(i)}return i},(e,r)=>{const o=Kh(e);let s=e;switch(o){case t.String:s=n.add(s);break;case t.Error:s=s.getCode()}return[s,o]},o),tp=(t,n)=>{const r=[],o=n?e.Orientation.Column:e.Orientation.Row,s=t.length;for(let e=0;e<s;e++){const s=t[e],i=s[0],a=s[1],l=a.length;for(let t=0;t<l;t++){const e=a[t],s=e[0],l=e[1].length-1,c={colStart:n?i:s,rowStart:n?s:i,colEnd:n?i:s+l,rowEnd:n?s+l:i,value:new id({colStart:n?i:s,rowStart:n?s:i,colEnd:n?i:s+l,rowEnd:n?s+l:i},o)};r.push(c)}}return r},ep=(t,e,n=-1)=>{if(!t||0===t.length)return null;const r=1===t.length&&t[0].rowStart===t[0].rowEnd&&t[0].colStart===t[0].colEnd,o=-1===n?t.length-1:Math.min(Math.max(0,n),t.length-1);return{cell:e??{rowIndex:t[o].rowStart,colIndex:t[o].colStart},ranges:r?[]:[...t],rangeIndex:r?-1:o}},np=t=>{if(!t)return null;const e=[];if(t.ranges&&t.ranges.length>0){const n=Math.max(0,Math.min(t.rangeIndex??0,t.ranges.length));for(let r=n;r<t.ranges.length;r++)e.push(t.ranges[r]);for(let r=0;r<n;r++)e.push(t.ranges[r])}else t.cell&&e.push(W.cellToRange(t.cell));return e},rp=(t,e)=>{if(!t||0===t.length)return null;let n=t.length-1;const r=t[n],o=t[0];if(!o||!o)return null;const s=1===t.length&&o.rowStart===o.rowEnd&&o.colStart===o.colEnd;return r?{cell:{rowIndex:r.rowStart,colIndex:r.colStart},ranges:s?[]:[...t],rangeIndex:s?-1:n}:null},op="Item has been closed. No further operations are allowed.";class sp{constructor(t){if(this._emitter=null,this._closed=!1,!t)throw new Error("Anchored.ConstructorOptions is required");if(this._options={...t},!this._options.initialAnchor)throw new Error("Initial anchor is required");const e=this;this._transactions=this._options.transactions??new ie({transient:!0}),this._emitter=new Ll(this,this._transactions),this._updateState({anchor:this._options.initialAnchor},{description:t?.createDescription??"Create Anchored Item"}),this._options.setContainerShiftCallback?.(t=>e._processContainerShift(t)),this._options.setContainerLayoutCallback?.(()=>{e._processContainerLayout()}),this._options.setContainerDeleteCallback?.(()=>{e._processContainerDelete()}),this._options.setContainerProtectionCallback?.(()=>{e._processContainerProtection()}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onBeforeCommitStart(t,n,r){e._processBeforeCommitStart(t,n,r)},onAfterStateChange(t,n,r){e._processStateChange(t,n,r),e._processAnchorCoords(),e._emitter.notify("onAnchorCoordsChange")},onRestoreOrRevert(t,n,r){e._processRestoreOrRevert(t,n,r)}})}_getEmitter(){return this._emitter}delete(t){this._options.deleteFromContainer?.(t)}getAnchorCoords(){return this._getState()?.anchor??null}getAnchorType(){return this._getState()?.anchorType??Fl.Type.TwoCell}isProtected(){return this._options.isProtected?.()??!1}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(op);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_getTransactions(){return this._transactions}_updateState(t,e,n){if(this._closed)throw new Error(op);if(!t)return;const r=this._beginCommit(e?.description);try{r.updateState(this,t);let e=!1;if(n)for(let t=0;t<n.length;t++){const r=n[t];e=e||"onAnyChange"===r,this._emitter.notify(r)}!e&&n&&n.length>0&&this._emitter.notify("onAnyChange"),r.commit()}catch(t){throw r.rollback(),t}return this}_processContainerShift(t){let e=null;const n={anchor:t.after};return t.after||(n.isDeleted=!0,e=["onDelete"]),this._updateState(n,{description:"Update Anchor"},e),t.after}_processBeforeCommitStart(t,e,n){}_processStateChange(t,e,n){}_processRestoreOrRevert(t,e,n){this._emitter.notify("onInvalidated")}_processAnchorCoords(){}_processContainerLayout(){}_getDescription(){return null}_delete(){const t=this._getDescription(),e="Delete",n=t?`${e} ${t}`:e,r=this._beginCommit(n);try{this._processDelete(),r.commit()}catch(t){throw r.rollback(),t}}_processContainerDelete(){this._processDelete()}_processDelete(){}_processContainerProtection(){this._emitter.notify("onProtectedChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}_processClose(){this._closed=!0,this._emitter.notify("onClose"),this._transactionsRemoveListener?.()}close(){this._closed||this._processClose()}get isIAnchored(){return!0}}var ip,ap;(ap=ip||(ip={})).fastStringToCol=Hu,ap.fastStringToCell=zu,ap.fastStringToRange=Vu,ap.rangeToString=Au,ap.cellToString=Cu,ap.normalizeA1ToR1C1=Qu,ap.resolveRelativeToA1=Xu;const lp=(t,e)=>t.offset-e.offset,cp=t=>{if(!t||0===t.size)return[];let e=[];return t.forEach((t,n)=>{t&&0!==Object.keys(t).length&&e.push({...t,offset:n})}),e.sort(lp)};class hp extends sp{constructor(t){super({...t,createDescription:"Insert AutoSort"}),this._apply=t.apply,this._processUpdate=t.processUpdate,this._fromJSON(t.json)}getRange(){return this._getState().anchor}getFieldAt(t){const e=this._getState().byOffset.get(t)??null;if(!e)return null;return 0===Object.keys(e).length||1===Object.keys(e).length&&e.hasOwnProperty("offset")?null:{collatorOptions:null,...e}}insertSort(){return null}getSort(){return null}apply(t){const e=this._getState().byOffset,n=new Map(e);for(let e=0;e<t.length;e++){const r={...t[e]},o=r.offset;delete r.offset,n.set(o,r)}return this._updateState({byOffset:n},{description:"Set Sort Criteria"}),this.reapply()}setFieldAt(t,e){const n=this._getState().byOffset,r=new Map(n);return e&&Object.keys(e).length>0?r.set(t,e):r.delete(t),this._updateState({byOffset:r},{description:"Sort"}),this.reapply()}_processStateChange(t,e,n){super._processStateChange(t,e,n),this._processUpdate?.()}reapply(){const t=this._getState(),e=cp(t.byOffset);return this._apply?.(e),this}clear(){return this._updateState({byOffset:new Map},{description:"Clear Sort"}),this.reapply()}_fromJSON(t){const e=t??{},n={byOffset:new Map};if(e.fields)for(let t=0;t<e.fields.length;t++){let r=e.fields[t];const o=r.offset;r={...e.fields[t]},delete r.offset,n.byOffset.set(o,r)}this._updateState(n,{description:"Load"})}toJSON(){const t={},e=this._getState();e.anchor&&(t.ref=ip.rangeToString(e.anchor,this._options.maxRangeCoords));const n=cp(e.byOffset);return n.length>0&&(t.fields=n),0===Object.keys(t).length?null:t}}const up=(t,e)=>t.offset-e.offset,dp=t=>{if(!t||0===t.size)return[];let e=[];return t.forEach((t,n)=>{t&&0!==Object.keys(t).length&&e.push({...t,offset:n})}),e.sort(up)},gp=(t,e=new Map)=>{if(!t||0===t.length)return e;for(let n=0;n<t.length;n++){const r={...t[n]},o=r.offset;delete r.offset,e.set(o,r)}return e},mp=t=>{let e=0;const n=t.entries();let r=null;do{r=n.next(),r.value?.[1]&&r.value[1].hiddenButton&&e++}while(!r.done);return e};class fp extends sp{constructor(t){super({...t,createDescription:"Insert AutoFilter"}),this._apply=t.apply,this._processUpdate=t.processUpdate,t.setFilterCoordsCallback?.(t=>{this._getState().anchor}),this._fromJSON(t.json)}getCoords(){return this._getState().anchor}getFieldAt(t){const e=this._getState().byOffset.get(t)??null;if(!e)return null;return 0===Object.keys(e).length||1===Object.keys(e).length&&e.hasOwnProperty("offset")?null:{hiddenButton:!1,criteria:_t.EmptyArray,...e}}insertSort(){return null}getSort(){return null}apply(t){const e=this._getState().byOffset,n=new Map(e);return gp(t,n),this._updateState({byOffset:n,hiddenCount:mp(n)},{description:"Set Filter Criteria"}),this.reapply()}setFieldAt(t,e){const n=this._getState(),r=n.anchor.colEnd-n.anchor.colStart+1;if(t<0||t>r-1)throw new Error(`Invalid range: '${t}'`);const o=n.byOffset,s=new Map(o);e&&Object.keys(e).length>0?s.set(t,e):s.delete(t);const i=!0===o.get(t)?.hiddenButton?1:0,a=!0===e?.hiddenButton?1:0;return this._updateState({byOffset:s,hiddenCount:Math.min(r,Math.max(0,n.hiddenCount+a-i))},{description:"Set Filter Criteria"}),this.reapply()}getShowFilterButton(){const t=this._getState(),e=t.anchor,n=e.colEnd-e.colStart+1;return t.hiddenCount<n}setShowFilterButton(t){const e=this.getAnchorCoords(),n=e.colEnd-e.colStart+1;let r=Array(n);const o=this._getState().byOffset,s=dp(o);for(let e=0;s&&e<s.length;e++){const n={...s[e]};r[n.offset]=n,t?delete n.hiddenButton:n.hiddenButton=!0}if(!t)for(let t=0;t<r.length;t++)r[t]||(r[t]={hiddenButton:!0});const i=new Map;for(let t=0;t<r.length;t++){const e=r[t];i.set(t,e)}return this._updateState({byOffset:i,hiddenCount:t?i.size:0},{description:(t?"Hide":"Show")+" Filter Buttons"}),this._processUpdate?.(),this}_processStateChange(t,e,n){super._processStateChange(t,e,n),this._processUpdate?.()}_processContainerShift(t){if(t.after&&t.orientation===e.Orientation.Column){let e=t.intersect.colStart-t.before.colStart,n=t.amount;e<=0&&(n-=e,e=0);const r=this._getState().byOffset,o=new Map(r);if(r.forEach((t,r)=>{t&&0!==Object.keys(t).length&&(r>=e&&o.delete(r),r>e&&o.set(r+n,t))}),n>0&&this._getState().hiddenCount>0)for(let t=e;t<e+n;t++)o.set(t,{hiddenButton:!0});this._updateState({byOffset:o,hiddenCount:mp(o),sort:null},{description:"Update Fields"})}return super._processContainerShift(t)}reapply(){const t=this._getState(),e=dp(t.byOffset);return this._apply?.(e),this}clear(){return this._updateState({byOffset:new Map,hiddenCount:0,sort:null},{description:"Set Filter Criteria"}),this.reapply()}_fromJSON(t){const e=t??{},n={byOffset:new Map,hiddenCount:0};e.fields&&(gp(e.fields,n.byOffset),n.hiddenCount=mp(n.byOffset)),e.sort,this._updateState(n,{description:"Load"})}toJSON(){const t={},e=this._getState();e.anchor&&(t.ref=Au(e.anchor,this._options.maxRangeCoords));const n=dp(e.byOffset);return n.length>0&&(t.fields=n),e.sort,0===Object.keys(t).length?null:t}}const pp="A table must have a least one row for the data.",_p="Table1",Sp=Object.freeze({showRowStripes:!0,showColumnStripes:!1,showFirstColumn:!1,showLastColumn:!1}),wp=(t,e,n)=>{if(t.length!==e.length)return console.warn("make columns the same length"),!1;const r=new Set;for(let t=0;t<e.length;t++){const n=e[t]?.name;n&&r.add(n.toLocaleLowerCase())}for(let t=0;n&&t<n.length;t++){const e=n[t]?.name;e&&r.add(e.toLocaleLowerCase())}const o=(t,e="")=>{if(!t)return!1;const n=t.toLocaleLowerCase();return n===e||!r.has(n)};let s=1;const i=(t,e,n,r,o=1e3)=>{if(r(t,n=(n??"").trim().toLocaleLowerCase()))return t;for(;s<o;)try{const t=e+ ++s;if(r(t,n))return t}catch(t){}throw new Error(`Unable to find valid name for '${e}'.`)};let a=0;for(let n=0;n<t.length;n++){const s=t[n]?.name;if(s&&s===e[n]?.name)continue;const l=i(s,t[n]?.name||"Column",e[n]?.name,o);r.add(l.toLocaleLowerCase()),e[n]?.name!==l&&(t[n].name=l,a++)}return a>0};class yp{constructor(t,e,n,r){this._name=t,this._filter=e,this._sort=n,this._offset=r}getName(){return this._name}getField(){return this._filter?this._filter.getFieldAt(this._offset)??null:null}setField(t){return this._filter?(this._filter.setFieldAt(this._offset,t),this):this}getSortField(){return this._sort?this._sort.getFieldAt(this._offset):null}setSortField(t){return this._sort?(this._sort.setFieldAt(this._offset,t),this):this}reapply(){return this._filter?.reapply(),this}clear(){return this._filter?.setFieldAt(this._offset,null),this._sort?.setFieldAt(this._offset,null),this}hasHiddenButton(){return this._filter?.getFieldAt(this._offset)?.hiddenButton??!1}}class Ep extends Bl{constructor(t,e,n,r){super({...r,type:"namedTable"}),this._names=t,this._sheet=e,this._table=n;const o=this;this._table.addListeners({onDelete:()=>{o._options.deleteFromContainer?o._options.deleteFromContainer?.():o._delete()},onAnyChange:()=>{o._emitter.notify("onAnyChange")},onAnchorCoordsChange:()=>{o._emitter.notify("onAnyChange")}},{transactional:!0})}async select(t){return await this._table.select(t),this}getRanges(){return this._names.getRanges(this._table.getUsedRange())}getScope(){return null}getType(){return"table"}getName(){return this._table.getName()}getValue(){return this._table}}class bp extends sp{constructor(t){if(super({...t,createDescription:"Insert Table"}),this._isUpdatingHeader=!1,this._colHeadersSizeUnlistener=null,this._rowHeadersSizeUnlistener=null,this._visibleRange=null,this._isHeaderVisible=!0,this._isTotalVisible=!0,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0,this._range=null,!t.json)throw new Error("json is required");if(!t.json.ref)throw new Error("json.ref is required");const e=this;this._styles=t.styles??t.sheet?.getStyles()??new Fp,this._names=t.names,this._sheet=t.sheet,this._processTableUpdate=t.processTableUpdate,this._setNameOnContainer=t.setNameOnContainer,this._options={...t},this._styleCache=null,this._stylePropsCache=null,this._stylesRemoveListener=this._styles.addListeners({onTableStylesChange(){e._styleCache=null,e._stylePropsCache=null,e._getEmitter().notify("onStyleChange"),e._getEmitter().notify("onAnyChange")}});const n={...t?.json};if(t.sheet){const r=t.sheet;if(this._autoExpandRemoveListener=r.getEntireRange().addListener(t=>{if("setCells"!==t.trigger)return;if(t.isUndo)return;const n=e.getAnchorCoords();if(!n)return;let o=t.getSource().getCoords();Array.isArray(o)&&(o=o[0]);let s=null;if(o.rowStart>=n.rowStart&&o.rowEnd<=n.rowEnd&&o.colStart>=n.colStart&&o.colStart<=n.colEnd+1&&o.colEnd>n.colEnd){const t={...o,colStart:n.colEnd+1};if(r.getRange(t).isContentful()){const e={...t,rowStart:n.rowStart,rowEnd:t.rowStart-1};if(e.rowEnd-e.rowStart<0||!r.getRange(e).isContentful()){const e={...t,rowStart:t.rowEnd+1,rowEnd:n.rowEnd};(e.rowEnd-e.rowStart<0||!r.getRange(e).isContentful())&&(s={...n,colEnd:o.colEnd})}}}else if(!e.getShowTotals()&&o.colStart>=n.colStart&&o.colEnd<=n.colEnd&&o.rowStart>=n.rowStart&&o.rowStart<=n.rowEnd+1&&o.rowEnd>n.rowEnd){const t={...o,rowStart:n.rowEnd+1};if(r.getRange(t).isContentful()){const e={...t,colStart:n.colStart,colEnd:t.colStart-1};if(e.colEnd-e.colStart<0||!r.getRange(e).isContentful()){const e={...t,colStart:t.colEnd+1,colEnd:n.colEnd};(e.colEnd-e.colStart<0||!r.getRange(e).isContentful())&&(s={...n,rowEnd:o.rowEnd})}}}if(s&&r.getRange(s).getMerges().length>0&&(s=null),s&&1!==r.getTables().search({address:s}).length&&(s=null),s){const t=e._beginCommit("Table Auto Expansion");try{e.resize(s),t.commit({viewAfter:null})}catch(e){t.rollback(),console.warn("Unable to AutoExpand"),console.warn(e)}}},{transactional:!1,ignoreShifts:!0}),this._headerValueListener=()=>{if(this._isUpdatingHeader)return;const t=this._columnsFromSheet();t&&this._updateColumns(t.columns,!1,t.forceUpdate,null)},t.readSheetHeader){const t=this._columnsFromSheet();n.columns=t.columns}const o=()=>{const t=this.getAnchorCoords();let e=0,n=0;if(t&&(e=r.getColumnHeaders().findVisibleIndex(t.colEnd).min,n=r.getRowHeaders().findVisibleIndex(t.rowEnd).min),t&&(e<t.colEnd||n<t.rowEnd)){const o=r.getColumnHeaders(),s=r.getRowHeaders(),i=o.findVisibleIndex(t.colStart).max,a=s.findVisibleIndex(t.rowStart).max;this._visibleRange={colStart:i,colEnd:e,rowStart:a,rowEnd:n},this._isHeaderVisible=!s.at(t.rowStart).isHidden(),this._isTotalVisible=!s.at(t.rowEnd).isHidden(),this._isFirstColumnVisible=!o.at(t.colStart).isHidden(),this._isLastColumnVisible=!o.at(t.colEnd).isHidden()}else this._visibleRange=null,this._isHeaderVisible=!0,this._isTotalVisible=!0,this._isFirstColumnVisible=!0,this._isLastColumnVisible=!0},s={onSizesChange:()=>{o()}};this._colHeadersSizeUnlistener=r.getColumnHeaders().addListeners(s),this._rowHeadersSizeUnlistener=r.getRowHeaders().addListeners(s),o()}this._fromJSON(n),this._names&&(this._namedItem=this._createNamed(),this._namedItem&&this._names.add(this._namedItem))}getSnapshot(t){const e=this.toJSON(),n=this.getAnchorCoords(),r=this.getName(),o={...e};delete o.ref;const s=this,i=Object.freeze({...t});let a=!1;return{async copyTo(t,e){const r=t.tables,l=t.range;({...i,...e}).isCut&&!a&&(s.delete(),a=!0);const c={colStart:l.colStart,rowStart:l.rowStart,colEnd:n.colEnd-n.colStart+l.colStart,rowEnd:n.rowEnd-n.rowStart+l.rowStart};return r.add(c,{json:o,isLoad:!0,hasHeader:!0,styleName:o.styleOptions?.name??null}),c},getCoords:()=>n,getSource:()=>s,getName:()=>r,getMarkOptions:()=>i,isISnapshot:!0}}getAnchorType(){return Fl.Type.TwoCell}getStyle(){if(this._styleCache)return this._styleCache;const t=this._getState();return t?(this._styleCache=this._styles.getTableStyle(t.styleOptions.name)??this._styles.getDefaultTableStyle(),this._styleCache):this._styles.getTableStyle(null)}addRows(t,e=1){const n={...this._getState().anchor};return n.rowEnd+=e,this._modifyTable({anchor:n},"Add Table Row"+(e>1?"s":"")),this}deleteRowsAt(t,e=1){let n={...this._getState().anchor};return n.rowEnd-=e,n.rowEnd<n.rowStart&&(n=null),this._modifyTable({anchor:n},"Delete Table Row"+(e>1?"s":"")),this}addColumn(t,e){const n=this._getState(),r={...n.anchor};r.colEnd+=1;const o=[];const s={name:`${e??n.columns[t-1]?.name??`Column${t+1}`}3`};o.push(s);const i=[...n.columns.slice(0,t),...o,...n.columns.slice(t)];return this._modifyTable({anchor:r,columns:i},"Add Table Column"),s}getColumns(){return this._getState()?.columns}convertToRange(t=Number.MAX_SAFE_INTEGER){let n=this._beginCommit("Convert to Range");try{if(this._sheet){const n=this.getAnchorCoords(),r=(n.colEnd-n.colStart+1)*(n.rowEnd-n.rowStart+1);if(r>t)throw new Error(`There are ${r} and there is a limit of ${t}.`);const o=this._sheet.getRange(n),s=o.startIncrementalUpdates({orientation:e.Orientation.Column});o.forEach((t,e)=>{const n=e.getCoords(),r=e.getCell();s.pushAt(n.rowIndex,n.colIndex,{style:r.getStyle(!1)})},{includeEmpty:!0,orientation:e.Orientation.Column}),s.apply()}this.delete()}catch(t){n.rollback(),n=null}return n&&n.commit(),this._sheet.getRange(this._getState()?.anchor)}resize(t,e="Resize Table"){let n=this._sheet.getRange(t).getCoords();const r=this._getState().anchor;if(r.rowStart!==n.rowStart||n.colEnd<r.colStart||n.colStart>r.colEnd)throw new Error("The top of the table must not change and the new table location must overlap with the original table.");const o=this._beginCommit(e);try{n=this._options.setContainerCoords(t),W.isEqualRanges(n,r)||this._modifyTable({anchor:n}),o.commit()}catch(t){throw console.warn(t),o.rollback(),t}return this._sheet.getRange(n)}getName(){return this._getState()?.name}setName(t){const e=this._beginCommit(`Set Table Name '${t}'`);try{this._modifyTable({name:t}),e.commit()}catch(t){throw e.rollback(),t}return this}getDescription(){return this._getState()?.description}setDescription(t){return this._modifyTable({description:t})}select(t){return this.getUsedRange().select(t)}getRange(){return this._range?this._range:this._getState()?this._range=this._sheet.getRange(this._getState().anchor):Hf}_processRestoreOrRevert(t,e,n){this._styleCache=null,super._processRestoreOrRevert(t,e,n)}_processAnchorCoords(){this._range=null,super._processAnchorCoords()}getUsedRange(){const t=this._getUsedCoords();return t?this._sheet.getRange(t):Hf}_getUsedCoords(){const t=this._getState(),e=t.headerRowCount,n=t.totalsRowCount,r=t.anchor;if(!r)return null;const o={...r,rowStart:r.rowStart+e,rowEnd:r.rowEnd-n};return o.rowEnd<o.rowStart||o.colEnd<o.colStart?null:o}getHeaderRange(){const t=this._getHeaderCoords();return t?this._sheet.getRange(t):Hf}_getHeaderCoords(){const t=this._getState(),e=t.headerRowCount;if(e<1)return null;const n=t.anchor;return n?{...n,rowEnd:n.rowStart+e-1}:null}getTotalRange(){const t=this._getTotalCoords();return t?this._sheet.getRange(t):Hf}_getTotalCoords(){const t=this._getState(),e=t.totalsRowCount;if(e<1)return null;const n=t.anchor;return n?{...n,rowStart:n.rowEnd-e+1}:null}getStyleOptions(){return this.isClosed()?Sp:this._getState()?.styleOptions}updateStyleOptions(t,e="Update Style Info"){const n=this.getStyleOptions(),r=t?{...n,...t}:Sp;return this._modifyTable({styleOptions:r},e),this._styleCache=null,this._getEmitter().notify("onStyleChange"),this}getStyleAt(t){let e=this._stylePropsCache;return e||(e=this.getStyle().getRanged(this),this._stylePropsCache=e),rf(this._styles,e,W.cellToRange(t))}getShowTotals(){const t=this._getState()?.totalsRowCount;return t>0}setShowTotals(t){return this._modifyTable({totalsRowCount:t?1:0},"Toggle Show Totals")}getShowHeaders(){const t=this._getState()?.headerRowCount;return t>0}setShowHeaders(t){return this._modifyTable({headerRowCount:t?1:0},"Toggle Show Headers")}getShowFilterButton(){const t=this.getFilter();return!!t&&t.getShowFilterButton()}setShowFilterButton(t){const e=this.getFilter();return e?(e.setShowFilterButton(t),this):this}_applyFilterAndSort(){console.log("apply Filter",this.getFilter(),this.getSort()),this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_processUpdate(){this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_createFilter(t){const e=this;return new fp({initialAnchor:this._getUsedCoords(),maxRangeCoords:this._options.maxRangeCoords,json:t,transactions:this._getTransactions(),setContainerShiftCallback(t){e._filterShiftCallback=t},setFilterCoordsCallback(t){e._filterCoordsCallback=t},deleteFromContainer:t=>{this._updateState({filter:null},{description:t?.description??"Delete Filter"}),e._processUpdate?.()},apply:t=>{e._applyFilterAndSort()},processUpdate:()=>{e._processUpdate?.()},isProtected:()=>e.isProtected()})}insertFilter(){let t=this.getFilter();return t||(t=this._createFilter(),this._updateState({filter:t},{description:"Insert Filter"}),t)}getFilter(){return this._getState()?.filter??null}_createSort(t){const e=this;return new hp({initialAnchor:this._getUsedCoords(),maxRangeCoords:this._options.maxRangeCoords,json:t,transactions:this._getTransactions(),deleteFromContainer:t=>{this._updateState({sort:null},{description:t?.description??"Delete Sort"}),e._processUpdate?.()},apply:t=>{e._applyFilterAndSort()},processUpdate:()=>{e._processUpdate?.()},isProtected:()=>e.isProtected()})}insertSort(){let t=this.getSort();return t||(t=this._createSort(),this._updateState({sort:t},{description:"Insert Sort"}),t)}getSort(){return this._getState()?.sort??null}getColumnFilter(t){const e=this.getFilter();if(!e)return null;const n=this.getSort();let r=null;return r=this._getState()?.columns[t],null===r?null:new yp(r.name,e,n,t)}getVisibleRefRangeCoords(){return this._visibleRange?this._visibleRange:this.getAnchorCoords()}getVisibleCellCoords(t){return t&&this._visibleRange?{colIndex:Math.min(this._visibleRange.colEnd,Math.max(this._visibleRange.colStart,this._sheet.getColumnHeaders().findVisibleIndex(t.colIndex).min)),rowIndex:Math.min(this._visibleRange.rowEnd,Math.max(this._visibleRange.rowStart,this._sheet.getRowHeaders().findVisibleIndex(t.rowIndex).min))}:t}isHeaderVisible(){return this._isHeaderVisible}isTotalVisible(){return this._isTotalVisible}isFirstColumnVisible(){return this._isFirstColumnVisible}isLastColumnVisible(){return this._isLastColumnVisible}_columnsFromSheet(){const e=this._getHeaderCoords();if(!e||!this._sheet){const t=this.getAnchorCoords();return{columns:t?Array(t.colEnd-t.colStart+1).fill(null):[],forceUpdate:!0}}const n={columns:[],forceUpdate:!1};return this._sheet.getRange({...e,rowEnd:e.rowStart}).forEach((e,r)=>{const o=r.getCell();n.columns.push({name:o.toText()}),n.forceUpdate=n.forceUpdate||o.getType()!==t.String},{includeEmpty:!0}),n}_updateColumns(t,n,r=!1,o){if(this._isUpdatingHeader)return;const s=this._getHeaderCoords(),i=this._getUsedCoords(),a=[];if(i){const e=i.colEnd-i.colStart+1;for(let n=0;n<e;n++){const e=t[n];a.push({...e})}}let l=!1;const c=this._getState().columns;l=n?((t,e)=>{const n=new Set,r=t=>!!t&&!n.has(t.toLocaleLowerCase()),o=(t,e,n,r)=>r(t)?t:e+(n+1);let s=0;for(let i=0;i<t.length;i++){const a=o(t[i]?.name||e[i]?.name,t[i]?.name||"Column",s,r);n.add(a.toLocaleLowerCase()),t[i]?.name!==a&&(t[i].name=a,s++)}return s>0})(a,c):wp(a,c,o);if(!(r||c.length!==a.length||l))return;const h="Update Columns";this._isUpdatingHeader=!0;let u=this._beginCommit(h);try{if(this._updateState({columns:a},{description:h}),this._sheet&&s){const t=this._sheet.getEntireRange().startIncrementalUpdates({orientation:e.Orientation.Row});for(let e=0;e<a.length;e++){const n=a[e].name;t.pushAt(s.rowStart,s.colStart+e,n)}t.apply({textParser:!1})}}catch(t){u.rollback()}return u&&u.commit(),this._isUpdatingHeader=!1,a}_processDelete(){const t=this._getState();t.headerRemoveListener?.(),this._updateState({headerRemoveListener:null}),super._processDelete()}_processFilterUpdate(){const t=this._getUsedCoords();console.log("process on Filter and Sort dataRange",t)}_processContainerShift(t){if(t.isSplit)throw new Error("We can not partially insert or remove cells as this would split a table.");const n=this._getState();if(t.after&&t.after.rowStart+n.headerRowCount>=t.after.rowEnd+1)throw new Error(pp);const r=t.orientation===e.Orientation.Column;if(t.amount<0&&t.after&&!r){const e=this._getHeaderCoords();if(e&&t.intersect.rowStart<=e.rowEnd&&t.intersect.rowEnd>=e.rowStart)throw new Error("We can not remove rows that contain table headers. Remove the table header.")}const o=super._processContainerShift(t);if(r){let e=t.amount,n=t.intersect.colStart-t.before.colStart;if(n<=0&&e>0)return;n<0&&(e-=n,n=0);const r=this._getState()?.columns;let o=[...r],s=[],i=[];if(e>0){o.splice(n,0,...Array(e).fill(null)),s=[...o];const t=new Set;for(let e=0;e<r.length;e++)t.add(r[e]?.name?.toLowerCase().trim());const i=r[n-1],a=i?.name?.match(/\d+$/);let l=null,c=0;a&&(l=a.input.substring(0,a.index),c=parseInt(a[0]));for(let r=0;r<e;r++){let e={...i};s[n+r]=e;const o=l+(c+r+1);o&&!t.has(o.toLowerCase().trim())&&(e.name=o)}wp(s,o,null)}else s=o,i=s.splice(n,-e);this._updateState({columns:s},{description:"Process Columns"}),this._updateColumns(s,!1,!0,i)}else t.after||this._updateState({columns:[]},{description:"Process Columns"});return t.after||this._delete(),this._filterShiftCallback&&this._filterShiftCallback({...t,after:this._getUsedCoords()}),o}_modifyTable(t,n="Modify Table"){if(this.isClosed())throw new Error("Table has been closed. No further operations are allowed.");const r=this._getState(),o=r.anchor,s=r.headerRowCount,i=this._getHeaderCoords();let a=this._beginCommit(n);try{if(this._updateState(t),void 0!==t.name){if(!t.name)throw new Error("Table must have a name.");this._setNameOnContainer?.(t.name)}let l=t.anchor??null;if((void 0!==t.anchor||void 0!==t.headerRowCount||void 0!==t.totalsRowCount)&&void 0!==t.headerRowCount&&s!==t.headerRowCount)if(t.headerRowCount>s){const n=o.rowStart-(t.headerRowCount-s);this._sheet&&(n<this._options.maxRangeCoords.rowStart||this._sheet.getRange({...o,rowStart:n,rowEnd:o.rowStart-1}).isContentful())?(this._sheet.getRange({...o,rowStart:o.rowStart+t.headerRowCount,rowEnd:o.rowStart+t.headerRowCount}).insert(e.Orientation.Row),l={...o,rowEnd:o.rowEnd+(t.headerRowCount-s)}):l={...o,rowStart:o.rowStart+(s-t.headerRowCount)}}else i&&this._sheet&&this._sheet.doBatch(()=>{this._sheet.getRange(i).clear()},{}),l={...o,rowStart:o.rowStart+(s-(t.headerRowCount??s))};if(l){let e=r.columns;const s=void 0!==t.headerRowCount&&t.headerRowCount!==r.headerRowCount||void 0!==t.totalsRowCount&&t.totalsRowCount!==r.totalsRowCount,i=l.colStart!==o.colStart||l.colEnd!==o.colEnd;let a=[];if(i){const t=[...r.columns];l.colEnd>o.colEnd?t.splice(o.colEnd+1,0,...Array(l.colEnd-o.colEnd).fill(null)):l.colEnd<o.colEnd&&(a=t.splice(l.colEnd-1,o.colEnd-l.colEnd)),l.colStart<o.colStart?t.splice(0,0,...Array(o.colStart-l.colStart).fill(null)):l.colStart>o.colStart&&(a=a.concat(t.splice(0,l.colStart-o.colStart))),e=t}if(this._options.setContainerCoords?.(l),this._updateState({anchor:l,columns:e},{description:n}),!this._getUsedCoords())throw new Error(pp);if(i||s){const t=s?{columns:e,forceUpdate:!0}:this._columnsFromSheet();t&&(this._updateColumns(t.columns,!1,t.forceUpdate,a),this._processHeaderListener())}this._filterCoordsCallback?.(l)}void 0!==t.styleOptions&&(this._styleCache=null),this._getEmitter().notify("onAnyChange"),a.commit()}catch(t){throw a.rollback(),t}return this}addListeners(t,e){return this._emitter.addListeners(t,e)}_processStateChange(t,e,n){super._processStateChange(t,e,n),this._styleCache=null,this._stylePropsCache=null,this._processTableUpdate?.(),this._getEmitter().notify("onAnyChange")}_processHeaderListener(){const t=this._getState();if(t.headerRemoveListener?.(),this._sheet){let t=this._getHeaderCoords();if(!t){const e=this._getUsedCoords();t={...e,rowEnd:e.rowStart}}const e=this._sheet.getRange(t).addListener(this._headerValueListener,{transactional:!0});this._updateState({headerRemoveListener:e})}}toJSON(){const t={},e=this._getState();if(!e)return null;if(e.name&&(t.name=e.name),e.anchor&&(t.ref=Au(e.anchor,this._options.maxRangeCoords)),e.description&&(t.description=e.description),1!==e.headerRowCount&&(t.headerRowCount=e.headerRowCount),0!==e.totalsRowCount&&(t.totalsRowCount=e.totalsRowCount),e.columns&&(t.columns=[...e.columns]),e.styleOptions){const n=_t.diffValues(e.styleOptions,{...Sp,name:null});n&&(t.styleOptions=n)}if(e.filter){const n=e.filter.toJSON();n&&(t.filter=n,delete t.filter.ref)}return t}_createNamed(){const t=this._sheet?.getName();return t&&this._names?new Ep(this._names,this._sheet,this,{transactions:this._getTransactions(),json:{name:this.getName()}}):null}_fromJSON(t){const e=t??{},n={headerRowCount:1,totalsRowCount:0};var r;if(e.name&&(n.name=e.name),e.ref&&(e.ref=(r=e.ref)&&"string"==typeof r?Fu(r):r),this._names){const t=this._names.findValidName(n.name??_p);n.name!==t&&(n.name=t)}n.name||(n.name=_p),e.description&&(n.description=e.description),void 0!==e.headerRowCount&&(n.headerRowCount=e.headerRowCount),void 0!==e.totalsRowCount&&(n.totalsRowCount=e.totalsRowCount),n.columns=e.columns??_t.EmptyArray,n.styleOptions={...Sp,...e.styleOptions};const o="Insert Table";this._updateState(n,{description:o});const s=this._columnsFromSheet();s&&(n.columns=this._updateColumns(s.columns,!0,s.forceUpdate,null),delete n.columns),e.sort&&(n.sort=this._createSort(e.sort)),e.filter&&(n.filter=this._createFilter(e.filter)),this._modifyTable(n,o),this._processHeaderListener()}close(){super.close(),this.isClosed()||(this._autoExpandRemoveListener?.(),this._getState()?.headerRemoveListener?.(),this._updateState({headerRemoveListener:null},{description:"Close Table"}),this._stylesRemoveListener?.(),this._colHeadersSizeUnlistener?.(),this._rowHeadersSizeUnlistener?.())}get isITable(){return!0}}let vp=null;const Cp="TableStyleMedium2",xp=(t,e,n)=>{if(!t.border)return t;let r=((t,e,n)=>{if(!t)return t;let r=null;return(t.top||t.horizontal)&&(e.rowIndex!==n.rowStart||e.colIndex<n.colStart||e.colIndex>n.colEnd)&&(r=r??{...t},delete r.top,t.horizontal&&(r.top=t.horizontal)),(t.bottom||t.horizontal)&&(e.rowIndex!==n.rowEnd||e.colIndex<n.colStart||e.colIndex>n.colEnd)&&(r=r??{...t},delete r.bottom,t.horizontal&&(r.bottom=t.horizontal)),(t.left||t.vertical)&&(e.colIndex!==n.colStart||e.rowIndex<n.rowStart||e.rowIndex>n.rowEnd)&&(r=r??{...t},delete r.left,t.vertical&&(r.left=t.vertical)),(t.right||t.vertical)&&(e.colIndex!==n.colEnd||e.rowIndex<n.rowStart||e.rowIndex>n.rowEnd)&&(r=r??{...t},delete r.right,t.vertical&&(r.right=t.vertical)),t.horizontal&&(r=r??{...t},delete r.horizontal),t.vertical&&(r=r??{...t},delete r.vertical),r??t})(t.border,e,n),o=t;return r!==t.border&&(o={...t},Object.keys(r).length>0?o.border=r:delete o.border),o};class Ip{constructor(t,e,n){this._table=t,this._styles=e,this._properties=n}_resolveProperties(t){const e={name:t.name},n=this._styles,r=Object.values(Nl.ElementType),o=r.length;for(let s=0;s<o;s++){const o=r[s],i=t[o];if(!i||!_t.isObject(i))continue;const a=Mt.resolveTypedUpdates(Object.freeze(i),Nm,n);e[o]=a}return Object.freeze(e)}getCoords(){return this._table.getAnchorCoords()}getPropertiesAt(t,e){const n=this._table,r=this._styles,o=this._properties;Rp.rowIndex=t,Rp.colIndex=e;const s=n.getVisibleCellCoords(Rp),i=n.getVisibleRefRangeCoords();if(!i)return null;const a=Math.max(0,i.colEnd-i.colStart)+1,l=Math.max(0,i.rowEnd-i.rowStart)+1,c=Math.max(0,s.rowIndex-i.rowStart),h=Math.max(0,s.colIndex-i.colStart),u={rowIndex:c,colIndex:h},d=n.getStyleOptions();let g={},m=!1,f=0;n.isHeaderVisible()&&(f=n.getShowHeaders()?1:0,m=f>c);let p=!1,_=0;n.isTotalVisible()&&(_=n.getShowTotals()?1:0,p=l-_<=c);let S=h===a-1&&d.showLastColumn;n.isLastColumnVisible()||(S=!1);let w=0===h&&d.showFirstColumn;n.isFirstColumnVisible()||(w=!1);const y=!m&&!p;if(o.wholeTable&&(g=o.wholeTable,g.border&&(g=xp(g,u,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:a-1}))),y&&d.showColumnStripes){const t=o.firstColumnStripe?.size??1,e=o.secondColumnStripe?.size??1;let n=h%(t+e);const s=n<t;s||(n-=t);let i=s?o.firstColumnStripe:o.secondColumnStripe;if(i){const u={rowIndex:c,colIndex:n},d={rowStart:f,rowEnd:l-_-1,colStart:0,colEnd:Math.min(a-h,s?t:e)};s&&0===n&&h>0&&i.border?.left&&o.secondColumnStripe?.border.right&&(i={...i},i.border={...i.border},delete i.border.left),s&&n===t-1&&h<a-1&&i.border?.right&&o.secondColumnStripe?.border.left&&(i={...i},i.border={...i.border},delete i.border.right);const m=i.border?xp(i,u,d):i;g=Mt.resolveTypedUpdates(m,Nm,r,g)}}if(y&&d.showRowStripes){const t=f,e=o.firstRowStripe?.size??1,n=o.secondRowStripe?.size??1;let s=(c-t)%(e+n);const i=s<e;i||(s-=e);let u=i?o.firstRowStripe:o.secondRowStripe;if(u){const d={colIndex:h,rowIndex:s},m={colStart:0,colEnd:a-1,rowStart:0,rowEnd:Math.min(l-c,i?e:n)};i&&0===s&&c>t&&u.border?.top&&o.secondRowStripe?.border.bottom&&(u={...u},u.border={...u.border},delete u.border.top),i&&s===e-1&&c<l-1&&u.border?.bottom&&o.secondRowStripe?.border.top&&(u={...u},u.border={...u.border},delete u.border.bottom);const f=u.border?xp(u,d,m):u;g=Mt.resolveTypedUpdates(f,Nm,r,g)}}if(S&&o.lastColumn){let t=o.lastColumn;t.border&&(t=xp(t,u,{rowStart:0,rowEnd:l-1,colStart:a-1,colEnd:a-1})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(w&&o.firstColumn){let t=o.firstColumn;t.border&&(t=xp(t,u,{rowStart:0,rowEnd:l-1,colStart:0,colEnd:0})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(m&&o.headerRow){let t=o.headerRow;t.border&&(t=xp(t,u,{rowStart:0,rowEnd:f-1,colStart:0,colEnd:a-1})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(p&&o.totalRow){let t=o.totalRow;t.border&&(t=xp(t,u,{rowStart:l-_,rowEnd:l-1,colStart:0,colEnd:a-1})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(m&&w&&o.firstHeaderCell){let t=o.firstHeaderCell;t.border&&(t=xp(t,u,{rowStart:0,rowEnd:f-1,colStart:0,colEnd:0})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(m&&S&&o.lastHeaderCell){let t=o.lastHeaderCell;t.border&&(t=xp(t,u,{rowStart:0,rowEnd:f-1,colStart:a-1,colEnd:a-1})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(p&&w&&o.firstTotalCell){let t=o.firstTotalCell;t.border&&(t=xp(t,u,{rowStart:l-_,rowEnd:l-1,colStart:0,colEnd:0})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}if(p&&S&&o.lastTotalCell){let t=o.lastTotalCell;t.border&&(t=xp(t,u,{rowStart:l-_,rowEnd:l-1,colStart:a-1,colEnd:a-1})),g=Mt.resolveTypedUpdates(t,Nm,r,g)}return m&&o.headerRow&&n.getColumnFilter(h)&&!n.getColumnFilter(h).hasHiddenButton()&&(g.insets={right:15}),g}}class Ap{constructor(t,e,n,r){this._styles=t,this._isBuiltIn=n,this._doDelete=r,this._properties=_t.deepFreeze(this._resolveProperties(e)),this.isShownInTableStyles()}_resolveProperties(t){const e={name:t.name};void 0!==t.table&&(e.table=t.table),void 0!==t.pivot&&(e.pivot=t.pivot);const n=this._styles,r=Object.values(Nl.ElementType),o=r.length;for(let s=0;s<o;s++){const o=r[s],i=t[o];if(!i||!_t.isObject(i))continue;const a=Mt.resolveTypedUpdates(Object.freeze(i),Nm,n);e[o]=a}return Object.freeze(e)}delete(){if(!this._doDelete)throw new Error("Not able to delete builtin style.");this._doDelete(this._properties.name)}getRanged(t){return new Ip(t,this._styles,this._properties)}getProperties(){return this._properties}getName(){return this._properties.name}isShownInTableStyles(){return!1!==this._properties.table}isShownInPivotStyles(){return this._properties.pivot??!1}isBuiltIn(){return this._isBuiltIn}toJSON(){const t=_t.cloneObject(this._properties);return t.name=this._properties.name,t}get isITableStyle(){return!0}}const Rp={rowIndex:0,colIndex:0};class Mp extends af{constructor(t,e){super(t,W.EmptyRange,e)}isEmpty(){return null===this._p}getCoords(){return this._r}cloneWithUpdate(t){if(void 0===t)return this;const e=this._c,n=this._r,r=Mt.resolveTypedUpdates(t,Nm,e,this._p);return new af(e,n,r)}_createShifted(t){return new af(this._c,t,this._p)}getShifted(t){return t.after?{...t.after,value:this._createShifted(W.sanitizeRange(t.after))}:null}getSplit(t,e){const n=this._c,r=this._p;return[new af(n,t[0],r),new af(n,t[1],r)]}getMerged(t,e,n){const r=this._p,o=t._p;if(r&&!o||o&&!r||!r&&!o)return;let s=Object.keys(r),i=Object.keys(o);if(r.named===rl.BuiltInName.Normal&&(s=s.filter(t=>t.toLowerCase()!==rl.BuiltInName.Normal)),o.named===rl.BuiltInName.Normal&&(i=i.filter(t=>t.toLowerCase()!==rl.BuiltInName.Normal)),s.length!==i.length)return;for(let t=0;t<s.length;t++){const e=s[t],n=r[e],i=o[e];if(!_t.deepEqual(n,i))return}const a=this._c;return new af(a,e,this._p)}getPropertiesAt(t,e){return this._p}toJSON(){return _t.toSafeJSON(this._p)}}class Tp{constructor(t,e,n,r=null){this._name=e.name,this._properties=e,this._rangeStyle=new Mp(t,e.style),this._doDelete=n,this._builtInID=r}getRanged(){return this._rangeStyle}getName(){return this._name}isHidden(){return this._properties.hidden??!1}getILevel(){return this._properties.iLevel??null}getBuiltInID(){return this._builtInID}delete(){this._doDelete?.(this)}toJSON(){return this._properties?_t.toSafeJSON(this._properties):null}get isINamed(){return!0}}let Np=class{constructor(t,e,n,r,o){this._state=t,this._normalJSON=e??{},this._toJSONInternal=n,this._fromJSONInternal=r,this._onLastEnd=o,this._state.openScopes.add(this),this._isClosed=!1,this._state.byJSONs.set(At(this._normalJSON),0),this._state.byIds.set(0,this._normalJSON)}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}getElementID(t){if(this._isClosed)throw new Error("PersistScope is closed.");const e=At(t=t??{});let n=this._state.byJSONs.get(e);return void 0!==n||(n=this._state.byJSONs.size,this._state.byJSONs.set(e,n),this._state.byIds.set(n,t)),n}getElementJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");const e=JSON.parse(JSON.stringify(t||{}));this._fromJSONInternal(e);const n=e.direct;if(n)for(let t=0;t<n.length;t++){const e=t,r=n[t],o=At(r);this._state.byIds.set(e,r),this._state.byJSONs.set(o,e)}}toJSON(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byIds.forEach((e,n)=>{t[n]=e}),1===t.length&&t.splice(0,1),this._toJSONInternal(t)}};class Fp{constructor(t=null,e=null,n=11){this._emitter=null,this._normalRanged=null,this._theme=t??(new Tl).getDefaultTheme(),this._defaultFontSize=n;const r=this;this._emitter=new Ll(this),this._schemeLookup=t=>r._theme.schemeLookup()(t),this._indexedColors=this._fromJSONIndexedColors(e),this._indexedLookup=t=>{const e=this._indexedColors[t];return e?e.toRGBA():Vo(t)},this._initializeBuiltIns(),this._customCellStyles=new Map,this._customTableStyles=new Map,this._indexedColors=[],this._mruColors=[],this._persistCache=null}_initializeNamedStyles(t,e){for(let n=0;n<t.length;n++){const r=t[n],o={...r},s=r.named;delete o.named;const i=Mt.resolveTypedUpdates(o,Nm,this),a=new Tp(this,{name:s,style:i},this._hideOrRemoveNamed.bind(this),n);s===rl.BuiltInName.Normal&&(this._normalRanged=a.getRanged(),this._normalStyle=rf(this,null)),e.set(s.toLowerCase(),a)}}_initializeTableStyles(){const t=(()=>{if(vp)return vp;vp=new Map;const t=(t,e)=>{if(0===e)return"TableStyleNone";let n="Custom";return"l"===t?n="Light":"m"===t?n="Medium":"d"===t&&(n="Dark"),`TableStyle${n}${e}`},e=(t,e=0)=>0===e?t:e>0?`${t} lumMod ${100-e}, lumOff ${e}`:e<0?`${t} lumMod ${100+e}`:void 0,n=t=>({type:ya.Type.Pattern,patternType:ya.BuiltInSheetPattern.Solid,foreground:t,background:t}),r=(t,e=!1)=>{const n={fill:t};return e&&(n.weight=700),n},o=(t,e=Ba.StrokeStyle.Thin)=>({style:e,color:t}),s=(t,e)=>{for(let n=0;n<7;n++)t.push(e(`accent${n+1}`))};let i=0,a=[];a.push(["dk1",e("bg1",-15),"dk1"]),s(a,t=>[e(t,-25),e(t,80),t]),i=1;for(let e=0;e<7;e++){const s=t("l",e+i),l=a[e][0],c=a[e][1]??l,h=a[e][2]??l;vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),border:{top:o(h),bottom:o(h)}},headerRow:{font:r(l,!0),border:{bottom:o(h)}},totalRow:{font:r(l,!0),border:{top:o(h)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{fill:n(c)},firstColumnStripe:{fill:n(c)}}))}i+=7,a=[],a.push(["dk1","dk1","lt1"]),s(a,t=>["dk1",t,"lt1"]);for(let e=0;e<7;e++){const s=t("l",e+i),l=a[e][0],c=a[e][1],h=a[e][2];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),border:{left:o(c),right:o(c),top:o(c),bottom:o(c)}},headerRow:{font:r(h,!0),fill:n(c)},totalRow:{font:r(l,!0),border:{top:o(c,Ba.StrokeStyle.Double)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{border:{top:o(c)}},secondRowStripe:{border:{top:o(c)}},firstColumnStripe:{border:{left:o(c)}},secondColumnStripe:{border:{left:o(c)}}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15)]),s(a,t=>[t,e(t,80)]);for(let e=0;e<7;e++){const s=t("l",e+i),l="dk1",c=a[e][0],h=a[e][1];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),border:{left:o(c),right:o(c),top:o(c),bottom:o(c),horizontal:o(c),vertical:o(c)}},headerRow:{font:r(l,!0)},totalRow:{font:r(l,!0),border:{top:o(c,Ba.StrokeStyle.Double)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{fill:n(h)},firstColumnStripe:{fill:n(h)}}))}i=1,a=[],a.push(["dk1","dk1",e("bg1",-15)]),s(a,t=>[t,e(t,40),e(t,80)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c="lt1",h=a[e][0],u=a[e][1],d=a[e][2];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),border:{left:o(u),right:o(u),top:o(u),bottom:o(u),horizontal:o(u)}},headerRow:{font:r(c,!0),fill:n(h)},totalRow:{font:r(l,!0),border:{top:o(h,Ba.StrokeStyle.Double)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{fill:n(d)},firstColumnStripe:{fill:n(d)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35)]),s(a,t=>[t,e(t,80),e(t,60)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c="lt1",h=a[e][0],u=a[e][1],d=a[e][2];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),fill:n(u),border:{horizontal:o(c),vertical:o(c)}},headerRow:{font:r(c,!0),fill:n(h),border:{bottom:o(c,Ba.StrokeStyle.Thick)}},totalRow:{font:r(c,!0),fill:n(h),border:{top:o(c,Ba.StrokeStyle.Thick)}},firstColumn:{font:r(c,!0),fill:n(h)},lastColumn:{font:r(c,!0),fill:n(h)},firstRowStripe:{fill:n(d)},firstColumnStripe:{fill:n(d)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35)]),s(a,t=>[t,e(t,80),e(t,60)]);for(let s=0;s<7;s++){const l=t("m",s+i),c="dk1",h="lt1",u=a[s][0],d=e("bg1",-15);vp.set(l.toLocaleLowerCase(),Object.freeze({name:l,wholeTable:{font:r(c),border:{top:o(c,Ba.StrokeStyle.Medium),bottom:o(c,Ba.StrokeStyle.Medium),left:0===s?o(c,Ba.StrokeStyle.Thin):void 0,right:0===s?o(c,Ba.StrokeStyle.Thin):void 0,horizontal:0===s?o(c,Ba.StrokeStyle.Thin):void 0,vertical:0===s?o(c,Ba.StrokeStyle.Thin):void 0}},headerRow:{font:r(h,!0),fill:n(u),border:{bottom:o(c,Ba.StrokeStyle.Medium)}},totalRow:{border:{top:o(c,Ba.StrokeStyle.Double)}},firstColumn:{font:r(h,!0),fill:n(u)},lastColumn:{font:r(h,!0),fill:n(u)},firstRowStripe:{fill:n(d)},firstColumnStripe:{fill:n(d)}}))}i+=7,a=[],a.push(["dk1",e("bg1",-15),e("bg1",-35),"dk1"]),s(a,t=>[t,e(t,80),e(t,60),e(t,40)]);for(let e=0;e<7;e++){const s=t("m",e+i),l="dk1",c=a[e][0],h=a[e][1],u=a[e][2],d=a[e][3];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),fill:n(h),border:{top:o(d),right:o(d),left:o(d),bottom:o(d),vertical:o(d),horizontal:o(d)}},headerRow:{font:r(l),fill:n(h)},totalRow:{font:r(l),border:{top:o(c,Ba.StrokeStyle.Medium)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{fill:n(u)},firstColumnStripe:{fill:n(u)}}))}i=1,a=[],a.push(["dk1",e("dk1",15),e("dk1",25),e("dk1",50)]),s(a,t=>["dk1",e(t,-50),e(t,-25),t]);for(let e=0;e<7;e++){const s=t("d",e+i),l="lt1",c=a[e][0],h=a[e][1],u=a[e][2],d=a[e][3];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),fill:n(d)},headerRow:{font:r(l,!0),fill:n(c),border:{bottom:o(l,Ba.StrokeStyle.Medium)}},totalRow:{font:r(l,!0),fill:n(h),border:{top:o(l,Ba.StrokeStyle.Medium)}},firstColumn:{font:r(l,!0),fill:n(u),border:{right:o(l,Ba.StrokeStyle.Medium)}},lastColumn:{font:r(l,!0),fill:n(u),border:{left:o(l,Ba.StrokeStyle.Medium)}},firstRowStripe:{fill:n(u)},firstColumnStripe:{fill:n(u)}}))}i+=7,a=[],a.push([e("bg1",-15),"dk1",e("bg1",-35)]),a.push([e("accent1",80),"accent2",e("accent1",60)]),a.push([e("accent3",80),"accent4",e("accent3",60)]),a.push([e("accent5",80),"accent6",e("accent5",60)]);for(let e=0;e<4;e++){const s=t("d",e+i),l="dk1",c="lt1",h=a[e][0],u=a[e][1],d=a[e][2];vp.set(s.toLocaleLowerCase(),Object.freeze({name:s,wholeTable:{font:r(l),fill:n(h)},headerRow:{font:r(c,!0),fill:n(u)},totalRow:{font:r(l,!0),border:{top:o(l,Ba.StrokeStyle.Double)}},firstColumn:{font:r(l,!0)},lastColumn:{font:r(l,!0)},firstRowStripe:{fill:n(d)},firstColumnStripe:{fill:n(d)}}))}return vp})(),e=new Map;return t.forEach((t,n)=>{const r=t.name.toLowerCase(),o=new Ap(this,t,!0);e.set(r,o)}),e}_initializeBuiltIns(){const t=new Map;this._builtInsCellStyles=t,this._initializeNamedStyles(Hm,t),this._builtInsTableStyles=this._initializeTableStyles(),this._emptyTableStyle=new Nl.Empty(this._normalStyle)}getNormal(){return this._normalStyle}getNormalRanged(){return this._normalRanged}setTheme(t){this._theme=t,this._emitter.notify("onThemeChange"),this._emitter.notify("onAnyChange")}getTheme(){return this._theme}setDefaultFontSize(t){this._defaultFontSize=t,this._emitter.notify("onDefaultFontChange"),this._emitter.notify("onAnyChange")}getDefaultFontSize(){return this._defaultFontSize}beginPersist(){return this._persistCache||(this._persistCache={byIds:new Map,byJSONs:new Map,openScopes:new Set}),new Np(this._persistCache,{},this._toJSONInternal.bind(this),this._fromJSONInternal.bind(this),()=>{this._persistCache=null})}getNamed(t){if(!t)return null;t=t.toLowerCase();let e=null;return this._customCellStyles&&(e=this._customCellStyles.get(t)),e||(e=this._builtInsCellStyles.get(t)),e??null}getCustomNamed(){const t=Array.from(this._customCellStyles.values());return t.sort((t,e)=>t.getName().localeCompare(e.getName())),t}setNamed(t,e=!1){if(!t||!t.name||!t.style)throw new Lt;this.validateStyleName(t.name,!1);const n=this._setCustomCellStyleInternal(t,e);return this._emitter.notify("onNamedStylesChange"),this._emitter.notify("onAnyChange"),n}_setCustomCellStyleInternal(t,e=!1,n=0){const r=t.name.toLowerCase(),o=this._builtInsCellStyles.get(r),s=o?.getBuiltInID()??null;let i=null;if(e){const t=this._customCellStyles.get(r)??o;i=t?._properties??null}const a=$m(0,t.style,this.getNormal());t={...t,style:a};const l=Mt.resolveTypedUpdates(t,Fm,this,i),c=new Tp(this,l,this._hideOrRemoveNamed.bind(this),s);return l.name===rl.BuiltInName.Normal&&(this._normalRanged=c.getRanged(),this._normalStyle=rf(this,null)),this._customCellStyles.set(r,c),c}_setCustomTableStyleInternal(t,e){const n=t.toLowerCase();let r=this._customTableStyles.get(n)??this._builtInsTableStyles.get(n);r&&(t=r.getName());const o=new Ap(this,{...e,name:t},!1,this._deleteCustomTableStyle.bind(this));return this._customTableStyles.set(n,o),o}_hideOrRemoveNamed(t){let e=null;if(e="string"==typeof t?t:t?.getName?.(),!e)return!1;if(e=e.toLowerCase(),e===rl.BuiltInName.Normal.toLowerCase())return!1;const n=this._builtInsCellStyles.get(e);let r=!1;if(n&&!n.isHidden()){const t=n.toJSON();this.setNamed({...t,hidden:!0}),r=!0}else e=e.toLowerCase(),r=this._customCellStyles.delete(e);return r&&(this._emitter.notify("onNamedStylesChange"),this._emitter.notify("onAnyChange")),r}getTableStyle(t){if(!t)return this._emptyTableStyle;let e=this._customTableStyles.get(t.toLowerCase());return e||(e=this._builtInsTableStyles.get(t.toLowerCase())),e??null}getCustomTableStyles(){const t=Array.from(this._customTableStyles.values());return t.sort((t,e)=>t.getName().localeCompare(e.getName())),t}setDefaultTableStyle(t){const e=t?.toLowerCase();return this._defaultTableStyle=this._customTableStyles.get(e)??this._builtInsTableStyles.get(e)??this._builtInsTableStyles.get(Cp.toLowerCase()),this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),t===this._defaultTableStyle.getName()}getDefaultTableStyle(){return this._defaultTableStyle||(this._defaultTableStyle=this._builtInsTableStyles.get(Cp.toLowerCase())),this._defaultTableStyle}_deleteCustomTableStyle(t){const e=this._customTableStyles.get(t?.toLowerCase());return!!e&&(this._customTableStyles.delete(t.toLowerCase()),this._defaultTableStyle?.getName()===e.getName()&&(this._defaultTableStyle=this._builtInsTableStyles.get(Cp.toLowerCase())),this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),!0)}setCustomTableStyle(t,e){const n=this._setCustomTableStyleInternal(t,e);return this._emitter.notify("onTableStylesChange"),this._emitter.notify("onAnyChange"),n}validateStyleName(t,e=!1){if(!t||0===t.trim().length)throw new Error("Style name cannot be empty.");if(e&&null!==this.getNamed(t))throw new Error("Style name is already taken.")}normalize(t){if(!t)return null;const e=Mt.resolveTypedUpdates(t,Nm,this),n=jm;let r=null;if(r=e.named?this.getNamed(e.named)?.getRanged().getPropertiesAt(0,0,null):this._normalRanged.getPropertiesAt(0,0,null),r){const t={...r};_t.removeEqualValues(e,t)}const o=this.getTheme().getFontScheme();return _t.removeEqualValues(e,{font:{size:this.getDefaultFontSize(),family:o.getMinorFont(),fallbacks:o.getMinorFallbacks()}}),_t.removeEqualValues(e,n),e}schemeLookup(){return this._schemeLookup}indexedLookup(){return this._indexedLookup}parseColor(t){return Da.parse(t,this._schemeLookup,this._indexedLookup)}recentColors(){return this._mruColors}addRecentColor(t){if(!t)return;const e=this._mruColors,n=[],r=t.toString();for(let t=0;t<e.length&&t<10;t++){e[t].toString()!==r&&n.push(e[t])}return n.unshift(t),this._mruColors=Object.freeze(n),this._mruColors}clearRecentColors(){this._mruColors=Object.freeze([])}getIndexedColors(){return this._indexedColors}setCustomIndexedColors(t){this._indexedColors=t?.length>0?[...t]:null}getCustomIndexedColors(){const t=Math.max(this._indexedColors?.length,66),e=[];for(let n=0;n<t;n++)null!==this._indexedColors[n]&&e.push(this._indexedColors[n]??new Da(Vo(n)?.toString()));return e}addListeners(t,e){return this._emitter.addListeners(t,e)}_toJSONInternal(t){const e={};t.length>0&&(e.direct=t);const n=this.getCustomNamed();let r=[];for(let t=0;t<n.length;t++){let e=n[t].toJSON();r.push(e)}r.length>0&&(e.named=r);const o={};this._defaultTableStyle&&this._defaultTableStyle.getName()!==Cp&&(o.defaultTableStyle=this._defaultTableStyle.getName());const s={},i=this.getCustomTableStyles();for(let t=0;t<i.length;t++){let e=i[t].toJSON();delete e.name,e&&Object.keys(e).length>0&&(s[i[t].getName()]=e)}if(Object.keys(s).length>0&&(o.styles=s),Object.keys(o).length>0&&(e.tables=o),this._indexedColors.length>0){e.indexedColors=[];for(let t=0;t<this._indexedColors.length;t++)e.indexedColors.push(this._indexedColors[t].toString())}if(this._mruColors.length>0){e.mruColors=[];for(let t=0;t<this._mruColors.length;t++)e.mruColors.push(this._mruColors[t].toString())}return 0===Object.keys(e).length?null:e}_fromJSONIndexedColors(t){if(!t||0===t.length)return _t.EmptyArray;const e=[];if(t?.length>0)for(let n=0;n<t.length;n++)try{e.push(this.parseColor(t[n]))}catch(e){console.warn("Unable to parse color: "+t[n])}return e}_fromJSONInternal(t){this._indexedColors=this._fromJSONIndexedColors(t.indexedColors);const e=t.named;for(let n=0;e&&n<e.length;n++)this._setCustomCellStyleInternal(t.named[n]);let n=Cp;if(this._defaultTableStyle=null,t.tables){t.tables.defaultTableStyle&&(n=t.tables.defaultTableStyle);const e=t.tables.styles?Object.keys(t.tables.styles):null;for(let n=0;e&&n<e.length;n++){const r=e[n],o=t.tables.styles[r];this._setCustomTableStyleInternal(r,o)}}this._defaultTableStyle=this.getTableStyle(n);let r=[];if(t.mruColors?.length>0)for(let e=0;e<t.mruColors.length;e++)try{r.push(this.parseColor(t.mruColors[e]))}catch(n){console.warn("Unable to parse color: "+t.mruColors[e])}this._mruColors=r}}const kp="BinaryResource must have only one initial data value.",Op="Resource is closed.";class Lp{constructor(t){if(this._listeners=new Set,this._type=t.type,this._name=t?.name,t.base64){const e=t.base64;this._asArrayBufferResolve=async()=>{const t=await Promise.resolve(e);return Promise.resolve(Et.base64ToArrayBuffer(t))}}if(t.fetch){if(this._asArrayBufferResolve)throw new Error(kp);const e=t.fetch;this._asArrayBufferResolve=async()=>{let n,r=null;r="string"==typeof e?e:t.input;const o=await fetch(r,n),s=o.headers.get("Content-Type");return!this._type&&s&&(this._type=s),o.arrayBuffer()}}if(t.buffer){if(this._asArrayBufferResolve)throw new Error(kp);this._asArrayBufferResolve=async()=>{let e=null;return e="function"==typeof t.buffer?await t.buffer():t.buffer,Promise.resolve(e)}}if(t.file){if(this._asArrayBufferResolve)throw new Error(kp);this._asArrayBufferResolve=async()=>{const e=await Promise.resolve(t.file);return await e.arrayBuffer()}}if(!this._asArrayBufferResolve)throw new Error("BinaryResource must have an initial data value.");this._refs=new Set,this._isClosed=!1}getName(){return this._name}async toJSONAsync(){const t=await this.toBuffer(),e={base64:Et.arrayBufferToBase64(t)};return this._type!==Et.DEFAULT_MIME_TYPE&&(e.type=this._type),this._name&&(e.name=this._name),e}async toBuffer(){if(this._asArrayBuffer)return this._asArrayBuffer;try{this._asArrayBuffer=this._asArrayBufferResolve()}catch(t){throw t}return this._asArrayBuffer}async getType(){return this._type?this._type:(await this.toBuffer(),this._type??Et.DEFAULT_MIME_TYPE)}addReference(t){if(this._isClosed)throw new Error(Op);this._refs.add(t)}deleteReference(t){if(this._isClosed)throw new Error(Op);if(0===this._refs.size||!this._refs.has(t))return;this._refs.delete(t);const e=this;if(0===this._refs.size){const t=this._listeners;t.forEach(n=>{n.onUnload?.(e),t.delete(n)}),this._asArrayBuffer=null,this._isClosed=!0}}addUnloadListener(t){if(this._isClosed)throw new Error(Op);this._listeners.add(t)}get isIResource(){return!0}isClosed(){return this._isClosed}}let Dp=class{constructor(t,e,n){this._state=t,this._fromJSON=e,this._onLastEnd=n,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}toResourceId(t){if(this._isClosed)throw new Error("PersistScope is closed.");let e=this._state.byRefs.get(t);return void 0!==e||(e=this._state.byRefs.size,this._state.byRefs.set(t,e),this._state.byIds.set(e,t)),e}fromResourceId(t){return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");if(!t||0===t.length)return;const e=this._state.byRefs.size;for(let n=0;n<t.length;n++){const r=t[n],o=this._fromJSON(r);this._state.byRefs.set(o,e+n),this._state.byIds.set(e+n,o)}}toJSONAsync(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byRefs.forEach((e,n)=>{t[e]=Promise.resolve(n.toJSONAsync())}),Promise.all(t)}};class Bp{constructor(){this._resources=new Set}add(t){if("string"==typeof t){let e=!1;this._resources.forEach(n=>{n.getName()===t&&(e=!0,t=n)}),e||(t=new Lp({name:t,fetch:t,type:null}))}let e=null;e=t instanceof Lp?t:new Lp({...t});const n=this;return this._resources.has(e)||(e.addUnloadListener({onUnload:t=>{n._resources.delete(e)}}),this._resources.add(e)),e}getCount(){return this._resources.size}beginPersist(){this._persistOpen||(this._persistOpen={byRefs:new Map,byIds:new Map,openScopes:new Set});const t={},e=new Set,n=this;return new Dp(this._persistOpen,r=>{const o=n.add({base64:r.base64,name:r.name,type:r.type});return o.addReference(t),e.add(o),o},()=>{e.forEach(e=>{e.deleteReference(t)}),n._persistOpen=null})}}class zp{constructor(t,e,n){this._state=t,this._fromJSON=e,this._onLastEnd=n,this._state.openScopes.add(this),this._isClosed=!1}endPersist(){if(!this._state.openScopes.delete(this))throw new Error("PersistScope is closed.");this._isClosed=!0,0===this._state.openScopes.size&&this._onLastEnd()}add(t){if(this._isClosed)throw new Error("PersistScope is closed.");let e=this._state.byRefs.get(t);return void 0!==e||(e=this._state.byRefs.size,this._state.byRefs.set(t,e),this._state.byIds.set(e,t)),e}at(t){return this._state.byIds.get(t)??null}fromJSON(t){if(this._isClosed)throw new Error("PersistScope is closed.");t&&0!==t.length&&this._fromJSON(t)}toJSONAsync(){if(this._isClosed)throw new Error("PersistScope is closed.");const t=[];return this._state.byRefs.forEach((e,n)=>{t[e]=Promise.resolve(n.toJSONAsync?n.toJSONAsync():n)}),Promise.all(t)}}class Pp{constructor(){this._nextId=0,this._lastReadId=-1,this._lastReadValue=null,this._stringsByText=new Map,this._stringsById=new Map}addMultiple(t,e=!1){const n=this._stringsByText,r=this._stringsById,o=t.length;let s=this._nextId;for(let i=0;i<o;i++){const o=t[i];void 0!==n.get(o)&&e||(n.set(o,s),r.set(s,o),s++)}this._lastReadId=-1,this._nextId=s}add(t){const e=this._stringsByText,n=e.get(t);if(void 0!==n)return n;const r=this._nextId++;return e.set(t,r),this._stringsById.set(r,t),this._lastReadId=-1,r}getById(t){if(this._lastReadId===t)return this._lastReadValue;const e=this._stringsById.get(t)??null;return this._lastReadId=t,this._lastReadValue=e,e}getCount(){return this._stringsById.size}beginPersist(){this._persistOpen||(this._persistOpen={byRefs:new Map,byIds:new Map,openScopes:new Set});const t=this;return new zp(this._persistOpen,e=>(Array.isArray(e)?t.addMultiple(e):t.add(e),e),()=>{t._persistOpen=null})}}var jp,Hp;jp||(jp={});class Vp extends Dl{constructor(t){super(t),t.json&&(this._resource=t.fromResourceId(t.json.resId))}getType(){return"picture"}toJSON(t){const e={},n=t?.(this._resource);null!==n&&(e.resId=n);const r=this._getState();return r&&r.effects&&(e.effects=r.effects),e}getTypeDescription(){return"Picture"}async _asDataUrl(){if(this._dataUrl)return this._dataUrl;const t=await this.getDetails(),e=await It.getImageDataUrl(t.asUrl());return this._dataUrl=e.dataUrl,this._dataUrl}toHtml(){return null}async toImage(){const t=(await this._asDataUrl()).substring(It.DATA_URL_PNG_PREFIX.length),e=Et.base64ToArrayBuffer(t);return new Blob([e],{type:E.png})}async getDetails(){return this._details||(this._details=new Promise(async(t,e)=>{try{const e=await this._resource.toBuffer(),n=await this._resource.getType(),r=await It.loadImageDetails(e,n);t({getNaturalDimensions:()=>r.naturalDimensions,asUrl:()=>r.asUrl,asSVGText:()=>r.asSVGText})}catch(t){e(t)}})),this._details}_fromDrawingJSON(t,e){this._resource?.deleteReference(this),this._resource=e?.(t.resId),this._resource.addReference(this)}_toDrawingJSON(t){const e={},n=t?.(this._resource);return null!==n&&(e.resId=n),e}_processDelete(){super._processDelete()}}(Hp||(Hp={})).Status={Ready:"ready",Error:"error",Starting:"starting",Stopping:"stopping",Off:"off"};class $p extends Uh{constructor(t,e=null,n,r,o){if(super(t,n,e),this._sheetName=r||null,this._getEntireCoords=o??Xh,this._coords=Up(n,this._getEntireCoords()),!n)throw new Error("ReferenceRange requires a coords");this._validateCoords(n)}toType(t){return new $p(this._values,t,this._coords,this._sheetName,this._getEntireCoords)}getCoords(){return this._coords}get isIReferenceRange(){return!0}isLiteral(){return!1}_validateCoords(t){const e=this._getEntireCoords?.();if(e&&(t.rowStart<e.rowStart&&t.rowStart!==Number.MIN_SAFE_INTEGER||t.rowEnd>e.rowEnd&&t.rowEnd!==Number.MAX_SAFE_INTEGER||t.colStart<e.colStart&&t.colStart!==Number.MIN_SAFE_INTEGER||t.colEnd>e.colEnd&&t.colEnd!==Number.MAX_SAFE_INTEGER))throw new kt}get[Symbol.toStringTag](){return"[ReferenceRange]"}toString(){return`${Au(this._coords,this._getEntireCoords?.())}`}}const Up=(t,e)=>{let n=t.rowStart,r=t.rowEnd,o=t.colStart,s=t.colEnd,i=!1;return o===Number.MIN_SAFE_INTEGER&&(o=e.colStart,i=!0),n===Number.MIN_SAFE_INTEGER&&(n=e.rowStart,i=!0),r===Number.MAX_SAFE_INTEGER&&(r=e.rowEnd,i=!0),s===Number.MAX_SAFE_INTEGER&&(s=e.colEnd,i=!0),i?{rowStart:n,rowEnd:r,colStart:o,colEnd:s}:t},Gp=(t,e)=>t.value?.once===e.value?.once,Wp=(t,e)=>t.colStart===e.colStart&&t.rowStart===e.rowStart,qp=(t,e,n)=>!!n&&(t===n.rowStart&&e===n.colStart),Jp=(t,n=0,r=0)=>{const o=t._values,s=t._coords,i=o.getRuns({bounds:s}),a=o.getOrientation()!==e.Orientation.Row,l=a?s.colStart:s.rowStart,c=a?s.rowStart:s.colStart,h=new Ke.Builder(null,n,r);let u=i.next();for(;!u.done;){const t=u.value;h.addValues(t[0]-l,t[1]-c,t[2]),u=i.next()}return h.build()},Xp=(t,n,r,o,s,i,a,l,c,h,u,d,g=!1)=>{let m,f,p=null,_=s.size();void 0===d&&(d=i.getOrientation()===e.Orientation.Column);const S=n?n.length:0,w=r?r.length:0;let y;const E=S+w;for(let e=0;e<E&&_>0;e++){const h=e<S?n[e]:r[e-S],u=s.search(h),d=u.length;for(let e=0;e<d;e++){const n=u[e];if(!qp(n.rowStart,n.colStart,h)){if(n.value.getError())continue;y||(y=[]),y.push(n)}s.remove(n,Wp);const r=n.value;r.getCycleId()!==t&&c?.insert(n),r.getError()||(i.delete(n),o.insertNonOverlapping({colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:null},{onIntersect:(t,e)=>{if(null!==t.value)return a?.push(t),p=W.unionRanges(p,t),l?.insertNonOverlapping(t),p=W.unionRanges(p,t),e}})),_--}}for(let t=0;t<S;t++){const e=n[t],r={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:null};o.insertNonOverlapping(r,{onIntersect:(t,e)=>{if(null===t.value)return;const n=W.sanitizeRange(e);return g&&l?.insertNonOverlapping(n),h?.insertNonOverlapping({...e,value:!1}),a?.push(n),p=W.unionRanges(p,n),e}}),u?.insertNonOverlapping(r,{onIntersect:(t,e)=>{if(null!==t.value)return a?.push(e),p=W.unionRanges(p,e),e},onUpdates:(t,e,n)=>{f||(f=[]);const r=t.length;for(let e=0;e<r;e++){const n=t[e];f.push(n)}m||(m=[]);const o=e.length;for(let t=0;t<o;t++){const n=e[t],r=W.sanitizeRange(n);m.push(r)}}})}const b=d?e.Orientation.Column:e.Orientation.Row;if(y){const e=y.length,n=new Array(e);for(let r=0;r<e;r++){const e=y[r],s=e.value.setError(!0,t);c?.insert(s),n[r]=s,p=W.unionRanges(p,e);const i={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowStart};o.insertNonOverlapping({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colStart,rowEnd:e.rowStart,value:new id(e,b)}),a?.push(i)}s.load(n)}for(let t=0;t<w;t++){const e=W.sanitizeRange(r[t]);o.insertNonOverlapping({colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd,rowEnd:e.rowEnd,value:new id(e,b)}),g&&l?.insertNonOverlapping(e),a?.push(e),p=W.unionRanges(p,e)}return p},Kp=(t,e,n)=>{if(!e)return t;const r=e.block;if(!r)return t;const o=t??[],s=e.colIndex,i=e.rowIndex;let a,l,c,h;n?(a=n.colStart,l=n.rowStart,c=n.colEnd,h=n.rowEnd):(a=s,l=i,c=s,h=i);const u={colStart:a,rowStart:l,colEnd:c,rowEnd:h,value:{blockEntry:{colStart:a,rowStart:l,colEnd:c,rowEnd:h,value:r},width:1,height:1,index:-1,$absWidth:!1,$absHeight:!1,once:e}};let d=e.dynamic;return d||(d=[],e.dynamic=d),d.push(u),o.push(u),o};class Yp{constructor(t){this._fullCalcRequired=!1,this._iterationId=0,this._cycleId=1,this._pendingInvalidations=new Set,this._emitter=null,this._isProcessingJSON=!1,this._collectDirties=(t,e=!1,n,r)=>{const o=this._formulaSpatial,s=this._precedentSpatial;let i=h_,a=0;if(e){const e=o.all();for(let n=0;n<e.length;n++){const r=e[n].value.calcs,o=r.length;for(let e=0;e<o;e++){const n=r[e],o=n.length;for(let e=0;e<o;e++){const r=n[e];r.markId!==t&&(i[a++]=r,r.markId=t,r.pending=!1,r.pendingResolved=!1,r.pendingPromise&&(r.pendingPromise.cancelled=!0))}}}}else{const e=n.length;for(let r=0;r<e;r++){const e=n[r];v_.length=0;const l=v_;s.search(e,!1,l),o.search(e,!1,l);const c=l.length;if(0===c)continue;const h=e.colStart,u=e.rowStart,d=e.colEnd-h,g=e.rowEnd-u;for(let e=0;e<c;e++){const n=l[e],r=n.value,o=r.blockEntry?.value??r,c=o.ref,m=c.colEnd-c.colStart,f=c.rowEnd-c.rowStart,p=n.colEnd-n.colStart-m,_=n.rowEnd-n.rowStart-f,S=r.once;if(S)S.markId<=t&&(S.removed?(s.remove(n,Gp),S.removed=!1):i[a++]=S,S.markId=t);else{let e=0,s=0,l=m,c=f;if(!r.$absHeight){const t=u-n.rowStart;s=Math.min(Math.max(t-_,0),f),c=Math.min(g+u,f)}if(!r.$absWidth){const t=h-n.colStart;e=Math.min(Math.max(t-p,0),m),l=Math.min(d+t,m)}const S=o.calcs;for(let n=s;n<=c;n++){const r=S[n];for(let n=e;n<=l;n++){const e=r[n];e.markId!==t&&(i[a++]=e,e.markId=t,e.pendingPromise&&(e.pendingPromise.cancelled=!0))}}}}}r&&r.forEach(e=>{if(Array.isArray(e)){const n=e.length;for(let r=0;r<n;r++){const n=e[r],o=n.length;for(let e=0;e<o;e++){const r=n[e];r.markId===t||r.removed||(i[a++]=r,r.markId=t,r.pendingPromise&&(r.pendingPromise.cancelled=!0))}}}else e.markId===t||e.removed||(i[a++]=e,e.markId=t,e.pendingPromise&&(e.pendingPromise.cancelled=!0))})}return i.length=a,i};const n=(t={strings:new Pp,...t}).getEntireCoords??Xh;if(this._getEntireCoords=n,this._options=t,this._strings=t.strings,this._onCalculated=t?.onCalculated??(()=>{}),this._cycleId=1,this._values=new hh({orientation:e.Orientation.Column}),this._getFormulaParser=t.getFormulaParser,!this._getFormulaParser)throw new Error("Formula parser is not defined");this._latest={graph:this},this._iterationId=0;const o=this;this._formulaSpatial=new Lc({updateEntryOptions:{isMergeOnShift:!0,isSplitOnExpand:!0,onUpdates:(t,e,n)=>{const s=n._cloneKey??o;if(s._isProcessingJSON)return;let i=s._notifyFormulaInsertEntries,a=s._notifyFormulaRemoveEntries;const l=s._precedentSpatial,c=e?e.length:0;if(c>0){let t=a?a.length:0;a?a.length=t+c:(a=new Array(c),s._notifyFormulaRemoveEntries=a);for(let n=0;n<c;n++){const o=e[n],s=o.value,i=s.ref;a[t+n]=i;const c=i.rowStart,h=i.colStart,u=s.formula.getDirectPrecedentsAt(c,h);if(!u)continue;const d=u.length;for(let t=0;t<d;t++){const e=u[t];if(null===e)continue;if(e instanceof r.Known)continue;const n=l.search(e),s=n.length;for(let t=0;t<s;t++){const e=n[t];e.value.blockEntry.value===o.value&&l.remove(e)}}}}const h=t?t.length:0;if(h>0){const e=[];for(let n=0;n<h;n++){const o=t[n],a=o.colEnd-o.colStart,l=o.rowEnd-o.rowStart,c=o.value,h=c.formula,u=c.ref,d=u.rowStart,g=u.colStart,m=[],f=h.getDirectPrecedentsAt(d,g,!0,r_,o_),p=f.length;for(let t=0;t<p;t++){const n=f[t];if(n instanceof r.Known)continue;const s=r_[t],i=o_[t],c={colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd+(i?0:a),rowEnd:n.rowEnd+(s?0:l),value:{blockEntry:o,width:a+1,height:l+1,index:t,$absWidth:i,$absHeight:s,once:null}};m.push(n),e.push(c)}i||(i=[],s._notifyFormulaInsertEntries=i),i.push({colStart:o.colStart,rowStart:o.rowStart,colEnd:o.colEnd,rowEnd:o.rowEnd,value:{tokens:h.getTokens(),references:h.getReferences(),precedents:m}})}l.load(e)}}}}),this._contentfulSpatial=new Lc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}});const s={updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!1}};this._precedentSpatial=new Lc(s),this._volatile=new Set,this._spillSpatial=new Lc(s),this._errorSpatial=new Lc(s),this._pendingSpatial=new Lc(s),this._invalidations=new Lc,this._notifyValues=new Lc,this._notifySpills=new Lc,this._notifyFormats=new Lc,this._notifyPending=new Lc,this._calculation=t.calculation,this._clearScope()}addListeners(t,e){return this._emitter||(this._emitter=new Ll(this)),this._emitter.addListeners(t,e)}shift(t){const n=t.cloneIfUpdate??!0?this.clone(this):this,o={...t};delete o.cloneIfUpdate,delete o.onShift;n._values.shift(o.range,o.direction);const s=n._contentfulSpatial;n._contentfulSpatial=s.shift(o);const i=n._spillSpatial;n._spillSpatial=i.shift(o);const a=n._formulaSpatial;if(a.isEmpty())return n;const l=t.range,c=t.direction,h=c===e.Direction.Left||c===e.Direction.Right;c!==e.Direction.Up&&e.Direction.Left,h?(l.colEnd,l.colStart):(l.rowEnd,l.rowStart),n._notifyFormulaInsertEntries,n._notifyFormulaRemoveEntries;const u=n._getEntireCoords(),d=new Map;this._precedentSpatial.visitRanges({...l,colEnd:h?u.colEnd:l.colEnd,rowEnd:h?l.rowEnd:u.rowEnd},t=>{let e=t.value;if(t.value.once)return;let n=e.blockEntry,r=d.get(n);r||(r={rows:[],cols:[],index:[]},d.set(n,r)),r.index.push(e.index)});const g=[],m=[],f=d.entries();let p=f.next();const _=(t,e,n,o)=>{let s=t.value;const i=s.formula.getReferences(),a=e.length;for(let t=0;t<a;t++){const e=i[t];if(null===e)continue;if(e instanceof r.Known)continue;if("string"==typeof e)continue;e[t]}return t.value=s,t};for(;!p.done;){const[t,n]=p.value,r=t.value,o=n.rows.sort(),s=o.length,i=n.cols.sort().length,a=n.index.sort();if(m.push(t),0===s&&0===i){const e={...t};_(e,a),g.push(e),p=f.next();continue}let l=0;for(let t=0;t<s;t++){const n=o[t];if(n===l)continue;I_[0]={colStart:r.ref.colStart,rowStart:l,colEnd:r.ref.colEnd,rowEnd:n-1,value:r},I_[1]={colStart:r.ref.colStart,rowStart:n,colEnd:r.ref.colStart,rowEnd:r.ref.rowEnd,value:r};const s=R_(r,I_,e.Orientation.Row,n);let i=s[0];_(i,a),g.push(i),i=s[1],_(i,a),g.push(i),l=n}p=f.next()}return a._updateNodes(g,m),n._fullCalcRequired=!0,this._invalidate(g),n}clone(t){if(void 0!==t&&this._cloneKey===t)return this;const e=new Yp(this._options);e._cloneKey=t,e._values=this._values.clone(e),e._contentfulSpatial=this._contentfulSpatial.clone(e),e._formulaSpatial=this._formulaSpatial.clone(e),e._precedentSpatial=this._precedentSpatial.clone(e),e._volatile=new Set(this._volatile),e._spillSpatial=this._spillSpatial.clone(e),e._errorSpatial=this._errorSpatial.clone(e),e._pendingSpatial=this._pendingSpatial.clone(e),e._invalidations=this._invalidations.clone(e),e._notifyValues=this._notifyValues.clone(e),e._notifySpills=this._notifySpills.clone(e),e._notifyFormats=this._notifyFormats.clone(e),e._notifyPending=this._notifyPending.clone(e);const n=this._notifyFormulaInsertEntries;n&&(e._notifyFormulaInsertEntries=[...n]);const r=this._notifyFormulaRemoveEntries;r&&(e._notifyFormulaRemoveEntries=[...r]);const o=this._pendingActions;return o&&(e._pendingActions=[...o]),e._cycleId=this._cycleId,e._emitter=this._emitter,e._fullCalcRequired=this._fullCalcRequired,this._latest.graph=e,e._iterationId=this._iterationId+1,e}invalidate(t){const e=this._invalidations;if(Array.isArray(t)){const n=t.length;for(let r=0;r<n;r++){let n=t[r];"string"==typeof n&&(n=Vu(n)),e.insertNonOverlapping(n)}}else{let n=t;"string"==typeof n&&(n=Vu(n)),e.insertNonOverlapping(n)}}setFormulaAt(t,e){let n,r=null;return"string"==typeof t?n=Vu(t,n_):(n_.colStart=t.colIndex,n_.rowStart=t.rowIndex,n_.colEnd=t.colIndex,n_.rowEnd=t.rowIndex,n=n_),e?r=this._setInputs(null,[{colStart:n.colStart,rowStart:n.rowStart,colEnd:n.colEnd,rowEnd:n.rowEnd,value:e}]):this.delete(n),r}getFormulaAt(t,e){let n;"string"==typeof t&&(n=Vu(t,n_));const r=this._formulaSpatial.search(n);if(0===r.length)return null;const o=r[0].value;return o.formula?o.formula.getTextAt(n.rowStart,n.colStart,e):void 0}_formulaAt(t,e){x_.colStart=e,x_.rowStart=t,x_.colEnd=e,x_.rowEnd=t;const n=this._formulaSpatial.search(x_);if(0===n.length)throw new Error(`No formula found at ${vu({rowIndex:t,colIndex:e})}`);return n[0]}getDirectPrecedentsAt(t,e,n){return this._formulaAt(t,e).value.formula.getDirectPrecedentsAt(t,e,n)}getReferencesAt(t,e){return this._formulaAt(t,e).value.formula.getReferences()}setReferenceAt(t,e,n,r){const o=this._formulaAt(t,e).value.formula.setReferenceAt(n,r).getTextAt(t,e);return this.setFormulaAt({rowIndex:t,colIndex:e},o),this}evaluateAt(t,e,n){const r=this._formulaAt(t,e),o=r.value,s=o.ref,i=s.colStart-e,a=s.rowStart-t,l=this._calculation._getContext(),c=this._calculation._getScope();return c.sheetName=this._options.getSheetName?.(),c.rowIndex=t,c.colIndex=e,c.node=o.calcs[a][i],r.value.formula.evaluate(l,n)}setInputAt(t,n){let r=null;const o="string"==typeof t?zu(t,e_):t;if(null!==n){const t=new Ke.Builder,s=this._values.getOrientation()===e.Orientation.Column,i=s?o.colIndex:o.rowIndex,a=s?o.rowIndex:o.colIndex;t.addValue(i,a,n),r=this.setInputs(t.build(),null)}else this.delete(W.cellToRange(o,n_));return r}setInputs(t,e){return this._setInputs(t,e)}delete(t){"string"==typeof t&&(t=Fu(t));const e=this._setInputs(null,[{...t,value:null}],t);return this._emitter?.notify("onInvalidate"),e.removes}_createCopySpillEntries(t,e,n,r,o){const s=r??[],i=o??[],a=e.colStart,l=e.rowStart,c=e.colEnd,h=e.rowEnd,u=n.colStart,d=n.rowStart,g=t.search(e),m=g.length;for(let t=0;t<m;t++){const e=g[t];i&&i.push(e);const n=e.rowStart,r=e.colStart;if(n<l||n>h)continue;if(r<a||r>c)continue;if(e.value.getError())continue;const o=u+(e.colEnd-r),m=d+(e.rowEnd-n),f={colStart:u,rowStart:d,colEnd:o,rowEnd:m};s.push({colStart:u,rowStart:d,colEnd:o,rowEnd:m,value:new sd(f,0,!1)})}return{removes:i,inserts:s}}_copyCalcs(t,e,n){const r=t._formulaSpatial;if(r.isEmpty())return;const o=this._getEntireCoords(),s=o.colStart,i=o.rowStart,a=o.colEnd,l=o.rowEnd,c=r.createCopiedEntries(e,n),h=c.inserts;let u=h.length,d=0;const g=t._spillSpatial;let m=[];for(;d<u;){let t=h[d],n=t.value,r=n.ref,o=r.colStart,c=r.rowStart,f=r.colEnd,p=r.rowEnd;this._createCopySpillEntries(g,e,r,m,null);let _=n.formula.getReferences();const S=_.length;for(let e=0;e<S;e++){const d=_[e];if(!d)continue;if(d.isFormulaError)continue;if("string"==typeof d)continue;const g=d,m=g.colStart,S=g.rowStart,w=g.colEnd,y=g.rowEnd;let E=g.$colStart?m:m+o,b=g.$rowStart?S:S+c,v=g.$colEnd?w:w+f,C=g.$rowEnd?y:y+p;if(m===Number.MIN_SAFE_INTEGER&&(E=s,v=a),S===Number.MIN_SAFE_INTEGER&&(b=i,C=l),E<s||v>a||b<i||C>l){const d=s-E,g=i-b,m=a-v,S=l-C;C_.colStart=Math.max(o,o+d),C_.rowStart=Math.max(c,c+g),C_.colEnd=Math.min(f,f+m),C_.rowEnd=Math.min(p,p+S);const w=Pc(t,C_,$c);if(w){const e=w.length;t=w[e-1],n=t.value,r=n.ref,o=r.colStart,c=r.rowStart,f=r.colEnd,p=r.rowEnd;for(let t=0;t<e-1;t++){const e=w[t];h.push(e),u++}}else n=n.setReferenceAt(e,null),t.value=n,_=n.formula.getReferences()}}h[d++]=t}this._formulaSpatial._updateNodes(h,c.removes),r._mergeNodes({colStart:n.colStart-1,rowStart:n.rowStart-1,colEnd:n.colEnd+1,rowEnd:n.rowEnd+1}),m&&this._spillSpatial._updateNodes(m,[]),this._fullCalcRequired=!0,this._invalidate(h),this._invalidate(c.removes)}_moveCalcs(t,n,r){const o=t._formulaSpatial.createCopiedEntries(n,r);console.log("_moveCalcs",o,"from:",n,"to:",r);const s=this._formulaSpatial,i=(t,e,n,r)=>{let o=t.value;const s=o.formula.getReferences(),i=s.length,a=e.colStart-n.colStart,l=e.rowStart-n.rowStart,c=o.ref,h=n.colStart-c.colStart,u=n.colEnd-c.colEnd,d=n.rowStart-c.rowStart,g=n.rowEnd-c.rowEnd;for(let t=0;t<i;t++){const e=s[t];if(!e)continue;if(e.isFormulaError)continue;if("string"==typeof e)continue;const n=e,r=n.colStart,i=n.rowStart,c=n.colEnd,m=n.rowEnd;let f=a,p=l;const _=h<=r&&u>=c||r==Number.MIN_SAFE_INTEGER,S=d<=i&&g>=m||i==Number.MIN_SAFE_INTEGER;let w=!S;n.$colStart||0===f||r===Number.MIN_SAFE_INTEGER?w=!1:w||(w=r<h||r>u,w||!n.$colEnd||n.$colStart||(w=!0));let y=!_;n.$rowStart||0===p||i===Number.MIN_SAFE_INTEGER?y=!1:y||(y=i<d||i>g,w||!n.$rowEnd||n.$rowStart||(y=!0));let E=!S;n.$colEnd||0===f||i===Number.MIN_SAFE_INTEGER?E=!1:E||(E=c<h||c>u,w||!n.$colStart||n.$colEnd||(E=!0));let b=!_;n.$rowEnd||0===p||i===Number.MIN_SAFE_INTEGER?b=!1:b||(b=m<d||m>g,b||!n.$rowEnd||n.$rowStart||(b=!0));if(!(w||E||y||b))continue;const v={...n};w&&(v.colStart+=f),y&&(v.rowStart+=p),E&&(v.colEnd+=f),b&&(v.rowEnd+=p),o=o.setReferenceAt(t,v)}return t.value=o,t},a=t._spillSpatial;let l=[],c=[];const h=o.inserts,u=h.length;for(let t=0;t<u;t++){const e=h[t];this._createCopySpillEntries(a,n,e,l,c),h[t]=i(e,n,r)}s._updateNodes(o.inserts,[]),t._formulaSpatial._updateNodes([],o.removes);const d=[];l.length>0&&(this._spillSpatial._updateNodes(l,[]),t._spillSpatial._updateNodes([],c),Xp(this._cycleId,c,_t.EmptyArray,t._contentfulSpatial,a,t._values,d,t._notifyValues,t._notifySpills,t._notifyPending,t._errorSpatial,t._values.getOrientation()!==e.Orientation.Row,!1)),this._fullCalcRequired=!0,this._invalidate(o.inserts),t._invalidate(d),t._invalidate(o.removes)}getSnapshot(t){const e=this,n=Object.freeze({...t});let r=n.range;"string"==typeof r&&(r=Vu(r));return{async copyTo(t,o){const s=t.calcGraph;let i=t.range;"string"==typeof i&&(i=Vu(i));const a=Vh(i,r,o?.fitDestination,o?.transpose);return{...n,...o}.isCut?s._moveCalcs(e,r,a):s._copyCalcs(e,r,a),i},getCoords:()=>r,getSource:()=>e,getName:()=>"Calculation",getMarkOptions:()=>n,isISnapshot:!0}}autoFill(t,e){return"string"==typeof t&&(t=Vu(t)),"string"==typeof e&&(e=Vu(e)),this._copyCalcs(this,t,e),this}_scheduleRecalculation(t){const e=this._pendingInvalidations;if(t)if(Array.isArray(t)){const n=t.length;for(let r=0;r<n;r++)e.add(t[r])}else e.add(t);const n=this;_t.debounce(()=>{const t=n._latest.graph,r=t._volatile,o=t._cycleId;e.forEach(t=>{t.cycleId>o||r.add(t)}),e.clear(),t.calculate()},100)()}_notifyCalculated(t){const n=this,r=n._notifyValues,o=r.all();return new Promise(s=>{_t.nextTick(()=>{const i=n._cycleId;let a;let l=n._fullCalcRequired;l||("boolean"==typeof t?l=t:t&&(a=t,l=a.full??!1));const c={};let h=null;const u=o.length;if(u>0){r.clear();let t=o,s=null;for(let t=0;t<u;t++){const e=o[t],n=e.colStart,r=e.colEnd;if(n!==r){s||(s=[]);for(let t=n+1;t<=r;t++)s.push({colStart:t,rowStart:e.rowStart,colEnd:t,rowEnd:e.rowEnd});e.colEnd=n}}s&&(t=o.concat(s)),t.sort(W.columnFirstRangeComparator);const i=new Ke.Builder(t=>new ql(t));let a;const l=n._values,d=l.getOrientation()===e.Orientation.Column,g=t.length;for(let e=0;e<g;e++){const n=t[e];h=W.unionRanges(h,n,n_);const r=l.getRuns({bounds:n});let o=r.next();const s=n.colStart,c=n.rowStart,u=n.colEnd,g=n.rowEnd,m=d?c:s,f=d?u:g,p=d?g:u;let _=d?s:c,S=m;for(;!o.done;){const t=o.value,e=t[0];for(;_<e;)a||(a=[]),a.push({colStart:d?_:S,rowStart:d?S:_,colEnd:d?_:p,rowEnd:d?p:_}),_++,S=m;const n=t[1],s=t[2],l=Math.max(n,m),c=Math.min(n+s.length-1,p);i.addValues(e,l,s),S<l&&(a||(a=[]),a.push({colStart:d?e:S,rowStart:d?S:e,colEnd:d?e:l-1,rowEnd:d?l-1:e})),S=c+1,c>=p?(_=e+1,S=m):_=e,o=r.next()}for(;_<=f;)S<=p&&(a||(a=[]),a.push({colStart:d?_:S,rowStart:d?S:_,colEnd:d?_:p,rowEnd:d?p:_})),_++,S=m}const m=i.build();m&&(c.valueInserts=m),a&&(c.valueRemoves=a)}const d=n._notifyPending,g=d.all();if(g.length>0){d.clear();const t=n._pendingSpatial;let e;const r=g.length;for(let n=0;n<r;n++){const r=g[n];t.insertNonOverlapping(r,{onIntersect:(t,n)=>(e||(e=[]),e.push({...n}),h=W.unionRanges(h,n),!1===n.value&&(n.value=null),n)})}e&&e.length>0&&(c.pendingUpdates=e,h=W.unionRangesArrays(e,h,n_))}const m=n._notifySpills,f=m.all();if(f.length>0){m.clear();const t=n._spillSpatial;let e,r,o;const s=f.length;for(let n=0;n<s;n++){const s=f[n],a=s.value;if(a.getCycleId()!==i)e||(e=[]),e.push({colStart:s.colStart,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:s.rowEnd});else{const e=t.search(s),n=e.length;for(let t=0;t<n;t++){let n=e[t];if(qp(s.rowStart,s.colStart,n)&&a.getCycleId()===i){r||(r=[],o=new Set);const t=Eu(n.colStart)+Su(n.rowStart);if(o.has(t))continue;o.add(t),r.push({colStart:s.colStart,rowStart:s.rowStart,colEnd:s.colEnd,rowEnd:s.rowEnd,value:n.value.getError()})}}}}r&&(c.spillInserts=r,h=W.unionRangesArrays(r,h,n_)),e&&(c.spillRemoves=e,h=W.unionRangesArrays(e,h,n_))}const p=n._notifyFormats.all();p.length>0&&(c.formatInserts=p,h=W.unionRangesArrays(p,h,n_),n._notifyFormats.clear());const _=n._notifyFormulaInsertEntries;if(_){const t=n._formulaSpatial;for(let e=_.length-1;e>=0;e--){const n=_[e];0===t.search(n).length?_.splice(e,1):h=W.unionRanges(h,n,n_)}c.formulaInserts=_,n._notifyFormulaInsertEntries=void 0}const S=n._notifyFormulaRemoveEntries;S&&(c.formulaRemoves=S,h=W.unionRangesArrays(S,h,n_),n._notifyFormulaRemoveEntries=void 0),h&&(c.bounds=W.sanitizeRange(h)),0===Object.keys(c).length?c.cycleId=i-1:(c.cycleId=i,n._cycleId++),l&&(c.isFull=!0),n._fullCalcRequired=!1,n._options.onCalculated?.(c),s(c)})})}_setInputs(t,n,r){if(this._calculation.getStatus()===Hp.Status.Starting)return this._addToPending(()=>{const e=this._setInputs(t,n,r),o={formulaInserts:e.inserts??_t.EmptyArray,formulaRemoves:e.removes??_t.EmptyArray,cycleId:this._cycleId,bounds:W.unionRanges(W.unionRangesArrays(e.inserts),W.unionRangesArrays(e.removes))};return Promise.resolve(o)}),A_;const o=this._values.getOrientation()!==e.Orientation.Row,s=this._spillSpatial,i=this._errorSpatial,a=this._contentfulSpatial,l=[],c=this._formulaSpatial;let h,u,d=!c.isEmpty(),g=d?[]:null,m=this._values;if(t&&t.tuples){if(h=t.tuples,g){let e=t.bounds;if(d)if(e){const t=Yc(e,o);l.push(t)}else{const t={colStart:Number.MIN_SAFE_INTEGER,rowStart:Number.MIN_SAFE_INTEGER,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER};l.push(t)}const n={majorStart:0,minorStart:0,majorEnd:0,minorEnd:0},r=h.length;for(let t=0;t<r;t++){const e=h[t],r=e[0];n.majorStart=r,n.majorEnd=r;const s=e[1],i=s.length;for(let t=0;t<i;t++){const e=s[t];n.minorStart=e[0];const r=e[1];n.minorEnd=n.minorStart+r.length-1;const i=Yc(n,o);if(g){c.search(i).length>0&&g.push(i)}}}}u=ad(t.tuples,o)}(r||h)&&(Xp(this._cycleId,r?[r]:_t.EmptyArray,u,a,s,m,l,this._notifyValues,this._notifySpills,this._notifyPending,i,o,!1),r&&m.delete(r),h&&m.setValues(h));const f=this._calculation._getContext(),p=this._calculation._getScope();let _,S;p.sheetName=this._options.getSheetName?.();const w=this._getFormulaParser(),y=(t,e)=>{const n=t.rowStart,r=t.colStart,o={...t,value:null};if(c.insertNonOverlapping(o,{noMerge:!0,onIntersect:(t,e)=>null===t.value?null:(S||(S=[]),S.push(t),e)}),null!==e){p.rowIndex=n,p.colIndex=r;const o=w.parse(f,e),s=new hd(t,o),i={...t,value:s};_||(_=[]),_.push(i)}},E=g?g.length:0;for(let t=0;t<E;t++)y(g[t],null);const b=n?n.length:0;for(let t=0;t<b;t++){const e=n[t],r=e.value;y(W.sanitizeRange(e),r)}const v=S?S.length:0,C=this._precedentSpatial;for(let t=0;t<v;t++){const e=S[t].value.calcs;if(e){const t=e.length;for(let n=0;n<t;n++){const t=e[n];for(let e=0;e<t.length;e++){const n=t[e];if(n.dynamic){for(let t=0;t<n.dynamic.length;t++){const e=n.dynamic[t];C.remove(e)}n.dynamic=null}}}}}n&&(c._updateNodes(_,_t.EmptyArray),Xp(this._cycleId,S,_,a,s,m,l,this._notifyValues,this._notifySpills,this._notifyPending,i,o,!0)),this._invalidate(l);return{inserts:this._notifyFormulaInsertEntries??_t.EmptyArray,removes:this._notifyFormulaRemoveEntries??_t.EmptyArray}}_invalidate(t){if(!t||0==t.length)return;const n=this._invalidations,r=Hc(t,e.Orientation.Column,2);for(let t=0;t<r.length;t++)n.insertNonOverlapping(r[t]);this._emitter?.notify("onInvalidate")}_markAndPlan(t,e,n){let r;m_=0,w_=0,y_=0,b_=0;const o=this._precedentSpatial,s=this._formulaSpatial;p_=0,__=0;const i=this._cycleId,a=e.length;for(let t=0;t<a;t++){const r=e[t];r.markId!==n&&(r.markId=n,r.cycleId=i,r.inDegree=0,g_[m_++]=r,f_[__++]=r)}const l=(e,n,o)=>{(t||e.state===ld)&&(r||(r=[]),r.push(n),t||o(e))},c=t=>{t.markId!==n&&(t.markId=n,t.cycleId=i,t.inDegree=0,g_[m_++]=t,f_[__++]=t)};for(;p_<__;){const t=f_[p_++],e=t.colIndex,n=t.rowIndex;n_.colStart=e,n_.rowStart=n,n_.colEnd=e,n_.rowEnd=n;const r=o.search(n_),s=r.length;if(0===s)t.dependents=_t.EmptyArray;else for(let t=0;t<s;t++){const o=r[t],s=o.value.once;s?l(s,o,c):t_(o,n,e,c)}}for(let t=0;t<m_;t++){const e=g_[t],r=e.block,o=e.rowIndex,i=e.colIndex,a=r.formula.getDirectPrecedentsAt(o,i);let l=0;const c=e.precedents;for(let t=0;t<a.length;t++){const e=a[t];if(e.isFormulaError){c[t]=e;continue}{const n=e;n.calc=void 0,c[t]=n}const r=e.colStart,o=e.rowStart,i=e.colEnd,h=e.rowEnd,u=s.search(e),d=u.length;for(let t=0;t<d;t++){const s=u[t],a=s.colStart,c=s.rowStart,d=s.colEnd,g=s.rowEnd,m=Math.max(a,r),f=Math.max(c,o),p=Math.min(d,i),_=Math.min(g,h),S=s.value.calcs;for(let t=f;t<=_;t++){const r=S[t-c];for(let t=m;t<=p;t++){const o=r[t-a];o.markId===n&&(e.calc=o,l++)}}}}e.inDegree=l,0===e.inDegree&&(S_[y_++]=e)}const h=t=>{t.markId===n&&(t.inDegree--,0===t.inDegree&&(S_[y_++]=t))};for(;w_<y_;){const t=S_[w_++];E_[b_++]=t;const e=t.colIndex,n=t.rowIndex;n_.colStart=e,n_.rowStart=n,n_.colEnd=e,n_.rowEnd=n;const r=o.search(n_),s=r.length;for(let t=0;t<s;t++){const o=r[t],s=o.value.once;s?l(s,o,h):t_(o,n,e,h)}}return b_<m_?{completed:!1,onces:r}:{completed:!0,onces:r}}_evaluate(t){const n=this._calculation._getContext(),o=this._calculation._getScope();o.sheetName=this._options.getSheetName?.();let s=u_;s.length=0;let i=0,a=!0;const l=this._cycleId,c=this._invalidations,h=this._contentfulSpatial,u=this._notifyValues,d=this._notifySpills,g=this._precedentSpatial,m=this._spillSpatial,f=this._values,p=f.getOrientation(),_=p===e.Orientation.Column;let S;o.spillSpatial=this._spillSpatial,o.values=f;const w=n.getEntireCoords.bind(n);let y;for(let e=0;e<b_;e++){const E=E_[e];if(E.state===cd&&l===E.cycleId){E.state=ld;continue}if(E.dynamic){for(let t=0;t<E.dynamic.length;t++){const e=E.dynamic[t];g.remove(e)}E.dynamic=null}const b=E.block,v=E.colIndex,C=E.rowIndex;let x=t?void 0:E.cachedValue,I=E.error;!I&&x&&x.isFormulaError&&(I=x);let A=!1;const R=E.precedents;if(R){const t=R.length,e=E.inputs;for(let n=0;n<t;n++){const t=R[n],r=t.calc;if(r&&r.pending){A=!0;continue}if(t.isFormulaError){e[n]=t;continue}const o=t.colStart,a=t.rowStart,l=t.colEnd;t.rowEnd!==a||o!==l?(i>0&&(s.length=i,Zp(s,f,u,_),i=0),e[n]=new $p(f,null,{...t},null,w)):e[n]=void 0===r?t:r.cachedValue}E.pendingPrecedents=A}const M=_?v:C,T=_?C:v;o.node=E,o.colIndex=v,o.rowIndex=C;const N=b.formula;let F,k;const O=E.pending;let L=O;if((A||E.pendingPromise)&&(L=!0,F=E.cachedValue??null,E.pendingPromise&&(E.pendingResolved?(E.pendingPromise=null,E.pendingResolved=!1,L=!1):(E.pendingPromise.cancelled=!0,F=void 0))),void 0===F&&(o.formula=N,o.colIndex=v,o.rowIndex=C,F=N.evaluate(n,void 0,E.inputs),o.formula=null,k=F&&F.then?F:null,L=!!k),L!==O&&(E.pending=L,S||(S=ch(_)),S.append(M,T,L)),k&&(F=E.cachedValue??null,!k.__originator)){k.__originator=l;const t=E;d_.add(t),t.pendingPromise=k,t.pendingResolved=!1,k.then(e=>{if(d_.delete(t),k.cancelled)return;t.pendingPromise=k,t.pendingResolved=!0;let r=ou(e,n);null===r&&(r=0),t.cachedValue=r,this._scheduleRecalculation(t)},t=>{})}let D=1,B=1;const z=x instanceof Uh;let P;const j=x instanceof r.Spill;if(z||j){i_.colStart=v,i_.rowStart=C,i_.colEnd=v,i_.rowEnd=C;const t=m.search(i_);for(let e=0;!P&&e<t.length;e++){const n=t[e];n.colStart===v&&n.rowStart===C&&(P=n)}if(P){if(z){const t=x;D=t.getWidth(),B=t.getHeight()}const t={colStart:v,rowStart:C,colEnd:v+D-1,rowEnd:C+B-1};m.remove(P),P&&P.value.getError()||(h.insertNonOverlapping({...t,value:null}),f.delete(t),u.insertNonOverlapping(t))}}let H=1,V=1;const $=F,U=$?.isIRange;let G,q=F instanceof r.Spill;if(U&&$.size>1){H=$.getWidth(),V=$.getHeight();const t={colStart:v,rowStart:C,colEnd:v+H-1,rowEnd:C+V-1},e=n.getEntireCoords(),o=!W.isRangeWithinRange(t,e);if(o&&(t.colEnd=Math.min(t.colEnd,e.colEnd),t.rowEnd=Math.min(t.rowEnd,e.rowEnd)),q=o,!q){const e=h.search(t);if(q=e.length>1,!q&&1===e.length){const n=e[0],r=W.intersectRanges(t,n,n_);(r&&(r.rowEnd!==r.rowStart||r.colStart!==r.colEnd)||r.colStart!==v||r.rowStart!==C)&&(q=!0)}}let s,i;if(q){F=r.BuiltIn.Spill,H=1,V=1;s=[[M,[[T,[F]]]]],f.setValues(s),i={colStart:v,rowStart:C,colEnd:v,rowEnd:C}}else{const e=Jp($,M,T);e&&(s=e.tuples),s&&f.setValues(s),i=t}G={...t,value:new sd(t,l,q)},m.insert(G),y=Kp(y,E,t),u.insertNonOverlapping(i),c.insertNonOverlapping(i),h.insertNonOverlapping({...i,value:new id(i,p)})}(!W.isEqualRanges(P,G)||q||j)&&(P&&d.insert(P),G&&d.insert(G)),H===D&&V===B||(E.state=cd,c.insertNonOverlapping({colStart:v,rowStart:C,colEnd:v+Math.max(H,D)-1,rowEnd:C+Math.max(V,B)-1}),a=!1);let J=F&&F.isFormulaError?F:null;N.getError()&&(J=N.getError()),(J||I&&!t)&&(J&&!J.equals(I)||I&&I.equals(J)),E.cachedValue=F,s[i++]=E}if(o.node=null,o.colIndex=Number.MAX_SAFE_INTEGER,o.rowIndex=Number.MAX_SAFE_INTEGER,S){const t=S.done(!0);this._notifyPending.load(t)}return i>0&&(s.length=i,Zp(s,f,u,_),i=0),{completed:a,dynamic:y,count:b_}}async calculate(t){const e=this._calculation.getStatus();if(e===Hp.Status.Starting)return void this._addToPending(()=>this.calculate(t));if(e!==Hp.Status.Ready)return;let n=this._fullCalcRequired;n||("boolean"==typeof t?n=t:t&&(n=t.full??!1));const r=this._invalidations;if(this._formulaSpatial.isEmpty()){if(r.clear(),d_.size>0){const t=++l_;d_.forEach(e=>{e.markId=t})}return this._notifyCalculated(t)}let o=n;const s=this._volatile;let i=++l_,a=this._collectDirties(i,o,r.all(),s);if(r.clear(),s.clear(),!o&&0===a.length)return this._notifyCalculated(t);o&&this._clearCalcs();const l=this._resetScope();for(;a.length>0;){i=++l_;const t=this._markAndPlan(o,a,i).onces;if(t){const e=this._precedentSpatial,n=t.length;for(let r=0;r<n;r++)e.remove(t[r],Gp)}a.length=0;const e=this._evaluate(o);if(e.dynamic&&this._precedentSpatial.load(e.dynamic),l.dynamicPrecedentsInserts&&(this._precedentSpatial.load(l.dynamicPrecedentsInserts),l.dynamicPrecedentsInserts=[]),l.conflatingFormats){const t=l.conflatingFormats.done(!0),e=this._notifyFormats;for(let n=0;n<t.length;n++){const r=t[n];e.insertNonOverlapping(r)}l.conflatingFormats=null}e.completed||(o=!1,i=++l_,a=this._collectDirties(i,o,r.all(),s),r.clear())}return this._clearScope(),this._notifyCalculated(t)}_clearScope(){const t=this._calculation._getScope();t&&(t.rowIndex=0,t.colIndex=0,t.node=null,t.values=this._values,t.formulaSpatial=this._formulaSpatial,t.volatile=this._volatile,t.conflatingFormats=null,t.dynamicPrecedentsInserts=null,t.formula=null,t.getEntireCoords=Xh)}_resetScope(){const t=this._calculation._getScope();if(t)return t.rowIndex=0,t.colIndex=0,t.node=null,t.values=this._values,t.formulaSpatial=this._formulaSpatial,t.volatile=this._volatile,t.conflatingFormats=null,t.dynamicPrecedentsInserts=null,t.formula=null,t.getEntireCoords=this._getEntireCoords,t}_clearCalcs(){const t=this._values,e=this._spillSpatial,n=this._contentfulSpatial,r=e.all();for(let e=0;e<r.length;e++){const o=r[e];o.value.getError()||(t.delete(o),n.insertNonOverlapping({...o,value:null}))}e.clear(),this._errorSpatial.clear(),this._pendingSpatial.clear(),this._volatile.clear(),this._clearNotifications()}_clearNotifications(){this._invalidations.clear(),this._notifyValues.clear(),this._notifySpills.clear(),this._notifyFormats.clear(),this._notifyPending.clear()}_clearAll(){1!==this._cycleId&&this._cycleId++,l_++,this._formulaSpatial.clear(),this._contentfulSpatial.clear(),this._pendingInvalidations.clear(),this._values.clear(),this._precedentSpatial.clear(),this._volatile.clear(),this._spillSpatial.clear(),this._errorSpatial.clear(),this._pendingSpatial.clear(),this._clearNotifications(),this._notifyFormulaInsertEntries=void 0,this._notifyFormulaRemoveEntries=void 0}_addToPending(t){let e=this._pendingActions;if(!e){this._pendingActions=e=[];const t=this;t._calculation.addListeners({onReady:()=>{(async()=>{const e=t._pendingActions,n=e.length;for(let r=0;r<n;r++){const n=e[r],o=await n.bind(t)();t._options.onCalculated?.(o)}this._pendingActions=null})()},onError:()=>{}},{once:!0})}e.push(t)}fromJSON(t){const n=this._calculation.getStatus();if(n===Hp.Status.Starting)return void this._addToPending(()=>Promise.resolve(this.fromJSON(t)));if(n!==Hp.Status.Ready)return;this._clearAll();const o={cycleId:0,isFull:!0};if(!t)return o;this._isProcessingJSON=!0;try{if(t.data){const n=t.data;this._values.setValues(n);const r=this._values.getOrientation()===e.Orientation.Column,o=ad(n,r);this._contentfulSpatial.load(o)}const n=this._formulaSpatial,s=t.formulas;if(s){const e=t.dynamic,i=new Set;if(e){const t=e.length;for(let n=0;n<t;n++){const t=e[n],r=t[0].split(":")[0];i.add(r)}}const a=s.length,l=new Array(a),c=[],h=[],u=this._calculation._getContext(),d=this._calculation._getScope();d.colIndex=0,d.rowIndex=0;const g=this._getFormulaParser();for(let t=0;t<a;t++){const e=s[t],n=e[0],o=Vu(n),a=e[1],m=o.rowStart,f=o.colStart;d.colIndex=f,d.rowIndex=m;let p=g.parse(u,a);const _=p.getDirectPrecedentsAt(m,f,!0,r_,o_),S=_.length;1===S&&(p=p.wrapImplicit(m,f,i));const w={...o},y=new hd(w,p);o.value=y,l[t]=o;const E=o.rowEnd,b=o.colEnd-f,v=E-m,C=[];for(let t=0;t<S;t++){const e=_[t];if(e instanceof r.Known)continue;const n=r_[t],s=o_[t],i={colStart:e.colStart,rowStart:e.rowStart,colEnd:e.colEnd+(s?0:b),rowEnd:e.rowEnd+(n?0:v),value:{blockEntry:o,width:b+1,height:v+1,index:t,$absWidth:s,$absHeight:n,once:null}};C.push(e),h.push(i)}c.push({colStart:w.colStart,rowStart:w.rowStart,colEnd:w.colEnd,rowEnd:w.rowEnd,value:{tokens:p.getTokens(),references:p.getReferences(),precedents:C}})}if(n.load(l),this._precedentSpatial.load(h),c.length>0&&(o.formulaInserts=c),e){const t=[],s=[];let i;const a=this._values,l=e.length;for(let o=0;o<l;o++){const l=e[o],c=l[0],h=Vu(c),u=l[1],d={...h},g=d.colStart,m=d.rowStart,f=d.colEnd,p=d.rowEnd;s_.colStart=g,s_.rowStart=m,s_.colEnd=g,s_.rowEnd=m;const _=n.search(s_);if(1!==_.length)continue;const S=_[0].value,w=S.ref,y=S.calcs,E=m-w.rowStart,b=g-w.colStart,v=y[E][b];if(u)v.cachedValue=r.BuiltIn.Spill;else{const t=new Uh(a,d);v.cachedValue=t}h.value=new sd(d,0,u),s.push(h);const C={colStart:g,rowStart:m,colEnd:f,rowEnd:p,value:u};W.isSingleCell(C)||t.push(C),Kp(i,v,d)}this._spillSpatial.load(s),this._precedentSpatial.load(i),t.length>0&&(o.spillInserts=t)}const m=t.volatile,f=m?m.length:0;if(f>0){const t=this._volatile,e=e=>{t.add(e)};for(let t=0;t<f;t++){const r=m[t],o=Vu(r,s_),s=n.search(o),i=s.length;for(let t=0;t<i;t++){const n=s[t];Qp(n,o,e)}}}}}catch(t){throw t}finally{this._isProcessingJSON=!1}return o}async toJSON(t=!1){const n=this._formulaSpatial.all(),r=n.length;if(0===r)return null;const o={};if(r>0){const t=new Array(r);for(let e=0;e<r;e++){const r=n[e];t[e]=r.value.toJSON()}o.formulas=t}const s=this._spillSpatial.all(),i=s.length;if(i>0){const t=this._getEntireCoords(),e=new Array(i);for(let n=0;n<i;n++){const r=s[n],o=Au(r,t);e[n]=[o,r.value.getError()]}o.dynamic=e}const a=this._volatile;if(a.size>0){const t=a.values();let n=t.next();const r=this._values.getOrientation()===e.Orientation.Column,s=ch(!0);for(;!n.done;){const e=n.value;if(Array.isArray(e))for(let t=0;t<e.length;t++){const n=e[t];for(let t=0;t<n.length;t++){const e=n[t],o=e.colIndex,i=e.rowIndex,a=r?o:i,l=r?i:o;s.append(a,l)}}else{const t=e.colIndex,n=e.rowIndex,o=r?t:n,i=r?n:t;s.append(o,i)}n=t.next()}const i=s.done(!0),l=i.length,c=new Array(l);for(let t=0;t<l;t++){const e=i[t],n=Au(e,this._getEntireCoords());c[t]=n}o.volatile=c}return o}}const Zp=(t,e,n,r)=>{const o=new Ke.Builder(a_),s=ch(r);t.sort(r?W.columnFirstCellComparator:W.rowFirstCellComparator);const i=t.length;for(let e=0;e<i;e++){const n=t[e],i=n.colIndex,a=n.rowIndex;let l=n.cachedValue;if(!l?.isIRange){const t=r?i:a,e=r?a:i;let l=n.cachedValue;o.addValue(t,e,l),s.append(t,e)}}const a=o.build();a&&a.tuples&&e.setValues(a.tuples);const l=s.done(!0);for(let t=0;t<l.length;t++){const e=l[t];n.insertNonOverlapping(e)}},Qp=(t,e,n)=>{const r=t.colStart,o=t.rowStart,s=t.colEnd,i=t.rowEnd,a=e.colStart,l=e.rowStart,c=e.colEnd,h=e.rowEnd,u=Math.max(r,a),d=Math.max(o,l),g=Math.min(s,c),m=Math.min(i,h),f=t.value.calcs;for(let t=d;t<=m;t++){const e=t-o,s=f[e];for(let t=u;t<=g;t++){const o=t-r;n(s[o],e,o)}}},t_=(t,e,n,r)=>{const o=t.value,s=o.$absHeight,i=o.$absWidth,a=o.width,l=o.height,c=o.blockEntry.value.calcs,h=n-t.colStart,u=e-t.rowStart,d=Math.min(Math.max(h,0),a-1),g=Math.min(Math.max(u,0),l-1);if(s||i)if(i){const t=c[g];for(let e=0;e<a;e++){r(t[e])}}else if(s)for(let t=0;t<l;t++){r(c[t][d])}else for(let t=0;t<l;t++){const e=c[t];for(let t=0;t<a;t++){r(e[t])}}else{r(c[g][d])}},e_={rowIndex:0,colIndex:0},n_={rowStart:0,colStart:0,rowEnd:0,colEnd:0},r_=[],o_=[],s_={rowStart:0,colStart:0,rowEnd:0,colEnd:0},i_={rowStart:0,colStart:0,rowEnd:0,colEnd:0};new r.Calc("Cyclical dependency");const a_=t=>new ql(t);let l_=0;const c_=1e4,h_=new Array(c_),u_=new Array(c_),d_=new Set,g_=new Array(c_);let m_=0;const f_=new Array(c_);let p_=0,__=0;const S_=new Array(c_);let w_=0,y_=0;const E_=new Array(c_);let b_=0;const v_=new Array(c_),C_={colStart:0,rowStart:0,colEnd:0,rowEnd:0},x_={colStart:0,rowStart:0,colEnd:0,rowEnd:0},I_=[null,null],A_=Object.freeze({inserts:_t.EmptyArray,removes:_t.EmptyArray});function R_(t,e,n,r){const o=t;if(o?.getSplit){const t=o.getSplit(e,n,r);if(void 0===t)return;e[0].value=t[0],e[1].value=t[1]}return e}class M_{constructor(t,e=!0){this._options={...F_,...t},this._getFunction=this._options.getFunction,this._isColumn=e}_setInstanceScope(t){this._instanceScope=t}async _initialize(){const t=await Ie._validate(!0),e=N_();this._calcScope=e,this._runtime=new T_(this._options,t);const{initializeBuiltIns:n}=await import("./ByHA0yF73W3Lubv1.mjs"),r=this;return this._builtInFunctions=Object.freeze(n(()=>r)),{builtInFunctions:this._builtInFunctions,calcScope:this._calcScope}}getBuiltInFunctions(){return this._builtInFunctions}getFunction(t){return this._builtInFunctions.get(t)??this._getFunction?.(t)}getNumberFormat(t,e){return el.Parser.formatValue(t,e,{date1904:this._options.isDate1904?.()??!1})}getEntireCoords(){return this._calcScope.getEntireCoords()}getFormulaAt(t,e){const n=this._calcScope.formulaSpatial;if(!n)return null;O_.colStart=e,O_.rowStart=t,O_.colEnd=e,O_.rowEnd=t;const r=n.search(O_);if(0===r.length)return null;return r[0].value.formula.getTextAt(t,e)??null}markVolatile(){const t=this._calcScope,e=t.volatile;e&&e.add(t.node)}formatResults(t){const e=this._calcScope,n=this._isColumn,r=n?e.colIndex:e.rowIndex,o=n?e.rowIndex:e.colIndex;e.conflatingFormats||(e.conflatingFormats=ch(n)),e.conflatingFormats.append(r,o,t)}getSheetIndex(t){const e=this._calcScope;return void 0===t&&(t=e.sheetName),this._options.getSheetIndex?.(t)??-1}getSheetCount(){return this._options.getSheetCount?.()??1}isValidDate(t){return ms(t)}fromOADate(t){return ys(t,this._options.isDate1904?.()??!1)}toOADate(t){return Es(t,this._options.isDate1904?.()??!1)}_fromTuples(t,n=null,r=!1){if(!t)return null;const o=Yc(t.bounds,!0),s=this._calcScope,i=this._isColumn?e.Orientation.Column:e.Orientation.Row,a=new hh({orientation:i,maxCoords:s.getEntireCoords()});a.setValues(t.tuples);return new Uh(a,o,n,r)}getValueAt(t,e){return this._calcScope.values.getValueAt(t,e)??null}getSpillAt(t,e){const n=this._calcScope.spillSpatial;if(!n)return null;L_.rowStart=t,L_.colStart=e,L_.rowEnd=t,L_.colEnd=e;const r=n.search(L_);if(0===r.length)return null;for(let n=0;n<r.length;n++){const o=r[n];if(o.rowStart===t&&o.colStart===e)return this.getReference(W.sanitizeRange(o))}return null}getRange(t,n){if(t?.isIRange)return t;let o;const s=Array.isArray(t);if(n=n??s,s)if(Array.isArray(t[0]))o=t;else{if(t[0]?.isIRange)throw r.BuiltIn.Value;o=[t]}else o=[[t]];const i=this._isColumn,a=i?e.Orientation.Column:e.Orientation.Row,l=this._fromTuples(sh(o,i,Kc(0,0,void 0,void 0,i),!0),void 0,n);if(l)return l;const c=new hh({orientation:a,maxCoords:this._calcScope.getEntireCoords()});return new Uh(c,W.EmptyRange,void 0,n)}getPosition(){const t=this._calcScope;return{colIndex:t.colIndex,rowIndex:t.rowIndex}}getReference(t,e){if(!t)throw r.BuiltIn.Ref;const n=this._calcScope,o=n.getEntireCoords;if("string"==typeof t){if(e)throw r.BuiltIn.Ref;try{const n=Bu(t,o(),ku,()=>{throw r.BuiltIn.Ref},e);if(n.length>1)throw r.BuiltIn.Ref;t=n[0]}catch(t){throw r.BuiltIn.Ref}}if(!t)throw r.BuiltIn.Ref;const s=n.values;let i;const a=n.node;let l;if(a){const e=a.precedents;l=k_(e,t)}if(l){const e=l.calc;i=e&&e.isIReferenceRange?e.cachedValue:new $p(s,void 0,t,null,o)}else n.dynamicPrecedentsInserts=Kp(n.dynamicPrecedentsInserts,a,t),i=new $p(s,void 0,t,null,o);return i}getAddress(t,e=!1){t||(t=this.getPosition());const n=this.getEntireCoords().sheetName;return void 0!==t.colIndex?((t,e,n=!1)=>n?Ku(t,e):Ru(t,e))(t,n,e):((t,e,n=!1)=>(n?Ku({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart,sheetName:t.sheetName},e):Ru({colIndex:t.colStart,rowIndex:t.rowStart,$colIndex:t.$colStart,$rowIndex:t.$rowStart,sheetName:t.sheetName},e))+":"+(n?Ku({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd},null):Ru({colIndex:t.colEnd,rowIndex:t.rowEnd,$colIndex:t.$colEnd,$rowIndex:t.$rowEnd},null)))(t,n,e)}parseAsDateTime(t,e=!1){return function(t,e=!1,n=!1){let r=t,o=Ns(t,e,!0);o&&(r=o.leadingText);let s=null;if(r.trim().length>0&&(s=ks(r,e),!s&&n))return null;!s&&o?.leadingText.trim().length>0&&(o=null);let i=0;return s&&(i+=s.asOADate),o&&(i+=o.parsed.oaDateTime),i}(t,this._options.isDate1904?.()??!1,e)}getRuntime(){return this._runtime}get[Symbol.toStringTag](){return"[CalculationContext]"}toString(){let t="";const e=this._instanceScope;let n;if(e&&(n=e.toString?.()),n){n&&(t=`${t}:[${n}]`)}return t}}class T_{constructor(t,e){this._options=t,this._license=e}getCurrencySymbol(){return"$"}getNumberDecimalSeparator(){return"."}getNumberGroupSeparator(){return","}isDate1904(){return this._options.isDate1904?.()??!1}getDescription(){return"Calculation Runtime"}getLocation(){return _t.isNode()?process.cwd():window.location?.href??"/"}getVersion(){try{const t="0.4.12";if(-1===t.indexOf(".env."))return`${t}`}catch(t){return"local"}}getOS(){return _t.getOS()}getUser(){return this._license?.licensee?.()??null}}const N_=()=>({rowIndex:0,colIndex:0,sheetName:null,node:null,values:null,formulaSpatial:null,spillSpatial:null,volatile:null,conflatingFormats:null,dynamicPrecedentsInserts:null,formula:null,getEntireCoords:()=>qh}),F_={getSheetIndex:t=>-1,getSheetCount:()=>1,getSheetName:()=>null,getEntireCoords:()=>qh,getNamed:(t,e)=>null,getFunction:t=>null,isDate1904:()=>!1},k_=(t,e)=>{if(!t)return;const n=t.length;if(0===n)return;const r=e.colStart,o=e.rowStart,s=e.colEnd,i=e.rowEnd;for(let e=0;e<n;e++){const n=t[e],a=n;if(void 0!==a&&(n.colStart===r&&n.rowStart===o&&n.colEnd===s&&n.rowEnd===i))return a}return null},O_={rowStart:0,colStart:0,rowEnd:0,colEnd:0},L_={rowStart:0,colStart:0,rowEnd:0,colEnd:0};class D_{_setScope(t){this._scope=t}_getScope(t=!1){const e=this._scope;if(!e&&!t)throw new Error("FunctionContext can only be used in a function.");return e}getNumberFormat(t,e){return this._getScope().getNumberFormat(t,e)}getEntireCoords(){return this._getScope().getEntireCoords()??qh}isValidDate(t){return this._getScope().isValidDate(t)}parseAsDateTime(t,e){return this._getScope().parseAsDateTime(t,e)}fromOADate(t){return this._getScope().fromOADate(t)}toOADate(t){return this._getScope().toOADate(t)}getRange(t){return this._getScope().getRange(t)}getValueAt(t,e){return this._getScope().getValueAt(t,e)}getPosition(){return this._getScope().getPosition?.()??Jh}getReference(t,e){return this._getScope().getReference(t,e)}getFormulaAt(t,e){return this._getScope().getFormulaAt?.(t,e)??null}getSpillAt(t,e){return this._getScope().getSpillAt?.(t,e)??null}getSheetIndex(t){return this._getScope().getSheetIndex?.(t)??-1}getSheetCount(){return this._getScope().getSheetCount?.()??1}markVolatile(){this._getScope().markVolatile?.()}formatResults(t){this._getScope().formatResults?.(t)}getFunction(t){return this._getScope().getFunction?.(t)??null}getAddress(t,e){return this._getScope().getAddress(t,e)}getRuntime(){return this._getScope().getRuntime()}get[Symbol.toStringTag](){return"[FormulaContext]"}toString(){const t=this._getScope();if(t){const e=t.toString?.();if(e)return e}return""+(t?"":"{NO SCOPE}")}}const B_=new D_,z_="__SHEETXL";let P_;const j_={FormulaContext:P_,ScalarType:t,IRange:e,FormulaError:r,Observable:d};let H_;function V_(t){P_||(P_=B_,j_.FormulaContext=P_),H_=globalThis[z_],globalThis[z_]=j_,P_._setScope(t)}function $_(){H_?(globalThis[z_]=H_,H_=void 0):delete globalThis[z_],P_&&P_._setScope(null)}var U_;(U_||(U_={})).Context={Workbook:"workbook",Sheet:"sheet",Ranges:"ranges",Range:"range",Calculation:"calculation"};class G_{constructor(t,e,n,r=null,o=!1){this._ct=U_.Context.Calculation,this._builtIn=!1,this._broadcast=!1,this._pj=null,this._json=t,this._n=t.name,this._d=new Y_(t),this._ct=t.context??U_.Context.Calculation;const s=t.parameters;let i;this._pj=s,e||(console.log(`TypeFunction '${t.name}' was not provided a function implementation.`),e=()=>{}),this._fn=e.bind(this),this._cf=n??q_,this._builtIn=o,i=r?"function"==typeof r?r:()=>Promise.resolve(r):W_(t),this._descFn=i;const a=s?.length??0;let l=1===a||2===a;l&&(s[0].arrayDepth>0||s[0].range)&&(l=!1),l&&2===a&&(s[1].arrayDepth>0||s[1].range)&&(l=!1),this._broadcast=l}execute(...e){const n=this._pj,o=[],s=this._cf?.();V_(s);let i=!1,a=null;const l=n?.length??0;let c,h=this._broadcast;if(h){const t=eu(e[0]);if(1===l&&t)h=!1;else if(2===l){const n=eu(e[1]);t&&n&&(h=!1)}}try{for(let r=0;!i&&r<l;r++){const l=n[r];let c=l.scalar??null;c!==t.Null&&"*"!==c||(c=null);let u=l.range??null;const d=l.rest??!1,g=l.optional??!1;let m=e[r];if(g&&null===m&&(m=void 0),void 0===m){if(g){o.push(void 0);continue}if(!g&&!d)throw r<=e.length?tS.ARGS_TOO_FEW([l.name],this._n):tS.PARAM_MISSING(l.name,this._n);if(r>=e.length){i=!0;continue}}const f=l.arrayDepth??0;let p=(l.range?2:0)+f;const _=l.rest??!1;if(_)for(;r<e.length&&!a;)void 0!==m&&(a=Q_(s,o,m,c,u,f,_,p)),m=e[++r];else h&&(u="l",p=2),a=Q_(s,o,m,c,u,f,_,p),i=!!a}if(a)throw a;for(;o.length>0&&void 0===o[o.length-1];)o.length--;const u=this._fn;if(h){if(1===o.length){const e=o[0];let s=n[0].scalar;s!==t.Null&&"*"!==s||(s=null),c=e.map(t=>{if(t instanceof r.Known)return t;let e=t;try{e=u(e),(Array.isArray(e)||e?.isIRange)&&(e=r.BuiltIn.Value)}catch(t){e=t}return e},{type:s})}if(2===o.length){const e=o[0];let s=n[0].scalar;s!==t.Null&&"*"!==s||(s=null);const i=o[1];let a=n[1].scalar;a!==t.Null&&"*"!==a||(a=null),c=e.broadcast(i,(t,e)=>{if(t instanceof r.Known)return t;if(e instanceof r.Known)return e;let n;try{n=u(t,e),(Array.isArray(n)||n?.isIRange)&&(n=r.BuiltIn.Value)}catch(t){n=t}return n},{type:s,otherType:a})}}else c=u(...o);c=ou(c,s)}catch(t){throw t}finally{$_()}return c}getName(){return this._n}getDeclaration(){return this._d}async getDescriptor(t){if(this._desc)return this._desc;const e=await Promise.resolve(this._descFn(t));return this._desc=new Z_(this,e),this._desc}isBuiltIn(){return this._builtIn}getContext(){const t=this._ct;if("sheet"===t||"workbook"===t||"ranges"===t||"range"===t){const t=this._json;return t&&t.behavior&&t.behavior.default?"autoRun":"macro"}return"formula"}get[Symbol.toStringTag](){return"[TypedFunction]"}toString(){let t="";const e=this._pj;return e.length>0&&(t=e.map(t=>{let e=t.name;return t.rest&&(e="..."+e),t.optional&&(e+="?"),e+=": "+((t,e)=>{if(e){const n=Zh.get(e)??"InvalidRange";return t?`${n}<${Yh.get(t)??"InvalidScalar"}>`:n}return Yh.get(t)??"InvalidScalar"})(t.scalar,t.range),e+="[]".repeat(t.arrayDepth),e}).join(", ")),`${this.getName()}(${t})`}get isIFunction(){return!0}get isITypedFunction(){return!0}}const W_=t=>async e=>{const n={};for(let e=0;e<t.parameters.length;e++)n[t.parameters[e].name]=_t.camelToPrettyCase(t.parameters[e].description);return{summary:_t.camelToPrettyCase(t.name),parameters:n,category:"User Defined"}},q_=()=>null;class J_{constructor(t){this._s=t.scalar,this._r=t.range??null,this._d=t.arrayDepth??0}getScalarType(){return this._s}getRangeType(){return this._r}getArrayDepth(){return this._d}}class X_ extends J_{constructor(t){super(t),this._n=t.name,this._o=t.optional??!1,this._rest=t.rest??!1,this._e=t.enums?Object.freeze(t.enums):_t.EmptyArray}getName(){return this._n}isOptional(){return this._o}isRest(){return this._rest}getEnums(){return this._e}}class K_ extends J_{constructor(t){super(t),this._a=t.async??!1,this._stream=t.stream??!1}isAsync(){return this._a}isStreaming(){return this._stream}}class Y_{constructor(t){if(this._n=t.name,t.parameters){const e=t.parameters.length,n=new Array(e);for(let r=0;r<e;r++)n[r]=new X_(t.parameters[r]);this._p=Object.freeze(n)}else this._p=_t.EmptyArray;t.returnType?this._r=new K_(t.returnType):this._r=new K_({scalar:null,arrayDepth:0,range:null})}getName(){return this._n}getParameters(){return this._p}getReturnType(){return this._r}}class Z_{constructor(t,e){if(this._n=e.name,this._fn=t,this._s=e.summary??_t.camelToPrettyCase(e.name),this._c=e.category??"Uncategorized",this._h=e.hidden??!1,e.links&&e.links.length>0){const t=e.links.length,n=new Array(t);for(let r=0;r<t;r++)n[r]=Object.freeze([e.links[r][0],e.links[r][1]]);this._l=Object.freeze(n)}else this._l=_t.EmptyArray;if(e.parameters)for(const t in e.parameters)if(Object.prototype.hasOwnProperty.call(e.parameters,t)){const n=e.parameters[t].description,r=e.parameters[t].example,o=e.parameters[t].defaultValue,s={};n&&(s.description=n),r&&(s.example=r),void 0!==o&&(s.defaultValue=o),Object.freeze(s)}}getName(){return this._n}getSummary(){return this._s}getCategory(){return this._c}isHidden(){return this._h}getLinks(){return this._l}getParameters(){return this._p}get[Symbol.toStringTag](){return"[Descriptor]"}toString(){const t=this._fn;return`${this.getSummary()}: ${t}`}}const Q_=(t,e,n,o,s,i,a,l)=>{if(n&&void 0!==n.colStart)if(s)n=t.getReference?.(n);else{const e=n.colStart,r=n.rowStart,o=n.colEnd;n=n.rowEnd!==r||e!==o?t.getReference?.(n):t.getValueAt(r,e)}if(0===l){let t=((t,e=null,n=!1)=>{let o=t;for(;Array.isArray(o);){if(o.length>1)return n?r.BuiltIn.Value:o;o=o[0]}if(o?.isIRange){if(1!==o.size)return n?r.BuiltIn.Value:o;o=o.getValueAt(0,0)}return e&&(o=tu(o,Kh(o,!0),e)),o})(n,o,!0);return t instanceof r.Known?t:void e.push(t)}if(2===l)return ru(t,e,n,o,s,Array.isArray(n));if(1===l||3===l){let r;const i=a?e:[];if(s){const e=Array.isArray(n);if(e){const a=n.length;for(let l=0;!r&&l<a;l++)r=ru(t,i,n[l],o,s,e)}else r=ru(t,i,n,o,s,e)}else if(3===l){let e=(t=>{let e=t,n=0;for(;Array.isArray(e);)n++,e=e[0];return e.isIRange&&(n+=2),n})(n);for(let t=e;t<2;t++)n=[n],e++;if(3===e){const e=n.length;for(let a=0;!r&&a<e;a++)r=ru(t,i,n[a],o,s,!0)}else r=ru(t,i,n,o,s,!0)}else r=nu(t,i,n,o,s,null!==s);return r?.isFormulaError?r:void(a||e.push(i))}{if(!Array.isArray(n)){if(o&&(n=tu(n,Kh(n,!0),o,!1),n?.isFormulaError))return e.push(n),n;n=[n]}const r=n.length;for(let c=0;c<r;c++){const r=[],h=Q_(t,r,n[c],o,s,i,a,l-1);if(h?.isFormulaError)return h;r.length>0&&e.push(r)}}},tS={PARAM_MISSING:(t,e)=>new r.NA(`Parameter ${t} is missing${e?` for ${e}`:""}.`),ARGS_TOO_FEW:(t,e)=>new r.Parse(`Argument type ${t.join(", ")} is missing${e?` for ${e}`:""}.`)};class eS{constructor(t){this._emitter=null,this._readonly=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new ie({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,n,r){e._emitter.notify("onCollectionChange")}}),this._emitter=new Ll(this,this._transactions),this._readonly=t?.readonlyFunctions,this._initState()}search(t){const e=this._getState();if(!e)return _t.EmptyArray;const n=t?.name?t.name.toUpperCase():null,r=t?.type?t.type:null;let o;t?.category&&t.category.toUpperCase(),t?.text&&t.text;const s=(t,e)=>(!n||e===n)&&((!r||t.getContext()===r)&&(o||(o=[]),void o.push(t))),i=this._readonly;return i&&i.forEach(s),e.itemsByKey.forEach(s),o??_t.EmptyArray}getByName(t){if(!t)return null;const e=this._getState();if(!e)return null;if(!e)return _t.EmptyArray;const n=t.toUpperCase(),r=this._readonly;if(!r||!r.size)return null;let o=r.get(n);return o||(o=e.itemsByKey.get(n),o||null)}getCount(){const t=this._getState();if(!t)return 0;let e=t.itemsByKey.size;return this._readonly&&(e+=this._readonly.size),e}validateName(t){return this._validateName(t)}_validateName(t,e=!1){if(this._closed)throw new Error(kl)}add(t){if(this._closed)throw new Error(kl);if(!t)throw new Error("Item must be specified.");let e;if(t.isIFunction){const n=t,r=t._json;e=new G_(r,n._fn,()=>this._options.context,n._desc)}else{const n=t;e=new G_(n.declaration,n.execute,()=>this._options.context,n.descriptor)}const n=this._getState(),r=e.getName().toUpperCase();return n.itemsByKey.set(r,e),e}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(kl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update",n){if(!t)return;const r=this._beginCommit(e);try{r.updateState(this,t),r.commit(n)}catch(t){throw r.rollback(),t}}_initState(){this._updateState(t=>({...t,itemsByKey:new Map}),"Initialize",{forceAmend:!0})}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}}class nS extends Dl{constructor(t){super(t),this._status=Hp.Status.Off,this._statusTransition=null,this._emitter=new Ll(this)}_getContext(){return this._context}_getScope(){return this._scope}start(){return this._statusTransition||(this._statusTransition=(async()=>{if(this._status===Hp.Status.Off)try{this._status=Hp.Status.Starting,this._emitter.notify("onStatusChange"),this._emitter.notify("onStarting");const t=this,e=this._options,n=n=>t.getFunctions().getByName(n)??e?.getFunction?.(n),r=new M_({...e,getFunction:n});this._context=r;const o=await r._initialize(),s=o.builtInFunctions;this._functions=new eS({transactions:this._transactions,context:r,readonlyFunctions:s});const i=await import("./BuJVzVii6s-ETLFo.mjs");this._formulaParser=new i.FormulaParser,this._scope=o.calcScope,this._status=Hp.Status.Ready,this._emitter.notify("onStatusChange"),this._emitter.notify("onReady")}catch(t){throw this._status=Hp.Status.Off,this._emitter.notify("onError",t),this._emitter.notify("onStatusChange"),t}finally{this._statusTransition=null}})()),this._statusTransition}_createGraph(t){const e=this._options;return new Yp({...e,...t,getFormulaParser:()=>this._formulaParser,calculation:this})}async stop(){this._status===Hp.Status.Ready&&(this._status=Hp.Status.Stopping,this._emitter.notify("onStatusChange"),this._emitter.notify("onStopping"),this._status=Hp.Status.Off,this._emitter.notify("onStatusChange"),this._emitter.notify("onStop"))}getStatus(){return this._status}getFunctions(){return this._checkReady(),this._functions}getRuntime(){return this._checkReady(),this._runtime}_checkReady(){if(this._status!==Hp.Status.Ready)throw new Error(this._statusMessage())}_statusMessage(){switch(this._status){case Hp.Status.Off:return"Calculation is off";case Hp.Status.Starting:return"Calculation is starting";case Hp.Status.Ready:return"Calculation is ready";default:return"Unknown calculation status"}}}var rS,oS,sS,iS,aS,lS,cS,hS;rS||(rS={}),oS||(oS={}),sS||(sS={}),(aS=iS||(iS={})).NumberFilterOperatorType={Equal:"equal",GreaterThan:"greaterThan",GreaterThanOrEqual:"greaterThanOrEqual",LessThan:"lessThan",LessThanOrEqual:"lessThanOrEqual",NotEqual:"notEqual"},aS.Type={Color:"color",Custom:"custom",Dynamic:"dynamic",Items:"items",Icon:"icon",Top10:"top10"},aS.DynamicType={AboveAverage:"aboveAverage",BelowAverage:"belowAverage",LastMonth:"lastMonth",LastQuarter:"lastQuarter",LastWeek:"lastWeek",LastYear:"lastYear",M1:"M1",M2:"M2",M3:"M3",M4:"M4",M5:"M5",M6:"M6",M7:"M7",M8:"M8",M9:"M9",M10:"M10",M11:"M11",M12:"M12",NextMonth:"nextMonth",NextQuarter:"nextQuarter",NextWeek:"nextWeek",Null:"null",Q1:"Q1",Q2:"Q2",Q3:"Q3",Q4:"Q4",ThisMonth:"thisMonth",ThisQuarter:"thisQuarter",ThisWeek:"thisWeek",Today:"today",Tomorrow:"tomorrow",YearToDate:"yearToDate",Yesterday:"yesterday"},aS.DateItemGroupingType={Day:"day",Hour:"hour",Minute:"minute",Month:"month",Second:"Second",Year:"year"},(cS=lS||(lS={})).Type={AboveAverage:"aboveAverage",BeginsWith:"beginsWith",CellIs:"cellIs",ColorScale:"colorScale",ContainsBlanks:"containsBlanks",ContainsErrors:"containsErrors",ContainsText:"containsText",DataBar:"dataBar",DuplicateValues:"duplicateValues",EndsWith:"endsWith",Expression:"expression",IconSet:"iconSet",NotContainsBlanks:"notContainsBlanks",NotContainsErrors:"notContainsErrors",NotContainsText:"notContainsText",TimePeriod:"timePeriod",Top10:"top10",UniqueValues:"uniqueValues"},cS.OperatorType={BeginsWith:"beginsWith",Between:"between",ContainsText:"containsText",EndsWith:"endsWith",Equal:"equal",GreaterThan:"greaterThan",GreaterThanOrEqual:"greaterThanOrEqual",LessThan:"lessThan",LessThanOrEqual:"lessThanOrEqual",NotBetween:"notBetween",NotContains:"notContains",NotEqual:"notEqual"},cS.TimePeriod={Last7Days:"last7Days",LastMonth:"lastMonth",LastWeek:"lastWeek",NextMonth:"nextMonth",NextWeek:"nextWeek",ThisMonth:"thisMonth",ThisWeek:"thisWeek",Today:"today",Tomorrow:"tomorrow",Yesterday:"yesterday"},cS.ConditionalBoundsType={Formula:"formula",Max:"max",Min:"min",Num:"num",Percent:"percent",Percentile:"percentile"},(hS||(hS={})).HeaderTextStyle={A1:"a1",Zero:"zero",One:"one"};class uS{constructor(t,e,n,r){this._mergedReading=[],this._colsReading=[],this._rowsReading=[],this._styles=t,this._topLeft=r??{rowIndex:0,colIndex:0},this._sheet=new Dw({styles:this._styles,date1904:e,container:{getName:()=>n,getIndex:()=>1}}),this._cellUpdater=this._sheet.getEntireRange().startIncrementalUpdates()}applyCSSStyle(t,e){let n=!1;t.style||(t.style={},n=!0);let r=t.style,o={...e};if(e.msoIgnore){const t=e.msoIgnore.split(",");let n=Object.keys(o);for(let e=0;e<n.length;e++){const r=n[e];t.includes(r)&&delete o[r]}}const s=Yd(o.fontFamily);r.font={},s&&(r.font.family=s.family,r.font.fallbacks=s.fallbacks,r.font.size=s.size),r.font.size=o.fontSize,r.font.weight=o.fontWeight,r.font.style=o.fontStyle,r.font.fill=o.color;const i=(t=>{if(!t)return eg;let e=fi.UnderlineStyle.None,n=!1;return(t=t.toLowerCase()).includes("underline")&&(e=fi.UnderlineStyle.Single),(t.includes("line-through")||t.includes("linethrough"))&&(n=!0),{underline:e,strike:n}})(o.textDecoration);r.font.underline=i.underline,r.font.strike=i.strike,o.textUnderlineStyle&&(r.font.underline=ng(o.textUnderlineStyle)),r.alignment={},o?.textAlign&&(r.alignment.horizontal=(t=>{const e=_t.textToKey(t);return Em.get(e)||null})(o.textAlign)),o?.textAlign&&!r.alignment.horizontal&&"general"!==o?.textAlign&&("center-across"===o.textAlign?r.alignment.horizontal=zs.HorizontalAlignment.CenterContinuous:"fill"===o.textAlign?r.alignment.horizontal=zs.HorizontalAlignment.Fill:"121"===o.textAlign||"010"===o.textAlign?(r.alignment.horizontal=zs.HorizontalAlignment.Distributed,r.alignment.justifyLastLine="121"===o.textAlign):console.warn("unknown text-align",o.textAlign)),o.verticalAlign&&("super"===o.verticalAlign.toLowerCase()?r.font.verticalAlign=fi.VerticalAlignment.Super:"sup"===o.verticalAlign.toLowerCase()?r.font.verticalAlign=fi.VerticalAlignment.Sub:r.alignment.vertical=(t=>{const e=_t.textToKey(t);return bm.get(e)||null})(o.verticalAlign),r.alignment.vertical||("121"===o.verticalAlign?r.alignment.vertical=zs.VerticalAlignment.Distributed:console.warn("unknown vertical-align",o.verticalAlign))),o.msoCharIndentCount&&(r.alignment.indent=o.msoCharIndentCount),o.whiteSpace&&(r.alignment.overflow="no-wrap"===o.whiteSpace||"nowrap"===o.whiteSpace?zs.Overflow.Visible:zs.Overflow.Wrap),"shrinktofit"===o.msoTextControl&&(r.alignment.overflow=zs.Overflow.Shrink);let a=null;if(o.background?a=o.background:o.backgroundColor&&(a=o.backgroundColor),a&&(r.fill={color:a}),o.msoPattern){let t=qg(o.msoPattern);t&&(t.patternType===ya.BuiltInSheetPattern.Solid?r.fill={color:t.foreground}:t.patternType!==ya.BuiltInSheetPattern.None&&(a&&(t.background=a),r.fill=t))}void 0!==o.msoRotate&&(r.alignment.rotation=(t=>{let e=parseFloat(t);return isNaN(e)||(e%=360,e>0?e=360-e:e<0&&(e*=-1)),e})(o.msoRotate));const l=(t,e)=>{t&&(r.border||(r.border={}),r.border[t]=e)};o.border&&"none"!==o.border&&(l("top",o.border),l("left",o.border),l("right",o.border),l("bottom",o.border)),o.borderTop&&l("top",o.borderTop),o.borderLeft&&l("left",o.borderLeft),o.borderRight&&l("right",o.borderRight),o.borderBottom&&l("bottom",o.borderBottom),o.msoDiagonalUp&&l("diagonalUp",o.msoDiagonalUp),o.msoDiagonalDown&&l("diagonalDown",o.msoDiagonalDown);let c=r.numberFormat;o.msoNumberFormat&&(c=(t=>{let e=t.replace(/(\\[0-9]{4})/g,t=>String.fromCharCode(parseInt(t.replace(/\\/g,""),16)));return e=e.replace(/(\\.{1})/g,t=>t.substring(t.length-1,t.length)),e.includes("\\")&&(e=e.replace(/(\\.{1})/g,t=>t.substring(t.length-1,t.length))),e=e.replace(/^"(.*)"$/,"$1"),e})(o.msoNumberFormat),c.includes("\\")?c=null:"Fixed"===c?c=el.Styles.lookupStyle(r.numberFormat).formatType===el.Type.Number?null:el.Type.Number:"Percent"===c&&(c=el.Styles.lookupStyle(r.numberFormat).formatType===el.Type.Percentage?null:el.Type.Percentage)),c&&(r.numberFormat=c),t.style=this._styles.normalize(r),n&&0===Object.keys(t.style).length&&delete t.style}onCell(t,e,n,r,o){const s=r(o);let i={value:void 0!==e?e:n??""};if("string"==typeof i.value&&0===i.value.length&&(i.value=void 0),s&&this.applyCSSStyle(i,s),"TD"===o?.tagName.toUpperCase()){let t=i.style,e=t?.font??{};(o.querySelectorAll("s").length>0||o.querySelectorAll("strike").length>0)&&(e.strike=!0),o.querySelectorAll("sub").length>0&&(e.verticalAlign=fi.VerticalAlignment.Sub),o.querySelectorAll("sup").length>0&&(e.verticalAlign=fi.VerticalAlignment.Super),(o.querySelectorAll("b").length>0||o.querySelectorAll("strong").length>0)&&(e.weight=700),o.querySelectorAll("i").length>0&&(e.style=fi.Style.Italic),o.querySelectorAll("u").length>0&&(e.underline=fi.UnderlineStyle.Single),Object.keys(e).length>0&&(t||(t={},i.style=t),t.font||(t.font=e));const n=o.querySelectorAll("a");if(n.length>0){const t=n[0].getAttribute("href");t&&(i.hyperlink=t)}}if(!W.isSingleCell(t)){const e={rowStart:this._topLeft.rowIndex+t.rowStart,colStart:this._topLeft.colIndex+t.colStart,rowEnd:this._topLeft.rowIndex+t.rowEnd,colEnd:this._topLeft.colIndex+t.colEnd};this._mergedReading.push(e)}if((void 0!==i.value||i.style||!(Object.keys(i).length<=1))&&(this._cellUpdater.pushAt(this._topLeft.rowIndex+t.rowStart,this._topLeft.colIndex+t.colStart,i),!W.isSingleCell(t)&&s.msoIgnore)){if(s.msoIgnore.includes("colspan")){const e={};s&&this.applyCSSStyle(e,s);const n=t.colEnd-t.colStart;for(let r=1;r<=n;r++)this._cellUpdater.pushAt(this._topLeft.rowIndex+t.rowStart,this._topLeft.colIndex+t.colStart+r,e);t={...t,colEnd:t.colStart}}s.msoIgnore.includes("rowspan")&&(t={...t,rowEnd:t.rowStart})}}onNoTable(t,e,n){this.onCell({rowStart:this._topLeft.rowIndex,colStart:this._topLeft.colIndex,rowEnd:this._topLeft.rowIndex,colEnd:this._topLeft.colIndex},t,null,e,n)}onRowStart(t,e,n,r){const o=n(r);if("userset"!==o.msoHeightSource)return;let s=r.getAttribute("height")??o.height,i=null;if(s&&(i=Vg(s,this._styles.getNormal().getFont().getSize(),"px")),null===i)for(let t=0;t<r.cells.length;t++){const e=r.cells[t],o=e.getAttribute("height")??n(e).height;let s=Vg(o,this._styles.getNormal().getFont().getSize(),"px");null!==s&&(i=Math.max(s,i??0))}null!==i&&this._rowsReading.push({address:{min:this._topLeft.rowIndex+t,max:this._topLeft.rowIndex+t+e-1},update:{size:i*fi.getDeviceScale()}})}onColumn(t,e,n,r){const o=n(r);if("userset"!==o.msoWidthSource)return;let s=r.getAttribute("width")??o.width,i=null;s&&(i=Vg(s,this._styles.getNormal().getFont().getSize(),"px")),null!==i&&this._colsReading.push({address:{min:this._topLeft.colIndex+t,max:this._topLeft.colIndex+t+e-1},update:{size:i*fi.getDeviceScale()}})}onDone(){this._colsReading.length>0&&this._sheet.getColumnHeaders().updateHeaderPairs(this._colsReading),this._rowsReading.length>0&&this._sheet.getRowHeaders().updateHeaderPairs(this._rowsReading),this._sheet.doBatch(()=>{this._cellUpdater.apply()}),this._mergedReading.length>0&&this._sheet.getRanges(this._mergedReading).merge()}sheet(){return this._sheet}}let dS=!1;class gS{constructor(t,e){this._mapStylesByName=new Map,this._arrStyleNames=[],this._mapStylesByName=t,this._arrStyleNames=e}setNode(t){this._node=t}addStyle(t,e){null!=e&&(this._node?.styles||(this._node.styles=new Map),this._node.styles.set(t,e))}addAttribute(t,e){null!=e&&(this._node?.attributes||(this._node.attributes=new Map),this._node.attributes.set(t,e),"rowspan"===t.toLowerCase()&&parseInt(e)>1&&(this._node.rowspan=parseInt(e)),"colspan"===t.toLowerCase()&&parseInt(e)>1&&(this._node.colspan=parseInt(e)))}addSharedStyle(t,e){let n=this._mapStylesByName.get(t);n?n={...e}:(this._arrStyleNames.push(t),n=e),this._mapStylesByName.set(t,n)}setPlainText(t){this._node.plainText=t}setHTMLText(t){this._node.htmlText=t.replace(/(?:\r\n|\r|\n)/g,"<br>")}}const mS=t=>{const e={};if(!t)return e;t.endsWith(";")||(t+=";");const n=new RegExp(';(?=([^"]*"[^"]*")*[^"]*$)',"gsm");let r,o=0;for(;null!==(r=n.exec(t));){try{let n=t.substring(o,r.index).trim();const s=new RegExp(':(?=([^"]*"[^"]*")*[^"]*$)',"gsm");let i,a,l;for(;null!==(l=s.exec(n));)i=unescape(n.substring(0,l.index)).trim(),a=unescape(n.substring(l.index+1,n.length)).trim();null!==a&&"null"!==a&&(i&&(i=$s(i)),e[i]=a)}catch(t){console.warn(t)}o=r.index+1}return e},fS=(t,e)=>{const n=[];if(!t)return n;const r=t.children;for(let t=0;t<r.length;t++){const o=r.item(t);if(1===o.nodeType){const t=o.tagName.toUpperCase();e.includes(t)&&n.push(o)}}return n},pS=(t,e,n)=>{try{let r=null,o=null;const s=t=>((t,e)=>{if(!t)return{};let n={},r=e.get(t.localName);r&&(n=Object.assign(n,r));const o=t.getAttribute("class");if(o){const t=e.get("."+o);t&&(n=Object.assign(n,t))}const s=t.getAttribute("style");if(s){const t=mS(s);t&&(n=Object.assign(n,t))}return t.getAttribute("align")&&!n.textAlign&&(n.textAlign=t.getAttribute("align")),n})(t,o);if(t)try{r=[];const i="P, H1, H2, H3, H4, H5, H6, PRE",a=t.querySelector("parsererror");if(a)return console.warn("error",a),!1;const l=t.querySelectorAll("html"),c=l[l.length-1];o=(t=>{const e=t.querySelectorAll("style"),n=new Map;if(e.length<=0)return n;for(let t=0;t<e.length;t++){const r=e[t].childNodes;for(let t=0;t<r.length;t++)if(r[t].nodeType===Node.TEXT_NODE){const e=new RegExp("\x3c!--(.*)--\x3e","gs");let o=r[t].textContent;const s=e.exec(r[t].textContent);if(s&&s.length>1&&(o=s[1]),o=o.replace(/^\s/,""),o?.startsWith("table")){const t=new RegExp("{(.*?)}","gs");let e,r=0;for(;null!==(e=t.exec(o));)try{const t=o.substring(r,e.index),s=mS(e[1]);n.set(t.trim(),s),r=e.index+e[0].length}catch(t){console.warn(t)}return n}}}return n})(c);const h=c.querySelectorAll("body"),u=h[h.length-1];let d=u.querySelectorAll("table");let g=d[0],m=!1;if(!g){let t=u.querySelectorAll("span");g=t[0],m=t.length>1}if(!g){g=fS(u,i)[0]}if(!g){g=fS(t,i)[0]}if("TABLE"===g?.nodeName.toUpperCase()){n.onStart?.(o);const t=g;n.onTableStart?.(s,t);const e=fS(t,"COLGROUP");for(let t=0;e&&t<e.length;t++){const r=fS(e[t],"COL");let o=0;for(let t=0;t<r.length;t++){const e=r[t],i=parseFloat(e.getAttribute("span")),a=isNaN(i)?1:i;n.onColumn?.(o,a,s,e),o+=a}}const i=t.rows;let a=0;for(let t=0;t<i.length;t++){const e=i[t],o=parseFloat(e.getAttribute("span")),l=isNaN(o)?1:o;n.onRowStart?.(a,l,s,e);const c=[];r.push(c);const h=e.cells;for(let t=0;t<h.length;t++){let e=h[t],n=!1;for(let t=0;!n&&t<e.childNodes.length;t++)if(8===e.childNodes[t].nodeType){const r=e.childNodes[t].textContent;if("[if gte vml 1]"===r);else if("[if !vml]"===r);else if("[endif]"===r){const r=e.childNodes[t+1];r?.querySelectorAll&&2===r.querySelectorAll("table, td").length&&(e=r?.querySelectorAll("table, td")[1],n=!0)}}c.push({htmlValue:e.textContent?.replace(/^"|"$/gi,""),element:e})}a+=l,n.onRowDow?.(a,l,s,e)}n.onTableDone?.(s,t)}else{if("SPAN"===g?.nodeName.toUpperCase()){const t=e?e[0]?.[0]:null,r=m&&t?t:g.textContent.replace(/^"|"$/gi,"");return n.onStart?.(o),n.onCell({colStart:0,colEnd:0,rowStart:0,rowEnd:0},e?e[0]?.[0]:null,r,s,g),n.onDone?.(),!0}if(g?.textContent){const t=g.textContent.replace(/^"|"$/gi,"");return n.onStart?.(o),n.onNoTable?.(t,s,g),n.onDone?.(),!0}}}catch(t){console.warn(t),r=null}!r||0!==r.length&&(1!==r.length||null!==r[0]&&0!==r[0].length)||(r=null);const i=e&&(0===e.length||1===e.length&&(null===e[0]||0===e[0].length));r&&i&&(e=null);const a=t=>{const n=new Set;let o=1,i=1;for(let a=0;a<Math.max(e?e.length:0,r?r.length:0);a++){let l=0,c=0,h=r&&r[a]?r[a].length:e[a]?e[a].length:0;for(;c<h;){const h=a+"-"+l;if(!n.has(h)){o=Math.max(o,l+1),i=Math.max(i,a+1);let h=null;const u=r?r[a]?.[c]?.element:void 0;if(u&&(u.getAttribute("rowspan")||u.getAttribute("colspan"))){const t=parseInt(u.getAttribute("colspan"))||1,e=parseInt(u.getAttribute("rowspan"))||1;o=Math.max(o,l+t),i=Math.max(i,a+e),h={rowStart:a,colStart:l,rowEnd:a+Math.max(0,e-1),colEnd:l+Math.max(0,t-1)};for(let r=a;r<a+e;r++)for(let e=l;e<l+t;e++)r===a&&e===l||n.add(r+"-"+e)}else h={rowStart:a,colStart:l,rowEnd:a,colEnd:l};t(h,e?e[a]?.[l]:void 0,r?r[a]?.[c]?.htmlValue:null,s,u||null),c++}l++}}};if(r&&e){let t=0,n=0;a(e=>{t=Math.max(t,e.colEnd+1),n=Math.max(n,e.rowEnd+1)}),e&&r&&(e.length!==n||e[0].length!==t)&&(console.warn("mismatched mimeTypes",e,r),e=null)}return a(n.onCell.bind(n)),n.onDone?.(),!i||null!==r}catch(t){throw console.warn(t),t}};class _S{constructor(t){if(!t)throw new Lt("snapshot is required.");this._snapshot=t}getItemType(){return"range"}getItem(){return this._snapshot}editMode(){return this._snapshot?.getMarkOptions().editMode??null}isCut(){return this._snapshot?.getMarkOptions().isCut??!1}getName(){return this._snapshot.getName()}toText(){return this._snapshot.toText()}toHtml(){return this._snapshot.toHtml()}toImage(){return this._snapshot.toImage()}get isClipboardItem(){return!0}}class SS{constructor(t,e,n,r){if(this._parsed=void 0,!t)throw new Lt("nativeItems are required.");this._native=t,this._markOptions=Object.freeze(e??{}),this._styles=n,this._isDate1904=r}getItemType(){return"range"}isCut(){return!1}toText(){return this._native?.text}toHtml(){return this._native?.html?.documentElement.outerHTML||null}toImage(){return this._native?.image}getItem(){const t=this._parsed;if(void 0===t)throw new Error("Must call 'parse()' before getItem().");if(null===t)return null;if(this._snapshot)return this._snapshot;const e=this;return this._snapshot={copyTo:(n,r)=>t.copyTo(n,{...e._markOptions,...r}),getMarkOptions:()=>e._markOptions,getName:()=>t?.getName()??"Clipboard Data",getCoords:()=>t?.getCoords?.()??null,toText:()=>e.toText(),toHtml:()=>e.toHtml(),toImage:()=>e.toImage(),getSource:()=>t?.getSource?.()??null,isISnapshot:!0},this._snapshot}async parse(){let t,e=this._native?.text,n=this._native.html;if(null===n&&e&&e.includes("<table"))try{const t=(new DOMParser).parseFromString(e,E.html),r=t.querySelector("parsererror");if(r)throw new Error("Unable to parse: "+r);n=t,e=null}catch(t){console.warn("Discovered text as html table but could could not parse.")}try{const r=new uS(this._styles,this._isDate1904,n?"HTML":"Text"),o=await Promise.resolve(e?((t,e="\t")=>new Promise((n,r)=>{import("./ChB6ZgoNr49oUuh9.mjs").then(t=>t.p).then(o=>{try{const r=o.parse(t,{delimiter:e}).data;r.length>1&&(0===r[r.length-1].length||1===r[r.length-1].length&&0===r[r.length-1][0].length)&&r.pop(),n(r)}catch(t){console.warn(t),r(t)}},t=>{r(t)})}))(e):[[]]);let s;if(pS(n,o,r)?(t=r.sheet(),s=t.getUsedRange()):n=null,s)return this._parsed={async copyTo(t,e){const n=await t.copyFrom(s,e);return n?.getCoords()??null},getCoords:()=>s.getCoords(),getSource:()=>t,getName:()=>t.getName()},!0}catch(t){throw t}if(!e&&!n&&this._native.image){const t=this;return this._parsed={async copyTo(e,n){const r=e.getSource(),o=await r.getMovables().addImage({buffer:t._native.image.arrayBuffer()},{type:"picture",description:"Copy Image from Clipboard"});return r.getView().selectMovables([o]),null},getName:()=>"Image"},!0}return!1}get isClipboardItem(){return!0}}var wS;(wS||(wS={})).Visibility={Visible:"visible",Hidden:"hidden",VeryHidden:"veryHidden"};class yS extends sp{static{this.instanceCounter=0}constructor(t){if(super(t),!t.content)throw new Error("Content type is required");this._content=t.content,this._uuid=_t.uuidV4(),this._optionsMovable=t;const e=this;this._optionsMovable.setContainerZIndexCallback?.(()=>{e._processZIndex()}),this._optionsMovable.setContainerSelectionCallback?.((t,n)=>{e._processContainerSelect(t,n)}),t.json&&this._fromJSON(t.json);const n=this._content.addListeners({onDelete:()=>{e._options.deleteFromContainer&&e._options.deleteFromContainer?.()}},{transactional:!0});this._updateState({contentListenerRemove:n},null,[])}getUUID(){return this._uuid}getContent(){return this._content}_processStateChange(t,e,n){super._processStateChange(t,e,n),this._getEmitter().notify("onBoundsChange"),this._getEmitter().notify("onAnyChange")}_processZIndex(){this._getEmitter().notify("onAnyChange")}_processContainerSelect(t,e){this._getEmitter().notify("onSelectionChange")}isSelected(){return this._optionsMovable.isSelected?.()??!1}async scrollIntoView(t){return this._optionsMovable.scrollIntoView?.(t)??!1}async select(t){if(!1===await(this._optionsMovable.select?.(t)))return!1;if(!1!==t?.autoFocus){const t=await this._getEmitter().notify("onRequestFocus",{async:!0});if(!t)return!1;for(let e=0;e<t.length;e++)if(!1===t[e])return!1}return!0}unselect(){const t=this._optionsMovable.isSelected?.()??!1;return this._optionsMovable.unselect?.(),t}_clone(){const t=this.isSelected(),e=this.getZIndex(),n=this._optionsMovable.getMaxBounds,r=this._options.maxRangeCoords,o=this.getContent(),s={beginPersistResource:this._optionsMovable.beginPersistResource,getBoundsAtCoords:this._optionsMovable.getBoundsAtCoords,getCoordsAtBounds:this._optionsMovable.getCoordsAtBounds,isSelected:()=>t,getZIndex:()=>e,getMaxBounds:n,maxRangeCoords:r,transactions:new ie({transient:!0}),json:this.toJSON(),initialAnchor:this.getAnchorCoords(),content:o},i=new yS(s),a=this._getState();return i._updateState({...a}),i}getSnapshot(t,e){const n=this._optionsMovable.getCoordsAtBounds(t),r=this._getState().offsets;let o=this.getAnchorCoords();if((r.br.x>0||r.br.y>0)&&(o={...o},o.colEnd-=r.br.x>0?1:0,o.rowEnd-=r.br.y>0?1:0),!W.isRangeWithinRange(o,n))return null;const s=this,i=s._clone(),a=Object.freeze({...e});let l=!1;const c={async copyTo(t,e){const n={...a,...e};return await i._doCopy(t,n),n.isCut&&!l&&(s.delete(),l=!0),t.bounds},getCoords:()=>i.getBounds(),getSource:()=>i,getName:()=>i.getName(),getMarkOptions:()=>a,toText:()=>i._toText(),toHtml:()=>i._toHtml(),toImage:()=>i._toImage(),isISnapshot:!0};return c}async _doCopy(t,e){const n=this._optionsMovable.beginPersistResource(),r=this.toJSON(n.toResourceId.bind(n));r.content.json.name=`${this.getName()} (Copy)`;const o=r.content.json;delete r.content;const s=t.movables;if(!s)throw new Error("Movables is required");const i=t.bounds??this.getBounds();try{await s.add({...r,...e,fromResourceId:n.fromResourceId.bind(n),bounds:i,type:this.getContent().getType(),json:o,description:"Copy Movable"})}finally{n.endPersist()}}_toText(){return this.getContent().toText?.()}_toHtml(){return this.getContent().toHtml?.()}_toImage(){return this.getContent().toImage?.()}setName(t){return this._updateState({name:t},{description:"Set Movable Name"},["onNameChange"]),this}getName(){return this.isClosed()?null:this._getState()?.name}setDescription(t){return this._updateState({description:t},{description:"Set Movable Description"}),this}getDescription(){return this.isClosed()?null:this._getState()?.description}setHidden(t=!1){return this._updateState({hidden:t},{description:"Set Movable Visibility"}),this}isHidden(){return this._getState()?.hidden??!1}setLockAspectRatio(t){return this._updateState({lockAspectRatio:t},{description:"Set Lock Aspect Ratio"}),this}isLockAspectRatio(){return this._getState()?.lockAspectRatio??this._optionsMovable.defaultLockAspectRatio??!1}setRotation(t=0){return this._updateState({rotation:t},{description:"Set Movable Rotation"}),this}getRotation(){return this._getState()?.rotation??0}moveToBack(){return this._optionsMovable.moveToBackOnContainer?.(),this}moveBackward(){return this._optionsMovable.moveBackwardOnContainer?.(),this}moveToFront(){return this._optionsMovable.moveToFrontOnContainer?.(),this}moveForward(){return this._optionsMovable.moveForwardOnContainer?.(),this}getZIndex(){return this._optionsMovable.getZIndex?.()??0}setBounds(t,e){if(!t)return this;let n={...this.getBounds(),...t};if(this._optionsMovable.getMaxBounds){n={x:Math.max(n.x,this._optionsMovable.getMaxBounds().x),y:Math.max(n.y,this._optionsMovable.getMaxBounds().y),width:Math.min(n.width,this._optionsMovable.getMaxBounds().width),height:Math.min(n.height,this._optionsMovable.getMaxBounds().height)}}if(n.width<0||n.height<0)throw new kt;const r=this._updateMovableLocation({bounds:n,anchorType:Fl.Type.Absolute}),o=this._beginCommit(e?.description??"Set Movable Bounds");return this._updateState({offsets:r.offsets,anchor:r.anchor},{description:"Update Movable Bounds"}),this._options.setContainerCoords(r.anchor),this._invalidateBounds(),o.commit(),this}_updateMovableLocation(t){let e=t.offsets??{tl:{x:0,y:0},br:{x:0,y:0}},n=t.anchor??this.getAnchorCoords(),r=t.anchorType??this.getAnchorType();const o=t.bounds??this.getBounds();if(o){if(r===Fl.Type.Absolute){n=this._optionsMovable.getCoordsAtBounds(o);const t=this._optionsMovable.getBoundsAtCoords(n);e={...e,tl:{x:o.x-t.x,y:o.y-t.y}}}if(r===Fl.Type.Absolute||r===Fl.Type.OneCell){const t=this._optionsMovable.getBoundsAtCoords({rowStart:n.rowStart,colStart:n.colStart,colEnd:n.colStart,rowEnd:n.rowStart}),r=this._optionsMovable.getCoordsAtBounds({x:t.x,y:t.y,width:o.width+Math.min(t.width,e.tl.x),height:o.height+Math.min(t.height,e.tl.y)});n={...n,colEnd:r.colEnd,rowEnd:r.rowEnd};const s=this._optionsMovable.getBoundsAtCoords({colStart:n.colEnd,rowStart:n.rowEnd,colEnd:n.colEnd,rowEnd:n.rowEnd}),i=o.width-(s.x-t.x-Math.min(e?.tl.x??0,t.width)),a=o.height-(s.y-t.y-Math.min(e?.tl.y??0,t.height));e={...e,br:{x:i,y:a}}}return e!==t.offsets&&(e.br.y<=0&&(e.br={...e.br,y:0},n.rowEnd--),e.br.x<=0&&(e.br={...e.br,x:0},n.colEnd--)),{anchor:n,offsets:e}}}_calcAbsoluteBounds(t,e={tl:{x:0,y:0},br:{x:0,y:0}}){if(!t)return null;const n=this._optionsMovable.getBoundsAtCoords({rowStart:t.rowStart,colStart:t.colStart,colEnd:t.colStart,rowEnd:t.rowStart});let r=e.br.x?0:1,o=e.br.y?0:1;const s=this._optionsMovable.getBoundsAtCoords({colStart:t.colEnd+r,rowStart:t.rowEnd+o,colEnd:t.colEnd+r,rowEnd:t.rowEnd+o}),i=Math.min(n.x+(e?.tl.x??0),n.x+n.width),a=Math.min(n.y+(e?.tl.y??0),n.y+n.height);return{x:i,y:a,width:Math.min(s.x+(e?.br.x??0),s.x+s.width)-i,height:Math.min(s.y+(e?.br.y??0),s.y+s.height)-a}}getBounds(){return this._getState()?.bounds}setAnchorType(t){return _t.validEnumValue(Fl.Type,t),this._updateState({anchorType:t},{description:"Set Movable Resize Behavior"},["onAnchorTypeChange"]),this}_processContainerShift(t){const n=this.getAnchorType(),r=this._getState()?.offsets;let o=r,s=!1;const i=t.before,a=t.orientation===e.Orientation.Column,l=t.intersect,c=t.amount;let h=t.after;if(n!==Fl.Type.Absolute){let t=a?l.colStart:l.rowStart,e=a?i.colStart:i.rowStart;n===Fl.Type.TwoCell&&(e=a?i.colEnd:i.rowEnd),s=t<=e}if(s&&(n!==Fl.Type.OneCell||h)||(h=i),s&&h&&c<0&&(a?(l.colStart<=i.colStart&&l.colEnd>=i.colStart&&(o={...o,tl:{...o.tl,x:0}}),o.br.x>0&&l.colStart<=i.colEnd&&l.colEnd>=i.colEnd&&(o={...o,br:{...o.br,x:0}},h={...h,colEnd:h.colEnd+1})):(l.rowStart<=i.rowStart&&l.rowEnd>=i.rowStart&&(o={...o,tl:{...o.tl,y:0}}),o.br.y>0&&l.rowStart<=i.rowEnd&&l.rowEnd>=i.rowEnd&&(o={...o,br:{...o.br,y:0}},h={...h,rowEnd:h.rowEnd+1}))),null!==h){const{offsets:t,anchor:e}=this._updateMovableLocation({anchor:h,offsets:o});o=t,h=e}let u=null;const d=this._beginCommit("Shifting Movable Bounds");try{if(r!==o||!W.isEqualRanges(i,h)){const t={offsets:o,anchor:h};this._updateState(t)}this._invalidateBounds(),u=super._processContainerShift({...t,after:h}),d.commit()}catch(t){throw d.rollback(),t}return u}_invalidateBounds(){const t=this.getAnchorCoords();if(null===t)return null;const e=this._getState()?.offsets,n=this._calcAbsoluteBounds(t,e);this._updateState({bounds:n},null,["onBoundsChange"])}_processContainerDelete(){super._processContainerDelete(),this._getState().contentListenerRemove?.(),this.getContent().delete()}_processContainerLayout(){const t=this.getAnchorCoords(),e=this._getState()?.offsets,{offsets:n,anchor:r}=this._updateMovableLocation({anchor:t,offsets:e}),o=this._beginCommit("Updating Movable Bounds");try{if(e!==n||t!==r){const t={offsets:n,anchor:r};this._updateState(t)}this._invalidateBounds(),super._processContainerLayout(),o.commit()}catch(t){throw o.rollback(),t}}_processAnchorCoords(){super._processAnchorCoords()}_fromJSON(t){const e={tl:{x:0,y:0},br:{x:0,y:0}},n={...W.EmptyRange};t.anchor&&(e.tl.x=t.anchor.tl?.x??0,e.tl.y=t.anchor.tl?.y??0,e.br.x=t.anchor.br?.x??0,e.br.y=t.anchor.br?.y??0,n.colStart=t.anchor.tl?.c??0,n.rowStart=t.anchor.tl?.r??0,n.colEnd=Math.max(n.colStart,(t.anchor.br?.c??0)+(e.br.x>0?0:-1)),n.rowEnd=Math.max(n.rowStart,(t.anchor.br?.r??0)+(e.br.y>0?0:-1)));const r=this._beginCommit("Load Movable"),o=t.content.json,s={offsets:e,name:o.name??null,description:o.name??null,hidden:o.hidden??!1,rotation:o.rotation??0,lockAspectRatio:o.lockAspect??null};t.anchorType&&(s.anchorType=t.anchorType),s.name||(s.name=`${this._content.getTypeDescription()} ${++yS.instanceCounter}`),s.bounds=this._calcAbsoluteBounds(n,e),this._updateState(s,{description:"Load Movable"}),this._optionsMovable.setContainerCoords?.(n),r.commit()}toJSON(t){const e=this._getState(),n=e.anchor,r=e.offsets,o={tl:{c:n.colStart,r:n.rowStart},br:{c:n.colEnd+(r.br.x?0:1),r:n.rowEnd+(r.br.y?0:1)}};r&&(r.tl?.x&&(o.tl.x=_t.roundAccurately(r.tl.x,1)),r.tl?.y&&(o.tl.y=_t.roundAccurately(r.tl.y,1)),r.br?.x&&(o.br.x=_t.roundAccurately(r.br.x,1)),r.br?.y&&(o.br.y=_t.roundAccurately(r.br.y,1)));const s=this._content.toJSON(t)??{},i={anchor:o,content:{type:this._content.getType(),json:s}},a=e.anchorType;return a&&a!==Fl.Type.TwoCell&&(i.anchorType=this.getAnchorType()),e.hidden&&(i.hidden=e.hidden),e.name&&(i.name=e.name),e.description&&(i.name=e.description),void 0!==e.rotation&&0!==e.rotation&&(i.rotation=e.rotation),_t.isDefined(e.lockAspectRatio)&&e.lockAspectRatio!==this._optionsMovable.defaultLockAspectRatio&&(i.lockAspect=e.lockAspectRatio),i}get isIMovable(){return!0}}class ES{constructor(t,e,n,r,o,s){this._add=t,this._search=e,this._getCount=n,this._updateSelected=r,this._addListeners=o,this._addImage=s}async add(t){return this._add(t)}search(t){return this._search(t)}getCount(){return this._getCount()}updateSelected(t,e){return this._updateSelected(t,e)}addListeners(t,e){return this._addListeners(t,e)}addImage(t,e){return this._addImage(t,e)}}const bS={transactional:!0,ignoreDataChanges:!0};class vS extends Bl{constructor(t){super({...t,type:"namedReference"});const e=this;this._listener=t=>{const n=this._getState().ranges;let r=t.getSource(),o=!1;const s={ranges:r};if("moveCells"===t.trigger){const r=e._getState(),i=t.getTo(),a=t.getFrom(),l=[];for(let t=0;t<n.getCount();t++){const e=n.at(t);if(l.push(e.getCoords()),!e.isInvalid()){for(let n=0;n<a.getCount();n++){const r=a.at(n).getCoords(),s=e.getCoords();if(!W.isRangeWithinRange(s,r))continue;const c=i.getCoords(),h=c.colStart-r.colStart+s.colStart,u=c.rowStart-r.rowStart+s.rowStart,d={...s,colStart:h,rowStart:u,colEnd:h+(s.colEnd-s.colStart),rowEnd:u+(s.rowEnd-s.rowStart)};(1!==i.size||W.isRangeWithinRange(d,c))&&(l[t]=i.getSource().getRange(d).getCoords(),o=!0)}if(!o)return}}const c=this._options.addressToRanges(l);let h;r.removeListener?.(),c.isInvalid()||(h=c.addListener(e._listener,bS)),s.ranges=c,s.removeListener=h}this._updateState(s,null,["onRangesChange"]);const i=r.getCoords();let a=!i||0===i.length;for(let t=0;!a&&t<i.length;t++)if(!i[t]){a=!0;break}a&&e.delete()};const n=t.value;if(n&&!n.isInvalid()){const t=n.addListener(this._listener,bS);this._updateState({ranges:n,removeListener:t},null)}}setReference(t){const e=this._options.addressToRanges(t);if(e&&!e.isInvalid()){const t=this._getState();t.removeListener?.();const n=e.addListener(this._listener,bS);this._updateState({ranges:e,removeListener:n},null)}return null}async select(t){return await this._getState().ranges.select(t),this}getRanges(){return this._getState().ranges}setHidden(t=!1,e){return this._updateState({hidden:t},{description:"Set Hidden",...e},[]),this}setScope(t,e){return this._updateState({scope:t},{description:"Set Scope",...e},[]),this}getType(){return"reference"}getValue(){return this._getState().ranges}toJSON(){const t=super._toJSON();return t.ref=this._getState().ranges.toString(),t}_getDescription(){return`Named '${this.getName()}'`}_processDelete(){const t=this._getState();t&&t.removeListener?.(),super._processDelete()}}const CS="Item must be specified.",xS="Name must be a non-empty string",IS=(t,e=null)=>`Named item '${t}' already exists${e?`in scope ${e}`:""}.`,AS=t=>{const e=[];for(let n=0;n<t.getCount();n++){let r=null;try{r=t.at(n),r.isICellRange&&(r=r.getFixed(!0))}catch(t){console.warn("Invalid range",t)}e.push(r?r.toString().toLowerCase():gu)}return e.sort(),e.join(",")},RS=/^[^a-zA-Z_\\]+$/,MS=/^[^a-zA-Z0-9_.]+$/;class TS{constructor(t){this._emitter=null,this._closed=!1,this._lastLookup=_t.EmptyArray,this._lastLookupAddress=null,this._lastLookupScope=null,this._lastLookupType=null,this._allowExtrudes=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new ie({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,n,r){n?.initial||e._emitter.notify("onCollectionChange")}}),this._emitter=new Ll(this,this._transactions),this._initState(),this._fromJSON(this._options?.json)}search(t){if(this.isClosed())return _t.EmptyArray;const e=this._getState();if(!e)return _t.EmptyArray;const n=e.itemsSpatial;if(n.isEmpty())return _t.EmptyArray;if(t&&t.address===this._lastLookupAddress&&t.scope===this._lastLookupScope&&t.type===this._lastLookupType&&t.allowExtrudes===this._allowExtrudes)return this._lastLookup;this._lastLookupAddress=t?.address??void 0,this._lastLookupScope=t?.scope??void 0,this._lastLookupType=t?.type??void 0,this._allowExtrudes=t?.allowExtrudes??void 0;let r=null;if(t?.address){const e=this._options.addressToRanges(t?.address);if(!e)return console.warn("invalid address",t?.address),this._lastLookup=null,null;r=e.getCoords()}let o=null;if(r){o=[];for(let t=0;t<r.length;t++){const e=n.search(r[t]);for(let t=0;t<e.length;t++)o.push(e[t])}}else o=n.all();if(!o||0===o.length)return this._lastLookup=_t.EmptyArray,_t.EmptyArray;const s=new Set,i=new Set;o.forEach(e=>{const n=e.value;if(!t?.type||n.getType()===t.type){if(r&&!t?.allowExtrudes){const t=n.getRanges?.();if(!t||0===t.getCount())return;for(let t=0;t<r.length;t++)if(!W.isRangeWithinRange(e,r[t]))return}!t?.scope||n.getScope()!==t.scope&&"all"!==t.scope?n.getScope()||i.add(n):s.add(n)}});const a=new Map;i.forEach(t=>{a.set(t.getName(),t)}),s.forEach(t=>{a.set(t.getName(),t)});let l=[];return a.forEach(t=>{l.push(t)}),l=l.sort((t,e)=>{let n=t.getType().localeCompare(e.getType());return 0!==n?n:t.getName().localeCompare(e.getName())}),this._lastLookup=l,l}lookupByRanges(t){const e=this._options.addressToRanges(t);if(!e||0===e.getCount())return null;const n=this._getState();if(!n)return null;if(0===n.itemsByKey.size)return null;const r=AS(e),o=n.itemsByFullRange.get(r);if(!o)return null;const s=[];return o.forEach(t=>{const e=n.itemsByKey.get(t);e&&s.push(e.item)}),s.length>0?s:null}getByName(t,e=!1){if(!t)return null;const n=this._getState();if(!n)return null;if(0===n.itemsByKey.size)return null;if("string"!=typeof t)return null;const r=t.toLowerCase(),o=this._options.getCurrentScope();if(!e&&o){const t=r+":"+o.toLowerCase(),e=n.itemsByKey.get(t);if(e)return e.item}const s=n.itemsByKey.get(r);return s?.item??null}getCount(){const t=this._getState();return t?t.itemsByKey.size:0}getRanges(t){const e=this._options.addressToRanges(t),n=[];for(let t=0;t<e.getCount();t++){const r=e.at(t).getFixed(!0).getCoords();n.push(r)}return this._options.addressToRanges(n)}findValidName(t,e=null,n=!1){if(!t)throw new Error("A template string must be specified.");const r=this,o=t=>{try{return r._validateName(t,e,n),!0}catch(t){}return!1};return o(t)?t:js(t,o)}validateName(t,e=null,n=!1){return this._validateName(t,e,n)}_validateName(t,e,n=!1){if(this._closed)throw new Error(kl);if(!t||0===t.length)throw new Error(xS);if(t.length>255)throw new Error("Name must not exceed 255 characters.");if(-1!==t.indexOf(" "))throw new Error("Name must not contain any spaces.");const r=t.trim().toLowerCase(),o=r.substring(1,t.length-1);if(new RegExp(RS).test(r[0]))throw new Error("First letter must be either a letter, an underscore, or a backslash.");if(new RegExp(MS).test(o))throw new Error("Name must be either letters, numbers, periods or underscores.");if(1===r.length&&("r"===r[0]||"c"===r[0]))throw new Error("Name can not be 'r' or 'c'.");if(((t,e=fu,n=mu,r=!1)=>{let o=$u(t,r);if(!o)return!1;if(o[2])return!1;if(!o[1])return!1;const s=ju(t,Uu);if(!s)return!1;const i=s.rowIndex;if(i<0||i>e)return!1;const a=s.colIndex;return!(a<0||a>=n)})(t))throw new Error("Name can not be an address.");let s=t.toLowerCase()?.trim();e&&(s=s+":"+e.toLowerCase());const i=this._getState()?.itemsByKey.get(s);if(i){const r=i.item.getRanges();if(!n||r||r.getCount()>0)throw new Error(IS(t,e))}}addReference(t,e,n=!1){const r=this._options.addressToRanges(e),o=this.getByName(t);let s=null;const i=this._beginCommit(`${o&&n?"Update":"Insert"} Named '${t}'`);try{if(o){if(!n)throw new Error(IS(t));this._delete(o,{description:`Delete Named '${o.getName()}'`})}s=new vS({value:r,addressToRanges:this._options.addressToRanges,json:{name:t,ref:r.toString()},transactions:this._transactions}),this.add(s),i.commit()}catch(t){throw i.rollback(),t}return s}add(t){if(this._closed)throw new Error(kl);if(!t)throw new Error(CS);if(!t.getName||"string"==typeof t)throw new Error("Add must take a 'INamed' object. To add a string use 'addReference'.");if(this._validateName(t.getName(),t.getScope(),!1),this._options.isReadOnly?.())throw new Error("Names are read-only.");const e=this._beginCommit(`Insert Named Item '${t.getName()}'`),n=this._add([t]);if(null===n)return e.rollback(),null;const r=n.itemsByKey.get(t.getName().toLowerCase());return this._updateState(t=>({...t,...n})),e.commit(),r?.item??null}_toKey(t){let e=t.getName().toLowerCase();return e.startsWith("_xlnm.")&&(e=e.substring(6)),t.getScope()?e+":"+t.getScope().toLowerCase():e}_delete(t,e){if(!t)throw new Error(CS);if(this._closed)throw new Error(kl);const n=this._beginCommit(e?.description??`Delete Named Item '${t.getName()}'`);let r=null;try{const e=this._getState()?.itemsByKey,o=this._toKey(t);if(r=e.get(o),!r)throw new Error(`Item '${t.getName()}' does not exist.`);const s=this._cloneState();this._index(o,null,s),this._updateState(t=>({...t,...s})),n.commit()}catch(t){throw n.rollback(),t}return this._emitter.notify("onCollectionChange"),r.item}_cloneState(){const t=this._getState();return{itemsBySource:new Map(t.itemsBySource),itemsByKey:new Map(t.itemsByKey),itemsSpatial:t.itemsSpatial.clone(),itemsByFullRange:new Map(t.itemsByFullRange),itemsByPartialRange:new Map(t.itemsByPartialRange)}}_index(t,e,n){const r=n.itemsByKey.get(t);if(r){const e=r.asPartialRanges;if(e)for(let r=0;r<e.length;r++){const o=n.itemsByPartialRange.get(e[r]);if(o)if(1===o.size)n.itemsByPartialRange.delete(e[r]);else{const s=new Set(o);s.delete(t),n.itemsByPartialRange.set(e[r],s)}}const o=r.asFullRange;if(o){const e=n.itemsByFullRange.get(o);if(e)if(1===e.size)n.itemsByFullRange.delete(o);else{const r=new Set(e);r.delete(t),n.itemsByFullRange.set(o,r)}}if(r.nodes)for(let t=0;t<r.nodes.length;t++)n.itemsSpatial.remove(r.nodes[t]);r.unwatch?.(),n.itemsByKey.delete(t),n.itemsBySource.delete(r.item)}let o=null;if(e){let t=[],r=null,s=null;o=e.getRanges?.();const i=this._toKey(e);if(o){const{asFullRange:a,asPartialRanges:l,asRanges:c}=(t=>{const e=t.getCoords(),n=AS(t),r=n.split(",");return{asFullRange:n,asPartialRanges:r,asRanges:e}})(o);if(r=a,s=l,c){for(let r=0;r<l.length;r++){let o=n.itemsByPartialRange.get(l[r]);const s=o?new Set(o):new Set;s.add(i),n.itemsByPartialRange.set(l[r],s),t.push({...c[r],value:e})}if(n.itemsSpatial.load(t),a){let t=n.itemsByFullRange.get(a);const e=t?new Set(t):new Set;e.add(i),n.itemsByFullRange.set(a,e)}}}const a=this,l=e.addListeners({onDelete:t=>{a._delete(t)},onAnyChange:t=>{const e=a._beginCommit(`Update Named '${t.getName()}'`);try{const n=a._cloneState(),r=n.itemsBySource.get(t).globalKey;a._index(r,t,n),a._updateState(t=>({...t,...n})),e.commit()}catch(t){throw e.rollback(),t}}},{transactional:!0}),c={item:e,asFullRange:r,asPartialRanges:s,unwatch:l,nodes:t,globalKey:i};n.itemsByKey.set(i,c),n.itemsBySource.set(e,c)}}_add(t){if(this._closed)throw new Error(kl);const e=this._getState();if(!t)return e;const n=this._cloneState();for(let e=0;e<t.length;e++){const r=t[e];if(!r.getName())throw new Error(xS);const o=this._toKey(r);try{this._index(o,r,n)}catch(t){console.warn(`Unable to add named item '${o}'.`,t)}}return n}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(kl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update"){if(!t)return;this._lastLookup=_t.EmptyArray,this._lastLookupAddress=null,this._lastLookupType=null,this._lastLookupScope=null;const n=this._beginCommit(e);try{n.updateState(this,t),n.commit()}catch(t){throw n.rollback(),t}}fromJSON(t){if(this._closed)throw new Error(kl);this._fromJSON(t)}_initState(){this._updateState(t=>({...t,items:new Set,itemsByKey:new Map,itemsSpatial:new Lc,itemsByFullRange:new Map,itemsByPartialRange:new Map}))}_fromJSON(t){const e=this._beginCommit("Load Names");try{if(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];try{const t=this._options.addressToRanges(r.ref),n=new vS({value:t,addressToRanges:this._options.addressToRanges,deleteFromContainer:t=>{this._delete(n,t)},json:r,transactions:this._transactions});e.push(n)}catch(t){console.warn("Unable to load named item.",r,t.message)}}const n=this._add(e);this._updateState(t=>({...t,...n}))}e.commit({viewAfter:{initial:!0}})}catch(t){throw e.rollback(),t}}toJSON(){const t=this._getState();if(!t||0===t.itemsByKey.size)return null;const e=[],n=Array.from(t.itemsByKey.keys()).sort();for(let r=0;r<n.length;r++){const o=t.itemsByKey.get(n[r]).item,s=o.toJSON?.();s&&e.push(s)}return 0===e.length?null:e}addListeners(t,e){return this._emitter.addListeners(t,e)}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isNamedCollection(){return!0}}class NS extends Dl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"chart"}getDescription(){const t=this._getState()?.data;return`Chart: ${t?.types?.[0]?.type??"unknown"}`}toJSON(t){const e=this._getState();let n=null;return e&&e.data&&(n=e.data),n}getTypeDescription(){return"Chart"}}class FS extends Dl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"shape"}getDescription(){const t=this._getState()?.data;return`Shape: ${t}`}toJSON(t){const e=this._getState();let n=null;return e&&e.data&&(n=e.data),n}getTypeDescription(){return"Shape"}}class kS extends Dl{constructor(t){super(t),t.json&&this._updateState({data:t.json})}getType(){return"custom"}getDescription(){const t=this._getState()?.data;return`CustomElement: ${t}`}toJSON(t){const e=this._getState();let n=null;return e&&e.data&&(n=e.data),n}getTypeDescription(){return"CustomElement"}}const OS=(t,e,n=!0,r=!0)=>{let o=0,s=0;if(!n&&!r)return{x:o,y:s};let i=!1,a=0;do{const a={x:e.x+o,y:e.y+s,width:0,height:0},l=t.search({bounds:a});if(i=!1,l.length>0){for(let t=0;!i&&t<l.length;t++){const e=l[t].getBounds();e.x===a.x&&e.y===a.y&&(i=!0)}i&&(o+=n?16:0,s+=r?16:0)}}while(i&&++a<100);return{x:o,y:s}};class LS{constructor(t,e,n){this._add=t,this._get=e,this._getByName=n}add(t,e){if(!t)throw new Error(pp);return this._add(t,e)}search(t){if(t&&t.name&&0===Object.keys(t).length)return[this._getByName(t.name)];let e;t?.address&&(e=t.address);const n=this._get(e,t?.excludeHidden,t?.fullyContained);if(t?.name){const e=t.name.toLocaleLowerCase();for(let t=0;t<n.length;t++)if(n[t].getName().toLocaleLowerCase()===e)return[n[t]]}return n}getByName(t){if("string"!=typeof t)throw new Error("Get by name must take a valid name.");return this._getByName(t)}getCount(){return this._get(null,!1,!1).length}}const DS=(t,n,r)=>{if(!t)return n;let o=n;const s=r===e.Direction.Right||r===e.Direction.Down;for(;;){const e=t(o,!s);if(0===e)return o;s?o+=e:o-=e}},BS=Object.freeze({colIndex:0,rowIndex:0}),zS=Object.freeze([]),PS=Object.freeze({cell:W.EmptyCell,ranges:zS,rangeIndex:-1}),jS=(t,n=e.Direction.Right,r,o,s,i=null)=>{if(i&&W.isEqualSelectionCoords(i,t))return t;const a=t.ranges[t.rangeIndex];if(!W.isRangesIntersect({rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},a))return t;let l={...t.cell},c=t.rangeIndex;switch(n){case e.Direction.Right:l.colIndex=DS(s,l.colIndex+1,n);break;case e.Direction.Left:l.colIndex=DS(s,l.colIndex-1,n);break;case e.Direction.Down:l.rowIndex=DS(o,l.rowIndex+1,n);break;case e.Direction.Up:l.rowIndex=DS(o,l.rowIndex-1,n)}const h=e=>{if(e){c=t.rangeIndex>=t.ranges.length-1?0:t.rangeIndex+1;const e=t.ranges[c];l={colIndex:e.colStart,rowIndex:e.rowStart}}else{c=t.rangeIndex<=0?t.ranges.length-1:t.rangeIndex-1;const e=t.ranges[c];l={colIndex:e.colEnd,rowIndex:e.rowEnd}}};if(n===e.Direction.Right&&l.colIndex>a.colEnd&&l.rowIndex===a.rowEnd)h(!0);else if(n===e.Direction.Left&&l.colIndex<a.colStart&&l.rowIndex===a.rowStart)h(!1);else if(n===e.Direction.Down&&l.colIndex===a.colEnd&&l.rowIndex>a.rowEnd)h(!0);else if(n===e.Direction.Up&&l.colIndex===a.colStart&&l.rowIndex<a.rowStart)h(!1);else{let t=l.rowIndex,r=l.colIndex;switch(n){case e.Direction.Right:r>a.colEnd&&(t=DS(o,t+1,n),r=a.colStart,t>a.rowEnd&&(t=a.rowStart));break;case e.Direction.Left:r<a.colStart&&(t=DS(o,t-1,n),r=a.colEnd,t<a.rowStart&&(t=a.rowEnd));break;case e.Direction.Down:t>a.rowEnd&&(r=DS(s,r+1,n),t=a.rowStart,r>a.colEnd&&(r=a.colStart));break;case e.Direction.Up:t<a.rowStart&&(r=DS(s,r-1,n),t=a.rowEnd,r<a.colStart&&(r=a.colEnd))}l={rowIndex:t,colIndex:r}}let u=r(l);if(!W.isRangeWithinRange(u,a)){const t=W.intersectRanges(u,a);t&&(u=t)}let d={rowStart:DS(o,u.rowStart,e.Direction.Down),colStart:DS(s,u.colStart,e.Direction.Right),rowEnd:DS(o,u.rowEnd,e.Direction.Up),colEnd:DS(s,u.colEnd,e.Direction.Left)};if(d.rowStart!==l.rowIndex||d.colStart!==l.colIndex){switch(n){case e.Direction.Right:t.ranges[c].colStart===d.colStart&&t.ranges[c].colEnd===d.colEnd&&(l.rowIndex=d.rowEnd),l.colIndex=d.colEnd;break;case e.Direction.Left:t.ranges[c].colStart===d.colStart&&t.ranges[c].colEnd===d.colEnd&&(l.rowIndex=d.rowStart),l.rowIndex===d.rowStart?l.colIndex=d.colStart+1:l.colIndex=d.colStart;break;case e.Direction.Down:t.ranges[c].rowStart===d.rowStart&&t.ranges[c].rowEnd===d.rowEnd&&(l.colIndex=d.colEnd),l.rowIndex=d.rowEnd;break;case e.Direction.Up:t.ranges[c].rowStart===d.rowStart&&t.ranges[c].rowEnd===d.rowEnd&&(l.colIndex=d.colStart),l.colIndex===d.colStart?l.rowIndex=d.rowStart+1:l.rowIndex=d.rowStart}return i&&console.warn("call recursive > 1"),jS({cell:l,ranges:t.ranges,rangeIndex:c},n,r,o,s,i??t)}return{ranges:t.ranges,cell:l,rangeIndex:c}};class HS{constructor(t){this._adjusting=null,this._emitter=null,this._coords=PS,this._sheet=t.sheet,this._emitter=new Ll(this);const n=t.sheet;this._adjusting=null,this._hiddenRowsAt=(t,e)=>n.getRowHeaders().hiddenHeadersAt(t,e),this._hiddenColumnsAt=(t,e)=>n.getColumnHeaders().hiddenHeadersAt(t,e),this._getCellCoordsAsRangeCoords=t=>{const e=W.cellToRange(t);if(n.isClosed())return e;const r=n.getRange(e,{excludeHidden:!0}).getMerges();return 0===r.length?e:r[0]},this._canSelectionSpanMergedCells=t=>{const e=n.getRange(t);return e.isEntireColumns()||e.isEntireRows()},this._getMergedRanges=t=>n.getRange(t,{excludeHidden:!0}).getMerges(),this._isContentfulCell=()=>!1,this._contentfulCellFinder=(t,r,o,s,i,a)=>{const l=n.getSelectedRange().getExtended(s,t).getCoords();switch(s){case e.Direction.Up:return l.rowStart;case e.Direction.Down:return l.rowEnd;case e.Direction.Left:return l.colStart;case e.Direction.Right:return l.colEnd}},this._scrollCellCoordsIntoView=(t,e)=>n.scrollTo(t,e?{scroll:e}:void 0),this._selectionPolicy=t.selectionPolicy??"multiple",this._newSelectionMode=t.newSelectionMode??"clear"}navigate(t,n=!1,r=!1,o=0){const s=this._coords;if(!s.cell)return this;let i=s.cell,a=s.cell;if(n&&s.ranges.length>0){const n=s.ranges[s.rangeIndex],r=s.cell;switch(t){case e.Direction.Up:a={rowIndex:r.rowIndex===n.rowStart?n.rowEnd:n.rowStart,colIndex:n.colEnd},i={rowIndex:r.rowIndex===n.rowStart?n.rowStart:n.rowEnd,colIndex:n.colStart};break;case e.Direction.Down:a={rowIndex:r.rowIndex===n.rowEnd?n.rowStart:n.rowEnd,colIndex:n.colEnd},i={rowIndex:r.rowIndex===n.rowEnd?n.rowEnd:n.rowStart,colIndex:n.colStart};break;case e.Direction.Left:a={rowIndex:n.rowEnd,colIndex:r.colIndex===n.colStart?n.colEnd:n.colStart},i={rowIndex:n.rowStart,colIndex:r.colIndex===n.colStart?n.colStart:n.colEnd};break;case e.Direction.Right:a={rowIndex:n.rowEnd,colIndex:r.colIndex===n.colEnd?n.colStart:n.colEnd},i={rowIndex:n.rowStart,colIndex:r.colIndex===n.colEnd?n.colEnd:n.colStart}}}const l=this._getCellCoordsAsRangeCoords(a);let{rowStart:c,colStart:h}=l;const u=this._magicCell;if(u)switch(t){case e.Direction.Up:case e.Direction.Down:u.colIndex>=l.colStart&&u.colIndex<=l.colEnd&&(h=u.colIndex);break;case e.Direction.Left:case e.Direction.Right:u.rowIndex>=l.rowStart&&u.rowIndex<=l.rowEnd&&(c=u.rowIndex)}if(!o){const n=this._getMaxRange();switch(t){case e.Direction.Up:c=DS(this._hiddenRowsAt,Math.max(l.rowStart-1,n.rowStart??0),t);break;case e.Direction.Down:c=DS(this._hiddenRowsAt,Math.min(l.rowEnd+1,n.rowEnd??Number.MAX_SAFE_INTEGER),t);break;case e.Direction.Left:h=DS(this._hiddenColumnsAt,Math.max(l.colStart-1,n.colStart??0),t);break;case e.Direction.Right:h=DS(this._hiddenColumnsAt,Math.min(l.colEnd+1,n.colEnd??Number.MAX_SAFE_INTEGER),t)}if(r){const n=this._getMaxRange();let r=0;switch(t){case e.Direction.Up:r=n.rowStart??0,c=this._contentfulCellFinder({...a,colIndex:this._coords.cell.colIndex},this._isContentfulCell,this._hiddenRowsAt,t,!1,Math.max(r,this._hiddenRowsAt(r,!1)));break;case e.Direction.Down:r=n.rowEnd??Number.MAX_SAFE_INTEGER,c=this._contentfulCellFinder({...a,colIndex:this._coords.cell.colIndex},this._isContentfulCell,this._hiddenRowsAt,t,!1,Math.min(r,r-this._hiddenRowsAt(r,!0)));break;case e.Direction.Left:r=n.colStart??0,h=this._contentfulCellFinder({...a,rowIndex:this._coords.cell.rowIndex},this._isContentfulCell,this._hiddenColumnsAt,t,!1,Math.max(r,this._hiddenColumnsAt(r,!1)));break;case e.Direction.Right:r=n.colEnd??Number.MAX_SAFE_INTEGER,h=this._contentfulCellFinder({...a,rowIndex:this._coords.cell.rowIndex},this._isContentfulCell,this._hiddenColumnsAt,t,!1,Math.min(r,r-this._hiddenColumnsAt(r,!0)))}}}let d=null;o&&(d={});const g={rowIndex:c,colIndex:h},m=this._getCellCoordsAsRangeCoords(g),f={rowIndex:m.rowStart,colIndex:m.colStart};n||(this._magicCell=g);const p=this._firstActiveCoords,_=W.isEqualCells(p,f)&&W.isEqualCells(p,i);if(n&&!_?this.modify(f,i):this.clearAndModify(f),d)this._scrollCellCoordsIntoView(d);else{if(n&&p){const n=this._getMaxRange();if(t===e.Direction.Right&&p.colIndex===n.colEnd||t===e.Direction.Left&&p.colIndex===n.colStart||t===e.Direction.Up&&p.rowIndex===n.rowEnd||t===e.Direction.Down&&p.rowIndex===n.rowStart)return this}t===e.Direction.Left||t===e.Direction.Right?this._scrollCellCoordsIntoView({colStart:g.colIndex}):t!==e.Direction.Up&&t!==e.Direction.Down||this._scrollCellCoordsIntoView({rowStart:g.rowIndex})}return this}getCoords(){return this._coords}updateCoords(t){const e=this._coords;if(W.isEqualSelectionCoords(e,t))return;const n=((t,e,n)=>{if(!t)return PS;let r=e.cell;W.isEqualCells(r,t?.cell)||(r=Object.freeze({colIndex:Math.max(0,Math.min(t?.cell?.colIndex??e.cell?.colIndex??0)),rowIndex:Math.max(0,Math.min(t?.cell?.rowIndex??e?.cell?.rowIndex??0))}));const o=t?.ranges?[...t.ranges]:[];let s=!1;const i=o.length;let a=0===i;for(let t=0;t<i;t++){const e=o[t];o[t]=Object.freeze({colStart:Math.max(n.colStart,Math.min(e.colStart,n.colEnd)),colEnd:Math.max(n.colStart,Math.min(e.colEnd,n.colEnd)),rowStart:Math.max(n.rowStart,Math.min(e.rowStart,n.rowEnd)),rowEnd:Math.max(n.rowStart,Math.min(e.rowEnd,n.rowEnd))}),a=a||W.isCellWithinRange(r,e),s=s||Object.keys(e).length>4}let l=e?.ranges??[];!s&&W.isEqualRangesArrays(l,o)||(l=o);let c=t?.rangeIndex??e?.rangeIndex??PS.rangeIndex;if(c=Math.max(-1,Math.min(c,l.length-1)),!a){const t=l[c];let e=r.rowIndex;e<t.rowStart?e=t.rowStart:e>t.rowEnd&&(e=t.rowEnd);let n=r.rowIndex;n<t.colStart?n=t.colStart:n>t.colEnd&&(n=t.colEnd),r=Object.freeze({colIndex:n,rowIndex:e})}const h={cell:r,ranges:l,rangeIndex:c};return Object.freeze(h)})(t,this._coords,this._getMaxRange());this._coords=n;return!W.isEqualCells(n.cell,e.cell)&&this._scrollCellCoordsIntoView({colStart:n.cell.colIndex,rowStart:n.cell.rowIndex}),this._emitter.notify("onChange"),this}isEntire(){const t=this._coords;if(0===t.ranges.length)return!1;const e=this._getMaxRange();for(let n=0;n<t.ranges.length;n++){const r=t.ranges[n];if(!W.isRangeWithinRange(e,r))return!1}return!0}traverse(t=e.Orientation.Row,n=!1){let r=e.Direction.Right;r=t===e.Orientation.Row?n?e.Direction.Left:e.Direction.Right:n?e.Direction.Up:e.Direction.Down;const o=this._coords;if(0===o.ranges.length)return this.navigate(r);const s=this._getCellCoordsAsRangeCoords(o.cell);if(W.isEqualRangesArrays([s],o.ranges))return this.navigate(r);const i=jS(o,r,this._getCellCoordsAsRangeCoords.bind(this),this._hiddenRowsAt.bind(this),this._hiddenColumnsAt.bind(this));this.updateCoords(i)}clear(){this._setSelectionRanges(zS)}modify(t,e,n){if("single"===this._selectionPolicy)return;const r=this._coords,o=this._rangesFromCellOptional(r,t,e??r.cell);if(!o)return;const s=r.rangeIndex;this._setSelectionRanges(t=>t.length?t.map((t,e)=>s===e?o:t):[o]),n&&o&&this._setSelectionCell({colIndex:o.colStart,rowIndex:o.rowStart})}append(t,e=t,n){if("multiple"!==this._selectionPolicy||!t||this._isCellOutOfBounds(t)||this._isCellOutOfBounds(e))return;const r=this._coords,o=this._cellToRangeActual(t,e);if(!o)return;const s=r.ranges.length>0?[...r.ranges]:[this._cellToRangeActual(r.cell,r.cell)];s.push(o);const i={ranges:s,cell:{rowIndex:o.rowStart,colIndex:o.colStart,...n},rangeIndex:s.length-1};W.isEqualSelectionCoords(i,r)||this.updateCoords(i)}clearAndModify(t,e,n){const r=this._coords;t={...r.cell,...t},e=e??t;const o=this._rangesFromCellOptional(r,t,e);if(!o)return;const s={rowIndex:o.rowStart,colIndex:o.colStart},i={...s,...n},a=this._newSelectionMode;"clear"===a?(this._firstActiveCoords=i,this.clear()):"modify"===a?this.modify(s):this.append(s),this._setSelectionCell(i)}setAdjusting(t){this._adjusting=t,this._emitter.notify("onAdjustingChange")}getAdjusting(){return this._adjusting}addListeners(t,e){return this._emitter.addListeners(t,e)}_setSelectionRanges(t){const e=this._coords;let n="function"==typeof t?t(e.ranges):t??zS;if(W.isEqualRangesArrays(n,e.ranges))return;let r=Math.max(n.length?0:-1,Math.min(e.rangeIndex,n.length-1)),o=e.cell;-1===r||W.isCellWithinRange(o,n[r])||(o={rowIndex:n[r].rowStart,colIndex:n[r].colStart}),1===n.length&&W.isSingleCell(n[0])&&W.isCellWithinRange(o,n[0])&&(n=[],r=-1);const s={cell:o,ranges:n,rangeIndex:r};W.isEqualSelectionCoords(s,e)||this.updateCoords(s)}_setSelectionCell(t){const e=this._coords,n=t??BS,r=this._getCellCoordsAsRangeCoords(n);if(!W.isSingleCell(r)&&0===e.ranges.length)return this.updateCoords({ranges:[r],rangeIndex:0,cell:n});if(W.isEqualCells(n,e.cell))return;let o=e.ranges,s=e.rangeIndex;1===e.ranges.length&&(W.isSingleCell(e.ranges[0])&&W.isCellWithinRange(n,e.ranges[0])||!W.isCellWithinRange(n,e.ranges[0]))&&(o=[],s=-1);const i={ranges:o,rangeIndex:s,cell:n};return W.isEqualSelectionCoords(i,e)?void 0:this.updateCoords(i)}_isCellOutOfBounds(t){const e=this._getMaxRange();return t.rowIndex<e.rowStart||t.colIndex<e.colStart||t.colIndex>e.colEnd||t.rowIndex>e.rowEnd}_cellToRangeActual(t,e){const n={rowStart:Math.min(t.rowIndex,e.rowIndex),colStart:Math.min(t.colIndex,e.colIndex),rowEnd:Math.max(t.rowIndex,e.rowIndex),colEnd:Math.max(t.colIndex,e.colIndex)};if(this._canSelectionSpanMergedCells(n))return n;const r=this._getCellCoordsAsRangeCoords(t),o=this._getCellCoordsAsRangeCoords(e),s={rowStart:Math.min(r.rowStart,o.rowStart),colStart:Math.min(r.colStart,o.colStart),rowEnd:Math.max(r.rowEnd,o.rowEnd),colEnd:Math.max(r.colEnd,o.colEnd)},i=this._getMergedRanges(s);return W.extendRangeToUnionRanges(s,i)}_rangesFromCellOptional(t,e,n){const r=t.ranges.length>0?t.ranges[t.rangeIndex]:{rowStart:t.cell.rowIndex,colStart:t.cell.colIndex,rowEnd:t.cell.rowIndex,colEnd:t.cell.colIndex},o={rowStart:Math.min(e.rowIndex??r.rowStart,n.rowIndex??r.rowStart),colStart:Math.min(e.colIndex??r.colStart,n.colIndex??r.colStart),rowEnd:Math.max(e.rowIndex??r.rowEnd,n.rowIndex??r.rowEnd),colEnd:Math.max(e.colIndex??r.colEnd,n.colIndex??r.colEnd)},s={rowIndex:o.rowStart,colIndex:o.colStart},i={rowIndex:o.rowEnd,colIndex:o.colEnd};if(this._isCellOutOfBounds(s)||this._isCellOutOfBounds(i))return;return this._cellToRangeActual(s,i)}_getMaxRange(){return this._sheet.getEntireRange().getCoords()}toString(){let t="";return t+=`selection:[${this._sheet.getRange(this._coords.cell).toString()}`,this._coords.ranges&&this._coords.ranges.length>0&&(t+=`, ${this._sheet.getRanges(this._coords.ranges).toString()}`),void 0!==this._coords.rangeIndex&&-1!==this._coords.rangeIndex&&(t+=`, ${this._coords.rangeIndex}`),t+="]",t}}class VS{constructor(t,e){this._c=t,this._m=e}getModel(){return this._m}getCoords(){return this._c}getPropertiesAt(t,e,n){return this._m.getPropertiesAt(t,e,n)}getSplit(t){const e=this._m;return[new VS(t[0],e),new VS(t[1],e)]}}class $S extends Dl{constructor(t){if(super({...t}),this._coordsCache=null,!t.json)throw new Error("json is required");this._sheet=t.sheet,this._styles=t.sheet?.getStyles()??new Fp,this._options={...t},t.setOnContainerCoordsChange(this._processCoordsChange.bind(this)),t.setCreateSpatial(this._createSpatial.bind(this)),this._getContainerRanges=t.getContainerRanges,this._setContainerRanges=t.setContainerRanges;const e=this;this._options.transactions.addStateListener(this,{onRestoreOrRevert(){e._coordsCache=null},onBeforeCommitEnd(){e._coordsCache=null}}),this._fromJSON({...t.json})}getRanges(){return this._getContainerRanges()}setRanges(t,e){const n=this.getRanges(),r=this._setContainerRanges(t,e);return this._processCoordsChange({before:n?.getCoords()??null,after:r?.getCoords()??null}),this}setType(t,e){return this._updateState({type:t},{description:"Set Conditional Format Type",...e}),this}getType(){return this._getState().type}setPriority(t,e){return this._updateState({priority:t},{description:"Set Priority",...e}),this}getPriority(){return this._getState().priority}setStopIfTrue(t,e){return this._updateState({stopIfTrue:t},{description:`Set Stop ${t??!1}`,...e}),this}getStopIfTrue(){return this._getState().stopIfTrue??!1}getScalar(){return this._getState().value??null}getColorScale(){return this._getState().colorScale??null}getContainsText(){return this._getState().text}getCustom(){return this._getState().formulas}getDataBar(){return this._getState().dataBar??null}getIconSet(){return this._getState().iconSet}getPresetCriteria(){return this._getState().style}getTopBottom(){return this._getState()}getSnapshot(t){this.toJSON();const e=null,n=this,r=Object.freeze({...t});let o=!1;return{async copyTo(t,s){t.conditionals;const i=t.range;({...r,...s}).isCut&&!o&&(n.delete(),o=!0);const a={colStart:i.colStart,rowStart:i.rowStart,colEnd:e.colEnd-e.colStart+i.colStart,rowEnd:e.rowEnd-e.rowStart+i.rowStart};return console.log("implement copyTo"),a},getCoords:()=>e,getSource:()=>n,getName:()=>"Conditional Format",getMarkOptions:()=>r,isISnapshot:!0}}_processRestoreOrRevert(t,e,n){super._processRestoreOrRevert(t,e,n)}_createSpatial(t){return new VS(t,this)}_processCoordsChange(t){this._coordsCache=null,t.after?this._emitter.notify("onAnyChange"):this._delete()}update(t,e){if(this.isClosed())throw new Error("Table has been closed. No further operations are allowed.");const n=this._getState(),r=this._beginCommit(e?.description??"Update Conditional Format");try{const o={...n,...t};this._updateState(o,e),this._getEmitter().notify("onAnyChange"),r.commit()}catch(t){throw r.rollback(),t}return this}_processDelete(){this._getState(),super._processDelete()}_processStateChange(t,e,n){super._processStateChange(t,e,n),this._getEmitter().notify("onAnyChange")}toJSON(){const t={},e=this._getState();if(null===e)return null;const n=this.getRanges()?.toString();return n?(t.ref=n,t.type=e.type,0!==e.priority&&(t.priority=e.priority),e.stopIfTrue&&(t.stopIfTrue=e.stopIfTrue),e.style&&(t.style=e.style),e.colorScale&&(t.colorScale=e.colorScale),e.dataBar&&(t.dataBar=e.dataBar),e.iconSet&&(t.iconSet=e.iconSet),e.aboveAverage&&(t.aboveAverage=e.aboveAverage),e.equalAverage&&(t.equalAverage=e.equalAverage),0!==e.stdDev&&(t.stdDev=e.stdDev),e.bottom&&(t.bottom=e.bottom),e.percent&&(t.percent=e.percent),0!==e.rank&&(t.rank=e.rank),e.operator&&(t.operator=e.operator),e.formulas&&(t.formulas=e.formulas),e.text&&(t.text=e.text),e.timePeriod&&(t.timePeriod=e.timePeriod),t):null}_fromJSON(t){const e={};e.type=t.type??lS.Type.CellIs,e.priority=t.priority??0,e.stopIfTrue=t.stopIfTrue??!1,e.style=t.style??null,e.colorScale=t.colorScale??null,e.dataBar=t.dataBar??null,e.iconSet=t.iconSet??null,e.aboveAverage=t.aboveAverage??!1,e.equalAverage=t.equalAverage??!1,e.stdDev=t.stdDev??0,e.bottom=t.bottom??!1,e.percent=t.percent??!1,e.rank=t.rank??0,e.operator=t.operator??null,e.formulas=t.formulas??null,e.text=t.text??null,e.timePeriod=t.timePeriod??null,this._updateState(e,{description:"Initialize Conditional Format"})}close(){super.close(),this.isClosed()||(this._updateState({},{description:"Close Conditional"}),this._stylesRemoveListener?.())}getCoords(){return this.getRanges().getCoords()[0]}getPropertiesAt(t,e,n){let r=this._coordsCache;r||(r=this._coordsCache=this.getRanges().getCoords());let o=0,s=0;const i={rowIndex:t,colIndex:e};for(let n=0;n<r.length;n++){const a=r[n];if(W.isCellWithinRange(i,a)){const n=t-a.rowStart,r=e-a.colStart;s=o+(n*(a.colEnd-a.colStart+1)+r+1)}o+=(a.rowEnd-a.rowStart+1)*(a.colEnd-a.colStart+1)}let a={fill:{type:"solid",color:"red"}};return a.fill.color=((t,e,n,r)=>{let o=1;0!==e&&(o=t/e);const s=n[0]+o*(r[0]-n[0]),i=n[1]+o*(r[1]-n[1]),a=n[2]+o*(r[2]-n[2]);return`rgb(${Math.round(s)}, ${Math.round(i)}, ${Math.round(a)})`})(s,o,[255,255,255],[255,0,0]),a}get isIConditionalFormat(){return!0}}class US{constructor(t,e){this._add=t,this._get=e}add(t,e){if(!t)throw new Error(td);return this._add(t,e)}search(t){let e;t?.address&&(e=t.address);return this._get(e,t?.excludeHidden,t?.fullyContained)}getCount(){return this._get(null,!1,!1).length}}const GS=(t,e)=>{if(e)if(e.getType()===ya.Type.Solid)t.background=Zd(e.getColor())||"none",t["mso-pattern"]="black none";else if(e.getType()===ya.Type.Pattern){const n=e;t.background=Zd(n.getBackground())||"none";const r=Zd(n.getForeground())||"";if(n.getPatternType()===ya.BuiltInSheetPattern.Solid)t["mso-pattern"]=`${t.background} none`,t.background=r;else{const e=(t=>{const e=$g.get(t);return e?.cssKey??"solid"})(n.getPatternType());t["mso-pattern"]=r+(e?" ":"")+e}}else if(e.getType()===ya.Type.Gradient){const n=e;t.background=Zd(n.getStops()?.[0]?.getColor())||"auto",t.msoGradient=Jg(n)||"auto"}};class WS{constructor(t,e){if(this._visitedStyles=new Map,this._lastStyleClassId=63,this._wroteTD=!1,!t)throw new Error("Can not create with a null sheet.");this._sheet=t,this._includeSizeInCell=e??!1,this._normalStyle=t.getStyles().getNormal()}_createCSSStyle(t){const e=this._normalStyle,n={},r=(t,e)=>t===e||!(t&&!e)&&(!(!t&&e)&&e.isEqual?.(t)),o=t.getFont(),s=e.getFont();var i;r(o.getFill(),s.getFill())||(n.color=Zd(o.getFill())),r(o.getSize(),s.getSize())||(n["font-size"]=Qd(o.getSize())),r(o.getWeight(),s.getWeight())||(n["font-weight"]=o.getWeight()),r(o.getStyle(),s.getStyle())||(n["font-style"]=o.getStyle()),r(o.getUnderline(),s.getUnderline())||(n["text-decoration"]="underline",n["text-underline-style"]=(i=o.getUnderline())===fi.UnderlineStyle.Single?"single":i===fi.UnderlineStyle.Double?"double":i===fi.UnderlineStyle.SingleAccounting?"single-accounting":i===fi.UnderlineStyle.DoubleAccounting?"double-accounting":"none"),r(o.getFamily(),s.getFamily())&&r(o.getFallbacks(),s.getFallbacks())||(n["font-family"]=sg(o.getFamily(),o.getFallbacks())),r(t.getNumberFormat(),e.getNumberFormat())||(n["mso-number-format"]=ig(t.getNumberFormat()));const a=t.getAlignment(),l=e.getAlignment();if(!r(a.getHorizontal(),l.getHorizontal())){const t=a.getHorizontal();t===zs.HorizontalAlignment.CenterContinuous?n["text-align"]="center-across":t===zs.HorizontalAlignment.Fill?n["text-align"]="fill":t===zs.HorizontalAlignment.Distributed?n["text-align"]=a.getJustifyLastLine()?"121":"010":n["text-align"]=zs.toCSSHorizontalTextAlign(t)}if(!r(a.getVertical(),l.getVertical())){const t=a.getVertical();t===zs.VerticalAlignment.Distributed?n["vertical-align"]="121":n["vertical-align"]=rg(t)}if(!r(a.getOverflow(),l.getOverflow())){const t=a.getOverflow();n["white-space"]=og(t),t===zs.Overflow.Shrink&&(n["mso-text-control"]="shrinktofit")}var c;r(a.getRotation(),l.getRotation())||(n["mso-rotate"]=(c=a.getRotation(),(c%=360)<0&&(c+=360),c>180?c=360-c:c>1&&(c*=-1),c)),r(a.getIndent(),l.getIndent())||(n["mso-char-indent-count"]=a.getIndent()),r(t.getFill(),s.getFill())||GS(n,t.getFill());const h=t.getBorder();return h.getTop().isNone()||(n["border-top"]=Kg(h.getTop())),h.getLeft().isNone()||(n["border-left"]=Kg(h.getLeft())),h.getRight().isNone()||(n["border-right"]=Kg(h.getRight())),h.getBottom().isNone()||(n["border-bottom"]=Kg(h.getBottom())),h.getDiagonalUp().isNone()||(n["border-mso-diagonal-up"]=Kg(h.getDiagonalUp())),h.getDiagonalDown().isNone()||(n["border-mso-diagonal-down"]=Kg(h.getDiagonalDown())),0===Object.keys(n).length?null:n}_createCSSNormalStyle(){const t=this._normalStyle,e={"padding-top":"1px","padding-left":"1px","padding-right":"1px","mso-ignore":"padding"},n=t.getFont(),r=t.getAlignment();return e.color=Zd(n.getFill()),GS(e,t.getFill()),e["font-size"]=Qd(n.getSize()),e["font-weight"]=n.getWeight(),e["font-style"]=n.getStyle(),e["text-decoration"]=tg(n.getUnderline(),n.getStrike()),e["font-family"]=sg(n.getFamily(),n.getFallbacks()),e["mso-font-charset"]="0",e["mso-background-source"]="auto",e["mso-number-format"]=ig(t.getNumberFormat()),e["text-align"]=zs.toCSSHorizontalTextAlign(r.getHorizontal()),e["vertical-align"]=rg(r.getVertical()),e.border="none",e["mso-pattern"]="auto",e["white-space"]=og(r.getOverflow()),r.getOverflow()===zs.Overflow.Shrink&&(e["mso-text-control"]="shrinktofit"),e["mso-rotate"]="0",r.getIndent()>0&&(e["mso-char-indent-count"]=r.getIndent()),e["mso-protection"]="locked visible",e}onCell(t,e,n){let r;const o=t.getSpans();if(o.width>1||o.height>1){if(!t.isTopLeft())return!1;o.height>1&&n.addAttribute("rowspan",o.height),o.width>1&&n.addAttribute("colspan",o.width)}let s=t.toTextUnformatted();t.getNumberFormat().repeatPlaceholder&&(s=t.getNumberFormat().repeatPlaceholder.repeat(5)),n.setPlainText(s||"");const i=t.getStyle(),a=i.getFont();if(a.getVerticalAlignment()===fi.VerticalAlignment.Super&&(s=`<sup>${s}</sup>`),a.getVerticalAlignment()===fi.VerticalAlignment.Sub&&(s=`<sub>${s}</sub>`),a.getStrike()&&(s=`<s>${s}</s>`),t.getHyperlink()&&(s=`<a href="${t.getHyperlink().getAddress()}">${s}</a>`),n.setHTMLText(s||"&nbsp"),!this._wroteTD){const t=this._createCSSNormalStyle();n.addSharedStyle("td",t),this._wroteTD=!0}let l=this._visitedStyles.get(i);if(!l){const t=this._createCSSStyle(i);t&&(l="xl"+ ++this._lastStyleClassId,this._visitedStyles.set(i,l),n.addSharedStyle("."+l,t))}if(l&&n.addAttribute("class",l),this._includeSizeInCell){const t=this._sheet.getColumnHeaders().at(e.colIndex).getSize();n.addAttribute("width",t),n.addStyle("width",_t.roundAccurately(t/fi.getDeviceScale(),2)+"pt");const r=this._sheet.getRowHeaders().at(e.rowIndex).getSize();n.addAttribute("height",r),n.addStyle("height",_t.roundAccurately(r/fi.getDeviceScale(),2)+"pt")}return r}onRow(t,e,n,r){const o=t.getSize();r.addAttribute("height",o),r.addStyle("height",_t.roundAccurately(o/fi.getDeviceScale(),2)+"pt"),t.isCustomSize()&&r.addStyle("mso-height-source","userset")}onColumn(t,e,n,r){const o=t.getSize();r.addAttribute("width",o),r.addStyle("width",_t.roundAccurately(o/fi.getDeviceScale(),2)+"pt"),t.isCustomSize()&&r.addStyle("mso-width-source","userset"),n>1&&r.addAttribute("colspan",n)}}const qS=(t,e,n)=>{const r=t.getOrientation()===I.Column,o=(r?"Column":"Row")+" Copy",s=t.getSnapshot(n);return{...s,getName:()=>o,getCoords:()=>e,copyTo:async(t,o)=>{const i=r?t.getColumnHeaders():t.getRowHeaders(),a={...n,...o};if(!0===a.includeHeaders){const t=await s.copyTo(i,a);return r?{colStart:t.min,rowStart:e.rowStart,colEnd:t.max,rowEnd:e.rowEnd}:{colStart:e.colStart,rowStart:t.min,colEnd:e.colEnd,rowEnd:t.max}}},getMarkOptions:()=>n}},JS=(t,e,n,r,o,s)=>{const i=n[0];let a,l;const c=()=>{if(void 0!==l)return;const[t,n]=((t,e)=>{const n=e.getRowHeaders(),r=e.getColumnHeaders(),o=e.getUsedRange()?.getCoords(),s=n.getUsedRange()?.getCoords(),i=r.getUsedRange()?.getCoords(),a={...W.EmptyRange,...o,colEnd:Math.max(o?.colEnd??0,i?.max??0),rowEnd:Math.max(o?.rowEnd??0,s?.max??0)},l=new Map,c=[];t.onStart?.();const h={rows:[],cols:[]},u=new gS(l,c);u.setNode(h),t.onTable?.(u,a);let d=0;r.forEachSpan((e,n)=>{const r=n.getCoords();d=d+r.max-r.min+1;const o={};u.setNode(o),t.onColumn?.(n.getCellHeader(),r.min,r.max-r.min+1,u),h.cols.push(o)},{address:a,includeEmpty:!0,includeStyles:!0});let g=0;const m=[];if(n.forEachSpan((t,e)=>{const n=e.getCoords();g=g+n.max-n.min+1,m.push({min:n.min,max:n.max,value:e.getCellHeader()})},{address:a,includeEmpty:!0,includeStyles:!0,excludeHidden:!1}),d*g>5e4){if(!dS)throw dS=!0,new Ot("Unable to write more than 50000 cells to system clipboard. Items can still be pasted within the application to but if you want to copy to another application select a smaller set of data.");return[null,null]}let f=0,p=-1,_=null;e.forEach((e,n)=>{const r=n.getCoords(),o=n.getCell();if(r.rowIndex!==p){r.rowIndex>m[f].max&&++f;const e=m[f];_={cells:[]},u.setNode(_),t.onRow?.(e.value,r.rowIndex,1,u),h.rows.push(_),p=r.rowIndex}const s={};u.setNode(s),!1!==t.onCell(o,r,u)&&_.cells.push(s)},{address:a,includeEmpty:!0,excludeHidden:!1}),t.onDone?.(),0===h.rows.length&&h.rows.push({cells:[]});const S=[];for(let t=0;t<c.length;t++){const e=c[t],n=l.get(e);S.push(e);let r="";const o=Object.keys(n);for(let t=0;t<o.length;t++){r+=" ",0===t&&(r+="{");const e=o[t];r+=`${e}:${n[e]};`,t===o.length-1?r+="}":r+="\n"}S.push(r)}const w=['<div clipboard-uuid=xxx>\n<html\n xmlns:v="urn:schemas-microsoft-com:vml"\n xmlns:o="urn:schemas-microsoft-com:office:office"\n xmlns:x="urn:schemas-microsoft-com:office:excel"\n xmlns="http://www.w3.org/TR/REC-html40"\n>'];w.push('<head>\n<meta http-equiv=Content-Type content="text/html; charset=utf-8">\n<meta name=ProgId content=Excel.Sheet>\n<meta name=Generator content="Microsoft Excel 15">'),w.push('<style>\ntable\n {mso-displayed-decimal-separator:"\\.";\n mso-displayed-thousand-separator:"\\,";}\n@page\n {margin:.75in .25in .75in .25in;\n mso-header-margin:.3in;\n mso-footer-margin:.3in;\n mso-horizontal-page-align:center;}\ntr\n {mso-height-source:auto;}\ncol\n {mso-width-source:auto;}\nbr\n {mso-data-placement:same-cell;}'),S.length>0&&w.push(S.join("\n")),w.push("</style>"),w.push("</head>"),w.push("<body>"),w.push("<table>"),w.push("\x3c!--StartFragment--\x3e");const y=t=>{let e=(t=>{let e="";return t&&t.attributes&&0!==t.attributes.length?(t.attributes.forEach((t,n)=>{e.length>0&&(e+=" "),e+=`${n}=${t}`}),e):e})(t);e.length>0&&(e=" "+e);let n=(t=>{let e="";return t&&t.styles&&0!==t.styles.length?(t.styles.forEach((t,n)=>{e.length>0&&(e+=";"),e+=n+":"+t}),e.length>0&&(e=`style='${e}'`),e):e})(t);return n.length>0&&(n=" "+n),`${e}${n}`},E=[];return h.cols?.forEach(t=>{w.push(` <col${y(t)}>`)}),h.rows.forEach(t=>{w.push(` <tr${y(t)}>`);const e=[];t.cells.forEach(t=>{w.push(` <td${y(t)}>${t.htmlText??t.plainText??""}</td>`);const n=`${_t.castToString(t.plainText??"")?.replace(/"/g,'""')}`;e.push(n)}),E.push(e.join("\t")),w.push(" </tr>")}),w.push("\x3c!--EndFragment--\x3e"),w.push("</table>"),w.push("</body>"),w.push("</html>"),w.push("</div>"),[w.join("\n"),E.join("\n").concat("\n")]})(new WS(e),e.getRange(i));a=t??null,l=n??null};return{copyTo(t,e){const n={...o,...e};return e.isCut,s(t,n)},getMarkOptions:()=>o,getSource:()=>t,getName:()=>r,getCoords:()=>i,toText:()=>(c(),l),toHtml:()=>(c(),a),toImage:()=>null,isISnapshot:!0}},XS=(t,e)=>Math.round(t*e),KS=(t,e,n)=>{const r=[],o=[];if(!t||0===t.length)return{sizes:r,hidden:o};if(!e||!n)return console.warn("_HeaderUtils:default size and scaleFactor should be available"),{sizes:r,hidden:o};let s=0,i=0,a=0,l=null,c=-2;for(let h=0;h<t.length;h++){const u=t[h],d=u.min,g=u.max;s=0===r.length?0:r[r.length-1].runningOffsetMax,r.length>0&&r[r.length-1].spanSize>0&&s++,i<u.min&&r.push({indexMin:i,indexMax:d-1,runningOffsetMin:s,runningOffsetMax:Math.round(s+(d-i)*e*n)-1,runningHiddenRuns:a,spanSize:Math.round(e*n)});const m=r.length,f=r[m-1];s=0===m?0:f.runningOffsetMax,m>0&&f.spanSize>0&&s++;let p=0;u.value.h||(p=XS(u.value?.sz??e,n));const _=0===p?0:-1;0===p&&(a+=g-d+1,c+1===d?l.max=g:(l={min:d,max:g,value:!0},o.push(l)),c=g),m>0&&f.spanSize===p&&f.indexMax+1===d?(f.indexMax=g,f.runningHiddenRuns=a,f.runningOffsetMax=f.runningOffsetMin+(g+1-f.indexMin)*p+_):r.push({indexMin:d,indexMax:g,runningOffsetMin:s,runningOffsetMax:Math.round(s+(g+1-d)*p)+_,runningHiddenRuns:a,spanSize:p}),i=g+1}return{sizes:r,hidden:o}};function YS(t,e,n){void 0!==n&&(null!==n?t[e]=n:delete t[e])}const ZS=()=>{},QS=()=>0,tw=()=>!1;const ew=(t,e,n,r)=>{if(void 0!==r){if(null===r)return null;if(r?.isICellHeader){return r._headerState}if(r){const o=r,s={...n};let i,a=o.hidden,l=o.size;if(void 0!==o.size){if("function"==typeof l){const e=void 0===n?.sz?t.getDefaultSize():n?.sz*t.getScaleFactor();l=l?.(e)}if("string"==typeof l&&(l=Vg(l,e.getNormal().getFont().getSize(),"px")),"number"==typeof l){const e=t.getMinSize(),n=t.getMaxSize();if(l=Math.max(e,Math.min(_t.roundAccurately(l,e),n)),!0!==o.relativeSize){l/=t.getScaleFactor()}isNaN(l)&&(console.warn("headerSize can not be NaN"),l=void 0),0===l&&(a=!0,l=void 0),i=!o.autoSize}else null===l?(l=null,i=!o.autoSize):void 0!==l&&(console.warn("headerSize can not be type",l),l=void 0)}return YS(s,"sz",l),YS(s,"h",a),YS(s,"csz",i),0===Object.keys(s).length?null:s}}};class nw{constructor(t,e,n){this._sheetHeader=t;const r=this._sheetHeader.getSheet().getStyles();this._styles=r,this._headerState=e,this._template=n}getSize(){const t=this._headerState?.sz;return Math.round(void 0===t?this._sheetHeader.getDefaultSize():t*this._sheetHeader.getScaleFactor())}getDisplayText(){return""+this.asCell().getValue()}getOrientation(){return this._sheetHeader.getOrientation()}isHidden(){const t=this._headerState?.h;return t??!1}isCustomSize(){const t=this._headerState?.cs;return t??!1}getSheetHeader(){return this._sheetHeader}getStyle(){const t=this._headerState?.s;return t??this._styles.getNormal()}asCell(){return this._cellTemplate||(this._cellTemplate=this._sheetHeader.getSheet().createTemporaryCell({style:this.getStyle(),...this._template})),this._cellTemplate}getSizeRelative(){return this.getSize()/this._sheetHeader.getScaleFactor()}createTemporaryCellHeader(t){const e=ew(this._sheetHeader,this._sheetHeader.getSheet().getStyles(),this._headerState,t);return new nw(this._sheetHeader,e,this._template)}isEqual(t){if(!t)return!1;if(t===this)return;const e=t;if(!e.isICellHeader)return!1;const n=this._headerState,r=e._headerState;return n===r||!(n&&!r||r&&!n)&&(this.getSize()===e.getSize()&&(this.isCustomSize()===e.isCustomSize()&&(this.isHidden()===e.isHidden()&&this.getStyle()===e.getStyle())))}isEmpty(){const t=this._headerState;return!t||void 0===t.sz&&(void 0===t.csz&&(!t.cs&&(void 0===t.h&&!(!t.s||t.s!==this._styles.getNormal()||t.cs))))}get isICellHeader(){return!0}}const rw="The columns are protected. To make a change, unprotect the sheet. You might be requested to enter a password.",ow="The rows are protected. To make a change, unprotect the sheet. You might be requested to enter a password.",sw="Rows",iw="Columns";class aw{constructor(t){if(this._emitter=null,this._closed=!1,this._scaleFactor=1,this._defaultSize=-1,this._defaultCustomSize=-1,this._defaultPxSize=1,this._isColumn=!0,this._indexedSizes=[],this._indexedHidden=[],this._headerRunCoords=null,this._hasCustomFormats=!1,this._hasStyles=!1,this._hasHidden=!1,this._lastHeaderRead=null,this._readCache=null,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null,this._options={isProtected:()=>!1,getUpdateId:()=>null,scaleFactor:()=>1,defaultSize:()=>100,minSize:()=>0,maxSize:()=>500,orientation:e.Orientation.Column,createCellHeader:(t,e,n)=>new nw(t,e,n),...t},!this._options.sheet)throw new Error("An ISheet must be provided");if(this._emptyHeader=this._options.createCellHeader(this,null,null),this._scaleFactor=this._options.scaleFactor(),this._defaultSize=this._options.defaultSize(),this._defaultSize<=0)throw new Error("defaultSize must be greater than 0");this._defaultPxSize=XS(this._defaultSize,this._scaleFactor);const n=this._options.orientation===e.Orientation.Column;this._isColumn=n;const r=this._options.maxSheetCoords??{colStart:0,rowStart:0,colEnd:Number.MAX_SAFE_INTEGER,rowEnd:Number.MAX_SAFE_INTEGER};this._maxSheetCoords=r;const o=n?r.colEnd:r.rowEnd;this._maxDataIndex=o,this._maxRunCoords={min:0,max:o},this._maxDataRange=this.getRange(this._maxRunCoords),this._maxRangeCoords={colStart:0,rowStart:0,colEnd:n?o:0,rowEnd:n?0:o};const s=this;this._options.setContainerShiftedCallback&&this._options.setContainerShiftedCallback((t,e)=>{e<0?s._deleteHeaders(t,-e):s._insertHeaders(t,e)}),this._options.sheet&&(this._sheetRemoveListener=this._options.sheet.addListeners({onProtectionChange(){},onSelectionChange(t){s._selection=t.getSelection().getCoords(),s._selectionRuns=null},onStyleChange:()=>{},onViewChange(){const t={runs:s._headers};s._invalidSizes(),s._emitter.notify("onSizesChange",{params:t})}},{transactional:!1}),s._selection=s._options.sheet.getSelection().getCoords()),this._transactions=this._options.transactions??new ie({transient:!0}),this._emitter=new Ll(s,this._transactions),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t){s._lastHeaders!==t.headers&&s._onHeaderChange()}}),this.fromJSON(this._options?.json)}addListeners(t,e){return this._emitter.addListeners(t,e)}_invalidSizes(){const t=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize,e=this._options.scaleFactor();if(t!==this._defaultSize||e!==this._scaleFactor){this._defaultSize=t,this._scaleFactor=e,this._defaultPxSize=XS(t,e);const n=KS(this._headers,t,e);this._indexedSizes=n.sizes,this._indexedHidden=n.hidden,this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null}}_onHeaderChange(){this._lastHeaders=null;const t=this._headers,e=this._getState();this._defaultCustomSize=e.defaultCustomSize;const n=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize;this._defaultSize=n;const r=this._scaleFactor;this._defaultPxSize=XS(n,r);const o=KS(t,n,r);this._indexedSizes=o.sizes,this._indexedHidden=o.hidden,this._lastHeaderRead=null,this._readCache=ma(this._lastHeaders),this._lastVisibleRunsRead=null,this._lastVisibleRunCoords=null;const s=this._options.sheet.getStyles().getNormal();let i=!1,a=!1,l=!1,c=-1;for(let e=t.length-1;e>=0;e--){const r=t[e],o=r.value,h=o.s,u=o.csz||o.sz!==n;-1!==c||!u&&h===s||(c=r.max),i=i||o.cs,a=a||o.s!==s,l=l||o.h||0===o.sz}c=Math.min(c??0,this._maxDataIndex);const h=Math.min(t[0]?.min??c,c);this._headerRunCoords=Object.freeze({min:h,max:c}),this._hasCustomFormats=i,this._hasStyles=a,this._hasHidden=l;const u=e.runs;this._emitter.notify("onSizesChange",{params:u})}getSheet(){return this._options.sheet}getOrientation(){return this._isColumn?e.Orientation.Column:e.Orientation.Row}getTextAt(t){return this._options.getTextAt?.(t)??t+""}_scanHeaders(t,e,n,r,o,s){const i=o?.min??null,a=o?.max??null,l=s?.includeEmpty??!1,c=s?.includeStyles??!1,h=s?.excludeHidden??!1,u=s?.includeSizes??!1,d=this,g=this._options.sheet.getStyles().getNormal(),m=this._defaultSize,f=this._scaleFactor,p=this._emptyHeader;let _;const S={getCoords(){if(!_)throw new Error(Rd);return{min:_.min,max:_.max}},getIndex:()=>_.min,getCellHeader(){if(!_)throw new Error(Rd);return _.value?n(d,_.value):p},getA1(t){if(!_)throw new Error(Rd);return this._parseHeaderRangeAddress({min:i+t,end:i+t})??_}},w=pa(e,e=>{const n=e.value;if(!l&&!n)return;let r=l;if(u&&!r&&n&&(n.csz||n.sz!==m)&&(r=!0),c&&!r&&n&&(n.s&&n.s!==g||n.cs)&&(r=!0),n&&!0===n.h&&(r=!h),!r)return;let o=m;e.value&&(o=e.value.h?0:e.value?.sz??m),o*=f,_=e;const s=t(o,S);return s&&s.break?s:void 0},i,a);return _=null,w}getRange(t,e){if(!t)throw new Error(td);const n=this,r=this._parseHeaderRangeAddress(t);if(r.min<0||r.max>this._maxDataIndex)return function(t){const e={getCoords:()=>null,getOrientation:()=>t.getOrientation(),toString:()=>gu,getA1:()=>gu,getCount:QS,getVisibleCount:QS,isEntireHeaders:tw,forEach:ZS,forEachSpan:ZS,forEachVisibleSpan:ZS,getUsedRange:od,getSnapshot:od,updateHeaders:od,clear:od,setHidden:od,setSize:od,at:od,doBatch:od,getSheetHeader:()=>t,isICellHeaderRange:!0};return Object.freeze(e)}(this);const o=(t,o,s,i=n._options.createCellHeader)=>{let a=r;if(o?.address){const t=n._parseHeaderRangeAddress(o?.address);if(t&&(a=ga(r,t),!a))return}const l=this._scanHeaders(t,s,i,e,a,o);if(l&&l.break)return l.break},s=()=>{const t=n._isColumn?{colStart:r.min,colEnd:r.max}:{rowStart:r.min,rowEnd:r.max};return Mu(t,n._maxRangeCoords)??gu},i={getCoords:()=>r,getA1:s,toString:s,forEach:(t,e)=>{let n=Number.MAX_SAFE_INTEGER,s=null;const i={getIndex:()=>n,getCellHeader:()=>s.getCellHeader(),getA1:t=>s.getA1(t),getCoords:()=>s.getCoords()};return o((e,o)=>{s=o;for(let o=r.min;o<r.max;o++)n=o,t(e,i)},e,this._headers,()=>this.at(undefined))},forEachSpan:(t,e)=>o(t,e,this._headers),forEachVisibleSpan:(t,e)=>{const n=r?.min??null,o=r?.max??null;let s;if(s=e?.includeHidden?t(n,o):pa(this._indexedHidden,e=>{if(e.value)return;const n=t(e.min,e.max);return n&&n.break?n:void 0},n,o),s&&s.break)return s.break},updateHeaders:(t,e)=>(n.updateHeaderPairs([{address:r,update:t}],{description:e?.description??`Update ${n._isColumn?iw:sw} ${toString()}`,...e}),i),setHidden:t=>(n.setHidden(r,t),i),getUsedRange:t=>{const e=n._headerRunCoords;if(!e||e.min<0||e.max>n._maxDataIndex)return null;return ga(e,r)?n.getRange(e,t):null},getCount:()=>r.max-r.min+1,getVisibleCount:()=>n.getVisibleCount(r.min,r.max),isEntireHeaders:()=>{const t=n._maxRunCoords;return!(r.min>t.min||r.max<t.max)},getSnapshot:t=>this._getSnapshot(r,t),clear:()=>(n._clear(r),i),setSize:(t,e)=>(n.setSize(r,t,e),i),at:t=>n.at(r.min+t),getOrientation:()=>n.getOrientation(),doBatch:(t,e)=>this.doBatch(e=>t(e),e),getSheetHeader:()=>n,isICellHeaderRange:!0};return Object.freeze(i)}getSelectedRange(t){const e=(t=>{if(!t)return null;let e=W.cellToRange(t.cell);for(let n=0;n<t.ranges.length;n++)e=W.unionRanges(e,t.ranges[n]);return e})(this._options.sheet.getSelection().getCoords());return this.getRange(e,t)}getUsedRange(t){return this.getRange(this._headerRunCoords,t)}getEntireRange(t){return t?this.getRange(this._maxRangeCoords,t):this._maxDataRange}at(t){if(t<0||t>this._maxDataIndex)return this._emptyHeader;if(this._lastHeaderRead?.offset===t)return this._lastHeaderRead.header;const e=fa(t,this._readCache);if(!e)return this._emptyHeader;const n=this._options.getTextAt?.(t)??t+"",r=this._options.createCellHeader(this,e,{value:n});return this._lastHeaderRead={offset:t,header:r},r}updateHeaderPairs(t,e){if(this.isProtected())throw new Error(this._isColumn?rw:ow);return this._updatePairsInternal(t,e)}_parseHeaderRangeAddress(t){if(null==t)throw new Error("Must specify a range.");const e=((t,e,n)=>{if(null==t)return null;let r={};if("number"==typeof t)r.colStart=t,r.colEnd=t,r.rowStart=t,r.rowEnd=t;else if("string"==typeof t){if(e){if(t.match(/[0-9]+/))throw new Error("Invalid range address for header orientation")}else if(t.match(/[a-zA-Z]+/))throw new Error("Invalid range address for header orientation");let o=Fu(t,n);if(!o){const e=Nu(t.toUpperCase(),!0);void 0!==e?.colIndex&&(r.colStart=e.colIndex,r.colEnd=e.colIndex),void 0!==e?.rowIndex&&(r.rowStart=e.rowIndex,r.rowEnd=e.rowIndex)}r={...r,...o}}const o={min:void 0,max:void 0};return e?(o.min=t.min??t.colStart??r.colStart,o.max=t.max??t.colEnd??r.colEnd):(o.min=t.min??t.rowStart??r.rowStart,o.max=t.max??t.rowEnd??r.rowEnd),void 0===o.min||void 0===o.max?null:o})(t,this._isColumn,this._maxRangeCoords);if(!e)throw new Error("Invalid header range.");return e}update(t,e,n){if(!t)return;if(Array.isArray(t)||(t=[t]),0===t.length)return;const r=[];for(let n=0;n<t.length;n++){const o=this._parseHeaderRangeAddress(t[n]);this.getRange(o).forEachSpan((t,n)=>{const o=n.getCoords();r.push({address:o,update:e})},{includeEmpty:!0})}return this.updateHeaderPairs(r,n),this}setSize(t,e=null,n){(n?.relativeSize??!1)||"number"!=typeof e||(e+="px");const r={size:e,autoSize:n?.autoSize??!1},o=`Resize ${this._isColumn?iw:sw}`;return this.update(t,r,{description:o,...n}),this}setHidden(t,e=null){const n={hidden:e},r=`${e?"Unhide":"Hide"} ${this._isColumn?iw:sw}`;return this.update(t,n,{description:r}),this}_clear(t,e){const n="Clear "+(this._isColumn?"Column Headers":"Row Headers");this.updateHeaderPairs([{address:t,update:null}],{description:n,...e})}_getSnapshot(t,e){if(t.min<0)return _t.EmptyArray;e=Object.freeze({...e});const n=this,r=this._getState(),o=(this._isColumn?"Column":"Row")+" Headers",s={copyTo(s,i){const a={...e,...i},l=s.getCoords(),c=l.min-t.min,h=[];if(n._scanHeaders((t,e)=>{const n=e.getCoords();h.push({address:{min:n.min+c,max:n.max+c},update:e.getCellHeader()})},r.headers,n._options.createCellHeader,null,t,{includeSizes:!0,includeStyles:!0}),!a.fitDestination){let e=t.max-t.min+1,n=l.max-l.min+1,r=_t.roundAccurately(n/e);if(r>1&&n%e===0){const t=h.length;for(let n=0;n<r;n++)for(let r=0;r<t;r++){const t=h[r],o=t.address,s=(n+1)*e;h.push({address:{min:o.min+s,max:o.max+s},update:t.update})}}}if(s.doBatch(()=>{s.clear(),s.getSheetHeader()._updatePairsInternal(h)},o),a.isCut){const e=n._maxRunCoords;t.min<=e.min&&t.max>=e.max&&n._clear(t)}return l},getCoords:()=>t,toText:()=>null,toHtml:()=>null,toImage:()=>null,getSource:()=>n,getName:()=>o,isISnapshot:!0};return s}isProtected(){return this._options?.isProtected()??!1}getScaleFactor(){return this._options.scaleFactor()??1}get _headers(){return null===this._lastHeaders&&(this._lastHeaders=this._getState()?.headers),this._lastHeaders}_updatePairsInternal(t,e){if(!t||0===t.length)return null;const n=e?.skipCustomSize??!1,r=this._isColumn,o=this.getSheet().getStyles(),s=this._beginCommit({description:e?.description??`Update ${r?iw:sw}`});let i=[...this._getState().headers],a=!1,l=!1;const c=r?Ba.Edge.Top:Ba.Edge.Left;Ba.oppositeEdge(c);const h=r?Ba.Edge.Right:Ba.Edge.Bottom;Ba.oppositeEdge(h);const u=this,d=(t,e)=>{if(this.isProtected())throw new Error(this._isColumn?rw:ow);l=l||null===e,!l&&e&&(l=!!e.isICellHeader||(void 0!==e?.size||void 0!==e?.hidden)),a=a||null===e||void 0!==e?.style||e?.isICellHeader;const r={onUpdate:(t,e)=>{if(n&&t&&t.csz)return t;return ew(u,o,t,e)},onSplit:t=>[t.value,t.value],onMerge:(t,e,n,r)=>{if(!(t&&!e||!t&&e||!t&&!e)&&t.sz===e.sz&&t.csz===e.csz&&t.h===e.h&&t.cs===e.cs)return t},isCull:(t,e,n)=>void 0===t};i=ca(la(i,{min:t.min,max:t.max,value:e},r))},g=t.length,m=new Array(g);for(let e=0;e<g;e++){const n=t[e],r=this._parseHeaderRangeAddress(n.address);if(r.min<0||r.max>this._maxDataIndex)throw new kt(wd);d(r,n.update),m[e]=r}let f=!1,p=i.length;if(p>0&&0===i[0].min&&i[p-1].max===this._maxDataIndex){let t=i[0],e=!1,n=-1;for(let r=0;!e&&r<p;r++){const o=i[r],s=o.min;if(n+1!==s){e=!0;continue}const a=o.max;n=a,t.max-t.min<a-s&&(t=o)}e||(this._defaultCustomSize=t.value?.sz??-1,f=!0);const r=-1===this._defaultCustomSize?this._options.defaultSize():this._defaultCustomSize,o=[];for(let t=0;t<p;t++){const e=i[t],n=e.value;if(null===n)continue;const s=Object.keys(n);0!==s.length&&((1!==s.length||void 0===n.sz||null!==n.sz&&n.sz!==r)&&o.push(e))}i=o,p=i.length}const _=[],S=this._defaultSize;for(let t=0;t<p;t++){const e=i[t],n=e.value;if(null===n)continue;let r=!1;void 0!==n.sz&&n.sz!==S&&(r=!0),n.csz&&(r=!0),n.h&&(r=!0),n.cs&&(r=!0),r&&_.push(e)}return i=_,p=i.length,f&&u._invalidSizes(),this._updateState({headers:i,defaultCustomSize:this._defaultCustomSize,runs:m}),s.commit(),m}hasCustomFormats(){return this._hasCustomFormats}hasCustomStyles(){return this._hasStyles}hasHidden(){return this._hasHidden}getDefaultSize(){return this._defaultPxSize}getMaxSize(){return Math.ceil(this._options.maxSize()*this._options.scaleFactor())}getMinSize(){return Math.floor(this._options.minSize()*this._options.scaleFactor())}findOffset(t){return((t,e,n)=>{if(e<0)return 0;if(!t||0===t.length)return e*n;const r=t[t.length-1];if(e>r.indexMax)return r.runningOffsetMax+Math.round((e-r.indexMax-1)*n+(0!==r.spanSize?1:0));const o=1===t.length?0:_t.findEqualOrGreater(t,e,t=>t.indexMax),s=t[o],i=e-s.indexMin;return s.runningOffsetMin+i*s.spanSize})(this._indexedSizes,t,this._defaultPxSize)}findIndex(t){return Math.min(Math.max(0,((t,e,n)=>{if(!t||0===t.length)return Math.floor(e/n);const r=t[t.length-1];if(e>r.runningOffsetMax)return r.indexMax+Math.ceil((e-r.runningOffsetMax)/n);let o=1===t.length?0:_t.findEqualOrGreater(t,e,t=>t.runningOffsetMax);const s=t[o];if(0===s.spanSize)return Math.max(0,s.indexMin-1);const i=e-s.runningOffsetMin;return s.indexMin+Math.floor(i/s.spanSize)})(this._indexedSizes,t,this._defaultPxSize)),this._maxDataIndex)}findVisibleIndex(t){return this._lastVisibleRunsRead===t||(this._lastVisibleRunCoords=((t,e,n=Number.MAX_SAFE_INTEGER)=>{if(!t||0===t.length)return{min:e,max:e};let r=t.length-1,o=t[r];if(e>o.indexMax){const t=e-o.runningHiddenRuns;return{min:t,max:t}}r=1===t.length?0:_t.findEqualOrGreater(t,e,t=>t.indexMax),o=t[r];const s=0===o.spanSize?Math.max(-1,o.indexMin-1-(t[r-1]?.runningHiddenRuns??1)):e-o.runningHiddenRuns;return{min:s,max:s+Math.min(n+1,0===o.spanSize?1:0)}})(this._indexedSizes,t,this._maxDataIndex),this._lastVisibleRunsRead=t),this._lastVisibleRunCoords}getSpanSize(t,e=t+1){return this.findOffset(e)-this.findOffset(t)}getVisibleCount(t,e){if(t>e)throw new Error("Invalid arguments.");if(t<0||e>this._maxDataIndex)throw new kt;return this._hasHidden?((t,e,n)=>{let r=n-e+1;if(0===t.length)return r;let o=t.length-1,s=t[o];if(e>s.indexMax)return r;o=1===t.length?0:_t.findEqualOrGreater(t,e,t=>t.indexMax),s=t[o];let i=s.runningHiddenRuns;if(0===s.spanSize&&e<=s.indexMax){const t=s.indexMax-s.indexMin+1;r-=Math.min(t,s.indexMax-e+1)}n>s.indexMax&&o<t.length&&(o=_t.findEqualOrGreater(t,n,t=>t.indexMax),s=t[Math.min(o,t.length-1)]);let a=s.runningHiddenRuns;if(0===s.spanSize&&s.indexMin<=n){const t=s.indexMax-s.indexMin+1;r-=Math.min(t,n-s.indexMin+1),a-=t}return r-=a-i,r})(this._indexedSizes,t,e):e-t+1}isSelectedAll(t){const e=this.getSelectedRuns();if(0===e.length)return!1;const n=_t.findEqualOrGreater(e,t,t=>t.max),r=e[n];return!(!r||t<r.min||t>r.max)&&r.value.isSelectedAll}isSelected(t){const e=this.getSelectedRuns();if(0===e.length)return!1;const n=_t.findEqualOrGreater(e,t,t=>t.max),r=e[n];return!(!r||t<r.min||t>r.max)}getSelectedRuns(){let t=this._selectionRuns;return t||(this._selection&&(t=((t,n,r)=>{let o=[];n?.ranges&&n.ranges.length>0?o=n.ranges:n?.cell&&(o=[W.cellToRange(n?.cell)]);let s=[];const i=t.getOrientation()===e.Orientation.Column;for(let t=0;o&&t<o.length;t++){const e=o[t],n=i?e.colStart:e.rowStart,a=i?e.colEnd:e.rowEnd,l=i?e.rowStart:e.colStart,c=i?e.rowEnd:e.colEnd,h=i?r.rowStart:r.colStart,u=i?r.rowEnd:r.colEnd,d=l<=h&&c>=u;s=ca(la(s,{min:n,max:a,value:{isSelectedAll:!1}},{onUpdate:(t,e)=>{const n=ra(t,e);return n.isSelectedAll=t?.isSelectedAll||d,n}}))}return s})(this,this._selection,this._maxSheetCoords)),t||(t=_t.EmptyArray)),this._selectionRuns=t,this._selectionRuns}hiddenHeadersAt(t,e=!1){if(0===this._indexedSizes.length)return 0;let n=1===this._indexedSizes.length?0:_t.findEqualOrGreater(this._indexedSizes,t,t=>t.indexMax),r=this._indexedSizes[n];return!r||0!==r.spanSize||r.indexMin>t||r.indexMax<t?0:e?t-r.indexMin+1:r.indexMax-t+1}_insertHeaders(t,e){if(this.isProtected())throw new Error(this._isColumn?rw:ow);if(e<=0)return;const n=this._beginCommit({description:`Insert ${this._isColumn?iw:sw}`}),r=this._getState();let o=[...r.headers];o=ca(((t,e,n=1)=>{const r=_t.findEqualOrGreater(t,e,t=>t.max),o=t.slice(0,r),s=[],i=[];if(!t[r])return{preceding:o,modified:i,trailing:s};t[r].min>=e?s.push({...t[r],min:t[r].min+n,max:t[r].max+n}):i.push({...t[r],min:t[r].min,max:t[r].max+n});for(let e=r+1;e<t.length;e++)s.push({...t[e],min:t[e].min+n,max:t[e].max+n});return{preceding:o,modified:i,trailing:s}})(o,t,e));const s=[{min:t,max:t+e}];this._updateState({headers:o,runs:ca(ha([...r?.runs??[],...s]))}),n.commit()}_deleteHeaders(t,e){if(this.isProtected())throw new Error(this._isColumn?rw:ow);const n=this._beginCommit({description:`Delete ${this._isColumn?iw:sw}`}),r=this._getState();let o=[...r.headers];o=ca(aa(o,t,e));const s=[{min:t,max:t+e}];this._updateState({headers:o,runs:ca(ha([...r?.runs??[],...s]))}),n.commit()}beginCommit(t){return this._beginCommit("string"==typeof t?{description:t}:t)}doBatch(t,e){return this._transactions.doBatch(t,"string"==typeof e?{description:e}:{description:"Update Header",...e})}isClosed(){return this._closed}close(){this._sheetRemoveListener?.(),this._emitter.close(),this._transactionsRemoveListener?.(),this._closed=!0}_getState(){return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit(t)}_updateState(t){const e=this._transactions.beginCommit();try{e.updateState(this,t),this._onHeaderChange(),e.commit()}catch(t){throw e.rollback(),t}}fromJSON(t){const e=t||{};this._defaultCustomSize=e.defaultSize??-1,this._defaultCustomSize<=0&&(this._defaultCustomSize=-1),this._invalidSizes();const n=this._options.sheet.getStyles().beginPersist();try{const t=[],n=e.headers?e.headers.length:0,r=this._maxDataIndex;for(let o=0;o<n;o++){let n=e.headers[o];if(n.min>=r)continue;let s={min:n.min,max:Math.min(n.max,r)};const i={};void 0!==n.sz&&-1!==n.sz&&(i.sz=n.sz),void 0!==n.h&&(i.h=n.h),void 0!==n.csz&&(i.csz=n.csz),void 0!==n.cs&&(i.cs=n.cs),0===Object.keys(i).length&&(i.cs=!0),s.value=i,t.push(s)}this._updateState({headers:t,defaultCustomSize:this._defaultCustomSize})}finally{n.endPersist()}}toJSON(){if(0===this._headers.length&&-1===this._defaultCustomSize)return null;const t={headers:[]};if(-1!==this._defaultCustomSize&&(t.defaultSize=_t.roundAccurately(this._defaultCustomSize,8)),0===this._headers.length)return t;const e=this._defaultCustomSize,n=this.getSheet().getStyles().beginPersist();for(let n=0;n<this._headers.length;n++){const r=this._headers[n],o=r.value;if(!o)continue;const s={min:r.min,max:r.max};void 0!==o.sz&&o.sz!==e&&(s.sz=_t.roundAccurately(o.sz,8),void 0!==o.csz&&(s.csz=o.csz)),!0===o.h&&(s.h=o.h),Object.keys(s).length>2&&t.headers.push(s)}return n.endPersist(),t}}class lw{constructor(t,e,n){this._c=t,this._tvTl=e,this._rsTl=n}tvTl(){return this._tvTl(this._c)}rsTl(){return this._rsTl(this._c)}getCoords(){return this._c}}const cw=t=>{let e="";const n=Ku,r=t.length;for(let o=0;o<r;o++){const r=t[o];if("cell"===r.type){e+=n(r.value)}else{e+=r.value}}return e},hw=(t,e=0,n=0)=>{let r="";const o=Yu,s=t.length;for(let i=0;i<s;i++){const s=t[i];if("cell"===s.type){r+=o(s.value,e,n)}else{r+=s.value}}return r};class uw{constructor(t,e,n){this._c=t,this._tokens=e,this._references=n||_t.EmptyArray}getFormulaTextAt(t,e,n=!1){return n?cw(this._tokens):hw(this._tokens,t,e)}getTokensAt(t,e,n){let r=this._tokens;return void 0!==n&&(r=((t,e)=>{const n=t.length,r=[];if(void 0===e)return _t.EmptyArray;let o=-1,s=!1;for(let i=0;!s&&i<n;i++){const n=t[i],a=n.evalIndex??Number.MAX_SAFE_INTEGER;if(-1===o){if(a!==e)continue;o=i}a>e?s=!0:r.push(n)}s=!1;for(let n=o-1;!s&&n>=0;n--){const o=t[n];(o.evalIndex??Number.MAX_SAFE_INTEGER)>e?s=!0:r.unshift(o)}return r.length>1&&"whitespace"===r[0].type&&r.shift(),r.length>1&&"whitespace"===r[r.length-1].type&&r.pop(),r})(r,n)),r=((t,e=0,n=0)=>{const r=t.length,o=new Array(r);for(let s=0;s<r;s++){const r=t[s];if("cell"!==r.type){o[s]=r;continue}const i={...r},a={...i.value};i.value=a,o[s]=i,a.colIndex===Number.MIN_SAFE_INTEGER||a.$colIndex||(a.colIndex+=n),a.rowIndex===Number.MIN_SAFE_INTEGER||a.$rowIndex||(a.rowIndex+=e)}return o})(r,t,e),r}getReferencesAt(t,e){return((t,e=0,n=0)=>{const o=t.length,s=new Array(o);for(let i=0;i<o;i++){const o=t[i];if("string"==typeof o||o instanceof r.Known){s[i]=o;continue}const a={...o};s[i]=a,a.colStart===Number.MIN_SAFE_INTEGER||a.$colStart||(a.colStart+=n),a.rowStart===Number.MIN_SAFE_INTEGER||a.$rowStart||(a.rowStart+=e),a.colEnd===Number.MIN_SAFE_INTEGER||a.$colEnd||(a.colEnd+=n),a.rowEnd===Number.MIN_SAFE_INTEGER||a.$rowEnd||(a.rowEnd+=e)}return s})(this._references,t,e)}toJSON(){const t=this._c;return[Au(t),this.getFormulaTextAt(t.rowStart,t.colStart)]}getCoords(){return this._c}}class dw{constructor(t,e,n){this.groupId=t,this.uuid=e,this.noShift=n}onRemove(t){}getShifted(t){if(!t.after)return null;const e=this.noShift;return e?void 0:{...t.after,value:new dw(this.groupId,this.uuid,e)}}getSplit(t,e){}copyTo(t,e){return new dw(this.groupId,this.uuid,this.noShift)}canTile(t,e){return!1}}class gw{constructor(t,e,n,r,o,s,i,a,l,c){this.uuid=t,this.spatialsIds=e,this.isRanges=r,this.coords=n,this.sheet=o,this.generation=s,this.handler=i,this.handlerW=a,this.removeListener=l,this.options=c}delete(){this.removeListener()}createRangeEvent(t,e){const n=this;let r;const o=()=>{if(r)return r;const t=n.sheet,o=n.isRanges,s=n.coords;return e||!s||0===s.length?Vf(t,t.getEntireRange().getCoords(),null,e):o?(r=t.getRanges(n.coords),r):(r=t.getRange(n.coords[0]),r)},s=t.trigger;return{getSource:o,trigger:s,isTransactional:t.isTransactional??!0,toString:()=>`SheetRangeEvent: ('${s}', ${o().toString()})`,timeStamp:t.timeStamp??Date.now()}}notify(t,e){const n=this.createRangeEvent(t,e),r=this.handler??this.handlerW.deref();try{r?.(n)}catch(t){console.warn(t)}this.options?.once&&this.removeListener()}processRemove(t){const e=this.spatialsIds,n=e.indexOf(t.value.uuid);console.assert(-1!==n,"invalid uuid");const r=this.coords,o=r.slice(0,n).concat(r.slice(n+1)),s=e.slice(0,n).concat(e.slice(n+1));return new gw(this.uuid,s,o,this.isRanges,this.sheet,this.generation,this.handler,this.handlerW,this.removeListener,this.options)}processShift(t){const e=this.spatialsIds.indexOf(t.value.uuid);console.assert(-1!==e,"invalid uuid");const n=[...this.coords];return n[e]={...n[e],...W.sanitizeRange(t)},new gw(this.uuid,this.spatialsIds,n,this.isRanges,this.sheet,this.generation,this.handler,this.handlerW,this.removeListener,this.options)}processSplit(t){}processMerge(t){}}const mw=Object.freeze({coords:W.EmptyCell,topLeft:x.EmptyTopLeft}),fw=Object.freeze({cell:W.EmptyCell,ranges:_t.EmptyArray,rangeIndex:0}),pw=Object.freeze({selection:fw,topLeft:x.EmptyTopLeft,freezePanes:mw,showRowHeaders:!0,showColumnHeaders:!0,showRowGridlines:!0,showColumnGridlines:!0,rowHeaderStyle:hS.HeaderTextStyle.One,columnHeaderStyle:hS.HeaderTextStyle.A1,showFormulas:!1,showZeros:!0,zoomScale:100,gridLineColor:null});class _w{constructor(t){if(this._emitter=null,!t?.sheet)throw new Error("SheetView requires a sheet.");const e=new Ll(this);this._emitter=e,this._sheet=t.sheet,this.clear(!1),t.json&&this._fromJSON(t.json)}addListeners(t,e){return this._emitter.addListeners(t,e)}setTopLeft(t){return this._state.topLeft=Object.freeze({left:t?.left??this._state.topLeft.left,top:t?.top??this._state.topLeft.top}),this._emitter.notify("onTopLeftChange"),this}getTopLeft(){return this._state.topLeft}getFreezePanes(){return this._state.freezePanes}setFreezePanes(t){return this._state.freezePanes=this._mergeFreezePanes(t),this._emitter.notify("onFreezeSplitChange"),this}_mergeFreezePanes(t){return t?{...this._state.freezePanes,coords:{colIndex:t?.coords?.colIndex??this._state.freezePanes.coords.colIndex,rowIndex:t?.coords?.rowIndex??this._state.freezePanes.coords.rowIndex},topLeft:{left:t?.topLeft?.left??this._state.topLeft.left,top:t?.topLeft?.top??this._state.topLeft.top}}:mw}isShowRowHeaders(){return this._state.showRowHeaders}setShowRowHeaders(t){return this._state.showRowHeaders=t,this._notifyAll(),this}isShowColumnHeaders(){return this._state.showColumnHeaders}setShowColumnHeaders(t){return this._state.showColumnHeaders=t,this._notifyAll(),this}isShowRowGridlines(){return this._state.showRowGridlines}setShowRowGridlines(t){return this._state.showRowGridlines=t,this._notifyAll(),this}isShowColumnGridlines(){return this._state.showColumnGridlines}setShowColumnGridlines(t){return this._state.showColumnGridlines=t,this._notifyAll(),this}getRowHeaderStyle(){return this._state.rowHeaderStyle}setRowHeaderStyle(t){return this._state.rowHeaderStyle=t,this._notifyAll(),this}getColumnHeaderStyle(){return this._state.columnHeaderStyle}setColumnHeaderStyle(t){return this._state.columnHeaderStyle=t,this._notifyAll(),this}getZoomScale(){return this._state.zoomScale}setZoomScale(t){return this._state.zoomScale=t,this._notifyAll(),this}isShowFormulas(){return this._state.showFormulas}setShowFormulas(t){return this._state.showFormulas=t,this._notifyAll(),this}isShowZeros(){return this._state.showZeros}setShowZeros(t){return this._state.showZeros=t,this._notifyAll(),this}getGridLineColor(){return this._state.gridLineColor}setGridLineColor(t){return this._state.gridLineColor=t,this._notifyAll(),this}setRangeSelection(t){return this._state.selection=t,this._emitter.notify("onRangeSelectionChange"),this}getRangeSelection(){return this._state.selection}getMovableSelection(){return this._movableSelection}setMovableSelection(t){const e=this._movableSelection;return this._movableSelection=Object.freeze(t??[]),_t.isEqualArrays(e,this._movableSelection)||this._emitter.notify("onMovableSelectionChange"),this}selectMovables(t,e=!1){const n=new Set(this._sheet.getMovables().search());let r=null,o=!1;if(e){r=[...this._movableSelection];for(let e=t.length-1;e>=0;e--){const s=t[e];let i=r.indexOf(s);if(i!==e){if(o=!0,!n.has(s))throw new Error(`Movable ${s.getName()} not found in sheet.`);-1!==i&&r.splice(i,1),r.unshift(s)}}}else o=!_t.isEqualArrays(t,this._movableSelection),r=[...t];o&&(this._movableSelection=r,this._emitter.notify("onRangeSelectionChange"),this._emitter.notify("onMovableSelectionChange"))}unselectMovables(t){const e=this._movableSelection,n=[];for(let r=0;r<e.length;r++){const o=e[r];-1===t.indexOf(o)&&n.push(o)}return e.length!==n.length&&(this._movableSelection=n,this._emitter.notify("onRangeSelectionChange"),this._emitter.notify("onMovableSelectionChange")),this}_notifyAll(){const t=this._emitter;t.notify("onRangeSelectionChange"),t.notify("onTopLeftChange"),t.notify("onFreezeSplitChange"),t.notify("onAnyChange")}toJSON(){const t={},e=Object.keys(this._state);for(let n=0;n<e.length;n++){const r=this._state[e[n]];null!=r&&r!==pw[e[n]]&&(t[e[n]]=r)}delete t.movableSelection,delete t.gridLineColor,this._state.gridLineColor instanceof Da&&(t.gridLineColor=this._state.gridLineColor.toString()),delete t.topLeft,!this._state.topLeft||0===this._state.topLeft.left&&0===this._state.topLeft.top||(t.topLeft={left:this._state.topLeft.left??0,top:this._state.topLeft.top??0}),delete t.selection;const n=this._state.selection;if(n){let e={};!n.cell||0===n.cell.colIndex&&0===n.cell.rowIndex||(e.cell=vu(n.cell)),n.ranges&&n.ranges.length>0&&(e.ranges=Ou(n.ranges),void 0!==n.rangeIndex&&-1!==n.rangeIndex&&0!==n.rangeIndex&&(e.rangeIndex=n.rangeIndex)),Object.keys(e).length>0&&(t.selection=e)}if(delete t.freezePanes,this._state.freezePanes&&(0!==this._state.freezePanes.coords.colIndex||0!==this._state.freezePanes.coords.rowIndex)){const e={};0!==this._state.freezePanes.coords.colIndex&&(e.c=this._state.freezePanes.coords.colIndex),0!==this._state.freezePanes.coords.rowIndex&&(e.r=this._state.freezePanes.coords.rowIndex),0!==this._state.freezePanes.topLeft.left&&(e.x=this._state.freezePanes.topLeft.left),0!==this._state.freezePanes.topLeft.top&&(e.y=this._state.freezePanes.topLeft.top),t.freezePanes=e}return 0===Object.keys(t).length?null:t}_fromJSON(t){let e=JSON.parse(JSON.stringify(t||{}));e?.zoomScale&&(e.zoomScale=_t.roundAccurately(parseFloat(t.zoomScale),2));const n=t=>{const n=this._sheet.getRange(t).getBounds(),r=(e.zoomScale??100)/100;return{x:n.x*r,y:n.y*r,width:n.width*r,height:n.height*r}};if("string"==typeof e?.gridLineColor&&(this._sheet?.getStyles()?e.gridLineColor=this._sheet.getStyles().parseColor(t.gridLineColor):console.warn("Style was created with no styles so gridLineColor can't be parsed.")),e.topLeft)if("string"==typeof e.topLeft){const t=n(zu(e.topLeft));e.topLeft={left:t.x,top:t.y}}else e.topLeft=Object.freeze({left:e.topLeft?.left??e?.x??0,top:e.topLeft?.top??e?.y??0});if(e.selection){let t=zu(e.selection.cell??"A1");if(e.selection.cell=t,e.selection.ranges){let n=Math.max(0,Math.min(e.selection.rangeIndex??e.selection.ranges?.length-1,e.selection.ranges?.length-1));e.selection.rangeIndex=n;let r=!1;for(let o=0;o<e.selection.ranges.length;o++){const s=Vu(e.selection.ranges[o]);e.selection.ranges[o]=s,o===n&&t&&!W.isCellWithinRange(t,s)&&(r=!0)}if(r)for(let n=0;r&&n<e.selection.ranges.length;n++)W.isCellWithinRange(t,e.selection.ranges[n])&&(r=!1,e.selection.rangeIndex=n);r&&(e.selection.ranges.push(W.cellToRange(t)),e.selection.rangeIndex=e.selection.ranges.length-1)}else delete e.selection.rangeIndex}if(e.freezePanes){const t=e.freezePanes;if("string"==typeof t.coords&&(t.coords=zu(t.coords)),"string"==typeof t.topLeft){const r=zu(t.topLeft),o=n({colIndex:r.colIndex+1,rowIndex:r.rowIndex+1}),s=n({colIndex:(t?.coords?.colIndex??-1)+1,rowIndex:(t?.coords?.rowIndex??-1)+1});t.topLeft={left:0,top:0},e.topLeft||(e.topLeft={top:0,left:0}),r.colIndex>0&&(t.topLeft.left=e.topLeft?.left??0,e.topLeft.left=o.x-s.x+t.topLeft.left),r.rowIndex>0&&(t.topLeft.top=e.topLeft?.top??0,e.topLeft.top=o.y-s.y+t.topLeft.top)}e.freezePanes={coords:{colIndex:t?.coords?.colIndex??e.freezePanes?.c??0,rowIndex:t?.coords?.rowIndex??e.freezePanes?.r??0},topLeft:{left:t?.topLeft?.left??e.freezePanes?.x??0,top:t?.topLeft?.top??e.freezePanes?.y??0}}}this.update(e)}clear(t=!0){return this._state={...pw},this._movableSelection=Object.freeze([]),t&&this._notifyAll(),this}update(t){return this._state={...pw,...this._state,...t},this._state.freezePanes=this._mergeFreezePanes(this._state.freezePanes),this._state.zoomScale=Math.min(400,Math.max(10,this._state.zoomScale)),this._notifyAll(),this}get isISheetView(){return!0}}async function Sw(){const{getCrypto:t}=await import("./9jeiH8SVL_ZJYLxo.mjs");return t()}const ww=async(t,e,...n)=>{const r=yw(...n);return t.subtle.digest(e,r)},yw=(...t)=>{const e=t.reduce((t,e)=>t+e.byteLength,0),n=new Uint8Array(e);let r=0;return t.forEach(t=>{n.set(new Uint8Array(t),r),r+=t.byteLength}),n.buffer},Ew=t=>{const e=new Uint8Array(t);let n="";for(let t=0;t<e.byteLength;t++)n+=String.fromCharCode(e[t]);return btoa(n)};class bw{static{this.DefaultAlgo="SHA-512"}static{this.DefaultSpinCount=1e5}static async generateSaltAndHash(t,e=bw.DefaultAlgo,n=bw.DefaultSpinCount){if(!t)return null;const r=(await Sw()).getRandomValues(new Uint8Array(16)),o=Ew(r.buffer);return{salt:o,hash:await bw._convertPasswordToHash(t,o,e,n)}}static async verifyPassword(t,e,n=bw.DefaultAlgo,r=bw.DefaultSpinCount){if(!t||!e)throw new Lt;return((t,e)=>{const n=t.length,r=e.length;let o=n===r?0:1;for(let s=0;s<Math.max(n,r);s++)o|=t.charCodeAt(s%n)^e.charCodeAt(s%r);return 0===o})(await bw._convertPasswordToHash(t,e.salt,n,r),e.hash)}static async _convertPasswordToHash(t,e,n,r){const o=await Sw();n=n.toUpperCase();const s=(t=>{const e=new ArrayBuffer(2*t.length),n=new DataView(e);for(let e=0;e<t.length;e++)n.setUint16(2*e,t.charCodeAt(e),!0);return new Uint8Array(e)})(t),i=(t=>{const e=atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n.buffer})(e);let a=await ww(o,n,i,s.buffer);for(let t=0;t<r;t++){const e=new Uint32Array([t]).buffer;a=await ww(o,n,a,e)}return Ew(a)}}class vw{constructor(t,e=!1){this._emitter=null,this._emitter=new Ll(this),this.fromJSON(t),this._isReadOnly=e}async lock(t,e,n,r){if(this._isReadOnly)return this;if(this.isLocked()&&!this._isPaused)throw new Error("Cannot lock an already locked object. Use unlock first.");try{this._validatePassword()}catch(t){throw new Error("A password is already set. Unlock first to change.")}let o;if(e){const t=await bw.generateSaltAndHash(e,n,r);o={salt:t.salt,hash:t.hash},n&&(o.algorithm=n),r&&(o.spinCount=r)}else o=null;return t=t??{},this._updateProperties(t),this._properties=t,this._password=o,this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),this}async unlock(t){if(this._isReadOnly)throw new Error("Cannot unlock a readonly workbook.");return await this._validatePassword(t),this._clearProperties(),this._password=null,this._identities=null,this._password=null,this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),this}checkPassword(t){return this._validatePassword(t)}hasPassword(){return null!==this._password}async pause(t){return this._emitter.notify("onLockChange"),this._emitter.notify("onChange"),await this._validatePassword(t),this._password&&(this._isPaused=!0),this}resume(){return this._isPaused=!1,this}isPaused(){return this._isPaused}isLocked(){return null!==this._properties&&!this._isPaused}isReadOnly(){return this._isReadOnly}async _validatePassword(t){const e=this._password;if(!(t&&0!==t.length||e&&e.hash))return!0;if(!t)throw new Error("Password is required.");if(!await bw.verifyPassword(t,{salt:e.salt,hash:e.hash},e.algorithm,e.spinCount))throw new Error("Invalid password.");return!0}getProperties(){return this._properties}_isPropertyAllowed(t){if(this._isReadOnly)return!1;if(!this.isLocked())return!0;const e=this._properties[t];return"boolean"==typeof e&&e}_updateProperties(t){this._properties={...t,...this._properties??{}}}_clearProperties(){this._properties=null}addListeners(t,e){return this._emitter.addListeners(t,e)}fromJSON(t){this._password=null,this._identities=null,this._isPaused=!1,this._properties=null,this._fromJSON(t??null),t&&(t.password&&(this._password=t.password),t.identities&&(this._identities=t.identities))}_fromJSON(t){}_toJSON(t){return t}toJSON(){if(!this._properties)return null;let t={};return t=this._toJSON(t)??{},this._password&&(t.password=this._password),this._identities&&(t.identities=this._identities),t}}const Cw=Object.freeze({selectLockedCells:!0,selectUnlockedCells:!0,autoFilter:!1,deleteColumns:!1,deleteRows:!1,formatCells:!1,formatColumns:!1,formatRows:!1,insertColumns:!1,insertHyperlinks:!1,insertRows:!1,objects:!1,pivotTables:!1,scenarios:!1,sheet:!1,sort:!1,verifier:null});class xw extends vw{isAutoFilterAllowed(){return this._isPropertyAllowed("autoFilter")}isDeleteColumnsAllowed(){return this._isPropertyAllowed("deleteColumns")}isDeleteRowsAllowed(){return this._isPropertyAllowed("deleteRows")}isFormatCellsAllowed(){return this._isPropertyAllowed("formatCells")}isFormatColumnsAllowed(){return this._isPropertyAllowed("formatColumns")}isFormatRowsAllowed(){return this._isPropertyAllowed("formatRows")}isInsertColumnsAllowed(){return this._isPropertyAllowed("insertColumns")}isInsertHyperlinksAllowed(){return this._isPropertyAllowed("insertHyperlinks")}isInsertRowsAllowed(){return this._isPropertyAllowed("insertRows")}isObjectsAllowed(){return this._isPropertyAllowed("objects")}isPivotTablesAllowed(){return this._isPropertyAllowed("pivotTables")}isScenariosAllowed(){return this._isPropertyAllowed("scenarios")}isSortAllowed(){return this._isPropertyAllowed("sort")}isSelectLockedCellsAllowed(){return!1}isSelectUnlockedCellsAllowed(){return!1}_updateProperties(t){super._updateProperties(t),this._properties=t}_clearProperties(){super._clearProperties(),this._properties=null}_fromJSON(t){super._fromJSON(t),this._properties=t}_toJSON(t){let e=this._properties;if(e){t={...t,...e};const n=Object.keys(e);for(let r=0;r<n.length;r++){const o=e[n[r]];null!=o&&o!==Cw[n[r]]&&(t[n[r]]=o)}}return super._toJSON(t)}}class Iw{constructor(t,e,n){this._coords=Object.freeze(t),this._sheet=e,this._readOnly=n?.readOnly??null}_createRanges(t,e){let n=this._options;return e&&(n={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Iw(t,this._sheet,n)}_createRange(t,e){let n=this._options;return e&&(n={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Aw(t,this._sheet,n)}_validateWrite(){const t=this._readOnly;if(t)throw new Error(t)}getCoords(){return this._coords}[Symbol.iterator](){const t=this.entries({excludeCellDetails:!0});return{next(){const e=t.next();return e.done?Ul:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}entries(t){const e=this.getCoords(),n=t?.reverse??!1;let r=n?e.length-1:0;const o=this;let s=o._createRange(e[r]),i=s.entries(t),a=i.next();return{next(){let l=a;do{if(a.done){if(r=n?r-1:r+1,r>=e.length||r<0)return a=Ul,l;s=o._createRange(e[r]),i=s.entries(t)}a=i.next()}while(a.done);return l},[Symbol.iterator](){return this}}}async select(t){const e=await this._sheet._autoSelect(t??!0,rp(this.getCoords()));return this._createRanges(e)}calculate(){const t=this.getCoords();return this._sheet._calculate(t),this}addListener2(t,e){return this._sheet._addRangesListeners2(this.getCoords(),t,e,!0)}addListener(t,e){return this._sheet._addRangesListeners(this.getCoords(),t,e)}find(t,e){return this._sheet._find(this.getCoords(),t,e)}getFlattened(t){const n=this.getCoords();if(1===n.length)return this._createRanges(n,t);const r=t?.orientations??e.Orientations.Both,o=r===e.Orientations.Both,s=o?Number.MAX_SAFE_INTEGER:1,i=r===e.Orientations.Row?e.Orientation.Column:e.Orientation.Row;let a=Vc(n,s,i);if(o){const t=Vc(n,s,e.Orientation.Column);t.length<a.length&&(a=t)}return this._createRanges(a,t)}getVisible(t){const e=this._sheet._getVisible(this.getCoords(),t);return e&&0!==e.length?this._createRanges(e,t):null}getFixed(t){const e=[],n=this.getCoords();for(let r=0;r<n.length;r++)e.push(Xf(n[r],t));return this._createRanges(e,t)}autoFit(t){return this._validateWrite(),this._sheet._autoFit(this.getCoords(),t),this}clear(t,e){return this._validateWrite(),this._sheet._clear(this.getCoords(),t,e),this}updateStyle(t,e){return this._validateWrite(),this._sheet._updateStyles(this.getCoords(),t,e),this}getStyleUpdater(){return this._sheet._getStyleUpdater(this.getCoords())}merge(t){return this._validateWrite(),this._sheet._merge(this.getCoords(),t),this}unmerge(t){return this._validateWrite(),this._sheet._unmerge(this.getCoords(),t),this}getMerges(){return this._sheet._getMerges(this.getCoords(),this._options?.excludeHidden??!1)}insert(t,e){return this._validateWrite(),this._sheet._insertCells(this.getCoords(),t,e),this}delete(t,e){return this._validateWrite(),this._sheet._deleteCells(this.getCoords(),t,e),this}async insertFrom(t,e){this._validateWrite();const n=await this._sheet._insertFrom(this.getCoords(),t,e);return n?this._createRanges([n]):null}async copyFrom(t,e){const n=await this._sheet._copyFrom(this.getCoords()[0],t,e);return n?this._createRanges([n]):null}isInvalidAny(){const t=this.getCoords();if(!t||0===t.length)return!0;for(let e=0;e<t.length;e++)if(null===t[e])return!0;return!1}getSnapshot(t){return this._sheet._getSnapshot(this.getCoords(),t)}getEntireRows(t,n){return this._createRanges(Mf(this.getCoords(),this._sheet._entireCoords,e.Orientation.Column,t),n)}getEntireColumns(t,n){return this._createRanges(Mf(this.getCoords(),this._sheet._entireCoords,e.Orientation.Row,t),n)}getDefaultShiftOrientation(){return this._sheet._getDefaultShiftOrientation(this.getCoords()[0])}getCount(){return this.getCoords()?.length??0}getCounts(t){return this._sheet._contentCounts(this.getCoords(),t,this._options?.excludeHidden??!1)}isContentful(){return this._sheet._isContentful(this.getCoords(),this._options?.excludeHidden??!1)}getRowCount(){return Ff(this.getCoords(),e.Orientation.Row)}getColumnCount(){return Ff(this.getCoords(),e.Orientation.Column)}isEntireRowsAny(){return Tf(this.getCoords(),this._sheet._entireCoords,!1)}isEntireColumnsAny(){return Nf(this.getCoords(),this._sheet._entireCoords,!1)}isEntireRows(){return Tf(this.getCoords(),this._sheet._entireCoords,!0)}isEntireColumns(){return Nf(this.getCoords(),this._sheet._entireCoords,!0)}isOverlapping(){return Bh(this.getCoords())}at(t){const e=this.getCoords();if(t<0||t>e.length-1)throw new kt;return this._createRange(e[t])}isReadOnly(){return null!==this._readOnly}isInvalid(){return!1}getA1(){return Lu(this.getCoords(),this._sheet._entireCoords,Mu,Cu)}getSource(){return this._sheet}doBatch(t,e){return this._sheet.doBatch(e=>t(e),"string"==typeof e?e:{description:"Ranges Update",...e})}get[Symbol.toStringTag](){return"[SheetRanges]"}toString(){return this.getA1()}get isICellRanges(){return!0}}class Aw{constructor(t,e,n){this._coords=Object.freeze(t),this._sheet=e,this._readOnly=n?.readOnly??null}getCoords(){return this._coords}_createRange(t,e){const n=this._sheet;if(!t)return Vf(n,n._entireCoords);if(n._validateCoords(t),n._closed)return Vf(null,n._entireCoords,t);let r=this._options;return e&&(r={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Aw(t,this._sheet,r)}_createRanges(t,e){let n=this._options;return e&&(n={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Iw(t,this._sheet,n)}_deriveRanges(t,e){const n=this.getCoords();let r=n;return e&&(r=e(n),!r)?null:this._createRanges(r,t)}_deriveRange(t,e,n){if(!t)return this;let r=this._sheet._rangeToCoords(t);if(!r)return this;const o=this.getCoords();if(Jf(r,o))return this;if(n){const t=n(r,o);if(!t)return this;r={...o,...t}}var s,i;return s=r,(i=o)&&(void 0===i.$colStart?delete s.$colStart:s.$colStart=i.$colStart,void 0===i.$rowStart?delete s.$rowStart:s.$rowStart=i.$rowStart,void 0===i.$colEnd?delete s.$colEnd:s.$colEnd=i.$colEnd,void 0===i.$rowEnd?delete s.$rowEnd:s.$rowEnd=i.$rowEnd),this._createRange(r,Yf(this._options?.getOptions,e))}_validateMaxSize(t=5e4){const e=this.getCoords(),n=this._sheet,r=n._colHeaders.getVisibleCount(e.colStart,e.colEnd);if(n._rowHeaders.getVisibleCount(e.rowStart,e.rowEnd)*r>t)throw new Error(Td(t))}[Symbol.iterator](){const t=this.entries({excludeCellDetails:!0});return{next(){const e=t.next();return e.done?Ul:{done:!1,value:e.value.value}},[Symbol.iterator](){return this}}}entries(t){const e=this.getCoords();let n=e;const r=this._sheet;if(t?.address){const o=r._rangeToCoords(t?.address);if(!o)throw new Error(rd(t?.address));if(n=W.intersectRanges(o,e),!n)return Gl}n.colEnd<n.colStart&&(n.colStart=e.colStart,n.colEnd=e.colEnd),n.rowEnd<n.rowStart&&(n.rowStart=e.rowStart,n.rowEnd=e.rowEnd);const o=this._options?.excludeHidden??!1;return r._cellIterator({excludeHidden:o,...t,includeRangeTypes:!t?.excludeCellDetails,bounds:n})}forEach(t,e){if(!t)return;const n=this.entries(e);let r=n.next();for(;!r.done;){const e=r.value,o=t(e.value,e.context);if(o)return o.break;r=n.next()}}_validateWrite(){const t=this._readOnly;if(t)throw new Error(t)}updateCells(t,n,r){this._validateWrite();const o=this.getCoords();r||(r=o);const s=this._sheet,i=s._isDataColumn,a={majorStart:i?o.colStart:o.rowStart,majorEnd:i?o.colEnd:o.rowEnd,minorStart:i?o.rowStart:o.colStart,minorEnd:i?o.rowEnd:o.colEnd},l=(n?.orientation??e.Orientation.Row)===e.Orientation.Column!==i,c=sh(Array.isArray(t)?t:[[t]],l,a);return s._updateTuples(c,{description:n?.description??`Set ${W.isSingleCell(r)?"Cell":"Range"} ${Mu(r,s._entireCoords)}`,...n},null,{isCell:!0}),this}setValue(t,e){if(Array.isArray(t))throw new Error("'setValue' expects a single value; when working with an array use 'setValue'.");return this._setValueOrValues(t,e)}setValues(t,e){if(!Array.isArray(t))throw new Error("'setValues' expects a 2d array; when working with a single value use 'setValue'.");return this._setValueOrValues(t,e)}_setValueOrValues(t,n){this._validateWrite();let r=this.getCoords(),o=this;const s=this._sheet,i=s._isDataColumn,a=(n?.orientation??e.Orientation.Row)===e.Orientation.Column,l=Array.isArray(t);if(n?.skipBoundsCheck&&l){const e=t;let s=Math.max(0,e.length-1),i=0;for(let t=0;t<e.length;t++)i=Math.max(i,e[t].length-1);const l=a?r.colStart:r.rowStart,c=a?r.rowStart:r.colStart,h={...r,colEnd:a?l+s:c+i,rowEnd:a?c+i:l+s};W.isEqualRanges(h,r)||(r=h,o=this._deriveRange(h,n))}const c={majorStart:i?r.colStart:r.rowStart,majorEnd:i?r.colEnd:r.rowEnd,minorStart:i?r.rowStart:r.colStart,minorEnd:i?r.rowEnd:r.colEnd},h=a!==i;let u=null;return u=l?sh(Array.isArray(t)?t:[[t]],h,c):oh(t,c,i),s._updateTuples(u,{description:n?.description??`Set ${W.isSingleCell(r)?"Value":"Values"} ${Mu(r,s._entireCoords)}`,...n}),o}getValues(t){this._validateMaxSize(t?.maxSize);const e=this.getCoords(),n=this._sheet;return qf(n._cellIterator.bind(this._sheet),e,!1,t)}getValue(t){const e=this.getCoords();return this._sheet._getScalar(e.rowStart,e.colStart,t?.asJSDate)}calculate(t){return this._sheet._calculate([this.getCoords()],{full:t}),this}getCells(t){this._validateMaxSize(t?.maxSize);const e=this.getCoords(),n=this._sheet;return qf(n._cellIterator.bind(this._sheet),e,!0,t)}getCell(){const t=this.getCoords(),e=this._sheet,n=qf(e._cellIterator.bind(this._sheet),{colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colStart,rowEnd:t.rowStart},!0,null);return 0===n.length?e._emptyCell:n[0][0]}async select(t){const e=this._sheet,n=await e._autoSelect(t??!0,rp([this.getCoords()]));return this._createRange(n[0])}find(t,e){return this._sheet._find([this.getCoords()],t,e)}getFixed(t){return this._createRange(Xf(this.getCoords(),t))}getSurrounding(t){const e=this._sheet;return this._createRange(e._surroundingRegion(this.getCoords(),t))}getExtended(t,n){let r=null;const o=this.getCoords();switch(t){case e.Direction.Up:r={colIndex:o.colStart,rowIndex:o.rowStart};break;case e.Direction.Down:r={colIndex:o.colStart,rowIndex:o.rowEnd};break;case e.Direction.Left:r={colIndex:o.colStart,rowIndex:o.rowStart};break;case e.Direction.Right:r={colIndex:o.colEnd,rowIndex:o.rowStart}}const s=this._sheet,i=n?s._cellToCoords(n):r;if(!W.isCellWithinRange(i,o))throw new Error("Invalid cell.");let a=s._extendRange(t,i);return a=W.unionRanges(o,a),this._createRange(a)}getEntireRows(t,n){const r=this._sheet;return this._createRange(Mf([this.getCoords()],r._entireCoords,e.Orientation.Column,t)[0],n)}getEntireColumns(t,n){const r=this._sheet;return this._createRange(Mf([this.getCoords()],r._entireCoords,e.Orientation.Row,t)[0],n)}getRowHeaders(t){const e=this.getCoords();return this._sheet._rowHeaders.getRange(e,t)}getColumnHeaders(t){const e=this.getCoords();return this._sheet._colHeaders.getRange(e,t)}getDifferences(t,n){return this._deriveRanges(n,r=>{const o=this._sheet,s=o._rangeToCoords(t),i=zh(r,s,e.Orientation.Row);return o._getVisible(i,n)})}getIntersect(t,e){return this._deriveRange(t,e,(t,e)=>W.intersectRanges(t,e))}getUnion(t,e){return this._deriveRange(t,e,(t,e)=>W.unionRanges(t,e))}getResizeTo(t,e,n){if(e=e??0,(t=t??0)<0||e<0)throw new Error("Invalid range. The Range must be at a size of at least 1x1'.");const r=this.getCoords();return this._deriveRange({colStart:r.colStart,rowStart:r.rowStart,colEnd:e+r.colStart-1,rowEnd:t+r.rowStart-1},n)}getResizeBy(t,e,n){t=t??0,e=e??0;const r=this.getCoords();return this._deriveRange({colStart:r.colStart,rowStart:r.rowStart,colEnd:r.colEnd+e,rowEnd:r.rowEnd+t},n)}getOffsetTo(t,e,n){const r=this.getCoords(),o=e,s=t,i={colStart:o,rowStart:s,colEnd:r.colEnd-r.colStart+o,rowEnd:r.rowEnd-r.rowStart+s};return this._deriveRange(i,n)}getOffsetBy(t,e,n){const r=this.getCoords(),o=r.colStart+t,s=r.rowStart+e,i={colStart:o,rowStart:s,colEnd:r.colEnd-r.colStart+o,rowEnd:r.rowEnd-r.rowStart+s};return this._deriveRange(i,n)}getUsedRange(t){const e=this._sheet._getUsedCoords(t);if(!e)return null;const n=W.intersectRanges(e,this.getCoords());return n?this._deriveRange(n,t):null}isEmpty(){const t=this._sheet._getUsedCoords();if(!t)return!0;return!W.intersectRanges(t,this.getCoords())}getColumnStart(){return this.getCoords().colStart}getRowStart(){return this.getCoords().rowStart}getColumnEnd(){return this.getCoords().colEnd}getRowEnd(){return this.getCoords().rowEnd}getColumnCount(){const t=this.getCoords();return t.colEnd-t.colStart+1}getRowCount(){const t=this.getCoords();return t.rowEnd-t.rowStart+1}getVisible(t){return this._deriveRanges(t,e=>this._sheet._getVisible([e],t))}isContentful(t){return this._sheet._isContentful([this.getCoords()],t,this._options?.excludeHidden??!1)}getCounts(t){return this._sheet._contentCounts([this.getCoords()],t,this._options?.excludeHidden??!1)}getCount(t){return this._sheet._getCount([this.getCoords()],t,this._options?.excludeHidden??!1)}isEntireRows(){const t=this._sheet;return Tf([this.getCoords()],t._entireCoords,!0)}isEntireColumns(){const t=this._sheet;return Nf([this.getCoords()],t._entireCoords,!0)}isEntireRange(){const t=this.getCoords(),e=this._sheet;return Nf([t],e._entireCoords,!0)&&Tf([t],e._entireCoords,!0)}getWidth(){const t=this._coords;return t.colEnd-t.colStart+1}getHeight(){const t=this._coords;return t.rowEnd-t.rowStart+1}get size(){const t=this._coords;return t.colEnd-t.colStart+1*(t.rowEnd-t.rowStart+1)}getBounds(){return this._sheet._getBoundsAtCoords(this.getCoords())}isInvalid(){return!1}getDefaultShiftOrientation(){return this._sheet._getDefaultShiftOrientation(this.getCoords())}getDefaultSortCriteria(t,e){return this._sheet._getDefaultSortCriteria(this.getCoords(),t,e)}getMerges(){return this._sheet._getMerges([this.getCoords()],this._options?.excludeHidden??!1)}getSnapshot(t){return this._sheet._getSnapshot([this.getCoords()],t)}isReadOnly(){return null!==this._readOnly}addListener2(t,e){return this._sheet._addRangesListeners2([this.getCoords()],t,e,!1)}addListener(t,e){return this._sheet._addRangesListeners([this.getCoords()],t,e)}getSource(){return this._sheet}autoFill(t,e){this._validateWrite();const n=this._sheet,r=n._rangeToCoords(t,()=>[],!0);return n._autoFill(this.getCoords(),r,e)?this._createRange(r):this}autoFit(t){this._validateWrite();return this._sheet._autoFit([this.getCoords()],t),this}clear(t,e){this._validateWrite();return this._sheet._clear([this.getCoords()],t,e),this}setHyperlink(t,e){this._validateWrite();return this._sheet._setHyperlinks([this.getCoords()],t,e),this}setComments(t,e){this._validateWrite();return this._sheet._setComments([this.getCoords()],t,e),this}setFormula(t,e){this._validateWrite();return this._sheet._setFormula([this.getCoords()],t,e),this}updateStyle(t,e){this._validateWrite();return this._sheet._updateStyles([this.getCoords()],t,e),this}getStyleUpdater(){return this._sheet._getStyleUpdater([this.getCoords()])}merge(t){this._validateWrite();return this._sheet._merge([this.getCoords()],t),this}unmerge(t){this._validateWrite();return this._sheet._unmerge([this.getCoords()],t),this}insert(t,e){this._validateWrite();return this._sheet._insertCells([this.getCoords()],t,e),this}async insertFrom(t,e){this._validateWrite();const n=this._sheet,r=await n._insertFrom([this.getCoords()],t,e);return r?this._createRange(r):null}async copyFrom(t,e){this._validateWrite();const n=this._sheet,r=await n._copyFrom(this.getCoords(),t,e);return r?this._createRange(r):null}delete(t,e){this._validateWrite();return this._sheet._deleteCells([this.getCoords()],t,e),this}sort(t){this._validateWrite();const e=this.getCoords(),n=this._sheet._sort(e,t);return W.isEqualRanges(n,e)?this:this._createRange(n)}doBatch(t,e){return this._sheet.doBatch(e=>t(e),"string"==typeof e?e:{description:"Range Update",...e})}startIncrementalUpdates(t){return this._sheet._createIncrementalUpdater(t,this)}getA1(){const t=this._sheet;return Mu(this.getCoords(),t._entireCoords)}get[Symbol.toStringTag](){return"[SheetRange]"}toString(){const t=this._sheet;return Mu(this.getCoords(),t._entireCoords)}get isICellRange(){return!0}}const Rw=Math.pow(2,14),Mw=Math.pow(2,20),Tw=t=>`${t}`,Nw=t=>Eu(t),Fw=t=>`${t+1}`;let kw=0;const Ow=()=>[];let Lw=0;class Dw{constructor(t){this._lastTransactionUUID=null,this._emitter=null,this._initializing=!0,this._emitterMovables=null,this._rangesListenerSorted=null,this._lastCellDecoded={address:null,coords:null},this._lastCellSelected={coords:null,cell:null},this._lastCellRead={coords:null,cell:null},this._lastValueRead={range:null,isDateOrTime:null},this._lastGetRangeRead={},this._lastUsedCoordsRead={coords:null,range:null},this._lastActiveRead={selection:null,range:null,ranges:null},this._lastRangeRead={address:null,range:null,ranges:null},this._isDataColumn=!0,this._isDate1904=!1,this._colHeaders=null,this._colHeadersShiftCallback=null,this._colHeadersListener=null,this._colHeadersRemoveListener=null,this._rowHeaders=null,this._rowHeadersShiftCallback=null,this._rowHeadersListener=null,this._rowHeadersRemoveListener=null,this._closed=!1;const e=Object.freeze({...t});Ie._validate(!0),this._transactions=e.transactions??new ie,this._ownTransactions=!e.transactions;const n=this._beginCommit({description:"New Sheet"}),r=this;try{this._entireCoords=Object.freeze({colStart:0,rowStart:0,colEnd:(e.maxColumns??Rw)-1,rowEnd:(e.maxRows??Mw)-1}),this._strings=e.strings??new Pp,this._ownStrings=!e.strings;const t=e.styles??new Fp;this._styles=t,this._ownStyles=!e.styles,this._names=e.names??new TS({addressToRanges:t=>r.getRanges(t),getCurrentScope:()=>r.getName(),isReadOnly:()=>r._options.readonly??!1,transactions:r._transactions}),this._ownNames=!e.names,this._namesRemoveListener=this._names.addListeners({onCollectionChange:t=>{r._calculateFull()}},{transactional:!1}),this._calculation=e.calculation??new nS({getNamed:(t,e)=>{Bw.address=t,Bw.scope=e;const n=this._names.search({address:t,scope:e});return n&&0!==n.length?n[0].getRanges().getCoords():null},getSheetIndex:t=>void 0===t||t===r.getName()?1:0,getSheetCount:()=>1,isDate1904:()=>r.isDate1904(),strings:r._strings,transactions:r._transactions}),this._ownsCalculation=!e.calculation,this._normalStyleRanged=t.getNamed(rl.BuiltInName.Normal).getRanged(),this._resources=e.resources??new Bp,this._ownResources=!e.resources;const o=async()=>{this._ownsCalculation&&await this._calculation.start(),this._starting=null};this._starting=o(),e.container?.setNameChangeCallback&&e.container.setNameChangeCallback(()=>{r._emitter.notify("onNameChange");const t=this._getState().rangesListenerMap,e=new Map;t.forEach((t,n)=>{e.set(n,{beforeState:t,afterState:t})});const n=this._beginCommit({description:"Set Name"});n.updateState(r,{}),n.commit({viewAfter:{ranges:[r._entireCoords],listeners:e},forceAmend:!0}),r._calculateFull()}),e.container?.setVisibilityCallback&&e.container.setVisibilityCallback(()=>{r._emitter.notify("onVisibilityChange")}),e.container?.setIndexCallback&&e.container.setIndexCallback(()=>{r._calculateFull()}),this._movables=new ES(this._addMovable.bind(this),this._searchMovables.bind(this),()=>{const t=r._getState();return t?t.movableMapModel?.size??0:0},this._updateSelectedMovables.bind(this),(t,e)=>this._emitterMovables.addListeners(t,e),this._addImage.bind(this)),this._emitterMovables=new Ll(this._movables,this._transactions),this._tables=new LS(this._addTable.bind(this),(t,e,n)=>{const o=t?this._rangeToCoords(t):this._entireCoords;return r._getRangedEntries("tableSpatial",[o],{excludeHidden:e,fullyContained:n,onEntry:t=>t.model})},t=>{const e=r._getState();return e?e.tableMapName.get(t.toLocaleLowerCase()):null}),this._conditionals=new US(this._addConditional.bind(this),(t,e,n)=>{const o=t?this._rangeToCoords(t):this._entireCoords,s=new Set;return r._getRangedEntries("conditionalSpatial",[o],{excludeHidden:e,fullyContained:n,onEntry:t=>{s.add(t.getModel())}}),Array.from(s)}),this._isDate1904=e.date1904??!1,this._options=e,this._emitter=new Ll(this,this._transactions),this._entireRange=this.getRange(this._entireCoords),this._initState(),e?.container?.beforeFromJSON?.(this),e.json&&this._fromJSON(e.json),n.commit({viewAfter:{initial:!0,skipProtectionCheck:!0}})}catch(t){throw n.rollback(),t}this._initializing=!1}_createRange(t,e,n=null){if(!t)return Vf(this,this._entireCoords);if(this._validateCoords(t),this._closed)return Vf(null,this._entireCoords,t);null===n&&this._options.readonly&&(n="Readonly sheet");let r=null;return(e||n)&&(r={getOptions:e,readOnly:n}),new Aw((t=>{if(!t)return null;const e={colStart:t.colIndex??t.colStart??0,rowStart:t.rowIndex??t.rowStart??0,colEnd:t.colIndex??t.colEnd??0,rowEnd:t.rowIndex??t.rowEnd??0};return(t.$colStart||t.$colIndex)&&(e.$colStart=!0),(t.$colEnd||t.$colIndex)&&(e.$colEnd=!0),(t.$rowStart||t.$rowIndex)&&(e.$rowStart=!0),(t.$rowEnd||t.$rowIndex)&&(e.$rowEnd=!0),e})(t),this,r)}_createRanges(t,e,n=null){let r=null;return null===n&&this._options.readonly&&(n="Readonly sheet"),(e||n)&&(r={getOptions:e,readOnly:n}),new Iw(t,this,r)}getRange(t,e){let n=!e&&t&&(void 0!==t.rowStart||"string"==typeof t);if(n)if("string"==typeof t){if(this._lastRangeRead.address===t)return this._lastRangeRead.range}else if(void 0!==t.rowStart&&Jf(t,this._lastRangeRead.address))return this._lastRangeRead.range;const r=this._rangesToCoords(t);if(r.length>1)throw new Error(ed);const o=this._createRange(r[0],e);return n&&(this._lastRangeRead.address={...t},this._lastRangeRead.range=o),o}getRanges(t,e){if(!t)throw new Error(td);const n=this._rangesToCoords(t);if(0===n.length)throw this._createRangeError(t);return this._createRanges(n,e)}getSelectedRange(t){const e=this.getSelection().getCoords();if(!t&&this._lastActiveRead.selection===e&&this._lastActiveRead.range)return this._lastActiveRead.range;const n=np(e),r=this.getRange(n[0]);return t||(this._lastActiveRead.selection=e,this._lastActiveRead.range=r,this._lastActiveRead.ranges=this.getRanges(n)),r}getSelectedRanges(t){const e=this.getSelection().getCoords();if(!t&&this._lastActiveRead.selection===e&&this._lastActiveRead.ranges)return this._lastActiveRead.ranges;const n=np(e),r=this.getRanges(n,t);return t||(this._lastActiveRead.selection=e,this._lastActiveRead.ranges=r,this._lastActiveRead.range=this.getRange(n[0])),r}getEntireRange(t){if(!t)return this._entireRange;return this.getRange(this._entireCoords,t)}getUsedRange(t){const e=this._getUsedCoords(),n=e?this.getRange(e,t):null;return t||(this._lastUsedCoordsRead.coords=e,this._lastUsedCoordsRead.range=n),n}_cellToCoords(t){if(this._lastCellDecoded.address===t)return this._lastCellDecoded.coords;const e=this._rangeToCoords(t);if(!e||!W.isSingleCell(e))throw new Error("Only a single cell is allowed.");const n={colIndex:e.colStart,rowIndex:e.rowStart};return this._lastCellDecoded.address=t,this._lastCellDecoded.coords=n,n}_validateCoords(t,e=wd){if(!W.isRangeWithinRange(t,this._entireCoords))throw new kt(e);const n=t.colStart,r=t.rowStart,o=t.colEnd,s=t.rowEnd;if(s<r||o<n)throw new Error(nd);if(!(Number.isInteger(n)&&Number.isFinite(n)&&Number.isInteger(r)&&Number.isFinite(r)&&Number.isInteger(o)&&Number.isFinite(o)&&Number.isInteger(s)&&Number.isFinite(s)))throw new Error("Invalid range. All points must be valid integers.")}_createRangeError(t){return t?new Error(td):new Error(rd(t))}_protectionCheck(t=null,e=null,n=null){if(t&&this._closed)return;if(!this._initializing&&this._options.readonly)throw new Error(((t="update")=>`Unable to ${t}, this sheet is readonly.`)(n));e&&!Array.isArray(e)&&(e=[e]);const r=t(e),o=this.getProtection(),s=o?.getProperties();if(s){if(0===r.length)throw new Error(_d);if(r){const t=r.length;for(let e=0;e<t;e++){if(!0!==o[r[e]])throw new Error(Sd())}}}}_rangesToCoords(t,e=null,n=!0,r=!1){if(e&&this._closed)return _t.EmptyArray;if(null==t)return _t.EmptyArray;const o=this,s=Bu(t,this._entireCoords,r?Fu:ku,t=>{if(n&&"string"==typeof t){const e=o.getNames()?.getByName(t);if(e)return e.getRanges().getCoords();const n=this._options.resolveRange?.(t);if(n&&n.getSource()===o)return console.warn(Md),[n.getCoords()];throw new Error(`Invalid sheet reference '${t}'.`)}}),i=s.length;for(let t=0;t<i;t++){const e=s[t];if(e){if(r){const t=e.sheetName;if(t&&t!==this.getName())throw new Error(Md)}this._validateCoords(e)}}if(!e)return s;if(0===s.length)throw this._createRangeError(t);return this._protectionCheck(e,s),s}_rangeToCoords(t,e=null,n=!0){if(!t)throw new Error(td);const r=e?t=>e(t):void 0,o=this._rangesToCoords(t,r,n);if(0===o.length)throw new Error(rd(t));return o[0]}_collectRanges(t,e=[],n=!0,r=this._getState(),o=!1){if(!n||0===Object.keys(n).length)return;const s=t=>!0===n||void 0!==n[t],i=(r,o,s)=>{if(!0!==n&&void 0===n[r])return;const i=o.search(t,!1),a=i.length;if(0===a)return;const l=n[r];for(let n=0;n<a;n++){const r=i[n];if(l&&!W.isRangeWithinRange(t,r))continue;const o=W.intersectRanges(t,r);let a=r.value;void 0===a&&(a=!0),e.push({...o,value:{[s]:a}})}};if(s(dd.Type.Merge)&&r.mergeSpatial){const n=r.mergeSpatial.search(t),s=n.length;for(let r=0;r<s;r++){const s=n[r],i=o?s:W.intersectRanges(t,s);e.push({...i,value:{merge:s.value}})}}if(i(dd.Type.Unlock,r.unlockSpatial,"unlock"),i(dd.Type.Contentful,r.contentfulSpatial,"contentful"),i(dd.Type.Continuous,r.continuousFillSpatial,"continuous"),i(dd.Type.Hyperlink,r.hyperlinkSpatial,"hyperlink"),i(dd.Type.Comments,r.commentsSpatial,"comments"),i(dd.Type.Style,r.directStyleSpatial,"directStyle"),i(dd.Type.Formula,r.formulaSpatial,"formula"),i(dd.Type.Pending,r.pendingSpatial,"pending"),i(dd.Type.CalcError,r.calcErrorsSpatial,"calcError"),i(dd.Type.Spill,r.spillSpatial,"spills"),s(dd.Type.Conditional)&&r.conditionalSpatial){const o=r.conditionalSpatial.search(t),s=n[dd.Type.Conditional],i=o.length;for(let n=0;n<i;n++){const r=o[n],i=W.intersectRanges(t,r);s&&!i||e.push({...i,value:{conditionals:[r.value]}})}}if(s(dd.Type.Table)&&r.tableSpatial){const o=r.tableSpatial.search(t),s=n[dd.Type.Table],i=o.length;for(let n=0;n<i;n++){const r=o[n];if(s&&!W.isRangeWithinRange(t,r))continue;const i=W.intersectRanges(t,r);e.push({...i,value:{table:r.value.model}})}}}_cellIterator(t){const e=this._cellOptions,n=this._strings,r=this._cellStateIterator(t);return{next(o){const s=r.next(o);if(s.done)return Ul;const i=s.value,a=new Kf(n,t,e),l=a.context;return{done:!1,value:{value:a.setState(i),context:l}}},[Symbol.iterator](){return this}}}_rangeStateIterator(t){const n=this._getState();if(!n||!t||!t.includeRangeTypes)return Gl;const r=t?.bounds??this._getUsedCoords()??this._entireCoords;let o=null;!0===t.includeRangeTypes?o=gd:_t.isObject(t.includeRangeTypes)&&(o=t.includeRangeTypes);const s=t?.excludeHidden,i=!0===s||s===e.Orientation.Row,a=!0===s||s===e.Orientation.Column,l=[],c=this,h={includeHidden:!a},u={min:r.colStart,max:r.colEnd},d={includeHidden:!i},g={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(g).forEachVisibleSpan((t,e)=>{this._colHeaders.getRange(u).forEachVisibleSpan((r,s)=>{c._collectRanges({rowStart:t,rowEnd:e,colStart:r,colEnd:s},l,o,n)},h)},d);const m=new Ql.IteratorInstance(l,t),f=t?.reverse??!1,p=t?.byCell;let _;const S={next:t=>{if(_=m.next(t),_.done)return Ul;const e=_.value,n=e.range,r={colIndex:n.colStart,rowIndex:n.rowStart},o={colIndex:n.colEnd,rowIndex:n.rowEnd};let s=null;p&&(s={...e.cell});const i=(t=>{if(!t)return null;let e=null;const n=t.length;for(let r=0;r<n;r++){const n=t[r].value;if(!n)continue;e||(e={...e});const o=Object.keys(n),s=o.length;for(let t=0;t<s;t++){const r=o[t],s=e[r];if(s)if(Array.isArray(s)){const t=n[r];if(Array.isArray(t)){const e=t.length;for(let n=0;n<e;n++)s.push(t[n])}else s.push(t)}else e[r]=[s,n[r]];else e[r]=n[r]}}return e})(e.overlaps);return{done:!1,value:{start:f?o:r,end:f?r:o,cell:s,intersection:i}}}};return S}_cellStateIterator(t){const n=this._getState();if(!n)return Gl;const r=t?.bounds??this._entireCoords,o=t?.orientation??e.Orientation.Row,s=t?.reverse??!1,i=t?.includeEmpty,a={bounds:r,orientation:o,reverse:s};let l;i&&(l={bounds:r,orientation:o,reverse:s});const c=t?.excludeHidden;if(!0===c||c===e.Orientation.Row){const t=Wf(this._rowHeaders);a.processRowSkip=$l(t),i&&(l.processRowSkip=$l(t))}if(!0===c||c===e.Orientation.Column){const t=Wf(this._colHeaders);a.processColumnSkip=$l(t),i&&(l.processRowSkip=$l(t))}const h=i||!t?.ignoreEmptyIntersections;let u=t.includeRangeTypes;!0===u&&(u=md);const d=this._getState().contentfulSpatial,g=u?this._rangeStateIterator({bounds:r,orientation:o,reverse:s,includeRangeTypes:u,excludeHidden:t.excludeHidden,byCell:!0}):Gl,m=t?.includeMergeOverflow??!1,f=n?.cellValuesGrid??null;let p=f?f.entries(a):Gl,_=p.next(),S=null,w=null,y=null;_.done||(S=_.value[0],w=_.value[1]);let E=g.next(),b=null;const v=o!==e.Orientation.Row;let C;const x=W.createCellComparator(o,s);let I;if(!E.done){const t=E.value;I=t.start,b=t.intersection}C=t=>{let e=null,n=null,r=null,o=!1,s=!1;if(S&&I){const t=x(S,I);t<0?(e=S,n=w,o=!0):t>0?(e=I,r=b,s=!0):(e=S,n=w,r=b,o=!0,s=!0)}else if(S)e=S,n=w,o=!0;else{if(!I||!h)return Ul;e=I,r=b,s=!0}if(o&&(_=p.next(),_.done?S=null:(S=_.value[0],w=_.value[1])),s){const t=h?void 0:S;if(E=g.next(t),E.done)I=null,b=null;else{const t=E.value;I=t.cell,b=t.intersection}}let i=!1;const a=e.rowIndex,l=e.colIndex;v||(i=a===y?.rowIndex);let c=!1;v||(c=a===S?.rowIndex);let u=null;if(i)u=y;else if(m&&!y){Jw.rowStart=a,Jw.rowEnd=a,Jw.colStart=l-5,Jw.colEnd=l-1;const t=d.search(Jw,!1);if(t.length>0){t.sort(W.columnFirstRangeComparator);const e=t[t.length-1];u={colIndex:e.colStart,rowIndex:e.rowStart}}}let f=null;if(c)f=S;else if(m&&!S){Jw.colStart=l+1,Jw.rowStart=a,Jw.colEnd=l+5,Jw.rowEnd=a;const t=d.search(Jw,!1);if(t.length>0){t.sort(W.columnFirstRangeComparator);const e=t[0];f={colIndex:e.colStart,rowIndex:e.rowStart}}}return o&&(y=e),{done:!1,value:[e,n,r,u,f]}};let A={next:C,return:t=>null,throw:t=>null};return i&&(A=new th(A,a)),A}_indexMerges(t,e=null){if(!(t&&0!==t.length||e&&0!==e.length))return;const n=this._getState();if(!n)return;const r=this._beginCommit({description:"indexMerges"}),o=n.mergeSpatial.clone();if(e){const t=e.length;for(let n=0;n<t;n++)o.remove(e[n])}if(t){const e=pd,n=t=>this._getState().cellValuesGrid.getValueAt(t.rowStart,t.colStart),r=t=>{const n=this._getState();if(!n)return;const r=[];this._collectRanges(t,r,e,n);return{...r?.[0]??null}},s=[],i=t.length;for(let e=0;e<i;e++){const o=t[e];s.push({...o,value:new lw(o,n,r)})}o.load(s)}this._updateState({mergeSpatial:o}),r.commit()}_updateStyles(t,e,n,r=!1){const o=n?.description??"Update Style";this._protectionCheck(()=>["formatCells"],t,o);const s=this._beginCommit({description:o}),i=ep(t);try{const o=this._getState();if(!o)return _t.EmptyArray;const a=o.directStyleSpatial,l=s.getId(),c=a.clone(l);let h=o.continuousFillSpatial;const u=!h.isEmpty();let d=null;const g=this._styles,m=t.length;for(let n=0;n<m;n++){const o=(t,e)=>{let n=null;const r=$m(0,e,()=>{if(n)return n;const e=t.getCoords();return n=rf(g,t,e),n});return t.cloneWithUpdate(r)},s=t[n],i=s.value,a=void 0!==i?i:e,l=o(new af(g,s),a),h=(t,e)=>{if(r&&t.value&&t.value.getProperties()?.numberFormat)return t;const n=W.sanitizeRange(t);let s=null,i=t.value;"function"==typeof a&&i?s=o(i,a):(i||(i=new af(g,n)),s=i.cloneWithUpdate(e.value._p??null)),s.isEmpty()&&(s=null);let l=!1;if(s){const t=s._p?.alignment?.horizontal;!t||t!==zs.HorizontalAlignment.CenterContinuous&&t!==zs.HorizontalAlignment.Fill||(l=!0)}return(l||u)&&(d||(d=[]),d.push({...t,value:l?s:null})),{...e,value:s}};c.insertNonOverlapping({...s,value:l},{onIntersect:h})}if(d){h=h.clone();const t=d.length;for(let e=0;e<t;e++){const t=d[e];h.insertNonOverlapping(t)}}if(this._lastUsedCoordsRead.coords=null,this._updateState({directStyleSpatial:c,continuousFillSpatial:h}),n?.autoFit){const e="boolean"==typeof n.autoFit?qw:n.autoFit;this._autoFit(t,e)}this._emitter.notify("onStyleChange"),r?s.commit({forceAmend:!0}):this._commitAndAutoSelect(s,i,n?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw s.rollback(),t}}_createIncrementalUpdater(t,n=null,r){const o=t?.orientation??e.Orientation.Row,s=t?.allowUnorderedWrites??!1,i=o===e.Orientation.Column,a=this._isDataColumn,l=i!==a,c=this;let h,u,d,g=l?new Ke.TransposedBuilder:new Ke.Builder,m=null;if(n){const t=n.getCoords(),e=t.colStart,r=t.rowStart,o=t.colEnd,s=t.rowEnd;m=(t,n)=>{if(t<r||t>s||n<e||n>o)throw new kt}}i?(u=(t,e,n)=>(m?.(t,e),g.addValue(e,t,n),h),d=(t,e,n)=>(m?.(t,e+(n?.length??0)),g.addValues(e,t,n),h)):(u=(t,e,n)=>(m?.(t,e),g.addValue(t,e,n),h),d=(t,e,n)=>(m?.(t+(n?.length??0),e),g.addValues(t,e,n),h));const f=t=>{const e=g.build();return e&&c._updateTuples(e,t,null,r),n},p=!1!==s?W.createCellComparator(t?.orientation):null,_=_t.isObject(s)?s:void 0;let S=null;return h=Object.freeze({push:(t,e)=>{const n=c._cellToCoords(t);return p&&(S&&p(n,S)<=0&&(f(_),g=l?new Ke.TransposedBuilder:new Ke.Builder),S=n),u(i?n.colIndex:n.rowIndex,i?n.rowIndex:n.colIndex,e)},pushAt:u,pushMultipleAt:d,apply:f}),h}_updateTuples(t,n,r=void 0,o=null){if(!t)return;const s=o?.isCell??!1,i=o?.isHyperlink??!1,a=t.tuples,l=t.bounds,c=this._beginCommit({description:n?.description??"Update Cells"});let h=null;const u=this._isDataColumn,d=u?e.Orientation.Column:e.Orientation.Row,g=this.getProtection().isLocked(),m=this.getProtection().isFormatCellsAllowed(),f=this._strings,p=l.majorStart,_=l.majorEnd,S=l.minorStart,w=l.minorEnd,y={colStart:u?p:S,rowStart:u?S:p,colEnd:u?_:w,rowEnd:u?w:_},E=this;(r=r??((t,e)=>{E._validateCoords(t,e??wd)}))(y);const b={[dd.Type.Style]:!1,[dd.Type.Table]:!1};let v=!1;g&&this._hasRangedEntries("unlockSpatial",y)&&(b[dd.Type.Unlock]=!1,v=!0),this._hasRangedEntries("mergeSpatial",y)&&(b[dd.Type.Merge]=!1,v=!0);const C=this._rangeStateIterator({bounds:y,orientation:d,includeRangeTypes:b,reuseIterator:{done:!1,value:null}});let x=C.next(),I=-1,A=-1,R=-1,M=-1,T=null;if(!x.done){const t=x.value,e=t.start,n=t.end;I=u?e.colIndex:e.rowIndex,A=u?n.colIndex:n.rowIndex,R=u?e.rowIndex:e.colIndex,M=u?n.rowIndex:n.colIndex,T=t.intersection}let N=(t,e)=>{do{if(!T||t<=R&&e<R)return null;if(t>=I&&e>=R&&t<=A&&e<=M)return T;if(x=C.next(),x.done)T=null,N=null,v=!1;else{const t=x.value;I=u?t.start.colIndex:t.start.rowIndex,A=u?t.end.colIndex:t.end.rowIndex,R=u?t.start.rowIndex:t.start.colIndex,M=u?t.end.rowIndex:t.end.colIndex,T=t.intersection}}while(T);return T};const F=c.getState(this),k=F.cellValuesGrid.clone(),O=F.calcGraph.clone(),L=F.formulaSpatial.clone(),D=F.spillSpatial.clone(),B=F.pendingSpatial.clone(),z=F.calcErrorsSpatial.clone(),P=F.contentfulSpatial.clone(),j=ch(u),H=ch(u,(t,e)=>{if(t===e)return e}),V=ch(u,(t,e)=>{if(t===e)return e}),$=ch(u,(t,e)=>{if(t===e)return e}),U=[];let G=null,W=null;if(!1!==n?.textParser){const t=n&&!0!==n.textParser?n.textParser:{};W={ignoreQuotePrefix:!1,date1904:this._isDate1904,dateNF:!1,parse:null,...t},G=new Kf(f,null,this._cellOptions)}const q=[],J=this._cellOptions,X=new Map,K=Qf,Y=(t,e,n)=>{const r=N?.(e,n);if(r?.merge){const t=r.merge.getCoords(),o=u?t.colStart:t.rowStart,s=u?t.rowStart:t.colStart;if(o!==e||s!==n)return}if(s&&t&&t.isICell){const r=t;if(r.isTopLeft()){const t=r.getSpans();U.push({colStart:u?e:n,rowStart:u?n:e,colEnd:(u?e:n)+t.width-1,rowEnd:(u?n:e)+t.height-1})}}let o=mf(t,J,W,X);if(void 0===o)return;const a=o.value;if(o.stringToParse){Uw[0].colIndex=u?e:n,Uw[0].rowIndex=u?n:e,Uw[1]=a,Uw[2]=r,G.setState(Uw);const t=W?.parse(o.stringToParse,G.context),s=mf(t,J,W,X,!0);if(G.clear(),null===s)return s;void 0!==s&&(o={...s})}if(g){if(g&&(null===t||void 0!==o.value))throw new Error(_d);if(!m&&void 0!==o.style)throw new Error(_d)}if(!i){const t=o.style;void 0===t||null===t&&!s||H.append(e,n,t);const r=o.hyperlink;void 0===r||null===r&&!s||V.append(e,n,r)}const l=o.formula;return void 0===l||null===l&&!s||$.append(e,n,l),a};let Z=-1,Q=-1;try{const t=a.length;for(let e=0;e<t;e++){const t=a[e],n=t[0];if(Z>=n)throw new Ke.OutOfOrderError(`Duplicate or out of order major indices: {${n}}.`);if(Z=n,Q=Number.MIN_SAFE_INTEGER,n<p||n>_)throw new kt("Provided major bounds is invalid");const r=t[1],o=[],i=r.length;for(let t=0;t<i;t++){const e=r[t],i=e[1],a=i.length;let l=e[0],c=l;if(Q>c)throw new Ke.OutOfOrderError(`Duplicate or out of order minor indices: {${c}}.`);if(c<S||c+a>w+1)throw new kt("Provided minor bounds is invalid");let h=[];for(let t=0;t<a;t++){const e=i[t];let r=null;if(v||"number"!=typeof e?(v||null!==e||s)&&(r=Y(e,n,c)):r=e,null==r){if(null===r&&j.append(n,c),h.length>0){const t=K(h,f);o.push([l,t]),h=[]}l=c+1}else h.push(r);c++}if(Q=c,h.length>0){const t=K(h,f);o.push([l,t]),h=null}}o.length>0&&q.push([n,o])}const r=j.done(),o=r.length;for(let t=0;t<o;t++){const e=r[t];k.delete(r[t]),P.insertNonOverlapping({...e,value:null});const n=O.delete(e);this._updateFormulaSpatial(L,null,n)}let i;q.length>0&&(k.setValues(q),i={tuples:q,bounds:l});let d,g=$.done();if(g.length>1&&(g=Hc(g,e.Orientation.Column,1)),i||g.length>0){const t=O.setInputs(i,g);d=this._updateFormulaSpatial(L,t.inserts,t.removes,F.directStyleSpatial)}const m=tp(q,u),E=m.length;for(let t=0;t<E;t++)P.insertNonOverlapping(m[t]);const b=H.done();b.length>0&&this._updateStyles(b),U.length>0&&this._merge(U);const C=V.done();if(C.length>0&&this._setHyperlinks(C),this._updateState({cellValuesGrid:k,contentfulSpatial:P,calcGraph:O,formulaSpatial:L,spillSpatial:D,pendingSpatial:B,calcErrorsSpatial:z}),d&&d.length>0&&this._updateStyles(d,void 0,{},!0),n?.autoFit){const t="boolean"==typeof n.autoFit?qw:n.autoFit;this._autoFit([y],t)}h={ranges:[y]},this._addEvent("data",y),this._commitAndAutoSelect(c,h,n?.autoSelect,{viewAfter:{formulas:[y],ranges:[y]}})}catch(t){throw c.rollback(),t}}_sort(t,n){"boolean"==typeof n&&(n={reverse:n});const r=n?.description??"Sort "+(n?.reverse?"Descending":"Ascending");this._protectionCheck(()=>["sort"],t,r);let o=1,s=1,i=!1;const a=this._getMerges([t]);if(a.length>0){i=!0;let e=a[0];if(o=e.colEnd-e.colStart+1,s=e.rowEnd-e.rowStart+1,(t.colEnd-t.colStart+1)%o!=0||(t.rowEnd-t.rowStart+1)%s!=0)throw new Error(Id);const n=a.length;for(let t=1;t<n;t++){const e=a[t];if(e.colEnd-e.colStart+1!==o||e.rowEnd-e.rowStart+1!==s)throw new Error(Id)}}const l=n?.orientation??e.Orientation.Row,c=l===e.Orientation.Row;let h=n?.offset??0,u=t;n?.hasHeader&&(u={...u},c?u.rowStart+=s:u.colStart+=o,h=Math.max(h-1,0));const d={offset:h,reverse:n?.reverse??Pl.DefaultRangeOptions.reverse,collatorOptions:n?.collatorOptions??Pl.DefaultRangeOptions.collatorOptions},g=c?u.colStart:u.rowStart,m=c?u.colEnd-u.colStart:u.rowEnd-u.rowStart,f=[];if(n?.fields){const t=n?.fields.length??0;for(let e=0;e<t;e++){let t=n.fields[e];"number"==typeof t&&(t={offset:t}),f.push(t)}}else f.push(d);const p=f.length;for(let t=0;t<p;t++){const e=f[t]={...d,...f[t]};if(e.offset<0||e.offset>m)throw new kt("The sort offset is outside of the bounds of the sort.");e.offset+=g}const _=[];let S=null,w=null,y=null,E=Number.MIN_SAFE_INTEGER;f.sort((t,e)=>t.offset-e.offset);let b=null;const v=n?.includeHidden??!1;if(!v){const t=Wf(c?this._rowHeaders:this._colHeaders);b=$l(t)}const C=this._cellIterator({bounds:u,orientation:l,excludeHidden:!v&&l,includeRangeTypes:{[dd.Type.Style]:!1,[dd.Type.Merge]:!1}}),x=c?s:o;let I=(c?u.rowStart:u.colStart)-x,A=C.next();for(;!A.done;){const t=A.value.context,e=t.getCell();if(i&&!e.isTopLeft()){A=C.next();continue}const n=t.getCoords(),r=c?n.rowIndex:n.colIndex,o=c?n.colIndex:n.rowIndex;if(I!==r){for(I+=x,b&&(I=b(I));I<r;)_.push(null),I+=x;w=[],y=[],S={minorIndex:r,values:w,sortValues:y},_.push(S),I=r,E=f[0].offset}for(;o>E;){const t=f[y.length];E=t?t.offset:Number.MAX_SAFE_INTEGER,o>E&&y.push(null)}o===E&&y.push(e),w.push(e),A=C.next()}if(!S)return;if(0===_.length)return;const R=new Map,M=new Map,T=n?.collators??Pl.DefaultCollators,N=T.length;for(let t=0;t<N;t++)R.set(T[t].type,T[t].compare),M.set(T[t].type,t);let F=null,k=null,O=null;_.sort((t,e)=>{const n=f.length;for(let r=0;r<n;r++){const n=f[r],o=t?t.sortValues[r]:null,s=e?e.sortValues[r]:null,i=o?o.getValue():null,a=s?s.getValue():null,l=null===i,c=null===a;if(i===a)continue;if(l&&c)return 0;if(!l&&c)return-1;if(l&&!c)return 1;const h=o.getType(),u=s.getType();let d=0;if(h!==u){let t=M.get(h);d=M.get(u)-t}else{let t=k;if(F!==h){t=R.get(h),k=t,F=h;let e=M.get(u);const r=T[e].defaultOptions;O={...r,...n.collatorOptions}}d=t(i,a,O)}return n.reverse&&(d*=-1),d}return 0});const L=this._beginCommit({description:r});let D=[u];v||(D=this._getVisible(D,{orientations:c?e.Orientations.Row:e.Orientations.Column})),this._clear(D,void 0,void 0,!0);const B=this._createIncrementalUpdater({orientation:l});let z=c?u.rowStart:u.colStart;const P=_.length;for(let t=0;t<P;t++){const e=_[t];if(b&&(z=b(z)),e){const t=e.values,n=t.length;for(let e=0;e<n;e++){const n=t[e],r=c?z:n.getCoords().rowIndex,o=c?n.getCoords().colIndex:z;B.pushAt(r,o,n)}}z+=x}return B.apply(),L.commit(),u}_autoFill(t,n,r){const{direction:o,amount:s}=((t,n)=>{let r=e.Direction.Down,o=0;const s={...t};if(n.colStart<t.colStart?(r=e.Direction.Left,o=t.colStart-n.colStart,s.colStart=n.colStart):n.colEnd>t.colEnd?(r=e.Direction.Right,o=n.colEnd-t.colEnd,s.colEnd=n.colEnd):n.rowStart<t.rowStart?(r=e.Direction.Up,o=t.rowStart-n.rowStart,s.rowStart=n.rowStart):n.rowEnd>t.rowEnd&&(r=e.Direction.Down,o=n.rowEnd-t.rowEnd,s.rowEnd=n.rowEnd),!W.isEqualRanges(s,n))throw new Error("Autofill destination must be the same as the range for 3 of the 4 edges.");return{direction:r,amount:o}})(t,n);if(s<=0)return!1;const i=o===e.Direction.Up||o===e.Direction.Down,a=this.getSelection().getCoords(),l=[],c=r?.previewOnly,h=r?.contentsOnly,u=r?.filler??Sa.Types.Series,d={...r?.fillerOptions};let g=null,m=null;try{const f={...t};let p={...t};const _=[t],S=this._getMerges(_);if(S.length>0&&!W.isRangeWithinRange(W.unionRangesArrays(S),t))throw new Error(xd);const w={...p};let y=1;if(o===e.Direction.Left)f.colStart=p.colStart=t.colStart-s,f.colEnd=t.colStart-1,y=0===S.length?y:t.colEnd+1-t.colStart,w.rowStart=w.rowEnd;else if(o===e.Direction.Right)f.colEnd=p.colEnd=t.colEnd+s,f.colStart=t.colEnd+1,y=0===S.length?y:t.colEnd+1-t.colStart,w.rowStart=w.rowEnd;else if(o===e.Direction.Up)f.rowStart=p.rowStart=t.rowStart-s,f.rowEnd=t.rowStart-1,y=0===S.length?y:t.rowEnd+1-t.rowStart,w.colStart=w.colEnd;else{if(o!==e.Direction.Down)throw new Error(St.MESSAGE_ERROR_INVALID_ARG(o));f.rowEnd=p.rowEnd=t.rowEnd+s,f.rowStart=t.rowEnd+1,y=0===S.length?y:t.rowEnd+1-t.rowStart,w.colStart=w.colEnd}if(s%y!==0)throw new Error((t=>`When filling with merged cells the amount to fill must be a multiple of the input range [${t}].`)(y));const E=i?"rowIndex":"colIndex",b=i?"colIndex":"rowIndex",v=i?t.rowEnd+1-t.rowStart:t.colEnd+1-t.colStart,C=i?t.rowStart:t.colStart,x=i?t.rowEnd:t.colEnd,I=i?n.rowStart:n.colStart,A=i?n.rowEnd:n.colEnd,R=i?o===e.Direction.Down:o===e.Direction.Right;R||(d.reverse=!0);const M=R?x+1:I,T=(R?A:C-1)-M+1,N=i?t.colEnd:t.rowEnd;l.push(W.unionRanges(f,t));const F=[];let k=null;c||(g=this._beginCommit({description:"Auto Fill",operation:{name:"autoFill",params:[t,n,r]}}));const O=this._cellIterator({bounds:c?w:t,reverse:!R,orientation:i?e.Orientation.Column:e.Orientation.Row,includeRangeTypes:{[dd.Type.Style]:!1}});let L=O.next();for(;!L.done;){const t=L.value.context,e=t.getCell(),n=t.getCoords();k?.oppositeIndex!==n[b]&&(k={oppositeIndex:n[b],lastIndex:R?C-1:x+1,values:[]},F.push(k));const r=n[E];if(R)for(let t=k.lastIndex+1;t<r;t++)k.values.push(null);else for(let t=k.lastIndex-1;t>r;t--)k.values.push(null);k.lastIndex=r;const o=e.toDate();if(o)k.values.push(o);else{let t=e.getValue();k.values.push(t)}L=O.next()}const D=F.length;for(let t=0;t<D;t++){const e=F[t].values;for(let t=e.length;t<v;t++)e.push(null)}const B=(t,e)=>{if(t.canFill(e[0],[])){const n=t.createFillAt(e,d);if(n)return n}return Sa.Types.Copy.createFillAt(e)},z=this;if(c){const t=F[F.length-1];if(F[F.length-1]?.oppositeIndex!==N)return null;const n=B(u,t.values);return c(t=>{const r=z._rangeToCoords(t);let s;o===e.Direction.Down||o===e.Direction.Right?s={rowIndex:r.rowEnd,colIndex:r.colEnd}:o===e.Direction.Left?s={rowIndex:r.rowEnd,colIndex:r.colStart}:o===e.Direction.Up&&(s={rowIndex:r.rowStart,colIndex:r.colEnd});const a=i?s.rowIndex:s.colIndex,l={value:n(R?a-C:C-a+v-1)};let c=null;return c=h?this.createTemporaryCell(l,s):this.createTemporaryCell(null,s).createTemporaryCell(l),c}),!1}const P=this._createIncrementalUpdater({orientation:i?e.Orientation.Column:e.Orientation.Row}),j=F.length;F.sort((t,e)=>t.oppositeIndex-e.oppositeIndex);for(let t=0;t<j;t++){const e=t,n=B(u,F[e].values),r=F[e].oppositeIndex,o=R?v:v+T-1,s=this.isDate1904();for(let t=0;t<T;t++){let e=n(o+(R?t:-t));ms(e)&&(e=Es(e,s));const a=M+t;i?P.pushAt(a,r,e):P.pushAt(r,a,e)}}this._clear([f],r?.contentsOnly?Gd.Content.Formats:void 0),P.apply();const H=this._getMerges([p]),V=W.unionRangesArrays(H);if(H.length>0&&!W.isRangeWithinRange(V,p))throw new Error(xd);if(H.length>0){const n=[],r=s/y;if(i){const s=t.rowEnd-t.rowStart+1,i=o===e.Direction.Up?f.rowStart:t.rowEnd+1,a=H.length;for(let e=0;e<a;e++){const o=H[e],a=o.rowStart-t.rowStart,l=o.rowEnd-o.rowStart+1;for(let t=0;t<r;t++){const e=t*s;n.push({colStart:o.colStart,rowStart:i+e+a,colEnd:o.colEnd,rowEnd:i+e+a+l-1})}}}else{const s=t.colEnd-t.colStart+1,i=o===e.Direction.Left?f.colStart:t.colEnd+1,a=H.length;for(let e=0;e<a;e++){const o=H[e],a=o.colStart-t.colStart,l=o.colEnd-o.colStart+1;for(let t=0;t<r;t++){const e=t*s;n.push({colStart:i+e+a,rowStart:o.rowStart,colEnd:i+e+a+l-1,rowEnd:o.rowEnd})}}}this._merge(n)}const $=this._getState(),U={},G={};G.directStyleSpatial=$.directStyleSpatial,G.continuousFillSpatial=$.continuousFillSpatial;let q=t,J=f;if(!R){let e=(i?p.rowEnd+1-p.rowStart:p.colEnd+1-p.colStart)%v;const n=i?"rowStart":"colStart",r=i?"rowEnd":"colEnd";0!==e&&(J={...f,[r]:Math.min(f[r],f[n]+e)},q={...t,[n]:t[r]-e+1},f[n]=f[n]+e)}const X=Object.keys(G),K=X.length;for(let t=0;t<K;t++){const e=X[t],n=G[e].createCopiedEntries(q,J),r=$[e].clone(),o=n.removes,s=o.length;for(let t=0;t<s;t++)r.remove(o[t]);r.load(n.inserts),U[e]=r}if(R){const e=this.getTables().search({address:{rowIndex:t.rowEnd,colIndex:t.colEnd}});if(1===e.length){const t=e[0],n=t.getRange().getCoords();t.resize({colStart:n.colStart,rowStart:n.rowStart,colEnd:i?n.colEnd:f.colEnd,rowEnd:i?f.rowEnd:n.rowEnd})}}const Y=$.calcGraph.clone();Y.autoFill(t,f),U.calcGraph=Y,this._updateState(U),m={...a,ranges:l},g.commit({viewBefore:{view:this.getView(),selection:rp([t]),selectOptions:r?.autoSelect},viewAfter:{view:this.getView(),selection:m,selectOptions:r?.autoSelect}}),this._autoSelect(r?.autoSelect??!1,m)}catch(t){throw g?.rollback(),t}return!0}_setHyperlinks(t,n,r){const o=r?.description??"Set Hyperlink";this._protectionCheck(()=>["insertHyperlinks","formatCells"],t,o);const s=rp(t),i=this._beginCommit({description:o});let a=null;try{const o=this._getState();if(!o)return _t.EmptyArray;const l=o.hyperlinkSpatial;let c=l;let h=o.directStyleSpatial.clone();const u=t.length;for(let r=0;r<u;r++){const o=t[r];let s=null;const i=o.value,u=void 0!==i?i:n;let d;if(null!==u){if(u.isIHyperlink)d={...u._j},s=u.getDisplayText();else if("string"==typeof u)d={address:u},s=u;else if(u.address){const t=u,e={...t};delete e.displayText,d=e,s=t.displayText??t.address}}else d=null;if(a=W.unionRanges(a,o),l===c&&(c=l.clone()),null!==d||l.size()>0){if(s&&n){const t=this._createIncrementalUpdater({orientation:e.Orientation.Column},void 0,{isHyperlink:!0});for(let e=o.colStart;e<=o.colEnd;e++)for(let n=o.rowStart;n<=o.rowEnd;n++)t.pushAt(n,e,s);t.apply()}if(null===d)this._getRangedEntries("hyperlinkSpatial",[o],{onEntry:(t,e)=>(c.insertNonOverlapping({...e,value:d}),e.value)});else{c.insertNonOverlapping({...o,value:d});const t=this._styles,e=e=>{const n=e.value??new af(t,W.sanitizeRange(e));let r={...n.getPropertiesAt(0,0,null)};if(r.named){const e=t.getNamed(r.named)?.getRanged().getPropertiesAt(0,0,null);r=_t.mergeContentful(e,r)}return delete r.font,r.named=rl.BuiltInName.Hyperlink,{...e,value:n.cloneWithUpdate(r)}};h.insertNonOverlapping({...o,value:null},{onIntersect:e})}}}this._lastUsedCoordsRead.coords=null,this._updateState({hyperlinkSpatial:c,directStyleSpatial:h}),this._commitAndAutoSelect(i,s,r?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw i.rollback(),t}}_updateFormulaSpatial(t,e,n,r){if(n){const e=n.length;for(let r=0;r<e;r++){const e=n[r];t.remove(e)}}let o;if(e){const n=[],s=e.length;for(let t=0;t<s;t++){const s=e[t],i=W.sanitizeRange(s),a=new uw(i,s.value.tokens,s.value.references);if(n.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:a}),!r)continue;const l=s.value.precedents;let c,h,u=!1;const d=l.length;for(let t=0;!u&&t<d;t++){const e=l[t],n=e.colStart;if(void 0===e.colStart)continue;const o=e.rowStart;$w.colStart=n,$w.rowStart=o,$w.colEnd=n,$w.rowEnd=o;const s=r.search($w)[0];if(s){const t=s.value.getPropertiesAt(o,n,null),e=t?.numberFormat;if(e)if(c){h||(h=el.Styles.lookupStyle(c)?.formatType);const t=el.Styles.lookupStyle(e)?.formatType;gs(t,h)>0?(h=t,c=e):u=!0}else c=e}}c&&(o||(o=[]),o.push({colStart:i.colStart,rowStart:i.rowStart,colEnd:i.colEnd,rowEnd:i.rowEnd,value:{numberFormat:c}}))}t.load(n)}return o}_realizeCalcedValues(t){if(!t)return;const n=this._getState();if(!n)return;const r=t.valueInserts,o=t.spillRemoves,s=t.errorRemoves,i=n.cellValuesGrid;t.isFull&&(n.calcErrorsSpatial.clear(),n.spillSpatial.clear(),n.pendingSpatial.clear());const a=t.valueRemoves;if(a){const t=n.contentfulSpatial,e=a.length;for(let n=0;n<e;n++){const e=a[n];i.delete(e),t.insertNonOverlapping({...e,value:null})}}if(o){const t=n.spillSpatial,e=o.length;for(let n=0;n<e;n++){const e=o[n];t.remove(e)}}if(s){const t=n.calcErrorsSpatial,e=s.length;for(let n=0;n<e;n++){const e=s[n];t.remove(e)}}this._updateFormulaSpatial(n.formulaSpatial,t.formulaInserts,t.formulaRemoves);const l=t.formatInserts;if(l){const t=l.length;for(let e=0;e<t;e++){const t=l[e],n={numberFormat:t.value};t.value=n}this._updateStyles(l,void 0,{autoFit:!0},!0)}if(r){const t=r.tuples;i.setValues(t);const o=this._isDataColumn,s=o?e.Orientation.Column:e.Orientation.Row,a=n.contentfulSpatial,l=t.length;for(let e=0;e<l;e++){const n=t[e],r=n[0],i=n[1],l=i.length;for(let t=0;t<l;t++){const e=i[t],n=e[0],l=n+e[1].length-1,c={colStart:o?r:n,rowStart:o?n:r,colEnd:o?r:l,rowEnd:o?l:r};a.insertNonOverlapping({colStart:c.colStart,rowStart:c.rowStart,colEnd:c.colEnd,rowEnd:c.rowEnd,value:new id(c,s)})}}}const c=t.spillInserts;if(c){const t=c.length;for(let e=0;e<t;e++){const t=c[e],n=t.value;t.value=new sd(W.sanitizeRange(t),0,n)}n.spillSpatial.load(c)}const h=t.pendingUpdates;if(h){const t=n.pendingSpatial,e=h.length;for(let n=0;n<e;n++){const e=h[n];!1===e.value&&(e.value=null),t.insertNonOverlapping(e)}}const u=t.errorInserts;if(u){n.calcErrorsSpatial.load(u)}const d=t.formulaInserts;if(d){const t=Hc(d);this._autoFit(t,qw)}if((t.bounds||t.isFull)&&!this._initializing){const e=this._rangesListenerMap;if(e.size>0){const n={isDataChange:!0,isTransactional:!1,timeStamp:Date.now(),isUndo:!1,trigger:"calc"};this._notifyRangeListeners(this._rangeListenerSpatial,e,[t.bounds??this._entireCoords],n)}(c||o)&&this._emitter.notify("onSpillsChange")}}_calculate(t,e){const n=this._getState().calcGraph;n.invalidate(t),n.calculate(e)}_calculateFull(){this._initializing||_t.debounce(()=>{this._getState()?.calcGraph.calculate({full:!0})},100)()}_setComments(t,e,n){const r=n?.description??"Set Comments",o=rp(t),s=this._beginCommit({description:r});let i=null;try{const r=this._getState();if(!r)return _t.EmptyArray;const a=r.commentsSpatial;let l=a;const c=t.length;for(let n=0;n<c;n++){const r=t[n];let o=null;if(null!==e){let t=e;if(!t)continue;o="string"==typeof t?{content:{runs:{text:t}}}:{...t}}i=W.unionRanges(i,r),a===l&&(l=a.clone()),l.insertNonOverlapping({...r,value:o})}this._lastUsedCoordsRead.coords=null,this._updateState({commentsSpatial:l}),this._commitAndAutoSelect(s,o,n?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw s.rollback(),t}}_clear(t,e=null,n,r=!1,o=!1){let s=null,i="Clear",a=!1,l=!1,c=!1,h=!1;e===Gd.Content.Formulas?(i=`${i} Formulas`,h=!0):e===Gd.Content.Values?(i=`${i} Values`,h=!0):e===Gd.Content.Formats?(i=`${i} Formats`,a=!0,s=["formatCells"]):e===Gd.Content.Comments?(i=`${i} Comments`,c=!0):e===Gd.Content.Hyperlinks?(i=`${i} Hyperlinks`,l=!0,s=["formatCells"]):(s=[],i=`${i} All`,h=!0,a=!0,l=!0,c=!0),null!==s&&this._protectionCheck(()=>s,t,n?.description??i);const u=rp(t),d=this._beginCommit({description:n?.description??i});let g=this._getState(),m=g.cellValuesGrid,f=g.calcGraph,p=g.contentfulSpatial,_=g.formulaSpatial,S=g.spillSpatial,w=g.pendingSpatial,y=g.calcErrorsSpatial,E=g.rangesListenerSpatial2;h&&(m=m.clone(),f=f.clone(),p=p.clone(),_=_.clone(),S=S.clone(),w=w.clone(),y=y.clone());try{if(l&&this._setHyperlinks(t,null),c&&this._setComments(t,null),a&&(this._updateStyles(t,null),r||this._unmerge(t)),a||h){Xp(0,t,[],p,S,m);const n=t.length;for(let r=0;r<n;r++){const n=t[r];if(h){m.delete(n);const t={...n,value:null};p.insertNonOverlapping(t);const e=f.delete(n);this._updateFormulaSpatial(_,null,e)}const s=this.getTables().search({address:n}),i=s.length;for(let t=0;t<i;t++){const r=s[t];W.isRangeWithinRange(r.getAnchorCoords(),n)&&(e===Gd.Content.Formats?r.updateStyleOptions({name:null}):r.delete())}if(a){let t=g.conditionalSpatial;t.size()>0&&(t=t.clone(d.getId()),t.insertNonOverlapping({...n,value:null},{noMerge:!0}),g=this._updateState({conditionalSpatial:t}))}if(o){const t=E.search(n),e=t.length;for(let r=0;r<e;r++){const e=t[r];W.isRangeWithinRange(e,n)&&(E===g.rangesListenerSpatial2&&(E=E.clone()),console.log("cut and move listener"),E.remove(e))}}}}this._updateState({cellValuesGrid:m,calcGraph:f,contentfulSpatial:p,formulaSpatial:_,spillSpatial:S,pendingSpatial:w,calcErrorsSpatial:y,rangesListenerSpatial2:E}),this._commitAndAutoSelect(d,u,n?.autoSelect,{viewAfter:{ranges:t}})}catch(t){throw d.rollback(),t}}_merge(t,n=null){if(this._protectionCheck(Ow,t),1===t.length&&W.isSingleCell(t[0]))return;let r=e.Orientations.Both;n?.orientations?r=n?.orientations:n===e.Orientations.Row?r=e.Orientations.Row:n===e.Orientations.Column&&(r=e.Orientations.Column);const o=n?.discardMultipleValues??!1;let s=rp(t);const i=this.getSelection().getCoords();let a=null;const l=this._beginCommit({description:n?.description??"Merge"});let c=t[0];try{const h=this._getMerges(t);if(Bh(t)||h.length>0){const e=W.unionRangesArrays(h),n=W.unionRangesArrays(t);if(!(!e&&!n||e&&n&&W.isRangeWithinRange(e,n)))throw console.warn(vd,t),new Error(vd);this._unmerge(h)}const u=this._createIncrementalUpdater({orientation:e.Orientation.Column}),d=[];try{const n=this._entireCoords,l=this._getState().contentfulSpatial;let h=!1;const g=t=>{const e={rowIndex:t.rowStart,colIndex:t.colStart};let n=null;if(h){let e=0;const n=l.search(t),r=n.length;for(let o=0;o<r;o++){const r=W.intersectRanges(n[o],t);if(r&&(e+=(r.rowEnd-r.rowStart+1)*(r.colEnd-r.colStart+1)),e>1)throw new Dt("Merging cells would cause some values to be discarded. Use 'discardMultipleValues' option if desired.","discardMultipleValues")}}if(n||(n=e),!W.isEqualCells(n,e)){const e=this.getRange(n).getCell();u.pushAt(t.rowStart,t.colStart,e),u.pushAt(n.rowIndex,n.colIndex,null)}d.push(t),c=W.unionRanges(c,t)},m=[...t].sort(W.createRangeComparator(e.Orientation.Column)),f=m.length;for(let t=0;t<f;t++){const c=m[t];if(!W.isSingleCell(c)){if(a||!i||!W.isCellWithinRange(i.cell,c)||i.cell.rowIndex===c.rowStart&&i.cell.colIndex===c.colStart||(a={...s,cell:{rowIndex:c.rowStart,colIndex:c.colStart}}),!o){const t=l.search(c);h=t.length>0}if(this._validateOrRemoveOverlaps(c,"merge"),c.colStart<n.colStart||c.rowStart<n.rowStart||c.colEnd>n.colEnd||c.rowEnd>n.rowEnd)throw new Error("We can't merge outside of the maximum cell location.");if(r===e.Orientations.Column){const t=c.rowEnd!==n.rowEnd?c.rowEnd:Math.max(1,n.rowEnd);for(let e=c.rowStart;e<=t;e++)g({...c,rowStart:e,rowEnd:e})}else if(r===e.Orientations.Row){const t=c.colEnd!==n.colEnd?c.colEnd:Math.max(1,n.colEnd);for(let e=c.colStart;e<=t;e++)g({...c,colStart:e,colEnd:e})}else g(c)}}u.apply(),this._indexMerges(d),this._updateState({})}catch(t){if(t.type)throw new Dt(t.message??"Unable to merge",t.type);throw new Error(t.message??"Unable to merge")}a&&(s=a,this.getSelection().updateCoords(a)),l.commit({viewAfter:{view:this.getView(),selection:s,merges:t,ranges:t,selectOptions:n?.autoSelect}}),this._autoSelect(n?.autoSelect??!1,s)}catch(t){throw l.rollback(),t}}_unmerge(t,e){if(this._protectionCheck(Ow,t),Bh(t))throw new Error("We can't unmerge intersecting ranges.");if(!this._getState())return null;const n=W.unionRangesArrays(t),r=rp(t),o=this._beginCommit({description:e?.description??"Unmerge"}),s=o.getState(this).mergeSpatial,i=[];try{const a=t.length;for(let e=0;e<a;e++){const r=t[e],o=s.search(r),a=o.length;for(let t=0;t<a;t++){const e=o[t];if(!W.isSingleCell(r)&&!W.isRangeWithinRange(e,n))throw new Error("We can't unmerge partial cells.");i.push(e)}}if(0===i.length)return o.rollback(),null;this._indexMerges(null,i),this._commitAndAutoSelect(o,r,e?.autoSelect,{viewAfter:{merges:t,ranges:t}})}catch(t){throw o.rollback(),t}}_getMerges(t,e=!1){return 0===t.length?_t.EmptyArray:this._getRangedEntries("mergeSpatial",t,{excludeHidden:e,fullyContained:!1,onEntry:t=>t.getCoords()})}_clone(){const t={...this._options,container:null};this._ownStyles&&(t.styles=this._styles),this._ownStrings&&(t.strings=this._strings),this._ownResources&&(t.resources=this._resources),this._ownNames&&(t.names=this._names),this._ownsCalculation&&(t.calculation=this._calculation),t.transactions=new ie({transient:!0});const e=new Dw(t),n=this._transactions.getState(this);e._updateState(n);const r=new _w({sheet:this,json:this.getView().toJSON()});return r.selectMovables(this.getView().getMovableSelection()),e.setView(r),e}_getSnapshot(t,e){if(0===t.length)return _t.EmptyArray;const n=this._getState();if(!n)return null;e=Object.freeze({...e});const r=this._clone();r.isMarked=!0;const o=this,s=o.getView(),i="Range",a=[],l=((t,e,n,r)=>{const o=[];let s=null,i=null;const a=n&&n.length>0;if(a){const t=n.length;for(let e=0;e<t;e++){const t=n[e].getSnapshot?.(r);t&&(o.push(t),s=Re(t.getCoords(),s))}}else if(e){const n=e.length;for(let a=0;a<n;a++){const n=e[a],l=t.getMovables().search({excludeHidden:!1,fullyContained:!0,address:n}),c=l.length;for(let e=0;e<c;e++){const a=l[e].getSnapshot?.(r);a&&(o.push(a),s=Re(t.getRange(n).getBounds(),s),i=W.unionRanges(i,n))}}}if(0===o.length)return null;const l=()=>r.description??(1===o?.length?Hs(o[0]?.getName()):"Drawings");return{copyTo:async(e,n)=>{const i={...r,...n},a=e.getSource(),c=a.getView(),h=c.getMovableSelection(),u=e.getCoords(),d=i?.isCut??!1,g=c.getMovableSelection();c.selectMovables([]);const m=a.beginCommit(i.description??`${d?"Cut":"Copy"} ${l()}`);try{let e=0,n=0;if(g.length>0&&o.length>0){let t=Number.MAX_SAFE_INTEGER,r=Number.MAX_SAFE_INTEGER;for(let e=0;e<h.length;e++){const n=h[e].getBounds();t=Math.min(n.x,t),r=Math.min(n.y,r)}let s=Number.MAX_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER;const l=o.length;for(let t=0;t<l;t++){const e=o[t].getCoords();s=Math.min(e.x,s),i=Math.min(e.y,i)}e=t-s,n=r-i;const c=o[0].getCoords(),u={...c,x:c.x+e,y:c.y+n},d=OS(a.getMovables(),u);e+=d.x,n+=d.y}else if(s){const t=a.getRange(u).getBounds();e=t.x-s.x,n=t.y-s.y}const r=[],l=o.length;for(let t=0;t<l;t++){const s=o[t],l=s.getCoords(),c={...l,x:l.x+e,y:l.y+n};r.push(s.copyTo({movables:a.getMovables(),bounds:c},{autoSelect:{addToSelection:!0},...i}))}await Promise.all(r),m?.updateState(a,t=>t),m.commit({viewBefore:e=>({...e,view:t.getView(),movableSelection:g})})}catch(t){throw m.rollback(),t}return null},getName:l,getCoords:()=>i,getMarkOptions:()=>r,toText:()=>a?o[0].toText?.()??null:null,toHtml:()=>a?o[0].toHtml?.()??null:null,toImage:()=>a?o[0].toImage?.()??null:null,getSource:()=>t,isISnapshot:!0}})(r,t,s.getMovableSelection(),e);if(l){if(s.getMovableSelection().length>0)return l;a.push(l)}if(t.length>1)throw new Error(Nd);const c={singleMerge:null};a.push({copyTo(n,o){const s={...e,...o};let i=null;if(!s.skipBlanks){const e=n.getSource(),o=n.getCoords(),l=Vh(o,t[0],s?.fitDestination,s?.transpose);i=e.getRange(l);let h=!1;const u=i.getMerges();if(1===u.length&&W.isEqualRanges(u[0],o))if(W.isSingleCell(t[0]))h=!0;else{const t=(a=f)?{colIndex:a.colStart,rowIndex:a.rowStart}:null;1===r._getMerges([W.cellToRange(t)]).length&&(h=!0)}return h?(c.singleMerge=o,i.clear(s.type??Gd.Content.Values)):i.clear(s.type),l}var a}});const h=r._entireCoords,u=t.length;for(let o=0;o<u;o++){const s=t[o],i=n.rangeListenerSpatial.search(s,!1),l=n.rangesListenerMap;a.push({async copyTo(e,n){if(!n.isCut)return;const o=new Set,s=i.length;for(let n=0;n<s;n++){const s=i[n].value,a=s.id;if(o.has(a))continue;const c=l.get(a);o.add(a);if(null===c.ranges[s.offset])return;const h={isTransactional:!0,isDataChange:!1,trigger:"moveCells",from:r.getRanges(t),to:e},u=r._createRangeEvent(c.ranges,h);r._notifyRangeListener2(c,u,h)}return null},getMarkOptions:()=>e,getCoords:()=>null,isISnapshot:!0})}const d={excludeHidden:!1,fullyContained:!0,onEntry:t=>t.model};for(let n=0;n<u;n++){const o=t[n],s=r._getRangedEntries("tableSpatial",[o],d),i=s.length;for(let t=0;t<i;t++){const n=s[t],i=n.getAnchorCoords(),l=i.colStart-o.colStart,c=i.rowStart-o.rowStart,h=n.getSnapshot(e);a.push({async copyTo(t,e){const n=t.getSource(),o=t.getCoords();if(r.getProtection().isLocked())return;const s={colStart:o.colStart+l,rowStart:o.rowStart+c,colEnd:o.colEnd+l,rowEnd:o.rowEnd+c};return h.copyTo({tables:n.getTables(),range:s},e)}})}}for(let n=0;n<u;n++){const r=t[n];a.push(qS(o.getColumnHeaders().getRange(r),r,Object.freeze({...e,includeHeaders:r.rowStart<=h.rowStart&&r.rowEnd>=h.rowEnd})))}for(let n=0;n<u;n++){const r=t[n];a.push(qS(o.getRowHeaders().getRange(r),r,Object.freeze({...e,includeHeaders:r.colStart<=h.colStart&&r.colEnd>=h.colEnd})))}const g=JS(o,r,t,i,e,(e,n)=>r._copyRange(o,r,t,e,n,c));a.push(g);const m=r._getState().calcGraph.getSnapshot({range:t[0]});a.push({async copyTo(t,e){const n=t.getSource(),o=t.getCoords();if(r.getProtection().isLocked())return;const s=n._getState().calcGraph;return m.copyTo({calcGraph:s,range:o},e)}});const f=t[0];return((t,e,n,r,o,s,i=null)=>{const a={async copyTo(e,r){let i=null;const a={...o,...r},l=n.beginCommit(a.description??s);try{const n=t.length;for(let r=0;r<n;r++){const n=await t[r].copyTo(e,a);n&&(i=W.unionRanges(i,n))}l.commit()}catch(t){throw l.rollback(),t}return i},getMarkOptions:()=>o,getName:()=>s,getSource:()=>e,getCoords:()=>r,toText(){let e=i?.toText?.()??null;const n=t.length;for(let r=0;!e&&r<n;r++)e=t?.[r].toText?.();return e??null},toHtml(){let e=i?.toHtml?.()??null;const n=t.length;for(let r=0;!e&&r<n;r++)e=t?.[r].toHtml?.();return e??null},toImage(){let e=i?.toImage?.()??null;const n=t.length;for(let r=0;!e&&r<n;r++)e=t?.[r].toImage?.();return e??null},isISnapshot:!0};return a})(a,o,r,f,e,i,g)}async _copyRange(t,n,r,o,s,i){if(r.length>1)throw new Error("Only a single selection is supported when using 'Insert Copy'.");if(!r||0===r.length)throw new Error("The source has no range.");const a=o.getSource();let l=o.getCoords(),c={...r[0]};const h=(s={...s}).isCut;let u=!s.type||s.type===Gd.Content.Formats,d=!s.type||s.type===Gd.Content.Values,g=!s.type||s.type===Gd.Content.Formats||s.type===Gd.Content.Hyperlinks;const m=a.getEntireRange(),f=m.getCoords(),p=[],_=[],S=[];let w=[],y=[];const E=(s.fitDestination??!1)&&!W.isSingleCell(l),b=Vh(l,c,E,s.transpose);if(E&&(c={...c,colEnd:c.colStart+Math.min(b.colEnd-b.colStart,c.colEnd-c.colStart),rowEnd:c.rowStart+Math.min(b.rowEnd-b.rowStart,c.rowEnd-c.rowStart)}),!W.isRangeWithinRange(b,f))throw console.warn(b,f),new Error("We can't paste outside of the sheet bounds.");let v=null;v=s.undoRange?{view:a.getView(),selection:rp([s.undoRange.getCoords()])}:{sheet:a,selection:rp([b])};const C=a.getTransactions().beginCommit({description:s.description??"Paste"});try{if(!this._getState())return _t.EmptyArray;const r=new Set,o=s.transpose;let f=!((o||s.adjustCells)&&u)&&1===r.size;if(f){const t=r.values().next();f=W.isRangeWithinRange(c,t.value.getCoords())&&!Jf(c,t.value.getCoords())}if(f){const t=a.getTables().search({address:b});f=0===t.length}o&&(f=!0),i.singleMerge&&(u=!1,g=!1);const E=l.colStart-c.colStart,x=l.rowStart-c.rowStart,I=s.adjustCells;let A={...fd};if(delete A[dd.Type.Style],!u){const t=this.getProtection().isLocked();A={},t&&(A[dd.Type.Unlock]=!1)}const R=e.Orientation.Column;let M;if(d){M=m.startIncrementalUpdates({orientation:s.transpose?e.Orientation.Row:e.Orientation.Column});const t={orientation:R,includeRangeTypes:A,bounds:c},n=new Kf(this._strings,t,this._cellOptions),r=(t,e,r)=>{const i=t[0],a=n.setState(t),h=n.context,m=h.getCell(),_=m.isTopLeft();let S=x,w=E;if(o){const t=i.colIndex-c.colStart,n=i.rowIndex-c.rowStart;S=t+r+l.rowStart,w=n+e+l.colStart}else S=x+i.rowIndex+e,w=E+i.colIndex+r;let y=!1;const b={value:void 0,style:void 0,hyperlink:void 0};if(d&&(b.value=a,y=!0),u){const e=t[2];e&&(e.directStyle||e.table)&&(b.style=m.getStyle(!f),y=!0)}g&&(b.hyperlink=m.getHyperlink(),y=!0);let v=b;if(I&&_){const t=I(a,h,{rowIndex:S,colIndex:w},s);void 0!==t&&(v=t,y=!0)}if(y&&(M.pushAt(S,w,v),u)){const t=m.getSpans();(t.width>1||t.height>1)&&_&&p.push({colStart:w,rowStart:S,colEnd:w+(s.transpose?t.height:t.width)-1,rowEnd:S+(s.transpose?t.width:t.height)-1})}},a=this._cellStateIterator(t);let h={next(){const t=a.next();if(t.done)return Ul;const e=t.value[0];let n;return t.value&&(n=[e,t.value]),{done:t.done,value:n}}};if(!i.singleMerge&&!W.isEqualRanges(b,c)){const t=b.colEnd-b.colStart+1,e=b.rowEnd-b.rowStart+1;h=new eh({delegate:h,bounds:c,orientation:R,dims:{major:s.transpose?e:t,minor:s.transpose?t:e}})}let _=h.next();for(;!_.done;){const t=_.value,e=t[1],n=t[0],o=e[0];r(e,n.rowIndex-o.rowIndex,n.colIndex-o.colIndex),_=h.next()}}const T=n._getState(),N={},F={transpose:o??!1};u&&(N.directStyleSpatial=T.directStyleSpatial,N.continuousFillSpatial=T.continuousFillSpatial,N.mergeSpatial=T.mergeSpatial),h&&(t._clear([c],void 0,void 0,!1,!0),w.push(c),N.rangesListenerSpatial2=T.rangesListenerSpatial2);const k=a,O=k._getState(),L=Object.keys(N),D=L.length;for(let t=0;t<D;t++){const e=L[t],n=N[e].createCopiedEntries(c,b,F),r=O[e].clone(),o=n.removes,s=o.length;for(let t=0;t<s;t++)r.remove(o[t]);r.load(n.inserts),O[e]=r}k._updateState(O),w.push(b),y.push(b),_&&_.length>0&&k._colHeaders.updateHeaderPairs(_),S&&S.length>0&&k._rowHeaders.updateHeaderPairs(S),M?.apply(),p.length>0&&a.getRanges(p).merge(),C.commit({viewBefore:v,viewAfter:t=>({...t,view:a.getView(),selection:rp(y),ranges:w})})}catch(t){throw console.warn(t),C.rollback(),new Error((t=>`Unable to paste: ${t}`)(t.message),{cause:t})}return W.unionRangesArrays(y)}_snapShotFromSource(t,e){if(t.isISnapshot)return t;const n=t;let r=null;if(n?.isICellRanges)throw new Error(Nd);if(r=n?.isICellRange?n:this.getRange(n),r.isICellRange){const t=r;if(t.isInvalid())throw new Error(Fd);return t.getSnapshot(e)}throw new Error(Fd)}async _copyFrom(t,e,n){if(!e)throw new Error("Both a source and a destination are required to copy.");const r=this._snapShotFromSource(e),o="Paste",s=this._beginCommit({description:n?.description??o});let i=null;try{const e=this.getRange(t);i=await r.copyTo(e,n);const a=r.getName(),l=[i];n?.isCut&&l.push(r.getCoords()),s.commit({description:a?n?.description??`${o} ${a}`:o,viewAfter:{view:this.getView(),selection:rp([i]),ranges:l}})}catch(t){throw s.rollback(),t}return i}_createFilter(t,e,n){const r=this;return new fp({initialAnchor:t,maxRangeCoords:this._entireCoords,json:e,transactions:this._transactions,deleteFromContainer:t=>{const e=this._beginCommit({description:t?.description??"Delete Filter"});this._updateState({filter:null}),e.commit()},apply:t=>{console.log("apply Filter",t)},processUpdate:()=>{},isProtected:()=>!r._initializing&&!r.getProtection().isAutoFilterAllowed()})}insertFilter(t){const e=this._rangeToCoords(t,()=>["autoFilter"]);let n=this.getFilter();if(n)return n;n=this._createFilter(e);const r=rp([e]),o=this._beginCommit({description:"Insert Filter"});return this._updateState({filter:n}),o.commit({viewAfter:{ranges:[e],view:this.getView(),selection:r,selectOptions:void 0}}),n}getFilter(){return this._getState()?.filter??null}insertSort(t){return this._rangeToCoords(t,()=>["sort"]),null}getSort(){return null}_getDefaultShiftOrientation(t){return kf(t,this._entireCoords)}_getDefaultSortCriteria(t,e,n){return Zf(this,t,n?this._cellToCoords(n):null,e)}async _insertFrom(t,n,r){if(!n)throw new Lt;const o=this._snapShotFromSource(n),s=o.getCoords();let i=Vh(t[0],s,r?.fitDestination),a=ep([i]),l=a;const c=r?.orientation??this._getDefaultShiftOrientation(i),h=this._beginCommit({description:r?.description??"Insert Copied Cells",autoSelect:r?.autoSelect});try{if(this._insertCells([i],c),await this._copyFrom(i,o,{...r,isCut:!1}),r.isCut){const t={...s};if(a=ep([t]),i={...i},this===o.getSource()){if(c===e.Orientation.Row){if(i.colStart<t.colStart&&i.colEnd>=t.colStart||i.colEnd>t.colEnd&&i.colStart<=t.colEnd)throw new Error(kd);if(t.colStart===i.colStart&&t.colEnd===i.colEnd){const e=t.rowEnd-t.rowStart+1;i.rowStart<=t.rowStart?(t.rowStart+=e,t.rowEnd+=e):(i.rowStart-=e,i.rowEnd-=e)}}else{if(i.rowStart<t.rowStart&&i.rowEnd>=t.rowStart||i.rowEnd>t.rowEnd&&i.rowStart<=t.rowEnd)throw new Error(kd);if(t.rowStart===i.rowStart&&t.rowEnd===i.rowEnd){const e=t.colEnd-t.colStart+1;i.colStart<=t.colStart?(t.colStart+=e,t.colEnd+=e):(i.colStart-=e,i.colEnd-=e)}}l=ep([i])}o.getSource().getRanges([t]).delete(c)}h.commit({viewBefore:{ranges:t,view:this.getView(),selection:a,selectOptions:r?.autoSelect},viewAfter:{ranges:t,view:this.getView(),selection:l,selectOptions:r?.autoSelect}}),this._autoSelect(r?.autoSelect??!1,l)}catch(t){throw h.rollback(),t}return i}_insertCells(t,n,r,o=void 0){const s=this;o=o??((t,e)=>{s._validateCoords(t,e??Cd)});const i=r?.description??"Insert Cells",a=(n??this._getDefaultShiftOrientation(t[0]))===e.Orientation.Column;if(this._protectionCheck(()=>[a?"insertColumns":"insertRows"],t,i),Bh(t))throw new Error("We can't insert cells with overlapping selections.");const l=this._entireCoords;let c=l.colEnd,h=l.rowEnd;const u=rp(t),d=this._beginCommit({description:i,operation:{name:"insertCells"}}),g=d.getState(this),m=a?e.Direction.Right:e.Direction.Down;try{let n=g.cellValuesGrid,s=g.contentfulSpatial,i=g.unlockSpatial,f=g.mergeSpatial,p=g.directStyleSpatial,_=g.continuousFillSpatial,S=g.conditionalSpatial,w=g.hyperlinkSpatial,y=g.commentsSpatial,E=g.movableSpatial,b=g.tableSpatial,v=g.calcGraph,C=g.rangesListenerSpatial2,x=g.rangeListenerSpatial,I=g.rangesListenerMap;const A=new Map,R=tc(t.slice(),e.Direction.Left),M=R.length;for(let t=0;t<M;t++){const e=R[t];c=Math.min(c,e.colStart),h=Math.min(h,e.rowStart);const r=a?e.colEnd-e.colStart+1:e.rowEnd-e.rowStart+1,u=n.getCoords();if(u){const t={...e,colEnd:a?Math.max(e.colEnd,u?.colEnd??e.colStart)+(e.colEnd-e.colStart+1):e.colStart,rowEnd:a?e.rowStart:Math.max(e.rowEnd,u?.rowEnd??e.rowStart)+(e.rowEnd-e.rowStart+1)},i=s.search(t),l=i.length;for(let t=0;t<l;t++){const n=i[t],s={...e};a?s.colEnd=Math.max(s.colEnd,n.colEnd)+r:s.rowEnd=Math.max(s.rowEnd,n.rowEnd)+r,o(s)}n=n.clone(),n.shift(e,m),this._updateState({cellValuesGrid:n})}const d=e.colStart<=l.colStart&&e.colEnd>=l.colEnd,M=e.rowStart<=l.rowStart&&e.rowEnd>=l.rowEnd,T=(t,e,n,r)=>{let o=null;n>1&&(o=t.at(n-1));const s=r-n+1;e?.(n,s),o&&t.updateHeaderPairs([{address:{min:n,max:r},update:o}])};d&&T(this._rowHeaders,this._rowHeadersShiftCallback,e.rowStart,e.rowEnd),M&&T(this._colHeaders,this._colHeadersShiftCallback,e.colStart,e.colEnd),s=s.shift({range:e,direction:m,cloneIfUpdate:s===g.contentfulSpatial,coordValidator:o}),i=i.shift({range:e,direction:m,cloneIfUpdate:i===g.unlockSpatial,coordValidator:o}),f=f.shift({range:e,direction:m,cloneIfUpdate:f===g.mergeSpatial,coordValidator:o}),p=p.shift({range:e,direction:m,cloneIfUpdate:p===g.directStyleSpatial,coordValidator:o}),_=_.shift({range:e,direction:m,cloneIfUpdate:_===g.continuousFillSpatial,coordValidator:o}),S=S.shift({range:e,direction:m,cloneIfUpdate:S===g.conditionalSpatial,coordValidator:o}),w=w.shift({range:e,direction:m,cloneIfUpdate:w===g.hyperlinkSpatial,coordValidator:o}),y=y.shift({range:e,direction:m,cloneIfUpdate:y===g.commentsSpatial,coordValidator:o}),E=E.shift({range:e,direction:m,cloneIfUpdate:E===g.movableSpatial,coordValidator:o}),b=b.shift({range:e,direction:m,cloneIfUpdate:b===g.tableSpatial,coordValidator:o}),v=v.shift({range:e,direction:m,cloneIfUpdate:v===g.calcGraph}),x=x.shift({range:e,direction:m,cloneIfUpdate:x===g.rangeListenerSpatial,onShift:t=>{I===g.rangesListenerMap&&(I=new Map(I)),this._processListenerShift(I,A,g.rangesListenerMap,t)}}),C=C.shift({range:e,direction:m,cloneIfUpdate:C===g.rangesListenerSpatial2,coordValidator:o})}let T=g.formulaSpatial,N=g.spillSpatial,F=g.pendingSpatial;v!==g.calcGraph&&(T=T.clone(),N=N.clone(),F=F.clone()),this._updateState({contentfulSpatial:s,unlockSpatial:i,mergeSpatial:f,directStyleSpatial:p,continuousFillSpatial:_,conditionalSpatial:S,hyperlinkSpatial:w,commentsSpatial:y,movableSpatial:E,tableSpatial:b,calcGraph:v,formulaSpatial:T,spillSpatial:N,pendingSpatial:F,rangesListenerSpatial2:C,rangeListenerSpatial:x,rangesListenerMap:I}),this._commitAndAutoSelect(d,u,r?.autoSelect,{viewAfter:{ranges:R,listeners:A}})}catch(t){if(console.warn(t),d.rollback(),t instanceof kt)throw new Error(t.message??Cd);throw t}}_deleteCells(t,n,r){const o=(n??this._getDefaultShiftOrientation(t[0]))===e.Orientation.Column,s=r?.description??"Delete Cells";if(this._protectionCheck(()=>[o?"deleteColumns":"deleteRows"],t,s),Bh(t))throw new Error("We can't delete cells with overlapping selections.");const i=this._entireCoords;let a=i.colEnd,l=i.rowEnd;const c=o?e.Direction.Left:e.Direction.Up,h=rp(t),u=this._beginCommit({description:s,operation:{name:"deleteCells"}}),d=u.getState(this);try{let n=d.cellValuesGrid,o=d.contentfulSpatial,s=d.mergeSpatial,g=d.unlockSpatial,m=d.directStyleSpatial,f=d.continuousFillSpatial,p=d.conditionalSpatial,_=d.hyperlinkSpatial,S=d.commentsSpatial,w=d.movableSpatial,y=d.movableMapModel,E=d.tableSpatial,b=d.tableMapModel,v=d.calcGraph,C=d.rangesListenerSpatial2,x=d.rangeListenerSpatial,I=d.rangesListenerMap;const A=new Map,R=tc(t.slice(),e.Direction.Left),M=R.length;for(let t=0;t<M;t++){const e=R[t];a=Math.min(a,e.colStart),l=Math.min(l,e.rowStart);n.getCoords()&&(n=n.clone(),n.shift(e,c),this._updateState({cellValuesGrid:n}));const r=e.colStart<=i.colStart&&e.colEnd>=i.colEnd,h=e.rowStart<=i.rowStart&&e.rowEnd>=i.rowEnd;r&&this._rowHeadersShiftCallback(e.rowStart,-1*(e.rowEnd-e.rowStart+1)),h&&this._colHeadersShiftCallback(e.colStart,-1*(e.colEnd-e.colStart+1)),o=o.shift({range:e,direction:c,cloneIfUpdate:o===d.contentfulSpatial}),g=g.shift({range:e,direction:c,cloneIfUpdate:g===d.unlockSpatial}),s=s.shift({range:e,direction:c,cloneIfUpdate:s===d.mergeSpatial}),m=m.shift({range:e,direction:c,cloneIfUpdate:m===d.directStyleSpatial}),f=f.shift({range:e,direction:c,cloneIfUpdate:f===d.continuousFillSpatial}),p=p.shift({range:e,direction:c,cloneIfUpdate:p===d.conditionalSpatial}),_=_.shift({range:e,direction:c,cloneIfUpdate:_===d.hyperlinkSpatial}),S=S.shift({range:e,direction:c,cloneIfUpdate:S===d.commentsSpatial}),w=w.shift({range:e,direction:c,cloneIfUpdate:w===d.movableSpatial}),E=E.shift({range:e,direction:c,cloneIfUpdate:E===d.tableSpatial}),v=v.shift({range:e,direction:c,cloneIfUpdate:v===d.calcGraph}),x=x.shift({range:e,direction:c,cloneIfUpdate:x===d.rangeListenerSpatial,onShift:t=>{I===d.rangesListenerMap&&(I=new Map(I)),this._processListenerShift(I,A,d.rangesListenerMap,t)}}),C=C.shift({range:e,direction:c,cloneIfUpdate:C===d.rangesListenerSpatial2})}this._updateState({contentfulSpatial:o,unlockSpatial:g,mergeSpatial:s,directStyleSpatial:m,continuousFillSpatial:f,conditionalSpatial:p,hyperlinkSpatial:_,commentsSpatial:S,movableSpatial:w,movableMapModel:y,tableSpatial:E,tableMapModel:b,calcGraph:v,rangesListenerSpatial2:C,rangeListenerSpatial:x,rangesListenerMap:I}),this._commitAndAutoSelect(u,h,r?.autoSelect,{viewAfter:{ranges:R,listeners:A}})}catch(t){if(u.rollback(),t instanceof kt)throw new Error(t.message??Cd);throw t}}_autoFit(n,r){if(this._closed)throw new Error(Ad);r={expandOnly:!1,skipCustomSize:!1,minContent:!1,...r};const o="Autofit";let s;const i=Nf(n,this._entireCoords,!0),a=Tf(n,this._entireCoords,!0);!i&&a?(r.orientations=r.orientations??e.Orientations.Column,s=`${o} ${iw}`):!a&&i?(r.orientations=r.orientations??e.Orientations.Row,s=`${o} ${sw}`):a&&i?(r.orientations=r.orientations??e.Orientations.Both,s=`${o} All`):(r.orientations=r.orientations??e.Orientations.Both,s=`${o}`);let l=r.orientations!==e.Orientations.Row;this._colHeaders.isProtected()&&(l=!1);let c=r.orientations!==e.Orientations.Column;if(this._rowHeaders.isProtected()&&(c=!1),!c&&!l)return;const h=l&&(!1===r.expandOnly||r.expandOnly===e.Orientation.Row),u=c&&(!1===r.expandOnly||r.expandOnly===e.Orientation.Column),d=r.minContent,g=rp(n),m=this._beginCommit({description:r.description??s});try{let o=Number.MAX_SAFE_INTEGER,s=Number.MIN_SAFE_INTEGER,i=!1,a="",f=-1,p=!1,_=!1,S=!1,w=Number.MAX_SAFE_INTEGER,y=Number.MIN_SAFE_INTEGER;const E=this._styles.getNormal(),b=this._cellOptions,v=r.orientations===e.Orientations.Row,C=new Map,x=Vc(n,1);x.sort(W.createRangeComparator(e.Orientation.Column));const I=x.length,A={skipCustomSize:r.skipCustomSize},R=fi.getDeviceScale(),M=this._defaultRowHeight()*R,T=(t,e=1)=>{if(0!==t&&null!==t&&!(e>1))return t=Math.max(t,M),e=>u?t:Math.max(e,t)},N=(t,e=1)=>{if(0!==t&&null!==t&&!(e>1))return e=>h?t:Math.max(e,t)};for(let n=0;n<I;n++){const r=[];let g=-1,m=!1,I=E,R=-1,M=1,F=1;const k=x[n];let O=k.colStart,L=k.rowStart,D=k.colEnd,B=k.rowEnd;const z=this._getUsedCoords();(u||h)&&z&&(O=u?z.colStart:k.colStart,L=h?z.rowStart:k.rowStart,D=u?z.colEnd:k.colEnd,B=h?z.rowEnd:k.rowEnd);const P={includeRangeTypes:{[dd.Type.Style]:!1,[dd.Type.Contentful]:!1},excludeHidden:!1,bounds:{colStart:O,rowStart:L,colEnd:D,rowEnd:B},orientation:e.Orientation.Column},j=c?[]:void 0,H=l?[]:void 0,V=(t,e,n)=>{if(t>e)return null;const r=[];let o=t;const s=n?n.length:0;for(let t=0;t<s;t++){const e=n[t],s=e.min,i=e.max;if(o>=s){o=i+1;continue}const a={address:{min:o,max:s-1},update:Ww};r.push(a),o=i+1}if(o<=e){const t={address:{min:o,max:e},update:Ww};r.push(t)}return r},$=this._rangeStateIterator(P);let U=$.next();for(;!U.done;){const t=U.value,e=t.intersection,n=t.start,r=t.end;Pw.colStart=n.colIndex,Pw.rowStart=n.rowIndex,Pw.colEnd=r.colIndex,Pw.rowEnd=r.rowIndex;const o=W.intersectRanges(Pw,k,zw),s=Ef(0,o,e,b).getBestFit();if(c){const t=Math.max(n.rowIndex,L),e={address:{min:t,max:Math.min(r.rowIndex,B)},update:{size:T(s.height),autoSize:!0}};j.push(e)}if(l){const t=Math.max(n.colIndex,O),e={address:{min:t,max:Math.min(r.colIndex,D)},update:{size:N(s.width),autoSize:!0}};H.push(e)}U=$.next()}if(H){let t=this._colHeaders.updateHeaderPairs(H,A);t=ca(ha(ua(t)));const e=V(k.colStart,k.colEnd,t);e&&this._colHeaders.updateHeaderPairs(e,A)}if(j){let t=this._rowHeaders.updateHeaderPairs(j,A);t=ca(ha(ua(t)));const e=V(k.rowStart,k.rowEnd,t);e&&this._rowHeaders.updateHeaderPairs(e,A)}const G=this._cellStateIterator({...P,includeRangeTypes:{[dd.Type.Merge]:!1,[dd.Type.Table]:!1,[dd.Type.Style]:!1},ignoreEmptyIntersections:!0});let q,J,X,K=G.next(),Y=1,Z=1;for(;!K.done;){const e=K.value,n=e[0],l=e[2];let c=E;const h=l?.directStyle??null;h===q?c=J:(c=h?Ef(0,W.cellToRange(n,jw),l,b):E,J=c);let u=1,d=1;const v=l?.merge??null;if(v===X)u=Y,d=Z;else{if(v){const t=v.getCoords();u=t.colEnd-t.colStart+1,d=t.rowEnd-t.rowStart+1}else u=1,d=1;Y=u,Z=d}const C=n.colIndex,x=n.rowIndex,A=e[1],T=Kh(A),N=W.isCellWithinRange(n,k);let O=!1,L=!1;if(q!==h||u!==M||d!==F||T===t.String||T===t.Error||N!==m){if(O=!0,(u>1||d>1||T===t.RichData)&&(L=!0),!L&&l){const t=c.getAlignment().getHorizontal();t!==zs.HorizontalAlignment.CenterContinuous&&t!==zs.HorizontalAlignment.Fill||(L=!0)}L&&(O=!1)}if(q=h,X=v,(g!==C||O)&&(g!==C&&(R=this._colHeaders.getSpanSize(C)),-1!==g&&r.push({col:g,style:I,spanWidth:u,spanHeight:d,minVal:o,maxVal:s,hasZero:i,text:a,textId:f,hasFalse:_,hasTrue:p,hasEmpty:S,minRow:w,maxRow:y,colWidth:R,measureWidth:-1,measureHeight:-1,isFit:m}),g=C,I=c,m=N,M=u,F=d,o=Number.MAX_SAFE_INTEGER,s=Number.MIN_SAFE_INTEGER,i=!1,a="",f=-1,_=!1,p=!1,S=!1,w=x),y=x,!L)if(null===A)S=!0;else switch(T){case t.Number:0===A&&(i=!0),o=Math.min(o,A),s=Math.max(s,A);break;case t.String:a=A,f=A;break;case t.Error:a=A.toString(),f=-1;break;case t.Boolean:A?p=!0:_=!0}K=G.next()}-1!==g&&r.push({col:g,style:I,spanWidth:M,spanHeight:F,minVal:o,maxVal:s,hasZero:i,text:a,textId:f,hasFalse:_,hasTrue:p,hasEmpty:S,minRow:w,maxRow:y,colWidth:R,measureWidth:-1,measureHeight:-1,isFit:m});let Q=-1,tt=-1;const et=r.length;for(let e=0;e<et;e++){const n=r[e],o=v||!n.isFit,s=n.maxVal,i=n.style,a=n.colWidth;if(Q=0,tt=0,s!==Number.MIN_SAFE_INTEGER){const e=bf(t.Number,i,s,b,a,d,o);Q=e.width,tt=e.height;const r=n.minVal;if(r*s<0){const e=bf(t.Number,i,r,b,a,d,o);Q=Math.max(Q,e.width),tt=Math.max(tt,e.height)}if(n.hasZero&&0!==r&&0!==s){const e=bf(t.Number,i,0,b,a,d,o);Q=Math.max(Q,e.width),tt=Math.max(tt,e.height)}}const l=n.text;if(l.length>0){const e=bf(t.String,i,l,b,a,d,o,void 0,C);Q=Math.max(Q,e.width),tt=Math.max(tt,e.height)}if(n.hasTrue||n.hasFalse){const e=bf(t.Boolean,i,!n.hasFalse,b,a,d,o);Q=Math.max(Q,e.width),tt=Math.max(tt,e.height)}if(n.hasEmpty){const e=bf(t.Boolean,i,null,b,a,d,o);Q=Math.max(Q,e.width),tt=Math.max(tt,e.height)}n.measureWidth=Q,n.measureHeight=tt}if(l){const t=[];for(let e=0;e<et;e++){let n=r[e];const o=n.col;let s=r[e+1],i=n.measureWidth??0;for(;s&&s.col===o;)s.measureWidth&&(i=Math.max(s.measureWidth??0,i)),e++,n=r[e],s=r[e+1];0===i&&(i=null);const a=N(i,n.spanWidth);t.push({address:{min:o,max:o},update:{size:a,autoSize:!0}})}this._colHeaders.updateHeaderPairs(t,A)}if(c){let t=1;const e={onUpdate:(e,n,r)=>{if(!(t>1))return null===e?n:Math.max(n,e)}};let n=[];for(let o=0;o<et;o++){const s=r[o];t=s.spanHeight;n=ca(la(n,{min:s.minRow,max:s.maxRow,value:s.measureHeight},e))}const o=n.length,s=new Array(o);for(let t=0;t<o;t++){const e=n[t],r=T(e.value,1),o={address:{min:e.min,max:e.max},update:{size:r,autoSize:!0}};s[t]=o}this._rowHeaders.updateHeaderPairs(s,A)}}this._commitAndAutoSelect(m,g,r?.autoSelect,{viewAfter:{ranges:n}})}catch(t){throw m.rollback(),t}}_createRangeEvent(t,e){const n=this,r=()=>{const e=n._getState();return this._closed||e.deleted?Vf(null):t?Array.isArray(t)?n._createRanges(t):n._createRange(t):Vf(this,this._entireCoords)},o=e.trigger;return{getSource:r,getFrom:()=>e.from??null,getTo:()=>e.to??null,trigger:o,isUndo:e.isUndo??!1,isDataChange:e.isDataChange??!1,isTransactional:e.isTransactional??!0,toString:()=>`SheetRangeEvent: ('${o}', ${r().toString()})`,timeStamp:e.timeStamp??Date.now()}}_notifyAddressListeners(t,e,n,r){const o=e.entries();let s=o.next();const i=r.trigger;for(;!s.done;){const e=s.value[0];let a=s[1];if(a||(a=t.get(e)),a&&!n.has(e)){let t=!1;const o=a.options;o&&(t="address"===i?o.ignoreAddressChanges:o.ignoreDataChanges),!0!==t&&a.notify(r),n.add(e)}s=o.next()}}_notifyDataListeners(t,e,n=null,r,o){if(!t)return;const s=n.length;for(let i=0;i<s;i++){const s=n[i];if(!s)continue;const a=t.search(s),l=a.length;for(let t=0;t<l;t++){const n=a[t].value.groupId;if(!r.has(n)){const t=e.get(n);!0!==t.options?.ignoreDataChanges&&t.notify(o),r.add(n)}}}}_notifyRangeListeners(t,e,n=null,r){if(!t)return;const o=new Set;r.timeStamp||(r.timeStamp=Date.now());const s=n.length;for(let i=0;i<s;i++){const s=n[i];if(!s)continue;const a=t.search(s),l=a.length;for(let t=0;t<l;t++){const n=a[t].value.id;if(o.has(n))continue;const s=e.get(n);o.add(n);const i=s.ranges,l=i.length;for(let t=0;t<l;t++){const e=i[t],n=this._createRangeEvent(e,r);this._notifyRangeListener2(s,n,r)}}}}_notifyRangeListener2(t,e=null,n=null){const r=t.options;if(r?.ignoreDataChanges&&n?.isDataChange)return;const o=t.handler??t.handlerW.deref();if(o)try{o?.(e)}catch(t){console.warn(t)}}_notifyUsedRangeChange(){this._lastCellRead.coords=null,this._lastUsedCoordsRead.coords=null,this._emitter.notify("onUsedRangeChange")}_notifyMergeChange(){this._emitter.notify("onMergesChange")}addListeners(t,e){let n=null;if(t.onLayoutChange){const r=t,o={onSizesChange:()=>{r.onLayoutChange(this)}};n=[],n.push(this._colHeaders.addListeners(o,e)),n.push(this._rowHeaders.addListeners(o,e))}let r=this._emitter.addListeners(t,e);if(n){const t=r;r=()=>{const e=n.length;for(let t=0;t<e;t++)n[t]();t()}}return r}_addRangesListeners(t,e,n){if(this._closed)throw new Error(Ad);if(!e)throw new Error(yd);n=n?{...Vw,...n}:Vw;const r=n?.transactional??!1,o=this,s=kw++%Number.MAX_SAFE_INTEGER,i=()=>{let t=null,e=null;if(r){const n=o._getState();if(!n)return;t=n.rangeListenerSpatial.clone(),e=new Map(n.rangesListenerMap)}else t=o._rangeListenerSpatial,e=o._rangesListenerMap;const n=e.get(s);if(!n)return void console.log("Listener not found");const i=n.ranges,a=i.length;for(let e=0;e<a;e++){const n=W.sanitizeRange(i[e]);null!==n&&t.remove(n,(t,e)=>{if(e.value.id===s)return!0})}if(e.delete(s),r){const n=this._beginCommit({description:"Remove Range Listener"});this._updateState({rangeListenerSpatial:t,rangesListenerMap:e}),n.commit({forceAmend:!0})}},a=[...t];let l={id:s,handler:null,handlerW:null,removeListener:i,options:n,ranges:a};n?.weakly?l.handlerW=new WeakRef(e):l.handler=e;let c=null,h=null,u=null;if(r){u=this._beginCommit({description:"Add Range Listener"});const t=this._getState();c=t.rangeListenerSpatial.clone(),h=new Map(t.rangesListenerMap)}else c=o._rangeListenerSpatial,h=o._rangesListenerMap;const d=[],g=t.length;for(let e=0;e<g;e++){const r={...t[e],value:{id:s,offset:e,options:n}};d.push(r)}return c.load(d),h.set(s,l),u&&(this._updateState({rangeListenerSpatial:c,rangesListenerMap:h}),u.commit({forceAmend:!0})),i}_addRangesListeners2(t,e,n,r){if(this._closed)throw new Error(Ad);if(!e)throw new Error(yd);n=n?{...Vw,...n}:Vw;const o=n?.transactional??!1,s=this,i=_t.uuidV4(),a=Lw++,l=()=>{let t=null,e=null;const n=s._getState();if(!n)return;t=n.rangesListenerSpatial2.clone(),e=n.rangesListenerMap2;const r=e.get(i);if(r){const o=r?.spatialsIds,s=r?.coords,a=o.length;for(let e=0;e<a;e++){const n=o[e],r=s[e];t.remove(r,(t,e)=>{if(e.value.uuid===n)return!0})}e=new Map(n.rangesListenerMap2),e.delete(i)}const l=this._beginCommit({description:"Remove Range Listener"});this._updateState({rangesListenerMap2:e}),l.commit({forceAmend:!0}),o||this._rangesListenerSorted.delete(a)};let c=null,h=this._beginCommit({description:"Add Range Listener"});const u=this._getState();c=u.rangesListenerSpatial2.clone();let d=null,g=null;n?.weakly?g=new WeakRef(e):d=e;const m=[],f=[...t];let p=[];const _=t.length;for(let e=0;e<_;e++){const r={...t[e]};f[e]=r;const o=_t.uuidV4(),s=new dw(i,o,n?.ignoreAddressChanges??!1);p.push(o);const a={...W.sanitizeRange(r),value:s};m.push(a)}c.load(m),n={...n};const S=new gw(i,p,f,r,this,a,d,g,l,n),w=new Map(u.rangesListenerMap2);return w.set(i,S),this._updateState({rangesListenerSpatial2:c,rangesListenerMap2:w}),o||this._rangesListenerSorted.set(a,S),h.commit({forceAmend:!0}),l}_getUsedCoords(t){const e=this._getState();if(!e)return null;let n=e.cellValuesGrid.getCoords();return n=W.unionRanges(e.mergeSpatial.getBoundingCoords(),n),n=W.unionRanges(e.directStyleSpatial.getBoundingCoords(),n),n=W.unionRanges(e.formulaSpatial.getBoundingCoords(),n),n=W.unionRanges(e.spillSpatial.getBoundingCoords(),n),n=W.unionRanges(e.pendingSpatial.getBoundingCoords(),n),n&&(n.colStart=Math.max(n.colStart,this._entireCoords.colStart),n.rowStart=Math.max(n.rowStart,this._entireCoords.rowStart),n.colEnd=Math.min(n.colEnd,this._entireCoords.colEnd),n.rowEnd=Math.min(n.rowEnd,this._entireCoords.rowEnd)),!n||n.rowStart>n.rowEnd||n.colStart>n.colEnd?(this._lastUsedCoordsRead.coords=null,null):(this._lastUsedCoordsRead&&this._lastUsedCoordsRead.coords&&Jf(this._lastUsedCoordsRead.coords,n)||(this._lastUsedCoordsRead.coords=n,this._lastUsedCoordsRead.range=null),this._lastUsedCoordsRead.coords)}_isContentful(t,e){return!!this._contentCounts(t,void 0,e)}_getCount(t,e=!1){const n=this._contentCounts(t,Gw,e);return n?n[Gd.Content.Values]??0:0}_contentCounts(t,e,n){if(!e){const t=Object.keys(Gd.Content),n=t.length;e=new Array(n);for(let r=0;r<n;r++){const n=t[r];e[r]=Gd.Content[n]}}const r={},o=e.length;let s,i,a=!1;for(let t=0;t<o;t++){const n=e[t];n===Gd.Content.Values?(r[dd.Type.Contentful]=!1,r[dd.Type.Table]=!1):n===Gd.Content.Formulas?r[dd.Type.Formula]=!1:n===Gd.Content.Formats?r[dd.Type.Style]=!1:n===Gd.Content.Tables&&(r[dd.Type.Table]=!1,a=!0)}const l=()=>{s=new Set,i={};for(let t=0;t<o;t++){const n=e[t];i[n]=0}},c=t.length;for(let e=0;e<c;e++){const o=t[e],c=this._rangeStateIterator({includeRangeTypes:r,excludeHidden:n,bounds:o});let h=c.next();for(;!h.done;){i||l();const t=h.value,e=(t.end.colIndex-t.start.colIndex+1)*(t.end.rowIndex-t.start.rowIndex+1),n=t.intersection;if(n){n.contentful&&(i[Gd.Content.Values]+=e),n.formula&&(i[Gd.Content.Formulas]+=e);const t=n.table;t&&(a&&!s.has(t)&&(i[Gd.Content.Tables]+=1,s.add(t)),n.contentful||(i[Gd.Content.Values]+=e))}h=c.next()}}return i}getSelectedCell(){const t=this.getSelection().getCoords().cell,e=this._lastCellSelected;if(e?.cell&&W.isEqualCells(t,e.coords))return e.cell;const n=this.getRange(t).getCell();return this._lastCellSelected={coords:t,cell:n},n}find(t,e){return this.getEntireRange().find(t,e)}_find(t,n,r){if(this._closed)throw new Error(Ad);if(!n)return null;const o=[...t],s=r?.orientation??e.Orientation.Row,i=r?.reverse,a=!r?.disableWrap,l=r?.from?this._cellToCoords(r?.from):null;let c=null;if(l){let t=-1;for(let e=0;-1===t&&e<o.length;e++)W.isCellWithinRange(l,o[e])&&(t=e);c=W.cellToRange(l);let e=zh(o[t],c,s);e.push(c);const n=W.createRangeComparator(s,i);e.sort(n);let r=-1;const h=e.length;for(let t=0;t<h;t++){n(e[t],c)<=0&&(r=t)}o.splice(t,1,...e);const u=t+r,d=[];for(let t=0;t<=u;t++)d.push(o.shift());if(a){const t=d.length;for(let e=0;e<t;e++)o.push(d[e])}}if(0===o.length)return Gl;const h=r?.fields?.includes(Gd.Content.Formulas)??!1,u=r?.fields?.includes(Gd.Content.Values)??!0,d=r?.matchEntireCell??!1,g=r?.matchCase??!1,m=r?.useRegex??!1,f=((t,e,n)=>{const r=e?"":"i";return n?new RegExp(t,r):new RegExp((t=>{let e=t.replace(/[|\\{}()[\]^$+.]/g,"\\$&");return e=e.replace(/~\?/g,"\\?"),e=e.replace(/~\*/g,"\\*"),e=e.replace(/~~/g,"~"),e})(t),r)})(n,g,m),p=n.length;let _=(t,e)=>{const n=t=>{if(!t)return!1;let e=!!t.match(f);return e&&d&&t.length!==p&&(e=!1),e},r=e.getCell();let o=!1;return!o&&h?o=n(r.getFormulaText()??r.toTextUnformatted(!0)):u&&(o=n(r.getNumberFormat().displayText)),o};if(r?.matchCustom){const t=r.matchCustom,e={matchCase:g,matchEntireCell:d,useRegex:m,fields:r?.fields??[Gd.Content.Formulas]};let n,o,s=_;const i=()=>s(n,o);_=(r,s)=>(n=r,o=s,t(r,i,e,s))}let S=-1,w=null,y=Ul,E=!1;const b=()=>{if(y.done){if(S++,S>=o.length)return void(E=!0);w=this._cellIterator({reverse:i,orientation:s,includeRangeTypes:!1,bounds:o[S]})}if(y=w.next(),!y.done){const t=y.value;return _(t.value,t.context)}return!1};return{next:()=>{let t=null;for(;!E&&!t;)b()&&(t=y.value.context.getCell());return t?{value:t,done:!1}:Ul}}}isDate1904(){return this._isDate1904}_surroundingRegion(t,e){const n=this._getState(),r=e?.contentOnly??!1,o=this._entireCoords;if(!r){const e=n.tableSpatial.search(t);if(e.length>0){const n=e[0].value.model,r=n.getUsedRange().getCoords(),s=n.getRange().getCoords();return W.isEqualRanges(r,t)?s:W.isEqualRanges(s,t)?o:r}}const s=r?t:o,i=((t,e,n=2e4)=>{if(!e||0===e.length)return null;let r,o=!1;for(let n=0;n<e.length;n++){const s=e[n];r=W.unionRanges(r,s.getBoundingCoords()),o=o||s.search(t).length>0}if(!r)return null;const s={...W.EmptyRange},i=t;let a=o?{...t}:null;if(!a){const n=t=>{let n=[];const r=e.length;for(let o=0;o<r;o++){const r=e[o].search(t),s=r.length;n=s>0?new Array(s):void 0;for(let t=0;t<s;t++){const e=r[t];n[t]=e}}return n||_t.EmptyArray},r=n({colStart:t.colEnd,rowStart:t.rowEnd,colEnd:t.colEnd+1,rowEnd:t.rowEnd+1}),o=r.length;if(o>0){a={...t};for(let t=0;t<o;t++){const e=r[t];a.colEnd=Math.max(a.colEnd,e.colStart),a.rowEnd=Math.max(a.rowEnd,e.rowStart)}}}const l={...W.EmptyRange},c=()=>{const t=e.length;for(let n=0;n<t;n++){const t=e[n].search(s),r=t.length;for(let e=0;e<r;e++){const n=t[e];a=W.unionRanges(a,n,l)}}return a};s.colStart=t.colStart,s.rowStart=t.rowStart,s.colEnd=t.colEnd,s.rowEnd=t.rowEnd,c();const h={...a},u={...W.EmptyRange};let d=0;do{if(s.colStart=u.colStart=h.colStart,s.rowStart=u.rowStart=h.rowStart,s.colEnd=u.colEnd=h.colEnd,s.rowEnd=u.rowEnd=h.rowEnd,h.colStart>r.colStart&&(s.colStart=h.colStart-1,s.colEnd=h.colStart-1,s.rowStart=h.rowStart-1,s.rowEnd=h.rowEnd+1,c()),h.rowStart>r.rowStart&&(s.rowStart=h.rowStart-1,s.rowEnd=h.rowStart-1,s.colStart=h.colStart-1,s.colEnd=h.colEnd+1,c()),h.colEnd<r.colEnd&&(s.colStart=h.colEnd+1,s.colEnd=h.colEnd+1,s.rowStart=h.rowStart-1,s.rowEnd=h.rowEnd+1,c()),h.rowEnd<r.rowEnd&&(s.rowStart=h.rowEnd+1,s.rowEnd=h.rowEnd+1,s.colStart=h.colStart-1,s.colEnd=h.colEnd+1,c()),!a)return null;if(h.colStart=a.colStart,h.rowStart=a.rowStart,h.colEnd=a.colEnd,h.rowEnd=a.rowEnd,W.isEqualRanges(h,u))return W.isEqualRanges(i,h)?null:h;if(W.isEqualRanges(h,i))return null;if(W.isEqualRanges(h,u))return h;d++}while(d<n);return null})(t,[n.contentfulSpatial,n.mergeSpatial,n.formulaSpatial,n.spillSpatial,n.pendingSpatial]);return i||s}_extendRange(t,n){if(this._closed)throw new Error(Ad);const r=this._entireCoords,o=this,s={excludeHidden:!0,onEntry:(t,e)=>e},i={excludeHidden:!0,onEntry:(t,e)=>void 0===t.tvTl()?null:e};let a;const l=o._getRangedEntries("mergeSpatial",[W.cellToRange(n)],i);l.length>0&&(a=l[0]);const c=[t=>o._getRangedEntries("mergeSpatial",t,i),t=>o._getRangedEntries("contentfulSpatial",t,s)];return((t,n,r,o,s)=>{let i,a,l,c={...n},h=W.cellToRange(c),u=o(h).length>0;if(u){let n=1,s=t===e.Direction.Up||t===e.Direction.Down;r&&(n+=s?r.rowEnd-r.rowStart:r.colEnd-r.colStart),t!==e.Direction.Left&&t!==e.Direction.Up||(n=-n),s?c.rowIndex=c.rowIndex+n:c.colIndex=c.colIndex+n,h=W.cellToRange(c),u=o(h).length>0}switch(t){case e.Direction.Up:h.rowStart=Math.min(s.rowStart,h.rowStart),a=o(h).sort(W.createRangeComparator(e.Orientation.Row,!0)),i=n.rowIndex,l=u?1===a.length&&i===a[0].rowStart?s.rowStart:a[0].rowStart:0===a.length?s.rowStart:a[0].rowEnd;break;case e.Direction.Down:h.rowEnd=Math.max(s.rowEnd,h.rowEnd),a=o(h).sort(W.createRangeComparator(e.Orientation.Row,!1)),i=n.rowIndex,l=u?1===a.length&&i===a[0].rowEnd?s.rowEnd:a[0].rowEnd:0===a.length?s.rowEnd:a[0].rowStart;break;case e.Direction.Left:h.colStart=Math.min(s.colStart,h.colStart),a=o(h).sort(W.createRangeComparator(e.Orientation.Column,!0)),i=n.colIndex,l=u?1===a.length&&i===a[0].colStart?s.colStart:a[0].colStart:0===a.length?s.colStart:a[0].colEnd;break;case e.Direction.Right:h.colEnd=Math.max(s.colEnd,h.colEnd),a=o(h).sort(W.createRangeComparator(e.Orientation.Column,!1)),i=n.colIndex,l=u?1===a.length&&i===a[0].colEnd?s.colEnd:a[0].colEnd:0===a.length?s.colEnd:a[0].colStart}if(u&&a.length>1){let n=!1;for(let r=1;!n&&r<a.length;r++){const o=a[r];switch(t){case e.Direction.Up:o.rowEnd<l-1?n=!0:l=Math.min(l,o.rowStart);break;case e.Direction.Down:o.rowStart>l+1?n=!0:l=Math.max(l,o.rowEnd);break;case e.Direction.Left:o.colEnd<l-1?n=!0:l=Math.min(l,o.colStart);break;case e.Direction.Right:o.colStart>l+1?n=!0:l=Math.max(l,o.colEnd)}}}const d=W.cellToRange(n);switch(t){case e.Direction.Up:d.rowStart=l;break;case e.Direction.Down:d.rowEnd=l;break;case e.Direction.Left:d.colStart=l;break;case e.Direction.Right:d.colEnd=l}return d})(t,n,a,t=>{const e=[],n=[t],r=c.length;for(let t=0;t<r;t++){const r=(0,c[t])(n),o=r.length;for(let t=0;t<o;t++){const n=r[t];e.push(n)}}return e},r)}_defaultFontDims(){if(this._defaultFontBoundsCache)return this._defaultFontBoundsCache;const t=this._styles.getNormal();let e=0,n=0;for(let r=0;r<=9;r++){const o=t.measureText(r.toString());e=Math.ceil(Math.max(o.width,e)),n=Math.max(o.lineHeight,n)}return this._defaultFontBoundsCache={width:e,height:n},this._defaultFontBoundsCache}getColumnWidthAsFontUnit(t){const e=Math.round(this._defaultFontDims().width),n=t/(this.getView().isShowFormulas()?2:1);if(!e||!t)return 0;let r=5;return n<r+e&&(r=n*(r/(r+e))),(n-r)/e}_defaultColWidth(){if(this._defaultColWidthCache)return this._defaultColWidthCache;const t=this._defaultFontDims()?.width||7,e=8*Math.round((8*t+5)/8);return this._defaultColWidthCache=e}_defaultRowHeight(){if(this._defaultRowHeightCache)return this._defaultRowHeightCache;let t=this._defaultFontDims();if(!t||0===t.width)return this._defaultRowHeightCache=20/fi.getDeviceScale(),this._defaultRowHeightCache;const e=this._styles.getNormal(),n=new Map;let r=t.height+2;return this._colHeaders.getUsedRange().forEachSpan((t,o)=>{const s=o.getCellHeader();s?.getStyle()!==e&&(r=Math.max((t=>{let e=n.get(t);void 0===e&&(e=t.measureText("M").lineHeight+2,n.set(t,e));return e})(s.getStyle()),r))}),this._defaultRowHeightCache=Math.round(r/fi.getDeviceScale()*4)/4,this._defaultRowHeightCache}getProtection(){return this._protection??null}async _selectSheet(t,e){if(!1===await(this._options.container?.requestSelect?.()))return!1;if(!1===e)return!0;const n={coords:t};!0!==e&&void 0!==e&&(n.scrollIntoView=e);const r=await this._emitter.notify("onRequestScrollIntoView",{params:n,async:!0});if(!r)return!1;const o=r.length;for(let t=0;t<o;t++)if(!1===r[t])return!1;return!0}async scrollTo(t,e){const n={...e,coords:t},r=await this._emitter.notify("onRequestScrollIntoView",{params:n,async:!0});if(!r)return!1;const o=r.length;for(let t=0;t<o;t++)if(!1===r[t])return!1}async _commitAndAutoSelect(t,e,n=!1,r){return r={...r,viewAfter:{view:this.getView(),selection:e,selectOptions:n,...r?.viewAfter}},t.commit(r),this._autoSelect(n,e)}async _autoSelect(t,e){if(!t)return;!0===t&&(t={autoFocus:!0,scrollIntoView:!0});const n=t?.autoFocus,r=t?.scrollIntoView,o=t?.anchor,s=this.getSelection().getCoords(),i=np(e??s),a=this._entireCoords,l=((t,e,n)=>{if(!t||0===t.length||!e)return _t.EmptyArray;const r=[...t];for(let t=0;t<r.length;t++){const o={...r[t]};let s=o;const i=e.search(o),a=o.rowStart<=n.rowStart&&o.rowEnd>=n.rowEnd,l=o.colStart<=n.colStart&&o.colStart>=n.colEnd;for(let t=0;t<i.length;t++){const e=i[t];a||(s.colStart=Math.min(s.colStart,e.colStart),s.colEnd=Math.max(s.colEnd,e.colEnd)),l||(s.rowStart=Math.min(s.rowStart,e.rowStart),s.rowEnd=Math.max(s.rowEnd,e.rowEnd))}r[t]=s}return r})(i,this._getState().mergeSpatial,a);let c=-1,h=null;if(!o){const t=s?.cell;for(let e=0;-1===c&&e<l.length;e++){const n=l[e];W.isCellWithinRange(t,n)&&(c=e,h=t)}}const u=ep(l,h,c);this.getSelection().updateCoords(u);const d=u.ranges?.[u.rangeIndex]??W.cellToRange(u.cell),g=await this._selectSheet(d,r);if(!1!==r&&!1===g)return l;if(!1!==n){const t=await this._emitter.notify("onRequestFocus");if(!t)return l;const e=t.length;for(let n=0;n<e;n++)if(!1===t[n])return l}return l}getSelection(){return this._rangeSelection}getView(){return this._view}setView(t){if(this._closed)throw new Error(Ad);if(!t)throw new Error("View can not be empty.");this._viewRemoveListener?.(),this._view=t,this._viewRemoveListener=t.addListeners(this._viewListener,{transactional:!1});const e=this.getSelection().getCoords();return this._rangeSelection.updateCoords(e),this._emitter.notify("onMovableSelectionChange"),this._emitter.notify("onTopLeftChange"),this._emitter.notify("onFreezeSplitChange"),this._emitter.notify("onViewChange",{source:t}),this}getTabColor(){return this._tabColor}setTabColor(t){if(this._closed)throw new Error(Ad);return this._tabColor="string"==typeof t?this._styles.parseColor(t):t??null,this._emitter.notify("onTabColorChange"),this}getRowHeaders(){return this._rowHeaders}getColumnHeaders(){return this._colHeaders}async toJSON(n=!1){if(this._closed)throw new Error(Ad);await this._emitter.notify("onBeforeSave",{async:!0}),await Promise.resolve(this._starting);let r={};const o=this._getState();if(!o)return r;try{const o=this._strings.beginPersist();try{if(!n){const n=[],s=this._cellStateIterator({includeRangeTypes:!1,orientation:e.Orientation.Column});let i=s.next(),a=Number.MIN_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER,c=null,h=null,u=null,d=null;for(;!i.done;){const e=i.value[0],r=e.colIndex,g=e.rowIndex;r!==a&&(d&&n.push(d),c=[],u=[],d=[r,u],a=r,l=g-2),g>l+1&&(c=[],h=[g,c],u.push(h));const m=i.value[1],f=Kh(m);let p;if(f===t.Number||f===t.Boolean)p=m;else if(f===t.String){p=""+o.add(m)}else if(f===t.Error)p={t:f,v:m.getCode()};else if(f===t.RichData){const t=m,e=t.type,n=t?.toJSON?.();if(e&&n){p={t:f,v:0}}}else console.warn("error",p);c.push(p),l=g,i=s.next()}d&&n.push(d),n.length>0&&(r.data=n)}this._ownStrings&&(r.strings=await o.toJSONAsync())}catch(t){console.warn("error",t)}finally{o.endPersist()}const s=this._colHeaders.toJSON();s&&(s.headers&&s.headers.length>0&&(r.cols=s.headers),void 0!==s.defaultSize&&-1!==s.defaultSize&&(r.defaultColSize=s.defaultSize));const i=this._rowHeaders.toJSON();i&&(i.headers&&i.headers.length>0&&(r.rows=i.headers),void 0!==i.defaultSize&&-1!==i.defaultSize&&(r.defaultRowSize=i.defaultSize));const a=this.getProtection().toJSON();a&&(r.protection=a),this._view.setRangeSelection(this.getSelection().getCoords());const l=this._view.toJSON();l&&(r.view=l),this._tabColor&&(r.tabColor=this._tabColor.toString())}catch(t){console.warn(t)}const s=tc(o.mergeSpatial.all());s.length>0&&(r.merges=Ou(s));const i=tc(o.directStyleSpatial.all());if(i.length>0){const t=this._styles.beginPersist();try{const e=[],n=i.length;for(let r=0;r<n;r++){const n=i[r],o=t.getElementID(n.value.toJSON());e.push({r:ip.rangeToString(n),v:o})}if(r.directStyles=e,this._ownStyles){const e=t.toJSON();e&&Object.keys(e).length>0&&(r.styles=e)}}catch(t){console.warn(t)}finally{t.endPersist()}}const a=tc(o.hyperlinkSpatial.all()),l=a.length;if(l>0){const t=[];for(let e=0;e<l;e++){const n=a[e];let r=n.value;t.push({r:ip.rangeToString(n),v:r})}r.hyperlinks=t}const c=tc(o.commentsSpatial.all()),h=c.length;if(h>0){const t=[];for(let e=0;e<h;e++){const n=c[e],r={...n.value};r.ref=ip.rangeToString(n),t.push(r)}r.comments=t}const u=this._resources.beginPersist();try{const t=this.getMovables().search(),e=t.length;if(e>0){const n=[];for(let r=0;r<e;r++)try{const e=t[r].toJSON(u.toResourceId.bind(u));e&&n.push(e)}catch(t){console.warn("Unable to persist movable",t)}n.length>0&&(r.movables=n)}this._ownResources&&(r.resources=await u.toJSONAsync())}catch(t){console.warn(t)}finally{u.endPersist()}const d=tc(o.tableSpatial.all()),g=d.length;if(g>0){const t=[];for(let e=0;e<g;e++){const n=d[e].value.model.toJSON();t.push(n)}r.tables=t}const m=Array.from(o.conditionalModels.values()),f=m.length;if(f>0){const t=[];for(let e=0;e<f;e++){const n=m[e].model.toJSON();t.push(n)}r.conditionals=t}const p=await o.calcGraph.toJSON(!1);if(p){const t=p.formulas;t&&(r.formulas=t);const e=p.dynamic;e&&(r.dynamicArray=e);const n=p.volatile;n&&(r.volatile=n)}return this._emitter.notify("onSave",{params:r}),r}getStyles(){return this._styles}getResources(){return this._resources}getTransactions(){return this._transactions}getStrings(){return this._strings}_searchMovables(t){const e=t?.excludeHidden??!1,n=t?.bounds,r=t?.fullyContained,o=this,s=t?.address?this._rangeToCoords(t?.address):this._entireCoords,i=this._getRangedEntries("movableSpatial",[s],{excludeHidden:e,fullyContained:r,onEntry:r=>{if(t?.type&&r.model.getContent().getType()!==t.type)return null;let s=null;if(e){if(r.model.isHidden())return null;if(s=o._getBoundsAtCoords(r.model.getAnchorCoords()),0===s.width||0===s.height)return null}if(n){s||(s=o._getBoundsAtCoords(r.model.getAnchorCoords()));const t=s,e=n;if(t.y>e.y+e.height||t.y+t.height<e.y||t.x>e.x+e.width||t.x+t.width<e.x)return null}return r.model}}),a=i.sort((t,e)=>t.getZIndex()-e.getZIndex());return a}_updateSelectedMovables(t,e){const n=this.getView().getMovableSelection();if(!n||0===n.length)return;let r="Movables";if(1===n.length){const t=n[0];r=Hs(t.getContent().getType())??"Drawing"}const o=this._beginCommit({description:`${e} ${r}`});try{const e=n.length;for(let r=0;r<e;r++){t(n[r])}o.commit()}catch(t){throw o.rollback(),t}}async _addMovable(t){if(!this.getProtection().isObjectsAllowed())throw new Error(Ed);if(!t)throw new Error("No movable options provided");if(this._closed)throw new Error(Ad);const e={};t?.type&&(e.content={type:t.type,json:t?.json}),t?.anchorType&&(e.anchorType=t?.anchorType),t.bounds&&(e.anchor=null);const n=this._getState().movableSpatial,r=this._beginCommit({description:t?.description??"Insert Drawing"}),o=this._createMovableEntry(e,n.size(),t.fromResourceId),s=n.clone();s.insert(o);const i=this._getState().movableMapModel,a=new Map(i),l=o.value.model;a.set(l,o),this._updateState({movableSpatial:s,movableMapModel:a}),t.bounds&&o.value.model.setBounds(t.bounds,t);let c=null,h=null;if(!1!==t?.autoSelect){c={view:this.getView(),movableSelection:this.getView().getMovableSelection()};let e=t?.autoSelect??!1;!0===e&&(e={autoFocus:!0,scrollIntoView:!0,addToSelection:!1}),e&&this.getView().selectMovables([o.value.model],e.addToSelection),h=t=>({...t,view:this.getView(),movableSelection:this.getView().getMovableSelection()})}return r.commit({viewBefore:c,viewAfter:h}),this._emitterMovables.notify("onCollectionChange"),this._emitter.notify("onMovablesChange"),o.value.model}async _addImage(t,e={type:"picture"}){if(!t)throw new Error("An image must be provided as a string or a resource option.");if(!this.getProtection().isObjectsAllowed())throw new Error(Ed);const n=this._resources.add(t),r=await n.toBuffer(),o=await n.getType(),s=this._getBoundsAtCoords(np(this.getSelection().getCoords())[0]),{naturalDimensions:i,asUrl:a}=await It.loadImageDetails(r,o);URL.revokeObjectURL(a);const l={...s,...i,...e?.bounds};if(_t.isNullOrUndefined(e?.bounds?.x)||_t.isNullOrUndefined(e?.bounds?.y)){const t=OS(this.getMovables(),l,_t.isNullOrUndefined(e?.bounds?.x),_t.isNullOrUndefined(e?.bounds?.y));l.x+=t.x,l.y+=t.y}e?.bounds&&!1!==e?.json?.lockAspect&&(_t.isNullOrUndefined(e?.bounds.width)&&_t.isDefined(e?.bounds.height)&&(l.width=l.height*i.width/i.height),_t.isNullOrUndefined(e?.bounds.height)&&_t.isDefined(e?.bounds.width)&&(l.height=l.width*i.height/i.width));const c={...e?.json,resId:0};return await this._addMovable({anchorType:Fl.Type.OneCell,description:"Insert Image",...e,bounds:l,type:"picture",json:c,fromResourceId:t=>0!==t?(console.warn("received an unexpected resourceId",t),null):n})}getTables(){return this._tables}getConditionals(){return this._conditionals}getMovables(){return this._movables}_doPerfTest(t=1e7,e=!1){const n=Array.from({length:t},(t,e)=>e);let r,o;r=performance.now(),e&&console.profile("nativeArray");const s=[t];for(let e=0;e<t;e++)s.push(e);e&&console.profileEnd("nativeArray"),window.noLoseArray=s,o=performance.now(),console.log(`NativeArray: ${t} records in ${o-r} milliseconds`),r=performance.now(),e&&console.profile("mixedType");const i=Sh.fromArray(n);e&&console.profileEnd("mixedType"),window.noLoseList=i,o=performance.now(),console.log(`MixedTypedList: ${t} records in ${o-r} milliseconds`)}_validateOrRemoveOverlaps(t,e,n=null,r=!1){const o=this;"merge"!==e&&Ph(this._getMerges([t]),t,(t,n)=>{if(n||!r)throw new Error(bd(e));o._unmerge([t])});const s=[],i=this.getTables().search({address:t}),a=i.length;for(let t=0;t<a;t++){const e=i[t];n!==e&&s.push(e.getAnchorCoords())}Ph(s,t,(t,n,o)=>{if(n||!r)throw new Error(bd(e));i[o].delete()})}_addTable(t,n){let r=this._rangeToCoords(t,()=>["objects"]);const o=this._entireCoords;let s=n?.hasHeader;if(r.rowStart===r.rowEnd){if(r.rowEnd===o.rowEnd)throw new Error("A table must have a least two rows; one for the table header and one for data.");r.rowEnd=r.rowEnd+1}if(void 0===s){const t=Zf(this,r);s=t?.options?.hasHeader??!1}const i=rp([r]),a={...r},l=this._beginCommit({description:"Insert Table"});let c=null;try{s||(this._isContentful([r])&&this._insertCells([{...r,rowStart:r.rowStart,rowEnd:r.rowStart}],e.Orientation.Row),r={...r,rowEnd:r.rowEnd+1});const t={...n?.json,ref:r};this._validateOrRemoveOverlaps(r,"table",null,!0),t.styleOptions=n?.json?.styleOptions??{},void 0===t.styleOptions.name&&(n?.styleName?t.styleOptions.name=n.styleName:void 0===n?.styleName&&(t.styleOptions.name=this._styles.getDefaultTableStyle().getName()));const o=n?.isLoad;!0!==o&&(void 0===t.filter&&(t.filter={}),void 0===t.sort&&(t.sort={}));const h=this._createTableEntry(t,s&&!o),u=this._getState(),d=u.tableSpatial.clone();d.insert(h);const g=u.tableMapModel,m=new Map(g),f=h.value.model;m.set(f,h);const p=u.tableMapName,_=new Map(p);_.set(f.getName().toLocaleLowerCase(),f),n?.clearFormatting&&this.getRange(r).updateStyle(null),c=h.value.model,this._updateState({tableSpatial:d,tableMapModel:m,tableMapName:_}),this._emitter.notify("onTablesChange"),o||this._autoFit([c.getHeaderRange().getCoords()],{expandOnly:!0});const S=rp([r]);l.commit({viewBefore:{view:this.getView(),selection:i,ranges:[a]},viewAfter:{view:this.getView(),selection:S,ranges:[r]}})}catch(t){throw l.rollback(),t}return c}_addConditional(t,e){const n=this._rangesToCoords(t,()=>["objects"]),r=e?.autoSelect?rp(n):null,o=[...n],s=this._beginCommit({description:e?.description??"Insert Conditional"});let i=null;try{const t={...e,ref:o},n=this._getState(),a=n.conditionalSpatial.clone(),l=new Map(n.conditionalModels),c=this._createConditionalEntries(t,a,l);this._updateState({conditionalSpatial:a,conditionalModels:l}),i=c,s.commit({viewBefore:{view:this.getView(),selection:r,ranges:o},viewAfter:{view:this.getView(),selection:r,ranges:o}}),this._autoSelect(e?.autoSelect,r)}catch(t){throw s.rollback(),t}return i}createTemporaryCell(t,e=null){if(t?.createTemporaryCell)return t;return(e?this.getRange(e).getCell():this._emptyCell).createTemporaryCell(t)}_getBoundsAtCoords(t){const e=this._rowHeaders,n=this._colHeaders,r=n.findOffset(t.colStart),o=e.findOffset(t.rowStart);return{x:r,y:o,width:n.findOffset(t.colEnd+1)-r,height:e.findOffset(t.rowEnd+1)-o}}_getCoordsAtBounds(t){const e=this._rowHeaders,n=this._colHeaders;return{colStart:n.findIndex(t.x),rowStart:e.findIndex(t.y),colEnd:n.findIndex(t.x+t.width),rowEnd:e.findIndex(t.y+t.height)}}getRangeAtBounds(t,e){if(!t)throw new Lt;const n=this._getCoordsAtBounds(t);return this.getRange(n,e)}_getVisible(t,n){if(0===t.length)return t;const r=new Lc;r.load(t);const o=n?.orientations??e.Orientations.Both,s=(t,e)=>{const n=r.search(t),o=n.length;for(let s=0;s<o;s++){const o=n[s],i=zh(o,t,e);r.remove(o),r.load(i)}},i=this._cellOptions.maxCoords;if(o===e.Orientations.Both||o===e.Orientations.Row){const n=this._rowHeaders,r=t.length;for(let o=0;o<r;o++){const r=t[o];n.getRange({min:r.rowStart,max:r.rowEnd}).forEachSpan((t,n)=>{if(0!==t)return;const r=n.getCoords();s({colStart:i.colStart,rowStart:r.min,colEnd:i.colEnd,rowEnd:r.max},e.Orientation.Row)})}}if(o===e.Orientations.Both||o===e.Orientations.Column){const n=this._colHeaders,r=t.length;for(let o=0;o<r;o++){const r=t[o];n.getRange({min:r.colStart,max:r.colEnd}).forEachSpan((t,n)=>{if(0!==t)return;const r=n.getCoords();s({colStart:r.min,rowStart:i.rowStart,colEnd:r.max,rowEnd:i.rowEnd},e.Orientation.Column)})}}return r.all()}_hasRangedEntries(t,e){const n=this._getState();if(!n)return _t.EmptyArray;const r=n[t];if(!r)throw new Error(`Invalid range key ${t}`);return!(!r||r.isEmpty())&&r.has(e)}_getRangedEntries(t,n,r){if(0===n.length)return _t.EmptyArray;const o=r?.excludeHidden??!1,s=r?.fullyContained??!1,i=r?.onEntry??null,a=this._getState();if(!a)return _t.EmptyArray;const l=a[t];if(!l)throw new Error(`Invalid range key ${t}`);if(!l||l.isEmpty())return _t.EmptyArray;const c=new Set,h=t=>{const e=t.length;for(let n=0;n<e;n++){const e=t[n];c.add(e)}},u=n.length;for(let t=0;t<u;t++){const r=n[t];if(o){if(!0===o){const t={min:r.colStart,max:r.colEnd},e={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(e).forEachVisibleSpan((e,n)=>{this._colHeaders.getRange(t).forEachVisibleSpan((t,r)=>{h(l.search({colStart:t,rowStart:e,colEnd:r,rowEnd:n},s))},Hw)},Hw)}else if(o===e.Orientation.Column){const t={min:r.colStart,max:r.colEnd};this._colHeaders.getRange(t).forEachVisibleSpan((t,e)=>{h(l.search({colStart:t,rowStart:r.rowStart,colEnd:e,rowEnd:r.rowEnd},s))},Hw)}else if(o===e.Orientation.Row){const t={min:r.rowStart,max:r.rowEnd};this._rowHeaders.getRange(t).forEachVisibleSpan((t,e)=>{h(l.search({colStart:r.colStart,rowStart:t,colEnd:r.colEnd,rowEnd:e},s))},Hw)}}else h(l.search(r,s))}if(0===c.size)return _t.EmptyArray;const d=Array.from(c.values()),g=r?.sort;g&&d.sort(W.createRangeComparator(g.orientation,g.reverse));let m=[];const f=d.length;for(let t=0;t<f;t++){let e;e=void 0,i&&(e=i(d[t].value,d[t])),void 0===e&&(e=d[t].value),null!==e&&m.push(e)}return m||(m=_t.EmptyArray),m}_processAnchorShift(t){let e=t.after;const n=W.sanitizeRange(t.after),r=W.sanitizeRange(t.before);t.after&&this._validateCoords(n,"We can't insert cells because this would push items off the end of the worksheet.");const o=t.before.value.processShiftCallback?.({...t,after:n,before:r});return o?(Jf(o,n)||(e||(e=t.before),e={...e,...o}),e):e}_processListenerShift(t,e,n,r){if(r.isSplit||r.before.value.options.ignoreShifts)return[r.before];let o=null;r.after&&(o=W.intersectRanges(W.sanitizeRange(r.after),this._entireCoords),r.after,o.colStart,o.rowStart,o.colEnd,o.rowEnd);const s=r.before.value,i=s.id,a=t.get(i),l={...a},c=[...a.ranges];l.ranges=c,c[s.offset]=o?{...c[s.offset],...o}:null,t.set(i,l);const h=n.get(i);e.set(i,{beforeState:h,afterState:l})}delete(){if(this._closed)return;try{this._emitter.notify("onBeforeDelete")}catch(t){throw t instanceof Error?t:new Error(t.message??"Unable to delete.")}const t=this._beginCommit({description:`Delete Sheet '${this.getName()}'`}),n=this._getState();let r=n.rangeListenerSpatial,o=n.rangesListenerMap;const s=new Map;r=r.shift({range:this._entireCoords,direction:e.Direction.Left,cloneIfUpdate:r===n.rangeListenerSpatial,onShift:t=>{o===n.rangesListenerMap&&(o=new Map(o)),this._processListenerShift(o,s,n.rangesListenerMap,t)}}),this._updateState({rangeListenerSpatial:r,rangesListenerMap:o,deleted:!0}),this._deleteCells([this._entireCoords]),this._emitter.notify("onDelete"),this._rangesListenerMap.forEach((t,e)=>{s.set(e,{beforeState:t,afterState:null})}),t.commit({viewAfter:t=>({...t,view:this.getView(),selection:this.getSelection().getCoords(),listeners:s})})}doBatch(t,e){const n=this;return e="string"==typeof e?{description:e}:{description:"Update Sheet",...e},this._transactions.doBatch(t,e,(t,r)=>{if(0===t.getDepth()&&(n._lastTransactionUUID=t.getId(),e?.autoSelect)){const e=t.getView()?.selection;e&&n._autoSelect(!0,e)}})}isClosed(){return this._closed}close(){if(this._closed)return;this._protectionRemoveListener?.(),this._protection=new xw(void 0,this._options.readonly);const t=this._getState().tableMapModel.keys();for(const e of t)e.close();this._searchMovables().forEach(t=>{t.close()}),this._emitter.notify("onClose"),this._ownResources,this._namesRemoveListener?.(),this._ownNames&&this._names.close(),this._ownsCalculation&&this._calculation.close(),this._ownStyles,this._colHeaders.close(),this._rowHeaders.close(),this._emitter.close(),this._transactionsRemoveListener?.(),this._closed=!0}beginCommit(t){if(this._closed)throw new Error(Ad);return this._beginCommit("string"==typeof t?{description:t}:t)}_getState(){return this._closed?null:this._transactions.getState(this)}_beginCommit(t){const e=this;return this._transactions.beginCommit(t,t=>{0===t.getDepth()&&(e._lastTransactionUUID=t.getId())})}_updateState(t){if(!t)return;this._lastGetRangeRead=null;const e=this._transactions.beginCommit();let n;try{n=e.updateState(this,t),e.commit()}catch(t){throw e.rollback(),t}return n}_addEvent(t,e){const n=this.getTransactions().getPendingView();if(!n)return;let r=n.events;if(r||(r={},n.events=r),"address"===t){let t=r.address;if(t||(t=new Map,r.address=t),"string"==typeof e)t.set(e,null);else{const n=e;if(n.options.ignoreAddressChanges)return;t.set(n.uuid,e)}}else if("data"===t)if("string"==typeof e){let t=r.dataListeners;t||(t=new Map,r.dataListeners=t),t.set(e,null)}else{let t=r.data;t||(t=[],r.data=t),t.push(e)}}_getScalar(t,e,n=!1){const r=this._getState();let o;if(void 0===o){o=r.cellValuesGrid.getValueAt(t,e)}if(void 0===o)return null;let s=o;if(n&&"number"==typeof s){let n=!1;$w.colStart=e,$w.rowStart=t,$w.colEnd=e,$w.rowEnd=t;const o=this._lastValueRead,i=this._lastValueRead.range;if(i&&W.isRangeWithinRange($w,i))n=o.isDateOrTime;else{const i=r.directStyleSpatial.search($w)[0];if(i){const r=i.value.getPropertiesAt(t,e,s),a=r?.numberFormat;a&&(n=Os(a)||Ls(a)),o.range=i,o.isDateOrTime=n}else o.range=null;n&&(s=ys(s,this._isDate1904))}}return s}getStyleUpdater(t,e){return null}_initState(){const t=this,n=()=>{t._lastCellDecoded.address=null,t._lastCellSelected.coords=null,t._lastCellRead.coords=null,t._lastValueRead.range=null,t._lastGetRangeRead={},t._lastUsedCoordsRead.coords=null,t._lastActiveRead.selection=null,t._lastRangeRead.address=null};this._transactionsRemoveListener=this._transactions.addStateListener(this,{onBeforeCommitStart(e,n,r){if(!t._initializing&&!n?.skipProtectionCheck){if(t.getProtection().isLocked())throw new Error(_d)}},async onBeforeCommitEnd(e,n,r){if(n?.ranges){const o={isDataChange:!0,isTransactional:!0,timeStamp:r.getTimestamp(),trigger:"setCells"},s=e.rangeListenerSpatial,i=e.rangesListenerMap;t._notifyRangeListeners(s,i,n.ranges,o)}if(n?.listeners){const o={isDataChange:!1,isTransactional:!0,timeStamp:r.getTimestamp(),trigger:"shiftCells"},s=e.rangeListenerSpatial,i=e.rangesListenerMap;t._notifyRangeListeners(s,i,n.ranges,o)}},async onRestoreOrRevert(e,r,o,s){n(),t._calculateFull(),r&&(r.view===t.getView()&&r.selection&&t._autoSelect(!0,r.selection),r.movableSelection&&t.getView().selectMovables(r.movableSelection)),t._emitter.notify("onInvalidated"),t._emitterMovables.notify("onInvalidated"),t._notifyUsedRangeChange();if(t._rangesListenerMap.size>0){const n={isDataChange:!0,isTransactional:!1,timeStamp:o.getTimestamp(),isUndo:s,trigger:"invalidate"},r=e.rangeListenerSpatial,i=e.rangesListenerMap,a=new Set;i.forEach((e,o)=>{const s=e.id;if(a.has(s))return;const l=e.ranges;l&&(a.add(s),t._notifyRangeListeners(r,i,l,n))})}},async onAfterStateChange(e,r,o,s,i){n(),r&&o.getId()!==t._lastTransactionUUID&&r.view===t.getView()&&r.selection&&(s||i)&&t._autoSelect(!0,r.selection),t._lastTransactionUUID=o.getId(),r?.merges&&t._notifyMergeChange();const a=t._rangesListenerSorted;if(a.size>0){t._notifyUsedRangeChange();const n=new Set,l=e.rangesListenerMap2,c={isTransactional:!1,timeStamp:o.getTimestamp()};if((i||s)&&(c.trigger="restore",t._notifyAddressListeners(l,l,n,c),a.size>l.size)){const t=a.values();let e=t.next(),n=!1;for(;!n&&!e.done;){const r=e.value;n=l.has(r.uuid),n||(r.notify(c,"#N/A"),e=t.next())}}const h=r?.events;h&&(h.address&&(c.trigger="address",t._notifyAddressListeners(l,h.address,n,c)),h.dataListeners&&(c.trigger="data",t._notifyAddressListeners(l,h.dataListeners,n,c)),h.data&&(c.trigger="data",t._notifyDataListeners(e.rangesListenerSpatial2,e.rangesListenerMap2,h.data,n,c)))}if(r&&r.ranges&&!r.initial&&e.calcGraph.calculate(),r?.ranges){t._notifyUsedRangeChange();const e=t._rangesListenerMap;if(e.size>0){const n={isDataChange:!0,isTransactional:!1,timeStamp:o.getTimestamp(),isUndo:s,trigger:"setCells"};t._notifyRangeListeners(t._rangeListenerSpatial,e,r.ranges,n)}}},onClose(){const e=t._getState();e&&e.movableSpatial.clear()}});const r=new HS({sheet:this}),o={onChange(){t._emitter.notify("onSelectionChange")}},s=r.addListeners(o,{transactional:!1});this._rangeSelection=r,this._rangeSelectionRemoveListener=s;const i=e=>{const n=t._getState();if(!n)return;const r=n.movableSpatial,o=e.length;for(let t=0;t<o;t++){const n=r.search(e[t]),o=n.length;for(let t=0;t<o;t++){const e=n[t].value;e.processLayoutCallback?.()}}};this._colHeadersListener={onSizesChange:(e,n)=>{const r=[];if(n){const e=n.length;for(let o=0;n&&o<e;o++){const e={colStart:n[o].min,rowStart:t._entireCoords.rowStart,colEnd:t._entireCoords.colEnd,rowEnd:t._entireCoords.rowEnd};r.push(e)}}i(r)}},this._rowHeadersListener={onSizesChange:(e,n)=>{const r=[];if(n){const e=n.length;for(let o=0;o<e;o++){const e=n[o],s={colStart:t._entireCoords.colStart,rowStart:e.min,colEnd:t._entireCoords.colEnd,rowEnd:t._entireCoords.rowEnd};r.push(s)}}i(r)}};let a=new Set;const l={onTopLeftChange(){t._emitter.notify("onTopLeftChange")},onFreezeSplitChange(){t._emitter.notify("onFreezeSplitChange")},onRangeSelectionChange(){const e=t.getSelection().getCoords();t._rangeSelection.updateCoords(e)},onMovableSelectionChange(e){const n=e.getMovableSelection(),r=new Map,o=new Set,s=t._getState().movableMapModel,i=n.length;for(let t=0;t<i;t++){const e=n[t];a.has(e)?a.delete(e):r.set(e,t),o.add(e)}a.forEach(t=>{s.get(t)?.value.processSelectionCallback(!1,!1)}),r.forEach((t,e)=>{s.get(e)?.value.processSelectionCallback(!0,0===t)}),a=o,t._emitter.notify("onMovableSelectionChange")},onAnyChange(){t._emitter.notify("onViewChange")}},c=new _w({sheet:this});this._view=c,this._clearState(),this._viewRemoveListener=c.addListeners(l,{transactional:!1}),this._viewListener=l,this._colHeadersRemoveListener?.();const h=()=>Math.round(this._defaultFontDims().width);this._colHeaders=new aw({sheet:t,orientation:e.Orientation.Column,maxSheetCoords:this._entireCoords,transactions:this._transactions,isProtected:()=>!t._initializing&&!t.getProtection().isFormatColumnsAllowed(),getTextAt:t=>{const e=this.getView().getColumnHeaderStyle();return e===hS.HeaderTextStyle.A1?Nw(t):e===hS.HeaderTextStyle.Zero?Tw(t):e===hS.HeaderTextStyle.One?Fw(t):void 0},defaultSize:()=>{const t=this.getView().isShowFormulas()?2:1;return this._defaultColWidth()/h()*t},scaleFactor:h,maxSize:()=>255,setContainerShiftedCallback:t=>{this._colHeadersShiftCallback=t}}),this._colHeadersRemoveListener=this._colHeaders.addListeners(this._colHeadersListener,{transactional:!0}),this._rowHeadersRemoveListener?.();const u=fi.getDeviceScale();this._rowHeaders=new aw({sheet:t,orientation:e.Orientation.Row,maxSheetCoords:this._entireCoords,transactions:this._transactions,isProtected:()=>!t._initializing&&!t.getProtection().isFormatRowsAllowed(),getTextAt:t=>{const e=this.getView().getRowHeaderStyle();return e===hS.HeaderTextStyle.One?Fw(t):e===hS.HeaderTextStyle.Zero?Tw(t):e===hS.HeaderTextStyle.A1?Nw(t):void 0},defaultSize:()=>this._defaultRowHeight(),scaleFactor:()=>u,minSize:()=>0,maxSize:()=>409,setContainerShiftedCallback:t=>{this._rowHeadersShiftCallback=t}}),this._rowHeadersRemoveListener=this._rowHeaders.addListeners(this._rowHeadersListener,{transactional:!0}),this._defaultFontBoundsCache=null,this._defaultColWidthCache=null,this._defaultRowHeightCache=null;const d={colStart:0,rowStart:0,colEnd:0,rowEnd:0},g=[d],m={excludeHidden:!0,sort:{orientation:e.Orientation.Column,reverse:!1}};this._cellOptions={resolveRange:t=>{const e=this._rangesToCoords(t);return this._createRange(e[0],null)},date1904:this._isDate1904,sheet:this,normalStyleRanged:this._normalStyleRanged,colHeaders:this._colHeaders,styles:this._styles,maxCoords:this._entireCoords,getRange:this.getRange.bind(this),getProtection:this.getProtection.bind(this),calcGraph:()=>this._getState().calcGraph,nextContentful:(e,n,r=!1)=>{d.colStart=r?n:e.colIndex+1,d.rowStart=e.rowIndex,d.colEnd=r?e.colIndex-1:n,d.rowEnd=e.rowIndex,m.sort.reverse=r;const o=t._getRangedEntries("contentfulSpatial",g,m);if(!o||0===o.length)return n;const s=o[0],i=r?s.getState().colStart:s.getState().colEnd;return r?Math.min(i+1,e.colIndex):Math.max(i-1,e.colIndex)},opener:async(t,e,n,r)=>{if(t.startsWith("#")){t=t.substring(1);const n=this._rangesToCoords(t);return await this._autoSelect(e??!0,rp(n)),!0}return window.open(t,n??"_blank",r),!0}},this._emptyCell=new xf(this._cellOptions)}_clearState(){this._lastGetRangeRead=null,this._lastCellDecoded.address=null,this._lastCellSelected.coords=null,this._lastCellRead.coords=null,this._protectionRemoveListener?.(),this._protection=new xw(void 0,this._options.readonly),this._protectionRemoveListener=this._protection.addListeners({onChange(){if(t._closed)throw new Error(Ad);t._getState().movableMapModel.forEach(t=>{t.value.processProtectionCallback?.()}),t._getState().tableMapModel.forEach(t=>{t.value.processProtectionCallback?.()}),t._emitter.notify("onProtectionChange")}}),this._stylesRemoveListener?.();const t=this;this._stylesRemoveListener=this._styles.addListeners({onAnyChange(){t._defaultColWidthCache=null,t._defaultRowHeightCache=null,t._defaultFontBoundsCache=null,t._emitter.notify("onLayoutChange"),t._emitter.notify("onStyleChange")}}),this._view.clear(!1),this._rangeListenerSpatial=new Lc,this._rangesListenerMap=new Map,this._rangesListenerSorted=new ze;const n=e=>{const n=t._getState().rangesListenerSpatial2;if(n.isEmpty())return;const r=e.length;for(let o=0;o<r;o++){const r=e[o],s=n.search(r),i=s.length;for(let e=0;e<i;e++){const n=s[e].value.groupId;t._addEvent("data",n)}}},r=this._entireCoords,o=r.rowEnd,s=r.colEnd,i=this._calculation._createGraph({onCalculated(e){t._realizeCalcedValues(e)},getEntireCoords:()=>t._entireCoords,getSheetName:()=>t.getName()});i.addListeners({onStart(t){},onInvalidate:()=>{}}),this._updateState({rangesListenerSpatial2:new Lc({updateEntryOptions:{onShifted:e=>{let n=t._getState().rangesListenerMap2;if(0===n.size)return;n=new Map(n);const r=e.length;for(let o=0;o<r;o++){const r=e[o],s=r.value.groupId;let i=n.get(s);i=i.processShift(r),t._addEvent("address",i),n.set(s,i)}t._updateState({rangesListenerMap2:n})},onRemoved:e=>{let n=t._getState().rangesListenerMap2;if(0===n.size)return;n=new Map(n);const r=e.length;for(let o=0;o<r;o++){const r=e[o],s=r.value.groupId;let i=n.get(s);i=i.processRemove(r),t._addEvent("address",i),n.set(s,i)}t._updateState({rangesListenerMap2:n})}}}),rangesListenerMap2:new Map,cellValuesGrid:new hh({orientation:this._isDataColumn?e.Orientation.Column:e.Orientation.Row}),formulaSpatial:new Lc,spillSpatial:new Lc,pendingSpatial:new Lc,calcErrorsSpatial:new Lc,calcGraph:i,directStyleSpatial:new Lc({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0,onUpdated:n,onRemoved:n}}),continuousFillSpatial:new Lc({updateEntryOptions:{isMergeOnShift:!0,isTrailingEdge:!0}}),conditionalModels:new Map,conditionalSpatial:new Lc({updateEntryOptions:{onGroupUpdate(e,n){let r=t._getState().conditionalModels,o=r.get(n);if(!o)return;r=new Map(r);const s=o.spatials;o={...o},o.spatials=e,r.set(n,o),t._updateState({conditionalModels:r}),o.processCoordsChange({before:s,after:o.spatials})}}}),mergeSpatial:new Lc({updateEntryOptions:{getShifted:(t,e)=>e?(e.value=new lw(W.sanitizeRange(e),t.value._tvTl,t.value._rsTl),e):null,getSplit(t,e){throw new Error("We can't insert through merges. Unmerge and try again.")},onUpdated:n,onRemoved:n}}),movableMapModel:new Map,movableSpatial:new Lc({updateEntryOptions:{getShifted(e,n,r){const o=e.value.processShiftCallback?.(r);let s=null;const i=new Map(t._getState().movableMapModel),a=e.value.model;return o?(s={...o,value:{...e.value}},i.set(a,s)):i.delete(a),t._updateState({movableMapModel:i}),s}}}),hyperlinkSpatial:new Lc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0}}),commentsSpatial:new Lc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0,onUpdated:n,onRemoved:n}}),tableMapModel:new Map,tableMapName:new Map,tableSpatial:new Lc({updateEntryOptions:{getShifted(e,n,r){const o=new Map(t._getState().tableMapModel),s=e.value.model,i=e.value.processShiftCallback?.(r);let a=null;return i?(a={...i,value:{...n.value}},o.set(s,a)):o.delete(s),t._updateState({tableMapModel:o}),a}}}),filter:null,sort:null,rangeListenerSpatial:new Lc,rangesListenerMap:new Map,contentfulSpatial:new Lc({updateEntryOptions:{isSplitOnExpand:!0,isMergeOnShift:!0,onShifted:e=>{const n=t._getState().rangesListenerSpatial2;if(0===n.size())return;const r=e.length;for(let i=0;i<r;i++){const r=e[i],a=n.search({colStart:r.colStart,rowStart:r.rowStart,colEnd:s,rowEnd:o}),l=a.length;for(let e=0;e<l;e++){const n=a[e].value.groupId;t._addEvent("data",n)}}},onRemoved:n,onUpdated:n}}),unlockSpatial:new Lc({updateEntryOptions:{isMergeOnShift:!0}}),deleted:!1}),this._defaultFontBoundsCache=null,this._defaultColWidthCache=null,this._defaultRowHeightCache=null}_createTableEntry(t,e=!1){const n={model:null,processShiftCallback:null,processDeleteCallback:null,processProtectionCallback:null,currentName:null,removeListener:null};let r=null;r="string"==typeof t.ref?Fu(t.ref,this._entireCoords):t.ref;const o={...r,value:n},s=this,i=()=>n.model?s._getState().tableMapModel?.get(n.model):o,a=(t,e)=>!(!W.isEqualRanges(t,e)||t.value.model!==e.value.model),l={transactions:this._transactions,sheet:this,names:this._names,readSheetHeader:e,json:t,maxRangeCoords:this._entireCoords,setNameOnContainer(t){const e=i().value;if(!e.currentName)return;if(e.currentName.toLowerCase()===t.toLowerCase())return;const n="Set Table Name";s._protectionCheck(()=>["objects"],void 0,n);const r=s._beginCommit({description:n});try{const n=s._getState()?.tableMapName,o=t.toLocaleLowerCase();if(n.has(o))throw new Error((t=>`Name must be unique: '${t}' is already in use.`)(t));const i=new Map(n);i.delete(e.currentName),e.currentName=o,i.set(o,e.model),s._updateState({tableMapName:i}),r.commit()}catch(t){throw r.rollback(),t}},setContainerCoords(t,e){if(!t)return;const n=s._rangeToCoords(t,()=>["objects"]),r=i();if(!r)return;const o=r.value.model;s._validateOrRemoveOverlaps(n,"table",o);const l=s._beginCommit({description:e?.description??"Resize Table"}),h=s._getState(),u=h.tableSpatial.clone(),d=h.tableMapModel,g=new Map(d);u.remove(r,a);const m={...r,...n};return u.insert(m),g.set(m.value.model,m),s._updateState({tableSpatial:u,tableMapModel:g}),l.commit({viewAfter:{view:s.getView(),selection:rp([c.getAnchorCoords()])}}),n},deleteFromContainer(t){const e=i();if(!e)return;const n=e.value.model,r=t?.description??`Delete Table '${n.getName()}`;s._protectionCheck(()=>["objects"],void 0,r);const o=s._beginCommit({description:r}),l=s._getState(),c=l.tableSpatial.clone(),h=l.tableMapModel,u=new Map(h),d=l.tableMapName,g=new Map(d);c.remove(e,a),u.delete(n),g.delete(n.getName().toLocaleLowerCase()),e.value.processDeleteCallback?.(),s._updateState({tableSpatial:c,tableMapModel:u,tableMapName:g}),s._emitter.notify("onTablesChange"),o.commit({viewAfter:{sheet:s,view:s.getView(),selection:rp([n.getAnchorCoords()])}})},setContainerDeleteCallback(t){const e=i()?.value??n;e&&(e.processDeleteCallback=t,e.removeListener?.())},isProtected:()=>!s._initializing&&s.getProtection().isLocked(),setContainerProtectionCallback(t){(i()?.value??n).processProtectionCallback=t},setContainerShiftCallback(t){(i()?.value??n).processShiftCallback=t},processTableUpdate(){s._notifyUsedRangeChange()},initialAnchor:r},c=new bp(l);return o.value.model=c,o.value.removeListener=c.addListeners({onStyleChange(t){s._emitter.notify("onStyleChange")},onDelete(t){s._emitter.notify("onStyleChange")}},{transactional:!1}),o.value.currentName=c.getName().toLocaleLowerCase(),o}_createConditionalEntries(t,e,n){const r="Conditional Format",o=()=>["objects"],s=t??{};let i=null;const a=this._entireCoords;if("string"==typeof s.ref){i=[];const t=s.ref.split(","),e=t.length;for(let n=0;n<e;n++){const e=Fu(t[n],a);e&&i.push(e)}}else i=Array.isArray(s.ref)?s.ref:[s.ref];const l=this,c=_t.uuidV4(),h={model:null,removeListener:null,processCoordsChange:null,spatials:null};n.set(c,h);const u=()=>h.model?l._getState().conditionalModels.get(c):h;let d=t=>(console.log("default createSpatialEntry",t),null);const g=(t,e,n)=>{if(!h.model)return void(i=t);let r=e.spatials;if(r){const t=r.length;for(let e=0;e<t;e++)n.remove(r[e])}let o=[];if(t){const e=t.length;for(let n=0;n<e;n++){const e=t[n];o.push({...e,value:d(e)})}o.length>0&&n.insertGroup(o,c)}e.spatials=o},m=()=>{const t=u().spatials??i;return t?l.getRanges(t):null};var f;return h.model=(f={sheet:l,transactions:l._transactions,json:t,type:"conditional",setOnContainerCoordsChange:t=>{u().processCoordsChange=t},setCreateSpatial(t){d=t},setContainerRanges:(t,e)=>{const n=l._rangesToCoords(t,o);if(!h.model)return i=n,n&&n.length>0?l.getRanges(n):null;const s=l._beginCommit({description:e?.description??`Set ${r} Ranges`});let a=rp(n);try{const t=l._getState();let r=t.conditionalSpatial;r=r.clone();let o=t.conditionalModels;o=new Map(o);let i=u();i={...i},o.set(c,i),g(n,i,r),l._updateState({conditionalSpatial:r,conditionalModels:o}),s.commit({viewBefore:{view:l.getView(),selection:rp(m()?.getCoords())},viewAfter:{view:l.getView(),selection:a}}),l._autoSelect(e?.autoSelect,a)}catch(t){throw s.rollback(),t}return n&&n.length>0?l.getRanges(n):null},getContainerRanges:m,deleteFromContainer(t){let e=u();const n=l._beginCommit({description:t?.description??`Set ${r} Ranges`}),o=t?.autoSelect?rp(e.spatials):void 0;try{const r=l._getState();let s=r.conditionalSpatial;s=s.clone();let i=r.conditionalModels;i=new Map(i),e={...e},g(null,e,s),i.delete(c),l._updateState({conditionalSpatial:s,conditionalModels:i}),this._commitAndAutoSelect(n,o,t?.autoSelect)}catch(t){throw n.rollback(),t}},isReadOnly:()=>!1,setContainerReadOnlyCallback(t){}},new $S({...f,createDescription:`New ${r}`})),h.removeListener=h.model.addListeners({onAnyChange(t){l._emitter.notify("onStyleChange")}},{transactional:!1}),g(i,h,e),h.model}_createMovableEntry(t,e,n){let r=null;if(t?.anchor)r={colStart:t.anchor.tl?.c??0,rowStart:t.anchor.tl?.r??0,colEnd:t.anchor.br?.c??0,rowEnd:t.anchor.br?.r??0},t.anchor.br?.x||(r.colEnd-=1),t.anchor.br?.y||(r.rowEnd-=1);else{const t=np(this.getSelection().getCoords())[0];r={colStart:t.colStart,rowStart:t.rowStart,colEnd:t.colEnd,rowEnd:t.rowEnd}}const o={model:null,processShiftCallback:null,processLayoutCallback:null,processDeleteCallback:null,processZIndexCallback:null,processSelectionCallback:null,processProtectionCallback:null,zIndex:e},s={...r,value:o},i=()=>o.model?c._getState()?.movableMapModel?.get(o.model):s,a=(t,e)=>!(!W.isEqualRanges(t,e)||t.value.model!==e.value.model),l=(t,e,n=!0)=>{if(u)return;const r=i();if(!r)return;const o=e??"Update Drawing";c._protectionCheck(()=>["objects"],void 0,o);const a=c._beginCommit({description:o}),l=c._getState()?.movableSpatial,h=l.clone(),d=c._getState()?.movableMapModel,g=new Map(d);!1!==t(r,h,g)&&(c._updateState({movableSpatial:h,movableMapModel:g}),n&&(c._emitterMovables.notify("onCollectionChange",{source:c,transactional:!0}),c._emitter.notify("onMovablesChange")),a.commit({viewAfter:t=>{if(s.value.model.isSelected()&&!t?.movableSelection?.includes(s.value.model)){const e=[...t?.movableSelection??[]];return e.push(s.value.model),{...t,view:this.getView(),movableSelection:e}}}}))},c=this,h=t.content.type;let u=!0;const d=(t,e,n,r)=>{const o=n.all().sort((t,e)=>t.value.zIndex-e.value.zIndex),s=e.value.zIndex;if((t=Math.max(0,Math.min(o.length-1,t)))===s)return!1;const i=[],l=[],c=[],h=s<t,u=e=>{const n=o[e];i.push(n);const a={...n,value:{...n.value,zIndex:h?e-1:e+1}};n.value.zIndex===s&&(a.value.zIndex=t),l.push(a),r.set(a.value.model,a),c.push(a)};if(h)for(let e=s;e<=t;e++)u(e);else for(let e=s;e>=t;e--)u(e);const d=i.length;for(let t=0;t<d;t++)n.remove(i[t],a);n.load(l);const g=c.length;for(let t=0;t<g;t++)c[t].value.processZIndexCallback?.()},g=()=>c._resources.beginPersist(),m="picture"===h,f={content:null,fromResourceId:n,defaultLockAspectRatio:m,beginPersistResource:g,getMaxBounds:()=>c._getBoundsAtCoords(c._entireCoords),transactions:this._transactions,getBoundsAtCoords:c._getBoundsAtCoords.bind(c),getCoordsAtBounds:c._getCoordsAtBounds.bind(c),scrollIntoView:t=>c._selectSheet(i()?.value.model.getAnchorCoords(),t),select:async t=>{const e=i()?.value.model;if(!e)return!1;try{c.getView().selectMovables([e],t?.addToSelection)}catch(t){return console.warn(t),!1}const n=await c._selectSheet(i()?.value.model.getAnchorCoords(),t?.scrollIntoView);return!t?.scrollIntoView||!1!==n},unselect:()=>{const t=i()?.value.model;return!!t&&(c.getView().unselectMovables([t]),!0)},isSelected:()=>c.getView().getMovableSelection().includes(i()?.value.model),setContainerSelectionCallback(t){(i()?.value??o).processSelectionCallback=t},moveToBackOnContainer:()=>{l((t,e,n)=>d(0,t,e,n),"Move to Back")},moveBackwardOnContainer:()=>{l((t,e,n)=>d(t.value.zIndex-1,t,e,n),"Move Backwards")},moveForwardOnContainer(){l((t,e,n)=>d(t.value.zIndex+1,t,e,n),"Move Forward")},moveToFrontOnContainer(){l((t,e,n)=>d(e.size()-1,t,e,n),"Move To Front")},getZIndex:()=>i()?.value.zIndex??0,setContainerZIndexCallback(t){(i()?.value??o).processZIndexCallback=t},setContainerCoords(t){if(!t)return;const e=c._rangeToCoords(t,()=>["objects"]);return l((t,n,r)=>{const o={...t,...e};n.remove(t,a),n.insert(o),r.set(o.value.model,o)},"Update Drawing",!1),e},deleteFromContainer(t){const e=i();e?.value&&c.getView().unselectMovables([e.value.model]);const n=[];l((t,e,r)=>{r.delete(t.value.model),e.remove(t,a),t.value.processDeleteCallback?.(),n.push(t);const o=t.value.model.getZIndex(),s=e.all().sort((t,e)=>t.value.zIndex-e.value.zIndex),i=[],l=[],c=s.length;for(let t=o+1;t<c;t++){const e=s[t];i.push(e);const n={...e,value:{...e.value,zIndex:t-1}};l.push(n),r.set(n.value.model,n)}const h=i.length;for(let t=0;t<h;t++)e.remove(i[t],a);e.load(l)},t?.description??"Delete Drawing",!0);const r=n.length;for(let t=0;t<r;t++)n[t].value.processZIndexCallback?.()},setContainerDeleteCallback(t){(i()?.value??o).processDeleteCallback=t},isProtected:()=>!c._initializing&&!c.getProtection().isObjectsAllowed(),setContainerProtectionCallback(t){(i()?.value??o).processProtectionCallback=t},setContainerShiftCallback(t){(i()?.value??o).processShiftCallback=t},setContainerLayoutCallback(t){(i()?.value??o).processLayoutCallback=t},initialAnchor:r,maxRangeCoords:this._entireCoords,json:t},p=t.content.json,_={type:h,transactions:this._transactions,beginPersistResource:g,fromResourceId:n,defaultLockAspectRatio:m,json:p};let S=null;if("picture"===h)S=new Vp(_);else if("chart"===h)S=new NS(_);else if("sp"===h||"cxnSp"===h||"grpSp"===h)S=new FS(_);else{if("graphicFrame"!==h)throw new Error((t=>`Unsupported float type: ${t}`)(h));S=new kS(_)}return o.model=new yS({...f,content:S}),u=!1,s}_fromJSON(n){this._initializing=!0,this._emitter.notify("onBeforeLoad",{params:n}),this._clearState();const r=this._beginCommit({description:"Load Sheet",viewAfter:{initial:!0,skipProtectionCheck:!0}}),o=n||{},s=this._strings,i=s.beginPersist(),a=this._resources.beginPersist(),l=this._styles.beginPersist();try{this._ownStrings&&i.fromJSON(o.strings),this._ownResources&&a.fromJSON(o.resources),this._ownStyles&&l.fromJSON(o.styles),this._colHeaders.fromJSON({headers:o.cols,defaultSize:o.defaultColSize}),this._rowHeaders.fromJSON({headers:o.rows,defaultSize:o.defaultRowSize}),this.setView(new _w({sheet:this,json:o.view})),this._rangeSelection.updateCoords(this._view.getRangeSelection()),o.tabColor&&(this._tabColor=this._styles.parseColor(o.tabColor));let c=this._getState();const h=c.cellValuesGrid,u=c.contentfulSpatial,d=o.data,g=d?.length??0,m=Qf,f=[];if(g>0){for(let e=0;e<g;e++){let n=d[e];"string"==typeof n&&(n=JSON.parse(n));const r=n[1],o=r.length;let i;for(let e=0;e<o;e++){const n=r[e][1],o=n.length;for(let e=0;e<o;e++){let r=n[e],o=r?.t;if(void 0!==o)r=r?.v;else switch(typeof r){case"number":o=t.Number;break;case"boolean":o=t.Boolean;break;case"string":o=t.String,r=parseInt(r)}n[e]=[r,o]}i=m(null,s,n),r[e][1]=i}f.push(n)}h.setValues(f);const e=tp(f,this._isDataColumn);u.load(e)}const p=this._entireCoords,_=c.directStyleSpatial,S=c.continuousFillSpatial,w=this._options.styles;if(n.directStyles){const t=[],e=[],r=n.directStyles,o=(n,r)=>{const o=l.getElementJSON(r),s=new af(w,W.sanitizeRange(n),o),i={...n,value:s};t.push(i);const a=s._p?.alignment?.horizontal;!a||a!==zs.HorizontalAlignment.CenterContinuous&&a!==zs.HorizontalAlignment.Fill||e.push(i)};if(Array.isArray(r)){const t=r.length;for(let e=0;e<t;e++){const t=r[e],n=t.r;o("string"==typeof n?Fu(n,p):n,t.v)}}_.load(t),S.load(e)}c=this._updateState({cellValuesGrid:h,contentfulSpatial:u,directStyleSpatial:_,continuousFillSpatial:S});const y=o.merges;if(y){const t=[],e=y.length;for(let n=0;n<e;n++){const e=Fu(y[n],p);t.push(e)}this._indexMerges(t)}const E=c.hyperlinkSpatial,b=o.hyperlinks;if(b){const t=b,e=[],n=t.length;for(let r=0;r<n;r++){const n=t[r];let o=n.r;o="string"==typeof o?Fu(o,p):W.sanitizeRange(o);let s=n.v;"string"==typeof s&&(s={address:s}),e.push({...o,value:s})}E.load(e)}const v=c.commentsSpatial,C=o.comments;if(C){const t=C,e=[],n=t.length;for(let r=0;r<n;r++){const n=t[r];let o=n.ref;o="string"==typeof o?Fu(o,p):W.sanitizeRange(o);const s={...n};delete s.ref,e.push({...o,value:s})}v.load(e)}const x=c.movableMapModel,I=c.movableSpatial;if(o.movables){const t=[],e=o.movables,n=e.length;for(let r=0;r<n;r++){const n=e[r];try{const e=this._createMovableEntry(n,r,a.fromResourceId.bind(a));x.set(e.value.model,e),t.push(e)}catch(t){console.warn("Unable to load movable",r,n,t)}}I.load(t)}const A=c.tableMapModel,R=c.tableMapName,M=c.tableSpatial,T=o.tables;if(T){const t=[],e=T.length;for(let n=0;n<e;n++){const e=T[n],r=this._createTableEntry(e),o=r.value.model;A.set(o,r),R.set(r.value.currentName,o),t.push(r)}M.load(t)}const N=c.conditionalSpatial,F=c.conditionalModels,k=o.conditionals;if(k){const t=k.length;for(let e=0;e<t;e++){const t=k[e];this._createConditionalEntries(t,N,F)}}const O=c.calcGraph,L=O.fromJSON({formulas:o.formulas,data:f,dynamic:o.dynamicArray,volatile:o.volatile});c=this._updateState({hyperlinkSpatial:E,commentsSpatial:v,movableSpatial:I,movableMapModel:x,tableSpatial:M,tableMapModel:A,tableMapName:R,conditionalSpatial:N,conditionalModels:F,calcGraph:O});const D=this._getUsedCoords();D&&this._autoFit([D],{orientations:e.Orientations.Row,skipCustomSize:!0}),r.commit(),L&&this._realizeCalcedValues(L),o.protection&&this._protection.fromJSON(o.protection),this._emitter.notify("onLoad")}finally{l.endPersist(),a.endPersist(),i.endPersist()}this._initializing=!1}getName(){return this._closed?gu:this._options.container?.getName?.()??null}setName(t){if(this._closed)throw new Error(Ad);const e=this._options.container?.setName;if(!e)throw new Error("Unable to set name for sheet.");return e(t),this}getVisibility(){return this._closed?wS.Visibility.VeryHidden:this._options.container?.getVisibility?.()??wS.Visibility.Hidden}setVisibility(t=!0){if(this._closed)throw new Error(Ad);const e=this._options.container?.setVisibility;if(!e)throw new Error("Unable to set visibility for sheet.");let n;return n=!0===t?wS.Visibility.Visible:!1===t?wS.Visibility.Hidden:t,e(n),this}async select(t){return await(this._options.container?.requestSelect?.(t)),this}duplicate(){return this._options.container?.duplicate?.()}setPosition(t){return this._options.container?.setPosition(t),this}getNames(){return this._names}getCalculation(){return this._calculation}get[Symbol.toStringTag](){return"[Sheet]"}toString(){const t=this.getName();return t||"(untitled sheet)"}get isISheet(){return!0}}const Bw={address:null,scope:null},zw={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Pw={colStart:0,rowStart:0,colEnd:0,rowEnd:0},jw={colStart:0,rowStart:0,colEnd:0,rowEnd:0},Hw={includeHidden:!1};Object.freeze({[Gd.Content.Values]:Number.MAX_SAFE_INTEGER,[Gd.Content.Formulas]:Number.MAX_SAFE_INTEGER}),Object.freeze({[Gd.Content.Values]:1,[Gd.Content.Formulas]:1});const Vw={ignoreDataChanges:!1},$w={colStart:-1,rowStart:-1,colEnd:-1,rowEnd:-1},Uw=[{colIndex:-1,rowIndex:-1},null,null,null,null],Gw=[Gd.Content.Values],Ww={size:null,autoSize:!0},qw={skipCustomSize:!0,expandOnly:!0,minContent:!0},Jw={rowStart:0,colStart:0,rowEnd:0,colEnd:0},Xw={showFormulaBar:!0,showTabs:!0,tabRatio:600,showHorizontalScrollbar:!0,showVerticalScrollbar:!0,showStatusBar:!0,activeSheetId:null};class Kw{constructor(t){this._emitter=null,this._emitter=new Ll(this),this._state={...Xw},t?.json&&this._fromJSON(t?.json)}isShowFormulaBar(){return this._state.showFormulaBar}setShowFormulaBar(t){return this._state.showFormulaBar=t,this._emitter.notify("onViewChange"),this}isShowTabs(){return this._state.showTabs}setShowTabs(t){return this._state.showTabs=t,this._emitter.notify("onViewChange"),this}getTabRatio(){return this._state.tabRatio}setTabRatio(t){return this._state.tabRatio=t,this._emitter.notify("onViewChange"),this}isShowHorizontalScrollbar(){return this._state.showHorizontalScrollbar}setShowHorizontalScrollbar(t){return this._state.showHorizontalScrollbar=t,this._emitter.notify("onViewChange"),this}isShowVerticalScrollbar(){return this._state.showVerticalScrollbar}setShowVerticalScrollbar(t){return this._state.showVerticalScrollbar=t,this._emitter.notify("onViewChange"),this}isShowStatusBar(){return this._state.showStatusBar}setShowStatusBar(t){return this._state.showStatusBar=t,this._emitter.notify("onViewChange"),this}getActiveSheetId(){return this._state.activeSheetId}setActiveSheetId(t){return this._state.activeSheetId=t,this._emitter.notify("onViewChange"),this}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){let t={};const e=Object.keys(this._state);for(let n=0;n<e.length;n++){const r=this._state[e[n]];null!=r&&r!==Xw[e[n]]&&(t[e[n]]=r)}return 0===Object.keys(t).length&&(t=null),t}_fromJSON(t,e=!0){let n=t||{};this.update(n,e)}update(t,e=!0){this._state={...Xw,...this._state,...t},e&&this._emitter.notify("onViewChange")}}class Yw{constructor(t){this._emitter=null,this._closed=!1,this._options={...t};const e=this;this._transactions=this._options.transactions??new ie({transient:!0}),this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,n,r){e._emitter.notify("onCollectionChange")}}),this._emitter=new Ll(this,this._transactions),this._initState(t?.initial)}add(t,e,n){const r=this;e&&e.addListeners({onDelete:e=>{r._updateState(e=>{if(!e.modules[t])return;const n=e.modules[t];if(n){const o={...e};return r._options.onRemove?.(t,n),r._emitter.notify("onCollectionChange"),delete o.modules[t],o}return e},"Delete Module")}},{once:!0});const o=this._getState()?.modules,s=o?.[t],i=n?.replace??!1;if(s&&!i)throw new Error(`Already existing '${t}'`);const a={...o};e?(a[t]=e,r._options.onAdd?.(t,e),this._updateState({modules:a},i?"Save Scripts":"Add Script")):(delete a[t],r._options.onRemove?.(t,null),this._updateState({modules:a},"Remove Script")),r._emitter.notify("onCollectionChange")}search(t){const e=this._getState();if(!e)return _t.EmptyArray;const n=e.modules,r=Object.keys(n),o=r.length;if(0===o)return _t.EmptyArray;const s=[],i=t?.name?t.name.toUpperCase():null;for(let t=0;t<o;t++){const e=r[t],o=n[e];let a=!0;i&&i!==e.toUpperCase()&&(a=!1),a&&s.push(o)}return s??_t.EmptyArray}getByName(t){if(!t)return null;const e=this._getState();if(!e)return null;const n=t.toUpperCase(),r=e.modules,o=Object.keys(r),s=o.length;for(let t=0;t<s;t++){const e=o[t];if(n===e)return r[e]}return null}getCount(){const t=this._getState();return t?Object.keys(t.modules).length:0}beginCommit(t){return this._beginCommit(t)}_getState(){if(this._closed)throw new Error(kl);return this._transactions.getState(this)}_beginCommit(t){return this._transactions.beginCommit("string"==typeof t?{description:t}:t)}_updateState(t,e="Update",n){if(!t)return;const r=this._beginCommit(e);try{r.updateState(this,t),r.commit(n)}catch(t){throw r.rollback(),t}}_initState(t){let e=t??{};this._updateState({modules:e},"Initialize",{forceAmend:!0});const n=this._options.onAdd;if(n){const t=Object.keys(e),r=t.length;for(let o=0;o<r;o++){const r=t[o];n(r,e[r])}}}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){const t=this._getState();if(!t)return _t.EmptyArray;const e=t.modules,n=Object.keys(e),r=n.length,o={};for(let t=0;t<r;t++){const r=n[t];o[r]=e[r].toJSON()}return o}isClosed(){return this._closed}close(){this._closed||(this._emitter.notify("onClose"),this._closed=!0,this._transactionsRemoveListener?.())}get isFunctionCollection(){return!0}}let Zw;const Qw="SheetXL",ty=Zw||(Zw=_t.deepFreeze({ISheet:{Visibility:wS.Visibility},ICell:{Content:Gd.Content,CalcStatus:Gd.CalcStatus},IColor:{Named:ba.Named,Scheme:ba.Scheme,Type:ba.Type,AdjustmentType:ba.AdjustmentType},Direction:w}),Zw);let ey;class ny extends G_{constructor(t,e,n,r=null,o=!1){super(t,e,n,r,o)}execute(...t){const e=t[0];if(!e||!e.isIWorkbook)throw new Error(`Macro '${this.getName()}' must be called with a valid workbook as the only argument.`);const n=this._ct;try{const t=[];switch(n){case U_.Context.Workbook:t.push(e);break;case U_.Context.Sheet:t.push(e.getSelectedSheet());break;case U_.Context.Ranges:t.push(e.getSelectedRanges());break;case U_.Context.Range:t.push(e.getSelectedRange());break;default:throw new Error(`Function '${this.getName()}' is not a valid macro function.`)}const r=async(t,e)=>{const n=await e;if(void 0!==n)if(null!==n){if(Array.isArray(n)){if(Kh(n[0]?.[0]))return void t.setValues(n,{skipBoundsCheck:!0})}else if(Kh(n))return void t.setValues([[n]]);n.isICell?t.updateCells(n):n.isICellRange&&await t.copyFrom(n)}else t.clear()};let o;return(async()=>{const n=(await this.getDescriptor()).getSummary()??`Macro '${this.getName()}'`;return await e.doBatch(async()=>{try{const n=e.getSelectedRange();let s=this._cf();if(!s){s=function(t){return new Proxy(t,{set:(t,e,n)=>(console.log(`Adding property "${e}" with value:`,n),t[e]=n,!0),deleteProperty:(t,e)=>(console.log(`Deleting property "${e}"`),delete t[e])})}({})}try{V_({getPosition:()=>n.getCell().getCoords()}),ey=globalThis[Qw],globalThis[Qw]=ty;const e=this._fn;o=e.call(s,...t),ey?(globalThis[Qw]=ey,ey=void 0):delete globalThis[Qw],$_()}catch(t){throw t}finally{$_()}await r(n,o)}catch(t){throw t}},n),{params:t,results:o}})()}catch(t){throw t}}}class ry{constructor(t){this._emitter=null;const e=t.json;if(this._json=e,!this._json)throw new Error("Module JSON is required.");this._emitter=new Ll(this),this._functions=new eS({transactions:null,readonlyFunctions:t.readonlyFunctions})}getFunctions(){return this._functions}getSource(){return this._json.source}getLanguage(){return this._json.language||"typescript"}getErrors(){return null}delete(){this._emitter.notify("onDelete")}addListeners(t,e){return this._emitter.addListeners(t,e)}toJSON(){return this._json}}const oy=async(t,e)=>{let n=null;try{V_(null)}catch(t){console.warn("Error setting global scope",t)}try{const e=new Function("modulePath","return import(modulePath)");n=await e(
8
+ /* @vite-ignore */
9
+ /* webpackIgnore: true */
10
+ `data:text/javascript,${encodeURIComponent(t.compiled)}`)}catch(t){throw new Error("Invalid Javascript module.",{cause:t})}finally{$_()}if(!e)throw new Error(`No function available for '${t.name??t.commitId}'.`);const r=e.name;let o=n[r];if(!o&&e.behavior.default&&(o=n.default),!o)throw new Error(`Found the descriptor for '${r}' but not the function. The descriptor manifest must be corrupt.`);return o},sy=async(t,e=!1)=>{const n=t?.functions,r=new Map;if(n)for(let o=0;o<n.length;o++){const s=n[o],i=s[0],a=s[1];let l,c=e?()=>{}:await oy(t,i);l=i.context&&i.context!==U_.Context.Calculation?new ny(i,c,()=>null,a):new G_(i,c,()=>null,a),r.set(i.name.toUpperCase(),l)}return new ry({json:t,readonlyFunctions:r})};class iy{constructor(t){this._options=t,this._initState()}_initState(){}getModules(){return this._modules}async createModule(t){const e=await import("./MRXgg6FvbB08Ze4M.mjs").then(t=>t.i),n=await e.ScriptingUtils.compileTypescript(t);return n?await sy(n,t?.declarationsOnly??!1):null}addModule(t,e,n){this._modules.add(t,e,n)}executeMacro(t,e){const n=this._modules.search({name:e}),r=n.length;for(let e=0;e<r;e++){const r=n[e].getFunctions().getByName(t);if(r)return r.execute(this._options.workbook)}throw new Error(`No macro ${t} found.`)}searchFunction(t){const e=t?.name,n=t?.moduleName,r=t?.type,o=this._modules;if(!o)return _t.EmptyArray;const s=o.getCount();if(0===s)return _t.EmptyArray;if(n){const t=this._modules.search({name:n});return 0===t.length?_t.EmptyArray():t[0].getFunctions().search({name:e,type:r})}const i=this._modules.search();for(let t=0;t<s;t++){const n=i[t].getFunctions().search({name:e,type:r});if(n.length>0)return n}return _t.EmptyArray}async start(){if(this._modules)return Promise.resolve();const t=this._options?.workbook,e=this._options?.json;let n={};if(e){const t=Object.keys(e);for(let r=0;r<t.length;r++){const o=t[r],s=e[o],i=await sy(s);n[o]=i}}const r=new Yw({transactions:this._options?.transactions,initial:n,onRemove:this._options?.onRemove,onAdd:this._options?.onAdd});this._modules=r;const o=r.search();if(0===o.length)return Promise.resolve(_t.EmptyArray);const s=o.length;for(let e=0;e<s;e++){const n=o[e];try{const e=n.getFunctions().search({type:"autoRun"}),r=e.length;for(let n=0;n<r;n++){const r=e[n];await r.execute(t)}}catch(t){console.error("Error executing autoRun script:",t)}}}toJSON(){const t=this._modules;if(!t)throw new Error("Scripts is initializing.");return t.toJSON()}}const ay=Object.freeze({lockStructure:!1,lockWindows:!1,lockRevision:!1,workbookPassword:null,revisionsPassword:null});class ly extends vw{isWindowsAllowed(){return this._isPropertyAllowed("windows")}isRevisionAllowed(){return this._isPropertyAllowed("revision")}isStructureAllowed(){return this._isPropertyAllowed("structure")}_fromJSON(t){this._properties=t}_toJSON(t){let e=this._properties;if(e){t={...t,...e};const n=Object.keys(e),r=n.length;for(let o=0;o<r;o++){const r=n[o],s=e[r];null!=s&&s!==ay[r]&&(t[r]=s)}}return super._toJSON(t)}}const cy=t=>`Invalid SheetKey: ${t}`,hy="A workbook must contain at least one visible worksheet.",uy="Internal error no visible sheetRefs",dy="Workbook has been closed. No further operations are allowed.",gy="This workbook structure is protected. To make a change, unprotect the workbook. You might be requested to enter a password.",my="A sheet name",fy=`${my} can not be blank.`,py=`${my} can not be longer than 31 characters.`,_y=`${my} can not begin or end with a "'" (single quote).`;class Sy{constructor(t,e){this._add=t,this._get=e}add(t){return this._add(t)}search(t){return this._get(t?.name,t?.visibility)}getByName(t){return this._get(t)?.[0]??null}getCount(){return this._get().length}}const wy=new RegExp(/[\\/\\*?:[\]]+/),yy=new RegExp(/\(((\d+)(?!.*\d))\)$/,"g"),Ey=t=>`Sheet${t+1}`,by=(t,e)=>({...Hf,getSource:()=>null,toString:()=>Tu(t,e)}),vy=(t,e=!1)=>{if(!t)throw new Error(fy);if(wy.test(t)){if(!e)throw new Error((t=>`${t?`'${t}'`:my} can not contain any of the following characters '\\ , / , * , ? , : , [ , ]'.`)(t));t=t.replace(wy,"")}if(0===t.length)throw new Error(fy);const n=t.length;if(n>31){if(!e)throw new Error(py);t=t.substring(0,31)}if("'"===t.charAt(0)||"'"===t.charAt(n-1)){if(!e)throw new Error(_y);t=t.replace(/^'|'$/g,"")}return t};class Cy extends Iw{constructor(t,e,n,r){super(t,e,r),this._workbook=n}getSource(){return this._workbook}_createRanges(t,e){let n=this._options;return e&&(n={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Cy(t,this._sheet,this._workbook,n)}_createRange(t,e){const n=t?{...t}:null;if(!(n?this._workbook._getSheetRef(n.sheetName,wS.Visibility.VeryHidden):null)){const t=this._workbook.getSelectedSheet();return delete n?.sheetName,by(n,n?{sheetName:gu,...t.getEntireRange().getCoords()}:null)}let r=this._options;return e&&(r={...this._options,getOptions:Yf(this._options.getOptions,e)}),new xy(t,this._sheet,this._workbook,r)}async select(t){const e=[];let n=null;const r=this.getCoords();for(let t=0;t<r.length;t++){const o=r[t];o&&(n||(n=o.sheetName),o&&o.sheetName===n&&e.push(o))}n||(n=this._workbook.getSelectedSheet().getName());const o=this._workbook.getSheets().getByName(n);if(!o)return;const s=await o.getRanges(e).select(t),i=this._workbook._rangesAddressToCoords(s.getCoords());return this._createRanges(i,t)}addListener(t,e){if(!this.getCoords())return()=>{};const n=this._workbook._sheetToWBEvent(t);return super.addListener(n,e)}get[Symbol.toStringTag](){return"[WorkbookRanges]"}toString(){const t=this.getCoords(),e=this._sheet,n=e.getEntireRange().getCoords(),r={sheetName:e.getName(),...n};return Lu(t,r,Tu,Cu)}}class xy extends Aw{constructor(t,e,n,r){super(t,e,r),this._workbook=n}_createRanges(t,e){let n=this._options;return e&&(n={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new Cy(t,this._sheet,this._workbook,n)}_createRange(t,e){const n=this._sheet;if(!t)return Vf(n,n._entireCoords);if(n._validateCoords(t),n._closed)return Vf(null,n._entireCoords,t);let r=this._options;return e&&(r={...this._options,getOptions:Yf(this._options?.getOptions,e)}),new xy(t,this._sheet,this._workbook,r)}getSource(){return this._workbook}get[Symbol.toStringTag](){return"[WorkbookRange]"}toString(){const t=this._sheet,e=t?.getEntireRange().getCoords()??null;return Tu(this.getCoords(),{...e,sheetName:t.getName()})}addListener(t,e){if(!this.getCoords())return()=>{};const n=this._workbook._sheetToWBEvent(t);return super.addListener(n,e)}}class Iy{constructor(t){this._lastTransactionUUID=null,this._closed=!1,this._initializing=!0,this._emitter=null,this._names=null,this._calculation=null,this._isDate1904=!1;const e=this,n={...t},r=n.json;delete n.json,this._transactions=n.transactions??new ie,this._ownTransactions=!n.transactions,this._emitter=new Ll(this,this._transactions);const o=this._beginCommit({description:(r?"Open":"New")+" Workbook"});try{this._strings=n.strings??new Pp,this._ownStrings=!n.strings,this._resources=n.resources??new Bp,this._ownResources=!n.resources,this._createSheetName=n.createSheetNameCallback??Ey;let t=n.createSheetCallback;t||(t=t=>new Dw(t)),this._sheetOnNameChange=new Map,this._sheetOnVisibilityChange=new Map,this._sheetOnIndexChange=new Map,this._createSheet=(n,r,o,s,i)=>{let a=null;const l={date1904:e.isDate1904(),readonly:e._options.readonly??!1,transactions:e._transactions,styles:e._styles,strings:e._strings,resources:e._resources,names:e._names,calculation:e._calculation,resolveRange:t=>e._options.resolveRange?.(t)??e.getRange(t),container:{beforeFromJSON:t=>{a=t,e._addSheetRef({name:r,id:n,visibility:o??wS.Visibility.Visible,sheet:t},s)},getName:()=>{const t=e._getSheetRef(a);return t?t.name:e._createSheetName(1)},setName:t=>{e._getSheetRef(a)&&e._setSheetName(a,t)},getIndex:()=>{const t=e._getSheetRef(a);return t?e._findOffsetForId(t.id,e._getSheetRefs(wS.Visibility.VeryHidden)):-1},setIndexCallback:t=>{e._sheetOnIndexChange.set(n,t)},setNameChangeCallback:t=>{e._sheetOnNameChange.set(n,t)},getVisibility:()=>{const t=e._getSheetRef(a);return t?t.visibility:wS.Visibility.Visible},setVisibility:t=>{e._setSheetVisibility(a,t)},setVisibilityCallback:t=>{e._sheetOnVisibilityChange.set(n,t)},duplicate:()=>e._duplicateSheet(a),setPosition:t=>{const n=e._getSheetRef(a,wS.Visibility.VeryHidden);return!!n&&(e._moveSheet(n,t),!0)},requestSelect:async()=>(e._setSelectedSheet(a),await this._emitter.notify("onRequestSelect",{source:e,params:a,async:!0}),e.getSelectedSheet()===a)}};return i&&(l.json=i),a=t(l,r,s,o),a},this._names=n.names??new TS({addressToRanges:t=>e.getRanges(t),getCurrentScope:()=>e.getSelectedSheet().getName(),isReadOnly:()=>e._options.readonly??!1,transactions:e._transactions}),this._ownNames=!n.names,this._calculation=n.calculation??new nS({getNamed:(t,e)=>{try{Ay.address=t,Ay.scope=e;const n=this._names.search(Ay);return n&&0!==n.length?n[0].getRanges().getCoords():null}catch(t){return null}},getSheetIndex:t=>{if(void 0===t)return e.getSelectedSheetIndex();const n=this._getSheetRefs(wS.Visibility.Hidden);t=t.toLowerCase();for(let e=0;e<n.length;e++)if(n[e].name.toLowerCase()===t)return e;try{Ay.address=t,Ay.scope=void 0;const e=this._names.search(Ay);if(!e||0===e.length)return-1;const n=e[0].getRanges().getCoords()?.[0];let r=n?.sheetName;if(!r)return-1;const o=this._getSheetRefs(wS.Visibility.Hidden);r=r.toLowerCase();for(let t=0;t<o.length;t++)if(o[t].name.toLowerCase()===r)return t}catch(t){return-1}return-1},getSheetCount:()=>e.getSheets().getCount(),isDate1904:()=>e.isDate1904(),strings:e._strings,transactions:e._transactions}),this._ownsCalculation=!n.calculation,this._scripts=this._createScripts(),this._ownNames=!n.names,this._options={...n};const s=async()=>{this._ownsCalculation&&await this._calculation.start(),await this._scripts.start(),this._starting=null};this._starting=s(),r?this._fromJSON(r):(this._initState(),this._addSheet(!1)),this._emitter.notify("onLoad"),o.commit()}catch(t){throw o.rollback(),t}this._sheets=new Sy(t=>e._addSheetOptions(t),(t,e)=>t?[this.getSheet(t,e)]:this._getSheets(e)),this._initializing=!1}_initState(){let t=this._getSheetRefs();for(let e=t&&t.length-1;e>=0;e--);this._isDate1904=this._options.date1904??!1,this._theme=this._options.theme??(new Tl).getDefaultTheme(),this._styles=this._options?.styles??new Fp(this._theme),this._ownStyles=!this._options.styles,this._styles.getTheme()||this._styles.setTheme(this.getTheme()),this._activeSheetOffset=0,this.setView(new Kw),this._listenerProtection?.(),this._protection=new ly(void 0,this._options.readonly??!1),this._listenerProtection=this._protection.addListeners({onChange:t=>{e._emitter.notify("onProtectionChange")}});const e=this;this._transactionsRemoveListener=this._transactions.addStateListener(this,{onAfterStateChange(t,n,r){if(n&&void 0!==n.activeSheetId&&n.view===e.getView()&&r.getId()===e._lastTransactionUUID&&e._getSheetRef(n.activeSheetId)?.sheet.select(),n&&r.getId()!==e._lastTransactionUUID){let r=e.getView().getActiveSheetId();n.view===e.getView()&&(r=n.activeSheetId);let o=0;try{o=e._findOffsetForId(r,t.sheetRefsVisible)}catch(t){}e._activeSheetOffset=o}e._lastTransactionUUID=r.getId(),e._notifyAllChange()},onRestoreOrRevert(){e._emitter.notify("onInvalidated")}});const n=this._getState();n?.listenersSheets&&(n?.listenersSheets.forEach(t=>{t()}),n?.listenersSheets.clear()),this._updateState({sheetRefsAll:[],sheetRefsVisibleAndHidden:[],sheetRefsVisible:[],refsById:new Map,sheetsById:new Map,refsByLowerCaseName:new Map,sheetsByLowerCaseName:new Map,refsByInstance:new Map,lastId:-1,sheetsCreated:new Set,listenersSheets:new Map})}getView(){return this._view}setView(t){if(this._closed)throw new Error(dy);if(!t)throw new Error("View can not be empty.");this._listenerWorkbookView?.();const e=this;return this._listenerWorkbookView=t.addListeners({onViewChange:t=>{const n=e._getState();this._activeSheetOffset=this._findOffsetForId(this._view.getActiveSheetId(),n.sheetRefsVisible),e._emitter.notify("onViewChange")}}),this._view=t,e._emitter.notify("onViewChange"),this}isDate1904(){return this._isDate1904}setDate1904(t){if(this._closed)throw new Error(dy);return this._isDate1904=t,this._notifyAllChange(),this}getStyles(){return this._styles}getResources(){return this._resources}getTransactions(){return this._transactions}getStrings(){return this._strings}getTheme(){return this._theme}setTheme(t){if(this._closed)throw new Error(dy);if(!t)throw new Error("A value must be provided.");const e=this._theme;return this._theme=t,this.getStyles().setTheme(t),this._emitter.notify("onThemeChange"),e}getSelectedSheetIndex(){return this._activeSheetOffset}getSelectedSheet(){const t=this._getSheetRef(this.getSelectedSheetIndex());return t?t?.sheet:null}getSheet(t,e=wS.Visibility.Visible){const n=this._getSheetRef(t,e);if(!n)throw new kt(`Sheet '${t}' not found.`);return n.sheet}getSheetAt(t,e=wS.Visibility.Visible){const n=this._getSheetRef(t,e);if(!n)throw new kt((t=>`No sheet found at ${t}.`)(t));return n.sheet}getSheets(){return this._sheets}_getSheets(t=wS.Visibility.Visible){const e=this._getSheetRefs(t),n=[];for(let t=0;t<e.length;t++)n.push(e[t].sheet);return n}_getSheetRefs(t=wS.Visibility.Visible){if(this._closed)return _t.EmptyArray;const e=this._getState();return e?t===wS.Visibility.Visible?e.sheetRefsVisible:t===wS.Visibility.Hidden?e.sheetRefsVisibleAndHidden:t===wS.Visibility.VeryHidden?e.sheetRefsAll:_t.EmptyArray:[]}_getSheetRef(t,e=wS.Visibility.Visible){if(this._closed)return null;let n=null;if("number"==typeof t){return this._getSheetRefs(e)[t]}return"string"==typeof t?n=this._getState().refsByLowerCaseName.get(t.toLowerCase()):t instanceof Dw?n=this._getState().refsByInstance.get(t):t?.id&&t.sheet&&(n=this._getState().refsById.get(t.id)),n}_validateNewSheetName(t,e=!0){if(null==t)return t;if(vy(t),e&&this._getState().sheetsByLowerCaseName.has(t.toLowerCase()))throw new Error("That name is already taken. Try a different one.");return t.substring(0,31)}findValidSheetName(t){t&&(t=vy(t,!0));try{return((t,e)=>{try{if(e(t))return t}catch(t){}let n,r,o=yy.exec(t);for(null!==o?(n=t.substring(0,o.index),r=parseFloat(o[1])):(n=t+" ",r=1);r<256;){r++;const t="("+r+")",o=n.substring(0,31-t.length)+t;try{if(e(o))return o}catch(t){}}throw new Error(t+" is not a valid sheet name")})(t,t=>this._validateNewSheetName(t))}catch(t){return this._nextSheetName()}}isValidSheetNameCharacter(t){return!wy.test(t)}_addSheetOptions(t){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);let e=null;t={...t,description:t?.description??"Add Sheet"};const n=this.beginCommit(t);try{e=this._addSheet(!0,t.name,t.index??null);const r=this.getView().getActiveSheetId();let o,s;if(!1!==t.autoSelect){let n=this.getView().getActiveSheetId();n=this._getSheetRef(e).id,t?.autoSelect&&(o={view:this.getView(),activeSheetId:r},s={view:this.getView(),activeSheetId:n})}if(n.commit({description:`Add Sheet '${e.getName()}'`,viewBefore:o,viewAfter:s}),!1!==t.autoSelect){const n="boolean"==typeof t.autoSelect?void 0:t.autoSelect;e.select(n)}}catch(t){throw n.rollback(),t}return e}_nextSheetName(t=null){let e=t?t.toLowerCase():null;const n=this._getState(),r=n.sheetsByLowerCaseName;if(t&&r.has(e))throw new Error((t=>`The sheet name '${t}' already exist in workbook.`)(t));e=(t=this._validateNewSheetName(t))?t.toLowerCase():null;let o=n.lastId+1;for(;!t;){const e=this._createSheetName(o),n=e.toLowerCase();r.has(n)?o++:t=e}return this._updateState({lastId:o}),t}_addSheet(t,e=null,n=null){e=this._nextSheetName(e);const r=this._getState(),o=this._createSheet(r.lastId,e,wS.Visibility.Visible,n,null);if(!o)throw new Error(fy);return t&&this._emitter.notify("onSheetsChange"),o}_updateSheetRefStates(t){if(this._closed)throw new Error(dy);if(!this._initializing&&!this.getProtection().isStructureAllowed())throw new Error(gy);const e=t,n=[],r=[];for(let t=0;t<e.length;t++)e[t].visibility===wS.Visibility.Visible?(n.push(e[t]),r.push(e[t])):e[t].visibility===wS.Visibility.Hidden&&r.push(e[t]);this._updateState({sheetRefsAll:e,sheetRefsVisible:n,sheetRefsVisibleAndHidden:r})}_addSheetRef(t,e=null){const n=this._getState(),r=n.sheetRefsAll,o=Math.max(0,Math.min(r.length,e??r.length));let s=[...r.slice(0,o),t,...r.slice(o)];this._updateSheetRefStates(s);const i=t.sheet,a=t.name.toLowerCase(),l=new Map(n.refsById);l.set(t.id,t);const c=new Map(n.refsByLowerCaseName);c.set(a,t);const h=new Map(n.refsByInstance);h.set(i,t);const u=new Map(n.sheetsById);u.set(t.id,i);const d=new Map(n.sheetsByLowerCaseName);d.set(a,i);const g=this;let m=n.listenersSheets;if(void 0!==i){const e=i.addListeners({onBeforeDelete:t=>{g._validateDeleteSheet(t)},onDelete(t){let e=g._getSheetRef(t,wS.Visibility.VeryHidden);if(!e)return;const n=g._beginCommit({description:`Remove Sheet ${e.name}`});try{const r=g._getState(),o=r.sheetRefsAll,s=g._findOffsetForId(e.id,o);let a=[...o];a.splice(s,1),g._updateSheetRefStates(a);const l=new Map(r.refsById);l.delete(e.id);const c=new Map(r.sheetsById);c.delete(e.id);const h=e.name.toLowerCase(),u=new Map(r.refsByLowerCaseName);u.delete(h);const d=new Map(r.sheetsByLowerCaseName);d.delete(h);const m=new Map(r.refsByInstance);m.delete(t);r.listenersSheets.get(e.id)();const f=new Map(r.listenersSheets);f.delete(e.id),g._adjustRemoveSelectionIfRequired(s,e.id),g._adjustSheetNamesIfRequired(),g._emitter.notify("onSheetsChange");const p=new Set(r.sheetsCreated);p.has(i)&&p.delete(i),g._updateState({refsById:l,sheetsById:c,refsByLowerCaseName:u,sheetsByLowerCaseName:d,refsByInstance:m,sheetsCreated:p,listenersSheets:f}),n.commit()}catch(t){throw n.rollback(),t}}});m=new Map(n.listenersSheets),m.set(t.id,e)}let f=n.lastId;-1!==f&&(f=Math.max(f,t.id)),this._updateState({lastId:f}),this._updateState({refsById:l,refsByLowerCaseName:c,refsByInstance:h,sheetsById:u,sheetsByLowerCaseName:d,listenersSheets:m}),this._adjustSheetNamesIfRequired();const p=new Set(this._getState().sheetsCreated);return p.add(t.sheet),this._updateState({sheetsCreated:p}),t}_adjustRemoveSelectionIfRequired(t,e){if(this._view.getActiveSheetId()===e){let e;const n=this._getState().sheetRefsVisible;e=t<n.length?n[t].id:n[t-1].id,this._view.setActiveSheetId(e)}}_adjustSheetNamesIfRequired(){const t=this._getState(),e=t.lastId;if(-1===e)return;let n=this._view.getActiveSheetId();null==n&&(this._view.setActiveSheetId(e),n=e);t.refsById.get(n).visibility===wS.Visibility.Visible&&(this._activeSheetOffset=this._findOffsetForId(n,t.sheetRefsVisible))}_validateDeleteSheet(t){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);let e=this._getSheetRef(t);if(!e)throw new Error((t=>`Invalid reference for delete: ${t}`)(t));const n=this._getState().sheetRefsVisible;if(1===n.length&&n[0].id===e.id)throw new Error(hy)}_findOffsetForId(t,e){for(let n=0;n<e.length;n++)if(e[n].id===t)return n;throw new Error(uy)}find(t,e){if(this._closed)throw new Error(dy);const n=this._getSheets();if(1===n.length)return n[0].find(t,e);const r=!e?.reverse;let o=e?.disableWrap??!1;const s=this.getSelectedSheetIndex();let i=s,a=n[i],l=!1;e={...e,disableWrap:!0};let c,h=a.find(t,e),u=h.next(),d=!1;if(e?.from){const t=this._rangesAddressToCoords(e?.from);c={colIndex:t[0].colStart,rowIndex:t[0].rowStart}}else c={colIndex:0,rowIndex:0};const g=W.createCellComparator(e?.orientation,e?.reverse);delete(e={...e}).from;const m=()=>{if(!d&&u.done&&(l&&i===s?d=!0:r?(i++,i>n.length-1&&(i=0,l=!0)):(i--,i<0&&(i=n.length-1,l=!0)),o&&l&&(d=!0),!d))return a=n[i],h=a.find(t,e),u=h.next(),u;if(!d&&l&&i===s&&(u.done||!u.done&&g(u.value.getCoords(),c)>=0)&&(d=!0),d)return Ul;const m=u;return u=h.next(),m};return{next:()=>{let t=m();for(;!d&&t.done;)t=m();return t}}}replace(t,e,n){let r=0,o=null;const s="function"==typeof e,i=n?.maxCount??Number.MAX_SAFE_INTEGER;let a=n.maxCount?"":"All";const l="string"==typeof e?` with '${Us(e)}'`:"";let c=n?.description??"Replace";const h=this._transactions.beginCommit({description:c});try{let c=null,u=null,d=t.next();for(;!d.done&&r<i;){const i=d.value,a=i.getSource();a!==c&&(c=a,null!==u&&u.apply(),u=c.getEntireRange().startIncrementalUpdates({orientation:n?.orientation,allowUnorderedWrites:!0}));const l=s?e(i):e;void 0!==l&&l!==i&&(u.push(i,l),r++,o=i),d=t.next()}u?.apply(),1===r&&1===i&&o&&(a=o.getA1()),h.commit({description:n?.description??`Replace ${a}${l}`})}catch(t){throw h.rollback(),t}return{count:r,last:o}}_nextSheetIndex(t,e=this._getSheetRefs()){return 1===e.length?0:(void 0===t&&(t=this.getSelectedSheetIndex()),(t=Math.max(0,Math.min(t,e.length-1)))>=e.length-1?0:t+1)}_prevSheetIndex(t,e=this._getSheetRefs()){return 1===e.length?0:(void 0===t&&(t=this.getSelectedSheetIndex()),(t=Math.max(0,Math.min(t,e.length-1)))<=0?e.length-1:t-1)}getNextSheet(t){if(this._closed)throw new Error(dy);const e=this._getSheetRefs();return e[this._nextSheetIndex(t,e)]?.sheet??null}getPreviousSheet(t){if(this._closed)throw new Error(dy);const e=this._getSheetRefs();return e[this._prevSheetIndex(t,e)]?.sheet??null}async _duplicateSheet(t){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);const e=this._getSheetRefs(),n=this.getSelectedSheetIndex();let r=null;if(t){if(r=this._getSheetRef(t),!r)throw new Error(cy(r))}else r=e[n];if(!r)return null;const o=r.sheet,s=this._strings.beginPersist(),i=this.getResources().beginPersist(),a=this.getStyles().beginPersist();let l=null;const c=this.beginCommit(`Duplicate '${o.getName()}'`);try{const t=this._getState().refsByInstance.get(o),r=await o.toJSON(),s=e.length+1,i=this.findValidSheetName(t.name),a=this._createSheet(s,i,t.visibility,n,r);this._emitter.notify("onSheetsChange"),l=a,c.commit()}catch(t){throw c.rollback(),t}finally{a.endPersist(),i.endPersist(),s.endPersist()}return l}_createRange(t,e){const n=t?{...t}:null;if(!(n?this._getSheetRef(n.sheetName,wS.Visibility.VeryHidden):null)){const t=this.getSelectedSheet();return t?(delete n?.sheetName,by(n,n?{sheetName:gu,...t.getEntireRange().getCoords()}:null)):void console.warn(uy)}const r=this.getSelectedSheet();let o=null;return e&&(o={getOptions:e}),new xy(t,r,this,o)}_createRanges(t,e){const n=this.getSelectedSheet();let r=null;return e&&(r={getOptions:e}),new Cy(t,n,this,r)}getRange(t,e){try{const n=this._rangesAddressToCoords(t);if(1!==n.length)throw new Error(ed);return this._createRange(n[0],e)}catch(e){if(e instanceof kt)throw new kt(e.message);throw new Error(e.message??rd(t))}}getRanges(t,e){const n=this._rangesAddressToCoords(t);if(0===n.length)throw new Error(rd(t));return this._createRanges(n,e)}_activeRangeCoords(){const t=this.getSelectedSheet(),e=np(t.getSelection().getCoords()),n=t.getName(),r=[];for(let t=0;t<e.length;t++)r.push({sheetName:n,...e[t]});return r}getSelectedRange(t){return this.getRange(this._activeRangeCoords()[0],t)}getSelectedRanges(t){return this.getRanges(this._activeRangeCoords(),t)}getSelectedCell(){return this.getSelectedSheet().getSelectedCell()}_rangesAddressToCoords(t,e=!0,n=wS.Visibility.Hidden){if(!t)throw new Error(td);const r=this.getSelectedSheet(),o=r?.getEntireRange().getCoords(),s={...o},i=r?.getName();if(i&&(s.sheetName=i),"string"==typeof t){const e=t.trim().toLowerCase();if("r"===e||"c"===e){const n=this.getSelectedCell().getCoords(),r={};"r"===e?r.rowStart=r.rowEnd=n.rowIndex:r.colStart=r.colEnd=n.colIndex,t=r}}const a=this,l=Bu(t,s,ku,t=>{if(!e)return null;if("string"==typeof t){const e=a.getNames().getByName(t);if(e)return e.getRanges()?.getCoords()}throw new Error(`Invalid sheet reference '${t}'.`)});for(let t=0;t<l.length;t++)this._validateCoords(l[t],n);return l}_validateCoords(t,e=wS.Visibility.Visible,n=wd){if(null===t)return;const r=this.getSheet(t.sheetName,e).getEntireRange().getCoords();if(!W.isRangeWithinRange(t,r))throw new kt(n);if(t.rowEnd<t.rowStart||t.colEnd<t.colStart)throw new Error(nd)}_updateSheetRef(t,e){const n=this._getState();let r=[...n.sheetRefsAll];r[this._findOffsetForId(t.id,n.sheetRefsAll)]=e,this._updateSheetRefStates(r);const o=new Map(n.refsById);o.set(t.id,e);const s=t.name.toLowerCase(),i=e.name.toLowerCase(),a=new Map(n.refsByLowerCaseName);a.delete(s),a.set(i,e);const l=new Map(n.sheetsByLowerCaseName);let c=l.get(s);l.delete(s),l.set(i,c);const h=new Map(n.refsByInstance);return h.set(c,e),this._updateState({refsById:o,refsByLowerCaseName:a,sheetsByLowerCaseName:l,refsByInstance:h}),e}_setSheetName(t,e){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);const n=this._getSheetRef(t);if(!n)throw new Error(cy(t));if(e===n.name)return n.sheet;e=this._validateNewSheetName(e);const r=Object.freeze({...n,name:e});let o=null;const s=this.beginCommit("Rename Sheet");try{const t=this._updateSheetRef(n,r);this._adjustSheetNamesIfRequired(),this._sheetOnNameChange.forEach((t,e)=>{n.id===e&&t()}),this._emitter.notify("onSheetsChange"),o=t.sheet,s.commit()}catch(t){throw s.rollback(),t}return o}_setSheetVisibility(t,e=wS.Visibility.Visible){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);const n=this._getSheetRef(t);if(!n)return null;if(e===n.visibility)return;let r=null,o="";e===wS.Visibility.Visible?o="Unhide Sheet":e===wS.Visibility.Hidden?o="Hide Sheet":e===wS.Visibility.VeryHidden&&(o="Very Hide Sheet");const s=this.beginCommit(o);try{const t=this._getState().sheetRefsVisible;if(e!==wS.Visibility.Visible&&1===t.length&&t[0].id===n.id)throw new Error(hy);const o={...n,visibility:e};let i=-1;e!==wS.Visibility.Visible&&(i=this._findOffsetForId(n.id,t));const a=this._updateSheetRef(n,o);e!==wS.Visibility.Visible&&this._adjustRemoveSelectionIfRequired(i,n.id),r=a.sheet,this._adjustSheetNamesIfRequired(),s.commit()}catch(t){throw s.rollback(),t}return this._sheetOnVisibilityChange.forEach((t,e)=>{n.id===e&&t()}),this._emitter.notify("onSheetsChange"),r}_moveSheet(t,e){if(this._closed)throw new Error(dy);if(!this.getProtection().isStructureAllowed())throw new Error(gy);let n=null;const r=this.beginCommit(`Move Sheet '${t.name}'`);try{const o=this._getState(),s=o.sheetRefsVisible;if(e<0||e>s.length-1)throw new Error(`Invalid to index: ${e}`);const i={view:this.getView(),activeSheetId:this.getView().getActiveSheetId()},a=o.sheetRefsAll,l=this._findOffsetForId(t.id,a),c=this._findOffsetForId(s[e].id,a);if(l===c)return;const h=a[l];let u=[...a];u.splice(l,1),u.splice(c,0,h),this._updateSheetRefStates(u),this._adjustSheetNamesIfRequired(),this._sheetOnIndexChange.forEach((t,e)=>{e>=l&&e<=c&&t()}),this._emitter.notify("onSheetsChange"),n=h.sheet,r.commit({viewBefore:i,viewAfter:{view:this.getView(),activeSheetId:this.getView().getActiveSheetId()}})}catch(t){throw r.rollback(),t}return n}_setSelectedSheet(t){if(this._closed)throw new Error(dy);const e=this._getSheetRef(t);if(!e)throw new Error(cy(t));let n=null;return e.visibility!==wS.Visibility.Visible&&this._setSheetVisibility(e,wS.Visibility.Visible),this._view.setActiveSheetId(e.id),n=e.sheet,n}getProtection(){return this._protection}getNames(){return this._names}getCalculation(){return this._calculation}getScripts(){return this._scripts??null}_notifyAllChange(){this._emitter.notify("onSheetsChange"),this._emitter.notify("onViewChange")}addListeners(t,e){return this._emitter.addListeners(t,e)}_sheetToWBEvent(t){const e=this;return n=>{const r=()=>{const t=n.getSource();if(t.isICellRanges){const n=[...t.getCoords()];for(let e=0;e<n.length;e++){const r=n[e];!r.sheetName&&t.getSource().getName()&&(n[e]={...r,sheetName:t.getSource().getName()})}return e.getRanges(n)}if(t.isICellRange){const n=t.getCoords(),r=t.getSource().getName();return e.getRange({...n,sheetName:r})}},o={getSource:r,trigger:n.trigger,getFrom:()=>e.getRanges(n.getFrom()),getTo:()=>e.getRange(n.getTo()),isDataChange:n.isDataChange,isTransactional:n.isTransactional,isUndo:n.isUndo,toString:()=>`WorkbookRangeEvent: ('${n.trigger}', ${r().toString()})`,timeStamp:Date.now()};t(o)}}_fromJSON(t){if(this._emitter.notify("onBeforeLoad",{params:t}),this._initState(),!t.sheets||0===t.sheets.length)throw new Error(hy);t.theme&&(this._theme=new Rl(t.theme),this._styles.setTheme(this._theme));const e=this._strings.beginPersist(),n=this._resources.beginPersist(),r=this._styles.beginPersist();try{e.fromJSON(t.strings),n.fromJSON(t.resources),r.fromJSON(t.styles),t.date1904&&(this._isDate1904=!0),t.view||(t.view={});const o=t.sheets,s=o.length;let i=t.view.activeSheetId??null;null!==i&&(i=Math.min(Math.max(1,i),s));let a=null;for(let t=0;t<s;t++){const e=o[t],n=e.visibility||wS.Visibility.Visible,r=t+1;n===wS.Visibility.Visible?a=r:null!==i&&i===r&&(i=null),this._createSheet(r,e.name,n,void 0,e.sheet)}this._updateState({lastId:a}),t.names&&this._names.fromJSON(t.names),t.view.activeSheetId=i??a,this.setView(new Kw({json:t.view})),this._adjustSheetNamesIfRequired(),this._listenerProtection?.();const l=this;this._protection=new ly(t?.protection,this._options?.readonly),this._listenerProtection=this._protection.addListeners({onChange:t=>{l._emitter.notify("onProtectionChange",{source:t})}}),t.scripts&&(this._scripts=this._createScripts(t.scripts)),this._emitter.notify("onLoad")}finally{r.endPersist(),n.endPersist(),e.endPersist()}}_createScripts(t){return new iy({transactions:this._transactions,json:t,workbook:this,onAdd:(t,e)=>{const n=this._calculation;n.getStatus()!==Hp.Status.Off&&n.start().then(()=>{const t=e.getFunctions().search({type:"formula"});for(let e=0;e<t.length;e++){const n=t[e];this._calculation.getFunctions().add(n)}})},onRemove:(t,e)=>{}})}async toJSON(t=!1){if(this._closed)throw new Error(dy);await this._emitter.notify("onBeforeSave",{async:!0});const e={sheets:[]};await Promise.resolve(this._starting);const n=this._theme.toJSON();(n?Object.keys(n).length:0)>0&&(e.theme=n);const r=this._strings.beginPersist(),o=this._resources.beginPersist(),s=this._styles.beginPersist();try{const n=this._getSheetRef(this.getSelectedSheetIndex()).id;let i=n,a=null;const l=this._getState(),c=l.sheetRefsAll,h=l.sheetsById;for(let r=0;r<c.length;r++){const o=c[r],s=r+1,l=await h.get(o.id).toJSON(t),u={name:o.name,sheet:l};o.visibility===wS.Visibility.Visible?a=s:u.visibility=o.visibility,o.id===n&&(i=s),e.sheets.push(u)}const u=s.toJSON();u&&Object.keys(u).length>0&&(e.styles=u);const d=this.getProtection().toJSON();d&&(e.protection=d);const g=await r.toJSONAsync();g&&g.length>0&&(e.strings=g);const m=await o.toJSONAsync();m&&m.length>0&&(e.resources=m);const f=this._names.toJSON();f&&f.length>0&&(e.names=f);const p=this._view.toJSON();p&&(i!==a?p.activeSheetId=i:delete p.activeSheetId,Object.keys(p).length>0&&(e.view=p))}finally{s.endPersist(),o.endPersist(),r.endPersist()}if(this._scripts){const t=this._scripts.toJSON();t&&Object.keys(t).length>0&&(e.scripts=t)}return this._isDate1904&&(e.date1904=!0),this._emitter.notify("onSave",{params:e}),e}isClosed(){return this._closed}close(){if(this._closed)return;this._emitter.notify("onClose");const t=this._getState();t.listenersSheets.forEach(t=>{t()}),t.listenersSheets.clear();const e=t.sheetRefsAll;for(let t=e.length-1;t>=0;t--)try{e[t].sheet.close()}catch(t){console.warn("error on close",t)}this._ownResources,this._ownNames&&this._names.close(),this._ownsCalculation&&this._calculation.close(),this._ownStyles,this._transactionsRemoveListener?.(),this._closed=!0}beginCommit(t){if(this._closed)throw new Error(dy);return this._beginCommit("string"==typeof t?{description:t}:t)}doBatch(t,e){const n=this;return e="string"==typeof e?{description:e}:{description:"Update Workbook",...e},this._transactions.doBatch(t,e,(t,e)=>{0===t.getDepth()&&(n._lastTransactionUUID=t.getId())})}_beginCommit(t){const e=this;return this._transactions.beginCommit("string"==typeof t?{description:t}:t,t=>{0===t.getDepth()&&(e._lastTransactionUUID=t.getId())})}_getState(){return this._transactions.getState(this)}_updateState(t,e="Update Workbook"){if(!t)return;const n=this._beginCommit(e);try{n.updateState(this,t),n.commit()}catch(t){throw n.rollback(),t}}get options(){return this._options}get[Symbol.toStringTag](){return"[Workbook]"}toString(){return""}get isIWorkbook(){return!0}}const Ay={address:null,scope:null};export{ya as $,E as A,Lt as B,d as C,kt as D,Bt as E,B_ as F,Ot as G,I as H,A as I,Mt as J,x as K,ne as L,Jt as M,Ft as N,ie as O,te as P,he as Q,Ie as R,Dt as S,G_ as T,Be as U,Ke as V,Sa as W,wa as X,xi as Y,fi as Z,_i as _,_t as a,ba as a0,Da as a1,Ba as a2,ri as a3,Ds as a4,zs as a5,el as a6,rl as a7,Fp as a8,Lp as a9,Dw as aA,Kw as aB,Iy as aC,Bp as aa,Pp as ab,Fl as ac,jp as ad,Vp as ae,Hp as af,nS as ag,ip as ah,Gd as ai,rS as aj,oS as ak,sS as al,zl as am,Pl as an,iS as ao,lS as ap,Nl as aq,bp as ar,al as as,ll as at,Rl as au,Tl as av,hS as aw,_S as ax,SS as ay,wS as az,hw as b,tu as c,cw as d,t as e,Zu as f,su as g,Eu as h,Xh as i,W as j,Fi as k,e as l,ou as m,r as n,S as o,g as p,y as q,Su as r,Et as s,Kh as t,St as u,Rt as v,Nt as w,w as x,It as y,At as z};