texlite 0.18.0 → 0.19.1

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 (228) hide show
  1. package/DESIGN.md +442 -26
  2. package/NPM_TESTING.md +23 -0
  3. package/OPERATIONS.md +227 -6
  4. package/README.md +8 -2
  5. package/README.zh-CN.md +6 -2
  6. package/THIRD_PARTY_NOTICES.md +73 -0
  7. package/dist/client/assets/AdminUsers-CuYfWnEk.js +1 -0
  8. package/dist/client/assets/AdminUsers-CuYfWnEk.js.br +0 -0
  9. package/dist/client/assets/AdminUsers-CuYfWnEk.js.gz +0 -0
  10. package/dist/client/assets/AgentIcon-ClP5dPRL.js +1 -0
  11. package/dist/client/assets/AgentIcon-ClP5dPRL.js.br +0 -0
  12. package/dist/client/assets/AgentIcon-ClP5dPRL.js.gz +0 -0
  13. package/dist/client/assets/AgentIcon-DxrC-zx_.css +1 -0
  14. package/dist/client/assets/AgentIcon-DxrC-zx_.css.br +0 -0
  15. package/dist/client/assets/AgentIcon-DxrC-zx_.css.gz +0 -0
  16. package/dist/client/assets/AgentManagement-jY_BF6Qy.js +1 -0
  17. package/dist/client/assets/AgentManagement-jY_BF6Qy.js.br +0 -0
  18. package/dist/client/assets/AgentManagement-jY_BF6Qy.js.gz +0 -0
  19. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js +2 -0
  20. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.br +0 -0
  21. package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.gz +0 -0
  22. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css +1 -0
  23. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.br +0 -0
  24. package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.gz +0 -0
  25. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js +16 -0
  26. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.br +0 -0
  27. package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.gz +0 -0
  28. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js +1 -0
  29. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.br +0 -0
  30. package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.gz +0 -0
  31. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js +1 -0
  32. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.br +0 -0
  33. package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.gz +0 -0
  34. package/dist/client/assets/Dashboard-B7mMz5Gj.js +5 -0
  35. package/dist/client/assets/Dashboard-B7mMz5Gj.js.br +0 -0
  36. package/dist/client/assets/Dashboard-B7mMz5Gj.js.gz +0 -0
  37. package/dist/client/assets/GitDialog-C2H-jKVO.js +3 -0
  38. package/dist/client/assets/GitDialog-C2H-jKVO.js.br +0 -0
  39. package/dist/client/assets/GitDialog-C2H-jKVO.js.gz +0 -0
  40. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js +1 -0
  41. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.br +0 -0
  42. package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.gz +0 -0
  43. package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-Cjli8pd_.js} +1 -1
  44. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js +8 -0
  45. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.br +0 -0
  46. package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.gz +0 -0
  47. package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BhAKioho.js} +26 -26
  48. package/dist/client/assets/LatexEditor-BhAKioho.js.br +0 -0
  49. package/dist/client/assets/LatexEditor-BhAKioho.js.gz +0 -0
  50. package/dist/client/assets/PdfPreview-CC8KEz1Y.js +1 -0
  51. package/dist/client/assets/PdfPreview-CC8KEz1Y.js.br +0 -0
  52. package/dist/client/assets/PdfPreview-CC8KEz1Y.js.gz +0 -0
  53. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js +1 -0
  54. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.br +0 -0
  55. package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.gz +0 -0
  56. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js +4 -0
  57. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.br +0 -0
  58. package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.gz +0 -0
  59. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js +30 -0
  60. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.br +0 -0
  61. package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.gz +0 -0
  62. package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-BAzyrB-4.js} +1 -1
  63. package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.br +0 -0
  64. package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.gz +0 -0
  65. package/dist/client/assets/SaveButton-DkyoEu6j.js +1 -0
  66. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js +3 -0
  67. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.br +0 -0
  68. package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.gz +0 -0
  69. package/dist/client/assets/SuccessNotice-ubBtzzi_.js +1 -0
  70. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js +1 -0
  71. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.br +0 -0
  72. package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.gz +0 -0
  73. package/dist/client/assets/TagColorSelect-xbc2H5ou.js +1 -0
  74. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js +1 -0
  75. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.br +0 -0
  76. package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.gz +0 -0
  77. package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-BODhL9iz.js} +1 -1
  78. package/dist/client/assets/WordCountDialog-BODhL9iz.js.br +0 -0
  79. package/dist/client/assets/WordCountDialog-BODhL9iz.js.gz +0 -0
  80. package/dist/client/assets/arrow-down-B6T7Z6IO.js +1 -0
  81. package/dist/client/assets/check-BRlv1lrZ.js +1 -0
  82. package/dist/client/assets/chevron-up-krb7w67X.js +1 -0
  83. package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-Bz-LKycq.js} +1 -1
  84. package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-Fb1_e3ec.js} +1 -1
  85. package/dist/client/assets/{dist-D5mbpudl.js → dist-CMYWzCHL.js} +1 -1
  86. package/dist/client/assets/dist-CMYWzCHL.js.br +0 -0
  87. package/dist/client/assets/dist-CMYWzCHL.js.gz +0 -0
  88. package/dist/client/assets/{eye-CvzXPIMu.js → eye-B6AX_5uX.js} +1 -1
  89. package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-CBmnJ2xS.js} +1 -1
  90. package/dist/client/assets/i18n-DF6keNBA.js +13 -0
  91. package/dist/client/assets/i18n-DF6keNBA.js.br +0 -0
  92. package/dist/client/assets/i18n-DF6keNBA.js.gz +0 -0
  93. package/dist/client/assets/index-DCwfhKK9.js +42 -0
  94. package/dist/client/assets/index-DCwfhKK9.js.br +0 -0
  95. package/dist/client/assets/index-DCwfhKK9.js.gz +0 -0
  96. package/dist/client/assets/index-SVNFLCYh.css +1 -0
  97. package/dist/client/assets/index-SVNFLCYh.css.br +0 -0
  98. package/dist/client/assets/index-SVNFLCYh.css.gz +0 -0
  99. package/dist/client/assets/info-DNSAs0_-.js +1 -0
  100. package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-C8oL6PTV.js} +1 -1
  101. package/dist/client/assets/{minus-CNHOVLWS.js → minus-TCBOakyi.js} +1 -1
  102. package/dist/client/assets/plus-Dfkyfvvy.js +1 -0
  103. package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-DuLtxWBX.js} +1 -1
  104. package/dist/client/assets/relativeTime-BR0CVAvz.js +1 -0
  105. package/dist/client/assets/relativeTime-BR0CVAvz.js.br +0 -0
  106. package/dist/client/assets/relativeTime-BR0CVAvz.js.gz +0 -0
  107. package/dist/client/assets/{search-Czv3qsBy.js → search-n-2tBATf.js} +1 -1
  108. package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-xzICTGx1.js} +1 -1
  109. package/dist/client/assets/spellCheck-xzICTGx1.js.br +0 -0
  110. package/dist/client/assets/spellCheck-xzICTGx1.js.gz +0 -0
  111. package/dist/client/assets/tags-Dy96boLq.js +1 -0
  112. package/dist/client/assets/terminal-C0xh8jVR.js +1 -0
  113. package/dist/client/assets/{type-NT195OCy.js → type-BjXWxrjH.js} +1 -1
  114. package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-3oJZJXHW.js} +1 -1
  115. package/dist/client/index.html +13 -7
  116. package/dist/server/agents/adapters/claude.js +180 -0
  117. package/dist/server/agents/adapters/codex.js +47 -0
  118. package/dist/server/agents/adapters/common.js +86 -0
  119. package/dist/server/agents/adapters/opencode.js +196 -0
  120. package/dist/server/agents/adapters/types.js +1 -0
  121. package/dist/server/agents/execution.js +147 -0
  122. package/dist/server/agents/launcher.js +57 -0
  123. package/dist/server/agents/processIdentity.js +63 -0
  124. package/dist/server/agents/registry.js +72 -0
  125. package/dist/server/agents/sessions.js +574 -0
  126. package/dist/server/agents/terminal.js +84 -0
  127. package/dist/server/agents/workspaces.js +341 -0
  128. package/dist/server/app.js +32 -1
  129. package/dist/server/cli.js +19 -47
  130. package/dist/server/collaboration.js +64 -36
  131. package/dist/server/compileArtifacts.js +11 -44
  132. package/dist/server/compiler.js +16 -38
  133. package/dist/server/config.js +8 -2
  134. package/dist/server/db.js +33 -0
  135. package/dist/server/editHistory.js +59 -65
  136. package/dist/server/history.js +28 -13
  137. package/dist/server/i18n.js +26 -8
  138. package/dist/server/latexRoot.js +4 -2
  139. package/dist/server/locales/zh-Hant.js +145 -0
  140. package/dist/server/lucideIcons.js +14 -17
  141. package/dist/server/projectMutations.js +21 -0
  142. package/dist/server/routes/agents.js +135 -0
  143. package/dist/server/routes/compile.js +23 -43
  144. package/dist/server/routes/projectHistory.js +13 -6
  145. package/dist/server/routes/projectShared.js +6 -1
  146. package/dist/server/routes/projects.js +15 -23
  147. package/dist/shared/agentMessages.js +51 -0
  148. package/dist/shared/agentProtocol.js +41 -0
  149. package/dist/shared/historyFiles.js +1 -1
  150. package/dist/shared/historyTracking.js +2 -0
  151. package/dist/shared/locales.js +21 -0
  152. package/dist/shared/sourceCommentAnchors.js +52 -4
  153. package/package.json +7 -3
  154. package/templates/agents/AGENTS.md +135 -0
  155. package/texlite.config.example.json +3 -2
  156. package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
  157. package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
  158. package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
  159. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js +0 -1
  160. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.br +0 -0
  161. package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.gz +0 -0
  162. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js +0 -1
  163. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.br +0 -0
  164. package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
  165. package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
  166. package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
  167. package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
  168. package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
  169. package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
  170. package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
  171. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js +0 -1
  172. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
  173. package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
  174. package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
  175. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
  176. package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
  177. package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
  178. package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
  179. package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
  180. package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
  181. package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
  182. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js +0 -1
  183. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
  184. package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
  185. package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
  186. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
  187. package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
  188. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
  189. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
  190. package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
  191. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
  192. package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
  193. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
  194. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
  195. package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
  196. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
  197. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
  198. package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
  199. package/dist/client/assets/TagColorSelect-D3T-rw4K.js +0 -1
  200. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
  201. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
  202. package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
  203. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
  204. package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
  205. package/dist/client/assets/binary-B57nBiwS.js +0 -1
  206. package/dist/client/assets/check-DFoA73zZ.js +0 -1
  207. package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
  208. package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
  209. package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
  210. package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
  211. package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
  212. package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
  213. package/dist/client/assets/index-D0eqhDpZ.js +0 -42
  214. package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
  215. package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
  216. package/dist/client/assets/index-DnhiIb1V.css +0 -1
  217. package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
  218. package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
  219. package/dist/client/assets/plus-BDquy76g.js +0 -1
  220. package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
  221. package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
  222. package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
  223. package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
  224. package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
  225. package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
  226. package/dist/client/assets/tags-CLK7WRSs.js +0 -1
  227. package/preview-1.png +0 -0
  228. package/preview-2.png +0 -0
@@ -0,0 +1,30 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./spellCheck-xzICTGx1.js","./index-DCwfhKK9.js","./rolldown-runtime-XKyaHtl9.js","./react-DUEFWlB7.js","./i18nInstance-CIMFwH0l.js","./i18n-DF6keNBA.js","./basePath-B5-c90eh.js","./vite-runtime-CRzLMJPS.js","./index-SVNFLCYh.css","./chktex-Bz-LKycq.js","./LatexEditor-BhAKioho.js","./relativeTime-BR0CVAvz.js","./editor-oR9RlWUz.js","./CitationLibraryDialog-BdU9nbgG.js","./check-BRlv1lrZ.js","./chevron-up-krb7w67X.js","./SaveButton-DkyoEu6j.js","./tags-Dy96boLq.js","./plus-Dfkyfvvy.js","./search-n-2tBATf.js","./dist-CMYWzCHL.js","./SuccessNotice-ubBtzzi_.js","./TagColorSelect-xbc2H5ou.js","./citationLibrary-BzlqZiFU.js","./GitDialog-C2H-jKVO.js","./GitHubIcon-Cjli8pd_.js","./eye-B6AX_5uX.js","./minus-TCBOakyi.js","./minimize-2-C8oL6PTV.js","./HistoryDialog-CoxJ3EsK.js","./clock-3-Fb1_e3ec.js","./hard-drive-CBmnJ2xS.js","./dist-Dxkdrap6.js","./SelectionHistoryDialog-DzlVKtxs.js","./QuickOpenDialog-BAzyrB-4.js","./ProjectSettings-Bl1t-Gnh.js","./refresh-cw-DuLtxWBX.js","./terminal-C0xh8jVR.js","./type-BjXWxrjH.js","./AgentTerminal-JKP2SVkZ.js","./info-DNSAs0_-.js","./AgentIcon-ClP5dPRL.js","./AgentIcon-DxrC-zx_.css","./WordCountDialog-BODhL9iz.js"])))=>i.map(i=>d[i]);
2
+ import{n as e,r as t}from"./rolldown-runtime-XKyaHtl9.js";import{i as n,r,t as i}from"./react-DUEFWlB7.js";import{a,r as o,s,t as c}from"./i18nInstance-CIMFwH0l.js";import{t as l}from"./i18n-DF6keNBA.js";import{r as u,t as d}from"./basePath-B5-c90eh.js";import{t as f}from"./vite-runtime-CRzLMJPS.js";import{t as p}from"./arrow-down-B6T7Z6IO.js";import{$ as m,B as h,C as g,D as _,E as v,F as y,G as b,H as x,I as S,J as C,K as w,L as T,M as E,N as D,P as O,Q as k,R as A,S as j,T as M,U as N,V as ee,W as te,X as ne,Y as P,Z as re,_ as ie,at as ae,b as oe,et as se,f as ce,i as F,it as I,n as le,nt as L,o as R,q as z,r as B,rt as V,t as ue,tt as de,v as fe,w as pe,y as me,z as he}from"./relativeTime-BR0CVAvz.js";import{t as ge}from"./check-BRlv1lrZ.js";import{t as _e}from"./chevron-up-krb7w67X.js";import{n as H,t as ve}from"./SaveButton-DkyoEu6j.js";import{t as ye}from"./refresh-cw-DuLtxWBX.js";import{t as U}from"./user-plus-3oJZJXHW.js";import{A as be,C as W,E as G,F as xe,I as Se,M as K,N as Ce,O as we,P as Te,S as Ee,T as De,b as q,c as Oe,i as ke,j as Ae,k as je,o as Me,s as Ne,w as Pe,y as Fe}from"./index-DCwfhKK9.js";import{a as Ie,l as J,n as Le,r as Re,t as ze}from"./dist-CMYWzCHL.js";var Be={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,"!doctype":!0,"!DOCTYPE":!0},Ve=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?("[^"]*"|'[^']*')/g;function He(e){let t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(Be[n[1]]||e.charAt(e.length-2)===`/`)&&(t.voidElement=!0),t.name.startsWith(`!--`))){let t=e.indexOf(`-->`);return{type:`comment`,comment:t===-1?``:e.slice(4,t)}}let r=new RegExp(Ve),i=null;for(;i=r.exec(e),i!==null;)if(i[0].trim()){if(i[1]){let e=i[1].trim(),n=[e,null],a=e.indexOf(`=`);a>-1&&(n=[e.slice(0,a),e.slice(a+1)]),t.attrs[n[0]]=n[1],r.lastIndex--}else i[2]&&(t.attrs[i[2]]=i[3].trim().substring(1,i[3].length-1))}return t}var Ue=/<!--[\s\S]*?-->|<[a-zA-Z0-9\-!/](?:"[^"]*"|'[^']*'|[^'">])*>/g,We=/<\/?([^\s]+?)[/\s>]/,Ge=/^\s*$/,Ke=/^(script|style)$/i,qe=`\0`,Je=Object.create(null);function Ye(e){e.forEach(function(e){if(e.type===`text`)e.content=e.content.split(qe).join(`<`);else if(e.type===`comment`)e.comment=e.comment.split(qe).join(`<`);else{for(let t in e.attrs){let n=e.attrs[t];typeof n==`string`&&n.indexOf(qe)>-1&&(e.attrs[t]=n.split(qe).join(`<`))}e.children.length&&Ye(e.children)}})}function Xe(e,t){let n=t&&t.components||Je,r=t&&t.allowedTags,i=!1;if(r){let t=typeof r==`function`?r:function(e){return r.indexOf(e)>-1},n=``,a=0;Ue.lastIndex=0;let o;for(;o=Ue.exec(e);){let r=o[0];n+=e.slice(a,o.index);let s=r.match(We);r.startsWith(`<!--`)||s&&t(s[1])?(n+=r,a=o.index+r.length):(i=!0,n+=qe,a=o.index+1,Ue.lastIndex=a)}e=n+e.slice(a)}let a=[],o=[],s,c=-1,l=!1,u=0,d;if(e.indexOf(`<`)!==0){let t=e.indexOf(`<`);a.push({type:`text`,content:t===-1?e:e.substring(0,t)})}let f=[],p;for(;p=Ue.exec(e);)f.push(p);return f.forEach(function(e,t){let n=e[0];if(!n||n.startsWith(`<!--`))return;let r=0,i=0,a=-1,o=null;for(let e=0;e<n.length;e++){let t=n.charAt(e);o?t===o&&(o=null):t===`"`||t===`'`?o=t:t===`<`?(r++,r===2&&(a=e)):t===`>`&&i++}let s=a>-1&&/[a-zA-Z0-9\-!/]/.test(n.charAt(a+1));if(r>i&&s){let e=n.substring(0,a),r=n.substring(e.length);f[t][0]=r,f[t].index+=e.length}}),f.forEach(function(t,r){let i=t[0];if(!i)return;let p=t.index;if(p<u)return;if(l){if(i!==`</`+s.name+`>`)return;l=!1}let m=i.charAt(1)!==`/`,h=i.startsWith(`<!--`),g=p+i.length,_=e.charAt(g),v=f[r+1],y;if(_===`<`&&v){let t=e.substring(g,v.index);y=t.split(`<`).length>t.split(`>`).length}let b;if(h){let t=He(i);if(c<0)return a.push(t),a;b=o[c],b.children.push(t);let n=e.slice(g,v?v.index:void 0);return n.length>0&&b.children.push({type:`text`,content:n}),a}if(m){c++,s=He(i),s.type===`tag`&&n[s.name]&&(s.type=`component`,l=!0);let t=!1;if(!l&&!s.voidElement&&Ke.test(s.name)){t=!0,d||=e.toLowerCase();let n=d.indexOf(`</`+s.name.toLowerCase()+`>`,g),r=n===-1?e.length:n,i=e.slice(g,r);i&&s.children.push({type:`text`,content:i}),u=r}!s.voidElement&&!l&&!t&&_&&_!==`<`&&s.children.push({type:`text`,content:e.slice(g,v?v.index:void 0)}),c===0&&a.push(s),b=o[c-1],b&&b.children.push(s),o[c]=s}if((!m||s.voidElement)&&(c>-1&&(s.voidElement||s.name===i.slice(2,-1))&&(c--,s=c===-1?a:o[c]),!l&&(_!==`<`||y)&&_)){b=c===-1?a:o[c].children;let t=v?v.index:-1,n=e.slice(g,t===-1?void 0:t);Ge.test(n)&&(n=` `),(t>-1&&c+b.length>=0||n!==` `)&&b.push({type:`text`,content:n})}}),i&&Ye(a),a}function Ze(e){let t=[];for(let n in e)e[n]===null?t.push(n):t.push(n+`="`+String(e[n]).replace(/"/g,`&quot;`)+`"`);return t.length?` `+t.join(` `):``}function Qe(e,t){switch(t.type){case`text`:return e+t.content;case`tag`:{let n=t.voidElement&&t.name.toLowerCase()!==`!doctype`?`/>`:`>`;return e+=`<`+t.name+(t.attrs?Ze(t.attrs):``)+n,t.voidElement?e:e+t.children.reduce(Qe,``)+`</`+t.name+`>`}case`comment`:return e+=`<!--`+t.comment+`-->`,e}}function $e(e){return e.reduce(function(e,t){return e+Qe(``,t)},``)}var et={parse:Xe,stringify:$e},Y=t(n()),tt=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},nt=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?it(t):t},rt=e=>it(e).every(Y.isValidElement),it=e=>Array.isArray(e)?e:[e],at=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},ot=e=>{let t={};if(!e)return t;let n=e=>{it(e).forEach(e=>{Te(e)||(tt(e)?n(nt(e)):Ce(e)&&!(0,Y.isValidElement)(e)&&Object.assign(t,e))})};return n(e),t},st=(e,t,n,r)=>{if(!e)return``;let i=``,a=it(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(Te(e))i+=`${e}`;else if((0,Y.isValidElement)(e)){let{props:s,type:c}=e,l=Object.keys(s).length,u=o.indexOf(c)>-1,d=s.children;if(!d&&u&&!l){i+=`<${c}/>`;return}if(!d&&(!u||l)||s.i18nIsDynamicList){i+=`<${a}></${a}>`;return}if(u&&l<=1){let e=Te(d)?d:st(d,t,n,r);i+=`<${c}>${e}</${c}>`;return}let f=st(d,t,n,r);i+=`<${a}>${f}</${a}>`}else if(e===null)xe(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});else if(Ce(e)){let{format:t,...a}=e,o=Object.keys(a);if(o.length===1){let e=t?`${o[0]}, ${t}`:o[0];i+=`{{${e}}}`;return}xe(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e})}else xe(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),i},ct=(e,t,n,r,i,s,c)=>{if(n===``)return[];let l=i.transKeepBasicHtmlNodesFor||[],u=n&&new RegExp(l.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!u&&!c)return[n];let d=t??{},f=e=>{it(e).forEach(e=>{Te(e)||(tt(e)?f(nt(e)):Ce(e)&&!(0,Y.isValidElement)(e)&&Object.assign(d,e))})};f(e);let p=Object.keys(d),m=et.parse(`<0>${n}</0>`,{allowedTags:e=>/^\d+$/.test(e)||l.indexOf(e)>-1||p.indexOf(e)>-1}),h={...d,...s},g=(e,t,n)=>{let r=nt(e),i=v(r,t.children,n);return rt(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},_=(e,t,n,r,i)=>{e.dummy?(e.children=t,n.push((0,Y.cloneElement)(e,{key:r},i?void 0:t))):n.push(...Y.Children.map([e],e=>{if(e.type===Y.Fragment||e.props?.i18nIsDynamicList!==void 0){let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t!==`children`&&t!==`i18nIsDynamicList`&&(n[t]=e.props[t])}),(0,Y.createElement)(e.type,n,i?null:t)}let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t!==`ref`&&t!==`children`&&(n[t]=e.props[t])}),(0,Y.cloneElement)(e,n,i?null:t)}))},v=(e,n,s)=>{let d=it(e),f=it(n),p={};return f.reduce((e,n,f)=>{let m=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,h,r.language);if(n.type===`tag`){let o=d[parseInt(n.name,10)];!o&&t&&(o=t[n.name]),s.length===1&&!o&&(o=s[0][n.name]),o||={};let y={...n.attrs};c&&Object.keys(y).forEach(e=>{let t=y[e];Te(t)&&(y[e]=a(t))});let b=Object.keys(y).length===0?o:at({props:y},o),x=(0,Y.isValidElement)(b),S=x&&tt(n,!0)&&!n.voidElement,C=u&&Ce(b)&&b.dummy&&!x,w=Ce(t)&&Object.hasOwnProperty.call(t,n.name);if(Te(b)){let t=r.services.interpolator.interpolate(b,h,r.language);e.push(t)}else if(tt(b)||S){let t=g(b,n,s);_(b,t,e,f)}else if(C){let t=v(d,n.children,s);_(b,t,e,f)}else if(Number.isNaN(parseFloat(n.name))){if(w){let t=g(b,n,s);_(b,t,e,f,n.voidElement)}else if(i.transSupportBasicHtmlNodes&&l.indexOf(n.name)>-1){if(n.voidElement)e.push((0,Y.createElement)(n.name,{key:`${n.name}-${f}`}));else{let t=p[n.name]||0;p[n.name]=t+1;let r,i=0;for(let e=0;e<d.length;e+=1){let a=d[e];if((0,Y.isValidElement)(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let a=r?it(nt(r)):d,o=v(a,n.children,s);e.push((0,Y.createElement)(n.name,{key:`${n.name}-${f}`},o))}}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=v(d,n.children,s);e.push(`<${n.name}>${t}</${n.name}>`)}}else if(Ce(b)&&!x){let t=n.children[0]?m:null;t&&e.push(t)}else _(b,m,e,f,n.children.length!==1||!m)}else if(n.type===`text`){let t=i.transWrapTextNodes,a=typeof i.unescape==`function`?i.unescape:o().unescape,s=c?a(r.services.interpolator.interpolate(n.content,h,r.language)):r.services.interpolator.interpolate(n.content,h,r.language);t?e.push((0,Y.createElement)(t,{key:`${n.name}-${f}`},s)):e.push(s)}return e},[])};return nt(v([{dummy:!0,children:e||[]}],m,it(e||[]))[0])},lt=(e,t,n)=>{let r=e.key||t,i=(0,Y.cloneElement)(e,{key:r});if(!i.props||!i.props.children||n.indexOf(`${t}/>`)<0&&n.indexOf(`${t} />`)<0)return i;function a(){return(0,Y.createElement)(Y.Fragment,null,i)}return(0,Y.createElement)(a,{key:r})},ut=(e,t)=>e.map((e,n)=>lt(e,n,t)),dt=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:lt(e[r],r,t)})}),n},ft=(e,t,n,r)=>e?Array.isArray(e)?ut(e,t):Ce(e)?dt(e,t):(Se(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,pt=e=>!Ce(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function mt({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:l,defaults:u,components:d,ns:f,i18n:p,t:m,shouldUnescape:h,...g}){let _=p||c();if(!_)return Se(_,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using initReactI18next or by passing it via props or context. In monorepo setups, make sure there is only one instance of react-i18next.`,{i18nKey:r}),e;let v=m||_.t.bind(_)||(e=>e),y={...o(),..._.options?.react},b=f||(v.ns?void 0:_.options?.defaultNS||`translation`);Te(b)&&(b=[b]);let{transDefaultProps:x}=y,S=x?.tOptions?{...x.tOptions,...a}:a,C=h??x?.shouldUnescape,w=x?.values?{...x.values,...l}:l,T=x?.components?{...x.components,...d}:d,E=st(e,y,_,r),D=u||S?.defaultValue||E||y.transEmptyNodeValue||(typeof r==`function`?s(r):r),{hashTransKey:O}=y,k=r||(O?O(E||D):E||D);l=_.options?.interpolation?.defaultVariables?{..._.options.interpolation.defaultVariables,...w}:w;let A=ot(e);A&&typeof A.count==`number`&&t===void 0&&(t=A.count);let j=l||t!==void 0&&!_.options?.interpolation?.alwaysFormat||!e?S.interpolation:{interpolation:{...S.interpolation,prefix:`#$?`,suffix:`?$#`}},M={...S,context:i||S.context,count:t,...l,...j,defaultValue:D,ns:b},N=k?v(k,M):D;N===k&&D&&(N=D);let ee=ft(T,N,_,r),te=ee||e,ne=null;pt(ee)&&(ne=ee,te=e);let P=ct(te,ne,N,_,y,M,C),re=n??y.defaultTransParent;return re?(0,Y.createElement)(re,g,P):P}function ht({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:s,components:l,ns:u,i18n:d,t:f,shouldUnescape:p,...m}){let{i18n:h,defaultNS:g}=(0,Y.useContext)(K)||{},_=d||h||c(),v=f||_?.t.bind(_);return mt({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:o,defaults:s,components:l,ns:u||(v?.ns?void 0:g||_?.options?.defaultNS),i18n:_,t:f,shouldUnescape:p,...m})}var gt={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};gt.node;var _t=q(gt),vt={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};vt.node;var yt=q(vt),bt={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};bt.node;var xt=q(bt),St={name:`columns-2`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]],aliases:[`columns`]};St.node;var Ct=q(St),wt={name:`eraser`,size:24,node:[[`path`,{d:`M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21`,key:`g5wo59`}],[`path`,{d:`m5.082 11.09 8.828 8.828`,key:`1wx5vj`}]]};wt.node;var Tt=q(wt),Et={name:`file-clock`,size:24,node:[[`path`,{d:`M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85`,key:`ryk6xj`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 14v2.2l1.6 1`,key:`6m4bie`}],[`circle`,{cx:`8`,cy:`16`,r:`6`,key:`10v15b`}]]};Et.node;var Dt=q(Et),Ot={name:`file-cog`,size:24,node:[[`path`,{d:`M15 8a1 1 0 0 1-1-1V2a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8z`,key:`1ckgky`}],[`path`,{d:`M20 8v12a2 2 0 0 1-2 2h-4.182`,key:`1726p0`}],[`path`,{d:`m3.305 19.53.923-.382`,key:`ao1pio`}],[`path`,{d:`M4 10.592V4a2 2 0 0 1 2-2h8`,key:`1foop0`}],[`path`,{d:`m4.228 16.852-.924-.383`,key:`1fv9zy`}],[`path`,{d:`m5.852 15.228-.383-.923`,key:`1a9hc2`}],[`path`,{d:`m5.852 20.772-.383.924`,key:`1sh9ke`}],[`path`,{d:`m8.148 15.228.383-.923`,key:`4yu6lf`}],[`path`,{d:`m8.53 21.696-.382-.924`,key:`18b0s9`}],[`path`,{d:`m9.773 16.852.922-.383`,key:`ti6xop`}],[`path`,{d:`m9.773 19.148.922.383`,key:`rws47d`}],[`circle`,{cx:`7`,cy:`18`,r:`3`,key:`lvkj7j`}]],aliases:[`file-cog-2`]};Ot.node;var kt=q(Ot),At={name:`file-headphone`,size:24,node:[[`path`,{d:`M4 6.835V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-.343`,key:`1vfytu`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M2 19a2 2 0 0 1 4 0v1a2 2 0 0 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 0 1-4 0v-1a2 2 0 0 1 4 0`,key:`1etmh7`}]],aliases:[`file-audio`,`file-audio-2`]};At.node;var jt=q(At),Mt={name:`file-image`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]};Mt.node;var Nt=q(Mt),Pt={name:`file-plus-corner`,size:24,node:[[`path`,{d:`M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35`,key:`17jvcc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 19h6`,key:`bvotb8`}],[`path`,{d:`M17 16v6`,key:`18yu1i`}]],aliases:[`file-plus-2`]};Pt.node;var Ft=q(Pt),It={name:`file-play`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z`,key:`1tzo1f`}]],aliases:[`file-video`]};It.node;var Lt=q(It),Rt={name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]};Rt.node;var zt=q(Rt),Bt={name:`grip-vertical`,size:24,node:[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]};Bt.node;var Vt=q(Bt),Ht={name:`hash`,size:24,node:[[`line`,{x1:`4`,x2:`20`,y1:`9`,y2:`9`,key:`4lhtct`}],[`line`,{x1:`4`,x2:`20`,y1:`15`,y2:`15`,key:`vyu0kd`}],[`line`,{x1:`10`,x2:`8`,y1:`3`,y2:`21`,key:`1ggp8o`}],[`line`,{x1:`16`,x2:`14`,y1:`3`,y2:`21`,key:`weycgp`}]]};Ht.node;var Ut=q(Ht),Wt={name:`keyboard`,size:24,node:[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]};Wt.node;var Gt=q(Wt),Kt={name:`library-big`,size:24,node:[[`rect`,{width:`8`,height:`18`,x:`3`,y:`3`,rx:`1`,key:`oynpb5`}],[`path`,{d:`M7 3v18`,key:`bbkbws`}],[`path`,{d:`M20.4 18.9c.2.5-.1 1.1-.6 1.3l-1.9.7c-.5.2-1.1-.1-1.3-.6L11.1 5.1c-.2-.5.1-1.1.6-1.3l1.9-.7c.5-.2 1.1.1 1.3.6Z`,key:`1qboyk`}]]};Kt.node;var qt=q(Kt),Jt={name:`logs`,size:24,node:[[`path`,{d:`M3 5h1`,key:`1mv5vm`}],[`path`,{d:`M3 12h1`,key:`lp3yf2`}],[`path`,{d:`M3 19h1`,key:`w6f3n9`}],[`path`,{d:`M8 5h1`,key:`1nxr5w`}],[`path`,{d:`M8 12h1`,key:`1con00`}],[`path`,{d:`M8 19h1`,key:`k7p10e`}],[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}]]};Jt.node;var Yt=q(Jt),Xt={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};Xt.node;var Zt=q(Xt),Qt={name:`move`,size:24,node:[[`path`,{d:`M12 2v20`,key:`t6zp3m`}],[`path`,{d:`m15 19-3 3-3-3`,key:`11eu04`}],[`path`,{d:`m19 9 3 3-3 3`,key:`1mg7y2`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`m5 9-3 3 3 3`,key:`j64kie`}],[`path`,{d:`m9 5 3-3 3 3`,key:`l8vdw6`}]]};Qt.node;var $t=q(Qt),en={name:`package-open`,size:24,node:[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]};en.node;var tn=q(en),nn={name:`panel-left-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]],aliases:[`sidebar-close`]};nn.node;var rn=q(nn),an={name:`panel-left-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]],aliases:[`sidebar-open`]};an.node;var on=q(an),sn={name:`panel-left`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]],aliases:[`sidebar`]};sn.node;var cn=q(sn),ln={name:`panel-right`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]};ln.node;var un=q(ln),dn={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};dn.node;var fn=q(dn),pn={name:`rotate-ccw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]};pn.node;var mn=q(pn),hn={name:`send`,size:24,node:[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]};hn.node;var gn=q(hn),_n={name:`settings`,size:24,node:[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]};_n.node;var vn=q(_n),yn={name:`wand-sparkles`,size:24,node:[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]],aliases:[`wand-2`]};yn.node;var bn=q(yn),X=i(),xn=new Set(`tex.latex.ltx.bib.bibtex.bst.sty.cls.dtx.ins.def.fd.aux.bbl.blg.log.toc.lof.lot.idx.ilg.ind.nav.snm.out.vrb.txt.text.dat.csv.tsv.md.markdown.mdown.mkdn.rst.ps.eps.json.jsonc.json5.jsonl.ipynb.yaml.yml.toml.ini.cfg.conf.cnf.env.properties.rc.lock.c.cc.cpp.cxx.h.hh.hpp.hxx.m.mm.cs.java.js.mjs.cjs.jsx.ts.mts.cts.tsx.py.pyw.pyi.r.rmd.qmd.jl.pl.pm.rb.go.rs.lua.php.sh.bash.zsh.ksh.fish.bashrc.zshrc.profile.awk.sed.ps1.psm1.bat.cmd.sql.html.htm.xhtml.css.scss.sass.less.xml.xsd.xsl.xslt.graphql.gql.proto.cmake.mk.diff.patch.srt.vtt.asc.pem`.split(`.`)),Sn=new Set(`latexmkrc,.latexmkrc,readme,license,licence,copying,authors,changelog,makefile,gnumakefile,dockerfile,containerfile,pkgbuild,.gitignore,.gitattributes,.gitmodules,.dockerignore,.editorconfig,.npmrc,.yarnrc,.prettierrc,.eslintrc,.babelrc,.bashrc,.zshrc,.profile,.bash_profile,.zprofile`.split(`,`));function Cn(e){let t=e.split(`/`).at(-1)?.toLowerCase()??``,n=t.lastIndexOf(`.`),r=n>0?t.slice(n+1).toLowerCase():``;return r===`pdf`?`pdf`:/^(?:png|jpe?g|gif|webp|svg|bmp|ico|avif|tiff?)$/.test(r)?`image`:/^(?:zip|gz|bz2|xz|tar|rar|7z|zst|svgz|docx?|xlsx?|pptx?|od[tps]|mp[34]|wav|ogg|webm|mov|avi|flac|woff2?|ttf|otf|eot|pfb|pfa|tfm|vf|fmt|dvi|xdv|synctex|wasm|exe|bin|[ao]|so|dylib|dll|class|jar|sqlite3?|db|pyc|psd)$/.test(r)?`binary`:xn.has(r)||Sn.has(t)||t===`.env`||t.startsWith(`.env.`)||t.startsWith(`dockerfile.`)||t.startsWith(`containerfile.`)?`text`:`other`}function wn(e,t){return!!e&&Cn(e)===`text`&&t!==!1}function Tn(e,t=!1){for(let t of e)if(t<32&&t!==9&&t!==10&&t!==12&&t!==13||t===127)return!1;try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e,{stream:t}),!0}catch{return!1}}function En({size:e=16,...t}){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.75,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:`false`,...t,children:(0,X.jsx)(`path`,{d:`M2.5 17V7l5 5 5-5v10M19.5 7v10m-3-3 3 3 3-3`})})}function Dn({size:e=16,variant:t=`document`,...n}){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.75,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:`false`,...n,children:t===`wordmark`?(0,X.jsx)(`path`,{d:`M2.5 17V7H5a2.5 2.5 0 0 1 0 5H2.5M9.5 7H11a5 5 0 0 1 0 10H9.5ZM21.5 7h-4v10m0-5H21`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`path`,{d:`M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9Z`}),(0,X.jsx)(`path`,{d:`M14 3v6h6`}),(0,X.jsx)(`path`,{transform:`translate(2.4 3.1) scale(.8)`,strokeWidth:1.5,d:`M5.5 18v-5H7a1.5 1.5 0 0 1 0 3H5.5M10 13h1a2.5 2.5 0 0 1 0 5h-1ZM18.5 13h-3v5m0-2.5H18`})]})})}function On({size:e=16,...t}){return(0,X.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:`false`,...t,children:(0,X.jsx)(`path`,{d:`M2 6.5h6m-3 0v10M14 9.5H9.5v10H14m-4.5-5h4M16 6.5l6 10m0-10-6 10`})})}var kn=new Set([`avif`,`bmp`,`gif`,`ico`,`jpeg`,`jpg`,`png`,`svg`,`webp`,`eps`]),An=new Set([`latex`,`ltx`,`tex`]),jn=new Set(`aux.blg.bbl.bst.c.cc.cls.cpp.css.dtx.go.h.hpp.html.idx.ilg.ind.ins.java.js.json.jsx.lof.log.lot.lua.ltx.nav.out.php.py.r.rs.sh.snm.sql.sty.tex.toc.ts.tsx.vrb.xml.yaml.yml`.split(`.`)),Mn=new Set([`cfg`,`conf`,`dat`,`env`,`ini`,`text`,`toml`,`txt`]),Nn=new Set([`csv`,`ods`,`tsv`,`xls`,`xlsx`]),Pn=new Set([`7z`,`bz2`,`gz`,`rar`,`tar`,`xz`,`zip`]),Fn=new Set([`m4a`,`mp3`,`ogg`,`wav`]),In=new Set([`avi`,`mkv`,`mov`,`mp4`,`webm`]);function Ln(e){let t=e.split(`/`).at(-1)?.toLocaleLowerCase()??``;if(t===`.latexmkrc`||t===`latexmkrc`)return`latexmkrc`;if(t===`makefile`||t===`dockerfile`)return`code`;if(t===`readme`)return`markdown`;let n=t.includes(`.`)?t.slice(t.lastIndexOf(`.`)+1):``;return n===`pdf`?`pdf`:kn.has(n)?`image`:n===`md`||n===`markdown`||n===`mdown`||n===`mkdn`?`markdown`:An.has(n)?`tex`:n===`bib`||n===`bibtex`?`bib`:jn.has(n)?`code`:Mn.has(n)?`text`:Nn.has(n)?`spreadsheet`:Pn.has(n)?`archive`:Fn.has(n)?`audio`:In.has(n)?`video`:`file`}var Rn={bib:qt,latexmkrc:kt,image:Nt,text:h,code:P,spreadsheet:z,archive:ne,audio:jt,video:Lt,file:zt};function zn({path:e,size:t=13}){let n=Ln(e),r=`file-type-icon file-type-icon-${n}`;if(n===`pdf`)return(0,X.jsx)(Dn,{className:r,size:t,variant:`wordmark`});if(n===`tex`)return(0,X.jsx)(On,{className:r,size:t});if(n===`markdown`)return(0,X.jsx)(En,{className:r,size:t});let i=Rn[n];return(0,X.jsx)(i,{className:r,size:t,"aria-hidden":`true`})}var Bn=()=>new Map,Vn=e=>{let t=Bn();return e.forEach((e,n)=>{t.set(n,e)}),t},Hn=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Un=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Wn=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Gn=()=>new Set,Kn=e=>e[e.length-1],qn=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Jn=Array.from,Yn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Xn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Zn=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Qn=Array.isArray,$n=class{constructor(){this._observers=Bn()}on(e,t){return Hn(this._observers,e,Gn).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Jn((this._observers.get(e)||Bn()).values()).forEach(e=>e(...t))}destroy(){this._observers=Bn()}},er=class{constructor(){this._observers=Bn()}on(e,t){Hn(this._observers,e,Gn).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Jn((this._observers.get(e)||Bn()).values()).forEach(e=>e(...t))}destroy(){this._observers=Bn()}},tr=Math.floor,nr=Math.abs,rr=(e,t)=>e<t?e:t,ir=(e,t)=>e>t?e:t;Number.isNaN;var ar=Math.pow,or=e=>e===0?1/e<0:e<0,sr=1<<29,cr=2**53-1,lr=-(2**53-1),ur=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&tr(e)===e);Number.isNaN,Number.parseInt;var dr=String.fromCharCode;String.fromCodePoint,dr(65535);var fr=e=>e.toLowerCase(),pr=/^\s*/g,mr=e=>e.replace(pr,``),hr=/([A-Z])/g,gr=(e,t)=>mr(e.replace(hr,e=>`${t}${fr(e)}`)),_r=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},vr=typeof TextEncoder<`u`?new TextEncoder:null,yr=vr?e=>vr.encode(e):_r,br=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});br&&br.decode(new Uint8Array).length===1&&(br=null);var xr=(e,t)=>Zn(t,()=>e).join(``),Sr=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Cr=()=>new Sr,wr=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},Tr=e=>{let t=new Uint8Array(wr(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},Er=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(ir(n,t)*2),e.cpos=0)},Dr=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},Or=Dr,Z=(e,t)=>{for(;t>127;)Dr(e,128|127&t),t=tr(t/128);Dr(e,127&t)},kr=(e,t)=>{let n=or(t);for(n&&(t=-t),Dr(e,(t>63?128:0)|(n?64:0)|63&t),t=tr(t/64);t>0;)Dr(e,(t>127?128:0)|127&t),t=tr(t/128)},Ar=new Uint8Array(3e4),jr=Ar.length/3,Mr=vr&&vr.encodeInto?(e,t)=>{if(t.length<jr){let n=vr.encodeInto(t,Ar).written||0;Z(e,n);for(let t=0;t<n;t++)Dr(e,Ar[t])}else Pr(e,yr(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;Z(e,r);for(let t=0;t<r;t++)Dr(e,n.codePointAt(t))},Nr=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=rr(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(ir(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Pr=(e,t)=>{Z(e,t.byteLength),Nr(e,t)},Fr=(e,t)=>{Er(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Ir=(e,t)=>Fr(e,4).setFloat32(0,t,!1),Lr=(e,t)=>Fr(e,8).setFloat64(0,t,!1),Rr=(e,t)=>Fr(e,8).setBigInt64(0,t,!1),zr=new DataView(new ArrayBuffer(4)),Br=e=>(zr.setFloat32(0,e),zr.getFloat32(0)===e),Vr=(e,t)=>{switch(typeof t){case`string`:Dr(e,119),Mr(e,t);break;case`number`:ur(t)&&nr(t)<=2147483647?(Dr(e,125),kr(e,t)):Br(t)?(Dr(e,124),Ir(e,t)):(Dr(e,123),Lr(e,t));break;case`bigint`:Dr(e,122),Rr(e,t);break;case`object`:if(t===null)Dr(e,126);else if(Qn(t)){Dr(e,117),Z(e,t.length);for(let n=0;n<t.length;n++)Vr(e,t[n])}else if(t instanceof Uint8Array)Dr(e,116),Pr(e,t);else{Dr(e,118);let n=Object.keys(t);Z(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Mr(e,i),Vr(e,t[i])}}break;case`boolean`:Dr(e,t?120:121);break;default:Dr(e,127)}},Hr=class extends Sr{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&Z(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Ur=e=>{e.count>0&&(kr(e.encoder,e.count===1?e.s:-e.s),e.count>1&&Z(e.encoder,e.count-2))},Wr=class{constructor(){this.encoder=new Sr,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Ur(this),this.count=1,this.s=e)}toUint8Array(){return Ur(this),Tr(this.encoder)}},Gr=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);kr(e.encoder,t),e.count>1&&Z(e.encoder,e.count-2)}},Kr=class{constructor(){this.encoder=new Sr,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Gr(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Gr(this),Tr(this.encoder)}},qr=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Wr}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Sr;return this.sarr.push(this.s),this.s=``,Mr(e,this.sarr.join(``)),Nr(e,this.lensE.toUint8Array()),Tr(e)}},Jr=e=>Error(e),Yr=()=>{throw Jr(`Method unimplemented`)},Xr=()=>{throw Jr(`Unexpected case`)},Zr=Jr(`Unexpected end of array`),Qr=Jr(`Integer out of Range`),$r=class{constructor(e){this.arr=e,this.pos=0}},ei=e=>new $r(e),ti=e=>e.pos!==e.arr.length,ni=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ri=e=>ni(e,Q(e)),ii=e=>e.arr[e.pos++],Q=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>cr)throw Qr}throw Zr},ai=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>cr)throw Qr}throw Zr},oi=br?e=>br.decode(ri(e)):e=>{let t=Q(e);if(t===0)return``;{let n=String.fromCodePoint(ii(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ii(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},si=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},ci=[e=>void 0,e=>null,ai,e=>si(e,4).getFloat32(0,!1),e=>si(e,8).getFloat64(0,!1),e=>si(e,8).getBigInt64(0,!1),e=>!1,e=>!0,oi,e=>{let t=Q(e),n={};for(let r=0;r<t;r++){let t=oi(e);n[t]=li(e)}return n},e=>{let t=Q(e),n=[];for(let r=0;r<t;r++)n.push(li(e));return n},ri],li=e=>ci[127-ii(e)](e),ui=class extends $r{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=ti(this)?Q(this)+1:-1),this.count--,this.s}},di=class extends $r{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ai(this);let e=or(this.s);this.count=1,e&&(this.s=-this.s,this.count=Q(this)+2)}return this.count--,this.s}},fi=class extends $r{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ai(this),t=e&1;this.diff=tr(e/2),this.count=1,t&&(this.count=Q(this)+2)}return this.s+=this.diff,this.count--,this.s}},pi=class{constructor(e){this.decoder=new di(e),this.str=oi(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var mi=crypto.getRandomValues.bind(crypto),hi=()=>mi(new Uint32Array(1))[0],gi=`10000000-1000-4000-8000-100000000000`,_i=()=>gi.replace(/[018]/g,e=>(e^hi()&15>>e/4).toString(16)),vi=Date.now,yi=e=>new Promise(e);Promise.all.bind(Promise);var bi=e=>e===void 0?null:e,xi=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Si=!0;try{typeof localStorage<`u`&&localStorage&&(xi=localStorage,Si=!1)}catch{}var Ci=xi,wi=e=>Si||addEventListener(`storage`,e),Ti=e=>Si||removeEventListener(`storage`,e),Ei=Symbol(`Equality`),Di=(e,t)=>e===t||!!e?.[Ei]?.(t)||!1,Oi=e=>typeof e==`object`,ki=Object.assign,Ai=Object.keys,ji=(e,t)=>{for(let n in e)t(e[n],n)},Mi=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},Ni=e=>Ai(e).length,Pi=e=>{for(let t in e)return!1;return!0},Fi=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Ii=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Li=(e,t)=>e===t||Ni(e)===Ni(t)&&Fi(e,(e,n)=>(e!==void 0||Ii(t,n))&&Di(t[n],e)),Ri=Object.freeze,zi=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&zi(e[t])}return Ri(e)},Bi=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Bi(e,t,n+1)}},Vi=e=>e,Hi=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Ei]!=null)return e[Ei](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!Hi(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Ni(e)!==Ni(t))return!1;for(let n in e)if(!Ii(e,n)||!Hi(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Hi(e[n],t[n]))return!1;break;default:return!1}return!0},Ui=(e,t)=>t.includes(e),Wi=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Gi=typeof window<`u`&&typeof document<`u`&&!Wi;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Ki,qi=[],Ji=()=>{if(Ki===void 0){if(Wi){Ki=Bn();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&Ki.set(t,``),t=r):t===null?qi.push(r):(Ki.set(t,r),t=null)}t!==null&&Ki.set(t,``)}else typeof location==`object`?(Ki=Bn(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);Ki.set(`--${gr(t,`-`)}`,n),Ki.set(`-${gr(t,`-`)}`,n)}})):Ki=Bn()}return Ki},Yi=e=>Ji().has(e),Xi=e=>bi(Wi?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Ci.getItem(e)),Zi=e=>Yi(`--`+e)||Xi(e)!==null,Qi=Zi(`production`),$i=Wi&&Ui({}.FORCE_COLOR,[`true`,`1`,`2`])||!Yi(`--no-colors`)&&!Zi(`no-color`)&&(!Wi||process.stdout.isTTY)&&(!Wi||Yi(`--color`)||Xi(`COLORTERM`)!==null||(Xi(`TERM`)||``).includes(`color`)),ea=e=>new Uint8Array(e),ta=(e,t,n)=>new Uint8Array(e,t,n),na=e=>new Uint8Array(e),ra=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=dr(e[n]);return btoa(t)},ia=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),aa=e=>{let t=atob(e),n=ea(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},oa=e=>{let t=Buffer.from(e,`base64`);return ta(t.buffer,t.byteOffset,t.byteLength)},sa=Gi?ra:ia,ca=Gi?aa:oa,la=e=>{let t=ea(e.byteLength);return t.set(e),t},ua=class{constructor(e,t){this.left=e,this.right=t}},da=(e,t)=>new ua(e,t),fa=(e,t)=>e.forEach(e=>t(e.left,e.right)),pa=e=>e.next()>=.5,ma=(e,t,n)=>tr(e.next()*(n+1-t)+t),ha=(e,t,n)=>tr(e.next()*(n+1-t)+t),ga=(e,t,n)=>ha(e,t,n),_a=e=>dr(ga(e,97,122)),va=(e,t=0,n=20)=>{let r=ga(e,t,n),i=``;for(let t=0;t<r;t++)i+=_a(e);return i},ya=(e,t)=>t[ga(e,0,t.length-1)],ba=Symbol(`0schema`),xa=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(xr(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
3
+ `)}},Sa=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Ei]?Di(e,t):Qn(e)?Yn(e,e=>Xn(t,t=>Sa(e,t))):Oi(e)?Fi(e,(e,n)=>Sa(e,t[n])):!1,Ca=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Sa(t,n)}equals(e){return this.constructor===e.constructor&&Hi(this.shape,e.shape)}[ba](){return!0}[Ei](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Yr()}get nullable(){return no(this,vo)}get optional(){return new Pa(this)}cast(e){return So(e,this),e}expect(e){return So(e,this),e}},wa=class extends Ca{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Ta=(e,t=null)=>new wa(e,t);Ta(wa);var Ea=class extends Ca{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Da=e=>new Ea(e);Ta(Ea);var Oa=class extends Ca{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},ka=(...e)=>new Oa(e),Aa=Ta(Oa),ja=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Ma=e=>{if(po.check(e))return[ja(e)];if(Aa.check(e))return e.shape.map(e=>e+``);if(fo.check(e))return[`[+-]?\\d+.?\\d*`];if(mo.check(e))return[`.*`];if(ro.check(e))return e.shape.map(Ma).flat(1);Xr()};Ta(class extends Ca{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ma).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Na=Symbol(`optional`),Pa=class extends Ca{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Na](){return!0}},Fa=Ta(Pa),Ia=class extends Ca{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Ia,Ta(Ia);var La=class e extends Ca{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Fi(this.shape,(n,r)=>{let i=this._isPartial&&!Ii(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Ra=e=>new La(e),za=Ta(La),Ba=Da(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Va=class extends Ca{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Fi(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},Ha=(e,t)=>new Va(e,t),Ua=Ta(Va),Wa=class extends Ca{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Fi(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},Ga=(...e)=>new Wa(e);Ta(Wa);var Ka=class extends Ca{constructor(e){super(),this.shape=e.length===1?e[0]:new to(e)}check(e,t){let n=Qn(e)&&Yn(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},qa=(...e)=>new Ka(e),Ja=Ta(Ka),Ya=Da(e=>Qn(e)),Xa=class extends Ca{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},Za=(e,t=null)=>new Xa(e,t);Ta(Xa);var Qa=Za(Ca),$a=Ta(class extends Ca{constructor(e){super(),this.len=e.length-1,this.args=Ga(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),eo=Da(e=>typeof e==`function`);Ta(class extends Ca{constructor(e){super(),this.shape=e}check(e,t){let n=Yn(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var to=class extends Ca{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=Xn(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},no=(...e)=>e.findIndex(e=>ro.check(e))>=0?no(...e.map(e=>xo(e)).map(e=>ro.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new to(e),ro=Ta(to),io=()=>!0,ao=Da(io),oo=Ta(Ea,e=>e.shape===io),so=Da(e=>typeof e==`bigint`),co=Da(e=>e===so),lo=Da(e=>typeof e==`symbol`);Da(e=>e===lo);var uo=Da(e=>typeof e==`number`),fo=Da(e=>e===uo),po=Da(e=>typeof e==`string`),mo=Da(e=>e===po),ho=Da(e=>typeof e==`boolean`),go=Da(e=>e===ho),_o=ka(void 0);Ta(Oa,e=>e.shape.length===1&&e.shape[0]===void 0),ka(void 0);var vo=ka(null),yo=Ta(Oa,e=>e.shape.length===1&&e.shape[0]===null);Ta(Uint8Array),Ta(wa,e=>e.shape===Uint8Array);var bo=no(uo,po,vo,_o,so,ho,lo);(()=>{let e=qa(ao),t=Ha(po,ao),n=no(uo,po,vo,ho,e,t);return e.shape=n,t.shape.values=n,n})();var xo=e=>{if(Qa.check(e))return e;if(Ba.check(e)){let t={};for(let n in e)t[n]=xo(e[n]);return Ra(t)}if(Ya.check(e))return no(...e.map(xo));if(bo.check(e))return ka(e);if(eo.check(e))return Ta(e);Xr()},So=Qi?()=>{}:(e,t)=>{let n=new xa;if(!t.check(e,n))throw Jr(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Co=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:xo(e),h:t}),this}else(e){return this.if(ao,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Jr(`Unhandled pattern`)}}},wo=(e=>new Co(e))(ao).if(fo,(e,t)=>ma(t,lr,cr)).if(mo,(e,t)=>va(t)).if(go,(e,t)=>pa(t)).if(co,(e,t)=>BigInt(ma(t,lr,cr))).if(ro,(e,t)=>To(t,ya(t,e.shape))).if(za,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Fa.check(i)){if(pa(t))continue;i=i.shape}n[r]=wo(i,t)}return n}).if(Ja,(e,t)=>{let n=[],r=ha(t,0,42);for(let i=0;i<r;i++)n.push(To(t,e.shape));return n}).if(Aa,(e,t)=>ya(t,e.shape)).if(yo,(e,t)=>null).if($a,(e,t)=>{let n=To(t,e.res);return()=>n}).if(oo,(e,t)=>To(t,ya(t,[uo,po,vo,_o,so,ho,qa(uo),Ha(no(`a`,`b`,`c`),uo)]))).if(Ua,(e,t)=>{let n={},r=ma(t,0,3);for(let i=0;i<r;i++){let r=To(t,e.shape.keys);n[r]=To(t,e.shape.values)}return n}).done(),To=(e,t)=>wo(xo(t),e),Eo=typeof document<`u`?document:{},Do=e=>Eo.createElement(e),Oo=()=>Eo.createDocumentFragment();Da(e=>e.nodeType===Bo);var ko=e=>Eo.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var Ao=(e,t)=>(fa(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),jo=e=>{let t=Oo();for(let n=0;n<e.length;n++)Io(t,e[n]);return t},Mo=(e,t)=>(Io(e,jo(t)),e),No=(e,t=[],n=[])=>Mo(Ao(Do(e),t),n);Da(e=>e.nodeType===Lo);var Po=ko;Da(e=>e.nodeType===Ro);var Fo=e=>Un(e,(e,t)=>`${t}:${e};`).join(``),Io=(e,t)=>e.appendChild(t),Lo=Eo.ELEMENT_NODE,Ro=Eo.TEXT_NODE;Eo.CDATA_SECTION_NODE,Eo.COMMENT_NODE;var zo=Eo.DOCUMENT_NODE;Eo.DOCUMENT_TYPE_NODE;var Bo=Eo.DOCUMENT_FRAGMENT_NODE;Da(e=>e.nodeType===zo);var Vo=Symbol,Ho=Vo(),Uo=Vo(),Wo=Vo(),Go=Vo(),Ko=Vo(),qo=Vo(),Jo=Vo(),Yo=Vo(),Xo=Vo(),Zo=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};vi();var Qo={[Ho]:da(`font-weight`,`bold`),[Uo]:da(`font-weight`,`normal`),[Wo]:da(`color`,`blue`),[Ko]:da(`color`,`green`),[Go]:da(`color`,`grey`),[qo]:da(`color`,`red`),[Jo]:da(`color`,`purple`),[Yo]:da(`color`,`orange`),[Xo]:da(`color`,`black`)},$o=$i?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Bn(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=Qo[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=Fo(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:Zo,es=(...e)=>{console.log(...$o(e)),ns.forEach(t=>t.print(e))},ts=(...e)=>{console.warn(...$o(e)),e.unshift(Yo),ns.forEach(t=>t.print(e))},ns=Gn(),rs=e=>({[Symbol.iterator](){return this},next:e}),is=(e,t)=>rs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),as=(e,t)=>rs(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),os=class{constructor(e,t){this.clock=e,this.len=t}},ss=class{constructor(){this.clients=new Map}},cs=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])wc(e,i,o.clock,o.len,n)}}),ls=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=tr((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},us=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ls(n,t.clock)!==null},ds=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new os(r.clock,ir(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},fs=e=>{let t=new ss;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)qn(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return ds(t),t},ps=(e,t,n,r)=>{Hn(e.clients,t,()=>[]).push(new os(n,r))},ms=()=>new ss,hs=e=>{let t=ms();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new os(i,a))}}r.length>0&&t.clients.set(n,r)}),t},gs=(e,t)=>{Z(e.restEncoder,t.clients.size),Jn(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),Z(e.restEncoder,t);let r=n.length;Z(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},_s=e=>{let t=new ss,n=Q(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=Q(e.restDecoder),r=Q(e.restDecoder);if(r>0){let i=Hn(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new os(e.readDsClock(),e.readDsLen()))}}return t},vs=(e,t,n)=>{let r=new ss,i=Q(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=Q(e.restDecoder),a=Q(e.restDecoder),o=n.clients.get(i)||[],s=gc(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&ps(r,i,s,a-s);let e=vc(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Bu(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Bu(t,c,a-c.id.clock)),c.delete(t))}else ps(r,i,n,a-n)}}if(r.clients.size>0){let e=new Os;return Z(e.restEncoder,0),gs(e,r),e.toUint8Array()}return null},ys=hi,bs=class e extends $n{constructor({guid:e=_i(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=ys(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new mc,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=yi(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>yi(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&Mc(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Jn(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Mc(this,e,t)}get(e,t=cl){let n=Hn(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==cl&&r!==t){if(r===cl){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Ol)}getText(e=``){return this.get(e,Yl)}getMap(e=``){return this.get(e,jl)}getXmlElement(e=``){return this.get(e,eu)}getXmlFragment(e=``){return this.get(e,Ql)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Jn(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Mc(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},xs=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Q(this.restDecoder)}readDsLen(){return Q(this.restDecoder)}},Ss=class extends xs{readLeftID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readRightID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readClient(){return Q(this.restDecoder)}readInfo(){return ii(this.restDecoder)}readString(){return oi(this.restDecoder)}readParentInfo(){return Q(this.restDecoder)===1}readTypeRef(){return Q(this.restDecoder)}readLen(){return Q(this.restDecoder)}readAny(){return li(this.restDecoder)}readBuf(){return la(ri(this.restDecoder))}readJSON(){return JSON.parse(oi(this.restDecoder))}readKey(){return oi(this.restDecoder)}},Cs=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Q(this.restDecoder),this.dsCurrVal}readDsLen(){let e=Q(this.restDecoder)+1;return this.dsCurrVal+=e,e}},ws=class extends Cs{constructor(e){super(e),this.keys=[],Q(e),this.keyClockDecoder=new fi(ri(e)),this.clientDecoder=new di(ri(e)),this.leftClockDecoder=new fi(ri(e)),this.rightClockDecoder=new fi(ri(e)),this.infoDecoder=new ui(ri(e),ii),this.stringDecoder=new pi(ri(e)),this.parentInfoDecoder=new ui(ri(e),ii),this.typeRefDecoder=new di(ri(e)),this.lenDecoder=new di(ri(e))}readLeftID(){return new Zs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Zs(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return li(this.restDecoder)}readBuf(){return ri(this.restDecoder)}readJSON(){return li(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Ts=class{constructor(){this.restEncoder=Cr()}toUint8Array(){return Tr(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Z(this.restEncoder,e)}writeDsLen(e){Z(this.restEncoder,e)}},Es=class extends Ts{writeLeftID(e){Z(this.restEncoder,e.client),Z(this.restEncoder,e.clock)}writeRightID(e){Z(this.restEncoder,e.client),Z(this.restEncoder,e.clock)}writeClient(e){Z(this.restEncoder,e)}writeInfo(e){Or(this.restEncoder,e)}writeString(e){Mr(this.restEncoder,e)}writeParentInfo(e){Z(this.restEncoder,+!!e)}writeTypeRef(e){Z(this.restEncoder,e)}writeLen(e){Z(this.restEncoder,e)}writeAny(e){Vr(this.restEncoder,e)}writeBuf(e){Pr(this.restEncoder,e)}writeJSON(e){Mr(this.restEncoder,JSON.stringify(e))}writeKey(e){Mr(this.restEncoder,e)}},Ds=class{constructor(){this.restEncoder=Cr(),this.dsCurrVal=0}toUint8Array(){return Tr(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,Z(this.restEncoder,t)}writeDsLen(e){e===0&&Xr(),Z(this.restEncoder,e-1),this.dsCurrVal+=e}},Os=class extends Ds{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Kr,this.clientEncoder=new Wr,this.leftClockEncoder=new Kr,this.rightClockEncoder=new Kr,this.infoEncoder=new Hr(Or),this.stringEncoder=new qr,this.parentInfoEncoder=new Hr(Or),this.typeRefEncoder=new Wr,this.lenEncoder=new Wr}toUint8Array(){let e=Cr();return Z(e,0),Pr(e,this.keyClockEncoder.toUint8Array()),Pr(e,this.clientEncoder.toUint8Array()),Pr(e,this.leftClockEncoder.toUint8Array()),Pr(e,this.rightClockEncoder.toUint8Array()),Pr(e,Tr(this.infoEncoder)),Pr(e,this.stringEncoder.toUint8Array()),Pr(e,Tr(this.parentInfoEncoder)),Pr(e,this.typeRefEncoder.toUint8Array()),Pr(e,this.lenEncoder.toUint8Array()),Nr(e,Tr(this.restEncoder)),Tr(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Vr(this.restEncoder,e)}writeBuf(e){Pr(this.restEncoder,e)}writeJSON(e){Vr(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},ks=(e,t,n,r)=>{r=ir(r,t[0].id.clock);let i=vc(t,r);Z(e.restEncoder,t.length-i),e.writeClient(n),Z(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},As=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{gc(t,n)>e&&r.set(n,e)}),hc(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),Z(e.restEncoder,r.size),Jn(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{ks(e,t.clients.get(n),n,r)})},js=(e,t)=>{let n=Bn(),r=Q(e.restDecoder);for(let i=0;i<r;i++){let r=Q(e.restDecoder),i=Array(r),a=e.readClient(),o=Q(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new lu($(a,o),t),o+=t;break}case 10:{let t=Q(e.restDecoder);i[n]=new qu($(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Uu($(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,Wu(e,r));i[n]=c,o+=c.length}}}}return n},Ms=(e,t,n)=>{let r=[],i=Jn(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new mc,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==qu){let i=Hn(d,u.id.client,()=>gc(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,gc(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Os;return As(e,s,new Map),Z(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},Ns=(e,t)=>As(e,t.doc.store,t.beforeState),Ps=(e,t,n,r=new ws(e))=>Mc(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Ms(e,i,js(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<gc(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=Hc([o.update,a.update])}}else i.pendingStructs=a;let s=vs(r,e,i);if(i.pendingDs){let t=new ws(ei(i.pendingDs));Q(t.restDecoder);let n=vs(t,e,i);i.pendingDs=s&&n?Hc([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Fs(e.doc,t)}},n,!1),Fs=(e,t,n,r=ws)=>{let i=ei(t);Ps(i,e,n,new r(i))},Is=(e,t,n)=>Fs(e,t,n,Ss),Ls=(e,t,n=new Map)=>{As(e,t.store,n),gs(e,hs(t.store))},Rs=(e,t=new Uint8Array([0]),n=new Os)=>{Ls(n,e,Vs(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Uc(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Es)return Bc(r.map((e,t)=>t===0?e:Jc(e)));if(n.constructor===Os)return Hc(r)}return r[0]},zs=(e,t)=>Rs(e,t,new Es),Bs=e=>{let t=new Map,n=Q(e.restDecoder);for(let r=0;r<n;r++){let n=Q(e.restDecoder),r=Q(e.restDecoder);t.set(n,r)}return t},Vs=e=>Bs(new xs(ei(e))),Hs=(e,t)=>(Z(e.restEncoder,t.size),Jn(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{Z(e.restEncoder,t),Z(e.restEncoder,n)}),e),Us=(e,t)=>Hs(e,hc(t.store)),Ws=(e,t=new Ds)=>(e instanceof Map?Hs(t,e):Us(t,e),t.toUint8Array()),Gs=e=>Ws(e,new Ts),Ks=class{constructor(){this.l=[]}},qs=()=>new Ks,Js=(e,t)=>e.l.push(t),Ys=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},Xs=(e,t,n)=>Bi(e.l,[t,n]),Zs=class{constructor(e,t){this.client=e,this.clock=t}},Qs=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,$=(e,t)=>new Zs(e,t),$s=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw Xr()},ec=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},tc=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},nc=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},rc=e=>new tc(e.type==null?null:$(e.type.client,e.type.clock),e.tname??null,e.item==null?null:$(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),ic=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},ac=(e,t,n=0)=>new ic(e,t,n),oc=(e,t,n)=>{let r=null,i=null;return e._item===null?i=$s(e):r=$(e._item.id.client,e._item.id.clock),new tc(r,i,t,n)},sc=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return oc(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return oc(e,$(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return oc(e,r.lastId,n);r=r.right}return oc(e,null,n)},cc=(e,t)=>{let n=yc(e,t);return{item:n,diff:t.clock-n.id.clock}},lc=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(gc(r,i.client)<=i.clock)return null;let e=n?Ru(r,i):cc(r,i),t=e.item;if(!(t instanceof Uu))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(gc(r,a.client)<=a.clock)return null;let{item:e}=n?Ru(r,a):{item:yc(r,a)};if(e instanceof Uu&&e.content instanceof Iu)c=e.content.type;else return null}else throw Xr();l=s>=0?c._length:0}return ac(c,l,e.assoc)},uc=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qs(e.item,t.item)&&Qs(e.type,t.type)&&e.assoc===t.assoc,dc=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new dc(e,t))(ms(),new Map);var fc=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!us(t.ds,e.id),pc=(e,t)=>{let n=Hn(e.meta,pc,Gn),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<gc(r,n)&&xc(e,$(n,t))}),cs(e,t.ds,e=>{}),n.add(t))},mc=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},hc=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},gc=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},_c=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw Xr()}n.push(t)},vc=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=tr(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=tr((n+r)/2)}throw Xr()},yc=(e,t)=>{let n=e.clients.get(t.client);return n[vc(n,t.clock)]},bc=(e,t,n)=>{let r=vc(t,n),i=t[r];return i.id.clock<n&&i instanceof Uu?(t.splice(r+1,0,Bu(e,i,n-i.id.clock)),r+1):r},xc=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[bc(e,n,t.clock)]},Sc=(e,t,n)=>{let r=t.clients.get(n.client),i=vc(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==lu&&r.splice(i+1,0,Bu(e,a,n.clock-a.id.clock+1)),a},Cc=(e,t,n)=>{let r=e.clients.get(t.id.client);r[vc(r,t.id.clock)]=n},wc=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=bc(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&bc(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Tc=class{constructor(e,t,n){this.doc=e,this.deleteSet=new ss,this.beforeState=hc(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Ec=(e,t)=>t.deleteSet.clients.size===0&&!Wn(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(ds(t.deleteSet),Ns(e,t),gs(e,t.deleteSet),!0),Dc=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Hn(e.changed,t,Gn).add(n)},Oc=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Uu&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},kc=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=vc(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Uu&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Ac=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=rr(r.length-1,1+vc(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Oc(r,e)}})},jc=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{ds(a),n.afterState=hc(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{Xs(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Kl(n)})}),Bi(e,[])}finally{r.gc&&kc(a,i,r.gcFilter),Ac(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=ir(vc(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Oc(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=vc(r,n);a+1<r.length&&Oc(r,a+1)>1||a>0&&Oc(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(es(Yo,Ho,`[yjs] `,Uo,qo,`Changed the client-id because another client seems to be using it.`),r.clientID=ys()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Es;Ec(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Os;Ec(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):jc(e,t+1)}}},Mc=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Tc(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&jc(i,0)}}return o},Nc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Pc=(e,t,n)=>{cs(e,n.deletions,n=>{n instanceof Uu&&t.scope.some(t=>t===e.doc||ec(t,n))&&zu(n,!1)})},Fc=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;Mc(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;cs(n,o.insertions,e=>{if(e instanceof Uu){if(e.redone!==null){let{item:t,diff:i}=Ru(r,e.id);i>0&&(t=xc(n,$(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||ec(t,e))&&c.push(e)}}),cs(n,o.deletions,e=>{e instanceof Uu&&a.some(t=>t===n.doc||ec(t,e))&&!us(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Hu(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Ic=class extends $n{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=Qn(e)?e[0].doc:e instanceof bs?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new ss;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&ps(i,n,r,a)});let a=vi(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=fs([t.deletions,e.deleteSet]),t.insertions=fs([t.insertions,i])}else r.push(new Nc(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),cs(e,e.deleteSet,t=>{t instanceof Uu&&this.scope.some(n=>n===e.doc||ec(n,t))&&zu(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=Qn(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof cl?e.doc!==this.doc:e!==this.doc)&&ts(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Pc(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Pc(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Fc(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Fc(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),super.destroy()}};function*Lc(e){let t=Q(e.restDecoder);for(let n=0;n<t;n++){let t=Q(e.restDecoder),n=e.readClient(),r=Q(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=Q(e.restDecoder);yield new qu($(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Uu($(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Wu(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new lu($(n,r),t),r+=t}}}}var Rc=class{constructor(e,t){this.gen=Lc(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===qu);return this.curr}},zc=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Bc=e=>Hc(e,Ss,Es),Vc=(e,t)=>{if(e.constructor===lu){let{client:n,clock:r}=e.id;return new lu($(n,r+t),e.length-t)}if(e.constructor===qu){let{client:n,clock:r}=e.id;return new qu($(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Uu($(r,i+t),null,$(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Hc=(e,t=ws,n=Os)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(ei(e))),i=r.map(e=>new Rc(e,!0)),a=null,o=new n,s=new zc(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===qu?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Gc(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock){if(a.struct.constructor===qu)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Gc(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new qu($(t,a.struct.id.clock+a.struct.length),e),offset:0}}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===qu?a.struct.length-=t:n=Vc(n,t)),a.struct.mergeWith(n)||(Gc(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==qu;n=e.next())Gc(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Gc(s,a.struct,a.offset),a=null),Kc(s),gs(o,fs(r.map(e=>_s(e)))),o.toUint8Array()},Uc=(e,t,n=ws,r=Os)=>{let i=Vs(t),a=new r,o=new zc(a),s=new n(ei(e)),c=new Rc(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===qu)c.next();else if(e.id.clock+e.length>n)for(Gc(o,e,ir(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Gc(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Kc(o),gs(a,_s(s)),a.toUint8Array()},Wc=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Tr(e.encoder.restEncoder)}),e.encoder.restEncoder=Cr(),e.written=0)},Gc=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Wc(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),Z(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Kc=e=>{Wc(e);let t=e.encoder.restEncoder;Z(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];Z(t,r.written),Nr(t,r.restEncoder)}},qc=(e,t,n,r)=>{let i=new n(ei(e)),a=new Rc(i,!1),o=new r,s=new zc(o);for(let e=a.curr;e!==null;e=a.next())Gc(s,t(e),0);return Kc(s),gs(o,_s(i)),o.toUint8Array()},Jc=e=>qc(e,Vi,ws,Es),Yc=`You must not compute changes after the event-handler fired.`,Xc=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=Zc(this.currentTarget,this.target)}deletes(e){return us(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Jr(Yc);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=Kn(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=Kn(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Kn(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Jr(Yc);let t=this.target,n=Gn(),r=Gn(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Zc=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},Qc=()=>{ts(`Invalid access: Add Yjs type to a document before reading data.`)},$c=80,el=0,tl=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=el++}},nl=e=>{e.timestamp=el++},rl=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=el++},il=(e,t,n)=>{if(e.length>=$c){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return rl(r,t,n),r}{let r=new tl(t,n);return e.push(r),r}},al=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>nr(t-e.index)<nr(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,nl(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&nr(n.index-i)<r.parent.length/$c?(rl(n,r,i),n):il(e._searchMarker,r,i)},ol=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=ir(t,i.index+n))}},sl=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Hn(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Xs(r._eH,n,t)},cl=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=qs(),this._dEH=qs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Yr()}clone(){throw Yr()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Js(this._eH,e)}observeDeep(e){Js(this._dEH,e)}unobserve(e){Ys(this._eH,e)}unobserveDeep(e){Ys(this._dEH,e)}toJSON(){}},ll=(e,t,n)=>{e.doc??Qc(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},ul=e=>{e.doc??Qc();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},dl=(e,t)=>{let n=0,r=e._start;for(e.doc??Qc();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},fl=(e,t)=>{let n=[];return dl(e,(r,i)=>{n.push(t(r,i,e))}),n},pl=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},ml=(e,t)=>{e.doc??Qc();let n=al(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},hl=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Uu($(o,gc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wu(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Uu($(o,gc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new uu(new Uint8Array(n))),i.integrate(e,0);break;case bs:i=new Uu($(o,gc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new hu(n)),i.integrate(e,0);break;default:if(n instanceof cl)i=new Uu($(o,gc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Iu(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},gl=()=>Jr(`Length exceeded!`),_l=(e,t,n,r)=>{if(n>t._length)throw gl();if(n===0)return t._searchMarker&&ol(t._searchMarker,n,r.length),hl(e,t,null,r);let i=n,a=al(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&xc(e,$(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&ol(t._searchMarker,i,r.length),hl(e,t,o,r)},vl=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return hl(e,t,r,n)},yl=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=al(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&xc(e,$(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&xc(e,$(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw gl();t._searchMarker&&ol(t._searchMarker,i,-a+r)},bl=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},xl=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new wu([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new wu([r]);break;case Uint8Array:s=new uu(r);break;case bs:s=new hu(r);break;default:if(r instanceof cl)s=new Iu(r);else throw Error(`Unexpected content type`)}new Uu($(o,gc(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Sl=(e,t)=>{e.doc??Qc();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Cl=e=>{let t={};return e.doc??Qc(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},wl=(e,t)=>{e.doc??Qc();let n=e._map.get(t);return n!==void 0&&!n.deleted},Tl=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&fc(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},El=e=>(e.doc??Qc(),is(e._map.entries(),e=>!e[1].deleted)),Dl=class extends Xc{},Ol=class e extends cl{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof cl?e.clone():e)),t}get length(){return this.doc??Qc(),this._length}_callObserver(e,t){super._callObserver(e,t),sl(this,e,new Dl(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Mc(this.doc,n=>{_l(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):Mc(this.doc,t=>{vl(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Mc(this.doc,n=>{yl(n,this,e,t)})}get(e){return ml(this,e)}toArray(){return ul(this)}slice(e=0,t=this.length){return ll(this,e,t)}toJSON(){return this.map(e=>e instanceof cl?e.toJSON():e)}map(e){return fl(this,e)}forEach(e){dl(this,e)}[Symbol.iterator](){return pl(this)}_write(e){e.writeTypeRef(ku)}},kl=e=>new Ol,Al=class extends Xc{constructor(e,t,n){super(e,t),this.keysChanged=n}},jl=class e extends cl{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof cl?e.clone():e)}),t}_callObserver(e,t){sl(this,e,new Al(this,e,t))}toJSON(){this.doc??Qc();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof cl?r.toJSON():r}}),e}get size(){return[...El(this)].length}keys(){return as(El(this),e=>e[0])}values(){return as(El(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return as(El(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Qc(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):Mc(this.doc,t=>{bl(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):Mc(this.doc,n=>{xl(n,this,e,t)}),t}get(e){return Sl(this,e)}has(e){return wl(this,e)}clear(){this.doc===null?this._prelimContent.clear():Mc(this.doc,e=>{this.forEach(function(t,n,r){bl(e,r,n)})})}_write(e){e.writeTypeRef(Au)}},Ml=e=>new jl,Nl=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Li(e,t),Pl=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&Xr(),this.right.content.constructor){case yu:this.right.deleted||Rl(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Fl=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case yu:t.right.deleted||Rl(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&xc(e,$(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length)}t.left=t.right,t.right=t.right.right}return t},Il=(e,t,n,r)=>{let i=new Map,a=r?al(t,n):null;return a?Fl(e,new Pl(a.p.left,a.p,a.index,i),n-a.index):Fl(e,new Pl(null,t._start,0,i),n)},Ll=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===yu&&Nl(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Uu($(a,gc(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new yu(o,r));l.integrate(e,0),n.right=l,n.forward()})},Rl=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},zl=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===yu&&Nl(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Bl=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Nl(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Uu($(a,gc(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new yu(s,c)),n.right.integrate(e,0),n.forward()}}return o},Vl=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;zl(n,i);let s=Bl(e,t,n,i),c=r.constructor===String?new Eu(r):r instanceof cl?new Iu(r):new _u(r),{left:l,right:u,index:d}=n;t._searchMarker&&ol(t._searchMarker,n.index,c.getLength()),u=new Uu($(o,gc(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Ll(e,t,n,s)},Hl=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;zl(n,i);let s=Bl(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===yu));){if(!n.right.deleted)switch(n.right.content.constructor){case yu:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Nl(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&xc(e,$(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
4
+ `;n.right=new Uu($(o,gc(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new Eu(i)),n.right.integrate(e,0),n.forward()}Ll(e,t,n,s)},Ul=(e,t,n,r,i)=>{let a=t,o=Bn();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===yu){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case yu:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Rl(i,n);break}}}t=t.right}return s},Wl=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===yu){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Gl=e=>{let t=0;return Mc(e.doc,n=>{let r=e._start,i=e._start,a=Bn(),o=Vn(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case yu:Rl(o,i.content);break;default:t+=Ul(n,r,i,a,o),a=Vn(o),r=i}i=i.right}}),t},Kl=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&wc(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===yu&&e.constructor!==lu&&t.add(e.parent)})}Mc(n,n=>{cs(e,e.deleteSet,e=>{if(e instanceof lu||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===yu?t.add(r):Wl(n,e)});for(let e of t)Gl(e)})},ql=(e,t,n)=>{let r=n,i=Vn(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Iu:case _u:case Eu:n<t.right.length&&xc(e,$(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Ul(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&ol(o._searchMarker,t.index,-r+n),t},Jl=class extends Xc{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];Mc(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Pi(o)||(e.attributes=ki({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Iu:case _u:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case Eu:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case yu:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Nl(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Nl(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Nl(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Nl(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Rl(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Yl=class e extends cl{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Qc(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Jl(this,e,t);sl(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Qc();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Eu&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):Mc(this.doc,n=>{let r=new Pl(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
5
+ `?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Vl(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&ql(n,r,a.delete):Hl(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??Qc();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(fc(s,e)||t!==void 0&&fc(s,t))switch(s.content.constructor){case Eu:{let r=i.get(`ychange`);e!==void 0&&!fc(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!fc(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Iu:case _u:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case yu:fc(s,e)&&(c(),Rl(i,s.content))}s=s.right}c()};return e||t?Mc(a,n=>{e&&pc(n,e),t&&pc(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):Mc(r,r=>{let i=Il(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Vl(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Mc(r,r=>{let i=Il(r,this,e,!n);Vl(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):Mc(n,n=>{ql(n,Il(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):Mc(r,r=>{let i=Il(r,this,e,!1);i.right!==null&&Hl(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Mc(this.doc,t=>{bl(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Mc(this.doc,n=>{xl(n,this,e,t)})}getAttribute(e){return Sl(this,e)}getAttributes(){return Cl(this)}_write(e){e.writeTypeRef(ju)}},Xl=e=>new Yl,Zl=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Qc()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===eu||t.constructor===Ql)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Ql=class e extends cl{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof cl?e.clone():e)),t}get length(){return this.doc??Qc(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Zl(this,e)}querySelector(e){e=e.toUpperCase();let t=new Zl(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Jn(new Zl(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){sl(this,e,new nu(this,t,e))}toString(){return fl(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),dl(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Mc(this.doc,n=>{_l(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Mc(this.doc,n=>{let r=e&&e instanceof cl?e._item:e;hl(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw Jr(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Mc(this.doc,n=>{yl(n,this,e,t)})}toArray(){return ul(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ml(this,e)}slice(e=0,t=this.length){return ll(this,e,t)}forEach(e){dl(this,e)}_write(e){e.writeTypeRef(Nu)}},$l=e=>new Ql,eu=class e extends Ql{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return ji(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof cl?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):Mc(this.doc,t=>{bl(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Mc(this.doc,n=>{xl(n,this,e,t)})}getAttribute(e){return Sl(this,e)}hasAttribute(e){return wl(this,e)}getAttributes(e){return e?Tl(this,e):Cl(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return dl(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Mu),e.writeKey(this.nodeName)}},tu=e=>new eu(e.readKey()),nu=class extends Xc{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},ru=class e extends jl{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Pu),e.writeKey(this.hookName)}},iu=e=>new ru(e.readKey()),au=class e extends Yl{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Fu)}},ou=e=>new au,su=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Yr()}mergeWith(e){return!1}write(e,t,n){throw Yr()}integrate(e,t){throw Yr()}},cu=0,lu=class extends su{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),_c(e.doc.store,this)}write(e,t){e.writeInfo(cu),e.writeLen(this.length-t)}getMissing(e,t){return null}},uu=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw Yr()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},du=e=>new uu(e.readBuf()),fu=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){ps(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},pu=e=>new fu(e.readLen()),mu=(e,t)=>new bs({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),hu=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(mu(this.doc.guid,this.opts))}splice(e){throw Yr()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},gu=e=>new hu(mu(e.readString(),e.readAny())),_u=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw Yr()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},vu=e=>new _u(e.readJSON()),yu=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw Yr()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},bu=e=>new yu(e.readKey(),e.readJSON()),xu=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}},Su=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new xu(n)},Cu=Xi(`node_env`)===`development`,wu=class e{constructor(e){this.arr=e,Cu&&zi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},Tu=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new wu(n)},Eu=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Du=e=>new Eu(e.readString()),Ou=[kl,Ml,Xl,tu,$l,iu,ou],ku=0,Au=1,ju=2,Mu=3,Nu=4,Pu=5,Fu=6,Iu=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw Yr()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Lu=e=>new Iu(Ou[e.readTypeRef()](e)),Ru=(e,t)=>{let n=t,r=0,i;do r>0&&(n=$(n.client,n.clock+r)),i=yc(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Uu);return{item:i,diff:r}},zu=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Bu=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Uu($(r,i+n),t,$(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=$(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Vu=(e,t)=>Xn(e,e=>us(e.deletions,t)),Hu=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return xc(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Hu(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=xc(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:xc(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:xc(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||us(r,d.right.id)||Vu(a.undoStack,d.right.id)||Vu(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=xc(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=$(c,gc(s,c)),h=new Uu(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,zu(h,!0),h.integrate(e,0),h},Uu=class e extends su{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=gc(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=gc(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zs&&this.id.client!==this.parent.client&&this.parent.clock>=gc(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Sc(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=xc(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===lu||this.right&&this.right.constructor===lu)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Zs){let e=yc(n,this.parent);this.parent=e.constructor===lu?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Sc(e,e.doc.store,$(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),Qs(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(Qs(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(yc(e.doc.store,n.origin)))r.has(yc(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),_c(e.doc.store,this),this.content.integrate(e,this),Dc(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new lu(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:$(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Qs(e.origin,this.lastId)&&this.right===e&&Qs(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),ps(e.deleteSet,this.id.client,this.id.clock,this.length),Dc(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Xr();this.content.gc(e),t?Cc(e,this,new lu(this.id,this.length)):this.content=new fu(this.length)}write(e,t){let n=t>0?$(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=$s(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Zs?(e.writeParentInfo(!1),e.writeLeftID(t)):Xr();i!==null&&e.writeString(i)}this.content.write(e,t)}},Wu=(e,t)=>Gu[t&31](e),Gu=[()=>{Xr()},pu,Su,du,Du,vu,bu,Lu,Tu,gu,()=>{Xr()}],Ku=10,qu=class extends su{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Xr()}write(e,t){e.writeInfo(Ku),Z(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Ju=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Yu=`__ $YJS$ __`;Ju[Yu]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ju[Yu]=!0;var Xu=`verbatim.verbatim*.Verbatim.BVerbatim.LVerbatim.SaveVerbatim.VerbatimOut.bverbatim.bverbatim*.lverbatim.lverbatim*.saveverbatim.saveverbatim*.verbatimout.verbatimwrite.lstlisting.lstlisting*.minted.minted*.tcblisting.tcblisting*.pygmented.alltt.filecontents.filecontents*.luacode.luacodestar.comment`.split(`.`),Zu=new Set(Xu);function Qu(e){return Zu.has(e)}function $u(e,t,n){if(e[t]!==`[`)return t;let r=1;for(let i=t+1;i<n;i+=1)if(e[i]===`\\`)i+=1;else if(e[i]===`[`&&(r+=1),e[i]===`]`&&(--r,r===0))return i+1;return null}function ed(e,t,n){if(e[t]!==`{`)return null;let r=1;for(let i=t+1;i<n;i+=1)if(e[i]===`\\`)i+=1;else if(e[i]===`{`&&(r+=1),e[i]===`}`&&(--r,r===0))return i+1;return null}function td(e,t,n=e.length){let r=e.indexOf(`
6
+ `,t);r>=0&&(n=Math.min(n,r));let i=/^\\(verb\*?|Verb\*?|lstinline\*?|mintinline\*?)(?![A-Za-z@])/.exec(e.slice(t,n));if(!i)return null;let a=i[1].replace(/\*$/,``),o=t+i[0].length;if(a!==`verb`){let t=$u(e,o,n);if(t===null)return null;o=t}if(a===`mintinline`){let t=ed(e,o,n);if(t===null)return null;o=t}let s=e[o];if(!s||/\s/.test(s))return null;if(s===`{`&&a!==`verb`){let t=ed(e,o,n);return{end:t??n,closed:t!==null}}let c=e.indexOf(s,o+1);return c<0||c>=n?{end:n,closed:!1}:{end:c+1,closed:!0}}function nd(e,t,n=e.length){return td(e,t,n)?.end??null}function rd(e,t,n){let r=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i=new RegExp(String.raw`\\end\s*\{\s*${r}\s*\}`,`g`);i.lastIndex=t;let a=i.exec(e);return a?{from:a.index,to:a.index+a[0].length}:null}function id(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function ad(e,t){let n=t+1;if(/[A-Za-z@]/.test(e[n]??``)){for(;/[A-Za-z@]/.test(e[n]??``);)n+=1;return e[n]===`*`&&(n+=1),n}return Math.min(e.length,n+1)}function od(e,t){let n=/^\\begin\s*\{\s*([A-Za-z0-9@:_*.\-]+)\s*\}/.exec(e.slice(t));return!n||!Qu(n[1])?null:{name:n[1],to:t+n[0].length}}function sd(e,t){let n=Math.max(0,Math.min(e.length,t));for(let t=0;t<n;){if(e[t]===`%`&&!id(e,t)){let r=e.indexOf(`
7
+ `,t),i=r<0?e.length:r;if(n<=i)return`comment`;t=i+1;continue}if(e[t]!==`\\`||id(e,t)){t+=1;continue}let r=td(e,t);if(r!==null){if(n<r.end||!r.closed&&n<=r.end)return`literal`;t=r.end;continue}let i=od(e,t);if(i){let r=rd(e,i.to,i.name),a=r?.to??e.length;if(n<a||!r&&n<=a)return`literal`;t=a}else t=ad(e,t)}return null}function cd(e,t,n){return e.slice(t,n).replace(/[^\r\n]/g,` `)}function ld(e){let t=e.split(``);for(let n=0;n<e.length;n+=1){if(e[n]!==`%`||id(e,n))continue;let r=e.indexOf(`
8
+ `,n),i=r<0?e.length:r;for(let e=n;e<i;e+=1)t[e]=` `;n=i}return t.join(``)}function ud(e){let t=``,n=0;for(;n<e.length;){if(e[n]===`%`&&!id(e,n)){let r=e.indexOf(`
9
+ `,n),i=r<0?e.length:r;t+=e.slice(n,i),n=i;continue}if(e[n]!==`\\`||id(e,n)){t+=e[n],n+=1;continue}let r=nd(e,n);if(r!==null){t+=cd(e,n,r),n=r;continue}let i=od(e,n);if(i){let r=rd(e,i.to,i.name)?.to??e.length;t+=cd(e,n,r),n=r}else t+=e[n],n+=1}return t}var dd=new Set(Xu);function fd(e){return/[A-Za-z@0-9:_-]/.test(e)}function pd(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function md(e,t){return e[t]===`%`&&!pd(e,t)}function hd(e,t){let n=e.indexOf(`
10
+ `,t);return n===-1?e.length:n}function gd(e,t){let n=t;for(;n<e.length;)if(/\s/.test(e[n]))n+=1;else if(md(e,n))n=hd(e,n);else break;return n}function _d(e,t,n,r){if(e[t]!==n)return null;let i=0,a=0;for(let o=t;o<e.length;o+=1){let s=e[o];if(s===`\\`&&o+1<e.length)o+=1;else if(md(e,o))o=hd(e,o)-1;else{if(n===`[`){if(s===`{`){a+=1;continue}if(s===`}`&&a>0){--a;continue}if(a>0)continue}if(s===n)i+=1;else if(s===r&&(--i,i===0))return{from:t,to:o+1,contentFrom:t+1,contentTo:o}}}return null}function vd(e,t,n){let r=[],i=t;for(;r.length<n;){for(i=gd(e,i);e[i]===`[`;){let t=_d(e,i,`[`,`]`);if(!t)return r;i=gd(e,t.to)}if(e[i]!==`{`)break;let t=_d(e,i,`{`,`}`);if(!t)break;r.push(t),i=t.to}return r}function yd(e,t,n){let r=[],i=t;for(;r.length<n&&(i=gd(e,i),e[i]===`[`);){let t=_d(e,i,`[`,`]`);if(!t)break;r.push(t),i=t.to}return r}function bd(e,t){if(e[t]!==`\\`||t+1>=e.length)return null;let n=t+1;if(!/[A-Za-z@]/.test(e[n]))return{name:e[n],from:t,to:n+1};for(;n<e.length&&fd(e[n]);)n+=1;let r=e.slice(t+1,n);return e[n]===`*`&&(n+=1),{name:r,from:t,to:n}}function xd(e,t){if(t.name!==`begin`)return t.to;let n=vd(e,t.to,1)[0];if(!n)return t.to;let r=e.slice(n.contentFrom,n.contentTo).trim();return dd.has(r)?rd(e,n.to,r)?.to??e.length:t.to}function Sd(e,t){let n=0;for(;n<e.length;){if(md(e,n)){n=hd(e,n);continue}if(e[n]!==`\\`){n+=1;continue}let r=bd(e,n);if(!r){n+=1;continue}let i=nd(e,r.from);if(i!==null&&i>r.to){n=i;continue}let a=xd(e,r);a>r.to?n=a:(t(r),n=r.to)}}function Cd(e,t,n){let r=[],i=t.contentFrom,a=t.contentFrom;for(;a<=t.contentTo;){if(a<t.contentTo&&md(e,a)){a=hd(e,a),e[a]===`
11
+ `&&(a+=1);continue}if(a!==t.contentTo&&(!n||e[a]!==`,`)){a+=1;continue}let o=wd(e,i,a);o&&r.push(o),i=a+1,a+=1}return r}function wd(e,t,n){let r=[],i=t;for(;i<n;)md(e,i)?(i=hd(e,i),e[i]===`
12
+ `&&(i+=1)):(r.push({character:e[i],index:i}),i+=1);let a=0,o=r.length;for(;a<o&&/\s/.test(r[a].character);)a+=1;for(;o>a&&/\s/.test(r[o-1].character);)--o;return a===o?null:{path:r.slice(a,o).map(e=>e.character).join(``),command:``,from:r[a].index,to:r[o-1].index+1}}function Td(e,t){let n=gd(e,t);if(n>=e.length||/[\\{}\[\]#~]/.test(e[n]))return null;let r=n;for(;r<e.length&&!/\s/.test(e[r])&&!md(e,r)&&!/[\\{}\[\]#~]/.test(e[r]);)r+=1;return r===n?null:{path:e.slice(n,r),command:``,from:n,to:r}}function Ed(e){let t=[];return Sd(e,n=>{let r=n.name.toLowerCase();if(r===`input`||r===`include`||r===`subfile`){let i=vd(e,n.to,1)[0];if(i)for(let r of Cd(e,i,!1))t.push({...r,command:n.name});else if(r===`input`){let r=Td(e,n.to);r&&t.push({...r,command:n.name})}return}if(r!==`import`&&r!==`subimport`&&r!==`includefrom`&&r!==`inputfrom`&&r!==`subinputfrom`&&r!==`subincludefrom`)return;let i=vd(e,n.to,2);if(i.length!==2)return;let a=Cd(e,i[0],!1)[0]?.path??``,o=Cd(e,i[1],!1)[0];if(!o)return;let s=a&&!a.endsWith(`/`)?`/`:``;t.push({path:a+s+o.path,command:n.name,from:o.from,to:o.to,directory:a})}),t}var Dd=(e,t)=>e>>>t|e<<32-t,Od=e=>Dd(e,2)^Dd(e,13)^Dd(e,22),kd=e=>Dd(e,6)^Dd(e,11)^Dd(e,25),Ad=e=>Dd(e,7)^Dd(e,18)^e>>>3,jd=e=>Dd(e,17)^Dd(e,19)^e>>>10,Md=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Nd=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Pd=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Nd),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=jd(t[e-2])+t[e-7]+Ad(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+kd(o)+(o&s^~o&c)+Md[e]+t[e]>>>0,d=Od(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<(3-t%4)*8,t++;this._W[n]|=128<<(3-t%4)*8}this._updateHash()}let n=t%64!=0;this._W.fill(0,0,16);let r=0;for(;t<e.length;r++)for(let n=3;n>=0&&t<e.length;n--)this._W[r]|=e[t++]<<n*8;n||(this._W[r-(t%4==0?0:1)]|=128<<(3-t%4)*8),this._W[14]=e.byteLength/sr,this._W[15]=e.byteLength*8,this._updateHash();let i=new Uint8Array(32);for(let e=0;e<this._H.length;e++)for(let t=0;t<4;t++)i[e*4+t]=this._H[e]>>>(3-t)*8;return i}},Fd=e=>new Pd().digest(e);function Id(e){return Array.from(Fd(new TextEncoder().encode(e)),e=>e.toString(16).padStart(2,`0`)).join(``)}function Ld(e){for(let t=0;t<e.length;t+=1)e[t]=Math.floor(Math.random()*256);return e}function Rd(e){e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function zd(e=globalThis.crypto){if(typeof e?.randomUUID==`function`)return e.randomUUID();let t=new Uint8Array(16);return Rd(typeof e?.getRandomValues==`function`?e.getRandomValues(t):Ld(t))}function Bd(e){return/\.(?:tex|sty|cls|ltx|dtx|ins|txt|md|markdown|rst)$/i.test(e.trim())}function Vd(e){return/\.(?:tex|sty|cls)$/i.test(e.trim())}function Hd(e){return(typeof e==`number`||typeof e==`string`)&&e!==``}function Ud(e){let t=(0,Y.useId)();return Hd(e)?`${e}`:t}var Wd=typeof window<`u`?Y.useLayoutEffect:Y.useEffect;function Gd(e){let t=(0,Y.useRef)(e);return Wd(()=>{t.current=e},[e]),(0,Y.useCallback)((...e)=>t.current?.(...e),[t])}function Kd(...e){return Gd(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t}})})}function qd(e,t){let n=e?.[`data-testid`];return Hd(n)?`${n}`:Hd(t)?`${t}`:void 0}function Jd(e,t=`Assertion error`){if(!e)throw Error(t)}(0,Y.createContext)(null);var Yd;function Xd(){return Yd===void 0&&(Yd=typeof matchMedia==`function`&&!!matchMedia(`(pointer:coarse)`).matches),Yd}function Zd({expandHitTargets:e,axis:t,rect:n}){let r=e?Xd()?t.resizeTargetMinimumSize.coarse:t.resizeTargetMinimumSize.fine:0;if(n.width<r){let e=r-n.width;n=new DOMRect(n.x-e/2,n.y,n.width+e,n.height)}if(n.height<r){let e=r-n.height;n=new DOMRect(n.x,n.y-e/2,n.width,n.height+e)}return n}function Qd(e){switch(typeof e){case`number`:return[e,`px`];case`string`:{let t=parseFloat(e);return e.endsWith(`%`)?[t,`%`]:e.endsWith(`px`)?[t,`px`]:e.endsWith(`rem`)?[t,`rem`]:e.endsWith(`em`)?[t,`em`]:e.endsWith(`vh`)?[t,`vh`]:e.endsWith(`vw`)?[t,`vw`]:[t,`%`]}}}var $d=class{#e={};addListener(e,t){let n=this.#e[e];return n===void 0?this.#e[e]=[t]:n.includes(t)||n.push(t),()=>{this.removeListener(e,t)}}emit(e,t){let n=this.#e[e];if(n!==void 0){if(n.length===1){n[0].call(null,t);return}let e,r=Array.from(n);for(let n=0;n<r.length;n++){let i=r[n];try{i.call(null,t)}catch(t){e??={error:t}}}if(e)throw e.error}}removeAllListeners(){this.#e={}}removeListener(e,t){let n=this.#e[e];if(n!==void 0){let e=n.indexOf(t);e>=0&&n.splice(e,1)}}},ef={cursorFlags:0,state:`inactive`},tf=new $d;function nf(){return ef}function rf(e){return tf.addListener(`change`,e)}function af(e,t=[],n,r=!1){let i=ef,a={...ef};a.cursorFlags=e,a.state===`active`&&(a.didPointerMove||=r,a.previews=t,n&&(a.previewLayoutMap=n)),ef=a,tf.emit(`change`,{prev:i,next:a})}function of(e){let t=ef;ef=e,t.state===`active`&&e.state!==`active`&&t.didPointerMove&&t.hitRegions.forEach(({separator:e})=>{e&&e.element.ownerDocument.activeElement===e.element&&e.element.blur()}),tf.emit(`change`,{prev:t,next:e})}function sf(e){ef.state!==`active`||!ef.previews.some(t=>t.separator===e)||of({...ef,previews:ef.previews.map(t=>t.separator===e?{...t}:t)})}function cf(e){if(ef.state===`inactive`)return;let t=ef.hitRegions.filter(t=>t.axis!==e),n=ef.state===`active`&&ef.previews.some(t=>t.axis===e);if(t.length!==ef.hitRegions.length||n){if(t.length===0)of({cursorFlags:0,state:`inactive`});else if(ef.state===`active`){let n=new Map(ef.initialLayoutMap),r=new Map(ef.previewLayoutMap);n.delete(e),r.delete(e),of({...ef,cursorFlags:0,hitRegions:t,initialLayoutMap:n,previewLayoutMap:r,previews:ef.previews.filter(t=>t.axis!==e)})}else of({...ef,hitRegions:t})}}var lf=e=>e,uf=()=>{},df=1,ff=2,pf=4,mf=8,hf=3,gf=12,_f;function vf(){return _f===void 0&&(_f=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(_f=!0)),_f}function yf({cursorFlags:e,axes:t,state:n}){let r=0,i=0;switch(n){case`active`:case`hover`:t.forEach(e=>{if(!e.mutableState.disableCursor)switch(e.orientation){case`horizontal`:r++;break;case`vertical`:i++}})}if(r!==0||i!==0){if(n===`active`&&e&&vf()){let t=(e&df)!==0,n=(e&ff)!==0,r=(e&pf)!==0,i=(e&mf)!==0;if(t)return r?`se-resize`:i?`ne-resize`:`e-resize`;if(n)return r?`sw-resize`:i?`nw-resize`:`w-resize`;if(r)return`s-resize`;if(i)return`n-resize`}return vf()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var bf=new WeakMap;function xf(e){if(!e.defaultView||!e.adoptedStyleSheets)return;let{prevStyle:t,styleSheet:n}=bf.get(e)??{};n===void 0&&(n=new e.defaultView.CSSStyleSheet,e.adoptedStyleSheets&&(Object.isExtensible(e.adoptedStyleSheets)?e.adoptedStyleSheets.push(n):e.adoptedStyleSheets=[...e.adoptedStyleSheets,n]));let r=nf();switch(r.state!==`inactive`&&r.ownerDocument!==e&&(r={cursorFlags:0,state:`inactive`}),r.state){case`active`:case`hover`:{let e=yf({cursorFlags:r.cursorFlags,axes:r.hitRegions.map(e=>e.axis),state:r.state}),i=`*, *:hover {cursor: ${e} !important; }`;if(t===i)return;t=i,e?n.cssRules.length===0?n.insertRule(i):n.replaceSync(i):n.cssRules.length===1&&n.deleteRule(0);break}case`inactive`:t=void 0,n.cssRules.length===1&&n.deleteRule(0)}bf.set(e,{prevStyle:t,styleSheet:n})}function Sf(e){return e.state===`inactive`?void 0:e.ownerDocument}function Cf({next:e,prev:t}){let n=Sf(t),r=Sf(e);n&&n!==r&&xf(n),r&&xf(r)}function wf({axis:e}){let{layoutStrategy:t,orientation:n,items:r}=e;return t?t.calculateAvailableSize():r.reduce((e,t)=>(e+=n===`horizontal`?t.element.offsetWidth:t.element.offsetHeight,e),0)}function Tf(e,t){let n=e.compareDocumentPosition(t);return n&Node.DOCUMENT_POSITION_DISCONNECTED?0:n&Node.DOCUMENT_POSITION_FOLLOWING?-1:n&Node.DOCUMENT_POSITION_PRECEDING?1:0}function Ef(e,t){return Array.from(t).sort((t,n)=>{let r=e===`horizontal`?Df(t,n):Of(t,n);return r===0?Tf(t.element,n.element):r})}function Df(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function Of(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function kf(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function Af(e,t){return{x:e.x>=t.left&&e.x<=t.right?0:Math.min(Math.abs(e.x-t.left),Math.abs(e.x-t.right)),y:e.y>=t.top&&e.y<=t.bottom?0:Math.min(Math.abs(e.y-t.top),Math.abs(e.y-t.bottom))}}function jf({orientation:e,rects:t,targetRect:n}){let r={x:n.x+n.width/2,y:n.y+n.height/2},i,a=Number.MAX_VALUE;for(let n of t){let{x:t,y:o}=Af(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return Jd(i,`No rect found`),i}function Mf({expandHitTargets:e=!0,axis:t,includeDisabled:n=!1}){if(t.layoutStrategy)return t.layoutStrategy.calculateHitRegions({expandHitTargets:e,axis:t,includeDisabled:n});let{element:r,orientation:i,items:a,separators:o}=t,s=Ef(i,Array.from(r.children).filter(kf).filter(e=>!e.hasAttribute(`data-resize-preview`)).map(e=>({element:e}))).map(({element:e})=>e),c=[],l=!1,u=!1,d=-1,f,p=-1,m=0,h,g=[];{let e=-1;for(let t of s)t.hasAttribute(`data-panel`)&&(e++,t.hasAttribute(`data-disabled`)||(m++,d===-1&&(d=e),p=e))}if(n||m>1){let r=-1;for(let m of s)if(m.hasAttribute(`data-panel`)){r++;let o=a.find(e=>e.element===m);if(o){if(h){let a=h.element.getBoundingClientRect(),s=m.getBoundingClientRect(),_;if(u){let e=i===`horizontal`?new DOMRect(a.right,a.top,0,a.height):new DOMRect(a.left,a.bottom,a.width,0),t=i===`horizontal`?new DOMRect(s.left,s.top,0,s.height):new DOMRect(s.left,s.top,s.width,0);switch(g.length){case 0:_=[e,t];break;case 1:{let n=g[0];_=[n,jf({orientation:i,rects:[a,s],targetRect:n.element.getBoundingClientRect()})===a?t:e];break}default:_=g}}else _=g.length?g:[i===`horizontal`?new DOMRect(a.right,s.top,s.left-a.right,s.height):new DOMRect(s.left,a.bottom,s.width,s.top-a.bottom)];for(let i of _){let a=Zd({expandHitTargets:e,axis:t,rect:`width`in i?i:i.element.getBoundingClientRect()});(n||!l&&!(r<=d||r>p))&&(f??=wf({axis:t}),c.push({axis:t,axisSize:f,items:[h,o],separator:`width`in i?void 0:i,rect:a})),l=!1}}u=!1,h=o,g=[]}}else if(m.hasAttribute(`data-separator`)){m.ariaDisabled!==null&&(l=!0);let e=o.find(e=>e.element===m);e?g.push(e):(h=void 0,g=[])}else u=!0}return c}function Nf(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function Pf(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function Ff(e){return e/100*window.innerHeight}function If(e){return e/100*window.innerWidth}function Lf({axisSize:e,itemElement:t,styleProp:n}){let r,[i,a]=Qd(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=Pf(t,i);break;case`em`:r=Nf(t,i);break;case`vh`:r=Ff(i);break;case`vw`:r=If(i)}return r}function Rf(e){return parseFloat(e.toFixed(3))}function zf(e,t=wf({axis:e})){let{items:n}=e;return t===0?n.map(e=>({groupResizeBehavior:e.constraintProps.groupResizeBehavior,collapsedSize:0,collapsible:e.constraintProps.collapsible===!0,defaultSize:void 0,disabled:e.constraintProps.disabled,minSize:0,maxSize:100,itemId:e.id})):n.map(e=>{let{element:n,constraintProps:r}=e,i=0;r.collapsedSize!==void 0&&(i=Rf(Lf({axisSize:t,itemElement:n,styleProp:r.collapsedSize})/t*100));let a;r.collapsedThreshold!==void 0&&(a=Rf(Lf({axisSize:t,itemElement:n,styleProp:r.collapsedThreshold})/t*100));let o;r.defaultSize!==void 0&&(o=Rf(Lf({axisSize:t,itemElement:n,styleProp:r.defaultSize})/t*100));let s=0;r.minSize!==void 0&&(s=Rf(Lf({axisSize:t,itemElement:n,styleProp:r.minSize})/t*100));let c=100;return r.maxSize!==void 0&&(c=Rf(Lf({axisSize:t,itemElement:n,styleProp:r.maxSize})/t*100)),{groupResizeBehavior:r.groupResizeBehavior,collapsedSize:i,collapsedThreshold:a,collapsible:r.collapsible===!0,defaultSize:o,disabled:r.disabled,minSize:s,maxSize:c,itemId:e.id}})}var Bf=new Map,Vf=new $d,Hf=0,Uf=[],Wf;function Gf(){Hf++}function Kf(){for(let e=0;e<Uf.length;e++)try{Vf.emit(`axisChange`,Uf[e])}catch(e){Wf??={error:e}}Uf.length=0}function qf(){if(Hf===1&&Kf(),Hf--,Hf===0&&Wf){let{error:e}=Wf;throw Wf=void 0,e}}function Jf(e){Bf=new Map(Bf),Bf.delete(e)}function Yf(e,t){for(let[t]of Bf)if(t.id===e)return t}function Xf(e,t){for(let[t,n]of Bf)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function Zf(){return Bf}function Qf(e,t){return Vf.addListener(`axisChange`,n=>{n.axis.id===e&&t(n)})}function $f(e,t,n){let r=Bf.get(e);Bf=new Map(Bf),Bf.set(e,t);let i={axis:e,isUserInteraction:n?.isUserInteraction===!0,prev:r,next:t};Hf>0?Uf.push(i):Vf.emit(`axisChange`,i)}function ep(e,{pointerId:t,pointerType:n}){return t===e.pointerId||n===`pen`&&e.pointerType===`pen`}function tp(e,t,n={}){return e.ownerDocument===t&&(n.pointerId===void 0||ep(e,n))}function np(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function rp(e,t,n=0){return Math.abs(Rf(e)-Rf(t))<=n}function ip(e,t){return rp(e,t)?0:e>t?1:-1}function ap({overrideDisabledItems:e,itemConstraints:t,prevSize:n,size:r}){let{collapsedSize:i=0,collapsedThreshold:a,collapsible:o,disabled:s,maxSize:c=100,minSize:l=0}=t;if(s&&!e)return n;if(ip(r,l)<0){if(o){let e=a??(l-i)/2,t=ip(n,i)<=0,o=t?i+e:l-e,s=ip(r,o);r=ip(r,i)<=0||s<0||a!==void 0&&t&&s===0?i:l}else r=l}return r=Math.min(c,r),r=Rf(r),r}function op({delta:e,initialLayout:t,itemConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(rp(e,0))return t;let o=a===`imperative-api`,s=n.map(({itemId:e})=>t[e]),c=n.map(({itemId:e})=>i[e]),l=[...s],[u,d]=r;Jd(u!=null,`Invalid first pivot index`),Jd(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];Jd(r,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(Jd(n!=null,`Previous layout not found for panel index ${t}`),rp(n,i)){let t=o-n;ip(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];Jd(r,`No panel constraints found for index ${t}`);let{collapsedSize:i=0,collapsible:a,minSize:o=0}=r;if(a){let n=s[t];if(Jd(n!=null,`Previous layout not found for panel index ${t}`),rp(n,o)){let t=n-i;ip(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];Jd(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsedSize:a,collapsedThreshold:o,collapsible:c,minSize:l}=r;if(c&&ip(i,l)<0){let t=l-a,n=o??t/2;if(ip(i+Math.abs(e),l)<0){let r=ip(Math.abs(e),n);e=r>0||r===0&&o===void 0&&e<0?e<0?-t:t:0}}break}}{let t=e<0?1:-1,r=e<0?d:u,i=0;for(;;){let e=s[r];Jd(e!=null,`Previous layout not found for panel index ${r}`);let a=ap({overrideDisabledItems:o,itemConstraints:n[r],prevSize:e,size:100})-e;if(i+=a,r+=t,r<0||r>=n.length)break}let a=Math.min(Math.abs(e),Math.abs(i));e=e<0?0-a:a}{let t=e<0?u:d;for(;t>=0&&t<n.length;){let r=Math.abs(e)-Math.abs(f),i=s[t];Jd(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=ap({overrideDisabledItems:o,itemConstraints:n[t],prevSize:i,size:a});if(!rp(i,c)&&(f+=i-c,l[t]=c,f.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?t--:t++}}if(np(c,l))return i;{let t=e<0?d:u,r=s[t];Jd(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=ap({overrideDisabledItems:o,itemConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!rp(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];Jd(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=ap({overrideDisabledItems:o,itemConstraints:n[r],prevSize:i,size:a});if(rp(i,s)||(t-=s-i,l[r]=s),rp(t,0))break;e>0?r--:r++}}}return rp(Object.values(l).reduce((e,t)=>t+e,0),100,.1)?l.reduce((e,t,r)=>(e[n[r].itemId]=t,e),{}):i}function sp(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||ip(e[n],t[n])!==0)return!1;return!0}function cp(e){Gf();try{lp(e)}finally{qf()}}function lp({commit:e,event:t,hitRegions:n,initialLayoutMap:r,mountedAxes:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0,c=nf(),l=c.state===`active`?c.previews:[],u=new Map(c.state===`active`?c.previewLayoutMap:void 0);n.forEach(n=>{let{axis:o,axisSize:c}=n,{orientation:d,items:f}=o;if(e&&o.resizePreviewMode!==`separator`)return;let{disableCursor:p}=o.mutableState,m=0;m=a?d===`horizontal`?(t.clientX-a.x)/c*100:(t.clientY-a.y)/c*100:d===`horizontal`?t.clientX<0?-100:100:t.clientY<0?-100:100;let h=r.get(o),g=i.get(o);if(!h||!g)return;let{defaultLayoutDeferred:_,derivedItemConstraints:v,axisSize:y,layout:b,separatorToItems:x}=g;if(v&&b&&x){let t=o.resizePreviewMode===`separator`?u.get(o)??b:b,r=op({delta:m,initialLayout:h,itemConstraints:v,pivotIndices:n.items.map(e=>f.indexOf(e)),prevLayout:t,trigger:`mouse-or-touch`});if(o.resizePreviewMode===`separator`&&!e&&!sp(r,t)){u.set(o,r);let e=0,t=f.map(t=>(e+=r[t.id]-h[t.id],c/100*e));l=l.map(e=>{if(e.axis!==o)return e;let n=t[e.itemIndex];return n===e.offset?e:{...e,offset:n}})}if(sp(r,t)&&m!==0&&!p)switch(d){case`horizontal`:s|=m<0?df:ff;break;case`vertical`:s|=m<0?pf:mf}(o.resizePreviewMode!==`separator`||e)&&!sp(r,b)&&$f(n.axis,{defaultLayoutDeferred:_,derivedItemConstraints:v,axisSize:y,layout:r,requestedAxisSize:y,requestedLayout:r,separatorToItems:x})}});let d=0;t.movementX===0?d|=o&hf:d|=s&hf,t.movementY===0?d|=o&gf:d|=s&gf;let f=c.state===`active`&&(t.clientX!==c.pointerDownAtPoint.x||t.clientY!==c.pointerDownAtPoint.y);af(d,l,u,f)}function up(e,t){let n=nf();if(n.state!==`active`||!tp(n,e,t))return;let r=Zf();Gf();try{cp({commit:!0,event:t,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags}),Kf(),of({cursorFlags:0,state:`inactive`}),n.hitRegions.length>0&&(t.preventDefault?.(),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=Xf(e.axis.id,!0);$f(e.axis,t,{isUserInteraction:!0})}))}finally{qf()}}function dp(e){if(e.defaultPrevented)return;let{clientX:t,clientY:n,movementX:r,movementY:i}=e;up(e.currentTarget,{clientX:t,clientY:n,movementX:r,movementY:i})}function fp(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=Af(n,a.rect);switch(e){case`horizontal`:(t.x<i.x||t.x===i.x&&t.y<=i.y)&&(r=a,i=t);break;case`vertical`:(t.y<i.y||t.y===i.y&&t.x<=i.x)&&(r=a,i=t)}}return r?{distance:i,hitRegion:r}:void 0}function pp(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function mp(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:bp(e),b:bp(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();Jd(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:yp(vp(n.a)),b:yp(vp(n.b))};if(i.a===i.b){let e=r.childNodes,t={a:n.a.at(-1),b:n.b.at(-1)},i=e.length;for(;i--;){let n=e[i];if(n===t.a)return 1;if(n===t.b)return-1}}return Math.sign(i.a-i.b)}var hp=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function gp(e){let t=getComputedStyle(xp(e)??e).display;return t===`flex`||t===`inline-flex`}function _p(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||gp(e))||+t.opacity<1||`transform`in t&&t.transform!==`none`||`webkitTransform`in t&&t.webkitTransform!==`none`||`mixBlendMode`in t&&t.mixBlendMode!==`normal`||`filter`in t&&t.filter!==`none`||`webkitFilter`in t&&t.webkitFilter!==`none`||`isolation`in t&&t.isolation===`isolate`||hp.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function vp(e){let t=e.length;for(;t--;){let n=e[t];if(Jd(n,`Missing node`),_p(n))return n}return null}function yp(e){return e&&Number(getComputedStyle(e).zIndex)||0}function bp(e){let t=[];for(;e;)t.push(e),e=xp(e);return t}function xp(e){let{parentNode:t}=e;return pp(t)?t.host:t}function Sp(e,t){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function Cp(e){try{return e.matches(`:modal`)}catch{return!1}}function wp({axisElement:e,hitRegion:t,pointerEventTarget:n}){if(kf(n)){let t=n.closest(`dialog`);if(t&&!t.contains(e)&&Cp(t))return!1}if(!kf(n)||n.contains(e)||e.contains(n)||!n.isConnected||!e.isConnected)return!0;if(mp(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Sp(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function Tp(e,t,n){let r=[];return t.forEach((t,i)=>{if(i.disabled||i.element.ownerDocument!==n)return;let a=Mf({axis:i}),o=fp(i.orientation,a,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&wp({axisElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&r.push(o.hitRegion)}),r}function Ep(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=Rf(i.defaultSize);n+=e,r[i.itemId]=e}else r[i.itemId]=void 0;let i=e.length-t;if(i!==0){let t=Rf((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.itemId]=t)}return r}function Dp(e,t){let n=e.map(e=>e.id),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e of n)if(!r.includes(e))return!1;return!0}function Op({axis:e,itemConstraints:t}){let n=e.items.map(({id:e})=>e).join(`,`),r=e.mutableState.defaultLayout;return e.mutableState.layouts[n]??(r&&Dp(e.items,r)?r:Ep(t))}function kp(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Ap(e,t){return e.length===t.length&&e.every((e,n)=>kp(e,t[n]))}function jp({layout:e,itemConstraints:t}){let n=t.map(({itemId:t})=>e[t]),r=[...n],i=r.reduce((e,t)=>e+t,0);if(Object.keys(e).length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${Object.values(e).map(e=>`${e}%`).join(`, `)}`);if(!rp(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];Jd(t!=null,`No layout data found for index ${e}`);let n=100/i*t;r[e]=n}let a=0;for(let e=0;e<t.length;e++){let i=n[e];Jd(i!=null,`No layout data found for index ${e}`);let o=r[e];Jd(o!=null,`No layout data found for index ${e}`);let s=ap({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!rp(a,0))for(let e=0;e<t.length;e++){let n=r[e];Jd(n!=null,`No layout data found for index ${e}`);let i=n+a,o=ap({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,rp(a,0)))break}return r.reduce((e,n,r)=>(e[t[r].itemId]=n,e),{})}function Mp({itemIds:e,layout:t}){return jp({layout:t,itemConstraints:e.map(e=>({collapsedSize:0,collapsible:!1,defaultSize:void 0,disabled:void 0,itemId:e,maxSize:100,minSize:0}))})}function Np({axis:e,nextAxisSize:t,prevAxisSize:n,prevLayout:r}){if(n<=0||t<=0||n===t)return r;let i=0,a=0,o=!1,s=new Map,c=[];for(let l of e.items){let e=r[l.id]??0;switch(l.constraintProps.groupResizeBehavior){case`preserve-pixel-size`:{o=!0;let r=Rf(e/100*n/t*100);s.set(l.id,r),i+=r;break}default:c.push(l.id),a+=e}}if(!o||c.length===0)return r;let l=100-i,u={...r};if(s.forEach((e,t)=>{u[t]=e}),a>0)for(let e of c)u[e]=Rf((r[e]??0)/a*l);else{let e=Rf(l/c.length);for(let t of c)u[t]=e}return u}function Pp({axis:e,axisState:t}){let n=wf({axis:e});if(n===0)return;let r=zf(e,n),i=t.requestedAxisSize,a=t.requestedLayout;t.defaultLayoutDeferred&&(i=n,a=Mp({itemIds:e.items.map(({id:e})=>e),layout:Op({axis:e,itemConstraints:r})}));let o=jp({layout:Np({axis:e,nextAxisSize:n,prevAxisSize:i,prevLayout:a}),itemConstraints:r});return{changed:t.defaultLayoutDeferred||!sp(t.layout,o)||!Ap(t.derivedItemConstraints,r)||t.axisSize!==n,state:{defaultLayoutDeferred:!1,derivedItemConstraints:r,axisSize:n,layout:o,requestedAxisSize:i,requestedLayout:a,separatorToItems:t.separatorToItems}}}function Fp({axisId:e,itemId:t}){let n=()=>{let t=Zf();for(let[n,r]of t)if(n.id===e)return{axis:n,...r};throw Error(`Group ${e} not found`)},r=()=>{let e=n().derivedItemConstraints.find(e=>e.itemId===t);if(e!==void 0)return e;throw Error(`Panel constraints not found for Panel ${t}`)},i=()=>{let{axis:e,...r}=n(),i=Pp({axis:e,axisState:r}),a=i?.state??r,o=a.derivedItemConstraints.find(e=>e.itemId===t);if(o===void 0)throw Error(`Panel constraints not found for Panel ${t}`);let s=a.layout[t];if(s===void 0)throw Error(`Layout not found for Panel ${t}`);return{axis:e,changed:i?.changed===!0,itemConstraints:o,itemSize:s,state:a}},a=()=>{let e=n().axis.items.find(e=>e.id===t);if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},o=()=>{let e=n().layout[t];if(e!==void 0)return e;throw Error(`Layout not found for Panel ${t}`)},s=({nextSize:e,items:n,prevLayout:r,derivedItemConstraints:i})=>{let a=r[t],o=n.findIndex(e=>e.id===t),s=o===0,c=o===n.length-1;if(c&&e<a&&(s||n.slice(0,o).every((e,t)=>{let n=i[t];return n?.collapsible&&rp(n.collapsedSize,r[n.itemId])}))){let e=n.slice(0,o).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:Rf(100-e)}}return op({delta:c?a-e:e-a,initialLayout:r,itemConstraints:i,pivotIndices:c?[o-1,o]:[o,o+1],prevLayout:r,trigger:`imperative-api`})},c=(e,{axis:t,changed:n,itemSize:r,state:i})=>{if(e===r)return;let{derivedItemConstraints:a,axisSize:o,layout:c}=i,l=jp({layout:s({nextSize:e,items:t.items,prevLayout:c,derivedItemConstraints:a}),itemConstraints:a});(n||!sp(c,l))&&$f(t,{...i,layout:l,requestedAxisSize:o,requestedLayout:l})};return{collapse:()=>{let e=i(),{collapsible:t,collapsedSize:n}=e.itemConstraints,{mutableValues:r}=a(),o=e.itemSize;t&&o!==n&&(r.expandToSize=o,c(n,e))},expand:()=>{let e=i(),{collapsible:t,collapsedSize:n,minSize:r}=e.itemConstraints,{mutableValues:o}=a(),s=e.itemSize;if(t&&s===n){let t=o.expandToSize??r;t===0&&(t=1),c(t,e)}},getSize:()=>{let{axis:e}=n(),r=o(),{element:i}=a();return{asPercentage:r,inPixels:e.layoutStrategy?e.layoutStrategy.getItemSizeInPixels(t):e.orientation===`horizontal`?i.offsetWidth:i.offsetHeight}},isCollapsed:()=>{let{collapsible:e,collapsedSize:t}=r(),n=o();return e&&rp(t,n)},resize:e=>{let t=i(),{axisSize:n}=t.state,{element:r}=a(),o=Rf(Lf({axisSize:n,itemElement:r,styleProp:e})/n*100);c(o,t)}}}function Ip(e){e.defaultPrevented||Tp(e,Zf(),e.currentTarget).forEach(t=>{if(t.separator&&!t.separator.disableDoubleClick){let n=t.items.find(e=>e.constraintProps.defaultSize!==void 0);if(n){let r=n.constraintProps.defaultSize,i=Fp({axisId:t.axis.id,itemId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function Lp(e){let t=Zf();for(let[n]of t)if(n.separators.some(t=>t.element===e))return n;throw Error(`Could not find parent Group for separator element`)}function Rp({axisId:e}){let t=()=>{let t=Zf();for(let[n,r]of t)if(n.id===e)return{axis:n,...r};throw Error(`Could not find Group with id "${e}"`)};return{getLayout(){let{defaultLayoutDeferred:e,layout:n}=t();return e?{}:n},setLayout(e){let{axis:n,...r}=t(),i=Pp({axis:n,axisState:r}),a=i?.state??r,{defaultLayoutDeferred:o,derivedItemConstraints:s,axisSize:c,layout:l}=a,u=jp({layout:e,itemConstraints:s});return o?l:((i?.changed||!sp(l,u))&&$f(n,{...a,layout:u,requestedAxisSize:c,requestedLayout:u}),u)}}}function zp(e,t){let n=Lp(e),r=Xf(n.id,!0),i=n.separators.find(t=>t.element===e);Jd(i,`Matching separator not found`);let a=r.separatorToItems.get(i);Jd(a,`Matching panels not found`);let o=a.map(e=>n.items.indexOf(e)),s=Rp({axisId:n.id}).getLayout(),c=jp({layout:op({delta:t,initialLayout:s,itemConstraints:r.derivedItemConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),itemConstraints:r.derivedItemConstraints});sp(s,c)||$f(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedItemConstraints:r.derivedItemConstraints,axisSize:r.axisSize,layout:c,requestedAxisSize:r.axisSize,requestedLayout:c,separatorToItems:r.separatorToItems},{isUserInteraction:!0})}function Bp(e){return e.separators.filter(e=>!e.disabled)}function Vp(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=Lp(t);if(!(n.disabled||n.separators.find(e=>e.element===t)?.disabled))switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&zp(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&zp(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&zp(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&zp(t,-5);break;case`End`:e.preventDefault(),zp(t,100);break;case`Enter`:{e.preventDefault();let{derivedItemConstraints:r,layout:i,separatorToItems:a}=Xf(n.id,!0),o=n.separators.find(e=>e.element===t);Jd(o,`Matching separator not found`);let s=a.get(o);Jd(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.itemId===c.id);if(Jd(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];zp(t,(l.collapsedSize===e?n.mutableState.expandedItemSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let t=Bp(n).map(e=>e.element),r=t.findIndex(t=>t===e.currentTarget);Jd(r!==-1,`Index not found`),t[e.shiftKey?r>0?r-1:t.length-1:r+1<t.length?r+1:0].focus({preventScroll:!0});break}case`Home`:e.preventDefault(),zp(t,-100)}}function Hp(e,t){let n=nf();if(n.state!==`active`||!tp(n,e,t))return!1;let r=Zf();Gf();try{n.previewLayoutMap.forEach((e,t)=>{let n=r.get(t);t.resizePreviewMode===`separator`&&n&&!sp(e,n.layout)&&$f(t,{...n,layout:e,requestedAxisSize:n.axisSize,requestedLayout:e})}),Kf(),of({cursorFlags:0,state:`inactive`}),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=Xf(e.axis.id,!0);$f(e.axis,t,{isUserInteraction:!0})})}finally{qf()}return!0}function Up(e){let t=nf();if(t.state!==`active`)return;let n=t.hitRegions.flatMap(({separator:e})=>e?[e.element]:[]);!n.some(t=>t===e.target)||n.some(t=>t.hasPointerCapture?.(e.pointerId))||Hp(e.currentTarget,e)}function Wp(e){Hp(e.currentTarget,e)}function Gp(e,t){let{element:n,orientation:r,items:i}=e,a=n.getBoundingClientRect(),o=r===`horizontal`;return Mf({expandHitTargets:!1,axis:e,includeDisabled:!0}).map(({items:r,rect:s,separator:c},l)=>{let u=i.indexOf(r[0]),d=o?s.left+s.width/2:s.top+s.height/2;return{active:t.some(t=>{if(t.axis!==e||t.items[0]!==r[0])return!1;if(c||t.separator)return t.separator===c;let n=o?t.rect.left+t.rect.width/2:t.rect.top+t.rect.height/2;return rp(d,n)}),axis:e,key:c?`separator-${c.id}`:`panel-${r[0].id}-${l}`,offset:0,itemIndex:u,rect:new DOMRect((o&&!c?d:s.left)-a.left-n.clientLeft+n.scrollLeft,(!o&&!c?d:s.top)-a.top-n.clientTop+n.scrollTop,o&&!c?0:s.width,!o&&!c?0:s.height),separator:c}})}function Kp(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=nf();if(t.state===`active`){ep(t,e)&&Hp(t.ownerDocument,t);return}let n=Zf(),r=Tp(e,n,e.currentTarget);if(r.length===0)return;let i=new Map,a=!1;r.forEach(e=>{e.separator&&(a||(a=!0,e.separator.element.focus({focusVisible:!1,preventScroll:!0})));let t=n.get(e.axis);t&&i.set(e.axis,t.layout)});let o=Array.from(i.keys()).flatMap(e=>e.resizePreviewMode===`separator`?Gp(e,r):[]);of({cursorFlags:0,didPointerMove:!1,hitRegions:r,initialLayoutMap:i,ownerDocument:e.currentTarget,pointerDownAtPoint:{x:e.clientX,y:e.clientY},pointerId:e.pointerId,pointerType:e.pointerType,previewLayoutMap:new Map(i),previews:o,state:`active`}),e.preventDefault()}function qp(e){let t=e.currentTarget,n=Zf(),r=nf();if(r.state===`active`){if(!tp(r,t,e))return;cp({commit:!1,event:e,hitRegions:r.hitRegions,initialLayoutMap:r.initialLayoutMap,mountedAxes:n,prevCursorFlags:r.cursorFlags})}}function Jp(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=nf(),r=Zf();switch(n.state){case`active`:if(!tp(n,t,e))return;if(e.buttons===0){Hp(t,e);return}for(let t of n.hitRegions)if(t.separator){let{element:n}=t.separator;n.isConnected&&!n.hasPointerCapture?.(e.pointerId)&&n.setPointerCapture?.(e.pointerId)}cp({commit:!1,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags});break;default:{let i=Tp(e,r,t);i.length===0?n.state!==`inactive`&&of({cursorFlags:0,state:`inactive`}):of({cursorFlags:0,hitRegions:i,ownerDocument:t,state:`hover`});break}}}function Yp(e){if(e.relatedTarget instanceof HTMLIFrameElement){let t=nf();t.state===`hover`&&t.ownerDocument===e.currentTarget&&of({cursorFlags:0,state:`inactive`})}}function Xp(e){e.defaultPrevented||e.pointerType===`mouse`&&e.button>0||up(e.currentTarget,e)}function Zp(e){e.target===e.currentTarget&&Hp(e.currentTarget.document)}function Qp(e){Hp(e.currentTarget.document)}function $p(e,t,n){if(!n[0])return;let r=e.items.find(e=>e.element===t);if(!r||!r.onResize)return;let i=wf({axis:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:Rf(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}var em=new Map,tm=!1;function nm(e){let t=!0;Jd(e.element.ownerDocument.defaultView,`Cannot register an unmounted Group`);let n=e.element.ownerDocument.defaultView.ResizeObserver,r=new Set,i=new Set,a=new n(n=>{let r;Gf();try{for(let i of n){let{borderBoxSize:n,target:a}=i;if(a===e.element){if(t){let t=Xf(e.id);if(!t)break;let n=Pp({axis:e,axisState:t});if(!n)break;if(!n.changed)continue;$f(e,n.state)}}else try{$p(e,a,n)}catch(e){r??={error:e}}}}finally{qf()}if(r)throw r.error});a.observe(e.element),e.items.forEach(e=>{Jd(!r.has(e.id),`Panel ids must be unique; id "${e.id}" was used more than once`),r.add(e.id),e.onResize&&a.observe(e.element)});let o=wf({axis:e}),s=zf(e,o),c=Op({axis:e,itemConstraints:s}),l=jp({layout:c,itemConstraints:s}),u=e.element.ownerDocument,d=u.defaultView;em.set(u,(em.get(u)??0)+1);let f=new Map;return Mf({axis:e,includeDisabled:!0}).forEach(e=>{e.separator&&f.set(e.separator,e.items)}),$f(e,{defaultLayoutDeferred:o===0,derivedItemConstraints:s,axisSize:o,layout:l,requestedAxisSize:o,requestedLayout:Mp({itemIds:e.items.map(({id:e})=>e),layout:c}),separatorToItems:f}),e.separators.forEach(e=>{Jd(!i.has(e.id),`Separator ids must be unique; id "${e.id}" was used more than once`),i.add(e.id),e.element.addEventListener(`keydown`,Vp)}),tm||(tm=!0,rf(Cf)),em.get(u)===1&&(u.addEventListener(`contextmenu`,dp,!0),u.addEventListener(`dblclick`,Ip,!0),u.addEventListener(`lostpointercapture`,Up,!0),u.addEventListener(`pointercancel`,Wp,!0),u.addEventListener(`pointerdown`,Kp,!0),u.addEventListener(`pointerleave`,qp),u.addEventListener(`pointermove`,Jp),u.addEventListener(`pointerout`,Yp),u.addEventListener(`pointerup`,Xp,!0),d?.addEventListener(`blur`,Zp),d?.addEventListener(`pagehide`,Qp)),function(){t=!1,em.set(u,Math.max(0,(em.get(u)??0)-1)),Jf(e),cf(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,Vp)}),em.get(u)||(u.removeEventListener(`contextmenu`,dp,!0),u.removeEventListener(`dblclick`,Ip,!0),u.removeEventListener(`lostpointercapture`,Up,!0),u.removeEventListener(`pointercancel`,Wp,!0),u.removeEventListener(`pointerdown`,Kp,!0),u.removeEventListener(`pointerleave`,qp),u.removeEventListener(`pointermove`,Jp),u.removeEventListener(`pointerout`,Yp),u.removeEventListener(`pointerup`,Xp,!0),d?.removeEventListener(`blur`,Zp),d?.removeEventListener(`pagehide`,Qp)),a.disconnect()}}function rm({derivedItemConstraints:e,axis:t,layout:n,prevLayout:r,requestedLayout:i}){let a=t.items.map(({id:e})=>e).join(`,`);t.mutableState.layouts[a]=i,r&&e.forEach(e=>{if(e.collapsible){let i=rp(e.collapsedSize,n[e.itemId]),a=rp(e.collapsedSize,r[e.itemId]);i&&!a&&(t.mutableState.expandedItemSizes[e.itemId]=r[e.itemId])}})}function im(){let[e,t]=(0,Y.useState)({});return[e,(0,Y.useCallback)(()=>t({}),[])]}function am(e){let t=(0,Y.useRef)({...e});return Wd(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var om=(0,Y.createContext)(null);function sm({layout:e,itemConstraints:t,itemId:n,itemIndex:r}){let i,a,o=e[n],s=t.find(e=>e.itemId===n);if(s){let c=s.maxSize,l=s.collapsible?s.collapsedSize:s.minSize,u=[r,r+1];a=jp({layout:op({delta:l-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n],i=jp({layout:op({delta:c-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function cm({attributes:e,axisId:t,axisOrientation:n,children:r,className:i,"data-testid":a,disableCursor:o,disabled:s,disableDoubleClick:c,elementRef:l,id:u,isSharedHitRegion:d,preview:f,registerSeparator:p,requiredStyle:m,style:h,styleDefaults:g,tabIndex:_=0,updateSeparatorProps:v}){let y=am({disabled:s,disableDoubleClick:c,children:r,className:i,preview:f,style:h}),[b,x]=(0,Y.useState)({}),[S,C]=(0,Y.useState)(`inactive`),[w,T]=(0,Y.useState)(!1),E=(0,Y.useRef)(null),D=(0,Y.useRef)(null),O=Kd(E,l),k=n===`horizontal`?`vertical`:`horizontal`;Wd(()=>{let e=E.current;if(e!==null){let n={disabled:y.disabled,disableDoubleClick:y.disableDoubleClick,element:e,id:u,get children(){return y.children},get className(){return y.className},get preview(){return y.preview},get style(){return y.style}};D.current=n;let r=p(n),i=rf(e=>{C(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===n||(d?.(e)??!1))?e.next.state:`inactive`)}),a=Qf(t,e=>{let{derivedItemConstraints:t,layout:r,separatorToItems:i}=e.next,a=i.get(n);if(a){let n=a[0],i=t.findIndex(e=>e.itemId===n.id),{layoutStrategy:o}=e.axis;x({...sm({layout:r,itemConstraints:t,itemId:n.id,itemIndex:i}),...o?.getItemAriaControls&&{valueControls:o.getItemAriaControls(n.id)}})}});return()=>{D.current=null,i(),a(),r()}}},[t,u,d,p,y]),Wd(()=>{let e=D.current;e&&sf(e)},[f]),(0,Y.useEffect)(()=>{v(u,{disabled:s,disableDoubleClick:c})},[s,c,u,v]);let A;s&&!o&&(A=`not-allowed`);let j;if(s)j=`disabled`;else switch(S){case`active`:j=`active`;break;default:j=w?`focus`:S}return(0,X.jsx)(`div`,{...e,"aria-controls":b.valueControls,"aria-disabled":s||void 0,"aria-orientation":k,"aria-valuemax":b.valueMax,"aria-valuemin":b.valueMin,"aria-valuenow":b.valueNow,children:r,className:i,"data-separator":j,"data-testid":a,id:u,onBlur:()=>T(!1),onFocus:()=>T(!0),ref:O,role:`separator`,style:{...g,cursor:A,...h,...m,touchAction:`none`},tabIndex:s?void 0:_})}function lm(e){for(let t=1;t<e.length;t++)if(Tf(e[t-1],e[t])>0)return!1;return!0}function um({separator:e}){let{element:t}=e,n=(0,Y.useRef)(null);return Wd(()=>{let e=t.cloneNode(!0),r=[t,...t.querySelectorAll(`*`)],i=[e,...e.querySelectorAll(`*`)],a=t.ownerDocument.defaultView;return r.forEach((e,t)=>{let n=i[t];if(n instanceof a.HTMLElement||n instanceof a.SVGElement){let t=a.getComputedStyle(e);for(let e=0;e<t.length;e++){let r=t.item(e);n.style.setProperty(r,t.getPropertyValue(r))}}n.removeAttribute(`data-testid`),n.removeAttribute(`id`)}),Object.assign(e.style,{boxSizing:`border-box`,height:`100%`,margin:`0`,position:`static`,transform:`none`,width:`100%`}),n.current.appendChild(e),()=>e.remove()},[t]),(0,X.jsx)(`div`,{ref:n,style:{height:`100%`,opacity:.65,pointerEvents:`none`,width:`100%`}})}function dm(){let e=(0,Y.useContext)(om);return Jd(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function fm(e){let{registerOverlay:t}=dm(),n=(0,Y.useRef)(e);kp(n.current,e)||(n.current=e);let r=n.current;return Wd(()=>t(r),[t,r]),null}fm.displayName=`SeparatorOverlay`;function pm({active:e,orientation:t,style:n,...r}){let i;switch(t){case`horizontal`:i={height:`100%`,minWidth:`1px`};break;case`vertical`:i={minHeight:`1px`,width:`100%`}}return(0,X.jsx)(`div`,{...r,"data-separator-overlay":e?`active`:`inactive`,style:{...i,...n,flexShrink:0,pointerEvents:`none`}})}function mm({overlay:e,preview:t}){let{axis:n,offset:r,rect:i,separator:a}=t,o=n.orientation===`horizontal`,s=a?.preview,c=e;return(0,Y.isValidElement)(s)&&s.type===fm&&(c=s.props,s=void 0),s??(c?s=(0,X.jsx)(pm,{...c,active:t.active,orientation:n.orientation}):a&&(s=(0,X.jsx)(um,{separator:a}))),(0,X.jsx)(`div`,{"aria-hidden":`true`,"data-resize-preview":!0,inert:!0,style:{height:i.height,left:i.left,pointerEvents:`none`,position:`absolute`,top:i.top,transform:o?`translateX(${r}px)`:`translateY(${r}px)`,width:i.width},children:s})}function hm(e){return Array.from(e).sort(Tf)}function gm(e,t){let n=(0,Y.useRef)({getLayout:()=>({}),setLayout:lf});(0,Y.useImperativeHandle)(t,()=>n.current,[]),Wd(()=>{Object.assign(n.current,Rp({axisId:e}))})}function _m({groupId:e,resizePreviewMode:t}){let[n,r]=(0,Y.useState)([]),i=(0,Y.useRef)(n);return Wd(()=>{let n=n=>{let a=Yf(e),o=t===`separator`&&n.state===`active`?n.previews.filter(e=>e.axis===a&&(e.active||!rp(e.offset,0))):[],s=i.current;s.length===o.length&&o.every((e,t)=>e===s[t])||(i.current=o,r(o))};if(t!==`separator`){n(nf());return}let a=rf(({next:e})=>n(e));return n(nf()),a},[e,t]),n}function vm({children:e,className:t,defaultLayout:n,disableCursor:r,disabled:i,elementRef:a,groupRef:o,id:s,onLayoutChange:c,onLayoutChanged:l,orientation:u=`horizontal`,resizePreviewMode:d=`panel`,resizeTargetMinimumSize:f={coarse:20,fine:10},style:p,...m}){let h=(0,Y.useRef)({onLayoutChange:{},onLayoutChanged:{}}),g=Gd(e=>{sp(h.current.onLayoutChange,e)||(h.current.onLayoutChange=e,c?.(e))}),_=Gd((e,t,n)=>{sp(h.current.onLayoutChanged,e)||(h.current.onLayoutChanged=e,l?.(e,{isUserInteraction:t,requestedLayout:n}))}),v=Ud(s),[y,b]=(0,Y.useState)(),x=_m({groupId:v,resizePreviewMode:d}),S=(0,Y.useRef)(null),[C,w]=im(),T=(0,Y.useRef)([]),E=(0,Y.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],separators:[]}),D=Kd(S,a);gm(v,o);let O=Gd((e,t)=>{let r=Xf(e);if(r)return{flexGrow:r.layout[t]??1};if(n?.[t])return{flexGrow:n?.[t]}}),k=am({defaultLayout:n,disableCursor:r,resizeTargetMinimumSize:f}),A=(0,Y.useMemo)(()=>({get disableCursor(){return!!k.disableCursor},getPanelStyles:O,id:v,orientation:u,registerPanel:e=>{let t=E.current;return t.panels=Ef(u,[...t.panels,e]),w(),()=>{t.panels=t.panels.filter(t=>t!==e),w()}},registerOverlay:e=>(b(e),()=>{b(void 0)}),registerSeparator:e=>{let t=E.current;return t.separators=Ef(u,[...t.separators,e]),w(),()=>{t.separators=t.separators.filter(t=>t!==e),w()}},updatePanelProps:(e,{disabled:t})=>{let n=E.current.panels.find(t=>t.id===e);if(!n||n.constraintProps.disabled===t)return;n.constraintProps.disabled=t;let r=Yf(v),i=Xf(v);r&&i&&$f(r,{...i,derivedItemConstraints:zf(r)})},updateSeparatorProps:(e,{disabled:t,disableDoubleClick:n})=>{let r=E.current.separators.find(t=>t.id===e);r&&(r.disabled=t,r.disableDoubleClick=n)}}),[O,v,w,u,k]),j=(0,Y.useRef)(null);return Wd(()=>{let e=S.current;if(e===null)return;let t=E.current;t.panels=Ef(u,t.panels),t.separators=Ef(u,t.separators),T.current=hm([...t.panels.map(({element:e})=>e),...t.separators.map(({element:e})=>e)]);let n;if(k.defaultLayout!==void 0&&Object.keys(k.defaultLayout).length===t.panels.length){n={};for(let e of t.panels){let t=k.defaultLayout[e.id];t!==void 0&&(n[e.id]=t)}}let r={disabled:!!i,element:e,id:v,mutableState:{defaultLayout:n,disableCursor:!!k.disableCursor,expandedItemSizes:E.current.lastExpandedPanelSizes,layouts:E.current.layouts},orientation:u,items:t.panels,resizePreviewMode:d,get resizeTargetMinimumSize(){return k.resizeTargetMinimumSize},separators:t.separators};j.current=r;let a=nm(r),{defaultLayoutDeferred:o,derivedItemConstraints:s,layout:c,requestedLayout:l}=Xf(r.id,!0);if(!o&&s.length>0)try{try{g(c)}finally{_(c,!1,l)}}catch(e){throw j.current=null,a(),e}let f=Qf(v,e=>{let{defaultLayoutDeferred:t,derivedItemConstraints:n,layout:i,requestedLayout:a}=e.next;if(t||n.length===0)return;rm({derivedItemConstraints:n,axis:r,layout:i,prevLayout:e.prev?.layout,requestedLayout:a});let o=nf(),s=o.state!==`active`||!o.hitRegions.some(e=>e.axis===r);try{g(i)}finally{s&&_(i,e.isUserInteraction,a)}});return()=>{j.current=null,a(),f()}},[i,v,_,g,u,C,d,k]),Wd(()=>{lm(T.current)||w()}),(0,Y.useEffect)(()=>{let e=j.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,X.jsx)(om.Provider,{value:A,children:(0,X.jsxs)(`div`,{...m,className:t,"data-group":!0,"data-testid":qd(m,s),id:v,ref:D,style:{height:`100%`,width:`100%`,overflow:`hidden`,position:d===`separator`?`relative`:void 0,...p,display:`flex`,flexDirection:u===`horizontal`?`row`:`column`,flexWrap:`nowrap`,touchAction:u===`horizontal`?`pan-y`:`pan-x`},children:[e,x.map(e=>(0,X.jsx)(mm,{overlay:y,preview:e},e.key))]})})}vm.displayName=`Group`;function ym(e,t){return`react-resizable-panels:${[e,...t].join(`:`)}`}function bm({id:e,panelIds:t,storage:n}){let r=ym(e,[]),i=n.getItem(r);if(i)try{let e=JSON.parse(i);if(t){let n=e[t.join(`,`)];if(n&&Array.isArray(n.layout)&&t.length===n.layout.length){let e={};for(let r=0;r<t.length;r++)e[t[r]]=n.layout[r];return e}}else{let t=Object.keys(e);if(t.length===1){let n=e[t[0]];if(n&&Array.isArray(n.layout)){let e=t[0].split(`,`);if(e.length===n.layout.length){let t={};for(let r=0;r<e.length;r++)t[e[r]]=n.layout[r];return t}}}}}catch{}}function xm({debounceSaveMs:e=100,onlySaveAfterUserInteractions:t,panelIds:n,storage:r=localStorage,...i}){let a=n!==void 0,o=`id`in i?i.id:i.groupId,s=ym(o,n??[]),c=(0,Y.useSyncExternalStore)(Sm,()=>r.getItem(s),()=>r.getItem(s)),l=(0,Y.useMemo)(()=>{if(c){let e=JSON.parse(c),t=Object.values(e);if(Array.from(t).every(e=>typeof e==`number`))return e}},[c]),u=(0,Y.useMemo)(()=>{if(!l)return bm({id:o,panelIds:n,storage:r})},[l,o,n,r]),d=l??u,f=(0,Y.useRef)(null),p=(0,Y.useCallback)(()=>{let e=f.current;e&&(f.current=null,clearTimeout(e))},[]);(0,Y.useLayoutEffect)(()=>()=>{p()},[p]);let m=(0,Y.useCallback)((e,n)=>{if(t&&!n.isUserInteraction)return;p();let i=n.requestedLayout??e,s;s=a?ym(o,Object.keys(i)):ym(o,[]);try{r.setItem(s,JSON.stringify(i))}catch(e){console.error(e)}},[p,a,o,t,r]);return{defaultLayout:d,onLayoutChange:(0,Y.useCallback)(t=>{p(),e===0?m(t,{isUserInteraction:!1}):f.current=setTimeout(()=>{m(t,{isUserInteraction:!1})},e)},[p,e,m]),onLayoutChanged:m}}function Sm(){return function(){}}function Cm(e,t){let{id:n}=dm(),r=(0,Y.useRef)({collapse:uf,expand:uf,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:uf});(0,Y.useImperativeHandle)(t,()=>r.current,[]),Wd(()=>{Object.assign(r.current,Fp({axisId:n,itemId:e}))})}function wm({children:e,className:t,collapsedSize:n=`0%`,collapsedThreshold:r,collapsible:i=!1,defaultSize:a,disabled:o,elementRef:s,groupResizeBehavior:c=`preserve-relative-size`,id:l,maxSize:u=`100%`,minSize:d=`0%`,onResize:f,panelRef:p,style:m,...h}){let g=Hd(l),_=Ud(l),v=am({disabled:o}),y=(0,Y.useRef)(null),b=Kd(y,s),{getPanelStyles:x,id:S,orientation:C,registerPanel:w,updatePanelProps:T}=dm(),E=f!==null,D=Gd((e,t,n)=>{f?.(e,l,n)});Wd(()=>{let e=y.current;if(e!==null){let t={element:e,id:_,idIsStable:g,mutableValues:{expandToSize:void 0,prevSize:void 0},onResize:E?D:void 0,constraintProps:{groupResizeBehavior:c,collapsedSize:n,collapsedThreshold:r,collapsible:i,defaultSize:a,disabled:v.disabled,maxSize:u,minSize:d}};return w(t)}},[c,n,r,i,a,E,_,g,u,d,D,w,v]),(0,Y.useEffect)(()=>{T(_,{disabled:o})},[o,_,T]),Cm(_,p);let O=()=>{let e=x(S,_);if(e)return JSON.stringify(e)},k=(0,Y.useSyncExternalStore)(e=>Qf(S,e),O,O),A;return A=k?JSON.parse(k):a===void 0?{flexGrow:1}:{flexGrow:void 0,flexShrink:void 0,flexBasis:a},(0,X.jsx)(`div`,{...h,"data-disabled":o||void 0,"data-panel":!0,"data-testid":qd(h,l),id:_,ref:b,style:{...Tm,display:`flex`,flexBasis:0,flexShrink:1,overflow:`visible`,...A},children:(0,X.jsx)(`div`,{className:t,style:{maxHeight:`100%`,maxWidth:`100%`,flexGrow:1,overflow:`auto`,...m,touchAction:C===`horizontal`?`pan-y`:`pan-x`},children:e})})}wm.displayName=`Panel`;var Tm={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function Em(){return(0,Y.useRef)(null)}var Dm={flexBasis:`auto`},Om={flexGrow:0,flexShrink:0};function km({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,preview:o,style:s,...c}){let l=Ud(a),{disableCursor:u,id:d,orientation:f,registerSeparator:p,updateSeparatorProps:m}=dm();return(0,X.jsx)(cm,{attributes:c,axisId:d,axisOrientation:f,className:t,"data-testid":qd(c,a),disableCursor:u,disabled:n,disableDoubleClick:r,elementRef:i,id:l,preview:o,registerSeparator:p,requiredStyle:Om,style:s,styleDefaults:Dm,updateSeparatorProps:m,children:e})}km.displayName=`Separator`;function Am(){let e={status:`loading`,error:``},t=new Set,n=(n,r=``)=>{if(e.status!==n||e.error!==r){e={status:n,error:r};for(let e of t)e()}};return{getSnapshot:()=>e,subscribe:e=>(t.add(e),()=>t.delete(e)),loading:()=>n(`loading`),working:()=>n(`working`),failed:e=>n(`error`,e instanceof Error?e.message:String(e))}}var jm=Am(),Mm=/\.(?:tex|bib|cls|sty)$/i,Nm=3e4,Pm=null,Fm=!1,Im=null,Lm=1,Rm=new Map,zm=[],Bm=null,Vm=null,Hm=class extends Error{kind;constructor(e,t){super(t),this.kind=e,this.name=`TexFmtError`}};function Um(e){return e instanceof Hm}function Wm(e){Pm?.terminate(),Pm=null,Fm=!1,Im!==null&&window.clearTimeout(Im),Im=null,Bm=null,zm.length=0,Vm=null,jm.failed(e);for(let t of Rm.values())t.timeout!==null&&window.clearTimeout(t.timeout),t.reject(e);Rm.clear()}function Gm(){if(Bm!==null||zm.length===0)return;let e;try{e=Km()}catch(e){Wm(e instanceof Hm?e:new Hm(`load`,`The bundled tex-fmt formatter could not be loaded.`));return}if(!Fm)return;let t=zm.shift();if(t===void 0)return;let n=Rm.get(t);if(!n)Gm();else{Bm=t,n.timeout=window.setTimeout(()=>{Bm===t&&Wm(new Hm(`result`,`The formatter did not respond within 30 seconds.`))},Nm);try{e.postMessage({...n.request,id:t})}catch{Wm(new Hm(`load`,`The formatter worker could not receive the source.`))}}}function Km(){if(Pm)return Pm;if(typeof Worker>`u`){let e=new Hm(`load`,`This browser does not support formatter workers.`);throw jm.failed(e),e}jm.loading();try{Pm=new Worker(new URL(new URL(`latexFormatterWorker-BIDCSZPd.js`,import.meta.url).href,``+import.meta.url),{type:`module`,name:`texlite-latex-formatter`}),Im=window.setTimeout(()=>{Fm||Wm(new Hm(`load`,`The formatter did not finish loading within 30 seconds.`))},Nm)}catch{let e=new Hm(`load`,`The bundled tex-fmt formatter could not be loaded.`);throw jm.failed(e),e}return Pm.onmessage=e=>{let t=e.data;if(t&&`type`in t){t.type===`ready`&&(Fm=!0,Im!==null&&window.clearTimeout(Im),Im=null,Gm());return}if(!t||typeof t.id!=`number`){Wm(new Hm(`result`,`The formatter worker returned an invalid response.`));return}let n=Rm.get(t.id);if(n){if(Rm.delete(t.id),n.timeout!==null&&window.clearTimeout(n.timeout),Bm===t.id&&(Bm=null),t.ok)jm.working(),n.resolve(t.result),Gm();else{let e=new Hm(t.kind,t.message);t.kind===`format`?(jm.working(),n.reject(e),Gm()):(n.reject(e),Wm(e))}}},Pm.onerror=()=>{Wm(new Hm(`load`,`The bundled tex-fmt formatter could not be loaded.`))},Pm.onmessageerror=()=>{Wm(new Hm(`result`,`The formatter worker returned an unreadable response.`))},Pm}function qm(e){let t=Lm++;return new Promise((n,r)=>{Rm.set(t,{request:e,resolve:n,reject:r,timeout:null}),zm.push(t),Gm()})}function Jm(e,t=``){return qm({action:`format`,source:e,config:t})}async function Ym(){Pm&&jm.getSnapshot().status===`working`||(Vm||=qm({action:`probe`}).then(()=>void 0).finally(()=>{Vm=null}),await Vm)}async function Xm(){(Pm||Rm.size)&&Wm(new Hm(`load`,`The formatter runtime was reloaded.`)),jm.loading(),await Ym()}function Zm(e){return Mm.test(e)}function Qm(e){return e.match(/(?:\r?\n)+$/)?.[0]??``}function $m(e,t){let n=Qm(e),r=(n?e.slice(0,-n.length):e).split(/\r?\n/).find(e=>e.trim())?.match(/^[\t ]*/)?.[0]??``,i=t.replace(/(?:\r?\n)+$/,``);return`${r?i.split(`
13
+ `).map(e=>e&&`${r}${e}`).join(`
14
+ `):i}${n}`}async function eh(e,t,n=0){return qm({action:`diff`,source:e,formatted:t,baseOffset:n})}var th=null,nh=1,rh=new Map,ih=class extends Error{kind;constructor(e){super(`BibTeX formatter: ${e}`),this.kind=e,this.name=`BibtexFormatterError`}};function ah(e){th?.terminate(),th=null;for(let t of rh.values())clearTimeout(t.timeout),t.reject(new ih(e));rh.clear()}function oh(){if(th)return th;let e=new Worker(new URL(new URL(`bibtexFormatterWorker-B_jvobIv.js`,import.meta.url).href,``+import.meta.url),{type:`module`,name:`texlite-bibtex-formatter`});return th=e,e.onmessage=({data:t})=>{if(th!==e)return;if(!t||typeof t.id!=`number`||typeof t.ok!=`boolean`){ah(`unavailable`);return}let n=rh.get(t.id);n&&(t.ok&&(t.action!==n.action||(t.action===`format`?typeof t.result!=`string`:!sh(t.result)))?ah(`unavailable`):(clearTimeout(n.timeout),rh.delete(t.id),t.ok?n.resolve(t.result):t.kind===`too-large`||t.kind===`invalid`?n.reject(new ih(t.kind)):(n.reject(new ih(`unavailable`)),ah(`unavailable`))))},e.onerror=e.onmessageerror=()=>{th===e&&ah(`unavailable`)},e}function sh(e){if(!Array.isArray(e))return!1;let t=0;return e.every(e=>!e||!Number.isSafeInteger(e.from)||!Number.isSafeInteger(e.to)||e.from<t||e.to<e.from||typeof e.replacement!=`string`?!1:(t=e.to,!0))}function ch(e){return new Promise((t,n)=>{let r;try{r=oh()}catch{n(new ih(`unavailable`));return}let i=nh++,a=setTimeout(()=>ah(`timeout`),3e4);rh.set(i,{action:e.action,resolve:t,reject:n,timeout:a});try{r.postMessage({...e,id:i})}catch{ah(`unavailable`)}})}function lh(e,t){return ch({action:`format`,source:e,maxBytes:t})}function uh(e,t,n=0){return ch({action:`diff`,source:e,formatted:t,baseOffset:n})}function dh(e,t=null){let n=fh(e),r=t===`succeeded`||t===null&&hh(e)?[]:ph(n.filter(gh));return{warnings:ph(fh(mh(e)).filter(e=>!gh(e)&&_h(e))),errors:r}}function fh(e){return e.split(`
15
+ `).map(e=>e.trim()).filter(Boolean)}function ph(e){return[...new Set(e)]}function mh(e){let t=/^Running ['"][^\n]*(?:pdf|xe|lua)latex(?:\s|['"])[^\n]*$/gim,n=-1;for(let r of e.matchAll(t))n=r.index;return n>=0?e.slice(n):e}function hh(e){return/Latexmk: All targets .* are up-to-date/i.test(e)&&/Output written on .*\.pdf/i.test(e)}function gh(e){return/^!\s/.test(e)||/(?:^|:\s)(?:LaTeX|Package|Class|pdfTeX|XeTeX|LuaTeX)?\s*Error:/i.test(e)||/^Latexmk:.*(?:\bErrors?,|did not complete making targets|failure)/i.test(e)||/^Collected error summary/i.test(e)||/\b(?:fatal error|emergency stop|undefined control sequence|no output pdf|no pages of output)\b/i.test(e)||/\b(?:bibtex|biber) errors?:/i.test(e)||/^error, and then rerun latexmk/i.test(e)}function _h(e){return/\bwarnings?\b|overfull|underfull|badness/i.test(e)}var vh=Object.freeze({}),yh=class{threads=new Map;listeners=new Map;newComments=new Map;getThread(e){return this.threads.get(e)??vh}subscribe(e,t){let n=this.listeners.get(e)??new Set;return n.add(t),this.listeners.set(e,n),()=>{n.delete(t),n.size||this.listeners.delete(e)}}publish(e,t){Object.keys(t).length?this.threads.set(e,t):this.threads.delete(e);for(let t of this.listeners.get(e)??[])t()}isPending(e){return Object.values(this.getThread(e)).some(e=>e?.pending)}open(e,t,n=``){if(this.isPending(e))return;let r={...this.getThread(e)};if(t.startsWith(`edit-reply:`))for(let[e,t]of Object.entries(r))e.startsWith(`edit-reply:`)&&t?.open&&(r[e]={...t,open:!1});r[t]={content:n,pending:!1,error:``,...r[t],open:!0},this.publish(e,r)}change(e,t,n){let r=this.getThread(e)[t];r&&!this.isPending(e)&&this.publish(e,{...this.getThread(e),[t]:{...r,content:n}})}discard(e,t){let n={...this.getThread(e)};t===void 0?this.publish(e,vh):(delete n[t],this.publish(e,n))}async submit(e,t,n,r){let i=this.getThread(e)[t];if(!i||!i.content.trim()||this.isPending(e))return!1;let a={...i,pending:!0,error:``};this.publish(e,{...this.getThread(e),[t]:a});let o=r;try{if(await n(i.content))return this.getThread(e)[t]===a&&this.discard(e,t),!0}catch(e){o=W(e)}return this.getThread(e)[t]===a&&this.publish(e,{...this.getThread(e),[t]:{...i,pending:!1,error:o}}),!1}getNew(e){return this.newComments.get(e)}setNew(e){this.newComments.set(e.filePath,{...e,selection:{...e.selection}})}discardNew(e){this.newComments.delete(e)}},bh=Y.createContext(void 0),xh=e=>{let t=Y.useContext(bh);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},Sh=({client:e,children:t})=>(Y.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,X.jsx)(bh.Provider,{value:e,children:t})),Ch={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},wh=new class{#e=Ch;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function Th(e){setTimeout(e,0)}var Eh=typeof window>`u`||`Deno`in globalThis;function Dh(){}function Oh(e,t){return typeof e==`function`?e(t):e}function kh(e){return typeof e==`number`&&e>=0&&e!==1/0}function Ah(e,t){return Math.max(e+(t||0)-Date.now(),0)}function jh(e,t){return typeof e==`function`?e(t):e}function Mh(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==Ph(o,t.options))return!1}else if(!Ih(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function Nh(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(Fh(t.options.mutationKey)!==Fh(a))return!1}else if(!Ih(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Ph(e,t){return(t?.queryKeyHashFn||Fh)(e)}function Fh(e){return JSON.stringify(e,(e,t)=>Vh(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Ih(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e&&t&&typeof e==`object`&&typeof t==`object`){if(Array.isArray(e)&&Array.isArray(t)){if(t.length>e.length)return!1;for(let n=0;n<t.length;n++)if(!Ih(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Ih(e[r],t[r]))return!1;return!0}return!1}var Lh=Object.prototype.hasOwnProperty;function Rh(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=Bh(e)&&Bh(t);if(!r&&!(Vh(e)&&Vh(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:Lh.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Rh(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function zh(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Bh(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Vh(e){if(!Hh(e))return!1;let t=Object.getPrototypeOf(e),n=t?.constructor;if(n===void 0)return!0;if(typeof n!=`function`)return!1;let r=n.prototype;return!(!Hh(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Hh(e){return Object.prototype.toString.call(e)===`[object Object]`}function Uh(e){return new Promise(t=>{wh.setTimeout(t,e)})}function Wh(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Rh(e,t)}function Gh(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function Kh(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var qh=Symbol();function Jh(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===qh?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function Yh(e,t){return typeof e==`function`?e(...t):!!e}function Xh(e,t,n){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r||(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0})),i)}),e}var Zh=()=>Eh,Qh=()=>Zh(),$h=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},eg=new class extends $h{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},tg=Th;function ng(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=tg,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var rg=ng(),ig=new class extends $h{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function ag(e){return Math.min(1e3*2**e,3e4)}function og(e){return(e??`online`)!==`online`||ig.isOnline()}var sg=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function cg(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(Dh);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new sg(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>eg.isFocused()&&(e.networkMode===`always`||ig.isOnline())&&e.canRun(),p=()=>og(e.networkMode)&&e.canRun(),m=e=>{c()||(r?.(),i=`resolved`,a(e))},h=e=>{c()||(r?.(),i=`rejected`,o(e))},g=t=>new Promise(n=>{r=e=>{(c()||t())&&n(e)},e.onPause?.()}).then(()=>{r=void 0,c()||e.onContinue?.()}),_=()=>{if(c())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(m).catch(r=>{if(c())return;let i=e.retry??(Qh()?0:3),a=e.retryDelay??ag,o=typeof a==`function`?a(n,r):a,s=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);t||!s?h(r):(n++,e.onFail?.(n,r),Uh(o).then(()=>f()?void 0:g(f)).then(()=>{t?h(r):_()}))})};return{promise:s,status:()=>i,cancel:l,continue:()=>(r?.(),s),cancelRetry:u,continueRetry:d,canStart:p,start:()=>(p()?_():g(p).then(_),s)}}var lg=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),kh(this.gcTime)&&(this.#e=wh.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Qh()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(wh.clearTimeout(this.#e),this.#e=void 0)}};function ug(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{Xh(e,()=>t.signal,()=>n=!0)},u=Jh(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject(t.signal.reason);if(r==null&&e.pages.length)return Promise.resolve(e);let a=(()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})(),o=await u(a),{maxPages:s}=t.options,c=i?Kh:Gh;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?fg:dg,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]===void 0?r.initialPageParam:o[0]:dg(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.fetchFn=t.options.persister?()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):l}}}function dg(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function fg(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var pg=class extends lg{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=gg(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#a?.promise}setOptions(e){if(this.options={...this.#o,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=gg(this.options);e.data!==void 0&&(this.setState(hg(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Wh(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#c({type:`setState`,state:e})}cancel(e){let t=this.#a?.promise;return this.#a?.cancel(e),t?t.then(Dh).catch(Dh):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>jh(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===qh||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>jh(e.options.staleTime,this)===`static`)}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!Ah(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#a?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#a?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){let t=this.observers.indexOf(e);t!==-1&&(this.observers.splice(t,1),this.observers.length||(this.#a&&(this.#s||this.state.fetchStatus===`paused`&&this.state.status===`pending`?this.#a.cancel({revert:!0}):this.#a.cancelRetry()),this.scheduleGc()),this.#r.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#a?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#a)return this.#a.continueRetry(),this.#a.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#s=!0,n.signal)})},i=()=>{let e=Jh(this.options,t),n=(()=>{let e={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#s=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(e),e})();(this.#e===`infinite`?ug(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta});let o=this.#a=cg({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof sg&&e.revert&&this.setState({...this.#n,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await o.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#r.config.onSuccess?.(e,this),this.#r.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof sg){if(e.silent)return this.#a.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#r.config.onError?.(e,this),this.#r.config.onSettled?.(this.state.data,e,this),e}finally{this.#a===o&&(this.#a=void 0),this.scheduleGc()}}#c(e){let t=t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...mg(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...hg(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}};this.state=t(this.state),rg.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function mg(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:og(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function hg(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function gg(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var _g=class extends $h{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),yg(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return bg(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return bg(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof jh(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!zh(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&xg(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||jh(this.options.enabled,this.#t)!==jh(t.enabled,this.#t)||jh(this.options.staleTime,this.#t)!==jh(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||jh(this.options.enabled,this.#t)!==jh(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return zh(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch(t).then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(Dh)),t}#h(e){return!Qh()&&jh(this.options.enabled,this.#t)!==!1&&kh(e)}#g(){this.#b();let e=jh(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Ah(this.#r.dataUpdatedAt,e)+1;this.#u=wh.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return jh(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=wh.setInterval(()=>{(this.options.refetchIntervalInBackground||eg.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(wh.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(wh.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&yg(e,t),o=i&&xg(e,n,t,r);(a||o)&&(l={...l,...mg(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=Wh(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=Wh(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:Sg(e,t),refetch:this.refetch,isEnabled:jh(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),zh(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();rg.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function vg(e,t){return jh(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||jh(t.retryOnMount,e)!==!1)}function yg(e,t){return vg(e,t)||e.state.data!==void 0&&bg(e,t,t.refetchOnMount)}function bg(e,t,n){if(jh(t.enabled,e)!==!1&&jh(t.staleTime,e)!==`static`){let r=jh(n,e);return r===`always`||r!==!1&&Sg(e,t)}return!1}function xg(e,t,n,r){return(e!==t||jh(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&Sg(e,n)}function Sg(e,t){return jh(t.enabled,e)!==!1&&e.isStaleByTime(jh(t.staleTime,e))}var Cg=class extends lg{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||wg(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??(this.state.status===`pending`?this.execute(this.state.variables):Promise.resolve())}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey},r=this.#r=cg({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)}),i=this.state.status===`pending`,a=!r.canStart();try{if(i)t();else{this.#i({type:`pending`,variables:e,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:a})}let o=await r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#i({type:`success`,data:o}),o}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#r===r&&(this.#r=void 0),this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),rg.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function wg(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var Tg=class extends $h{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new Cg({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=Eg(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=Eg(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=Eg(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=Eg(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){rg.batch(()=>{let e=this.getAll();this.#e.clear(),this.#t.clear(),e.forEach(e=>{this.notify({type:`removed`,mutation:e})})})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>Nh(t,e))}findAll(e={}){return this.getAll().filter(t=>Nh(e,t))}notify(e){rg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return rg.batch(()=>Promise.all(e.map(e=>e.continue().catch(Dh))))}};function Eg(e){return e.options.scope?.id}var Dg=class extends $h{#e;#t=void 0;#n;#r;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#e.defaultMutationOptions(e),zh(this.options,t)||this.#e.getMutationCache().notify({type:`observerOptionsUpdated`,mutation:this.#n,observer:this}),t?.mutationKey&&this.options.mutationKey&&Fh(t.mutationKey)!==Fh(this.options.mutationKey)?this.reset():this.#n?.state.status===`pending`&&this.#n.setOptions(this.options)}onSubscribe(){this.listeners.size===1&&this.#n&&(this.#n.addObserver(this),this.#i())}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#a(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#i(),this.#a()}mutate(e,t){return this.#r=t,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#i(){let e=this.#n?.state??wg();this.#t={...e,isPending:e.status===`pending`,isSuccess:e.status===`success`,isError:e.status===`error`,isIdle:e.status===`idle`,mutate:this.mutate,reset:this.reset}}#a(e){rg.batch(()=>{let t=this.#r;if(t&&this.hasListeners()){let n=this.#t.variables,r=this.#t.context,i={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type===`success`){try{t.onSuccess?.(e.data,n,r,i)}catch(e){Promise.reject(e)}try{t.onSettled?.(e.data,null,n,r,i)}catch(e){Promise.reject(e)}}else if(e?.type===`error`){try{t.onError?.(e.error,n,r,i)}catch(e){Promise.reject(e)}try{t.onSettled?.(void 0,e.error,n,r,i)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#t)})})}},Og=class extends $h{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??Ph(r,t),a=this.get(i);return a||(a=new pg({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){this.#e.get(e.queryHash)===e&&(e.destroy(),this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){rg.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>Mh(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>Mh(e,t)):t}notify(e){rg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){rg.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){rg.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},kg=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new Og,this.#t=e.mutationCache||new Tg,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=eg.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=ig.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(jh(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Oh(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return rg.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;rg.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return rg.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=rg.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Dh).catch(Dh)}invalidateQueries(e,t={}){return rg.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=rg.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(Dh)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Dh)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(jh(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(jh(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Dh).catch(Dh)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Dh).catch(Dh)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return ig.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Fh(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Ih(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Fh(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Ih(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=Ph(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===qh&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},Ag=Y.createContext(!1),jg=()=>Y.useContext(Ag);Ag.Provider;function Mg(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Ng=Y.createContext(Mg()),Pg=()=>Y.useContext(Ng),Fg=(e,t,n)=>{let r=n?.state.status===`error`&&typeof e.throwOnError==`function`?Yh(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},Ig=e=>{Y.useEffect(()=>{e.clearReset()},[e])},Lg=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||Yh(n,[e.error,r])),Rg=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},zg=(e,t)=>e?.suspense&&t.isPending,Bg=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function Vg(e,t,n){let r=jg(),i=Pg(),a=xh(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,Rg(o),Fg(o,i,s),Ig(i);let[l]=Y.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(Y.useSyncExternalStore(Y.useCallback(e=>{let t=d?l.subscribe(rg.batchCalls(e)):Dh;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),Y.useEffect(()=>{l.setOptions(o)},[o,l]),zg(o,u))throw Bg(o,l,i);if(Lg({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Hg(e,t){return Vg(e,_g,t)}function Ug(e,t){let n=xh(t),[r]=Y.useState(()=>new Dg(n,e));Y.useEffect(()=>{r.setOptions(e)},[r,e]);let i=Y.useSyncExternalStore(Y.useCallback(e=>r.subscribe(rg.batchCalls(e)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),a=Y.useCallback((...e)=>{r.mutate(e[0],e[1]).catch(Dh)},[r]);if(i.error&&Yh(r.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:a,mutateAsync:i.mutate}}var Wg={lists:e=>[`discussion`,e,`comments`],file:(e,t)=>[`discussion`,e,`comments`,`file`,t],all:e=>[`discussion`,e,`comments`,`project`],summary:e=>[`discussion`,e,`summary`],mentions:e=>[`discussion`,e,`mentions`],candidates:e=>[`discussion`,e,`candidates`]},Gg=[],Kg=[],qg=e=>e instanceof De&&[401,403,404].includes(e.status);function Jg(){return new kg({defaultOptions:{queries:{staleTime:3e4,gcTime:3e5,retry:(e,t)=>!qg(t)&&e<2&&(!(t instanceof De)||t.status===0||t.status>=500||t.code===`INVALID_RESPONSE`),retryDelay:e=>Math.min(500*2**e,2e3),refetchOnReconnect:`always`},mutations:{retry:!1}}})}var Yg=new WeakMap;function Xg(e){let t=Yg.get(e);return t||(t={next:0,summaries:new Map},Yg.set(e,t)),++t.next}function Zg(e,t,n,r){let i=Yg.get(e);!n||!i||r<(i.summaries.get(t)??0)||(i.summaries.set(t,r),e.setQueryData(Wg.summary(t),n))}function Qg(e,t){if(t.kind===`created`)return e.some(e=>e.id===t.comment.id)?e:[...e,t.comment];let n=t.kind===`edited`?t.comment.id:t.kind===`resolved`?t.resolution.id:t.commentId;return t.kind===`deleted`?e.filter(e=>e.id!==n):e.map(e=>{if(e.id!==n)return e;if(t.kind===`edited`)return{...e,...t.comment};if(t.kind===`resolved`)return{...e,...t.resolution};if(t.kind===`reply-deleted`)return{...e,replies:e.replies.filter(e=>e.id!==t.replyId)};let r=e.replies.some(e=>e.id===t.reply.id);return{...e,replies:r?e.replies.map(e=>e.id===t.reply.id?t.reply:e):[...e.replies,t.reply]}})}async function $g(e,t,n){await Promise.all([e.cancelQueries({queryKey:Wg.lists(t)}),e.cancelQueries({queryKey:Wg.mentions(t)})]);let r=n.change,i=r.kind===`created`||r.kind===`edited`?r.comment.filePath:r.kind===`resolved`?r.resolution.filePath:r.filePath;if(e.setQueriesData({queryKey:Wg.lists(t)},e=>{if(!e)return e;let t=e.comments;return r.kind===`created`?e:{...e,comments:Qg(t,r),summary:n.summary}}),r.kind===`created`)for(let a of[Wg.file(t,i),Wg.all(t)])e.setQueryData(a,e=>e&&{...e,comments:Qg(e.comments,r),summary:n.summary});Zg(e,t,n.summary,Xg(e)),e.setQueryData(Wg.mentions(t),e=>e&&{mentions:e.mentions.filter(e=>r.kind===`deleted`?e.commentId!==r.commentId:r.kind===`resolved`&&r.resolution.resolved?e.commentId!==r.resolution.id:r.kind!==`reply-deleted`||e.replyId!==r.replyId)})}async function e_(e,t){await Promise.all([Wg.lists(t),Wg.mentions(t)].map(async t=>{await e.cancelQueries({queryKey:t}),await e.invalidateQueries({queryKey:t})}))}function t_(e,t,n,r,i){let a=xh(),o=async(t,n)=>{let r=Xg(a),i=await G(t,{signal:n});return n.aborted||Zg(a,e,i.summary,r),i},s=Hg({queryKey:Wg.file(e,t),enabled:!!t,queryFn:({signal:n})=>o(`/api/projects/${e}/comments?path=${encodeURIComponent(t)}`,n)}),c=Hg({queryKey:Wg.all(e),enabled:n===`project`,queryFn:({signal:t})=>o(`/api/projects/${e}/comments?scope=project`,t)}),l=Hg({queryKey:Wg.summary(e),enabled:!1}),u=(0,Y.useRef)({projectId:e,revision:r,sourceOrderRevision:i});(0,Y.useEffect)(()=>{let t=u.current;if(u.current={projectId:e,revision:r,sourceOrderRevision:i},t.projectId!==e)return;let n=t.revision===r?t.sourceOrderRevision===i?null:Wg.all(e):Wg.lists(e);n&&a.cancelQueries({queryKey:n}).then(()=>a.invalidateQueries({queryKey:n}))},[a,e,r,i]);let d=n===`project`?c:s,f=s.error?W(s.error):``;return{comments:qg(s.error)?Gg:s.data?.comments??Gg,commentsFilePath:t&&(s.data||s.error)?t:``,commentsReady:!(!t||!s.data||s.isFetching||s.error),fileCommentsLoading:!!(t&&s.isFetching),fileCommentsError:f,reviewComments:qg(d.error)?Gg:d.data?.comments??Gg,reviewCommentsLoading:!(n!==`project`&&!t||!d.isFetching),reviewCommentsError:d.error?W(d.error):``,projectCommentSummary:qg(s.error)||qg(c.error)?null:l.data??null,refreshComments:()=>e_(a,e)}}function n_(e){let t=xh(),n=Ug({retry:!1,mutationFn:async({id:e,path:n,options:r})=>{let i=await G(`/api/projects/${e}/comments${n}`,r);return await $g(t,e,i),e_(t,e),i}});return(t,r)=>n.mutateAsync({id:e,path:t,options:r})}function r_({projectId:e,activeFile:t,content:n,permission:r,revision:i,sourceOrderRevision:a,selection:o,save:s,saveFailureMessage:c,onError:l,onAdded:u}){let d=(0,Y.useMemo)(()=>new yh,[e]),f=(0,Y.useMemo)(()=>({active:!1}),[e]);(0,Y.useEffect)(()=>(f.active=!0,()=>{f.active=!1}),[f]);let[p,m]=(0,Y.useState)(`file`),h=t_(e,t,p,i,a),g=n_(e),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(``),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(``),N=(0,Y.useRef)(!1),ee=(0,Y.useRef)(t),te=(0,Y.useRef)(s),ne=(0,Y.useRef)(l),P=(0,Y.useRef)(u),re=(0,Y.useRef)(C),ie=(0,Y.useRef)(x);re.current=C,ie.current=x,ee.current=t,te.current=s,ne.current=l,P.current=u,(0,Y.useEffect)(()=>{v(null),m(`file`),b(!1),w(null),E(null),S(``),O(!1),M(``)},[e]),(0,Y.useEffect)(()=>{b(!1),w(null),E(null),S(``),O(!1),M(``)},[t]);let ae=(e,r)=>{if(!t)return;M(``);let i={filePath:t,selection:{...e??o},sourceHash:Id(r??n)},a=d.getNew(t);w(a??i),S(a?.content??``),E(i),O(!!a),b(!0)},oe=e=>{S(e),C&&(e?d.setNew({...C,content:e}):d.discardNew(C.filePath))},se=()=>{N.current||(b(!1),M(``))},ce=()=>{N.current||(C&&d.discardNew(C.filePath),S(``),w(null),E(null),O(!1),se())},F=()=>{!N.current&&T&&T.filePath===ee.current&&(w(T),x&&d.setNew({...T,content:x}),O(!1),M(``))},I=async()=>{let e=C,t=x;if(!x.trim()||!e||N.current)return;let n=()=>{let n=re.current;return n?.filePath===e.filePath&&n.sourceHash===e.sourceHash&&n.selection.startOffset===e.selection.startOffset&&n.selection.endOffset===e.selection.endOffset&&ie.current===t};N.current=!0,A(!0),M(``);try{if(r!==`read`&&!await te.current()){n()&&M(c);return}await g(``,{method:`POST`,body:JSON.stringify({path:e.filePath,content:t,...e.selection,sourceHash:e.sourceHash})});let i=d.getNew(e.filePath);if(i?.content===t&&i.sourceHash===e.sourceHash&&i.selection.startOffset===e.selection.startOffset&&i.selection.endOffset===e.selection.endOffset&&d.discardNew(e.filePath),!f.active)return;n()&&(b(!1),w(null),S(``),O(!1)),P.current()}catch(e){n()&&M(W(e))}finally{N.current=!1,A(!1)}},le=async e=>{try{await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({resolved:!e.resolved})})}catch(e){f.active&&ne.current(W(e))}},L=async(e,t)=>(await g(`/${e.id}/replies`,{method:`POST`,body:JSON.stringify({content:t})}),!0),R=async(e,t)=>(await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({content:t})}),!0),z=async e=>(await g(`/${e.id}`,{method:`DELETE`}),f.active&&(v(t=>t?.id===e.id?null:t),d.discard(e.id)),!0),B=async(e,t,n)=>(await g(`/${e.id}/replies/${t}`,{method:`PATCH`,body:JSON.stringify({content:n})}),!0),V=async(e,t)=>(await g(`/${e.id}/replies/${t}`,{method:`DELETE`}),d.discard(e.id,`edit-reply:${t}`),!0);return{commentDraftStore:d,...h,retryFileComments:h.refreshComments,retryReviewComments:h.refreshComments,commentScope:p,setCommentScope:m,focusComment:_,setFocusComment:v,commentOpen:y,openComment:ae,closeComment:se,cancelComment:ce,commentDraftRestored:D,commentDraftCanRetarget:!(!C||!T||C.sourceHash===T.sourceHash&&C.selection.startOffset===T.selection.startOffset&&C.selection.endOffset===T.selection.endOffset),useCurrentCommentSelection:F,commentText:x,setCommentText:oe,commentSelection:C?.selection??o,commentSubmitting:k,commentError:j,addComment:I,toggleComment:le,replyToComment:L,editComment:R,deleteComment:z,editCommentReply:B,deleteCommentReply:V}}function i_(e){let t=new Map;for(let n of e)for(let e of[n,...n.replies])t.has(e.authorId)||t.set(e.authorId,{authorId:e.authorId,authorUsername:e.authorUsername,authorDisplayName:e.authorDisplayName,authorAvatarStyle:e.authorAvatarStyle});return[...t.values()].sort((e,t)=>(e.authorDisplayName??e.authorUsername??``).localeCompare(t.authorDisplayName??t.authorUsername??``))}function a_(e,t){let n=t.participantIds;return!n?.size||n.has(e.authorId)||!t.topLevelOnly&&e.replies.some(e=>n.has(e.authorId))}function o_(e,t=`source`){return[...e].sort((e,n)=>{if(t===`time`)return Date.parse(n.createdAt)-Date.parse(e.createdAt);let r=e.sourceOrder??1/0,i=n.sourceOrder??1/0;return r===i?e.filePath.localeCompare(n.filePath,`en`,{numeric:!0})||e.startLine-n.startLine||e.startOffset-n.startOffset:r-i})}function s_(e,t){return t.scope===`project`||e.filePath===t.activeFile}function c_(e,t){return t===`unresolved`?!e.resolved:e.resolved}function l_(e,t){return t.some(t=>t.commentId===e.id&&t.readAt===null)}function u_(e,t){return e.filter(e=>s_(e,t)&&a_(e,t)&&c_(e,t.filter)&&(!t.unreadMentionsOnly||l_(e,t.unreadMentions)))}function d_(e,t,n=[]){let r=new Set(n.filter(e=>!!e));return o_(e.filter(e=>s_(e,t)?r.has(e.id)||a_(e,t)&&c_(e,t.filter)&&(!t.unreadMentionsOnly||l_(e,t.unreadMentions)):!1),t.sort)}function f_(e,t,n){let r=e.find(e=>e.id===t&&e.filePath===n&&!e.resolved);return r?[r]:[]}function p_(e,t){return e.filter(e=>e.filePath===t)}function m_(e,t,n){return!e||e.filePath!==t||n!==t?null:e}function h_(e,t,n,r,i,a){return!e||e.filePath!==t||n!==t||r!==t||!i?null:a.find(n=>n.id===e.id&&n.filePath===t)??null}function g_(e,t){if(!t)return 0;let n=e.findIndex(e=>e.id===t);return n<0?0:n+1}function __(e,t,n){if(!e.length)return null;let r=t?e.findIndex(e=>e.id===t):-1;if(r<0)return n===1?e[0]:null;let i=r+n;return i>=0&&i<e.length?e[i]:null}function v_(e,t,n,r){let i=xh(),a=Wg.mentions(e),o=Hg({queryKey:a,queryFn:({signal:t})=>G(`/api/projects/${e}/mentions?unread=1&limit=100`,{signal:t})}),s=qg(o.error)?Kg:o.data?.mentions??Kg,c=(0,Y.useRef)({onError:n,onRead:r});c.current={onError:n,onRead:r};let l=(0,Y.useMemo)(()=>({active:!1,pending:new Map}),[e]);(0,Y.useEffect)(()=>(l.active=!0,()=>{l.active=!1}),[l]);let u=(0,Y.useRef)({projectId:e,revision:t}),d=async(e=!1)=>{if(!l.active)return;await i.cancelQueries({queryKey:a});let t=await o.refetch();e&&t.error&&l.active&&c.current.onError(W(t.error))};(0,Y.useEffect)(()=>{let n=u.current;u.current={projectId:e,revision:t},n.projectId===e&&n.revision!==t&&d()},[e,t]);let f=t=>{let n=t??`all`,r=l.pending.get(n);if(r)return r;let o=(async()=>{try{let n=await G(`/api/projects/${e}/mentions/${t?`${encodeURIComponent(t)}/read`:`read-all`}`,{method:`POST`});if(!l.active||(await i.cancelQueries({queryKey:a}),!l.active))return!1;i.setQueryData(a,e=>e&&{mentions:t?e.mentions.filter(e=>e.id!==t):[]});let r=Number(n.changed)||0;return(r||!t)&&c.current.onRead?.(r,!t),i.invalidateQueries({queryKey:a}),!0}catch(e){return l.active&&c.current.onError(W(e)),!1}finally{l.pending.delete(n)}})();return l.pending.set(n,o),o};return{unreadMentions:s,mentionsError:o.error?W(o.error):``,refresh:d,markMentionRead:e=>f(e),markAllMentionsRead:()=>f()}}function y_({children:e}){let[t]=(0,Y.useState)(Jg);return(0,X.jsx)(Sh,{client:t,children:e})}function b_(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`update`||t.kind===`move`||t.kind===`delete`)&&typeof t.revision==`string`}function x_(e,t,n,r){let[i,a]=(0,Y.useState)(`connecting`),[o,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(``),[b,x]=(0,Y.useState)(``),[S,C]=(0,Y.useState)([]),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(n),[O,k]=(0,Y.useState)(null),[A,j]=(0,Y.useState)(!1),M=(0,Y.useRef)(t),N=(0,Y.useRef)(r);M.current=t,N.current=r,(0,Y.useEffect)(()=>{let n=e.compileStates();d(n[t]??null)},[t,e]),(0,Y.useEffect)(()=>{let t=()=>l(e.sessions()),n=()=>{s(!1),l([]),d(null),p(null),h(``),_(!1),y(``),x(``),C([])},r=({status:t})=>{a(t),t===`connected`?s(e.synced):n()},i=e=>{s(e),e&&(t(),c())},o=()=>{a(`disconnected`),n()},c=()=>{_(e.meta.get(`historyWarning`)===!0);let t=e.meta.get(`filesEvent`);b_(t)&&p(t);let n=e.meta.get(`commentsRevision`);typeof n==`string`&&h(n);let r=e.meta.get(`dictionaryRevision`);typeof r==`string`&&y(r);let i=e.meta.get(`chktexSettingsRevision`);typeof i==`string`&&x(i);let a=e.compileStates();d(a[M.current]??null)},u=()=>{let t=e.compileStates();d(t[M.current]??null)};e.awareness.on(`change`,t),e.provider.on(`status`,r),e.provider.on(`sync`,i),e.provider.on(`connection-close`,o),e.provider.on(`connection-error`,o),e.meta.observe(c);let f=e.onCompileStates(u),m=e.onProtocolUpgrade(()=>{j(!0),a(`disconnected`),n()}),g=e.onFormatLeaseState(()=>C(e.formatLeaseStates())),v=()=>{if(!N.current||e.currentPermission!==`read`)return;let t=e.hasWritableDraft,n=e.hasOtherWritableDraft;(t||n)&&k({previous:`edit`,localDraftReady:t,otherTabDraft:n})},b=e.onDraftReady(()=>{T(!0),v()}),S=e.onPermissionChanged((t,r)=>{t===`revoked`?(a(`disconnected`),n()):(D(t),t===`read`&&r!==`read`?k({previous:r,localDraftReady:e.hasWritableDraft,otherTabDraft:e.hasOtherWritableDraft}):t!==`read`&&k(null))});return t(),c(),a(e.connected?`connected`:`connecting`),s(e.synced),()=>{e.awareness.off(`change`,t),e.provider.off(`status`,r),e.provider.off(`sync`,i),e.provider.off(`connection-close`,o),e.provider.off(`connection-error`,o),e.meta.unobserve(c),f(),m(),g(),b(),S()}},[e]),(0,Y.useEffect)(()=>{r&&e.connect()},[e,r]),(0,Y.useEffect)(()=>{e.setPermission(n),D(n),r&&n===`read`&&(e.hasWritableDraft||e.hasOtherWritableDraft)?k({previous:`edit`,localDraftReady:e.hasWritableDraft,otherTabDraft:e.hasOtherWritableDraft}):n!==`read`&&k(null)},[e,n,r]);let ee=O!==null;return(0,Y.useEffect)(()=>{if(!ee)return;let t=()=>{if(e.currentPermission!==`read`)return;let t=e.hasWritableDraft,n=e.hasOtherWritableDraft;k(e=>!e||e.localDraftReady===t&&e.otherTabDraft===n?e:{...e,localDraftReady:t,otherTabDraft:n})};t();let n=window.setInterval(t,2e3);return()=>window.clearInterval(n)},[e,ee]),{collaboration:e,status:i===`connected`&&!o?`syncing`:i,synced:i===`connected`&&o,activeSessions:c,compileState:u,setCompileState:d,formatLeaseStates:S,filesEvent:f,commentsRevision:m,historyWarning:g,dictionaryRevision:v,chktexSettingsRevision:b,localDraftReady:w,permission:E,protocolUpgradeRequired:A,reconnect:()=>{A||(a(`connecting`),s(!1),l([]),d(null),C([]),e.reconnect())},permissionDowngrade:O,dismissPermissionDowngrade:()=>k(null),discardLocalDraft:async()=>await e.discardLocalDraft()?(k(null),window.location.reload(),!0):(k(e=>e&&{...e,otherTabDraft:!0}),!1)}}var S_=new Map,C_=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:ca(t.newValue||``)}),wi(this._onChange)}postMessage(e){Ci.setItem(this.room,sa(na(e)))}close(){Ti(this._onChange)}},w_=typeof BroadcastChannel>`u`?C_:BroadcastChannel,T_=e=>Hn(S_,e,()=>{let t=Gn(),n=new w_(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),E_=(e,t)=>(T_(e).subs.add(t),t),D_=(e,t)=>{let n=T_(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),S_.delete(e)),r},O_=(e,t,n=null)=>{let r=T_(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},k_=(e,t)=>{Z(e,0),Pr(e,Gs(t))},A_=(e,t,n)=>{Z(e,1),Pr(e,zs(t,n))},j_=(e,t,n)=>A_(t,n,ri(e)),M_=(e,t,n,r)=>{try{Is(t,ri(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},N_=(e,t)=>{Z(e,2),Pr(e,t)},P_=M_,F_=(e,t,n,r,i)=>{let a=Q(e);switch(a){case 0:j_(e,t,n);break;case 1:M_(e,n,r,i);break;case 2:P_(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},I_=(e,t,n)=>{Q(e)===0&&n(t,oi(e))},L_=3e4,R_=class extends er{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=vi();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&z_(this,t,`timeout`)},tr(L_/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:vi()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Hi(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},z_=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:vi()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},B_=(e,t,n=e.states)=>{let r=t.length,i=Cr();Z(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;Z(i,r),Z(i,s),Mr(i,JSON.stringify(o))}return Tr(i)},V_=(e,t,n)=>{let r=ei(t),i=vi(),a=[],o=[],s=[],c=[],l=Q(r);for(let t=0;t<l;t++){let t=Q(r),n=Q(r),l=JSON.parse(oi(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(Hi(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},H_=e=>Mi(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`),U_=[];U_[0]=(e,t,n,r,i)=>{Z(e,0);let a=F_(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},U_[3]=(e,t,n,r,i)=>{Z(e,1),Pr(e,B_(n.awareness,Array.from(n.awareness.getStates().keys())))},U_[1]=(e,t,n,r,i)=>{V_(n.awareness,ri(t),n)},U_[2]=(e,t,n,r,i)=>{I_(t,n.doc,(e,t)=>G_(n,t))};var W_=3e4,G_=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),K_=(e,t,n)=>{let r=ei(t),i=Cr(),a=Q(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},q_=(e,t,n)=>{t===e.ws&&(e.emit(`connection-close`,[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,z_(e.awareness,Array.from(e.awareness.getStates().keys()).filter(t=>t!==e.doc.clientID),e),e.emit(`status`,[{status:`disconnected`}])):e.wsUnsuccessfulReconnects++,setTimeout(J_,rr(ar(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},J_=e=>{if(e.shouldConnect&&e.ws===null){let t=new e._WS(e.url,e.protocols);t.binaryType=`arraybuffer`,e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=vi();let r=K_(e,new Uint8Array(n.data),!0);wr(r)>1&&t.send(Tr(r))},t.onerror=t=>{e.emit(`connection-error`,[t,e])},t.onclose=n=>{q_(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=vi(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit(`status`,[{status:`connected`}]);let n=Cr();if(Z(n,0),k_(n,e.doc),t.send(Tr(n)),e.awareness.getLocalState()!==null){let n=Cr();Z(n,1),Pr(n,B_(e.awareness,[e.doc.clientID])),t.send(Tr(n))}},e.emit(`status`,[{status:`connecting`}])}},Y_=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&O_(e.bcChannel,t,e)},X_=class extends $n{constructor(e,t,n,{connect:r=!0,awareness:i=new R_(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1}={}){for(super();e[e.length-1]===`/`;)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+`/`+t,this.maxBackoffTime=l,this.params=a,this.protocols=o,this.roomname=t,this.doc=n,this._WS=s,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=U_.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let e=Cr();Z(e,0),k_(e,n),this.ws.send(Tr(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=K_(this,new Uint8Array(e),!1);wr(t)>1&&O_(this.bcChannel,Tr(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=Cr();Z(t,0),N_(t,e),Y_(this,Tr(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=Cr();Z(o,1),Pr(o,B_(i,a)),Y_(this,Tr(o))},this._exitHandler=()=>{z_(this.awareness,[n.clientID],`app closed`)},Wi&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&W_<vi()-this.wsLastMessageReceived&&q_(this,this.ws,null)},W_/10),r&&this.connect()}get url(){let e=H_(this.params);return this.serverUrl+`/`+this.roomname+(e.length===0?``:`?`+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit(`synced`,[e]),this.emit(`sync`,[e]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Wi&&typeof process<`u`&&process.off(`exit`,this._exitHandler),this.awareness.off(`update`,this._awarenessUpdateHandler),this.doc.off(`update`,this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||=(E_(this.bcChannel,this._bcSubscriber),!0);let e=Cr();Z(e,0),k_(e,this.doc),O_(this.bcChannel,Tr(e),this);let t=Cr();Z(t,0),A_(t,this.doc),O_(this.bcChannel,Tr(t),this);let n=Cr();Z(n,3),O_(this.bcChannel,Tr(n),this);let r=Cr();Z(r,1),Pr(r,B_(this.awareness,[this.doc.clientID])),O_(this.bcChannel,Tr(r),this)}disconnectBc(){let e=Cr();Z(e,1),Pr(e,B_(this.awareness,[this.doc.clientID],new Map)),Y_(this,Tr(e)),this.bcconnected&&=(D_(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&q_(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(J_(this),this.connectBc())}},Z_=e=>yi((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),Q_=(e,t)=>yi((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(Jr(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),$_=e=>Z_(indexedDB.deleteDatabase(e)),ev=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),tv=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>fv(r,e))},nv=(e,t)=>Z_(e.count(t)),rv=(e,t)=>Z_(e.get(t)),iv=(e,t)=>Z_(e.delete(t)),av=(e,t,n)=>Z_(e.put(t,n)),ov=(e,t)=>Z_(e.add(t)),sv=(e,t,n)=>Z_(e.getAll(t,n)),cv=(e,t,n)=>{let r=null;return dv(e,t,e=>(r=e,!1),n).then(()=>r)},lv=(e,t=null)=>cv(e,t,`prev`),uv=(e,t)=>yi((n,r)=>{e.onerror=r,e.onsuccess=async e=>{let r=e.target.result;if(r===null||await t(r)===!1)return n();r.continue()}}),dv=(e,t,n,r=`next`)=>uv(e.openKeyCursor(t,r),e=>n(e.key)),fv=(e,t)=>e.objectStore(t),pv=(e,t)=>IDBKeyRange.upperBound(e,t),mv=(e,t)=>IDBKeyRange.lowerBound(e,t),hv=`custom`,gv=`updates`,_v=(e,t=()=>{},n=()=>{})=>{let[r]=tv(e.db,[gv]);return sv(r,mv(e._dbref,!1)).then(i=>{e._destroyed||(t(r),Mc(e.doc,()=>{i.forEach(t=>Is(e.doc,t))},e,!1),n(r))}).then(()=>lv(r).then(t=>{e._dbref=t+1})).then(()=>nv(r).then(t=>{e._dbsize=t})).then(()=>r)},vv=(e,t=!0)=>_v(e).then(n=>{(t||e._dbsize>=500)&&ov(n,zs(e.doc)).then(()=>iv(n,pv(e._dbref,!0))).then(()=>nv(n).then(t=>{e._dbsize=t}))}),yv=class extends er{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=Q_(e,e=>ev(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=yi(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,_v(this,e=>ov(e,zs(t)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit(`synced`,[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(e,t)=>{if(this.db&&t!==this){let[t]=tv(this.db,[gv]);ov(t,e),++this._dbsize>=500&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{vv(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},t.on(`update`,this._storeUpdate),this.destroy=this.destroy.bind(this),t.on(`destroy`,this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off(`update`,this._storeUpdate),this.doc.off(`destroy`,this.destroy),this._destroyed=!0,this._db.then(e=>{e.close()})}clearData(){return this.destroy().then(()=>{$_(this.name)})}get(e){return this._db.then(t=>{let[n]=tv(t,[hv],`readonly`);return rv(n,e)})}set(e,t){return this._db.then(n=>{let[r]=tv(n,[hv]);return av(r,t,e)})}del(e){return this._db.then(t=>{let[n]=tv(t,[hv]);return iv(n,e)})}},bv={Sync:0,Awareness:1,QueryAwareness:3,Flush:4,Protocol:5,Maintenance:6,Permission:7,CompileStates:8,FormatLease:9},xv=[`queued`,`running`,`succeeded`,`failed`,`cleaned`],Sv=[`cache`,`artifacts`];function Cv(e){return typeof e==`string`&&xv.includes(e)}function wv(e){return typeof e==`string`&&Sv.includes(e)}var Tv=[[`#1677c8`,`#1677c833`],[`#d65745`,`#d6574533`],[`#16866a`,`#16866a33`],[`#9a58b5`,`#9a58b533`],[`#d27b18`,`#d27b1833`],[`#3f7d20`,`#3f7d2033`],[`#be3e7b`,`#be3e7b33`],[`#4964c6`,`#4964c633`],[`#8a6a14`,`#8a6a1433`],[`#087f8c`,`#087f8c33`]],{Sync:Ev,Awareness:Dv,Flush:Ov,Protocol:kv,Maintenance:Av,Permission:jv,CompileStates:Mv,FormatLease:Nv}=bv,Pv=6e4,Fv=2592e6,Iv=15e3,Lv=3e5;function Rv(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.requestedBy;return typeof t.mainFile!=`string`||typeof t.runId!=`string`||!Cv(t.status)||t.status===`cleaned`&&!wv(t.cleanMode)||t.stale!==void 0&&typeof t.stale!=`boolean`||typeof t.updatedAt!=`string`||!n||typeof n.id!=`string`||typeof n.username!=`string`||typeof n.name!=`string`?null:t}function zv(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){let e=Rv(r);e&&e.mainFile===n&&(t[n]=e)}return t}function Bv(e,t,n){return e<=n&&t<=n}function Vv(e,t,n){let r=e=>e>0&&n-e<=Lv;return{recoverable:e.some(e=>e.tabId===t||!r(e.activeAt)),otherActive:e.some(e=>e.tabId!==t&&r(e.activeAt))}}var Hv=class{projectId;user;doc=new bs;provider;awareness;persistence;permission=`read`;activeFile=``;epoch=null;destroyed=!1;localDraftReady=!1;draftListeners=new Set;permissionListeners=new Set;protocolUpgradeListeners=new Set;compileStateListeners=new Set;flushRequests=new Map;formatLeaseRequests=new Map;formatLeaseListeners=new Set;formatLeaseStatesByPath=new Map;formatLeaseExpiryTimers=new Map;draftTabId;draftGeneration=0;draftUpdatedAt=0;draftMarkerPresent=!1;draftHeartbeatTimer=null;markDraftTabInactive;markDraftTabActive;undoManagers=new Map;authoritativeCompileStates=null;metaObserver;localDraftTransactionObserver;constructor(e,t){this.projectId=e,this.user=t;let n=window.location.protocol===`https:`?`wss:`:`ws:`;this.draftTabId=Yv(u(`texlite:collaboration-tab:${t.id}:${e}`));let r=this.readOwnWritableDraftMarker();this.draftGeneration=r?.generation??0,this.draftUpdatedAt=r?.updatedAt??0,this.draftMarkerPresent=r!==null,this.markDraftTabInactive=()=>this.setOwnDraftActivity(!1),this.markDraftTabActive=()=>this.resumeOwnDraftActivity(),window.addEventListener(`pagehide`,this.markDraftTabInactive),window.addEventListener(`pageshow`,this.markDraftTabActive),r&&(this.setOwnDraftActivity(!0),this.startDraftHeartbeat()),this.persistence=new yv(u(`texlite:${t.id}:${e}`),this.doc),this.localDraftTransactionObserver=e=>{if(e.local){for(let[t,n]of this.doc.share)if(t.startsWith(`source:`)&&(e.changed.has(n)||e.changedParentTypes.has(n))){this.markWritableDraft();return}}},this.doc.on(`afterTransaction`,this.localDraftTransactionObserver),this.persistence.on(`synced`,()=>{this.localDraftReady=!0;for(let e of this.draftListeners)e()}),this.provider=new X_(`${n}//${window.location.host}${d(`/api/collaboration`)}`,e,this.doc,{connect:!1,disableBc:!0,maxBackoffTime:2500}),this.awareness=this.provider.awareness;let i=this.doc.getMap(`texlite:meta`);this.metaObserver=(e,t)=>{t.origin===this.provider&&e.keysChanged.has(`compileStates`)&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners())},i.observe(this.metaObserver),this.provider.messageHandlers[Ov]=(e,t)=>{let n=oi(t),r=this.flushRequests.get(n);if(!r)return;let i=Q(t)===1,a=Q(t),o=oi(t),s=Q(t),c=[];for(let e=0;e<s;e++)c.push(oi(t));if(window.clearTimeout(r.timer),this.flushRequests.delete(n),i)this.clearOwnWritableDraftMarker(r.draftGeneration),r.resolve({revision:a,persistedAt:o,ok:!0,failedPaths:[]});else{let e=Object.assign(Error(c.length?`保存失败:${c.join(`, `)}`:`源码保存到服务器磁盘失败`),{failedPaths:c});r.reject(e)}},this.provider.messageHandlers[kv]=(e,t)=>{let n=oi(t),r=this.epochStorageKey(),i=Uv(r),a=/^([0-9]+):/.exec(n)?.[1]??null,o=i?/^([0-9]+):/.exec(i)?.[1]??null:null,s=!this.epoch&&a===`3`&&o!==null&&o!==a;if((this.epoch&&this.epoch!==n||i&&i!==n)&&!s){this.provider.disconnect(),this.rejectFlushes(Error(`Collaboration state changed`));let e=n.endsWith(`:reload`)||a!==null&&a!==`3`,t=()=>{Wv(r,n.replace(/:reload$/,``)),window.location.reload()};if(e)for(let e of this.protocolUpgradeListeners)e();else this.persistence.clearData().then(()=>{this.clearWritableDraftMarkers(),t()});return}this.epoch=n,Wv(r,n);let c=this.provider.ws;if(!c||c.readyState!==WebSocket.OPEN)return;let l=Cr();Z(l,kv),Mr(l,n),Z(l,3),c.send(Tr(l));let u=Cr();Z(u,Ev),k_(u,this.doc),c.send(Tr(u));let d=Cr();Z(d,Dv),Pr(d,B_(this.awareness,[this.doc.clientID])),c.send(Tr(d))},this.provider.messageHandlers[jv]=(e,t)=>{let n=oi(t),r=oi(t);if(n!==this.user.id)return;if(r===`revoked`){this.rejectFlushes(Error(`Project access revoked`)),this.provider.disconnect();for(let e of this.permissionListeners)e(`revoked`,this.permission);return}if(r!==`read`&&r!==`edit`&&r!==`owner`)return;let i=this.permission;if(this.setPermission(r),i!==r){r===`read`&&this.rejectFlushes(Error(`Project permission changed to read-only`));for(let e of this.permissionListeners)e(r,i)}},this.provider.messageHandlers[Av]=(e,t)=>{oi(t)},this.provider.messageHandlers[Mv]=(e,t)=>{let n={};try{n=zv(JSON.parse(oi(t)))}catch{}this.authoritativeCompileStates=n,this.notifyCompileStateListeners()},this.provider.messageHandlers[Nv]=(e,t)=>{let n=oi(t),r=oi(t),i=oi(t),a=oi(t),o=oi(t),s=oi(t);if(n===`state`){let e=ti(t)?oi(t):``,n=ti(t)?oi(t):``,r=Number(o);if(!e||!Number.isFinite(r)||r<=Date.now())this.removeFormatLeaseState(i),this.notifyFormatLeaseListeners(null);else{let t={path:i,holderUserId:e,holderName:n,expiresAt:r};this.formatLeaseStatesByPath.set(i,t);let a=this.formatLeaseExpiryTimers.get(i);a!==void 0&&window.clearTimeout(a);let o=window.setTimeout(()=>{let e=this.formatLeaseStatesByPath.get(i);!e||e.expiresAt>Date.now()||(this.removeFormatLeaseState(i),this.notifyFormatLeaseListeners(null))},Math.max(0,r-Date.now())+25);this.formatLeaseExpiryTimers.set(i,o),this.notifyFormatLeaseListeners(t)}return}let c=this.formatLeaseRequests.get(r);c&&(window.clearTimeout(c.timer),this.formatLeaseRequests.delete(r),n===`denied`?c.reject(Error(s||`Format lease request was denied`)):c.resolve({status:n,filePath:i,token:a,expiresAt:Number(o)}))},this.provider.on(`status`,({status:e})=>{e===`disconnected`&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners(),this.rejectFlushes(Error(`Collaboration connection closed`)),this.rejectFormatLeaseRequests(Error(`Collaboration connection closed`)),this.clearFormatLeaseStates())}),this.updateLocalAwareness()}connect(){this.destroyed||(this.provider.connect(),this.updateLocalAwareness())}getText(e){return this.doc.getText(`source:${e}`)}getUndoManager(e){let t=this.undoManagers.get(e);if(t)return t;let n=new Ic(this.getText(e));return this.undoManagers.set(e,n),n}applyTextEdits(e,t){if(this.permission===`read`)throw Error(`Read-only collaborators cannot edit source files`);let n=this.getText(e),r=0;for(let e of t){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<r||e.to<e.from||e.to>n.length)throw RangeError(`Invalid collaborative text edits`);r=e.to}this.doc.transact(()=>{for(let e=t.length-1;e>=0;--e){let r=t[e];r.to>r.from&&n.delete(r.from,r.to-r.from),r.replacement&&n.insert(r.from,r.replacement)}})}get meta(){return this.doc.getMap(`texlite:meta`)}compileStates(){return this.authoritativeCompileStates??zv(this.meta.get(`compileStates`))}onCompileStates(e){return this.compileStateListeners.add(e),()=>this.compileStateListeners.delete(e)}get synced(){return this.provider.synced}get connected(){return this.provider.wsconnected}get draftReady(){return this.localDraftReady}get currentPermission(){return this.permission}onDraftReady(e){return this.draftListeners.add(e),this.localDraftReady&&e(),()=>this.draftListeners.delete(e)}onPermissionChanged(e){return this.permissionListeners.add(e),()=>this.permissionListeners.delete(e)}onProtocolUpgrade(e){return this.protocolUpgradeListeners.add(e),()=>this.protocolUpgradeListeners.delete(e)}async discardLocalDraft(){return!this.hasOtherWritableDraft&&(await this.persistence.clearData(),this.localDraftReady=!1,this.clearWritableDraftMarkers(),!0)}get hasWritableDraft(){return Vv(this.readWritableDraftMarkers().map(({tabId:e,marker:t})=>({tabId:e,activeAt:t.activeAt})),this.draftTabId,Date.now()).recoverable}get hasOtherWritableDraft(){return Vv(this.readWritableDraftMarkers().map(({tabId:e,marker:t})=>({tabId:e,activeAt:t.activeAt})),this.draftTabId,Date.now()).otherActive}setPermission(e,t=!1){let n=this.permission;if(this.permission=e,e===`read`&&(n!==`read`&&this.rejectFlushes(Error(`Project permission changed to read-only`)),this.destroyUndoManagers(),this.clearFormatLeaseStates()),this.updateLocalAwareness(),t&&n!==e)for(let t of this.permissionListeners)t(e,n)}setActiveFile(e){this.activeFile!==e&&(this.activeFile=e,this.awareness.setLocalStateField(`cursor`,null),this.updateLocalAwareness())}sessions(){let e=[];return this.awareness.getStates().forEach((t,n)=>{let r=t?.user;r&&typeof r.id==`string`&&typeof r.name==`string`&&e.push({clientId:n,userId:r.id,username:typeof r.username==`string`?r.username:r.name,name:r.name,avatarStyle:j(r.avatarStyle)?r.avatarStyle:null,color:typeof r.color==`string`?r.color:`#1677c8`,colorLight:typeof r.colorLight==`string`?r.colorLight:`#1677c833`,permission:r.permission===`owner`||r.permission===`edit`?r.permission:`read`,filePath:typeof t.filePath==`string`?t.filePath:``,editing:!!t.cursor,local:n===this.doc.clientID})}),e.sort((e,t)=>Number(t.local)-Number(e.local)||e.name.localeCompare(t.name))}flush(){let e=this.provider.ws;if(!this.provider.synced||!e||e.readyState!==WebSocket.OPEN)return Promise.reject(Error(`Collaboration connection is unavailable`));let t=zd(),n=this.draftGeneration,r=Cr();return Z(r,Ov),Mr(r,t),new Promise((i,a)=>{let o=window.setTimeout(()=>{this.flushRequests.delete(t),a(Error(`Collaboration save timed out`))},5e3);this.flushRequests.set(t,{resolve:i,reject:a,timer:o,draftGeneration:n}),e.send(Tr(r))})}onFormatLeaseState(e){this.formatLeaseListeners.add(e);for(let t of this.formatLeaseStatesByPath.values())e(t);return()=>this.formatLeaseListeners.delete(e)}formatLeaseStates(){let e=Date.now();for(let[t,n]of this.formatLeaseStatesByPath)n.expiresAt<=e&&this.removeFormatLeaseState(t);return[...this.formatLeaseStatesByPath.values()]}async acquireFormatLease(e){if(this.permission===`read`)throw Error(`Formatting requires write permission`);let t=await this.requestFormatLease(`acquire`,e);if(t.status!==`grant`||!t.token||!Number.isFinite(t.expiresAt))throw Error(`Format lease was not granted`);let n=t.token,r=t.expiresAt,i=!1,a=async()=>{if(i)throw Error(`Format lease has already been released`);let t=await this.requestFormatLease(`renew`,e,n);if(t.status!==`renewed`||!Number.isFinite(t.expiresAt))throw Error(`Format lease renewal failed`);n=t.token||n,r=t.expiresAt};return{path:e,get token(){return n},get expiresAt(){return r},confirm:a,renew:a,release:async()=>{if(i)return;i=!0;let t=this.provider.ws;if(t&&t.readyState===WebSocket.OPEN)try{await this.requestFormatLease(`release`,e,n)}catch{}}}}reconnect(){this.destroyed||(this.rejectFlushes(Error(`Collaboration connection reset`)),this.provider.disconnect(),this.provider.connect(),this.updateLocalAwareness())}destroy(){this.destroyed=!0,this.setOwnDraftActivity(!1),this.stopDraftHeartbeat(),window.removeEventListener(`pagehide`,this.markDraftTabInactive),window.removeEventListener(`pageshow`,this.markDraftTabActive),this.rejectFlushes(Error(`Collaboration connection closed`)),this.provider.destroy(),this.persistence.destroy(),this.draftListeners.clear(),this.protocolUpgradeListeners.clear(),this.compileStateListeners.clear(),this.rejectFormatLeaseRequests(Error(`Collaboration connection closed`)),this.clearFormatLeaseStates(),this.formatLeaseListeners.clear(),this.meta.unobserve(this.metaObserver),this.doc.off(`afterTransaction`,this.localDraftTransactionObserver),this.destroyUndoManagers(),this.doc.destroy()}destroyUndoManagers(){for(let e of this.undoManagers.values())e.destroy();this.undoManagers.clear()}notifyCompileStateListeners(){for(let e of this.compileStateListeners)e()}rejectFlushes(e){for(let t of this.flushRequests.values())window.clearTimeout(t.timer),t.reject(e);this.flushRequests.clear()}requestFormatLease(e,t,n=``){let r=this.provider.ws;if(!this.provider.synced||!r||r.readyState!==WebSocket.OPEN)return Promise.reject(Error(`Collaboration connection is unavailable`));let i=zd(),a=Cr();return Z(a,Nv),Mr(a,e),Mr(a,i),Mr(a,t),Mr(a,n),new Promise((n,o)=>{let s=window.setTimeout(()=>{if(this.formatLeaseRequests.delete(i),e===`acquire`){let e=this.provider.ws;if(e?.readyState===WebSocket.OPEN){let n=Cr();Z(n,Nv),Mr(n,`cancel`),Mr(n,i),Mr(n,t),Mr(n,``),e.send(Tr(n))}}o(Error(`Format lease request timed out`))},e===`acquire`?Pv:5e3);this.formatLeaseRequests.set(i,{resolve:n,reject:o,timer:s}),r.send(Tr(a))})}rejectFormatLeaseRequests(e){for(let t of this.formatLeaseRequests.values())window.clearTimeout(t.timer),t.reject(e);this.formatLeaseRequests.clear()}clearFormatLeaseStates(){for(let e of this.formatLeaseExpiryTimers.values())window.clearTimeout(e);this.formatLeaseExpiryTimers.clear(),this.formatLeaseStatesByPath.size&&(this.formatLeaseStatesByPath.clear(),this.notifyFormatLeaseListeners(null))}removeFormatLeaseState(e){let t=this.formatLeaseExpiryTimers.get(e);t!==void 0&&window.clearTimeout(t),this.formatLeaseExpiryTimers.delete(e),this.formatLeaseStatesByPath.delete(e)}notifyFormatLeaseListeners(e){for(let t of this.formatLeaseListeners)t(e)}updateLocalAwareness(){let[e,t]=Tv[Math.abs(this.doc.clientID)%Tv.length],n=this.awareness.getLocalState()?.user,r=n&&Object.hasOwn(n,`avatarStyle`)?n.avatarStyle:this.user.avatarStyle;this.awareness.setLocalStateField(`user`,{id:this.user.id,username:this.user.username,name:this.user.displayName,avatarStyle:j(r)?r:null,color:e,colorLight:t,permission:this.permission,sessionId:String(this.doc.clientID)}),this.awareness.setLocalStateField(`filePath`,this.activeFile)}epochStorageKey(){return u(`texlite:collaboration-epoch:${this.user.id}:${this.projectId}`)}writableDraftStoragePrefix(){return`${u(`texlite:collaboration-writable:${this.user.id}:${this.projectId}`)}:`}ownWritableDraftStorageKey(){return`${this.writableDraftStoragePrefix()}${this.draftTabId}`}markWritableDraft(){this.draftGeneration+=1,this.draftUpdatedAt=Date.now(),this.draftMarkerPresent||this.writeOwnWritableDraftMarker(!0),this.startDraftHeartbeat()}clearWritableDraftMarkers(){for(let{key:e}of this.readWritableDraftMarkers())Gv(e);this.draftMarkerPresent=!1,this.stopDraftHeartbeat(),Gv(this.writableDraftStoragePrefix().slice(0,-1))}clearOwnWritableDraftMarker(e){let t=this.readOwnWritableDraftMarker();t&&Bv(t.generation,this.draftGeneration,e)&&(Gv(this.ownWritableDraftStorageKey()),this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}readOwnWritableDraftMarker(){return this.readWritableDraftMarker(this.ownWritableDraftStorageKey())}readWritableDraftMarkers(){let e=this.writableDraftStoragePrefix(),t=[];for(let n of Kv()){if(!n.startsWith(e))continue;let r=this.readWritableDraftMarker(n);r&&t.push({key:n,tabId:n.slice(e.length),marker:r})}return t}readWritableDraftMarker(e){let t=Uv(e);if(!t)return null;try{let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))return null;let r=n,i=Date.now();if(!Number.isInteger(r.generation)||(r.generation??0)<0||typeof r.updatedAt!=`number`||!Number.isFinite(r.updatedAt)||r.updatedAt<=0||i-r.updatedAt>Fv)return Gv(e),null;let a=typeof r.activeAt==`number`&&Number.isFinite(r.activeAt)?Math.max(0,r.activeAt):0;return{generation:r.generation,updatedAt:r.updatedAt,activeAt:a}}catch{return Gv(e),null}}writeOwnWritableDraftMarker(e){if(!this.draftMarkerPresent&&this.draftUpdatedAt<=0)return;let t={generation:this.draftGeneration,updatedAt:this.draftUpdatedAt||Date.now(),activeAt:e?Date.now():0};Wv(this.ownWritableDraftStorageKey(),JSON.stringify(t)),this.draftMarkerPresent=!0}setOwnDraftActivity(e){this.draftMarkerPresent&&(this.writeOwnWritableDraftMarker(e),e?this.startDraftHeartbeat():this.stopDraftHeartbeat())}resumeOwnDraftActivity(){let e=this.readOwnWritableDraftMarker();e?(this.draftGeneration=Math.max(this.draftGeneration,e.generation),this.draftUpdatedAt=e.updatedAt,this.draftMarkerPresent=!0,this.setOwnDraftActivity(!0)):(this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}startDraftHeartbeat(){this.draftHeartbeatTimer===null&&this.draftMarkerPresent&&(this.draftHeartbeatTimer=window.setInterval(()=>{this.writeOwnWritableDraftMarker(!0)},Iv))}stopDraftHeartbeat(){this.draftHeartbeatTimer!==null&&(window.clearInterval(this.draftHeartbeatTimer),this.draftHeartbeatTimer=null)}};function Uv(e){try{return window.localStorage.getItem(e)}catch{return null}}function Wv(e,t){try{window.localStorage.setItem(e,t)}catch{}}function Gv(e){try{window.localStorage.removeItem(e)}catch{}}function Kv(){try{let e=[];for(let t=0;t<window.localStorage.length;t+=1){let n=window.localStorage.key(t);n&&e.push(n)}return e}catch{return[]}}function qv(e){try{return window.sessionStorage.getItem(e)}catch{return null}}function Jv(e,t){try{window.sessionStorage.setItem(e,t)}catch{}}function Yv(e){let t=qv(e);if(t)return t;let n=zd();return Jv(e,n),n}function Xv({projectId:e,user:t,children:n}){let{t:r}=Ae(),i=(0,Y.useRef)(t);i.current=t;let[a,o]=(0,Y.useState)(null),s=(0,Y.useRef)(null),c=(0,Y.useRef)(null),l=t.id;return(0,Y.useEffect)(()=>{c.current=null;let t=s.current;return(!t||t.projectId!==e||t.userId!==l)&&(t?.collaboration.destroy(),t={projectId:e,userId:l,collaboration:new Hv(e,i.current)},s.current=t),o(t),()=>{let e={};c.current=e,queueMicrotask(()=>{c.current===e&&s.current===t&&(c.current=null,s.current=null,t.collaboration.destroy())})}},[e,l]),!a||a.projectId!==e||a.userId!==l?(0,X.jsx)(`div`,{className:`center-card`,role:`status`,children:r(`common.loading`)}):(0,X.jsx)(Y.Fragment,{children:n(a.collaboration)},a.collaboration.doc.guid)}var Zv=class{selection;restoreRetained;value;sharedAllowed;initialAllowed;constructor(e,t){this.selection=e,this.restoreRetained=t,this.value={selection:e,run:null,pdf:null},this.sharedAllowed=t,this.initialAllowed=t}get snapshot(){return this.value}get sharedCompletionAllowed(){return this.sharedAllowed}observeRunning(){this.sharedAllowed=!0}hasRun(e){return this.snapshot.run?.identity.runId===e&&this.snapshot.run.outcome!==null}beginCompile(){this.initialAllowed=!1,this.sharedAllowed=!0,this.value={...this.snapshot,run:null}}clean(e){this.initialAllowed=!1,e===`artifacts`&&(this.value={selection:this.selection,run:null,pdf:null})}receiveLatest(e,t){if(e.mainFile!==this.selection.mainFile||(t===`initial`?!this.initialAllowed:!this.sharedCompletionAllowed)||t===`shared`&&(!e.latestRun||this.hasRun(e.latestRun.id)))return null;let n=e.latestRun,r=n?.status===`succeeded`?`succeeded`:n?.log.includes(`Compilation was cancelled.`)?`cancelled`:n?.status===`failed`?`failed`:null;return this.receive(e,n?{identity:{...this.selection,runId:n.id},log:n.log,diagnostics:n.diagnostics,outcome:r}:null,t!==`initial`)}receiveLocal(e){return e.mainFile===this.selection.mainFile?this.receive(e,{identity:{...this.selection,runId:e.runId},log:e.log,diagnostics:e.diagnostics,outcome:e.cancelled?`cancelled`:e.ok?`succeeded`:`failed`},!0,e.skipped):null}receive(e,t,n,r=!1){let i=this.snapshot,a=t?this.hasRun(t.identity.runId):!1,o=i.pdf;if(e.pdfUrl){let t=new URL(e.pdfUrl,`https://texlite.invalid/`).searchParams.get(`run`);if(!t)throw Error(`PDF response is missing its compile run identity`);o={identity:{...this.selection,runId:t},url:e.pdfUrl,compiledAt:e.pdfCompiledAt,sizeBytes:e.pdfSizeBytes,loadingMode:e.pdfLoadingMode??`full`}}else n||(o=null);return this.initialAllowed=!1,this.value={selection:this.selection,run:t,pdf:o},{snapshot:this.snapshot,pdfChanged:i.pdf?.url!==o?.url,focusPdf:n&&t?.outcome===`succeeded`&&!!e.pdfUrl&&(r||!a)}}},Qv=(e,t)=>`${e}\0${t}`,$v=e=>e instanceof Error&&e.name===`AbortError`;function ey(e,t){e.current&&(!t||e.current.owner===t)&&(e.current.controller.abort(),e.current=null)}function ty(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof Element&&!!e.closest(`[role="dialog"], [role="alertdialog"], [data-agent-terminal]`)}function ny(e){let{projectId:t,project:n,mainFile:r,initialLatest:i,collaborationSynced:a,pdfVisible:o,sharedState:s}=e,{t:c}=Ae(),l=(0,Y.useRef)({...e,t:c});l.current={...e,t:c};let u=(0,Y.useRef)(!1),d=(0,Y.useRef)(null),f=d.current;(!f||f.selection.projectId!==t||f.selection.mainFile!==r)&&(d.current=new Zv({projectId:t,mainFile:r},!f||f.selection.projectId!==t||!f.selection.mainFile));let p=d.current,[m,h]=(0,Y.useState)(p.snapshot),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(()=>new Set),[A,j]=(0,Y.useState)(()=>new Set),[M,N]=(0,Y.useState)(``),ee=(0,Y.useRef)(null),te=(0,Y.useRef)(null),ne=(0,Y.useRef)(null),P=(0,Y.useRef)(null),re=(0,Y.useRef)(null),ie=(0,Y.useRef)(new Map),ae=(0,Y.useRef)(new Map),oe=(0,Y.useRef)(new Set),se=(0,Y.useRef)({projectId:t,promise:i});se.current.projectId!==t&&(se.current={projectId:t,promise:i});let ce=(0,Y.useRef)(null),F=(0,Y.useRef)(null),I=(0,Y.useRef)(()=>void 0),le=()=>l.current.getCurrentMainFile?.()||d.current.selection.mainFile,L=(e,t)=>u.current&&!t?.aborted&&d.current===e&&le()===e.selection.mainFile,R=Qv(t,r),z=m.selection===p.selection,B=O.has(R),V=E===p,ue=e=>{for(let t of[ee,te,ne,P])ey(t,e);for(let t of oe.current)t.owner===e&&(t.controller.abort(),oe.current.delete(t));_(t=>t?.owner===e?null:t),y(t=>t?.owner===e?null:t),T(!1)},de=()=>{F.current=null,ce.current=null,x([]),C(null),T(!1),N(``),l.current.onPdfChanged()},fe=async(e,t)=>{if(!L(e))return;let n=t??{owner:e,controller:new AbortController};t||(ey(ne),ne.current=n);let r=e.snapshot.pdf?.url,i=()=>L(e,n.controller.signal)&&e.snapshot.pdf?.url===r;try{let t=await G(`/api/projects/${e.selection.projectId}/compile/artifacts?mainFile=${encodeURIComponent(e.selection.mainFile)}`,{signal:n.controller.signal});i()&&(x(t.artifacts),C(null))}catch(e){!$v(e)&&i()&&(x([]),C(null))}finally{ne.current===n&&(ne.current=null)}},pe=()=>{let e=F.current;e&&(F.current=null,L(e.owner)&&e.owner.snapshot.pdf?.url===e.url&&fe(e.owner))},me=e=>{let t=e.snapshot.pdf?.url;t&&(F.current={owner:e,url:t},(!l.current.pdfVisible||ce.current?.owner===e&&ce.current.url===t)&&pe())},he=e=>{L(p)&&p.snapshot.pdf?.url===e&&(ce.current={owner:p,url:e},F.current?.owner===p&&F.current.url===e&&pe())},ge=(e,t)=>!t||!L(e)?!1:(h(t.snapshot),t.pdfChanged&&l.current.onPdfChanged(),t.focusPdf&&l.current.onCompileSuccess(),!0),_e=(e,t)=>{ue(e),F.current=null,e.clean(t),h(e.snapshot),t===`artifacts`&&(de(),l.current.onPreviewTab(`pdf`)),N(l.current.t(t===`cache`?`editor.cleanCacheComplete`:`editor.cleanArtifactsComplete`))};(0,Y.useEffect)(()=>(u.current=!0,()=>{u.current=!1;for(let e of[ee,te,ne,P,re])ey(e);for(let e of[...oe.current,...ae.current.values(),...ie.current.values()])e.controller.abort();oe.current.clear(),ae.current.clear(),ie.current.clear()}),[]),(0,Y.useEffect)(()=>{o||pe()},[o]),(0,Y.useEffect)(()=>{h(p.snapshot),de();for(let e of[ae.current,ie.current])for(let[n,r]of e)r.owner.selection.projectId!==t&&(r.controller.abort(),e.delete(n));let e=Qv(t,``),n=t=>{let n=new Set([...t].filter(t=>t.startsWith(e)));return n.size===t.size?t:n};if(k(n),j(n),re.current?.owner!==p&&ey(re),!r)return;if(!p.restoreRetained){l.current.onPreviewTab(`pdf`);let e={owner:p,controller:new AbortController};return l.current.loadOutline(e.controller.signal,r).catch(()=>void 0),()=>{e.controller.abort(),ue(p)}}let i={owner:p,controller:new AbortController};ee.current=i,_(i);let a=null,o,s=()=>(o=l.current.sharedState,G(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:i.controller.signal})),c=se.current.promise;return se.current.promise=null,(c?c.then(e=>L(p,i.controller.signal)?e.mainFile===r?e:s():null,()=>L(p,i.controller.signal)?s():null):s()).then(e=>{if(e&&L(p,i.controller.signal)&&ge(p,p.receiveLatest(e,`initial`))){if(e.latestRun?.requestedBy&&(e.latestRun.status===`queued`||e.latestRun.status===`running`)){let t={mainFile:r,runId:e.latestRun.id,status:e.latestRun.status,requestedBy:e.latestRun.requestedBy,updatedAt:new Date().toISOString()};l.current.onSharedState(e=>!L(p,i.controller.signal)||e?.mainFile===r&&(e!==o||e.runId===t.runId&&(e.status!==`queued`||t.status===`queued`))?e:t)}e.pdfUrl&&l.current.onPreviewTab(`pdf`)}}).catch(e=>{!$v(e)&&L(p,i.controller.signal)&&l.current.onError(W(e))}).finally(()=>{ee.current===i&&(ee.current=null),_(e=>e===i?null:e),L(p,i.controller.signal)&&(oe.current.add(i),a=window.setTimeout(()=>{L(p,i.controller.signal)?Promise.all([fe(p,i),l.current.loadOutline(i.controller.signal,r).catch(()=>void 0)]).finally(()=>oe.current.delete(i)):oe.current.delete(i)},0))}),()=>{a!==null&&window.clearTimeout(a),i.controller.abort(),ue(p)}},[p]),(0,Y.useEffect)(()=>{s&&s.mainFile===r&&s.status===`cleaned`&&s.cleanMode&&_e(p,s.cleanMode)},[p,s?.runId,s?.status,s?.cleanMode,s?.mainFile]),(0,Y.useEffect)(()=>{s?.mainFile===r&&(s.status===`queued`||s.status===`running`)?p.observeRunning():j(e=>{if(!e.has(R))return e;let t=new Set(e);return t.delete(R),t})},[p,s?.mainFile,s?.status,s?.runId]),(0,Y.useEffect)(()=>{if(!s||s.mainFile!==r||s.status!==`succeeded`&&s.status!==`failed`||ee.current?.owner===p||re.current?.owner===p||V||B||!p.sharedCompletionAllowed||p.hasRun(s.runId))return;let e={owner:p,controller:new AbortController};return ey(te),ey(P),T(!1),te.current=e,y(e),G(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:e.controller.signal}).then(t=>{L(p,e.controller.signal)&&t.latestRun?.id===s.runId&&ge(p,p.receiveLatest(t,`shared`))&&(s.status===`succeeded`&&s.stale&&N(l.current.t(`editor.compileSnapshotStale`)),s.status===`succeeded`&&t.pdfUrl?(l.current.onPreviewTab(`pdf`),me(p)):s.status===`failed`&&l.current.onPreviewTab(t.latestRun.diagnostics.errors.length?`errors`:`log`))}).catch(t=>{!$v(t)&&L(p,e.controller.signal)&&l.current.onError(W(t))}).finally(()=>{te.current===e&&(te.current=null),y(t=>t===e?null:t)}),()=>{e.controller.abort(),te.current===e&&(te.current=null)}},[p,s?.runId,s?.status,s?.mainFile,s?.stale,B,g,V]);let H=async()=>{if(!n||n.permission===`read`||!a)return;let e=l.current.resolveCompileMainFile?.()||le(),r=Qv(t,e),i=l.current.sharedState;if(!e||ae.current.has(r)||i?.mainFile===e&&(i.status===`queued`||i.status===`running`))return;let o=d.current;o.selection.mainFile!==e&&(ue(o),o=new Zv({projectId:t,mainFile:e},!1),d.current=o,de()),ue(o),N(``),l.current.onCompileStart(),l.current.onPreviewTab(o.snapshot.pdf?`pdf`:`log`);let s={owner:o,controller:new AbortController};ae.current.set(r,s),k(e=>new Set([...e,r]));try{if(!await l.current.save()||!L(o,s.controller.signal))return;o.beginCompile(),h(o.snapshot);let n=await G(`/api/projects/${t}/compile`,{method:`POST`,signal:s.controller.signal,body:JSON.stringify({mainFile:e})});if(!L(o,s.controller.signal)||!ge(o,o.receiveLocal(n)))return;n.cancelled&&N(l.current.t(`compileControls.cancelled`)),n.skipped&&N(l.current.t(`editor.upToDate`)),n.ok&&n.stale&&N(l.current.t(`editor.compileSnapshotStale`)),n.pdfUrl?(me(o),l.current.onPreviewTab(`pdf`)):l.current.onPreviewTab(n.diagnostics.errors.length?`errors`:`log`)}catch(e){!$v(e)&&L(o,s.controller.signal)&&l.current.onError(W(e))}finally{ae.current.get(r)===s&&(ae.current.delete(r),k(e=>{let t=new Set(e);return t.delete(r),t}),j(e=>{let t=new Set(e);return t.delete(r),t}))}},ve=async()=>{if(!n||n.permission===`read`||!a||!L(p))return;let e=Qv(t,r);if(!r||ie.current.has(e))return;let i={owner:p,controller:new AbortController};ie.current.set(e,i),j(t=>new Set([...t,e]));try{!(await G(`/api/projects/${t}/compile/cancel`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r})})).cancelled&&L(p,i.controller.signal)&&j(t=>{let n=new Set(t);return n.delete(e),n})}catch(t){L(p,i.controller.signal)&&(j(t=>{let n=new Set(t);return n.delete(e),n}),$v(t)||l.current.onError(W(t)))}finally{ie.current.get(e)===i&&ie.current.delete(e)}},ye=async e=>{if(!n||n.permission===`read`||!a||!L(p)||!r||re.current||ae.current.has(R)||s?.mainFile===r&&(s.status===`queued`||s.status===`running`))return;let i={owner:p,controller:new AbortController},o=l.current.sharedState;re.current=i,D(p),ue(p);try{let n=await G(`/api/projects/${t}/compile/clean`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r,mode:e})});if(!L(p,i.controller.signal)||n.mainFile!==r)return;l.current.sharedState===o&&l.current.onSharedState(null),_e(p,e)}catch(e){!$v(e)&&L(p,i.controller.signal)&&l.current.onError(W(e))}finally{re.current===i&&(re.current=null),D(e=>e===p?null:e)}},U=async e=>{if(!e.viewable||!L(p))return;ey(P);let n={owner:p,controller:new AbortController},i=p.snapshot.pdf?.url;P.current=n,T(!0);try{let a=await G(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(r)}&path=${encodeURIComponent(e.path)}`,{signal:n.controller.signal});L(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&C(a)}catch(e){!$v(e)&&L(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&l.current.onError(W(e))}finally{P.current===n&&(P.current=null,T(!1))}};I.current=()=>void H(),(0,Y.useEffect)(()=>{if(!M)return;let e=window.setTimeout(()=>N(``),3e3);return()=>window.clearTimeout(e)},[M,p]),(0,Y.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLocaleLowerCase()===`s`&&(e.preventDefault(),!ty(e.target)&&(e.stopPropagation(),e.repeat||I.current()))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let be=z?m:null;return{pdfUrl:be?.pdf?.url??``,pdfCompiledAt:be?.pdf?.compiledAt??null,pdfSizeBytes:be?.pdf?.sizeBytes??null,pdfLoadingMode:be?.pdf?.loadingMode??`full`,pdfLoading:g?.owner===p&&!g.controller.signal.aborted||v?.owner===p&&!v.controller.signal.aborted,compileLog:be?.run?.log??``,compileDiagnostics:be?.run?.diagnostics??null,compileOutcome:be?.run?.outcome??null,artifacts:z?b:[],artifactPreview:z?S:null,artifactLoading:z&&w,editorNotice:z?M:``,localCompiling:B,cancelling:A.has(R),cleaning:V,pdfDisplayed:he,compile:H,cancelCompile:ve,cleanCompile:ye,viewArtifact:U}}var ry=10485760;function iy(e){return e instanceof Error&&e.name===`AbortError`}function ay(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.map((e,n)=>t.slice(0,n+1).join(`/`))}function oy(e,t){return!!(e&&t)&&(t===e||t.startsWith(`${e}/`))}function sy(e,t){let n=Cn(e);return n===`binary`||n===`other`||n===`text`&&t===!1?`unsupported`:n}function cy(e,t){let n=sy(e.path,e.textContent);return n===`unsupported`?n:(e.size??0)>10485760||n===`text`&&(e.size??0)>t?`large`:n===`text`?`editor`:n}function ly(e,t){return d(`/api/projects/${e}/file/raw?path=${encodeURIComponent(t)}`)}function uy({projectId:e,site:t,activeFile:n,dirty:r,save:i,onError:a,onProject:o,onActiveFile:s,onActiveMainFile:c}){let{t:l}=Ae(),[u,d]=(0,Y.useState)([]),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)(!1),[S,C]=(0,Y.useState)(``),[w,T]=(0,Y.useState)(``),[E,D]=(0,Y.useState)(null),[O,k]=(0,Y.useState)(``),[A,j]=(0,Y.useState)(new Set),[M,N]=(0,Y.useState)(null),[ee,te]=(0,Y.useState)(``),[ne,P]=(0,Y.useState)(``),[re,ie]=(0,Y.useState)(null),[ae,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(null),[F,I]=(0,Y.useState)(!1),[le,L]=(0,Y.useState)(null),R=(0,Y.useRef)(!1),z=(0,Y.useRef)(null),B=(0,Y.useRef)(null),V=(0,Y.useRef)(null),ue=async(t={})=>{B.current?.abort(),B.current=null;let n=t.signal?null:new AbortController;n&&(B.current=n);try{let r=await G(`/api/projects/${e}/files`,{signal:t.signal??n?.signal});return(!t.isCurrent||t.isCurrent())&&d(r.files),r.files}catch(e){if(!iy(e))throw e;return}finally{n&&B.current===n&&(B.current=null)}},de=async()=>{if(m.trim()&&!m.trim().endsWith(`/`)){T(``);try{await G(`/api/projects/${e}/file`,{method:`POST`,body:JSON.stringify({path:m,content:``})});let t=(await ue())?.find(e=>e.path===m);t&&await _e(t),D(null),j(e=>new Set([...e,...ay(m)])),p(!1),h(``)}catch(e){T(W(e))}}},fe=async()=>{if(!S.trim())return;T(``);let t=E?`${E}/${S.trim()}`:S.trim();try{let n=await G(`/api/projects/${e}/folders`,{method:`POST`,body:JSON.stringify({path:t})});await ue(),j(e=>new Set([...e,...ay(n.path),n.path])),D(n.path),x(!1),C(``)}catch(e){T(W(e))}},pe=async(n,r=new Set,i=E)=>{if(!n.length||R.current)return;let a=t.maxUploadSizeMB;if(n.find(e=>e.size>a*1024*1024)){L({kind:`error`,message:l(`errors.fileTooLarge`,{size:a})});return}let o=i??``,s=n.map(e=>o?`${o}/${e.name}`:e.name),c=new Map;for(let e of s)c.set(e,(c.get(e)??0)+1);let d=[...c.entries()].filter(([,e])=>e>1).map(([e])=>e);if(d.length){L({kind:`error`,message:l(`errors.duplicateUploadNames`,{files:d.join(`, `)})});return}let f=new Set(u.map(e=>e.path)),p=[...new Set(s.filter(e=>f.has(e)&&!r.has(e)))];if(p.length){L(null),ce({files:n,directory:o,collisions:p});return}ce(null),z.current!==null&&window.clearTimeout(z.current),z.current=null,L(null),R.current=!0,I(!0);let m=0;try{let i=new URLSearchParams;o&&i.set(`directory`,o);let a=``;for(let[t,c]of n.entries()){let l=s[t];i.delete(`overwrite`),r.has(l)&&i.set(`overwrite`,`1`);let u=i.toString()?`?${i.toString()}`:``,d=new FormData;d.append(`file`,c);try{L({kind:`uploading`,fileName:c.name,current:t+1,total:n.length});let r=await G(`/api/projects/${e}/upload${u}`,{method:`POST`,body:d});m+=1,typeof r.path==`string`&&wn(r.path)&&(a=r.path)}catch(e){if(e instanceof De&&e.status===409&&!r.has(l)&&e.code===`FILE_EXISTS`){if(L(null),t>0)try{await ue()}catch{}ce({files:n.slice(t),directory:o,collisions:[l]});return}throw e}}let c;try{c=(await ue())?.find(e=>e.path===a&&wn(e.path,e.textContent)&&(e.size??0)<=t.maxCollaborativeFileSizeMB*1024*1024)}catch(e){L({kind:`error`,message:l(`editor.uploadSucceededRefreshFailed`,{message:W(e)})});return}c&&await _e(c),L({kind:`success`,count:m}),z.current=window.setTimeout(()=>{L(e=>e?.kind===`success`?null:e),z.current=null},3e3)}catch(e){try{await ue()}catch{}let t=m>0?l(`editor.uploadFailedPartial`,{count:n.length,uploaded:m,total:n.length,message:W(e)}):l(`editor.uploadFailed`,{message:W(e)});L({kind:`error`,message:t})}finally{R.current=!1,I(!1)}},me=()=>{z.current!==null&&window.clearTimeout(z.current),z.current=null,L(null)},he=async e=>{await pe(Array.from(e.target.files??[])),e.target.value=``},ge=async n=>{V.current?.abort(),V.current=null,y(!1);let r=ly(e,n.path);if(cy(n,t.maxCollaborativeFileSizeMB*1024*1024)===`large`){let e=wn(n.path,n.textContent)?Math.min(ry,t.maxCollaborativeFileSizeMB*1024*1024):ry;_({path:n.path,kind:`large`,size:n.size??0,url:r,limitBytes:e});return}let i=sy(n.path,n.textContent);if(i!==`text`){_({path:n.path,kind:i,size:n.size??0,url:r});return}_({path:n.path,kind:i,size:n.size??0,url:r,content:``}),y(!0);let o=new AbortController;V.current=o;try{let e;try{e=await fetch(r,{signal:o.signal})}catch(e){throw je(e)}let t=e.headers.get(`content-type`)??``;if(!e.ok){let n=null;try{n=t.includes(`application/json`)?await e.json():await e.text()}catch{}throw new De(we(n,e.status),e.status,be(n))}let i=new Uint8Array(await e.arrayBuffer());if(!Tn(i)){_(e=>e?.path===n.path?{...e,kind:`unsupported`,content:void 0}:e);return}let a=new TextDecoder().decode(i);_(e=>e?.path===n.path?{...e,content:a}:e)}catch(e){iy(e)||(_(null),a(W(e)))}finally{V.current===o&&(V.current=null,y(!1))}},_e=async n=>{if(V.current?.abort(),V.current=null,y(!1),D(null),k(n.path),cy(n,t.maxCollaborativeFileSizeMB*1024*1024)!==`editor`){await ge(n);return}let r=new AbortController;V.current=r;try{if(await G(`/api/projects/${e}/file?path=${encodeURIComponent(n.path)}&validate=1`,{signal:r.signal}),r.signal.aborted||V.current!==r)return;s(n.path)}catch(t){if(r.signal.aborted||V.current!==r||iy(t))return;t instanceof De&&t.code===`FILE_CONTENT_INVALID`?(d(e=>e.map(e=>e.path===n.path?{...e,textContent:!1}:e)),_({path:n.path,kind:`unsupported`,size:n.size??0,url:ly(e,n.path)})):a(W(t))}finally{V.current===r&&(V.current=null)}},H=async(t,n,r)=>{if(!await i())return null;let a=await G(`/api/projects/${e}/path`,{method:`PATCH`,body:JSON.stringify({source:t.path,destinationDirectory:n,destinationName:r})}),l=e=>e===t.path?a.path:e.startsWith(`${t.path}/`)?`${a.path}${e.slice(t.path.length)}`:e;s(e=>l(e)),c(e=>l(e)),D(e=>e&&l(e)),k(e=>e&&l(e));let[u,f]=await Promise.all([G(`/api/projects/${e}/files`),G(`/api/projects/${e}`)]);return d(u.files),o(f.project),j(e=>new Set([...e,...ay(a.path),n].filter(Boolean))),a.path};return(0,Y.useEffect)(()=>()=>{B.current?.abort(),V.current?.abort(),z.current!==null&&window.clearTimeout(z.current)},[]),(0,Y.useEffect)(()=>{V.current?.abort(),V.current=null,y(!1)},[n]),(0,Y.useEffect)(()=>{E!==null&&(V.current?.abort(),V.current=null,y(!1))},[E]),(0,Y.useEffect)(()=>{n&&k(n)},[n]),{files:u,setFiles:d,loadFiles:ue,newFileOpen:f,setNewFileOpen:p,newFilePath:m,setNewFilePath:h,resourcePreview:g,setResourcePreview:_,resourcePreviewLoading:v,setResourcePreviewLoading:y,newFolderOpen:b,setNewFolderOpen:x,newFolderName:S,setNewFolderName:C,fileDialogError:w,setFileDialogError:T,selectedFolder:E,setSelectedFolder:D,selectedFile:O,setSelectedFile:k,expandedFolders:A,setExpandedFolders:j,moveEntry:M,setMoveEntry:N,moveName:ee,setMoveName:te,moveDestination:ne,setMoveDestination:P,deleteEntry:re,setDeleteEntry:ie,fileDragActive:ae,setFileDragActive:oe,uploadConflict:se,setUploadConflict:ce,uploadingFiles:F,uploadFeedback:le,dismissUploadFeedback:me,directoryEntries:u.filter(e=>e.type===`directory`),visibleEntries:u.filter(e=>ay(e.path).every(e=>A.has(e))),createFile:de,createFolder:fe,uploadFiles:pe,upload:he,openFile:_e,movePath:async()=>{if(!M)return;let e=ee.trim();if(e){T(``);try{if(!await H(M,ne,e))return;N(null),te(``),P(``)}catch(e){T(W(e))}}},movePathToFolder:async(e,t)=>{if(dy(e.path)!==t&&(e.type!==`directory`||t!==e.path&&!t.startsWith(`${e.path}/`)))try{await H(e,t,e.path.split(`/`).at(-1)??e.path)}catch(e){a(W(e))}},removePath:async()=>{if(re){T(``);try{if(r&&!await i())return;await G(`/api/projects/${e}/file?path=${encodeURIComponent(re.path)}`,{method:`DELETE`}),ie(null)}catch(e){T(W(e))}}}}}function dy(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function fy({active:e,harperEnabled:t=!0,projectId:n,activeFile:r,content:i,dictionaryWords:a,additionalIssues:o=[],additionalIssuesReady:s=!0}){let[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(0),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(0),T=(0,Y.useRef)(0),E=(0,Y.useRef)(!1),D=(0,Y.useRef)(!1),O=(0,Y.useRef)(i),k=(0,Y.useRef)(r),A=(0,Y.useRef)(0);O.current=i,k.current=r,D.current=x,(0,Y.useEffect)(()=>{l([]),d(``),m(``),v(null),b(null),S(!1)},[r,a,t]),(0,Y.useEffect)(()=>{b(null),S(!1)},[n]),(0,Y.useEffect)(()=>{let o=++T.current;if(!e||!r){l([]),d(``),m(``),v(null);return}if(!t||y){l([]),d(``),m(``);return}let s=i,c=r,u=!1,p=window.setTimeout(()=>{b(null),(async()=>{try{let{lintLatex:e,isHarperLintSupersededError:t}=await f(async()=>{let{lintLatex:e,isHarperLintSupersededError:t}=await import(`./spellCheck-xzICTGx1.js`);return{lintLatex:e,isHarperLintSupersededError:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url);if(u||o!==T.current||O.current!==s||k.current!==c)return;let r;try{r=await e(n,c,s,a)}catch(e){if(t(e))return;throw e}if(u||o!==T.current||O.current!==s||k.current!==c)return;E.current=!1,S(!1),l(r),d(s),m(c),g(0),v(null)}catch(e){if(u||o!==T.current||O.current!==s||k.current!==c)return;l([]),d(``),m(``),b(e instanceof Error?e.message:String(e));let t=E.current;E.current=!1,S(t?D.current:!1)}})()},700);return()=>{u=!0,window.clearTimeout(p)}},[e,t,n,r,i,a,C,y]),(0,Y.useEffect)(()=>{if(!y||!e||!t)return;let n=!1,r=()=>{n||(n=!0,E.current=!0,b(null),w(e=>e+1))},i=window.setTimeout(r,15e3);return window.addEventListener(`online`,r,{once:!0}),()=>{window.clearTimeout(i),window.removeEventListener(`online`,r)}},[y,e,t]);let j=t&&e&&p===r&&u===i,M=(0,Y.useMemo)(()=>{if(!e)return[];let t=[...j?c:[],...o].sort((e,t)=>e.from-t.from||e.to-t.to),n=new Set;return t.filter(e=>{let t=`${e.from}:${e.to}:${e.kind}:${e.message}`;return!n.has(t)&&(n.add(t),!0)})},[e,o,j,c]),N=(0,Y.useMemo)(()=>e&&(!t||j)&&s?{total:M.length,unique:new Set(M.map(e=>`${e.kind}:${e.word.toLocaleLowerCase(`en-US`)}`)).size}:null,[e,s,t,j,M]);return(0,Y.useEffect)(()=>{g(e=>M.length?Math.min(e,M.length-1):0)},[M]),{issues:M,jump:e?_:null,index:h,summary:N,jumpToIssue:e=>{if(!M.length)return;let t=Math.max(0,Math.min(e,M.length-1)),n=M[t];g(t),v({from:n.from,to:n.to,nonce:++A.current})},error:e&&t&&!x?y:null,nativeFallback:e&&t&&!!y,retry:()=>{E.current=!1,b(null),S(!1),w(e=>e+1)},dismissError:()=>{E.current=!1,S(!0)}}}function py({active:e,projectId:t,activeFile:n,content:r}){let[i,a]=(0,Y.useState)([]),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(0),_=(0,Y.useRef)(0),v=(0,Y.useRef)(r),y=(0,Y.useRef)(n);v.current=r,y.current=n,(0,Y.useEffect)(()=>{a([]),s(``),l(``),d(null),m(!1)},[t,n]),(0,Y.useEffect)(()=>{let i=++_.current;if(!e||!n){a([]),s(``),l(``);return}let o=r,c=n,u=!1,p=window.setTimeout(()=>{(async()=>{try{let{lintChktex:e,isChktexLintSupersededError:n}=await f(async()=>{let{lintChktex:e,isChktexLintSupersededError:t}=await import(`./chktex-Bz-LKycq.js`);return{lintChktex:e,isChktexLintSupersededError:t}},__vite__mapDeps([9,1,2,3,4,5,6,7,8]),import.meta.url);if(u||i!==_.current||v.current!==o||y.current!==c)return;let r;try{r=await e(t,c,o)}catch(e){if(n(e))return;throw e}if(u||i!==_.current||v.current!==o||y.current!==c)return;a(r),s(o),l(c),d(null),m(!1)}catch(e){if(u||i!==_.current||v.current!==o||y.current!==c)return;a([]),s(``),l(``),d(e instanceof Error?e.message:String(e))}})()},2e3);return()=>{u=!0,window.clearTimeout(p)}},[e,t,n,r,h]);let b=e&&c===n&&o===r;return{issues:b?i:[],checked:b,error:e&&!p?u:null,retry:()=>{d(null),m(!1),g(e=>e+1)},dismissError:()=>m(!0)}}function my(e){return e instanceof Error&&e.name===`AbortError`}function hy(e,t){return/\.tex$/i.test(e)&&/\.tex$/i.test(t)}function gy({projectId:e,mainFile:t,activeFile:n,onOpenSourceFile:r,onError:i,onShowPdf:a,onShowEditor:o}){let[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),p=(0,Y.useRef)(null),m=(0,Y.useRef)(0),h=(0,Y.useRef)(n),g=(0,Y.useRef)(r),_=(0,Y.useRef)(i),v=(0,Y.useRef)(a),y=(0,Y.useRef)(o);h.current=n,g.current=r,_.current=i,v.current=a,y.current=o,(0,Y.useEffect)(()=>(p.current?.abort(),p.current=null,c(null),u(null),f(null),()=>p.current?.abort()),[e,t]);let b=(e,t,n)=>{f({path:e,line:t,column:n,nonce:++m.current}),g.current(e)},x=async(n,r,i,a={})=>{if(!hy(n,t))return;p.current?.abort();let o=new AbortController;p.current=o;try{let a=await G(`/api/projects/${e}/sync/pdf?mainFile=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}&line=${r}&column=${i}`,{signal:o.signal});if(p.current!==o||!a)return;c({...a,nonce:++m.current}),v.current()}catch(e){!my(e)&&!a.silent&&_.current(W(e))}finally{p.current===o&&(p.current=null)}},S=async(n,r,i)=>{let a=h.current;p.current?.abort();let o=new AbortController;p.current=o;try{let s=await G(`/api/projects/${e}/sync/source?mainFile=${encodeURIComponent(t)}&page=${n}&x=${r}&y=${i}`,{signal:o.signal});if(p.current!==o||h.current!==a)return;y.current(),b(s.path,s.line,s.column)}catch(e){my(e)||_.current(W(e))}finally{p.current===o&&(p.current=null)}};return{pdfTarget:s,pdfViewport:l,sourceJump:d,setPdfViewport:u,resetPdfViewport:()=>u(null),clearPdfViewport:()=>{p.current?.abort(),p.current=null,u(null),c(null)},jumpToSource:b,syncSourceToPdf:x,syncPdfToSource:S,syncVisiblePdfToSource:()=>{l&&S(l.page,l.x,l.y)}}}function _y(e,t){return u(`texlite.workspaceLayout:${encodeURIComponent(e)}:${encodeURIComponent(t)}`)}function vy(e,t){try{let n=window.localStorage.getItem(_y(e,t));if(n===`editor-pdf`||n===`editor-only`||n===`pdf-only`)return n}catch{}return`editor-pdf`}function yy(e,t){let[n,r]=(0,Y.useState)(()=>vy(e,t));return(0,Y.useEffect)(()=>{r(vy(e,t))},[e,t]),{workspaceLayout:n,setWorkspaceLayout:n=>{r(n);try{window.localStorage.setItem(_y(e,t),n)}catch{}}}}function by(e,t){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let n=Object.entries(e);return n.length===t.length&&n.every(([e,n])=>t.includes(e)&&typeof n==`number`&&Number.isFinite(n)&&n>=0&&n<=100)&&Math.abs(n.reduce((e,[,t])=>e+t,0)-100)<.1}function xy(e,t,n=()=>window.localStorage){let r=`react-resizable-panels:${e}:${t.join(`:`)}`;return{getItem(e){if(e!==r)return null;try{let e=n().getItem(r);return e&&by(JSON.parse(e),t)?e:null}catch{return null}},setItem(e,t){if(e===r)try{n().setItem(r,t)}catch{}}}}function Sy(e,t,n){let r=(0,Y.useMemo)(()=>[...e?[`files`,`source`]:[],...t?[`preview`]:[],...n?[`context`]:[]],[e,t,n]),i=u(`texlite-workspace-layout`);return xm({id:i,panelIds:r,storage:(0,Y.useMemo)(()=>xy(i,r),[i,r])})}function Cy(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function wy(e){let t=ld(ud(e));for(let e of t.matchAll(/\\documentclass(?![A-Za-z@])\s*(?:\[[^\]]*\]\s*)?\{/g))if(e.index!==void 0&&!Cy(t,e.index))return!0;return!1}function Ty({sessions:e,status:t}){let{t:n}=Ae(),[r,i]=(0,Y.useState)(!1),a=Math.max(0,e.length-5),o=r&&a>0,s=o?e:e.slice(0,5);return(0,Y.useEffect)(()=>{e.length<=5&&i(!1)},[e.length]),e.length<=1?null:(0,X.jsxs)(`div`,{className:`collaboration-presence collaboration-${t}`,children:[(0,X.jsx)(`span`,{className:`collaboration-status-dot`,"data-tooltip":n(`editor.collaboration.${t}`),"aria-label":n(`editor.collaboration.${t}`)}),(0,X.jsxs)(`div`,{className:`collaboration-avatars`,"aria-label":n(`editor.collaboration.activeSessions`,{count:e.length}),children:[s.map(e=>{let t=e.editing?n(`editor.collaboration.editing`):n(`editor.collaboration.viewing`),r=e.permission===`read`?n(`common.readOnly`):n(`common.readWrite`),i=n(`editor.collaboration.sessionTooltip`,{name:e.name,username:e.username,file:e.filePath||n(`editor.collaboration.joining`),activity:t,permission:r});return(0,X.jsxs)(`span`,{className:`collaboration-avatar${e.editing?` editing`:``}${e.local?` local`:``}`,style:{"--session-color":e.color},"aria-label":i,tabIndex:0,children:[(0,X.jsx)(oe,{userId:e.userId,name:e.name,username:e.username,avatarStyle:e.avatarStyle,className:`collaboration-avatar-face`}),(0,X.jsxs)(`span`,{className:`collaboration-avatar-tooltip`,role:`tooltip`,children:[(0,X.jsx)(`strong`,{children:e.name}),(0,X.jsxs)(`span`,{children:[`@`,e.username]}),(0,X.jsxs)(`small`,{children:[e.filePath||n(`editor.collaboration.joining`),` · `,t,` · `,r]})]})]},e.clientId)}),a>0&&(0,X.jsx)(`button`,{type:`button`,className:`collaboration-avatar collaboration-avatar-overflow`,"aria-expanded":o,"aria-label":o?n(`editor.collaboration.showFewerSessions`):n(`editor.collaboration.showMoreSessions`,{count:a}),title:o?n(`editor.collaboration.showFewerSessions`):n(`editor.collaboration.showMoreSessions`,{count:a}),onClick:()=>i(e=>!e),children:o?`−`:`+${a}`})]})]})}function Ey({value:e,onChange:t}){let{t:n}=Ae(),[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),o=[{value:`editor-pdf`,icon:Ct},{value:`editor-only`,icon:cn},{value:`pdf-only`,icon:un}];return(0,Y.useEffect)(()=>{if(!r)return;let e=e=>{a.current?.contains(e.target)||i(!1)},t=e=>{e.key===`Escape`&&i(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[r]),(0,X.jsxs)(`div`,{className:`layout-menu`,ref:a,children:[(0,X.jsxs)(`button`,{type:`button`,className:`layout-trigger${r?` active`:``}`,"aria-haspopup":`menu`,"aria-expanded":r,title:n(`editor.layout.current`,{layout:n(`editor.layout.${e}.name`)}),onClick:()=>i(e=>!e),children:[(0,X.jsx)(Ct,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`small`,{children:n(`editor.layout.label`)}),n(`editor.layout.${e}.name`)]}),(0,X.jsx)(de,{size:13})]}),r&&(0,X.jsxs)(`div`,{className:`layout-popover`,role:`menu`,"aria-label":n(`editor.layout.label`),children:[(0,X.jsx)(`div`,{className:`layout-popover-title`,children:n(`editor.layout.choose`)}),o.map(r=>{let a=r.icon,o=r.value===e;return(0,X.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":o,className:`layout-option${o?` selected`:``}`,onClick:()=>{t(r.value),i(!1)},children:[(0,X.jsx)(a,{size:19}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:n(`editor.layout.${r.value}.name`)}),(0,X.jsx)(`small`,{children:n(`editor.layout.${r.value}.description`)})]}),o&&(0,X.jsx)(ge,{size:16})]},r.value)})]})]})}function Dy({site:e,project:t,activeFile:n,saveStateLabel:r,editorPreferences:i,activeSessions:a,collaborationStatus:o,reconnectCollaboration:s,protocolUpgradeRequired:c,showEditor:l,filesCollapsed:u,toggleFilesPanel:f,workspaceLayout:p,changeWorkspaceLayout:m,onBack:h,onShare:g,showCitationLibrary:_,citationLibraryOpen:v,onCitationLibrary:y,onHistory:b,onGit:x,canManageGit:S,formatting:C,readOnly:w,collaborationSynced:O,onToggleComments:k,commentsOpen:A,unresolvedCommentCount:j,onToggleSettings:M,settingsOpen:te,compileBusy:ne,sharedCompiling:P,localCompiling:re,cancelling:ie,onCompile:oe,onCancelCompile:se,agentTerminal:F}){let{t:I}=Ae(),{showExecutionReminder:le}=ce();return(0,X.jsxs)(`header`,{className:`editor-topbar`,children:[(0,X.jsx)(`button`,{className:`back`,title:I(`editor.backToProjects`),"aria-label":I(`editor.backToProjects`),onClick:h,children:(0,X.jsx)(ae,{size:18})}),(0,X.jsx)(`a`,{className:`brand-link compact-brand-link`,href:d(`/`),"aria-label":e.siteName,onClick:e=>{e.preventDefault(),h()},children:(0,X.jsx)(Ee,{siteName:e.siteName,compact:!0})}),(0,X.jsxs)(`div`,{className:`project-heading`,children:[(0,X.jsx)(`strong`,{children:t.name}),(0,X.jsxs)(`small`,{children:[n,` · `,r]})]}),i.vimMode&&(0,X.jsxs)(`span`,{className:`vim-status-badge`,title:I(`editor.vimOnHint`),children:[(0,X.jsx)(Gt,{size:14}),I(`editor.vimOn`)]}),(0,X.jsx)(Ty,{sessions:a,status:o}),o===`disconnected`&&!c&&(0,X.jsxs)(`div`,{className:`collaboration-recovery`,role:`status`,children:[(0,X.jsx)(`span`,{children:I(`editor.collaboration.disconnected`)}),(0,X.jsx)(`button`,{type:`button`,onClick:s,children:I(`editor.collaboration.reconnect`)})]}),(0,X.jsxs)(`div`,{className:`editor-actions`,children:[l&&(0,X.jsxs)(`button`,{className:u?``:`active`,onClick:f,children:[u?(0,X.jsx)(on,{size:15}):(0,X.jsx)(rn,{size:15}),I(`common.files`)]}),(0,X.jsx)(Ey,{value:p,onChange:m}),(0,X.jsxs)(`button`,{onClick:g,children:[(0,X.jsx)(D,{size:15}),I(`projectSettings.share`)]}),_&&(0,X.jsxs)(`button`,{className:v?`active`:``,onClick:y,children:[(0,X.jsx)(V,{size:15}),I(`citationLibrary.title`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`snapshots-action`,title:I(`history.projectSnapshots`),onClick:b,children:[(0,X.jsx)(Dt,{size:15}),I(`history.projectSnapshotsButton`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`comments-action${A?` active`:``}`,title:I(`editor.commentsAll`),"aria-label":j>0?`${I(`common.comments`)} (${j})`:I(`common.comments`),onClick:k,children:[(0,X.jsx)(ee,{size:15}),(0,X.jsx)(`span`,{children:I(`common.comments`)}),j>0&&(0,X.jsx)(`sup`,{className:`comments-action-count`,children:j})]}),(0,X.jsxs)(`button`,{className:`git-action`,title:I(S?`git.title`:`git.ownerOnly`),disabled:!S,onClick:x,children:[(0,X.jsx)(N,{size:15}),`Git`]}),F&&(0,X.jsxs)(`button`,{type:`button`,className:F.open?`active`:``,"aria-expanded":F.open,"aria-label":le&&F.activeCount>0?`${I(`agents.terminal`)}: ${I(`agents.activeCount`,{count:F.activeCount})}`:I(`agents.terminal`),onClick:F.toggle,children:[(0,X.jsx)(T,{size:15}),(0,X.jsx)(`span`,{children:I(`agents.terminal`)}),le&&F.activeCount>0&&(0,X.jsx)(`sup`,{className:`agent-active-count`,"aria-label":I(`agents.activeCount`,{count:F.activeCount}),children:F.activeCount})]}),(0,X.jsxs)(`button`,{className:te?`active`:``,onClick:M,children:[(0,X.jsx)(vn,{size:15}),I(`common.settings`)]}),P||re?(0,X.jsxs)(`button`,{className:`compile cancel-compile`,title:I(`compileControls.cancel`),onClick:se,disabled:ie||C||w||!O,children:[ie?(0,X.jsx)(Fe,{className:`spin`,size:15}):(0,X.jsx)(E,{size:15}),I(ie?`compileControls.cancelling`:`compileControls.cancel`)]}):(0,X.jsxs)(`button`,{className:`compile`,title:I(`editor.compileShortcut`),onClick:oe,disabled:ne||C||w||!O,children:[ne?(0,X.jsx)(Fe,{className:`spin`,size:15}):(0,X.jsx)(fn,{size:15}),I(`editor.compile`,{engine:t.engine})]})]})]})}function Oy(e,t,n){return e===`connected`?t:e===`disconnected`&&n?`editor.offlineDraft`:`editor.collaboration.${e}`}function ky(e){return`${e.path}\u0000${e.line}`}function Ay(e){let t=[],n=[];for(let r of e){for(;n.length&&n.at(-1).level>=r.level;)n.pop();let e=n.at(-1);e&&(t[e.index].hasChildren=!0),t.push({item:r,key:ky(r),ancestorKeys:n.map(({index:e})=>t[e].key),hasChildren:!1}),n.push({level:r.level,index:t.length-1})}return t}function jy(e,t){return e.filter(e=>!e.ancestorKeys.some(e=>t.has(e)))}var My=e=>e.path,Ny=(e,t)=>t===e||t.startsWith(`${e}/`),Py=`application/x-texlite-project-path`,Fy=`texlite-path:`;function Iy({project:e,filesPanel:t,visibleEntries:n,deletedPath:r=null,activeFile:i,activeMainFile:a,selectedFile:o,selectedFolder:s,expandedFolders:c,fileDragActive:l,uploadingFiles:u,uploadFeedback:f,readOnly:p,formatting:h,canFormat:g,activeFormatLease:_,collaborationSynced:v,editorFontSize:x,outline:w,sourceCursorStore:T,wordCountBusy:D,hasSelection:A,hasFormatSelection:j,uploadInput:M,setSelectedFolder:N,setExpandedFolders:ee,setMoveEntry:ne,setMoveName:P,setMoveDestination:re,setDeleteEntry:ie,setFileDialogError:ae,setNewFolderName:oe,setNewFolderOpen:se,setNewFilePath:ce,setNewFileOpen:I,setQuickOpen:le,setFileDragActive:L,dismissUploadFeedback:R,setFilesCollapsed:z,uploadFiles:V,upload:ue,openFile:fe,movePathToFolder:pe,onError:me,onFormatFile:he,onFormatSelection:ge,jumpToSource:_e,syncSourceToPdf:ve,onWordCount:ye}){let{t:U}=Ae(),[be,W]=(0,Y.useState)(!1),[G,xe]=(0,Y.useState)(null),[Se,K]=(0,Y.useState)(null),{entries:Ce,finishExit:we}=F(n,{scopeKey:JSON.stringify([e.id,[...c].sort()]),deletedKey:r,keyOf:My,contains:Ny,duration:180}),Te=(0,Y.useRef)(0),Ee=(e,t)=>zy(e.path)!==t&&(e.type!==`directory`||t!==e.path&&!t.startsWith(`${e.path}/`)),De=()=>{xe(null),K(null)};return(0,X.jsx)(wm,{id:`files`,panelRef:t,defaultSize:`16%`,minSize:`12%`,maxSize:`30%`,collapsible:!0,collapsedSize:`0%`,onResize:e=>z(e.asPercentage===0),children:(0,X.jsxs)(`aside`,{className:`left-panel`,children:[(0,X.jsxs)(`section`,{className:`files-panel${l?` drop-active`:``}`,onDragEnter:e=>{Ry(e.dataTransfer)?e.preventDefault():e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),!p&&!u&&L(!0))},onDragOver:e=>{Ry(e.dataTransfer)?(e.preventDefault(),e.dataTransfer.dropEffect=`move`):e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=p||u?`none`:`copy`)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||L(!1)},onDrop:e=>{if(Ry(e.dataTransfer)){e.preventDefault(),e.stopPropagation();return}if(e.preventDefault(),L(!1),p||u)return;let t=Array.from(e.dataTransfer.files);Ly(e.dataTransfer)||t.length===0?me(U(`editor.dropFoldersUnsupported`)):V(t)},children:[(0,X.jsxs)(`div`,{className:`panel-title`,children:[(0,X.jsx)(`button`,{className:`file-size-toggle`,type:`button`,"aria-pressed":be,title:U(be?`editor.hideFileSizes`:`editor.showFileSizes`),onClick:()=>W(e=>!e),children:U(`common.files`)}),(0,X.jsxs)(`span`,{className:`file-tools`,children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":U(`navigation.quickOpen`),title:`${U(`navigation.quickOpen`)} (Ctrl/Cmd+P)`,onClick:()=>le(!0),children:(0,X.jsx)(C,{size:15})}),!p&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:u,"aria-label":U(`editor.uploadAttachment`),title:U(`editor.uploadTo`,{folder:s||U(`editor.projectRoot`)}),onClick:()=>M.current?.click(),children:(0,X.jsx)(O,{size:15})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":U(`editor.newFolder`),title:U(`editor.newFolder`),onClick:()=>{oe(``),se(!0)},children:(0,X.jsx)(te,{size:15})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":U(`editor.newFile`),title:U(`editor.newFile`),onClick:()=>{ce(s?`${s}/`:``),I(!0)},children:(0,X.jsx)(Ft,{size:15})}),(0,X.jsx)(`input`,{ref:M,type:`file`,multiple:!0,hidden:!0,onChange:e=>void ue(e)})]})]})]}),f&&(0,X.jsxs)(`div`,{className:`file-upload-feedback ${f.kind}`,role:f.kind===`error`?`alert`:`status`,"aria-live":f.kind===`error`?`assertive`:`polite`,"aria-busy":f.kind===`uploading`,children:[f.kind===`uploading`?(0,X.jsx)(Fe,{className:`spin`,size:14}):f.kind===`success`?(0,X.jsx)(H,{size:14}):(0,X.jsx)(y,{size:14}),(0,X.jsxs)(`span`,{className:`file-upload-feedback-text`,children:[f.kind===`uploading`&&U(`editor.uploadingFile`,{file:f.fileName,current:f.current,total:f.total}),f.kind===`success`&&U(`editor.uploadSucceeded`,{count:f.count}),f.kind===`error`&&f.message]}),f.kind!==`uploading`&&(0,X.jsx)(`button`,{type:`button`,className:`file-upload-feedback-dismiss`,"aria-label":U(`common.close`),title:U(`common.close`),onClick:R,children:(0,X.jsx)(E,{size:13})})]}),l&&(0,X.jsxs)(`div`,{className:`file-drop-overlay`,children:[(0,X.jsx)(O,{size:24}),(0,X.jsx)(`strong`,{children:U(`editor.dropFiles`)}),(0,X.jsx)(`span`,{children:U(`editor.uploadTo`,{folder:s||U(`editor.projectRoot`)})})]}),(0,X.jsx)(`div`,{className:`file-list${s===null?``:` folder-selected`}${Se===``?` root-drop-target`:``}`,style:{fontSize:`${x}px`},onDragOver:e=>{(G||Ry(e.dataTransfer))&&(e.preventDefault(),e.stopPropagation(),G&&(Ee(G,``)?(e.dataTransfer.dropEffect=`move`,K(``)):e.dataTransfer.dropEffect=`none`))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||K(e=>e===``?null:e)},onDrop:e=>{if(!G&&!Ry(e.dataTransfer)||(e.preventDefault(),e.stopPropagation(),!G))return;let t=G;De(),Ee(t,``)&&pe(t,``)},children:Ce.map(({item:t,removeAt:n})=>{let r=t.path.split(`/`).length-1,i=t.path.split(`/`).at(-1),a=c.has(t.path),l=e.mainFile===t.path,u=t.path!==e.mainFile&&!e.mainFile.startsWith(`${t.path}/`),f={ref:n===null?void 0:B,inert:n!==null||void 0,"aria-hidden":n!==null||void 0,"data-deletion-exit":n!==null||void 0,onAnimationEnd:e=>{e.target===e.currentTarget&&n!==null&&we(t.path)}};return t.type===`directory`?(0,Y.createElement)(`div`,{...f,className:`file-entry folder-entry${s===t.path?` selected`:``}${Se===t.path?` move-drop-target`:``}`,style:{paddingLeft:`${r*13+5}px`},key:t.path,onDragOver:e=>{(G||Ry(e.dataTransfer))&&(e.preventDefault(),e.stopPropagation(),G&&(Ee(G,t.path)?(e.dataTransfer.dropEffect=`move`,K(t.path)):e.dataTransfer.dropEffect=`none`))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||K(e=>e===t.path?null:e)},onDrop:e=>{if(!G&&!Ry(e.dataTransfer)||(e.preventDefault(),e.stopPropagation(),!G))return;let n=G;De(),Ee(n,t.path)&&pe(n,t.path)}},(0,X.jsxs)(`button`,{type:`button`,className:`file-entry-main`,onClick:()=>{N(t.path),ee(e=>{let n=new Set(e);return n.has(t.path)?n.delete(t.path):n.add(t.path),n})},children:[a?(0,X.jsx)(de,{size:13}):(0,X.jsx)(m,{size:13}),(0,X.jsx)(b,{size:14}),(0,X.jsx)(`span`,{children:i})]}),!p&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action`,title:U(`editor.move`),"aria-label":U(`editor.move`),onClick:()=>{ne(t),P(i??``),re(``)},children:(0,X.jsx)($t,{size:13})}),u&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action danger-text`,title:U(`editor.deletePath`),"aria-label":U(`editor.deletePath`),onClick:()=>{ie(t),ae(``)},children:(0,X.jsx)(S,{size:13})})]})):(0,Y.createElement)(`div`,{...f,className:`file-entry${s===null&&o===t.path?` active`:``}${G?.path===t.path?` move-drag-source`:``}`,style:{paddingLeft:`${r*13+18}px`},key:t.path},(0,X.jsxs)(`button`,{type:`button`,className:`file-entry-main`,draggable:!p,onDragStart:e=>{Te.current=Date.now()+500,By(e,t,xe)},onDragEnd:De,onClick:()=>{Te.current>Date.now()?Te.current=0:fe(t)},children:[(0,X.jsx)(zn,{path:t.path}),(0,X.jsx)(`span`,{children:i}),l&&(0,X.jsx)(`small`,{children:U(`editor.currentMainShort`)})]}),be&&typeof t.size==`number`&&(0,X.jsx)(`span`,{className:`file-entry-size`,children:Hy(t.size)}),!p&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action`,title:U(`editor.move`),"aria-label":U(`editor.move`),onClick:()=>{ne(t),P(i??``),re(``)},children:(0,X.jsx)($t,{size:13})}),(0,X.jsx)(`a`,{className:`file-entry-action`,href:d(`/api/projects/${e.id}/file/raw?path=${encodeURIComponent(t.path)}&download=1`),download:i,draggable:!1,title:U(`editor.downloadResource`),"aria-label":U(`editor.downloadResource`),onClick:e=>e.stopPropagation(),children:(0,X.jsx)(k,{size:13})}),!p&&u&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action danger-text`,title:U(`editor.deletePath`),"aria-label":U(`editor.deletePath`),onClick:()=>{ie(t),ae(``)},children:(0,X.jsx)(S,{size:13})}))})}),!p&&g&&(0,X.jsxs)(`div`,{className:`file-format-footer`,role:`group`,"aria-label":U(`editor.format`),"aria-busy":h,children:[(0,X.jsxs)(`div`,{className:`file-format-label`,children:[(0,X.jsx)(bn,{size:13}),U(`editor.format`)]}),(0,X.jsxs)(`div`,{className:`file-format-actions`,children:[(0,X.jsx)(`button`,{className:j?``:`active`,type:`button`,title:U(`editor.formatFileHint`),onMouseDown:e=>e.preventDefault(),onClick:he,disabled:h||_||!v,children:U(`editor.formatFile`)}),(0,X.jsx)(`button`,{className:j?`active`:``,type:`button`,title:U(j?`editor.formatSelection`:`editor.formatSelectionHint`),onMouseDown:e=>e.preventDefault(),onClick:ge,disabled:h||_||!v||!j,children:U(`editor.formatSelected`)})]})]})]}),(0,X.jsx)(Vy,{outline:w,activeFile:i,activeMainFile:a,sourceCursorStore:T,wordCountBusy:D,hasSelection:A,jumpToSource:_e,syncSourceToPdf:ve,onWordCount:ye})]})})}function Ly(e){return Array.from(e.items).some(e=>e.webkitGetAsEntry?.()?.isDirectory===!0)}function Ry(e){return Array.from(e.types).includes(Py)?!0:Array.from(e.types).includes(`text/plain`)&&e.getData(`text/plain`).startsWith(Fy)}function zy(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function By(e,t,n){e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(Py,t.path),e.dataTransfer.setData(`text/plain`,`${Fy}${t.path}`),n(t)}function Vy({outline:e,activeFile:t,activeMainFile:n,sourceCursorStore:r,wordCountBusy:i,hasSelection:a,jumpToSource:o,syncSourceToPdf:s,onWordCount:c}){let{t:l}=Ae(),u=(0,Y.useSyncExternalStore)(r.subscribe,r.getOutlineLine,r.getOutlineLine),d=(0,Y.useMemo)(()=>Ay(e),[e]),f=(0,Y.useMemo)(()=>d.filter(e=>e.hasChildren).map(e=>e.key),[d]),[p,h]=(0,Y.useState)(()=>new Set);(0,Y.useEffect)(()=>{let e=new Set(f);h(t=>{let n=new Set([...t].filter(t=>e.has(t)));return n.size===t.size?t:n})},[f]);let g=f.length>0&&f.every(e=>p.has(e)),_=(0,Y.useMemo)(()=>jy(d,p),[d,p]),v=()=>h(e=>g?new Set([...e].filter(e=>!f.includes(e))):new Set([...e,...f])),y=e=>h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,X.jsxs)(`section`,{className:`outline-panel`,children:[(0,X.jsxs)(`div`,{className:`panel-title`,children:[(0,X.jsxs)(`button`,{className:`outline-heading`,type:`button`,"aria-expanded":!g,title:l(g?`editor.expandOutline`:`editor.collapseOutline`),onClick:v,disabled:f.length===0,children:[(0,X.jsx)(x,{size:14}),l(`common.outline`)]}),(0,X.jsxs)(`span`,{className:`word-count-actions`,role:`group`,"aria-label":l(`editor.wordCountTitle`),children:[(0,X.jsxs)(`button`,{type:`button`,title:l(`editor.wordCountFullHint`),onClick:()=>c(`full`),disabled:i||!n,children:[i?(0,X.jsx)(Fe,{className:`spin`,size:12}):(0,X.jsx)(Ut,{size:12}),l(`editor.wordCountFull`)]}),(0,X.jsxs)(`button`,{type:`button`,title:l(`editor.wordCountSelectionHint`),onClick:()=>c(`selection`),disabled:i||!a,children:[i?(0,X.jsx)(Fe,{className:`spin`,size:12}):(0,X.jsx)(Ut,{size:12}),l(`editor.wordCountSelection`)]})]})]}),(0,X.jsxs)(`div`,{className:`outline`,children:[_.map(e=>{let{item:r}=e,i=p.has(e.key),a=t===r.path&&u===r.line,c=r.path===n||r.path===t;return(0,X.jsxs)(`div`,{className:`outline-row${a?` current`:``}`,children:[(0,X.jsx)(`span`,{className:`outline-guides`,"aria-hidden":!0,style:{width:`${r.level*12}px`}}),e.hasChildren?(0,X.jsx)(`button`,{className:`outline-toggle`,type:`button`,"aria-label":l(i?`editor.expandOutlineItem`:`editor.collapseOutlineItem`,{title:r.title}),"aria-expanded":!i,onClick:()=>y(e.key),children:i?(0,X.jsx)(m,{size:13}):(0,X.jsx)(de,{size:13})}):(0,X.jsx)(`span`,{className:`outline-toggle-spacer`,"aria-hidden":!0}),(0,X.jsxs)(`button`,{className:`outline-item`,type:`button`,onClick:()=>{o(r.path,r.line,1),s(r.path,r.line,1)},children:[(0,X.jsx)(`small`,{children:c?r.line:r.path.split(`/`).at(-1)}),(0,X.jsx)(`span`,{className:`outline-title`,children:r.title})]})]},e.key)}),e.length===0&&(0,X.jsx)(`p`,{className:`muted padded`,children:l(`editor.noOutline`)})]})]})}function Hy(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function Uy({children:e,tabs:t,terminal:n}){let{t:r}=Ae(),i=Em(),[a,o]=(0,Y.useState)(!1),s=!!n,c=(0,Y.useRef)(s),l=s&&a;return(0,Y.useLayoutEffect)(()=>{c.current&&!s&&i.current?.resize(`100%`),c.current=s},[i,s]),(0,X.jsx)(`main`,{className:`source-panel`,children:(0,X.jsxs)(vm,{orientation:`vertical`,className:`agent-editor-group`,children:[(0,X.jsx)(wm,{id:`source-editor`,panelRef:i,minSize:`20%`,collapsible:!!n,collapsedSize:`0%`,onResize:e=>o(e.asPercentage===0),children:(0,X.jsxs)(`div`,{className:`source-editor-pane`,inert:l,children:[t,e]})}),n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(km,{className:`agent-terminal-resizer`,"aria-label":r(`agents.resizeTerminal`)}),(0,X.jsx)(wm,{id:`agent-terminal`,defaultSize:`35%`,minSize:`20%`,children:n({maximized:l,toggleMaximized:()=>{let e=i.current;e?.isCollapsed()?e.expand():e?.collapse()}})})]})]})})}var Wy=(0,Y.lazy)(()=>f(()=>import(`./LatexEditor-BhAKioho.js`).then(e=>({default:e.LatexEditor})),__vite__mapDeps([10,2,3,7,11,6,1,4,5,8,12]),import.meta.url));function Gy({project:e,activeFile:t,openTabs:n,content:r,loadedFile:i,readOnly:a,comments:o,focusComment:s,editorPreferences:c,completionIndex:l,nativeSpellCheck:u,spellCheckIssues:d,spellCheckJump:f,sourceJump:p,collaborativeText:m,collaborationAwareness:h,undoManager:g,editorNotice:_,activateTab:v,closeTab:y,handleTabKeyDown:b,updateEditorContent:x,setSelection:S,onAddComment:C,onSelectionHistory:T,onCommentClick:D,onSpellCheckReplace:O,onReferenceNavigate:k,onCursor:A,terminal:j}){let{t:M}=Ae(),N=p_(o,t),ee=m_(s,t,i);return(0,X.jsx)(wm,{id:`source`,minSize:`22%`,children:(0,X.jsx)(Uy,{terminal:j,tabs:c.openFilesInTabs&&n.length>0&&(0,X.jsx)(`div`,{className:`editor-tabs-bar`,role:`tablist`,"aria-label":M(`editor.openFiles`),children:(0,X.jsx)(`div`,{className:`editor-tabs-scroll`,children:n.map((n,r)=>{let i=n===t,a=n===e.mainFile,o=n.split(`/`).at(-1)||n;return(0,X.jsxs)(`div`,{className:`editor-tab-item${i?` active`:``}`,role:`presentation`,children:[(0,X.jsxs)(`button`,{id:`editor-tab-${encodeURIComponent(n)}`,type:`button`,role:`tab`,"aria-selected":i,"aria-controls":`editor-source-content`,tabIndex:i?0:-1,className:`editor-tab${i?` active`:``}${a?` main-tab`:``}`,onClick:()=>v(n),onKeyDown:e=>b(e,r),title:n,children:[(0,X.jsx)(`span`,{className:`editor-tab-icon`,children:a?(0,X.jsx)(L,{size:13}):(0,X.jsx)(w,{size:13})}),(0,X.jsx)(`span`,{className:`editor-tab-title`,children:o}),a&&(0,X.jsx)(`small`,{className:`editor-tab-badge`,children:M(`editor.currentMainShort`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`editor-tab-close`,title:M(`common.close`),"aria-label":`${M(`common.close`)} ${o}`,onClick:()=>y(n),children:(0,X.jsx)(E,{size:12})})]},n)})})}),children:(0,X.jsxs)(`div`,{id:`editor-source-content`,className:`editor-content-container`,children:[(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`preview-empty`,children:[(0,X.jsx)(Fe,{className:`spin`,size:22}),(0,X.jsx)(`span`,{children:M(`common.loading`)})]}),children:(0,X.jsx)(Wy,{value:r,filePath:t,readOnly:a,comments:N,focusComment:ee,preferences:c,nativeSpellCheck:u,completionIndex:l,spellCheckIssues:d,spellCheckJump:f,jumpTo:i===t&&p?.path===t?p:null,searchRequest:0,collaboration:m?{text:m,awareness:h,undoManager:a?void 0:g}:void 0,onChange:x,onSelection:S,onAddComment:C,onSelectionHistory:T,onCommentClick:D,onSpellCheckReplace:O,onReferenceNavigate:k,onCursor:A},t)}),_&&(0,X.jsx)(`div`,{className:`editor-centered-notice`,role:`status`,"aria-live":`polite`,children:_})]})})})}var Ky=t(r(),1);function qy({children:e,showControls:t=!0}){let[n,r]=(0,Y.useState)(null),[i,a]=(0,Y.useState)(null);return(0,Y.useLayoutEffect)(()=>{if(!n||!t)return;let e=()=>{let e=n.getBoundingClientRect(),t=e.left+e.width/2,r=e.top+e.height/2;a(e=>e?.left===t&&e.top===r?e:{left:t,top:r})},r=new ResizeObserver(e);r.observe(n);let i=n.parentElement;if(i){r.observe(i);for(let e of i.children)e.hasAttribute(`data-panel`)&&r.observe(e)}return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),e(),()=>{r.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[n,t]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(km,{className:`resize-handle sync-resize-handle`,elementRef:r,children:(0,X.jsx)(Vt,{className:`resize-grip`,size:12})}),t&&i&&(0,Ky.createPortal)((0,X.jsx)(`span`,{className:`sync-direction-buttons`,style:{position:`fixed`,...i},children:e}),document.body)]})}function Jy({diagnostics:e,files:t,empty:n,tone:r,onJump:i}){let{t:a}=Ae(),o=r===`error`?xt:y;return e.length?(0,X.jsx)(`div`,{className:`compile-diagnostic-list compile-${r}`,children:e.map((e,n)=>{let r=Qy(e.file,t),s=!!(r&&e.line);return(0,X.jsxs)(`button`,{type:`button`,disabled:!s,className:`compile-diagnostic-row`,onClick:()=>{r&&e.line&&i(r,e.line,e.column??1)},children:[(0,X.jsx)(o,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.message}),(0,X.jsxs)(`small`,{children:[e.phase,r?` · ${r}${e.line?`:${e.line}`:``}`:e.line?` · ${a(`editor.lineNumber`,{line:e.line})}`:``]})]})]},`${e.phase}-${e.file??``}-${e.line??0}-${n}`)})}):(0,X.jsxs)(`div`,{className:`compile-empty compile-${r}`,children:[(0,X.jsx)(o,{size:26}),(0,X.jsx)(`span`,{children:n})]})}function Yy({lines:e,empty:t,tone:n=`log`}){let r=n===`error`?xt:n===`warning`?y:A;return e.length?(0,X.jsx)(`pre`,{className:`compile-output compile-${n}`,children:e.join(`
16
+ `)}):(0,X.jsxs)(`div`,{className:`compile-empty compile-${n}`,children:[(0,X.jsx)(r,{size:26}),(0,X.jsx)(`span`,{children:t})]})}function Xy({projectId:e,mainFile:t,artifacts:n,preview:r,loading:i,onView:a}){let{t:o}=Ae(),s=n=>d(`/api/projects/${e}/compile/artifacts?mainFile=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}&download=1`);return n.length?(0,X.jsxs)(`div`,{className:`artifact-browser`,children:[(0,X.jsx)(`div`,{className:`artifact-list`,children:n.map(e=>(0,X.jsxs)(`div`,{className:`artifact-row${r?.path===e.path?` active`:``}`,children:[(0,X.jsxs)(`button`,{type:`button`,disabled:!e.viewable,title:e.viewable?o(`editor.viewArtifact`):o(`editor.downloadToView`),onClick:()=>a(e),children:[(0,X.jsx)(zn,{path:e.path,size:14}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.path}),(0,X.jsx)(`small`,{children:$y(e.size)})]})]}),(0,X.jsx)(`a`,{href:s(e.path),title:o(`editor.downloadArtifact`),"aria-label":o(`editor.downloadArtifact`),children:(0,X.jsx)(k,{size:14})})]},e.path))}),(0,X.jsx)(`div`,{className:`artifact-preview`,children:i?(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(Fe,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:o(`common.loading`)})]}):r?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`header`,{children:[(0,X.jsx)(`strong`,{children:r.path}),(0,X.jsxs)(`a`,{href:s(r.path),children:[(0,X.jsx)(k,{size:13}),o(`projects.download`)]})]}),(0,X.jsx)(`pre`,{children:r.content})]}):(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(w,{size:24}),(0,X.jsx)(`span`,{children:o(`editor.selectArtifact`)})]})})]}):(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(tn,{size:26}),(0,X.jsx)(`span`,{children:o(`editor.noArtifacts`)})]})}function Zy({mainFile:e,disabled:t,cleaning:n,onCleanCache:r,onCleanArtifacts:i}){let{t:a}=Ae();return(0,X.jsxs)(`div`,{className:`compile-clean-panel`,children:[(0,X.jsxs)(`div`,{className:`compile-clean-intro`,children:[(0,X.jsx)(y,{size:28}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`strong`,{children:a(`editor.cleanTitle`)}),(0,X.jsx)(`p`,{children:a(`editor.cleanDescription`,{file:e})})]})]}),(0,X.jsxs)(`div`,{className:`compile-clean-actions`,children:[(0,X.jsxs)(`article`,{children:[(0,X.jsx)(`div`,{className:`compile-clean-action-icon`,children:(0,X.jsx)(Tt,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`compile-clean-action-heading`,children:[(0,X.jsx)(`strong`,{children:a(`editor.cleanCache`)}),(0,X.jsx)(`button`,{type:`button`,className:`compile-clean-help`,"aria-label":a(`editor.cleanCacheDescription`),"data-tooltip":a(`editor.cleanCacheDescription`),"data-texlite-tooltip-always":!0,children:(0,X.jsx)(yt,{size:13,"aria-hidden":`true`})})]}),(0,X.jsxs)(`button`,{type:`button`,className:`compile-clean-operation`,disabled:t||n,onClick:r,children:[n?(0,X.jsx)(Fe,{className:`spin`,size:14}):(0,X.jsx)(Tt,{size:14}),a(`editor.cleanCache`)]})]})]}),(0,X.jsxs)(`article`,{className:`danger`,children:[(0,X.jsx)(`div`,{className:`compile-clean-action-icon`,children:(0,X.jsx)(S,{size:19})}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`compile-clean-action-heading`,children:[(0,X.jsx)(`strong`,{children:a(`editor.cleanArtifacts`)}),(0,X.jsx)(`button`,{type:`button`,className:`compile-clean-help`,"aria-label":a(`editor.cleanArtifactsDescription`),"data-tooltip":a(`editor.cleanArtifactsDescription`),"data-texlite-tooltip-always":!0,children:(0,X.jsx)(yt,{size:13,"aria-hidden":`true`})})]}),(0,X.jsxs)(`button`,{type:`button`,className:`compile-clean-operation danger`,disabled:t||n,onClick:i,children:[n?(0,X.jsx)(Fe,{className:`spin`,size:14}):(0,X.jsx)(S,{size:14}),a(`editor.cleanArtifacts`)]})]})]})]})]})}function Qy(e,t){if(!e)return null;let n=t.filter(e=>e.type===`file`).map(e=>e.path),r=e.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(n.includes(r))return r;let i=n.filter(e=>r.endsWith(`/${e}`));if(i.length===1)return i[0];let a=r.split(`/`).at(-1),o=n.filter(e=>e.split(`/`).at(-1)===a);return o.length===1?o[0]:null}function $y(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}var eb=(0,Y.lazy)(()=>Pe().then(e=>({default:e.PdfPreview})));function tb({commentsOpen:e=!1,onCommentsHost:t,projectId:n,activeMainFile:r,previewTab:i,diagnosticTab:a,pdfUrl:o,pdfLoadingMode:s,pdfLoading:c,pdfCompiledAt:u,pdfSizeBytes:d,pdfCompiledLabel:f,pdfTargetLabel:p,pdfDownloadUrl:m,pdfTarget:h,pdfViewport:g,activeFile:_,compileBusy:v,compileLog:b,compileDiagnostics:x,compileMessages:S,artifacts:C,artifactPreview:w,artifactLoading:T,cleaning:E,readOnly:D,collaborationSynced:O,workspaceLayout:j,showSyncResize:M,diagnosticCount:N,selectPreviewTab:ee,changeWorkspaceLayout:te,onSetPdfViewport:ne,onResetPdfViewport:P,onPdfDisplayed:re,syncVisiblePdfToSource:ie,syncCurrentSourceToPdf:ae,syncPdfToSource:oe,canSyncWithPdf:se,canSyncPdfToSource:ce,files:F,jumpToSource:I,onSetCleanMode:le,viewArtifact:L}){let{t:R}=Ae(),[z,B]=(0,Y.useState)(``),V=(0,Y.useRef)(``),ue=e=>{V.current!==e&&(V.current=e,B(e),P(),re(e))},de=ce&&!!o&&z===o,fe=[d==null?``:nb(d),f?R(`editor.pdfUpdatedAt`,{time:f}):``].filter(Boolean).join(` · `);return(0,X.jsxs)(X.Fragment,{children:[M&&(0,X.jsxs)(qy,{showControls:!e,children:[(0,X.jsx)(`button`,{disabled:!o||!g||!de,title:R(ce?de?`editor.showInSource`:`editor.syncTexWaitingForPdf`:`editor.syncTexOnlyForMain`),"aria-label":R(`editor.showInSource`),onClick:e=>{e.stopPropagation(),de&&ie()},children:(0,X.jsx)(`span`,{"aria-hidden":!0,children:`←`})}),(0,X.jsx)(`button`,{disabled:!_||!o||!se,title:R(se?`editor.showInPdf`:`editor.syncTexOnlyForTex`),"aria-label":R(`editor.showInPdf`),onClick:e=>{e.stopPropagation(),_&&o&&se&&ae()},children:(0,X.jsx)(`span`,{"aria-hidden":!0,children:`→`})})]}),(0,X.jsx)(wm,{id:`preview`,minSize:`22%`,children:(0,X.jsx)(`div`,{className:`workspace-preview-region`,children:(0,X.jsxs)(`div`,{className:`workspace-output-layout${e?` has-comments`:``}`,children:[(0,X.jsx)(`div`,{ref:t,className:`workspace-comments-slot`,hidden:!e}),(0,X.jsxs)(`section`,{className:`preview-panel`,children:[(0,X.jsxs)(`div`,{className:`preview-tabs`,children:[(0,X.jsxs)(`div`,{className:`preview-tab-list`,role:`tablist`,"aria-label":R(`editor.outputTabs`),children:[(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":i===`pdf`,className:`pdf-tab${i===`pdf`?` active`:``}`,onClick:()=>ee(`pdf`),title:u?R(`editor.pdfCompiledAtFor`,{file:r,time:me(u,l.resolvedLanguage)}):R(`editor.currentMainDocument`,{path:r}),children:[(0,X.jsx)(Dn,{className:`pdf-tab-icon`}),(0,X.jsxs)(`span`,{className:`pdf-tab-label`,children:[(0,X.jsxs)(`span`,{className:`pdf-tab-title`,children:[`PDF · `,p]}),fe&&(0,X.jsx)(`small`,{children:fe})]})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":i===`diagnostics`,className:`diagnostics-tab${i===`diagnostics`?` active`:``}`,onClick:()=>ee(`diagnostics`),children:[(0,X.jsx)(A,{size:14}),R(`editor.outputTabs`),(0,X.jsx)(`span`,{className:`diagnostic-count`,children:N})]})]}),m&&(0,X.jsxs)(`a`,{className:`pdf-download-top`,href:m,download:!0,title:R(`editor.downloadPdf`),"aria-label":R(`editor.downloadPdf`),children:[(0,X.jsx)(k,{size:15}),(0,X.jsx)(`span`,{children:R(`editor.downloadPdf`)})]})]}),i===`diagnostics`&&(0,X.jsxs)(`div`,{className:`preview-subtabs`,role:`tablist`,"aria-label":R(`editor.outputTabs`),children:[(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":a===`log`,className:a===`log`?`active`:``,onClick:()=>ee(`log`),children:[(0,X.jsx)(Yt,{size:13}),R(`editor.log`)]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":a===`warnings`,className:a===`warnings`?`active`:``,onClick:()=>ee(`warnings`),children:[(0,X.jsx)(y,{size:13}),R(`editor.warnings`),(0,X.jsx)(`span`,{children:S.warnings.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":a===`errors`,className:a===`errors`?`active`:``,onClick:()=>ee(`errors`),children:[(0,X.jsx)(xt,{size:13}),R(`editor.errors`),(0,X.jsx)(`span`,{children:S.errors.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":a===`artifacts`,className:a===`artifacts`?`active`:``,onClick:()=>ee(`artifacts`),children:[(0,X.jsx)(tn,{size:13}),R(`editor.artifacts`),(0,X.jsx)(`span`,{children:C.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":a===`clean`,className:a===`clean`?`active`:``,onClick:()=>ee(`clean`),children:[(0,X.jsx)(Tt,{size:13}),R(`editor.clean`)]})]}),(0,X.jsxs)(`div`,{className:`preview-content preview-${i} ${i===`diagnostics`?`preview-${a}`:``}`,children:[i===`pdf`&&(o?(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(Fe,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:R(`editor.loadingPdf`)})]}),children:(0,X.jsx)(eb,{url:o,loadingMode:s,target:h,compiling:v,onDisplayedUrlChange:ue,onViewportLocation:(e,t,n)=>{V.current===o&&ne({page:e,x:t,y:n})},onDoubleClickLocation:(e,t,n)=>{V.current===o&&de&&(ne({page:e,x:t,y:n}),oe(e,t,n))}})}):c?(0,X.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(Fe,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:R(`editor.loadingPdf`)})]}):(0,X.jsxs)(`div`,{className:`preview-empty preview-empty-uncompiled`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(`span`,{className:`preview-empty-icon`,"aria-hidden":`true`,children:v?(0,X.jsx)(Fe,{className:`spin`,size:26}):(0,X.jsx)(Dn,{size:32})}),(0,X.jsx)(`strong`,{children:R(v?`editor.compiling`:`editor.previewEmptyTitle`)}),(0,X.jsx)(`p`,{children:R(v?`editor.previewCompilingHint`:`editor.previewHint`)})]})),i===`diagnostics`&&a===`log`&&(0,X.jsx)(Yy,{lines:b?b.split(`
17
+ `):[],empty:R(v?`editor.compiling`:`editor.noLog`)}),i===`diagnostics`&&a===`warnings`&&(x?(0,X.jsx)(Jy,{tone:`warning`,diagnostics:x.warnings,files:F,empty:R(`editor.noWarnings`),onJump:(e,t,n)=>{j===`pdf-only`&&te(`editor-pdf`),I(e,t,n)}}):(0,X.jsx)(Yy,{tone:`warning`,lines:S.warnings,empty:R(`editor.noWarnings`)})),i===`diagnostics`&&a===`errors`&&(x?(0,X.jsx)(Jy,{tone:`error`,diagnostics:x.errors,files:F,empty:R(`editor.noErrors`),onJump:(e,t,n)=>{j===`pdf-only`&&te(`editor-pdf`),I(e,t,n)}}):(0,X.jsx)(Yy,{tone:`error`,lines:S.errors,empty:R(`editor.noErrors`)})),i===`diagnostics`&&a===`artifacts`&&(0,X.jsx)(Xy,{projectId:n,mainFile:r,artifacts:C,preview:w,loading:T,onView:e=>void L(e)}),i===`diagnostics`&&a===`clean`&&(0,X.jsx)(Zy,{mainFile:r,disabled:D||!O||v,cleaning:E,onCleanCache:()=>le(`cache`),onCleanArtifacts:()=>le(`artifacts`)})]})]})]})})})]})}function nb(e){return!Number.isFinite(e)||e<0?``:e<1024?`${Math.round(e)} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/1073741824).toFixed(1)} GB`}function rb({kind:e,onEdit:t,onDelete:n,disabled:r=!1}){let{t:i}=Ae(),a=(0,Y.useRef)(!1);return(0,X.jsx)(`span`,{className:`comment-actions-menu`,onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(ze,{modal:!1,children:[(0,X.jsx)(J,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,disabled:r,className:`comment-actions-menu-trigger`,"aria-label":i(e===`comment`?`editor.commentActions`:`editor.replyActions`),children:(0,X.jsx)(re,{size:16,"aria-hidden":!0})})}),(0,X.jsx)(Ie,{children:(0,X.jsxs)(Le,{className:`comment-actions-menu-content`,align:`end`,sideOffset:4,collisionPadding:8,onCloseAutoFocus:e=>{a.current&&e.preventDefault(),a.current=!1},children:[(0,X.jsxs)(Re,{onSelect:()=>{a.current=!0,t()},children:[(0,X.jsx)(he,{size:13,"aria-hidden":!0}),i(e===`comment`?`editor.editComment`:`editor.editReply`)]}),(0,X.jsxs)(Re,{className:`danger-text`,onSelect:()=>{a.current=!0,n()},children:[(0,X.jsx)(S,{size:13,"aria-hidden":!0}),i(e===`comment`?`editor.deleteComment`:`editor.deleteReply`)]})]})})]})})}function ib(e,t){let n=e.slice(0,t),r=/(^|[^\p{L}\p{N}_.-])@([\p{L}\p{N}_.-]*)$/u.exec(n);return r?{start:t-r[2].length-1,end:t,query:r[2]}:null}function ab({projectId:e,value:t,onChange:n,onKeyDown:r,onFocus:i,...a}){let{t:o}=Ae(),s=(0,Y.useRef)(null),[c,l]=(0,Y.useState)(null),u=Hg({queryKey:Wg.candidates(e),enabled:!!c,queryFn:({signal:t})=>G(`/api/projects/${e}/mention-candidates`,{signal:t})}),d=qg(u.error)?void 0:u.data?.users,[f,p]=(0,Y.useState)(0),m=(0,Y.useMemo)(()=>{if(!c||!d)return[];let e=c.query.toLocaleLowerCase();return(e?d.filter(t=>t.username.toLocaleLowerCase().includes(e)||t.displayName.toLocaleLowerCase().includes(e)):d).slice(0,8)},[d,c]),h=!!(c&&m.length),g=(e,t)=>{let n=ib(e,t);l(n),p(0),n&&!u.isFetching&&(u.isError||u.isStale)&&u.refetch()},_=e=>{if(!c)return;let r=`@${e.username} `,i=`${t.slice(0,c.start)}${r}${t.slice(c.end)}`,a=c.start+r.length;n(i),l(null),p(0),window.requestAnimationFrame(()=>{s.current?.focus(),s.current?.setSelectionRange(a,a)})},v=e=>{if(!e.nativeEvent.isComposing&&h){if(e.key===`ArrowDown`){e.preventDefault(),p(e=>(e+1)%m.length);return}if(e.key===`ArrowUp`){e.preventDefault(),p(e=>(e-1+m.length)%m.length);return}if(e.key===`Enter`&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){e.preventDefault(),_(m[f]??m[0]);return}if(e.key===`Escape`){l(null);return}}r?.(e)};return(0,X.jsxs)(`span`,{className:`mention-textarea`,children:[(0,X.jsx)(`textarea`,{...a,ref:s,value:t,onFocus:e=>{i?.(e),g(t,e.currentTarget.selectionStart??t.length)},onClick:e=>g(t,e.currentTarget.selectionStart??t.length),onChange:e=>{let t=e.currentTarget.value;n(t),g(t,e.currentTarget.selectionStart??t.length)},onKeyDown:v}),h&&(0,X.jsx)(`span`,{className:`mention-menu`,role:`listbox`,"aria-label":o(`editor.mentionUsers`),children:m.map((e,t)=>(0,X.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===f,className:t===f?`active`:``,onMouseDown:e=>e.preventDefault(),onClick:()=>_(e),children:[(0,X.jsx)(I,{"aria-hidden":!0,size:13}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.displayName}),(0,X.jsxs)(`small`,{children:[`(`,e.username,`)`]})]})]},e.id))})]})}function ob({projectId:e,value:t,onChange:n,onSubmit:r,onCancel:i,pending:a=!1,error:o=``,label:s,editing:c=!1,disabled:l=!1,autoFocus:u=!0}){let{t:d}=Ae(),f=(0,Y.useId)(),p=a||l,m=e=>{e?.preventDefault(),!p&&t.trim()&&r()};return(0,X.jsxs)(`form`,{className:`comment-reply-form${c?` comment-edit-form`:``}`,"aria-busy":a,onSubmit:e=>void m(e),onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(ab,{projectId:e,autoFocus:u,rows:c?4:3,value:t,onChange:n,disabled:p,"aria-label":s,"aria-invalid":!!o,"aria-describedby":o?f:void 0,placeholder:c?void 0:d(`editor.replyPlaceholder`),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.stopPropagation(),m())}}),o&&(0,X.jsx)(`p`,{id:f,className:`comment-form-error`,role:`alert`,children:o}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:p,onClick:i,children:d(`common.cancel`)}),c?(0,X.jsx)(ve,{type:`submit`,saving:a,disabled:l||!t.trim(),iconSize:13,children:d(a?`editor.commentSaving`:`editor.saveChanges`)}):(0,X.jsxs)(`button`,{className:`primary`,type:`submit`,disabled:p||!t.trim(),children:[a?(0,X.jsx)(Fe,{className:`spin`,"aria-hidden":!0,size:13}):(0,X.jsx)(gn,{"aria-hidden":!0,size:13}),d(a?`editor.commentSending`:`editor.sendReply`)]})]})]})}function sb(e,t={}){let n=e.slice(0,Math.max(0,e.length-2)),r=!!(t.activeDraft||t.targetReplyId&&e.some(e=>e.id===t.targetReplyId)||n.some(e=>t.unreadReplyMentionIds?.has(e.id)||t.highlightReplyParticipants&&t.selectedParticipantIds?.has(e.authorId))),i=r||(t.expansion??!!t.current),a=i?0:n.length;return{replies:a?e.slice(-2):e,hiddenCount:a,expanded:i,canToggle:n.length>0&&!r}}var cb=1100;function lb(e){let t=()=>{};if(!e||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return t;let n=e.closest(`.comments`)??e.parentElement,r=e.getBoundingClientRect(),i=e.closest(`.context-panel`)?.getBoundingClientRect(),a=Math.max(0,r.left,i?.left??0),o=Math.max(0,r.top,i?.top??0),s=Math.min(window.innerWidth,r.right,i?.right??window.innerWidth)-a,c=Math.min(180,Math.min(window.innerHeight,r.bottom,i?.bottom??window.innerHeight)-o);if(!n||s<=0||c<=0)return t;let l=!1;return()=>{if(l||!n.isConnected||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return;l=!0;let e=document.createElement(`div`);e.className=`comment-paper-shred`,e.setAttribute(`aria-hidden`,`true`),e.inert=!0,Object.assign(e.style,{left:`${a}px`,top:`${o}px`,width:`${s}px`,height:`${c}px`}),e.style.setProperty(`--shred-duration`,`${cb}ms`),e.style.setProperty(`--shred-height`,`${c}px`);let t=Math.min(12,Math.max(8,Math.round(s/22))),r=c<96?1:2;for(let n=0;n<t*r;n++){let i=document.createElement(`span`),a=n%t,o=Math.floor(n/t),s=a/(t-1)*2-1,l=n*37;i.style.left=`${a/t*100}%`,i.style.top=`${o/r*100}%`,i.style.width=`${100/t}%`,i.style.height=`${c/r}px`,i.style.setProperty(`--shred-x`,`${s*14+l%7-3}px`),i.style.setProperty(`--shred-y`,`${48+o*16+l%31}px`),i.style.setProperty(`--shred-angle`,`${s*12+l%13-6}deg`),i.style.setProperty(`--shred-flip`,`${(n%2?1:-1)*(18+l%23)}deg`),i.style.setProperty(`--shred-line-offset`,`${-o*c/r}px`),i.style.animationDuration=`${780+l%4*25}ms`,i.style.animationDelay=`${80+a*7+o*35+l%3*9}ms`,e.append(i)}let i=()=>{window.clearTimeout(d),u.disconnect(),window.removeEventListener(`resize`,i),e.remove()},u=new MutationObserver(()=>{n.isConnected||i()}),d=window.setTimeout(i,1300);e.addEventListener(`animationend`,t=>{t.target===e&&!t.pseudoElement&&i()}),window.addEventListener(`resize`,i),u.observe(document.body,{childList:!0,subtree:!0}),document.body.append(e)}}function ub(e){let t=/(^|\s)(@[\p{L}\p{N}_.-]+)/gu,n=[],r=0;for(let i of e.matchAll(t)){let t=i.index??0,a=i[1],o=i[2],s=t+a.length;s>r&&n.push(e.slice(r,s)),n.push((0,X.jsx)(`span`,{className:`comment-inline-mention`,children:o},`${s}:${o}`)),r=s+o.length}return n.length?(r<e.length&&n.push(e.slice(r)),n):e}function db({userId:e,avatarStyle:t,name:n,username:r,highlighted:i,children:a}){return(0,X.jsxs)(`span`,{className:`comment-identity`,children:[(0,X.jsx)(oe,{userId:e,name:n,username:r,avatarStyle:t,className:`comment-avatar`}),(0,X.jsxs)(`span`,{className:`comment-author-details`,children:[(0,X.jsx)(`span`,{className:`comment-author${i?` participant-match`:``}`,children:(0,X.jsx)(`strong`,{"data-tooltip":r?`@${r}`:void 0,"data-texlite-tooltip-always":!0,children:n})}),a]})]})}function fb({projectId:e,comment:t,draftStore:n,currentUserId:r,unreadCommentMentionId:i,unreadReplyMentionIds:a,highlightedComment:o,highlightedReplyId:s,currentComment:c,showFilePath:l,onMarkMentionRead:u,onFocus:d,onActivate:f,onToggle:p,onReply:h,onEdit:g,onDelete:_,onEditReply:v,onDeleteReply:y,selectedParticipantIds:b,highlightReplyParticipants:x,replyExpansion:S,onReplyExpansionChange:C}){let{t:w,i18n:T}=Ae(),E=le(),[D,O]=(0,Y.useState)(!1),k=(0,Y.useCallback)(e=>n.subscribe(t.id,e),[n,t.id]),A=(0,Y.useCallback)(()=>n.getThread(t.id),[n,t.id]),j=(0,Y.useSyncExternalStore)(k,A,A),M=j.reply,N=j[`edit-comment`],ee=(0,Y.useId)(),te=sb(t.replies,{expansion:S,current:c,targetReplyId:s,unreadReplyMentionIds:a,selectedParticipantIds:b,highlightReplyParticipants:x,activeDraft:!!(M?.open||M?.pending||t.authorId===r&&N?.open||t.replies.some(e=>e.authorId===r&&j[`edit-reply:${e.id}`]?.open))}),ne=n.isPending(t.id),[P,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)(!1),[oe,se]=(0,Y.useState)(null),[ce,F]=(0,Y.useState)(``),L=(0,Y.useRef)(null),R=(0,Y.useRef)(!1),[z,B]=(0,Y.useState)(!1),V=async e=>{if(R.current)return;R.current=!0,B(!0),F(``);let t=lb(e?L.current?.querySelector(`[data-comment-reply-id="${e}"]`)??null:L.current);try{if(!(e?await y(e):await _())){F(w(`editor.commentDeleteFailed`));return}e?se(null):ae(!1),t()}catch(e){F(W(e))}finally{R.current=!1,B(!1)}},de=(e,r=``)=>{f(),C(!0),re(e),n.open(t.id,e,r)},fe=(r,i,a)=>{let o=j[r];return o?.open?(0,X.jsx)(ob,{projectId:e,editing:r!==`reply`,label:i,value:o.content,pending:o.pending,error:o.error,disabled:ne||D,autoFocus:P===r,onChange:e=>n.change(t.id,r,e),onSubmit:()=>n.submit(t.id,r,a,w(`editor.commentSubmitFailed`)),onCancel:()=>n.discard(t.id,r)},r):null},pe=t.authorUsername,he=e=>ue(e,T.resolvedLanguage??`en`,E,(e,t)=>w(e,t)),ve=e=>me(e,T.resolvedLanguage,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),ye=e=>(0,X.jsx)(`time`,{dateTime:e,"data-tooltip":ve(e),"data-texlite-tooltip-always":!0,children:he(e)}),U=(e,t)=>(0,X.jsxs)(`span`,{className:`comment-times`,children:[ye(e),t&&(0,X.jsx)(`small`,{"data-tooltip":w(`editor.editedAt`,{time:ve(t)}),"data-texlite-tooltip-always":!0,children:w(`editor.commentEdited`)})]}),be=async(e,t)=>{t.stopPropagation(),C(!0),await u(e)};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`article`,{ref:L,"data-comment-id":t.id,className:`comment-thread${t.resolved?` resolved`:``}${t.orphaned?` orphaned`:``}${o?` mention-target`:``}${c?` review-current`:``}`,onFocusCapture:f,onClick:()=>{window.getSelection()?.toString()||d()},children:[(0,X.jsxs)(`header`,{className:`comment-header`,children:[(0,X.jsx)(db,{userId:t.authorId,avatarStyle:t.authorAvatarStyle,name:t.authorDisplayName??pe??w(`editor.deletedUser`),username:pe,highlighted:b?.has(t.authorId),children:U(t.createdAt,t.editedAt)}),(0,X.jsxs)(`span`,{className:`comment-header-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`resolve`,disabled:D||ne,"aria-busy":D,"aria-label":w(t.resolved?`editor.reopen`:`editor.resolve`),"data-tooltip":w(t.resolved?`editor.reopen`:`editor.resolve`),"data-texlite-tooltip-always":!0,onClick:e=>{e.stopPropagation(),!D&&(O(!0),p().finally(()=>O(!1)))},children:D?(0,X.jsx)(Fe,{className:`spin`,size:15,"aria-hidden":!0}):t.resolved?(0,X.jsx)(mn,{size:15,"aria-hidden":!0}):(0,X.jsx)(ge,{size:16,"aria-hidden":!0})}),t.authorId===r&&!N?.open&&(0,X.jsx)(rb,{kind:`comment`,disabled:ne||D,onEdit:()=>de(`edit-comment`,t.content),onDelete:()=>{F(``),ae(!0)}})]})]}),(0,X.jsx)(`div`,{className:`comment-location`,children:t.orphaned?w(`editor.orphaned`):l?w(`editor.commentLocation`,{path:t.filePath,line:t.startLine}):w(`editor.line`,{line:t.startLine})}),t.selectedText&&(0,X.jsx)(`blockquote`,{className:`comment-selected-text`,children:t.selectedText}),N?.open&&t.authorId===r?fe(`edit-comment`,w(`editor.editComment`),g):(0,X.jsx)(`p`,{className:`comment-content`,children:ub(t.content)}),i&&(0,X.jsxs)(`div`,{className:`comment-mention`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(I,{"aria-hidden":!0,size:12}),w(`editor.mentionedYou`)]}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>void be(i,e),children:w(`editor.markMentionRead`)})]}),t.replies.length>0&&(0,X.jsxs)(`div`,{className:`comment-replies`,children:[te.canToggle&&(0,X.jsxs)(`button`,{type:`button`,className:`comment-replies-toggle`,"aria-expanded":te.expanded,"aria-controls":ee,onClick:e=>{e.stopPropagation(),C(!te.expanded)},children:[te.expanded?(0,X.jsx)(_e,{size:12,"aria-hidden":!0}):(0,X.jsx)(m,{size:12,"aria-hidden":!0}),te.expanded?w(`editor.hideEarlierReplies`):w(`editor.showEarlierReplies`,{count:te.hiddenCount})]}),(0,X.jsx)(`div`,{className:`comment-replies-list`,id:ee,children:te.replies.map(e=>{let t=a?.get(e.id),n=`edit-reply:${e.id}`,i=j[n]?.open&&e.authorId===r;return(0,X.jsxs)(`div`,{"data-comment-reply-id":e.id,className:`comment-reply${s===e.id?` mention-target`:``}`,children:[(0,X.jsxs)(`header`,{children:[(0,X.jsx)(db,{userId:e.authorId,avatarStyle:e.authorAvatarStyle,name:e.authorDisplayName??e.authorUsername??w(`editor.deletedUser`),username:e.authorUsername,highlighted:x&&b?.has(e.authorId),children:U(e.createdAt,e.editedAt)}),(0,X.jsx)(`span`,{className:`comment-header-actions`,children:e.authorId===r&&!i&&(0,X.jsx)(rb,{kind:`reply`,disabled:ne||D,onEdit:()=>de(n,e.content),onDelete:()=>{F(``),se(e.id)}})})]}),i?fe(n,w(`editor.editReply`),t=>v(e.id,t)):(0,X.jsx)(`p`,{className:`comment-content`,children:ub(e.content)}),t&&(0,X.jsxs)(`div`,{className:`comment-mention`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(I,{"aria-hidden":!0,size:12}),w(`editor.mentionedYou`)]}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>void be(t,e),children:w(`editor.markMentionRead`)})]})]},e.id)})})]}),t.resolved&&t.resolvedAt&&(0,X.jsxs)(`div`,{className:`comment-resolution`,children:[(0,X.jsx)(H,{size:12,"aria-hidden":!0}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(ht,{i18nKey:`editor.resolvedBy`,values:{user:t.resolvedByDisplayName??t.resolvedByUsername??w(`editor.deletedUser`)},components:{user:(0,X.jsx)(`strong`,{className:`comment-resolution-user`,"data-tooltip":t.resolvedByUsername?`@${t.resolvedByUsername}`:void 0,"data-texlite-tooltip-always":!0})}}),` · `,ye(t.resolvedAt)]})]}),!M?.open&&(0,X.jsx)(`button`,{type:`button`,className:`reply-action`,disabled:ne||D,onClick:e=>{e.stopPropagation(),de(`reply`)},children:w(`editor.replyPrompt`)}),fe(`reply`,w(`editor.reply`),h)]}),(0,X.jsx)(Ne,{open:ie,title:w(`editor.deleteCommentTitle`),description:w(`editor.deleteCommentDescription`),confirmLabel:w(`common.delete`),danger:!0,busy:z,error:ce,onCancel:()=>ae(!1),onConfirm:()=>void V(null)}),(0,X.jsx)(Ne,{open:!!oe,title:w(`editor.deleteReplyTitle`),description:w(`editor.deleteReplyDescription`),confirmLabel:w(`common.delete`),danger:!0,busy:z,error:ce,onCancel:()=>se(null),onConfirm:()=>{oe&&V(oe)}})]})}function pb({open:e,onOpenChange:t,project:n,projectId:r}){let{t:i}=Ae(),[a,o]=(0,Y.useState)([]),[s,c]=(0,Y.useState)([]),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(`read`),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),_=n.permission===`owner`,v=async()=>{try{let[e,t]=await Promise.all([G(`/api/projects/${r}/members`),G(`/api/users`)]);o(e.members),c(t.users.filter(e=>e.id!==n.ownerId))}catch(e){g(W(e))}};(0,Y.useEffect)(()=>{e&&v()},[e,r]);let y=async()=>{if(l)try{await G(`/api/projects/${r}/members/${l}`,{method:`PUT`,body:JSON.stringify({permission:d})}),u(``),f(`read`),await v()}catch(e){g(W(e))}},b=async(e,t)=>{try{await G(`/api/projects/${r}/members/${e.id}`,{method:`PUT`,body:JSON.stringify({permission:t})}),await v()}catch(e){g(W(e))}},x=async()=>{if(p)try{await G(`/api/projects/${r}/members/${p.id}`,{method:`DELETE`}),m(null),await v()}catch(e){g(W(e))}},C=s.filter(e=>!a.some(t=>t.id===e.id));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Oe,{open:e,wide:!0,title:i(`projectSettings.share`),description:i(`projectSettings.shareDescription`),onOpenChange:t,footer:(0,X.jsx)(`button`,{onClick:()=>t(!1),children:i(`common.close`)}),children:(0,X.jsxs)(`div`,{className:`share-dialog`,children:[h&&(0,X.jsx)(`p`,{className:`error`,children:h}),(0,X.jsxs)(`div`,{className:`share-owner`,children:[(0,X.jsx)(D,{size:17}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`small`,{children:i(`projects.owner`)}),(0,X.jsx)(`strong`,{children:n.ownerDisplayName??n.ownerUsername})]})]}),_&&(0,X.jsxs)(`div`,{className:`share-add`,children:[(0,X.jsxs)(`label`,{className:`form-field`,children:[i(`common.user`),(0,X.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:i(`projectSettings.chooseUser`)}),C.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.displayName??e.username},e.id))]})]}),(0,X.jsxs)(`label`,{className:`form-field`,children:[i(`common.permission`),(0,X.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),children:[(0,X.jsx)(`option`,{value:`read`,children:i(`common.readOnly`)}),(0,X.jsx)(`option`,{value:`edit`,children:i(`common.readWrite`)})]})]}),(0,X.jsxs)(`button`,{className:`primary icon-button`,disabled:!l,onClick:()=>void y(),children:[(0,X.jsx)(U,{size:15}),i(`projectSettings.addMember`)]})]}),(0,X.jsxs)(`div`,{className:`shared-members-heading`,children:[(0,X.jsx)(`strong`,{children:i(`projectSettings.members`)}),(0,X.jsx)(`span`,{children:a.length})]}),(0,X.jsxs)(`div`,{className:`shared-members`,children:[a.map(e=>(0,X.jsxs)(`div`,{className:`shared-member`,children:[(0,X.jsxs)(`span`,{className:`member-identity`,children:[(0,X.jsx)(oe,{userId:e.id,name:e.displayName,username:e.username,avatarStyle:e.avatarStyle,className:`member-avatar`}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.displayName??e.username}),(0,X.jsxs)(`small`,{children:[`@`,e.username]})]})]}),(0,X.jsxs)(`span`,{className:`member-controls`,children:[(0,X.jsxs)(`select`,{"aria-label":i(`common.permission`),disabled:!_,value:e.permission,onChange:t=>void b(e,t.target.value),children:[(0,X.jsx)(`option`,{value:`read`,children:i(`common.readOnly`)}),(0,X.jsx)(`option`,{value:`edit`,children:i(`common.readWrite`)})]}),_&&(0,X.jsx)(`button`,{className:`icon-only danger-text`,title:i(`common.remove`),"aria-label":i(`common.remove`),onClick:()=>m(e),children:(0,X.jsx)(S,{size:15})})]})]},e.id)),a.length===0&&(0,X.jsxs)(`div`,{className:`share-empty`,children:[(0,X.jsx)(D,{size:24}),(0,X.jsx)(`span`,{children:i(`projectSettings.noMembers`)})]})]})]})}),(0,X.jsx)(Ne,{open:!!p,title:i(`projectSettings.removeTitle`),description:i(`projectSettings.removeDescription`,{username:p?.username??``}),confirmLabel:i(`common.remove`),danger:!0,onCancel:()=>m(null),onConfirm:()=>void x()})]})}var mb=(0,Y.lazy)(()=>f(()=>import(`./CitationLibraryDialog-BdU9nbgG.js`).then(e=>({default:e.CitationLibraryDialog})),__vite__mapDeps([13,2,3,11,6,1,4,5,7,8,14,15,16,17,18,19,20,21,22,23]),import.meta.url)),hb=(0,Y.lazy)(()=>f(()=>import(`./GitDialog-C2H-jKVO.js`).then(e=>({default:e.GitDialog})),__vite__mapDeps([24,2,3,11,6,1,4,5,7,8,25,26,27,28,18]),import.meta.url)),gb=(0,Y.lazy)(()=>f(()=>import(`./HistoryDialog-CoxJ3EsK.js`).then(e=>({default:e.HistoryDialog})),__vite__mapDeps([29,2,3,11,6,1,4,5,7,8,16,30,31,27,28,18,19,21,32]),import.meta.url)),_b=(0,Y.lazy)(()=>f(()=>import(`./SelectionHistoryDialog-DzlVKtxs.js`).then(e=>({default:e.SelectionHistoryDialog})),__vite__mapDeps([33,2,3,11,6,1,4,5,7,8,30,31,32]),import.meta.url)),vb=(0,Y.lazy)(()=>f(()=>import(`./QuickOpenDialog-BAzyrB-4.js`).then(e=>({default:e.QuickOpenDialog})),__vite__mapDeps([34,2,3,11,6,1,4,5,7,8,14,19]),import.meta.url));function yb({user:e,project:t,projectId:n,activeFile:r,content:i,maxCitationBibtexBytes:a,files:o,directoryEntries:s,readOnly:c,resourcePreview:l,resourcePreviewLoading:u,setResourcePreview:d,setResourcePreviewLoading:f,uploadConflict:p,setUploadConflict:m,dismissUploadFeedback:h,uploadFiles:g,cleanMode:_,setCleanMode:v,cleanCompile:b,newFileOpen:x,setNewFileOpen:C,newFilePath:w,setNewFilePath:T,newFolderOpen:E,setNewFolderOpen:D,newFolderName:O,setNewFolderName:A,selectedFolder:j,fileDialogError:M,setFileDialogError:N,createFile:ee,createFolder:te,moveEntry:P,setMoveEntry:re,moveName:ie,setMoveName:ae,moveDestination:oe,setMoveDestination:se,movePath:ce,deleteEntry:F,setDeleteEntry:I,deleteActiveSessions:le,removePath:L,commentOpen:R,closeComment:z,commentSelection:B,commentText:V,setCommentText:ue,commentSubmitting:de,commentError:fe,addComment:pe,cancelComment:me,commentDraftRestored:he,commentDraftCanRetarget:ge,useCurrentCommentSelection:_e,shareOpen:H,setShareOpen:ve,citationLibraryOpen:U,setCitationLibraryOpen:be,insertCitationAtCursor:W,quickOpen:G,setQuickOpen:xe,openFile:Se,selectionHistoryTarget:K,closeSelectionHistory:Ce,historyOpen:we,setHistoryOpen:Te,gitOpen:Ee,setGitOpen:De,save:q,permissionDowngrade:je,permissionDowngradeBusy:Me,dismissPermissionDowngrade:Pe,discardPermissionDraft:Ie}){let{t:J}=Ae();return(0,X.jsxs)(X.Fragment,{children:[je&&(0,X.jsx)(Oe,{open:!0,title:J(`editor.collaboration.permissionDowngradeTitle`),description:je.localDraftReady&&je.otherTabDraft?J(`editor.collaboration.permissionDowngradeMultipleDrafts`):je.otherTabDraft?J(`editor.collaboration.permissionDowngradeOtherTab`):je.localDraftReady?J(`editor.collaboration.permissionDowngradeDescription`,{previous:J(`common.readWrite`)}):J(`editor.collaboration.permissionDowngradeNoDraft`),onOpenChange:e=>{!e&&!Me&&Pe()},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:Me,onClick:Pe,children:je.localDraftReady?J(`editor.collaboration.permissionDowngradeKeep`):J(`common.close`)}),!je.otherTabDraft&&(0,X.jsxs)(`button`,{type:`button`,className:`danger`,disabled:Me,onClick:()=>void Ie(),children:[Me?(0,X.jsx)(Fe,{className:`spin`,size:14}):je.localDraftReady?(0,X.jsx)(S,{size:14}):(0,X.jsx)(ye,{size:14}),je.localDraftReady?J(`editor.collaboration.permissionDowngradeDiscard`):J(`editor.collaboration.permissionDowngradeReload`)]})]}),children:(0,X.jsx)(`div`,{})}),(0,X.jsxs)(Oe,{open:!!l,extraWide:l?.kind===`image`||l?.kind===`pdf`||l?.kind===`text`,title:l?.path??``,description:l?.kind===`large`?J(`editor.resourceTooLarge`,{size:bb(l.size),limit:bb(l.limitBytes??10485760)}):J(`editor.resourcePreview.${l?.kind??`text`}`),onOpenChange:e=>{e||(d(null),f(!1))},footer:l&&(0,X.jsxs)(`a`,{className:`primary resource-download`,href:`${l.url}&download=1`,download:!0,children:[(0,X.jsx)(k,{size:14}),J(`editor.downloadResource`)]}),children:[l?.kind===`large`&&(0,X.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,X.jsx)(ne,{size:34}),(0,X.jsx)(`strong`,{children:J(`editor.resourceTooLargeTitle`)}),(0,X.jsx)(`span`,{children:J(`editor.resourceTooLargeDescription`)})]}),l?.kind===`unsupported`&&(0,X.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,X.jsx)(zt,{size:34}),(0,X.jsx)(`strong`,{children:J(`editor.resourceUnsupportedTitle`)}),(0,X.jsx)(`span`,{children:J(`editor.resourceUnsupportedDescription`)})]}),l?.kind===`image`&&(0,X.jsx)(`div`,{className:`resource-image-wrap`,children:(0,X.jsx)(`img`,{className:`resource-image`,src:l.url,alt:l.path})}),l?.kind===`pdf`&&(0,X.jsx)(`iframe`,{className:`resource-pdf`,src:l.url,title:l.path}),l?.kind===`text`&&(u?(0,X.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,X.jsx)(Fe,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:J(`common.loading`)})]}):(0,X.jsx)(`pre`,{className:`resource-text`,children:l.content}))]}),(0,X.jsx)(Ne,{open:!!p,title:J(`editor.uploadOverwriteTitle`),description:J(`editor.uploadOverwriteDescription`,{count:p?.collisions.length??0,files:p?.collisions.join(`, `)??``}),confirmLabel:J(`editor.uploadOverwrite`),danger:!0,onCancel:()=>{m(null),h()},onConfirm:()=>{let e=p;m(null),e&&g(e.files,new Set(e.collisions),e.directory)}}),(0,X.jsx)(Ne,{open:!!_,title:J(_===`cache`?`editor.cleanCacheConfirmTitle`:`editor.cleanArtifactsConfirmTitle`),description:J(_===`cache`?`editor.cleanCacheConfirmDescription`:`editor.cleanArtifactsConfirmDescription`),confirmLabel:J(`editor.cleanConfirm`),danger:_===`artifacts`,onCancel:()=>v(null),onConfirm:()=>{let e=_;v(null),e&&b(e)}}),(0,X.jsx)(Oe,{open:x,title:J(`editor.newFile`),description:J(`editor.newFileDescription`),onOpenChange:e=>{C(e),e||N(``)},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>C(!1),children:J(`common.cancel`)}),(0,X.jsx)(`button`,{className:`primary`,onClick:()=>void ee(),children:J(`common.create`)})]}),children:(0,X.jsxs)(X.Fragment,{children:[M&&(0,X.jsx)(`p`,{className:`error dialog-error`,children:M}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.filePath`),(0,X.jsx)(`input`,{autoFocus:!0,value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),ee())}})]})]})}),(0,X.jsx)(Oe,{open:E,title:J(`editor.newFolder`),description:J(`editor.folderDestination`,{folder:j||J(`editor.projectRoot`)}),onOpenChange:e=>{D(e),e||N(``)},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>D(!1),children:J(`common.cancel`)}),(0,X.jsx)(`button`,{className:`primary`,onClick:()=>void te(),children:J(`common.create`)})]}),children:(0,X.jsxs)(X.Fragment,{children:[M&&(0,X.jsx)(`p`,{className:`error dialog-error`,children:M}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.folderName`),(0,X.jsx)(`input`,{autoFocus:!0,value:O,onChange:e=>A(e.target.value),onKeyDown:e=>{e.key===`Enter`&&te()}})]})]})}),(0,X.jsx)(Oe,{open:!!P,title:J(`editor.moveTitle`,{name:P?.path.split(`/`).at(-1)??``}),description:J(`editor.moveDescription`),onOpenChange:e=>{e||(re(null),ae(``),N(``))},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>re(null),children:J(`common.cancel`)}),(0,X.jsx)(`button`,{className:`primary`,disabled:!ie.trim(),onClick:()=>void ce(),children:J(`editor.moveApply`)})]}),children:(0,X.jsxs)(X.Fragment,{children:[M&&(0,X.jsx)(`p`,{className:`error dialog-error`,children:M}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.pathName`),(0,X.jsx)(`input`,{autoFocus:!0,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>{e.key===`Enter`&&ce()}})]}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.destinationFolder`),(0,X.jsxs)(`select`,{value:oe,onChange:e=>se(e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:J(`editor.projectRoot`)}),s.filter(e=>P?.type!==`directory`||e.path!==P.path&&!e.path.startsWith(`${P.path}/`)).map(e=>(0,X.jsx)(`option`,{value:e.path,children:e.path},e.path))]})]})]})}),(0,X.jsx)(Oe,{open:!!F,title:J(`editor.deletePathTitle`,{name:F?.path.split(`/`).at(-1)??``}),description:le.length?J(`editor.deletePathActiveDescription`,{count:le.length,path:F?.path??``,users:[...new Set(le.map(e=>e.name))].join(`, `)}):J(`editor.deletePathDescription`,{path:F?.path??``}),onOpenChange:e=>{e||(I(null),N(``))},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>I(null),children:J(`common.cancel`)}),(0,X.jsx)(`button`,{className:`danger`,onClick:()=>void L(),children:J(`common.delete`)})]}),children:(0,X.jsxs)(X.Fragment,{children:[M&&(0,X.jsx)(`p`,{className:`error dialog-error`,children:M}),le.length>0&&(0,X.jsxs)(`p`,{className:`warning`,children:[(0,X.jsx)(y,{size:15}),J(`editor.deletePathWillClose`)]})]})}),(0,X.jsxs)(Oe,{open:R,draggable:!0,wide:!0,className:`comment-compose-modal`,title:J(`editor.addComment`),description:B.selectedText?J(`editor.commentDescription`,{count:B.endOffset-B.startOffset}):J(`editor.pointComment`),onOpenChange:e=>{e||z()},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:de,onClick:me,children:J(`common.cancel`)}),(0,X.jsxs)(`button`,{type:`button`,className:`primary`,"aria-busy":de,disabled:de||!V.trim(),onClick:()=>void pe(),children:[de&&(0,X.jsx)(Fe,{className:`spin`,size:14}),J(de?`editor.commentSending`:`editor.addComment`)]})]}),children:[fe&&(0,X.jsx)(`p`,{className:`error dialog-error`,children:fe}),he&&(0,X.jsxs)(`p`,{className:`comment-draft-restored`,children:[(0,X.jsx)(`span`,{children:J(`editor.commentDraftRestored`)}),ge&&(0,X.jsx)(`button`,{type:`button`,disabled:de,onClick:_e,children:J(`editor.commentDraftUseSelection`)})]}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.commentContent`),(0,X.jsx)(ab,{projectId:n,autoFocus:!0,rows:5,disabled:de,value:V,placeholder:J(`editor.commentPlaceholder`),onChange:ue,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.stopPropagation(),pe())}})]}),B.selectedText&&(0,X.jsx)(`blockquote`,{className:`selection-preview`,children:B.selectedText})]}),(0,X.jsx)(pb,{open:H,onOpenChange:ve,project:t,projectId:n}),U&&(0,X.jsx)(ke,{title:J(`citationLibrary.title`),onClose:()=>be(!1),children:(0,X.jsx)(mb,{open:!0,onOpenChange:be,currentFile:r,currentSource:i,readOnly:c,currentUserId:e.id,maxBibtexBytes:a,onInsert:W})}),G&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(vb,{open:!0,files:o,onOpenChange:xe,onOpenFile:e=>{let t=o.find(t=>t.path===e);t&&Se(t)}})}),K&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(_b,{open:!0,onOpenChange:e=>{e||Ce()},project:t,filePath:K.filePath,selection:K.selection,currentSource:K.source})}),we&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(gb,{open:!0,onOpenChange:Te,project:t,onBeforeMutation:t.permission===`read`?async()=>!0:q})}),t.ownerId===e.id&&Ee&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(hb,{open:!0,onOpenChange:De,project:t,onBeforeMutation:q})})]})}function bb(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function xb({participants:e,selectedIds:t,topLevelOnly:n,onToggle:r,onClear:i,onTopLevelOnlyChange:a}){let{t:o}=Ae(),[s,c]=(0,Y.useState)(!1),l=(0,Y.useRef)(null),u=t.size>0,d=e.find(e=>t.has(e.authorId)),f=e=>e.authorDisplayName??e.authorUsername??o(`editor.deletedUser`),p=u?d?t.size===1?f(d):o(`editor.commentParticipantsSelected`,{name:f(d),count:t.size-1}):o(`editor.commentParticipantsCount`,{count:t.size}):o(`editor.commentParticipantsAll`);return(0,X.jsx)(`div`,{className:`comment-participant-filter`,children:(0,X.jsxs)(`div`,{className:`comment-participants-trigger-group${u?` active`:``}`,children:[(0,X.jsxs)(g,{open:s,onOpenChange:c,children:[(0,X.jsx)(_,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`comment-participants-toggle`,"aria-label":`${o(`editor.commentParticipants`)}: ${p}`,children:[(0,X.jsx)(D,{size:13,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`comment-participants-summary`,children:u&&d?f(d):p}),u&&d&&t.size>1&&(0,X.jsxs)(`span`,{className:`comment-participants-extra-count`,children:[`+`,t.size-1]}),(0,X.jsx)(de,{size:12,"aria-hidden":!0,className:s?`expanded`:``})]})}),(0,X.jsx)(M,{children:(0,X.jsxs)(pe,{ref:l,className:`comment-participants-popover`,side:`bottom`,align:`end`,sideOffset:6,collisionPadding:10,"aria-label":o(`editor.commentParticipants`),onOpenAutoFocus:e=>{e.preventDefault();let t=l.current?.querySelector(`input[type="checkbox"]:not(:disabled)`);t?t.focus():l.current?.focus()},children:[(0,X.jsxs)(`div`,{className:`comment-participants-heading`,children:[(0,X.jsx)(v,{children:o(`editor.commentParticipants`)}),u&&(0,X.jsx)(`button`,{type:`button`,onClick:i,children:o(`editor.commentParticipantsClear`)})]}),(0,X.jsxs)(`div`,{className:`comment-participants-list`,children:[e.map(e=>{let n=f(e),i=t.has(e.authorId);return(0,X.jsxs)(`label`,{className:`comment-participant-option${i?` selected`:``}`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>r(e.authorId)}),(0,X.jsx)(oe,{userId:e.authorId,name:n,username:e.authorUsername,avatarStyle:e.authorAvatarStyle,className:`comment-participant-avatar`}),(0,X.jsxs)(`span`,{className:`comment-participant-identity`,children:[(0,X.jsx)(`strong`,{children:n}),e.authorUsername&&(0,X.jsxs)(`small`,{children:[`@`,e.authorUsername]})]})]},e.authorId??`deleted`)}),e.length===0&&(0,X.jsx)(`p`,{className:`comment-participants-empty`,children:o(`editor.commentNoParticipants`)})]}),(0,X.jsxs)(`label`,{className:`comment-participants-root-only`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n,disabled:!u,onChange:e=>a(e.target.checked)}),o(`editor.commentTopLevelOnly`)]})]})})]}),u&&(0,X.jsx)(`button`,{type:`button`,className:`comment-participants-clear`,"aria-label":o(`editor.commentParticipantsClear`),onClick:i,children:(0,X.jsx)(E,{size:12,"aria-hidden":!0})})]})})}function Sb(e,t,n,r,i){let a=t.map(e=>({comment:e,exitAt:null})),o=new Set(t.map(e=>e.id)),s=new Map(n.map(e=>[e.id,e]));return e.forEach((e,t)=>{let n=s.get(e.comment.id);o.has(e.comment.id)||!n||c_(n,r)||a.splice(Math.min(t,a.length),0,{comment:n,exitAt:e.exitAt??i+280+50})}),a}function Cb(e,t,n,r){let[i,a]=(0,Y.useState)(()=>({contextKey:r,visible:e,comments:t,entries:e.map(e=>({comment:e,exitAt:null}))}));(i.contextKey!==r||i.visible!==e||i.comments!==t)&&a({contextKey:r,visible:e,comments:t,entries:i.contextKey===r?Sb(i.entries,e,t,n,Date.now()):e.map(e=>({comment:e,exitAt:null}))});let o=(0,Y.useCallback)(e=>{a(t=>({...t,entries:t.entries.filter(t=>t.comment.id!==e||t.exitAt===null)}))},[]);return(0,Y.useEffect)(()=>{let e=i.entries.flatMap(e=>e.exitAt===null?[]:[e.exitAt]);if(!e.length)return;let t=window.setTimeout(()=>{let e=Date.now();a(t=>({...t,entries:t.entries.filter(t=>t.exitAt===null||t.exitAt>e)}))},Math.max(0,Math.min(...e)-Date.now()));return()=>window.clearTimeout(t)},[i.entries]),{entries:i.entries,finishExit:o}}function wb(e,t,n,r){let[i,a]=(0,Y.useState)(()=>({contextKey:n,limit:50})),o=i.contextKey===n?i.limit:50;if(t)for(let t of r){if(!t)continue;let n=e.findIndex(e=>e.id===t)+1;o=Math.max(o,Math.ceil(n/50)*50)}(i.contextKey!==n||i.limit!==o)&&a({contextKey:n,limit:o});let s=(0,Y.useMemo)(()=>t?e.slice(0,o):e,[e,t,o]),c=(0,Y.useCallback)(()=>{a(e=>({contextKey:n,limit:(e.contextKey===n?e.limit:50)+50}))},[n]);return{shown:s,hasMore:s.length<e.length,loadMore:c}}var Tb=(0,Y.lazy)(()=>f(()=>import(`./ProjectSettings-Bl1t-Gnh.js`).then(e=>({default:e.ProjectSettings})),__vite__mapDeps([35,2,3,11,6,1,4,5,7,8,16,26,36,37,38,21]),import.meta.url));function Eb({commentsHost:e,sidePanel:t,onClose:n,project:r,projectId:i,site:a,files:o,currentUserId:s,comments:c,commentDraftStore:l,commentsLoading:u,commentsError:d,onRetryComments:f,unreadMentions:h,activeFile:g,singleCommentId:_,onShowAllComments:v,hasProjectCommentsScope:y,commentScope:b,onCommentScopeChange:x,focusedCommentId:S,commentFocusNonce:C,onMarkMentionRead:w,onMarkAllMentionsRead:T,onClearFocusComment:D,targetCommentId:O,targetReplyId:k,onFocusComment:A,onToggleComment:j,onReplyComment:M,onEditComment:N,onDeleteComment:ee,onEditCommentReply:te,onDeleteCommentReply:ne,dictionaryWords:P,onDictionaryChange:re,editorPreferences:ie,onEditorPreferences:ae,spellCheckCount:oe,spellCheckUniqueCount:ce,spellCheckIndex:F,onSpellCheckNavigate:le,onProject:L}){let{t:R}=Ae(),z=!!_,[B,V]=(0,Y.useState)(`unresolved`),[ue,de]=(0,Y.useState)(!1),[fe,pe]=(0,Y.useState)(`source`),me=R(fe===`time`?`editor.commentSortTime`:b===`project`?`editor.commentSortSourceProject`:`editor.commentSortSource`),[he,ge]=(0,Y.useState)(()=>new Set),[_e,H]=(0,Y.useState)(!0),[ve,ye]=(0,Y.useState)(()=>new Map),[U,be]=(0,Y.useState)(null),W=(0,Y.useRef)(new Map(c.map(e=>[e.id,e.resolved]))),G=(0,Y.useMemo)(()=>i_(c),[c]),xe=(0,Y.useMemo)(()=>{let e=c.filter(e=>s_(e,{activeFile:g,scope:b})),t=e.filter(e=>e.resolved).length;return{unresolved:e.length-t,resolved:t}},[g,b,c]),Se=(0,Y.useMemo)(()=>u_(c,{activeFile:g,scope:b,unreadMentions:h,participantIds:he,topLevelOnly:_e,filter:B,unreadMentionsOnly:!0}).length,[g,b,c,h,he,_e,B]),K=(0,Y.useMemo)(()=>_?f_(c,_,g):d_(c,{activeFile:g,scope:b,filter:B,unreadMentions:h,sort:fe,participantIds:he,topLevelOnly:_e,unreadMentionsOnly:ue},[O,S]),[g,_,B,b,c,S,O,h,fe,he,_e,ue]),Ce=S&&K.some(e=>e.id===S)?S:O&&K.some(e=>e.id===O)?O:null,we=z?K[0]?.id??null:U&&K.some(e=>e.id===U)?U:Ce;(0,Y.useEffect)(()=>{be(null)},[S,C,O,k,g,b]),(0,Y.useEffect)(()=>{U&&!K.some(e=>e.id===U)&&be(null)},[U,K]);let Te=g_(K,we),Ee=JSON.stringify([t,_,b,b===`file`?g:``,B,fe,[...he].sort(),_e,ue]),De=JSON.stringify([i,b,b===`file`?g:``,B,fe,[...he].sort(),_e,ue]),{shown:q,hasMore:Oe,loadMore:ke}=wb(K,!z&&B===`resolved`,De,[O,S,U]),{entries:je,finishExit:Ne}=Cb(q,c,z?`unresolved`:B,Ee);(0,Y.useEffect)(()=>{let e=c.some(e=>(e.id===S||e.id===O)&&W.current.has(e.id)&&W.current.get(e.id)!==e.resolved);W.current=new Map(c.map(e=>[e.id,e.resolved])),e&&D()},[c,S,O,D]),(0,Y.useEffect)(()=>{if(t!==`comments`||U)return;let e=O&&k?`.comments [data-comment-reply-id="${k}"]`:O?`.comments .comment-thread[data-comment-id="${O}"]`:Ce?`.comments .comment-thread[data-comment-id="${Ce}"]`:``;if(!e)return;let n=document.querySelector(e);if(!n)return;let r=window.requestAnimationFrame(()=>n.scrollIntoView({block:O?`center`:`nearest`,behavior:`smooth`}));return()=>window.cancelAnimationFrame(r)},[t,U,Ce,C,O,k,K]);let Pe=e=>{be(null),A(e)},Fe=e=>{let t=__(K,we,e);t?Pe(t):D()},Ie=async e=>{let t=await w(e);if(!t||z||!ue)return t;let n=h.find(t=>t.id===e)?.commentId;return n&&(h.some(t=>t.id!==e&&t.commentId===n)||(S===n||O===n)&&D()),t},J=async()=>{await T()&&ue&&D()},Le=e=>{e!==b&&(be(null),D(),x(e))},Re=e=>{e!==B&&(be(null),D(),V(e))},ze=()=>{be(null),D()},Be=e=>{ze(),he.size===1&&he.has(e)&&H(!0),ge(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(!t)return null;let Ve=(0,X.jsxs)(`aside`,{className:`context-panel`,"aria-label":R(t===`comments`?`editor.sourceComments`:`editor.projectSettings`),children:[t===`comments`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`drawer-title`,children:[(0,X.jsx)(`strong`,{children:R(z?`editor.currentComment`:`editor.sourceComments`)}),(0,X.jsxs)(`span`,{className:`drawer-title-actions`,children:[!z&&h.length>0&&(0,X.jsxs)(`button`,{className:`drawer-mention-read-all`,type:`button`,onClick:()=>void J(),title:R(`editor.markAllMentionsRead`),children:[(0,X.jsx)(I,{"aria-hidden":!0,size:13}),(0,X.jsx)(`span`,{children:R(`editor.markAllMentionsRead`)})]}),(0,X.jsx)(`button`,{"aria-label":R(`common.close`),onClick:n,children:(0,X.jsx)(E,{size:17})})]})]}),z?(0,X.jsx)(`div`,{className:`comment-current-controls`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:v,children:[(0,X.jsx)(Zt,{size:14,"aria-hidden":!0}),R(`editor.viewAllComments`)]})}):(0,X.jsxs)(`div`,{className:`comment-review-controls`,children:[(0,X.jsxs)(`div`,{className:`comment-review-queue-row`,children:[y&&(0,X.jsxs)(`div`,{className:`comment-review-group`,role:`group`,"aria-label":R(`editor.commentScope`),children:[(0,X.jsx)(`button`,{type:`button`,className:b===`file`?`active`:``,"aria-pressed":b===`file`,onClick:()=>Le(`file`),children:R(`editor.commentScopeFile`)}),(0,X.jsx)(`button`,{type:`button`,className:b===`project`?`active`:``,"aria-pressed":b===`project`,onClick:()=>Le(`project`),children:R(`editor.commentScopeProject`)})]}),(0,X.jsxs)(`div`,{className:`comment-review-group`,role:`group`,"aria-label":R(`editor.commentFilter`),children:[(0,X.jsx)(`button`,{type:`button`,className:B===`unresolved`?`active`:``,"aria-pressed":B===`unresolved`,onClick:()=>Re(`unresolved`),children:R(`editor.commentFilterUnresolved`,{count:xe.unresolved})}),(0,X.jsx)(`button`,{type:`button`,className:B===`resolved`?`active`:``,"aria-pressed":B===`resolved`,onClick:()=>Re(`resolved`),children:R(`editor.commentFilterResolved`,{count:xe.resolved})})]}),(0,X.jsxs)(`div`,{className:`comment-review-navigation`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:Te<=1,"aria-label":R(`editor.commentPrevious`),title:R(`editor.commentPrevious`),onClick:()=>Fe(-1),children:(0,X.jsx)(se,{size:14})}),(0,X.jsx)(`output`,{"aria-live":`polite`,children:R(`editor.commentPosition`,{current:Te,total:K.length})}),(0,X.jsx)(`button`,{type:`button`,disabled:K.length===0||Te>0&&Te>=K.length,"aria-label":R(`editor.commentNext`),title:R(`editor.commentNext`),onClick:()=>Fe(1),children:(0,X.jsx)(m,{size:14})})]})]}),(0,X.jsxs)(`div`,{className:`comment-review-sort-row`,children:[(0,X.jsx)(xb,{participants:G,selectedIds:he,topLevelOnly:_e,onToggle:Be,onClear:()=>{ze(),ge(new Set),H(!0)},onTopLevelOnlyChange:e=>{ze(),H(e)}},`${b}:${b===`file`?g:`project`}`),(0,X.jsxs)(`button`,{type:`button`,className:`comment-unread-toggle${ue?` active`:``}`,"aria-pressed":ue,"aria-label":R(`editor.commentUnreadMentionsHint`),title:R(`editor.commentUnreadMentionsHint`),onClick:()=>{ze(),de(e=>!e)},children:[(0,X.jsx)(I,{size:12,"aria-hidden":!0}),R(`editor.commentUnreadMentionsOnly`),(0,X.jsx)(`span`,{children:Se})]}),(0,X.jsxs)(`label`,{className:`comment-review-sort`,"data-texlite-tooltip-always":!0,"data-tooltip":me,children:[(0,X.jsx)(`span`,{className:`sr-only`,children:R(`editor.commentSort`)}),fe===`source`?(0,X.jsx)(p,{size:12,"aria-hidden":!0}):(0,X.jsx)(_t,{size:12,"aria-hidden":!0}),(0,X.jsxs)(`select`,{value:fe,"aria-label":`${R(`editor.commentSort`)}: ${me}`,onChange:e=>{ze(),pe(e.target.value)},children:[(0,X.jsx)(`option`,{value:`source`,children:R(`editor.commentSortSourceShort`)}),(0,X.jsx)(`option`,{value:`time`,children:R(`editor.commentSortTimeShort`)})]})]})]})]}),d&&(0,X.jsxs)(`div`,{className:`comment-review-error`,role:`alert`,children:[(0,X.jsx)(`span`,{children:d}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>void f(),children:R(`common.retry`)})]}),u&&(0,X.jsx)(`div`,{className:`comment-review-loading`,role:`status`,children:R(`common.loading`)}),(0,X.jsxs)(`div`,{className:`comments`,children:[je.map(({comment:e,exitAt:t})=>{let n=h.find(t=>t.commentId===e.id&&!t.replyId)?.id,r=new Map(h.filter(t=>t.commentId===e.id&&t.replyId).map(e=>[e.replyId,e.id]));return(0,X.jsx)(`div`,{className:`comment-thread-slot${t===null?``:` is-exiting`}`,inert:t!==null||void 0,"aria-hidden":t!==null||void 0,style:{"--comment-exit-duration":`280ms`},onAnimationEnd:n=>{n.target===n.currentTarget&&t!==null&&Ne(e.id)},children:(0,X.jsx)(`div`,{className:`comment-thread-slot-content`,children:(0,X.jsx)(fb,{projectId:i,comment:e,draftStore:l,currentUserId:s,unreadCommentMentionId:n,unreadReplyMentionIds:r,highlightedComment:O===e.id&&!k,highlightedReplyId:O===e.id?k:null,currentComment:we===e.id,showFilePath:!z&&b===`project`&&y,replyExpansion:ve.get(e.id),onReplyExpansionChange:t=>{ye(n=>n.get(e.id)===t?n:new Map(n).set(e.id,t))},selectedParticipantIds:z?void 0:he,highlightReplyParticipants:!z&&!_e,onMarkMentionRead:Ie,onFocus:()=>Pe(e),onActivate:()=>be(e.id),onToggle:()=>j(e),onReply:t=>M(e,t),onEdit:t=>N(e,t),onDelete:()=>ee(e),onEditReply:(t,n)=>te(e,t,n),onDeleteReply:t=>ne(e,t)})})},e.id)}),je.length===0&&!u&&!d&&(0,X.jsxs)(`div`,{className:`comment-review-empty`,role:`status`,children:[(0,X.jsx)(`span`,{className:`comment-review-empty-icon`,"aria-hidden":`true`,children:(0,X.jsx)(Zt,{size:23,strokeWidth:1.5})}),(0,X.jsx)(`p`,{children:z?R(c.some(e=>e.id===_&&e.resolved)?`editor.currentCommentResolved`:`editor.currentCommentUnavailable`):xe.unresolved+xe.resolved>0?R(`editor.commentNoMatches`):R(`editor.noComments`)})]}),!z&&B===`resolved`&&Oe&&(0,X.jsx)(`div`,{className:`comment-review-pagination`,children:(0,X.jsx)(`button`,{type:`button`,onClick:ke,children:R(`editor.commentLoadMore`)})})]})]}),t===`settings`&&(0,X.jsx)(Me,{onClose:n,children:(0,X.jsx)(Tb,{onClose:n,project:r,projectId:i,site:a,files:o,dictionaryWords:P,onDictionaryChange:re,editorPreferences:ie,onEditorPreferences:ae,spellCheckCount:oe,spellCheckUniqueCount:ce,spellCheckIndex:F,onSpellCheckNavigate:le,onProject:L},i)})]});return t===`comments`&&e!==void 0?e?(0,Ky.createPortal)(Ve,e):null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(km,{className:`resize-handle`}),(0,X.jsx)(wm,{id:`context`,defaultSize:`20%`,minSize:`15%`,maxSize:`38%`,children:Ve})]})}function Db(e){if(typeof globalThis.requestAnimationFrame==`function`){let t=globalThis.requestAnimationFrame(e);return()=>globalThis.cancelAnimationFrame(t)}let t=globalThis.setTimeout(e,0);return()=>globalThis.clearTimeout(t)}function Ob(){let e={line:1,column:1,offset:0},t=e.line,n=null,r=null,i=new Set,a=()=>{for(let e of i)e()},o=()=>{r=null;let e=n;n=null,e!==null&&e!==t&&(t=e,a())},s=e=>{n=e,r===null&&(r=Db(o))};return{getCursor:()=>e,getOutlineLine:()=>t,subscribe:e=>(i.add(e),()=>i.delete(e)),update:(n,i,a)=>{(e.line!==n||e.column!==i||e.offset!==a)&&(e={line:n,column:i,offset:a},(n!==t||r!==null)&&s(n))},reset:()=>{r?.(),r=null,n=null,e={line:1,column:1,offset:0},t!==1&&(t=1,a())},dispose:()=>{r?.(),r=null,n=null}}}function kb(e,t,n){return e.mainFile===t?e.items:!t||n.filePath!==t?[]:Ab(n.content).map(e=>({...e,path:t}))}function Ab(e){let t=[],n=/^\s*\\(part|chapter|section|subsection|subsubsection)\*?(?:\[[^\]]*\])?\{([^}]*)\}/,r={part:0,chapter:0,section:1,subsection:2,subsubsection:3};return e.split(`
18
+ `).forEach((e,i)=>{let a=e.match(n);a&&t.push({level:r[a[1]],title:a[2],line:i+1})}),t}var jb=e({ProjectWorkspace:()=>Rb}),Mb=(0,Y.lazy)(()=>f(()=>import(`./AgentTerminal-JKP2SVkZ.js`).then(e=>({default:e.AgentTerminal})),__vite__mapDeps([39,2,3,7,11,6,1,4,5,8,14,15,16,40,18,41,42,20]),import.meta.url)),Nb=(0,Y.lazy)(()=>f(()=>import(`./WordCountDialog-BODhL9iz.js`).then(e=>({default:e.WordCountDialog})),__vite__mapDeps([43,3,2,11,6,1,4,5,7,8,38]),import.meta.url)),Pb=null;function Fb(){return Pb||=f(()=>import(`./citationLibrary-BzlqZiFU.js`),__vite__mapDeps([23,2]),import.meta.url).catch(e=>{throw Pb=null,e}),Pb}function Ib(e){return e instanceof Error&&e.name===`AbortError`}var Lb=300;function Rb(e){return(0,X.jsx)(y_,{children:(0,X.jsx)(Xv,{projectId:e.projectId,user:e.user,children:t=>(0,X.jsx)(zb,{...e,collaboration:t})})},`${e.user.id}:${e.projectId}`)}function zb({site:e,user:t,projectId:n,preload:r,mentionId:i=null,onMentionTargeted:a,onMentionsRead:o,onBack:s,collaboration:c}){let{t:u}=Ae(),d=(0,Y.useRef)(n),f=R(t.id,n),[p,m]=(0,Y.useState)(!1);d.current=n;let[h,g]=(0,Y.useState)(null);(0,Y.useEffect)(()=>(document.title=h?.name?`${e.siteName} | ${h.name}`:e.siteName,()=>{document.title=e.siteName}),[h?.name,e.siteName]);let[_,v]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)({mainFile:``,items:[]}),[D,O]=(0,Y.useState)(``),[k,A]=(0,Y.useState)(``),[j,M]=(0,Y.useState)(``),[N,ee]=(0,Y.useState)({filePath:``,content:``}),[te,ne]=(0,Y.useState)({path:``,hasIncludes:!1}),[P,re]=(0,Y.useState)(``),[ae,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(`editor.saved`),[F,I]=(0,Y.useState)(null),le=(0,Y.useRef)(F);le.current=F;let L=(0,Y.useRef)(null);L.current||=Ob();let z=L.current,[B,V]=(0,Y.useState)(`pdf`),[ue,de]=(0,Y.useState)(`log`),pe=e=>{e===`pdf`?V(`pdf`):(e===`diagnostics`||de(e),V(`diagnostics`))},{workspaceLayout:he,setWorkspaceLayout:ge}=yy(t.id,n),[_e,H]=(0,Y.useState)(``),[ve,ye]=(0,Y.useState)(``),[U,be]=(0,Y.useState)({selectedText:``,startOffset:0,endOffset:0}),xe=(0,Y.useRef)({selectedText:``,startOffset:0,endOffset:0}),Se=e=>{let t=xe.current;(t.selectedText!==e.selectedText||t.startOffset!==e.startOffset||t.endOffset!==e.endOffset)&&(xe.current=e,be(e))},[K,Ce]=(0,Y.useState)(null),[we,Te]=(0,Y.useState)(null),[Ee,q]=(0,Y.useState)(null),[Oe,je]=(0,Y.useState)(null),[Me,Ne]=(0,Y.useState)(null),[Ie,J]=(0,Y.useState)(null),[Le,Re]=(0,Y.useState)(!1),[ze,Be]=(0,Y.useState)(!1),[Ve,He]=(0,Y.useState)(!1),[Ue,We]=(0,Y.useState)(!1),[Ge,Ke]=(0,Y.useState)(null),[qe,Je]=(0,Y.useState)(!1),[Ye,Xe]=(0,Y.useState)(null),[Ze,Qe]=(0,Y.useState)(!1),[$e,et]=(0,Y.useState)(!1),[tt,nt]=(0,Y.useState)(`full`),[rt,it]=(0,Y.useState)(``),[at,ot]=(0,Y.useState)(!1),[st,ct]=(0,Y.useState)(``),[lt,ut]=(0,Y.useState)(null),[dt,ft]=(0,Y.useState)(!1),[pt,mt]=(0,Y.useState)(null),[ht,gt]=(0,Y.useState)(!1),[_t,vt]=(0,Y.useState)(()=>ie(t.id,n));(0,Y.useEffect)(()=>{let e=document.documentElement,t=_t.showTooltips?`on`:`off`;return e.setAttribute(`data-texlite-tooltips`,t),()=>{e.getAttribute(`data-texlite-tooltips`)===t&&e.removeAttribute(`data-texlite-tooltips`)}},[_t.showTooltips]);let[yt,bt]=(0,Y.useState)([]),xt=(0,Y.useRef)([]);xt.current=yt;let St=(0,Y.useRef)(null),Ct=(0,Y.useRef)(null),wt=(0,Y.useRef)(0),Tt=(0,Y.useRef)(0),Et=(0,Y.useRef)(``),Dt=(0,Y.useRef)(``),Ot=(0,Y.useRef)(()=>void 0),kt=(0,Y.useRef)(he),At=(0,Y.useRef)(0),jt=(0,Y.useRef)(null),Mt=(0,Y.useRef)(null),Nt=(0,Y.useRef)(null),Pt=(0,Y.useRef)(null),Ft=(0,Y.useRef)(null),It=(0,Y.useRef)(null),Lt=(0,Y.useRef)(null),Rt=(0,Y.useRef)(null),zt=(0,Y.useRef)(null),Bt=(0,Y.useRef)(!1),Ht=(0,Y.useRef)(null),Ut=(0,Y.useRef)(s),Wt=(0,Y.useRef)(a),Gt=(0,Y.useRef)(o);Ut.current=s,Wt.current=a,Gt.current=o,Et.current=D,Dt.current=k,kt.current=he,(0,Y.useEffect)(()=>{if(!ve)return;let e=window.setTimeout(()=>ye(``),3e3);return()=>window.clearTimeout(e)},[ve]);let Kt=(0,Y.useCallback)((e,t,n=0)=>{z.update(e,t,n)},[z]);(0,Y.useEffect)(()=>()=>z.dispose(),[z]),(0,Y.useEffect)(()=>()=>{Rt.current?.abort(),Rt.current=null},[]);let qt=e=>{let t=xt.current,n=e(t);n!==t&&(xt.current=n,bt(n))};(0,Y.useEffect)(()=>{xt.current=[],bt([]),mt(null),Ke(null),It.current?.abort(),It.current=null,Lt.current?.abort(),Lt.current=null,Rt.current?.abort(),Rt.current=null,zt.current=null,je(null),Ne(null),J(null),et(!1),ot(!1),ct(``),ut(null)},[n]);let Jt=e=>{let t=xt.current,n=t.indexOf(e);if(n<0)return;let r=t.filter(t=>t!==e);if(xt.current=r,bt(r),Et.current!==e)return;let i=r.length>0?r[Math.min(n,r.length-1)]:h?.mainFile??``;O(i)},{status:Yt,synced:Xt,activeSessions:Zt,formatLeaseStates:Qt,compileState:$t,setCompileState:en,filesEvent:tn,commentsRevision:nn,historyWarning:rn,dictionaryRevision:an,chktexSettingsRevision:on,localDraftReady:sn,permission:cn,reconnect:ln,protocolUpgradeRequired:un,permissionDowngrade:dn,dismissPermissionDowngrade:fn,discardLocalDraft:pn}=x_(c,k,h?.permission??`read`,_),{unreadMentions:mn,mentionsError:hn,markMentionRead:gn,markAllMentionsRead:_n}=v_(n,nn,H,(e,t)=>Gt.current?.(e,t)),{pdfTarget:vn,pdfViewport:yn,sourceJump:bn,setPdfViewport:xn,resetPdfViewport:Sn,clearPdfViewport:Cn,jumpToSource:Tn,syncSourceToPdf:En,syncPdfToSource:Dn,syncVisiblePdfToSource:On}=gy({projectId:n,mainFile:k,activeFile:D,onOpenSourceFile:e=>Ot.current(e),onError:H,onShowPdf:()=>pe(`pdf`),onShowEditor:()=>{kt.current===`pdf-only`&&ge(`editor-pdf`)}}),kn=!!(h&&h.chktexEnabled&&D&&Xt&&Vd(D)),An=py({active:kn,projectId:n,activeFile:D,content:j}),jn=fy({active:!!(h&&D&&Xt&&Bd(D)&&(_t.spellCheck||h.chktexEnabled&&Vd(D))),harperEnabled:_t.spellCheck,projectId:n,activeFile:D,content:j,dictionaryWords:b,additionalIssues:An.issues,additionalIssuesReady:!kn||An.checked});(0,Y.useEffect)(()=>{vt(ie(t.id,n))},[t.id,n]);let Mn=e=>{M(e)};(0,Y.useEffect)(()=>{if(!D||P!==D){ee(e=>e.filePath||e.content?{filePath:``,content:``}:e);return}let e=D,t=j,n=window.setTimeout(()=>{ee(n=>n.filePath===e&&n.content===t?n:{filePath:e,content:t})},Lb);return()=>window.clearTimeout(n)},[D,P,j]),(0,Y.useEffect)(()=>{Et.current=D,z.reset(),Se({selectedText:``,startOffset:0,endOffset:0}),_t.openFilesInTabs?D&&qt(e=>e.includes(D)?e:[...e,D]):xt.current.length>0&&(xt.current=[],bt([]))},[D,_t.openFilesInTabs,n,z]),(0,Y.useEffect)(()=>{if(!ae)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ae]),(0,Y.useEffect)(()=>{if(Yt!==`disconnected`)return;let e=new AbortController;return G(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||(g(t),H(``))}).catch(e=>{Ib(e)||(e instanceof De&&[401,403,404].includes(e.status)?(H(W(e)),Ut.current()):H(u(`errors.collaborationUnavailable`)))}),()=>e.abort()},[Yt,n,u]);let Nn=async(e={},t=Dt.current)=>{jt.current?.abort(),jt.current=null;let r=e.signal?null:new AbortController;r&&(jt.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await G(`/api/projects/${n}/completions${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&C(a.index)}catch(t){if(Ib(t))return;(!e.isCurrent||e.isCurrent())&&C(null)}finally{r&&jt.current===r&&(jt.current=null)}},Pn=async(e={},t=Dt.current)=>{Nt.current?.abort(),Nt.current=null;let r=e.signal?null:new AbortController;r&&(Nt.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await G(`/api/projects/${n}/outline${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&Dt.current===t&&T({mainFile:t,items:a.outline})}catch(e){if(Ib(e))return}finally{r&&Nt.current===r&&(Nt.current=null)}},Fn=async(e={})=>{Pt.current?.abort(),Pt.current=null;let t=e.signal?null:new AbortController;t&&(Pt.current=t);try{let r=await G(`/api/projects/${n}/dictionary`,{signal:e.signal??t?.signal});(!e.isCurrent||e.isCurrent())&&x(r.words)}catch(t){if(Ib(t))return;(!e.isCurrent||e.isCurrent())&&x([])}finally{t&&Pt.current===t&&(Pt.current=null)}};(0,Y.useEffect)(()=>{let e=!1,t=++At.current,i=new AbortController,a=()=>!e&&At.current===t,o=!1,s=``;g(null),qn([]),T({mainFile:``,items:[]}),O(``),A(``),ne({path:``,hasIncludes:!1}),M(``),re(``),en(null),Cn(),C(null),x([]),Pe();let c=(r?.projectId===n?r.project:G(`/api/projects/${n}`,{signal:i.signal})).then(e=>{a()&&(o=!0,s=e.project.mainFile,g(e.project),O(e.project.mainFile),Dt.current=e.project.mainFile,A(e.project.mainFile),mr(new Set(ay(e.project.mainFile))))}).catch(e=>{a()&&H(W(e))}),l=G(`/api/projects/${n}/files`,{signal:i.signal}).then(e=>{a()&&qn(e.files)}).catch(e=>{a()&&H(W(e))}),u=null;return Promise.allSettled([c,l]).then(()=>{a()&&o&&(u=window.setTimeout(()=>{a()&&Promise.all([Nn({signal:i.signal,isCurrent:a},Dt.current||s),Fn({signal:i.signal,isCurrent:a})])},0))}),()=>{e=!0,u!==null&&window.clearTimeout(u),i.abort(),jt.current?.abort(),jt.current=null,Nt.current?.abort(),Nt.current=null,Pt.current?.abort(),Pt.current=null,Ft.current?.abort(),Ft.current=null}},[n,r]),(0,Y.useEffect)(()=>{h&&k&&(Mt.current===n?Nn({},k):Mt.current=n)},[k,h?.id,n]),(0,Y.useEffect)(()=>{if(!i||!h)return;Lt.current?.abort();let e=new AbortController;return Lt.current=e,G(`/api/projects/${n}/mentions/${encodeURIComponent(i)}`,{signal:e.signal}).then(({mention:t})=>{e.signal.aborted||(je(t),q(null),Ce(`comments`),O(t.filePath),Wt.current?.(t.id))}).catch(t=>{Ib(t)||e.signal.aborted||(H(W(t)),Wt.current?.(i))}).finally(()=>{Lt.current===e&&(Lt.current=null)}),()=>e.abort()},[i,h?.id,n]),(0,Y.useEffect)(()=>{an&&Fn()},[an,n]),(0,Y.useEffect)(()=>{if(!on)return;let e=new AbortController;return G(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||g(e=>e?{...e,chktexEnabled:t.chktexEnabled}:t)}).catch(e=>{Ib(e)||H(W(e))}),()=>e.abort()},[on,n]),(0,Y.useEffect)(()=>{h&&Yt===`connected`&&cn!==h.permission&&g(e=>e&&{...e,permission:cn})},[cn,h?.permission]),(0,Y.useEffect)(()=>{if(!tn)return;let t=tn.kind===`delete`&&!!tn.path&&oy(tn.path,Et.current),r=tn.kind===`delete`&&!!tn.path&&oy(tn.path,Dt.current);if(tn.kind===`move`&&tn.source&&tn.destination){let e=tn.source,t=tn.destination,n=n=>n===e?t:n.startsWith(`${e}/`)?`${t}${n.slice(e.length)}`:n;O(e=>n(e)),A(e=>n(e)),ur(e=>e&&n(e)),fr(e=>e&&n(e)),qt(e=>e.map(n))}t&&(O(``),re(``),Mn(``),ye(u(`editor.fileDeletedByCollaborator`,{path:tn.path}))),tn.kind===`delete`&&tn.path&&(ur(e=>e&&oy(tn.path,e)?null:e),fr(e=>oy(tn.path,e)?``:e),er(e=>e&&oy(tn.path,e.path)?null:e),qt(e=>e.filter(e=>!oy(tn.path,e)))),Ft.current?.abort();let i=new AbortController;Ft.current=i,Promise.all([Jn({signal:i.signal}),G(`/api/projects/${n}`,{signal:i.signal})]).then(([n,a])=>{if(g(a.project),r&&A(a.project.mainFile),t&&n){let t=n.find(e=>e.type===`file`&&e.path===a.project.mainFile)??n.find(t=>t.type===`file`&&wn(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024);O(t?.path??``)}Nn({signal:i.signal}),Pn({signal:i.signal},r?a.project.mainFile:Dt.current)}).catch(e=>{Ib(e)}).finally(()=>{Ft.current===i&&(Ft.current=null)})},[tn?.revision]),(0,Y.useEffect)(()=>{if(c.setActiveFile(D),!D)return;re(``),ce(`editor.loading`);let e=c.getText(D),t=(t,n)=>{Mn(e.toString()),re(D),n?.local&&h?.permission!==`read`?(wt.current+=1,oe(!0),ce(`editor.pending`)):wt.current<=Tt.current&&ce(le.current?`editor.savedAt`:`editor.saved`)};return e.observe(t),(Xt||sn)&&t(),()=>{e.unobserve(t)}},[D,c,Xt,sn,h?.permission]);let In=async()=>{if(!Xt)throw Error(`Collaboration is not synchronized`);let e=wt.current,t=await c.flush();return Tt.current=Math.max(Tt.current,e),I(t.persistedAt),/\.tex$/i.test(Et.current)&&Pn(),wt.current===e?(oe(!1),ce(`editor.savedAt`)):ce(`editor.pending`),t};(0,Y.useEffect)(()=>{if(!ae||!D||!Xt)return;ce(`editor.pending`);let e=window.setTimeout(()=>{ce(`editor.saving`),In().catch(()=>{ce(`editor.saveFailed`)})},750);return()=>window.clearTimeout(e)},[j,ae,D,Xt]);let Ln=async()=>{if(!h||h.permission===`read`||!Xt||!D)return!1;ce(`editor.saving`);try{return await In(),Nn(),!0}catch(e){return ce(`editor.saveFailed`),H(W(e)||u(`errors.collaborationUnavailable`)),!1}},Rn=async e=>{if(!h||at)return;let t=e===`full`?Dt.current||h.mainFile:Et.current,r=e===`selection`?xe.current.selectedText:``;if(!t)return;if(e===`selection`&&(!r.trim()||!/\.(?:tex|sty|cls)$/i.test(t))){ye(u(`editor.wordCountSelectionEmpty`));return}It.current?.abort();let i=new AbortController;It.current=i,nt(e),it(t),ut(null),ct(``),et(!0),ot(!0);try{if(e===`full`&&ae&&h.permission!==`read`&&!await Ln())throw Error(u(`editor.wordCountSaveRequired`));let a=e===`selection`?{mode:e,path:t,source:r}:{mode:e,mainFile:t},o=await G(`/api/projects/${n}/word-count`,{method:`POST`,body:JSON.stringify(a),signal:i.signal});if(i.signal.aborted)return;ut(o)}catch(e){if(Ib(e))return;i.signal.aborted||ct(W(e))}finally{It.current===i&&(It.current=null,ot(!1))}},zn=async(t,n,r=_t.texFmtConfig)=>{if(/\.bib$/i.test(t))try{return{formatted:await lh(n,e.maxCitationBibtexBytes)}}catch(t){throw t instanceof ih?t.kind===`too-large`?Error(u(`citationLibrary.fileTooLarge`,{size:`${Math.round(e.maxCitationBibtexBytes/1024)} KB`})):t.kind===`invalid`?Error(u(`citationLibrary.fileInvalid`)):Error(u(t.kind===`timeout`?`editor.bibtexFormatterTimeout`:`editor.bibtexFormatterUnavailable`)):t}return{formatted:(await Jm(n,r)).output}},Bn=async(e,t,n,r=0)=>{if(!/\.bib$/i.test(e))return eh(t,n,r);try{return await uh(t,n,r)}catch(e){throw e instanceof ih?Error(u(e.kind===`timeout`?`editor.bibtexFormatterTimeout`:`editor.bibtexFormatterUnavailable`)):e}},Vn=async e=>{if(!h||h.permission===`read`||!Xt||Bt.current||!Zm(Et.current))return;let t=Et.current,n=c.getText(t);Bt.current=!0,ft(!0);let r=()=>{},i=new Promise(e=>{r=e});Ht.current=i;let a=null;try{a=await c.acquireFormatLease(t);let r=n.toString(),{formatted:i}=await zn(t,r,e);if(Et.current!==t||n.toString()!==r){H(u(`editor.formatSourceChanged`));return}await a.confirm();let o=await Bn(t,r,i);if(Et.current!==t||n.toString()!==r||(await a.confirm(),Et.current!==t||n.toString()!==r)){H(u(`editor.formatSourceChanged`));return}o.length&&c.applyTextEdits(t,o),o.length&&await In(),mt(null),H(``),ye(u(`editor.formatFileComplete`))}catch(e){Um(e)?(mt({action:`file`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFileFailed`,{message:W(e)}))}finally{a&&await a.release(),Bt.current=!1,ft(!1),r(),Ht.current===i&&(Ht.current=null)}},Hn=async()=>{if(!_t.formatOnCompile||!h||h.permission===`read`||!Xt||!Zm(Et.current)||Bt.current)return;let e=Et.current,t=c.getText(e);Bt.current=!0,ft(!0);let n=null;try{n=await c.acquireFormatLease(e);let r=t.toString(),{formatted:i}=await zn(e,r);await n.confirm();let a=await Bn(e,r,i);if(Et.current!==e||t.toString()!==r||(await n.confirm(),Et.current!==e||t.toString()!==r))throw Error(u(`editor.formatSourceChanged`));a.length&&c.applyTextEdits(e,a),a.length&&await c.flush(),mt(null)}catch(e){Um(e)?(mt({action:`file`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFailedContinue`,{message:W(e)}))}finally{n&&await n.release(),Bt.current=!1,ft(!1)}},Un=async()=>(Ht.current&&await Ht.current,await Hn(),Ln()),Wn=async e=>{if(!h||h.permission===`read`||!Xt||Bt.current||!Zm(Et.current))return;let t=xe.current;if(!t.selectedText.trim()){ye(u(`editor.formatSelectionRequired`));return}let n=Et.current,{startOffset:r,endOffset:i,selectedText:a}=t,o=c.getText(n);if(o.toString().slice(r,i)!==a){H(u(`editor.formatSelectionChanged`));return}Bt.current=!0,ft(!0);let s=()=>{},l=new Promise(e=>{s=e});Ht.current=l;let d=null;try{if(d=await c.acquireFormatLease(n),o.toString().slice(r,i)!==a){H(u(`editor.formatSelectionChanged`));return}let t=$m(a,(await zn(n,a,e)).formatted);await d.confirm();let s=await Bn(n,a,t,r);if(Et.current!==n||o.toString().slice(r,i)!==a||(await d.confirm(),Et.current!==n||o.toString().slice(r,i)!==a)){H(u(`editor.formatSelectionChanged`));return}s.length&&c.applyTextEdits(n,s),s.length&&await In(),mt(null),H(``),ye(u(`editor.formatSelectionComplete`))}catch(e){Um(e)?(mt({action:`selection`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFailed`,{message:W(e)}))}finally{d&&await d.release(),Bt.current=!1,ft(!1),s(),Ht.current===l&&(Ht.current=null)}},Gn=async t=>{let n=Et.current;if(!/\.bib$/i.test(n)||h?.permission===`read`||!Xt)return ye(u(`citationLibrary.importRequiresWrite`)),!1;let r=c.getText(n),i;try{i=await Fb()}catch(e){return H(W(e)),!1}if(Et.current!==n||!Xt)return!1;let a=r.toString(),o=i.parseBibEntriesResult(a,e.maxCitationBibtexBytes);if(o.status===`too-large`)return ye(u(`citationLibrary.fileTooLarge`,{size:i.citationBibtexLimitLabel(e.maxCitationBibtexBytes)})),!1;if(o.status===`invalid`)return ye(u(`citationLibrary.fileInvalid`)),!1;if(o.entries.some(e=>e.citationKey.toLowerCase()===t.citationKey.toLowerCase()))return ye(u(`citationErrors.alreadyInFile`,{key:t.citationKey})),!1;let s=Math.max(0,Math.min(a.length,z.getCursor().offset)),l=a.slice(0,s),d=a.slice(s),f=l?l.endsWith(`
19
+
20
+ `)?``:l.endsWith(`
21
+ `)?`
22
+ `:`
23
+
24
+ `:``,p=d?d.startsWith(`
25
+
26
+ `)?``:d.startsWith(`
27
+ `)?`
28
+ `:`
29
+
30
+ `:``;return c.applyTextEdits(n,[{from:s,to:s,replacement:`${f}${t.bibtex.trim()}${p}`}]),ye(u(`citationLibrary.imported`,{key:t.citationKey})),!0},{files:Kn,setFiles:qn,loadFiles:Jn,newFileOpen:Yn,setNewFileOpen:Xn,newFilePath:Zn,setNewFilePath:Qn,resourcePreview:$n,setResourcePreview:er,resourcePreviewLoading:tr,setResourcePreviewLoading:nr,newFolderOpen:rr,setNewFolderOpen:ir,newFolderName:ar,setNewFolderName:or,fileDialogError:sr,setFileDialogError:cr,selectedFolder:lr,setSelectedFolder:ur,selectedFile:dr,setSelectedFile:fr,expandedFolders:pr,setExpandedFolders:mr,moveEntry:hr,setMoveEntry:gr,moveName:_r,setMoveName:vr,moveDestination:yr,setMoveDestination:br,deleteEntry:xr,setDeleteEntry:Sr,fileDragActive:Cr,setFileDragActive:wr,uploadConflict:Tr,setUploadConflict:Er,uploadingFiles:Dr,uploadFeedback:Or,dismissUploadFeedback:Z,directoryEntries:kr,visibleEntries:Ar,createFile:jr,createFolder:Mr,uploadFiles:Nr,upload:Pr,openFile:Fr,movePath:Ir,movePathToFolder:Lr,removePath:Rr}=uy({projectId:n,site:e,activeFile:D,dirty:ae,save:Ln,onError:H,onProject:g,onActiveFile:O,onActiveMainFile:A});Ot.current=e=>{ur(null),fr(e),mr(t=>new Set([...t,...ay(e)])),O(e)};let zr=e=>{if(e.id!==d.current)return;let t=e.mainFile!==h?.mainFile;g(e),t&&(Dt.current=e.mainFile,Et.current=e.mainFile,A(e.mainFile),O(e.mainFile),ur(null),fr(e.mainFile),mr(t=>new Set([...t,...ay(e.mainFile)])))},Br=()=>Dt.current||h?.mainFile||``,Vr=()=>{let e=Br(),t=Et.current;if(!t||!/\.tex$/i.test(t))return e;let n=Kn.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length;return wy(c.getText(t).toString())||n===1?(e!==t&&(Dt.current=t,A(t)),t):e===t&&h?.mainFile&&h.mainFile!==t?(Dt.current=h.mainFile,A(h.mainFile),h.mainFile):e};(0,Y.useEffect)(()=>{D&&D===k&&P===D&&N.filePath===D&&D.toLocaleLowerCase().endsWith(`.tex`)&&Kn.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length!==0&&D!==h?.mainFile&&!wy(N.content)&&h?.mainFile&&(Dt.current=h.mainFile,A(h.mainFile))},[D,k,P,N,Kn,h?.mainFile]),(0,Y.useEffect)(()=>{if(!_t.openFilesInTabs||Kn.length===0)return;let t=new Set(Kn.filter(t=>t.type===`file`&&wn(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024).map(e=>e.path));qt(e=>{let n=e.filter(e=>t.has(e));return n.length===e.length?e:n})},[Kn,_t.openFilesInTabs]);let{comments:Hr,projectCommentSummary:Ur,commentsFilePath:Wr,commentsReady:Gr,fileCommentsLoading:Kr,fileCommentsError:qr,retryFileComments:Jr,reviewComments:Yr,reviewCommentsLoading:Xr,reviewCommentsError:Zr,retryReviewComments:Qr,commentScope:$r,setCommentScope:ei,focusComment:ti,setFocusComment:ni,commentOpen:ri,openComment:ii,closeComment:Q,commentText:ai,setCommentText:oi,commentSelection:si,commentSubmitting:ci,commentError:li,addComment:ui,toggleComment:di,replyToComment:fi,editComment:pi,deleteComment:mi,editCommentReply:hi,deleteCommentReply:gi,commentDraftStore:_i,cancelComment:vi,commentDraftRestored:yi,commentDraftCanRetarget:bi,useCurrentCommentSelection:xi}=r_({projectId:n,activeFile:D,content:j,permission:h?.permission,revision:nn,sourceOrderRevision:`${h?.mainFile??``}\0${tn?.revision??``}`,selection:U,save:Ln,saveFailureMessage:u(`errors.collaborationUnavailable`),onError:H,onAdded:()=>{q(null),Ce(`comments`)}});(0,Y.useEffect)(()=>{if(!k||N.filePath!==k)return;let e=Ed(N.content).length>0;ne(t=>t.path===k&&t.hasIncludes===e?t:{path:k,hasIncludes:e})},[k,N]),(0,Y.useEffect)(()=>{if(!k||!Xt||D===k)return;let e=c.getText(k),t=null,n=()=>{let t=Ed(e.toString()).length>0;ne(e=>e.path===k&&e.hasIncludes===t?e:{path:k,hasIncludes:t})},r=()=>{t!==null&&window.clearTimeout(t),t=window.setTimeout(()=>{t=null,n()},Lb)};return n(),e.observe(r),()=>{t!==null&&window.clearTimeout(t),e.unobserve(r)}},[D,k,c,Xt]);let Si=(0,Y.useMemo)(()=>te.path===k&&te.hasIncludes||!!Ur?.filePaths.some(e=>e!==D),[k,te,Ur,D]),Ci=e=>{J(null),Ce(`comments`),ni(null),Ne(e),Et.current!==e.filePath&&Tn(e.filePath,e.startLine,1)},wi=(e,t=!1)=>{let n=Hr.find(t=>t.id===e&&t.filePath===D);!n||n.resolved||n.orphaned||(Ne(null),ni(null),je(null),t&&K===`comments`&&Ee===n.id?(q(null),J(null),Ce(null)):(q(n.id),J(e=>({id:n.id,filePath:n.filePath,nonce:(e?.nonce??0)+1})),Ce(`comments`)))};(0,Y.useEffect)(()=>{J(null),q(null)},[D]),(0,Y.useEffect)(()=>{if(!Me)return;let e=h_(Me,D,P,Wr,Gr,Hr);e?(ni({...e}),Ne(null)):Me.filePath===D&&P===D&&Wr===D&&Gr&&Ne(null)},[D,Hr,Wr,Gr,P,Me,ni]),(0,Y.useEffect)(()=>{if(!Oe||D!==Oe.filePath||K!==`comments`)return;let e=Hr.find(e=>e.id===Oe.commentId);if(!e||Oe.replyId&&!e.replies.some(e=>e.id===Oe.replyId)||zt.current===Oe.id)return;zt.current=Oe.id,Ci(e);let t=window.setTimeout(()=>je(e=>e?.id===Oe.id?null:e),3e3);return()=>window.clearTimeout(t)},[D,Hr,K,Oe]);let{pdfUrl:Ti,pdfCompiledAt:Ei,pdfSizeBytes:Di,pdfLoadingMode:Oi,pdfLoading:ki,compileLog:Ai,compileDiagnostics:ji,compileOutcome:Mi,artifacts:Ni,artifactPreview:Pi,artifactLoading:Fi,editorNotice:Ii,localCompiling:Li,cancelling:Ri,cleaning:zi,compile:Bi,cancelCompile:Vi,cleanCompile:Hi,viewArtifact:Ui,pdfDisplayed:Wi}=ny({projectId:n,project:h,mainFile:k,resolveCompileMainFile:Vr,getCurrentMainFile:Br,initialLatest:r?.projectId===n?r.latestCompile:null,collaborationSynced:Xt,pdfVisible:B===`pdf`&&he!==`editor-only`,sharedState:$t,onSharedState:en,save:Un,loadOutline:(e,t)=>Pn({signal:e},t),onPreviewTab:pe,onError:H,onCompileStart:()=>{H(``),ye(``)},onCompileSuccess:()=>{let e=Et.current;if(e){let t=z.getCursor();En(e,t.line,t.column,{silent:!0})}},onPdfChanged:Cn});(0,Y.useEffect)(()=>{if(!h||!k||!Ti&&ki)return;let e=window.setTimeout(()=>v(!0),Ti?150:0);return()=>window.clearTimeout(e)},[h,ki,Ti]),(0,Y.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&!e.shiftKey&&e.key.toLocaleLowerCase()===`p`&&(e.preventDefault(),Qe(!0))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let Gi=e=>{fe(t.id,n,e),vt(e)},Ki=(e=!1)=>{let t=pt;if(!t)return;mt(null),H(``),e&&Gi({..._t,texFmtConfig:``});let n=e?``:void 0;t.action===`selection`?Wn(n):Vn(n)},qi=async()=>{gt(!0);try{await pn()||(H(u(`editor.collaboration.permissionDowngradeOtherTabBlocked`)),gt(!1))}catch(e){H(W(e)),gt(!1)}},Ji=()=>{Ct.current?.isCollapsed()?Ct.current.expand():Ct.current?.collapse()},Yi=(0,Y.useMemo)(()=>kb(w,k,N),[w,k,N]),Xi=(0,Y.useMemo)(()=>dh(Ai,Mi),[Ai,Mi]),Zi=he!==`pdf-only`,Qi=he!==`editor-only`,$i=Sy(Zi,Qi,K===`settings`||K===`comments`&&!Qi),ea=e=>{ge(e),e===`pdf-only`&&pe(`pdf`)},ta=(0,Y.useCallback)(e=>{Rt.current?.abort();let t=new AbortController;Rt.current=t;let r=Et.current,i=Dt.current,a=new URLSearchParams({kind:e.kind,key:e.key,...r?{path:r}:{},...i?{mainFile:i}:{}});G(`/api/projects/${n}/references/resolve?${a}`,{signal:t.signal}).then(({target:n})=>{t.signal.aborted||Et.current!==r||Dt.current!==i||(n?(kt.current===`pdf-only`&&ea(`editor-pdf`),Tn(n.path,n.line,n.column)):H(u(e.kind===`citation`?`editor.citationTargetNotFound`:`editor.labelTargetNotFound`,{key:e.key})))}).catch(e=>{!t.signal.aborted&&!Ib(e)&&H(W(e))}).finally(()=>{Rt.current===t&&(Rt.current=null)})},[Tn,n,u]),na=xr?Zt.filter(e=>e.filePath&&oy(xr.path,e.filePath)):[];if(!h)return(0,X.jsxs)(`div`,{className:`center-card`,children:[(0,X.jsx)(`p`,{children:_e||u(`common.loading`)}),_e&&(0,X.jsx)(`button`,{className:`primary`,onClick:s,children:u(`editor.backToProjects`)})]});let ra=h.permission===`read`||!Xt,ia=Qt.find(e=>e.path===D),aa=ia&&!dt?ia:null,oa=(e,t)=>{if(ra)return;let n=Et.current;if(n){if(c.getText(n).toString().slice(e.from,e.to)!==e.word)H(u(`editor.spellCheckSourceChanged`));else try{c.applyTextEdits(n,[{from:e.from,to:e.to,replacement:t}])}catch(e){H(W(e))}}},sa=$t?.mainFile===k&&($t.status===`queued`||$t.status===`running`),ca=Li||sa||zi,la=D?c.getText(D):null,ua=Ei?me(Ei,l.resolvedLanguage,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`}):``,da=k.split(`/`).at(-1)??k,fa=Xi.warnings.length+Xi.errors.length+Ni.length,pa=Ti?`${Ti}${Ti.includes(`?`)?`&`:`?`}download=1`:``,ma=k||h.mainFile,ha=hy(D,ma),ga=!!(ma&&/\.tex$/i.test(ma)),_a=e=>{let t=Kn.find(t=>t.path===e);t&&wn(t.path,t.textContent)?Fr(t):Jt(e)},va=e=>{document.getElementById(`editor-tab-${encodeURIComponent(e)}`)?.focus()},ya=(e,t)=>{if(![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key))return;e.preventDefault();let n=e.key===`Home`?0:e.key===`End`?yt.length-1:(t+(e.key===`ArrowLeft`?-1:1)+yt.length)%yt.length,r=yt[n];r&&(_a(r),window.requestAnimationFrame(()=>va(r)))},ba=ca?sa?$t?.status===`queued`?u(`editor.compileQueued`):u(`editor.compilingBy`,{name:$t?.requestedBy.name??u(`common.user`)}):u(`editor.compiling`):Mi===`failed`?Ti&&Ei?u(`editor.compileFailedRetained`,{time:me(Ei,l.resolvedLanguage)}):u(`editor.compileFailedNoPdf`):Mi===`cancelled`?u(`compileControls.cancelled`):``,xa=Oy(Yt,se,Yt===`disconnected`&&(ae||c.hasWritableDraft)),Sa=xa===`editor.savedAt`&&F?u(`editor.savedAt`,{time:me(F,l.resolvedLanguage,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}):u(xa);return(0,X.jsxs)(`div`,{className:`workspace`,"data-texlite-tooltips":_t.showTooltips?`on`:`off`,children:[(0,X.jsx)(Dy,{agentTerminal:Zi&&f.visible&&h.permission!==`read`?{open:p,activeCount:f.activeCount,toggle:()=>m(e=>!e)}:void 0,site:e,project:h,activeFile:D,saveStateLabel:Sa,editorPreferences:_t,activeSessions:Zt,collaborationStatus:Yt,reconnectCollaboration:ln,protocolUpgradeRequired:un,showEditor:Zi,filesCollapsed:Le,toggleFilesPanel:Ji,workspaceLayout:he,changeWorkspaceLayout:ea,onBack:s,onShare:()=>Be(!0),showCitationLibrary:Zi&&/\.bib$/i.test(D),citationLibraryOpen:qe,onCitationLibrary:()=>Je(!0),onHistory:()=>We(!0),onGit:()=>He(!0),canManageGit:h.ownerId===t.id,formatting:dt,readOnly:ra,collaborationSynced:Xt,onToggleComments:()=>{let e=K!==`comments`||!!Ee;q(null),e&&ei(`project`),Ce(e?`comments`:null)},commentsOpen:K===`comments`,unresolvedCommentCount:Ur?.unresolvedCount??h.unresolvedCommentCount??0,onToggleSettings:()=>Ce(K===`settings`?null:`settings`),settingsOpen:K===`settings`,compileBusy:ca,sharedCompiling:sa,localCompiling:Li,cancelling:Ri,onCompile:Bi,onCancelCompile:()=>void Vi()}),un&&(0,X.jsxs)(`div`,{className:`workspace-update-banner`,role:`alert`,children:[(0,X.jsx)(y,{size:15}),(0,X.jsx)(`span`,{children:u(`workspaceUpdates.protocolUpgrade`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:u(`common.reload`)})]}),ba&&(0,X.jsxs)(`div`,{className:`compile-status-strip${Mi===`failed`?` failed`:``}`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(Fe,{className:ca?`spin`:``,size:14}),(0,X.jsx)(`span`,{children:ba})]}),(jn.error||An.error||pt||aa)&&(0,X.jsxs)(`div`,{className:`client-tool-recoveries`,children:[jn.error&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:jn.error,children:[(0,X.jsx)(y,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:u(`editor.harperRecoveryTitle`)}),u(`editor.harperFallbackHint`)]}),(0,X.jsx)(`div`,{className:`client-tool-recovery-actions`,children:(0,X.jsx)(`button`,{type:`button`,onClick:jn.retry,children:u(`common.retry`)})}),(0,X.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:jn.dismissError,children:(0,X.jsx)(E,{size:13})})]}),An.error&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:An.error,children:[(0,X.jsx)(y,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:u(`chktex.recoveryTitle`)}),u(`chktex.recoveryHint`)]}),(0,X.jsx)(`div`,{className:`client-tool-recovery-actions`,children:(0,X.jsx)(`button`,{type:`button`,onClick:An.retry,children:u(`common.retry`)})}),(0,X.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:An.dismissError,children:(0,X.jsx)(E,{size:13})})]}),pt&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:pt.detail,children:[(0,X.jsx)(y,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:u(pt.kind===`format`?`editor.texFmtOptionsRecoveryTitle`:pt.kind===`load`?`editor.texFmtRecoveryTitle`:`editor.texFmtRuntimeRecoveryTitle`)}),u(`editor.clientToolRecoveryHint`)]}),(0,X.jsxs)(`div`,{className:`client-tool-recovery-actions`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:dt||ra,onClick:()=>Ki(),children:u(`common.retry`)}),pt.kind===`format`&&_t.texFmtConfig.trim()&&(0,X.jsx)(`button`,{type:`button`,disabled:dt||ra,onClick:()=>Ki(!0),children:u(`editor.resetFormatterOptions`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:u(`common.reload`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:()=>mt(null),children:(0,X.jsx)(E,{size:13})})]}),aa&&(0,X.jsxs)(`div`,{className:`client-tool-recovery format-lease-status`,role:`status`,children:[(0,X.jsx)(Fe,{className:`spin`,size:15}),(0,X.jsx)(`span`,{children:u(`editor.formattingBy`,{name:aa.holderName})})]})]}),rn&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`status`,children:[(0,X.jsx)(y,{size:15}),(0,X.jsx)(`span`,{children:u(`history.saveWarning`)})]}),_e&&(0,X.jsx)(`div`,{className:`toast`,onClick:()=>H(``),children:_e}),ve&&(0,X.jsx)(`div`,{className:`toast success`,onClick:()=>ye(``),children:ve}),(0,X.jsxs)(vm,{orientation:`horizontal`,className:`work-grid`,...$i,children:[Zi&&(0,X.jsx)(Iy,{project:h,filesPanel:Ct,visibleEntries:Ar,deletedPath:tn?.kind===`delete`?tn.path:null,activeFile:D,activeMainFile:k,selectedFile:dr,selectedFolder:lr,expandedFolders:pr,fileDragActive:Cr,uploadingFiles:Dr,uploadFeedback:Or,readOnly:ra,formatting:dt,canFormat:Zm(D),activeFormatLease:!!ia,collaborationSynced:Xt,editorFontSize:_t.fontSize,outline:Yi,sourceCursorStore:z,wordCountBusy:at,hasSelection:!!U.selectedText.trim()&&/\.(?:tex|sty|cls)$/i.test(D),hasFormatSelection:!!U.selectedText.trim(),uploadInput:St,setSelectedFolder:ur,setExpandedFolders:mr,setMoveEntry:gr,setMoveName:vr,setMoveDestination:br,setDeleteEntry:Sr,setFileDialogError:cr,setNewFolderName:or,setNewFolderOpen:ir,setNewFilePath:Qn,setNewFileOpen:Xn,setQuickOpen:Qe,setFileDragActive:wr,dismissUploadFeedback:Z,setFilesCollapsed:Re,onError:H,uploadFiles:Nr,upload:Pr,openFile:Fr,movePathToFolder:Lr,onFormatFile:()=>void Vn(),onFormatSelection:()=>void Wn(),jumpToSource:Tn,syncSourceToPdf:En,onWordCount:e=>void Rn(e)}),Zi&&(0,X.jsx)(km,{className:`resize-handle`,children:(0,X.jsx)(Vt,{size:12})}),Zi&&(0,X.jsx)(Gy,{terminal:p?({maximized:e,toggleMaximized:t})=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`agent-task-empty`,children:(0,X.jsx)(Fe,{className:`spin`,size:18})}),children:(0,X.jsx)(Mb,{projectId:n,readOnly:ra,onHide:()=>m(!1),maximized:e,onToggleMaximized:t})}):null,project:h,activeFile:D,openTabs:yt,content:j,loadedFile:P,readOnly:ra,comments:Hr,focusComment:ti,editorPreferences:_t,completionIndex:S,nativeSpellCheck:jn.nativeFallback,spellCheckIssues:jn.issues,spellCheckJump:jn.jump,sourceJump:bn,collaborativeText:la,collaborationAwareness:c.awareness,undoManager:D?c.getUndoManager(D):void 0,editorNotice:Ii,activateTab:_a,closeTab:Jt,handleTabKeyDown:ya,updateEditorContent:Mn,setSelection:(e,t,n)=>Se({selectedText:e,startOffset:t,endOffset:n}),onAddComment:(e,t,n,r)=>ii({selectedText:e,startOffset:t,endOffset:n},r),onSelectionHistory:(e,t,n,r)=>{Ke({filePath:D,selection:{selectedText:e,startOffset:t,endOffset:n},source:r})},onCommentClick:wi,onSpellCheckReplace:oa,onReferenceNavigate:ta,onCursor:Kt}),Qi&&(0,X.jsx)(tb,{commentsOpen:K===`comments`,onCommentsHost:Te,projectId:n,activeMainFile:k,previewTab:B,diagnosticTab:ue,pdfUrl:Ti,pdfLoadingMode:Oi,pdfLoading:ki,pdfCompiledAt:Ei,pdfSizeBytes:Di,pdfCompiledLabel:ua,pdfTargetLabel:da,pdfDownloadUrl:pa,pdfTarget:vn,pdfViewport:yn,activeFile:D,compileBusy:ca,compileLog:Ai,compileDiagnostics:ji,compileMessages:Xi,artifacts:Ni,artifactPreview:Pi,artifactLoading:Fi,cleaning:zi,readOnly:ra,collaborationSynced:Xt,workspaceLayout:he,showSyncResize:Zi&&Qi,diagnosticCount:fa,selectPreviewTab:pe,changeWorkspaceLayout:ea,onSetPdfViewport:xn,onResetPdfViewport:Sn,onPdfDisplayed:Wi,syncVisiblePdfToSource:On,syncCurrentSourceToPdf:()=>{let e=Et.current;if(!e)return Promise.resolve();let t=z.getCursor();return En(e,t.line,t.column)},syncPdfToSource:Dn,canSyncWithPdf:ha,canSyncPdfToSource:ga,files:Kn,jumpToSource:Tn,onSetCleanMode:Xe,viewArtifact:Ui}),(0,X.jsx)(Eb,{commentsHost:Qi?we:void 0,sidePanel:K,onClose:()=>Ce(null),project:h,projectId:n,site:e,files:Kn,currentUserId:t.id,comments:Ee?Hr:Yr,commentDraftStore:_i,commentsLoading:Ee?Kr:Xr,commentsError:(Ee?qr:Zr)||hn,onRetryComments:Ee?Jr:Qr,activeFile:D,singleCommentId:Ee,onShowAllComments:()=>{q(null),ei(`project`)},hasProjectCommentsScope:Si,commentScope:$r,onCommentScopeChange:ei,focusedCommentId:Ie?.filePath===D?Ie.id:ti?.id,commentFocusNonce:Ie?.nonce,onClearFocusComment:()=>{J(null),ni(null),je(null)},unreadMentions:mn,onMarkMentionRead:gn,onMarkAllMentionsRead:_n,targetCommentId:Oe?.commentId,targetReplyId:Oe?.replyId,onFocusComment:Ci,onToggleComment:di,onReplyComment:fi,onEditComment:pi,onDeleteComment:mi,onEditCommentReply:hi,onDeleteCommentReply:gi,dictionaryWords:b,onDictionaryChange:x,editorPreferences:_t,onEditorPreferences:Gi,spellCheckCount:jn.summary?.total??null,spellCheckUniqueCount:jn.summary?.unique??null,spellCheckIndex:jn.summary?jn.index:-1,onSpellCheckNavigate:jn.jumpToIssue,onProject:zr},n)]}),$e&&(0,X.jsx)(ke,{title:u(`editor.wordCountTitle`),onClose:()=>et(!1),children:(0,X.jsx)(Nb,{open:!0,mode:tt,path:rt,busy:at,error:st,result:lt,onOpenChange:et})}),(0,X.jsx)(yb,{user:t,project:h,projectId:n,activeFile:D,content:j,maxCitationBibtexBytes:e.maxCitationBibtexBytes,files:Kn,directoryEntries:kr,readOnly:ra,resourcePreview:$n,resourcePreviewLoading:tr,setResourcePreview:er,setResourcePreviewLoading:nr,uploadConflict:Tr,setUploadConflict:Er,dismissUploadFeedback:Z,uploadFiles:Nr,cleanMode:Ye,setCleanMode:Xe,cleanCompile:Hi,newFileOpen:Yn,setNewFileOpen:Xn,newFilePath:Zn,setNewFilePath:Qn,newFolderOpen:rr,setNewFolderOpen:ir,newFolderName:ar,setNewFolderName:or,selectedFolder:lr,fileDialogError:sr,setFileDialogError:cr,createFile:jr,createFolder:Mr,moveEntry:hr,setMoveEntry:gr,moveName:_r,setMoveName:vr,moveDestination:yr,setMoveDestination:br,movePath:Ir,deleteEntry:xr,setDeleteEntry:Sr,deleteActiveSessions:na,removePath:Rr,commentOpen:ri,closeComment:Q,commentSelection:si,commentText:ai,setCommentText:oi,commentSubmitting:ci,cancelComment:vi,commentDraftRestored:yi,commentDraftCanRetarget:bi,useCurrentCommentSelection:xi,commentError:li,addComment:ui,shareOpen:ze,setShareOpen:Be,citationLibraryOpen:qe,setCitationLibraryOpen:Je,insertCitationAtCursor:Gn,quickOpen:Ze,setQuickOpen:Qe,openFile:Fr,selectionHistoryTarget:Ge,closeSelectionHistory:()=>Ke(null),historyOpen:Ue,setHistoryOpen:We,gitOpen:Ve,setGitOpen:He,save:Ln,permissionDowngrade:dn,permissionDowngradeBusy:ht,dismissPermissionDowngrade:fn,discardPermissionDraft:qi})]})}export{Po as A,Dt as B,Ic as C,sc as D,rc as E,Cn as F,vn as I,mn as L,ir as M,rr as N,nc as O,zn as P,Rb as ProjectWorkspace,fn as R,ud as S,lc as T,nd as _,Vd as a,rd as b,Id as c,pd as d,_d as f,gd as g,hd as h,jm as i,da as j,No as k,Sd as l,yd as m,Ym as n,Bd as o,vd as p,Xm as r,zd as s,jb as t,md as u,Qu as v,uc as w,ld as x,sd as y,Ut as z};