@datalayer/agent-runtimes 1.6.38 → 1.6.40

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 (171) hide show
  1. package/dist-embed/chunks/{AgentDetails-Ba3DRn2p.js → AgentDetails-DC7O2VWb.js} +1 -1
  2. package/dist-embed/chunks/{AgentDetailsDialog-CXN0RO_L.js → AgentDetailsDialog-BTJCl-o-.js} +1 -1
  3. package/dist-embed/chunks/{AgentInspector-C66D0b0W.js → AgentInspector-BXqYY8g-.js} +1 -1
  4. package/dist-embed/chunks/{AgentInspectorDialog-DeK96QG1.js → AgentInspectorDialog-dRHZ1p73.js} +1 -1
  5. package/dist-embed/chunks/Avatar-Cv5OpUWu.js +1 -0
  6. package/dist-embed/chunks/{CellSidebarExtension-D7aXShZc.js → CellSidebarExtension-DXPIz0Km.js} +7 -7
  7. package/dist-embed/chunks/{ChatView-2N7PbcDs.js → ChatView-CRitAB2i.js} +4 -4
  8. package/dist-embed/chunks/{CollapsiblePlugin-y8sx_FL8.js → CollapsiblePlugin-BPlfrDQU.js} +1 -1
  9. package/dist-embed/chunks/DatalayerAgentBridge-D01Ek4NE.js +1 -0
  10. package/dist-embed/chunks/{DeckComponent-BnyeYRQq.js → DeckComponent-jvb83Q__.js} +1 -1
  11. package/dist-embed/chunks/{DocumentView-DT4DcdJI.js → DocumentView-BrdFnTVh.js} +3 -3
  12. package/dist-embed/chunks/{EphemeralDocument-CGISw1N3.js → EphemeralDocument-CkPQKyfy.js} +1 -1
  13. package/dist-embed/chunks/{EphemeralNotebook-Dyx-25uN.js → EphemeralNotebook-CiQIC3MG.js} +1 -1
  14. package/dist-embed/chunks/{ExcalidrawComponent-Bl3R2Mic.js → ExcalidrawComponent-D6Cr_b0Z.js} +1 -1
  15. package/dist-embed/chunks/{ExcalidrawModal-DSL5jBhG.js → ExcalidrawModal-Bso7oDbl.js} +1 -1
  16. package/dist-embed/chunks/{JupyterLexicalExtension-C55KdpCk.js → JupyterLexicalExtension-DuD7IV6j.js} +6 -6
  17. package/dist-embed/chunks/{KernelVariables-D3DSQaD3.js → KernelVariables-CXQagESp.js} +2 -2
  18. package/dist-embed/chunks/{NotebookSkeleton-BkzTMhIX.js → NotebookSkeleton-CvO9WylK.js} +1 -1
  19. package/dist-embed/chunks/{NotebookToolSurfaces-Bvj9nwA9.js → NotebookToolSurfaces-B9fkzQNR.js} +1 -1
  20. package/dist-embed/chunks/{NotebookToolbar-BMjQTGrr.js → NotebookToolbar-D36duUxK.js} +1 -1
  21. package/dist-embed/chunks/{NotebookView-DRPnBAI2.js → NotebookView-BrdHwtKH.js} +1 -1
  22. package/dist-embed/chunks/{Output-D-7eUege.js → Output-D9cwH5rg.js} +1 -1
  23. package/dist-embed/chunks/{SandboxDetailsDialog-qJBg2naH.js → SandboxDetailsDialog-BYgLjg3W.js} +1 -1
  24. package/dist-embed/chunks/{SchemaForm-D6BAKaNe.js → SchemaForm-B3qMIWMy.js} +1 -1
  25. package/dist-embed/chunks/{SheetTabs-BLaEhX0D.js → SheetTabs-BR72mzuo.js} +2 -2
  26. package/dist-embed/chunks/{SpreadsheetPreviewView-CaFQASZ4.js → SpreadsheetPreviewView-RA8ASTBV.js} +1 -1
  27. package/dist-embed/chunks/{SpreadsheetView-DesdGLpm.js → SpreadsheetView-BfScdA-X.js} +1 -1
  28. package/dist-embed/chunks/{Toolbar-BncUh2ly.js → Toolbar-BAjGB6b-.js} +1 -1
  29. package/dist-embed/chunks/{WidgetVariableView-B4faSdWW.js → WidgetVariableView-7lvDcxCg.js} +1 -1
  30. package/dist-embed/chunks/{YouTubePlugin-BPUrB3sh.js → YouTubePlugin-BbjCzaT_.js} +1 -1
  31. package/dist-embed/chunks/{ar-SA-G6X2FPQ2-Dq_tRQtR.js → ar-SA-G6X2FPQ2-D4M2b5Lr.js} +1 -1
  32. package/dist-embed/chunks/{az-AZ-76LH7QW2-DQAoJi9C.js → az-AZ-76LH7QW2-Rn7oINhz.js} +1 -1
  33. package/dist-embed/chunks/{bg-BG-XCXSNQG7-CfZUFj2_.js → bg-BG-XCXSNQG7-xztohKe7.js} +1 -1
  34. package/dist-embed/chunks/{bn-BD-2XOGV67Q-DiqZdhkT.js → bn-BD-2XOGV67Q-C7Ssg1_2.js} +1 -1
  35. package/dist-embed/chunks/{ca-ES-6MX7JW3Y-B6c2PcO9.js → ca-ES-6MX7JW3Y-Cr0zd8Z6.js} +1 -1
  36. package/dist-embed/chunks/{celltoolbartracker-BHSFiiuz.js → celltoolbartracker-D1C_kGQL.js} +1 -1
  37. package/dist-embed/chunks/{component-BUTWfiVL.js → component-CmnuUtgX.js} +3 -3
  38. package/dist-embed/chunks/{cs-CZ-2BRQDIVT-ha7l75va.js → cs-CZ-2BRQDIVT-G9tBUkZh.js} +1 -1
  39. package/dist-embed/chunks/{da-DK-5WZEPLOC-C3b8_hbR.js → da-DK-5WZEPLOC-91_vyLpq.js} +1 -1
  40. package/dist-embed/chunks/{de-DE-XR44H4JA-CxWFSn3l.js → de-DE-XR44H4JA-Bb9tvIZa.js} +1 -1
  41. package/dist-embed/chunks/{dist-BF0YFIb6.js → dist-B5YvY_O1.js} +2 -2
  42. package/dist-embed/chunks/{dist-DsEDq9qF.js → dist-BBqWTRLi.js} +1 -1
  43. package/dist-embed/chunks/{dist-DRRbvr4-.js → dist-BC_2VyAM.js} +1 -1
  44. package/dist-embed/chunks/{dist-B_TGJsfl.js → dist-BhfyuH1D.js} +1 -1
  45. package/dist-embed/chunks/{dist-Cfvz7CF7.js → dist-BlIg6ytm.js} +1 -1
  46. package/dist-embed/chunks/{dist-COiURBxL.js → dist-Ct-bkqXx.js} +4 -4
  47. package/dist-embed/chunks/{dist-tosaS6vh.js → dist-CtFgtNKe.js} +1 -1
  48. package/dist-embed/chunks/{dist-B1tXS8Wo.js → dist-DLyNQ3Jj.js} +1 -1
  49. package/dist-embed/chunks/{document-CqNE0DPx.js → document-Dp0KpIjg.js} +1 -1
  50. package/dist-embed/chunks/{drivecontents-D1HzL7Fi.js → drivecontents-BsC6Y2Vl.js} +1 -1
  51. package/dist-embed/chunks/{el-GR-BZB4AONW-iSsL6em8.js → el-GR-BZB4AONW-B5kc3JC5.js} +1 -1
  52. package/dist-embed/chunks/{es-ES-U4NZUMDT-BEbh9GGw.js → es-ES-U4NZUMDT-CpFB18Kf.js} +1 -1
  53. package/dist-embed/chunks/{esm-RWOqF6ly.js → esm-BqqxV5QL.js} +1 -1
  54. package/dist-embed/chunks/{eu-ES-A7QVB2H4-C7o7R9hc.js → eu-ES-A7QVB2H4-CqCALK0Q.js} +1 -1
  55. package/dist-embed/chunks/{fa-IR-HGAKTJCU-DQNpeHKi.js → fa-IR-HGAKTJCU-BzSY8fri.js} +1 -1
  56. package/dist-embed/chunks/{fi-FI-Z5N7JZ37-D083iC1R.js → fi-FI-Z5N7JZ37-DPRPVT_v.js} +1 -1
  57. package/dist-embed/chunks/{fr-FR-RHASNOE6-CUvaq7hG.js → fr-FR-RHASNOE6-Cr4lVSvD.js} +1 -1
  58. package/dist-embed/chunks/{gl-ES-HMX3MZ6V-DU31KRvC.js → gl-ES-HMX3MZ6V-CZUw7dN0.js} +1 -1
  59. package/dist-embed/chunks/{he-IL-6SHJWFNN-bMtU7JNY.js → he-IL-6SHJWFNN-DaU5Odek.js} +1 -1
  60. package/dist-embed/chunks/{hi-IN-IWLTKZ5I-Pma0rKxO.js → hi-IN-IWLTKZ5I-BZ84Rooc.js} +1 -1
  61. package/dist-embed/chunks/{htmlselect-CqXICb9e.js → htmlselect-5N6NdDqL.js} +1 -1
  62. package/dist-embed/chunks/{hu-HU-A5ZG7DT2-Dof3afSc.js → hu-HU-A5ZG7DT2-SZiCSe0B.js} +1 -1
  63. package/dist-embed/chunks/{id-ID-SAP4L64H-ZwqZHBDj.js → id-ID-SAP4L64H-DrRa3vVi.js} +1 -1
  64. package/dist-embed/chunks/{index-9EhrHHj7.js → index-B6-uQd5L.js} +3 -3
  65. package/dist-embed/chunks/{index-9wJFadG-.js → index-CEeyR3FZ.js} +1 -1
  66. package/dist-embed/chunks/{index-CqP3xLL5.js → index-CKWSKbHe.js} +1 -1
  67. package/dist-embed/chunks/{index-BbcMy3Al.js → index-DpN8KK6c.js} +1 -1
  68. package/dist-embed/chunks/{index--S8WFITA.js → index-JmqWOkdt.js} +1 -1
  69. package/dist-embed/chunks/{index-CMhceBby.js → index-PKH5uAl-.js} +1 -1
  70. package/dist-embed/chunks/{index-C7UsrKrP.js → index-hhftmReh.js} +1 -1
  71. package/dist-embed/chunks/{index-6zxBQeM_.js → index-qhxI1VzX.js} +2 -2
  72. package/dist-embed/chunks/{index.esm-xgVG4GIx.js → index.esm-Bvtnemp7.js} +1 -1
  73. package/dist-embed/chunks/{it-IT-JPQ66NNP-C-uM6NhO.js → it-IT-JPQ66NNP-_TEhDIcF.js} +1 -1
  74. package/dist-embed/chunks/{ja-JP-DBVTYXUO-qzihtLnX.js → ja-JP-DBVTYXUO-IJaTVgTb.js} +1 -1
  75. package/dist-embed/chunks/{kaa-6HZHGXH3-Amx_Jfx0.js → kaa-6HZHGXH3-CTksAiLJ.js} +1 -1
  76. package/dist-embed/chunks/{kab-KAB-ZGHBKWFO-BPZfDYRT.js → kab-KAB-ZGHBKWFO-DbA7aOfU.js} +1 -1
  77. package/dist-embed/chunks/{kk-KZ-P5N5QNE5-B83bJ3Yw.js → kk-KZ-P5N5QNE5-Bdzg30AB.js} +1 -1
  78. package/dist-embed/chunks/{km-KH-HSX4SM5Z-BvPDwBVw.js → km-KH-HSX4SM5Z-Bwn2NP1-.js} +1 -1
  79. package/dist-embed/chunks/{ko-KR-MTYHY66A-jpQ_OpzG.js → ko-KR-MTYHY66A-KUaxlo0q.js} +1 -1
  80. package/dist-embed/chunks/{ku-TR-6OUDTVRD-RsfwTm7i.js → ku-TR-6OUDTVRD-DRegsFXo.js} +1 -1
  81. package/dist-embed/chunks/{lib-CFx15o08.js → lib--J3JPp2K.js} +1 -1
  82. package/dist-embed/chunks/{lib-D6X8UF4a.js → lib-9S57siQD.js} +1 -1
  83. package/dist-embed/chunks/{lib-CoK70EWs.js → lib-BpltV-0Y.js} +1 -1
  84. package/dist-embed/chunks/{lib-DGhrI5Uw.js → lib-C2mgrsS1.js} +1 -1
  85. package/dist-embed/chunks/{lib-XSPvEMl2.js → lib-C46CpvHb.js} +1 -1
  86. package/dist-embed/chunks/{lib-D0Q8IWel.js → lib-CHID83aM.js} +1 -1
  87. package/dist-embed/chunks/{lib-Pqxz_81N.js → lib-COJY2oKd.js} +25 -25
  88. package/dist-embed/chunks/{lib-p7v7zGkv.js → lib-CQeoQJWp.js} +1 -1
  89. package/dist-embed/chunks/{lib-CdtiDxdA.js → lib-CjBEbEzm.js} +1 -1
  90. package/dist-embed/chunks/{lib-BBnVlTAj.js → lib-Cpc8Fspj.js} +1 -1
  91. package/dist-embed/chunks/{lib-CsiCQ8oM.js → lib-D7CvuX1J.js} +1 -1
  92. package/dist-embed/chunks/{lib-7ge2Kma3.js → lib-DOnguzJf.js} +1 -1
  93. package/dist-embed/chunks/{lib-UYAFV0Oh.js → lib-Dh9o1esj.js} +1 -1
  94. package/dist-embed/chunks/{lib-DdeRC7g0.js → lib-DrEcjKb5.js} +1 -1
  95. package/dist-embed/chunks/{lib-Dj12Ge-1.js → lib-PbTUB5SW.js} +1 -1
  96. package/dist-embed/chunks/{lib-DMy40SOL.js → lib-QmOij8gS.js} +1 -1
  97. package/dist-embed/chunks/{lib-C7Y61LM1.js → lib-csBGF1d0.js} +1 -1
  98. package/dist-embed/chunks/{lib-DTyx2eLX.js → lib-op0DTswa.js} +1 -1
  99. package/dist-embed/chunks/{lib-CkcilPdy.js → lib-ox3VOLDA.js} +1 -1
  100. package/dist-embed/chunks/{lib-Bi95m_cb.js → lib-rn9DpcHi.js} +1 -1
  101. package/dist-embed/chunks/{lt-LT-XHIRWOB4-qZ_KjUTQ.js → lt-LT-XHIRWOB4-c6CdaS7u.js} +1 -1
  102. package/dist-embed/chunks/{lv-LV-5QDEKY6T-BOKJbljG.js → lv-LV-5QDEKY6T-D9RognOk.js} +1 -1
  103. package/dist-embed/chunks/{model-C2VRzh1c.js → model-DbDJZyri.js} +1 -1
  104. package/dist-embed/chunks/{mr-IN-CRQNXWMA-xba6p6AI.js → mr-IN-CRQNXWMA-ht3P_mrN.js} +1 -1
  105. package/dist-embed/chunks/{my-MM-5M5IBNSE-B_H0GaRX.js → my-MM-5M5IBNSE-CsIkhWRp.js} +1 -1
  106. package/dist-embed/chunks/{nb-NO-T6EIAALU-Ddg4NpHf.js → nb-NO-T6EIAALU-DJw7Uvbx.js} +1 -1
  107. package/dist-embed/chunks/{nl-NL-IS3SIHDZ-DS_Sofox.js → nl-NL-IS3SIHDZ-Dcrp-zwB.js} +1 -1
  108. package/dist-embed/chunks/{nn-NO-6E72VCQL-CYSB6TTi.js → nn-NO-6E72VCQL-DaBAIbM9.js} +1 -1
  109. package/dist-embed/chunks/{oc-FR-POXYY2M6-QrIn4XvF.js → oc-FR-POXYY2M6-DSdMEDCa.js} +1 -1
  110. package/dist-embed/chunks/{pa-IN-N4M65BXN-BbacRfk_.js → pa-IN-N4M65BXN-BMyPito1.js} +1 -1
  111. package/dist-embed/chunks/{percentages-BXMCSKIN-TyKhSuec.js → percentages-BXMCSKIN-pswfKMt2.js} +3 -3
  112. package/dist-embed/chunks/{pl-PL-T2D74RX3-Cn2ehrU4.js → pl-PL-T2D74RX3-CFk8rHgP.js} +1 -1
  113. package/dist-embed/chunks/{plugin-CPCdQWpK.js → plugin-BpyrQiv7.js} +1 -1
  114. package/dist-embed/chunks/{plugin-D7Giq2rW.js → plugin-NcgdmcAO.js} +1 -1
  115. package/dist-embed/chunks/{plugin-AdqytlNC.js → plugin-omHCT1Jk.js} +1 -1
  116. package/dist-embed/chunks/{pt-BR-5N22H2LF-CpNtiBPh.js → pt-BR-5N22H2LF-BYlDcalT.js} +1 -1
  117. package/dist-embed/chunks/{pt-PT-UZXXM6DQ-CcDR3Igq.js → pt-PT-UZXXM6DQ-xXdoFOOb.js} +1 -1
  118. package/dist-embed/chunks/{pyodide-kernel-CN7B4QLg.js → pyodide-kernel-bjLdubpe.js} +1 -1
  119. package/dist-embed/chunks/{pyodide-kernel-extension-CKE5jq9F.js → pyodide-kernel-extension-CshyO6Mm.js} +1 -1
  120. package/dist-embed/chunks/{renderer-8__rsP1H.js → renderer-We9CyR7b.js} +1 -1
  121. package/dist-embed/chunks/{ro-RO-JPDTUUEW-CANXxss1.js → ro-RO-JPDTUUEW-e-URCww-.js} +1 -1
  122. package/dist-embed/chunks/{ru-RU-B4JR7IUQ-B_NkKbWo.js → ru-RU-B4JR7IUQ-CrXBOpZl.js} +1 -1
  123. package/dist-embed/chunks/{server-extension-BvlUJPbJ.js → server-extension-D9R-wwz5.js} +1 -1
  124. package/dist-embed/chunks/{sessions-CgjtuOSm.js → sessions-DdXtI_C1.js} +1 -1
  125. package/dist-embed/chunks/{si-LK-N5RQ5JYF-Da_Bg8Mv.js → si-LK-N5RQ5JYF-DmJK04-A.js} +1 -1
  126. package/dist-embed/chunks/{sk-SK-C5VTKIMK-BKs6l_DT.js → sk-SK-C5VTKIMK-BDHycW1Q.js} +1 -1
  127. package/dist-embed/chunks/{sl-SI-NN7IZMDC-C4TvSXZU.js → sl-SI-NN7IZMDC-Bv9ZQTNb.js} +1 -1
  128. package/dist-embed/chunks/{subset-shared.chunk-BZGTZU2h.js → subset-shared.chunk-B0WCMaCa.js} +1 -1
  129. package/dist-embed/chunks/{subset-worker.chunk-CNJFtQV7.js → subset-worker.chunk-i0SNRqXr.js} +1 -1
  130. package/dist-embed/chunks/{sv-SE-XGPEYMSR-DdKzikID.js → sv-SE-XGPEYMSR-_HPzcZFc.js} +1 -1
  131. package/dist-embed/chunks/{ta-IN-2NMHFXQM-CDzGLNXS.js → ta-IN-2NMHFXQM-Ccvi-lqm.js} +1 -1
  132. package/dist-embed/chunks/{th-TH-HPSO5L25-X4BJ7awj.js → th-TH-HPSO5L25-DvAg4Mv1.js} +1 -1
  133. package/dist-embed/chunks/{tokens-CBhRbpQP.js → tokens-CTXFWLvM.js} +1 -1
  134. package/dist-embed/chunks/{tr-TR-DEFEU3FU-CN69_6_H.js → tr-TR-DEFEU3FU-DJsjfrja.js} +1 -1
  135. package/dist-embed/chunks/{uk-UA-QMV73CPH-KjB2cySI.js → uk-UA-QMV73CPH-3fvexlQA.js} +1 -1
  136. package/dist-embed/chunks/{usePrimerThemeBridge-DyX4EYyN.js → usePrimerThemeBridge-NsTRGuo7.js} +1 -1
  137. package/dist-embed/chunks/{vi-VN-M7AON7JQ-BqVSbGWG.js → vi-VN-M7AON7JQ-BoQ3ayAr.js} +1 -1
  138. package/dist-embed/chunks/{zh-CN-LNUGB5OW-oRPI4tbl.js → zh-CN-LNUGB5OW-Dzh0Ni_q.js} +1 -1
  139. package/dist-embed/chunks/{zh-HK-E62DVLB3-BUlz3y0i.js → zh-HK-E62DVLB3-_1FpSc_d.js} +1 -1
  140. package/dist-embed/chunks/{zh-TW-RAJ6MFWO-NxjUwhr3.js → zh-TW-RAJ6MFWO-CU-R8eF0.js} +1 -1
  141. package/dist-embed/datalayer-app-main.js +154 -154
  142. package/lib/apps/apps/AppRenderer.d.ts +6 -0
  143. package/lib/apps/apps/AppRenderer.js +3 -0
  144. package/lib/apps/plugins/agents/DatalayerAgentBridge.js +10 -3
  145. package/lib/apps/plugins/agents/SandboxSelector.js +1 -1
  146. package/lib/apps/plugins/agents/appLaunch.js +12 -0
  147. package/lib/apps/plugins/agents/handoffRuntime.d.ts +36 -0
  148. package/lib/apps/plugins/agents/handoffRuntime.js +50 -0
  149. package/lib/apps/plugins/agents/plugin.d.ts +20 -6
  150. package/lib/apps/plugins/agents/plugin.js +1 -0
  151. package/lib/apps/plugins/agents/switchable.d.ts +14 -2
  152. package/lib/apps/plugins/agents/switchable.js +13 -3
  153. package/lib/hooks/useAgentRuntimes.d.ts +1 -1
  154. package/lib/hooks/useAgentRuntimes.js +2 -0
  155. package/lib/loop-main.js +27 -25
  156. package/lib/portable/hosts/agentClient.d.ts +9 -9
  157. package/lib/portable/hosts/agentClient.js +34 -8
  158. package/lib/portable/hosts/contracts.json +3 -28
  159. package/lib/portable/hosts/index.d.ts +0 -1
  160. package/lib/portable/hosts/index.js +0 -1
  161. package/lib/runtimes/actions.js +6 -0
  162. package/lib/runtimes/apis.d.ts +8 -0
  163. package/lib/specs/agents/agents.js +1 -1
  164. package/lib/types/agents-lifecycle.d.ts +7 -0
  165. package/lib/types/agentspecs.d.ts +9 -4
  166. package/lib/types/agentspecs.js +7 -1
  167. package/package.json +1 -1
  168. package/dist-embed/chunks/Avatar-MNx1kN3F.js +0 -1
  169. package/dist-embed/chunks/DatalayerAgentBridge-BmoysA2b.js +0 -1
  170. package/lib/portable/hosts/sessionUid.d.ts +0 -9
  171. package/lib/portable/hosts/sessionUid.js +0 -29
