@datalayer/agent-runtimes 1.5.94 → 1.5.96

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 (359) hide show
  1. package/dist-embed/chunks/{AgentDetails-zWhn8VbU.js → AgentDetails-Bi0s0fAV.js} +4 -4
  2. package/dist-embed/chunks/{AgentDetailsDialog-BJ9tHQwo.js → AgentDetailsDialog-DcHJB-46.js} +1 -1
  3. package/dist-embed/chunks/{AgentInspector-BQfnFy0r.js → AgentInspector-BoLztEWM.js} +1 -1
  4. package/dist-embed/chunks/{AgentInspectorDialog-BiiiVFrn.js → AgentInspectorDialog-BQbJv6BQ.js} +1 -1
  5. package/dist-embed/chunks/{CellSidebarExtension-FjKdLUTo.js → CellSidebarExtension-I1K60vh4.js} +8 -8
  6. package/dist-embed/chunks/{ChatView-DcNJrPAa.js → ChatView-CS0QVQQ5.js} +1 -1
  7. package/dist-embed/chunks/{ContextPie-aeACuSE7.js → ContextPie-BlO8HMfv.js} +1 -1
  8. package/dist-embed/chunks/{DeckComponent-CUOfVxcw.js → DeckComponent-pNpyII0x.js} +2 -2
  9. package/dist-embed/chunks/{DocumentView-DWwnXQS6.js → DocumentView-DH3V3gQj.js} +1 -1
  10. package/dist-embed/chunks/{EphemeralDocument-BweYum6-.js → EphemeralDocument-MgLvMU4F.js} +1 -1
  11. package/dist-embed/chunks/{EphemeralNotebook-Dv3ooyEA.js → EphemeralNotebook-DRNUs2CY.js} +2 -2
  12. package/dist-embed/chunks/{ExcalidrawComponent-CA8OqyVA.js → ExcalidrawComponent-CFCkypGk.js} +1 -1
  13. package/dist-embed/chunks/{ExcalidrawModal-DQXmoNLV.js → ExcalidrawModal-Cb2Vho79.js} +1 -1
  14. package/dist-embed/chunks/{JupyterLexicalExtension-CqTlhiP6.js → JupyterLexicalExtension-IRPTy6fp.js} +9 -9
  15. package/dist-embed/chunks/{KernelVariables-C_f1RIys.js → KernelVariables-DKDFwfHn.js} +2 -2
  16. package/dist-embed/chunks/{LexicalToolRegistry-Cpg7_Rx1.js → LexicalToolRegistry-DSuihTus.js} +2 -2
  17. package/dist-embed/chunks/{NotebookSkeleton-b2FuNWEZ.js → NotebookSkeleton-D1ewE63E.js} +1 -1
  18. package/dist-embed/chunks/{NotebookToolSurfaces-DmXn7Kor.js → NotebookToolSurfaces-B04CoSFo.js} +1 -1
  19. package/dist-embed/chunks/{NotebookToolbar-emEpc3HB.js → NotebookToolbar-Ddg2JwS8.js} +1 -1
  20. package/dist-embed/chunks/{NotebookView-Bixz7_sD.js → NotebookView-D-Lsg7D7.js} +1 -1
  21. package/dist-embed/chunks/{Output-DQqgiXji.js → Output-nrXVDS-d.js} +1 -1
  22. package/dist-embed/chunks/{SandboxDetailsDialog-DYMkoPaQ.js → SandboxDetailsDialog-DMKJZFoP.js} +1 -1
  23. package/dist-embed/chunks/{SchemaForm-BJFajfde.js → SchemaForm-DZ0DKlG1.js} +1 -1
  24. package/dist-embed/chunks/{SheetTabs-PEVltw0u.js → SheetTabs-D6IAdDy0.js} +3 -3
  25. package/dist-embed/chunks/{SpreadsheetPreviewView-DD3QxWwS.js → SpreadsheetPreviewView-Dl3kr0Bb.js} +1 -1
  26. package/dist-embed/chunks/{SpreadsheetView-BO8hcxRz.js → SpreadsheetView-nspmk7vr.js} +1 -1
  27. package/dist-embed/chunks/{Toolbar-DmDwwFcU.js → Toolbar-BDrBbL69.js} +1 -1
  28. package/dist-embed/chunks/{WidgetVariableView-BUIkjdXe.js → WidgetVariableView-DQbR4tlr.js} +1 -1
  29. package/dist-embed/chunks/{YouTubePlugin-CzVIvki8.js → YouTubePlugin-Vcoo9cJt.js} +1 -1
  30. package/dist-embed/chunks/{abnfDiagram-VCTEODGH-DJCY5YDG.js → abnfDiagram-VCTEODGH-BnR307LJ.js} +1 -1
  31. package/dist-embed/chunks/{abnfDiagram-VCTEODGH-B_3Z10oX.js → abnfDiagram-VCTEODGH-CVbtYf4Z.js} +1 -1
  32. package/dist-embed/chunks/{abnfDiagram-VCTEODGH-CtAR02W1.js → abnfDiagram-VCTEODGH-DMM-4z2i.js} +1 -1
  33. package/dist-embed/chunks/{ar-SA-G6X2FPQ2-BmTCZ5Mw.js → ar-SA-G6X2FPQ2-BSgmpt5-.js} +1 -1
  34. package/dist-embed/chunks/{architectureDiagram-5GKGNRK7-DTH4cK6d.js → architectureDiagram-5GKGNRK7-Bt2FCLqZ.js} +1 -1
  35. package/dist-embed/chunks/{architectureDiagram-5GKGNRK7-BaXccVfI.js → architectureDiagram-5GKGNRK7-Dtz5vgdG.js} +1 -1
  36. package/dist-embed/chunks/{architectureDiagram-5GKGNRK7-DRjjB28b.js → architectureDiagram-5GKGNRK7-ZkhoS04q.js} +1 -1
  37. package/dist-embed/chunks/{az-AZ-76LH7QW2-Bg2AsLUk.js → az-AZ-76LH7QW2-DdJYOut1.js} +1 -1
  38. package/dist-embed/chunks/{bg-BG-XCXSNQG7-DVQg12Gk.js → bg-BG-XCXSNQG7-CqyLLUxV.js} +1 -1
  39. package/dist-embed/chunks/{blockDiagram-868be97b-Cpnhv2XE.js → blockDiagram-868be97b-Coa_jxC5.js} +1 -1
  40. package/dist-embed/chunks/{blockDiagram-I7D4REHJ-DJz-PaS1.js → blockDiagram-I7D4REHJ-DQ8iRsgf.js} +1 -1
  41. package/dist-embed/chunks/{blockDiagram-I7D4REHJ-DUEdJIdt.js → blockDiagram-I7D4REHJ-DXMyZCA-.js} +1 -1
  42. package/dist-embed/chunks/{blockDiagram-I7D4REHJ-Cxcbuqhe.js → blockDiagram-I7D4REHJ-G6aFEbTM.js} +1 -1
  43. package/dist-embed/chunks/{bn-BD-2XOGV67Q-CBXmr4Ua.js → bn-BD-2XOGV67Q-DkvkFbHE.js} +1 -1
  44. package/dist-embed/chunks/{c4Diagram-3f4bdde3-CSM7myPZ.js → c4Diagram-3f4bdde3-DrlpIJhH.js} +1 -1
  45. package/dist-embed/chunks/{c4Diagram-7LVT6UL2-B1PU4a3-.js → c4Diagram-7LVT6UL2-BGIfXVGs.js} +1 -1
  46. package/dist-embed/chunks/{c4Diagram-7LVT6UL2-CHsjn7C0.js → c4Diagram-7LVT6UL2-Cb_4lbrT.js} +1 -1
  47. package/dist-embed/chunks/{c4Diagram-7LVT6UL2-DWNgu9wc.js → c4Diagram-7LVT6UL2-cpEH7bse.js} +1 -1
  48. package/dist-embed/chunks/{ca-ES-6MX7JW3Y-zD7sFb3S.js → ca-ES-6MX7JW3Y-BGbo8RKg.js} +1 -1
  49. package/dist-embed/chunks/{celltoolbartracker-CUVLSakK.js → celltoolbartracker-Cw0z7did.js} +1 -1
  50. package/dist-embed/chunks/{chunk-2Q5K7J3B-B0vEpe5p.js → chunk-2Q5K7J3B-Wncj3lvJ.js} +1 -1
  51. package/dist-embed/chunks/{chunk-2Q5K7J3B-BHPppWfi.js → chunk-2Q5K7J3B-hFGnBugV.js} +1 -1
  52. package/dist-embed/chunks/{chunk-2Q5K7J3B-ChHYQA8V.js → chunk-2Q5K7J3B-n5Wh4T7i.js} +1 -1
  53. package/dist-embed/chunks/{chunk-5VM5RSS4-CfhMD1Pr.js → chunk-5VM5RSS4-1iG33qxM.js} +1 -1
  54. package/dist-embed/chunks/{chunk-5VM5RSS4-CVX97Wzj.js → chunk-5VM5RSS4-BPZ17Fvc.js} +1 -1
  55. package/dist-embed/chunks/{chunk-5VM5RSS4-Ds64UIBJ.js → chunk-5VM5RSS4-C0qOJhaZ.js} +1 -1
  56. package/dist-embed/chunks/{chunk-F27PBJKO--dd6Raku.js → chunk-F27PBJKO-BZvchzhT.js} +1 -1
  57. package/dist-embed/chunks/{chunk-F27PBJKO-JXJC4xFQ.js → chunk-F27PBJKO-FQuOLMts.js} +1 -1
  58. package/dist-embed/chunks/{chunk-F27PBJKO-CsMm8LRY.js → chunk-F27PBJKO-gaxXTTyt.js} +1 -1
  59. package/dist-embed/chunks/{chunk-IMKFNOWR-ChIkVUNl.js → chunk-IMKFNOWR-Ah6SL0XE.js} +1 -1
  60. package/dist-embed/chunks/{chunk-IMKFNOWR-DnOFGl3o.js → chunk-IMKFNOWR-Ce8Jl1Cu.js} +1 -1
  61. package/dist-embed/chunks/{chunk-IMKFNOWR-BQr2SQ1D.js → chunk-IMKFNOWR-D6WqThtx.js} +1 -1
  62. package/dist-embed/chunks/{chunk-JWPE2WC7-IGZTfAqZ.js → chunk-JWPE2WC7-BiLuWg0V.js} +1 -1
  63. package/dist-embed/chunks/{chunk-JWPE2WC7-BP4iQz9X.js → chunk-JWPE2WC7-DjfDnLXf.js} +1 -1
  64. package/dist-embed/chunks/{chunk-JWPE2WC7-wWOspwt8.js → chunk-JWPE2WC7-WEMpWwN6.js} +1 -1
  65. package/dist-embed/chunks/{chunk-POPQ4Y6H-B62L0CKD.js → chunk-POPQ4Y6H-Ci1ORfKB.js} +1 -1
  66. package/dist-embed/chunks/{chunk-POPQ4Y6H-Bw3Acvcv.js → chunk-POPQ4Y6H-D1zcv3TO.js} +1 -1
  67. package/dist-embed/chunks/{chunk-POPQ4Y6H-Daj2aQX7.js → chunk-POPQ4Y6H-DGo-c1gA.js} +1 -1
  68. package/dist-embed/chunks/{chunk-SVP7TREG-DfE4zWGL.js → chunk-SVP7TREG-BNbFIqtk.js} +1 -1
  69. package/dist-embed/chunks/{chunk-SVP7TREG-BmzVOqOi.js → chunk-SVP7TREG-Dp25klfn.js} +1 -1
  70. package/dist-embed/chunks/{chunk-SVP7TREG-CsDJ43fo.js → chunk-SVP7TREG-Dw-r79VX.js} +1 -1
  71. package/dist-embed/chunks/{chunk-TICWLB2K-DNtjNDty.js → chunk-TICWLB2K-BGlpRZHG.js} +1 -1
  72. package/dist-embed/chunks/{chunk-TICWLB2K-D4Z6a5tZ.js → chunk-TICWLB2K-Cdu1LH0d.js} +1 -1
  73. package/dist-embed/chunks/{chunk-TICWLB2K-DqqbHq6H.js → chunk-TICWLB2K-mR6tLG7x.js} +1 -1
  74. package/dist-embed/chunks/{chunk-XXDRQBXY-8Iy52v96.js → chunk-XXDRQBXY-Frt_zuHl.js} +1 -1
  75. package/dist-embed/chunks/{chunk-XXDRQBXY-CgdyGwP0.js → chunk-XXDRQBXY-Qb6D0SQd.js} +1 -1
  76. package/dist-embed/chunks/{chunk-XXDRQBXY-IFnSvNyf.js → chunk-XXDRQBXY-THCdSzRs.js} +1 -1
  77. package/dist-embed/chunks/{classDiagram-ZZMXUADV-Cq0pfC8N.js → classDiagram-ZZMXUADV-DQkKVwjv.js} +1 -1
  78. package/dist-embed/chunks/{classDiagram-ZZMXUADV-BJGOVdtk.js → classDiagram-ZZMXUADV-DVQyGWdi.js} +1 -1
  79. package/dist-embed/chunks/{classDiagram-ZZMXUADV-BqJJaF-F.js → classDiagram-ZZMXUADV-MmqdRe8H.js} +1 -1
  80. package/dist-embed/chunks/{classDiagram-f62afe4f-DWWYXHVw.js → classDiagram-f62afe4f-D5_ocBdB.js} +1 -1
  81. package/dist-embed/chunks/{classDiagram-v2-604399ef-DDQJlSCd.js → classDiagram-v2-604399ef-DW4EPvpW.js} +1 -1
  82. package/dist-embed/chunks/{classDiagram-v2-VYDZK3BY-Cq0pfC8N.js → classDiagram-v2-VYDZK3BY-DQkKVwjv.js} +1 -1
  83. package/dist-embed/chunks/{classDiagram-v2-VYDZK3BY-BJGOVdtk.js → classDiagram-v2-VYDZK3BY-DVQyGWdi.js} +1 -1
  84. package/dist-embed/chunks/{classDiagram-v2-VYDZK3BY-BqJJaF-F.js → classDiagram-v2-VYDZK3BY-MmqdRe8H.js} +1 -1
  85. package/dist-embed/chunks/{code-block-IT6T5CEO-BG9nTZfk.js → code-block-IT6T5CEO-JFor4YAD.js} +1 -1
  86. package/dist-embed/chunks/{component-B-Z2wxoX.js → component-C8C1Quml.js} +1 -1
  87. package/dist-embed/chunks/{cose-bilkent-JH36ORCC-B9LR7A5e.js → cose-bilkent-JH36ORCC-BQyw1y1U.js} +1 -1
  88. package/dist-embed/chunks/{cose-bilkent-JH36ORCC-DVbhW4d6.js → cose-bilkent-JH36ORCC-C_tMYGtf.js} +1 -1
  89. package/dist-embed/chunks/{cose-bilkent-JH36ORCC-Bn_bUKxa.js → cose-bilkent-JH36ORCC-CsAENBdP.js} +1 -1
  90. package/dist-embed/chunks/{createText-aed3d8b3-DlE4oIZ9.js → createText-aed3d8b3-CMnWQblC.js} +1 -1
  91. package/dist-embed/chunks/{cs-CZ-2BRQDIVT-D45-n1qX.js → cs-CZ-2BRQDIVT-CDANWU11.js} +1 -1
  92. package/dist-embed/chunks/{cynefinDiagram-5FMLGOSQ-CKpvl-b4.js → cynefinDiagram-5FMLGOSQ-6YzZCz6x.js} +1 -1
  93. package/dist-embed/chunks/{cynefinDiagram-5FMLGOSQ-DFRNXRSb.js → cynefinDiagram-5FMLGOSQ-Cq4XKqVa.js} +1 -1
  94. package/dist-embed/chunks/{cynefinDiagram-5FMLGOSQ-Bml1hn2J.js → cynefinDiagram-5FMLGOSQ-DIkKdCg7.js} +1 -1
  95. package/dist-embed/chunks/{da-DK-5WZEPLOC-B2tW8S5P.js → da-DK-5WZEPLOC-DwmgcOxN.js} +1 -1
  96. package/dist-embed/chunks/{dagre-GXQ25YYZ-DRX7Xgxg.js → dagre-GXQ25YYZ-BkueS0KV.js} +1 -1
  97. package/dist-embed/chunks/{dagre-GXQ25YYZ-BR6LUNaJ.js → dagre-GXQ25YYZ-CPco-SxY.js} +1 -1
  98. package/dist-embed/chunks/{dagre-GXQ25YYZ-sw0dVYun.js → dagre-GXQ25YYZ-n9sjDOqg.js} +1 -1
  99. package/dist-embed/chunks/{de-DE-XR44H4JA-C0l4YWe4.js → de-DE-XR44H4JA-l2943EP0.js} +1 -1
  100. package/dist-embed/chunks/{diagram-S7CK7UJ4-DCht8UFm.js → diagram-S7CK7UJ4-CrcfBLvv.js} +1 -1
  101. package/dist-embed/chunks/{diagram-S7CK7UJ4-C7kqshyQ.js → diagram-S7CK7UJ4-DYtNkxjk.js} +1 -1
  102. package/dist-embed/chunks/{diagram-S7CK7UJ4-BwQD-PwU.js → diagram-S7CK7UJ4-jZdRq6wu.js} +1 -1
  103. package/dist-embed/chunks/{diagram-UQ7AKVKN-BmyN5XI8.js → diagram-UQ7AKVKN-B9ZTK0Te.js} +1 -1
  104. package/dist-embed/chunks/{diagram-UQ7AKVKN-BmTWzWzZ.js → diagram-UQ7AKVKN-BdRY39AK.js} +1 -1
  105. package/dist-embed/chunks/{diagram-UQ7AKVKN-BaBnGmVS.js → diagram-UQ7AKVKN-CAYDX7Bd.js} +1 -1
  106. package/dist-embed/chunks/{diagram-VSXAHHWV-DWCHK-43.js → diagram-VSXAHHWV-CcaaK20P.js} +1 -1
  107. package/dist-embed/chunks/{diagram-VSXAHHWV-DVYBtYtK.js → diagram-VSXAHHWV-CxMii8H2.js} +1 -1
  108. package/dist-embed/chunks/{diagram-VSXAHHWV-BzDVUwzb.js → diagram-VSXAHHWV-Dt-I1eKY.js} +1 -1
  109. package/dist-embed/chunks/{diagram-VX7I27RA-DZw1ijDZ.js → diagram-VX7I27RA-D8bhlh3r.js} +1 -1
  110. package/dist-embed/chunks/{diagram-VX7I27RA-BIn5zbHp.js → diagram-VX7I27RA-DcbG7Tne.js} +1 -1
  111. package/dist-embed/chunks/{diagram-VX7I27RA-D_ubgMFK.js → diagram-VX7I27RA-DwX1uaCx.js} +1 -1
  112. package/dist-embed/chunks/{diagram-Z3DM3KII-DV4GXIB9.js → diagram-Z3DM3KII-C9dar5bS.js} +1 -1
  113. package/dist-embed/chunks/{diagram-Z3DM3KII-dMZ7Fpuw.js → diagram-Z3DM3KII-CeM42DVq.js} +1 -1
  114. package/dist-embed/chunks/{diagram-Z3DM3KII-C4EhNhYj.js → diagram-Z3DM3KII-fyF7IFt-.js} +1 -1
  115. package/dist-embed/chunks/{ebnfDiagram-PWID7BFC-DGE5iEf-.js → ebnfDiagram-PWID7BFC-B0F4iy5P.js} +1 -1
  116. package/dist-embed/chunks/{ebnfDiagram-PWID7BFC-BX3-evby.js → ebnfDiagram-PWID7BFC-COj5ulCD.js} +1 -1
  117. package/dist-embed/chunks/{ebnfDiagram-PWID7BFC-CT2xQQba.js → ebnfDiagram-PWID7BFC-Df0coz-U.js} +1 -1
  118. package/dist-embed/chunks/{edges-b2856ca0-0fbzACg6.js → edges-b2856ca0-ZiofUaoz.js} +1 -1
  119. package/dist-embed/chunks/{el-GR-BZB4AONW-B_YulamW.js → el-GR-BZB4AONW-Csfuo4E5.js} +1 -1
  120. package/dist-embed/chunks/{erDiagram-5d81789a-DXW16wCs.js → erDiagram-5d81789a-RepZY3NM.js} +1 -1
  121. package/dist-embed/chunks/{erDiagram-RLTQ6QDP-C2Zh71Nb.js → erDiagram-RLTQ6QDP-B5eHyTSb.js} +1 -1
  122. package/dist-embed/chunks/{erDiagram-RLTQ6QDP-Bru5UKrT.js → erDiagram-RLTQ6QDP-BulLtxKT.js} +1 -1
  123. package/dist-embed/chunks/{erDiagram-RLTQ6QDP-BzECyujy.js → erDiagram-RLTQ6QDP-CdBi4-uF.js} +1 -1
  124. package/dist-embed/chunks/{es-ES-U4NZUMDT-guNHUX4D.js → es-ES-U4NZUMDT-Barmg8lW.js} +1 -1
  125. package/dist-embed/chunks/{eu-ES-A7QVB2H4-BLG84_zR.js → eu-ES-A7QVB2H4-bSfPMjGm.js} +1 -1
  126. package/dist-embed/chunks/{fa-IR-HGAKTJCU-BtJ9p_Hg.js → fa-IR-HGAKTJCU-9wWNbyPp.js} +1 -1
  127. package/dist-embed/chunks/{fi-FI-Z5N7JZ37-CBa7Oegw.js → fi-FI-Z5N7JZ37-BwYpCx0e.js} +1 -1
  128. package/dist-embed/chunks/{flowDb-185abca5-5lj6SWgz.js → flowDb-185abca5-DjN9NKb1.js} +1 -1
  129. package/dist-embed/chunks/{flowDiagram-1629c991-DGzm4nlk.js → flowDiagram-1629c991-BvOM7G2N.js} +1 -1
  130. package/dist-embed/chunks/{flowDiagram-HODETNUW-DRH2E3xm.js → flowDiagram-HODETNUW-3KNlQIm_.js} +1 -1
  131. package/dist-embed/chunks/{flowDiagram-HODETNUW-DXQP-if5.js → flowDiagram-HODETNUW-BCEPp4ad.js} +1 -1
  132. package/dist-embed/chunks/{flowDiagram-HODETNUW-BjYGpRc0.js → flowDiagram-HODETNUW-CXD13cZH.js} +1 -1
  133. package/dist-embed/chunks/{flowDiagram-v2-1d953310-B4d06-22.js → flowDiagram-v2-1d953310-DhnQn8Nr.js} +1 -1
  134. package/dist-embed/chunks/{flowchart-elk-definition-6df44142-Bc6Dt1HZ.js → flowchart-elk-definition-6df44142-BqgdASPv.js} +1 -1
  135. package/dist-embed/chunks/{fr-FR-RHASNOE6-SpBaTvic.js → fr-FR-RHASNOE6-BDJ0uslp.js} +1 -1
  136. package/dist-embed/chunks/{ganttDiagram-3b0b3873-p5V6eFY7.js → ganttDiagram-3b0b3873-qKAuWTsd.js} +1 -1
  137. package/dist-embed/chunks/{ganttDiagram-EL5Y4UJY-Bpn47wNG.js → ganttDiagram-EL5Y4UJY-CI7N1FH6.js} +1 -1
  138. package/dist-embed/chunks/{ganttDiagram-EL5Y4UJY-D4tDthvl.js → ganttDiagram-EL5Y4UJY-Dk94wE3f.js} +1 -1
  139. package/dist-embed/chunks/{ganttDiagram-EL5Y4UJY-B4P4PMdh.js → ganttDiagram-EL5Y4UJY-dHpetUk-.js} +1 -1
  140. package/dist-embed/chunks/{gitGraphDiagram-WWUBYQGX-wYIzu2Xn.js → gitGraphDiagram-WWUBYQGX-2qOrIdt0.js} +1 -1
  141. package/dist-embed/chunks/{gitGraphDiagram-WWUBYQGX-aPF9w3Ye.js → gitGraphDiagram-WWUBYQGX-BODb2uT3.js} +1 -1
  142. package/dist-embed/chunks/{gitGraphDiagram-WWUBYQGX-DCycanv0.js → gitGraphDiagram-WWUBYQGX-D57Klnd8.js} +1 -1
  143. package/dist-embed/chunks/{gitGraphDiagram-f01e8bc2-Be27j7Xc.js → gitGraphDiagram-f01e8bc2-CB6fU3iE.js} +1 -1
  144. package/dist-embed/chunks/{gl-ES-HMX3MZ6V-C_CVQKTZ.js → gl-ES-HMX3MZ6V-Jphst371.js} +1 -1
  145. package/dist-embed/chunks/{he-IL-6SHJWFNN-CdeB6V7Y.js → he-IL-6SHJWFNN-Dq3r101K.js} +1 -1
  146. package/dist-embed/chunks/{hi-IN-IWLTKZ5I-CV6PUMLG.js → hi-IN-IWLTKZ5I-8B89dnMh.js} +1 -1
  147. package/dist-embed/chunks/{hu-HU-A5ZG7DT2-B8zqWAqi.js → hu-HU-A5ZG7DT2-CW5VclQQ.js} +1 -1
  148. package/dist-embed/chunks/{id-ID-SAP4L64H-BGEGnVxZ.js → id-ID-SAP4L64H-glKtNYpe.js} +1 -1
  149. package/dist-embed/chunks/{index-B1gxsONw.js → index-23xUfUK3.js} +1 -1
  150. package/dist-embed/chunks/{index-9bae90f3-kp9m9pOo.js → index-9bae90f3-CNczxBwD.js} +1 -1
  151. package/dist-embed/chunks/{index-vP7XtLT3.js → index-B1hVcCeL.js} +4 -4
  152. package/dist-embed/chunks/{index-DeyObBPy.js → index-B5Ar2C76.js} +1 -1
  153. package/dist-embed/chunks/{index-Dd3vBS-q.js → index-B5qB2n6R.js} +1 -1
  154. package/dist-embed/chunks/{index-CPwLAUDD.js → index-B6pSvSsm.js} +4 -4
  155. package/dist-embed/chunks/{index-CdapZifU.js → index-BDTquNK1.js} +1 -1
  156. package/dist-embed/chunks/{index-cHhthoh9.js → index-BEHCLH59.js} +1 -1
  157. package/dist-embed/chunks/{index-Dd5YgCU7.js → index-BFH1nmiJ.js} +1 -1
  158. package/dist-embed/chunks/{index-4t0OAxoh.js → index-BHHOSjZo.js} +2 -2
  159. package/dist-embed/chunks/{index-D-cPydK0.js → index-BM2hYh8Q.js} +1 -1
  160. package/dist-embed/chunks/{index-CJ9gXzDP.js → index-BW_-m6b-.js} +1 -1
  161. package/dist-embed/chunks/{index-D2QeDbAK.js → index-BWuVbZWH.js} +2 -2
  162. package/dist-embed/chunks/{index-DSw0yPWI.js → index-BgxqJ9_L.js} +1 -1
  163. package/dist-embed/chunks/{index-C7nrczhK.js → index-Bq90Fbc4.js} +1 -1
  164. package/dist-embed/chunks/{index-CBSdkrZu.js → index-BuNU8ABo.js} +1 -1
  165. package/dist-embed/chunks/{index-Dxmji156.js → index-C66Vbs6F.js} +1 -1
  166. package/dist-embed/chunks/{index-C8fVAzpb.js → index-CTr6-SsV.js} +1 -1
  167. package/dist-embed/chunks/{index-DbGATA2k.js → index-CYAoF-g4.js} +1 -1
  168. package/dist-embed/chunks/{index-DsioLFJS.js → index-CYUvojfN.js} +2 -2
  169. package/dist-embed/chunks/{index-DtlCGyVw.js → index-CZGjZxFf.js} +1 -1
  170. package/dist-embed/chunks/{index-Cc3y4dMQ.js → index-CgItmZMM.js} +4 -4
  171. package/dist-embed/chunks/{index-CWieStDj.js → index-CkFaHglB.js} +4 -4
  172. package/dist-embed/chunks/{index-B9zmTK3l.js → index-CnIHrGr-.js} +1 -1
  173. package/dist-embed/chunks/{index-Bzz7SUQ8.js → index-CtOE7MGN.js} +6 -6
  174. package/dist-embed/chunks/{index-DTYRIj8A.js → index-D3C4W1e1.js} +1 -1
  175. package/dist-embed/chunks/{index-xsqU1Upe.js → index-DIaoQxKH.js} +1 -1
  176. package/dist-embed/chunks/{index-Cq5HA4MJ.js → index-DKiNGAN5.js} +1 -1
  177. package/dist-embed/chunks/{index-aWBgejNs.js → index-DPr4u5vQ.js} +2 -2
  178. package/dist-embed/chunks/{index-Fh2BKjEJ.js → index-DckpK9sw.js} +1 -1
  179. package/dist-embed/chunks/{index-CCvelf1K.js → index-DtDFBOl9.js} +1 -1
  180. package/dist-embed/chunks/{index-Bh8xHTp_.js → index-H4p_UVsf.js} +5 -5
  181. package/dist-embed/chunks/{index-B-0wzsZj.js → index-kIY4bTgE.js} +1 -1
  182. package/dist-embed/chunks/{index-CQPzQ05p.js → index-nOhqCuwU.js} +4 -4
  183. package/dist-embed/chunks/{index-DGx1w2FG.js → index-w0c9DMN0.js} +1 -1
  184. package/dist-embed/chunks/{index-oh85LAjq.js → index-xmcTHVsH.js} +14 -14
  185. package/dist-embed/chunks/{index-MbAP6rXZ.js → index-zYmeKXxb.js} +1 -1
  186. package/dist-embed/chunks/{index.esm-LnnLBihr.js → index.esm-CWcjqNjR.js} +1 -1
  187. package/dist-embed/chunks/{index.esm-xikWUBGf.js → index.esm-zOy6kFPv.js} +1 -1
  188. package/dist-embed/chunks/{infoDiagram-27XIBGKW-06T_Gyg3.js → infoDiagram-27XIBGKW-CF4qMRpl.js} +1 -1
  189. package/dist-embed/chunks/{infoDiagram-27XIBGKW-BTgF7bPF.js → infoDiagram-27XIBGKW-drOzO4SB.js} +1 -1
  190. package/dist-embed/chunks/{infoDiagram-27XIBGKW-D-ROTMNL.js → infoDiagram-27XIBGKW-wn3LxC14.js} +1 -1
  191. package/dist-embed/chunks/{infoDiagram-a29d40f1-BWkxuHa5.js → infoDiagram-a29d40f1-REMs6KOr.js} +1 -1
  192. package/dist-embed/chunks/{isEqual-DitljbGA.js → isEqual-zPmcQAke.js} +1 -1
  193. package/dist-embed/chunks/{ishikawaDiagram-5VMMS53U-itmt4k-4.js → ishikawaDiagram-5VMMS53U-atVe3g88.js} +1 -1
  194. package/dist-embed/chunks/{ishikawaDiagram-5VMMS53U-Bjxh2IeU.js → ishikawaDiagram-5VMMS53U-g9P7XeQ7.js} +1 -1
  195. package/dist-embed/chunks/{ishikawaDiagram-5VMMS53U-CyQlbAkf.js → ishikawaDiagram-5VMMS53U-ykVOWtHE.js} +1 -1
  196. package/dist-embed/chunks/{it-IT-JPQ66NNP-BuDOnC-Y.js → it-IT-JPQ66NNP-B-ahG0CB.js} +1 -1
  197. package/dist-embed/chunks/{ja-JP-DBVTYXUO-ZiJPJg_x.js → ja-JP-DBVTYXUO-5JyLIwOs.js} +1 -1
  198. package/dist-embed/chunks/{journeyDiagram-3NMN7TZE-B_i8vEMe.js → journeyDiagram-3NMN7TZE-BMXUCxse.js} +1 -1
  199. package/dist-embed/chunks/{journeyDiagram-3NMN7TZE-C4oK4cQV.js → journeyDiagram-3NMN7TZE-Bjti-927.js} +1 -1
  200. package/dist-embed/chunks/{journeyDiagram-3NMN7TZE-DjbHb60A.js → journeyDiagram-3NMN7TZE-DUyUItoc.js} +1 -1
  201. package/dist-embed/chunks/{journeyDiagram-95396277-NGLK0sv9.js → journeyDiagram-95396277-B9L_UQQW.js} +1 -1
  202. package/dist-embed/chunks/{kaa-6HZHGXH3-B05Co2_0.js → kaa-6HZHGXH3-BIVYWYQP.js} +1 -1
  203. package/dist-embed/chunks/{kab-KAB-ZGHBKWFO-BFWwUTFX.js → kab-KAB-ZGHBKWFO-DVL8cRgk.js} +1 -1
  204. package/dist-embed/chunks/{kanban-definition-UXKFOSKX-CQHol1Ib.js → kanban-definition-UXKFOSKX-BcbVekZs.js} +1 -1
  205. package/dist-embed/chunks/{kanban-definition-UXKFOSKX-7MVHSdeg.js → kanban-definition-UXKFOSKX-ClVtSIhc.js} +1 -1
  206. package/dist-embed/chunks/{kanban-definition-UXKFOSKX-Ctj8o_cm.js → kanban-definition-UXKFOSKX-CmWGlZ0H.js} +1 -1
  207. package/dist-embed/chunks/{kk-KZ-P5N5QNE5-DqqZtsBn.js → kk-KZ-P5N5QNE5-KOEMwerS.js} +1 -1
  208. package/dist-embed/chunks/{km-KH-HSX4SM5Z-tXdj73d6.js → km-KH-HSX4SM5Z-CDH3ezLN.js} +1 -1
  209. package/dist-embed/chunks/{ko-KR-MTYHY66A-ZzVvd33o.js → ko-KR-MTYHY66A-Bmb-D285.js} +1 -1
  210. package/dist-embed/chunks/{ku-TR-6OUDTVRD-Cmo7xpcx.js → ku-TR-6OUDTVRD-BuhkTBbp.js} +1 -1
  211. package/dist-embed/chunks/{layout-CMavZfEN.js → layout-CIqBEWvO.js} +1 -1
  212. package/dist-embed/chunks/{layout-CVXurUAo.js → layout-DAiowMz2.js} +1 -1
  213. package/dist-embed/chunks/{layout-D6vp03y-.js → layout-LTmWPIeE.js} +1 -1
  214. package/dist-embed/chunks/{lexicalHooks-DY7QAcah.js → lexicalHooks-CKdIdyZ8.js} +1 -1
  215. package/dist-embed/chunks/{lt-LT-XHIRWOB4-xELzKp5t.js → lt-LT-XHIRWOB4-584bUjqP.js} +1 -1
  216. package/dist-embed/chunks/{lv-LV-5QDEKY6T-BzJDkdYT.js → lv-LV-5QDEKY6T-CkTBsD-R.js} +1 -1
  217. package/dist-embed/chunks/{mermaid.core-DoHaKouU.js → mermaid.core-CIytoWBO.js} +3 -3
  218. package/dist-embed/chunks/{mermaid.core-BrTwjZHj.js → mermaid.core-RXtCLUM0.js} +5 -5
  219. package/dist-embed/chunks/{mindmap-definition-YA3MSWOX-DJKalBH_.js → mindmap-definition-YA3MSWOX-B11GPGu3.js} +1 -1
  220. package/dist-embed/chunks/{mindmap-definition-YA3MSWOX-oSF-ay7t.js → mindmap-definition-YA3MSWOX-CGIHCY64.js} +1 -1
  221. package/dist-embed/chunks/{mindmap-definition-YA3MSWOX-C1GAPhx9.js → mindmap-definition-YA3MSWOX-MoPLOrcw.js} +1 -1
  222. package/dist-embed/chunks/{mindmap-definition-e4c1d938-pfMk2crv.js → mindmap-definition-e4c1d938-D_grZmp7.js} +1 -1
  223. package/dist-embed/chunks/{mr-IN-CRQNXWMA-CjOV2Fgl.js → mr-IN-CRQNXWMA-0Xba6kSJ.js} +1 -1
  224. package/dist-embed/chunks/{my-MM-5M5IBNSE-Cu1gYEx6.js → my-MM-5M5IBNSE-B09FZKSd.js} +1 -1
  225. package/dist-embed/chunks/{nb-NO-T6EIAALU-BEvsHGE0.js → nb-NO-T6EIAALU-BpCjfVUo.js} +1 -1
  226. package/dist-embed/chunks/{nl-NL-IS3SIHDZ-DKA6CYS6.js → nl-NL-IS3SIHDZ-IMA72Wj7.js} +1 -1
  227. package/dist-embed/chunks/{nn-NO-6E72VCQL-CAxiSlw0.js → nn-NO-6E72VCQL-BvFt5eEP.js} +1 -1
  228. package/dist-embed/chunks/{oc-FR-POXYY2M6-Cnw3_UEL.js → oc-FR-POXYY2M6-QMGUoXMd.js} +1 -1
  229. package/dist-embed/chunks/{pa-IN-N4M65BXN-B95dVQXb.js → pa-IN-N4M65BXN-a8dOum4D.js} +1 -1
  230. package/dist-embed/chunks/{pegDiagram-XKGWAZYB-snSGi40-.js → pegDiagram-XKGWAZYB-CXd1v4RS.js} +1 -1
  231. package/dist-embed/chunks/{pegDiagram-XKGWAZYB-C4BPuZD3.js → pegDiagram-XKGWAZYB-DTT8e_Vu.js} +1 -1
  232. package/dist-embed/chunks/{pegDiagram-XKGWAZYB-Daqlobjl.js → pegDiagram-XKGWAZYB-DkCI0q8Y.js} +1 -1
  233. package/dist-embed/chunks/{percentages-BXMCSKIN-B0ORTdXz.js → percentages-BXMCSKIN-Ck3DaSng.js} +6 -6
  234. package/dist-embed/chunks/{pica-D5t8EAkp.js → pica-io9rFAcX.js} +1 -1
  235. package/dist-embed/chunks/{pieDiagram-E7YTZNPT-CbUWXjCK.js → pieDiagram-E7YTZNPT-2Glo3MKw.js} +1 -1
  236. package/dist-embed/chunks/{pieDiagram-E7YTZNPT-BDGAjNk2.js → pieDiagram-E7YTZNPT-B4P8wCma.js} +1 -1
  237. package/dist-embed/chunks/{pieDiagram-E7YTZNPT-X2wS3_bC.js → pieDiagram-E7YTZNPT-D6zxicZn.js} +1 -1
  238. package/dist-embed/chunks/{pieDiagram-c941bede-BItRZOJx.js → pieDiagram-c941bede-Cqi77jMu.js} +1 -1
  239. package/dist-embed/chunks/{pl-PL-T2D74RX3-CBpTbSVL.js → pl-PL-T2D74RX3-BS06UMKK.js} +1 -1
  240. package/dist-embed/chunks/{plugin-BH7Rtuwm.js → plugin-DE0vZ9p3.js} +1 -1
  241. package/dist-embed/chunks/{plugin-B3LgqnRn.js → plugin-ihQPqJPB.js} +1 -1
  242. package/dist-embed/chunks/portable-DeuNvN1G.js +1 -0
  243. package/dist-embed/chunks/{pt-BR-5N22H2LF-CddNlro1.js → pt-BR-5N22H2LF-BIO1KViR.js} +1 -1
  244. package/dist-embed/chunks/{pt-PT-UZXXM6DQ-BBP4-9-R.js → pt-PT-UZXXM6DQ-BZuZ9OiO.js} +1 -1
  245. package/dist-embed/chunks/{quadrantDiagram-AXDQQJYC-Ca20yCfd.js → quadrantDiagram-AXDQQJYC-C_CEGa46.js} +1 -1
  246. package/dist-embed/chunks/{quadrantDiagram-AXDQQJYC-DPM18rUD.js → quadrantDiagram-AXDQQJYC-DSBKUuiq.js} +1 -1
  247. package/dist-embed/chunks/{quadrantDiagram-AXDQQJYC-B-lUCUO_.js → quadrantDiagram-AXDQQJYC-xiPOrF1K.js} +1 -1
  248. package/dist-embed/chunks/{quadrantDiagram-cf8b8fe0-CNyFHMHt.js → quadrantDiagram-cf8b8fe0-BMOuDGDF.js} +1 -1
  249. package/dist-embed/chunks/{railroadDiagram-O6MQD6OU-1C5f6wZm.js → railroadDiagram-O6MQD6OU-BgrbSE40.js} +1 -1
  250. package/dist-embed/chunks/{railroadDiagram-O6MQD6OU-DgZE9w0R.js → railroadDiagram-O6MQD6OU-CSD5KLnV.js} +1 -1
  251. package/dist-embed/chunks/{railroadDiagram-O6MQD6OU-UAOTUQFl.js → railroadDiagram-O6MQD6OU-DjTUEumb.js} +1 -1
  252. package/dist-embed/chunks/{renderer-DgyUd7NL.js → renderer-BU04-DkJ.js} +1 -1
  253. package/dist-embed/chunks/{requirementDiagram-53bda41b-B9QIXB-0.js → requirementDiagram-53bda41b-DKlphVxw.js} +1 -1
  254. package/dist-embed/chunks/{requirementDiagram-BXWQKSXE-u5T3XPNu.js → requirementDiagram-BXWQKSXE-BXaCAhpq.js} +1 -1
  255. package/dist-embed/chunks/{requirementDiagram-BXWQKSXE-B8vOAmrx.js → requirementDiagram-BXWQKSXE-CnRk1roG.js} +1 -1
  256. package/dist-embed/chunks/{requirementDiagram-BXWQKSXE-Ce83Z3oz.js → requirementDiagram-BXWQKSXE-DMdw9yP9.js} +1 -1
  257. package/dist-embed/chunks/{ro-RO-JPDTUUEW-BHCc25-Q.js → ro-RO-JPDTUUEW-Cr8vd9Pv.js} +1 -1
  258. package/dist-embed/chunks/{ru-RU-B4JR7IUQ-D0Fd3ren.js → ru-RU-B4JR7IUQ-Dht1kDyT.js} +1 -1
  259. package/dist-embed/chunks/{sankeyDiagram-P5KCCOFB-DE-aB_Xz.js → sankeyDiagram-P5KCCOFB-BS7hu1AF.js} +1 -1
  260. package/dist-embed/chunks/{sankeyDiagram-P5KCCOFB-C1mHPY7k.js → sankeyDiagram-P5KCCOFB-CzrCH920.js} +1 -1
  261. package/dist-embed/chunks/{sankeyDiagram-P5KCCOFB-BPeSLev7.js → sankeyDiagram-P5KCCOFB-okgEVTpa.js} +1 -1
  262. package/dist-embed/chunks/{sankeyDiagram-c3ef121a-CnWhSjKH.js → sankeyDiagram-c3ef121a-Dg6SbJjG.js} +1 -1
  263. package/dist-embed/chunks/{sequenceDiagram-82a5b84f-CTQ0WQxj.js → sequenceDiagram-82a5b84f-DE09oDEu.js} +1 -1
  264. package/dist-embed/chunks/{sequenceDiagram-WJ2MYXX4-IgZn-nni.js → sequenceDiagram-WJ2MYXX4-Bb3A79mo.js} +1 -1
  265. package/dist-embed/chunks/{sequenceDiagram-WJ2MYXX4-DsWgJxIQ.js → sequenceDiagram-WJ2MYXX4-C7v6HXxx.js} +1 -1
  266. package/dist-embed/chunks/{sequenceDiagram-WJ2MYXX4-DfGaDzPn.js → sequenceDiagram-WJ2MYXX4-CtR3Mxli.js} +1 -1
  267. package/dist-embed/chunks/{sessions-jGahwF6o.js → sessions-CnTFUfGi.js} +1 -1
  268. package/dist-embed/chunks/{si-LK-N5RQ5JYF-CkzbO-53.js → si-LK-N5RQ5JYF-B2xq7Zbi.js} +1 -1
  269. package/dist-embed/chunks/{sizeCapture-INFHLROL-B3GqP69B.js → sizeCapture-INFHLROL-CU32UBMk.js} +1 -1
  270. package/dist-embed/chunks/{sizeCapture-INFHLROL-VNiMzW-9.js → sizeCapture-INFHLROL-D5hzqzwD.js} +1 -1
  271. package/dist-embed/chunks/{sizeCapture-INFHLROL-CDhcfQR9.js → sizeCapture-INFHLROL-TdDsBg4W.js} +1 -1
  272. package/dist-embed/chunks/{sk-SK-C5VTKIMK-DgdXop0H.js → sk-SK-C5VTKIMK-Sw5YFSH1.js} +1 -1
  273. package/dist-embed/chunks/{sl-SI-NN7IZMDC-BMzYr7mj.js → sl-SI-NN7IZMDC-DZin2Uyg.js} +1 -1
  274. package/dist-embed/chunks/{stateDiagram-43e79a5f-yo7m95H6.js → stateDiagram-43e79a5f-uKY_K58g.js} +1 -1
  275. package/dist-embed/chunks/{stateDiagram-D77RDMKH-C2ft8KQa.js → stateDiagram-D77RDMKH-CY5udAKA.js} +1 -1
  276. package/dist-embed/chunks/{stateDiagram-D77RDMKH-CQHhs9El.js → stateDiagram-D77RDMKH-Cd_HasWU.js} +1 -1
  277. package/dist-embed/chunks/{stateDiagram-D77RDMKH-w3LtGTs_.js → stateDiagram-D77RDMKH-mOMKyP5U.js} +1 -1
  278. package/dist-embed/chunks/{stateDiagram-v2-2041ed4f-BWbH2lJG.js → stateDiagram-v2-2041ed4f-Cz97TKZ0.js} +1 -1
  279. package/dist-embed/chunks/{stateDiagram-v2-MP3YSRHH-IyUF4GcX.js → stateDiagram-v2-MP3YSRHH-2ASMATIX.js} +1 -1
  280. package/dist-embed/chunks/{stateDiagram-v2-MP3YSRHH-BWh1UldZ.js → stateDiagram-v2-MP3YSRHH-BJVCwCLk.js} +1 -1
  281. package/dist-embed/chunks/{stateDiagram-v2-MP3YSRHH-DOnaFq36.js → stateDiagram-v2-MP3YSRHH-hXyOMGYK.js} +1 -1
  282. package/dist-embed/chunks/{styles-455b33cd-B3UABG-p.js → styles-455b33cd-QxOIl59n.js} +1 -1
  283. package/dist-embed/chunks/{styles-f932cba9-CSFx2lve.js → styles-f932cba9-CRW7ybKl.js} +1 -1
  284. package/dist-embed/chunks/{styles-fcc2142b-COoZpTHz.js → styles-fcc2142b-lNkMjC8Z.js} +1 -1
  285. package/dist-embed/chunks/{subset-shared.chunk-BV_IsKIh.js → subset-shared.chunk-C8kMR6Ea.js} +1 -1
  286. package/dist-embed/chunks/{subset-worker.chunk-DOQj3F8p.js → subset-worker.chunk-BeXpWPn3.js} +1 -1
  287. package/dist-embed/chunks/{sv-SE-XGPEYMSR-DbCiTLoB.js → sv-SE-XGPEYMSR-XX8MI0nA.js} +1 -1
  288. package/dist-embed/chunks/{svgDrawCommon-148a3cd9-DPsjuono.js → svgDrawCommon-148a3cd9-DrX92bA5.js} +1 -1
  289. package/dist-embed/chunks/{swimlanes-42K2YHIH-BuZNdiWN.js → swimlanes-42K2YHIH-0MJvexik.js} +1 -1
  290. package/dist-embed/chunks/{swimlanes-42K2YHIH-BVp5t5cb.js → swimlanes-42K2YHIH-BUwYYg5o.js} +1 -1
  291. package/dist-embed/chunks/{swimlanes-42K2YHIH-DALRvUJV.js → swimlanes-42K2YHIH-CmWAxVZ_.js} +1 -1
  292. package/dist-embed/chunks/{swimlanesDiagram-VR7AAH4N-BOs_rwH9.js → swimlanesDiagram-VR7AAH4N-BuFLmgBx.js} +1 -1
  293. package/dist-embed/chunks/{swimlanesDiagram-VR7AAH4N-Cq4Txw-s.js → swimlanesDiagram-VR7AAH4N-DwTgKjIi.js} +1 -1
  294. package/dist-embed/chunks/{swimlanesDiagram-VR7AAH4N-DKdPzO9j.js → swimlanesDiagram-VR7AAH4N-vzU4YzHa.js} +1 -1
  295. package/dist-embed/chunks/{ta-IN-2NMHFXQM-CXc4mXhz.js → ta-IN-2NMHFXQM-Cm2c3FMf.js} +1 -1
  296. package/dist-embed/chunks/{th-TH-HPSO5L25-BT_dDTtq.js → th-TH-HPSO5L25-DD76ndfY.js} +1 -1
  297. package/dist-embed/chunks/{timeline-definition-24CTP7MA-s7PWneCh.js → timeline-definition-24CTP7MA-DxAxZYKP.js} +1 -1
  298. package/dist-embed/chunks/{timeline-definition-24CTP7MA-MzC7WabN.js → timeline-definition-24CTP7MA-SfVzoC7E.js} +1 -1
  299. package/dist-embed/chunks/{timeline-definition-24CTP7MA-BayCBe0U.js → timeline-definition-24CTP7MA-a0E0wu89.js} +1 -1
  300. package/dist-embed/chunks/{timeline-definition-7545f45a-CvG64YlJ.js → timeline-definition-7545f45a-CqsiZe-C.js} +1 -1
  301. package/dist-embed/chunks/{tr-TR-DEFEU3FU-cY-BrOYD.js → tr-TR-DEFEU3FU-CkX69g80.js} +1 -1
  302. package/dist-embed/chunks/{uk-UA-QMV73CPH-Rc2Y0Ge7.js → uk-UA-QMV73CPH-DILlpWB0.js} +1 -1
  303. package/dist-embed/chunks/{vennDiagram-4TSXK5OY-BJQtpN9d.js → vennDiagram-4TSXK5OY-BDOrQK88.js} +1 -1
  304. package/dist-embed/chunks/{vennDiagram-4TSXK5OY-BAHHfe64.js → vennDiagram-4TSXK5OY-BxUbBn7b.js} +1 -1
  305. package/dist-embed/chunks/{vennDiagram-4TSXK5OY-BK8QiwTB.js → vennDiagram-4TSXK5OY-C8SwZKm-.js} +1 -1
  306. package/dist-embed/chunks/{vi-VN-M7AON7JQ-CxcPrWvC.js → vi-VN-M7AON7JQ-D0REMGYG.js} +1 -1
  307. package/dist-embed/chunks/{wardleyDiagram-VM6X3IG4-DYAhYSyu.js → wardleyDiagram-VM6X3IG4-BZssbJ10.js} +1 -1
  308. package/dist-embed/chunks/{wardleyDiagram-VM6X3IG4-Pv8X1wgF.js → wardleyDiagram-VM6X3IG4-DQI20vwb.js} +1 -1
  309. package/dist-embed/chunks/{wardleyDiagram-VM6X3IG4-CFNgnKTi.js → wardleyDiagram-VM6X3IG4-DY5BAim8.js} +1 -1
  310. package/dist-embed/chunks/{xychartDiagram-3f383b91-DaQk0skw.js → xychartDiagram-3f383b91-DnD8gcm_.js} +1 -1
  311. package/dist-embed/chunks/{xychartDiagram-S5SC5T6Z-iMYvupUx.js → xychartDiagram-S5SC5T6Z-BO4MDqrK.js} +1 -1
  312. package/dist-embed/chunks/{xychartDiagram-S5SC5T6Z-BtjF1Dxw.js → xychartDiagram-S5SC5T6Z-CDXKKZoM.js} +1 -1
  313. package/dist-embed/chunks/{xychartDiagram-S5SC5T6Z-FKExWp2n.js → xychartDiagram-S5SC5T6Z-DfsjHT0Y.js} +1 -1
  314. package/dist-embed/chunks/{zh-CN-LNUGB5OW-Bpd1cqNl.js → zh-CN-LNUGB5OW-BmSYUWcq.js} +1 -1
  315. package/dist-embed/chunks/{zh-HK-E62DVLB3-LKyAMUX_.js → zh-HK-E62DVLB3-BqISOUKV.js} +1 -1
  316. package/dist-embed/chunks/{zh-TW-RAJ6MFWO-z36Cw8j8.js → zh-TW-RAJ6MFWO-DACyIjvO.js} +1 -1
  317. package/dist-embed/datalayer-app-main.js +71 -71
  318. package/lib/chat/assistant/orbCharacters.d.ts +5 -0
  319. package/lib/chat/assistant/orbCharacters.js +5 -1
  320. package/lib/components/inspector/a2aSpans.d.ts +7 -0
  321. package/lib/components/inspector/a2aSpans.js +34 -2
  322. package/lib/components/inspector/agentSpans.d.ts +1 -1
  323. package/lib/components/inspector/agentSpans.js +1 -0
  324. package/lib/components/teams/A2ATeamGraph.d.ts +11 -3
  325. package/lib/components/teams/A2ATeamGraph.js +27 -6
  326. package/lib/components/teams/backdrops/catalogue.d.ts +2 -2
  327. package/lib/components/teams/backdrops/catalogue.js +11 -1
  328. package/lib/components/teams/backdrops/hero.js +24 -3
  329. package/lib/components/teams/backdrops/index.d.ts +2 -2
  330. package/lib/components/teams/backdrops/index.js +5 -1
  331. package/lib/components/teams/backdrops/minimal.d.ts +14 -0
  332. package/lib/components/teams/backdrops/minimal.js +163 -0
  333. package/lib/components/teams/backdrops/nodes.d.ts +19 -10
  334. package/lib/components/teams/backdrops/nodes.js +85 -50
  335. package/lib/components/teams/backdrops/orb.d.ts +10 -0
  336. package/lib/components/teams/backdrops/orb.js +134 -0
  337. package/lib/components/teams/backdrops/plain.js +2 -1
  338. package/lib/components/teams/backdrops/space.d.ts +13 -2
  339. package/lib/components/teams/backdrops/space.js +44 -33
  340. package/lib/components/teams/backdrops/types.d.ts +17 -4
  341. package/lib/components/teams/sceneStage.d.ts +6 -0
  342. package/lib/components/teams/sceneStage.js +9 -0
  343. package/lib/examples/AgentA2ATeamExample.js +3 -1
  344. package/lib/examples/ScenesExample.js +4 -2
  345. package/lib/specs/agents/agents.js +168 -168
  346. package/lib/specs/apps.js +1 -1
  347. package/lib/specs/cogs.js +3 -3
  348. package/lib/specs/ops.js +1 -1
  349. package/lib/specs/sceneRecordings.js +132 -0
  350. package/lib/specs/sceneSchema.js +2 -2
  351. package/lib/specs/scenes.js +26 -0
  352. package/lib/specs/teams/teams.js +16 -16
  353. package/lib/types/agentspecs.d.ts +1 -1
  354. package/lib/types/scenes.d.ts +4 -2
  355. package/lib/types/teams.d.ts +1 -1
  356. package/package.json +2 -2
  357. package/scripts/codegen/generate_sandbox_agents.py +1 -1
  358. package/scripts/codegen/generate_teams.py +2 -2
  359. package/dist-embed/chunks/portable-CiQthkEs.js +0 -1