@@ -1,4 +1,4 @@
1
- import{mB as pe,mC as sa,bK as nt,bM as oe,e8 as Ti,mD as ia,j as C,r as k,e7 as Cr,mE as $r,gI as la,v as hs,_ as Ri,mF as aa,mG as ca,mH as ua,bs as Be,mI as ha,mJ as fs,dl as fa,I as ds,W as da,e6 as Uo}from"../datalayer-app-main.js";import{K as ma}from"./KebabHorizontalIcon-D6AY8pIS.js";const zi={rows:new Int32Array(0),cols:new Int32Array(0),values:[],formulas:[],styles:new Uint16Array(0)};function Kt(t,e){const n=[],o=[],r=[],s=[],i=[];for(const[a,l,c]of t.cells.entries(e))n.push(a),o.push(l),r.push(c.value),s.push(c.formula),i.push(c.style);return{rows:Int32Array.from(n),cols:Int32Array.from(o),values:r,formulas:s,styles:Uint16Array.from(i)}}function Rt(t){return{rows:Int32Array.from(t,e=>e[0]),cols:Int32Array.from(t,e=>e[1]),values:t.map(e=>e[2].value),formulas:t.map(e=>e[2].formula),styles:Uint16Array.from(t,e=>e[2].style)}}function Mn(t){const e=[];for(let n=0;n<t.rows.length;n+=1){const o=t.formulas[n];e.push([t.rows[n],t.cols[n],o===void 0?{value:t.values[n],style:t.styles[n]}:{value:t.values[n],formula:o,style:t.styles[n]}])}return e}function ms(t){let e=64+t.rows.length*26;for(const n of t.values)typeof n=="string"&&(e+=n.length*2);for(const n of t.formulas)n!==void 0&&(e+=n.length*2);return e}function fo(t){return 64+t.ids.byteLength+(t.sizes?.byteLength??0)+(t.hidden?.byteLength??0)}const Co=(t,e)=>e==="rows"?t.rows:t.cols,ur=t=>({ids:Int32Array.from(t),sizes:null,hidden:null}),ga={op:"cells",apply(t,e){const n=t.sheet(e.sheet);for(const[o,r]of[...n.cells.entries(e.zone)])n.cells.set(o,r,null);for(const[o,r,s]of Mn(e.after)){if(o<e.zone.top||o>e.zone.bottom||r<e.zone.left||r>e.zone.right)throw new Error(`A cells patch writes ${o},${r} outside its zone.`);n.cells.set(o,r,s)}},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"cells",sheet:"s1",zone:{top:0,left:0,bottom:1,right:1},before:zi,after:Rt([[1,1,{value:42,style:0}]])}),bytes:t=>ms(t.before)+ms(t.after)};function Ni(t,e,n,o){e==="rows"?t.cells.shiftRows(n,o,t.rows.count):t.cells.shiftCols(n,o,t.cols.count)}const pa={op:"axis-insert",apply(t,e){const n=t.sheet(e.sheet);Co(n,e.axis).insert(e.at,e.n,e.inserted),Ni(n,e.axis,e.at,e.n)},invert:t=>({op:"axis-delete",sheet:t.sheet,axis:t.axis,at:t.at,n:t.n,removed:t.inserted,tail:t.dropped}),example:t=>{const e=t.sheet("s1").rows.count;return{op:"axis-insert",sheet:"s1",axis:"rows",at:2,n:2,inserted:ur([1<<30,(1<<30)+1]),dropped:ur([e-2,e-1])}},bytes:t=>fo(t.inserted)+(t.dropped?fo(t.dropped):0)},wa={op:"axis-delete",apply(t,e){const n=t.sheet(e.sheet);Co(n,e.axis).delete(e.at,e.n,e.tail),Ni(n,e.axis,e.at,-e.n)},invert:t=>({op:"axis-insert",sheet:t.sheet,axis:t.axis,at:t.at,n:t.n,inserted:t.removed,dropped:t.tail}),example:t=>({op:"axis-delete",sheet:"s1",axis:"rows",at:1,n:1,removed:ur([1])}),bytes:t=>fo(t.removed)+(t.tail?fo(t.tail):0)},ya={op:"axis-move",apply(t,e){Co(t.sheet(e.sheet),e.axis).move(e.at,e.n,e.to)},invert:t=>t.to<t.at?{...t,at:t.to,to:t.at+t.n}:{...t,at:t.to-t.n,to:t.at},example:()=>({op:"axis-move",sheet:"s1",axis:"cols",at:1,n:2,to:6})},ba={op:"axis-sizes",apply(t,e){Co(t.sheet(e.sheet),e.axis).setSegmentSizes(e.at,e.after.sizes,e.after.hidden,e.n)},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"axis-sizes",sheet:"s1",axis:"cols",at:3,n:2,before:{sizes:null,hidden:null},after:{sizes:Float64Array.of(40,50),hidden:Uint8Array.of(0,1)}})},xa={op:"merges",apply(t,e){t.sheet(e.sheet).merges=e.after.map(n=>({...n}))},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"merges",sheet:"s1",before:[],after:[{top:0,left:0,bottom:1,right:2}]})},va={op:"sheet-add",apply(t,e){if(t.hasSheet(e.sheet.id))throw new Error(`Sheet '${e.sheet.id}' is in the workbook already.`);if(e.index<0||e.index>t.sheets.length)throw new Error(`No sheet position ${e.index}.`);t.sheets.splice(e.index,0,e.sheet)},invert:t=>({op:"sheet-delete",index:t.index,sheet:t.sheet}),example:t=>({op:"sheet-add",index:1,sheet:t.createSheet("Example","example")})},Ea={op:"sheet-delete",apply(t,e){if(t.sheets[e.index]!==e.sheet)throw new Error(`Sheet '${e.sheet.id}' is not at position ${e.index}.`);t.sheets.splice(e.index,1)},invert:t=>({op:"sheet-add",index:t.index,sheet:t.sheet}),example:t=>({op:"sheet-delete",index:0,sheet:t.sheet("s1")})},ka={op:"sheet-rename",apply(t,e){t.sheet(e.sheet).name=e.after},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"sheet-rename",sheet:"s1",before:"Sheet1",after:"Budget"})},Sa={op:"sheet-move",apply(t,e){const[n]=t.sheets.splice(e.from,1);if(n===void 0)throw new Error(`No sheet at position ${e.from}.`);t.sheets.splice(e.to,0,n)},invert:t=>({...t,from:t.to,to:t.from}),example:()=>({op:"sheet-move",from:0,to:0})},Ca={op:"frozen",apply(t,e){t.sheet(e.sheet).frozen={...e.after}},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"frozen",sheet:"s1",before:{rows:0,cols:0},after:{rows:1,cols:2}})},$a=[ga,pa,wa,ya,ba,xa,va,Ea,ka,Sa,Ca],Oi=["#DIV/0!","#REF!","#NAME?","#VALUE!","#N/A","#NUM!","#NULL!","#CYCLE!","#BUSY!","#SPILL!","#ERROR!"],Ar=new Set(Oi);function Je(t,e){if(!Ar.has(t))throw new Error(`'${t}' is not a cell error; there are ${Oi.join(" ")}.`);return e===void 0?{error:t}:{error:t,message:e}}function j(t){return typeof t=="object"&&t!==null&&Ar.has(t.error)}function Cn(t){return Ar.has(t)}const $n={decimal:".",group:",",months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]};class At extends Error{}const gs={black:"#000000",blue:"#0000ff",cyan:"#00ffff",green:"#00ff00",magenta:"#ff00ff",red:"#ff0000",white:"#ffffff",yellow:"#ffff00"};function Aa(t){const e=[];let n="";for(let o=0;o<t.length;o+=1){const r=t[o];if(r==='"'){const s=t.indexOf('"',o+1);if(s<0)throw new At(`'${t}' opens a quote it never closes.`);n+=t.slice(o,s+1),o=s}else if(r==="["){const s=t.indexOf("]",o+1);if(s<0)throw new At(`'${t}' opens a bracket it never closes.`);n+=t.slice(o,s+1),o=s}else if(r==="\\"||r==="_"||r==="*"){if(o+1>=t.length)throw new At(`'${t}' ends with ${r} and nothing after it.`);n+=t.slice(o,o+2),o+=1}else r===";"?(e.push(n),n=""):n+=r}if(e.push(n),e.length>4)throw new At(`'${t}' has ${e.length} sections; a format has at most four.`);return e}const Ma=/[ymdhsYMDHS]/;function Ta(t,e){const n=[],o={tokens:n,isDate:!1,isText:!1,hasAmPm:!1};let r=0;const s=l=>{const c=n[n.length-1];c?.t==="lit"?c.s+=l:n.push({t:"lit",s:l})};for(;r<t.length;){const l=t[r],c=t.slice(r);if(l==='"'){const u=t.indexOf('"',r+1);s(t.slice(r+1,u)),r=u+1}else if(l==="\\")s(t[r+1]),r+=2;else if(l==="_")s(" "),r+=2;else if(l==="*")r+=2;else if(l==="["){const u=t.indexOf("]",r),h=t.slice(r+1,u),d=h.toLowerCase();if(d in gs)o.color=gs[d];else if(/^color\d+$/.test(d))o.color=void 0;else if(/^(<=|>=|<>|<|>|=)-?\d+(\.\d+)?$/.test(h)){const f=/^(<=|>=|<>|<|>|=)(-?\d+(?:\.\d+)?)$/.exec(h);o.condition={op:f[1],value:Number(f[2])}}else if(/^h+$/i.test(h)||/^m+$/i.test(h)||/^s+$/i.test(h))n.push({t:"elapsed",unit:h[0].toLowerCase(),width:h.length}),o.isDate=!0;else if(h.startsWith("$"))s(h.slice(1).split("-")[0]);else throw new At(`'${e}': [${h}] is not a colour, a condition or an elapsed time.`);r=u+1}else if(/^general/i.test(c))n.push({t:"general"}),r+=7;else if(/^(am\/pm|a\/p)/i.test(c)){const u=/^am\/pm/i.test(c)?t.slice(r,r+5):t.slice(r,r+3);n.push({t:"ampm",s:u}),o.hasAmPm=!0,o.isDate=!0,r+=u.length}else if(l==="0"||l==="#"||l==="?")n.push({t:"digit",c:l}),r+=1;else if(l==="."){const u=n[n.length-1];if(u?.t==="date"&&u.s.toLowerCase().startsWith("s")){let h=r+1;for(;t[h]==="0";)h+=1;n.push({t:"date",s:`.${"0".repeat(h-r-1)}`}),r=h}else n.push({t:"point"}),r+=1}else if(l===",")n.push({t:"comma"}),r+=1;else if(l==="%")n.push({t:"percent"}),r+=1;else if((l==="E"||l==="e")&&(t[r+1]==="+"||t[r+1]==="-"))n.push({t:"exp",sign:t[r+1]}),r+=2;else if(l==="@")n.push({t:"text"}),o.isText=!0,r+=1;else if(Ma.test(l)){let u=r+1;for(;u<t.length&&t[u].toLowerCase()===l.toLowerCase();)u+=1;n.push({t:"date",s:t.slice(r,u).toLowerCase()}),o.isDate=!0,r=u}else{if(l==="/"&&n.some(u=>u.t==="digit")&&!o.isDate)throw new At(`'${e}': fractions (# ?/?) are not supported yet.`);s(l),r+=1}}if(o.isDate)for(let l=0;l<n.length;l+=1){const c=n[l];c.t==="comma"?n[l]={t:"lit",s:","}:c.t==="point"?n[l]={t:"lit",s:"."}:c.t==="percent"&&(n[l]={t:"lit",s:"%"})}const i=n.filter(l=>l.t==="date"||l.t==="elapsed"),a=l=>l===void 0?"":l.t==="date"?l.s[0]:l.unit;return i.forEach((l,c)=>{l.t!=="date"||l.s[0]!=="m"||l.s.length>2||(a(i[c-1])==="h"||a(i[c+1])==="s")&&(l.s=l.s==="m"?"mi":"mmi")}),o}function Mr(t,e){if(t===0)return"0";const n=Math.abs(t);let o;if(n>=1e11||n<1e-9)o=t.toExponential(5).replace(/\.?0+e/,"e").replace("e+","E+").replace("e-","E-"),o=o.replace(/E([+-])(\d)$/,"E$10$2");else if(Number.isInteger(t))o=String(t);else{const r=String(Math.trunc(n)).length+(t<0?1:0),s=Math.max(0,Math.min(10,11-r-1));o=String(Number(t.toFixed(s)))}return o.replace(".",e.decimal)}function Ra(t){const e=Math.floor(t),n=Math.round((t-e)*864e5),o=e<60?e+1:e,r=new Date(Date.UTC(1899,11,30)+o*864e5-(e<60?864e5:0));return{...e===60?{y:1900,m:2,d:29,dow:4}:{y:r.getUTCFullYear(),m:r.getUTCMonth()+1,d:r.getUTCDate(),dow:r.getUTCDay()},ms:n}}function Ge(t,e){return String(t).padStart(e,"0")}function za(t,e,n){const o=t.tokens.reduce((m,g)=>g.t==="date"&&g.s.startsWith(".")?Math.max(m,g.s.length-1):m,0),r=86400*10**o,s=t.tokens.some(m=>m.t==="elapsed"),i=o>0||s?Math.round(e*r)/r:Math.floor(e*r+1e-9)/r,a=Ra(i),l=Math.round(i*864e5);let c=Math.floor(a.ms/36e5);const u=Math.floor(a.ms%36e5/6e4),h=Math.floor(a.ms%6e4/1e3),d=a.ms%1e3;let f="";for(const m of t.tokens)if(m.t==="lit")f+=m.s;else if(m.t==="ampm"){const g=c>=12;f+=m.s.length===5?g?"PM":"AM":g?"P":"A"}else if(m.t==="elapsed"){const g=m.unit==="h"?Math.floor(l/36e5):m.unit==="m"?Math.floor(l/6e4):Math.floor(l/1e3);f+=Ge(g,m.width)}else if(m.t==="date"){const g=t.hasAmPm?(c+11)%12+1:c;switch(m.s){case"y":case"yy":f+=Ge(a.y%100,2);break;case"yyy":case"yyyy":f+=String(a.y);break;case"m":f+=String(a.m);break;case"mm":f+=Ge(a.m,2);break;case"mmm":f+=n.months[a.m-1].slice(0,3);break;case"mmmm":f+=n.months[a.m-1];break;case"mmmmm":f+=n.months[a.m-1][0];break;case"d":f+=String(a.d);break;case"dd":f+=Ge(a.d,2);break;case"ddd":f+=n.days[a.dow].slice(0,3);break;case"dddd":f+=n.days[a.dow];break;case"h":f+=String(g);break;case"hh":f+=Ge(g,2);break;case"mi":f+=String(u);break;case"mmi":f+=Ge(u,2);break;case"s":f+=String(h);break;case"ss":f+=Ge(h,2);break;default:m.s.startsWith(".")?f+=n.decimal+Ge(Math.floor(d/10**(3-(m.s.length-1))),m.s.length-1):f+=m.s}}else m.t==="general"&&(f+=Mr(e,n));return c=0,f}function Na(t,e,n,o){const r=e.filter(a=>a==="0").length;let s=t==="0"&&r===0?"":t;s=s.padStart(r,"0");const i=Math.max(0,e.filter(a=>a==="?").length+r-s.length);return n&&(s=s.replace(/\B(?=(\d{3})+(?!\d))/g,o.group))," ".repeat(e.includes("?")?Math.max(0,i-r):0)+s}function Oa(t,e,n){const o=t.tokens;if(o.some(z=>z.t==="general"))return o.map(z=>z.t==="lit"?z.s:z.t==="general"?Mr(e,n):"").join("");let r=e;const s=o.filter(z=>z.t==="percent").length;r*=100**s;let i=-1;o.forEach((z,P)=>{z.t==="digit"&&(i=P)});const a=o.findIndex(z=>z.t==="point"),l=a>=0?a:i+1,c=new Set;if(a>=0)for(let z=a-1;z>=0&&o[z].t==="comma";z-=1)c.add(z);for(let z=i+1;z<o.length&&o[z].t==="comma";z+=1)c.add(z);r/=1e3**c.size;const u=o.findIndex(z=>z.t==="exp"),h=u>=0?o.slice(0,u):o,d=[],f=[];let m=!1,g=!1;h.forEach((z,P)=>{z.t==="point"?m=!0:z.t==="digit"?(m?f:d).push(z.c):z.t==="comma"&&!m&&!c.has(P)&&P<l&&(g=!0)});let w=0;if(u>=0&&r!==0){const z=d.length>1&&d[0]==="#"?d.length:1;w=Math.floor(Math.log10(Math.abs(r))/z)*z,z===1&&(w=Math.floor(Math.log10(Math.abs(r)))-Math.max(0,d.filter(P=>P==="0").length-1)),r/=10**w}const y=Math.abs(r).toFixed(f.length);let[x,$=""]=y.split(".");if(u>=0&&y.startsWith("10")&&d.length<=1){w+=1;const z=(Math.abs(r)/10).toFixed(f.length).split(".");x=z[0],$=z[1]??""}let A="";for(let z=f.length-1,P=!1;z>=0;z-=1){const F=$[z];if(!P&&F==="0"&&f[z]!=="0"){A=(f[z]==="?"?" ":"")+A;continue}P=!0,A=F+A}const O=Na(x,d,g,n);let D="",I=!1,U=!1,X=!1;for(let z=0;z<o.length;z+=1){const P=o[z];if(P.t==="lit")D+=P.s;else if(P.t==="percent")D+="%";else if(P.t==="text")D+="";else if(P.t==="digit"&&(u<0||z<u))z<(a>=0?a:1/0)&&!I?(D+=O,I=!0):z>a&&a>=0&&!U&&(D+=A,U=!0);else if(P.t==="point")I||(D+=O,I=!0),A.trim()===""&&f.every(F=>F==="#")||(D+=n.decimal);else if(P.t==="exp"&&!X){const F=o.slice(z+1).filter(J=>J.t==="digit").length,K=w<0?"-":P.sign==="+"?"+":"";D+=`E${K}${Ge(Math.abs(w),Math.max(1,F))}`,X=!0}}return D}const ps=new Map;function Tr(t,e=$n){const n=e===$n?t:`${t}\0${e.decimal}${e.group}`,o=ps.get(n);if(o)return o;const r=Aa(t).map(u=>Ta(u,t)),s=r.find(u=>u.isText),i=r.filter(u=>u!==s||r.length===1),a=r.some(u=>u.condition!==void 0),l=u=>{if(a){for(const d of i){const f=d.condition;if(f===void 0)continue;if(f.op==="<"?u<f.value:f.op==="<="?u<=f.value:f.op===">"?u>f.value:f.op===">="?u>=f.value:f.op==="="?u===f.value:u!==f.value)return{section:d,signed:f.value>=0&&u<0}}return{section:i.find(d=>d.condition===void 0)??i[i.length-1],signed:u<0}}return i.length>=3&&u===0?{section:i[2],signed:!1}:i.length>=2&&u<0?{section:i[1],signed:!1}:{section:i[0],signed:u<0}},c=u=>{if(u===null)return{text:""};if(j(u))return{text:u.error};if(typeof u=="boolean")return{text:u?"TRUE":"FALSE"};if(typeof u=="string"){const w=s??(r.length===1&&r[0].isText?r[0]:void 0);return w===void 0?{text:u}:{text:w.tokens.map(y=>y.t==="lit"?y.s:y.t==="text"?u:"").join(""),color:w.color}}const{section:h,signed:d}=l(u);if(h.isText)return{text:Mr(u,e)};const f=Math.abs(u),m=h.isDate?za(h,f,e):Oa(h,f,e),g=/^[^1-9]*$/.test(m);return{text:d&&!g?`-${m}`:m,color:h.color}};return ps.set(n,c),c}function Ii(t){Tr(t)}const Rr=["font","size","bold","italic","underline","strike","color","fill","align","valign","wrap","borders","format","type"],Ia=new Set(Rr),ws=65535;function ys(t){const e={};for(const n of Rr){const o=t[n];o===void 0||o===!1||(e[n]=n==="borders"?_a(o):o)}return JSON.stringify(e)}function _a(t){if(t===void 0)return;const e={};for(const n of["top","right","bottom","left"])t[n]&&(e[n]=t[n]);return e}function zr(t,e="style"){if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`${e}: a style is an object.`);for(const o of Object.keys(t))if(!Ia.has(o))throw new Error(`${e}: '${o}' is not a style property (${Rr.join(", ")}).`);const n=t;for(const o of["bold","italic","underline","strike","wrap"])if(n[o]!==void 0&&typeof n[o]!="boolean")throw new Error(`${e}.${o}: true or false.`);for(const o of["font","color","fill","format"])if(n[o]!==void 0&&typeof n[o]!="string")throw new Error(`${e}.${o}: a string.`);if(n.type!==void 0&&!(typeof n.type=="string"&&n.type!==""))throw new Error(`${e}.type: the id of a cell type, a non-empty string.`);if(n.format!==void 0)try{Ii(n.format)}catch(o){throw new Error(`${e}.format: ${o.message}`)}if(n.size!==void 0&&!(typeof n.size=="number"&&n.size>0))throw new Error(`${e}.size: a positive number.`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new Error(`${e}.align: left, center or right.`);if(n.valign!==void 0&&!["top","middle","bottom"].includes(n.valign))throw new Error(`${e}.valign: top, middle or bottom.`)}class La{#e=[{}];#t=new Map([[ys({}),0]]);intern(e){const n=ys(e);let o=this.#t.get(n);if(o===void 0){if(this.#e.length>ws)throw new Error(`A workbook holds at most ${ws+1} distinct styles.`);o=this.#e.length,this.#e.push(JSON.parse(n)),this.#t.set(n,o)}return o}get(e){const n=this.#e[e];if(n===void 0)throw new Error(`No style ${e}; the workbook has ${this.#e.length}.`);return n}get size(){return this.#e.length}all(){return this.#e}}function Ye(t){if(!Number.isInteger(t)||t<0)throw new Error(`No column at index ${t}.`);let e="",n=t+1;for(;n>0;){const o=(n-1)%26;e=String.fromCharCode(65+o)+e,n=Math.floor((n-1)/26)}return e}function _i(t){if(!/^[A-Za-z]{1,3}$/.test(t))throw new Error(`'${t}' is not a column (A to XFD).`);let e=0;for(const n of t.toUpperCase())e=e*26+(n.charCodeAt(0)-64);return e-1}function hr(t){return`${Ye(t.col)}${t.row+1}`}const Da=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;function fr(t){const e=Da.exec(t.trim());if(!e)throw new Error(`'${t}' is not a cell reference such as B3.`);return{row:Number(e[2])-1,col:_i(e[1])}}function Li(t){const e=t.trim().split(":");if(e.length>2||e[0]==="")throw new Error(`'${t}' is not a range such as A1:C4.`);const n=fr(e[0]),o=e.length===2?fr(e[1]):n;return $o(n,o)}function Oe(t){const e=hr({row:t.top,col:t.left});return t.top===t.bottom&&t.left===t.right?e:`${e}:${hr({row:t.bottom,col:t.right})}`}function $o(t,e=t){return{top:Math.min(t.row,e.row),left:Math.min(t.col,e.col),bottom:Math.max(t.row,e.row),right:Math.max(t.col,e.col)}}function zt(t,e){return e.row>=t.top&&e.row<=t.bottom&&e.col>=t.left&&e.col<=t.right}function mt(t,e){return t.left<=e.right&&e.left<=t.right&&t.top<=e.bottom&&e.top<=t.bottom}function Nr(t){const e=t.lastIndexOf("!");if(e<0)return{ref:t};let n=t.slice(0,e);if(n.startsWith("'")){if(!n.endsWith("'")||n.length<2)throw new Error(`'${t}' has an unclosed sheet name.`);n=n.slice(1,-1).replace(/''/g,"'")}if(n==="")throw new Error(`'${t}' names an empty sheet.`);return{sheet:n,ref:t.slice(e+1)}}const Di={argumentSeparator:",",decimal:".",arrayColumn:","},Ua=["#DIV/0!","#REF!","#NAME?","#VALUE!","#N/A","#NUM!","#NULL!","#CYCLE!","#BUSY!","#SPILL!","#ERROR!","#GETTING_DATA"],Fa=["<>","<=",">=","+","-","*","/","^","&","=","<",">","%",":"],Pa=/\$?[A-Za-z]{1,3}\$?[0-9]{1,7}/y,ja=/\$?[A-Za-z]{1,3}(?=\s*:)/y,Ba=/[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?/y,Ha=/[0-9]*(?:,[0-9]*)?(?:[eE][+-]?[0-9]+)?/y,Ya=/\$?[0-9]{1,7}(?=\s*:)/y,Xa=/\$?[0-9]{1,7}(?![0-9.eE%A-Za-z(])/y,Wa=/\$[0-9]{1,7}/y,Va=/[A-Za-z_\\][A-Za-z0-9_.\\]*/y,bs=/\$?[A-Za-z]{1,3}(?![A-Za-z0-9_(])/y;function Ve(t,e,n){t.lastIndex=n;const o=t.exec(e);return o===null?-1:o[0].length}const Fo=t=>t===" "||t===" "||t===`
1
+ import{mB as pe,mC as sa,bD as nt,bF as oe,e8 as Ti,mD as ia,j as C,r as k,e7 as Cr,mE as $r,gI as la,v as hs,_ as Ri,mF as aa,mG as ca,mH as ua,bk as Be,mI as ha,mJ as fs,dl as fa,I as ds,W as da,e6 as Uo}from"../datalayer-app-main.js";import{K as ma}from"./KebabHorizontalIcon-D6AY8pIS.js";const zi={rows:new Int32Array(0),cols:new Int32Array(0),values:[],formulas:[],styles:new Uint16Array(0)};function Kt(t,e){const n=[],o=[],r=[],s=[],i=[];for(const[a,l,c]of t.cells.entries(e))n.push(a),o.push(l),r.push(c.value),s.push(c.formula),i.push(c.style);return{rows:Int32Array.from(n),cols:Int32Array.from(o),values:r,formulas:s,styles:Uint16Array.from(i)}}function Rt(t){return{rows:Int32Array.from(t,e=>e[0]),cols:Int32Array.from(t,e=>e[1]),values:t.map(e=>e[2].value),formulas:t.map(e=>e[2].formula),styles:Uint16Array.from(t,e=>e[2].style)}}function Mn(t){const e=[];for(let n=0;n<t.rows.length;n+=1){const o=t.formulas[n];e.push([t.rows[n],t.cols[n],o===void 0?{value:t.values[n],style:t.styles[n]}:{value:t.values[n],formula:o,style:t.styles[n]}])}return e}function ms(t){let e=64+t.rows.length*26;for(const n of t.values)typeof n=="string"&&(e+=n.length*2);for(const n of t.formulas)n!==void 0&&(e+=n.length*2);return e}function fo(t){return 64+t.ids.byteLength+(t.sizes?.byteLength??0)+(t.hidden?.byteLength??0)}const Co=(t,e)=>e==="rows"?t.rows:t.cols,ur=t=>({ids:Int32Array.from(t),sizes:null,hidden:null}),ga={op:"cells",apply(t,e){const n=t.sheet(e.sheet);for(const[o,r]of[...n.cells.entries(e.zone)])n.cells.set(o,r,null);for(const[o,r,s]of Mn(e.after)){if(o<e.zone.top||o>e.zone.bottom||r<e.zone.left||r>e.zone.right)throw new Error(`A cells patch writes ${o},${r} outside its zone.`);n.cells.set(o,r,s)}},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"cells",sheet:"s1",zone:{top:0,left:0,bottom:1,right:1},before:zi,after:Rt([[1,1,{value:42,style:0}]])}),bytes:t=>ms(t.before)+ms(t.after)};function Ni(t,e,n,o){e==="rows"?t.cells.shiftRows(n,o,t.rows.count):t.cells.shiftCols(n,o,t.cols.count)}const pa={op:"axis-insert",apply(t,e){const n=t.sheet(e.sheet);Co(n,e.axis).insert(e.at,e.n,e.inserted),Ni(n,e.axis,e.at,e.n)},invert:t=>({op:"axis-delete",sheet:t.sheet,axis:t.axis,at:t.at,n:t.n,removed:t.inserted,tail:t.dropped}),example:t=>{const e=t.sheet("s1").rows.count;return{op:"axis-insert",sheet:"s1",axis:"rows",at:2,n:2,inserted:ur([1<<30,(1<<30)+1]),dropped:ur([e-2,e-1])}},bytes:t=>fo(t.inserted)+(t.dropped?fo(t.dropped):0)},wa={op:"axis-delete",apply(t,e){const n=t.sheet(e.sheet);Co(n,e.axis).delete(e.at,e.n,e.tail),Ni(n,e.axis,e.at,-e.n)},invert:t=>({op:"axis-insert",sheet:t.sheet,axis:t.axis,at:t.at,n:t.n,inserted:t.removed,dropped:t.tail}),example:t=>({op:"axis-delete",sheet:"s1",axis:"rows",at:1,n:1,removed:ur([1])}),bytes:t=>fo(t.removed)+(t.tail?fo(t.tail):0)},ya={op:"axis-move",apply(t,e){Co(t.sheet(e.sheet),e.axis).move(e.at,e.n,e.to)},invert:t=>t.to<t.at?{...t,at:t.to,to:t.at+t.n}:{...t,at:t.to-t.n,to:t.at},example:()=>({op:"axis-move",sheet:"s1",axis:"cols",at:1,n:2,to:6})},ba={op:"axis-sizes",apply(t,e){Co(t.sheet(e.sheet),e.axis).setSegmentSizes(e.at,e.after.sizes,e.after.hidden,e.n)},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"axis-sizes",sheet:"s1",axis:"cols",at:3,n:2,before:{sizes:null,hidden:null},after:{sizes:Float64Array.of(40,50),hidden:Uint8Array.of(0,1)}})},xa={op:"merges",apply(t,e){t.sheet(e.sheet).merges=e.after.map(n=>({...n}))},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"merges",sheet:"s1",before:[],after:[{top:0,left:0,bottom:1,right:2}]})},va={op:"sheet-add",apply(t,e){if(t.hasSheet(e.sheet.id))throw new Error(`Sheet '${e.sheet.id}' is in the workbook already.`);if(e.index<0||e.index>t.sheets.length)throw new Error(`No sheet position ${e.index}.`);t.sheets.splice(e.index,0,e.sheet)},invert:t=>({op:"sheet-delete",index:t.index,sheet:t.sheet}),example:t=>({op:"sheet-add",index:1,sheet:t.createSheet("Example","example")})},Ea={op:"sheet-delete",apply(t,e){if(t.sheets[e.index]!==e.sheet)throw new Error(`Sheet '${e.sheet.id}' is not at position ${e.index}.`);t.sheets.splice(e.index,1)},invert:t=>({op:"sheet-add",index:t.index,sheet:t.sheet}),example:t=>({op:"sheet-delete",index:0,sheet:t.sheet("s1")})},ka={op:"sheet-rename",apply(t,e){t.sheet(e.sheet).name=e.after},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"sheet-rename",sheet:"s1",before:"Sheet1",after:"Budget"})},Sa={op:"sheet-move",apply(t,e){const[n]=t.sheets.splice(e.from,1);if(n===void 0)throw new Error(`No sheet at position ${e.from}.`);t.sheets.splice(e.to,0,n)},invert:t=>({...t,from:t.to,to:t.from}),example:()=>({op:"sheet-move",from:0,to:0})},Ca={op:"frozen",apply(t,e){t.sheet(e.sheet).frozen={...e.after}},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"frozen",sheet:"s1",before:{rows:0,cols:0},after:{rows:1,cols:2}})},$a=[ga,pa,wa,ya,ba,xa,va,Ea,ka,Sa,Ca],Oi=["#DIV/0!","#REF!","#NAME?","#VALUE!","#N/A","#NUM!","#NULL!","#CYCLE!","#BUSY!","#SPILL!","#ERROR!"],Ar=new Set(Oi);function Je(t,e){if(!Ar.has(t))throw new Error(`'${t}' is not a cell error; there are ${Oi.join(" ")}.`);return e===void 0?{error:t}:{error:t,message:e}}function j(t){return typeof t=="object"&&t!==null&&Ar.has(t.error)}function Cn(t){return Ar.has(t)}const $n={decimal:".",group:",",months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]};class At extends Error{}const gs={black:"#000000",blue:"#0000ff",cyan:"#00ffff",green:"#00ff00",magenta:"#ff00ff",red:"#ff0000",white:"#ffffff",yellow:"#ffff00"};function Aa(t){const e=[];let n="";for(let o=0;o<t.length;o+=1){const r=t[o];if(r==='"'){const s=t.indexOf('"',o+1);if(s<0)throw new At(`'${t}' opens a quote it never closes.`);n+=t.slice(o,s+1),o=s}else if(r==="["){const s=t.indexOf("]",o+1);if(s<0)throw new At(`'${t}' opens a bracket it never closes.`);n+=t.slice(o,s+1),o=s}else if(r==="\\"||r==="_"||r==="*"){if(o+1>=t.length)throw new At(`'${t}' ends with ${r} and nothing after it.`);n+=t.slice(o,o+2),o+=1}else r===";"?(e.push(n),n=""):n+=r}if(e.push(n),e.length>4)throw new At(`'${t}' has ${e.length} sections; a format has at most four.`);return e}const Ma=/[ymdhsYMDHS]/;function Ta(t,e){const n=[],o={tokens:n,isDate:!1,isText:!1,hasAmPm:!1};let r=0;const s=l=>{const c=n[n.length-1];c?.t==="lit"?c.s+=l:n.push({t:"lit",s:l})};for(;r<t.length;){const l=t[r],c=t.slice(r);if(l==='"'){const u=t.indexOf('"',r+1);s(t.slice(r+1,u)),r=u+1}else if(l==="\\")s(t[r+1]),r+=2;else if(l==="_")s(" "),r+=2;else if(l==="*")r+=2;else if(l==="["){const u=t.indexOf("]",r),h=t.slice(r+1,u),d=h.toLowerCase();if(d in gs)o.color=gs[d];else if(/^color\d+$/.test(d))o.color=void 0;else if(/^(<=|>=|<>|<|>|=)-?\d+(\.\d+)?$/.test(h)){const f=/^(<=|>=|<>|<|>|=)(-?\d+(?:\.\d+)?)$/.exec(h);o.condition={op:f[1],value:Number(f[2])}}else if(/^h+$/i.test(h)||/^m+$/i.test(h)||/^s+$/i.test(h))n.push({t:"elapsed",unit:h[0].toLowerCase(),width:h.length}),o.isDate=!0;else if(h.startsWith("$"))s(h.slice(1).split("-")[0]);else throw new At(`'${e}': [${h}] is not a colour, a condition or an elapsed time.`);r=u+1}else if(/^general/i.test(c))n.push({t:"general"}),r+=7;else if(/^(am\/pm|a\/p)/i.test(c)){const u=/^am\/pm/i.test(c)?t.slice(r,r+5):t.slice(r,r+3);n.push({t:"ampm",s:u}),o.hasAmPm=!0,o.isDate=!0,r+=u.length}else if(l==="0"||l==="#"||l==="?")n.push({t:"digit",c:l}),r+=1;else if(l==="."){const u=n[n.length-1];if(u?.t==="date"&&u.s.toLowerCase().startsWith("s")){let h=r+1;for(;t[h]==="0";)h+=1;n.push({t:"date",s:`.${"0".repeat(h-r-1)}`}),r=h}else n.push({t:"point"}),r+=1}else if(l===",")n.push({t:"comma"}),r+=1;else if(l==="%")n.push({t:"percent"}),r+=1;else if((l==="E"||l==="e")&&(t[r+1]==="+"||t[r+1]==="-"))n.push({t:"exp",sign:t[r+1]}),r+=2;else if(l==="@")n.push({t:"text"}),o.isText=!0,r+=1;else if(Ma.test(l)){let u=r+1;for(;u<t.length&&t[u].toLowerCase()===l.toLowerCase();)u+=1;n.push({t:"date",s:t.slice(r,u).toLowerCase()}),o.isDate=!0,r=u}else{if(l==="/"&&n.some(u=>u.t==="digit")&&!o.isDate)throw new At(`'${e}': fractions (# ?/?) are not supported yet.`);s(l),r+=1}}if(o.isDate)for(let l=0;l<n.length;l+=1){const c=n[l];c.t==="comma"?n[l]={t:"lit",s:","}:c.t==="point"?n[l]={t:"lit",s:"."}:c.t==="percent"&&(n[l]={t:"lit",s:"%"})}const i=n.filter(l=>l.t==="date"||l.t==="elapsed"),a=l=>l===void 0?"":l.t==="date"?l.s[0]:l.unit;return i.forEach((l,c)=>{l.t!=="date"||l.s[0]!=="m"||l.s.length>2||(a(i[c-1])==="h"||a(i[c+1])==="s")&&(l.s=l.s==="m"?"mi":"mmi")}),o}function Mr(t,e){if(t===0)return"0";const n=Math.abs(t);let o;if(n>=1e11||n<1e-9)o=t.toExponential(5).replace(/\.?0+e/,"e").replace("e+","E+").replace("e-","E-"),o=o.replace(/E([+-])(\d)$/,"E$10$2");else if(Number.isInteger(t))o=String(t);else{const r=String(Math.trunc(n)).length+(t<0?1:0),s=Math.max(0,Math.min(10,11-r-1));o=String(Number(t.toFixed(s)))}return o.replace(".",e.decimal)}function Ra(t){const e=Math.floor(t),n=Math.round((t-e)*864e5),o=e<60?e+1:e,r=new Date(Date.UTC(1899,11,30)+o*864e5-(e<60?864e5:0));return{...e===60?{y:1900,m:2,d:29,dow:4}:{y:r.getUTCFullYear(),m:r.getUTCMonth()+1,d:r.getUTCDate(),dow:r.getUTCDay()},ms:n}}function Ge(t,e){return String(t).padStart(e,"0")}function za(t,e,n){const o=t.tokens.reduce((m,g)=>g.t==="date"&&g.s.startsWith(".")?Math.max(m,g.s.length-1):m,0),r=86400*10**o,s=t.tokens.some(m=>m.t==="elapsed"),i=o>0||s?Math.round(e*r)/r:Math.floor(e*r+1e-9)/r,a=Ra(i),l=Math.round(i*864e5);let c=Math.floor(a.ms/36e5);const u=Math.floor(a.ms%36e5/6e4),h=Math.floor(a.ms%6e4/1e3),d=a.ms%1e3;let f="";for(const m of t.tokens)if(m.t==="lit")f+=m.s;else if(m.t==="ampm"){const g=c>=12;f+=m.s.length===5?g?"PM":"AM":g?"P":"A"}else if(m.t==="elapsed"){const g=m.unit==="h"?Math.floor(l/36e5):m.unit==="m"?Math.floor(l/6e4):Math.floor(l/1e3);f+=Ge(g,m.width)}else if(m.t==="date"){const g=t.hasAmPm?(c+11)%12+1:c;switch(m.s){case"y":case"yy":f+=Ge(a.y%100,2);break;case"yyy":case"yyyy":f+=String(a.y);break;case"m":f+=String(a.m);break;case"mm":f+=Ge(a.m,2);break;case"mmm":f+=n.months[a.m-1].slice(0,3);break;case"mmmm":f+=n.months[a.m-1];break;case"mmmmm":f+=n.months[a.m-1][0];break;case"d":f+=String(a.d);break;case"dd":f+=Ge(a.d,2);break;case"ddd":f+=n.days[a.dow].slice(0,3);break;case"dddd":f+=n.days[a.dow];break;case"h":f+=String(g);break;case"hh":f+=Ge(g,2);break;case"mi":f+=String(u);break;case"mmi":f+=Ge(u,2);break;case"s":f+=String(h);break;case"ss":f+=Ge(h,2);break;default:m.s.startsWith(".")?f+=n.decimal+Ge(Math.floor(d/10**(3-(m.s.length-1))),m.s.length-1):f+=m.s}}else m.t==="general"&&(f+=Mr(e,n));return c=0,f}function Na(t,e,n,o){const r=e.filter(a=>a==="0").length;let s=t==="0"&&r===0?"":t;s=s.padStart(r,"0");const i=Math.max(0,e.filter(a=>a==="?").length+r-s.length);return n&&(s=s.replace(/\B(?=(\d{3})+(?!\d))/g,o.group))," ".repeat(e.includes("?")?Math.max(0,i-r):0)+s}function Oa(t,e,n){const o=t.tokens;if(o.some(z=>z.t==="general"))return o.map(z=>z.t==="lit"?z.s:z.t==="general"?Mr(e,n):"").join("");let r=e;const s=o.filter(z=>z.t==="percent").length;r*=100**s;let i=-1;o.forEach((z,P)=>{z.t==="digit"&&(i=P)});const a=o.findIndex(z=>z.t==="point"),l=a>=0?a:i+1,c=new Set;if(a>=0)for(let z=a-1;z>=0&&o[z].t==="comma";z-=1)c.add(z);for(let z=i+1;z<o.length&&o[z].t==="comma";z+=1)c.add(z);r/=1e3**c.size;const u=o.findIndex(z=>z.t==="exp"),h=u>=0?o.slice(0,u):o,d=[],f=[];let m=!1,g=!1;h.forEach((z,P)=>{z.t==="point"?m=!0:z.t==="digit"?(m?f:d).push(z.c):z.t==="comma"&&!m&&!c.has(P)&&P<l&&(g=!0)});let w=0;if(u>=0&&r!==0){const z=d.length>1&&d[0]==="#"?d.length:1;w=Math.floor(Math.log10(Math.abs(r))/z)*z,z===1&&(w=Math.floor(Math.log10(Math.abs(r)))-Math.max(0,d.filter(P=>P==="0").length-1)),r/=10**w}const y=Math.abs(r).toFixed(f.length);let[x,$=""]=y.split(".");if(u>=0&&y.startsWith("10")&&d.length<=1){w+=1;const z=(Math.abs(r)/10).toFixed(f.length).split(".");x=z[0],$=z[1]??""}let A="";for(let z=f.length-1,P=!1;z>=0;z-=1){const F=$[z];if(!P&&F==="0"&&f[z]!=="0"){A=(f[z]==="?"?" ":"")+A;continue}P=!0,A=F+A}const O=Na(x,d,g,n);let D="",I=!1,U=!1,X=!1;for(let z=0;z<o.length;z+=1){const P=o[z];if(P.t==="lit")D+=P.s;else if(P.t==="percent")D+="%";else if(P.t==="text")D+="";else if(P.t==="digit"&&(u<0||z<u))z<(a>=0?a:1/0)&&!I?(D+=O,I=!0):z>a&&a>=0&&!U&&(D+=A,U=!0);else if(P.t==="point")I||(D+=O,I=!0),A.trim()===""&&f.every(F=>F==="#")||(D+=n.decimal);else if(P.t==="exp"&&!X){const F=o.slice(z+1).filter(J=>J.t==="digit").length,K=w<0?"-":P.sign==="+"?"+":"";D+=`E${K}${Ge(Math.abs(w),Math.max(1,F))}`,X=!0}}return D}const ps=new Map;function Tr(t,e=$n){const n=e===$n?t:`${t}\0${e.decimal}${e.group}`,o=ps.get(n);if(o)return o;const r=Aa(t).map(u=>Ta(u,t)),s=r.find(u=>u.isText),i=r.filter(u=>u!==s||r.length===1),a=r.some(u=>u.condition!==void 0),l=u=>{if(a){for(const d of i){const f=d.condition;if(f===void 0)continue;if(f.op==="<"?u<f.value:f.op==="<="?u<=f.value:f.op===">"?u>f.value:f.op===">="?u>=f.value:f.op==="="?u===f.value:u!==f.value)return{section:d,signed:f.value>=0&&u<0}}return{section:i.find(d=>d.condition===void 0)??i[i.length-1],signed:u<0}}return i.length>=3&&u===0?{section:i[2],signed:!1}:i.length>=2&&u<0?{section:i[1],signed:!1}:{section:i[0],signed:u<0}},c=u=>{if(u===null)return{text:""};if(j(u))return{text:u.error};if(typeof u=="boolean")return{text:u?"TRUE":"FALSE"};if(typeof u=="string"){const w=s??(r.length===1&&r[0].isText?r[0]:void 0);return w===void 0?{text:u}:{text:w.tokens.map(y=>y.t==="lit"?y.s:y.t==="text"?u:"").join(""),color:w.color}}const{section:h,signed:d}=l(u);if(h.isText)return{text:Mr(u,e)};const f=Math.abs(u),m=h.isDate?za(h,f,e):Oa(h,f,e),g=/^[^1-9]*$/.test(m);return{text:d&&!g?`-${m}`:m,color:h.color}};return ps.set(n,c),c}function Ii(t){Tr(t)}const Rr=["font","size","bold","italic","underline","strike","color","fill","align","valign","wrap","borders","format","type"],Ia=new Set(Rr),ws=65535;function ys(t){const e={};for(const n of Rr){const o=t[n];o===void 0||o===!1||(e[n]=n==="borders"?_a(o):o)}return JSON.stringify(e)}function _a(t){if(t===void 0)return;const e={};for(const n of["top","right","bottom","left"])t[n]&&(e[n]=t[n]);return e}function zr(t,e="style"){if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`${e}: a style is an object.`);for(const o of Object.keys(t))if(!Ia.has(o))throw new Error(`${e}: '${o}' is not a style property (${Rr.join(", ")}).`);const n=t;for(const o of["bold","italic","underline","strike","wrap"])if(n[o]!==void 0&&typeof n[o]!="boolean")throw new Error(`${e}.${o}: true or false.`);for(const o of["font","color","fill","format"])if(n[o]!==void 0&&typeof n[o]!="string")throw new Error(`${e}.${o}: a string.`);if(n.type!==void 0&&!(typeof n.type=="string"&&n.type!==""))throw new Error(`${e}.type: the id of a cell type, a non-empty string.`);if(n.format!==void 0)try{Ii(n.format)}catch(o){throw new Error(`${e}.format: ${o.message}`)}if(n.size!==void 0&&!(typeof n.size=="number"&&n.size>0))throw new Error(`${e}.size: a positive number.`);if(n.align!==void 0&&!["left","center","right"].includes(n.align))throw new Error(`${e}.align: left, center or right.`);if(n.valign!==void 0&&!["top","middle","bottom"].includes(n.valign))throw new Error(`${e}.valign: top, middle or bottom.`)}class La{#e=[{}];#t=new Map([[ys({}),0]]);intern(e){const n=ys(e);let o=this.#t.get(n);if(o===void 0){if(this.#e.length>ws)throw new Error(`A workbook holds at most ${ws+1} distinct styles.`);o=this.#e.length,this.#e.push(JSON.parse(n)),this.#t.set(n,o)}return o}get(e){const n=this.#e[e];if(n===void 0)throw new Error(`No style ${e}; the workbook has ${this.#e.length}.`);return n}get size(){return this.#e.length}all(){return this.#e}}function Ye(t){if(!Number.isInteger(t)||t<0)throw new Error(`No column at index ${t}.`);let e="",n=t+1;for(;n>0;){const o=(n-1)%26;e=String.fromCharCode(65+o)+e,n=Math.floor((n-1)/26)}return e}function _i(t){if(!/^[A-Za-z]{1,3}$/.test(t))throw new Error(`'${t}' is not a column (A to XFD).`);let e=0;for(const n of t.toUpperCase())e=e*26+(n.charCodeAt(0)-64);return e-1}function hr(t){return`${Ye(t.col)}${t.row+1}`}const Da=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;function fr(t){const e=Da.exec(t.trim());if(!e)throw new Error(`'${t}' is not a cell reference such as B3.`);return{row:Number(e[2])-1,col:_i(e[1])}}function Li(t){const e=t.trim().split(":");if(e.length>2||e[0]==="")throw new Error(`'${t}' is not a range such as A1:C4.`);const n=fr(e[0]),o=e.length===2?fr(e[1]):n;return $o(n,o)}function Oe(t){const e=hr({row:t.top,col:t.left});return t.top===t.bottom&&t.left===t.right?e:`${e}:${hr({row:t.bottom,col:t.right})}`}function $o(t,e=t){return{top:Math.min(t.row,e.row),left:Math.min(t.col,e.col),bottom:Math.max(t.row,e.row),right:Math.max(t.col,e.col)}}function zt(t,e){return e.row>=t.top&&e.row<=t.bottom&&e.col>=t.left&&e.col<=t.right}function mt(t,e){return t.left<=e.right&&e.left<=t.right&&t.top<=e.bottom&&e.top<=t.bottom}function Nr(t){const e=t.lastIndexOf("!");if(e<0)return{ref:t};let n=t.slice(0,e);if(n.startsWith("'")){if(!n.endsWith("'")||n.length<2)throw new Error(`'${t}' has an unclosed sheet name.`);n=n.slice(1,-1).replace(/''/g,"'")}if(n==="")throw new Error(`'${t}' names an empty sheet.`);return{sheet:n,ref:t.slice(e+1)}}const Di={argumentSeparator:",",decimal:".",arrayColumn:","},Ua=["#DIV/0!","#REF!","#NAME?","#VALUE!","#N/A","#NUM!","#NULL!","#CYCLE!","#BUSY!","#SPILL!","#ERROR!","#GETTING_DATA"],Fa=["<>","<=",">=","+","-","*","/","^","&","=","<",">","%",":"],Pa=/\$?[A-Za-z]{1,3}\$?[0-9]{1,7}/y,ja=/\$?[A-Za-z]{1,3}(?=\s*:)/y,Ba=/[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?/y,Ha=/[0-9]*(?:,[0-9]*)?(?:[eE][+-]?[0-9]+)?/y,Ya=/\$?[0-9]{1,7}(?=\s*:)/y,Xa=/\$?[0-9]{1,7}(?![0-9.eE%A-Za-z(])/y,Wa=/\$[0-9]{1,7}/y,Va=/[A-Za-z_\\][A-Za-z0-9_.\\]*/y,bs=/\$?[A-Za-z]{1,3}(?![A-Za-z0-9_(])/y;function Ve(t,e,n){t.lastIndex=n;const o=t.exec(e);return o===null?-1:o[0].length}const Fo=t=>t===" "||t===" "||t===`
2
2
  `||t==="\r"||t!==void 0&&/\s/.test(t),Po=t=>t!==void 0&&t>="0"&&t<="9",Ka=t=>t>="A"&&t<="Z"||t>="a"&&t<="z"||t==="_"||t==="\\";function Ui(t,e=Di){const n=[];let o=0;const r=(i,a)=>{n.push({kind:i,text:t.slice(o,a),start:o,end:a}),o=a},s=()=>{for(let i=n.length-1;i>=0;i-=1)if(n[i].kind!=="whitespace")return n[i].kind==="operator"&&n[i].text===":";return!1};for(;o<t.length;){const i=t[o];if(Fo(i)){let a=o+1;for(;a<t.length&&Fo(t[a]);)a+=1;r("whitespace",a)}else if(i==='"'){let a=o+1;for(;!(a>=t.length);)if(t[a]==='"')if(t[a+1]==='"')a+=2;else{a+=1;break}else a+=1;r("string",a)}else if(i==="'"){let a=o+1;for(;!(a>=t.length);)if(t[a]==="'")if(t[a+1]==="'")a+=2;else{a+=1;break}else a+=1;t[a]==="!"?r("sheet",a+1):r("unknown",a)}else if(i==="#"){const a=Ua.find(l=>t.slice(o,o+l.length).toUpperCase()===l);a?r("error",o+a.length):r("unknown",o+1)}else if(i==="(")r("lparen",o+1);else if(i===")")r("rparen",o+1);else if(i==="{")r("lbrace",o+1);else if(i==="}")r("rbrace",o+1);else if(i===e.argumentSeparator)r("separator",o+1);else if(i===";"||e.arrayColumn!==e.argumentSeparator&&i===e.arrayColumn)r("arraySeparator",o+1);else if(Po(i)||i===e.decimal&&Po(t[o+1])){const a=Ve(Ya,t,o);if(a>=0){r("ref",o+a);continue}if(s()){const l=Ve(Xa,t,o);if(l>=0){r("ref",o+l);continue}}r("number",o+Ve(e.decimal==="."?Ba:Ha,t,o))}else if(i==="$"||Ka(i)){const a=Ve(Pa,t,o),l=Math.max(0,Ve(Va,t,o)),c=Ve(ja,t,o);if(l>0&&t[o+l]==="!")r("sheet",o+l+1);else if(a>=0&&a>=l&&t[o+a]!=="(")r("ref",o+a);else if(i==="$"&&Po(t[o+1]))r("ref",o+Ve(Wa,t,o));else if(c>=0&&(l===0||c>=l))r("ref",o+c);else if(s()&&Ve(bs,t,o)>=0)r("ref",o+Ve(bs,t,o));else if(l>0){const u=t.slice(o,o+l).toUpperCase();let h=o+l;for(;Fo(t[h]);)h+=1;t[h]==="("?r("function",o+l):r(u==="TRUE"||u==="FALSE"?"bool":"name",o+l)}else r("unknown",o+1)}else{const a=Fa.find(l=>t.startsWith(l,o));a?r("operator",o+a.length):r("unknown",o+1)}}return n}class te extends Error{start;end;constructor(e,n,o){super(e),this.start=n,this.end=o}}const Ga={"=":10,"<>":10,"<":10,"<=":10,">":10,">=":10,"&":20,"+":30,"-":30,"*":40,"/":40,"^":50},Za=60,Ja=70,xs=80,vs=90,Es=1048576,qa=16384;function ks(t,e,n){const o=/^(\$?)([A-Za-z]{1,3})?(\$?)([0-9]{1,7})?$/.exec(t);if(!o||o[2]===void 0&&o[4]===void 0)throw new te(`'${t}' is not a reference.`,e,n);const r={rowAbs:!1,colAbs:!1};if(o[2]!==void 0){if(r.col=_i(o[2]),r.colAbs=o[1]==="$",r.col>=qa)throw new te(`'${t}' is past the last column, XFD.`,e,n);o[4]!==void 0&&(r.rowAbs=o[3]==="$",r.row=Number(o[4])-1)}else r.rowAbs=o[1]==="$"||o[3]==="$",r.row=Number(o[4])-1;if(r.row!==void 0&&(r.row<0||r.row>=Es))throw new te(`'${t}' is outside rows 1 to ${Es}.`,e,n);return r}function Qa(t){const e=t.slice(0,-1);return e.startsWith("'")?e.slice(1,-1).replace(/''/g,"'"):e}class ec{#e;#t;#r;#o=0;constructor(e,n,o){this.#t=e,this.#e=n,this.#r=o}parse(){if(this.#n(),this.#o>=this.#e.length)throw new te("The formula is empty.",0,this.#t.length);const e=this.#l(0);this.#n();const n=this.#e[this.#o];if(n!==void 0)throw new te(n.kind==="rparen"?"A closing parenthesis has no opening one.":`Unexpected '${n.text}'.`,n.start,n.end);return e}#s(){return this.#n(),this.#e[this.#o]}#i(){let e=this.#o;for(;this.#e[e]?.kind==="whitespace";)e+=1;return{token:this.#e[e],at:e}}#n(){for(;this.#e[this.#o]?.kind==="whitespace";)this.#o+=1}#d(){if(this.#e[this.#o]?.kind!=="whitespace")return!1;const n=this.#e[this.#o+1];return n!==void 0&&(n.kind==="ref"||n.kind==="sheet"||n.kind==="name"||n.kind==="lparen"||n.kind==="function")}#l(e){let n=this.#h();for(;;){if(this.#d()&&xs>e&&this.#f(n)){this.#o+=1;const a=this.#l(xs);n={type:"binary",op:" ",left:n,right:a};continue}const{token:o,at:r}=this.#i();if(o===void 0||o.kind!=="operator")break;if(o.text==="%"){if(Ja<=e)break;this.#o=r+1,n={type:"percent",arg:n};continue}if(o.text===":"){if(vs<=e)break;this.#o=r+1;const a=this.#l(vs);n=this.#m(n,a,o);continue}const s=Ga[o.text];if(s===void 0||s<=e)break;this.#o=r+1;const i=this.#l(s);n={type:"binary",op:o.text,left:n,right:i}}return n}#f(e){return e.type==="cell"||e.type==="range"||e.type==="name"||e.type==="union"||e.type==="binary"&&e.op===" "||e.type==="call"}#m(e,n,o){const r=a=>a.type==="cell"?{sheet:a.sheet,part:a.ref}:void 0,s=r(e),i=r(n);if(s&&i){if(i.sheet!==void 0&&i.sheet!==s.sheet)throw new te("A range lies on one sheet.",o.start,o.end);const a=l=>l.row===void 0?"cols":l.col===void 0?"rows":"cells";if(a(s.part)!==a(i.part))throw new te("Both ends of a range are cells, columns or rows alike.",o.start,o.end);return{type:"range",sheet:s.sheet,from:s.part,to:i.part}}if(this.#f(e)&&this.#f(n))return{type:"call",name:":",args:[e,n]};throw new te("':' joins two references.",o.start,o.end)}#h(){const e=this.#s();if(e===void 0)throw new te("The formula ends where a value was expected.",this.#t.length,this.#t.length);switch(this.#o+=1,e.kind){case"number":{const n=Number(e.text.replace(this.#r.decimal,"."));if(!Number.isFinite(n))throw new te(`'${e.text}' is not a number.`,e.start,e.end);return{type:"number",value:n}}case"string":if(!/^"(?:[^"]|"")*"$/.test(e.text))throw new te("A text opens a quote it never closes.",e.start,this.#t.length);return{type:"string",value:e.text.slice(1,-1).replace(/""/g,'"')};case"bool":return{type:"bool",value:e.text.toUpperCase()==="TRUE"};case"error":{const n=e.text.toUpperCase();if(!Cn(n))throw new te(`'${e.text}' is not an error value.`,e.start,e.end);return{type:"error",code:n}}case"sheet":{const n=this.#e[this.#o];if(n?.kind!=="ref")throw new te(`A reference follows ${e.text}.`,e.start,e.end);return this.#o+=1,{type:"cell",sheet:Qa(e.text),ref:ks(n.text,n.start,n.end)}}case"ref":return{type:"cell",ref:ks(e.text,e.start,e.end)};case"name":return{type:"name",name:e.text};case"function":return this.#c(e);case"operator":if(e.text==="-"||e.text==="+"){const n=this.#l(Za);return{type:"unary",op:e.text,arg:n}}throw new te(`'${e.text}' needs a value before it.`,e.start,e.end);case"lparen":{const n=this.#l(0),o=[n];for(;this.#s()?.kind==="separator";)this.#o+=1,o.push(this.#l(0));const r=this.#s();if(r?.kind!=="rparen")throw new te("A parenthesis is never closed.",e.start,r?.start??this.#t.length);if(this.#o+=1,o.length===1)return n;if(!o.every(s=>this.#f(s)))throw new te("A union joins references only.",e.start,r.end);return{type:"union",items:o}}case"lbrace":return this.#u(e);case"rparen":throw new te("A closing parenthesis has no opening one.",e.start,e.end);default:throw new te(`Unexpected '${e.text}'.`,e.start,e.end)}}#c(e){if(this.#s()?.kind!=="lparen")throw new te(`${e.text} is called with ( ).`,e.start,e.end);this.#o+=1;const o=[],r=()=>{const i=this.#s();return i?.kind==="rparen"||i?.kind==="separator"};if(this.#s()?.kind!=="rparen")for(;;){if(o.push(r()?{type:"empty"}:this.#l(0)),this.#s()?.kind==="separator"){this.#o+=1,this.#s()?.kind==="rparen"&&o.push({type:"empty"});continue}break}const s=this.#s();if(s?.kind!=="rparen")throw new te(`${e.text}( is never closed.`,e.start,s?.start??this.#t.length);return this.#o+=1,{type:"call",name:e.text.toUpperCase(),args:o}}#u(e){const n=[[]];for(;;){const r=this.#s();if(r===void 0)throw new te("An array is never closed.",e.start,this.#t.length);if(r.kind==="rbrace"){this.#o+=1;break}if(r.kind==="separator"&&this.#r.argumentSeparator!==";"||r.kind==="arraySeparator"&&r.text===this.#r.arrayColumn){this.#o+=1;continue}if(r.kind==="arraySeparator"||r.kind==="separator"){this.#o+=1,n.push([]);continue}const s=this.#h();if(!(s.type==="number"||s.type==="string"||s.type==="bool"||s.type==="error"||s.type==="unary"&&s.arg.type==="number"))throw new te("An array holds constants only.",r.start,r.end);n[n.length-1].push(s)}const o=n[0].length;if(o===0||n.some(r=>r.length!==o))throw new te("Every row of an array has the same number of values.",e.start,e.end);return{type:"array",rows:n}}}function Nt(t,e=Di){const n=Ui(t,e),o=n.find(r=>r.kind==="unknown");if(o)throw new te(`'${o.text}' is not part of a formula.`,o.start,o.end);return{ast:new ec(t,n,e).parse(),tokens:n}}function Xt(t,e){return{rowAbs:t.rowAbs,colAbs:t.colAbs,...t.row!==void 0?{row:t.rowAbs?t.row:t.row-e.row}:{},...t.col!==void 0?{col:t.colAbs?t.col:t.col-e.col}:{}}}const jo=t=>`${t.row===void 0?"":t.rowAbs?`R${t.row}`:`R[${t.row}]`}${t.col===void 0?"":t.colAbs?`C${t.col}`:`C[${t.col}]`}`;function tc(t,e){const n=[],o=r=>{switch(r.type){case"number":return n.push(r.value),"#n";case"string":return n.push(r.value),"#s";case"bool":return r.value?"T":"F";case"error":return r.code;case"cell":return`${r.sheet===void 0?"":`'${r.sheet}'!`}${jo(Xt(r.ref,e))}`;case"range":return`${r.sheet===void 0?"":`'${r.sheet}'!`}${jo(Xt(r.from,e))}:${jo(Xt(r.to,e))}`;case"name":return`N(${r.name.toUpperCase()})`;case"call":return`${r.name}(${r.args.map(o).join(",")})`;case"unary":return`${r.op}(${o(r.arg)})`;case"percent":return`%(${o(r.arg)})`;case"binary":return`(${o(r.left)}${r.op===" "?"_":r.op}${o(r.right)})`;case"union":return`U(${r.items.map(o).join(",")})`;case"array":return`{${r.rows.map(s=>s.map(o).join(",")).join(";")}}`;case"empty":return"~"}};return{key:o(t),constants:n}}const Ss=t=>/^[A-Za-z_][A-Za-z0-9_.]*$/.test(t)&&!/^[A-Za-z]{1,3}[0-9]+$/.test(t)?t:`'${t.replace(/'/g,"''")}'`;function Bo(t){const e=t.col===void 0?"":`${t.colAbs?"$":""}${Ye(t.col)}`,n=t.row===void 0?"":`${t.rowAbs?"$":""}${t.row+1}`;return e+n}const nc={"=":10,"<>":10,"<":10,"<=":10,">":10,">=":10,"&":20,"+":30,"-":30,"*":40,"/":40,"^":50," ":80};function Ao(t){const e=(n,o=0)=>{switch(n.type){case"number":return String(n.value);case"string":return`"${n.value.replace(/"/g,'""')}"`;case"bool":return n.value?"TRUE":"FALSE";case"error":return n.code;case"cell":return`${n.sheet===void 0?"":`${Ss(n.sheet)}!`}${Bo(n.ref)}`;case"range":return`${n.sheet===void 0?"":`${Ss(n.sheet)}!`}${Bo(n.from)}:${Bo(n.to)}`;case"name":return n.name;case"call":return n.name===":"?`${e(n.args[0],90)}:${e(n.args[1],90)}`:`${n.name}(${n.args.map(r=>e(r)).join(",")})`;case"unary":return`${n.op}${e(n.arg,60)}`;case"percent":return`${e(n.arg,70)}%`;case"binary":{const r=nc[n.op],s=`${e(n.left,r-.5)}${n.op}${e(n.right,r)}`;return r<=o?`(${s})`:s}case"union":return`(${n.items.map(r=>e(r)).join(",")})`;case"array":return`{${n.rows.map(r=>r.map(s=>e(s)).join(",")).join(";")}}`;case"empty":return""}};return e(t)}function oc(t,e,n,o={rows:1048576,cols:16384}){return Fi(t,o,r=>({row:r.row===void 0||r.rowAbs?r.row:r.row+e,col:r.col===void 0||r.colAbs?r.col:r.col+n}))}function rc(t,e,n,o={rows:1048576,cols:16384}){return Fi(t,o,r=>r.row!==void 0&&r.col!==void 0&&!r.rowAbs&&!r.colAbs?{row:n.row+(r.col-e.col),col:n.col+(r.row-e.row)}:{row:r.row===void 0||r.rowAbs?r.row:r.row+n.row-e.row,col:r.col===void 0||r.colAbs?r.col:r.col+n.col-e.col})}function Fi(t,e,n){const o=s=>{const{row:i,col:a}=n(s);if(!(i!==void 0&&(i<0||i>=e.rows)||a!==void 0&&(a<0||a>=e.cols)))return{...s,...i!==void 0?{row:i}:{},...a!==void 0?{col:a}:{}}},r=s=>{switch(s.type){case"cell":{const i=o(s.ref);return i===void 0?{type:"error",code:"#REF!"}:{...s,ref:i}}case"range":{const i=o(s.from),a=o(s.to);return i===void 0||a===void 0?{type:"error",code:"#REF!"}:{...s,from:i,to:a}}case"call":return{...s,args:s.args.map(r)};case"unary":case"percent":return{...s,arg:r(s.arg)};case"binary":return{...s,left:r(s.left),right:r(s.right)};case"union":return{...s,items:s.items.map(r)};default:return s}};return r(t)}function sc(t,e,n,o){let r;try{r=Nt(t).ast}catch{return t}return Ao(rc(r,e,n,o))}function Or(t,e,n,o){if(e===0&&n===0)return t;let r;try{r=Nt(t).ast}catch{return t}return Ao(oc(r,e,n,o))}const lm=["bar","column","line","area","pie","scatter","combo"],Cs=["clustered","stacked","percent","smooth","doughnut"],$s=["top","right","bottom","left","none"],mo=1e5;class Pi extends Error{}function Y(t,e){throw new Pi(`${t}: ${e}`)}const at=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function Gt(t){let e;try{e=Nt(t).ast}catch{return}if(e.type==="cell"||e.type==="range"||e.type==="error"&&e.code==="#REF!")return e}function Ho(t,e){(typeof t!="string"||Gt(t)===void 0)&&Y(e,"not a range")}function Yo(t,e,n){at(t)||Y(e,"a cell offset is { row, col, dx, dy }");for(const o of["row","col"])(!Number.isInteger(t[o])||t[o]<0)&&Y(`${e}.${o}`,"a non-negative integer");(t.row>=n.rows||t.col>=n.cols)&&Y(e,"outside the sheet");for(const o of["dx","dy"])(typeof t[o]!="number"||!Number.isFinite(t[o])||t[o]<0)&&Y(`${e}.${o}`,"a non-negative number of px")}const Dn=t=>typeof t=="number"&&Number.isFinite(t)&&t>0;function ic(t,e){at(t)||Y(e,"an axis is { title?, min?, max?, format?, log?, gridlines? }");for(const n of Object.keys(t))["title","min","max","format","log","gridlines"].includes(n)||Y(`${e}.${n}`,"not a field of an axis");t.title!==void 0&&typeof t.title!="string"&&Y(`${e}.title`,"a text");for(const n of["min","max"])t[n]!==void 0&&(typeof t[n]!="number"||!Number.isFinite(t[n]))&&Y(`${e}.${n}`,"a number");t.format!==void 0&&typeof t.format!="string"&&Y(`${e}.format`,"a number format");for(const n of["log","gridlines"])t[n]!==void 0&&typeof t[n]!="boolean"&&Y(`${e}.${n}`,"true or false")}function ji(t,e,n){at(t)||Y(e,"a chart is an object");for(const s of Object.keys(t))["id","type","variant","anchor","data","title","legend","axes","labels"].includes(s)||Y(`${e}.${s}`,"not a field of a chart");(typeof t.id!="string"||t.id==="")&&Y(`${e}.id`,"a non-empty string"),(typeof t.type!="string"||!/^[a-z][a-zA-Z0-9.-]*$/.test(t.type))&&Y(`${e}.type`,"a chart type (column, line, … or a contributed type)"),t.variant!==void 0&&!Cs.includes(t.variant)&&Y(`${e}.variant`,`one of ${Cs.join(", ")}`);const o=t.anchor;if(at(o)||Y(`${e}.anchor`,"an anchor is { kind, … }"),o.kind==="cells"){Yo(o.from,`${e}.anchor.from`,n),Yo(o.to,`${e}.anchor.to`,n);const s=o.from,i=o.to;(i.row<s.row||i.col<s.col)&&Y(`${e}.anchor`,"from after to")}else if(o.kind==="cell")Yo(o.from,`${e}.anchor.from`,n),Dn(o.width)||Y(`${e}.anchor.width`,"a positive number of px"),Dn(o.height)||Y(`${e}.anchor.height`,"a positive number of px");else if(o.kind==="absolute"){for(const s of["x","y"])(typeof o[s]!="number"||!Number.isFinite(o[s])||o[s]<0)&&Y(`${e}.anchor.${s}`,"a non-negative number of px");Dn(o.width)||Y(`${e}.anchor.width`,"a positive number of px"),Dn(o.height)||Y(`${e}.anchor.height`,"a positive number of px")}else Y(`${e}.anchor.kind`,"cells, cell or absolute");const r=t.data;if(at(r)||Y(`${e}.data`,"the data is { series, by, headers, blanks }"),(!Array.isArray(r.series)||r.series.length===0)&&Y(`${e}.data.series`,"a non-empty list"),r.series.forEach((s,i)=>{const a=`${e}.data.series[${i}]`;at(s)||Y(a,"a series is { values, … }");for(const l of Object.keys(s))["name","values","categories","x","type","axis","color"].includes(l)||Y(`${a}.${l}`,"not a field of a series");Ho(s.values,`${a}.values`),s.categories!==void 0&&Ho(s.categories,`${a}.categories`),s.x!==void 0&&Ho(s.x,`${a}.x`),s.name!==void 0&&typeof s.name!="string"&&Y(`${a}.name`,"a text or a range"),s.type!==void 0&&!["column","line","area"].includes(s.type)&&Y(`${a}.type`,"column, line or area"),s.axis!==void 0&&s.axis!=="primary"&&s.axis!=="secondary"&&Y(`${a}.axis`,"primary or secondary"),s.color!==void 0&&(typeof s.color!="string"||!/^#[0-9a-fA-F]{6}$/.test(s.color))&&Y(`${a}.color`,"a colour such as #1f77b4")}),r.by!=="columns"&&r.by!=="rows"&&Y(`${e}.data.by`,"columns or rows"),(!at(r.headers)||typeof r.headers.row!="boolean"||typeof r.headers.column!="boolean")&&Y(`${e}.data.headers`,"{ row, column }, true or false each"),["gap","zero","connect"].includes(r.blanks)||Y(`${e}.data.blanks`,"gap, zero or connect"),t.title!==void 0&&typeof t.title!="string"&&Y(`${e}.title`,"a text or a range"),$s.includes(t.legend)||Y(`${e}.legend`,`one of ${$s.join(", ")}`),t.axes!==void 0){at(t.axes)||Y(`${e}.axes`,"{ x?, y?, y2? }");for(const s of Object.keys(t.axes))["x","y","y2"].includes(s)||Y(`${e}.axes.${s}`,"not an axis (x, y or y2)"),ic(t.axes[s],`${e}.axes.${s}`)}return t.labels!==void 0&&typeof t.labels!="boolean"&&Y(`${e}.labels`,"true or false"),t}function Ir(t,e,n="chart"){try{ji(t,n,e);return}catch(o){if(o instanceof Pi)return o.message;throw o}}function dt(t,e,n){const o=Gt(n);if(o===void 0||o.type==="error")return;const r=o.type==="cell"||o.type==="range"?o.sheet===void 0?e:t.sheetByName(o.sheet)?.id:void 0;if(r===void 0)return;const s=t.sheet(r);if(o.type==="cell"){const{row:u,col:h}=o.ref;return u===void 0||h===void 0?void 0:{sheet:r,zone:{top:u,left:h,bottom:u,right:h}}}if(o.type!=="range")return;const i=o.from.row??0,a=o.to.row??s.rows.count-1,l=o.from.col??0,c=o.to.col??s.cols.count-1;return{sheet:r,zone:{top:Math.min(i,a),left:Math.min(l,c),bottom:Math.max(i,a),right:Math.max(l,c)}}}const Bi=t=>(t.bottom-t.top+1)*(t.right-t.left+1);function Hi(t,e){const n=e.anchor;if(n.kind==="absolute")return{x:n.x,y:n.y,width:n.width,height:n.height};const o=t.cols.offsetOf(n.from.col)+n.from.dx,r=t.rows.offsetOf(n.from.row)+n.from.dy;if(n.kind==="cell")return{x:o,y:r,width:n.width,height:n.height};const s=t.cols.offsetOf(n.to.col)+n.to.dx,i=t.rows.offsetOf(n.to.row)+n.to.dy;return{x:o,y:r,width:Math.max(1,s-o),height:Math.max(1,i-r)}}function Yi(t){const e=[];for(const n of t.data.series)e.push(n.values),n.categories!==void 0&&e.push(n.categories),n.x!==void 0&&e.push(n.x),n.name!==void 0&&Gt(n.name)!==void 0&&e.push(n.name);return e}function lc(t,e,n){const o=[];for(const r of Yi(n)){const s=dt(t,e,r);s!==void 0&&o.push(s)}return o}function*As(t){for(let e=t.top;e<=t.bottom;e+=1)for(let n=t.left;n<=t.right;n+=1)yield[e,n]}function ac(t,e,n,o){const r=[],s=c=>{if(c===void 0)return;const u=dt(e,n,c);if(u===void 0)return r.push(c),[];const h=[];for(const[d,f]of As(u.zone)){const m=t(u.sheet,d,f);typeof m=="number"?h.push(m):h.push(m===null&&o.data.blanks==="zero"?0:null)}return h},i=c=>{const u=dt(e,n,c);if(u===void 0)return r.push(c),[];const h=[];for(const[d,f]of As(u.zone)){const m=t(u.sheet,d,f);h.push(typeof m=="number"||typeof m=="string"?m:m===null?"":String(m))}return h};let a;const l=o.data.series.map((c,u)=>{a===void 0&&c.categories!==void 0&&(a=i(c.categories));let h=`Series ${u+1}`;if(c.name!==void 0)if(Gt(c.name)===void 0)h=c.name;else{const g=dt(e,n,c.name);if(g===void 0)r.push(c.name);else{const w=t(g.sheet,g.zone.top,g.zone.left);w!==null&&typeof w!="object"&&(h=String(w))}}const d=s(c.values),f=s(c.x),m=dt(e,n,c.values)===void 0;return{name:h,values:d,...f!==void 0?{x:f}:{},...c.type!==void 0?{type:c.type}:{},...c.axis!==void 0?{axis:c.axis}:{},...c.color!==void 0?{color:c.color}:{},...m?{}:{source:c.values}}});return{categories:a??[],series:l,deleted:[...new Set(r)]}}function cc(t,e,n){let o=0;for(const r of n.data.series){const s=dt(t,e,r.values);s!==void 0&&(o+=Bi(s.zone))}return o}function uc(t,e,n){for(const o of n.data.series){const r=dt(t.workbook,e,o.values);if(r!==void 0){for(const[s,i]of t.workbook.sheet(r.sheet).cells.entries(r.zone))if(typeof t.value(r.sheet,s,i)=="number")return!0}}return!1}function Lt(t,e){const n=/^[A-Za-z_][A-Za-z0-9_.]*$/.test(t)&&!/^[A-Za-z]{1,3}[0-9]+$/.test(t)?t:`'${t.replace(/'/g,"''")}'`,o=`$${Ye(e.left)}$${e.top+1}`,r=`$${Ye(e.right)}$${e.bottom+1}`;return`${n}!${o===r?o:`${o}:${r}`}`}function hc(t,e,n,o=()=>!1){const r=n.bottom-n.top+1,s=n.right-n.left+1,i=(g,w)=>typeof t(g,w)=="string",a=(g,w)=>typeof t(g,w)=="number"&&!o(g,w);let l=0;for(let g=n.top;g<=n.bottom;g+=1)for(let w=n.left;w<=n.right;w+=1)a(g,w)&&(l+=1);if(l===0)return{ok:!1,reason:"NoNumericData",message:"The selection holds no number to chart."};let c=r>1;for(let g=n.left+(s>1?1:0);g<=n.right&&c;g+=1)i(n.top,g)||t(n.top,g)===null||(c=!1);if(c){let g=!1;for(let w=n.left;w<=n.right;w+=1)i(n.top,w)&&(g=!0);c=g}let u=s>1;for(let g=n.top+(c?1:0);g<=n.bottom&&u;g+=1)i(g,n.left)||o(g,n.left)||t(g,n.left)===null||(u=!1);const h={top:n.top+(c?1:0),left:n.left+(u?1:0),bottom:n.bottom,right:n.right};if(h.top>h.bottom||h.left>h.right)return{ok:!1,reason:"NoNumericData",message:"The selection holds no number to chart."};const d=Bi(h);if(d>mo)return{ok:!1,reason:"ChartTooLarge",message:`A chart holds at most ${mo.toLocaleString("en-US")} points; this selection has ${d.toLocaleString("en-US")}.`};const f=h.bottom-h.top>=h.right-h.left,m=[];if(f)for(let g=h.left;g<=h.right;g+=1)m.push({values:Lt(e,{top:h.top,left:g,bottom:h.bottom,right:g}),...c?{name:Lt(e,{top:n.top,left:g,bottom:n.top,right:g})}:{},...u?{categories:Lt(e,{top:h.top,left:n.left,bottom:h.bottom,right:n.left})}:{}});else for(let g=h.top;g<=h.bottom;g+=1)m.push({values:Lt(e,{top:g,left:h.left,bottom:g,right:h.right}),...u?{name:Lt(e,{top:g,left:n.left,bottom:g,right:n.left})}:{},...c?{categories:Lt(e,{top:n.top,left:h.left,bottom:n.top,right:h.right})}:{}});return{ok:!0,data:{series:m,by:f?"columns":"rows",headers:{row:c,column:u},blanks:"gap"}}}const fc={op:"chart",apply(t,e){const n=t.sheet(e.sheet);e.after===null?n.charts.delete(e.id):n.charts.set(e.id,e.after)},invert:t=>({...t,before:t.after,after:t.before}),bytes:()=>512,example:()=>({op:"chart",sheet:"s1",id:"c1",before:null,after:{id:"c1",type:"column",anchor:{kind:"cells",from:{row:1,col:4,dx:0,dy:0},to:{row:10,col:9,dx:0,dy:0}},data:{series:[{values:"Sheet1!$B$2:$B$5"}],by:"columns",headers:{row:!1,column:!1},blanks:"gap"},legend:"bottom"}})};function Xi(t,e){return t.workbook.hasSheet(e)?void 0:_("UnknownSheet",`No sheet '${e}'.`)}function Mo(t,e,n){const o=Xi(t,e);return o||(t.workbook.sheet(e).charts.get(n)??_("UnknownChart",`No chart '${n}' on this sheet.`))}const To=t=>typeof t=="object"&&t!==null&&"ok"in t&&typeof t.ok=="boolean";function Wi(t,e,n){const o=Ir(n,t.workbook.limits);if(o!==void 0)return _("InvalidArgument",o);const r=cc(t.workbook,e,n);return r>mo?_("ChartTooLarge",`A chart holds at most ${mo.toLocaleString("en-US")} points; this one has ${r.toLocaleString("en-US")}.`):uc(t,e,n)?se:_("NoNumericData","The chart’s ranges hold no number to draw.")}function dc(t,e){const n=t.workbook.sheet(e).charts;for(let o=1;;o+=1)if(!n.has(`chart${o}`))return`chart${o}`}const Tn=(t,e,n,o)=>({op:"chart",sheet:t,id:e,before:n,after:o});function Ms(t,e){return{...e.chart,id:e.chart.id??dc(t,e.sheet)}}const mc={type:"INSERT_CHART",allow:(t,e)=>{const n=Xi(t,e.sheet);if(n)return n;const o=Ms(t,e);return t.workbook.sheet(e.sheet).charts.has(o.id)?_("DuplicateChart",`A chart '${o.id}' is on this sheet already.`):Wi(t,e.sheet,o)},apply:(t,e)=>{const n=Ms(t,e);return[Tn(e.sheet,n.id,null,n)]}},gc={type:"UPDATE_CHART",allow:(t,e)=>{const n=Mo(t,e.sheet,e.id);return To(n)?n:"id"in e.changes||"anchor"in e.changes?_("InvalidArgument","An update changes neither the id nor the anchor (MOVE_CHART, RESIZE_CHART)."):Wi(t,e.sheet,{...n,...e.changes})},apply:(t,e)=>{const n=t.workbook.sheet(e.sheet).charts.get(e.id);return[Tn(e.sheet,e.id,n,{...n,...e.changes})]}};function Ts(t,e){const n=t.anchor;return n.kind==="absolute"?"x"in e?{...n,x:e.x,y:e.y}:"An absolute chart moves to px (x, y), not to a cell.":"row"in e?n.kind==="cell"?{...n,from:{...n.from,row:e.row,col:e.col}}:{...n,from:{...n.from,row:e.row,col:e.col},to:{...n.to,row:e.row+(n.to.row-n.from.row),col:e.col+(n.to.col-n.from.col)}}:"A chart anchored on cells moves to a cell (row, col), not to px."}const pc={type:"MOVE_CHART",allow:(t,e)=>{const n=Mo(t,e.sheet,e.id);if(To(n))return n;const o=Ts(n,e.to);if(typeof o=="string")return _("InvalidArgument",o);const r=Ir({...n,anchor:o},t.workbook.limits);return r===void 0?se:_("InvalidArgument",r)},apply:(t,e)=>{const n=t.workbook.sheet(e.sheet).charts.get(e.id);return[Tn(e.sheet,e.id,n,{...n,anchor:Ts(n,e.to)})]}};function Rs(t,e){const n=t.anchor;return n.kind==="cells"?"row"in e?{...n,to:{...n.to,row:e.row,col:e.col}}:"A chart anchored on cells is resized to a cell (row, col).":"width"in e?{...n,width:e.width,height:e.height}:"This chart is resized in px (width, height)."}const wc={type:"RESIZE_CHART",allow:(t,e)=>{const n=Mo(t,e.sheet,e.id);if(To(n))return n;const o=Rs(n,e.to);if(typeof o=="string")return _("InvalidArgument",o);const r=Ir({...n,anchor:o},t.workbook.limits);return r===void 0?se:_("InvalidArgument",r)},apply:(t,e)=>{const n=t.workbook.sheet(e.sheet).charts.get(e.id);return[Tn(e.sheet,e.id,n,{...n,anchor:Rs(n,e.to)})]}},yc={type:"DELETE_CHART",allow:(t,e)=>{const n=Mo(t,e.sheet,e.id);return To(n)?n:se},apply:(t,e)=>{const n=t.workbook.sheet(e.sheet).charts.get(e.id);return[Tn(e.sheet,e.id,n,null)]}},bc=[mc,gc,pc,wc,yc];function ut(t,e){const{at:n,n:o}=t;switch(t.kind){case"insert":return e>=n?e+o:e;case"delete":return e<n?e:e<n+o?void 0:e-o;case"move":{const{to:r}=t;return e>=n&&e<n+o?r<n?r+(e-n):r-o+(e-n):r<n&&e>=r&&e<n?e+o:r>n&&e>=n+o&&e<r?e-o:e}}}function Vi(t,e,n,o){const r=n==="rows"?"row":"col",s={type:"error",code:"#REF!"},i=(u,h)=>({...u,[r]:h});let a=!1;const l=u=>{switch(u.type){case"cell":{const h=u.ref[r];if(!e(u.sheet)||h===void 0)return u;const d=ut(o,h);return d===h?u:(a=!0,d===void 0?s:{...u,ref:i(u.ref,d)})}case"range":{const h=u.from[r],d=u.to[r];if(!e(u.sheet)||h===void 0||d===void 0)return u;const f=Math.min(h,d),m=Math.max(h,d);let g,w;if(o.kind==="delete"){if(g=f>=o.at&&f<o.at+o.n?o.at:ut(o,f),w=m>=o.at&&m<o.at+o.n?o.at-1:ut(o,m),g>w)return a=!0,s}else{const $=ut(o,f),A=ut(o,m);g=Math.min($,A),w=Math.max($,A)}const[y,x]=h<=d?[u.from,u.to]:[u.to,u.from];return g===f&&w===m&&h<=d?u:(a=!0,{...u,from:i(y,g),to:i(x,w)})}case"call":return{...u,args:u.args.map(l)};case"unary":case"percent":return{...u,arg:l(u.arg)};case"binary":return{...u,left:l(u.left),right:l(u.right)};case"union":return{...u,items:u.items.map(l)};default:return u}},c=l(t);return a?c:t}function _r(t,e,n,o){const s=t.sheet(e).name.toLowerCase(),i=[];for(const l of t.sheets){const c=l.id===e,u=h=>h===void 0?c:h.toLowerCase()===s;for(const[h,d,f]of l.cells.entries()){if(f.formula===void 0)continue;let m;try{m=Nt(f.formula).ast}catch{continue}const g=Vi(m,u,n,o);if(g===m)continue;const w=Ao(g);let y=h,x=d;if(c){const A=ut(o,n==="rows"?h:d);if(A===void 0)continue;n==="rows"?y=A:x=A}const $={...f,formula:w,value:null};i.push({op:"cells",sheet:l.id,zone:{top:y,left:x,bottom:y,right:x},before:Rt([[y,x,f]]),after:Rt([[y,x,$]])})}}i.push(...xc(t,e,n,o));const a=t.sheet(e).dataSource;if(a!==null){const l=n==="rows"?"row":"col",c=ut(o,a.at[l]);c!==void 0&&c!==a.at[l]&&i.push({op:"dataSource",sheet:e,before:a,after:{...a,at:{...a.at,[l]:c}}})}return i}function zs(t,e,n){const o=ut(t,e);return o!==void 0?o:n?Math.max(0,t.at-1):t.at}function xc(t,e,n,o){const r=t.sheet(e).name.toLowerCase(),s=[];for(const i of t.sheets){const a=i.id===e,l=c=>c===void 0?a:c.toLowerCase()===r;for(const[c,u]of i.charts){let h=!1;const d=w=>{if(w===void 0)return;const y=Gt(w);if(y===void 0||y.type==="error")return w;const x=Vi(y,l,n,o);return x===y?w:(h=!0,Ao(x))},f=u.data.series.map(w=>{const y=d(w.values),x=d(w.categories),$=d(w.x),A=w.name!==void 0&&Gt(w.name)!==void 0?d(w.name):w.name;return{...w,values:y,...x!==void 0?{categories:x}:{},...$!==void 0?{x:$}:{},...A!==void 0?{name:A}:{}}});let m=u.anchor;if(a&&m.kind!=="absolute"){const w=n==="rows"?"row":"col",y={...m.from,[w]:zs(o,m.from[w],!1)};if(m.kind==="cells"){let x={...m.to,[w]:zs(o,m.to[w],!0)};x[w]<y[w]&&(x={...x,[w]:y[w]}),m={...m,from:y,to:x}}else m={...m,from:y};JSON.stringify(m)!==JSON.stringify(u.anchor)&&(h=!0)}if(!h)continue;const g={...u,anchor:m,data:{...u.data,series:f}};s.push({op:"chart",sheet:i.id,id:c,before:u,after:g})}}return s}const se={ok:!0};function _(t,e){return{ok:!1,refusals:[{reason:t,message:e}]}}function dr(t){if(t.startsWith("'"))return t.slice(1);if(t.startsWith("=")&&t.length>1)return{formula:t.slice(1)};const e=t.trim();return e!==""&&/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(e)?Number(e):/^true$/i.test(e)?!0:/^false$/i.test(e)?!1:t===""?null:t}function Ce(t,e){return t.hasSheet(e)?t.sheet(e):_("UnknownSheet",`No sheet '${e}'.`)}const $e=t=>typeof t=="object"&&t!==null&&"ok"in t&&typeof t.ok=="boolean";function Rn(t,e){return![e.top,e.left,e.bottom,e.right].every(Number.isInteger)||e.top<0||e.left<0||e.top>e.bottom||e.left>e.right?_("InvalidArgument",`The zone ${JSON.stringify(e)} is not a zone.`):e.bottom>=t.rows.count||e.right>=t.cols.count?_("OutOfBounds",`The zone reaches past the sheet's ${t.rows.count} rows or ${t.cols.count} columns.`):se}function zn(t,e,n,o){const r=e==="rows"?t.rows.count:t.cols.count;return!Number.isInteger(n)||!Number.isInteger(o)||o<1||n<0?_("InvalidArgument",`${o} ${e} at ${n} is not a span.`):n+o>r?_("OutOfBounds",`${o} ${e} at ${n} reach past the sheet's ${r}.`):se}function vc(t,e,n){if(e===null||typeof e!="object"||j(e))return{value:e,style:n?.style??0};const o=e.style===void 0?n?.style??0:e.style===null?0:t.styles.intern(e.style);return e.formula!==void 0?e.value!==void 0&&e.value!==null?{value:e.value,formula:e.formula,style:o}:{value:null,formula:e.formula,style:o}:{value:e.value??null,style:o}}function Ec(t){if(t===null||typeof t=="string"||typeof t=="boolean")return;if(typeof t=="number")return Number.isFinite(t)?void 0:`${t} is not a cell value`;if(j(t))return;if(typeof t!="object")return`${String(t)} is not a cell input`;if(t.formula!==void 0&&(typeof t.formula!="string"||t.formula===""))return"a formula is a non-empty string, without the =";if(t.style!==void 0&&t.style!==null)try{zr(t.style)}catch(n){return n.message}const e=t.value;if(e!=null&&typeof e=="number"&&!Number.isFinite(e))return`${e} is not a cell value`}function en(t,e,n){const o=Kt(t,e),r=new Map;for(const s of Mn(o))r.set(`${s[0]},${s[1]}`,s);for(const[s,i,a]of n){const l=`${s},${i}`;a===null||a.value===null&&a.formula===void 0&&a.style===0?r.delete(l):r.set(l,[s,i,a])}return{op:"cells",sheet:t.id,zone:e,before:o,after:Rt([...r.values()])}}function Ns(t,e,n){return n===null?0:t.styles.intern({...t.styles.get(e),...n})}function Ki(t,e,n,o,r){const s=e==="rows"?t.rows:t.cols,i={sizes:new Float64Array(o),hidden:new Uint8Array(o)},a={sizes:new Float64Array(o),hidden:new Uint8Array(o)};for(let l=0;l<o;l+=1){const c=s.sizeOf(n+l),u=s.isHidden(n+l);i.sizes[l]=c,i.hidden[l]=u?1:0;const[h,d]=r(l,c,u);a.sizes[l]=h,a.hidden[l]=d?1:0}return{op:"axis-sizes",sheet:t.id,axis:e,at:n,n:o,before:i,after:a}}function Gi(t,e,n,o,r){const s=[];for(const i of t){const a=e==="rows"?i.top:i.left,l=e==="rows"?i.bottom:i.right;let c=a,u=l;if(o>0){if(a>=n&&(c+=o),l>=n&&(u+=o),u>=r)continue}else{const d=-o,f=n+d;if(c=(g=>g>=f?g-d:g>=n?n:g)(a),u=l>=f?l-d:l>=n?n-1:l,u<c)continue}const h=e==="rows"?{...i,top:c,bottom:u}:{...i,left:c,right:u};h.top===h.bottom&&h.left===h.right||s.push(h)}return s}const Zi=(t,e)=>JSON.stringify(t)===JSON.stringify(e),kc={type:"SET_CELLS",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;if(!Array.isArray(e.cells)||e.cells.length===0||!e.cells.every(r=>Array.isArray(r)))return _("InvalidArgument","SET_CELLS takes a non-empty block of rows.");const o=Math.max(...e.cells.map(r=>r.length));if(o===0)return _("InvalidArgument","SET_CELLS takes at least one cell.");for(const r of e.cells)for(const s of r){const i=Ec(s);if(i)return _("InvalidArgument",`SET_CELLS: ${i}.`)}return Rn(n,{top:e.at.row,left:e.at.col,bottom:e.at.row+e.cells.length-1,right:e.at.col+o-1})},apply({workbook:t},e){const n=t.sheet(e.sheet),o=Math.max(...e.cells.map(i=>i.length)),r={top:e.at.row,left:e.at.col,bottom:e.at.row+e.cells.length-1,right:e.at.col+o-1},s=[];return e.cells.forEach((i,a)=>i.forEach((l,c)=>{const u=e.at.row+a,h=e.at.col+c;s.push([u,h,vc(t,l,n.cells.get(u,h))])})),[en(n,r,s)]}},Sc={type:"SET_STYLE",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;if(e.style!==null)try{zr(e.style)}catch(o){return _("InvalidArgument",o.message)}return Rn(n,e.zone)},apply({workbook:t},e){const n=t.sheet(e.sheet),o=[],{top:r,left:s,bottom:i,right:a}=e.zone;if((i-r+1)*(a-s+1)>1e6)for(const[c,u,h]of n.cells.entries(e.zone))o.push([c,u,{...h,style:Ns(t,h.style,e.style)}]);else for(let c=r;c<=i;c+=1)for(let u=s;u<=a;u+=1){const h=n.cells.get(c,u)??{value:null,style:0};o.push([c,u,{...h,style:Ns(t,h.style,e.style)}])}return[en(n,e.zone,o)]}},Cc={type:"CLEAR",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:e.what!==void 0&&!["all","contents","styles"].includes(e.what)?_("InvalidArgument",`CLEAR clears all, contents or styles, not '${e.what}'.`):Rn(n,e.zone)},apply({workbook:t},e){const n=t.sheet(e.sheet),o=e.what??"all",r=[];for(const[s,i,a]of n.cells.entries(e.zone))o==="all"?r.push([s,i,null]):o==="contents"?r.push([s,i,{value:null,style:a.style}]):r.push([s,i,{...a,style:0}]);return[en(n,e.zone,r)]}},$c={type:"INSERT_AXIS",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;if(e.axis!=="rows"&&e.axis!=="cols")return _("InvalidArgument",`No axis '${String(e.axis)}'.`);const o=zn(n,e.axis,e.at,e.n);if(!o.ok)return o;const r=e.axis==="rows"?n.rows.count:n.cols.count,s=e.axis==="rows"?{top:r-e.n,left:0,bottom:r-1,right:n.cols.count-1}:{top:0,left:r-e.n,bottom:n.rows.count-1,right:r-1};return!n.cells.isEmpty(s)||n.mergesIn(s).length>0?_("NotEmptyAtEnd",`Inserting ${e.n} ${e.axis} would push content off the end of the sheet.`):se},apply({workbook:t},e){const n=t.sheet(e.sheet),o=e.axis==="rows"?n.rows:n.cols,r=o.count,s=o.segment(r-e.n,e.n),i={op:"axis-insert",sheet:n.id,axis:e.axis,at:e.at,n:e.n,inserted:{ids:o.freshIds(e.n),sizes:null,hidden:null},dropped:s},a=Gi(n.merges,e.axis,e.at,e.n,r),l=[i];return Zi(a,n.merges)||l.push({op:"merges",sheet:n.id,before:n.merges,after:a}),l.push(..._r(t,n.id,e.axis,{kind:"insert",at:e.at,n:e.n})),l}},Ac={type:"DELETE_AXIS",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:e.axis!=="rows"&&e.axis!=="cols"?_("InvalidArgument",`No axis '${String(e.axis)}'.`):zn(n,e.axis,e.at,e.n)},apply({workbook:t},e){const n=t.sheet(e.sheet),o=e.axis==="rows"?n.rows:n.cols,r=e.axis==="rows"?{top:e.at,left:0,bottom:e.at+e.n-1,right:n.cols.count-1}:{top:0,left:e.at,bottom:n.rows.count-1,right:e.at+e.n-1},s=[],i=Kt(n,r);i.rows.length>0&&s.push({op:"cells",sheet:n.id,zone:r,before:i,after:zi});const a=Gi(n.merges,e.axis,e.at,-e.n,o.count);return Zi(a,n.merges)||s.push({op:"merges",sheet:n.id,before:n.merges,after:a}),s.push({op:"axis-delete",sheet:n.id,axis:e.axis,at:e.at,n:e.n,removed:o.segment(e.at,e.n)}),s.push(..._r(t,n.id,e.axis,{kind:"delete",at:e.at,n:e.n})),s}},Mc={type:"MOVE_AXIS",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;const o=zn(n,e.axis,e.at,e.n);if(!o.ok)return o;const r=e.axis==="rows"?n.rows.count:n.cols.count;if(!Number.isInteger(e.to)||e.to<0||e.to>r||e.to>=e.at&&e.to<=e.at+e.n)return _("InvalidArgument",`Cannot move ${e.n} ${e.axis} at ${e.at} to ${e.to}.`);const s=Math.min(e.at,e.to),i=Math.max(e.at+e.n,e.to)-1,a=e.axis==="rows"?{top:s,left:0,bottom:i,right:n.cols.count-1}:{top:0,left:s,bottom:n.rows.count-1,right:i};return n.mergesIn(a).length>0?_("MergeOverlap","Moving across merged cells is not supported yet; unmerge first."):se},apply({workbook:t},e){const n=t.sheet(e.sheet),o=Math.min(e.at,e.to),r=Math.max(e.at+e.n,e.to)-1,s=e.axis==="rows"?{top:o,left:0,bottom:r,right:n.cols.count-1}:{top:0,left:o,bottom:n.rows.count-1,right:r},i=c=>c>=e.at&&c<e.at+e.n?e.to<e.at?e.to+(c-e.at):e.to-e.n+(c-e.at):e.to<e.at&&c>=e.to&&c<e.at?c+e.n:e.to>e.at&&c>=e.at+e.n&&c<e.to?c-e.n:c,a=Kt(n,s),l=Mn(a).map(([c,u,h])=>e.axis==="rows"?[i(c),u,h]:[c,i(u),h]);return[{op:"cells",sheet:n.id,zone:s,before:a,after:Rt(l)},{op:"axis-move",sheet:n.id,axis:e.axis,at:e.at,n:e.n,to:e.to},..._r(t,n.id,e.axis,{kind:"move",at:e.at,n:e.n,to:e.to})]}},Tc={type:"RESIZE_AXIS",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:!(e.size>0)||!Number.isFinite(e.size)?_("InvalidArgument",`A size must be positive; ${e.size} was given.`):zn(n,e.axis,e.from,e.to-e.from+1)},apply({workbook:t},e){const n=t.sheet(e.sheet);return[Ki(n,e.axis,e.from,e.to-e.from+1,(o,r,s)=>[e.size,s])]}},Rc={type:"HIDE_AXIS",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:zn(n,e.axis,e.from,e.to-e.from+1)},apply({workbook:t},e){const n=t.sheet(e.sheet);return[Ki(n,e.axis,e.from,e.to-e.from+1,(o,r)=>[r,e.hidden])]}},zc={type:"MERGE",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;const o=Rn(n,e.zone);return o.ok?e.zone.top===e.zone.bottom&&e.zone.left===e.zone.right?_("InvalidArgument","A merge spans more than one cell."):n.mergesIn(e.zone).length>0?_("MergeOverlap","The zone overlaps a merge; unmerge it first."):se:o},apply({workbook:t},e){const n=t.sheet(e.sheet),o=[];for(const[s,i]of n.cells.entries(e.zone))(s!==e.zone.top||i!==e.zone.left)&&o.push([s,i,null]);const r=[];return o.length>0&&r.push(en(n,e.zone,o)),r.push({op:"merges",sheet:n.id,before:n.merges,after:[...n.merges,e.zone]}),r}},Nc={type:"UNMERGE",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;const o=Rn(n,e.zone);return o.ok?n.mergesIn(e.zone).length===0?_("NoMerge","Nothing is merged there."):se:o},apply({workbook:t},e){const n=t.sheet(e.sheet),o=n.merges.filter(r=>!mt(r,e.zone));return[{op:"merges",sheet:n.id,before:n.merges,after:o}]}};function Ji(t,e,n){if(typeof e!="string"||e.trim()===""||e.length>31||/[\\/?*[\]:]/.test(e)||/^'|'$/.test(e))return _("InvalidSheetName",`'${String(e)}' is not a sheet name: 1 to 31 characters, none of \\ / ? * [ ] :, no leading or trailing '.`);const o=t.sheetByName(e);return o!==void 0&&o.id!==n?_("DuplicateSheetName",`A sheet is called '${e}' already.`):se}const Oc={type:"ADD_SHEET",allow({workbook:t},e){return e.at!==void 0&&(!Number.isInteger(e.at)||e.at<0||e.at>t.sheets.length)?_("OutOfBounds",`No tab position ${e.at}.`):e.id!==void 0&&t.hasSheet(e.id)?_("InvalidArgument",`A sheet has the id '${e.id}' already.`):e.name===void 0?se:Ji(t,e.name)},apply({workbook:t},e){const n=t.createSheet(e.name??t.freshSheetName(),e.id);return[{op:"sheet-add",index:e.at??t.sheets.length,sheet:n}]}},Ic={type:"DELETE_SHEET",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:t.sheets.length===1?_("LastSheet","A workbook keeps at least one sheet."):se},apply({workbook:t},e){const n=t.sheet(e.sheet);return[{op:"sheet-delete",index:t.sheets.indexOf(n),sheet:n}]}},_c={type:"RENAME_SHEET",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:Ji(t,e.name,e.sheet)},apply({workbook:t},e){const n=t.sheet(e.sheet);return[{op:"sheet-rename",sheet:n.id,before:n.name,after:e.name}]}},Lc={type:"MOVE_SHEET",allow({workbook:t},e){const n=Ce(t,e.sheet);return $e(n)?n:!Number.isInteger(e.to)||e.to<0||e.to>=t.sheets.length?_("OutOfBounds",`No tab position ${e.to}.`):se},apply({workbook:t},e){const n=t.sheets.indexOf(t.sheet(e.sheet));return n===e.to?[]:[{op:"sheet-move",from:n,to:e.to}]}},Dc={type:"FREEZE",allow({workbook:t},e){const n=Ce(t,e.sheet);if($e(n))return n;const o=(s,i)=>Number.isInteger(s)&&s>=0&&s<i;if(!o(e.rows,n.rows.count)||!o(e.cols,n.cols.count))return _("OutOfBounds",`Cannot freeze ${e.rows} rows and ${e.cols} columns.`);const r=s=>e.rows>0&&s.top<e.rows&&s.bottom>=e.rows||e.cols>0&&s.left<e.cols&&s.right>=e.cols;return n.merges.some(r)?_("MergeOverlap","A merge crosses the frozen edge."):se},apply({workbook:t},e){const n=t.sheet(e.sheet);return[{op:"frozen",sheet:n.id,before:n.frozen,after:{rows:e.rows,cols:e.cols}}]}},Uc=[kc,Sc,Cc,$c,Ac,Mc,Tc,Rc,zc,Nc,Oc,Ic,_c,Lc,Dc],Os=["width","height","dx","dy"],Fc="code",Is=["stream","display_data","execute_result","error"],_s=["source","language","outputs","result","executionCount","lastRun","run","frame"],yn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function qi(t,e="code"){if(!yn(t))return`${e}: a code cell is { source, language, outputs, result, run }`;for(const r of Object.keys(t))if(!_s.includes(r))return`${e}.${r}: a code cell has ${_s.join(", ")} only`;if(typeof t.source!="string")return`${e}.source: the code, a string`;if(t.language!=="python")return`${e}.language: 'python'`;if(!Array.isArray(t.outputs))return`${e}.outputs: a list of nbformat outputs`;for(let r=0;r<t.outputs.length;r+=1){const s=t.outputs[r];if(!yn(s)||!Is.includes(s.output_type))return`${e}.outputs[${r}].output_type: one of ${Is.join(", ")}`}const n=t.result;if(!(n===null||typeof n=="string"||typeof n=="boolean"||typeof n=="number"&&Number.isFinite(n)||yn(n)&&Object.keys(n).length===1&&typeof n.error=="string"&&Cn(n.error)))return`${e}.result: a value (a number, a string, a boolean, null or { error })`;if(t.executionCount!==void 0&&!(Number.isInteger(t.executionCount)&&t.executionCount>=0))return`${e}.executionCount: a non-negative integer`;if(t.lastRun!==void 0&&(typeof t.lastRun!="string"||Number.isNaN(Date.parse(t.lastRun))))return`${e}.lastRun: an ISO time`;if(t.run!=="manual"&&t.run!=="auto")return`${e}.run: 'manual' or 'auto'`;if(t.frame!==void 0&&t.frame!==null){const r=t.frame;if(!yn(r))return`${e}.frame: { width, height } or null`;for(const s of Object.keys(r))if(!Os.includes(s))return`${e}.frame.${s}: a frame has ${Os.join(", ")} only`;for(const s of["width","height"])if(!(typeof r[s]=="number"&&r[s]>0&&Number.isFinite(r[s])))return`${e}.frame.${s}: a positive size in px`;for(const s of["dx","dy"])if(r[s]!==void 0&&!(typeof r[s]=="number"&&Number.isFinite(r[s])))return`${e}.frame.${s}: an offset in px, a finite number`}}function Qi(t,e={}){return{source:t,language:"python",outputs:[],result:null,run:"manual",...e}}function Pc(t){return yn(t)?{error:t.error}:t}const jc={width:360,height:240};function Wt(t){if(!(t.frame===null||t.outputs.length===0))return t.frame??jc}function ht(t,e,n){return`${t.rows.materialize(e)}.${t.cols.materialize(n)}`}function Bc(t,e,n){if(t.code.size!==0)return t.code.get(`${t.rows.idAt(e)}.${t.cols.idAt(n)}`)}function el(t,e){const[n,o]=e.split(".").map(Number),r=t.rows.indexOfId(n),s=t.cols.indexOfId(o);return r<0||s<0?void 0:{row:r,col:s}}function En(t){const e=[];for(const[n,o]of t.code){const r=el(t,n);r!==void 0&&e.push({...r,code:o})}return e.sort((n,o)=>n.row-o.row||n.col-o.col)}const et=(t,e)=>`${Ye(e)}${t+1}`,Hc={op:"code",apply(t,e){const n=t.sheet(e.sheet);e.after===null?n.code.delete(e.key):n.code.set(e.key,e.after)},invert:t=>({...t,before:t.after,after:t.before}),bytes:t=>256+JSON.stringify(t.after??t.before??{}).length*2,example:t=>({op:"code",sheet:"s1",key:ht(t.sheet("s1"),1,1),before:null,after:Qi("1 + 1")})};function Yc(t,e,n){const{type:o,...r}=t.styles.get(e);return t.styles.intern(n===void 0?r:{...r,type:n})}function Xc(t,e){const n=t.sheet(e.sheet),o=ht(n,e.row,e.col),r=n.code.get(o)??null,s={top:e.row,left:e.col,bottom:e.row,right:e.col},i=Kt(n,s),a=Mn(i)[0]?.[2],l=Yc(t,a?.style??0,e.code===null?void 0:Fc),c=e.code===null?l===0?null:{value:null,style:l}:{value:Pc(e.code.result),style:l},u={op:"cells",sheet:n.id,zone:s,before:i,after:Rt(c===null?[]:[[e.row,e.col,c]])};return[{op:"code",sheet:n.id,key:o,before:r,after:e.code},u]}const Wc={type:"SET_CODE",allow({workbook:t},e){if(!t.hasSheet(e.sheet))return _("UnknownSheet",`No sheet '${e.sheet}'.`);const n=t.sheet(e.sheet);if(!Number.isInteger(e.row)||!Number.isInteger(e.col)||e.row<0||e.col<0||e.row>=n.rows.count||e.col>=n.cols.count)return _("OutOfBounds",`No cell at row ${e.row}, column ${e.col}.`);if(e.code!==null){const r=qi(e.code);if(r!==void 0)return _("InvalidArgument",r)}const o=n.mergeAt(e.row,e.col);return o!==void 0&&(o.top!==e.row||o.left!==e.col)?_("MergeOverlap","A code cell cannot sit under a merge."):se},apply:({workbook:t},e)=>Xc(t,e)},un=0,Un=1<<30;class Ls{count;defaultSize;#e=new Int32Array(0);#t=0;#r=0;#o=Un;#s=null;#i=null;#n=null;constructor(e){if(!Number.isInteger(e.count)||e.count<1||e.count>Un-1)throw new Error(`An axis holds 1 to ${Un-1} indexes; ${e.count} was asked for.`);if(!(e.defaultSize>0))throw new Error(`An axis's default size must be positive; ${e.defaultSize} was given.`);this.count=e.count,this.defaultSize=e.defaultSize}idAt(e){return this.#y(e),e<this.#t?this.#e[e]:un+this.#r+(e-this.#t)}materialize(e){if(this.#y(e),e>=this.#t){const n=e+1-this.#t;this.#a(e+1);for(let o=0;o<n;o+=1)this.#e[this.#t+o]=un+this.#r+o;this.#r+=n,this.#t=e+1}return this.#e[e]}get materialized(){return this.#t}freshIds(e){const n=new Int32Array(e);for(let o=0;o<e;o+=1)n[o]=this.#o++;return n}#d(e,n){if(e.sizes!==null||e.hidden!==null)return!1;const o=this.#t-n;for(let r=0;r<n;r+=1){const s=this.count-n+r;if(s<o||e.ids[r]!==un+this.#r+(s-o))return!1}return!0}indexOfId(e){for(let n=0;n<this.#t;n+=1)if(this.#e[n]===e)return n;if(e>=un+this.#r&&e<Un){const n=this.#t+(e-un-this.#r);return n<this.count?n:-1}return-1}ids(){return this.#e.slice(0,this.#t)}segment(e,n){return this.#b(e,n,!1),{ids:Int32Array.from({length:n},(o,r)=>this.idAt(e+r)),sizes:this.#s===null?null:this.#s.slice(e,e+n),hidden:this.#n===null?null:Uint8Array.from({length:n},(o,r)=>this.isHidden(e+r)?1:0)}}insert(e,n,o){if(this.#b(e,n,!0),o!==void 0&&o.ids.length!==n)throw new Error(`insert: ${n} indexes but a segment of ${o.ids.length}.`);const r=this.segment(this.count-n,n);let s;if(o!==void 0)s=o.ids.slice();else{s=new Int32Array(n);for(let a=0;a<n;a+=1)s[a]=this.#o++}if(e>this.#t&&this.materialize(e-1),this.#a(Math.min(this.#t+n,this.count)),this.#e.copyWithin(e+n,e,Math.min(this.#t,this.count-n)),this.#e.set(s,e),this.#t=Math.min(this.#t+n,this.count),this.#s!==null||o?.sizes!=null||o?.hidden!=null){this.#f();const a=this.#s;if(a.copyWithin(e+n,e,this.count-n),o?.sizes?a.set(o.sizes,e):a.fill(this.defaultSize,e,e+n),(this.#n!==null||o?.hidden)&&(this.#n===null&&(this.#n=new Uint32Array(Math.ceil(this.count/32))),Ds(this.#n,this.count,e,n),o?.hidden))for(let l=0;l<n;l+=1)o.hidden[l]&&this.#m(e+l,!0);this.#c(e)}return{inserted:{ids:s,sizes:o?.sizes??null,hidden:o?.hidden??null},dropped:r}}delete(e,n,o){if(this.#b(e,n,!1),o!==void 0&&o.ids.length!==n)throw new Error(`delete: ${n} indexes but a tail of ${o.ids.length}.`);const r=this.segment(e,n);this.materialize(e+n-1);const s=o!==void 0&&!this.#d(o,n);if(s&&this.materialize(this.count-1),this.#e.copyWithin(e,e+n,this.#t),this.#t-=n,s&&(this.#e.set(o.ids,this.count-n),this.#t=this.count),this.#s!==null||o?.sizes!=null||o?.hidden!=null){this.#f();const a=this.#s;if(a.copyWithin(e,e+n,this.count),o?.sizes?a.set(o.sizes,this.count-n):a.fill(this.defaultSize,this.count-n,this.count),(this.#n!==null||o?.hidden)&&(this.#n===null&&(this.#n=new Uint32Array(Math.ceil(this.count/32))),Ds(this.#n,this.count,e,-n),o?.hidden))for(let l=0;l<n;l+=1)o.hidden[l]&&this.#m(this.count-n+l,!0);this.#c(e)}return r}move(e,n,o){if(this.#b(e,n,!1),!Number.isInteger(o)||o<0||o>this.count||o>=e&&o<=e+n)throw new Error(`Cannot move ${n} index(es) at ${e} to ${o}.`);const r=Math.min(e,o),s=Math.max(e+n,o);this.materialize(s-1);const i=a=>{const l=a.slice(e,e+n);o<e?(a.copyWithin(o+n,o,e),a.set(l,o)):(a.copyWithin(e,e+n,o),a.set(l,o-n))};if(i(this.#e),this.#s!==null){if(i(this.#s),this.#n!==null){const a=Float64Array.from({length:this.count},(l,c)=>c>=r&&c<s&&this.isHidden(c)?1:0);i(a);for(let l=r;l<s;l+=1)this.#m(l,a[l]===1)}this.#c(r)}}setSegmentSizes(e,n,o,r){if(this.#b(e,r,!1),!(n===null&&o===null&&this.#s===null)){if(this.#f(),n?this.#s.set(n,e):this.#s.fill(this.defaultSize,e,e+r),o||this.#n!==null){this.#n===null&&(this.#n=new Uint32Array(Math.ceil(this.count/32)));for(let s=0;s<r;s+=1)this.#m(e+s,o?o[s]===1:!1)}this.#c(e)}}sizeOf(e){return this.#y(e),this.#s===null?this.defaultSize:this.#s[e]}effectiveSizeOf(e){return this.isHidden(e)?0:this.sizeOf(e)}resize(e,n){if(this.#y(e),!(n>0)||!Number.isFinite(n))throw new Error(`A size must be positive; ${n} was given.`);this.#f();const o=this.effectiveSizeOf(e);this.#s[e]=n;const r=this.effectiveSizeOf(e);r!==o&&this.#h(e,r-o)}get customized(){return this.#s!==null}get hasHidden(){return this.#n!==null&&this.#n.some(e=>e!==0)}isHidden(e){this.#y(e);const n=this.#n;return n!==null&&(n[e>>>5]&1<<(e&31))!==0}setHidden(e,n){if(this.isHidden(e)===n)return;this.#f(),this.#n===null&&(this.#n=new Uint32Array(Math.ceil(this.count/32)));const o=this.#s[e];n?this.#n[e>>>5]|=1<<(e&31):this.#n[e>>>5]&=~(1<<(e&31)),this.#h(e,n?-o:o)}offsetOf(e){if(!Number.isInteger(e)||e<0||e>this.count)throw new Error(`No offset at index ${e} of an axis of ${this.count}.`);if(this.#i===null)return e*this.defaultSize;let n=0;for(let o=e;o>0;o-=o&-o)n+=this.#i[o];return n}get extent(){return this.offsetOf(this.count)}indexAt(e){if(e<=0)return this.#l(0);if(this.#i===null)return Math.min(Math.floor(e/this.defaultSize),this.count-1);const n=this.#i;let o=0,r=e;for(let s=Vc(this.count);s>0;s>>=1){const i=o+s;i<=this.count&&n[i]<=r&&(o=i,r-=n[i])}return Math.min(o,this.count-1)}#l(e){let n=e;for(;n<this.count-1&&this.effectiveSizeOf(n)===0;)n+=1;return n}#f(){this.#s===null&&(this.#s=new Float64Array(this.count).fill(this.defaultSize),this.#i=new Float64Array(this.count+1),this.#c(0))}#m(e,n){const o=this.#n;n?o[e>>>5]|=1<<(e&31):o[e>>>5]&=~(1<<(e&31))}#h(e,n){const o=this.#i;for(let r=e+1;r<=this.count;r+=r&-r)o[r]+=n}#c(e){const n=this.#i,o=this.count,r=e+1,s=this.#u(e),i=new Float64Array(o-e+1);i[0]=s;let a=s;for(let l=r;l<=o;l+=1){a+=this.effectiveSizeOf(l-1),i[l-e]=a;const c=l-(l&-l),u=c>=e?i[c-e]:this.#u(c);n[l]=a-u}}#u(e){const n=this.#i;let o=0;for(let r=e;r>0;r-=r&-r)o+=n[r];return o}#a(e){if(e<=this.#e.length)return;let n=Math.max(64,this.#e.length);for(;n<e;)n*=2;const o=new Int32Array(Math.min(n,this.count+1));o.set(this.#e.subarray(0,this.#t)),this.#e=o}#y(e){if(!Number.isInteger(e)||e<0||e>=this.count)throw new Error(`Index ${e} is outside an axis of ${this.count}.`)}#b(e,n,o){if(!Number.isInteger(n)||n<1)throw new Error(`A span needs at least one index; ${n} was given.`);if(!Number.isInteger(e)||e<0||e+n>this.count||o&&e>=this.count)throw new Error(`${n} index(es) at ${e} do not fit an axis of ${this.count}.`)}}function Vc(t){let e=1;for(;e*2<=t;)e*=2;return e}function Ds(t,e,n,o){const r=i=>(t[i>>>5]&1<<(i&31))!==0,s=(i,a)=>{a?t[i>>>5]|=1<<(i&31):t[i>>>5]&=~(1<<(i&31))};if(o>0){for(let i=e-1;i>=n+o;i-=1)s(i,r(i-o));for(let i=n;i<n+o;i+=1)s(i,!1)}else{const i=-o;for(let a=n;a<e-i;a+=1)s(a,r(a+i));for(let a=e-i;a<e;a+=1)s(a,!1)}}const ve=1024,ze=10,hn=ve-1;class Kc{source;cached;parsed;constructor(e,n,o=void 0){this.source=e,this.cached=n,this.parsed=o}}class Gc{#e=[];#t=[];add(e){const n=this.#t.pop()??this.#e.length;return this.#e[n]=e,n}get(e){const n=this.#e[e];if(n===void 0)throw new Error(`No formula at ${e} in the formula table.`);return n}remove(e){this.get(e),this.#e[e]=void 0,this.#t.push(e)}get size(){return this.#e.length-this.#t.length}forEach(e){for(const n of this.#e)n!==void 0&&e(n)}}function Fn(t,e){const n=new Array(e-t+1);for(let o=t;o<=e;o+=1)n[o-t]=o;return n}class Zc{kind=new Uint8Array(ve);num=new Float64Array(ve);ref=new Uint32Array(ve);style=new Uint16Array(ve);filled=0}class Jc{chunks=new Map}class qc{#e;#t=new Map;#r=0;constructor(e){this.#e=e}get filled(){return this.#r}get chunkCount(){let e=0;for(const n of this.#t.values())e+=n.chunks.size;return e}columnIndexes(){return this.#t.keys()}get(e,n){const o=this.#t.get(n)?.chunks.get(e>>>ze);if(o===void 0)return null;const r=e&hn;return o.kind[r]===0&&o.style[r]===0?null:this.#o(o,r)}styleAt(e,n){const o=this.#t.get(n)?.chunks.get(e>>>ze);return o===void 0?0:o.style[e&hn]}formulaAt(e,n){const o=this.#t.get(n)?.chunks.get(e>>>ze);if(o===void 0)return;const r=e&hn;return o.kind[r]===5?this.#e.formulas.get(o.ref[r]):void 0}numberAt(e,n){const o=this.#t.get(n)?.chunks.get(e>>>ze);if(o===void 0)return;const r=e&hn;return o.kind[r]===1?o.num[r]:void 0}set(e,n,o){let r=this.#t.get(n);const s=e>>>ze;let i=r?.chunks.get(s);const a=e&hn;if(i!==void 0&&this.#i(i,a),o===null||o.value===null&&o.formula===void 0&&o.style===0){i!==void 0&&i.filled===0&&(r.chunks.delete(s),r.chunks.size===0&&this.#t.delete(n));return}r===void 0&&(r=new Jc,this.#t.set(n,r)),i===void 0&&(i=new Zc,r.chunks.set(s,i)),this.#s(i,a,o)}*entries(e){const n=e!==void 0&&e.right-e.left<this.#t.size?Fn(e.left,e.right):[...this.#t.keys()].sort((o,r)=>o-r);for(const o of n){if(e&&(o<e.left||o>e.right))continue;const r=this.#t.get(o);if(r===void 0)continue;const s=e===void 0?0:e.top>>>ze,i=e===void 0?1/0:e.bottom>>>ze,a=i-s<r.chunks.size?Fn(s,i):[...r.chunks.keys()].sort((l,c)=>l-c);for(const l of a){const c=l<<ze;if(e&&(c+ve-1<e.top||c>e.bottom))continue;const u=r.chunks.get(l);if(u===void 0)continue;const h=e?Math.max(0,e.top-c):0,d=e?Math.min(ve-1,e.bottom-c):ve-1;for(let f=h;f<=d;f+=1)u.kind[f]===0&&u.style[f]===0||(yield[c+f,o,this.#o(u,f)])}}}scan(e,n){const o=e.right-e.left<this.#t.size?Fn(e.left,e.right):[...this.#t.keys()].sort((s,i)=>s-i),r=this.#e.strings;for(const s of o){if(s<e.left||s>e.right)continue;const i=this.#t.get(s);if(i===void 0)continue;const a=e.top>>>ze,l=e.bottom>>>ze,c=l-a<i.chunks.size?Fn(a,l):[...i.chunks.keys()].sort((u,h)=>u-h);for(const u of c){const h=u<<ze;if(h+ve-1<e.top||h>e.bottom)continue;const d=i.chunks.get(u);if(d===void 0)continue;const f=Math.max(0,e.top-h),m=Math.min(ve-1,e.bottom-h),{kind:g,num:w,ref:y}=d;for(let x=f;x<=m;x+=1)switch(g[x]){case 0:break;case 1:n(h+x,s,w[x],!1);break;case 3:n(h+x,s,w[x]!==0,!1);break;case 2:n(h+x,s,r.get(y[x]),!1);break;case 4:{const $=r.get(y[x]);if(!Cn($))throw new Error(`The store holds '${$}' as an error.`);n(h+x,s,Je($),!1);break}case 5:n(h+x,s,null,!0);break}}}}lastRowIn(e){const n=this.#t.get(e);if(n===void 0)return-1;const o=Math.max(...n.chunks.keys()),r=n.chunks.get(o);for(let s=ve-1;s>=0;s-=1)if(r.kind[s]!==0||r.style[s]!==0)return(o<<ze)+s;throw new Error("A kept chunk holds nothing: the store is inconsistent.")}isEmpty(e){for(const n of this.entries(e))return!1;return!0}shiftRows(e,n,o){for(const[r,s]of[...this.#t]){const i=[];for(const[a,l]of[...s.chunks]){const c=a<<ze;if(!(c+ve-1<e))for(let u=0;u<ve;u+=1){const h=c+u;if(h<e||l.kind[u]===0&&l.style[u]===0)continue;const d=this.#o(l,u);if(this.set(h,r,null),n<0&&h<e-n)continue;const f=h+n;f<o&&i.push([f,d])}}for(const[a,l]of i)this.set(a,r,l)}}shiftCols(e,n,o){const r=[...this.#t.keys()].filter(s=>s>=e).sort((s,i)=>n>0?i-s:s-i);for(const s of r){const i=this.#t.get(s);if(this.#t.delete(s),n<0&&s<e-n){for(const[l,c]of i.chunks)for(let u=0;u<ve;u+=1)this.#i(c,u);continue}const a=s+n;if(a<o)this.#t.set(a,i);else for(const l of i.chunks.values())for(let c=0;c<ve;c+=1)this.#i(l,c)}}#o(e,n){const o=e.style[n];switch(e.kind[n]){case 0:return{value:null,style:o};case 1:return{value:e.num[n],style:o};case 3:return{value:e.num[n]!==0,style:o};case 2:return{value:this.#e.strings.get(e.ref[n]),style:o};case 4:{const r=this.#e.strings.get(e.ref[n]);if(!Cn(r))throw new Error(`The store holds '${r}' as an error.`);return{value:Je(r),style:o}}case 5:{const r=this.#e.formulas.get(e.ref[n]);return{value:r.cached,formula:r.source,style:o}}}}#s(e,n,o){const{value:r,formula:s,style:i}=o;if(!Number.isInteger(i)||i<0||i>65535)throw new Error(`No style index ${i}.`);if(e.style[n]=i,s!==void 0)e.kind[n]=5,e.ref[n]=this.#e.formulas.add(new Kc(s,r));else if(r===null)e.kind[n]=0;else if(typeof r=="number"){if(!Number.isFinite(r))throw new Error(`A cell cannot hold ${r}; use an error value.`);e.kind[n]=1,e.num[n]=r}else if(typeof r=="boolean")e.kind[n]=3,e.num[n]=r?1:0;else if(typeof r=="string")e.kind[n]=2,e.ref[n]=this.#e.strings.intern(r);else if(j(r))e.kind[n]=4,e.ref[n]=this.#e.strings.intern(r.error);else throw new Error(`A cell cannot hold ${JSON.stringify(r)}.`);e.filled+=1,this.#r+=1}#i(e,n){const o=e.kind[n];o===0&&e.style[n]===0||(o===2||o===4?this.#e.strings.release(e.ref[n]):o===5&&this.#e.formulas.remove(e.ref[n]),e.kind[n]=0,e.num[n]=0,e.ref[n]=0,e.style[n]=0,e.filled-=1,this.#r-=1)}}class Qc{#e=[];#t=new Int32Array(64);#r=new Map;#o=[];intern(e){let n=this.#r.get(e);if(n===void 0&&(n=this.#o.pop()??this.#e.length,this.#e[n]=e,this.#r.set(e,n),n>=this.#t.length)){const o=new Int32Array(this.#t.length*2);o.set(this.#t),this.#t=o}return this.#t[n]+=1,n}release(e){const n=this.#e[e];if(n===void 0||this.#t[e]<=0)throw new Error(`The string pool holds nothing at ${e}: released twice?`);this.#t[e]-=1,this.#t[e]===0&&(this.#e[e]=void 0,this.#r.delete(n),this.#o.push(e))}get(e){const n=this.#e[e];if(n===void 0)throw new Error(`The string pool holds nothing at ${e}.`);return n}get size(){return this.#r.size}references(e){return this.#t[e]??0}}const Lr={rows:1048576,cols:16384,rowHeight:21,colWidth:100};class eu{id;name;rows;cols;cells;merges=[];frozen={rows:0,cols:0};charts=new Map;code=new Map;dataSource=null;constructor(e,n,o,r){this.id=e,this.name=n,this.rows=new Ls({count:o.rows,defaultSize:o.rowHeight}),this.cols=new Ls({count:o.cols,defaultSize:o.colWidth}),this.cells=r}mergeAt(e,n){return this.merges.find(o=>e>=o.top&&e<=o.bottom&&n>=o.left&&n<=o.right)}mergesIn(e){return this.merges.filter(n=>mt(n,e))}}class tu{limits;sheetIdPrefix="s";strings=new Qc;styles=new La;formulas=new Gc;sheets=[];#e=1;constructor(e=Lr){for(const[n,o]of Object.entries(e))if(!(typeof o=="number"&&o>0))throw new Error(`limits.${n} must be positive; ${o} was given.`);this.limits=e}createSheet(e,n){const o=n??this.#t();if(this.sheets.some(r=>r.id===o))throw new Error(`A sheet with id '${o}' exists already.`);return new eu(o,e,this.limits,new qc({strings:this.strings,formulas:this.formulas}))}sheet(e){const n=this.sheets.find(o=>o.id===e);if(n===void 0)throw new Error(`No sheet '${e}'; the workbook has ${this.sheets.map(o=>o.id).join(", ")||"none"}.`);return n}hasSheet(e){return this.sheets.some(n=>n.id===e)}sheetByName(e){const n=e.toLowerCase();return this.sheets.find(o=>o.name.toLowerCase()===n)}freshSheetName(){for(let e=1;;e+=1)if(this.sheetByName(`Sheet${e}`)===void 0)return`Sheet${e}`}#t(){for(;;){const e=`${this.sheetIdPrefix}${this.#e++}`;if(!this.hasSheet(e))return e}}}class ct{#e;#t;#r;#o=-1;#s=new Map;#i=[];constructor(e,n,o){this.#e=e,this.#t=n,this.#r=o}get(e){return this.#n(),this.#s.get(e)}all(){return this.#n(),this.#i}keys(){return this.#n(),this.#s.keys()}get revision(){return this.#n(),this.#o}#n(){const e=this.#e.getRevision();if(e===this.#o)return;const n=this.#e.getContributions(this.#t),o=new Map,r=[];for(const s of n){const i=nu(s,this.#r),a=this.#r.key(s.value),l=o.get(a);if(l!==void 0)throw new Error(`The ${this.#r.label} '${a}' is contributed twice to ${this.#t.id}: by ${l.plugin} (id '${l.id}') and by ${s.plugin} (id '${s.id}'). Disable one of the two plugins, or rename one ${this.#r.label}.`);o.set(a,i),r.push(i)}this.#o=e,this.#s=o,this.#i=r}}function nu(t,e){if(e.check)try{e.check(t.value)}catch(n){throw new Error(`${t.plugin} contributes a malformed ${e.label} (id '${t.id}'): ${n.message}`)}return{value:t.value,plugin:t.plugin,id:t.id}}function tl(t,e,n){const o=t.getContributions(e),[r,s]=o;if(r!==void 0){if(s!==void 0&&s.order===r.order)throw new Error(`Two plugins contribute a ${n} (${e.id}) at the same order ${r.order}: ${r.plugin} (id '${r.id}') and ${s.plugin} (id '${s.id}'). Give one a lower order, or disable one.`);return{value:r.value,plugin:r.plugin,id:r.id}}}const Dr=pe("datalayer.cells.patchOp"),Zt=pe("datalayer.cells.command"),Ur=pe("datalayer.cells.function"),Fr=pe("datalayer.cells.cellType"),nl=pe("datalayer.cells.renderLayer"),Tt=pe("datalayer.cells.clipboard"),Pr=pe("datalayer.cells.fillRule"),ou=pe("datalayer.cells.importer"),ol=pe("datalayer.cells.exporter"),go=pe("datalayer.cells.dataSource"),ru=pe("datalayer.cells.collabProvider"),rl=pe("datalayer.cells.codeRenderer"),sl=pe("datalayer.cells.kernel"),po=pe("datalayer.cells.toolbarItem"),qe=pe("datalayer.cells.menuItem"),jr=pe("datalayer.cells.chartType"),il=pe("datalayer.cells.chartOption"),Br=pe("datalayer.cells.chartRenderer"),ll=sa("datalayer.cells.gate.edit"),su=[Dr,Zt,Ur,Fr,nl,Tt,Pr,ou,ol,go,ru,po,qe,jr,il,Br,ll,sl,rl],Fe=1024,iu=256;function kn(t){return{top:t.at.row,left:t.at.col,bottom:t.at.row+t.rows-1,right:t.at.col+t.cols-1}}const lu={op:"dataSource",apply(t,e){t.sheet(e.sheet).dataSource=e.after===null?null:{...e.after,at:{...e.after.at}}},invert:t=>({...t,before:t.after,after:t.before}),example:()=>({op:"dataSource",sheet:"s1",before:null,after:{id:"example",at:{row:1,col:1},rows:10,cols:2}})},au={type:"BIND_DATA_SOURCE",allow(t,e){const{workbook:n}=t;if(!n.hasSheet(e.sheet))return _("UnknownSheet",`No sheet '${e.sheet}'.`);const o=n.sheet(e.sheet);if(e.source===null)return o.dataSource===null?_("InvalidArgument",`Sheet '${o.name}' is bound to no data source.`):{ok:!0};if(typeof e.source!="string"||e.source==="")return _("InvalidArgument","BIND_DATA_SOURCE names a data source by id, or null.");const r=t.contributions(go).find(u=>u.id===e.source);if(r===void 0)return _("UnknownDataSource",`No plugin contributes the data source '${e.source}'.`);const s=e.at??{row:0,col:0},i=u=>Number.isInteger(u)&&u>=0;if(!i(s.row)||!i(s.col))return _("InvalidArgument","BIND_DATA_SOURCE lands at a cell: { row, col }.");if(o.dataSource!==null)return _("InvalidArgument",`Sheet '${o.name}' is bound to the data source '${o.dataSource.id}' already; unbind it first.`);const a=r.rowCount,l=r.columns.length;if(a<1||l<1)return _("InvalidArgument",`The data source '${r.id}' has no rows or no columns.`);if(s.row+a>o.rows.count||s.col+l>o.cols.count)return _("OutOfBounds",`The data source '${r.id}' has ${a.toLocaleString("en-US")} rows and ${l} columns: from ${Oe({top:s.row,left:s.col,bottom:s.row,right:s.col})} it reaches past the sheet's ${o.rows.count.toLocaleString("en-US")} rows and ${o.cols.count.toLocaleString("en-US")} columns.`);const c=kn({id:r.id,at:s,rows:a,cols:l});return o.cells.isEmpty(c)?o.mergesIn(c).length>0?_("MergeOverlap",`${Oe(c)} holds merges; a data source lands on plain cells.`):{ok:!0}:_("InvalidArgument",`${Oe(c)} holds cells; a data source lands on empty cells.`)},apply(t,e){const n=t.workbook.sheet(e.sheet),o=n.dataSource;if(e.source===null)return[{op:"dataSource",sheet:n.id,before:o,after:null}];const r=t.contributions(go).find(i=>i.id===e.source),s={id:r.id,at:e.at??{row:0,col:0},rows:r.rowCount,cols:r.columns.length};return[{op:"dataSource",sheet:n.id,before:o,after:s}]}};class cu{#e;#t;#r;#o;#s;#i=new Map;#n=new Map;stats={resident:0,loading:0,failed:0,fetches:0,evictions:0};constructor(e,n,o){if(this.#e=e,this.#t=n,this.#r=o.pages??iu,!(Number.isInteger(this.#r)&&this.#r>=1))throw new Error(`dataSources.pages is a positive integer; ${String(o.pages)} was given.`);this.#o=o.onWritten,this.#s=o.onError}get capacity(){return this.#r}resolve(e){if(!this.#e.hasSheet(e))return;const n=this.#e.sheet(e).dataSource;if(n===null)return;const o=this.#t.revision,r=this.#n.get(e);return r!==void 0&&r.revision===o&&r.binding===n?r.out:this.#d(e,n,o,r)}#d(e,n,o,r){const s=kn(n),i=this.#t.get(n.id);let a;return i===void 0?a={binding:n,zone:s,problem:`No plugin contributes the data source '${n.id}'.`}:i.value.rowCount!==n.rows||i.value.columns.length!==n.cols?a={binding:n,zone:s,problem:`The data source '${n.id}' has ${i.value.rowCount.toLocaleString("en-US")} rows and ${i.value.columns.length} columns; the sheet binds ${n.rows.toLocaleString("en-US")} rows and ${n.cols} columns. Bind it again.`}:a={binding:n,zone:s,source:i},this.#n.set(e,{revision:o,binding:n,out:a}),r!==void 0&&r.binding===n&&r.out.source!==a.source&&this.forget(e),a}zoneOf(e){return this.resolve(e)?.zone}missing(e,n,o){const r=e.dataSource;if(r===null||n<r.at.row||n>=r.at.row+r.rows||o<r.at.col||o>=r.at.col+r.cols)return;const s=this.resolve(e.id);if(s.source===void 0)return Je("#N/A",s.problem);const i=Math.floor((n-s.zone.top)/Fe),a=this.#f(e.id,i,s);if(a.state!=="resident")return this.#l(a,s)}ensureZone(e,n){const o=this.resolve(e);if(o===void 0||!mt(o.zone,n))return;if(o.source===void 0)return Je("#N/A",o.problem);const r=Math.max(n.top,o.zone.top),s=Math.min(n.bottom,o.zone.bottom),i=Math.floor((r-o.zone.top)/Fe),a=Math.floor((s-o.zone.top)/Fe),l=a-i+1;if(l>this.#r)return Je("#N/A",`Reading ${Oe(n)} needs ${l.toLocaleString("en-US")} pages of the data source '${o.binding.id}'; ${this.#r} stay resident. Read a smaller range.`);let c;for(let u=i;u<=a;u+=1){const h=this.#f(e,u,o);h.state!=="resident"&&c===void 0&&(c=this.#l(h,o))}return c}forget(e){for(const[n,o]of[...this.#i])o.sheet===e&&this.#u(n,o,!0)}forgetAll(){this.#i.clear(),this.#n.clear(),this.stats.resident=0,this.stats.loading=0,this.stats.failed=0}willApply(e){if(e.op!=="dataSource")return;const{sheet:n,before:o,after:r}=e;o!==null&&(r===null||r.id!==o.id||r.rows!==o.rows||r.cols!==o.cols)&&this.forget(n)}refuses(e){const n=[...e.filter(o=>o.op.startsWith("axis-")),...e.filter(o=>!o.op.startsWith("axis-"))];for(const o of n){const r=o.sheet;if(typeof r!="string"||!this.#e.hasSheet(r))continue;const s=this.#e.sheet(r).dataSource;if(s===null)continue;const i=kn(s),a=l=>_("ReadOnly",`${Oe(i)} shows the data source '${s.id}' and cannot be changed${l}.`);if(o.op==="cells"){if(mt(o.zone,i))return a("")}else if(o.op==="merges"){if(o.after.some(c=>mt(c,i)))return a(": no merge over it")}else if(o.op==="axis-insert"||o.op==="axis-delete"||o.op==="axis-move"){const l=o,c=l.axis==="rows"?i.top:i.left,u=l.axis==="rows"?i.bottom:i.right,h=f=>f>c&&f<=u,d=l.at<=u&&l.at+l.n-1>=c;if(o.op==="axis-insert"&&h(l.at))return a(`: no ${l.axis} inserted inside it`);if(o.op==="axis-delete"&&d)return a(`: no ${l.axis} deleted from it`);if(o.op==="axis-move"&&(d||h(l.to)))return a(`: no ${l.axis} moved into or out of it`)}}}#l(e,n){return e.state==="failed"?Je("#N/A",`The data source '${n.binding.id}' failed for rows ${(e.index*Fe+1).toLocaleString("en-US")}–${Math.min((e.index+1)*Fe,n.binding.rows).toLocaleString("en-US")}: ${e.error}`):Je("#BUSY!",`The data source '${n.binding.id}' is reading rows ${(e.index*Fe+1).toLocaleString("en-US")}–${Math.min((e.index+1)*Fe,n.binding.rows).toLocaleString("en-US")}.`)}#f(e,n,o){const r=`${e}:${n}`,s=this.#i.get(r);if(s!==void 0)return this.#i.delete(r),this.#i.set(r,s),s;const i={sheet:e,index:n,state:"loading"};this.#i.set(r,i),this.stats.loading+=1,this.stats.fetches+=1;const a=n*Fe,l=Math.min(a+Fe-1,o.binding.rows-1),c=o.source.value,u=(h,d)=>{if(!(this.#i.get(r)!==i||i.state!=="loading")){if(this.stats.loading-=1,d===void 0&&h!==void 0&&(Array.isArray(h)&&h.length===o.binding.cols?h.find(m=>!Array.isArray(m)||m.length!==l-a+1):h)!==void 0&&(d=new Error(`the data source '${c.id}' answered ${Array.isArray(h)?h.length:"no"} columns for rows ${a+1}–${l+1}, not ${o.binding.cols} columns of ${l-a+1} rows.`)),d!==void 0){i.state="failed",i.error=d.message,this.stats.failed+=1,this.#s({sheet:e,source:c.id,rows:{from:a,to:l},error:d}),this.#o(e,this.#m(o,n));return}this.#c(i),i.state="resident",this.stats.resident+=1,this.#h(e,o,n,h,a,l),this.#o(e,this.#m(o,n))}};try{Promise.resolve(c.fetch({from:a,to:l})).then(h=>u(h,void 0),h=>u(void 0,h instanceof Error?h:new Error(String(h))))}catch(h){u(void 0,h instanceof Error?h:new Error(String(h)))}return i}#m(e,n){const o=e.zone;return{top:o.top+n*Fe,left:o.left,bottom:Math.min(o.top+(n+1)*Fe-1,o.bottom),right:o.right}}#h(e,n,o,r,s,i){const a=this.#e.sheet(e).cells,l=n.zone;for(let c=0;c<r.length;c+=1){const u=l.left+c,h=r[c];for(let d=0;d<=i-s;d+=1){const f=h[d],m=l.top+s+d;f!=null&&a.set(m,u,{value:f,style:a.styleAt(m,u)})}}}#c(e){for(;this.stats.resident>=this.#r;){let n;for(const o of this.#i)if(o[1].state==="resident"&&o[1]!==e){n=o;break}if(n===void 0)return;this.#u(n[0],n[1],!0),this.stats.evictions+=1}}#u(e,n,o){if(this.#i.delete(e),n.state==="resident"?this.stats.resident-=1:n.state==="loading"?this.stats.loading-=1:this.stats.failed-=1,n.state!=="resident"||!o)return;const r=this.#e.sheet(n.sheet).dataSource;if(r===null)return;const s=this.#m({binding:r,zone:kn(r)},n.index),i=this.#e.sheet(n.sheet).cells;for(const[a,l]of[...i.entries(s)])i.set(a,l,null);this.#o(n.sheet,s)}}function uu(t){return t.dataSource===null?void 0:kn(t.dataSource)}const mr=1;class al extends Error{}function B(t,e){throw new al(`${t}: ${e}`)}const xe=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Xo=(t,e)=>/^(0|[1-9][0-9]*)$/.test(t)&&Number(t)<e;function hu(t,e){if(!(t===null||typeof t=="string"||typeof t=="boolean")){if(typeof t=="number"){Number.isFinite(t)||B(e(),`${t} is not a value`);return}if(xe(t)&&typeof t.error=="string"&&Object.keys(t).length===1){Cn(t.error)||B(e(),`'${t.error}' is not an error code`);return}B(e(),`${JSON.stringify(t)} is not a value (a number, a string, a boolean, null or { error })`)}}function fu(t,e,n){xe(t)||B(e,"a zone is { top, left, bottom, right }");for(const a of["top","left","bottom","right"])(!Number.isInteger(t[a])||t[a]<0)&&B(`${e}.${a}`,"a non-negative integer");const{top:o,left:r,bottom:s,right:i}=t;(o>s||r>i)&&B(e,"top-left after bottom-right"),(s>=n.rows||i>=n.cols)&&B(e,"outside the sheet")}function cl(t,e=Lr){xe(t)||B("workbook","a CellsWorkbook is a JSON object"),t.version!==mr&&B("version",`this is format version ${JSON.stringify(t.version)}; Cells reads version ${mr}`);const n=t.styles??[];Array.isArray(n)||B("styles","a list"),n.forEach((s,i)=>zr(s,`styles[${i}]`)),n.length>0&&Object.keys(n[0]).length>0&&B("styles[0]","style 0 is the default: {}"),(!Array.isArray(t.sheets)||t.sheets.length===0)&&B("sheets","a non-empty list");const o=new Set,r=new Set;return t.sheets.forEach((s,i)=>{const a=`sheets[${i}]`;xe(s)||B(a,"a sheet is an object"),(typeof s.id!="string"||s.id==="")&&B(`${a}.id`,"a non-empty string"),o.has(s.id)&&B(`${a}.id`,`'${s.id}' is used twice`),o.add(s.id),(typeof s.name!="string"||s.name.trim()==="")&&B(`${a}.name`,"a non-empty string"),r.has(s.name.toLowerCase())&&B(`${a}.name`,`'${s.name}' is used twice`),r.add(s.name.toLowerCase()),xe(s.rows)||B(`${a}.rows`,"an object keyed by row index");for(const l in s.rows){const c=s.rows[l],u=()=>`${a}.rows["${l}"]`;Xo(l,e.rows)||B(u(),`'${l}' is not a row index below ${e.rows}`),(!xe(c)||!xe(c.cells))&&B(u(),"a row is { cells: { … } }");const h=c.cells;for(const d in h){const f=h[d],m=()=>`${u()}.cells["${d}"]`;Xo(d,e.cols)||B(m(),`'${d}' is not a column index below ${e.cols}`),xe(f)||B(m(),"a cell is { v?, f?, s? }");for(const g in f)g!=="v"&&g!=="f"&&g!=="s"&&B(`${m()}.${g}`,"a cell has v, f and s only");"v"in f&&hu(f.v,()=>`${m()}.v`),"f"in f&&(typeof f.f!="string"||f.f==="")&&B(`${m()}.f`,"a formula without the ="),"s"in f&&(!Number.isInteger(f.s)||f.s<0||f.s>=Math.max(1,n.length))&&B(`${m()}.s`,`no style ${JSON.stringify(f.s)}`)}}if(s.sizes!==void 0){xe(s.sizes)||B(`${a}.sizes`,"{ rows?, cols? }");for(const l of["rows","cols"]){const c=s.sizes[l];if(c!==void 0){xe(c)||B(`${a}.sizes.${l}`,"an object keyed by index");for(const[u,h]of Object.entries(c))Xo(u,e[l])||B(`${a}.sizes.${l}["${u}"]`,"not an index of the sheet"),typeof h=="number"&&h>0&&Number.isFinite(h)||B(`${a}.sizes.${l}["${u}"]`,"a positive size")}}}if(s.hidden!==void 0){xe(s.hidden)||B(`${a}.hidden`,"{ rows?, cols? }");for(const l of["rows","cols"]){const c=s.hidden[l];c!==void 0&&(Array.isArray(c)||B(`${a}.hidden.${l}`,"a list of indexes"),c.forEach((u,h)=>{(!Number.isInteger(u)||u<0||u>=e[l])&&B(`${a}.hidden.${l}[${h}]`,"not an index of the sheet")}))}}if(s.merges!==void 0&&(Array.isArray(s.merges)||B(`${a}.merges`,"a list of zones"),s.merges.forEach((l,c)=>fu(l,`${a}.merges[${c}]`,e))),s.charts!==void 0){xe(s.charts)||B(`${a}.charts`,"an object of charts by id");for(const[l,c]of Object.entries(s.charts)){const u=`${a}.charts["${l}"]`,h=ji(c,u,e);h.id!==l&&B(`${u}.id`,`the chart is filed under '${l}' and says '${h.id}'`)}}if(s.code!==void 0){xe(s.code)||B(`${a}.code`,"an object of code cells by cell (B4)");for(const[l,c]of Object.entries(s.code)){const u=`${a}.code["${l}"]`,h=/^([A-Z]{1,3})([1-9][0-9]*)$/.exec(l);let d=-1;if(h!==null)for(const m of h[1])d=(d+1)*26+m.charCodeAt(0)-65;(h===null||Number(h[2])>e.rows||d>=e.cols)&&B(u,`'${l}' is not a cell of the sheet`);const f=qi(c,u);if(f!==void 0)throw new al(f)}}if(s.dataSource!==void 0){const l=s.dataSource,c=`${a}.dataSource`;xe(l)||B(c,"{ id, row, col, rows, cols }"),(typeof l.id!="string"||l.id==="")&&B(`${c}.id`,"the id of a data source");for(const u of["row","col","rows","cols"])(!Number.isInteger(l[u])||l[u]<0)&&B(`${c}.${u}`,"a non-negative integer");for(const u of["rows","cols"])l[u]<1&&B(`${c}.${u}`,"at least 1");(l.row+l.rows>e.rows||l.col+l.cols>e.cols)&&B(c,"reaches outside the sheet")}if(s.frozen!==void 0){const l=s.frozen;(!xe(l)||!Number.isInteger(l.rows)||!Number.isInteger(l.cols)||l.rows<0||l.cols<0)&&B(`${a}.frozen`,"{ rows, cols }, non-negative integers")}}),t}const Us=t=>t==null?null:typeof t=="object"?Je(t.error):t,du=t=>j(t)?{error:t.error}:t;function Fs(t,e){if(t.sheets.length>0)throw new Error("loadInto fills an empty workbook.");const n=cl(e,t.limits),o=(n.styles??[]).map(r=>t.styles.intern(r));for(const r of n.sheets){const s=t.createSheet(r.name,r.id);for(const i in r.rows){const a=Number(i),l=r.rows[i].cells;for(const c in l){const u=l[c],h=u.s===void 0?0:o[u.s]??0,d=u.f===void 0?{value:Us(u.v),style:h}:{value:Us(u.v),formula:u.f,style:h};s.cells.set(a,Number(c),d)}}for(const i of["rows","cols"]){const a=i==="rows"?s.rows:s.cols;for(const[l,c]of Object.entries(r.sizes?.[i]??{}))a.resize(Number(l),c);for(const l of r.hidden?.[i]??[])a.setHidden(l,!0)}s.merges=(r.merges??[]).map(i=>({...i}));for(const[i,a]of Object.entries(r.charts??{}))s.charts.set(i,a);for(const[i,a]of Object.entries(r.code??{})){const l=/^([A-Z]+)([0-9]+)$/.exec(i);let c=-1;for(const u of l[1])c=(c+1)*26+u.charCodeAt(0)-65;s.code.set(ht(s,Number(l[2])-1,c),a)}s.frozen=r.frozen?{rows:r.frozen.rows,cols:r.frozen.cols}:{rows:0,cols:0},s.dataSource=r.dataSource?{id:r.dataSource.id,at:{row:r.dataSource.row,col:r.dataSource.col},rows:r.dataSource.rows,cols:r.dataSource.cols}:null,t.sheets.push(s)}}function mu(t){const e=new Map([[0,0]]),n=[{}],o=s=>{let i=e.get(s);return i===void 0&&(i=n.length,n.push(t.styles.get(s)),e.set(s,i)),i},r=t.sheets.map(s=>{const i={},a=uu(s),l=[...s.cells.entries()].filter(([f,m])=>a===void 0||!zt(a,{row:f,col:m})).sort((f,m)=>f[0]-m[0]||f[1]-m[1]);for(const[f,m,g]of l){const w={};g.value!==null&&(w.v=du(g.value)),g.formula!==void 0&&(w.f=g.formula),g.style!==0&&(w.s=o(g.style)),(i[f]??={cells:{}}).cells[m]=w}const c={id:s.id,name:s.name,rows:i},u={},h={};for(const f of["rows","cols"]){const m=f==="rows"?s.rows:s.cols,g=gu(m);Object.keys(g.sizes).length>0&&(u[f]=g.sizes),g.hidden.length>0&&(h[f]=g.hidden)}Object.keys(u).length>0&&(c.sizes=u),Object.keys(h).length>0&&(c.hidden=h),s.merges.length>0&&(c.merges=s.merges.map(f=>({...f}))),(s.frozen.rows>0||s.frozen.cols>0)&&(c.frozen={...s.frozen}),s.charts.size>0&&(c.charts=Object.fromEntries(s.charts));const d={};for(const[f,m]of s.code){const g=el(s,f);g!==void 0&&(d[et(g.row,g.col)]=m)}return Object.keys(d).length>0&&(c.code=Object.fromEntries(Object.entries(d).sort(([f],[m])=>f.localeCompare(m)))),s.dataSource!==null&&(c.dataSource={id:s.dataSource.id,row:s.dataSource.at.row,col:s.dataSource.at.col,rows:s.dataSource.rows,cols:s.dataSource.cols}),c});return{version:mr,sheets:r,styles:n}}function gu(t){const e={},n=[];if(!t.customized)return{sizes:e,hidden:n};for(let o=0;o<t.count;o+=1){const r=t.sizeOf(o);r!==t.defaultSize&&(e[o]=r),t.isHidden(o)&&n.push(o)}return{sizes:e,hidden:n}}const ul={steps:500,bytes:64*1024*1024};class pu{limits;#e=[];#t=[];#r=0;constructor(e=ul){if(!(e.steps>=1)||!(e.bytes>=1))throw new Error("History limits must be positive.");this.limits=e}push(e){this.#e.push(e),this.#r+=e.bytes;for(const n of this.#t)this.#r-=n.bytes;for(this.#t=[];this.#e.length>this.limits.steps||this.#r>this.limits.bytes&&this.#e.length>1;)this.#r-=this.#e.shift().bytes}popUndo(){const e=this.#e.pop();return e&&this.#t.push(e),e}popRedo(){const e=this.#t.pop();return e&&this.#e.push(e),e}get canUndo(){return this.#e.length>0}get canRedo(){return this.#t.length>0}get size(){return{steps:this.#e.length,bytes:this.#r}}get undoLabel(){return this.#e.at(-1)?.label}get redoLabel(){return this.#t.at(-1)?.label}clear(){this.#e=[],this.#t=[],this.#r=0}}const wo=1;function hl(t,e={}){return e.transpose?{rows:t.cols,cols:t.rows}:{rows:t.rows,cols:t.cols}}function fl(t){const e=t;if(typeof t!="object"||t===null)throw new Error("A clipboard slice is an object.");if(e.version!==wo)throw new Error(`This clipboard slice is version ${String(e.version)}; Cells reads version ${wo}.`);if(!Number.isInteger(e.rows)||!Number.isInteger(e.cols)||e.rows<1||e.cols<1)throw new Error("A clipboard slice has a size of at least one cell.");if(typeof e.parts!="object"||e.parts===null)throw new Error("A clipboard slice has parts.")}function wu(t,e,n){const{workbook:o}=t,r=o.sheet(e),s=[];for(const[i,a,l]of r.cells.entries(n)){const c=l.style===0?void 0:o.styles.get(l.style),u=l.formula===void 0?l.value:t.value(e,i,a);s.push({r:i-n.top,c:a-n.left,...u!==null?{v:u}:{},...l.formula!==void 0?{f:l.formula}:{},...c?{style:c}:{}})}return s}function yu(t,e,n,o,r,s){const i=t.workbook,a=i.sheet(e),l={rows:a.rows.count,cols:a.cols.count},c=r.special??"all",u=[],h=new Set;for(const d of n){const[f,m]=r.transpose?[d.c,d.r]:[d.r,d.c],g=o.top+f,w=o.left+m,y=a.cells.get(g,w);h.add(`${g},${w}`);const x=c==="values"||c==="formulas"?y?.style??0:d.style?i.styles.intern(d.style):0;if(c==="formats")u.push([g,w,y===null?{value:null,style:x}:{...y,style:x}]);else if(c==="values"||d.f===void 0)u.push([g,w,{value:d.v??null,style:x}]);else{const $=s&&{row:s.zone.top+d.r,col:s.zone.left+d.c},A=s===void 0||s.cut?d.f:r.transpose?sc(d.f,$,{row:g,col:w},l):Or(d.f,g-$.row,w-$.col,l);u.push([g,w,{value:null,formula:A,style:x}])}}for(const[d,f,m]of a.cells.entries(o))h.has(`${d},${f}`)||(c==="all"?u.push([d,f,null]):c==="values"||c==="formulas"?u.push([d,f,{value:null,style:m.style}]):u.push([d,f,{...m,style:0}]));return en(a,o,u)}function dl(t,e){return{top:t.row,left:t.col,bottom:t.row+e.rows-1,right:t.col+e.cols-1}}function bu(t,e){if(!t.workbook.hasSheet(e.sheet))return _("UnknownSheet",`No sheet '${e.sheet}'.`);try{fl(e.slice)}catch(r){return _("InvalidArgument",r.message)}const n=t.workbook.sheet(e.sheet),o=dl(e.at,hl(e.slice,e.options));if(o.top<0||o.left<0||o.bottom>=n.rows.count||o.right>=n.cols.count)return _("OutOfBounds",`The paste of ${o.bottom-o.top+1} × ${o.right-o.left+1} cells reaches past the end of the sheet.`);for(const r of n.mergesIn(o))if(!(r.top>=o.top&&r.bottom<=o.bottom&&r.left>=o.left&&r.right<=o.right))return _("MergeOverlap","The paste would cut a merged cell in two; unmerge it first.");return se}function xu(t){const e=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;return t.map(n=>n.map(e).join(" ")).join(`
3
3
  `)}function vu(t){const e=[];let n=[],o="",r=!1;const s=t.replace(/\r\n?/g,`
4
4
  `).replace(/\n$/,"");for(let i=0;i<s.length;i+=1){const a=s[i];r?a==='"'&&s[i+1]==='"'?(o+='"',i+=1):a==='"'?r=!1:o+=a:a==='"'&&o===""?r=!0:a===" "?(n.push(o),o=""):a===`
@@ -84,4 +84,4 @@ ${n.text.slice(ie.selectionEnd)}`)}else R.key==="Enter"?(R.preventDefault(),xt({
84
84
  grid full ${o.gridFull} · partial ${o.gridPartial} · blits ${o.blits} · overlay ${o.overlay}
85
85
  painted ${o.cells} cells, ${o.texts} texts
86
86
  text cache ${s.size} · hit ${i} %
87
- cells ${r.cells.toLocaleString()} · chunks ${r.chunks} · strings ${r.strings} · styles ${r.styles}`})}const rm="@datalayer/cells-charts",mm=ha({name:rm,displayName:"Cells charts",description:"Column, bar, line, area, pie, scatter and combo charts, drawn with Apache ECharts.",octicon:"graph",activationEvents:[fs(jr),fs(Br)],load:()=>Ri(()=>import("./plugin-D7Giq2rW.js"),[],import.meta.url)});function gm(t){const{sheets:e,active:n,add:o,rename:r,move:s,remove:i,activate:a}=Hf(),[l,c]=k.useState(null),[u,h]=k.useState(""),d=k.useRef(new Map),f=()=>{if(l===null)return;const y=r(l.id,l.name.trim());y.ok?(c(null),h("")):h(y.refusals.map(x=>x.message).join(" "))},m=(y,x)=>{const $=e.length,A=y.key==="ArrowRight"?(x+1)%$:y.key==="ArrowLeft"?(x+$-1)%$:y.key==="Home"?0:y.key==="End"?$-1:void 0;A!==void 0?(y.preventDefault(),a(e[A].id),d.current.get(e[A].id)?.focus()):y.key==="F2"&&(y.preventDefault(),c({id:e[x].id,name:e[x].name}))},g=e.findIndex(y=>y.id===n),w=e[g];return C.jsxs("div",{"data-cells-sheet-tabs":"",style:{display:"flex",alignItems:"center",gap:4,padding:4},children:[C.jsx("div",{role:"tablist","aria-label":t["aria-label"]??"Sheets",style:{display:"flex",gap:2},children:e.map((y,x)=>{const $=y.id===n;return C.jsx("button",{ref:A=>{d.current.set(y.id,A)},role:"tab",type:"button","aria-selected":$,tabIndex:$?0:-1,onClick:()=>a(y.id),onDoubleClick:()=>c({id:y.id,name:y.name}),onKeyDown:A=>m(A,x),style:{padding:"2px 10px",border:"1px solid var(--borderColor-muted, #d0d7de)",borderBottom:$?"2px solid var(--borderColor-accent-emphasis, #0969da)":void 0,background:$?"var(--bgColor-default, #fff)":"var(--bgColor-muted, #f6f8fa)",color:"var(--fgColor-default, #1f2328)",fontWeight:$?600:400,cursor:"pointer"},children:y.name},y.id)})}),l!==null&&C.jsx(fa,{"aria-label":`Rename ${e.find(y=>y.id===l.id)?.name??""}`,size:"small",autoFocus:!0,value:l.name,onChange:y=>c({id:l.id,name:y.target.value}),onBlur:f,onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),f()):y.key==="Escape"&&(c(null),h(""))}}),C.jsx(ds,{icon:da,"aria-label":"Add a sheet",size:"small",variant:"invisible",onClick:()=>{const y=o();y.ok||h(y.refusals.map(x=>x.message).join(" "))}}),w!==void 0&&C.jsxs(Uo,{children:[C.jsx(Uo.Anchor,{children:C.jsx(ds,{icon:ma,"aria-label":`More for ${w.name}`,size:"small",variant:"invisible"})}),C.jsx(Uo.Overlay,{children:C.jsxs(Be,{children:[C.jsx(Be.Item,{onSelect:()=>c({id:w.id,name:w.name}),children:"Rename"}),C.jsx(Be.Item,{disabled:g===0,onSelect:()=>s(w.id,g-1),children:"Move left"}),C.jsx(Be.Item,{disabled:g===e.length-1,onSelect:()=>s(w.id,g+1),children:"Move right"}),C.jsx(Be.Divider,{}),C.jsx(Be.Item,{variant:"danger",disabled:e.length===1,onSelect:()=>{const y=i(w.id);y.ok||h(y.refusals.map(x=>x.message).join(" "))},children:"Delete"})]})})]}),u&&C.jsx("span",{role:"alert",style:{color:"var(--fgColor-danger, #d1242f)"},children:u})]})}export{Hi as A,lm as B,po as C,jr as D,Br as E,dm as S,cm as a,um as b,Ye as c,Bf as d,_f as e,hm as f,fm as g,am as h,j as i,Pf as j,gm as k,If as l,mm as m,Jt as n,qi as o,Cn as p,Wr as q,Li as r,hc as s,Or as t,yt as u,Yh as v,fr as w,Yi as x,dr as y,Oe as z};
87
+ cells ${r.cells.toLocaleString()} · chunks ${r.chunks} · strings ${r.strings} · styles ${r.styles}`})}const rm="@datalayer/cells-charts",mm=ha({name:rm,displayName:"Cells charts",description:"Column, bar, line, area, pie, scatter and combo charts, drawn with Apache ECharts.",octicon:"graph",activationEvents:[fs(jr),fs(Br)],load:()=>Ri(()=>import("./plugin-NcgdmcAO.js"),[],import.meta.url)});function gm(t){const{sheets:e,active:n,add:o,rename:r,move:s,remove:i,activate:a}=Hf(),[l,c]=k.useState(null),[u,h]=k.useState(""),d=k.useRef(new Map),f=()=>{if(l===null)return;const y=r(l.id,l.name.trim());y.ok?(c(null),h("")):h(y.refusals.map(x=>x.message).join(" "))},m=(y,x)=>{const $=e.length,A=y.key==="ArrowRight"?(x+1)%$:y.key==="ArrowLeft"?(x+$-1)%$:y.key==="Home"?0:y.key==="End"?$-1:void 0;A!==void 0?(y.preventDefault(),a(e[A].id),d.current.get(e[A].id)?.focus()):y.key==="F2"&&(y.preventDefault(),c({id:e[x].id,name:e[x].name}))},g=e.findIndex(y=>y.id===n),w=e[g];return C.jsxs("div",{"data-cells-sheet-tabs":"",style:{display:"flex",alignItems:"center",gap:4,padding:4},children:[C.jsx("div",{role:"tablist","aria-label":t["aria-label"]??"Sheets",style:{display:"flex",gap:2},children:e.map((y,x)=>{const $=y.id===n;return C.jsx("button",{ref:A=>{d.current.set(y.id,A)},role:"tab",type:"button","aria-selected":$,tabIndex:$?0:-1,onClick:()=>a(y.id),onDoubleClick:()=>c({id:y.id,name:y.name}),onKeyDown:A=>m(A,x),style:{padding:"2px 10px",border:"1px solid var(--borderColor-muted, #d0d7de)",borderBottom:$?"2px solid var(--borderColor-accent-emphasis, #0969da)":void 0,background:$?"var(--bgColor-default, #fff)":"var(--bgColor-muted, #f6f8fa)",color:"var(--fgColor-default, #1f2328)",fontWeight:$?600:400,cursor:"pointer"},children:y.name},y.id)})}),l!==null&&C.jsx(fa,{"aria-label":`Rename ${e.find(y=>y.id===l.id)?.name??""}`,size:"small",autoFocus:!0,value:l.name,onChange:y=>c({id:l.id,name:y.target.value}),onBlur:f,onKeyDown:y=>{y.key==="Enter"?(y.preventDefault(),f()):y.key==="Escape"&&(c(null),h(""))}}),C.jsx(ds,{icon:da,"aria-label":"Add a sheet",size:"small",variant:"invisible",onClick:()=>{const y=o();y.ok||h(y.refusals.map(x=>x.message).join(" "))}}),w!==void 0&&C.jsxs(Uo,{children:[C.jsx(Uo.Anchor,{children:C.jsx(ds,{icon:ma,"aria-label":`More for ${w.name}`,size:"small",variant:"invisible"})}),C.jsx(Uo.Overlay,{children:C.jsxs(Be,{children:[C.jsx(Be.Item,{onSelect:()=>c({id:w.id,name:w.name}),children:"Rename"}),C.jsx(Be.Item,{disabled:g===0,onSelect:()=>s(w.id,g-1),children:"Move left"}),C.jsx(Be.Item,{disabled:g===e.length-1,onSelect:()=>s(w.id,g+1),children:"Move right"}),C.jsx(Be.Divider,{}),C.jsx(Be.Item,{variant:"danger",disabled:e.length===1,onSelect:()=>{const y=i(w.id);y.ok||h(y.refusals.map(x=>x.message).join(" "))},children:"Delete"})]})})]}),u&&C.jsx("span",{role:"alert",style:{color:"var(--fgColor-danger, #d1242f)"},children:u})]})}export{Hi as A,lm as B,po as C,jr as D,Br as E,dm as S,cm as a,um as b,Ye as c,Bf as d,_f as e,hm as f,fm as g,am as h,j as i,Pf as j,gm as k,If as l,mm as m,Jt as n,qi as o,Cn as p,Wr as q,Li as r,hc as s,Or as t,yt as u,Yh as v,fr as w,Yi as x,dr as y,Oe as z};
@@ -1 +1 @@
1
- import{bK as He,bM as Ze,fc as qe,fd as Ke,r as ce,j as U,T as $e,B as he,v as Ye,f6 as Je,fe as Qe,ff as et}from"../datalayer-app-main.js";import{o as tt,t as nt,p as rt,B as be,q as st,r as fe,z as se,s as it,v as ot,w as lt,x as at,y as ft,A as dt,j as ct,S as ut,k as ht,l as gt,m as pt}from"./SheetTabs-BLaEhX0D.js";import"./KebabHorizontalIcon-D6AY8pIS.js";var z=Uint8Array,re=Uint16Array,mt=Int32Array,ze=new z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Pe=new z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),wt=new z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),je=function(e,t){for(var s=new re(31),n=0;n<31;++n)s[n]=t+=1<<e[n-1];for(var r=new mt(s[30]),n=1;n<30;++n)for(var o=s[n];o<s[n+1];++o)r[o]=o-s[n]<<5|n;return{b:s,r}},Le=je(ze,2),_e=Le.b,vt=Le.r;_e[28]=258,vt[258]=28;var xt=je(Pe,0),bt=xt.b,ye=new re(32768);for(var T=0;T<32768;++T){var q=(T&43690)>>1|(T&21845)<<1;q=(q&52428)>>2|(q&13107)<<2,q=(q&61680)>>4|(q&3855)<<4,ye[T]=((q&65280)>>8|(q&255)<<8)>>1}var ie=(function(e,t,s){for(var n=e.length,r=0,o=new re(t);r<n;++r)e[r]&&++o[e[r]-1];var l=new re(t);for(r=1;r<t;++r)l[r]=l[r-1]+o[r-1]<<1;var f;if(s){f=new re(1<<t);var g=15-t;for(r=0;r<n;++r)if(e[r])for(var u=r<<4|e[r],p=t-e[r],i=l[e[r]-1]++<<p,c=i|(1<<p)-1;i<=c;++i)f[ye[i]>>g]=u}else for(f=new re(n),r=0;r<n;++r)e[r]&&(f[r]=ye[l[e[r]-1]++]>>15-e[r]);return f}),le=new z(288);for(var T=0;T<144;++T)le[T]=8;for(var T=144;T<256;++T)le[T]=9;for(var T=256;T<280;++T)le[T]=7;for(var T=280;T<288;++T)le[T]=8;var Be=new z(32);for(var T=0;T<32;++T)Be[T]=5;var yt=ie(le,9,1),Ct=ie(Be,5,1),ge=function(e){for(var t=e[0],s=1;s<e.length;++s)e[s]>t&&(t=e[s]);return t},j=function(e,t,s){var n=t/8|0;return(e[n]|e[n+1]<<8)>>(t&7)&s},pe=function(e,t){var s=t/8|0;return(e[s]|e[s+1]<<8|e[s+2]<<16)>>(t&7)},St=function(e){return(e+7)/8|0},Se=function(e,t,s){return(t==null||t<0)&&(t=0),(s==null||s>e.length)&&(s=e.length),new z(e.subarray(t,s))},At=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],O=function(e,t,s){var n=new Error(t||At[e]);if(n.code=e,Error.captureStackTrace&&Error.captureStackTrace(n,O),!s)throw n;return n},kt=function(e,t,s,n){var r=e.length,o=n?n.length:0;if(!r||t.f&&!t.l)return s||new z(0);var l=!s,f=l||t.i!=2,g=t.i;l&&(s=new z(r*3));var u=function(Ae){var ke=s.length;if(Ae>ke){var Te=new z(Math.max(ke*2,Ae));Te.set(s),s=Te}},p=t.f||0,i=t.p||0,c=t.b||0,v=t.l,b=t.d,d=t.m,a=t.n,w=r*8;do{if(!v){p=j(e,i,1);var x=j(e,i+1,3);if(i+=3,x)if(x==1)v=yt,b=Ct,d=9,a=5;else if(x==2){var N=j(e,i,31)+257,L=j(e,i+10,15)+4,X=N+j(e,i+5,31)+1;i+=14;for(var _=new z(X),H=new z(19),h=0;h<L;++h)H[wt[h]]=j(e,i+h*3,7);i+=L*3;for(var k=ge(H),C=(1<<k)-1,m=ie(H,k,1),h=0;h<X;){var E=m[j(e,i,C)];i+=E&15;var y=E>>4;if(y<16)_[h++]=y;else{var R=0,S=0;for(y==16?(S=3+j(e,i,3),i+=2,R=_[h-1]):y==17?(S=3+j(e,i,7),i+=3):y==18&&(S=11+j(e,i,127),i+=7);S--;)_[h++]=R}}var M=_.subarray(0,N),I=_.subarray(N);d=ge(M),a=ge(I),v=ie(M,d,1),b=ie(I,a,1)}else O(1);else{var y=St(i)+4,$=e[y-4]|e[y-3]<<8,A=y+$;if(A>r){g&&O(0);break}f&&u(c+$),s.set(e.subarray(y,A),c),t.b=c+=$,t.p=i=A*8,t.f=p;continue}if(i>w){g&&O(0);break}}f&&u(c+131072);for(var D=(1<<d)-1,B=(1<<a)-1,K=i;;K=i){var R=v[pe(e,i)&D],G=R>>4;if(i+=R&15,i>w){g&&O(0);break}if(R||O(2),G<256)s[c++]=G;else if(G==256){K=i,v=null;break}else{var Q=G-254;if(G>264){var h=G-257,Z=ze[h];Q=j(e,i,(1<<Z)-1)+_e[h],i+=Z}var ee=b[pe(e,i)&B],Y=ee>>4;ee||O(3),i+=ee&15;var I=bt[Y];if(Y>3){var Z=Pe[Y];I+=pe(e,i)&(1<<Z)-1,i+=Z}if(i>w){g&&O(0);break}f&&u(c+131072);var te=c+Q;if(c<I){var ae=o-I,Ve=Math.min(I,te);for(ae+c<0&&O(3);c<Ve;++c)s[c]=n[ae+c]}for(;c<te;++c)s[c]=s[c-I]}}t.l=v,t.p=K,t.b=c,t.f=p,v&&(p=1,t.m=d,t.d=b,t.n=a)}while(!p);return c!=s.length&&l?Se(s,0,c):s.subarray(0,c)},Tt=new z(0),F=function(e,t){return e[t]|e[t+1]<<8},P=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},me=function(e,t){return P(e,t)+P(e,t+4)*4294967296};function $t(e,t){return kt(e,{i:2},t&&t.out,t&&t.dictionary)}var Ce=typeof TextDecoder<"u"&&new TextDecoder,Rt=0;try{Ce.decode(Tt,{stream:!0}),Rt=1}catch{}var Dt=function(e){for(var t="",s=0;;){var n=e[s++],r=(n>127)+(n>223)+(n>239);if(s+r>e.length)return{s:t,r:Se(e,s-1)};r?r==3?(n=((n&15)<<18|(e[s++]&63)<<12|(e[s++]&63)<<6|e[s++]&63)-65536,t+=String.fromCharCode(55296|n>>10,56320|n&1023)):r&1?t+=String.fromCharCode((n&31)<<6|e[s++]&63):t+=String.fromCharCode((n&15)<<12|(e[s++]&63)<<6|e[s++]&63):t+=String.fromCharCode(n)}};function Fe(e,t){if(t){for(var s="",n=0;n<e.length;n+=16384)s+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return s}else{if(Ce)return Ce.decode(e);var r=Dt(e),o=r.s,s=r.r;return s.length&&O(8),o}}var Et=function(e,t){return t+30+F(e,t+26)+F(e,t+28)},Mt=function(e,t,s){var n=F(e,t+28),r=F(e,t+30),o=Fe(e.subarray(t+46,t+46+n),!(F(e,t+8)&2048)),l=t+46+n,f=It(e,l,r,s,P(e,t+20),P(e,t+24),P(e,t+42)),g=f[0],u=f[1],p=f[2];return[F(e,t+10),g,u,o,l+r+F(e,t+32),p]},It=function(e,t,s,n,r,o,l){var f=r==4294967295,g=o==4294967295,u=l==4294967295,p=t+s,i=f+g+u;if(n&&i){for(;t+4<p;t+=4+F(e,t+2))if(F(e,t)==1)return[f?me(e,t+4+8*g):r,g?me(e,t+4):o,u?me(e,t+4+8*(g+f)):l,1];n<2&&O(13)}return[r,o,l,0]};function Nt(e,t){for(var s={},n=e.length-22;P(e,n)!=101010256;--n)(!n||e.length-n>65558)&&O(13);var r=F(e,n+8);if(!r)return{};var o=P(e,n+16),l=P(e,n-20)==117853008;if(l){var f=P(e,n-12);l=P(e,f)==101075792,l&&(r=P(e,f+32),o=P(e,f+48))}for(var g=0;g<r;++g){var u=Mt(e,o,l),p=u[0],i=u[1],c=u[2],v=u[3],b=u[4],d=u[5],a=Et(e,d);o=b,p?p==8?s[v]=$t(e.subarray(a,a+i),{out:new z(c)}):O(14,"unknown compression type "+p):s[v]=Se(e,a,a+i)}return s}const Ot={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yyyy",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/yyyy h:mm",37:"#,##0 ;(#,##0)",38:"#,##0 ;[Red](#,##0)",39:"#,##0.00;(#,##0.00)",40:"#,##0.00;[Red](#,##0.00)",45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@"},Re=/<(\/?)([A-Za-z_][\w:.-]*)((?:\s+[^\s=>/]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>|<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!\[CDATA\[([\s\S]*?)\]\]>|<![^>]*>|([^<]+)/g,De=/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,zt={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function oe(e){return e.includes("&")?e.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-z]+);/g,(t,s)=>{if(s[0]==="#"){const n=s[1]==="x"?parseInt(s.slice(2),16):parseInt(s.slice(1),10);return String.fromCodePoint(n)}return zt[s]??t}):e}const We=e=>{const t=e.indexOf(":");return t<0?e:e.slice(t+1)};function Pt(e){const t={};if(e==="")return t;De.lastIndex=0;let s;for(;(s=De.exec(e))!==null;)t[We(s[1])]=oe(s[2]??s[3]??"");return t}function V(e,t){Re.lastIndex=0;let s;for(;(s=Re.exec(e))!==null;)if(s[2]!==void 0){const n=We(s[2]);if(s[1]==="/")t.close?.(n);else{const r=s[4]==="/";t.open?.(n,Pt(s[3]),r),r&&t.close?.(n)}}else s[5]!==void 0?t.text?.(s[5]):s[6]!==void 0&&t.text?.(oe(s[6]))}const jt=9525,ne=e=>Math.round(Number(e??0)/jt);function Lt(e){const t=e.join("");return t===""?void 0:t}const Ee=new Set(["barChart","bar3DChart","lineChart","line3DChart","areaChart","area3DChart","pieChart","pie3DChart","doughnutChart","ofPieChart","scatterChart","radarChart","bubbleChart","stockChart","surfaceChart","surface3DChart"]),Xe=new Set(["barChart","bar3DChart","lineChart","line3DChart","areaChart","area3DChart","pieChart","pie3DChart","doughnutChart","scatterChart"]);function _t(e){const t={autoTitleDeleted:!1,groups:[],axes:[],pivot:!1,undrawn:[]},s=[];let n,r,o,l,f,g="",u=0;const p=i=>s.includes(i);return V(e,{open(i,c){if(s.push(i),Ee.has(i)&&p("plotArea")){n={element:i,series:[],axIds:[]},t.groups.push(n),Xe.has(i)||t.undrawn.push(i);return}if(i==="pivotSource"&&(t.pivot=!0),i==="autoTitleDeleted"&&(t.autoTitleDeleted=c.val==="1"||c.val==="true"),i==="legendPos"&&(t.legend=c.val),i==="dispBlanksAs"&&(t.dispBlanksAs=c.val),i==="title"&&!p("ser")){u+=1,l=[],f=o!==void 0&&p(o.element)?"axisTitle":"title";return}if(n!==void 0&&!p("ser")&&(i==="barDir"?n.barDir=c.val:i==="grouping"?n.grouping=c.val:i==="holeSize"?n.holeSize=!0:i==="axId"?n.axIds.push(c.val):i==="showVal"&&p("dLbls")&&(n.showVal=c.val==="1"||c.val==="true")),i==="ser"&&n!==void 0){r={idx:1e9,literal:!1,dPt:0,trendline:0,errBars:0,external:!1},n.series.push(r);return}if(r!==void 0&&(i==="idx"&&!p("dPt")&&!p("dLbl")?r.idx=Number(c.val):i==="tx"?f="name":i==="val"||i==="yVal"?f="values":i==="cat"?f="categories":i==="xVal"?f="x":i==="f"?g="":i==="numLit"||i==="strLit"?r.literal=!0:i==="dPt"&&n!==void 0&&!n.element.startsWith("pie")&&n.element!=="doughnutChart"?r.dPt+=1:i==="trendline"?r.trendline+=1:i==="errBars"?r.errBars+=1:i==="smooth"?r.smooth=c.val!=="0"&&c.val!=="false":i==="srgbClr"&&p("spPr")&&p("solidFill")&&!p("dPt")&&r.color===void 0?r.color=`#${c.val.toLowerCase()}`:i==="v"&&f==="name"&&p("tx")&&!p("strRef")&&(l=[])),(i==="catAx"||i==="valAx"||i==="dateAx"||i==="serAx")&&p("plotArea")){o={element:i,id:"",gridlines:!1,deleted:!1},t.axes.push(o);return}o!==void 0&&p(o.element)&&(i==="axId"?o.id=c.val:i==="min"?o.min=Number(c.val):i==="max"?o.max=Number(c.val):i==="logBase"?o.log=!0:i==="majorGridlines"?o.gridlines=!0:i==="numFmt"&&c.formatCode!==void 0&&c.formatCode!=="General"&&c.sourceLinked!=="1"&&c.sourceLinked!=="true"?o.format=c.formatCode:i==="delete"&&(o.deleted=c.val==="1"||c.val==="true"))},text(i){p("f")?g+=i:l!==void 0&&(p("t")||p("v")&&f==="name")&&l.push(i)},close(i){if(s.pop(),i==="f"&&r!==void 0&&f!==void 0&&f!=="title"&&f!=="axisTitle"){const c=g.trim();/^\[/.test(c)||/'\[/.test(c)?r.external=!0:r[f]=c}if(i==="v"&&r!==void 0&&f==="name"&&l!==void 0&&!p("strRef")&&(r.name=l.join(""),l=void 0),(i==="tx"||i==="val"||i==="yVal"||i==="cat"||i==="xVal")&&r!==void 0&&(f=void 0),i==="title"&&u>0){u-=1;const c=Lt(l??[]);f==="axisTitle"&&o!==void 0?o.title=c:f==="title"&&(t.title=c),l=void 0,f=void 0}i==="ser"&&(r=void 0),Ee.has(i)&&(n=void 0),(i==="catAx"||i==="valAx"||i==="dateAx"||i==="serAx")&&(o=void 0)}}),t}const Bt={t:"top",r:"right",b:"bottom",l:"left",tr:"right"},we=e=>e;function Ft(e,t,s,n,r){const o=`${n}: chart '${t}'`;if(e.pivot){r.push(`${o}: a pivot chart was not imported.`);return}for(const h of e.undrawn)r.push(`${o}: a ${h.replace(/Chart$/,"")} chart was not imported.`);const l=e.groups.filter(h=>Xe.has(h.element));if(l.length===0){e.undrawn.length===0&&r.push(`${o}: no chart that Cells draws.`);return}const f=l.filter(h=>h.element.includes("3D")),g=h=>{switch(h.element){case"barChart":case"bar3DChart":return h.barDir==="bar"?"bar":"column";case"lineChart":case"line3DChart":return"line";case"areaChart":case"area3DChart":return"area";case"pieChart":case"pie3DChart":case"doughnutChart":return"pie";default:return"scatter"}},u=e.axes.filter(h=>h.element==="valAx"),p=u[0],c=l.every(h=>h.element==="scatterChart")?void 0:u.find(h=>h!==p&&l.some(k=>k.axIds.includes(h.id))),v=e.axes.find(h=>h.element==="catAx"||h.element==="dateAx"||h.element==="valAx"&&l.every(k=>k.element==="scatterChart")&&h===p),b=l.length>1;let d=b?"combo":g(l[0]);if(b&&l.some(h=>h.element.startsWith("pie")||h.element==="doughnutChart"||h.element==="scatterChart")){d=g(l[0]);for(const h of l.slice(1))r.push(`${o}: a second plot (${h.element.replace(/Chart$/,"")}) beside a ${d} chart was not imported.`);l.length=1}f.length>0&&r.push(`${o}: a 3-D chart was imported as a ${d} chart.`);let a;const w=l[0];w.element==="doughnutChart"?a="doughnut":w.grouping==="stacked"?a="stacked":w.grouping==="percentStacked"?a="percent":(w.element==="lineChart"||w.element==="line3DChart")&&w.series.some(h=>h.smooth)&&(a="smooth");const x=[],y=[],$=[];for(const h of l){const k=g(h),C=c!==void 0&&h.axIds.includes(c.id);for(const m of h.series){if(m.values===void 0){y.push(m.external?"a series naming another workbook":m.literal?"a series given as literals":"a series without values");continue}m.literal&&r.push(`${o}: literal categories or names of a series were left out.`),m.dPt>0&&r.push(`${o}: ${m.dPt} per-point colour(s) were left out.`),m.trendline>0&&r.push(`${o}: ${m.trendline} trendline(s) were left out.`),m.errBars>0&&r.push(`${o}: error bars were left out.`),$.push([m.idx,{values:we(m.values),...m.name!==void 0?{name:m.name}:{},...m.categories!==void 0?{categories:we(m.categories)}:{},...m.x!==void 0?{x:we(m.x)}:{},...b?{type:k==="column"||k==="bar"?"column":k==="area"?"area":"line"}:{},...C?{axis:"secondary"}:{},...m.color!==void 0?{color:m.color}:{}}])}}$.sort((h,k)=>h[0]-k[0]);for(const[,h]of $)x.push(h);for(const h of y)r.push(`${o}: ${h} was not imported.`);if(x.length===0){r.push(`${o}: no series to draw.`);return}const A=h=>{if(h===void 0)return;const k=h.element==="valAx",C={...h.title!==void 0?{title:h.title}:{},...h.min!==void 0?{min:h.min}:{},...h.max!==void 0?{max:h.max}:{},...h.format!==void 0?{format:h.format}:{},...h.log?{log:!0}:{},...k&&!h.gridlines?{gridlines:!1}:{},...!k&&h.gridlines?{gridlines:!0}:{}};return Object.keys(C).length===0?void 0:C},N=A(v),L=A(d==="scatter"?u[1]??p:p),X=A(c),_=N!==void 0||L!==void 0||X!==void 0?{...N!==void 0?{x:N}:{},...L!==void 0?{y:L}:{},...X!==void 0?{y2:X}:{}}:void 0,H=x.length>1&&x.every(h=>{const k=/\$?([A-Z]+)\$?(\d+):\$?([A-Z]+)\$?(\d+)$/.exec(h.values);return k!==null&&k[2]===k[4]&&k[1]!==k[3]});return{id:t,type:d,...a!==void 0?{variant:a}:{},anchor:s,data:{series:x,by:H?"rows":"columns",headers:{row:x.some(h=>h.name!==void 0),column:x.some(h=>h.categories!==void 0)},blanks:e.dispBlanksAs==="zero"?"zero":e.dispBlanksAs==="span"?"connect":"gap"},...e.title!==void 0?{title:e.title}:{},legend:e.legend!==void 0?Bt[e.legend]??"bottom":"none",..._!==void 0?{axes:_}:{},...l.some(h=>h.showVal)?{labels:!0}:{}}}function Wt(e){const t=[];let s,n,r,o,l,f,g,u=!1,p,i={col:0,colOff:0,row:0,rowOff:0},c,v="";const b=()=>{if(s===void 0)return;let d;s==="twoCellAnchor"&&n!==void 0&&r!==void 0?d={kind:"cells",from:n,to:r}:s==="oneCellAnchor"&&n!==void 0&&l!==void 0?d={kind:"cell",from:n,width:Math.max(1,l.width),height:Math.max(1,l.height)}:s==="absoluteAnchor"&&o!==void 0&&l!==void 0&&(d={kind:"absolute",...o,width:Math.max(1,l.width),height:Math.max(1,l.height)}),d!==void 0&&t.push({anchor:d,chart:f,chartEx:g,picture:u}),s=void 0,n=r=o=l=f=g=void 0,u=!1};return V(e,{open(d,a){d==="twoCellAnchor"||d==="oneCellAnchor"||d==="absoluteAnchor"?s=d:d==="from"||d==="to"?(p=d,i={col:0,colOff:0,row:0,rowOff:0}):d==="col"||d==="colOff"||d==="row"||d==="rowOff"?(c=d,v=""):d==="pos"?o={x:ne(a.x),y:ne(a.y)}:d==="ext"&&s!==void 0&&a.cx!==void 0&&l===void 0?l={width:ne(a.cx),height:ne(a.cy)}:d==="chart"?(f===void 0&&(f=a.id),a.id===void 0&&(f=f??"missing")):d==="pic"&&(u=!0)},text(d){c!==void 0&&(v+=d)},close(d){if(d==="col"||d==="colOff"||d==="row"||d==="rowOff")i[d]=Number(v.trim()),c=void 0;else if(d==="from"||d==="to"){const a={row:i.row,col:i.col,dx:ne(String(i.colOff)),dy:ne(String(i.rowOff))};p==="from"?n=a:r=a,p=void 0}else(d==="twoCellAnchor"||d==="oneCellAnchor"||d==="absoluteAnchor")&&b()}}),t}function Me(e){const t=new Map;return e===void 0||V(e,{open(s,n){s==="Relationship"&&n.Id!==void 0&&n.Target!==void 0&&t.set(n.Id,{target:n.Target,type:n.Type??""})}}),t}function ve(e,t){if(t.startsWith("/"))return t.slice(1);const s=e.split("/").slice(0,-1);for(const n of t.split("/"))n===".."?s.pop():n!=="."&&s.push(n);return s.join("/")}function Xt(e,t,s,n,r){const o={},l=t.split("/").slice(0,-1).join("/"),f=t.split("/").pop(),u=Me(e(`${l}/_rels/${f}.rels`)).get(s);if(u===void 0)return r.push(`${n}: the drawing part is missing.`),o;const p=ve(t,u.target),i=e(p);if(i===void 0)return r.push(`${n}: the drawing part ${p} is missing.`),o;const c=p.split("/").slice(0,-1).join("/"),v=p.split("/").pop(),b=Me(e(`${c}/_rels/${v}.rels`));let d=0;for(const a of Wt(i)){if(a.chart===void 0)continue;const w=b.get(a.chart);if(w===void 0){r.push(`${n}: a chart's part is missing (${a.chart}).`);continue}d+=1;const x=`chart${d}`;if(/chartEx/i.test(w.type)||/chartEx/.test(w.target)){const A=e(ve(p,w.target))??"",N=/<cx:layoutId val="([^"]+)"/.exec(A)?.[1]??"unknown";r.push(`${n}: chart '${x}': an Excel 2016 chart (${N}) was not imported.`);continue}const y=e(ve(p,w.target));if(y===void 0){r.push(`${n}: chart '${x}': its part ${w.target} is missing.`);continue}const $=Ft(_t(y),x,a.anchor,n,r);$!==void 0&&(o[x]=$)}return o}const Ge="customXml/cells-code.xml";function Gt(e){let t=0;for(const s of e)t=t*26+(s.charCodeAt(0)-64);return t-1}function ue(e){const t=/^\$?([A-Z]{1,3})\$?([0-9]+)$/.exec(e);if(t===null)throw new Error(`'${e}' is not a cell reference.`);return{row:Number(t[2])-1,col:Gt(t[1])}}function Ut(e){const[t,s=t]=e.split(":"),n=ue(t),r=ue(s);return{top:Math.min(n.row,r.row),left:Math.min(n.col,r.col),bottom:Math.max(n.row,r.row),right:Math.max(n.col,r.col)}}function xe(e){const t=e?.rgb;if(!(t===void 0||!/^[0-9A-Fa-f]{6,8}$/.test(t)))return`#${t.slice(-6).toLowerCase()}`}const Vt={thin:"thin",hair:"thin",medium:"medium",thick:"thick",dashed:"dashed",mediumDashed:"dashed",dashDot:"dashed",mediumDashDot:"dashed",dashDotDot:"dotted",mediumDashDotDot:"dotted",slantDashDot:"dashed",dotted:"dotted",double:"double"};function Ht(e){if(e===void 0)return[{}];const t=new Map,s=[],n=[],r=[],o=[],l=new Map;let f="",g,u,p,i,c,v;V(e,{open(d,a){switch(d){case"numFmts":case"fonts":case"fills":case"borders":case"cellXfs":case"cellStyleXfs":case"dxfs":f=d;return;case"numFmt":f==="numFmts"&&t.set(Number(a.numFmtId),a.formatCode??"General");return}if(f==="fonts")d==="font"?g={}:g!==void 0&&(d==="b"?g.bold=a.val!=="0"&&a.val!=="false":d==="i"?g.italic=a.val!=="0"&&a.val!=="false":d==="u"?g.underline=a.val!=="none":d==="strike"?g.strike=a.val!=="0"&&a.val!=="false":d==="sz"?g.size=Number(a.val):d==="color"?g.color=xe(a):d==="name"&&(g.font=a.val));else if(f==="fills")d==="fill"?u={}:d==="patternFill"&&u?u.pattern=a.patternType:d==="fgColor"&&u&&(u.color=xe(a));else if(f==="borders")d==="border"?p={}:p!==void 0&&["left","right","top","bottom"].includes(d)?i={name:d,style:a.style===void 0?void 0:Vt[a.style]}:d==="color"&&i!==void 0&&i.style!==void 0&&(p[i.name]={style:i.style,color:xe(a)??"#000000"});else if(f==="cellXfs"){if(d==="xf"){const w=Number(a.numFmtId??0),x=s[Number(a.fontId??0)]??{};v=x;const y=n[Number(a.fillId??0)],$=r[Number(a.borderId??0)],A=w===0?void 0:(t.get(w)??Ot[w])?.replace(/^\[\$-(409|en-US)\]/,"");c={...x.bold?{bold:!0}:{},...x.italic?{italic:!0}:{},...x.underline?{underline:!0}:{},...x.strike?{strike:!0}:{},...x.color!==void 0&&x.color!=="#000000"?{color:x.color}:{},...y!==void 0?{fill:y}:{},...$!==void 0&&Object.keys($).length>0?{borders:$}:{},...A!==void 0&&A!=="General"?{format:A}:{}}}else if(d==="alignment"&&c!==void 0){const w=a.horizontal,x=a.vertical;c={...c,...w==="left"||w==="center"||w==="right"?{align:w}:{},...x==="top"?{valign:"top"}:x==="center"?{valign:"middle"}:{},...a.wrapText==="1"||a.wrapText==="true"?{wrap:!0}:{}}}}},close(d){d===f?f="":d==="font"&&g!==void 0?(s.push(g),g=void 0):d==="fill"&&u!==void 0?(n.push(u.pattern==="solid"?u.color:void 0),u=void 0):d==="border"&&p!==void 0?(r.push(p),p=void 0):["left","right","top","bottom"].includes(d)?i=void 0:d==="xf"&&c!==void 0&&f==="cellXfs"&&(o.push(c),v!==void 0&&l.set(c,v),c=void 0)}});const b=s[0]??{};return o.map((d,a)=>{if(a===0)return{};const w=l.get(d);return w===void 0?d:{...d,...w.size!==void 0&&w.size!==b.size?{size:w.size}:{},...w.font!==void 0&&w.font!==b.font?{font:w.font}:{}}})}function Zt(e){const t=[];if(e===void 0)return t;let s,n=!1,r=!1;return V(e,{open(o){o==="si"?s="":o==="t"?n=!r:o==="rPh"&&(r=!0)},close(o){o==="si"?(t.push(s??""),s=void 0):o==="t"?n=!1:o==="rPh"&&(r=!1)},text(o){n&&s!==void 0&&(s+=o)}}),t}const qt=e=>Math.round(e*7+5),Ie=e=>Math.round(e*4/3);function Kt(e,t,s){const n={},r={},o={},l=[],f=[],g=[];let u,p;const i=new Map;let c=0,v=0,b,d="n",a=0,w,x,y,$="",A,N=0,L=0;const X=(C,m,E,R,S,M,I)=>{const D={};if(M?.t==="shared"&&M.si!==void 0)if(S!==void 0&&S!=="")i.set(M.si,{formula:S,...C});else{const B=i.get(M.si);B!==void 0&&(S=nt(B.formula,C.row-B.row,C.col-B.col))}else M?.t==="array"&&s.set("array formula",(s.get("array formula")??0)+1);if(S!==void 0&&S!==""&&(D.f=S,v+=1),m==="s"&&R!==void 0?D.v=t[Number(R)]??"":m==="b"&&R!==void 0?D.v=R==="1":m==="e"&&R!==void 0?D.v=rt(R)?{error:R}:{error:"#VALUE!"}:(m==="str"||m==="inlineStr")&&(R!==void 0||I!=="")?D.v=m==="inlineStr"?I:R??"":R!==void 0&&R!==""&&(D.v=Number(R)),E!==0&&(D.s=E),D.v!==void 0||D.f!==void 0||D.s!==void 0){const B=String(C.row);(n[B]??={cells:{}}).cells[String(C.col)]=D,c+=1}},_=C=>{const m=/<(?:\w+:)?row\s([^>]*?)\/?>/g;let E;for(;(E=m.exec(C))!==null;){const S=E[1],M=/\br="(\d+)"/.exec(S);if(M===null)continue;const I=Number(M[1])-1,D=/\bht="([^"]+)"/.exec(S);D!==null&&/\bcustomHeight="(1|true)"/.test(S)&&(r[String(I)]=Ie(Number(D[1]))),/\bhidden="(1|true)"/.test(S)&&l.push(I)}const R=/<(?:\w+:)?c\s([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?c>)/g;for(;(E=R.exec(C))!==null;){const S=E[1],M=E[2]??"",I=ue(/\br="([^"]+)"/.exec(S)[1]),D=/\bt="([^"]+)"/.exec(S)?.[1]??"n",B=Number(/\bs="(\d+)"/.exec(S)?.[1]??0);let K,G,Q,Z="";if(M!==""){const ee=/<(?:\w+:)?v>([\s\S]*?)<\/(?:\w+:)?v>/.exec(M);ee!==null?K=oe(ee[1]):/<(?:\w+:)?v\/>/.test(M)&&(K="");const Y=/<(?:\w+:)?f\b([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?f>)/.exec(M);if(Y!==null){Q={};for(const[,te,ae]of Y[1].matchAll(/(\w+)="([^"]*)"/g))Q[te]=ae;G=oe(Y[2]??"")}if(D==="inlineStr")for(const[,te]of M.matchAll(/<(?:\w+:)?t(?:\s[^>]*)?>([\s\S]*?)<\/(?:\w+:)?t>/g))Z+=oe(te)}X(I,D,B,K,G,Q,Z)}};let H=e;const h=/<(?:\w+:)?sheetData\b[^>]*>/.exec(e),k=h===null?-1:e.search(/<\/(?:\w+:)?sheetData>/);return h!==null&&k>h.index&&!/<(?:\w+:)?c(?=[\s>/])(?![^>]*\sr=)/.test(e)&&(_(e.slice(h.index+h[0].length,k)),H=e.slice(0,h.index)+e.slice(k)),V(H,{open(C,m){switch(C){case"row":{const E=m.r===void 0?N:Number(m.r)-1;N=E+1,L=0,m.ht!==void 0&&(m.customHeight==="1"||m.customHeight==="true")&&(r[String(E)]=Ie(Number(m.ht))),(m.hidden==="1"||m.hidden==="true")&&l.push(E);return}case"c":{b=m.r===void 0?{row:N-1,col:L}:ue(m.r),L=b.col+1,d=m.t??"n",a=Number(m.s??0),w=void 0,x=void 0,y=void 0,$="";return}case"v":A="v",w="";return;case"f":A="f",x="",y=m;return;case"is":A="is";return;case"col":{const E=Number(m.min)-1,R=Math.min(Number(m.max)-1,16383);for(let S=E;S<=R;S+=1)m.width!==void 0&&(m.customWidth==="1"||m.customWidth==="true")&&(o[String(S)]=qt(Number(m.width))),(m.hidden==="1"||m.hidden==="true")&&f.push(S);return}case"mergeCell":m.ref!==void 0&&g.push(Ut(m.ref));return;case"pane":(m.state==="frozen"||m.state==="frozenSplit")&&(u={rows:Number(m.ySplit??0),cols:Number(m.xSplit??0)});return;case"drawing":p=m.id;return;case"conditionalFormatting":case"dataValidation":case"hyperlink":case"legacyDrawing":case"tablePart":case"sheetProtection":case"autoFilter":s.set(C,(s.get(C)??0)+1);return}},text(C){A==="v"?w+=C:A==="f"?x+=C:A==="is"&&($+=C)},close(C){if(C==="v"||C==="f"||C==="is"){A=void 0;return}C!=="c"||b===void 0||(X(b,d,a,w,x,y,$),b=void 0)}}),{sheet:{rows:n,...Object.keys(r).length+Object.keys(o).length>0?{sizes:{rows:r,cols:o}}:{},...l.length+f.length>0?{hidden:{rows:l,cols:f}}:{},...g.length>0?{merges:g}:{},...u!==void 0?{frozen:u}:{}},cells:c,formulas:v,...p!==void 0?{drawing:p}:{}}}function Yt(e){return e.startsWith("/")?e.slice(1):`xl/${e}`.replace(/\/[^/]+\/\.\.\//g,"/")}function Jt(e){let t;try{t=Nt(e)}catch(a){throw new Error(`The file is not an XLSX package: ${a.message}`)}const s=a=>t[a]===void 0?void 0:Fe(t[a]),n=s("xl/workbook.xml");if(n===void 0)throw new Error("The package has no xl/workbook.xml.");const r=new Map;V(s("xl/_rels/workbook.xml.rels")??"",{open(a,w){a==="Relationship"&&w.Id!==void 0&&w.Target!==void 0&&r.set(w.Id,Yt(w.Target))}});const o=[],l=new Map;V(n,{open(a,w){if(a==="sheet"){const x=r.get(w.id);if(x===void 0)throw new Error(`The sheet '${w.name}' has no part.`);o.push({name:w.name,path:x,hidden:w.state==="hidden"||w.state==="veryHidden"})}else a==="definedName"&&l.set("defined name",(l.get("defined name")??0)+1)}});const f=Zt(s("xl/sharedStrings.xml")),g=Ht(s("xl/styles.xml"));let u=0,p=0,i=0;const c=[],v=new Set,b=o.map((a,w)=>{const x=s(a.path);if(x===void 0)throw new Error(`The sheet '${a.name}' has no ${a.path}.`);a.hidden&&l.set("hidden sheet (shown)",(l.get("hidden sheet (shown)")??0)+1);const y=Kt(x,f,l);u+=y.cells,p+=y.formulas;let $=`s${w+1}`;for(;v.has($);)$+="_";v.add($);const A=y.drawing===void 0?{}:Xt(s,a.path,y.drawing,a.name,c);return i+=Object.keys(A).length,{id:$,name:a.name,...y.sheet,...Object.keys(A).length>0?{charts:A}:{}}}),d=Qt(s(Ge),b);for(const a of Object.keys(t))/^xl\/chartsheets\/sheet\d+\.xml$/.test(a)?c.push(`${a}: a chart sheet was not imported.`):a.startsWith("xl/media/")?l.set("image",(l.get("image")??0)+1):/^xl\/comments\d*\.xml$/.test(a)||a.startsWith("xl/threadedComments/")?l.set("comments",(l.get("comments")??0)+1):a.startsWith("xl/pivotTables/")&&l.set("pivot table",(l.get("pivot table")??0)+1);for(const a of b)for(const w of Object.values(a.rows))for(const x of Object.values(w.cells))x.s!==void 0&&x.s>=g.length&&delete x.s;return{workbook:{version:1,sheets:b,styles:g.length>0?g:[{}]},report:{sheets:b.length,cells:u,formulas:p,skipped:[...l].map(([a,w])=>({feature:a,count:w})),chartsImported:i,charts:c,code:d}}}function Qt(e,t){if(e===void 0)return[];const s=new Map(t.map(g=>[g.name,g])),n=new Map;let r=0,o,l="",f=!1;V(e,{open(g,u){if(g==="cell"){const p=s.get(u.sheet??"");o=p===void 0?void 0:{sheet:p,ref:u.ref??"",attrs:u},l=""}else g==="source"&&(f=!0)},text(g){f&&(l+=g)},close(g){if(g==="source"&&(f=!1),g!=="cell"||o===void 0)return;const{sheet:u,ref:p,attrs:i}=o,c=/^([A-Z]{1,3})([1-9][0-9]*)$/.exec(p);if(c===null)return;let v=-1;for(const w of c[1])v=(v+1)*26+w.charCodeAt(0)-65;const b=u.rows[String(Number(c[2])-1)]?.cells[String(v)]?.v,d={source:l,language:"python",outputs:[],result:b===void 0?null:b,run:i.run==="auto"?"auto":"manual",...i.executionCount!==void 0?{executionCount:Number(i.executionCount)}:{},...i.lastRun!==void 0?{lastRun:i.lastRun}:{},...i.frame==="none"?{frame:null}:i.frameWidth!==void 0&&i.frameHeight!==void 0?{frame:{width:Number(i.frameWidth),height:Number(i.frameHeight),...i.frameDx!==void 0?{dx:Number(i.frameDx)}:{},...i.frameDy!==void 0?{dy:Number(i.frameDy)}:{}}}:{}};if(tt(d)!==void 0)return;let a=n.get(u);a===void 0&&n.set(u,a={}),a[p]=d,r+=1,o=void 0}});for(const[g,u]of n)g.code=u;return r===0?[]:[`${r} code cell${r===1?"":"s"} read from ${Ge}: the sources and the results, as cached values; the outputs are not in XLSX and were dropped.`]}function en(e,t){const s=e.sheet(t).cells;let n=0,r=0;for(const o of s.columnIndexes()){const l=s.lastRowIn(o);l>=0&&(n=Math.max(n,o),r=Math.max(r,l))}return{top:0,left:0,bottom:r,right:n}}const W={readRange:"cells.agent.readRange",writeRange:"cells.agent.writeRange",insertChart:"cells.agent.insertChart",listCharts:"cells.agent.listCharts",selectRange:"cells.agent.selectRange"},tn=2e3,de={type:"string",description:"A range in A1 notation on the sheet shown, such as `A1:D13`, or one cell such as `B3`."},Ne=Ke({id:"cells",version:"0.0.1",name:"Cells",description:"Read and write the spreadsheet on the person's screen, and chart it: the grid drawn by Datalayer Cells.",plugin:"@datalayer/cells",commands:[{name:"cells_read_range",command:W.readRange,description:"The values of a range of the spreadsheet shown, row by row. Without a range, the whole used range from A1, which is how to find where the data is: the answer names the sheet and the range read. Numbers are numbers, empty cells null.",parameters:{type:"object",properties:{range:de}}},{name:"cells_write_range",command:W.writeRange,description:"Write a block of values, row by row, from the top-left cell of a range. A text starting with = is a formula (=SUM(B2:B13)); numbers, booleans and null (an empty cell) are written as they are. One undo step.",parameters:{type:"object",properties:{range:{...de,description:"Where the block starts: its top-left cell, such as `E1`, or a range whose top-left cell it is."},values:{type:"array",description:"The rows to write, each an array of cells: number, string, boolean or null.",items:{type:"array",items:{type:["number","string","boolean","null"]}}}},required:["range","values"]}},{name:"cells_insert_chart",command:W.insertChart,description:"Insert a chart of a range into the spreadsheet shown, as the Insert chart button does: the series are read from the range (a first row of names and a first column of categories become the legend and the axis). It is drawn over the grid, beside the range unless `at` says where; the answer gives its id.",parameters:{type:"object",properties:{range:{...de,description:"The data to chart, headers included, such as `A1:D13`."},type:{type:"string",enum:[...be],description:"The chart type; column by default."},title:{type:"string",description:"The title drawn above the chart."},at:{type:"string",description:"The cell where the chart's top-left corner goes, such as `A15` (below the data) or `F1`."}},required:["range"]}},{name:"cells_list_charts",command:W.listCharts,description:"The charts of the sheet shown: id, type, title and the ranges each reads."},{name:"cells_select_range",command:W.selectRange,description:"Select a range of the spreadsheet shown, to show the person the cells meant.",parameters:{type:"object",properties:{range:de},required:["range"]}}]}),J=(e,t)=>{if(typeof e!="string"||e.trim()==="")throw new Error(`${t} is a non-empty string.`);return e},Oe=e=>{if(!e.ok)throw new Error(e.refusals.map(t=>t.message).join(" "))};function nn(e,t){const s=e.sheet(t).cells;let n=-1,r=-1;for(const o of s.columnIndexes()){const l=s.lastRowIn(o);l<0||(n=Math.max(n,o),r=Math.max(r,l))}return n<0?null:{top:0,left:0,bottom:r,right:n}}const rn=e=>e!==null&&typeof e=="object"?`#${e.error.replace(/^#/,"")}`:e,sn=e=>{if(e==null)return null;if(typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="string")return e.startsWith("=")?ft(e):e;throw new Error(`A cell is a number, a string, a boolean or null, not ${JSON.stringify(e)}.`)};function Ue(e={}){const t=n=>e.model?.()??st(n,void 0).model,s=(n,r,o)=>({id:n,name:r,category:"Cells",execute:l=>o(t(n),l??{})});return He({name:e.name??on,displayName:"Cells agent tools",description:"Read, write, chart and select the grid on screen, as tools an agent calls.",octicon:"table",commands:[s(W.readRange,"Read a range",(n,r)=>{const o=n.selection.sheet,l=r.range===void 0?nn(n,o):fe(J(r.range,"The range"));if(l===null)return{sheet:n.sheet(o).name,range:null,values:[]};const f=l.right-l.left+1,g=Math.max(1,Math.min(l.bottom-l.top+1,Math.floor(tn/f))),u={...l,bottom:l.top+g-1};return{sheet:n.sheet(o).name,range:se(u),values:n.toRows(u,o).map(p=>p.map(rn)),...u.bottom<l.bottom?{truncated:!0,fullRange:se(l)}:{}}}),s(W.writeRange,"Write values into a range",(n,r)=>{const o=fe(J(r.range,"The range"));if(!Array.isArray(r.values)||r.values.length===0||!r.values.every(Array.isArray))throw new Error("The values are a non-empty array of rows, each an array of cells.");const l=n.selection.sheet,f=r.values.map(u=>u.map(sn));Oe(n.dispatch({type:"SET_CELLS",sheet:l,at:{row:o.top,col:o.left},cells:f}));const g=Math.max(...f.map(u=>u.length));return{ok:!0,sheet:n.sheet(l).name,range:se({top:o.top,left:o.left,bottom:o.top+f.length-1,right:o.left+Math.max(0,g-1)})}}),s(W.insertChart,"Insert a chart of a range",(n,r)=>{const o=fe(J(r.range,"The range")),l=r.type===void 0?"column":J(r.type,"The type");if(!be.includes(l))throw new Error(`'${l}' is not a chart type; there are ${be.join(", ")}.`);const f=n.selection.sheet,g=it((v,b)=>n.value(f,v,b),n.sheet(f).name,o,(v,b)=>/[dmy]/i.test(n.style(f,v,b).format??""));if(!g.ok)throw new Error(g.message);let u=ot(n,o);if(r.at!==void 0&&u.kind==="cells"){const v=lt(J(r.at,"Where the chart goes")),b=u.to.row-u.from.row,d=u.to.col-u.from.col;u={kind:"cells",from:{row:v.row,col:v.col,dx:0,dy:0},to:{row:v.row+b,col:v.col+d,dx:0,dy:0}}}const p=new Set(n.sheet(f).charts.keys()),i=r.title===void 0?void 0:J(r.title,"The title");Oe(n.dispatch({type:"INSERT_CHART",sheet:f,chart:{type:l,anchor:u,data:g.data,legend:"bottom",...i?{title:i}:{}}}));const c=[...n.sheet(f).charts.keys()].find(v=>!p.has(v));return c!==void 0&&n.selectChart(c),{ok:!0,chartId:c,sheet:n.sheet(f).name,range:se(o),type:l}}),s(W.listCharts,"List the charts",n=>{const r=n.selection.sheet;return{sheet:n.sheet(r).name,charts:[...n.sheet(r).charts.values()].map(o=>({id:o.id,type:o.type,...o.title?{title:o.title}:{},ranges:at(o)}))}}),s(W.selectRange,"Select a range",(n,r)=>{const o=fe(J(r.range,"The range")),l=n.selection.sheet,f={row:o.top,col:o.left};return n.select({sheet:l,zones:[o],anchor:f,active:f}),{ok:!0,sheet:n.sheet(l).name,range:se(o)}})],contributes:[Ze(qe,Ne,{id:Ne.id})]})}const on="@datalayer/cells-agent-tools";Ue();function ln(){}const an=40;function fn(e,t=160,s=560){const[n,r]=ce.useState(t);return ce.useEffect(()=>{if(!e)return;const o=()=>{const l=e.sheet(e.selection.sheet);let f=l.rows.offsetOf(en(e,l.id).bottom+1);for(const g of l.charts.values()){const u=dt(l,g);f=Math.max(f,u.y+u.height)}r(Math.min(s,Math.max(t,Math.ceil(f)+an)))};return o(),e.subscribe(o)},[e,t,s]),n}Ue({model:ln,name:"@datalayer/loop-plugin-agent-outputs-sheet-tools"});async function dn(e){const t=await et(e),{workbook:s}=Jt(t);return{model:gt({data:s,readOnly:!0,codeCells:!1,plugins:[pt]}),bytes:t}}function gn({data:e,name:t,maxHeight:s}){const[n,r]=ce.useState({model:null,bytes:null,error:""});ce.useEffect(()=>{let f=!1;return dn(e).then(({model:g,bytes:u})=>!f&&r({model:g,bytes:u,error:""}),g=>!f&&r({model:null,bytes:null,error:g instanceof Error?g.message:String(g)})),()=>{f=!0}},[e]);const o=fn(n.model,160,s);if(n.error)return U.jsxs($e,{sx:{color:"danger.fg",fontSize:0},children:["Could not read the spreadsheet: ",n.error]});if(!n.model)return U.jsx($e,{as:"p",sx:{color:"fg.muted",fontSize:0,m:0},children:"Reading the spreadsheet…"});const l=n.model.sheets.length>1;return U.jsxs(ct,{model:n.model,children:[U.jsxs(he,{"data-spreadsheet-preview-sheets":n.model.sheets.length,border:"1px solid",borderColor:"border.muted",borderRadius:2,overflow:"hidden",children:[U.jsx(he,{height:o,children:U.jsx(ut,{model:n.model,"aria-label":`${t}, read-only`})}),l?U.jsx(ht,{"aria-label":`The sheets of ${t}`}):null]}),U.jsx(he,{mt:1,children:U.jsxs(Ye,{size:"small",variant:"invisible",leadingVisual:Je,onClick:()=>n.bytes&&Qe(n.bytes,t),children:["Download ",t]})})]})}export{gn as SpreadsheetPreviewView,gn as default,dn as readOnlyWorkbook};
1
+ import{bD as He,bF as Ze,fc as qe,fd as Ke,r as ce,j as U,T as $e,B as he,v as Ye,f6 as Je,fe as Qe,ff as et}from"../datalayer-app-main.js";import{o as tt,t as nt,p as rt,B as be,q as st,r as fe,z as se,s as it,v as ot,w as lt,x as at,y as ft,A as dt,j as ct,S as ut,k as ht,l as gt,m as pt}from"./SheetTabs-BR72mzuo.js";import"./KebabHorizontalIcon-D6AY8pIS.js";var z=Uint8Array,re=Uint16Array,mt=Int32Array,ze=new z([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Pe=new z([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),wt=new z([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),je=function(e,t){for(var s=new re(31),n=0;n<31;++n)s[n]=t+=1<<e[n-1];for(var r=new mt(s[30]),n=1;n<30;++n)for(var o=s[n];o<s[n+1];++o)r[o]=o-s[n]<<5|n;return{b:s,r}},Le=je(ze,2),_e=Le.b,vt=Le.r;_e[28]=258,vt[258]=28;var xt=je(Pe,0),bt=xt.b,ye=new re(32768);for(var T=0;T<32768;++T){var q=(T&43690)>>1|(T&21845)<<1;q=(q&52428)>>2|(q&13107)<<2,q=(q&61680)>>4|(q&3855)<<4,ye[T]=((q&65280)>>8|(q&255)<<8)>>1}var ie=(function(e,t,s){for(var n=e.length,r=0,o=new re(t);r<n;++r)e[r]&&++o[e[r]-1];var l=new re(t);for(r=1;r<t;++r)l[r]=l[r-1]+o[r-1]<<1;var f;if(s){f=new re(1<<t);var g=15-t;for(r=0;r<n;++r)if(e[r])for(var u=r<<4|e[r],p=t-e[r],i=l[e[r]-1]++<<p,c=i|(1<<p)-1;i<=c;++i)f[ye[i]>>g]=u}else for(f=new re(n),r=0;r<n;++r)e[r]&&(f[r]=ye[l[e[r]-1]++]>>15-e[r]);return f}),le=new z(288);for(var T=0;T<144;++T)le[T]=8;for(var T=144;T<256;++T)le[T]=9;for(var T=256;T<280;++T)le[T]=7;for(var T=280;T<288;++T)le[T]=8;var Fe=new z(32);for(var T=0;T<32;++T)Fe[T]=5;var yt=ie(le,9,1),Ct=ie(Fe,5,1),ge=function(e){for(var t=e[0],s=1;s<e.length;++s)e[s]>t&&(t=e[s]);return t},j=function(e,t,s){var n=t/8|0;return(e[n]|e[n+1]<<8)>>(t&7)&s},pe=function(e,t){var s=t/8|0;return(e[s]|e[s+1]<<8|e[s+2]<<16)>>(t&7)},St=function(e){return(e+7)/8|0},Se=function(e,t,s){return(t==null||t<0)&&(t=0),(s==null||s>e.length)&&(s=e.length),new z(e.subarray(t,s))},At=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],O=function(e,t,s){var n=new Error(t||At[e]);if(n.code=e,Error.captureStackTrace&&Error.captureStackTrace(n,O),!s)throw n;return n},kt=function(e,t,s,n){var r=e.length,o=n?n.length:0;if(!r||t.f&&!t.l)return s||new z(0);var l=!s,f=l||t.i!=2,g=t.i;l&&(s=new z(r*3));var u=function(Ae){var ke=s.length;if(Ae>ke){var Te=new z(Math.max(ke*2,Ae));Te.set(s),s=Te}},p=t.f||0,i=t.p||0,c=t.b||0,v=t.l,b=t.d,d=t.m,a=t.n,w=r*8;do{if(!v){p=j(e,i,1);var x=j(e,i+1,3);if(i+=3,x)if(x==1)v=yt,b=Ct,d=9,a=5;else if(x==2){var N=j(e,i,31)+257,L=j(e,i+10,15)+4,X=N+j(e,i+5,31)+1;i+=14;for(var _=new z(X),H=new z(19),h=0;h<L;++h)H[wt[h]]=j(e,i+h*3,7);i+=L*3;for(var k=ge(H),C=(1<<k)-1,m=ie(H,k,1),h=0;h<X;){var E=m[j(e,i,C)];i+=E&15;var y=E>>4;if(y<16)_[h++]=y;else{var R=0,S=0;for(y==16?(S=3+j(e,i,3),i+=2,R=_[h-1]):y==17?(S=3+j(e,i,7),i+=3):y==18&&(S=11+j(e,i,127),i+=7);S--;)_[h++]=R}}var M=_.subarray(0,N),I=_.subarray(N);d=ge(M),a=ge(I),v=ie(M,d,1),b=ie(I,a,1)}else O(1);else{var y=St(i)+4,$=e[y-4]|e[y-3]<<8,A=y+$;if(A>r){g&&O(0);break}f&&u(c+$),s.set(e.subarray(y,A),c),t.b=c+=$,t.p=i=A*8,t.f=p;continue}if(i>w){g&&O(0);break}}f&&u(c+131072);for(var D=(1<<d)-1,F=(1<<a)-1,K=i;;K=i){var R=v[pe(e,i)&D],G=R>>4;if(i+=R&15,i>w){g&&O(0);break}if(R||O(2),G<256)s[c++]=G;else if(G==256){K=i,v=null;break}else{var Q=G-254;if(G>264){var h=G-257,Z=ze[h];Q=j(e,i,(1<<Z)-1)+_e[h],i+=Z}var ee=b[pe(e,i)&F],Y=ee>>4;ee||O(3),i+=ee&15;var I=bt[Y];if(Y>3){var Z=Pe[Y];I+=pe(e,i)&(1<<Z)-1,i+=Z}if(i>w){g&&O(0);break}f&&u(c+131072);var te=c+Q;if(c<I){var ae=o-I,Ve=Math.min(I,te);for(ae+c<0&&O(3);c<Ve;++c)s[c]=n[ae+c]}for(;c<te;++c)s[c]=s[c-I]}}t.l=v,t.p=K,t.b=c,t.f=p,v&&(p=1,t.m=d,t.d=b,t.n=a)}while(!p);return c!=s.length&&l?Se(s,0,c):s.subarray(0,c)},Tt=new z(0),B=function(e,t){return e[t]|e[t+1]<<8},P=function(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0},me=function(e,t){return P(e,t)+P(e,t+4)*4294967296};function $t(e,t){return kt(e,{i:2},t&&t.out,t&&t.dictionary)}var Ce=typeof TextDecoder<"u"&&new TextDecoder,Rt=0;try{Ce.decode(Tt,{stream:!0}),Rt=1}catch{}var Dt=function(e){for(var t="",s=0;;){var n=e[s++],r=(n>127)+(n>223)+(n>239);if(s+r>e.length)return{s:t,r:Se(e,s-1)};r?r==3?(n=((n&15)<<18|(e[s++]&63)<<12|(e[s++]&63)<<6|e[s++]&63)-65536,t+=String.fromCharCode(55296|n>>10,56320|n&1023)):r&1?t+=String.fromCharCode((n&31)<<6|e[s++]&63):t+=String.fromCharCode((n&15)<<12|(e[s++]&63)<<6|e[s++]&63):t+=String.fromCharCode(n)}};function Be(e,t){if(t){for(var s="",n=0;n<e.length;n+=16384)s+=String.fromCharCode.apply(null,e.subarray(n,n+16384));return s}else{if(Ce)return Ce.decode(e);var r=Dt(e),o=r.s,s=r.r;return s.length&&O(8),o}}var Et=function(e,t){return t+30+B(e,t+26)+B(e,t+28)},Mt=function(e,t,s){var n=B(e,t+28),r=B(e,t+30),o=Be(e.subarray(t+46,t+46+n),!(B(e,t+8)&2048)),l=t+46+n,f=It(e,l,r,s,P(e,t+20),P(e,t+24),P(e,t+42)),g=f[0],u=f[1],p=f[2];return[B(e,t+10),g,u,o,l+r+B(e,t+32),p]},It=function(e,t,s,n,r,o,l){var f=r==4294967295,g=o==4294967295,u=l==4294967295,p=t+s,i=f+g+u;if(n&&i){for(;t+4<p;t+=4+B(e,t+2))if(B(e,t)==1)return[f?me(e,t+4+8*g):r,g?me(e,t+4):o,u?me(e,t+4+8*(g+f)):l,1];n<2&&O(13)}return[r,o,l,0]};function Nt(e,t){for(var s={},n=e.length-22;P(e,n)!=101010256;--n)(!n||e.length-n>65558)&&O(13);var r=B(e,n+8);if(!r)return{};var o=P(e,n+16),l=P(e,n-20)==117853008;if(l){var f=P(e,n-12);l=P(e,f)==101075792,l&&(r=P(e,f+32),o=P(e,f+48))}for(var g=0;g<r;++g){var u=Mt(e,o,l),p=u[0],i=u[1],c=u[2],v=u[3],b=u[4],d=u[5],a=Et(e,d);o=b,p?p==8?s[v]=$t(e.subarray(a,a+i),{out:new z(c)}):O(14,"unknown compression type "+p):s[v]=Se(e,a,a+i)}return s}const Ot={0:"General",1:"0",2:"0.00",3:"#,##0",4:"#,##0.00",9:"0%",10:"0.00%",11:"0.00E+00",12:"# ?/?",13:"# ??/??",14:"m/d/yyyy",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/yyyy h:mm",37:"#,##0 ;(#,##0)",38:"#,##0 ;[Red](#,##0)",39:"#,##0.00;(#,##0.00)",40:"#,##0.00;[Red](#,##0.00)",45:"mm:ss",46:"[h]:mm:ss",47:"mmss.0",48:"##0.0E+0",49:"@"},Re=/<(\/?)([A-Za-z_][\w:.-]*)((?:\s+[^\s=>/]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>|<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!\[CDATA\[([\s\S]*?)\]\]>|<![^>]*>|([^<]+)/g,De=/([^\s=]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g,zt={lt:"<",gt:">",amp:"&",quot:'"',apos:"'"};function oe(e){return e.includes("&")?e.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-z]+);/g,(t,s)=>{if(s[0]==="#"){const n=s[1]==="x"?parseInt(s.slice(2),16):parseInt(s.slice(1),10);return String.fromCodePoint(n)}return zt[s]??t}):e}const We=e=>{const t=e.indexOf(":");return t<0?e:e.slice(t+1)};function Pt(e){const t={};if(e==="")return t;De.lastIndex=0;let s;for(;(s=De.exec(e))!==null;)t[We(s[1])]=oe(s[2]??s[3]??"");return t}function V(e,t){Re.lastIndex=0;let s;for(;(s=Re.exec(e))!==null;)if(s[2]!==void 0){const n=We(s[2]);if(s[1]==="/")t.close?.(n);else{const r=s[4]==="/";t.open?.(n,Pt(s[3]),r),r&&t.close?.(n)}}else s[5]!==void 0?t.text?.(s[5]):s[6]!==void 0&&t.text?.(oe(s[6]))}const jt=9525,ne=e=>Math.round(Number(e??0)/jt);function Lt(e){const t=e.join("");return t===""?void 0:t}const Ee=new Set(["barChart","bar3DChart","lineChart","line3DChart","areaChart","area3DChart","pieChart","pie3DChart","doughnutChart","ofPieChart","scatterChart","radarChart","bubbleChart","stockChart","surfaceChart","surface3DChart"]),Xe=new Set(["barChart","bar3DChart","lineChart","line3DChart","areaChart","area3DChart","pieChart","pie3DChart","doughnutChart","scatterChart"]);function _t(e){const t={autoTitleDeleted:!1,groups:[],axes:[],pivot:!1,undrawn:[]},s=[];let n,r,o,l,f,g="",u=0;const p=i=>s.includes(i);return V(e,{open(i,c){if(s.push(i),Ee.has(i)&&p("plotArea")){n={element:i,series:[],axIds:[]},t.groups.push(n),Xe.has(i)||t.undrawn.push(i);return}if(i==="pivotSource"&&(t.pivot=!0),i==="autoTitleDeleted"&&(t.autoTitleDeleted=c.val==="1"||c.val==="true"),i==="legendPos"&&(t.legend=c.val),i==="dispBlanksAs"&&(t.dispBlanksAs=c.val),i==="title"&&!p("ser")){u+=1,l=[],f=o!==void 0&&p(o.element)?"axisTitle":"title";return}if(n!==void 0&&!p("ser")&&(i==="barDir"?n.barDir=c.val:i==="grouping"?n.grouping=c.val:i==="holeSize"?n.holeSize=!0:i==="axId"?n.axIds.push(c.val):i==="showVal"&&p("dLbls")&&(n.showVal=c.val==="1"||c.val==="true")),i==="ser"&&n!==void 0){r={idx:1e9,literal:!1,dPt:0,trendline:0,errBars:0,external:!1},n.series.push(r);return}if(r!==void 0&&(i==="idx"&&!p("dPt")&&!p("dLbl")?r.idx=Number(c.val):i==="tx"?f="name":i==="val"||i==="yVal"?f="values":i==="cat"?f="categories":i==="xVal"?f="x":i==="f"?g="":i==="numLit"||i==="strLit"?r.literal=!0:i==="dPt"&&n!==void 0&&!n.element.startsWith("pie")&&n.element!=="doughnutChart"?r.dPt+=1:i==="trendline"?r.trendline+=1:i==="errBars"?r.errBars+=1:i==="smooth"?r.smooth=c.val!=="0"&&c.val!=="false":i==="srgbClr"&&p("spPr")&&p("solidFill")&&!p("dPt")&&r.color===void 0?r.color=`#${c.val.toLowerCase()}`:i==="v"&&f==="name"&&p("tx")&&!p("strRef")&&(l=[])),(i==="catAx"||i==="valAx"||i==="dateAx"||i==="serAx")&&p("plotArea")){o={element:i,id:"",gridlines:!1,deleted:!1},t.axes.push(o);return}o!==void 0&&p(o.element)&&(i==="axId"?o.id=c.val:i==="min"?o.min=Number(c.val):i==="max"?o.max=Number(c.val):i==="logBase"?o.log=!0:i==="majorGridlines"?o.gridlines=!0:i==="numFmt"&&c.formatCode!==void 0&&c.formatCode!=="General"&&c.sourceLinked!=="1"&&c.sourceLinked!=="true"?o.format=c.formatCode:i==="delete"&&(o.deleted=c.val==="1"||c.val==="true"))},text(i){p("f")?g+=i:l!==void 0&&(p("t")||p("v")&&f==="name")&&l.push(i)},close(i){if(s.pop(),i==="f"&&r!==void 0&&f!==void 0&&f!=="title"&&f!=="axisTitle"){const c=g.trim();/^\[/.test(c)||/'\[/.test(c)?r.external=!0:r[f]=c}if(i==="v"&&r!==void 0&&f==="name"&&l!==void 0&&!p("strRef")&&(r.name=l.join(""),l=void 0),(i==="tx"||i==="val"||i==="yVal"||i==="cat"||i==="xVal")&&r!==void 0&&(f=void 0),i==="title"&&u>0){u-=1;const c=Lt(l??[]);f==="axisTitle"&&o!==void 0?o.title=c:f==="title"&&(t.title=c),l=void 0,f=void 0}i==="ser"&&(r=void 0),Ee.has(i)&&(n=void 0),(i==="catAx"||i==="valAx"||i==="dateAx"||i==="serAx")&&(o=void 0)}}),t}const Ft={t:"top",r:"right",b:"bottom",l:"left",tr:"right"},we=e=>e;function Bt(e,t,s,n,r){const o=`${n}: chart '${t}'`;if(e.pivot){r.push(`${o}: a pivot chart was not imported.`);return}for(const h of e.undrawn)r.push(`${o}: a ${h.replace(/Chart$/,"")} chart was not imported.`);const l=e.groups.filter(h=>Xe.has(h.element));if(l.length===0){e.undrawn.length===0&&r.push(`${o}: no chart that Cells draws.`);return}const f=l.filter(h=>h.element.includes("3D")),g=h=>{switch(h.element){case"barChart":case"bar3DChart":return h.barDir==="bar"?"bar":"column";case"lineChart":case"line3DChart":return"line";case"areaChart":case"area3DChart":return"area";case"pieChart":case"pie3DChart":case"doughnutChart":return"pie";default:return"scatter"}},u=e.axes.filter(h=>h.element==="valAx"),p=u[0],c=l.every(h=>h.element==="scatterChart")?void 0:u.find(h=>h!==p&&l.some(k=>k.axIds.includes(h.id))),v=e.axes.find(h=>h.element==="catAx"||h.element==="dateAx"||h.element==="valAx"&&l.every(k=>k.element==="scatterChart")&&h===p),b=l.length>1;let d=b?"combo":g(l[0]);if(b&&l.some(h=>h.element.startsWith("pie")||h.element==="doughnutChart"||h.element==="scatterChart")){d=g(l[0]);for(const h of l.slice(1))r.push(`${o}: a second plot (${h.element.replace(/Chart$/,"")}) beside a ${d} chart was not imported.`);l.length=1}f.length>0&&r.push(`${o}: a 3-D chart was imported as a ${d} chart.`);let a;const w=l[0];w.element==="doughnutChart"?a="doughnut":w.grouping==="stacked"?a="stacked":w.grouping==="percentStacked"?a="percent":(w.element==="lineChart"||w.element==="line3DChart")&&w.series.some(h=>h.smooth)&&(a="smooth");const x=[],y=[],$=[];for(const h of l){const k=g(h),C=c!==void 0&&h.axIds.includes(c.id);for(const m of h.series){if(m.values===void 0){y.push(m.external?"a series naming another workbook":m.literal?"a series given as literals":"a series without values");continue}m.literal&&r.push(`${o}: literal categories or names of a series were left out.`),m.dPt>0&&r.push(`${o}: ${m.dPt} per-point colour(s) were left out.`),m.trendline>0&&r.push(`${o}: ${m.trendline} trendline(s) were left out.`),m.errBars>0&&r.push(`${o}: error bars were left out.`),$.push([m.idx,{values:we(m.values),...m.name!==void 0?{name:m.name}:{},...m.categories!==void 0?{categories:we(m.categories)}:{},...m.x!==void 0?{x:we(m.x)}:{},...b?{type:k==="column"||k==="bar"?"column":k==="area"?"area":"line"}:{},...C?{axis:"secondary"}:{},...m.color!==void 0?{color:m.color}:{}}])}}$.sort((h,k)=>h[0]-k[0]);for(const[,h]of $)x.push(h);for(const h of y)r.push(`${o}: ${h} was not imported.`);if(x.length===0){r.push(`${o}: no series to draw.`);return}const A=h=>{if(h===void 0)return;const k=h.element==="valAx",C={...h.title!==void 0?{title:h.title}:{},...h.min!==void 0?{min:h.min}:{},...h.max!==void 0?{max:h.max}:{},...h.format!==void 0?{format:h.format}:{},...h.log?{log:!0}:{},...k&&!h.gridlines?{gridlines:!1}:{},...!k&&h.gridlines?{gridlines:!0}:{}};return Object.keys(C).length===0?void 0:C},N=A(v),L=A(d==="scatter"?u[1]??p:p),X=A(c),_=N!==void 0||L!==void 0||X!==void 0?{...N!==void 0?{x:N}:{},...L!==void 0?{y:L}:{},...X!==void 0?{y2:X}:{}}:void 0,H=x.length>1&&x.every(h=>{const k=/\$?([A-Z]+)\$?(\d+):\$?([A-Z]+)\$?(\d+)$/.exec(h.values);return k!==null&&k[2]===k[4]&&k[1]!==k[3]});return{id:t,type:d,...a!==void 0?{variant:a}:{},anchor:s,data:{series:x,by:H?"rows":"columns",headers:{row:x.some(h=>h.name!==void 0),column:x.some(h=>h.categories!==void 0)},blanks:e.dispBlanksAs==="zero"?"zero":e.dispBlanksAs==="span"?"connect":"gap"},...e.title!==void 0?{title:e.title}:{},legend:e.legend!==void 0?Ft[e.legend]??"bottom":"none",..._!==void 0?{axes:_}:{},...l.some(h=>h.showVal)?{labels:!0}:{}}}function Wt(e){const t=[];let s,n,r,o,l,f,g,u=!1,p,i={col:0,colOff:0,row:0,rowOff:0},c,v="";const b=()=>{if(s===void 0)return;let d;s==="twoCellAnchor"&&n!==void 0&&r!==void 0?d={kind:"cells",from:n,to:r}:s==="oneCellAnchor"&&n!==void 0&&l!==void 0?d={kind:"cell",from:n,width:Math.max(1,l.width),height:Math.max(1,l.height)}:s==="absoluteAnchor"&&o!==void 0&&l!==void 0&&(d={kind:"absolute",...o,width:Math.max(1,l.width),height:Math.max(1,l.height)}),d!==void 0&&t.push({anchor:d,chart:f,chartEx:g,picture:u}),s=void 0,n=r=o=l=f=g=void 0,u=!1};return V(e,{open(d,a){d==="twoCellAnchor"||d==="oneCellAnchor"||d==="absoluteAnchor"?s=d:d==="from"||d==="to"?(p=d,i={col:0,colOff:0,row:0,rowOff:0}):d==="col"||d==="colOff"||d==="row"||d==="rowOff"?(c=d,v=""):d==="pos"?o={x:ne(a.x),y:ne(a.y)}:d==="ext"&&s!==void 0&&a.cx!==void 0&&l===void 0?l={width:ne(a.cx),height:ne(a.cy)}:d==="chart"?(f===void 0&&(f=a.id),a.id===void 0&&(f=f??"missing")):d==="pic"&&(u=!0)},text(d){c!==void 0&&(v+=d)},close(d){if(d==="col"||d==="colOff"||d==="row"||d==="rowOff")i[d]=Number(v.trim()),c=void 0;else if(d==="from"||d==="to"){const a={row:i.row,col:i.col,dx:ne(String(i.colOff)),dy:ne(String(i.rowOff))};p==="from"?n=a:r=a,p=void 0}else(d==="twoCellAnchor"||d==="oneCellAnchor"||d==="absoluteAnchor")&&b()}}),t}function Me(e){const t=new Map;return e===void 0||V(e,{open(s,n){s==="Relationship"&&n.Id!==void 0&&n.Target!==void 0&&t.set(n.Id,{target:n.Target,type:n.Type??""})}}),t}function ve(e,t){if(t.startsWith("/"))return t.slice(1);const s=e.split("/").slice(0,-1);for(const n of t.split("/"))n===".."?s.pop():n!=="."&&s.push(n);return s.join("/")}function Xt(e,t,s,n,r){const o={},l=t.split("/").slice(0,-1).join("/"),f=t.split("/").pop(),u=Me(e(`${l}/_rels/${f}.rels`)).get(s);if(u===void 0)return r.push(`${n}: the drawing part is missing.`),o;const p=ve(t,u.target),i=e(p);if(i===void 0)return r.push(`${n}: the drawing part ${p} is missing.`),o;const c=p.split("/").slice(0,-1).join("/"),v=p.split("/").pop(),b=Me(e(`${c}/_rels/${v}.rels`));let d=0;for(const a of Wt(i)){if(a.chart===void 0)continue;const w=b.get(a.chart);if(w===void 0){r.push(`${n}: a chart's part is missing (${a.chart}).`);continue}d+=1;const x=`chart${d}`;if(/chartEx/i.test(w.type)||/chartEx/.test(w.target)){const A=e(ve(p,w.target))??"",N=/<cx:layoutId val="([^"]+)"/.exec(A)?.[1]??"unknown";r.push(`${n}: chart '${x}': an Excel 2016 chart (${N}) was not imported.`);continue}const y=e(ve(p,w.target));if(y===void 0){r.push(`${n}: chart '${x}': its part ${w.target} is missing.`);continue}const $=Bt(_t(y),x,a.anchor,n,r);$!==void 0&&(o[x]=$)}return o}const Ge="customXml/cells-code.xml";function Gt(e){let t=0;for(const s of e)t=t*26+(s.charCodeAt(0)-64);return t-1}function ue(e){const t=/^\$?([A-Z]{1,3})\$?([0-9]+)$/.exec(e);if(t===null)throw new Error(`'${e}' is not a cell reference.`);return{row:Number(t[2])-1,col:Gt(t[1])}}function Ut(e){const[t,s=t]=e.split(":"),n=ue(t),r=ue(s);return{top:Math.min(n.row,r.row),left:Math.min(n.col,r.col),bottom:Math.max(n.row,r.row),right:Math.max(n.col,r.col)}}function xe(e){const t=e?.rgb;if(!(t===void 0||!/^[0-9A-Fa-f]{6,8}$/.test(t)))return`#${t.slice(-6).toLowerCase()}`}const Vt={thin:"thin",hair:"thin",medium:"medium",thick:"thick",dashed:"dashed",mediumDashed:"dashed",dashDot:"dashed",mediumDashDot:"dashed",dashDotDot:"dotted",mediumDashDotDot:"dotted",slantDashDot:"dashed",dotted:"dotted",double:"double"};function Ht(e){if(e===void 0)return[{}];const t=new Map,s=[],n=[],r=[],o=[],l=new Map;let f="",g,u,p,i,c,v;V(e,{open(d,a){switch(d){case"numFmts":case"fonts":case"fills":case"borders":case"cellXfs":case"cellStyleXfs":case"dxfs":f=d;return;case"numFmt":f==="numFmts"&&t.set(Number(a.numFmtId),a.formatCode??"General");return}if(f==="fonts")d==="font"?g={}:g!==void 0&&(d==="b"?g.bold=a.val!=="0"&&a.val!=="false":d==="i"?g.italic=a.val!=="0"&&a.val!=="false":d==="u"?g.underline=a.val!=="none":d==="strike"?g.strike=a.val!=="0"&&a.val!=="false":d==="sz"?g.size=Number(a.val):d==="color"?g.color=xe(a):d==="name"&&(g.font=a.val));else if(f==="fills")d==="fill"?u={}:d==="patternFill"&&u?u.pattern=a.patternType:d==="fgColor"&&u&&(u.color=xe(a));else if(f==="borders")d==="border"?p={}:p!==void 0&&["left","right","top","bottom"].includes(d)?i={name:d,style:a.style===void 0?void 0:Vt[a.style]}:d==="color"&&i!==void 0&&i.style!==void 0&&(p[i.name]={style:i.style,color:xe(a)??"#000000"});else if(f==="cellXfs"){if(d==="xf"){const w=Number(a.numFmtId??0),x=s[Number(a.fontId??0)]??{};v=x;const y=n[Number(a.fillId??0)],$=r[Number(a.borderId??0)],A=w===0?void 0:(t.get(w)??Ot[w])?.replace(/^\[\$-(409|en-US)\]/,"");c={...x.bold?{bold:!0}:{},...x.italic?{italic:!0}:{},...x.underline?{underline:!0}:{},...x.strike?{strike:!0}:{},...x.color!==void 0&&x.color!=="#000000"?{color:x.color}:{},...y!==void 0?{fill:y}:{},...$!==void 0&&Object.keys($).length>0?{borders:$}:{},...A!==void 0&&A!=="General"?{format:A}:{}}}else if(d==="alignment"&&c!==void 0){const w=a.horizontal,x=a.vertical;c={...c,...w==="left"||w==="center"||w==="right"?{align:w}:{},...x==="top"?{valign:"top"}:x==="center"?{valign:"middle"}:{},...a.wrapText==="1"||a.wrapText==="true"?{wrap:!0}:{}}}}},close(d){d===f?f="":d==="font"&&g!==void 0?(s.push(g),g=void 0):d==="fill"&&u!==void 0?(n.push(u.pattern==="solid"?u.color:void 0),u=void 0):d==="border"&&p!==void 0?(r.push(p),p=void 0):["left","right","top","bottom"].includes(d)?i=void 0:d==="xf"&&c!==void 0&&f==="cellXfs"&&(o.push(c),v!==void 0&&l.set(c,v),c=void 0)}});const b=s[0]??{};return o.map((d,a)=>{if(a===0)return{};const w=l.get(d);return w===void 0?d:{...d,...w.size!==void 0&&w.size!==b.size?{size:w.size}:{},...w.font!==void 0&&w.font!==b.font?{font:w.font}:{}}})}function Zt(e){const t=[];if(e===void 0)return t;let s,n=!1,r=!1;return V(e,{open(o){o==="si"?s="":o==="t"?n=!r:o==="rPh"&&(r=!0)},close(o){o==="si"?(t.push(s??""),s=void 0):o==="t"?n=!1:o==="rPh"&&(r=!1)},text(o){n&&s!==void 0&&(s+=o)}}),t}const qt=e=>Math.round(e*7+5),Ie=e=>Math.round(e*4/3);function Kt(e,t,s){const n={},r={},o={},l=[],f=[],g=[];let u,p;const i=new Map;let c=0,v=0,b,d="n",a=0,w,x,y,$="",A,N=0,L=0;const X=(C,m,E,R,S,M,I)=>{const D={};if(M?.t==="shared"&&M.si!==void 0)if(S!==void 0&&S!=="")i.set(M.si,{formula:S,...C});else{const F=i.get(M.si);F!==void 0&&(S=nt(F.formula,C.row-F.row,C.col-F.col))}else M?.t==="array"&&s.set("array formula",(s.get("array formula")??0)+1);if(S!==void 0&&S!==""&&(D.f=S,v+=1),m==="s"&&R!==void 0?D.v=t[Number(R)]??"":m==="b"&&R!==void 0?D.v=R==="1":m==="e"&&R!==void 0?D.v=rt(R)?{error:R}:{error:"#VALUE!"}:(m==="str"||m==="inlineStr")&&(R!==void 0||I!=="")?D.v=m==="inlineStr"?I:R??"":R!==void 0&&R!==""&&(D.v=Number(R)),E!==0&&(D.s=E),D.v!==void 0||D.f!==void 0||D.s!==void 0){const F=String(C.row);(n[F]??={cells:{}}).cells[String(C.col)]=D,c+=1}},_=C=>{const m=/<(?:\w+:)?row\s([^>]*?)\/?>/g;let E;for(;(E=m.exec(C))!==null;){const S=E[1],M=/\br="(\d+)"/.exec(S);if(M===null)continue;const I=Number(M[1])-1,D=/\bht="([^"]+)"/.exec(S);D!==null&&/\bcustomHeight="(1|true)"/.test(S)&&(r[String(I)]=Ie(Number(D[1]))),/\bhidden="(1|true)"/.test(S)&&l.push(I)}const R=/<(?:\w+:)?c\s([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?c>)/g;for(;(E=R.exec(C))!==null;){const S=E[1],M=E[2]??"",I=ue(/\br="([^"]+)"/.exec(S)[1]),D=/\bt="([^"]+)"/.exec(S)?.[1]??"n",F=Number(/\bs="(\d+)"/.exec(S)?.[1]??0);let K,G,Q,Z="";if(M!==""){const ee=/<(?:\w+:)?v>([\s\S]*?)<\/(?:\w+:)?v>/.exec(M);ee!==null?K=oe(ee[1]):/<(?:\w+:)?v\/>/.test(M)&&(K="");const Y=/<(?:\w+:)?f\b([^>]*?)(?:\/>|>([\s\S]*?)<\/(?:\w+:)?f>)/.exec(M);if(Y!==null){Q={};for(const[,te,ae]of Y[1].matchAll(/(\w+)="([^"]*)"/g))Q[te]=ae;G=oe(Y[2]??"")}if(D==="inlineStr")for(const[,te]of M.matchAll(/<(?:\w+:)?t(?:\s[^>]*)?>([\s\S]*?)<\/(?:\w+:)?t>/g))Z+=oe(te)}X(I,D,F,K,G,Q,Z)}};let H=e;const h=/<(?:\w+:)?sheetData\b[^>]*>/.exec(e),k=h===null?-1:e.search(/<\/(?:\w+:)?sheetData>/);return h!==null&&k>h.index&&!/<(?:\w+:)?c(?=[\s>/])(?![^>]*\sr=)/.test(e)&&(_(e.slice(h.index+h[0].length,k)),H=e.slice(0,h.index)+e.slice(k)),V(H,{open(C,m){switch(C){case"row":{const E=m.r===void 0?N:Number(m.r)-1;N=E+1,L=0,m.ht!==void 0&&(m.customHeight==="1"||m.customHeight==="true")&&(r[String(E)]=Ie(Number(m.ht))),(m.hidden==="1"||m.hidden==="true")&&l.push(E);return}case"c":{b=m.r===void 0?{row:N-1,col:L}:ue(m.r),L=b.col+1,d=m.t??"n",a=Number(m.s??0),w=void 0,x=void 0,y=void 0,$="";return}case"v":A="v",w="";return;case"f":A="f",x="",y=m;return;case"is":A="is";return;case"col":{const E=Number(m.min)-1,R=Math.min(Number(m.max)-1,16383);for(let S=E;S<=R;S+=1)m.width!==void 0&&(m.customWidth==="1"||m.customWidth==="true")&&(o[String(S)]=qt(Number(m.width))),(m.hidden==="1"||m.hidden==="true")&&f.push(S);return}case"mergeCell":m.ref!==void 0&&g.push(Ut(m.ref));return;case"pane":(m.state==="frozen"||m.state==="frozenSplit")&&(u={rows:Number(m.ySplit??0),cols:Number(m.xSplit??0)});return;case"drawing":p=m.id;return;case"conditionalFormatting":case"dataValidation":case"hyperlink":case"legacyDrawing":case"tablePart":case"sheetProtection":case"autoFilter":s.set(C,(s.get(C)??0)+1);return}},text(C){A==="v"?w+=C:A==="f"?x+=C:A==="is"&&($+=C)},close(C){if(C==="v"||C==="f"||C==="is"){A=void 0;return}C!=="c"||b===void 0||(X(b,d,a,w,x,y,$),b=void 0)}}),{sheet:{rows:n,...Object.keys(r).length+Object.keys(o).length>0?{sizes:{rows:r,cols:o}}:{},...l.length+f.length>0?{hidden:{rows:l,cols:f}}:{},...g.length>0?{merges:g}:{},...u!==void 0?{frozen:u}:{}},cells:c,formulas:v,...p!==void 0?{drawing:p}:{}}}function Yt(e){return e.startsWith("/")?e.slice(1):`xl/${e}`.replace(/\/[^/]+\/\.\.\//g,"/")}function Jt(e){let t;try{t=Nt(e)}catch(a){throw new Error(`The file is not an XLSX package: ${a.message}`)}const s=a=>t[a]===void 0?void 0:Be(t[a]),n=s("xl/workbook.xml");if(n===void 0)throw new Error("The package has no xl/workbook.xml.");const r=new Map;V(s("xl/_rels/workbook.xml.rels")??"",{open(a,w){a==="Relationship"&&w.Id!==void 0&&w.Target!==void 0&&r.set(w.Id,Yt(w.Target))}});const o=[],l=new Map;V(n,{open(a,w){if(a==="sheet"){const x=r.get(w.id);if(x===void 0)throw new Error(`The sheet '${w.name}' has no part.`);o.push({name:w.name,path:x,hidden:w.state==="hidden"||w.state==="veryHidden"})}else a==="definedName"&&l.set("defined name",(l.get("defined name")??0)+1)}});const f=Zt(s("xl/sharedStrings.xml")),g=Ht(s("xl/styles.xml"));let u=0,p=0,i=0;const c=[],v=new Set,b=o.map((a,w)=>{const x=s(a.path);if(x===void 0)throw new Error(`The sheet '${a.name}' has no ${a.path}.`);a.hidden&&l.set("hidden sheet (shown)",(l.get("hidden sheet (shown)")??0)+1);const y=Kt(x,f,l);u+=y.cells,p+=y.formulas;let $=`s${w+1}`;for(;v.has($);)$+="_";v.add($);const A=y.drawing===void 0?{}:Xt(s,a.path,y.drawing,a.name,c);return i+=Object.keys(A).length,{id:$,name:a.name,...y.sheet,...Object.keys(A).length>0?{charts:A}:{}}}),d=Qt(s(Ge),b);for(const a of Object.keys(t))/^xl\/chartsheets\/sheet\d+\.xml$/.test(a)?c.push(`${a}: a chart sheet was not imported.`):a.startsWith("xl/media/")?l.set("image",(l.get("image")??0)+1):/^xl\/comments\d*\.xml$/.test(a)||a.startsWith("xl/threadedComments/")?l.set("comments",(l.get("comments")??0)+1):a.startsWith("xl/pivotTables/")&&l.set("pivot table",(l.get("pivot table")??0)+1);for(const a of b)for(const w of Object.values(a.rows))for(const x of Object.values(w.cells))x.s!==void 0&&x.s>=g.length&&delete x.s;return{workbook:{version:1,sheets:b,styles:g.length>0?g:[{}]},report:{sheets:b.length,cells:u,formulas:p,skipped:[...l].map(([a,w])=>({feature:a,count:w})),chartsImported:i,charts:c,code:d}}}function Qt(e,t){if(e===void 0)return[];const s=new Map(t.map(g=>[g.name,g])),n=new Map;let r=0,o,l="",f=!1;V(e,{open(g,u){if(g==="cell"){const p=s.get(u.sheet??"");o=p===void 0?void 0:{sheet:p,ref:u.ref??"",attrs:u},l=""}else g==="source"&&(f=!0)},text(g){f&&(l+=g)},close(g){if(g==="source"&&(f=!1),g!=="cell"||o===void 0)return;const{sheet:u,ref:p,attrs:i}=o,c=/^([A-Z]{1,3})([1-9][0-9]*)$/.exec(p);if(c===null)return;let v=-1;for(const w of c[1])v=(v+1)*26+w.charCodeAt(0)-65;const b=u.rows[String(Number(c[2])-1)]?.cells[String(v)]?.v,d={source:l,language:"python",outputs:[],result:b===void 0?null:b,run:i.run==="auto"?"auto":"manual",...i.executionCount!==void 0?{executionCount:Number(i.executionCount)}:{},...i.lastRun!==void 0?{lastRun:i.lastRun}:{},...i.frame==="none"?{frame:null}:i.frameWidth!==void 0&&i.frameHeight!==void 0?{frame:{width:Number(i.frameWidth),height:Number(i.frameHeight),...i.frameDx!==void 0?{dx:Number(i.frameDx)}:{},...i.frameDy!==void 0?{dy:Number(i.frameDy)}:{}}}:{}};if(tt(d)!==void 0)return;let a=n.get(u);a===void 0&&n.set(u,a={}),a[p]=d,r+=1,o=void 0}});for(const[g,u]of n)g.code=u;return r===0?[]:[`${r} code cell${r===1?"":"s"} read from ${Ge}: the sources and the results, as cached values; the outputs are not in XLSX and were dropped.`]}function en(e,t){const s=e.sheet(t).cells;let n=0,r=0;for(const o of s.columnIndexes()){const l=s.lastRowIn(o);l>=0&&(n=Math.max(n,o),r=Math.max(r,l))}return{top:0,left:0,bottom:r,right:n}}const W={readRange:"cells.agent.readRange",writeRange:"cells.agent.writeRange",insertChart:"cells.agent.insertChart",listCharts:"cells.agent.listCharts",selectRange:"cells.agent.selectRange"},tn=2e3,de={type:"string",description:"A range in A1 notation on the sheet shown, such as `A1:D13`, or one cell such as `B3`."},Ne=Ke({id:"cells",version:"0.0.1",name:"Cells",description:"Read and write the spreadsheet on the person's screen, and chart it: the grid drawn by Datalayer Cells.",plugin:"@datalayer/cells",commands:[{name:"cells_read_range",command:W.readRange,description:"The values of a range of the spreadsheet shown, row by row. Without a range, the whole used range from A1, which is how to find where the data is: the answer names the sheet and the range read. Numbers are numbers, empty cells null.",parameters:{type:"object",properties:{range:de}}},{name:"cells_write_range",command:W.writeRange,description:"Write a block of values, row by row, from the top-left cell of a range. A text starting with = is a formula (=SUM(B2:B13)); numbers, booleans and null (an empty cell) are written as they are. One undo step.",parameters:{type:"object",properties:{range:{...de,description:"Where the block starts: its top-left cell, such as `E1`, or a range whose top-left cell it is."},values:{type:"array",description:"The rows to write, each an array of cells: number, string, boolean or null.",items:{type:"array",items:{type:["number","string","boolean","null"]}}}},required:["range","values"]}},{name:"cells_insert_chart",command:W.insertChart,description:"Insert a chart of a range into the spreadsheet shown, as the Insert chart button does: the series are read from the range (a first row of names and a first column of categories become the legend and the axis). It is drawn over the grid, beside the range unless `at` says where; the answer gives its id.",parameters:{type:"object",properties:{range:{...de,description:"The data to chart, headers included, such as `A1:D13`."},type:{type:"string",enum:[...be],description:"The chart type; column by default."},title:{type:"string",description:"The title drawn above the chart."},at:{type:"string",description:"The cell where the chart's top-left corner goes, such as `A15` (below the data) or `F1`."}},required:["range"]}},{name:"cells_list_charts",command:W.listCharts,description:"The charts of the sheet shown: id, type, title and the ranges each reads."},{name:"cells_select_range",command:W.selectRange,description:"Select a range of the spreadsheet shown, to show the person the cells meant.",parameters:{type:"object",properties:{range:de},required:["range"]}}]}),J=(e,t)=>{if(typeof e!="string"||e.trim()==="")throw new Error(`${t} is a non-empty string.`);return e},Oe=e=>{if(!e.ok)throw new Error(e.refusals.map(t=>t.message).join(" "))};function nn(e,t){const s=e.sheet(t).cells;let n=-1,r=-1;for(const o of s.columnIndexes()){const l=s.lastRowIn(o);l<0||(n=Math.max(n,o),r=Math.max(r,l))}return n<0?null:{top:0,left:0,bottom:r,right:n}}const rn=e=>e!==null&&typeof e=="object"?`#${e.error.replace(/^#/,"")}`:e,sn=e=>{if(e==null)return null;if(typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="string")return e.startsWith("=")?ft(e):e;throw new Error(`A cell is a number, a string, a boolean or null, not ${JSON.stringify(e)}.`)};function Ue(e={}){const t=n=>e.model?.()??st(n,void 0).model,s=(n,r,o)=>({id:n,name:r,category:"Cells",execute:l=>o(t(n),l??{})});return He({name:e.name??on,displayName:"Cells agent tools",description:"Read, write, chart and select the grid on screen, as tools an agent calls.",octicon:"table",commands:[s(W.readRange,"Read a range",(n,r)=>{const o=n.selection.sheet,l=r.range===void 0?nn(n,o):fe(J(r.range,"The range"));if(l===null)return{sheet:n.sheet(o).name,range:null,values:[]};const f=l.right-l.left+1,g=Math.max(1,Math.min(l.bottom-l.top+1,Math.floor(tn/f))),u={...l,bottom:l.top+g-1};return{sheet:n.sheet(o).name,range:se(u),values:n.toRows(u,o).map(p=>p.map(rn)),...u.bottom<l.bottom?{truncated:!0,fullRange:se(l)}:{}}}),s(W.writeRange,"Write values into a range",(n,r)=>{const o=fe(J(r.range,"The range"));if(!Array.isArray(r.values)||r.values.length===0||!r.values.every(Array.isArray))throw new Error("The values are a non-empty array of rows, each an array of cells.");const l=n.selection.sheet,f=r.values.map(u=>u.map(sn));Oe(n.dispatch({type:"SET_CELLS",sheet:l,at:{row:o.top,col:o.left},cells:f}));const g=Math.max(...f.map(u=>u.length));return{ok:!0,sheet:n.sheet(l).name,range:se({top:o.top,left:o.left,bottom:o.top+f.length-1,right:o.left+Math.max(0,g-1)})}}),s(W.insertChart,"Insert a chart of a range",(n,r)=>{const o=fe(J(r.range,"The range")),l=r.type===void 0?"column":J(r.type,"The type");if(!be.includes(l))throw new Error(`'${l}' is not a chart type; there are ${be.join(", ")}.`);const f=n.selection.sheet,g=it((v,b)=>n.value(f,v,b),n.sheet(f).name,o,(v,b)=>/[dmy]/i.test(n.style(f,v,b).format??""));if(!g.ok)throw new Error(g.message);let u=ot(n,o);if(r.at!==void 0&&u.kind==="cells"){const v=lt(J(r.at,"Where the chart goes")),b=u.to.row-u.from.row,d=u.to.col-u.from.col;u={kind:"cells",from:{row:v.row,col:v.col,dx:0,dy:0},to:{row:v.row+b,col:v.col+d,dx:0,dy:0}}}const p=new Set(n.sheet(f).charts.keys()),i=r.title===void 0?void 0:J(r.title,"The title");Oe(n.dispatch({type:"INSERT_CHART",sheet:f,chart:{type:l,anchor:u,data:g.data,legend:"bottom",...i?{title:i}:{}}}));const c=[...n.sheet(f).charts.keys()].find(v=>!p.has(v));return c!==void 0&&n.selectChart(c),{ok:!0,chartId:c,sheet:n.sheet(f).name,range:se(o),type:l}}),s(W.listCharts,"List the charts",n=>{const r=n.selection.sheet;return{sheet:n.sheet(r).name,charts:[...n.sheet(r).charts.values()].map(o=>({id:o.id,type:o.type,...o.title?{title:o.title}:{},ranges:at(o)}))}}),s(W.selectRange,"Select a range",(n,r)=>{const o=fe(J(r.range,"The range")),l=n.selection.sheet,f={row:o.top,col:o.left};return n.select({sheet:l,zones:[o],anchor:f,active:f}),{ok:!0,sheet:n.sheet(l).name,range:se(o)}})],contributes:[Ze(qe,Ne,{id:Ne.id})]})}const on="@datalayer/cells-agent-tools";Ue();function ln(){}const an=40;function fn(e,t=160,s=560){const[n,r]=ce.useState(t);return ce.useEffect(()=>{if(!e)return;const o=()=>{const l=e.sheet(e.selection.sheet);let f=l.rows.offsetOf(en(e,l.id).bottom+1);for(const g of l.charts.values()){const u=dt(l,g);f=Math.max(f,u.y+u.height)}r(Math.min(s,Math.max(t,Math.ceil(f)+an)))};return o(),e.subscribe(o)},[e,t,s]),n}Ue({model:ln,name:"@datalayer/loop-plugin-agent-outputs-sheet-tools"});async function dn(e){const t=await et(e),{workbook:s}=Jt(t);return{model:gt({data:s,readOnly:!0,codeCells:!1,plugins:[pt]}),bytes:t}}function gn({data:e,name:t,maxHeight:s}){const[n,r]=ce.useState({model:null,bytes:null,error:""});ce.useEffect(()=>{let f=!1;return dn(e).then(({model:g,bytes:u})=>!f&&r({model:g,bytes:u,error:""}),g=>!f&&r({model:null,bytes:null,error:g instanceof Error?g.message:String(g)})),()=>{f=!0}},[e]);const o=fn(n.model,160,s);if(n.error)return U.jsxs($e,{sx:{color:"danger.fg",fontSize:0},children:["Could not read the spreadsheet: ",n.error]});if(!n.model)return U.jsx($e,{as:"p",sx:{color:"fg.muted",fontSize:0,m:0},children:"Reading the spreadsheet…"});const l=n.model.sheets.length>1;return U.jsxs(ct,{model:n.model,children:[U.jsxs(he,{"data-spreadsheet-preview-sheets":n.model.sheets.length,border:"1px solid",borderColor:"border.muted",borderRadius:2,overflow:"hidden",children:[U.jsx(he,{height:o,children:U.jsx(ut,{model:n.model,"aria-label":`${t}, read-only`})}),l?U.jsx(ht,{"aria-label":`The sheets of ${t}`}):null]}),U.jsx(he,{mt:1,children:U.jsxs(Ye,{size:"small",variant:"invisible",leadingVisual:Je,onClick:()=>n.bytes&&Qe(n.bytes,t),children:["Download ",t]})})]})}export{gn as SpreadsheetPreviewView,gn as default,dn as readOnlyWorkbook};
@@ -1 +1 @@
1
- import{r as u,j as t,dl as D,e7 as L,e6 as S,bs as z,e8 as P,e9 as U,I as K,v as M,B as N}from"../datalayer-app-main.js";import{u as w,a as A,b as H,c as F,d as W,z as O,n as _,i as q,e as V,B as Y,f as G,g as J,h as Q,C as X,j as Z,S as ee,k as te,l as ae,m as se}from"./SheetTabs-BLaEhX0D.js";import{S as ne,I as oe,B as re}from"./StrikethroughIcon-CbiEuPT-.js";import{U as le,L as ie,C as ce,N as de,R as ue,a as me}from"./UnlockIcon-CKDBWE-s.js";import{S as fe}from"./SortAscIcon-CmH04s3F.js";import{S as he}from"./SortDescIcon-Qif6E10I.js";import"./KebabHorizontalIcon-D6AY8pIS.js";function pe(l){const n=w(),a=A(),o=H(),j=`'${n.sheet(a.sheet).name.replace(/'/g,"''")}'`,k=`${F(a.active.col)}${a.active.row+1}`,{content:g,value:i}=W(`${j}!${k}`),m=a.zones[a.zones.length-1],f=m.top===m.bottom&&m.left===m.right?k:O(m),[x,d]=u.useState(f),[I,y]=u.useState(!1),[h,e]=u.useState(""),r=u.useId();u.useEffect(()=>{I||d(f)},[f,I]);const c=o.edit!==null&&o.edit.sheet===a.sheet&&o.edit.row===a.active.row&&o.edit.col===a.active.col,v=c?o.edit.text:g?.formula!==void 0?`=${g.formula}`:i===null?"":typeof i=="number"?_(i):typeof i=="boolean"?i?"TRUE":"FALSE":q(i)?i.error:i;return t.jsxs("div",{role:"group","aria-label":l["aria-label"]??"Formula bar","data-cells-formula-bar":"",style:{display:"flex",alignItems:"center",gap:4,padding:4},children:[t.jsx(D,{"aria-label":"Name box",size:"small",value:x,style:{width:96},onFocus:()=>y(!0),onBlur:()=>y(!1),onChange:s=>d(s.target.value),onKeyDown:s=>{if(s.key==="Enter"){s.preventDefault();try{a.select(x.trim()),e(""),y(!1)}catch(p){e(p.message)}}else s.key==="Escape"&&(d(f),e(""))}}),t.jsx("span",{"aria-hidden":"true",style:{fontStyle:"italic",opacity:.7},children:"fx"}),t.jsx(D,{"aria-label":"Formula","aria-describedby":h?r:void 0,"aria-invalid":h?!0:void 0,size:"small",block:!0,value:v,onFocus:()=>{c||o.start()},onChange:s=>{c||o.start(),o.setText(s.target.value)},onKeyDown:s=>{if(s.key==="Enter"){s.preventDefault();const p=o.commit();e(p.ok?"":p.refusals.map(C=>C.message).join(" "))}else s.key==="Escape"&&(s.preventDefault(),o.cancel(),e(""))}}),h&&t.jsx("span",{id:r,role:"alert",style:{color:"var(--fgColor-danger, #d1242f)"},children:h})]})}function be(l){const n=V(l.reactor).all();return n.length>0?n.map(a=>({id:a.value.id,label:a.value.label})):Y.map(a=>({id:a,label:a[0].toUpperCase()+a.slice(1)}))}function ge(l){const n=w(),a=be(n);return t.jsx(L,{children:t.jsxs(S,{children:[t.jsx(S.Button,{size:"small",variant:"invisible","data-cells-chart-picker":"",children:"Insert chart"}),t.jsx(S.Overlay,{width:"small",children:t.jsx(z,{children:a.map(o=>t.jsx(z.Item,{"data-chart-type":o.id,onSelect:()=>{n.reactor.executeCommand("cells.chart.insert",{model:n,chartType:o.id}).catch(b=>l.onError?.(b.message))},children:o.label},o.id))})})]})})}const xe={bold:re,italic:oe,strikethrough:ne,undo:me,redo:ue,"sort-asc":fe,"sort-desc":he,number:de,calendar:ce,table:U,lock:ie,unlock:le},ye={"cells.bold":"bold","cells.italic":"italic","cells.underline":"underline","cells.strikethrough":"strike"};function ve(l){const n=w(),a=G(X),o=J(),b=A(),j=`${F(b.active.col)}${b.active.row+1}`,{style:k}=Q(`'${n.sheet(b.sheet).name.replace(/'/g,"''")}'!${j}`),[g,i]=u.useState(0),m=u.useRef([]),f=new Map(o.map(e=>[e.id,e])),x=a.filter(e=>f.has(e.value.command)),d=[];for(const e of x){const r=d[d.length-1];r!==void 0&&r[0].value.group===e.value.group?r.push(e):d.push([e])}const I=u.useCallback(e=>{n.reactor.executeCommand(e,{model:n}).catch(r=>l.onError?.(r.message))},[n,l]),y=e=>{const r=x.length;if(r===0)return;const c=e.key==="ArrowRight"?(g+1)%r:e.key==="ArrowLeft"?(g+r-1)%r:e.key==="Home"?0:e.key==="End"?r-1:void 0;c!==void 0&&(e.preventDefault(),i(c),m.current[c]?.focus())};let h=-1;return t.jsxs("div",{role:"toolbar","aria-label":l["aria-label"]??"Spreadsheet toolbar",onKeyDown:y,"data-cells-toolbar":"",style:{display:"flex",alignItems:"center",gap:4,flexWrap:"wrap",padding:4},children:[d.map((e,r)=>t.jsx("div",{role:"group","aria-label":e[0].value.group,style:{display:"flex",gap:2,paddingInlineEnd:4,borderInlineEnd:r<d.length-1?"1px solid var(--borderColor-muted, #d0d7de)":void 0},children:e.map(c=>{h+=1;const v=h,s=f.get(c.value.command),p=typeof s.keybinding=="string"?s.keybinding:void 0,C=p?`${s.name} (${P(p)})`:s.name,T=typeof s.octicon=="string"?xe[s.octicon]:void 0,$=ye[s.id],B={ref:R=>{m.current[v]=R},tabIndex:v===g?0:-1,onFocus:()=>i(v),onClick:()=>I(s.id),"aria-pressed":$===void 0?void 0:k[$]===!0,"data-command":s.id};return T!==void 0?t.jsx(K,{...B,icon:T,"aria-label":C,size:"small",variant:"invisible"},c.id):t.jsx(M,{...B,"aria-label":C,size:"small",variant:"invisible",children:s.name},c.id)})},r)),l.charts!==!1&&t.jsx("div",{role:"group","aria-label":"charts","data-cells-toolbar-group":"charts",children:t.jsx(ge,{onError:l.onError})})]})}const E=new Map;function ke(l){let n=E.get(l);return n||(n=ae({plugins:[se]}),E.set(l,n)),n}function $e(){E.clear()}function Be({workspace:l}){const n=l.surfaceId,a=u.useMemo(()=>ke(n),[n]);return t.jsx(Z,{model:a,children:t.jsxs(N,{"data-spreadsheet-editor":n,height:"100%",minHeight:0,display:"flex",flexDirection:"column",children:[t.jsx(ve,{}),t.jsx(pe,{}),t.jsx(N,{flex:1,minHeight:0,position:"relative",children:t.jsx(ee,{model:a,"aria-label":"Spreadsheet"})}),t.jsx(te,{})]})})}export{Be as default,$e as resetSpreadsheetWorkbooks,ke as spreadsheetWorkbook};
1
+ import{r as u,j as t,dl as D,e7 as L,e6 as S,bk as z,e8 as P,e9 as U,I as K,v as M,B as N}from"../datalayer-app-main.js";import{u as w,a as A,b as H,c as F,d as W,z as O,n as _,i as q,e as V,B as Y,f as G,g as J,h as Q,C as X,j as Z,S as ee,k as te,l as ae,m as se}from"./SheetTabs-BR72mzuo.js";import{S as ne,I as oe,B as re}from"./StrikethroughIcon-CbiEuPT-.js";import{U as le,L as ie,C as ce,N as de,R as ue,a as me}from"./UnlockIcon-CKDBWE-s.js";import{S as fe}from"./SortAscIcon-CmH04s3F.js";import{S as he}from"./SortDescIcon-Qif6E10I.js";import"./KebabHorizontalIcon-D6AY8pIS.js";function pe(l){const n=w(),a=A(),o=H(),j=`'${n.sheet(a.sheet).name.replace(/'/g,"''")}'`,k=`${F(a.active.col)}${a.active.row+1}`,{content:g,value:i}=W(`${j}!${k}`),m=a.zones[a.zones.length-1],f=m.top===m.bottom&&m.left===m.right?k:O(m),[x,d]=u.useState(f),[I,y]=u.useState(!1),[h,e]=u.useState(""),r=u.useId();u.useEffect(()=>{I||d(f)},[f,I]);const c=o.edit!==null&&o.edit.sheet===a.sheet&&o.edit.row===a.active.row&&o.edit.col===a.active.col,v=c?o.edit.text:g?.formula!==void 0?`=${g.formula}`:i===null?"":typeof i=="number"?_(i):typeof i=="boolean"?i?"TRUE":"FALSE":q(i)?i.error:i;return t.jsxs("div",{role:"group","aria-label":l["aria-label"]??"Formula bar","data-cells-formula-bar":"",style:{display:"flex",alignItems:"center",gap:4,padding:4},children:[t.jsx(D,{"aria-label":"Name box",size:"small",value:x,style:{width:96},onFocus:()=>y(!0),onBlur:()=>y(!1),onChange:s=>d(s.target.value),onKeyDown:s=>{if(s.key==="Enter"){s.preventDefault();try{a.select(x.trim()),e(""),y(!1)}catch(p){e(p.message)}}else s.key==="Escape"&&(d(f),e(""))}}),t.jsx("span",{"aria-hidden":"true",style:{fontStyle:"italic",opacity:.7},children:"fx"}),t.jsx(D,{"aria-label":"Formula","aria-describedby":h?r:void 0,"aria-invalid":h?!0:void 0,size:"small",block:!0,value:v,onFocus:()=>{c||o.start()},onChange:s=>{c||o.start(),o.setText(s.target.value)},onKeyDown:s=>{if(s.key==="Enter"){s.preventDefault();const p=o.commit();e(p.ok?"":p.refusals.map(C=>C.message).join(" "))}else s.key==="Escape"&&(s.preventDefault(),o.cancel(),e(""))}}),h&&t.jsx("span",{id:r,role:"alert",style:{color:"var(--fgColor-danger, #d1242f)"},children:h})]})}function be(l){const n=V(l.reactor).all();return n.length>0?n.map(a=>({id:a.value.id,label:a.value.label})):Y.map(a=>({id:a,label:a[0].toUpperCase()+a.slice(1)}))}function ge(l){const n=w(),a=be(n);return t.jsx(L,{children:t.jsxs(S,{children:[t.jsx(S.Button,{size:"small",variant:"invisible","data-cells-chart-picker":"",children:"Insert chart"}),t.jsx(S.Overlay,{width:"small",children:t.jsx(z,{children:a.map(o=>t.jsx(z.Item,{"data-chart-type":o.id,onSelect:()=>{n.reactor.executeCommand("cells.chart.insert",{model:n,chartType:o.id}).catch(b=>l.onError?.(b.message))},children:o.label},o.id))})})]})})}const xe={bold:re,italic:oe,strikethrough:ne,undo:me,redo:ue,"sort-asc":fe,"sort-desc":he,number:de,calendar:ce,table:U,lock:ie,unlock:le},ye={"cells.bold":"bold","cells.italic":"italic","cells.underline":"underline","cells.strikethrough":"strike"};function ve(l){const n=w(),a=G(X),o=J(),b=A(),j=`${F(b.active.col)}${b.active.row+1}`,{style:k}=Q(`'${n.sheet(b.sheet).name.replace(/'/g,"''")}'!${j}`),[g,i]=u.useState(0),m=u.useRef([]),f=new Map(o.map(e=>[e.id,e])),x=a.filter(e=>f.has(e.value.command)),d=[];for(const e of x){const r=d[d.length-1];r!==void 0&&r[0].value.group===e.value.group?r.push(e):d.push([e])}const I=u.useCallback(e=>{n.reactor.executeCommand(e,{model:n}).catch(r=>l.onError?.(r.message))},[n,l]),y=e=>{const r=x.length;if(r===0)return;const c=e.key==="ArrowRight"?(g+1)%r:e.key==="ArrowLeft"?(g+r-1)%r:e.key==="Home"?0:e.key==="End"?r-1:void 0;c!==void 0&&(e.preventDefault(),i(c),m.current[c]?.focus())};let h=-1;return t.jsxs("div",{role:"toolbar","aria-label":l["aria-label"]??"Spreadsheet toolbar",onKeyDown:y,"data-cells-toolbar":"",style:{display:"flex",alignItems:"center",gap:4,flexWrap:"wrap",padding:4},children:[d.map((e,r)=>t.jsx("div",{role:"group","aria-label":e[0].value.group,style:{display:"flex",gap:2,paddingInlineEnd:4,borderInlineEnd:r<d.length-1?"1px solid var(--borderColor-muted, #d0d7de)":void 0},children:e.map(c=>{h+=1;const v=h,s=f.get(c.value.command),p=typeof s.keybinding=="string"?s.keybinding:void 0,C=p?`${s.name} (${P(p)})`:s.name,T=typeof s.octicon=="string"?xe[s.octicon]:void 0,$=ye[s.id],B={ref:R=>{m.current[v]=R},tabIndex:v===g?0:-1,onFocus:()=>i(v),onClick:()=>I(s.id),"aria-pressed":$===void 0?void 0:k[$]===!0,"data-command":s.id};return T!==void 0?t.jsx(K,{...B,icon:T,"aria-label":C,size:"small",variant:"invisible"},c.id):t.jsx(M,{...B,"aria-label":C,size:"small",variant:"invisible",children:s.name},c.id)})},r)),l.charts!==!1&&t.jsx("div",{role:"group","aria-label":"charts","data-cells-toolbar-group":"charts",children:t.jsx(ge,{onError:l.onError})})]})}const E=new Map;function ke(l){let n=E.get(l);return n||(n=ae({plugins:[se]}),E.set(l,n)),n}function $e(){E.clear()}function Be({workspace:l}){const n=l.surfaceId,a=u.useMemo(()=>ke(n),[n]);return t.jsx(Z,{model:a,children:t.jsxs(N,{"data-spreadsheet-editor":n,height:"100%",minHeight:0,display:"flex",flexDirection:"column",children:[t.jsx(ve,{}),t.jsx(pe,{}),t.jsx(N,{flex:1,minHeight:0,position:"relative",children:t.jsx(ee,{model:a,"aria-label":"Spreadsheet"})}),t.jsx(te,{})]})})}export{Be as default,$e as resetSpreadsheetWorkbooks,ke as spreadsheetWorkbook};