@@ -1,4 +1,4 @@
1
- import{mv as pe,mw as sa,bK as nt,bM as oe,e3 as Ti,mx as ia,j as C,r as k,e2 as Cr,my as $r,gD as la,v as hs,_ as Ri,mz as aa,mA as ca,mB as ua,bs as Be,mC as ha,mD as fs,dg as fa,I as ds,W as da,e1 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{my as pe,mz as sa,bK as nt,bM as oe,e6 as Ti,mA as ia,j as C,r as k,e5 as Cr,mB as $r,gG as la,v as hs,_ as Ri,mC as aa,mD as ca,mE as ua,bs as Be,mF as ha,mG as fs,dj as fa,I as ds,W as da,e4 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===`
@@ -77,11 +77,11 @@ Exported from a Cells workbook: each cell below is a code cell of the sheet name
77
77
  `));const y=(f.textContent??"").replace(/ /g," "),x=f.getAttribute("data-sheets-numberformat");let $;if(x!==null)try{const I=JSON.parse(x);typeof I[2]=="string"&&($=I[2])}catch{}const A={...$!==void 0?{"data-sheets-numberformat":$}:{},...Object.assign({},...(f.getAttribute("class")??"").split(/\s+/).filter(Boolean).map(I=>s.get(I)??{})),...gi(f.getAttribute("style")??"")},O=Vf(A),D=Kf(f,y.trim()===""?"":y);(D.v!==void 0||D.f!==void 0||O!==void 0)&&i.push({r:h,c:d,...D,...O?{style:O}:{}}),d+=m,c=Math.max(c,d)}),l=h+1}),l>0&&c>0)return{version:1,rows:l,cols:c,parts:{cells:i}}}}if(e!==void 0&&e!=="")return ml(vu(e))}class Zf{capacity;#e=new Map;hits=0;misses=0;constructor(e){if(!Number.isInteger(e)||e<1)throw new Error(`An LRU holds at least one entry; ${e} was asked for.`);this.capacity=e}get(e){const n=this.#e.get(e);if(n===void 0){this.misses+=1;return}return this.hits+=1,this.#e.delete(e),this.#e.set(e,n),n}set(e,n){this.#e.delete(e),this.#e.set(e,n),this.#e.size>this.capacity&&this.#e.delete(this.#e.keys().next().value)}get size(){return this.#e.size}clear(){this.#e.clear()}}class Jf{cache;constructor(e=2e4){this.cache=new Zf(e)}width(e,n,o){const r=`${n}\0${o}`,s=this.cache.get(r);if(s!==void 0)return s;e.font!==n&&(e.font=n);const i=e.measureText(o).width;return this.cache.set(r,i),i}wrap(e,n,o,r){const s=[];for(const i of o.split(`
78
78
  `)){let a="";for(const l of i.split(/(\s+)/)){const c=a+l;a!==""&&this.width(e,n,c.trimEnd())>r?(s.push(a.trimEnd()),a=l.trimStart()):a=c}s.push(a.trimEnd())}return s}}function qf(t,e){if(!e)return{width:0,height:0};const n=String(t).length;return{width:Math.max(40,12+n*8),height:24}}function so(t,e,n,o){if(n<=0||o<=0||e>=t.offsetOf(o))return[0,-1];const r=t.indexAt(e),s=Math.min(t.indexAt(Math.max(e,e+n-1e-6)),o-1);return[r,s]}function Qf(t){if(!(t.zoom>0))throw new Error(`A zoom must be positive; ${t.zoom} was given.`);const e=t.zoom,n=qf(t.rows.count,t.showHeaders),o=n.width*e,r=n.height*e,s=t.rows.offsetOf(t.frozen.rows),i=t.cols.offsetOf(t.frozen.cols),a=t.cols.extent-i,l=t.rows.extent-s,c=Math.max(0,t.width-o),u=Math.max(0,t.height-r),h=Math.min(i*e,c),d=Math.min(s*e,u),f=c-h,m=u-d,g=Math.max(0,a-f/e),w=Math.max(0,l-m/e),y=Math.min(Math.max(0,t.scrollX),g),x=Math.min(Math.max(0,t.scrollY),w),$=so(t.rows,0,d/e,t.frozen.rows),A=so(t.cols,0,h/e,t.frozen.cols),O=so(t.rows,s+x,m/e,t.rows.count),D=so(t.cols,i+y,f/e,t.cols.count),I=(X,z,P,F,K,J,Ae,ae,ce)=>({name:X,x:z,y:P,width:F,height:K,firstRow:J[0],lastRow:J[1],firstCol:Ae[0],lastCol:Ae[1],originX:ae,originY:ce}),U=[];return d>0&&h>0&&U.push(I("corner",o,r,h,d,$,A,0,0)),d>0&&U.push(I("top",o+h,r,f,d,$,D,i+y,0)),h>0&&U.push(I("left",o,r+d,h,m,O,A,0,s+x)),U.push(I("main",o+h,r+d,f,m,O,D,i+y,s+x)),{zoom:e,headerWidth:o,headerHeight:r,panes:U,scrollWidth:a,scrollHeight:l,maxScrollX:g,maxScrollY:w}}function Tl(t,e,n){return t.panes.find(o=>e>=o.x&&e<o.x+o.width&&n>=o.y&&n<o.y+o.height)}function ed(t,e,n,o,r){const s=Tl(t,o,r);if(s===void 0)return;const i=s.originX+(o-s.x)/t.zoom,a=s.originY+(r-s.y)/t.zoom;if(!(i>=n.extent||a>=e.extent))return{row:e.indexAt(a),col:n.indexAt(i)}}function Se(t,e,n,o,r,s){const i=t.x+(o.offsetOf(s)-t.originX)*e,a=t.y+(n.offsetOf(r)-t.originY)*e;return{x:i,y:a,width:o.effectiveSizeOf(s)*e,height:n.effectiveSizeOf(r)*e}}const td=4;function nd(t,e,n,o,r){if(t.headerHeight===0)return;const s=r<t.headerHeight&&o>=t.headerWidth,i=o<t.headerWidth&&r>=t.headerHeight;if(!s&&!i)return;const a=s?"cols":"rows",l=s?n:e,c=t.panes.find(w=>s?o>=w.x&&o<w.x+w.width:r>=w.y&&r<w.y+w.height);if(c===void 0)return;const u=s?c.originX+(o-c.x)/t.zoom:c.originY+(r-c.y)/t.zoom;if(u>=l.extent)return;const h=l.indexAt(u),d=l.offsetOf(h),f=l.offsetOf(h+1),m=td/t.zoom;let g;if(f-u<=m)g=h;else if(u-d<=m&&h>0){let w=h-1;for(;w>0&&l.effectiveSizeOf(w)===0;)w-=1;g=w}return{axis:a,index:h,edge:g,x:o,y:r}}const Rl=3,xr=20;function zo(t,e,n){const o=(t.size??e.fontSize)*n;return`${t.italic?"italic ":""}${t.bold?"bold ":""}${o}px ${t.font??e.fontFamily}`}function xo(t,e,n,o,r){const s=Math.round(r*e)+.5;t.moveTo(Math.round(n*e),s),t.lineTo(Math.round(o*e),s)}function vo(t,e,n,o,r){const s=Math.round(n*e)+.5;t.moveTo(s,Math.round(o*e)),t.lineTo(s,Math.round(r*e))}function ns(t,e){t.save(),t.setTransform(1,0,0,1,0,0),e(),t.restore()}function wt(t,e){t.beginPath(),t.rect(e.x,e.y,e.width,e.height),t.clip()}function Eo(t,e,n){const o=[];for(let r=e;r<=n;r+=1)t.effectiveSizeOf(r)>0&&o.push(r);return o}function ar(t){return t===null||t.value===null&&t.formula===void 0}function vr(t,e){const n=Math.max(t.x,e.x),o=Math.max(t.y,e.y),r=Math.min(t.x+t.width,e.x+e.width)-n,s=Math.min(t.y+t.height,e.y+e.height)-o;return r>0&&s>0?{x:n,y:o,width:r,height:s}:void 0}function pi(t){const{ctx:e,dpr:n,viewport:o}=t,r={cells:0,texts:0};e.save(),e.setTransform(n,0,0,n,0,0),t.clip&&wt(e,t.clip);const s={x:0,y:0,width:Number.MAX_SAFE_INTEGER,height:Number.MAX_SAFE_INTEGER};for(const i of o.panes){const a=vr({x:i.x,y:i.y,width:i.width,height:i.height},t.clip??s);a!==void 0&&(e.save(),wt(e,a),rd(t,t.clip?od(i,a,o.zoom,t.sheet):i,r),e.restore())}return id(t),ld(t),e.restore(),r}function od(t,e,n,o){if(t.lastRow<t.firstRow||t.lastCol<t.firstCol)return t;const r=t.originY+(e.y-t.y)/n,s=t.originY+(e.y+e.height-t.y)/n,i=t.originX+(e.x-t.x)/n,a=t.originX+(e.x+e.width-t.x)/n,l=Math.max(t.firstRow,o.rows.indexAt(r)),c=Math.min(t.lastRow,o.rows.indexAt(s)),u=Math.max(t.firstCol,o.cols.indexAt(i)-xr),h=Math.min(t.lastCol,o.cols.indexAt(a)+xr);return{...t,firstRow:l,lastRow:c,firstCol:u,lastCol:h}}function rd(t,e,n){const{ctx:o,dpr:r,viewport:s,sheet:i,styles:a,theme:l,measure:c}=t,u=s.zoom;if(o.fillStyle=l.background,o.fillRect(e.x,e.y,e.width,e.height),e.lastRow<e.firstRow||e.lastCol<e.firstCol)return;const h=Eo(i.rows,e.firstRow,e.lastRow),d=Eo(i.cols,e.firstCol,e.lastCol),f=(y,x)=>Se(e,u,i.rows,i.cols,y,x);for(const y of h)for(const x of d){const $=i.cells.get(y,x);if($===null)continue;n.cells+=1;const A=a.get($.style).fill;if(A){const O=f(y,x);o.fillStyle=A,o.fillRect(O.x,O.y,O.width,O.height)}}t.showGridlines&&ns(o,()=>{o.beginPath(),o.strokeStyle=l.gridline,o.lineWidth=1;const y=e.x+e.width,x=e.y+e.height;for(const $ of h){const A=f($,d[0]??e.firstCol);xo(o,r,e.x,y,A.y+A.height-1/r)}for(const $ of d){const A=f(h[0]??e.firstRow,$);vo(o,r,A.x+A.width-1/r,e.y,x)}o.stroke()}),Er(t,"background",e,i,o);const m={top:e.firstRow,left:e.firstCol,bottom:e.lastRow,right:e.lastCol},g=i.merges.filter(y=>mt(y,m));for(const y of g){const x=f(y.top,y.left),$=f(y.bottom,y.right),A={x:x.x,y:x.y,width:$.x+$.width-x.x-1/r,height:$.y+$.height-x.y-1/r},O=i.cells.get(y.top,y.left),D=a.get(O?.style??0);o.fillStyle=D.fill??l.background,o.fillRect(A.x,A.y,A.width,A.height);const I=O===null?void 0:wi(t,D);if(O!==null&&(!ar(O)||I?.paintsEmpty===!0)){const U=I;U!==void 0?yi(t,U,A,t.value(y.top,y.left),D,n,y.top,y.left):bi(t,pt(t.value(y.top,y.left),D.format,t.locale),D,A,A,n)}}const w=(y,x)=>g.some($=>y>=$.top&&y<=$.bottom&&x>=$.left&&x<=$.right);for(const y of h){const x=d[0];if(x===void 0)break;const $=[],A=e.name==="main"||e.name==="top"?i.frozen.cols:0;for(let U=x-1;U>=Math.max(A,x-xr);U-=1)i.cols.effectiveSizeOf(U)>0&&$.unshift(U);const O=[...$,...d],D=t.bound,I=D!==void 0&&y>=D.top&&y<=D.bottom;for(let U=0;U<O.length;U+=1){const X=O[U];let z=i.cells.get(y,X);if(z===null&&I&&X>=D.left&&X<=D.right){const ae=t.value(y,X);if(ae===null)continue;z={value:ae,style:0},n.cells+=1}if(z===null||w(y,X))continue;const P=a.get(z.style),F=wi(t,P);if(ar(z)&&F?.paintsEmpty!==!0)continue;const K=f(y,X);if(F!==void 0){U>=$.length&&yi(t,F,K,t.value(y,X),P,n,y,X);continue}const J=pt(t.value(y,X),P.format,t.locale);let Ae=K;if(J.kind==="text"&&!P.wrap){const ae=zo(P,l,u),ce=c.width(o,ae,J.text)+2*Rl*u,bt=P.align??J.align;if(ce>K.width){let Me=K.x,de=K.x+K.width;const De=ue=>ue>=0&&ue<i.cols.count&&ar(i.cells.get(y,ue))&&!w(y,ue);if(bt!=="right")for(let ue=X+1;De(ue)&&de-Me<ce;ue+=1)de=f(y,ue).x+f(y,ue).width;if(bt!=="left")for(let ue=X-1;De(ue)&&de-Me<ce;ue-=1)Me=f(y,ue).x;Ae={x:Me,y:K.y,width:de-Me,height:K.height}}}U<$.length&&Ae.x+Ae.width<=f(y,x).x||bi(t,J,P,K,Ae,n)}}for(const y of h)for(const x of d){const $=i.cells.get(y,x);if($===null)continue;const A=a.get($.style).borders;if(!A)continue;const O=f(y,x);for(const D of["top","right","bottom","left"]){const I=A[D];if(!I)continue;const U=I.style==="thick"?3:I.style==="medium"?2:1;o.save(),o.strokeStyle=I.color,o.lineWidth=U,I.style==="dashed"&&o.setLineDash([4*u,2*u]),I.style==="dotted"&&o.setLineDash([1*u,1*u]),o.beginPath();const X=O.x,z=O.x+O.width,P=O.y,F=O.y+O.height,K=I.style==="double"?[-1,1]:[0];for(const J of K)D==="top"&&(o.moveTo(X,P+J),o.lineTo(z,P+J)),D==="bottom"&&(o.moveTo(X,F+J),o.lineTo(z,F+J)),D==="left"&&(o.moveTo(X+J,P),o.lineTo(X+J,F)),D==="right"&&(o.moveTo(z+J,P),o.lineTo(z+J,F));o.stroke(),o.restore()}}Er(t,"cells",e,i,o)}function sd(t,e,n){return{sheet:n.id,zone:{top:t.firstRow,left:t.firstCol,bottom:t.lastRow,right:t.lastCol},pane:t.name,zoom:e,cellRect:(o,r)=>({...Se(t,e,n.rows,n.cols,o,r),zoom:e})}}function Er(t,e,n,o,r){if(t.layers===void 0)return;let s;for(const i of t.layers)if(i.layer===e){s??=sd(n,t.viewport.zoom,o),r.save(),wt(r,n);try{i.draw(r,s,t.model)}finally{r.restore()}}}function wi(t,e){return e.type===void 0||t.cellType===void 0?void 0:t.cellType(e.type)}function yi(t,e,n,o,r,s,i,a){const{ctx:l}=t;l.save(),wt(l,n);const c={x:n.x,y:n.y,width:n.width-1,height:n.height-1,zoom:t.viewport.zoom};e.render(l,c,o,r,t.theme,{sheet:t.sheet.id,row:i,col:a,model:t.model}),l.restore(),s.texts+=1}function bi(t,e,n,o,r,s){const{ctx:i,viewport:a,theme:l,measure:c}=t,u=a.zoom;if(e.text==="")return;const h=zo(n,l,u),d=Rl*u;let f=e.text;if(e.kind==="number"&&c.width(i,h,f)+2*d>o.width){const O=c.width(i,h,"#");f="#".repeat(Math.max(1,Math.floor((o.width-2*d)/Math.max(O,1))))}const m=n.align??e.align;if(r!==o&&r.width>o.width){const O=t.dpr;i.fillStyle=n.fill??l.background,i.fillRect(r.x,r.y,r.width-1/O,r.height-1/O)}i.save(),wt(i,r),i.font=h,i.fillStyle=e.kind==="error"?l.errorText:e.color??n.color??l.text,i.textBaseline="alphabetic";const g=(n.size??l.fontSize)*u,w=n.wrap?c.wrap(i,h,f,o.width-2*d):[f],y=g*1.25,x=n.valign??"bottom",$=w.length*y,A=x==="top"?o.y+d:x==="middle"?o.y+(o.height-$)/2:o.y+o.height-d-$;w.forEach((O,D)=>{const I=c.width(i,h,O),U=A+(D+1)*y-(y-g)/2-g*.12,X=n.wrap?o:r,z=m==="left"?X.x+d:m==="right"?X.x+X.width-d-I:X.x+(X.width-I)/2;i.fillText(O,z,U),(n.underline||n.strike)&&i.fillRect(z,n.underline?U+1.5*u:U-g*.32,I,Math.max(1,u))}),i.restore(),s.texts+=1}function id(t){const{ctx:e,dpr:n,viewport:o,sheet:r,theme:s,measure:i}=t;if(o.headerHeight===0)return;const a=o.zoom,l=`${s.headerFontSize*a}px ${s.fontFamily}`,c=o.headerWidth,u=o.headerHeight;e.fillStyle=s.headerBackground,e.fillRect(0,0,e.canvas.width/n,u),e.fillRect(0,0,c,e.canvas.height/n),e.font=l,e.fillStyle=s.headerText,e.textBaseline="middle";const h=[];for(const d of o.panes){if(d.name==="main"||d.name==="top"){e.save(),wt(e,{x:d.x,y:0,width:d.width,height:u});for(const f of Eo(r.cols,d.firstCol,d.lastCol)){const m=Se(d,a,r.rows,r.cols,d.firstRow,f),g=Ye(f),w=i.width(e,l,g);e.fillStyle=s.headerText,e.fillText(g,m.x+(m.width-w)/2,u/2),h.push(()=>vo(e,n,m.x+m.width-1/n,0,u))}e.restore()}if(d.name==="main"||d.name==="left"){e.save(),wt(e,{x:0,y:d.y,width:c,height:d.height});for(const f of Eo(r.rows,d.firstRow,d.lastRow)){const m=Se(d,a,r.rows,r.cols,f,d.firstCol),g=String(f+1),w=i.width(e,l,g);e.fillStyle=s.headerText,e.fillText(g,(c-w)/2,m.y+m.height/2),h.push(()=>xo(e,n,0,c,m.y+m.height-1/n))}e.restore()}}ns(e,()=>{e.beginPath(),e.strokeStyle=s.headerBorder,e.lineWidth=1;for(const d of h)d();xo(e,n,0,e.canvas.width/n,u-1/n),vo(e,n,c-1/n,0,e.canvas.height/n),e.stroke()})}function ld(t){const{ctx:e,dpr:n,viewport:o,theme:r}=t;if(o.panes.find(a=>a.name==="top"||a.name==="left"||a.name==="corner")===void 0)return;const i=o.panes.find(a=>a.name==="main");ns(e,()=>{e.beginPath(),e.strokeStyle=r.frozenLine,e.lineWidth=Math.max(1,Math.round(2*n)),o.panes.some(a=>a.name==="top")&&xo(e,n,0,i.x+i.width,i.y-1/n),o.panes.some(a=>a.name==="left")&&vo(e,n,i.x-1/n,0,i.y+i.height),e.stroke()})}const ad=.4,io=7;function cd(t){const{ctx:e,dpr:n,viewport:o,sheet:r,theme:s,selection:i}=t,a=o.zoom;e.save(),e.setTransform(n,0,0,n,0,0),e.clearRect(0,0,e.canvas.width/n,e.canvas.height/n);const l=(u,h)=>{const d=Se(u,a,r.rows,r.cols,h.top,h.left),f=Math.min(h.bottom,r.rows.count-1),m=Math.min(h.right,r.cols.count-1),g=u.x+(r.cols.offsetOf(m+1)-u.originX)*a,w=u.y+(r.rows.offsetOf(f+1)-u.originY)*a;return{x:d.x,y:d.y,width:g-d.x,height:w-d.y}};if(o.headerHeight>0){e.fillStyle=s.headerSelectedBackground,e.globalAlpha=s.forcedColors?1:.6;for(const u of o.panes)for(const h of i.zones){const d=l(u,h);if(u.name==="main"||u.name==="top"){const f=vr({x:d.x,y:0,width:d.width,height:o.headerHeight},{x:u.x,y:0,width:u.width,height:o.headerHeight});f&&e.fillRect(f.x,f.y,f.width,f.height)}if(u.name==="main"||u.name==="left"){const f=vr({x:0,y:d.y,width:o.headerWidth,height:d.height},{x:0,y:u.y,width:o.headerWidth,height:u.height});f&&e.fillRect(f.x,f.y,f.width,f.height)}}e.globalAlpha=1}const c=i.zones[i.zones.length-1];for(const u of o.panes){e.save(),wt(e,u);for(const m of i.zones){const g=l(u,m);!(m.top===m.bottom&&m.left===m.right&&i.zones.length===1)&&!s.forcedColors&&(e.fillStyle=s.selectionFill,e.globalAlpha=ad,e.fillRect(g.x,g.y,g.width,g.height),e.globalAlpha=1),(m===c||s.forcedColors)&&(e.strokeStyle=s.selectionBorder,e.lineWidth=s.forcedColors?2:1,e.strokeRect(g.x+.5,g.y+.5,g.width-1,g.height-1))}const h=r.mergeAt(i.active.row,i.active.col),d=l(u,h??{top:i.active.row,left:i.active.col,bottom:i.active.row,right:i.active.col});if(e.strokeStyle=s.activeCellBorder,e.lineWidth=2,e.strokeRect(d.x+1,d.y+1,d.width-2,d.height-2),t.mark&&t.mark.sheet===r.id){const m=l(u,t.mark.zone);e.save(),e.strokeStyle=s.copyMarch,e.lineWidth=2,e.setLineDash([4,3]),e.strokeRect(m.x+1,m.y+1,m.width-2,m.height-2),e.restore()}for(const m of t.remote??[]){if(m.sheet!==r.id)continue;const g=s.forcedColors?s.remoteUserColors[0]:m.user.color;e.strokeStyle=g,e.lineWidth=2;for(const O of m.zones){const D=l(u,O);e.strokeRect(D.x+1,D.y+1,D.width-2,D.height-2)}const w=l(u,{top:m.active.row,left:m.active.col,bottom:m.active.row,right:m.active.col});m.editing!==void 0&&(e.setLineDash([3,2]),e.strokeRect(w.x+1,w.y+1,w.width-2,w.height-2),e.setLineDash([])),e.font=`${Math.max(9,s.headerFontSize-2)*a}px ${s.fontFamily}`;const y=m.editing!==void 0?`${m.user.name} (editing)`:m.user.name,x=e.measureText(y).width+8,$=14*a,A=w.y-$>=u.y?w.y-$:w.y+w.height;e.fillStyle=g,e.fillRect(w.x,A,x,$),e.fillStyle=s.forcedColors?"Canvas":"#ffffff",e.textBaseline="middle",e.fillText(y,w.x+4,A+$/2)}const f=l(u,c);e.fillStyle=s.fillHandle,e.fillRect(f.x+f.width-io/2-.5,f.y+f.height-io/2-.5,io,io),e.restore(),Er(t,"overlay",u,r,e)}e.restore()}class ud{counters={frames:0,gridFull:0,gridPartial:0,blits:0,overlay:0,lastFrameMs:0,cells:0,texts:0,blitMs:0,gridMs:0,overlayMs:0};measure=new Jf;#e;#t;#r;#o;#s;#i;#n;#d=$n;#l=0;#f=0;#m=1;#h=1;#c=0;#u=0;#a;#y=null;#b=!0;#w=!0;#k=[];#v={dx:0,dy:0};#$=!1;#x=!1;#g;constructor(e){this.#e=e.model,this.#t=e.grid,this.#r=e.overlay,this.#s=e.theme,this.#i=e.showGridlines??!0,this.#n=e.showHeaders??!0,this.#o=e.schedule??(s=>requestAnimationFrame(s)),this.#a=this.#e.selection.sheet;const n=this.#e.subscribe(s=>this.#p(s)),o=this.#e.subscribeSelection(s=>this.#T(s)),r=this.#e.subscribePresence(()=>{this.#w=!0,this.#R()});this.#g=()=>{n(),o(),r()}}dispose(){this.#x=!0,this.#g()}get viewport(){return this.#y===null&&(this.#y=this.#E()),this.#y}get sheet(){return this.#a}get dpr(){return this.#m}get zoom(){return this.#h}get scroll(){return{x:this.#c,y:this.#u}}setSize(e,n,o){if(!(e===this.#l&&n===this.#f&&o===this.#m)){this.#l=e,this.#f=n,this.#m=o;for(const r of[this.#t,this.#r])r.width=Math.max(1,Math.round(e*o)),r.height=Math.max(1,Math.round(n*o));this.#S()}}setZoom(e){if(!(e>=.5&&e<=4))throw new Error(`Zoom goes from 0.5 to 4; ${e} was asked for.`);e!==this.#h&&(this.#h=e,this.#S())}setTheme(e){e!==this.#s&&(this.#s=e,this.#S())}setOptions(e){const n=e.showGridlines??this.#i,o=e.showHeaders??this.#n;n===this.#i&&o===this.#n||(this.#i=n,this.#n=o,this.#S())}setLocale(e){e!==this.#d&&(this.#d=e,this.#S())}setSheet(e){e!==this.#a&&(this.#e.sheet(e),this.#a=e,this.#c=0,this.#u=0,this.#S())}setScroll(e,n){const o=this.viewport,r=Math.min(Math.max(0,e),o.maxScrollX),s=Math.min(Math.max(0,n),o.maxScrollY);if(r===this.#c&&s===this.#u)return;const i=(r-this.#c)*this.#h,a=(s-this.#u)*this.#h;this.#c=r,this.#u=s,this.#y=null,this.#b||(this.#v={dx:this.#v.dx+i,dy:this.#v.dy+a}),this.#w=!0,this.#R()}repaint(){this.#S()}frame(){if(this.#$=!1,this.#x||this.#l===0||this.#f===0)return;const e=performance.now(),n=this.viewport,o=this.#e.sheet(this.#a),r=this.#t.getContext("2d",{alpha:!1,desynchronized:!0});if(r===null)throw new Error("The grid canvas has no 2D context.");const s={ctx:r,dpr:this.#m,viewport:n,sheet:o,styles:this.#e.workbook.styles,theme:this.#s,measure:this.measure,showGridlines:this.#i,locale:this.#d,value:(f,m)=>this.#e.value(o.id,f,m),cellType:f=>this.#e.cellTypeOf(f)?.value,bound:this.#e.dataSource(o.id)?.zone,layers:this.#e.renderLayers(),model:this.#e};let i={cells:0,texts:0};const a=n.panes.find(f=>f.name==="main"),{dx:l,dy:c}=this.#v,u=!this.#b&&(l!==0||c!==0)&&Math.abs(l)<a.width/2&&Math.abs(c)<a.height/2;this.counters.blitMs=0;const h=performance.now();if(this.#b||!u&&(l!==0||c!==0))i=pi(s),this.counters.gridFull+=1;else{const f=[...this.#k];if(u){const m=performance.now();this.#A(r,a,l,c),this.counters.blitMs=performance.now()-m,f.push(...this.#M(a,l,c))}for(const m of f){const g=pi({...s,clip:m});i.cells+=g.cells,i.texts+=g.texts}f.length>0&&(this.counters.gridPartial+=1)}this.counters.gridMs=performance.now()-h-this.counters.blitMs;const d=performance.now();if(this.#w||this.#b||l!==0||c!==0||this.#k.length>0){const f=this.#r.getContext("2d",{desynchronized:!0});if(f===null)throw new Error("The overlay canvas has no 2D context.");cd({ctx:f,dpr:this.#m,viewport:n,sheet:o,theme:this.#s,selection:this.#e.selection,mark:this.#e.clipboardMark,remote:this.#e.remotePresence,layers:s.layers,model:this.#e}),this.counters.overlay+=1}this.counters.overlayMs=performance.now()-d,this.#b=!1,this.#w=!1,this.#k=[],this.#v={dx:0,dy:0},this.counters.frames+=1,this.counters.frames===1&&typeof performance.mark=="function"&&performance.mark("cells:first-frame"),this.counters.cells=i.cells,this.counters.texts=i.texts,this.counters.lastFrameMs=performance.now()-e}#A(e,n,o,r){const s=this.#m,i=this.#l,a=this.#f;if(e.save(),e.setTransform(1,0,0,1,0,0),o!==0){const l=n.x;e.drawImage(this.#t,(l+Math.max(o,0))*s,0,(i-l-Math.abs(o))*s,a*s,(l+Math.max(-o,0))*s,0,(i-l-Math.abs(o))*s,a*s)}if(r!==0){const l=n.y;e.drawImage(this.#t,0,(l+Math.max(r,0))*s,i*s,(a-l-Math.abs(r))*s,0,(l+Math.max(-r,0))*s,i*s,(a-l-Math.abs(r))*s)}e.restore(),this.counters.blits+=1}#M(e,n,o){const r=[],s=this.#l,i=this.#f;return n>0&&r.push({x:s-n-1,y:0,width:n+1,height:i}),n<0&&r.push({x:e.x,y:0,width:-n+1,height:i}),o>0&&r.push({x:0,y:i-o-1,width:s,height:o+1}),o<0&&r.push({x:0,y:e.y,width:s,height:-o+1}),r}#p(e){this.#y=null,this.#e.workbook.hasSheet(this.#a)||(this.#a=this.#e.selection.sheet);let n=e.origin==="load"||e.origin==="plugins"||e.origin==="async"||e.origin==="source"||e.origin==="code"?"all":hd(e.patches,this.#a);if(e.patches.length>0&&this.#e.workbook.formulas.size>0&&(n="all"),n==="all"){this.#S();return}if(n==="none"){this.#w=!0,this.#R();return}const o=this.viewport,r=this.#e.sheet(this.#a);for(const s of o.panes){const i=Math.max(n.top,s.firstRow),a=Math.min(n.bottom,s.lastRow);if(i>a)continue;const l=s.y+(r.rows.offsetOf(i)-s.originY)*o.zoom,c=s.y+(r.rows.offsetOf(a+1)-s.originY)*o.zoom;this.#k.push({x:0,y:Math.max(s.y,l-1),width:this.#l,height:Math.min(s.y+s.height,c+1)-Math.max(s.y,l-1)})}this.#w=!0,this.#R()}#T(e){if(e.sheet!==this.#a){this.setSheet(e.sheet);return}this.#w=!0,this.#R()}#S(){this.#y=null,this.#b=!0,this.#w=!0,this.#k=[],this.#v={dx:0,dy:0},this.#R()}#R(){this.#$||this.#x||(this.#$=!0,this.#o(()=>this.frame()))}#E(){const e=this.#e.sheet(this.#a);return Qf({rows:e.rows,cols:e.cols,frozen:e.frozen,scrollX:this.#c,scrollY:this.#u,width:this.#l,height:this.#f,zoom:this.#h,showHeaders:this.#n})}}function hd(t,e){let n=1/0,o=-1/0;for(const r of t){const s=r.sheet;if(r.op==="cells"){if(s!==e)continue;const i=r.zone;n=Math.min(n,i.top),o=Math.max(o,i.bottom)}else{if(typeof s=="string"&&s!==e)continue;return"all"}}return n===1/0?"none":o-n>200?"all":{top:n,bottom:o}}const fd=8e6;function ko(t,e){return Math.min(t+e,fd)}class xi{#e=0;#t=0;map(e,n){const o=ko(n.maxContent,n.viewport)-n.viewport;if(n.maxContent<=o||o<=0)return this.#e=e,this.#t=Math.min(Math.max(0,e),n.maxContent),this.#t;const r=e-this.#e;let s;return e<=0?s=0:e>=o?s=n.maxContent:Math.abs(r)<n.viewport?s=this.#t+r:s=e/o*n.maxContent,this.#e=e,this.#t=Math.min(Math.max(0,s),n.maxContent),this.#t}domFor(e,n){const o=ko(n.maxContent,n.viewport)-n.viewport,r=n.maxContent<=o||o<=0?e:e/n.maxContent*o;return this.#e=r,this.#t=e,r}get content(){return this.#t}}const dd='-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif',md=["#0969da","#cf222e","#1a7f37","#8250df","#bf8700","#bc4c00","#1b7c83"],No={background:"#ffffff",text:"#1f2328",textMuted:"#59636e",gridline:"#d1d9e0",headerBackground:"#f6f8fa",headerText:"#59636e",headerBorder:"#d1d9e0",headerSelectedBackground:"#ddf4ff",selectionFill:"#b6e3ff",selectionBorder:"#0969da",activeCellBorder:"#0969da",fillHandle:"#0969da",copyMarch:"#0969da",frozenLine:"#818b98",errorText:"#d1242f",linkText:"#0969da",referenceColors:md,remoteUserColors:["#bf3989","#1a7f37","#bc4c00","#8250df"],fontFamily:dd,fontSize:13,headerFontSize:12,chartColors:["#0969da","#1a7f37","#bc4c00","#8250df","#bf8700","#cf222e","#bf3989","#1b7c83"],chartAxis:"#59636e",chartGridline:"#d1d9e0",chartText:"#1f2328",chartBackground:"#ffffff"},gd={...No,background:"#0d1117",text:"#f0f6fc",textMuted:"#9198a1",gridline:"#3d444d",headerBackground:"#151b23",headerText:"#9198a1",headerBorder:"#3d444d",headerSelectedBackground:"#0c2d6b",selectionFill:"#1f6feb",selectionBorder:"#4493f8",activeCellBorder:"#4493f8",fillHandle:"#4493f8",copyMarch:"#4493f8",frozenLine:"#656c76",errorText:"#f85149",linkText:"#4493f8",referenceColors:["#4493f8","#f85149","#3fb950","#ab7df8","#d29922","#db6d28","#39c5cf"],remoteUserColors:["#db61a2","#3fb950","#db6d28","#ab7df8"],chartColors:["#4493f8","#3fb950","#db6d28","#ab7df8","#d29922","#f85149","#db61a2","#39c5cf"],chartAxis:"#9198a1",chartGridline:"#3d444d",chartText:"#f0f6fc",chartBackground:"#0d1117"},zl={...No,background:"Canvas",text:"CanvasText",textMuted:"GrayText",gridline:"GrayText",headerBackground:"Canvas",headerText:"CanvasText",headerBorder:"CanvasText",headerSelectedBackground:"Highlight",selectionFill:"transparent",selectionBorder:"Highlight",activeCellBorder:"Highlight",fillHandle:"Highlight",copyMarch:"Highlight",frozenLine:"CanvasText",errorText:"CanvasText",linkText:"LinkText",referenceColors:["Highlight"],remoteUserColors:["Highlight"],chartColors:["CanvasText","Highlight","LinkText","GrayText"],chartAxis:"CanvasText",chartGridline:"GrayText",chartText:"CanvasText",chartBackground:"Canvas",forcedColors:!0},pd=Object.keys(No);function Nl(t){if(typeof t!="object"||t===null)throw new Error("A CellsTheme is an object.");const e=t;for(const n of pd){const o=e[n];if(n==="referenceColors"||n==="remoteUserColors"||n==="chartColors"){if(!Array.isArray(o)||o.length===0||!o.every(r=>typeof r=="string"))throw new Error(`CellsTheme.${n}: a non-empty list of colours.`)}else if(n==="fontSize"||n==="headerFontSize"){if(!(typeof o=="number"&&o>0))throw new Error(`CellsTheme.${n}: a positive size in px.`)}else if(typeof o!="string"||o==="")throw new Error(`CellsTheme.${n}: a colour (or, for fontFamily, a font list).`)}}const wd=1e3;function yd({resolved:t,label:e}){if(t.kind!=="option")return null;const{data:n}=t,o=Math.max(0,...n.series.map(i=>i.values.length)),r=Math.min(o,wd),s=n.series.map(i=>i.source).filter(i=>i!==void 0);return C.jsxs("div",{style:Ol,"data-cells-chart-table":"",children:[C.jsxs("table",{children:[C.jsx("caption",{children:`Data of ${e}`}),C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{scope:"col",children:n.categories.length>0?"Category":"#"}),n.series.map((i,a)=>C.jsx("th",{scope:"col",children:i.name},a))]})}),C.jsx("tbody",{children:Array.from({length:r},(i,a)=>C.jsxs("tr",{children:[C.jsx("th",{scope:"row",children:String(n.categories[a]??a+1)}),n.series.map((l,c)=>C.jsx("td",{children:l.values[a]===null||l.values[a]===void 0?"":String(l.values[a])},c))]},a))})]}),o>r&&C.jsx("p",{children:`${o-r} more rows are not listed; the data is in ${s.join(", ")||"the sheet"}.`})]})}const Ol={position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0};function bd(t,e){return t.title!==void 0&&t.title!==""?t.title:e.kind==="option"?e.description.split(". ")[0]:e.text}function xd(t){const{spec:e,resolved:n,renderer:o,width:r,height:s,theme:i}=t,a=bd(e,n),l=n.kind==="option"?n.description:n.text,c=t.mounted!==!1&&n.kind==="option"&&o!==void 0,u=k.useId(),h=k.useRef(null);return k.useEffect(()=>{t.selected&&t.focusWhenSelected&&h.current?.focus({preventScroll:!0})},[t.selected,t.focusWhenSelected]),C.jsxs("div",{ref:h,role:"figure",tabIndex:-1,"aria-label":a,"aria-describedby":u,"aria-selected":t.selected||void 0,"data-cells-chart":e.id,"data-cells-chart-type":e.type,className:t.className,style:{boxSizing:"border-box",width:r,height:s,overflow:"hidden",background:i.chartBackground,border:`1px solid ${t.selected?i.selectionBorder:i.gridline}`,color:i.chartText,fontFamily:i.fontFamily,fontSize:i.fontSize,...t.style},children:[c?k.createElement(o.value.component,{option:n.option,modules:n.type.value.modules,width:r-2,height:s-2,theme:i}):n.kind==="placeholder"?C.jsx("div",{"data-cells-chart-placeholder":"",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",textAlign:"center",padding:8,boxSizing:"border-box",color:i.textMuted},children:n.text}):null,C.jsx("div",{id:u,style:Ol,children:l}),C.jsx(yd,{resolved:n,label:a})]})}function vd(t,e,n){const o=e.anchor;let r,s;o.kind==="absolute"?(r=t.frozen.rows>0&&o.y<t.rows.offsetOf(t.frozen.rows),s=t.frozen.cols>0&&o.x<t.cols.offsetOf(t.frozen.cols)):(r=o.from.row<t.frozen.rows,s=o.from.col<t.frozen.cols);const i=r&&s?"corner":r?"top":s?"left":"main";return n.find(a=>a.name===i)??n.find(a=>a.name==="main")}function Ed(t,e,n,o){const r=Hi(t,e),s=(r.x-n.originX)*o,i=(r.y-n.originY)*o,a=Math.max(1,Math.round(r.width*o)),l=Math.max(1,Math.round(r.height*o)),c=s+a>=-n.width&&s<=2*n.width&&i+l>=-n.height&&i<=2*n.height;return{x:Math.round(s),y:Math.round(i),width:a,height:l,near:c}}const kd=["nw","n","ne","w","e","sw","s","se"];function Sd(t,e,n,o,r,s){const i=n.rect,a=n.handle;let l=i.x,c=i.y,u=i.x+i.width,h=i.y+i.height;a==="move"?(l=Math.max(0,l+o),c=Math.max(0,c+r),u=l+i.width,h=c+i.height):(a.includes("w")&&(l=Math.min(l+o,u-16)),a.includes("e")&&(u=Math.max(u+o,l+16)),a.includes("n")&&(c=Math.min(c+r,h-16)),a.includes("s")&&(h=Math.max(h+r,c+16))),l=Math.max(0,l),c=Math.max(0,c);const d=e.anchor;if(d.kind==="absolute"){const w={};return(l!==i.x||c!==i.y)&&(w.move={x:Math.round(l),y:Math.round(c)}),(u-l!==i.width||h-c!==i.height)&&(w.resize={width:Math.round(u-l),height:Math.round(h-c)}),w}const f=Math.min(t.cols.indexAt(l),t.cols.count-1),m=Math.min(t.rows.indexAt(c),t.rows.count-1),g={};if((f!==d.from.col||m!==d.from.row||a==="move")&&(g.move={row:m,col:f}),d.kind==="cells"){const w=Math.max(f,Math.min(t.cols.indexAt(u),t.cols.count-1)),y=Math.max(m,Math.min(t.rows.indexAt(h),t.rows.count-1));a!=="move"&&(g.resize={row:y,col:w})}else a!=="move"&&(g.resize={width:Math.round(u-l),height:Math.round(h-c)});return g}function Cd(t){const{model:e,viewport:n,theme:o}=t,r=k.useRef(null),s=(d,f)=>{const m=r.current;if(r.current=null,m===null)return;const g=f.charts.get(m.id);if(g===void 0)return;const w=(d.clientX-m.startX)/n.zoom,y=(d.clientY-m.startY)/n.zoom;if(Math.abs(w)<2&&Math.abs(y)<2)return;const x=Sd(f,g,m,w,y,d.altKey),$=()=>{x.move!==void 0&&e.dispatch({type:"MOVE_CHART",sheet:f.id,id:m.id,to:x.move}),x.resize!==void 0&&e.dispatch({type:"RESIZE_CHART",sheet:f.id,id:m.id,to:x.resize})};x.move!==void 0&&x.resize!==void 0?e.transact(m.handle==="move"?"Move chart":"Resize chart",$):$()},i=k.useCallback(d=>e.subscribe(d),[e]);k.useSyncExternalStore(i,()=>e.revision,()=>e.revision);const a=k.useCallback(d=>e.reactor.subscribe(d),[e]);if(k.useSyncExternalStore(a,()=>e.reactor.getRevision(),()=>e.reactor.getRevision()),!e.workbook.hasSheet(t.sheet))return null;const l=e.sheet(t.sheet);if(l.charts.size===0)return null;const c=Al(e.reactor),u=c===void 0?"not-loaded":"loaded",h=new Map;for(const d of l.charts.values()){const f=vd(l,d,n.panes);let m=h.get(f);m===void 0&&h.set(f,m=[]),m.push(d)}return C.jsx(C.Fragment,{children:[...h].map(([d,f])=>C.jsx("div",{"data-cells-charts-pane":d.name,style:{position:"absolute",left:d.x,top:d.y,width:d.width,height:d.height,overflow:"hidden",pointerEvents:"none",zIndex:1},children:f.map(m=>{const g=Ed(l,m,d,n.zoom),w=g.near?Ff(e,l.id,m.id,o,u):null;return C.jsxs("div",{"data-cells-chart-holder":"",style:{position:"absolute",left:g.x,top:g.y,width:g.width,height:g.height,pointerEvents:"auto"},onPointerDown:y=>{t.onPointerDownChart?.(m.id,y);const x=y.target.getAttribute("data-cells-chart-handle");if(y.button!==0)return;const $=Hi(l,m);r.current={id:m.id,handle:x??"move",startX:y.clientX,startY:y.clientY,pointerId:y.pointerId,rect:$},y.currentTarget.setPointerCapture?.(y.pointerId)},onPointerUp:y=>s(y,l),onPointerCancel:()=>{r.current=null},onKeyDown:y=>{t.onChartKeyDown?.(y)&&y.stopPropagation()},children:[t.selectedChart===m.id&&kd.map(y=>C.jsx("div",{"data-cells-chart-handle":y,"aria-hidden":"true",style:{position:"absolute",width:8,height:8,background:o.selectionBorder,border:`1px solid ${o.background}`,boxSizing:"border-box",zIndex:2,cursor:`${y}-resize`,left:y.includes("w")?-4:y.includes("e")?g.width-4:g.width/2-4,top:y.includes("n")?-4:y.includes("s")?g.height-4:g.height/2-4}},y)),C.jsx(xd,{spec:m,resolved:w??{kind:"placeholder",text:`A ${m.type} chart, off screen`},renderer:c,width:g.width,height:g.height,theme:o,mounted:g.near,selected:t.selectedChart===m.id,focusWhenSelected:!0})]},m.id)})},d.name))})}const $d=20,Ad=2e5;function So(t){if(t.outputs.length>0)return t.outputs;const e=vi.get(t);if(e!==void 0)return e;const n=t.result,o=n==null||typeof n=="object"?Md:[{output_type:"execute_result",data:{"text/plain":String(n)},metadata:{},execution_count:t.executionCount??null}];return vi.set(t,o),o}const vi=new WeakMap,Md=[];function Il(t){const e=[];for(const n of t)if(n.output_type==="stream")e.push(String(n.text??""));else if(n.output_type==="error")e.push(`${String(n.ename??"Error")}: ${String(n.evalue??"")}`);else{const o=(n.data??{})["text/plain"];o!==void 0&&e.push(Array.isArray(o)?o.join(""):String(o))}return e.join(`
79
79
  `).trim()}const Td=["text/plain","image/png","image/jpeg","image/gif","text/latex"];function _l(t){return t.map(e=>{if(e.output_type==="stream"||e.output_type==="error")return e;const n=e.data??{},o=Object.fromEntries(Object.entries(n).filter(([s])=>Td.includes(s)));if(Object.keys(o).length>0)return{...e,data:o};const r=Object.keys(n).join(", ")||"nothing";return{...e,data:{"text/plain":`[${r}: shown once the cell runs here]`}}})}function Ei(t,e,n,o){const r=e<t.frozen.rows,s=n<t.frozen.cols,i=r&&s?"corner":r?"top":s?"left":"main";return o.find(a=>a.name===i)??o.find(a=>a.name==="main")}function ki(t,e,n,o,r,s){const i=t.cols.offsetOf(n)+t.cols.effectiveSizeOf(n)+(o.dx??0),a=t.rows.offsetOf(e)+(o.dy??0),l=Math.round((i-r.originX)*s),c=Math.round((a-r.originY)*s),u=Math.max(1,Math.round(o.width*s)),h=Math.max(1,Math.round(o.height*s)),d=l+u>=-r.width&&l<=2*r.width&&c+h>=-r.height&&c<=2*r.height,f=Math.hypot(Math.max(0,-l,l+u-r.width),Math.max(0,-c,c+h-r.height));return{x:l,y:c,width:u,height:h,near:d,distance:f}}const Rd='button, a, input, select, textarea, [role="button"], [role="menuitem"]';function os(t={}){const[e,n]=k.useState({dx:0,dy:0}),[o,r]=k.useState(!1),s=k.useRef(t);s.current=t;const i=k.useRef(null);return{offset:e,setOffset:n,dragging:o,handlers:{onPointerDown:l=>{if(l.button!==0)return;const c=l.target.closest?.(Rd);c!=null&&c!==l.currentTarget||(l.preventDefault(),l.stopPropagation(),i.current={id:l.pointerId,x:l.clientX,y:l.clientY,base:e},l.currentTarget.setPointerCapture?.(l.pointerId),r(!0),s.current.onStart?.())},onPointerMove:l=>{const c=i.current;c===null||l.pointerId!==c.id||(l.stopPropagation(),n({dx:c.base.dx+l.clientX-c.x,dy:c.base.dy+l.clientY-c.y}))},onPointerUp:l=>{const c=i.current;if(c===null||l.pointerId!==c.id)return;l.stopPropagation(),i.current=null,r(!1);const u={dx:c.base.dx+l.clientX-c.x,dy:c.base.dy+l.clientY-c.y};n(u),s.current.onDrop?.(l.clientX-c.x,l.clientY-c.y,u)},onPointerCancel:()=>{const l=i.current;i.current=null,r(!1),l!==null&&n(l.base)}}}}const rs={cursor:"move",userSelect:"none",touchAction:"none"},Ll=t=>JSON.stringify(t).length,ho=18;function zd(t){const{code:e,place:n,theme:o}=t,r=et(t.row,t.col),s=Ll(e.outputs)>Ad,i=k.useSyncExternalStore(k.useCallback(g=>t.model.subscribe(g),[t.model]),()=>t.model.codeState(t.sheet,t.row,t.col)!=="running",()=>!0),{offset:a,setOffset:l,dragging:c,handlers:u}=os({onDrop:(g,w)=>{l({dx:0,dy:0}),(Math.abs(g)>=2||Math.abs(w)>=2)&&t.onMove?.(g,w)}}),h=t.trusted?e.outputs:_l(e.outputs),d=Il(h),f=t.trusted?"":" Untrusted: from a file or another person; HTML, scripts and widgets are shown once the cell runs here.",m=Math.max(1,n.height-ho);return C.jsxs("div",{"data-cells-code-output":r,"data-cells-dragging":c?"":void 0,role:"region","aria-label":`Output of ${r}`,"aria-description":`${d.slice(0,500)}${f}`.trim()||void 0,"data-cells-code-untrusted":t.trusted?void 0:"",tabIndex:-1,style:{position:"absolute",left:n.x+a.dx,top:n.y+a.dy,width:n.width,height:n.height,display:"flex",flexDirection:"column",overflow:"hidden",boxSizing:"border-box",border:`1px solid ${o.gridline}`,background:o.background,color:o.text,pointerEvents:"auto",font:`${o.fontSize}px ${o.fontFamily}`},onKeyDown:g=>{g.key==="Escape"&&(g.stopPropagation(),t.onEscape?.())},children:[C.jsxs("div",{"data-cells-code-output-handle":"",title:"Drag to move",...u,style:{...rs,flex:`0 0 ${ho}px`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:4,padding:"0 2px 0 6px",fontSize:11,lineHeight:`${ho-1}px`,color:o.headerText,background:o.headerBackground,borderBottom:`1px solid ${o.gridline}`,overflow:"hidden",whiteSpace:"nowrap"},children:[C.jsxs("span",{children:["Output of ",r]}),C.jsx("button",{type:"button","data-cells-code-unpin":"","aria-label":`Unpin the output of ${r}`,title:"Unpin: show it on hover",onPointerDown:g=>g.stopPropagation(),onClick:()=>t.onUnpin?.(),style:{border:0,background:"transparent",color:"inherit",cursor:"pointer",padding:"0 4px",font:"inherit",lineHeight:"inherit"},children:"×"})]}),C.jsx("div",{style:{flex:"1 1 auto",overflow:"auto",minHeight:0},children:t.mounted&&i&&C.jsx(Dl,{heavy:s,renderer:t.renderer,outputs:h,trusted:t.trusted,cell:r,width:n.width,height:m,text:d})})]})}function Dl(t){const[e,n]=k.useState(!1);return t.heavy&&!e?C.jsxs("button",{type:"button",onClick:()=>n(!0),style:{margin:8},children:["Show output (",Math.round(Ll(t.outputs)/1024)," kB)"]}):t.renderer===void 0?C.jsx("pre",{style:{margin:8,whiteSpace:"pre-wrap",font:"inherit"},"data-cells-code-text":"",children:t.text}):C.jsx(k.Suspense,{fallback:C.jsx("span",{style:{margin:8},children:"Loading the output…"}),children:k.createElement(t.renderer,{outputs:t.outputs,trusted:t.trusted,cell:t.cell,width:t.width,height:t.height})})}function Nd(t){const{model:e,viewport:n,theme:o}=t;if(k.useSyncExternalStore(k.useCallback(x=>e.subscribe(x),[e]),()=>e.revision,()=>e.revision),k.useSyncExternalStore(k.useCallback(x=>e.reactor.subscribe(x),[e]),()=>e.reactor.getRevision(),()=>e.reactor.getRevision()),!e.workbook.hasSheet(t.sheet))return null;const r=e.sheet(t.sheet);if(r.code.size===0)return null;const s=_h(e.reactor)?.value,i=s?.output,a=s?.editor,l=[];for(const x of En(r)){const $=Wt(x.code);if($===void 0)continue;const A=Ei(r,x.row,x.col,n.panes);l.push({...x,pane:A,place:ki(r,x.row,x.col,$,A,n.zoom)})}const c=new Set(l.filter(x=>x.place.near).sort((x,$)=>x.place.distance-$.place.distance).slice(0,$d)),u=new Map;for(const x of l){let $=u.get(x.pane);$===void 0&&u.set(x.pane,$=[]),$.push(x)}const h=(x,$,A)=>{const O=e.code(r.id,x,$);O!==void 0&&e.dispatch({type:"SET_CODE",sheet:r.id,row:x,col:$,code:{...O,frame:A}})},d=n.zoom,f=(x,$,A,O)=>{const D=e.code(r.id,x,$),I=D===void 0?void 0:Wt(D);I!==void 0&&h(x,$,{...I,dx:Math.round((I.dx??0)+A/d),dy:Math.round((I.dy??0)+O/d)})},m=(x,$,A)=>{const O=Ei(r,x,$,n.panes),D=ki(r,x,$,{width:1,height:1},O,d);h(x,$,{width:Math.round(A.width/d),height:Math.round(A.height/d),dx:Math.round((A.x-O.x-D.x)/d),dy:Math.round((A.y-O.y-D.y)/d)})},g=t.editing??null,w=t.preview??null,y=w===null?void 0:e.code(r.id,w.row,w.col);return C.jsxs(C.Fragment,{children:[[...u].map(([x,$])=>C.jsx("div",{"data-cells-code-pane":x.name,style:{position:"absolute",left:x.x,top:x.y,width:x.width,height:x.height,overflow:"hidden",pointerEvents:"none",zIndex:1},children:$.map(A=>C.jsx(zd,{model:e,sheet:r.id,row:A.row,col:A.col,code:A.code,place:A.place,theme:o,renderer:i,mounted:c.has(A),trusted:e.codeTrusted(r.id,A.row,A.col),onEscape:t.onEscape,onMove:(O,D)=>f(A.row,A.col,O,D),onUnpin:()=>h(A.row,A.col,null)},`${A.row},${A.col}`))},x.name)),g!==null&&e.code(r.id,g.row,g.col)!==void 0&&C.jsx(_d,{model:e,sheet:r.id,row:g.row,col:g.col,x:g.x,y:g.y,width:Math.max(Id,Wt(e.code(r.id,g.row,g.col))?.width??0),editor:a,status:s?.status,portalName:t.portalName,returnFocusRef:t.returnFocusRef,onClose:()=>t.onCloseEditor?.()},`${r.id}:${g.row},${g.col}`),w!==null&&y!==void 0&&So(y).length>0&&C.jsx(Od,{cell:et(w.row,w.col),outputs:So(y),trusted:e.codeTrusted(r.id,w.row,w.col),x:w.x,y:w.y,renderer:i,theme:o,portalName:t.portalName,returnFocusRef:t.returnFocusRef,onClose:()=>t.onClosePreview?.(),onPointer:t.onPreviewPointer,onPin:x=>{m(w.row,w.col,x),t.onClosePreview?.()}},`preview:${r.id}:${w.row},${w.col}`)]})}const lt={width:480,height:360};function Od(t){const e=t.trusted?t.outputs:_l(t.outputs),n=Il(e),o=k.useRef(!1),r=k.useRef(null),{offset:s,dragging:i,handlers:a}=os({onStart:()=>{o.current=!0,t.onPointer?.(!0)},onDrop:(l,c,u)=>{if(o.current=!1,Math.abs(l)<2&&Math.abs(c)<2)return;const h=r.current?.getBoundingClientRect();t.onPin?.({x:t.x+u.dx,y:t.y+u.dy,width:Math.min(lt.width,Math.max(80,h?.width??lt.width)),height:Math.min(lt.height+ho,Math.max(40,h?.height??lt.height))})}});return C.jsx(Cr,{children:C.jsx($r,{role:"region","aria-label":`Output of ${t.cell}`,returnFocusRef:t.returnFocusRef,onClickOutside:t.onClose,onEscape:t.onClose,portalContainerName:t.portalName,position:"absolute",top:t.y+s.dy,left:t.x+s.dx,width:"auto",preventFocusOnOpen:!0,style:{backgroundColor:"var(--overlay-bgColor, Canvas)",color:"var(--fgColor-default, CanvasText)",boxShadow:"var(--shadow-floating-small, 0 0 0 1px rgba(128, 128, 128, 0.35), 0 8px 24px rgba(0, 0, 0, 0.2))"},"data-cells-code-preview":t.cell,"data-cells-dragging":i?"":void 0,children:C.jsxs("div",{ref:r,"data-cells-code-preview":t.cell,style:{font:`${t.theme.fontSize}px ${t.theme.fontFamily}`},onPointerEnter:()=>t.onPointer?.(!0),onPointerLeave:()=>{o.current||t.onPointer?.(!1)},onPointerDown:l=>l.stopPropagation(),onKeyDown:l=>{l.stopPropagation(),l.key==="Escape"&&(l.preventDefault(),t.onClose())},children:[C.jsxs("div",{"data-cells-code-preview-handle":"",title:"Drag to move",...a,style:{...rs,padding:"2px 8px",fontSize:11,color:"var(--fgColor-muted, GrayText)",borderBottom:"1px solid var(--borderColor-muted, rgba(128, 128, 128, 0.3))"},children:["Output of ",t.cell]}),C.jsx("div",{style:{maxWidth:lt.width,maxHeight:lt.height,overflow:"auto",padding:4},children:C.jsx(Dl,{heavy:!1,renderer:t.renderer,outputs:e,trusted:t.trusted,cell:t.cell,width:lt.width-8,height:lt.height-8,text:n})})]})})})}const Id=560;function _d(t){const{model:e,sheet:n,row:o,col:r}=t,{offset:s,dragging:i,handlers:a}=os(),l=k.useRef(null),c=k.useRef(!1),u=()=>l.current?.save(),h=()=>{c.current||(c.current=!0,u(),t.onClose())},d=()=>{u(),co(e).run({sheet:n,row:o,col:r}).catch(()=>{})},f=t.status,m={sheet:n,row:o,col:r,model:e,onClose:()=>{c.current=!0,t.onClose()},register:g=>{l.current=g}};return C.jsx(Cr,{children:C.jsx($r,{role:"dialog","aria-label":`Code of ${et(o,r)}`,returnFocusRef:t.returnFocusRef,onClickOutside:h,onEscape:h,portalContainerName:t.portalName,position:"absolute",top:t.y+s.dy,left:t.x+s.dx,width:"auto",style:{backgroundColor:"var(--overlay-bgColor, Canvas)",color:"var(--fgColor-default, CanvasText)",boxShadow:"var(--shadow-floating-small, 0 0 0 1px rgba(128, 128, 128, 0.35), 0 8px 24px rgba(0, 0, 0, 0.2))"},"data-cells-code-overlay":"","data-cells-dragging":i?"":void 0,children:C.jsxs("div",{"data-cells-code-overlay":"",style:{width:t.width,maxWidth:"calc(100vw - 32px)",padding:8},onPointerDown:g=>g.stopPropagation(),onKeyDownCapture:g=>{g.key==="Enter"&&g.shiftKey?(g.preventDefault(),g.stopPropagation(),d()):g.key.toLowerCase()==="s"&&(g.ctrlKey||g.metaKey)&&(g.preventDefault(),g.stopPropagation(),u())},onKeyDown:g=>{g.stopPropagation(),g.key==="Escape"&&(g.preventDefault(),h())},children:[C.jsxs("div",{"data-cells-code-overlay-header":"",title:"Drag to move",...a,style:{...rs,display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:6,fontSize:12},children:[C.jsx("strong",{children:et(o,r)}),f!==void 0&&C.jsx(k.Suspense,{fallback:null,children:C.jsx(f,{model:e})})]}),t.editor!==void 0?C.jsx(k.Suspense,{fallback:C.jsx("span",{"data-cells-code-loading":"",children:"Loading the editor…"}),children:k.createElement(t.editor,m)}):C.jsx(Ld,{...m})]})})})}function Ld({model:t,sheet:e,row:n,col:o,onClose:r,register:s}){const i=t,a=i.code(e,n,o),[l,c]=k.useState(a?.source??""),u=k.useRef(l);u.current=l;const h=()=>{const f=i.code(e,n,o);f!==void 0&&u.current!==f.source&&i.dispatch({type:"SET_CODE",sheet:e,row:n,col:o,code:{...f,source:u.current}})};if(s?.({save:h}),a===void 0)return null;const d=()=>{h(),r()};return C.jsxs("div",{role:"dialog","aria-label":`Code of ${et(n,o)}`,"data-cells-code-editor":"",children:[C.jsx(la,{"aria-label":"Source",value:l,block:!0,resize:"vertical",rows:Math.min(20,Math.max(4,l.split(`
80
- `).length+1)),style:{fontFamily:"var(--fontStack-monospace, monospace)"},onChange:f=>c(f.target.value)}),C.jsxs("div",{style:{marginTop:8,display:"flex",gap:8},children:[C.jsx(hs,{size:"small",variant:"primary",onClick:d,children:"Save"}),C.jsx(hs,{size:"small",onClick:r,children:"Cancel"})]})]})}const Le=t=>t.startsWith("=");function ss(t){return Ui(t.slice(1)).map(e=>({...e,start:e.start+1,end:e.end+1}))}function is(t,e){if(!Le(t)||e<1)return!1;let n=e-1;for(;n>0&&t[n]===" ";)n-=1;if(n===0)return!0;const o=ss(t).filter(s=>s.end<=n+1&&s.kind!=="whitespace"),r=o[o.length-1];return r===void 0?!0:r.kind==="lparen"||r.kind==="separator"||r.kind==="lbrace"||r.kind==="operator"&&r.text!=="%"}function Dd(t,e,n){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),s=Math.min(t.col,e.col),i=Math.max(t.col,e.col),a=`${Ye(s)}${o+1}`,l=`${Ye(i)}${r+1}`;return""+(a===l?a:`${a}:${l}`)}function Si(t){const e=/^\$?([A-Za-z]{1,3})?\$?([0-9]{1,7})?$/.exec(t);if(e===null)return{};let n;if(e[1]!==void 0){n=0;for(const o of e[1].toUpperCase())n=n*26+(o.charCodeAt(0)-64);n-=1}return{col:n,row:e[2]===void 0?void 0:Number(e[2])-1}}function Ul(t){if(!Le(t))return[];const e=ss(t),n=[];for(let o=0;o<e.length;o+=1){let r=e[o],s,i=r.start;if(r.kind==="sheet"){const d=r.text.slice(0,-1);if(s=d.startsWith("'")?d.slice(1,-1).replace(/''/g,"'"):d,o+=1,r=e[o],r===void 0||r.kind!=="ref")continue}else i=r.start;if(r.kind!=="ref")continue;const a=Si(r.text);let l=a,c=r.end;e[o+1]?.kind==="operator"&&e[o+1].text===":"&&e[o+2]?.kind==="ref"&&(l=Si(e[o+2].text),c=e[o+2].end,o+=2);const u=[a.row,l.row].filter(d=>d!==void 0),h=[a.col,l.col].filter(d=>d!==void 0);n.push({start:i,end:c,...s!==void 0?{sheet:s}:{},...u.length>0?{top:Math.min(...u),bottom:Math.max(...u)}:{},...h.length>0?{left:Math.min(...h),right:Math.max(...h)}:{}})}return n}const Ud=[(t,e)=>`$${t}$${e}`,(t,e)=>`${t}$${e}`,(t,e)=>`$${t}${e}`,(t,e)=>`${t}${e}`];function Fd(t,e){const n=Ul(t).find(f=>e>=f.start&&e<=f.end);if(n===void 0)return;const o=t.slice(n.start,n.end),r=o.lastIndexOf("!"),s=r>=0?o.slice(0,r+1):"",a=o.slice(s.length).split(":").map(f=>/^(\$?)([A-Za-z]{1,3})(\$?)([0-9]{1,7})$/.exec(f));if(a.some(f=>f===null))return;const l=a[0],c=(l[1]?2:0)+(l[3]?1:0),u={3:1,1:2,2:0,0:3}[c],h=Ud[{3:0,1:1,2:2,0:3}[u]],d=s+a.map(f=>h(f[2],f[4])).join(":");return{text:t.slice(0,n.start)+d+t.slice(n.end),caret:n.start+d.length}}function Pd(t,e){if(!Le(t))return;let n=e;for(;n>1&&/[A-Za-z0-9_.]/.test(t[n-1]);)n-=1;const o=t.slice(n,e);if(/^[A-Za-z][A-Za-z0-9_.]*$/.test(o)&&t[e]!=="("&&is(t,n))return{start:n,prefix:o}}function jd(t,e){if(!Le(t))return;const n=[];let o;for(const r of ss(t)){if(r.start>=e)break;if(r.kind==="lparen")n.push({name:o?.kind==="function"?o.text.toUpperCase():void 0,argument:0});else if(r.kind==="rparen")n.pop();else if(r.kind==="separator"){const s=n[n.length-1];s!==void 0&&(s.argument+=1)}r.kind!=="whitespace"&&(o=r)}for(let r=n.length-1;r>=0;r-=1){const s=n[r];if(s.name!==void 0)return{name:s.name,argument:s.argument}}}const be=(t,e)=>n=>e(n),wn=t=>t.axis==="rows"?t.n===1?"row":"rows":t.n===1?"column":"columns",Bd={SET_CELLS:be("SET_CELLS",t=>`Edited ${hr(t.at)}`),SET_STYLE:be("SET_STYLE",t=>`Formatted ${Oe(t.zone)}`),CLEAR:be("CLEAR",t=>`Cleared ${Oe(t.zone)}`),INSERT_AXIS:be("INSERT_AXIS",t=>`Inserted ${t.n} ${wn(t)} at ${t.at+1}`),DELETE_AXIS:be("DELETE_AXIS",t=>`Deleted ${t.n} ${wn(t)} at ${t.at+1}`),MOVE_AXIS:be("MOVE_AXIS",t=>`Moved ${t.n} ${wn(t)}`),RESIZE_AXIS:be("RESIZE_AXIS",t=>`Resized ${wn({axis:t.axis,n:t.to-t.from+1})}`),HIDE_AXIS:be("HIDE_AXIS",t=>`${t.hidden?"Hid":"Showed"} ${wn({axis:t.axis,n:t.to-t.from+1})}`),MERGE:be("MERGE",t=>`Merged ${Oe(t.zone)}`),UNMERGE:be("UNMERGE",t=>`Unmerged ${Oe(t.zone)}`),ADD_SHEET:be("ADD_SHEET",t=>`Added sheet ${t.name??""}`.trim()),DELETE_SHEET:be("DELETE_SHEET",()=>"Deleted a sheet"),RENAME_SHEET:be("RENAME_SHEET",t=>`Renamed the sheet to ${t.name}`),MOVE_SHEET:be("MOVE_SHEET",()=>"Moved a sheet"),FREEZE:be("FREEZE",t=>`Froze ${t.rows} rows and ${t.cols} columns`),INSERT_CHART:t=>`Inserted a ${t.chart.type} chart`,UPDATE_CHART:()=>"Changed the chart",MOVE_CHART:()=>"Moved the chart",RESIZE_CHART:()=>"Resized the chart",DELETE_CHART:()=>"Deleted the chart"};function Hd(t,e=Bd){const n=t.label.toLowerCase().replace(/_/g," ");if(t.origin==="undo")return`Undo: ${n}`;if(t.origin==="redo")return`Redo: ${n}`;if(t.commands.length===1){const o=e[t.commands[0].type];if(o)return o(t.commands[0])}return t.label}const Fl={background:"--bgColor-default",text:"--fgColor-default",textMuted:"--fgColor-muted",gridline:"--borderColor-muted",headerBackground:"--bgColor-muted",headerText:"--fgColor-muted",headerBorder:"--borderColor-default",headerSelectedBackground:"--bgColor-accent-muted",selectionFill:"--bgColor-accent-muted",selectionBorder:"--borderColor-accent-emphasis",activeCellBorder:"--borderColor-accent-emphasis",fillHandle:"--borderColor-accent-emphasis",copyMarch:"--borderColor-accent-emphasis",errorText:"--fgColor-danger",linkText:"--fgColor-accent",fontFamily:"--fontStack-sansSerif",chartAxis:"--fgColor-muted",chartGridline:"--borderColor-muted",chartText:"--fgColor-default",chartBackground:"--bgColor-default"},Yd=["--data-blue-color-emphasis","--data-green-color-emphasis","--data-orange-color-emphasis","--data-purple-color-emphasis","--data-yellow-color-emphasis","--data-red-color-emphasis","--data-pink-color-emphasis","--data-teal-color-emphasis"];function Pl(t,e){const n=e?gd:No,o={...n};for(const[r,s]of Object.entries(Fl)){const i=t(s)?.trim();i&&(o[r]=i)}return o.chartColors=Yd.map((r,s)=>t(r)?.trim()||n.chartColors[s]),Nl(o),o}function jl(t,e){if(e!=="auto")return e==="dark";const o=t.closest("[data-color-mode]")?.getAttribute("data-color-mode");return o==="dark"||o==="light"?o==="dark":typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches}function Bl(){return typeof matchMedia=="function"&&matchMedia("(forced-colors: active)").matches}function Xd(t,e){if(Bl())return zl;const n=getComputedStyle(t);return Pl(o=>n.getPropertyValue(o)||void 0,jl(t,e))}async function Wd(t,e,n){if(Bl())return zl;let o;try{o=await Ri(()=>import("./portable-CiQthkEs.js"),[],import.meta.url)}catch(i){throw new Error(`theme="${t}" needs @datalayer/primer-addons (an optional peer of @datalayer/cells), which could not be loaded: ${i.message}`)}if(!o.themeVariants.includes(t))throw new Error(`No primer-addons theme '${t}'; there are ${o.themeVariants.join(", ")}.`);const r=jl(e,n),s=o.exportPortableTheme(t).modes[r?"dark":"light"];return Pl(i=>{const a=s[i];return a&&kr(a)?Vd(a,e,i===Fl.fontFamily):a},r)}const kr=t=>/\b(?:var|color-mix|calc)\(/.test(t);function Vd(t,e,n){const o=getComputedStyle(e),r=Kd(t,i=>o.getPropertyValue(i).trim()||void 0);if(!kr(r))return r||void 0;const s=e.ownerDocument.createElement("span");s.style.display="none",n?s.style.fontFamily=r:s.style.color=r,e.appendChild(s);try{const i=getComputedStyle(s),a=(n?i.fontFamily:i.color).trim();return a&&!kr(a)?a:void 0}finally{s.remove()}}function Kd(t,e){let n=t;for(let o=0;o<32&&n.includes("var(");o++){const r=n.lastIndexOf("var(");let s=0,i=r+4;for(;i<n.length;i++)if(n[i]==="(")s++;else if(n[i]===")"){if(s===0)break;s--}const a=n.slice(r+4,i),l=a.indexOf(","),c=(l<0?a:a.slice(0,l)).trim(),u=l<0?"":a.slice(l+1).trim();n=n.slice(0,r)+(e(c)??u)+n.slice(i+1)}return n}const cr=1e3,Gd=300;function Ci(t){return{"#DIV/0!":"division by zero","#REF!":"invalid reference","#NAME?":"unknown name","#VALUE!":"wrong type of value","#N/A":"not available","#NUM!":"invalid number","#NULL!":"empty intersection","#CYCLE!":"circular reference","#BUSY!":"still calculating","#SPILL!":"cannot spill","#ERROR!":"the code raised an error"}[t]??"error"}function Zd(t,e,n,o){const r=t.content(e,n,o);if(r!==null&&r.value===null&&r.formula===void 0){const c=t.cellType(e,n,o)?.value;if(c?.paintsEmpty===!0&&c.accessibleName!==void 0)return c.accessibleName(null,t.style(e,n,o),{sheet:e,row:n,col:o,model:t})}if(r===null){const c=t.dataSource(e)?.zone;if(c===void 0||!zt(c,{row:n,col:o}))return"";const u=t.value(e,n,o);return u===null?"":j(u)?`${u.error}, ${Ci(u.error)}`:pt(u).text}const s=t.value(e,n,o),i=t.style(e,n,o),a=t.cellType(e,n,o)?.value;let l=a?.accessibleName!==void 0?a.accessibleName(s,i,{sheet:e,row:n,col:o,model:t}):pt(s,i.format).text;return r.formula!==void 0&&(l+=`, formula: =${r.formula}`),j(s)&&(l+=`, ${Ci(s.error)}`),l}const $i={position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},dm=k.forwardRef(function(e,n){const o=k.useRef(null);if(e.model!==void 0&&e.defaultData!==void 0)throw new Error("<Spreadsheet> takes model (controlled) or defaultData (uncontrolled), not both.");const r=e.model!==void 0?"controlled":"uncontrolled";if(o.current===null)o.current=r;else if(o.current!==r)throw new Error(`<Spreadsheet> switched from ${o.current} to ${r} after mount; create a new component instead.`);if(r==="controlled"&&(e.plugins!==void 0||e.reactor!==void 0||e.readOnly!==void 0))throw new Error("plugins, reactor and readOnly configure the model the component creates; with a model prop, give them to createCellsModel.");const[s]=k.useState(()=>e.model===void 0?If({data:e.defaultData,plugins:e.reactor===void 0?e.plugins:void 0,reactor:e.reactor,readOnly:e.readOnly}):null),i=e.model??s,a=k.useId().replace(/:/g,""),l=`cells-${a}`;k.useLayoutEffect(()=>{c.current&&aa(c.current,l)},[l]);const c=k.useRef(null),u=k.useRef(null),h=k.useRef(null),d=k.useRef(null),f=k.useRef(null),m=k.useRef({x:new xi,y:new xi}),[g,w]=k.useState(null),[y,x]=k.useState(null),[$,A]=k.useState({width:0,height:0}),[O,D]=k.useState({width:0,height:0}),[I,U]=k.useState(""),[,X]=k.useState(0),[z,P]=k.useState(0),F=k.useRef(e);F.current=e;const K=e.sheet??i.selection.sheet,J=e.theme??"auto",Ae=e.colorMode??"auto";k.useLayoutEffect(()=>{const p=c.current;let v=!1;const b=()=>{typeof J=="object"?(Nl(J),x(J)):J==="auto"?x(Xd(p,Ae)):Wd(J,p,Ae).then(T=>{v||x(T)})};b();const E=new MutationObserver(b);for(let T=p.parentElement;T;T=T.parentElement)E.observe(T,{attributes:!0,attributeFilter:["data-color-mode","data-theme","data-light-theme","data-dark-theme","style","class"]});const S=typeof matchMedia=="function"?[matchMedia("(prefers-color-scheme: dark)"),matchMedia("(forced-colors: active)")]:[];for(const T of S)T.addEventListener("change",b);return()=>{v=!0,E.disconnect();for(const T of S)T.removeEventListener("change",b)}},[J,Ae]),k.useLayoutEffect(()=>{if(y===null)return;const p=new ud({model:i,grid:h.current,overlay:d.current,theme:y,showGridlines:F.current.showGridlines,showHeaders:F.current.showHeaders});return f.current=p,p.setSheet(K),p.setZoom(F.current.zoom??1),O.width>0&&p.setSize(O.width,O.height,devicePixelRatio||1),w(p.viewport),()=>{p.dispose(),f.current=null}},[i,y===null]),k.useEffect(()=>{y&&f.current?.setTheme(y)},[y]);const ae=k.useCallback(()=>{const p=f.current;if(p===null)return;const v=p.viewport;w(v);const b=v.panes.find(T=>T.name==="main"),E=ko(v.maxScrollX*v.zoom,b.width),S=ko(v.maxScrollY*v.zoom,b.height);A(T=>T.width===E&&T.height===S?T:{width:E,height:S}),F.current.onViewportChange?.({sheet:p.sheet,rows:[b.firstRow,b.lastRow],cols:[b.firstCol,b.lastCol]})},[]);k.useEffect(()=>{const p=f.current;p!==null&&(p.setOptions({showGridlines:e.showGridlines,showHeaders:e.showHeaders}),p.setZoom(e.zoom??1),p.setLocale(e.locale??$n),p.setSheet(K),ae())},[e.showGridlines,e.showHeaders,e.zoom,e.locale,K,ae,y]),k.useLayoutEffect(()=>{const p=c.current,v=()=>{const L=p.getBoundingClientRect(),G={width:Math.floor(L.width),height:Math.floor(L.height)};D(H=>H.width===G.width&&H.height===G.height?H:G),f.current?.setSize(G.width,G.height,devicePixelRatio||1),ae()};v();const b=new ResizeObserver(v);b.observe(p);let E=null;const S=()=>{E?.removeEventListener("change",T),E=typeof matchMedia=="function"?matchMedia(`(resolution: ${devicePixelRatio||1}dppx)`):null,E?.addEventListener("change",T)},T=()=>{v(),S()};return S(),()=>{b.disconnect(),E?.removeEventListener("change",T)}},[ae]);const[ce,bt]=k.useState(i.edit);k.useEffect(()=>i.subscribeEdit(bt),[i]),k.useEffect(()=>{const p=i.subscribe(E=>{X(S=>S+1),P(S=>S+1),U(Hd(E,F.current.messages)),F.current.onChange?.(E),ae()}),v=i.subscribeDataSourceErrors(E=>{F.current.onDataSourceError?.(E)}),b=i.subscribeSelection(E=>{X(S=>S+1),F.current.onSelectionChange?.(E),E.sheet!==f.current?.sheet&&F.current.sheet===void 0&&(f.current?.setSheet(E.sheet),ae())});return()=>{p(),b(),v()}},[i,ae]);const Me=k.useCallback(()=>{const p=f.current,v=u.current;if(p===null||v===null)return;const b=p.viewport,E=b.panes.find(L=>L.name==="main"),S=m.current.x.map(v.scrollLeft,{maxContent:b.maxScrollX*b.zoom,viewport:E.width}),T=m.current.y.map(v.scrollTop,{maxContent:b.maxScrollY*b.zoom,viewport:E.height});p.setScroll(S/b.zoom,T/b.zoom),ae()},[ae]),de=k.useCallback((p,v,b="nearest")=>{const E=f.current,S=u.current;if(E===null||S===null)return;const T=i.sheet(E.sheet),L=E.viewport,G=L.panes.find(We=>We.name==="main"),{x:H,y:W}=E.scroll,ge=T.cols.offsetOf(T.frozen.cols),re=T.rows.offsetOf(T.frozen.rows),Re=G.width/L.zoom,rt=G.height/L.zoom;let st=H,Ue=W;if(v>=T.frozen.cols){const We=T.cols.offsetOf(v)-ge,cn=T.cols.offsetOf(v+1)-ge;b==="start"||We<H?st=We:cn>H+Re&&(st=cn-Re)}if(p>=T.frozen.rows){const We=T.rows.offsetOf(p)-re,cn=T.rows.offsetOf(p+1)-re;b==="start"||We<W?Ue=We:cn>W+rt&&(Ue=cn-rt)}st===H&&Ue===W||(st=Math.min(Math.max(0,st),L.maxScrollX),Ue=Math.min(Math.max(0,Ue),L.maxScrollY),E.setScroll(st,Ue),S.scrollLeft=m.current.x.domFor(st*L.zoom,{maxContent:L.maxScrollX*L.zoom,viewport:G.width}),S.scrollTop=m.current.y.domFor(Ue*L.zoom,{maxContent:L.maxScrollY*L.zoom,viewport:G.height}),ae())},[i,ae]),[De,ue]=k.useState(null),[xt,ot]=k.useState(null),R=k.useRef(xt);R.current=xt;const ee=k.useRef(null),me=k.useRef(!1),ie=()=>{ee.current!==null&&clearTimeout(ee.current.timer),ee.current=null},[Xe,tn]=k.useState(null),vt=k.useRef(!1),nn=k.useCallback((p,v)=>y===null?p.length*8:Yl(zo(v,y,1),p),[y]),Et=k.useMemo(()=>({get sheet(){return f.current?.sheet??i.selection.sheet},get pageRows(){const p=f.current;if(p===null)return 1;const v=p.viewport.panes.find(b=>b.name==="main");return Math.max(1,v.lastRow-v.firstRow)},scrollTo:(p,v)=>de(p,v),openMenu:()=>{const p=f.current;if(p===null)return;const v=i.sheet(p.sheet),b=p.viewport.panes.find(S=>S.name==="main"),E=Se(b,p.viewport.zoom,v.rows,v.cols,i.selection.active.row,i.selection.active.col);ue({x:E.x+E.width/2,y:E.y+E.height})},focusOutput:(p,v)=>{const b=c.current?.querySelector(`[data-cells-code-output="${et(p,v)}"]`);return b==null?!1:(b.focus({preventScroll:!1}),!0)},openCodeEditor:(p,v)=>{const b=f.current;if(b===null)return;const E=i.sheet(b.sheet),S=b.viewport.panes.find(L=>L.name==="main"),T=Se(S,b.viewport.zoom,E.rows,E.cols,p,v);ot(null),tn({row:p,col:v,x:T.x,y:T.y+T.height})},previewOutput:(p,v)=>{const b=f.current;if(b===null)return!1;const E=i.code(b.sheet,p,v);if(E===void 0||So(E).length===0||Wt(E)!==void 0)return!1;const S=i.sheet(b.sheet),T=b.viewport.panes.find(G=>G.name==="main"),L=Se(T,b.viewport.zoom,S.rows,S.cols,p,v);return ot({row:p,col:v,x:L.x,y:L.y+L.height}),!0}}),[i,de]),It=k.useMemo(()=>({model:i,measure:nn,grid:Et}),[i,nn,Et]);k.useEffect(()=>(Ks(It),()=>Ju(It)),[It]);const kt=k.useCallback(p=>{i.reactor.executeCommand(p,It).catch(v=>{U(v.message),F.current.onCommandRejected?.({ok:!1,refusals:[{reason:"Command",message:v.message}]})})},[i,It]),Nn=k.useCallback(p=>{const v=i.cellType(p.sheet,p.row,p.col)?.value;if(v?.activate===void 0)return!1;const b=i.value(p.sheet,p.row,p.col),E={workbook:i.workbook,value:(L,G,H)=>i.value(L,G,H),contributions:L=>i.reactor.getContributions(L).map(G=>G.value)},S=v.activate(p,b,E);if(S===void 0)return!0;if("open"in S)return typeof window<"u"&&window.open(S.open,"_blank","noopener,noreferrer"),!0;const T=i.dispatch(S.command);return T.ok||(U(T.refusals[0]?.message??`${v.id} refused.`),F.current.onCommandRejected?.(T)),!0},[i]),Oo=k.useCallback(p=>{if(i.selectedChart===null)return!1;const b={ArrowUp:["moveUp","shrinkUp"],ArrowDown:["moveDown","growDown"],ArrowLeft:["moveLeft","shrinkLeft"],ArrowRight:["moveRight","growRight"]}[p.key];let E;if(b!==void 0)E=`cells.chart.${p.shiftKey?b[1]:b[0]}`;else if(p.key==="Delete"||p.key==="Backspace")E="cells.chart.delete";else{if(p.key==="Escape")return i.selectChart(null),c.current?.focus({preventScroll:!0}),p.preventDefault(),!0;p.key==="Enter"&&p.shiftKey&&(E="cells.chart.showData")}return E===void 0?!1:(p.preventDefault(),kt(E),!0)},[i,kt]),ls=k.useCallback((p,v)=>{const b=f.current,E=c.current;if(b===null||E===null)return;const S=E.getBoundingClientRect(),T=Tl(b.viewport,p.clientX-S.left,p.clientY-S.top);if(T===void 0)return;const L=i.sheet(b.sheet),G=Se(T,b.viewport.zoom,L.rows,L.cols,v.row,v.col);return{...G,px:p.clientX-S.left-G.x,py:p.clientY-S.top-G.y}},[i]),Xl=k.useCallback(p=>{if(p.target!==c.current)return;const v=f.current;if(v===null||((p.ctrlKey||p.metaKey)&&p.shiftKey&&p.key.toLowerCase()==="v"&&(Io.current=!0),Oo(p)))return;if(p.key==="Escape"&&i.clipboardMark!==null){i.clearClipboardMark();return}if(p.key==="Escape"){vt.current=!0,U("Press Tab to leave the grid.");return}if(p.key==="Tab"&&vt.current){vt.current=!1;return}if(vt.current=!1,!p.ctrlKey&&!p.metaKey&&!p.altKey&&i.selection.sheet===v.sheet){const S=i.selection.active,T=i.cellType(v.sheet,S.row,S.col)?.value;if(T?.activateOn?.includes(p.key)&&T.activate!==void 0){p.preventDefault(),Nn({sheet:v.sheet,row:S.row,col:S.col});return}}const b=em(i,p.nativeEvent,F.current.keymap);if(b!==void 0){p.preventDefault(),kt(b);return}const E=p.ctrlKey||p.metaKey;if(!i.readOnly&&!E&&!p.altKey&&(p.key.length===1||p.key==="Process")){p.preventDefault();const S=i.selection.active;if(i.cellType(v.sheet,S.row,S.col)?.value.editable===!1)return;de(i.selection.active.row,i.selection.active.col),i.startEdit(void 0,p.key==="Process"?"":p.key)}},[i,de,kt,Nn]),Io=k.useRef(!1),as=k.useCallback((p,v)=>{if(p.target.closest?.("[data-cells-editor], [data-cells-menu], [data-cells-chart], [data-cells-chart-holder]"))return;p.preventDefault();const b=i.copy(void 0,{cut:v}),{text:E,html:S}=Wf(b,i);p.clipboardData.setData("text/plain",E),p.clipboardData.setData("text/html",S);const T=b.source.zone;U(`${v?"Cut":"Copied"} ${Oe(T)}`)},[i]),Wl=k.useCallback(p=>{if(p.target.closest?.("[data-cells-editor], [data-cells-menu], [data-cells-chart], [data-cells-chart-holder]"))return;p.preventDefault();const v=Io.current?"values":"all";if(Io.current=!1,i.readOnly)return;let b;try{b=Gf(p.clipboardData.getData("text/html")||void 0,p.clipboardData.getData("text/plain")||void 0)}catch(L){U(`Nothing pasted: ${L.message}`);return}if(b===void 0)return;const E=i.paste(b,void 0,{special:v});if(!E.ok){U(E.refusals.map(L=>L.message).join(" ")),F.current.onCommandRejected?.(E);return}const S=i.selection.active,T={top:S.row,left:S.col,bottom:S.row+b.rows-1,right:S.col+b.cols-1};i.select({...i.selection,zones:[T],anchor:S,active:S}),U(`Pasted ${Oe(T)}`)},[i]),On=k.useRef(!1),_t=k.useRef(null),[In,_o]=k.useState(null),on=k.useRef(null),[rn,Lo]=k.useState(null),cs=k.useCallback(()=>{const p=f.current;if(p===null)return;const v=i.selection;if(v.sheet!==p.sheet)return;const b=v.zones[v.zones.length-1],E=i.sheet(p.sheet),S=p.viewport.panes.find(L=>b.bottom>=L.firstRow&&b.bottom<=L.lastRow&&b.right>=L.firstCol&&b.right<=L.lastCol);if(S===void 0)return;const T=Se(S,p.viewport.zoom,E.rows,E.cols,b.bottom,b.right);return{x:T.x+T.width,y:T.y+T.height,zone:b}},[i]),Vl=k.useCallback((p,v)=>{const b=v.row-p.bottom,E=p.top-v.row,S=v.col-p.right,T=p.left-v.col,L=Math.max(b,E,S,T);return L<=0?p:L===b?{...p,bottom:v.row}:L===E?{...p,top:v.row}:L===S?{...p,right:v.col}:{...p,left:v.col}},[]),sn=k.useRef(null),ln=k.useRef(!1),Do=k.useCallback(p=>{const v=f.current,b=i.sheet(v.sheet),E=v.viewport.panes.find(L=>L.name==="main"),S=Se(E,v.viewport.zoom,b.rows,b.cols,p.top,p.left),T=Se(E,v.viewport.zoom,b.rows,b.cols,p.bottom,p.right);return{x:S.x,y:S.y,width:T.x+T.width-S.x,height:T.y+T.height-S.y}},[i]),an=k.useCallback(p=>{const v=f.current,b=c.current;if(v===null||b===null)return;const E=b.getBoundingClientRect(),S=i.sheet(v.sheet);return nd(v.viewport,S.rows,S.cols,p.clientX-E.left,p.clientY-E.top)},[i]),_n=k.useCallback((p,v,b)=>{const E=f.current;if(E===null)return;const S=i.sheet(E.sheet),T=Math.min(v,b),L=Math.max(v,b),G=p==="cols"?{top:0,bottom:S.rows.count-1,left:T,right:L}:{left:0,right:S.cols.count-1,top:T,bottom:L},H=p==="cols"?{row:0,col:v}:{row:v,col:0};i.select({sheet:E.sheet,zones:[G],anchor:H,active:H})},[i]),_e=k.useCallback(p=>{const v=f.current,b=c.current;if(v===null||b===null)return;const E=b.getBoundingClientRect(),S=i.sheet(v.sheet);return ed(v.viewport,S.rows,S.cols,p.clientX-E.left,p.clientY-E.top)},[i]),Kl=k.useCallback(p=>{if(p.target.closest("[data-cells-editor], [data-cells-popup], [data-cells-chart], [data-cells-chart-holder]"))return;const v=i.edit;if(v!==null&&p.button===0&&Le(v.text)){const H=c.current?.querySelector("[data-cells-editor]"),W=_e(p),ge=H?.selectionStart??v.text.length,re=sn.current;if(W!==void 0&&H&&(re!==null&&re.end===ge||is(v.text,ge))){p.preventDefault();const Re=p.shiftKey&&re!==null?re.anchor:W;Sr(i,sn,v,Re,W,ge),ln.current=!0,p.target.setPointerCapture?.(p.pointerId),H.focus({preventScroll:!0});return}}if(i.edit!==null){const H=i.commitEdit();if(!H.ok){F.current.onCommandRejected?.(H);return}}c.current?.focus({preventScroll:!0});const b=p.button===0&&!i.readOnly?cs():void 0;if(b!==void 0){const H=c.current.getBoundingClientRect(),W=p.clientX-H.left,ge=p.clientY-H.top;if(Math.abs(W-b.x)<=12&&Math.abs(ge-b.y)<=12){on.current={source:b.zone,target:b.zone},Lo(Do(b.zone)),p.target.setPointerCapture?.(p.pointerId);return}}const E=p.button===0?an(p):void 0;if(E!==void 0&&f.current!==null){const H=i.sheet(f.current.sheet),W=E.axis==="rows"?H.rows:H.cols;if(E.edge!==void 0&&!i.readOnly)_t.current={kind:"resize",axis:E.axis,index:E.edge,start:E.axis==="rows"?p.clientY:p.clientX,size:W.sizeOf(E.edge)},_o({axis:E.axis,at:E.axis==="rows"?E.y:E.x});else{const ge=i.selection,re=p.shiftKey?E.axis==="cols"?ge.anchor.col:ge.anchor.row:E.index;_n(E.axis,re,E.index),_t.current={kind:"select",axis:E.axis,from:re}}p.target.setPointerCapture?.(p.pointerId);return}const S=_e(p),T=f.current;if(S===void 0||T===null||p.button!==0)return;const L=i.selection.sheet===T.sheet?i.selection:we(T.sheet),G={top:S.row,left:S.col,bottom:S.row,right:S.col};if(p.shiftKey?i.select({...L,zones:[...L.zones.slice(0,-1),{top:Math.min(L.anchor.row,S.row),left:Math.min(L.anchor.col,S.col),bottom:Math.max(L.anchor.row,S.row),right:Math.max(L.anchor.col,S.col)}]}):p.ctrlKey||p.metaKey?i.select({...L,zones:[...L.zones,G],anchor:S,active:S}):i.select(we(T.sheet,S)),On.current=!0,p.target.setPointerCapture?.(p.pointerId),F.current.onCellClick?.({sheet:T.sheet,...S},p),!p.shiftKey&&!p.ctrlKey&&!p.metaKey&&p.isPrimary!==!1){const H=i.cellType(T.sheet,S.row,S.col)?.value;if(H?.activate!==void 0){const W=ls(p,S);W!==void 0&&(H.hitTest===void 0||H.hitTest({x:W.px,y:W.py},{width:W.width,height:W.height}))&&Nn({sheet:T.sheet,...S})}}},[i,_e,ls,Nn]),Gl=p=>{const v=f.current,b=v===null?void 0:_e(p),E=ee.current;if(b!==void 0&&E!==null&&E.row===b.row&&E.col===b.col)return;ie();const S=R.current;if(S!==null&&(b===void 0||S.row!==b.row||S.col!==b.col)&&(me.current||ot(null)),b===void 0||v===null)return;const T=i.code(v.sheet,b.row,b.col);T===void 0||So(T).length===0||Wt(T)!==void 0||S!==null&&S.row===b.row&&S.col===b.col||(ee.current={row:b.row,col:b.col,timer:setTimeout(()=>{ee.current=null,Et.previewOutput?.(b.row,b.col)},Gd)})},Zl=k.useCallback(p=>{if(!ln.current&&on.current===null&&_t.current===null&&!On.current&&Gl(p),ln.current){const re=i.edit,Re=sn.current,rt=_e(p);re!==null&&Re!==null&&rt!==void 0&&Sr(i,sn,re,Re.anchor,rt,Re.start);return}const v=on.current;if(v!==null){const re=_e(p);re!==void 0&&(v.target=Vl(v.source,re),Lo(Do(v.target)));return}const b=_t.current;if(b!==null){const re=an(p);if(b.kind==="select")re!==void 0&&re.axis===b.axis&&_n(b.axis,b.from,re.index);else{const Re=c.current.getBoundingClientRect();_o({axis:b.axis,at:b.axis==="rows"?p.clientY-Re.top:p.clientX-Re.left})}return}const E=an(p),S=cs(),T=c.current.getBoundingClientRect(),L=S!==void 0&&Math.abs(p.clientX-T.left-S.x)<=12&&Math.abs(p.clientY-T.top-S.y)<=12;if(c.current.style.cursor=L?"crosshair":E?.edge!==void 0?E.axis==="cols"?"col-resize":"row-resize":"",!On.current)return;const G=_e(p);if(G===void 0)return;const H=i.selection,W={top:Math.min(H.anchor.row,G.row),left:Math.min(H.anchor.col,G.col),bottom:Math.max(H.anchor.row,G.row),right:Math.max(H.anchor.col,G.col)},ge=H.zones[H.zones.length-1];ge.top===W.top&&ge.left===W.left&&ge.bottom===W.bottom&&ge.right===W.right||i.select({...H,zones:[...H.zones.slice(0,-1),W]})},[i,_e]),Jl=k.useCallback(p=>{if(ln.current){ln.current=!1;return}On.current=!1;const v=on.current;if(v!==null){if(on.current=null,Lo(null),!(JSON.stringify(v.source)===JSON.stringify(v.target))){const Ue=i.dispatch({type:"FILL",sheet:i.selection.sheet,source:v.source,target:v.target,mode:p.ctrlKey||p.metaKey?"copy":"series"});Ue.ok?(i.select({...i.selection,zones:[v.target]}),U(`Filled ${Oe(v.target)}`)):(U(Ue.refusals.map(We=>We.message).join(" ")),F.current.onCommandRejected?.(Ue))}return}const b=_t.current;if(_t.current=null,b===null||b.kind!=="resize")return;_o(null);const E=f.current;if(E===null)return;const S=E.viewport.zoom,T=((b.axis==="rows"?p.clientY:p.clientX)-b.start)/S,L=Math.max(4,Math.round(b.size+T));if(L===b.size)return;const G=i.selection,H=i.sheet(E.sheet),W=G.zones[G.zones.length-1],ge=b.axis==="cols"?W.top===0&&W.bottom===H.rows.count-1&&b.index>=W.left&&b.index<=W.right:W.left===0&&W.right===H.cols.count-1&&b.index>=W.top&&b.index<=W.bottom,[re,Re]=ge?b.axis==="cols"?[W.left,W.right]:[W.top,W.bottom]:[b.index,b.index],rt=i.dispatch({type:"RESIZE_AXIS",sheet:E.sheet,axis:b.axis,from:re,to:Re,size:L});rt.ok||F.current.onCommandRejected?.(rt)},[i]),ql=k.useCallback(p=>{const v=f.current;if(v===null||i.readOnly||p.button!==0||p.target.closest("[data-cells-editor], [data-cells-chart], [data-cells-chart-holder]"))return;const b=an(p);if(b===void 0){const E=_e(p);if(E===void 0)return;if(p.preventDefault(),(i.selection.sheet!==v.sheet||i.selection.active.row!==E.row||i.selection.active.col!==E.col)&&i.select(we(v.sheet,E)),i.code(v.sheet,E.row,E.col)!==void 0){Et.openCodeEditor?.(E.row,E.col);return}i.startEdit(E);return}if(b.edge!==void 0)if(b.axis==="cols"){const E=i.selection,S=E.zones[E.zones.length-1];b.edge>=S.left&&b.edge<=S.right||_n("cols",b.edge,b.edge),kt("cells.fitColumns")}else{const E=i.sheet(v.sheet);i.dispatch({type:"RESIZE_AXIS",sheet:v.sheet,axis:"rows",from:b.edge,to:b.edge,size:E.rows.defaultSize})}},[i,an,_e,_n,kt,Oo,Et]),Ql=k.useCallback(p=>{const v=_e(p),b=f.current;if(v===void 0||b===null||(F.current.onContextMenu?.({sheet:b.sheet,...v},p),p.defaultPrevented))return;p.preventDefault();const E=i.selection;(E.sheet!==b.sheet||!E.zones.some(T=>zt(T,v)))&&i.select(we(b.sheet,v));const S=c.current.getBoundingClientRect();ue({x:p.clientX-S.left,y:p.clientY-S.top})},[i,_e]);k.useImperativeHandle(n,()=>({model:i,dispatch:p=>{const v=i.dispatch(p);return v.ok||F.current.onCommandRejected?.(v),v},transact:(p,v)=>i.transact(p,v),undo:()=>i.undo(),redo:()=>i.redo(),select:p=>{const{sheet:v,zone:b}=es(i,p),E={row:b.top,col:b.left};i.select({sheet:v,zones:[b],anchor:E,active:E})},getSelection:()=>i.selection,scrollTo:(p,v)=>{const{row:b,col:E}=Qr(i,p);de(b,E,v?.align)},focus:()=>c.current?.focus(),toJSON:()=>i.toJSON(),repaint:()=>f.current?.repaint(),renderStats:()=>f.current?{...f.current.counters}:void 0}),[i,de]);const he=i.workbook.hasSheet(K)?i.sheet(K):i.sheets[0],Te=i.selection,ea=(p,v)=>`${a}-r${p}-c${v}`,Ln=k.useMemo(()=>{if(g===null)return{rows:[],cols:[]};const p=new Set,v=new Set;for(const S of g.panes){for(let T=S.firstRow;T<=S.lastRow;T+=1)he.rows.effectiveSizeOf(T)>0&&p.add(T);for(let T=S.firstCol;T<=S.lastCol;T+=1)he.cols.effectiveSizeOf(T)>0&&v.add(T)}Te.sheet===he.id&&(p.add(Te.active.row),v.add(Te.active.col));let b=[...p].sort((S,T)=>S-T),E=[...v].sort((S,T)=>S-T);if(b.length*E.length>cr){const S=Math.min(E.length,Math.floor(cr/Math.max(1,Math.min(b.length,20))));E=Mi(E,Te.active.col,S),b=Mi(b,Te.active.row,Math.floor(cr/E.length))}return{rows:b,cols:E}},[g,he,Te.active.row,Te.active.col,Te.sheet]),ta=Ln.cols.join(","),us=k.useMemo(()=>Ln.cols,[ta]),na=p=>{if(Te.sheet!==he.id)return"";const v=[];for(const b of us)Te.zones.some(E=>zt(E,{row:p,col:b}))&&v.push(b);return v.join(",")},oa=Te.sheet===he.id?ea(Te.active.row,Te.active.col):void 0,ra=g?.panes.find(p=>p.name==="main");return C.jsx(Pf,{model:i,children:C.jsxs("div",{className:e.className,style:{position:"relative",width:"100%",height:"100%",...e.style},"data-cells":"",children:[C.jsxs("div",{ref:c,style:{position:"absolute",inset:0,overflow:"hidden",outline:"none"},role:"grid",tabIndex:0,"aria-label":e["aria-label"]??`Spreadsheet, ${he.name}`,"aria-rowcount":he.rows.count+1,"aria-colcount":he.cols.count+1,"aria-multiselectable":"true","aria-description":"Arrow keys move between cells, Tab and Enter too. Press Escape, then Tab, to leave the grid.","aria-readonly":i.readOnly||void 0,"aria-activedescendant":oa,"data-cells-sheet":he.id,onKeyDown:Xl,onFocus:()=>Ks(It),onPointerDown:Kl,onPointerMove:Zl,onPointerLeave:()=>{ie(),me.current||ot(null)},onPointerUp:Jl,onDoubleClick:ql,onContextMenu:Ql,onCopy:p=>as(p,!1),onCut:p=>as(p,!0),onPaste:Wl,children:[C.jsx("div",{ref:u,onScroll:Me,"data-cells-scroller":"",style:{position:"absolute",left:g?g.panes.find(p=>p.name==="main").x:0,top:g?g.panes.find(p=>p.name==="main").y:0,right:0,bottom:0,overflow:"auto"},children:C.jsx("div",{style:{width:$.width,height:$.height}})}),C.jsx("canvas",{ref:h,"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:O.width,height:O.height,pointerEvents:"none"}}),C.jsx("canvas",{ref:d,"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:O.width,height:O.height,pointerEvents:"none"}}),C.jsxs("div",{style:$i,"data-cells-mirror":"",children:[C.jsx("div",{role:"row","aria-rowindex":1,children:Ln.cols.map(p=>C.jsx("div",{role:"columnheader","aria-colindex":p+2,children:Ye(p)},p))}),Ln.rows.map(p=>C.jsx(nm,{model:i,sheet:he.id,row:p,cols:us,uid:a,selected:na(p),revision:z},p))]}),g!==null&&y!==null&&C.jsx(Cd,{model:i,sheet:he.id,viewport:g,theme:y,selectedChart:i.selectedChart,onPointerDownChart:p=>i.selectChart(p),onChartKeyDown:Oo}),g!==null&&y!==null&&C.jsx(Nd,{model:i,sheet:he.id,viewport:g,theme:y,editing:Xe,preview:xt,onClosePreview:()=>{me.current=!1,ot(null)},onPreviewPointer:p=>{me.current=p,p||ot(null)},portalName:l,returnFocusRef:c,onCloseEditor:()=>{tn(null),c.current?.focus({preventScroll:!0})},onEscape:()=>c.current?.focus({preventScroll:!0})}),ce!==null&&g!==null&&ce.sheet===he.id&&y!==null&&C.jsx(qd,{model:i,edit:ce,viewport:g,theme:y,onDone:p=>{if(c.current?.focus({preventScroll:!0}),p){const v=i.selection,b=Kr(v,p,Gr(i.sheet(v.sheet)));i.select(b),de(b.active.row,b.active.col)}},onRejected:p=>F.current.onCommandRejected?.(p),point:sn}),In!==null&&C.jsx("div",{"aria-hidden":"true",style:In.axis==="cols"?{position:"absolute",top:0,bottom:0,left:In.at,width:0,borderLeft:`1px dashed ${y?.selectionBorder??"Highlight"}`,zIndex:3,pointerEvents:"none"}:{position:"absolute",left:0,right:0,top:In.at,height:0,borderTop:`1px dashed ${y?.selectionBorder??"Highlight"}`,zIndex:3,pointerEvents:"none"}}),ce!==null&&g!==null&&y!==null&&ce.sheet===he.id&&Ul(ce.text).filter(p=>p.sheet===void 0||p.sheet.toLowerCase()===he.name.toLowerCase()).map((p,v)=>{const b=Do({top:p.top??0,left:p.left??0,bottom:Math.min(p.bottom??he.rows.count-1,he.rows.count-1),right:Math.min(p.right??he.cols.count-1,he.cols.count-1)}),E=y.referenceColors[v%y.referenceColors.length];return C.jsx("div",{"data-cells-reference":ce.text.slice(p.start,p.end),style:{position:"absolute",left:b.x,top:b.y,width:b.width,height:b.height,boxSizing:"border-box",border:`2px dashed ${E}`,background:`${E}14`,pointerEvents:"none",zIndex:1}},`${p.start}-${p.end}`)}),rn!==null&&C.jsx("div",{"aria-hidden":"true","data-cells-fill-preview":"",style:{position:"absolute",left:rn.x,top:rn.y,width:rn.width,height:rn.height,border:`1px dashed ${y?.selectionBorder??"Highlight"}`,boxSizing:"border-box",pointerEvents:"none",zIndex:3}}),De!==null&&C.jsx(tm,{model:i,x:De.x,y:De.y,keymap:e.keymap,portalName:l,returnFocusRef:c,onRun:p=>{ue(null),c.current?.focus({preventScroll:!0}),kt(p)},onClose:()=>{ue(null),c.current?.focus({preventScroll:!0})}}),e.debug&&f.current&&ra&&C.jsx(om,{renderer:f.current,model:i}),e.children]}),C.jsx("div",{style:$i,"aria-live":"polite","data-cells-live":"",children:I})]})})});function Sr(t,e,n,o,r,s){const i=e.current,a=i!==null&&(i.end===s||i.start===s),l=a?i.start:s,c=a?i.end:s,u=Dd(o,r);t.setEditText(n.text.slice(0,l)+u+n.text.slice(c)),e.current={start:l,end:l+u.length,anchor:o,active:r}}const Jd={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};function Ai(t){return{position:"absolute",maxWidth:420,padding:"4px 0",font:`${t.headerFontSize}px ${t.fontFamily}`,background:t.background,color:t.text,border:`1px solid ${t.gridline}`,boxShadow:"0 2px 6px rgba(0,0,0,0.2)",zIndex:3,paddingInline:8}}function qd(t){const{model:e,edit:n,viewport:o,theme:r,point:s}=t,i=k.useRef(null),a=k.useRef(!1),[l,c]=k.useState(""),u=k.useId(),h=e.sheet(n.sheet),d=o.panes.find(R=>n.row>=R.firstRow&&n.row<=R.lastRow&&n.col>=R.firstCol&&n.col<=R.lastCol)??o.panes.find(R=>R.name==="main"),f=h.mergeAt(n.row,n.col),m=Se(d,o.zoom,h.rows,h.cols,n.row,n.col),g=f?Se(d,o.zoom,h.rows,h.cols,f.bottom,f.right):m,w=g.x+g.width-m.x,y=g.y+g.height-m.y,x=e.style(n.sheet,n.row,n.col),$=zo(x,r,o.zoom),A=k.useMemo(()=>{const R=n.text.split(`
80
+ `).length+1)),style:{fontFamily:"var(--fontStack-monospace, monospace)"},onChange:f=>c(f.target.value)}),C.jsxs("div",{style:{marginTop:8,display:"flex",gap:8},children:[C.jsx(hs,{size:"small",variant:"primary",onClick:d,children:"Save"}),C.jsx(hs,{size:"small",onClick:r,children:"Cancel"})]})]})}const Le=t=>t.startsWith("=");function ss(t){return Ui(t.slice(1)).map(e=>({...e,start:e.start+1,end:e.end+1}))}function is(t,e){if(!Le(t)||e<1)return!1;let n=e-1;for(;n>0&&t[n]===" ";)n-=1;if(n===0)return!0;const o=ss(t).filter(s=>s.end<=n+1&&s.kind!=="whitespace"),r=o[o.length-1];return r===void 0?!0:r.kind==="lparen"||r.kind==="separator"||r.kind==="lbrace"||r.kind==="operator"&&r.text!=="%"}function Dd(t,e,n){const o=Math.min(t.row,e.row),r=Math.max(t.row,e.row),s=Math.min(t.col,e.col),i=Math.max(t.col,e.col),a=`${Ye(s)}${o+1}`,l=`${Ye(i)}${r+1}`;return""+(a===l?a:`${a}:${l}`)}function Si(t){const e=/^\$?([A-Za-z]{1,3})?\$?([0-9]{1,7})?$/.exec(t);if(e===null)return{};let n;if(e[1]!==void 0){n=0;for(const o of e[1].toUpperCase())n=n*26+(o.charCodeAt(0)-64);n-=1}return{col:n,row:e[2]===void 0?void 0:Number(e[2])-1}}function Ul(t){if(!Le(t))return[];const e=ss(t),n=[];for(let o=0;o<e.length;o+=1){let r=e[o],s,i=r.start;if(r.kind==="sheet"){const d=r.text.slice(0,-1);if(s=d.startsWith("'")?d.slice(1,-1).replace(/''/g,"'"):d,o+=1,r=e[o],r===void 0||r.kind!=="ref")continue}else i=r.start;if(r.kind!=="ref")continue;const a=Si(r.text);let l=a,c=r.end;e[o+1]?.kind==="operator"&&e[o+1].text===":"&&e[o+2]?.kind==="ref"&&(l=Si(e[o+2].text),c=e[o+2].end,o+=2);const u=[a.row,l.row].filter(d=>d!==void 0),h=[a.col,l.col].filter(d=>d!==void 0);n.push({start:i,end:c,...s!==void 0?{sheet:s}:{},...u.length>0?{top:Math.min(...u),bottom:Math.max(...u)}:{},...h.length>0?{left:Math.min(...h),right:Math.max(...h)}:{}})}return n}const Ud=[(t,e)=>`$${t}$${e}`,(t,e)=>`${t}$${e}`,(t,e)=>`$${t}${e}`,(t,e)=>`${t}${e}`];function Fd(t,e){const n=Ul(t).find(f=>e>=f.start&&e<=f.end);if(n===void 0)return;const o=t.slice(n.start,n.end),r=o.lastIndexOf("!"),s=r>=0?o.slice(0,r+1):"",a=o.slice(s.length).split(":").map(f=>/^(\$?)([A-Za-z]{1,3})(\$?)([0-9]{1,7})$/.exec(f));if(a.some(f=>f===null))return;const l=a[0],c=(l[1]?2:0)+(l[3]?1:0),u={3:1,1:2,2:0,0:3}[c],h=Ud[{3:0,1:1,2:2,0:3}[u]],d=s+a.map(f=>h(f[2],f[4])).join(":");return{text:t.slice(0,n.start)+d+t.slice(n.end),caret:n.start+d.length}}function Pd(t,e){if(!Le(t))return;let n=e;for(;n>1&&/[A-Za-z0-9_.]/.test(t[n-1]);)n-=1;const o=t.slice(n,e);if(/^[A-Za-z][A-Za-z0-9_.]*$/.test(o)&&t[e]!=="("&&is(t,n))return{start:n,prefix:o}}function jd(t,e){if(!Le(t))return;const n=[];let o;for(const r of ss(t)){if(r.start>=e)break;if(r.kind==="lparen")n.push({name:o?.kind==="function"?o.text.toUpperCase():void 0,argument:0});else if(r.kind==="rparen")n.pop();else if(r.kind==="separator"){const s=n[n.length-1];s!==void 0&&(s.argument+=1)}r.kind!=="whitespace"&&(o=r)}for(let r=n.length-1;r>=0;r-=1){const s=n[r];if(s.name!==void 0)return{name:s.name,argument:s.argument}}}const be=(t,e)=>n=>e(n),wn=t=>t.axis==="rows"?t.n===1?"row":"rows":t.n===1?"column":"columns",Bd={SET_CELLS:be("SET_CELLS",t=>`Edited ${hr(t.at)}`),SET_STYLE:be("SET_STYLE",t=>`Formatted ${Oe(t.zone)}`),CLEAR:be("CLEAR",t=>`Cleared ${Oe(t.zone)}`),INSERT_AXIS:be("INSERT_AXIS",t=>`Inserted ${t.n} ${wn(t)} at ${t.at+1}`),DELETE_AXIS:be("DELETE_AXIS",t=>`Deleted ${t.n} ${wn(t)} at ${t.at+1}`),MOVE_AXIS:be("MOVE_AXIS",t=>`Moved ${t.n} ${wn(t)}`),RESIZE_AXIS:be("RESIZE_AXIS",t=>`Resized ${wn({axis:t.axis,n:t.to-t.from+1})}`),HIDE_AXIS:be("HIDE_AXIS",t=>`${t.hidden?"Hid":"Showed"} ${wn({axis:t.axis,n:t.to-t.from+1})}`),MERGE:be("MERGE",t=>`Merged ${Oe(t.zone)}`),UNMERGE:be("UNMERGE",t=>`Unmerged ${Oe(t.zone)}`),ADD_SHEET:be("ADD_SHEET",t=>`Added sheet ${t.name??""}`.trim()),DELETE_SHEET:be("DELETE_SHEET",()=>"Deleted a sheet"),RENAME_SHEET:be("RENAME_SHEET",t=>`Renamed the sheet to ${t.name}`),MOVE_SHEET:be("MOVE_SHEET",()=>"Moved a sheet"),FREEZE:be("FREEZE",t=>`Froze ${t.rows} rows and ${t.cols} columns`),INSERT_CHART:t=>`Inserted a ${t.chart.type} chart`,UPDATE_CHART:()=>"Changed the chart",MOVE_CHART:()=>"Moved the chart",RESIZE_CHART:()=>"Resized the chart",DELETE_CHART:()=>"Deleted the chart"};function Hd(t,e=Bd){const n=t.label.toLowerCase().replace(/_/g," ");if(t.origin==="undo")return`Undo: ${n}`;if(t.origin==="redo")return`Redo: ${n}`;if(t.commands.length===1){const o=e[t.commands[0].type];if(o)return o(t.commands[0])}return t.label}const Fl={background:"--bgColor-default",text:"--fgColor-default",textMuted:"--fgColor-muted",gridline:"--borderColor-muted",headerBackground:"--bgColor-muted",headerText:"--fgColor-muted",headerBorder:"--borderColor-default",headerSelectedBackground:"--bgColor-accent-muted",selectionFill:"--bgColor-accent-muted",selectionBorder:"--borderColor-accent-emphasis",activeCellBorder:"--borderColor-accent-emphasis",fillHandle:"--borderColor-accent-emphasis",copyMarch:"--borderColor-accent-emphasis",errorText:"--fgColor-danger",linkText:"--fgColor-accent",fontFamily:"--fontStack-sansSerif",chartAxis:"--fgColor-muted",chartGridline:"--borderColor-muted",chartText:"--fgColor-default",chartBackground:"--bgColor-default"},Yd=["--data-blue-color-emphasis","--data-green-color-emphasis","--data-orange-color-emphasis","--data-purple-color-emphasis","--data-yellow-color-emphasis","--data-red-color-emphasis","--data-pink-color-emphasis","--data-teal-color-emphasis"];function Pl(t,e){const n=e?gd:No,o={...n};for(const[r,s]of Object.entries(Fl)){const i=t(s)?.trim();i&&(o[r]=i)}return o.chartColors=Yd.map((r,s)=>t(r)?.trim()||n.chartColors[s]),Nl(o),o}function jl(t,e){if(e!=="auto")return e==="dark";const o=t.closest("[data-color-mode]")?.getAttribute("data-color-mode");return o==="dark"||o==="light"?o==="dark":typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches}function Bl(){return typeof matchMedia=="function"&&matchMedia("(forced-colors: active)").matches}function Xd(t,e){if(Bl())return zl;const n=getComputedStyle(t);return Pl(o=>n.getPropertyValue(o)||void 0,jl(t,e))}async function Wd(t,e,n){if(Bl())return zl;let o;try{o=await Ri(()=>import("./portable-DeuNvN1G.js"),[],import.meta.url)}catch(i){throw new Error(`theme="${t}" needs @datalayer/primer-addons (an optional peer of @datalayer/cells), which could not be loaded: ${i.message}`)}if(!o.themeVariants.includes(t))throw new Error(`No primer-addons theme '${t}'; there are ${o.themeVariants.join(", ")}.`);const r=jl(e,n),s=o.exportPortableTheme(t).modes[r?"dark":"light"];return Pl(i=>{const a=s[i];return a&&kr(a)?Vd(a,e,i===Fl.fontFamily):a},r)}const kr=t=>/\b(?:var|color-mix|calc)\(/.test(t);function Vd(t,e,n){const o=getComputedStyle(e),r=Kd(t,i=>o.getPropertyValue(i).trim()||void 0);if(!kr(r))return r||void 0;const s=e.ownerDocument.createElement("span");s.style.display="none",n?s.style.fontFamily=r:s.style.color=r,e.appendChild(s);try{const i=getComputedStyle(s),a=(n?i.fontFamily:i.color).trim();return a&&!kr(a)?a:void 0}finally{s.remove()}}function Kd(t,e){let n=t;for(let o=0;o<32&&n.includes("var(");o++){const r=n.lastIndexOf("var(");let s=0,i=r+4;for(;i<n.length;i++)if(n[i]==="(")s++;else if(n[i]===")"){if(s===0)break;s--}const a=n.slice(r+4,i),l=a.indexOf(","),c=(l<0?a:a.slice(0,l)).trim(),u=l<0?"":a.slice(l+1).trim();n=n.slice(0,r)+(e(c)??u)+n.slice(i+1)}return n}const cr=1e3,Gd=300;function Ci(t){return{"#DIV/0!":"division by zero","#REF!":"invalid reference","#NAME?":"unknown name","#VALUE!":"wrong type of value","#N/A":"not available","#NUM!":"invalid number","#NULL!":"empty intersection","#CYCLE!":"circular reference","#BUSY!":"still calculating","#SPILL!":"cannot spill","#ERROR!":"the code raised an error"}[t]??"error"}function Zd(t,e,n,o){const r=t.content(e,n,o);if(r!==null&&r.value===null&&r.formula===void 0){const c=t.cellType(e,n,o)?.value;if(c?.paintsEmpty===!0&&c.accessibleName!==void 0)return c.accessibleName(null,t.style(e,n,o),{sheet:e,row:n,col:o,model:t})}if(r===null){const c=t.dataSource(e)?.zone;if(c===void 0||!zt(c,{row:n,col:o}))return"";const u=t.value(e,n,o);return u===null?"":j(u)?`${u.error}, ${Ci(u.error)}`:pt(u).text}const s=t.value(e,n,o),i=t.style(e,n,o),a=t.cellType(e,n,o)?.value;let l=a?.accessibleName!==void 0?a.accessibleName(s,i,{sheet:e,row:n,col:o,model:t}):pt(s,i.format).text;return r.formula!==void 0&&(l+=`, formula: =${r.formula}`),j(s)&&(l+=`, ${Ci(s.error)}`),l}const $i={position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},dm=k.forwardRef(function(e,n){const o=k.useRef(null);if(e.model!==void 0&&e.defaultData!==void 0)throw new Error("<Spreadsheet> takes model (controlled) or defaultData (uncontrolled), not both.");const r=e.model!==void 0?"controlled":"uncontrolled";if(o.current===null)o.current=r;else if(o.current!==r)throw new Error(`<Spreadsheet> switched from ${o.current} to ${r} after mount; create a new component instead.`);if(r==="controlled"&&(e.plugins!==void 0||e.reactor!==void 0||e.readOnly!==void 0))throw new Error("plugins, reactor and readOnly configure the model the component creates; with a model prop, give them to createCellsModel.");const[s]=k.useState(()=>e.model===void 0?If({data:e.defaultData,plugins:e.reactor===void 0?e.plugins:void 0,reactor:e.reactor,readOnly:e.readOnly}):null),i=e.model??s,a=k.useId().replace(/:/g,""),l=`cells-${a}`;k.useLayoutEffect(()=>{c.current&&aa(c.current,l)},[l]);const c=k.useRef(null),u=k.useRef(null),h=k.useRef(null),d=k.useRef(null),f=k.useRef(null),m=k.useRef({x:new xi,y:new xi}),[g,w]=k.useState(null),[y,x]=k.useState(null),[$,A]=k.useState({width:0,height:0}),[O,D]=k.useState({width:0,height:0}),[I,U]=k.useState(""),[,X]=k.useState(0),[z,P]=k.useState(0),F=k.useRef(e);F.current=e;const K=e.sheet??i.selection.sheet,J=e.theme??"auto",Ae=e.colorMode??"auto";k.useLayoutEffect(()=>{const p=c.current;let v=!1;const b=()=>{typeof J=="object"?(Nl(J),x(J)):J==="auto"?x(Xd(p,Ae)):Wd(J,p,Ae).then(T=>{v||x(T)})};b();const E=new MutationObserver(b);for(let T=p.parentElement;T;T=T.parentElement)E.observe(T,{attributes:!0,attributeFilter:["data-color-mode","data-theme","data-light-theme","data-dark-theme","style","class"]});const S=typeof matchMedia=="function"?[matchMedia("(prefers-color-scheme: dark)"),matchMedia("(forced-colors: active)")]:[];for(const T of S)T.addEventListener("change",b);return()=>{v=!0,E.disconnect();for(const T of S)T.removeEventListener("change",b)}},[J,Ae]),k.useLayoutEffect(()=>{if(y===null)return;const p=new ud({model:i,grid:h.current,overlay:d.current,theme:y,showGridlines:F.current.showGridlines,showHeaders:F.current.showHeaders});return f.current=p,p.setSheet(K),p.setZoom(F.current.zoom??1),O.width>0&&p.setSize(O.width,O.height,devicePixelRatio||1),w(p.viewport),()=>{p.dispose(),f.current=null}},[i,y===null]),k.useEffect(()=>{y&&f.current?.setTheme(y)},[y]);const ae=k.useCallback(()=>{const p=f.current;if(p===null)return;const v=p.viewport;w(v);const b=v.panes.find(T=>T.name==="main"),E=ko(v.maxScrollX*v.zoom,b.width),S=ko(v.maxScrollY*v.zoom,b.height);A(T=>T.width===E&&T.height===S?T:{width:E,height:S}),F.current.onViewportChange?.({sheet:p.sheet,rows:[b.firstRow,b.lastRow],cols:[b.firstCol,b.lastCol]})},[]);k.useEffect(()=>{const p=f.current;p!==null&&(p.setOptions({showGridlines:e.showGridlines,showHeaders:e.showHeaders}),p.setZoom(e.zoom??1),p.setLocale(e.locale??$n),p.setSheet(K),ae())},[e.showGridlines,e.showHeaders,e.zoom,e.locale,K,ae,y]),k.useLayoutEffect(()=>{const p=c.current,v=()=>{const L=p.getBoundingClientRect(),G={width:Math.floor(L.width),height:Math.floor(L.height)};D(H=>H.width===G.width&&H.height===G.height?H:G),f.current?.setSize(G.width,G.height,devicePixelRatio||1),ae()};v();const b=new ResizeObserver(v);b.observe(p);let E=null;const S=()=>{E?.removeEventListener("change",T),E=typeof matchMedia=="function"?matchMedia(`(resolution: ${devicePixelRatio||1}dppx)`):null,E?.addEventListener("change",T)},T=()=>{v(),S()};return S(),()=>{b.disconnect(),E?.removeEventListener("change",T)}},[ae]);const[ce,bt]=k.useState(i.edit);k.useEffect(()=>i.subscribeEdit(bt),[i]),k.useEffect(()=>{const p=i.subscribe(E=>{X(S=>S+1),P(S=>S+1),U(Hd(E,F.current.messages)),F.current.onChange?.(E),ae()}),v=i.subscribeDataSourceErrors(E=>{F.current.onDataSourceError?.(E)}),b=i.subscribeSelection(E=>{X(S=>S+1),F.current.onSelectionChange?.(E),E.sheet!==f.current?.sheet&&F.current.sheet===void 0&&(f.current?.setSheet(E.sheet),ae())});return()=>{p(),b(),v()}},[i,ae]);const Me=k.useCallback(()=>{const p=f.current,v=u.current;if(p===null||v===null)return;const b=p.viewport,E=b.panes.find(L=>L.name==="main"),S=m.current.x.map(v.scrollLeft,{maxContent:b.maxScrollX*b.zoom,viewport:E.width}),T=m.current.y.map(v.scrollTop,{maxContent:b.maxScrollY*b.zoom,viewport:E.height});p.setScroll(S/b.zoom,T/b.zoom),ae()},[ae]),de=k.useCallback((p,v,b="nearest")=>{const E=f.current,S=u.current;if(E===null||S===null)return;const T=i.sheet(E.sheet),L=E.viewport,G=L.panes.find(We=>We.name==="main"),{x:H,y:W}=E.scroll,ge=T.cols.offsetOf(T.frozen.cols),re=T.rows.offsetOf(T.frozen.rows),Re=G.width/L.zoom,rt=G.height/L.zoom;let st=H,Ue=W;if(v>=T.frozen.cols){const We=T.cols.offsetOf(v)-ge,cn=T.cols.offsetOf(v+1)-ge;b==="start"||We<H?st=We:cn>H+Re&&(st=cn-Re)}if(p>=T.frozen.rows){const We=T.rows.offsetOf(p)-re,cn=T.rows.offsetOf(p+1)-re;b==="start"||We<W?Ue=We:cn>W+rt&&(Ue=cn-rt)}st===H&&Ue===W||(st=Math.min(Math.max(0,st),L.maxScrollX),Ue=Math.min(Math.max(0,Ue),L.maxScrollY),E.setScroll(st,Ue),S.scrollLeft=m.current.x.domFor(st*L.zoom,{maxContent:L.maxScrollX*L.zoom,viewport:G.width}),S.scrollTop=m.current.y.domFor(Ue*L.zoom,{maxContent:L.maxScrollY*L.zoom,viewport:G.height}),ae())},[i,ae]),[De,ue]=k.useState(null),[xt,ot]=k.useState(null),R=k.useRef(xt);R.current=xt;const ee=k.useRef(null),me=k.useRef(!1),ie=()=>{ee.current!==null&&clearTimeout(ee.current.timer),ee.current=null},[Xe,tn]=k.useState(null),vt=k.useRef(!1),nn=k.useCallback((p,v)=>y===null?p.length*8:Yl(zo(v,y,1),p),[y]),Et=k.useMemo(()=>({get sheet(){return f.current?.sheet??i.selection.sheet},get pageRows(){const p=f.current;if(p===null)return 1;const v=p.viewport.panes.find(b=>b.name==="main");return Math.max(1,v.lastRow-v.firstRow)},scrollTo:(p,v)=>de(p,v),openMenu:()=>{const p=f.current;if(p===null)return;const v=i.sheet(p.sheet),b=p.viewport.panes.find(S=>S.name==="main"),E=Se(b,p.viewport.zoom,v.rows,v.cols,i.selection.active.row,i.selection.active.col);ue({x:E.x+E.width/2,y:E.y+E.height})},focusOutput:(p,v)=>{const b=c.current?.querySelector(`[data-cells-code-output="${et(p,v)}"]`);return b==null?!1:(b.focus({preventScroll:!1}),!0)},openCodeEditor:(p,v)=>{const b=f.current;if(b===null)return;const E=i.sheet(b.sheet),S=b.viewport.panes.find(L=>L.name==="main"),T=Se(S,b.viewport.zoom,E.rows,E.cols,p,v);ot(null),tn({row:p,col:v,x:T.x,y:T.y+T.height})},previewOutput:(p,v)=>{const b=f.current;if(b===null)return!1;const E=i.code(b.sheet,p,v);if(E===void 0||So(E).length===0||Wt(E)!==void 0)return!1;const S=i.sheet(b.sheet),T=b.viewport.panes.find(G=>G.name==="main"),L=Se(T,b.viewport.zoom,S.rows,S.cols,p,v);return ot({row:p,col:v,x:L.x,y:L.y+L.height}),!0}}),[i,de]),It=k.useMemo(()=>({model:i,measure:nn,grid:Et}),[i,nn,Et]);k.useEffect(()=>(Ks(It),()=>Ju(It)),[It]);const kt=k.useCallback(p=>{i.reactor.executeCommand(p,It).catch(v=>{U(v.message),F.current.onCommandRejected?.({ok:!1,refusals:[{reason:"Command",message:v.message}]})})},[i,It]),Nn=k.useCallback(p=>{const v=i.cellType(p.sheet,p.row,p.col)?.value;if(v?.activate===void 0)return!1;const b=i.value(p.sheet,p.row,p.col),E={workbook:i.workbook,value:(L,G,H)=>i.value(L,G,H),contributions:L=>i.reactor.getContributions(L).map(G=>G.value)},S=v.activate(p,b,E);if(S===void 0)return!0;if("open"in S)return typeof window<"u"&&window.open(S.open,"_blank","noopener,noreferrer"),!0;const T=i.dispatch(S.command);return T.ok||(U(T.refusals[0]?.message??`${v.id} refused.`),F.current.onCommandRejected?.(T)),!0},[i]),Oo=k.useCallback(p=>{if(i.selectedChart===null)return!1;const b={ArrowUp:["moveUp","shrinkUp"],ArrowDown:["moveDown","growDown"],ArrowLeft:["moveLeft","shrinkLeft"],ArrowRight:["moveRight","growRight"]}[p.key];let E;if(b!==void 0)E=`cells.chart.${p.shiftKey?b[1]:b[0]}`;else if(p.key==="Delete"||p.key==="Backspace")E="cells.chart.delete";else{if(p.key==="Escape")return i.selectChart(null),c.current?.focus({preventScroll:!0}),p.preventDefault(),!0;p.key==="Enter"&&p.shiftKey&&(E="cells.chart.showData")}return E===void 0?!1:(p.preventDefault(),kt(E),!0)},[i,kt]),ls=k.useCallback((p,v)=>{const b=f.current,E=c.current;if(b===null||E===null)return;const S=E.getBoundingClientRect(),T=Tl(b.viewport,p.clientX-S.left,p.clientY-S.top);if(T===void 0)return;const L=i.sheet(b.sheet),G=Se(T,b.viewport.zoom,L.rows,L.cols,v.row,v.col);return{...G,px:p.clientX-S.left-G.x,py:p.clientY-S.top-G.y}},[i]),Xl=k.useCallback(p=>{if(p.target!==c.current)return;const v=f.current;if(v===null||((p.ctrlKey||p.metaKey)&&p.shiftKey&&p.key.toLowerCase()==="v"&&(Io.current=!0),Oo(p)))return;if(p.key==="Escape"&&i.clipboardMark!==null){i.clearClipboardMark();return}if(p.key==="Escape"){vt.current=!0,U("Press Tab to leave the grid.");return}if(p.key==="Tab"&&vt.current){vt.current=!1;return}if(vt.current=!1,!p.ctrlKey&&!p.metaKey&&!p.altKey&&i.selection.sheet===v.sheet){const S=i.selection.active,T=i.cellType(v.sheet,S.row,S.col)?.value;if(T?.activateOn?.includes(p.key)&&T.activate!==void 0){p.preventDefault(),Nn({sheet:v.sheet,row:S.row,col:S.col});return}}const b=em(i,p.nativeEvent,F.current.keymap);if(b!==void 0){p.preventDefault(),kt(b);return}const E=p.ctrlKey||p.metaKey;if(!i.readOnly&&!E&&!p.altKey&&(p.key.length===1||p.key==="Process")){p.preventDefault();const S=i.selection.active;if(i.cellType(v.sheet,S.row,S.col)?.value.editable===!1)return;de(i.selection.active.row,i.selection.active.col),i.startEdit(void 0,p.key==="Process"?"":p.key)}},[i,de,kt,Nn]),Io=k.useRef(!1),as=k.useCallback((p,v)=>{if(p.target.closest?.("[data-cells-editor], [data-cells-menu], [data-cells-chart], [data-cells-chart-holder]"))return;p.preventDefault();const b=i.copy(void 0,{cut:v}),{text:E,html:S}=Wf(b,i);p.clipboardData.setData("text/plain",E),p.clipboardData.setData("text/html",S);const T=b.source.zone;U(`${v?"Cut":"Copied"} ${Oe(T)}`)},[i]),Wl=k.useCallback(p=>{if(p.target.closest?.("[data-cells-editor], [data-cells-menu], [data-cells-chart], [data-cells-chart-holder]"))return;p.preventDefault();const v=Io.current?"values":"all";if(Io.current=!1,i.readOnly)return;let b;try{b=Gf(p.clipboardData.getData("text/html")||void 0,p.clipboardData.getData("text/plain")||void 0)}catch(L){U(`Nothing pasted: ${L.message}`);return}if(b===void 0)return;const E=i.paste(b,void 0,{special:v});if(!E.ok){U(E.refusals.map(L=>L.message).join(" ")),F.current.onCommandRejected?.(E);return}const S=i.selection.active,T={top:S.row,left:S.col,bottom:S.row+b.rows-1,right:S.col+b.cols-1};i.select({...i.selection,zones:[T],anchor:S,active:S}),U(`Pasted ${Oe(T)}`)},[i]),On=k.useRef(!1),_t=k.useRef(null),[In,_o]=k.useState(null),on=k.useRef(null),[rn,Lo]=k.useState(null),cs=k.useCallback(()=>{const p=f.current;if(p===null)return;const v=i.selection;if(v.sheet!==p.sheet)return;const b=v.zones[v.zones.length-1],E=i.sheet(p.sheet),S=p.viewport.panes.find(L=>b.bottom>=L.firstRow&&b.bottom<=L.lastRow&&b.right>=L.firstCol&&b.right<=L.lastCol);if(S===void 0)return;const T=Se(S,p.viewport.zoom,E.rows,E.cols,b.bottom,b.right);return{x:T.x+T.width,y:T.y+T.height,zone:b}},[i]),Vl=k.useCallback((p,v)=>{const b=v.row-p.bottom,E=p.top-v.row,S=v.col-p.right,T=p.left-v.col,L=Math.max(b,E,S,T);return L<=0?p:L===b?{...p,bottom:v.row}:L===E?{...p,top:v.row}:L===S?{...p,right:v.col}:{...p,left:v.col}},[]),sn=k.useRef(null),ln=k.useRef(!1),Do=k.useCallback(p=>{const v=f.current,b=i.sheet(v.sheet),E=v.viewport.panes.find(L=>L.name==="main"),S=Se(E,v.viewport.zoom,b.rows,b.cols,p.top,p.left),T=Se(E,v.viewport.zoom,b.rows,b.cols,p.bottom,p.right);return{x:S.x,y:S.y,width:T.x+T.width-S.x,height:T.y+T.height-S.y}},[i]),an=k.useCallback(p=>{const v=f.current,b=c.current;if(v===null||b===null)return;const E=b.getBoundingClientRect(),S=i.sheet(v.sheet);return nd(v.viewport,S.rows,S.cols,p.clientX-E.left,p.clientY-E.top)},[i]),_n=k.useCallback((p,v,b)=>{const E=f.current;if(E===null)return;const S=i.sheet(E.sheet),T=Math.min(v,b),L=Math.max(v,b),G=p==="cols"?{top:0,bottom:S.rows.count-1,left:T,right:L}:{left:0,right:S.cols.count-1,top:T,bottom:L},H=p==="cols"?{row:0,col:v}:{row:v,col:0};i.select({sheet:E.sheet,zones:[G],anchor:H,active:H})},[i]),_e=k.useCallback(p=>{const v=f.current,b=c.current;if(v===null||b===null)return;const E=b.getBoundingClientRect(),S=i.sheet(v.sheet);return ed(v.viewport,S.rows,S.cols,p.clientX-E.left,p.clientY-E.top)},[i]),Kl=k.useCallback(p=>{if(p.target.closest("[data-cells-editor], [data-cells-popup], [data-cells-chart], [data-cells-chart-holder]"))return;const v=i.edit;if(v!==null&&p.button===0&&Le(v.text)){const H=c.current?.querySelector("[data-cells-editor]"),W=_e(p),ge=H?.selectionStart??v.text.length,re=sn.current;if(W!==void 0&&H&&(re!==null&&re.end===ge||is(v.text,ge))){p.preventDefault();const Re=p.shiftKey&&re!==null?re.anchor:W;Sr(i,sn,v,Re,W,ge),ln.current=!0,p.target.setPointerCapture?.(p.pointerId),H.focus({preventScroll:!0});return}}if(i.edit!==null){const H=i.commitEdit();if(!H.ok){F.current.onCommandRejected?.(H);return}}c.current?.focus({preventScroll:!0});const b=p.button===0&&!i.readOnly?cs():void 0;if(b!==void 0){const H=c.current.getBoundingClientRect(),W=p.clientX-H.left,ge=p.clientY-H.top;if(Math.abs(W-b.x)<=12&&Math.abs(ge-b.y)<=12){on.current={source:b.zone,target:b.zone},Lo(Do(b.zone)),p.target.setPointerCapture?.(p.pointerId);return}}const E=p.button===0?an(p):void 0;if(E!==void 0&&f.current!==null){const H=i.sheet(f.current.sheet),W=E.axis==="rows"?H.rows:H.cols;if(E.edge!==void 0&&!i.readOnly)_t.current={kind:"resize",axis:E.axis,index:E.edge,start:E.axis==="rows"?p.clientY:p.clientX,size:W.sizeOf(E.edge)},_o({axis:E.axis,at:E.axis==="rows"?E.y:E.x});else{const ge=i.selection,re=p.shiftKey?E.axis==="cols"?ge.anchor.col:ge.anchor.row:E.index;_n(E.axis,re,E.index),_t.current={kind:"select",axis:E.axis,from:re}}p.target.setPointerCapture?.(p.pointerId);return}const S=_e(p),T=f.current;if(S===void 0||T===null||p.button!==0)return;const L=i.selection.sheet===T.sheet?i.selection:we(T.sheet),G={top:S.row,left:S.col,bottom:S.row,right:S.col};if(p.shiftKey?i.select({...L,zones:[...L.zones.slice(0,-1),{top:Math.min(L.anchor.row,S.row),left:Math.min(L.anchor.col,S.col),bottom:Math.max(L.anchor.row,S.row),right:Math.max(L.anchor.col,S.col)}]}):p.ctrlKey||p.metaKey?i.select({...L,zones:[...L.zones,G],anchor:S,active:S}):i.select(we(T.sheet,S)),On.current=!0,p.target.setPointerCapture?.(p.pointerId),F.current.onCellClick?.({sheet:T.sheet,...S},p),!p.shiftKey&&!p.ctrlKey&&!p.metaKey&&p.isPrimary!==!1){const H=i.cellType(T.sheet,S.row,S.col)?.value;if(H?.activate!==void 0){const W=ls(p,S);W!==void 0&&(H.hitTest===void 0||H.hitTest({x:W.px,y:W.py},{width:W.width,height:W.height}))&&Nn({sheet:T.sheet,...S})}}},[i,_e,ls,Nn]),Gl=p=>{const v=f.current,b=v===null?void 0:_e(p),E=ee.current;if(b!==void 0&&E!==null&&E.row===b.row&&E.col===b.col)return;ie();const S=R.current;if(S!==null&&(b===void 0||S.row!==b.row||S.col!==b.col)&&(me.current||ot(null)),b===void 0||v===null)return;const T=i.code(v.sheet,b.row,b.col);T===void 0||So(T).length===0||Wt(T)!==void 0||S!==null&&S.row===b.row&&S.col===b.col||(ee.current={row:b.row,col:b.col,timer:setTimeout(()=>{ee.current=null,Et.previewOutput?.(b.row,b.col)},Gd)})},Zl=k.useCallback(p=>{if(!ln.current&&on.current===null&&_t.current===null&&!On.current&&Gl(p),ln.current){const re=i.edit,Re=sn.current,rt=_e(p);re!==null&&Re!==null&&rt!==void 0&&Sr(i,sn,re,Re.anchor,rt,Re.start);return}const v=on.current;if(v!==null){const re=_e(p);re!==void 0&&(v.target=Vl(v.source,re),Lo(Do(v.target)));return}const b=_t.current;if(b!==null){const re=an(p);if(b.kind==="select")re!==void 0&&re.axis===b.axis&&_n(b.axis,b.from,re.index);else{const Re=c.current.getBoundingClientRect();_o({axis:b.axis,at:b.axis==="rows"?p.clientY-Re.top:p.clientX-Re.left})}return}const E=an(p),S=cs(),T=c.current.getBoundingClientRect(),L=S!==void 0&&Math.abs(p.clientX-T.left-S.x)<=12&&Math.abs(p.clientY-T.top-S.y)<=12;if(c.current.style.cursor=L?"crosshair":E?.edge!==void 0?E.axis==="cols"?"col-resize":"row-resize":"",!On.current)return;const G=_e(p);if(G===void 0)return;const H=i.selection,W={top:Math.min(H.anchor.row,G.row),left:Math.min(H.anchor.col,G.col),bottom:Math.max(H.anchor.row,G.row),right:Math.max(H.anchor.col,G.col)},ge=H.zones[H.zones.length-1];ge.top===W.top&&ge.left===W.left&&ge.bottom===W.bottom&&ge.right===W.right||i.select({...H,zones:[...H.zones.slice(0,-1),W]})},[i,_e]),Jl=k.useCallback(p=>{if(ln.current){ln.current=!1;return}On.current=!1;const v=on.current;if(v!==null){if(on.current=null,Lo(null),!(JSON.stringify(v.source)===JSON.stringify(v.target))){const Ue=i.dispatch({type:"FILL",sheet:i.selection.sheet,source:v.source,target:v.target,mode:p.ctrlKey||p.metaKey?"copy":"series"});Ue.ok?(i.select({...i.selection,zones:[v.target]}),U(`Filled ${Oe(v.target)}`)):(U(Ue.refusals.map(We=>We.message).join(" ")),F.current.onCommandRejected?.(Ue))}return}const b=_t.current;if(_t.current=null,b===null||b.kind!=="resize")return;_o(null);const E=f.current;if(E===null)return;const S=E.viewport.zoom,T=((b.axis==="rows"?p.clientY:p.clientX)-b.start)/S,L=Math.max(4,Math.round(b.size+T));if(L===b.size)return;const G=i.selection,H=i.sheet(E.sheet),W=G.zones[G.zones.length-1],ge=b.axis==="cols"?W.top===0&&W.bottom===H.rows.count-1&&b.index>=W.left&&b.index<=W.right:W.left===0&&W.right===H.cols.count-1&&b.index>=W.top&&b.index<=W.bottom,[re,Re]=ge?b.axis==="cols"?[W.left,W.right]:[W.top,W.bottom]:[b.index,b.index],rt=i.dispatch({type:"RESIZE_AXIS",sheet:E.sheet,axis:b.axis,from:re,to:Re,size:L});rt.ok||F.current.onCommandRejected?.(rt)},[i]),ql=k.useCallback(p=>{const v=f.current;if(v===null||i.readOnly||p.button!==0||p.target.closest("[data-cells-editor], [data-cells-chart], [data-cells-chart-holder]"))return;const b=an(p);if(b===void 0){const E=_e(p);if(E===void 0)return;if(p.preventDefault(),(i.selection.sheet!==v.sheet||i.selection.active.row!==E.row||i.selection.active.col!==E.col)&&i.select(we(v.sheet,E)),i.code(v.sheet,E.row,E.col)!==void 0){Et.openCodeEditor?.(E.row,E.col);return}i.startEdit(E);return}if(b.edge!==void 0)if(b.axis==="cols"){const E=i.selection,S=E.zones[E.zones.length-1];b.edge>=S.left&&b.edge<=S.right||_n("cols",b.edge,b.edge),kt("cells.fitColumns")}else{const E=i.sheet(v.sheet);i.dispatch({type:"RESIZE_AXIS",sheet:v.sheet,axis:"rows",from:b.edge,to:b.edge,size:E.rows.defaultSize})}},[i,an,_e,_n,kt,Oo,Et]),Ql=k.useCallback(p=>{const v=_e(p),b=f.current;if(v===void 0||b===null||(F.current.onContextMenu?.({sheet:b.sheet,...v},p),p.defaultPrevented))return;p.preventDefault();const E=i.selection;(E.sheet!==b.sheet||!E.zones.some(T=>zt(T,v)))&&i.select(we(b.sheet,v));const S=c.current.getBoundingClientRect();ue({x:p.clientX-S.left,y:p.clientY-S.top})},[i,_e]);k.useImperativeHandle(n,()=>({model:i,dispatch:p=>{const v=i.dispatch(p);return v.ok||F.current.onCommandRejected?.(v),v},transact:(p,v)=>i.transact(p,v),undo:()=>i.undo(),redo:()=>i.redo(),select:p=>{const{sheet:v,zone:b}=es(i,p),E={row:b.top,col:b.left};i.select({sheet:v,zones:[b],anchor:E,active:E})},getSelection:()=>i.selection,scrollTo:(p,v)=>{const{row:b,col:E}=Qr(i,p);de(b,E,v?.align)},focus:()=>c.current?.focus(),toJSON:()=>i.toJSON(),repaint:()=>f.current?.repaint(),renderStats:()=>f.current?{...f.current.counters}:void 0}),[i,de]);const he=i.workbook.hasSheet(K)?i.sheet(K):i.sheets[0],Te=i.selection,ea=(p,v)=>`${a}-r${p}-c${v}`,Ln=k.useMemo(()=>{if(g===null)return{rows:[],cols:[]};const p=new Set,v=new Set;for(const S of g.panes){for(let T=S.firstRow;T<=S.lastRow;T+=1)he.rows.effectiveSizeOf(T)>0&&p.add(T);for(let T=S.firstCol;T<=S.lastCol;T+=1)he.cols.effectiveSizeOf(T)>0&&v.add(T)}Te.sheet===he.id&&(p.add(Te.active.row),v.add(Te.active.col));let b=[...p].sort((S,T)=>S-T),E=[...v].sort((S,T)=>S-T);if(b.length*E.length>cr){const S=Math.min(E.length,Math.floor(cr/Math.max(1,Math.min(b.length,20))));E=Mi(E,Te.active.col,S),b=Mi(b,Te.active.row,Math.floor(cr/E.length))}return{rows:b,cols:E}},[g,he,Te.active.row,Te.active.col,Te.sheet]),ta=Ln.cols.join(","),us=k.useMemo(()=>Ln.cols,[ta]),na=p=>{if(Te.sheet!==he.id)return"";const v=[];for(const b of us)Te.zones.some(E=>zt(E,{row:p,col:b}))&&v.push(b);return v.join(",")},oa=Te.sheet===he.id?ea(Te.active.row,Te.active.col):void 0,ra=g?.panes.find(p=>p.name==="main");return C.jsx(Pf,{model:i,children:C.jsxs("div",{className:e.className,style:{position:"relative",width:"100%",height:"100%",...e.style},"data-cells":"",children:[C.jsxs("div",{ref:c,style:{position:"absolute",inset:0,overflow:"hidden",outline:"none"},role:"grid",tabIndex:0,"aria-label":e["aria-label"]??`Spreadsheet, ${he.name}`,"aria-rowcount":he.rows.count+1,"aria-colcount":he.cols.count+1,"aria-multiselectable":"true","aria-description":"Arrow keys move between cells, Tab and Enter too. Press Escape, then Tab, to leave the grid.","aria-readonly":i.readOnly||void 0,"aria-activedescendant":oa,"data-cells-sheet":he.id,onKeyDown:Xl,onFocus:()=>Ks(It),onPointerDown:Kl,onPointerMove:Zl,onPointerLeave:()=>{ie(),me.current||ot(null)},onPointerUp:Jl,onDoubleClick:ql,onContextMenu:Ql,onCopy:p=>as(p,!1),onCut:p=>as(p,!0),onPaste:Wl,children:[C.jsx("div",{ref:u,onScroll:Me,"data-cells-scroller":"",style:{position:"absolute",left:g?g.panes.find(p=>p.name==="main").x:0,top:g?g.panes.find(p=>p.name==="main").y:0,right:0,bottom:0,overflow:"auto"},children:C.jsx("div",{style:{width:$.width,height:$.height}})}),C.jsx("canvas",{ref:h,"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:O.width,height:O.height,pointerEvents:"none"}}),C.jsx("canvas",{ref:d,"aria-hidden":"true",style:{position:"absolute",left:0,top:0,width:O.width,height:O.height,pointerEvents:"none"}}),C.jsxs("div",{style:$i,"data-cells-mirror":"",children:[C.jsx("div",{role:"row","aria-rowindex":1,children:Ln.cols.map(p=>C.jsx("div",{role:"columnheader","aria-colindex":p+2,children:Ye(p)},p))}),Ln.rows.map(p=>C.jsx(nm,{model:i,sheet:he.id,row:p,cols:us,uid:a,selected:na(p),revision:z},p))]}),g!==null&&y!==null&&C.jsx(Cd,{model:i,sheet:he.id,viewport:g,theme:y,selectedChart:i.selectedChart,onPointerDownChart:p=>i.selectChart(p),onChartKeyDown:Oo}),g!==null&&y!==null&&C.jsx(Nd,{model:i,sheet:he.id,viewport:g,theme:y,editing:Xe,preview:xt,onClosePreview:()=>{me.current=!1,ot(null)},onPreviewPointer:p=>{me.current=p,p||ot(null)},portalName:l,returnFocusRef:c,onCloseEditor:()=>{tn(null),c.current?.focus({preventScroll:!0})},onEscape:()=>c.current?.focus({preventScroll:!0})}),ce!==null&&g!==null&&ce.sheet===he.id&&y!==null&&C.jsx(qd,{model:i,edit:ce,viewport:g,theme:y,onDone:p=>{if(c.current?.focus({preventScroll:!0}),p){const v=i.selection,b=Kr(v,p,Gr(i.sheet(v.sheet)));i.select(b),de(b.active.row,b.active.col)}},onRejected:p=>F.current.onCommandRejected?.(p),point:sn}),In!==null&&C.jsx("div",{"aria-hidden":"true",style:In.axis==="cols"?{position:"absolute",top:0,bottom:0,left:In.at,width:0,borderLeft:`1px dashed ${y?.selectionBorder??"Highlight"}`,zIndex:3,pointerEvents:"none"}:{position:"absolute",left:0,right:0,top:In.at,height:0,borderTop:`1px dashed ${y?.selectionBorder??"Highlight"}`,zIndex:3,pointerEvents:"none"}}),ce!==null&&g!==null&&y!==null&&ce.sheet===he.id&&Ul(ce.text).filter(p=>p.sheet===void 0||p.sheet.toLowerCase()===he.name.toLowerCase()).map((p,v)=>{const b=Do({top:p.top??0,left:p.left??0,bottom:Math.min(p.bottom??he.rows.count-1,he.rows.count-1),right:Math.min(p.right??he.cols.count-1,he.cols.count-1)}),E=y.referenceColors[v%y.referenceColors.length];return C.jsx("div",{"data-cells-reference":ce.text.slice(p.start,p.end),style:{position:"absolute",left:b.x,top:b.y,width:b.width,height:b.height,boxSizing:"border-box",border:`2px dashed ${E}`,background:`${E}14`,pointerEvents:"none",zIndex:1}},`${p.start}-${p.end}`)}),rn!==null&&C.jsx("div",{"aria-hidden":"true","data-cells-fill-preview":"",style:{position:"absolute",left:rn.x,top:rn.y,width:rn.width,height:rn.height,border:`1px dashed ${y?.selectionBorder??"Highlight"}`,boxSizing:"border-box",pointerEvents:"none",zIndex:3}}),De!==null&&C.jsx(tm,{model:i,x:De.x,y:De.y,keymap:e.keymap,portalName:l,returnFocusRef:c,onRun:p=>{ue(null),c.current?.focus({preventScroll:!0}),kt(p)},onClose:()=>{ue(null),c.current?.focus({preventScroll:!0})}}),e.debug&&f.current&&ra&&C.jsx(om,{renderer:f.current,model:i}),e.children]}),C.jsx("div",{style:$i,"aria-live":"polite","data-cells-live":"",children:I})]})})});function Sr(t,e,n,o,r,s){const i=e.current,a=i!==null&&(i.end===s||i.start===s),l=a?i.start:s,c=a?i.end:s,u=Dd(o,r);t.setEditText(n.text.slice(0,l)+u+n.text.slice(c)),e.current={start:l,end:l+u.length,anchor:o,active:r}}const Jd={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]};function Ai(t){return{position:"absolute",maxWidth:420,padding:"4px 0",font:`${t.headerFontSize}px ${t.fontFamily}`,background:t.background,color:t.text,border:`1px solid ${t.gridline}`,boxShadow:"0 2px 6px rgba(0,0,0,0.2)",zIndex:3,paddingInline:8}}function qd(t){const{model:e,edit:n,viewport:o,theme:r,point:s}=t,i=k.useRef(null),a=k.useRef(!1),[l,c]=k.useState(""),u=k.useId(),h=e.sheet(n.sheet),d=o.panes.find(R=>n.row>=R.firstRow&&n.row<=R.lastRow&&n.col>=R.firstCol&&n.col<=R.lastCol)??o.panes.find(R=>R.name==="main"),f=h.mergeAt(n.row,n.col),m=Se(d,o.zoom,h.rows,h.cols,n.row,n.col),g=f?Se(d,o.zoom,h.rows,h.cols,f.bottom,f.right):m,w=g.x+g.width-m.x,y=g.y+g.height-m.y,x=e.style(n.sheet,n.row,n.col),$=zo(x,r,o.zoom),A=k.useMemo(()=>{const R=n.text.split(`
81
81
  `).reduce((ee,me)=>Math.max(ee,Yl($,me)),0);return Math.min(Math.max(w,R+16*o.zoom),Math.max(w,d.x+d.width-m.x))},[n.text,$,w,o.zoom,d.x,d.width,m.x]),O=n.text.split(`
82
82
  `).length,D=(x.size??r.fontSize)*o.zoom*1.25,I=Math.max(y,O*D+6*o.zoom);k.useLayoutEffect(()=>{const R=i.current;R.closest("[data-cells]")?.contains(document.activeElement)&&(R.focus({preventScroll:!0}),R.setSelectionRange(R.value.length,R.value.length))},[n.row,n.col,n.sheet]);const U=k.useRef(null),[X,z]=k.useState(n.text.length);k.useLayoutEffect(()=>{const R=U.current??s.current?.end??null;R!==null&&(i.current?.setSelectionRange(R,R),U.current=null,z(R))},[n.text]),k.useLayoutEffect(()=>{s.current=null},[n.row,n.col,n.sheet]);const P=Le(n.text)?Pd(n.text,X):void 0,F=k.useMemo(()=>P===void 0?[]:e.functionNames().filter(R=>R.startsWith(P.prefix.toUpperCase())).slice(0,8),[e,P?.prefix,P?.start]),[K,J]=k.useState(0),[Ae,ae]=k.useState(null),ce=F.length>0&&Ae!==`${P?.start}:${P?.prefix}`;k.useEffect(()=>J(0),[P?.prefix]);const bt=R=>{const ee=P,me=`${n.text.slice(0,ee.start)}${R}(${n.text.slice(X)}`;U.current=ee.start+R.length+1,s.current=null,e.setEditText(me)},Me=Le(n.text)?jd(n.text,X):void 0,de=Me?e.formulaFunction(Me.name):void 0,De=k.useId(),ue=k.useId(),xt=R=>{const ee=e.commitEdit();ee.ok?(c(""),t.onDone(R)):(c(ee.refusals.map(me=>me.message).join(" ")),t.onRejected(ee))},ot=`Edit ${Ye(n.col)}${n.row+1}, ${h.name}`;return C.jsxs(C.Fragment,{children:[C.jsx("textarea",{ref:i,"data-cells-editor":"","aria-label":ot,"aria-describedby":l?u:void 0,"aria-invalid":l?!0:void 0,value:n.text,spellCheck:!1,role:Le(n.text)?"combobox":void 0,"aria-expanded":Le(n.text)?ce:void 0,"aria-controls":ce?De:void 0,"aria-autocomplete":Le(n.text)?"list":void 0,"aria-activedescendant":ce?`${De}-${K}`:void 0,onChange:R=>{s.current=null,z(R.target.selectionStart),e.setEditText(R.target.value)},onSelect:R=>z(R.currentTarget.selectionStart),onCompositionStart:()=>{a.current=!0},onCompositionEnd:()=>{a.current=!1},onBlur:R=>{e.edit===null||R.relatedTarget?.getAttribute("role")==="grid"||xt(void 0)},onKeyDown:R=>{if(a.current||R.nativeEvent.isComposing)return;const ee=R.currentTarget;if(ce){if(R.key==="ArrowDown"||R.key==="ArrowUp"){R.preventDefault();const ie=F.length;J((K+(R.key==="ArrowDown"?1:ie-1))%ie);return}if(R.key==="Tab"||R.key==="Enter"&&!R.altKey){R.preventDefault(),bt(F[K]);return}if(R.key==="Escape"){R.preventDefault(),ae(`${P?.start}:${P?.prefix}`);return}}if(R.key==="F4"&&Le(n.text)){R.preventDefault();const ie=Fd(n.text,ee.selectionStart);ie!==void 0&&(U.current=ie.caret,s.current=null,e.setEditText(ie.text));return}const me=Jd[R.key];if(me!==void 0&&!R.altKey&&!R.ctrlKey&&!R.metaKey&&Le(n.text)){const ie=s.current,Xe=ee.selectionStart;if(ee.selectionEnd===Xe&&(ie!==null&&ie.end===Xe||is(n.text,Xe))){R.preventDefault();const tn=ie?.active??{row:n.row,col:n.col},vt=e.sheet(n.sheet),nn={row:Math.max(0,Math.min(vt.rows.count-1,tn.row+me[0])),col:Math.max(0,Math.min(vt.cols.count-1,tn.col+me[1]))},Et=R.shiftKey&&ie!==null?ie.anchor:nn;Sr(e,s,n,Et,nn,Xe);return}}if(R.key==="Escape")R.preventDefault(),e.cancelEdit(),c(""),t.onDone(void 0);else if(R.key==="Enter"&&R.altKey){R.preventDefault();const ie=R.currentTarget,Xe=ie.selectionStart;U.current=Xe+1,e.setEditText(`${n.text.slice(0,Xe)}
83
83
  ${n.text.slice(ie.selectionEnd)}`)}else R.key==="Enter"?(R.preventDefault(),xt({type:"cycle",by:"col",reverse:R.shiftKey})):R.key==="Tab"&&(R.preventDefault(),xt({type:"cycle",by:"row",reverse:R.shiftKey}))},style:{position:"absolute",left:m.x,top:m.y,width:A,height:I,boxSizing:"border-box",margin:0,padding:`${2*o.zoom}px ${3*o.zoom}px`,border:`2px solid ${r.activeCellBorder}`,outline:"none",resize:"none",overflow:"hidden",whiteSpace:"pre",font:$,lineHeight:`${D}px`,color:x.color??r.text,background:x.fill??r.background,zIndex:2}}),ce&&C.jsx("div",{id:De,role:"listbox","aria-label":"Functions","data-cells-popup":"",style:{...Ai(r),left:m.x,top:m.y+I+2},children:F.map((R,ee)=>C.jsxs("div",{id:`${De}-${ee}`,role:"option","aria-selected":ee===K,onPointerDown:me=>{me.preventDefault(),bt(R)},style:{padding:"2px 8px",cursor:"pointer",background:ee===K?r.headerSelectedBackground:void 0},children:[C.jsx("strong",{children:R})," ",C.jsx("span",{style:{opacity:.75},children:e.formulaFunction(R)?.description})]},R))}),!ce&&de!==void 0&&Me!==void 0&&C.jsxs("div",{id:ue,role:"tooltip","data-cells-popup":"",style:{...Ai(r),left:m.x,top:m.y+I+2},children:[de.name,"(",de.args.map((R,ee)=>{const me=ee===Me.argument||R.repeating===!0&&ee<Me.argument&&ee===de.args.length-1,ie=R.optional?`[${R.name}${R.repeating?", …":""}]`:R.name;return C.jsxs("span",{children:[ee>0&&", ",me?C.jsx("strong",{children:ie}):ie]},R.name)}),")",C.jsx("div",{style:{opacity:.75},children:de.description})]}),l&&C.jsx("div",{id:u,role:"alert",style:{position:"absolute",left:m.x,top:m.y+I+2,maxWidth:320,padding:"4px 8px",font:`${r.headerFontSize}px ${r.fontFamily}`,background:r.background,color:r.errorText,border:`1px solid ${r.errorText}`,zIndex:3},children:l})]})}function Hl(t,e){if(e!==void 0&&t.id in e){const n=e[t.id];return n==null?[]:[n]}return[...t.keybinding!==void 0?[t.keybinding]:[],...t.gridKeybindings??[]]}function Qd(t,e){return Hl(t,e)[0]}function em(t,e,n){for(const o of t.reactor.listCommands())if(o.category==="Cells"&&!(o.isEnabled!==void 0&&!o.isEnabled()))for(const r of Hl(o,n)){const s=ca(r);if(s!==null&&ua(e,s))return o.id}}function tm(t){const{model:e}=t,n=k.useRef(null),o=k.useMemo(()=>{const r=new Map(e.reactor.listCommands().map(s=>[s.id,s]));return e.reactor.getContributions(qe).map(s=>({item:s.value,command:r.get(s.value.command)})).filter(s=>s.command!==void 0)},[e]);return C.jsx(Cr,{children:C.jsx($r,{role:"menu","aria-label":"Cell actions",returnFocusRef:t.returnFocusRef,onClickOutside:t.onClose,onEscape:t.onClose,portalContainerName:t.portalName,position:"absolute",top:t.y,left:t.x,width:"auto",style:{backgroundColor:"var(--overlay-bgColor, Canvas)",color:"var(--fgColor-default, CanvasText)",boxShadow:"var(--shadow-floating-small, 0 0 0 1px rgba(128, 128, 128, 0.35), 0 8px 24px rgba(0, 0, 0, 0.2))"},"data-cells-menu":"",children:C.jsx("div",{ref:n,"data-cells-menu":"",style:{minWidth:220,maxHeight:360,overflowY:"auto"},onPointerDown:r=>r.stopPropagation(),onKeyDown:r=>{r.stopPropagation(),(r.key==="Escape"||r.key==="Tab")&&(r.preventDefault(),t.onClose())},children:C.jsx(Be,{role:"menu",children:o.map(({item:r,command:s},i)=>{const a=Qd(s,t.keymap),l=i>0&&o[i-1].item.group!==r.group;return C.jsxs(k.Fragment,{children:[l&&C.jsx(Be.Divider,{}),C.jsxs(Be.Item,{role:"menuitem","aria-keyshortcuts":a,onSelect:()=>t.onRun(s.id),onMouseEnter:c=>{(c.currentTarget.closest('[role="menuitem"]')??c.currentTarget.querySelector('[role="menuitem"]')??c.currentTarget).focus()},children:[s.name,a&&C.jsx(Be.TrailingVisual,{children:Ti(a)})]})]},s.id)})})})})})}let lo=null;function Yl(t,e){return lo??=document.createElement("canvas").getContext("2d"),lo===null?e.length*8:(lo.font=t,lo.measureText(e).width)}const nm=k.memo(function(e){const{model:n,sheet:o,row:r,cols:s,uid:i}=e,a=new Set(e.selected===""?[]:e.selected.split(",").map(Number));return C.jsxs("div",{role:"row","aria-rowindex":r+2,children:[C.jsx("div",{role:"rowheader","aria-colindex":1,children:r+1}),s.map(l=>C.jsx("div",{id:`${i}-r${r}-c${l}`,role:"gridcell","aria-colindex":l+2,"aria-selected":a.has(l),children:Zd(n,o,r,l)},l))]})});function Mi(t,e,n){if(t.length<=n)return t;let o=t.findIndex(s=>s>=e);o<0&&(o=t.length-1);const r=Math.max(0,Math.min(o-Math.floor(n/2),t.length-n));return t.slice(r,r+n)}function om({renderer:t,model:e}){const[,n]=k.useState(0);k.useEffect(()=>{const a=setInterval(()=>n(l=>l+1),500);return()=>clearInterval(a)},[]);const o=t.counters,r=e.stats(),s=t.measure.cache,i=s.hits+s.misses===0?0:Math.round(100*s.hits/(s.hits+s.misses));return C.jsx("pre",{"data-cells-debug":"",style:{position:"absolute",right:8,bottom:8,margin:0,padding:8,font:"11px monospace",background:"rgba(0,0,0,0.75)",color:"#fff",borderRadius:4,pointerEvents:"none"},children:`frame ${o.lastFrameMs.toFixed(2)} ms · frames ${o.frames}
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-B3LgqnRn.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-ihQPqJPB.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};