texlite 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +357 -21
- package/NPM_TESTING.md +23 -0
- package/OPERATIONS.md +185 -6
- package/README.md +4 -2
- package/README.zh-CN.md +3 -2
- package/THIRD_PARTY_NOTICES.md +73 -0
- package/dist/client/assets/AdminUsers-DXWi8wl0.js +1 -0
- package/dist/client/assets/AdminUsers-DXWi8wl0.js.br +0 -0
- package/dist/client/assets/AdminUsers-DXWi8wl0.js.gz +0 -0
- package/dist/client/assets/AgentIcon-BlHvdrRo.js +1 -0
- package/dist/client/assets/AgentIcon-BlHvdrRo.js.br +0 -0
- package/dist/client/assets/AgentIcon-BlHvdrRo.js.gz +0 -0
- package/dist/client/assets/AgentIcon-DE7FEpRY.css +1 -0
- package/dist/client/assets/AgentIcon-DE7FEpRY.css.br +0 -0
- package/dist/client/assets/AgentIcon-DE7FEpRY.css.gz +0 -0
- package/dist/client/assets/AgentManagement-CDWaxEmP.js +1 -0
- package/dist/client/assets/AgentManagement-CDWaxEmP.js.br +0 -0
- package/dist/client/assets/AgentManagement-CDWaxEmP.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-BXH3gHWm.js +2 -0
- package/dist/client/assets/AgentTerminal-BXH3gHWm.js.br +0 -0
- package/dist/client/assets/AgentTerminal-BXH3gHWm.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css +1 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-D0MLcJmw.js +16 -0
- package/dist/client/assets/AgentTerminalSurface-D0MLcJmw.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-D0MLcJmw.js.gz +0 -0
- package/dist/client/assets/{AvatarSettingsDialog-CIPKapVe.js → AvatarSettingsDialog-CtbzavqH.js} +1 -1
- package/dist/client/assets/AvatarSettingsDialog-CtbzavqH.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CtbzavqH.js.gz +0 -0
- package/dist/client/assets/{CitationLibraryDialog-BhZX8BV2.js → CitationLibraryDialog-CnQVjovw.js} +1 -1
- package/dist/client/assets/CitationLibraryDialog-CnQVjovw.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-CnQVjovw.js.gz +0 -0
- package/dist/client/assets/Dashboard-Dzq1oMZU.js +5 -0
- package/dist/client/assets/Dashboard-Dzq1oMZU.js.br +0 -0
- package/dist/client/assets/Dashboard-Dzq1oMZU.js.gz +0 -0
- package/dist/client/assets/GitDialog-CzgguGGW.js +3 -0
- package/dist/client/assets/GitDialog-CzgguGGW.js.br +0 -0
- package/dist/client/assets/GitDialog-CzgguGGW.js.gz +0 -0
- package/dist/client/assets/{GitHubAccountDialog-hosK9cLW.js → GitHubAccountDialog-lRAWfkKP.js} +1 -1
- package/dist/client/assets/GitHubAccountDialog-lRAWfkKP.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-lRAWfkKP.js.gz +0 -0
- package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-BPTVKTrM.js} +1 -1
- package/dist/client/assets/HistoryDialog-Bw3GHfbM.js +8 -0
- package/dist/client/assets/HistoryDialog-Bw3GHfbM.js.br +0 -0
- package/dist/client/assets/HistoryDialog-Bw3GHfbM.js.gz +0 -0
- package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BDpqgoOa.js} +2 -2
- package/dist/client/assets/LatexEditor-BDpqgoOa.js.br +0 -0
- package/dist/client/assets/LatexEditor-BDpqgoOa.js.gz +0 -0
- package/dist/client/assets/PdfPreview-C2puKgCh.js +1 -0
- package/dist/client/assets/PdfPreview-C2puKgCh.js.br +0 -0
- package/dist/client/assets/PdfPreview-C2puKgCh.js.gz +0 -0
- package/dist/client/assets/{ProjectIconPickerDialog-D8Uo4H10.js → ProjectIconPickerDialog-BzNdyAz6.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-BzNdyAz6.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-BzNdyAz6.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-B_y5nRgp.js +4 -0
- package/dist/client/assets/ProjectSettings-B_y5nRgp.js.br +0 -0
- package/dist/client/assets/ProjectSettings-B_y5nRgp.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js +30 -0
- package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-BnT5JPTA.js.gz +0 -0
- package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-CEYxIk4l.js} +1 -1
- package/dist/client/assets/QuickOpenDialog-CEYxIk4l.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-CEYxIk4l.js.gz +0 -0
- package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js +3 -0
- package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-DBL6vVD4.js.gz +0 -0
- package/dist/client/assets/SuccessNotice-C8XV7MAJ.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-D2EQX5hh.js.gz +0 -0
- package/dist/client/assets/{TagColorSelect-D3T-rw4K.js → TagColorSelect-CfJaFovr.js} +1 -1
- package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js +1 -0
- package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-CiJ6AhVk.js.gz +0 -0
- package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-DaHxqArj.js} +1 -1
- package/dist/client/assets/WordCountDialog-DaHxqArj.js.br +0 -0
- package/dist/client/assets/WordCountDialog-DaHxqArj.js.gz +0 -0
- package/dist/client/assets/arrow-down-BySB1dS6.js +1 -0
- package/dist/client/assets/check-B-GEn6vk.js +1 -0
- package/dist/client/assets/chevron-up-B0yLKMZJ.js +1 -0
- package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-B2-niLAo.js} +1 -1
- package/dist/client/assets/circle-check-CfK-oqlC.js +1 -0
- package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-C_8q2yLj.js} +1 -1
- package/dist/client/assets/{dist-D5mbpudl.js → dist-CIxSPQK5.js} +1 -1
- package/dist/client/assets/dist-CIxSPQK5.js.br +0 -0
- package/dist/client/assets/dist-CIxSPQK5.js.gz +0 -0
- package/dist/client/assets/{eye-CvzXPIMu.js → eye-DpIOhQ2p.js} +1 -1
- package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-DRbINIYf.js} +1 -1
- package/dist/client/assets/i18n-BzlyqR_B.js +13 -0
- package/dist/client/assets/i18n-BzlyqR_B.js.br +0 -0
- package/dist/client/assets/i18n-BzlyqR_B.js.gz +0 -0
- package/dist/client/assets/index-BHHBwQuG.css +1 -0
- package/dist/client/assets/index-BHHBwQuG.css.br +0 -0
- package/dist/client/assets/index-BHHBwQuG.css.gz +0 -0
- package/dist/client/assets/index-h0BVkT8k.js +42 -0
- package/dist/client/assets/index-h0BVkT8k.js.br +0 -0
- package/dist/client/assets/index-h0BVkT8k.js.gz +0 -0
- package/dist/client/assets/info-DB-RajXx.js +1 -0
- package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-DtsKyo4M.js} +1 -1
- package/dist/client/assets/{minus-CNHOVLWS.js → minus-CdwrG9Yo.js} +1 -1
- package/dist/client/assets/plus-PHvPlka_.js +1 -0
- package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-c6Tzy-hb.js} +1 -1
- package/dist/client/assets/relativeTime-Cf5dzFc9.js +1 -0
- package/dist/client/assets/relativeTime-Cf5dzFc9.js.br +0 -0
- package/dist/client/assets/relativeTime-Cf5dzFc9.js.gz +0 -0
- package/dist/client/assets/{search-Czv3qsBy.js → search-Cy8DgYGb.js} +1 -1
- package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-DEQIFH7w.js} +1 -1
- package/dist/client/assets/spellCheck-DEQIFH7w.js.br +0 -0
- package/dist/client/assets/spellCheck-DEQIFH7w.js.gz +0 -0
- package/dist/client/assets/{tags-CLK7WRSs.js → tags-BQ0exG-g.js} +1 -1
- package/dist/client/assets/terminal-DaAc1558.js +1 -0
- package/dist/client/assets/terminalPreferences-CgacIg2F.js +1 -0
- package/dist/client/assets/terminalPreferences-CgacIg2F.js.br +0 -0
- package/dist/client/assets/terminalPreferences-CgacIg2F.js.gz +0 -0
- package/dist/client/assets/{type-NT195OCy.js → type-Cm3TiSO6.js} +1 -1
- package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-BLC3_SFQ.js} +1 -1
- package/dist/client/index.html +13 -7
- package/dist/server/agents/adapters/claude.js +19 -0
- package/dist/server/agents/adapters/codex.js +47 -0
- package/dist/server/agents/adapters/common.js +86 -0
- package/dist/server/agents/adapters/opencode.js +184 -0
- package/dist/server/agents/adapters/types.js +1 -0
- package/dist/server/agents/execution.js +147 -0
- package/dist/server/agents/launcher.js +57 -0
- package/dist/server/agents/processIdentity.js +63 -0
- package/dist/server/agents/registry.js +72 -0
- package/dist/server/agents/sessions.js +564 -0
- package/dist/server/agents/terminal.js +84 -0
- package/dist/server/agents/workspaces.js +341 -0
- package/dist/server/app.js +32 -1
- package/dist/server/cli.js +19 -47
- package/dist/server/collaboration.js +62 -35
- package/dist/server/compileArtifacts.js +11 -44
- package/dist/server/compiler.js +16 -38
- package/dist/server/config.js +8 -2
- package/dist/server/db.js +28 -0
- package/dist/server/editHistory.js +59 -65
- package/dist/server/history.js +28 -13
- package/dist/server/i18n.js +26 -8
- package/dist/server/latexRoot.js +4 -2
- package/dist/server/locales/zh-Hant.js +145 -0
- package/dist/server/lucideIcons.js +14 -17
- package/dist/server/projectMutations.js +21 -0
- package/dist/server/routes/agents.js +135 -0
- package/dist/server/routes/compile.js +23 -43
- package/dist/server/routes/projectHistory.js +13 -6
- package/dist/server/routes/projects.js +15 -23
- package/dist/shared/agentMessages.js +51 -0
- package/dist/shared/agentProtocol.js +41 -0
- package/dist/shared/historyFiles.js +1 -1
- package/dist/shared/historyTracking.js +2 -0
- package/dist/shared/locales.js +21 -0
- package/package.json +7 -3
- package/templates/agents/AGENTS.md +135 -0
- package/texlite.config.example.json +3 -2
- package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.gz +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
- package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
- package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
- package/dist/client/assets/check-DFoA73zZ.js +0 -1
- package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
- package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
- package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
- package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js +0 -42
- package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
- package/dist/client/assets/index-DnhiIb1V.css +0 -1
- package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
- package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
- package/dist/client/assets/plus-BDquy76g.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
- package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
- package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
- package/preview-1.png +0 -0
- package/preview-2.png +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./spellCheck-DEQIFH7w.js","./index-h0BVkT8k.js","./rolldown-runtime-XKyaHtl9.js","./react-DUEFWlB7.js","./i18nInstance-CIMFwH0l.js","./i18n-BzlyqR_B.js","./basePath-B5-c90eh.js","./vite-runtime-CRzLMJPS.js","./index-BHHBwQuG.css","./chktex-B2-niLAo.js","./LatexEditor-BDpqgoOa.js","./editor-oR9RlWUz.js","./CitationLibraryDialog-CnQVjovw.js","./relativeTime-Cf5dzFc9.js","./check-B-GEn6vk.js","./chevron-up-B0yLKMZJ.js","./plus-PHvPlka_.js","./search-Cy8DgYGb.js","./tags-BQ0exG-g.js","./TagColorSelect-CfJaFovr.js","./dist-CIxSPQK5.js","./citationLibrary-BzlqZiFU.js","./GitDialog-CzgguGGW.js","./GitHubIcon-BPTVKTrM.js","./eye-DpIOhQ2p.js","./minus-CdwrG9Yo.js","./minimize-2-DtsKyo4M.js","./HistoryDialog-Bw3GHfbM.js","./circle-check-CfK-oqlC.js","./clock-3-C_8q2yLj.js","./hard-drive-DRbINIYf.js","./dist-Dxkdrap6.js","./SuccessNotice-C8XV7MAJ.js","./SelectionHistoryDialog-DBL6vVD4.js","./QuickOpenDialog-CEYxIk4l.js","./ProjectSettings-B_y5nRgp.js","./refresh-cw-c6Tzy-hb.js","./terminal-DaAc1558.js","./type-Cm3TiSO6.js","./terminalPreferences-CgacIg2F.js","./AgentTerminal-BXH3gHWm.js","./info-DB-RajXx.js","./AgentIcon-BlHvdrRo.js","./AgentIcon-DE7FEpRY.css","./WordCountDialog-DaHxqArj.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-BzlyqR_B.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-BySB1dS6.js";import{A 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,K as C,L as w,M as T,N as E,O as D,P as O,R as k,S as A,T as j,U as M,V as N,W as ee,b as te,c as P,d as F,f as ne,h as re,i as ie,j as ae,k as oe,m as I,n as se,o as ce,p as L,q as R,r as z,s as B,t as le,u as V,w as ue,x as de,z as fe}from"./relativeTime-Cf5dzFc9.js";import{t as pe}from"./check-B-GEn6vk.js";import{t as me}from"./chevron-up-B0yLKMZJ.js";import{t as he}from"./circle-check-CfK-oqlC.js";import{t as H}from"./refresh-cw-c6Tzy-hb.js";import{t as ge}from"./user-plus-BLC3_SFQ.js";import{A as _e,C as U,E as W,F as G,I as ve,M as ye,N as K,O as be,P as xe,S as Se,T as Ce,b as q,c as we,i as Te,j as Ee,k as De,o as Oe,s as ke,w as Ae,y as je}from"./index-h0BVkT8k.js";import{a as Me,c as Ne,n as Pe,r as Fe,t as Ie}from"./dist-CIxSPQK5.js";import{t as J}from"./binary-B57nBiwS.js";var Le={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},Re=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?("[^"]*"|'[^']*')/g;function ze(e){let t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(Le[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(Re),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 Be=/<!--[\s\S]*?-->|<[a-zA-Z0-9\-!/](?:"[^"]*"|'[^']*'|[^'">])*>/g,Ve=/<\/?([^\s]+?)[/\s>]/,He=/^\s*$/,Ue=/^(script|style)$/i,We=`\0`,Ge=Object.create(null);function Ke(e){e.forEach(function(e){if(e.type===`text`)e.content=e.content.split(We).join(`<`);else if(e.type===`comment`)e.comment=e.comment.split(We).join(`<`);else{for(let t in e.attrs){let n=e.attrs[t];typeof n==`string`&&n.indexOf(We)>-1&&(e.attrs[t]=n.split(We).join(`<`))}e.children.length&&Ke(e.children)}})}function qe(e,t){let n=t&&t.components||Ge,r=t&&t.allowedTags,i=!1;if(r){let t=typeof r==`function`?r:function(e){return r.indexOf(e)>-1},n=``,a=0;Be.lastIndex=0;let o;for(;o=Be.exec(e);){let r=o[0];n+=e.slice(a,o.index);let s=r.match(Ve);r.startsWith(`<!--`)||s&&t(s[1])?(n+=r,a=o.index+r.length):(i=!0,n+=We,a=o.index+1,Be.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=Be.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=ze(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=ze(i),s.type===`tag`&&n[s.name]&&(s.type=`component`,l=!0);let t=!1;if(!l&&!s.voidElement&&Ue.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);He.test(n)&&(n=` `),(t>-1&&c+b.length>=0||n!==` `)&&b.push({type:`text`,content:n})}}),i&&Ke(a),a}function Je(e){let t=[];for(let n in e)e[n]===null?t.push(n):t.push(n+`="`+String(e[n]).replace(/"/g,`"`)+`"`);return t.length?` `+t.join(` `):``}function Ye(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?Je(t.attrs):``)+n,t.voidElement?e:e+t.children.reduce(Ye,``)+`</`+t.name+`>`}case`comment`:return e+=`<!--`+t.comment+`-->`,e}}function Xe(e){return e.reduce(function(e,t){return e+Ye(``,t)},``)}var Ze={parse:qe,stringify:Xe},Y=t(n()),Qe=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},$e=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?tt(t):t},et=e=>tt(e).every(Y.isValidElement),tt=e=>Array.isArray(e)?e:[e],nt=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},rt=e=>{let t={};if(!e)return t;let n=e=>{tt(e).forEach(e=>{xe(e)||(Qe(e)?n($e(e)):K(e)&&!(0,Y.isValidElement)(e)&&Object.assign(t,e))})};return n(e),t},it=(e,t,n,r)=>{if(!e)return``;let i=``,a=tt(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(xe(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=xe(d)?d:it(d,t,n,r);i+=`<${c}>${e}</${c}>`;return}let f=it(d,t,n,r);i+=`<${a}>${f}</${a}>`}else if(e===null)G(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});else if(K(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}G(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e})}else G(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),i},at=(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=>{tt(e).forEach(e=>{xe(e)||(Qe(e)?f($e(e)):K(e)&&!(0,Y.isValidElement)(e)&&Object.assign(d,e))})};f(e);let p=Object.keys(d),m=Ze.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=$e(e),i=v(r,t.children,n);return et(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=tt(e),f=tt(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];xe(t)&&(y[e]=a(t))});let b=Object.keys(y).length===0?o:nt({props:y},o),x=(0,Y.isValidElement)(b),S=x&&Qe(n,!0)&&!n.voidElement,C=u&&K(b)&&b.dummy&&!x,w=K(t)&&Object.hasOwnProperty.call(t,n.name);if(xe(b)){let t=r.services.interpolator.interpolate(b,h,r.language);e.push(t)}else if(Qe(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?tt($e(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(K(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 $e(v([{dummy:!0,children:e||[]}],m,tt(e||[]))[0])},ot=(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})},st=(e,t)=>e.map((e,n)=>ot(e,n,t)),ct=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:ot(e[r],r,t)})}),n},lt=(e,t,n,r)=>e?Array.isArray(e)?st(e,t):K(e)?ct(e,t):(ve(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,ut=e=>!K(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function dt({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 ve(_,`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`);xe(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=it(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=rt(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=lt(T,N,_,r),te=ee||e,P=null;ut(ee)&&(P=ee,te=e);let F=at(te,P,N,_,y,M,C),ne=n??y.defaultTransParent;return ne?(0,Y.createElement)(ne,g,F):F}function ft({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)(ye)||{},_=d||h||c(),v=f||_?.t.bind(_);return dt({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 pt={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};pt.node;var mt=q(pt),ht={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`]};ht.node;var gt=q(ht),_t={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`]};_t.node;var vt=q(_t),yt={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`]};yt.node;var bt=q(yt),xt={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`}]]};xt.node;var St=q(xt),Ct={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`}]]};Ct.node;var wt=q(Ct),Tt={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`]};Tt.node;var Et=q(Tt),Dt={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`]};Dt.node;var Ot=q(Dt),kt={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`}]]};kt.node;var At=q(kt),jt={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`]};jt.node;var Mt=q(jt),Nt={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`]};Nt.node;var Pt=q(Nt),Ft={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`}]]};Ft.node;var It=q(Ft),Lt={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`}]]};Lt.node;var Rt=q(Lt),zt={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`}]]};zt.node;var Bt=q(zt),Vt={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`}]]};Vt.node;var Ht=q(Vt),Ut={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`}]]};Ut.node;var Wt=q(Ut),Gt={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`}]]};Gt.node;var Kt=q(Gt),qt={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`}]]};qt.node;var Jt=q(qt),Yt={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`}]]};Yt.node;var Xt=q(Yt),Zt={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`}]]};Zt.node;var Qt=q(Zt),$t={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`]};$t.node;var en=q($t),tn={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`]};tn.node;var nn=q(tn),rn={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`]};rn.node;var an=q(rn),on={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`}]]};on.node;var sn=q(on),cn={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`}]]};cn.node;var ln=q(cn),un={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`}]]};un.node;var dn=q(un),fn={name:`save`,size:24,node:[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]};fn.node;var pn=q(fn),mn={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`}]]};mn.node;var hn=q(mn),gn={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`}]]};gn.node;var _n=q(gn),vn={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`]};vn.node;var yn=q(vn),X=i(),bn=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(`.`)),xn=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 Sn(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`:bn.has(r)||xn.has(t)||t===`.env`||t.startsWith(`.env.`)||t.startsWith(`dockerfile.`)||t.startsWith(`containerfile.`)?`text`:`other`}function Cn(e,t){return!!e&&Sn(e)===`text`&&t!==!1}function wn(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 Tn({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 En({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 Dn({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 On=new Set([`avif`,`bmp`,`gif`,`ico`,`jpeg`,`jpg`,`png`,`svg`,`webp`,`eps`]),kn=new Set([`latex`,`ltx`,`tex`]),An=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(`.`)),jn=new Set([`cfg`,`conf`,`dat`,`env`,`ini`,`text`,`toml`,`txt`]),Mn=new Set([`csv`,`ods`,`tsv`,`xls`,`xlsx`]),Nn=new Set([`7z`,`bz2`,`gz`,`rar`,`tar`,`xz`,`zip`]),Pn=new Set([`m4a`,`mp3`,`ogg`,`wav`]),Fn=new Set([`avi`,`mkv`,`mov`,`mp4`,`webm`]);function In(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`:On.has(n)?`image`:n===`md`||n===`markdown`||n===`mdown`||n===`mkdn`?`markdown`:kn.has(n)?`tex`:n===`bib`||n===`bibtex`?`bib`:An.has(n)?`code`:jn.has(n)?`text`:Mn.has(n)?`spreadsheet`:Nn.has(n)?`archive`:Pn.has(n)?`audio`:Fn.has(n)?`video`:`file`}var Ln={bib:Wt,latexmkrc:Et,image:At,text:D,code:w,spreadsheet:y,archive:k,audio:Ot,video:Pt,file:It};function Rn({path:e,size:t=13}){let n=In(e),r=`file-type-icon file-type-icon-${n}`;if(n===`pdf`)return(0,X.jsx)(En,{className:r,size:t,variant:`wordmark`});if(n===`tex`)return(0,X.jsx)(Dn,{className:r,size:t});if(n===`markdown`)return(0,X.jsx)(Tn,{className:r,size:t});let i=Ln[n];return(0,X.jsx)(i,{className:r,size:t,"aria-hidden":`true`})}var zn=()=>new Map,Bn=e=>{let t=zn();return e.forEach((e,n)=>{t.set(n,e)}),t},Vn=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Hn=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Un=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Wn=()=>new Set,Gn=e=>e[e.length-1],Kn=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},qn=Array.from,Jn=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Yn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Xn=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Zn=Array.isArray,Qn=class{constructor(){this._observers=zn()}on(e,t){return Vn(this._observers,e,Wn).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 qn((this._observers.get(e)||zn()).values()).forEach(e=>e(...t))}destroy(){this._observers=zn()}},$n=class{constructor(){this._observers=zn()}on(e,t){Vn(this._observers,e,Wn).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 qn((this._observers.get(e)||zn()).values()).forEach(e=>e(...t))}destroy(){this._observers=zn()}},er=Math.floor,tr=Math.abs,nr=(e,t)=>e<t?e:t,rr=(e,t)=>e>t?e:t;Number.isNaN;var ir=Math.pow,ar=e=>e===0?1/e<0:e<0,or=2**53-1,sr=-(2**53-1),cr=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&er(e)===e);Number.isNaN,Number.parseInt;var lr=String.fromCharCode;String.fromCodePoint,lr(65535);var ur=e=>e.toLowerCase(),dr=/^\s*/g,fr=e=>e.replace(dr,``),pr=/([A-Z])/g,mr=(e,t)=>fr(e.replace(pr,e=>`${t}${ur(e)}`)),hr=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},gr=typeof TextEncoder<`u`?new TextEncoder:null,_r=gr?e=>gr.encode(e):hr,vr=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});vr&&vr.decode(new Uint8Array).length===1&&(vr=null);var yr=(e,t)=>Xn(t,()=>e).join(``),br=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},xr=()=>new br,Sr=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},Cr=e=>{let t=new Uint8Array(Sr(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},wr=(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(rr(n,t)*2),e.cpos=0)},Tr=(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},Er=Tr,Z=(e,t)=>{for(;t>127;)Tr(e,128|127&t),t=er(t/128);Tr(e,127&t)},Dr=(e,t)=>{let n=ar(t);for(n&&(t=-t),Tr(e,(t>63?128:0)|(n?64:0)|63&t),t=er(t/64);t>0;)Tr(e,(t>127?128:0)|127&t),t=er(t/128)},Or=new Uint8Array(3e4),kr=Or.length/3,Ar=gr&&gr.encodeInto?(e,t)=>{if(t.length<kr){let n=gr.encodeInto(t,Or).written||0;Z(e,n);for(let t=0;t<n;t++)Tr(e,Or[t])}else Mr(e,_r(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;Z(e,r);for(let t=0;t<r;t++)Tr(e,n.codePointAt(t))},jr=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=nr(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(rr(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Mr=(e,t)=>{Z(e,t.byteLength),jr(e,t)},Nr=(e,t)=>{wr(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Pr=(e,t)=>Nr(e,4).setFloat32(0,t,!1),Fr=(e,t)=>Nr(e,8).setFloat64(0,t,!1),Ir=(e,t)=>Nr(e,8).setBigInt64(0,t,!1),Lr=new DataView(new ArrayBuffer(4)),Rr=e=>(Lr.setFloat32(0,e),Lr.getFloat32(0)===e),zr=(e,t)=>{switch(typeof t){case`string`:Tr(e,119),Ar(e,t);break;case`number`:cr(t)&&tr(t)<=2147483647?(Tr(e,125),Dr(e,t)):Rr(t)?(Tr(e,124),Pr(e,t)):(Tr(e,123),Fr(e,t));break;case`bigint`:Tr(e,122),Ir(e,t);break;case`object`:if(t===null)Tr(e,126);else if(Zn(t)){Tr(e,117),Z(e,t.length);for(let n=0;n<t.length;n++)zr(e,t[n])}else if(t instanceof Uint8Array)Tr(e,116),Mr(e,t);else{Tr(e,118);let n=Object.keys(t);Z(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Ar(e,i),zr(e,t[i])}}break;case`boolean`:Tr(e,t?120:121);break;default:Tr(e,127)}},Br=class extends br{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)}},Vr=e=>{e.count>0&&(Dr(e.encoder,e.count===1?e.s:-e.s),e.count>1&&Z(e.encoder,e.count-2))},Hr=class{constructor(){this.encoder=new br,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Vr(this),this.count=1,this.s=e)}toUint8Array(){return Vr(this),Cr(this.encoder)}},Ur=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);Dr(e.encoder,t),e.count>1&&Z(e.encoder,e.count-2)}},Wr=class{constructor(){this.encoder=new br,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Ur(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ur(this),Cr(this.encoder)}},Gr=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Hr}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 br;return this.sarr.push(this.s),this.s=``,Ar(e,this.sarr.join(``)),jr(e,this.lensE.toUint8Array()),Cr(e)}},Kr=e=>Error(e),qr=()=>{throw Kr(`Method unimplemented`)},Jr=()=>{throw Kr(`Unexpected case`)},Yr=Kr(`Unexpected end of array`),Xr=Kr(`Integer out of Range`),Zr=class{constructor(e){this.arr=e,this.pos=0}},Qr=e=>new Zr(e),$r=e=>e.pos!==e.arr.length,ei=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},ti=e=>ei(e,Q(e)),ni=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>or)throw Xr}throw Yr},ri=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>or)throw Xr}throw Yr},ii=vr?e=>vr.decode(ti(e)):e=>{let t=Q(e);if(t===0)return``;{let n=String.fromCodePoint(ni(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ni(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))}},ai=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},oi=[e=>void 0,e=>null,ri,e=>ai(e,4).getFloat32(0,!1),e=>ai(e,8).getFloat64(0,!1),e=>ai(e,8).getBigInt64(0,!1),e=>!1,e=>!0,ii,e=>{let t=Q(e),n={};for(let r=0;r<t;r++){let t=ii(e);n[t]=si(e)}return n},e=>{let t=Q(e),n=[];for(let r=0;r<t;r++)n.push(si(e));return n},ti],si=e=>oi[127-ni(e)](e),ci=class extends Zr{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=$r(this)?Q(this)+1:-1),this.count--,this.s}},li=class extends Zr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ri(this);let e=ar(this.s);this.count=1,e&&(this.s=-this.s,this.count=Q(this)+2)}return this.count--,this.s}},ui=class extends Zr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ri(this),t=e&1;this.diff=er(e/2),this.count=1,t&&(this.count=Q(this)+2)}return this.s+=this.diff,this.count--,this.s}},di=class{constructor(e){this.decoder=new li(e),this.str=ii(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 fi=crypto.getRandomValues.bind(crypto),pi=()=>fi(new Uint32Array(1))[0],mi=`10000000-1000-4000-8000-100000000000`,hi=()=>mi.replace(/[018]/g,e=>(e^pi()&15>>e/4).toString(16)),gi=Date.now,_i=e=>new Promise(e);Promise.all.bind(Promise);var vi=e=>e===void 0?null:e,yi=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},bi=!0;try{typeof localStorage<`u`&&localStorage&&(yi=localStorage,bi=!1)}catch{}var xi=yi,Si=e=>bi||addEventListener(`storage`,e),Ci=e=>bi||removeEventListener(`storage`,e),wi=Symbol(`Equality`),Ti=(e,t)=>e===t||!!e?.[wi]?.(t)||!1,Ei=e=>typeof e==`object`,Di=Object.assign,Oi=Object.keys,ki=(e,t)=>{for(let n in e)t(e[n],n)},Ai=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},ji=e=>Oi(e).length,Mi=e=>{for(let t in e)return!1;return!0},Ni=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Pi=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Fi=(e,t)=>e===t||ji(e)===ji(t)&&Ni(e,(e,n)=>(e!==void 0||Pi(t,n))&&Ti(t[n],e)),Ii=Object.freeze,Li=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&Li(e[t])}return Ii(e)},Ri=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ri(e,t,n+1)}},zi=e=>e,Bi=(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[wi]!=null)return e[wi](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)||!Bi(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(ji(e)!==ji(t))return!1;for(let n in e)if(!Pi(e,n)||!Bi(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(!Bi(e[n],t[n]))return!1;break;default:return!1}return!0},Vi=(e,t)=>t.includes(e),Hi=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Ui=typeof window<`u`&&typeof document<`u`&&!Hi;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Wi,Gi=[],Ki=()=>{if(Wi===void 0){if(Hi){Wi=zn();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&Wi.set(t,``),t=r):t===null?Gi.push(r):(Wi.set(t,r),t=null)}t!==null&&Wi.set(t,``)}else typeof location==`object`?(Wi=zn(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);Wi.set(`--${mr(t,`-`)}`,n),Wi.set(`-${mr(t,`-`)}`,n)}})):Wi=zn()}return Wi},qi=e=>Ki().has(e),Ji=e=>vi(Hi?{}[e.toUpperCase().replaceAll(`-`,`_`)]:xi.getItem(e)),Yi=e=>qi(`--`+e)||Ji(e)!==null,Xi=Yi(`production`),Zi=Hi&&Vi({}.FORCE_COLOR,[`true`,`1`,`2`])||!qi(`--no-colors`)&&!Yi(`no-color`)&&(!Hi||process.stdout.isTTY)&&(!Hi||qi(`--color`)||Ji(`COLORTERM`)!==null||(Ji(`TERM`)||``).includes(`color`)),Qi=e=>new Uint8Array(e),$i=(e,t,n)=>new Uint8Array(e,t,n),ea=e=>new Uint8Array(e),ta=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=lr(e[n]);return btoa(t)},na=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),ra=e=>{let t=atob(e),n=Qi(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},ia=e=>{let t=Buffer.from(e,`base64`);return $i(t.buffer,t.byteOffset,t.byteLength)},aa=Ui?ta:na,oa=Ui?ra:ia,sa=e=>{let t=Qi(e.byteLength);return t.set(e),t},ca=class{constructor(e,t){this.left=e,this.right=t}},la=(e,t)=>new ca(e,t),ua=(e,t)=>e.forEach(e=>t(e.left,e.right)),da=e=>e.next()>=.5,fa=(e,t,n)=>er(e.next()*(n+1-t)+t),pa=(e,t,n)=>er(e.next()*(n+1-t)+t),ma=(e,t,n)=>pa(e,t,n),ha=e=>lr(ma(e,97,122)),ga=(e,t=0,n=20)=>{let r=ma(e,t,n),i=``;for(let t=0;t<r;t++)i+=ha(e);return i},_a=(e,t)=>t[ma(e,0,t.length-1)],va=Symbol(`0schema`),ya=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(yr(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
3
|
+
`)}},ba=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[wi]?Ti(e,t):Zn(e)?Jn(e,e=>Yn(t,t=>ba(e,t))):Ei(e)?Ni(e,(e,n)=>ba(e,t[n])):!1,xa=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),ba(t,n)}equals(e){return this.constructor===e.constructor&&Bi(this.shape,e.shape)}[va](){return!0}[wi](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){qr()}get nullable(){return eo(this,go)}get optional(){return new Ma(this)}cast(e){return bo(e,this),e}expect(e){return bo(e,this),e}},Sa=class extends xa{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}},Ca=(e,t=null)=>new Sa(e,t);Ca(Sa);var wa=class extends xa{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}},Ta=e=>new wa(e);Ca(wa);var Ea=class extends xa{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}},Da=(...e)=>new Ea(e),Oa=Ca(Ea),ka=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Aa=e=>{if(uo.check(e))return[ka(e)];if(Oa.check(e))return e.shape.map(e=>e+``);if(lo.check(e))return[`[+-]?\\d+.?\\d*`];if(fo.check(e))return[`.*`];if(to.check(e))return e.shape.map(Aa).flat(1);Jr()};Ca(class extends xa{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Aa).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 ja=Symbol(`optional`),Ma=class extends xa{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[ja](){return!0}},Na=Ca(Ma),Pa=class extends xa{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Pa,Ca(Pa);var Fa=class e extends xa{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):Ni(this.shape,(n,r)=>{let i=this._isPartial&&!Pi(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Ia=e=>new Fa(e),La=Ca(Fa),Ra=Ta(e=>e!=null&&(e.constructor===Object||e.constructor==null)),za=class extends xa{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Ni(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)})}},Ba=(e,t)=>new za(e,t),Va=Ca(za),Ha=class extends xa{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Ni(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},Ua=(...e)=>new Ha(e);Ca(Ha);var Wa=class extends xa{constructor(e){super(),this.shape=e.length===1?e[0]:new $a(e)}check(e,t){let n=Zn(e)&&Jn(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},Ga=(...e)=>new Wa(e),Ka=Ca(Wa),qa=Ta(e=>Zn(e)),Ja=class extends xa{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}},Ya=(e,t=null)=>new Ja(e,t);Ca(Ja);var Xa=Ya(xa),Za=Ca(class extends xa{constructor(e){super(),this.len=e.length-1,this.args=Ua(...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}}),Qa=Ta(e=>typeof e==`function`);Ca(class extends xa{constructor(e){super(),this.shape=e}check(e,t){let n=Jn(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var $a=class extends xa{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=Yn(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},eo=(...e)=>e.findIndex(e=>to.check(e))>=0?eo(...e.map(e=>yo(e)).map(e=>to.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new $a(e),to=Ca($a),no=()=>!0,ro=Ta(no),io=Ca(wa,e=>e.shape===no),ao=Ta(e=>typeof e==`bigint`),oo=Ta(e=>e===ao),so=Ta(e=>typeof e==`symbol`);Ta(e=>e===so);var co=Ta(e=>typeof e==`number`),lo=Ta(e=>e===co),uo=Ta(e=>typeof e==`string`),fo=Ta(e=>e===uo),po=Ta(e=>typeof e==`boolean`),mo=Ta(e=>e===po),ho=Da(void 0);Ca(Ea,e=>e.shape.length===1&&e.shape[0]===void 0),Da(void 0);var go=Da(null),_o=Ca(Ea,e=>e.shape.length===1&&e.shape[0]===null);Ca(Uint8Array),Ca(Sa,e=>e.shape===Uint8Array);var vo=eo(co,uo,go,ho,ao,po,so);(()=>{let e=Ga(ro),t=Ba(uo,ro),n=eo(co,uo,go,po,e,t);return e.shape=n,t.shape.values=n,n})();var yo=e=>{if(Xa.check(e))return e;if(Ra.check(e)){let t={};for(let n in e)t[n]=yo(e[n]);return Ia(t)}if(qa.check(e))return eo(...e.map(yo));if(vo.check(e))return Da(e);if(Qa.check(e))return Ca(e);Jr()},bo=Xi?()=>{}:(e,t)=>{let n=new ya;if(!t.check(e,n))throw Kr(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},xo=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:yo(e),h:t}),this}else(e){return this.if(ro,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 Kr(`Unhandled pattern`)}}},So=(e=>new xo(e))(ro).if(lo,(e,t)=>fa(t,sr,or)).if(fo,(e,t)=>ga(t)).if(mo,(e,t)=>da(t)).if(oo,(e,t)=>BigInt(fa(t,sr,or))).if(to,(e,t)=>Co(t,_a(t,e.shape))).if(La,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Na.check(i)){if(da(t))continue;i=i.shape}n[r]=So(i,t)}return n}).if(Ka,(e,t)=>{let n=[],r=pa(t,0,42);for(let i=0;i<r;i++)n.push(Co(t,e.shape));return n}).if(Oa,(e,t)=>_a(t,e.shape)).if(_o,(e,t)=>null).if(Za,(e,t)=>{let n=Co(t,e.res);return()=>n}).if(io,(e,t)=>Co(t,_a(t,[co,uo,go,ho,ao,po,Ga(co),Ba(eo(`a`,`b`,`c`),co)]))).if(Va,(e,t)=>{let n={},r=fa(t,0,3);for(let i=0;i<r;i++){let r=Co(t,e.shape.keys);n[r]=Co(t,e.shape.values)}return n}).done(),Co=(e,t)=>So(yo(t),e),wo=typeof document<`u`?document:{},To=e=>wo.createElement(e),Eo=()=>wo.createDocumentFragment();Ta(e=>e.nodeType===Ro);var Do=e=>wo.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var Oo=(e,t)=>(ua(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),ko=e=>{let t=Eo();for(let n=0;n<e.length;n++)Po(t,e[n]);return t},Ao=(e,t)=>(Po(e,ko(t)),e),jo=(e,t=[],n=[])=>Ao(Oo(To(e),t),n);Ta(e=>e.nodeType===Fo);var Mo=Do;Ta(e=>e.nodeType===Io);var No=e=>Hn(e,(e,t)=>`${t}:${e};`).join(``),Po=(e,t)=>e.appendChild(t),Fo=wo.ELEMENT_NODE,Io=wo.TEXT_NODE;wo.CDATA_SECTION_NODE,wo.COMMENT_NODE;var Lo=wo.DOCUMENT_NODE;wo.DOCUMENT_TYPE_NODE;var Ro=wo.DOCUMENT_FRAGMENT_NODE;Ta(e=>e.nodeType===Lo);var zo=Symbol,Bo=zo(),Vo=zo(),Ho=zo(),Uo=zo(),Wo=zo(),Go=zo(),Ko=zo(),qo=zo(),Jo=zo(),Yo=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};gi();var Xo={[Bo]:la(`font-weight`,`bold`),[Vo]:la(`font-weight`,`normal`),[Ho]:la(`color`,`blue`),[Wo]:la(`color`,`green`),[Uo]:la(`color`,`grey`),[Go]:la(`color`,`red`),[Ko]:la(`color`,`purple`),[qo]:la(`color`,`orange`),[Jo]:la(`color`,`black`)},Zo=Zi?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=zn(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=Xo[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=No(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}:Yo,Qo=(...e)=>{console.log(...Zo(e)),es.forEach(t=>t.print(e))},$o=(...e)=>{console.warn(...Zo(e)),e.unshift(qo),es.forEach(t=>t.print(e))},es=Wn(),ts=e=>({[Symbol.iterator](){return this},next:e}),ns=(e,t)=>ts(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),rs=(e,t)=>ts(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),is=class{constructor(e,t){this.clock=e,this.len=t}},as=class{constructor(){this.clients=new Map}},os=(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])Sc(e,i,o.clock,o.len,n)}}),ss=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=er((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},cs=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ss(n,t.clock)!==null},ls=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 is(r.clock,rr(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},us=e=>{let t=new as;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++)Kn(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return ls(t),t},ds=(e,t,n,r)=>{Vn(e.clients,t,()=>[]).push(new is(n,r))},fs=()=>new as,ps=e=>{let t=fs();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 is(i,a))}}r.length>0&&t.clients.set(n,r)}),t},ms=(e,t)=>{Z(e.restEncoder,t.clients.size),qn(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)}})},hs=e=>{let t=new as,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=Vn(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new is(e.readDsClock(),e.readDsLen()))}}return t},gs=(e,t,n)=>{let r=new as,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=mc(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&ds(r,i,s,a-s);let e=gc(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Ru(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,Ru(t,c,a-c.id.clock)),c.delete(t))}else ds(r,i,n,a-n)}}if(r.clients.size>0){let e=new Es;return Z(e.restEncoder,0),ms(e,r),e.toUint8Array()}return null},_s=pi,vs=class e extends Qn{constructor({guid:e=hi(),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=_s(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new fc,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=_i(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>_i(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&&Ac(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(qn(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Ac(this,e,t)}get(e,t=ol){let n=Vn(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==ol&&r!==t){if(r===ol){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,El)}getText(e=``){return this.get(e,ql)}getMap(e=``){return this.get(e,kl)}getXmlElement(e=``){return this.get(e,Ql)}getXmlFragment(e=``){return this.get(e,Xl)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,qn(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,Ac(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()}},ys=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Q(this.restDecoder)}readDsLen(){return Q(this.restDecoder)}},bs=class extends ys{readLeftID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readRightID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readClient(){return Q(this.restDecoder)}readInfo(){return ni(this.restDecoder)}readString(){return ii(this.restDecoder)}readParentInfo(){return Q(this.restDecoder)===1}readTypeRef(){return Q(this.restDecoder)}readLen(){return Q(this.restDecoder)}readAny(){return si(this.restDecoder)}readBuf(){return sa(ti(this.restDecoder))}readJSON(){return JSON.parse(ii(this.restDecoder))}readKey(){return ii(this.restDecoder)}},xs=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}},Ss=class extends xs{constructor(e){super(e),this.keys=[],Q(e),this.keyClockDecoder=new ui(ti(e)),this.clientDecoder=new li(ti(e)),this.leftClockDecoder=new ui(ti(e)),this.rightClockDecoder=new ui(ti(e)),this.infoDecoder=new ci(ti(e),ni),this.stringDecoder=new di(ti(e)),this.parentInfoDecoder=new ci(ti(e),ni),this.typeRefDecoder=new li(ti(e)),this.lenDecoder=new li(ti(e))}readLeftID(){return new Ys(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ys(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 si(this.restDecoder)}readBuf(){return ti(this.restDecoder)}readJSON(){return si(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}}},Cs=class{constructor(){this.restEncoder=xr()}toUint8Array(){return Cr(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Z(this.restEncoder,e)}writeDsLen(e){Z(this.restEncoder,e)}},ws=class extends Cs{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){Er(this.restEncoder,e)}writeString(e){Ar(this.restEncoder,e)}writeParentInfo(e){Z(this.restEncoder,+!!e)}writeTypeRef(e){Z(this.restEncoder,e)}writeLen(e){Z(this.restEncoder,e)}writeAny(e){zr(this.restEncoder,e)}writeBuf(e){Mr(this.restEncoder,e)}writeJSON(e){Ar(this.restEncoder,JSON.stringify(e))}writeKey(e){Ar(this.restEncoder,e)}},Ts=class{constructor(){this.restEncoder=xr(),this.dsCurrVal=0}toUint8Array(){return Cr(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,Z(this.restEncoder,t)}writeDsLen(e){e===0&&Jr(),Z(this.restEncoder,e-1),this.dsCurrVal+=e}},Es=class extends Ts{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Wr,this.clientEncoder=new Hr,this.leftClockEncoder=new Wr,this.rightClockEncoder=new Wr,this.infoEncoder=new Br(Er),this.stringEncoder=new Gr,this.parentInfoEncoder=new Br(Er),this.typeRefEncoder=new Hr,this.lenEncoder=new Hr}toUint8Array(){let e=xr();return Z(e,0),Mr(e,this.keyClockEncoder.toUint8Array()),Mr(e,this.clientEncoder.toUint8Array()),Mr(e,this.leftClockEncoder.toUint8Array()),Mr(e,this.rightClockEncoder.toUint8Array()),Mr(e,Cr(this.infoEncoder)),Mr(e,this.stringEncoder.toUint8Array()),Mr(e,Cr(this.parentInfoEncoder)),Mr(e,this.typeRefEncoder.toUint8Array()),Mr(e,this.lenEncoder.toUint8Array()),jr(e,Cr(this.restEncoder)),Cr(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){zr(this.restEncoder,e)}writeBuf(e){Mr(this.restEncoder,e)}writeJSON(e){zr(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)}},Ds=(e,t,n,r)=>{r=rr(r,t[0].id.clock);let i=gc(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)},Os=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{mc(t,n)>e&&r.set(n,e)}),pc(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),Z(e.restEncoder,r.size),qn(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ds(e,t.clients.get(n),n,r)})},ks=(e,t)=>{let n=zn(),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 su($(a,o),t),o+=t;break}case 10:{let t=Q(e.restDecoder);i[n]=new Gu($(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Vu($(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,Hu(e,r));i[n]=c,o+=c.length}}}}return n},As=(e,t,n)=>{let r=[],i=qn(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 fc,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!==Gu){let i=Vn(d,u.id.client,()=>mc(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,mc(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 Es;return Os(e,s,new Map),Z(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},js=(e,t)=>Os(e,t.doc.store,t.beforeState),Ms=(e,t,n,r=new Ss(e))=>Ac(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=As(e,i,ks(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<mc(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=Bc([o.update,a.update])}}else i.pendingStructs=a;let s=gs(r,e,i);if(i.pendingDs){let t=new Ss(Qr(i.pendingDs));Q(t.restDecoder);let n=gs(t,e,i);i.pendingDs=s&&n?Bc([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Ns(e.doc,t)}},n,!1),Ns=(e,t,n,r=Ss)=>{let i=Qr(t);Ms(i,e,n,new r(i))},Ps=(e,t,n)=>Ns(e,t,n,bs),Fs=(e,t,n=new Map)=>{Os(e,t.store,n),ms(e,ps(t.store))},Is=(e,t=new Uint8Array([0]),n=new Es)=>{Fs(n,e,zs(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Vc(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===ws)return Rc(r.map((e,t)=>t===0?e:Kc(e)));if(n.constructor===Es)return Bc(r)}return r[0]},Ls=(e,t)=>Is(e,t,new ws),Rs=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},zs=e=>Rs(new ys(Qr(e))),Bs=(e,t)=>(Z(e.restEncoder,t.size),qn(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{Z(e.restEncoder,t),Z(e.restEncoder,n)}),e),Vs=(e,t)=>Bs(e,pc(t.store)),Hs=(e,t=new Ts)=>(e instanceof Map?Bs(t,e):Vs(t,e),t.toUint8Array()),Us=e=>Hs(e,new Cs),Ws=class{constructor(){this.l=[]}},Gs=()=>new Ws,Ks=(e,t)=>e.l.push(t),qs=(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.`)},Js=(e,t,n)=>Ri(e.l,[t,n]),Ys=class{constructor(e,t){this.client=e,this.clock=t}},Xs=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,$=(e,t)=>new Ys(e,t),Zs=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw Jr()},Qs=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},$s=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ec=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},tc=e=>new $s(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),nc=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},rc=(e,t,n=0)=>new nc(e,t,n),ic=(e,t,n)=>{let r=null,i=null;return e._item===null?i=Zs(e):r=$(e._item.id.client,e._item.id.clock),new $s(r,i,t,n)},ac=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ic(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ic(e,$(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ic(e,r.lastId,n);r=r.right}return ic(e,null,n)},oc=(e,t)=>{let n=_c(e,t);return{item:n,diff:t.clock-n.id.clock}},sc=(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(mc(r,i.client)<=i.clock)return null;let e=n?Iu(r,i):oc(r,i),t=e.item;if(!(t instanceof Vu))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(mc(r,a.client)<=a.clock)return null;let{item:e}=n?Iu(r,a):{item:_c(r,a)};if(e instanceof Vu&&e.content instanceof Pu)c=e.content.type;else return null}else throw Jr();l=s>=0?c._length:0}return rc(c,l,e.assoc)},cc=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Xs(e.item,t.item)&&Xs(e.type,t.type)&&e.assoc===t.assoc,lc=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new lc(e,t))(fs(),new Map);var uc=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!cs(t.ds,e.id),dc=(e,t)=>{let n=Vn(e.meta,dc,Wn),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<mc(r,n)&&yc(e,$(n,t))}),os(e,t.ds,e=>{}),n.add(t))},fc=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},pc=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},mc=(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},hc=(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 Jr()}n.push(t)},gc=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=er(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=er((n+r)/2)}throw Jr()},_c=(e,t)=>{let n=e.clients.get(t.client);return n[gc(n,t.clock)]},vc=(e,t,n)=>{let r=gc(t,n),i=t[r];return i.id.clock<n&&i instanceof Vu?(t.splice(r+1,0,Ru(e,i,n-i.id.clock)),r+1):r},yc=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[vc(e,n,t.clock)]},bc=(e,t,n)=>{let r=t.clients.get(n.client),i=gc(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==su&&r.splice(i+1,0,Ru(e,a,n.clock-a.id.clock+1)),a},xc=(e,t,n)=>{let r=e.clients.get(t.id.client);r[gc(r,t.id.clock)]=n},Sc=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=vc(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&vc(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Cc=class{constructor(e,t,n){this.doc=e,this.deleteSet=new as,this.beforeState=pc(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}},wc=(e,t)=>t.deleteSet.clients.size===0&&!Un(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(ls(t.deleteSet),js(e,t),ms(e,t.deleteSet),!0),Tc=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Vn(e.changed,t,Wn).add(n)},Ec=(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 Vu&&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},Dc=(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=gc(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 Vu&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Oc=(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=nr(r.length-1,1+gc(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+Ec(r,e)}})},kc=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{ls(a),n.afterState=pc(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(()=>{Js(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Wl(n)})}),Ri(e,[])}finally{r.gc&&Dc(a,i,r.gcFilter),Oc(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=rr(gc(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Ec(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=gc(r,n);a+1<r.length&&Ec(r,a+1)>1||a>0&&Ec(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(Qo(qo,Bo,`[yjs] `,Vo,Go,`Changed the client-id because another client seems to be using it.`),r.clientID=_s()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new ws;wc(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Es;wc(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])):kc(e,t+1)}}},Ac=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Cc(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&&kc(i,0)}}return o},jc=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Mc=(e,t,n)=>{os(e,n.deletions,n=>{n instanceof Vu&&t.scope.some(t=>t===e.doc||Qs(t,n))&&Lu(n,!1)})},Nc=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;Ac(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;os(n,o.insertions,e=>{if(e instanceof Vu){if(e.redone!==null){let{item:t,diff:i}=Iu(r,e.id);i>0&&(t=yc(n,$(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||Qs(t,e))&&c.push(e)}}),os(n,o.deletions,e=>{e instanceof Vu&&a.some(t=>t===n.doc||Qs(t,e))&&!cs(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Bu(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},Pc=class extends Qn{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=Zn(e)?e[0].doc:e instanceof vs?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 as;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&ds(i,n,r,a)});let a=gi(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=us([t.deletions,e.deleteSet]),t.insertions=us([t.insertions,i])}else r.push(new jc(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),os(e,e.deleteSet,t=>{t instanceof Vu&&this.scope.some(n=>n===e.doc||Qs(n,t))&&Lu(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=Zn(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof ol?e.doc!==this.doc:e!==this.doc)&&$o(`[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=>Mc(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Mc(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=Nc(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Nc(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*Fc(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 Gu($(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Vu($(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,Hu(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new su($(n,r),t),r+=t}}}}var Ic=class{constructor(e,t){this.gen=Fc(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===Gu);return this.curr}},Lc=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Rc=e=>Bc(e,bs,ws),zc=(e,t)=>{if(e.constructor===su){let{client:n,clock:r}=e.id;return new su($(n,r+t),e.length-t)}if(e.constructor===Gu){let{client:n,clock:r}=e.id;return new Gu($(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Vu($(r,i+t),null,$(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Bc=(e,t=Ss,n=Es)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(Qr(e))),i=r.map(e=>new Ic(e,!0)),a=null,o=new n,s=new Lc(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===Gu?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)Uc(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===Gu)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Uc(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new Gu($(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===Gu?a.struct.length-=t:n=zc(n,t)),a.struct.mergeWith(n)||(Uc(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!==Gu;n=e.next())Uc(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Uc(s,a.struct,a.offset),a=null),Wc(s),ms(o,us(r.map(e=>hs(e)))),o.toUint8Array()},Vc=(e,t,n=Ss,r=Es)=>{let i=zs(t),a=new r,o=new Lc(a),s=new n(Qr(e)),c=new Ic(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===Gu)c.next();else if(e.id.clock+e.length>n)for(Uc(o,e,rr(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Uc(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 Wc(o),ms(a,hs(s)),a.toUint8Array()},Hc=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Cr(e.encoder.restEncoder)}),e.encoder.restEncoder=xr(),e.written=0)},Uc=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Hc(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++},Wc=e=>{Hc(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),jr(t,r.restEncoder)}},Gc=(e,t,n,r)=>{let i=new n(Qr(e)),a=new Ic(i,!1),o=new r,s=new Lc(o);for(let e=a.curr;e!==null;e=a.next())Uc(s,t(e),0);return Wc(s),ms(o,hs(i)),o.toUint8Array()},Kc=e=>Gc(e,zi,Ss,ws),qc=`You must not compute changes after the event-handler fired.`,Jc=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||=Yc(this.currentTarget,this.target)}deletes(e){return cs(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Kr(qc);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=Gn(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=Gn(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Gn(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 Kr(qc);let t=this.target,n=Wn(),r=Wn(),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}},Yc=(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},Xc=()=>{$o(`Invalid access: Add Yjs type to a document before reading data.`)},Zc=80,Qc=0,$c=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Qc++}},el=e=>{e.timestamp=Qc++},tl=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Qc++},nl=(e,t,n)=>{if(e.length>=Zc){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return tl(r,t,n),r}{let r=new $c(t,n);return e.push(r),r}},rl=(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)=>tr(t-e.index)<tr(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,el(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&&tr(n.index-i)<r.parent.length/Zc?(tl(n,r,i),n):nl(e._searchMarker,r,i)},il=(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=rr(t,i.index+n))}},al=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Vn(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Js(r._eH,n,t)},ol=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Gs(),this._dEH=Gs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw qr()}clone(){throw qr()}_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){Ks(this._eH,e)}observeDeep(e){Ks(this._dEH,e)}unobserve(e){qs(this._eH,e)}unobserveDeep(e){qs(this._dEH,e)}toJSON(){}},sl=(e,t,n)=>{e.doc??Xc(),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},cl=e=>{e.doc??Xc();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},ll=(e,t)=>{let n=0,r=e._start;for(e.doc??Xc();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}},ul=(e,t)=>{let n=[];return ll(e,(r,i)=>{n.push(t(r,i,e))}),n},dl=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}}}},fl=(e,t)=>{e.doc??Xc();let n=rl(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}},pl=(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 Vu($(o,mc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Su(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 Vu($(o,mc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new cu(new Uint8Array(n))),i.integrate(e,0);break;case vs:i=new Vu($(o,mc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new pu(n)),i.integrate(e,0);break;default:if(n instanceof ol)i=new Vu($(o,mc(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Pu(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},ml=()=>Kr(`Length exceeded!`),hl=(e,t,n,r)=>{if(n>t._length)throw ml();if(n===0)return t._searchMarker&&il(t._searchMarker,n,r.length),pl(e,t,null,r);let i=n,a=rl(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&&yc(e,$(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&il(t._searchMarker,i,r.length),pl(e,t,o,r)},gl=(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 pl(e,t,r,n)},_l=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=rl(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&&yc(e,$(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&yc(e,$(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw ml();t._searchMarker&&il(t._searchMarker,i,-a+r)},vl=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},yl=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new Su([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new Su([r]);break;case Uint8Array:s=new cu(r);break;case vs:s=new pu(r);break;default:if(r instanceof ol)s=new Pu(r);else throw Error(`Unexpected content type`)}new Vu($(o,mc(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},bl=(e,t)=>{e.doc??Xc();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},xl=e=>{let t={};return e.doc??Xc(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Sl=(e,t)=>{e.doc??Xc();let n=e._map.get(t);return n!==void 0&&!n.deleted},Cl=(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&&uc(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},wl=e=>(e.doc??Xc(),ns(e._map.entries(),e=>!e[1].deleted)),Tl=class extends Jc{},El=class e extends ol{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 ol?e.clone():e)),t}get length(){return this.doc??Xc(),this._length}_callObserver(e,t){super._callObserver(e,t),al(this,e,new Tl(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ac(this.doc,n=>{hl(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):Ac(this.doc,t=>{gl(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ac(this.doc,n=>{_l(n,this,e,t)})}get(e){return fl(this,e)}toArray(){return cl(this)}slice(e=0,t=this.length){return sl(this,e,t)}toJSON(){return this.map(e=>e instanceof ol?e.toJSON():e)}map(e){return ul(this,e)}forEach(e){ll(this,e)}[Symbol.iterator](){return dl(this)}_write(e){e.writeTypeRef(Du)}},Dl=e=>new El,Ol=class extends Jc{constructor(e,t,n){super(e,t),this.keysChanged=n}},kl=class e extends ol{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 ol?e.clone():e)}),t}_callObserver(e,t){al(this,e,new Ol(this,e,t))}toJSON(){this.doc??Xc();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof ol?r.toJSON():r}}),e}get size(){return[...wl(this)].length}keys(){return rs(wl(this),e=>e[0])}values(){return rs(wl(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return rs(wl(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Xc(),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):Ac(this.doc,t=>{vl(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):Ac(this.doc,n=>{yl(n,this,e,t)}),t}get(e){return bl(this,e)}has(e){return Sl(this,e)}clear(){this.doc===null?this._prelimContent.clear():Ac(this.doc,e=>{this.forEach(function(t,n,r){vl(e,r,n)})})}_write(e){e.writeTypeRef(Ou)}},Al=e=>new kl,jl=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Fi(e,t),Ml=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&Jr(),this.right.content.constructor){case _u:this.right.deleted||Il(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Nl=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case _u:t.right.deleted||Il(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&yc(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},Pl=(e,t,n,r)=>{let i=new Map,a=r?rl(t,n):null;return a?Nl(e,new Ml(a.p.left,a.p,a.index,i),n-a.index):Nl(e,new Ml(null,t._start,0,i),n)},Fl=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===_u&&jl(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 Vu($(a,mc(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new _u(o,r));l.integrate(e,0),n.right=l,n.forward()})},Il=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Ll=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===_u&&jl(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Rl=(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(!jl(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Vu($(a,mc(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new _u(s,c)),n.right.integrate(e,0),n.forward()}}return o},zl=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Ll(n,i);let s=Rl(e,t,n,i),c=r.constructor===String?new wu(r):r instanceof ol?new Pu(r):new hu(r),{left:l,right:u,index:d}=n;t._searchMarker&&il(t._searchMarker,n.index,c.getLength()),u=new Vu($(o,mc(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(),Fl(e,t,n,s)},Bl=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Ll(n,i);let s=Rl(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===_u));){if(!n.right.deleted)switch(n.right.content.constructor){case _u:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(jl(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&&yc(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 Vu($(o,mc(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new wu(i)),n.right.integrate(e,0),n.forward()}Fl(e,t,n,s)},Vl=(e,t,n,r,i)=>{let a=t,o=zn();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===_u){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 _u:{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&&Il(i,n);break}}}t=t.right}return s},Hl=(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===_u){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Ul=e=>{let t=0;return Ac(e.doc,n=>{let r=e._start,i=e._start,a=zn(),o=Bn(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case _u:Il(o,i.content);break;default:t+=Vl(n,r,i,a,o),a=Bn(o),r=i}i=i.right}}),t},Wl=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&&Sc(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===_u&&e.constructor!==su&&t.add(e.parent)})}Ac(n,n=>{os(e,e.deleteSet,e=>{if(e instanceof su||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===_u?t.add(r):Hl(n,e)});for(let e of t)Ul(e)})},Gl=(e,t,n)=>{let r=n,i=Bn(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Pu:case hu:case wu:n<t.right.length&&yc(e,$(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Vl(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&il(o._searchMarker,t.index,-r+n),t},Kl=class extends Jc{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=[];Ac(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},Mi(o)||(e.attributes=Di({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Pu:case hu: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 wu: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 _u:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(jl(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),jl(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;jl(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(jl(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Il(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}},ql=class e extends ol{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Xc(),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 Kl(this,e,t);al(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Xc();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===wu&&(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)):Ac(this.doc,n=>{let r=new Ml(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)&&zl(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Gl(n,r,a.delete):Bl(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??Xc();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(uc(s,e)||t!==void 0&&uc(s,t))switch(s.content.constructor){case wu:{let r=i.get(`ychange`);e!==void 0&&!uc(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&&!uc(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 Pu:case hu:{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 _u:uc(s,e)&&(c(),Il(i,s.content))}s=s.right}c()};return e||t?Ac(a,n=>{e&&dc(n,e),t&&dc(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)):Ac(r,r=>{let i=Pl(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),zl(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Ac(r,r=>{let i=Pl(r,this,e,!n);zl(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)):Ac(n,n=>{Gl(n,Pl(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)):Ac(r,r=>{let i=Pl(r,this,e,!1);i.right!==null&&Bl(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Ac(this.doc,t=>{vl(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Ac(this.doc,n=>{yl(n,this,e,t)})}getAttribute(e){return bl(this,e)}getAttributes(){return xl(this)}_write(e){e.writeTypeRef(ku)}},Jl=e=>new ql,Yl=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Xc()}[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===Ql||t.constructor===Xl)&&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})}},Xl=class e extends ol{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 ol?e.clone():e)),t}get length(){return this.doc??Xc(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Yl(this,e)}querySelector(e){e=e.toUpperCase();let t=new Yl(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),qn(new Yl(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){al(this,e,new eu(this,t,e))}toString(){return ul(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),ll(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ac(this.doc,n=>{hl(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Ac(this.doc,n=>{let r=e&&e instanceof ol?e._item:e;pl(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 Kr(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ac(this.doc,n=>{_l(n,this,e,t)})}toArray(){return cl(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return fl(this,e)}slice(e=0,t=this.length){return sl(this,e,t)}forEach(e){ll(this,e)}_write(e){e.writeTypeRef(ju)}},Zl=e=>new Xl,Ql=class e extends Xl{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 ki(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof ol?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):Ac(this.doc,t=>{vl(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Ac(this.doc,n=>{yl(n,this,e,t)})}getAttribute(e){return bl(this,e)}hasAttribute(e){return Sl(this,e)}getAttributes(e){return e?Cl(this,e):xl(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 ll(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Au),e.writeKey(this.nodeName)}},$l=e=>new Ql(e.readKey()),eu=class extends Jc{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)})}},tu=class e extends kl{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(Mu),e.writeKey(this.hookName)}},nu=e=>new tu(e.readKey()),ru=class e extends ql{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(Nu)}},iu=e=>new ru,au=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw qr()}mergeWith(e){return!1}write(e,t,n){throw qr()}integrate(e,t){throw qr()}},ou=0,su=class extends au{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),hc(e.doc.store,this)}write(e,t){e.writeInfo(ou),e.writeLen(this.length-t)}getMissing(e,t){return null}},cu=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 qr()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},lu=e=>new cu(e.readBuf()),uu=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){ds(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}},du=e=>new uu(e.readLen()),fu=(e,t)=>new vs({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),pu=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(fu(this.doc.guid,this.opts))}splice(e){throw qr()}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}},mu=e=>new pu(fu(e.readString(),e.readAny())),hu=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 qr()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},gu=e=>new hu(e.readJSON()),_u=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 qr()}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}},vu=e=>new _u(e.readKey(),e.readJSON()),yu=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}},bu=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 yu(n)},xu=Ji(`node_env`)===`development`,Su=class e{constructor(e){this.arr=e,xu&&Li(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}},Cu=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Su(n)},wu=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}},Tu=e=>new wu(e.readString()),Eu=[Dl,Al,Jl,$l,Zl,nu,iu],Du=0,Ou=1,ku=2,Au=3,ju=4,Mu=5,Nu=6,Pu=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 qr()}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}},Fu=e=>new Pu(Eu[e.readTypeRef()](e)),Iu=(e,t)=>{let n=t,r=0,i;do r>0&&(n=$(n.client,n.clock+r)),i=_c(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Vu);return{item:i,diff:r}},Lu=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Ru=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Vu($(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},zu=(e,t)=>Yn(e,e=>cs(e.deletions,t)),Bu=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return yc(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Bu(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=yc(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:yc(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:yc(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||cs(r,d.right.id)||zu(a.undoStack,d.right.id)||zu(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=yc(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,mc(s,c)),h=new Vu(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,Lu(h,!0),h.integrate(e,0),h},Vu=class e extends au{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>=mc(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=mc(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ys&&this.id.client!==this.parent.client&&this.parent.clock>=mc(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=bc(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=yc(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===su||this.right&&this.right.constructor===su)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===Ys){let e=_c(n,this.parent);this.parent=e.constructor===su?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=bc(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),Xs(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(Xs(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(_c(e.doc.store,n.origin)))r.has(_c(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),hc(e.doc.store,this),this.content.integrate(e,this),Tc(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new su(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&&Xs(e.origin,this.lastId)&&this.right===e&&Xs(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(),ds(e.deleteSet,this.id.client,this.id.clock,this.length),Tc(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Jr();this.content.gc(e),t?xc(e,this,new su(this.id,this.length)):this.content=new uu(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=Zs(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===Ys?(e.writeParentInfo(!1),e.writeLeftID(t)):Jr();i!==null&&e.writeString(i)}this.content.write(e,t)}},Hu=(e,t)=>Uu[t&31](e),Uu=[()=>{Jr()},du,bu,lu,Tu,gu,vu,Fu,Cu,mu,()=>{Jr()}],Wu=10,Gu=class extends au{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Jr()}write(e,t){e.writeInfo(Wu),Z(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Ku=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},qu=`__ $YJS$ __`;Ku[qu]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ku[qu]=!0;var Ju=`wrap = false`,Yu=[{id:`jetbrains`,labelKey:`projectSettings.fontJetBrains`,stack:`"JetBrains Mono", ui-monospace, monospace`},{id:`source-code`,labelKey:`projectSettings.fontSourceCode`,stack:`"Source Code Pro", ui-monospace, monospace`},{id:`ibm-plex`,labelKey:`projectSettings.fontIbmPlex`,stack:`"IBM Plex Mono", ui-monospace, monospace`},{id:`fira-code`,labelKey:`projectSettings.fontFiraCode`,stack:`"Fira Code", ui-monospace, monospace`},{id:`iosevka`,labelKey:`projectSettings.fontIosevka`,stack:`"Iosevka", ui-monospace, monospace`}],Xu={font:`jetbrains`,fontSize:14,lineHeight:1.65,lineWrapping:!0,showTooltips:!1,spellCheck:!0,mathPreviewOnHover:!1,vimMode:!1,formatOnCompile:!1,texFmtConfig:Ju,openFilesInTabs:!1},Zu=`texlite-editor-preferences`;function Qu(e,t){return u(`${Zu}:${encodeURIComponent(e)}:${encodeURIComponent(t)}`)}function $u(e){return Yu.find(t=>t.id===e)?.stack??Yu[0].stack}function ed(e,t){try{let n=JSON.parse(localStorage.getItem(Qu(e,t))??`{}`);return{font:Yu.some(e=>e.id===n.font)?n.font:Xu.font,fontSize:[12,13,14,15,16,18,20].includes(Number(n.fontSize))?Number(n.fontSize):Xu.fontSize,lineHeight:[1.45,1.65,1.85].includes(Number(n.lineHeight))?Number(n.lineHeight):Xu.lineHeight,lineWrapping:typeof n.lineWrapping==`boolean`?n.lineWrapping:Xu.lineWrapping,showTooltips:typeof n.showTooltips==`boolean`?n.showTooltips:Xu.showTooltips,spellCheck:typeof n.spellCheck==`boolean`?n.spellCheck:Xu.spellCheck,mathPreviewOnHover:typeof n.mathPreviewOnHover==`boolean`?n.mathPreviewOnHover:Xu.mathPreviewOnHover,vimMode:typeof n.vimMode==`boolean`?n.vimMode:Xu.vimMode,formatOnCompile:typeof n.formatOnCompile==`boolean`?n.formatOnCompile:Xu.formatOnCompile,texFmtConfig:typeof n.texFmtConfig==`string`&&n.texFmtConfig.length<=16384?n.texFmtConfig:Xu.texFmtConfig,openFilesInTabs:typeof n.openFilesInTabs==`boolean`?n.openFilesInTabs:Xu.openFilesInTabs}}catch{return Xu}}function td(e,t,n){localStorage.setItem(Qu(e,t),JSON.stringify(n))}var nd=`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(`.`),rd=new Set(nd);function id(e){return rd.has(e)}function ad(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 od(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 sd(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=ad(e,o,n);if(t===null)return null;o=t}if(a===`mintinline`){let t=od(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=od(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 cd(e,t,n=e.length){return sd(e,t,n)?.end??null}function ld(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 ud(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function dd(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 fd(e,t){let n=/^\\begin\s*\{\s*([A-Za-z0-9@:_*.\-]+)\s*\}/.exec(e.slice(t));return!n||!id(n[1])?null:{name:n[1],to:t+n[0].length}}function pd(e,t){let n=Math.max(0,Math.min(e.length,t));for(let t=0;t<n;){if(e[t]===`%`&&!ud(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]!==`\\`||ud(e,t)){t+=1;continue}let r=sd(e,t);if(r!==null){if(n<r.end||!r.closed&&n<=r.end)return`literal`;t=r.end;continue}let i=fd(e,t);if(i){let r=ld(e,i.to,i.name),a=r?.to??e.length;if(n<a||!r&&n<=a)return`literal`;t=a}else t=dd(e,t)}return null}function md(e,t,n){return e.slice(t,n).replace(/[^\r\n]/g,` `)}function hd(e){let t=e.split(``);for(let n=0;n<e.length;n+=1){if(e[n]!==`%`||ud(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 gd(e){let t=``,n=0;for(;n<e.length;){if(e[n]===`%`&&!ud(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]!==`\\`||ud(e,n)){t+=e[n],n+=1;continue}let r=cd(e,n);if(r!==null){t+=md(e,n,r),n=r;continue}let i=fd(e,n);if(i){let r=ld(e,i.to,i.name)?.to??e.length;t+=md(e,n,r),n=r}else t+=e[n],n+=1}return t}var _d=new Set(nd);function vd(e){return/[A-Za-z@0-9:_-]/.test(e)}function yd(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function bd(e,t){return e[t]===`%`&&!yd(e,t)}function xd(e,t){let n=e.indexOf(`
|
|
10
|
+
`,t);return n===-1?e.length:n}function Sd(e,t){let n=t;for(;n<e.length;)if(/\s/.test(e[n]))n+=1;else if(bd(e,n))n=xd(e,n);else break;return n}function Cd(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(bd(e,o))o=xd(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 wd(e,t,n){let r=[],i=t;for(;r.length<n;){for(i=Sd(e,i);e[i]===`[`;){let t=Cd(e,i,`[`,`]`);if(!t)return r;i=Sd(e,t.to)}if(e[i]!==`{`)break;let t=Cd(e,i,`{`,`}`);if(!t)break;r.push(t),i=t.to}return r}function Td(e,t,n){let r=[],i=t;for(;r.length<n&&(i=Sd(e,i),e[i]===`[`);){let t=Cd(e,i,`[`,`]`);if(!t)break;r.push(t),i=t.to}return r}function Ed(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&&vd(e[n]);)n+=1;let r=e.slice(t+1,n);return e[n]===`*`&&(n+=1),{name:r,from:t,to:n}}function Dd(e,t){if(t.name!==`begin`)return t.to;let n=wd(e,t.to,1)[0];if(!n)return t.to;let r=e.slice(n.contentFrom,n.contentTo).trim();return _d.has(r)?ld(e,n.to,r)?.to??e.length:t.to}function Od(e,t){let n=0;for(;n<e.length;){if(bd(e,n)){n=xd(e,n);continue}if(e[n]!==`\\`){n+=1;continue}let r=Ed(e,n);if(!r){n+=1;continue}let i=cd(e,r.from);if(i!==null&&i>r.to){n=i;continue}let a=Dd(e,r);a>r.to?n=a:(t(r),n=r.to)}}function kd(e,t,n){let r=[],i=t.contentFrom,a=t.contentFrom;for(;a<=t.contentTo;){if(a<t.contentTo&&bd(e,a)){a=xd(e,a),e[a]===`
|
|
11
|
+
`&&(a+=1);continue}if(a!==t.contentTo&&(!n||e[a]!==`,`)){a+=1;continue}let o=Ad(e,i,a);o&&r.push(o),i=a+1,a+=1}return r}function Ad(e,t,n){let r=[],i=t;for(;i<n;)bd(e,i)?(i=xd(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 jd(e,t){let n=Sd(e,t);if(n>=e.length||/[\\{}\[\]#~]/.test(e[n]))return null;let r=n;for(;r<e.length&&!/\s/.test(e[r])&&!bd(e,r)&&!/[\\{}\[\]#~]/.test(e[r]);)r+=1;return r===n?null:{path:e.slice(n,r),command:``,from:n,to:r}}function Md(e){let t=[];return Od(e,n=>{let r=n.name.toLowerCase();if(r===`input`||r===`include`||r===`subfile`){let i=wd(e,n.to,1)[0];if(i)for(let r of kd(e,i,!1))t.push({...r,command:n.name});else if(r===`input`){let r=jd(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=wd(e,n.to,2);if(i.length!==2)return;let a=kd(e,i[0],!1)[0]?.path??``,o=kd(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 Nd=(e,t)=>e>>>t|e<<32-t,Pd=e=>Nd(e,2)^Nd(e,13)^Nd(e,22),Fd=e=>Nd(e,6)^Nd(e,11)^Nd(e,25),Id=e=>Nd(e,7)^Nd(e,18)^e>>>3,Ld=e=>Nd(e,17)^Nd(e,19)^e>>>10,Rd=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]),zd=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Bd=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(zd),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=Ld(t[e-2])+t[e-7]+Id(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+Fd(o)+(o&s^~o&c)+Rd[e]+t[e]>>>0,d=Pd(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/J,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}},Vd=e=>new Bd().digest(e);function Hd(e){return Array.from(Vd(new TextEncoder().encode(e)),e=>e.toString(16).padStart(2,`0`)).join(``)}function Ud(e){for(let t=0;t<e.length;t+=1)e[t]=Math.floor(Math.random()*256);return e}function Wd(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 Gd(e=globalThis.crypto){if(typeof e?.randomUUID==`function`)return e.randomUUID();let t=new Uint8Array(16);return Wd(typeof e?.getRandomValues==`function`?e.getRandomValues(t):Ud(t))}function Kd(e){return/\.(?:tex|sty|cls|ltx|dtx|ins|txt|md|markdown|rst)$/i.test(e.trim())}function qd(e){return/\.(?:tex|sty|cls)$/i.test(e.trim())}function Jd(e){return(typeof e==`number`||typeof e==`string`)&&e!==``}function Yd(e){let t=(0,Y.useId)();return Jd(e)?`${e}`:t}var Xd=typeof window<`u`?Y.useLayoutEffect:Y.useEffect;function Zd(e){let t=(0,Y.useRef)(e);return Xd(()=>{t.current=e},[e]),(0,Y.useCallback)((...e)=>t.current?.(...e),[t])}function Qd(...e){return Zd(t=>{e.forEach(e=>{if(e)switch(typeof e){case`function`:e(t);break;case`object`:e.current=t}})})}function $d(e,t){let n=e?.[`data-testid`];return Jd(n)?`${n}`:Jd(t)?`${t}`:void 0}function ef(e,t=`Assertion error`){if(!e)throw Error(t)}(0,Y.createContext)(null);var tf;function nf(){return tf===void 0&&(tf=typeof matchMedia==`function`&&!!matchMedia(`(pointer:coarse)`).matches),tf}function rf({expandHitTargets:e,axis:t,rect:n}){let r=e?nf()?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 af(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 of=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)}}},sf={cursorFlags:0,state:`inactive`},cf=new of;function lf(){return sf}function uf(e){return cf.addListener(`change`,e)}function df(e,t=[],n,r=!1){let i=sf,a={...sf};a.cursorFlags=e,a.state===`active`&&(a.didPointerMove||=r,a.previews=t,n&&(a.previewLayoutMap=n)),sf=a,cf.emit(`change`,{prev:i,next:a})}function ff(e){let t=sf;sf=e,t.state===`active`&&e.state!==`active`&&t.didPointerMove&&t.hitRegions.forEach(({separator:e})=>{e&&e.element.ownerDocument.activeElement===e.element&&e.element.blur()}),cf.emit(`change`,{prev:t,next:e})}function pf(e){sf.state!==`active`||!sf.previews.some(t=>t.separator===e)||ff({...sf,previews:sf.previews.map(t=>t.separator===e?{...t}:t)})}function mf(e){if(sf.state===`inactive`)return;let t=sf.hitRegions.filter(t=>t.axis!==e),n=sf.state===`active`&&sf.previews.some(t=>t.axis===e);if(t.length!==sf.hitRegions.length||n){if(t.length===0)ff({cursorFlags:0,state:`inactive`});else if(sf.state===`active`){let n=new Map(sf.initialLayoutMap),r=new Map(sf.previewLayoutMap);n.delete(e),r.delete(e),ff({...sf,cursorFlags:0,hitRegions:t,initialLayoutMap:n,previewLayoutMap:r,previews:sf.previews.filter(t=>t.axis!==e)})}else ff({...sf,hitRegions:t})}}var hf=e=>e,gf=()=>{},_f=1,vf=2,yf=4,bf=8,xf=3,Sf=12,Cf;function wf(){return Cf===void 0&&(Cf=!1,typeof window<`u`&&(window.navigator.userAgent.includes(`Chrome`)||window.navigator.userAgent.includes(`Firefox`))&&(Cf=!0)),Cf}function Tf({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&&wf()){let t=(e&_f)!==0,n=(e&vf)!==0,r=(e&yf)!==0,i=(e&bf)!==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 wf()?r>0&&i>0?`move`:r>0?`ew-resize`:`ns-resize`:r>0&&i>0?`grab`:r>0?`col-resize`:`row-resize`}}var Ef=new WeakMap;function Df(e){if(!e.defaultView||!e.adoptedStyleSheets)return;let{prevStyle:t,styleSheet:n}=Ef.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=lf();switch(r.state!==`inactive`&&r.ownerDocument!==e&&(r={cursorFlags:0,state:`inactive`}),r.state){case`active`:case`hover`:{let e=Tf({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)}Ef.set(e,{prevStyle:t,styleSheet:n})}function Of(e){return e.state===`inactive`?void 0:e.ownerDocument}function kf({next:e,prev:t}){let n=Of(t),r=Of(e);n&&n!==r&&Df(n),r&&Df(r)}function Af({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 jf(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 Mf(e,t){return Array.from(t).sort((t,n)=>{let r=e===`horizontal`?Nf(t,n):Pf(t,n);return r===0?jf(t.element,n.element):r})}function Nf(e,t){let n=e.element.offsetLeft-t.element.offsetLeft;return n===0?e.element.offsetWidth-t.element.offsetWidth:n}function Pf(e,t){let n=e.element.offsetTop-t.element.offsetTop;return n===0?e.element.offsetHeight-t.element.offsetHeight:n}function Ff(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.ELEMENT_NODE}function If(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 Lf({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}=If(r,n),s=e===`horizontal`?t:o;s<a&&(a=s,i=n)}return ef(i,`No rect found`),i}function Rf({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=Mf(i,Array.from(r.children).filter(Ff).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,Lf({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=rf({expandHitTargets:e,axis:t,rect:`width`in i?i:i.element.getBoundingClientRect()});(n||!l&&!(r<=d||r>p))&&(f??=Af({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 zf(e,t){let n=getComputedStyle(e);return t*parseFloat(n.fontSize)}function Bf(e,t){let n=getComputedStyle(e.ownerDocument.documentElement);return t*parseFloat(n.fontSize)}function Vf(e){return e/100*window.innerHeight}function Hf(e){return e/100*window.innerWidth}function Uf({axisSize:e,itemElement:t,styleProp:n}){let r,[i,a]=af(n);switch(a){case`%`:r=i/100*e;break;case`px`:r=i;break;case`rem`:r=Bf(t,i);break;case`em`:r=zf(t,i);break;case`vh`:r=Vf(i);break;case`vw`:r=Hf(i)}return r}function Wf(e){return parseFloat(e.toFixed(3))}function Gf(e,t=Af({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=Wf(Uf({axisSize:t,itemElement:n,styleProp:r.collapsedSize})/t*100));let a;r.collapsedThreshold!==void 0&&(a=Wf(Uf({axisSize:t,itemElement:n,styleProp:r.collapsedThreshold})/t*100));let o;r.defaultSize!==void 0&&(o=Wf(Uf({axisSize:t,itemElement:n,styleProp:r.defaultSize})/t*100));let s=0;r.minSize!==void 0&&(s=Wf(Uf({axisSize:t,itemElement:n,styleProp:r.minSize})/t*100));let c=100;return r.maxSize!==void 0&&(c=Wf(Uf({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 Kf=new Map,qf=new of,Jf=0,Yf=[],Xf;function Zf(){Jf++}function Qf(){for(let e=0;e<Yf.length;e++)try{qf.emit(`axisChange`,Yf[e])}catch(e){Xf??={error:e}}Yf.length=0}function $f(){if(Jf===1&&Qf(),Jf--,Jf===0&&Xf){let{error:e}=Xf;throw Xf=void 0,e}}function ep(e){Kf=new Map(Kf),Kf.delete(e)}function tp(e,t){for(let[t]of Kf)if(t.id===e)return t}function np(e,t){for(let[t,n]of Kf)if(t.id===e)return n;if(t)throw Error(`Could not find data for Group with id ${e}`)}function rp(){return Kf}function ip(e,t){return qf.addListener(`axisChange`,n=>{n.axis.id===e&&t(n)})}function ap(e,t,n){let r=Kf.get(e);Kf=new Map(Kf),Kf.set(e,t);let i={axis:e,isUserInteraction:n?.isUserInteraction===!0,prev:r,next:t};Jf>0?Yf.push(i):qf.emit(`axisChange`,i)}function op(e,{pointerId:t,pointerType:n}){return t===e.pointerId||n===`pen`&&e.pointerType===`pen`}function sp(e,t,n={}){return e.ownerDocument===t&&(n.pointerId===void 0||op(e,n))}function cp(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 lp(e,t,n=0){return Math.abs(Wf(e)-Wf(t))<=n}function up(e,t){return lp(e,t)?0:e>t?1:-1}function dp({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(up(r,l)<0){if(o){let e=a??(l-i)/2,t=up(n,i)<=0,o=t?i+e:l-e,s=up(r,o);r=up(r,i)<=0||s<0||a!==void 0&&t&&s===0?i:l}else r=l}return r=Math.min(c,r),r=Wf(r),r}function fp({delta:e,initialLayout:t,itemConstraints:n,pivotIndices:r,prevLayout:i,trigger:a}){if(lp(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;ef(u!=null,`Invalid first pivot index`),ef(d!=null,`Invalid second pivot index`);let f=0;switch(a){case`keyboard`:{let t=e<0?d:u,r=n[t];ef(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(ef(n!=null,`Previous layout not found for panel index ${t}`),lp(n,i)){let t=o-n;up(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}{let t=e<0?u:d,r=n[t];ef(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(ef(n!=null,`Previous layout not found for panel index ${t}`),lp(n,o)){let t=n-i;up(t,Math.abs(e))>0&&(e=e<0?0-t:t)}}}break;default:{let t=e<0?d:u,r=n[t];ef(r,`Panel constraints not found for index ${t}`);let i=s[t],{collapsedSize:a,collapsedThreshold:o,collapsible:c,minSize:l}=r;if(c&&up(i,l)<0){let t=l-a,n=o??t/2;if(up(i+Math.abs(e),l)<0){let r=up(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];ef(e!=null,`Previous layout not found for panel index ${r}`);let a=dp({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];ef(i!=null,`Previous layout not found for panel index ${t}`);let a=i-r,c=dp({overrideDisabledItems:o,itemConstraints:n[t],prevSize:i,size:a});if(!lp(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(cp(c,l))return i;{let t=e<0?d:u,r=s[t];ef(r!=null,`Previous layout not found for panel index ${t}`);let i=r+f,a=dp({overrideDisabledItems:o,itemConstraints:n[t],prevSize:r,size:i});if(l[t]=a,!lp(a,i)){let t=i-a,r=e<0?d:u;for(;r>=0&&r<n.length;){let i=l[r];ef(i!=null,`Previous layout not found for panel index ${r}`);let a=i+t,s=dp({overrideDisabledItems:o,itemConstraints:n[r],prevSize:i,size:a});if(lp(i,s)||(t-=s-i,l[r]=s),lp(t,0))break;e>0?r--:r++}}}return lp(Object.values(l).reduce((e,t)=>t+e,0),100,.1)?l.reduce((e,t,r)=>(e[n[r].itemId]=t,e),{}):i}function pp(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(t[n]===void 0||up(e[n],t[n])!==0)return!1;return!0}function mp(e){Zf();try{hp(e)}finally{$f()}}function hp({commit:e,event:t,hitRegions:n,initialLayoutMap:r,mountedAxes:i,pointerDownAtPoint:a,prevCursorFlags:o}){let s=0,c=lf(),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=fp({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&&!pp(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(pp(r,t)&&m!==0&&!p)switch(d){case`horizontal`:s|=m<0?_f:vf;break;case`vertical`:s|=m<0?yf:bf}(o.resizePreviewMode!==`separator`||e)&&!pp(r,b)&&ap(n.axis,{defaultLayoutDeferred:_,derivedItemConstraints:v,axisSize:y,layout:r,requestedAxisSize:y,requestedLayout:r,separatorToItems:x})}});let d=0;t.movementX===0?d|=o&xf:d|=s&xf,t.movementY===0?d|=o&Sf:d|=s&Sf;let f=c.state===`active`&&(t.clientX!==c.pointerDownAtPoint.x||t.clientY!==c.pointerDownAtPoint.y);df(d,l,u,f)}function gp(e,t){let n=lf();if(n.state!==`active`||!sp(n,e,t))return;let r=rp();Zf();try{mp({commit:!0,event:t,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags}),Qf(),ff({cursorFlags:0,state:`inactive`}),n.hitRegions.length>0&&(t.preventDefault?.(),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=np(e.axis.id,!0);ap(e.axis,t,{isUserInteraction:!0})}))}finally{$f()}}function _p(e){if(e.defaultPrevented)return;let{clientX:t,clientY:n,movementX:r,movementY:i}=e;gp(e.currentTarget,{clientX:t,clientY:n,movementX:r,movementY:i})}function vp(e,t,n){let r,i={x:1/0,y:1/0};for(let a of t){let t=If(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 yp(e){return typeof e==`object`&&!!e&&`nodeType`in e&&e.nodeType===Node.DOCUMENT_FRAGMENT_NODE}function bp(e,t){if(e===t)throw Error(`Cannot compare node with itself`);let n={a:Ep(e),b:Ep(t)},r;for(;n.a.at(-1)===n.b.at(-1);)r=n.a.pop(),n.b.pop();ef(r,`Stacking order can only be calculated for elements with a common ancestor`);let i={a:Tp(wp(n.a)),b:Tp(wp(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 xp=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Sp(e){let t=getComputedStyle(Dp(e)??e).display;return t===`flex`||t===`inline-flex`}function Cp(e){let t=getComputedStyle(e);return!!(t.position===`fixed`||t.zIndex!==`auto`&&(t.position!==`static`||Sp(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`||xp.test(t.willChange)||t.webkitOverflowScrolling===`touch`)}function wp(e){let t=e.length;for(;t--;){let n=e[t];if(ef(n,`Missing node`),Cp(n))return n}return null}function Tp(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Ep(e){let t=[];for(;e;)t.push(e),e=Dp(e);return t}function Dp(e){let{parentNode:t}=e;return yp(t)?t.host:t}function Op(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 kp(e){try{return e.matches(`:modal`)}catch{return!1}}function Ap({axisElement:e,hitRegion:t,pointerEventTarget:n}){if(Ff(n)){let t=n.closest(`dialog`);if(t&&!t.contains(e)&&kp(t))return!1}if(!Ff(n)||n.contains(e)||e.contains(n)||!n.isConnected||!e.isConnected)return!0;if(bp(n,e)>0){let r=n;for(;r;){if(r.contains(e))return!0;if(Op(r.getBoundingClientRect(),t))return!1;r=r.parentElement}}return!0}function jp(e,t,n){let r=[];return t.forEach((t,i)=>{if(i.disabled||i.element.ownerDocument!==n)return;let a=Rf({axis:i}),o=vp(i.orientation,a,{x:e.clientX,y:e.clientY});o&&o.distance.x<=0&&o.distance.y<=0&&Ap({axisElement:i.element,hitRegion:o.hitRegion.rect,pointerEventTarget:e.target})&&r.push(o.hitRegion)}),r}function Mp(e){let t=0,n=0,r={};for(let i of e)if(i.defaultSize!==void 0){t++;let e=Wf(i.defaultSize);n+=e,r[i.itemId]=e}else r[i.itemId]=void 0;let i=e.length-t;if(i!==0){let t=Wf((100-n)/i);for(let n of e)n.defaultSize===void 0&&(r[n.itemId]=t)}return r}function Np(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 Pp({axis:e,itemConstraints:t}){let n=e.items.map(({id:e})=>e).join(`,`),r=e.mutableState.defaultLayout;return e.mutableState.layouts[n]??(r&&Np(e.items,r)?r:Mp(t))}function Fp(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 Ip(e,t){return e.length===t.length&&e.every((e,n)=>Fp(e,t[n]))}function Lp({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(!lp(i,100)&&r.length>0)for(let e=0;e<t.length;e++){let t=r[e];ef(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];ef(i!=null,`No layout data found for index ${e}`);let o=r[e];ef(o!=null,`No layout data found for index ${e}`);let s=dp({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:i,size:o});o!=s&&(a+=o-s,r[e]=s)}if(!lp(a,0))for(let e=0;e<t.length;e++){let n=r[e];ef(n!=null,`No layout data found for index ${e}`);let i=n+a,o=dp({overrideDisabledItems:!0,itemConstraints:t[e],prevSize:n,size:i});if(n!==o&&(a-=o-n,r[e]=o,lp(a,0)))break}return r.reduce((e,n,r)=>(e[t[r].itemId]=n,e),{})}function Rp({itemIds:e,layout:t}){return Lp({layout:t,itemConstraints:e.map(e=>({collapsedSize:0,collapsible:!1,defaultSize:void 0,disabled:void 0,itemId:e,maxSize:100,minSize:0}))})}function zp({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=Wf(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]=Wf((r[e]??0)/a*l);else{let e=Wf(l/c.length);for(let t of c)u[t]=e}return u}function Bp({axis:e,axisState:t}){let n=Af({axis:e});if(n===0)return;let r=Gf(e,n),i=t.requestedAxisSize,a=t.requestedLayout;t.defaultLayoutDeferred&&(i=n,a=Rp({itemIds:e.items.map(({id:e})=>e),layout:Pp({axis:e,itemConstraints:r})}));let o=Lp({layout:zp({axis:e,nextAxisSize:n,prevAxisSize:i,prevLayout:a}),itemConstraints:r});return{changed:t.defaultLayoutDeferred||!pp(t.layout,o)||!Ip(t.derivedItemConstraints,r)||t.axisSize!==n,state:{defaultLayoutDeferred:!1,derivedItemConstraints:r,axisSize:n,layout:o,requestedAxisSize:i,requestedLayout:a,separatorToItems:t.separatorToItems}}}function Vp({axisId:e,itemId:t}){let n=()=>{let t=rp();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=Bp({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&&lp(n.collapsedSize,r[n.itemId])}))){let e=n.slice(0,o).reduce((e,t)=>e+r[t.id],0);return{...r,[t]:Wf(100-e)}}return fp({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=Lp({layout:s({nextSize:e,items:t.items,prevLayout:c,derivedItemConstraints:a}),itemConstraints:a});(n||!pp(c,l))&&ap(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&&lp(t,n)},resize:e=>{let t=i(),{axisSize:n}=t.state,{element:r}=a(),o=Wf(Uf({axisSize:n,itemElement:r,styleProp:e})/n*100);c(o,t)}}}function Hp(e){e.defaultPrevented||jp(e,rp(),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=Vp({axisId:t.axis.id,itemId:n.id});i&&r!==void 0&&(i.resize(r),e.preventDefault())}}})}function Up(e){let t=rp();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 Wp({axisId:e}){let t=()=>{let t=rp();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=Bp({axis:n,axisState:r}),a=i?.state??r,{defaultLayoutDeferred:o,derivedItemConstraints:s,axisSize:c,layout:l}=a,u=Lp({layout:e,itemConstraints:s});return o?l:((i?.changed||!pp(l,u))&&ap(n,{...a,layout:u,requestedAxisSize:c,requestedLayout:u}),u)}}}function Gp(e,t){let n=Up(e),r=np(n.id,!0),i=n.separators.find(t=>t.element===e);ef(i,`Matching separator not found`);let a=r.separatorToItems.get(i);ef(a,`Matching panels not found`);let o=a.map(e=>n.items.indexOf(e)),s=Wp({axisId:n.id}).getLayout(),c=Lp({layout:fp({delta:t,initialLayout:s,itemConstraints:r.derivedItemConstraints,pivotIndices:o,prevLayout:s,trigger:`keyboard`}),itemConstraints:r.derivedItemConstraints});pp(s,c)||ap(n,{defaultLayoutDeferred:r.defaultLayoutDeferred,derivedItemConstraints:r.derivedItemConstraints,axisSize:r.axisSize,layout:c,requestedAxisSize:r.axisSize,requestedLayout:c,separatorToItems:r.separatorToItems},{isUserInteraction:!0})}function Kp(e){return e.separators.filter(e=>!e.disabled)}function qp(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=Up(t);if(!(n.disabled||n.separators.find(e=>e.element===t)?.disabled))switch(e.key){case`ArrowDown`:e.preventDefault(),n.orientation===`vertical`&&Gp(t,5);break;case`ArrowLeft`:e.preventDefault(),n.orientation===`horizontal`&&Gp(t,-5);break;case`ArrowRight`:e.preventDefault(),n.orientation===`horizontal`&&Gp(t,5);break;case`ArrowUp`:e.preventDefault(),n.orientation===`vertical`&&Gp(t,-5);break;case`End`:e.preventDefault(),Gp(t,100);break;case`Enter`:{e.preventDefault();let{derivedItemConstraints:r,layout:i,separatorToItems:a}=np(n.id,!0),o=n.separators.find(e=>e.element===t);ef(o,`Matching separator not found`);let s=a.get(o);ef(s,`Matching panels not found`);let c=s[0],l=r.find(e=>e.itemId===c.id);if(ef(l,`Panel metadata not found`),l.collapsible){let e=i[c.id];Gp(t,(l.collapsedSize===e?n.mutableState.expandedItemSizes[c.id]??l.minSize:l.collapsedSize)-e)}break}case`F6`:{e.preventDefault();let t=Kp(n).map(e=>e.element),r=t.findIndex(t=>t===e.currentTarget);ef(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(),Gp(t,-100)}}function Jp(e,t){let n=lf();if(n.state!==`active`||!sp(n,e,t))return!1;let r=rp();Zf();try{n.previewLayoutMap.forEach((e,t)=>{let n=r.get(t);t.resizePreviewMode===`separator`&&n&&!pp(e,n.layout)&&ap(t,{...n,layout:e,requestedAxisSize:n.axisSize,requestedLayout:e})}),Qf(),ff({cursorFlags:0,state:`inactive`}),n.hitRegions.forEach(e=>{if(!r.has(e.axis))return;let t=np(e.axis.id,!0);ap(e.axis,t,{isUserInteraction:!0})})}finally{$f()}return!0}function Yp(e){let t=lf();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))||Jp(e.currentTarget,e)}function Xp(e){Jp(e.currentTarget,e)}function Zp(e,t){let{element:n,orientation:r,items:i}=e,a=n.getBoundingClientRect(),o=r===`horizontal`;return Rf({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 lp(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 Qp(e){if(e.defaultPrevented||e.pointerType===`mouse`&&e.button>0)return;let t=lf();if(t.state===`active`){op(t,e)&&Jp(t.ownerDocument,t);return}let n=rp(),r=jp(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`?Zp(e,r):[]);ff({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 $p(e){let t=e.currentTarget,n=rp(),r=lf();if(r.state===`active`){if(!sp(r,t,e))return;mp({commit:!1,event:e,hitRegions:r.hitRegions,initialLayoutMap:r.initialLayoutMap,mountedAxes:n,prevCursorFlags:r.cursorFlags})}}function em(e){if(e.defaultPrevented)return;let t=e.currentTarget,n=lf(),r=rp();switch(n.state){case`active`:if(!sp(n,t,e))return;if(e.buttons===0){Jp(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)}mp({commit:!1,event:e,hitRegions:n.hitRegions,initialLayoutMap:n.initialLayoutMap,mountedAxes:r,pointerDownAtPoint:n.pointerDownAtPoint,prevCursorFlags:n.cursorFlags});break;default:{let i=jp(e,r,t);i.length===0?n.state!==`inactive`&&ff({cursorFlags:0,state:`inactive`}):ff({cursorFlags:0,hitRegions:i,ownerDocument:t,state:`hover`});break}}}function tm(e){if(e.relatedTarget instanceof HTMLIFrameElement){let t=lf();t.state===`hover`&&t.ownerDocument===e.currentTarget&&ff({cursorFlags:0,state:`inactive`})}}function nm(e){e.defaultPrevented||e.pointerType===`mouse`&&e.button>0||gp(e.currentTarget,e)}function rm(e){e.target===e.currentTarget&&Jp(e.currentTarget.document)}function im(e){Jp(e.currentTarget.document)}function am(e,t,n){if(!n[0])return;let r=e.items.find(e=>e.element===t);if(!r||!r.onResize)return;let i=Af({axis:e}),a=e.orientation===`horizontal`?r.element.offsetWidth:r.element.offsetHeight,o=r.mutableValues.prevSize,s={asPercentage:Wf(a/i*100),inPixels:a};r.mutableValues.prevSize=s,r.onResize(s,r.id,o)}var om=new Map,sm=!1;function cm(e){let t=!0;ef(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;Zf();try{for(let i of n){let{borderBoxSize:n,target:a}=i;if(a===e.element){if(t){let t=np(e.id);if(!t)break;let n=Bp({axis:e,axisState:t});if(!n)break;if(!n.changed)continue;ap(e,n.state)}}else try{am(e,a,n)}catch(e){r??={error:e}}}}finally{$f()}if(r)throw r.error});a.observe(e.element),e.items.forEach(e=>{ef(!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=Af({axis:e}),s=Gf(e,o),c=Pp({axis:e,itemConstraints:s}),l=Lp({layout:c,itemConstraints:s}),u=e.element.ownerDocument,d=u.defaultView;om.set(u,(om.get(u)??0)+1);let f=new Map;return Rf({axis:e,includeDisabled:!0}).forEach(e=>{e.separator&&f.set(e.separator,e.items)}),ap(e,{defaultLayoutDeferred:o===0,derivedItemConstraints:s,axisSize:o,layout:l,requestedAxisSize:o,requestedLayout:Rp({itemIds:e.items.map(({id:e})=>e),layout:c}),separatorToItems:f}),e.separators.forEach(e=>{ef(!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`,qp)}),sm||(sm=!0,uf(kf)),om.get(u)===1&&(u.addEventListener(`contextmenu`,_p,!0),u.addEventListener(`dblclick`,Hp,!0),u.addEventListener(`lostpointercapture`,Yp,!0),u.addEventListener(`pointercancel`,Xp,!0),u.addEventListener(`pointerdown`,Qp,!0),u.addEventListener(`pointerleave`,$p),u.addEventListener(`pointermove`,em),u.addEventListener(`pointerout`,tm),u.addEventListener(`pointerup`,nm,!0),d?.addEventListener(`blur`,rm),d?.addEventListener(`pagehide`,im)),function(){t=!1,om.set(u,Math.max(0,(om.get(u)??0)-1)),ep(e),mf(e),e.separators.forEach(e=>{e.element.removeEventListener(`keydown`,qp)}),om.get(u)||(u.removeEventListener(`contextmenu`,_p,!0),u.removeEventListener(`dblclick`,Hp,!0),u.removeEventListener(`lostpointercapture`,Yp,!0),u.removeEventListener(`pointercancel`,Xp,!0),u.removeEventListener(`pointerdown`,Qp,!0),u.removeEventListener(`pointerleave`,$p),u.removeEventListener(`pointermove`,em),u.removeEventListener(`pointerout`,tm),u.removeEventListener(`pointerup`,nm,!0),d?.removeEventListener(`blur`,rm),d?.removeEventListener(`pagehide`,im)),a.disconnect()}}function lm({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=lp(e.collapsedSize,n[e.itemId]),a=lp(e.collapsedSize,r[e.itemId]);i&&!a&&(t.mutableState.expandedItemSizes[e.itemId]=r[e.itemId])}})}function um(){let[e,t]=(0,Y.useState)({});return[e,(0,Y.useCallback)(()=>t({}),[])]}function dm(e){let t=(0,Y.useRef)({...e});return Xd(()=>{for(let n in e)t.current[n]=e[n]},[e]),t.current}var fm=(0,Y.createContext)(null);function pm({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=Lp({layout:fp({delta:l-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n],i=Lp({layout:fp({delta:c-o,initialLayout:e,itemConstraints:t,pivotIndices:u,prevLayout:e}),itemConstraints:t})[n]}return{valueControls:n,valueMax:i,valueMin:a,valueNow:o}}function mm({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=dm({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=Qd(E,l),k=n===`horizontal`?`vertical`:`horizontal`;Xd(()=>{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=uf(e=>{C(e.next.state!==`inactive`&&e.next.hitRegions.some(e=>e.separator===n||(d?.(e)??!1))?e.next.state:`inactive`)}),a=ip(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({...pm({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]),Xd(()=>{let e=D.current;e&&pf(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 hm(e){for(let t=1;t<e.length;t++)if(jf(e[t-1],e[t])>0)return!1;return!0}function gm({separator:e}){let{element:t}=e,n=(0,Y.useRef)(null);return Xd(()=>{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 _m(){let e=(0,Y.useContext)(fm);return ef(e,`Group Context not found; did you render a Panel or Separator outside of a Group?`),e}function vm(e){let{registerOverlay:t}=_m(),n=(0,Y.useRef)(e);Fp(n.current,e)||(n.current=e);let r=n.current;return Xd(()=>t(r),[t,r]),null}vm.displayName=`SeparatorOverlay`;function ym({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 bm({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===vm&&(c=s.props,s=void 0),s??(c?s=(0,X.jsx)(ym,{...c,active:t.active,orientation:n.orientation}):a&&(s=(0,X.jsx)(gm,{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 xm(e){return Array.from(e).sort(jf)}function Sm(e,t){let n=(0,Y.useRef)({getLayout:()=>({}),setLayout:hf});(0,Y.useImperativeHandle)(t,()=>n.current,[]),Xd(()=>{Object.assign(n.current,Wp({axisId:e}))})}function Cm({groupId:e,resizePreviewMode:t}){let[n,r]=(0,Y.useState)([]),i=(0,Y.useRef)(n);return Xd(()=>{let n=n=>{let a=tp(e),o=t===`separator`&&n.state===`active`?n.previews.filter(e=>e.axis===a&&(e.active||!lp(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(lf());return}let a=uf(({next:e})=>n(e));return n(lf()),a},[e,t]),n}function wm({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=Zd(e=>{pp(h.current.onLayoutChange,e)||(h.current.onLayoutChange=e,c?.(e))}),_=Zd((e,t,n)=>{pp(h.current.onLayoutChanged,e)||(h.current.onLayoutChanged=e,l?.(e,{isUserInteraction:t,requestedLayout:n}))}),v=Yd(s),[y,b]=(0,Y.useState)(),x=Cm({groupId:v,resizePreviewMode:d}),S=(0,Y.useRef)(null),[C,w]=um(),T=(0,Y.useRef)([]),E=(0,Y.useRef)({lastExpandedPanelSizes:{},layouts:{},panels:[],separators:[]}),D=Qd(S,a);Sm(v,o);let O=Zd((e,t)=>{let r=np(e);if(r)return{flexGrow:r.layout[t]??1};if(n?.[t])return{flexGrow:n?.[t]}}),k=dm({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=Mf(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=Mf(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=tp(v),i=np(v);r&&i&&ap(r,{...i,derivedItemConstraints:Gf(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 Xd(()=>{let e=S.current;if(e===null)return;let t=E.current;t.panels=Mf(u,t.panels),t.separators=Mf(u,t.separators),T.current=xm([...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=cm(r),{defaultLayoutDeferred:o,derivedItemConstraints:s,layout:c,requestedLayout:l}=np(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=ip(v,e=>{let{defaultLayoutDeferred:t,derivedItemConstraints:n,layout:i,requestedLayout:a}=e.next;if(t||n.length===0)return;lm({derivedItemConstraints:n,axis:r,layout:i,prevLayout:e.prev?.layout,requestedLayout:a});let o=lf(),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]),Xd(()=>{hm(T.current)||w()}),(0,Y.useEffect)(()=>{let e=j.current;e&&(e.mutableState.defaultLayout=n,e.mutableState.disableCursor=!!r)}),(0,X.jsx)(fm.Provider,{value:A,children:(0,X.jsxs)(`div`,{...m,className:t,"data-group":!0,"data-testid":$d(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)(bm,{overlay:y,preview:e},e.key))]})})}wm.displayName=`Group`;function Tm(e,t){return`react-resizable-panels:${[e,...t].join(`:`)}`}function Em({id:e,panelIds:t,storage:n}){let r=Tm(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 Dm({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=Tm(o,n??[]),c=(0,Y.useSyncExternalStore)(Om,()=>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 Em({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?Tm(o,Object.keys(i)):Tm(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 Om(){return function(){}}function km(e,t){let{id:n}=_m(),r=(0,Y.useRef)({collapse:gf,expand:gf,getSize:()=>({asPercentage:0,inPixels:0}),isCollapsed:()=>!1,resize:gf});(0,Y.useImperativeHandle)(t,()=>r.current,[]),Xd(()=>{Object.assign(r.current,Vp({axisId:n,itemId:e}))})}function Am({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=Jd(l),_=Yd(l),v=dm({disabled:o}),y=(0,Y.useRef)(null),b=Qd(y,s),{getPanelStyles:x,id:S,orientation:C,registerPanel:w,updatePanelProps:T}=_m(),E=f!==null,D=Zd((e,t,n)=>{f?.(e,l,n)});Xd(()=>{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]),km(_,p);let O=()=>{let e=x(S,_);if(e)return JSON.stringify(e)},k=(0,Y.useSyncExternalStore)(e=>ip(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":$d(h,l),id:_,ref:b,style:{...jm,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})})}Am.displayName=`Panel`;var jm={minHeight:0,maxHeight:`100%`,height:`auto`,minWidth:0,maxWidth:`100%`,width:`auto`,border:`none`,borderWidth:0,padding:0,margin:0};function Mm(){return(0,Y.useRef)(null)}var Nm={flexBasis:`auto`},Pm={flexGrow:0,flexShrink:0};function Fm({children:e,className:t,disabled:n,disableDoubleClick:r,elementRef:i,id:a,preview:o,style:s,...c}){let l=Yd(a),{disableCursor:u,id:d,orientation:f,registerSeparator:p,updateSeparatorProps:m}=_m();return(0,X.jsx)(mm,{attributes:c,axisId:d,axisOrientation:f,className:t,"data-testid":$d(c,a),disableCursor:u,disabled:n,disableDoubleClick:r,elementRef:i,id:l,preview:o,registerSeparator:p,requiredStyle:Pm,style:s,styleDefaults:Nm,updateSeparatorProps:m,children:e})}Fm.displayName=`Separator`;function Im(){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 Lm=Im(),Rm=/\.(?:tex|bib|cls|sty)$/i,zm=3e4,Bm=null,Vm=!1,Hm=null,Um=1,Wm=new Map,Gm=[],Km=null,qm=null,Jm=class extends Error{kind;constructor(e,t){super(t),this.kind=e,this.name=`TexFmtError`}};function Ym(e){return e instanceof Jm}function Xm(e){Bm?.terminate(),Bm=null,Vm=!1,Hm!==null&&window.clearTimeout(Hm),Hm=null,Km=null,Gm.length=0,qm=null,Lm.failed(e);for(let t of Wm.values())t.timeout!==null&&window.clearTimeout(t.timeout),t.reject(e);Wm.clear()}function Zm(){if(Km!==null||Gm.length===0)return;let e;try{e=Qm()}catch(e){Xm(e instanceof Jm?e:new Jm(`load`,`The bundled tex-fmt formatter could not be loaded.`));return}if(!Vm)return;let t=Gm.shift();if(t===void 0)return;let n=Wm.get(t);if(!n)Zm();else{Km=t,n.timeout=window.setTimeout(()=>{Km===t&&Xm(new Jm(`result`,`The formatter did not respond within 30 seconds.`))},zm);try{e.postMessage({...n.request,id:t})}catch{Xm(new Jm(`load`,`The formatter worker could not receive the source.`))}}}function Qm(){if(Bm)return Bm;if(typeof Worker>`u`){let e=new Jm(`load`,`This browser does not support formatter workers.`);throw Lm.failed(e),e}Lm.loading();try{Bm=new Worker(new URL(new URL(`latexFormatterWorker-BIDCSZPd.js`,import.meta.url).href,``+import.meta.url),{type:`module`,name:`texlite-latex-formatter`}),Hm=window.setTimeout(()=>{Vm||Xm(new Jm(`load`,`The formatter did not finish loading within 30 seconds.`))},zm)}catch{let e=new Jm(`load`,`The bundled tex-fmt formatter could not be loaded.`);throw Lm.failed(e),e}return Bm.onmessage=e=>{let t=e.data;if(t&&`type`in t){t.type===`ready`&&(Vm=!0,Hm!==null&&window.clearTimeout(Hm),Hm=null,Zm());return}if(!t||typeof t.id!=`number`){Xm(new Jm(`result`,`The formatter worker returned an invalid response.`));return}let n=Wm.get(t.id);if(n){if(Wm.delete(t.id),n.timeout!==null&&window.clearTimeout(n.timeout),Km===t.id&&(Km=null),t.ok)Lm.working(),n.resolve(t.result),Zm();else{let e=new Jm(t.kind,t.message);t.kind===`format`?(Lm.working(),n.reject(e),Zm()):(n.reject(e),Xm(e))}}},Bm.onerror=()=>{Xm(new Jm(`load`,`The bundled tex-fmt formatter could not be loaded.`))},Bm.onmessageerror=()=>{Xm(new Jm(`result`,`The formatter worker returned an unreadable response.`))},Bm}function $m(e){let t=Um++;return new Promise((n,r)=>{Wm.set(t,{request:e,resolve:n,reject:r,timeout:null}),Gm.push(t),Zm()})}function eh(e,t=``){return $m({action:`format`,source:e,config:t})}async function th(){Bm&&Lm.getSnapshot().status===`working`||(qm||=$m({action:`probe`}).then(()=>void 0).finally(()=>{qm=null}),await qm)}async function nh(){(Bm||Wm.size)&&Xm(new Jm(`load`,`The formatter runtime was reloaded.`)),Lm.loading(),await th()}function rh(e){return Rm.test(e)}function ih(e){return e.match(/(?:\r?\n)+$/)?.[0]??``}function ah(e,t){let n=ih(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 oh(e,t,n=0){return $m({action:`diff`,source:e,formatted:t,baseOffset:n})}var sh=null,ch=1,lh=new Map,uh=class extends Error{kind;constructor(e){super(`BibTeX formatter: ${e}`),this.kind=e,this.name=`BibtexFormatterError`}};function dh(e){sh?.terminate(),sh=null;for(let t of lh.values())clearTimeout(t.timeout),t.reject(new uh(e));lh.clear()}function fh(){if(sh)return sh;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 sh=e,e.onmessage=({data:t})=>{if(sh!==e)return;if(!t||typeof t.id!=`number`||typeof t.ok!=`boolean`){dh(`unavailable`);return}let n=lh.get(t.id);n&&(t.ok&&(t.action!==n.action||(t.action===`format`?typeof t.result!=`string`:!ph(t.result)))?dh(`unavailable`):(clearTimeout(n.timeout),lh.delete(t.id),t.ok?n.resolve(t.result):t.kind===`too-large`||t.kind===`invalid`?n.reject(new uh(t.kind)):(n.reject(new uh(`unavailable`)),dh(`unavailable`))))},e.onerror=e.onmessageerror=()=>{sh===e&&dh(`unavailable`)},e}function ph(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 mh(e){return new Promise((t,n)=>{let r;try{r=fh()}catch{n(new uh(`unavailable`));return}let i=ch++,a=setTimeout(()=>dh(`timeout`),3e4);lh.set(i,{action:e.action,resolve:t,reject:n,timeout:a});try{r.postMessage({...e,id:i})}catch{dh(`unavailable`)}})}function hh(e,t){return mh({action:`format`,source:e,maxBytes:t})}function gh(e,t,n=0){return mh({action:`diff`,source:e,formatted:t,baseOffset:n})}function _h(e,t=null){let n=vh(e),r=t===`succeeded`||t===null&&xh(e)?[]:yh(n.filter(Sh));return{warnings:yh(vh(bh(e)).filter(e=>!Sh(e)&&Ch(e))),errors:r}}function vh(e){return e.split(`
|
|
15
|
+
`).map(e=>e.trim()).filter(Boolean)}function yh(e){return[...new Set(e)]}function bh(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 xh(e){return/Latexmk: All targets .* are up-to-date/i.test(e)&&/Output written on .*\.pdf/i.test(e)}function Sh(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 Ch(e){return/\bwarnings?\b|overfull|underfull|badness/i.test(e)}var wh=Object.freeze({}),Th=class{threads=new Map;listeners=new Map;newComments=new Map;getThread(e){return this.threads.get(e)??wh}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,wh):(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=U(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)}},Eh=Y.createContext(void 0),Dh=e=>{let t=Y.useContext(Eh);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},Oh=({client:e,children:t})=>(Y.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,X.jsx)(Eh.Provider,{value:e,children:t})),kh={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},Ah=new class{#e=kh;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 jh(e){setTimeout(e,0)}var Mh=typeof window>`u`||`Deno`in globalThis;function Nh(){}function Ph(e,t){return typeof e==`function`?e(t):e}function Fh(e){return typeof e==`number`&&e>=0&&e!==1/0}function Ih(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Lh(e,t){return typeof e==`function`?e(t):e}function Rh(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==Bh(o,t.options))return!1}else if(!Hh(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 zh(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(Vh(t.options.mutationKey)!==Vh(a))return!1}else if(!Hh(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Bh(e,t){return(t?.queryKeyHashFn||Vh)(e)}function Vh(e){return JSON.stringify(e,(e,t)=>qh(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function Hh(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(!Hh(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!Hh(e[r],t[r]))return!1;return!0}return!1}var Uh=Object.prototype.hasOwnProperty;function Wh(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=Kh(e)&&Kh(t);if(!r&&!(qh(e)&&qh(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:Uh.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Wh(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function Gh(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 Kh(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function qh(e){if(!Jh(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!(!Jh(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Jh(e){return Object.prototype.toString.call(e)===`[object Object]`}function Yh(e){return new Promise(t=>{Ah.setTimeout(t,e)})}function Xh(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Wh(e,t)}function Zh(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function Qh(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var $h=Symbol();function eg(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===$h?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function tg(e,t){return typeof e==`function`?e(...t):!!e}function ng(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 rg=()=>Mh,ig=()=>rg(),ag=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(){}},og=new class extends ag{#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`}},sg=jh;function cg(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=sg,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 lg=cg(),ug=new class extends ag{#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 dg(e){return Math.min(1e3*2**e,3e4)}function fg(e){return(e??`online`)!==`online`||ug.isOnline()}var pg=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function mg(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(Nh);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new pg(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>og.isFocused()&&(e.networkMode===`always`||ug.isOnline())&&e.canRun(),p=()=>fg(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??(ig()?0:3),a=e.retryDelay??dg,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),Yh(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 hg=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Fh(this.gcTime)&&(this.#e=Ah.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(ig()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(Ah.clearTimeout(this.#e),this.#e=void 0)}};function gg(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=>{ng(e,()=>t.signal,()=>n=!0)},u=eg(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?Qh:Zh;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?vg:_g,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]:_g(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 _g(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 vg(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var yg=class extends hg{#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=Sg(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=Sg(this.options);e.data!==void 0&&(this.setState(xg(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=Xh(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(Nh).catch(Nh):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=>Lh(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===$h||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>Lh(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:!Ih(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=eg(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`?gg(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=mg({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof pg&&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 pg){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,...bg(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...xg(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),lg.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function bg(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:fg(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function xg(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function Sg(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 Cg=class extends ag{#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),Tg(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Eg(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Eg(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 Lh(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&&!Gh(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&Dg(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||Lh(this.options.enabled,this.#t)!==Lh(t.enabled,this.#t)||Lh(this.options.staleTime,this.#t)!==Lh(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||Lh(this.options.enabled,this.#t)!==Lh(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 Gh(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(Nh)),t}#h(e){return!ig()&&Lh(this.options.enabled,this.#t)!==!1&&Fh(e)}#g(){this.#b();let e=Lh(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=Ih(this.#r.dataUpdatedAt,e)+1;this.#u=Ah.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return Lh(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=Ah.setInterval(()=>{(this.options.refetchIntervalInBackground||og.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(Ah.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(Ah.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&&Tg(e,t),o=i&&Dg(e,n,t,r);(a||o)&&(l={...l,...bg(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=Xh(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=Xh(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:Og(e,t),refetch:this.refetch,isEnabled:Lh(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),Gh(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)})})();lg.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 wg(e,t){return Lh(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||Lh(t.retryOnMount,e)!==!1)}function Tg(e,t){return wg(e,t)||e.state.data!==void 0&&Eg(e,t,t.refetchOnMount)}function Eg(e,t,n){if(Lh(t.enabled,e)!==!1&&Lh(t.staleTime,e)!==`static`){let r=Lh(n,e);return r===`always`||r!==!1&&Og(e,t)}return!1}function Dg(e,t,n,r){return(e!==t||Lh(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&Og(e,n)}function Og(e,t){return Lh(t.enabled,e)!==!1&&e.isStaleByTime(Lh(t.staleTime,e))}var kg=class extends hg{#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||Ag(),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=mg({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),lg.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function Ag(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var jg=class extends ag{#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 kg({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=Mg(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=Mg(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=Mg(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=Mg(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){lg.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=>zh(t,e))}findAll(e={}){return this.getAll().filter(t=>zh(e,t))}notify(e){lg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return lg.batch(()=>Promise.all(e.map(e=>e.continue().catch(Nh))))}};function Mg(e){return e.options.scope?.id}var Ng=class extends ag{#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),Gh(this.options,t)||this.#e.getMutationCache().notify({type:`observerOptionsUpdated`,mutation:this.#n,observer:this}),t?.mutationKey&&this.options.mutationKey&&Vh(t.mutationKey)!==Vh(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??Ag();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){lg.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)})})}},Pg=class extends ag{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??Bh(r,t),a=this.get(i);return a||(a=new yg({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(){lg.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=>Rh(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>Rh(e,t)):t}notify(e){lg.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){lg.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){lg.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},Fg=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new Pg,this.#t=e.mutationCache||new jg,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=og.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=ug.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(Lh(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=Ph(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return lg.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;lg.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return lg.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=lg.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(Nh).catch(Nh)}invalidateQueries(e,t={}){return lg.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=lg.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(Nh)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(Nh)}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(Lh(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(Lh(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Nh).catch(Nh)}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(Nh).catch(Nh)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return ug.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(Vh(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Hh(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Vh(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Hh(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||=Bh(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===$h&&(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()}},Ig=Y.createContext(!1),Lg=()=>Y.useContext(Ig);Ig.Provider;function Rg(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var zg=Y.createContext(Rg()),Bg=()=>Y.useContext(zg),Vg=(e,t,n)=>{let r=n?.state.status===`error`&&typeof e.throwOnError==`function`?tg(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},Hg=e=>{Y.useEffect(()=>{e.clearReset()},[e])},Ug=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||tg(n,[e.error,r])),Wg=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))}},Gg=(e,t)=>e?.suspense&&t.isPending,Kg=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function qg(e,t,n){let r=Lg(),i=Bg(),a=Dh(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,Wg(o),Vg(o,i,s),Hg(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(lg.batchCalls(e)):Nh;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),Y.useEffect(()=>{l.setOptions(o)},[o,l]),Gg(o,u))throw Kg(o,l,i);if(Ug({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Jg(e,t){return qg(e,Cg,t)}function Yg(e,t){let n=Dh(t),[r]=Y.useState(()=>new Ng(n,e));Y.useEffect(()=>{r.setOptions(e)},[r,e]);let i=Y.useSyncExternalStore(Y.useCallback(e=>r.subscribe(lg.batchCalls(e)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),a=Y.useCallback((...e)=>{r.mutate(e[0],e[1]).catch(Nh)},[r]);if(i.error&&tg(r.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:a,mutateAsync:i.mutate}}var Xg={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`]},Zg=[],Qg=[],$g=e=>e instanceof Ce&&[401,403,404].includes(e.status);function e_(){return new Fg({defaultOptions:{queries:{staleTime:3e4,gcTime:3e5,retry:(e,t)=>!$g(t)&&e<2&&(!(t instanceof Ce)||t.status===0||t.status>=500||t.code===`INVALID_RESPONSE`),retryDelay:e=>Math.min(500*2**e,2e3),refetchOnReconnect:`always`},mutations:{retry:!1}}})}var t_=new WeakMap;function n_(e){let t=t_.get(e);return t||(t={next:0,summaries:new Map},t_.set(e,t)),++t.next}function r_(e,t,n,r){let i=t_.get(e);!n||!i||r<(i.summaries.get(t)??0)||(i.summaries.set(t,r),e.setQueryData(Xg.summary(t),n))}function i_(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 a_(e,t,n){await Promise.all([e.cancelQueries({queryKey:Xg.lists(t)}),e.cancelQueries({queryKey:Xg.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:Xg.lists(t)},e=>{if(!e)return e;let t=e.comments;return r.kind===`created`?e:{...e,comments:i_(t,r),summary:n.summary}}),r.kind===`created`)for(let a of[Xg.file(t,i),Xg.all(t)])e.setQueryData(a,e=>e&&{...e,comments:i_(e.comments,r),summary:n.summary});r_(e,t,n.summary,n_(e)),e.setQueryData(Xg.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 o_(e,t){await Promise.all([Xg.lists(t),Xg.mentions(t)].map(async t=>{await e.cancelQueries({queryKey:t}),await e.invalidateQueries({queryKey:t})}))}function s_(e,t,n,r,i){let a=Dh(),o=async(t,n)=>{let r=n_(a),i=await W(t,{signal:n});return n.aborted||r_(a,e,i.summary,r),i},s=Jg({queryKey:Xg.file(e,t),enabled:!!t,queryFn:({signal:n})=>o(`/api/projects/${e}/comments?path=${encodeURIComponent(t)}`,n)}),c=Jg({queryKey:Xg.all(e),enabled:n===`project`,queryFn:({signal:t})=>o(`/api/projects/${e}/comments?scope=project`,t)}),l=Jg({queryKey:Xg.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:Xg.all(e):Xg.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?U(s.error):``;return{comments:$g(s.error)?Zg:s.data?.comments??Zg,commentsFilePath:t&&(s.data||s.error)?t:``,commentsReady:!(!t||!s.data||s.isFetching||s.error),fileCommentsLoading:!!(t&&s.isFetching),fileCommentsError:f,reviewComments:$g(d.error)?Zg:d.data?.comments??Zg,reviewCommentsLoading:!(n!==`project`&&!t||!d.isFetching),reviewCommentsError:d.error?U(d.error):``,projectCommentSummary:$g(s.error)||$g(c.error)?null:l.data??null,refreshComments:()=>o_(a,e)}}function c_(e){let t=Dh(),n=Yg({retry:!1,mutationFn:async({id:e,path:n,options:r})=>{let i=await W(`/api/projects/${e}/comments${n}`,r);return await a_(t,e,i),o_(t,e),i}});return(t,r)=>n.mutateAsync({id:e,path:t,options:r})}function l_({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 Th,[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=s_(e,t,p,i,a),g=c_(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),P=(0,Y.useRef)(l),F=(0,Y.useRef)(u),ne=(0,Y.useRef)(C),re=(0,Y.useRef)(x);ne.current=C,re.current=x,ee.current=t,te.current=s,P.current=l,F.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 ie=(e,r)=>{if(!t)return;M(``);let i={filePath:t,selection:{...e??o},sourceHash:Hd(r??n)},a=d.getNew(t);w(a??i),S(a?.content??``),E(i),O(!!a),b(!0)},ae=e=>{S(e),C&&(e?d.setNew({...C,content:e}):d.discardNew(C.filePath))},oe=()=>{N.current||(b(!1),M(``))},I=()=>{N.current||(C&&d.discardNew(C.filePath),S(``),w(null),E(null),O(!1),oe())},se=()=>{!N.current&&T&&T.filePath===ee.current&&(w(T),x&&d.setNew({...T,content:x}),O(!1),M(``))},ce=async()=>{let e=C,t=x;if(!x.trim()||!e||N.current)return;let n=()=>{let n=ne.current;return n?.filePath===e.filePath&&n.sourceHash===e.sourceHash&&n.selection.startOffset===e.selection.startOffset&&n.selection.endOffset===e.selection.endOffset&&re.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)),F.current()}catch(e){n()&&M(U(e))}finally{N.current=!1,A(!1)}},L=async e=>{try{await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({resolved:!e.resolved})})}catch(e){f.active&&P.current(U(e))}},R=async(e,t)=>(await g(`/${e.id}/replies`,{method:`POST`,body:JSON.stringify({content:t})}),!0),z=async(e,t)=>(await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({content:t})}),!0),B=async e=>(await g(`/${e.id}`,{method:`DELETE`}),f.active&&(v(t=>t?.id===e.id?null:t),d.discard(e.id)),!0),le=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:ie,closeComment:oe,cancelComment:I,commentDraftRestored:D,commentDraftCanRetarget:!(!C||!T||C.sourceHash===T.sourceHash&&C.selection.startOffset===T.selection.startOffset&&C.selection.endOffset===T.selection.endOffset),useCurrentCommentSelection:se,commentText:x,setCommentText:ae,commentSelection:C?.selection??o,commentSubmitting:k,commentError:j,addComment:ce,toggleComment:L,replyToComment:R,editComment:z,deleteComment:B,editCommentReply:le,deleteCommentReply:V}}function u_(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 d_(e,t){let n=t.participantIds;return!n?.size||n.has(e.authorId)||!t.topLevelOnly&&e.replies.some(e=>n.has(e.authorId))}function f_(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 p_(e,t){return t.scope===`project`||e.filePath===t.activeFile}function m_(e,t){return t===`unresolved`?!e.resolved:e.resolved}function h_(e,t){return t.some(t=>t.commentId===e.id&&t.readAt===null)}function g_(e,t){return e.filter(e=>p_(e,t)&&d_(e,t)&&m_(e,t.filter)&&(!t.unreadMentionsOnly||h_(e,t.unreadMentions)))}function __(e,t,n=[]){let r=new Set(n.filter(e=>!!e));return f_(e.filter(e=>p_(e,t)?r.has(e.id)||d_(e,t)&&m_(e,t.filter)&&(!t.unreadMentionsOnly||h_(e,t.unreadMentions)):!1),t.sort)}function v_(e,t,n){let r=e.find(e=>e.id===t&&e.filePath===n&&!e.resolved);return r?[r]:[]}function y_(e,t){return e.filter(e=>e.filePath===t)}function b_(e,t,n){return!e||e.filePath!==t||n!==t?null:e}function x_(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 S_(e,t){if(!t)return 0;let n=e.findIndex(e=>e.id===t);return n<0?0:n+1}function C_(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 w_(e,t,n,r){let i=Dh(),a=Xg.mentions(e),o=Jg({queryKey:a,queryFn:({signal:t})=>W(`/api/projects/${e}/mentions?unread=1&limit=100`,{signal:t})}),s=$g(o.error)?Qg:o.data?.mentions??Qg,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(U(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 W(`/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(U(e)),!1}finally{l.pending.delete(n)}})();return l.pending.set(n,o),o};return{unreadMentions:s,mentionsError:o.error?U(o.error):``,refresh:d,markMentionRead:e=>f(e),markAllMentionsRead:()=>f()}}function T_({children:e}){let[t]=(0,Y.useState)(e_);return(0,X.jsx)(Oh,{client:t,children:e})}function E_(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 D_(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`);E_(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 O_=new Map,k_=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:oa(t.newValue||``)}),Si(this._onChange)}postMessage(e){xi.setItem(this.room,aa(ea(e)))}close(){Ci(this._onChange)}},A_=typeof BroadcastChannel>`u`?k_:BroadcastChannel,j_=e=>Vn(O_,e,()=>{let t=Wn(),n=new A_(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),M_=(e,t)=>(j_(e).subs.add(t),t),N_=(e,t)=>{let n=j_(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),O_.delete(e)),r},P_=(e,t,n=null)=>{let r=j_(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},F_=(e,t)=>{Z(e,0),Mr(e,Us(t))},I_=(e,t,n)=>{Z(e,1),Mr(e,Ls(t,n))},L_=(e,t,n)=>I_(t,n,ti(e)),R_=(e,t,n,r)=>{try{Ps(t,ti(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},z_=(e,t)=>{Z(e,2),Mr(e,t)},B_=R_,V_=(e,t,n,r,i)=>{let a=Q(e);switch(a){case 0:L_(e,t,n);break;case 1:R_(e,n,r,i);break;case 2:B_(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},H_=(e,t,n)=>{Q(e)===0&&n(t,ii(e))},U_=3e4,W_=class extends $n{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=gi();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&&G_(this,t,`timeout`)},er(U_/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:gi()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Bi(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}},G_=(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:gi()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},K_=(e,t,n=e.states)=>{let r=t.length,i=xr();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),Ar(i,JSON.stringify(o))}return Cr(i)},q_=(e,t,n)=>{let r=Qr(t),i=gi(),a=[],o=[],s=[],c=[],l=Q(r);for(let t=0;t<l;t++){let t=Q(r),n=Q(r),l=JSON.parse(ii(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&&(Bi(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])},J_=e=>Ai(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`),Y_=[];Y_[0]=(e,t,n,r,i)=>{Z(e,0);let a=V_(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},Y_[3]=(e,t,n,r,i)=>{Z(e,1),Mr(e,K_(n.awareness,Array.from(n.awareness.getStates().keys())))},Y_[1]=(e,t,n,r,i)=>{q_(n.awareness,ti(t),n)},Y_[2]=(e,t,n,r,i)=>{H_(t,n.doc,(e,t)=>Z_(n,t))};var X_=3e4,Z_=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),Q_=(e,t,n)=>{let r=Qr(t),i=xr(),a=Q(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},$_=(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,G_(e.awareness,Array.from(e.awareness.getStates().keys()).filter(t=>t!==e.doc.clientID),e),e.emit(`status`,[{status:`disconnected`}])):e.wsUnsuccessfulReconnects++,setTimeout(ev,nr(ir(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},ev=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=gi();let r=Q_(e,new Uint8Array(n.data),!0);Sr(r)>1&&t.send(Cr(r))},t.onerror=t=>{e.emit(`connection-error`,[t,e])},t.onclose=n=>{$_(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=gi(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit(`status`,[{status:`connected`}]);let n=xr();if(Z(n,0),F_(n,e.doc),t.send(Cr(n)),e.awareness.getLocalState()!==null){let n=xr();Z(n,1),Mr(n,K_(e.awareness,[e.doc.clientID])),t.send(Cr(n))}},e.emit(`status`,[{status:`connecting`}])}},tv=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&P_(e.bcChannel,t,e)},nv=class extends Qn{constructor(e,t,n,{connect:r=!0,awareness:i=new W_(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=Y_.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=xr();Z(e,0),F_(e,n),this.ws.send(Cr(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=Q_(this,new Uint8Array(e),!1);Sr(t)>1&&P_(this.bcChannel,Cr(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=xr();Z(t,0),z_(t,e),tv(this,Cr(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=xr();Z(o,1),Mr(o,K_(i,a)),tv(this,Cr(o))},this._exitHandler=()=>{G_(this.awareness,[n.clientID],`app closed`)},Hi&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&X_<gi()-this.wsLastMessageReceived&&$_(this,this.ws,null)},X_/10),r&&this.connect()}get url(){let e=J_(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(),Hi&&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||=(M_(this.bcChannel,this._bcSubscriber),!0);let e=xr();Z(e,0),F_(e,this.doc),P_(this.bcChannel,Cr(e),this);let t=xr();Z(t,0),I_(t,this.doc),P_(this.bcChannel,Cr(t),this);let n=xr();Z(n,3),P_(this.bcChannel,Cr(n),this);let r=xr();Z(r,1),Mr(r,K_(this.awareness,[this.doc.clientID])),P_(this.bcChannel,Cr(r),this)}disconnectBc(){let e=xr();Z(e,1),Mr(e,K_(this.awareness,[this.doc.clientID],new Map)),tv(this,Cr(e)),this.bcconnected&&=(N_(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&$_(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(ev(this),this.connectBc())}},rv=e=>_i((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),iv=(e,t)=>_i((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(Kr(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),av=e=>rv(indexedDB.deleteDatabase(e)),ov=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),sv=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>vv(r,e))},cv=(e,t)=>rv(e.count(t)),lv=(e,t)=>rv(e.get(t)),uv=(e,t)=>rv(e.delete(t)),dv=(e,t,n)=>rv(e.put(t,n)),fv=(e,t)=>rv(e.add(t)),pv=(e,t,n)=>rv(e.getAll(t,n)),mv=(e,t,n)=>{let r=null;return _v(e,t,e=>(r=e,!1),n).then(()=>r)},hv=(e,t=null)=>mv(e,t,`prev`),gv=(e,t)=>_i((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()}}),_v=(e,t,n,r=`next`)=>gv(e.openKeyCursor(t,r),e=>n(e.key)),vv=(e,t)=>e.objectStore(t),yv=(e,t)=>IDBKeyRange.upperBound(e,t),bv=(e,t)=>IDBKeyRange.lowerBound(e,t),xv=`custom`,Sv=`updates`,Cv=(e,t=()=>{},n=()=>{})=>{let[r]=sv(e.db,[Sv]);return pv(r,bv(e._dbref,!1)).then(i=>{e._destroyed||(t(r),Ac(e.doc,()=>{i.forEach(t=>Ps(e.doc,t))},e,!1),n(r))}).then(()=>hv(r).then(t=>{e._dbref=t+1})).then(()=>cv(r).then(t=>{e._dbsize=t})).then(()=>r)},wv=(e,t=!0)=>Cv(e).then(n=>{(t||e._dbsize>=500)&&fv(n,Ls(e.doc)).then(()=>uv(n,yv(e._dbref,!0))).then(()=>cv(n).then(t=>{e._dbsize=t}))}),Tv=class extends $n{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=iv(e,e=>ov(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=_i(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,Cv(this,e=>fv(e,Ls(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]=sv(this.db,[Sv]);fv(t,e),++this._dbsize>=500&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{wv(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(()=>{av(this.name)})}get(e){return this._db.then(t=>{let[n]=sv(t,[xv],`readonly`);return lv(n,e)})}set(e,t){return this._db.then(n=>{let[r]=sv(n,[xv]);return dv(r,t,e)})}del(e){return this._db.then(t=>{let[n]=sv(t,[xv]);return uv(n,e)})}},Ev={Sync:0,Awareness:1,QueryAwareness:3,Flush:4,Protocol:5,Maintenance:6,Permission:7,CompileStates:8,FormatLease:9},Dv=[`queued`,`running`,`succeeded`,`failed`,`cleaned`],Ov=[`cache`,`artifacts`];function kv(e){return typeof e==`string`&&Dv.includes(e)}function Av(e){return typeof e==`string`&&Ov.includes(e)}var jv=[[`#1677c8`,`#1677c833`],[`#d65745`,`#d6574533`],[`#16866a`,`#16866a33`],[`#9a58b5`,`#9a58b533`],[`#d27b18`,`#d27b1833`],[`#3f7d20`,`#3f7d2033`],[`#be3e7b`,`#be3e7b33`],[`#4964c6`,`#4964c633`],[`#8a6a14`,`#8a6a1433`],[`#087f8c`,`#087f8c33`]],{Sync:Mv,Awareness:Nv,Flush:Pv,Protocol:Fv,Maintenance:Iv,Permission:Lv,CompileStates:Rv,FormatLease:zv}=Ev,Bv=6e4,Vv=2592e6,Hv=15e3,Uv=3e5;function Wv(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.requestedBy;return typeof t.mainFile!=`string`||typeof t.runId!=`string`||!kv(t.status)||t.status===`cleaned`&&!Av(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 Gv(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){let e=Wv(r);e&&e.mainFile===n&&(t[n]=e)}return t}function Kv(e,t,n){return e<=n&&t<=n}function qv(e,t,n){let r=e=>e>0&&n-e<=Uv;return{recoverable:e.some(e=>e.tabId===t||!r(e.activeAt)),otherActive:e.some(e=>e.tabId!==t&&r(e.activeAt))}}var Jv=class{projectId;user;doc=new vs;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=ty(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 Tv(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 nv(`${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[Pv]=(e,t)=>{let n=ii(t),r=this.flushRequests.get(n);if(!r)return;let i=Q(t)===1,a=Q(t),o=ii(t),s=Q(t),c=[];for(let e=0;e<s;e++)c.push(ii(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[Fv]=(e,t)=>{let n=ii(t),r=this.epochStorageKey(),i=Yv(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=()=>{Xv(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,Xv(r,n);let c=this.provider.ws;if(!c||c.readyState!==WebSocket.OPEN)return;let l=xr();Z(l,Fv),Ar(l,n),Z(l,3),c.send(Cr(l));let u=xr();Z(u,Mv),F_(u,this.doc),c.send(Cr(u));let d=xr();Z(d,Nv),Mr(d,K_(this.awareness,[this.doc.clientID])),c.send(Cr(d))},this.provider.messageHandlers[Lv]=(e,t)=>{let n=ii(t),r=ii(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[Iv]=(e,t)=>{ii(t)},this.provider.messageHandlers[Rv]=(e,t)=>{let n={};try{n=Gv(JSON.parse(ii(t)))}catch{}this.authoritativeCompileStates=n,this.notifyCompileStateListeners()},this.provider.messageHandlers[zv]=(e,t)=>{let n=ii(t),r=ii(t),i=ii(t),a=ii(t),o=ii(t),s=ii(t);if(n===`state`){let e=$r(t)?ii(t):``,n=$r(t)?ii(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 Pc(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??Gv(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 qv(this.readWritableDraftMarkers().map(({tabId:e,marker:t})=>({tabId:e,activeAt:t.activeAt})),this.draftTabId,Date.now()).recoverable}get hasOtherWritableDraft(){return qv(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:V(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=Gd(),n=this.draftGeneration,r=xr();return Z(r,Pv),Ar(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(Cr(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=Gd(),a=xr();return Z(a,zv),Ar(a,e),Ar(a,i),Ar(a,t),Ar(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=xr();Z(n,zv),Ar(n,`cancel`),Ar(n,i),Ar(n,t),Ar(n,``),e.send(Cr(n))}}o(Error(`Format lease request timed out`))},e===`acquire`?Bv:5e3);this.formatLeaseRequests.set(i,{resolve:n,reject:o,timer:s}),r.send(Cr(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]=jv[Math.abs(this.doc.clientID)%jv.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:V(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())Zv(e);this.draftMarkerPresent=!1,this.stopDraftHeartbeat(),Zv(this.writableDraftStoragePrefix().slice(0,-1))}clearOwnWritableDraftMarker(e){let t=this.readOwnWritableDraftMarker();t&&Kv(t.generation,this.draftGeneration,e)&&(Zv(this.ownWritableDraftStorageKey()),this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}readOwnWritableDraftMarker(){return this.readWritableDraftMarker(this.ownWritableDraftStorageKey())}readWritableDraftMarkers(){let e=this.writableDraftStoragePrefix(),t=[];for(let n of Qv()){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=Yv(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>Vv)return Zv(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 Zv(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};Xv(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)},Hv))}stopDraftHeartbeat(){this.draftHeartbeatTimer!==null&&(window.clearInterval(this.draftHeartbeatTimer),this.draftHeartbeatTimer=null)}};function Yv(e){try{return window.localStorage.getItem(e)}catch{return null}}function Xv(e,t){try{window.localStorage.setItem(e,t)}catch{}}function Zv(e){try{window.localStorage.removeItem(e)}catch{}}function Qv(){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 $v(e){try{return window.sessionStorage.getItem(e)}catch{return null}}function ey(e,t){try{window.sessionStorage.setItem(e,t)}catch{}}function ty(e){let t=$v(e);if(t)return t;let n=Gd();return ey(e,n),n}function ny({projectId:e,user:t,children:n}){let{t:r}=Ee(),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 Jv(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 ry=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)}}},iy=(e,t)=>`${e}\0${t}`,ay=e=>e instanceof Error&&e.name===`AbortError`;function oy(e,t){e.current&&(!t||e.current.owner===t)&&(e.current.controller.abort(),e.current=null)}function sy(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof Element&&!!e.closest(`[role="dialog"], [role="alertdialog"], [data-agent-terminal]`)}function cy(e){let{projectId:t,project:n,mainFile:r,initialLatest:i,collaborationSynced:a,pdfVisible:o,sharedState:s}=e,{t:c}=Ee(),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 ry({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),P=(0,Y.useRef)(null),F=(0,Y.useRef)(null),ne=(0,Y.useRef)(null),re=(0,Y.useRef)(new Map),ie=(0,Y.useRef)(new Map),ae=(0,Y.useRef)(new Set),oe=(0,Y.useRef)({projectId:t,promise:i});oe.current.projectId!==t&&(oe.current={projectId:t,promise:i});let I=(0,Y.useRef)(null),se=(0,Y.useRef)(null),ce=(0,Y.useRef)(()=>void 0),L=()=>l.current.getCurrentMainFile?.()||d.current.selection.mainFile,R=(e,t)=>u.current&&!t?.aborted&&d.current===e&&L()===e.selection.mainFile,z=iy(t,r),B=m.selection===p.selection,le=O.has(z),V=E===p,ue=e=>{for(let t of[ee,te,P,F])oy(t,e);for(let t of ae.current)t.owner===e&&(t.controller.abort(),ae.current.delete(t));_(t=>t?.owner===e?null:t),y(t=>t?.owner===e?null:t),T(!1)},de=()=>{se.current=null,I.current=null,x([]),C(null),T(!1),N(``),l.current.onPdfChanged()},fe=async(e,t)=>{if(!R(e))return;let n=t??{owner:e,controller:new AbortController};t||(oy(P),P.current=n);let r=e.snapshot.pdf?.url,i=()=>R(e,n.controller.signal)&&e.snapshot.pdf?.url===r;try{let t=await W(`/api/projects/${e.selection.projectId}/compile/artifacts?mainFile=${encodeURIComponent(e.selection.mainFile)}`,{signal:n.controller.signal});i()&&(x(t.artifacts),C(null))}catch(e){!ay(e)&&i()&&(x([]),C(null))}finally{P.current===n&&(P.current=null)}},pe=()=>{let e=se.current;e&&(se.current=null,R(e.owner)&&e.owner.snapshot.pdf?.url===e.url&&fe(e.owner))},me=e=>{let t=e.snapshot.pdf?.url;t&&(se.current={owner:e,url:t},(!l.current.pdfVisible||I.current?.owner===e&&I.current.url===t)&&pe())},he=e=>{R(p)&&p.snapshot.pdf?.url===e&&(I.current={owner:p,url:e},se.current?.owner===p&&se.current.url===e&&pe())},H=(e,t)=>!t||!R(e)?!1:(h(t.snapshot),t.pdfChanged&&l.current.onPdfChanged(),t.focusPdf&&l.current.onCompileSuccess(),!0),ge=(e,t)=>{ue(e),se.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,P,F,ne])oy(e);for(let e of[...ae.current,...ie.current.values(),...re.current.values()])e.controller.abort();ae.current.clear(),ie.current.clear(),re.current.clear()}),[]),(0,Y.useEffect)(()=>{o||pe()},[o]),(0,Y.useEffect)(()=>{h(p.snapshot),de();for(let e of[ie.current,re.current])for(let[n,r]of e)r.owner.selection.projectId!==t&&(r.controller.abort(),e.delete(n));let e=iy(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),ne.current?.owner!==p&&oy(ne),!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,W(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:i.controller.signal})),c=oe.current.promise;return oe.current.promise=null,(c?c.then(e=>R(p,i.controller.signal)?e.mainFile===r?e:s():null,()=>R(p,i.controller.signal)?s():null):s()).then(e=>{if(e&&R(p,i.controller.signal)&&H(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=>!R(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=>{!ay(e)&&R(p,i.controller.signal)&&l.current.onError(U(e))}).finally(()=>{ee.current===i&&(ee.current=null),_(e=>e===i?null:e),R(p,i.controller.signal)&&(ae.current.add(i),a=window.setTimeout(()=>{R(p,i.controller.signal)?Promise.all([fe(p,i),l.current.loadOutline(i.controller.signal,r).catch(()=>void 0)]).finally(()=>ae.current.delete(i)):ae.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&&ge(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(z))return e;let t=new Set(e);return t.delete(z),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||ne.current?.owner===p||V||le||!p.sharedCompletionAllowed||p.hasRun(s.runId))return;let e={owner:p,controller:new AbortController};return oy(te),oy(F),T(!1),te.current=e,y(e),W(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:e.controller.signal}).then(t=>{R(p,e.controller.signal)&&t.latestRun?.id===s.runId&&H(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=>{!ay(t)&&R(p,e.controller.signal)&&l.current.onError(U(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,le,g,V]);let _e=async()=>{if(!n||n.permission===`read`||!a)return;let e=l.current.resolveCompileMainFile?.()||L(),r=iy(t,e),i=l.current.sharedState;if(!e||ie.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 ry({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};ie.current.set(r,s),k(e=>new Set([...e,r]));try{if(!await l.current.save()||!R(o,s.controller.signal))return;o.beginCompile(),h(o.snapshot);let n=await W(`/api/projects/${t}/compile`,{method:`POST`,signal:s.controller.signal,body:JSON.stringify({mainFile:e})});if(!R(o,s.controller.signal)||!H(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){!ay(e)&&R(o,s.controller.signal)&&l.current.onError(U(e))}finally{ie.current.get(r)===s&&(ie.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}))}},G=async()=>{if(!n||n.permission===`read`||!a||!R(p))return;let e=iy(t,r);if(!r||re.current.has(e))return;let i={owner:p,controller:new AbortController};re.current.set(e,i),j(t=>new Set([...t,e]));try{!(await W(`/api/projects/${t}/compile/cancel`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r})})).cancelled&&R(p,i.controller.signal)&&j(t=>{let n=new Set(t);return n.delete(e),n})}catch(t){R(p,i.controller.signal)&&(j(t=>{let n=new Set(t);return n.delete(e),n}),ay(t)||l.current.onError(U(t)))}finally{re.current.get(e)===i&&re.current.delete(e)}},ve=async e=>{if(!n||n.permission===`read`||!a||!R(p)||!r||ne.current||ie.current.has(z)||s?.mainFile===r&&(s.status===`queued`||s.status===`running`))return;let i={owner:p,controller:new AbortController},o=l.current.sharedState;ne.current=i,D(p),ue(p);try{let n=await W(`/api/projects/${t}/compile/clean`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r,mode:e})});if(!R(p,i.controller.signal)||n.mainFile!==r)return;l.current.sharedState===o&&l.current.onSharedState(null),ge(p,e)}catch(e){!ay(e)&&R(p,i.controller.signal)&&l.current.onError(U(e))}finally{ne.current===i&&(ne.current=null),D(e=>e===p?null:e)}},ye=async e=>{if(!e.viewable||!R(p))return;oy(F);let n={owner:p,controller:new AbortController},i=p.snapshot.pdf?.url;F.current=n,T(!0);try{let a=await W(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(r)}&path=${encodeURIComponent(e.path)}`,{signal:n.controller.signal});R(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&C(a)}catch(e){!ay(e)&&R(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&l.current.onError(U(e))}finally{F.current===n&&(F.current=null,T(!1))}};ce.current=()=>void _e(),(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(),!sy(e.target)&&(e.stopPropagation(),e.repeat||ce.current()))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let K=B?m:null;return{pdfUrl:K?.pdf?.url??``,pdfCompiledAt:K?.pdf?.compiledAt??null,pdfSizeBytes:K?.pdf?.sizeBytes??null,pdfLoadingMode:K?.pdf?.loadingMode??`full`,pdfLoading:g?.owner===p&&!g.controller.signal.aborted||v?.owner===p&&!v.controller.signal.aborted,compileLog:K?.run?.log??``,compileDiagnostics:K?.run?.diagnostics??null,compileOutcome:K?.run?.outcome??null,artifacts:B?b:[],artifactPreview:B?S:null,artifactLoading:B&&w,editorNotice:B?M:``,localCompiling:le,cancelling:A.has(z),cleaning:V,pdfDisplayed:he,compile:_e,cancelCompile:G,cleanCompile:ve,viewArtifact:ye}}var ly=10485760;function uy(e){return e instanceof Error&&e.name===`AbortError`}function dy(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.map((e,n)=>t.slice(0,n+1).join(`/`))}function fy(e,t){return!!(e&&t)&&(t===e||t.startsWith(`${e}/`))}function py(e,t){let n=Sn(e);return n===`binary`||n===`other`||n===`text`&&t===!1?`unsupported`:n}function my(e,t){let n=py(e.path,e.textContent);return n===`unsupported`?n:(e.size??0)>10485760||n===`text`&&(e.size??0)>t?`large`:n===`text`?`editor`:n}function hy(e,t){return d(`/api/projects/${e}/file/raw?path=${encodeURIComponent(t)}`)}function gy({projectId:e,site:t,activeFile:n,dirty:r,save:i,onError:a,onProject:o,onActiveFile:s,onActiveMainFile:c}){let{t:l}=Ee(),[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)(``),[P,F]=(0,Y.useState)(``),[ne,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)(!1),[oe,I]=(0,Y.useState)(null),[se,ce]=(0,Y.useState)(!1),[L,R]=(0,Y.useState)(null),z=(0,Y.useRef)(!1),B=(0,Y.useRef)(null),le=(0,Y.useRef)(null),V=(0,Y.useRef)(null),ue=async(t={})=>{le.current?.abort(),le.current=null;let n=t.signal?null:new AbortController;n&&(le.current=n);try{let r=await W(`/api/projects/${e}/files`,{signal:t.signal??n?.signal});return(!t.isCurrent||t.isCurrent())&&d(r.files),r.files}catch(e){if(!uy(e))throw e;return}finally{n&&le.current===n&&(le.current=null)}},de=async()=>{if(m.trim()&&!m.trim().endsWith(`/`)){T(``);try{await W(`/api/projects/${e}/file`,{method:`POST`,body:JSON.stringify({path:m,content:``})});let t=(await ue())?.find(e=>e.path===m);t&&await ge(t),D(null),j(e=>new Set([...e,...dy(m)])),p(!1),h(``)}catch(e){T(U(e))}}},fe=async()=>{if(!S.trim())return;T(``);let t=E?`${E}/${S.trim()}`:S.trim();try{let n=await W(`/api/projects/${e}/folders`,{method:`POST`,body:JSON.stringify({path:t})});await ue(),j(e=>new Set([...e,...dy(n.path),n.path])),D(n.path),x(!1),C(``)}catch(e){T(U(e))}},pe=async(n,r=new Set,i=E)=>{if(!n.length||z.current)return;let a=t.maxUploadSizeMB;if(n.find(e=>e.size>a*1024*1024)){R({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){R({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){R(null),I({files:n,directory:o,collisions:p});return}I(null),B.current!==null&&window.clearTimeout(B.current),B.current=null,R(null),z.current=!0,ce(!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{R({kind:`uploading`,fileName:c.name,current:t+1,total:n.length});let r=await W(`/api/projects/${e}/upload${u}`,{method:`POST`,body:d});m+=1,typeof r.path==`string`&&Cn(r.path)&&(a=r.path)}catch(e){if(e instanceof Ce&&e.status===409&&!r.has(l)&&e.code===`FILE_EXISTS`){if(R(null),t>0)try{await ue()}catch{}I({files:n.slice(t),directory:o,collisions:[l]});return}throw e}}let c;try{c=(await ue())?.find(e=>e.path===a&&Cn(e.path,e.textContent)&&(e.size??0)<=t.maxCollaborativeFileSizeMB*1024*1024)}catch(e){R({kind:`error`,message:l(`editor.uploadSucceededRefreshFailed`,{message:U(e)})});return}c&&await ge(c),R({kind:`success`,count:m}),B.current=window.setTimeout(()=>{R(e=>e?.kind===`success`?null:e),B.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:U(e)}):l(`editor.uploadFailed`,{message:U(e)});R({kind:`error`,message:t})}finally{z.current=!1,ce(!1)}},me=()=>{B.current!==null&&window.clearTimeout(B.current),B.current=null,R(null)},he=async e=>{await pe(Array.from(e.target.files??[])),e.target.value=``},H=async n=>{V.current?.abort(),V.current=null,y(!1);let r=hy(e,n.path);if(my(n,t.maxCollaborativeFileSizeMB*1024*1024)===`large`){let e=Cn(n.path,n.textContent)?Math.min(ly,t.maxCollaborativeFileSizeMB*1024*1024):ly;_({path:n.path,kind:`large`,size:n.size??0,url:r,limitBytes:e});return}let i=py(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 De(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 Ce(be(n,e.status),e.status,_e(n))}let i=new Uint8Array(await e.arrayBuffer());if(!wn(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){uy(e)||(_(null),a(U(e)))}finally{V.current===o&&(V.current=null,y(!1))}},ge=async n=>{if(V.current?.abort(),V.current=null,y(!1),D(null),k(n.path),my(n,t.maxCollaborativeFileSizeMB*1024*1024)!==`editor`){await H(n);return}let r=new AbortController;V.current=r;try{if(await W(`/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||uy(t))return;t instanceof Ce&&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:hy(e,n.path)})):a(U(t))}finally{V.current===r&&(V.current=null)}},G=async(t,n,r)=>{if(!await i())return null;let a=await W(`/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([W(`/api/projects/${e}/files`),W(`/api/projects/${e}`)]);return d(u.files),o(f.project),j(e=>new Set([...e,...dy(a.path),n].filter(Boolean))),a.path};return(0,Y.useEffect)(()=>()=>{le.current?.abort(),V.current?.abort(),B.current!==null&&window.clearTimeout(B.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:P,setMoveDestination:F,deleteEntry:ne,setDeleteEntry:re,fileDragActive:ie,setFileDragActive:ae,uploadConflict:oe,setUploadConflict:I,uploadingFiles:se,uploadFeedback:L,dismissUploadFeedback:me,directoryEntries:u.filter(e=>e.type===`directory`),visibleEntries:u.filter(e=>dy(e.path).every(e=>A.has(e))),createFile:de,createFolder:fe,uploadFiles:pe,upload:he,openFile:ge,movePath:async()=>{if(!M)return;let e=ee.trim();if(e){T(``);try{if(!await G(M,P,e))return;N(null),te(``),F(``)}catch(e){T(U(e))}}},movePathToFolder:async(e,t)=>{if(_y(e.path)!==t&&(e.type!==`directory`||t!==e.path&&!t.startsWith(`${e.path}/`)))try{await G(e,t,e.path.split(`/`).at(-1)??e.path)}catch(e){a(U(e))}},removePath:async()=>{if(ne){T(``);try{if(r&&!await i())return;await W(`/api/projects/${e}/file?path=${encodeURIComponent(ne.path)}`,{method:`DELETE`}),re(null)}catch(e){T(U(e))}}}}}function _y(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function vy({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-DEQIFH7w.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 yy({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-B2-niLAo.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 by(e){return e instanceof Error&&e.name===`AbortError`}function xy(e,t){return/\.tex$/i.test(e)&&/\.tex$/i.test(t)}function Sy({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(!xy(n,t))return;p.current?.abort();let o=new AbortController;p.current=o;try{let a=await W(`/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){!by(e)&&!a.silent&&_.current(U(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 W(`/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){by(e)||_.current(U(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 Cy(e,t){return u(`texlite.workspaceLayout:${encodeURIComponent(e)}:${encodeURIComponent(t)}`)}function wy(e,t){try{let n=window.localStorage.getItem(Cy(e,t));if(n===`editor-pdf`||n===`editor-only`||n===`pdf-only`)return n}catch{}return`editor-pdf`}function Ty(e,t){let[n,r]=(0,Y.useState)(()=>wy(e,t));return(0,Y.useEffect)(()=>{r(wy(e,t))},[e,t]),{workspaceLayout:n,setWorkspaceLayout:n=>{r(n);try{window.localStorage.setItem(Cy(e,t),n)}catch{}}}}function Ey(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 Dy(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&&Ey(JSON.parse(e),t)?e:null}catch{return null}},setItem(e,t){if(e===r)try{n().setItem(r,t)}catch{}}}}function Oy(e,t,n){let r=(0,Y.useMemo)(()=>[...e?[`files`,`source`]:[],...t?[`preview`]:[],...n?[`context`]:[]],[e,t,n]),i=u(`texlite-workspace-layout`);return Dm({id:i,panelIds:r,storage:(0,Y.useMemo)(()=>Dy(i,r),[i,r])})}function ky(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function Ay(e){let t=hd(gd(e));for(let e of t.matchAll(/\\documentclass(?![A-Za-z@])\s*(?:\[[^\]]*\]\s*)?\{/g))if(e.index!==void 0&&!ky(t,e.index))return!0;return!1}function jy({sessions:e,status:t}){let{t:n}=Ee(),[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)(P,{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 My({value:e,onChange:t}){let{t:n}=Ee(),[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),o=[{value:`editor-pdf`,icon:bt},{value:`editor-only`,icon:an},{value:`pdf-only`,icon:sn}];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)(bt,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`small`,{children:n(`editor.layout.label`)}),n(`editor.layout.${e}.name`)]}),(0,X.jsx)(M,{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)(pe,{size:16})]},r.value)})]})]})}function Ny({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:x,onGit:S,canManageGit:C,formatting:w,readOnly:T,collaborationSynced:E,onToggleComments:D,commentsOpen:O,unresolvedCommentCount:k,onToggleSettings:A,settingsOpen:M,compileBusy:N,sharedCompiling:ee,localCompiling:P,cancelling:F,onCompile:ne,onCancelCompile:re,agentTerminal:ie}){let{t:I}=Ee();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)(R,{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)(Se,{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)(Ht,{size:14}),I(`editor.vimOn`)]}),(0,X.jsx)(jy,{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)(nn,{size:15}):(0,X.jsx)(en,{size:15}),I(`common.files`)]}),(0,X.jsx)(My,{value:p,onChange:m}),(0,X.jsxs)(`button`,{onClick:g,children:[(0,X.jsx)(de,{size:15}),I(`projectSettings.share`)]}),_&&(0,X.jsxs)(`button`,{className:v?`active`:``,onClick:y,children:[(0,X.jsx)(b,{size:15}),I(`citationLibrary.title`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`snapshots-action`,title:I(`history.projectSnapshots`),onClick:x,children:[(0,X.jsx)(wt,{size:15}),I(`history.projectSnapshotsButton`)]}),(0,X.jsxs)(`button`,{type:`button`,className:`comments-action${O?` active`:``}`,title:I(`editor.commentsAll`),"aria-label":k>0?`${I(`common.comments`)} (${k})`:I(`common.comments`),onClick:D,children:[(0,X.jsx)(oe,{size:15}),(0,X.jsx)(`span`,{children:I(`common.comments`)}),k>0&&(0,X.jsx)(`sup`,{className:`comments-action-count`,children:k})]}),(0,X.jsxs)(`button`,{className:`git-action`,title:I(C?`git.title`:`git.ownerOnly`),disabled:!C,onClick:S,children:[(0,X.jsx)(ae,{size:15}),`Git`]}),ie&&(0,X.jsxs)(`button`,{type:`button`,className:ie.open?`active`:``,"aria-expanded":ie.open,"aria-label":ie.activeCount>0?`${I(`agents.terminal`)}: ${I(`agents.activeCount`,{count:ie.activeCount})}`:I(`agents.terminal`),onClick:ie.toggle,children:[(0,X.jsx)(j,{size:15}),(0,X.jsx)(`span`,{children:I(`agents.terminal`)}),ie.activeCount>0&&(0,X.jsx)(`sup`,{className:`agent-active-count`,"aria-label":I(`agents.activeCount`,{count:ie.activeCount}),children:ie.activeCount})]}),(0,X.jsxs)(`button`,{className:M?`active`:``,onClick:A,children:[(0,X.jsx)(_n,{size:15}),I(`common.settings`)]}),ee||P?(0,X.jsxs)(`button`,{className:`compile cancel-compile`,title:I(`compileControls.cancel`),onClick:re,disabled:F||w||T||!E,children:[F?(0,X.jsx)(je,{className:`spin`,size:15}):(0,X.jsx)(te,{size:15}),I(F?`compileControls.cancelling`:`compileControls.cancel`)]}):(0,X.jsxs)(`button`,{className:`compile`,title:I(`editor.compileShortcut`),onClick:ne,disabled:N||w||T||!E,children:[N?(0,X.jsx)(je,{className:`spin`,size:15}):(0,X.jsx)(ln,{size:15}),I(`editor.compile`,{engine:t.engine})]})]})]})}function Py(e,t,n){return e===`connected`?t:e===`disconnected`&&n?`editor.offlineDraft`:`editor.collaboration.${e}`}function Fy(e){return`${e.path}\u0000${e.line}`}function Iy(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:Fy(r),ancestorKeys:n.map(({index:e})=>t[e].key),hasChildren:!1}),n.push({level:r.level,index:t.length-1})}return t}function Ly(e,t){return e.filter(e=>!e.ancestorKeys.some(e=>t.has(e)))}var Ry=e=>e.path,zy=(e,t)=>t===e||t.startsWith(`${e}/`),By=`application/x-texlite-project-path`,Vy=`texlite-path:`;function Hy({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:m,canFormat:_,activeFormatLease:v,collaborationSynced:y,editorFontSize:b,outline:x,sourceCursorStore:C,wordCountBusy:w,hasSelection:D,hasFormatSelection:O,uploadInput:k,setSelectedFolder:j,setExpandedFolders:ee,setMoveEntry:P,setMoveName:F,setMoveDestination:ne,setDeleteEntry:re,setFileDialogError:ae,setNewFolderName:oe,setNewFolderOpen:I,setNewFilePath:se,setNewFileOpen:ce,setQuickOpen:L,setFileDragActive:R,dismissUploadFeedback:B,setFilesCollapsed:le,uploadFiles:V,upload:de,openFile:fe,movePathToFolder:pe,onError:me,onFormatFile:H,onFormatSelection:ge,jumpToSource:_e,syncSourceToPdf:U,onWordCount:W}){let{t:G}=Ee(),[ve,ye]=(0,Y.useState)(!1),[K,be]=(0,Y.useState)(null),[xe,Se]=(0,Y.useState)(null),{entries:Ce,finishExit:q}=ie(n,{scopeKey:JSON.stringify([e.id,[...c].sort()]),deletedKey:r,keyOf:Ry,contains:zy,duration:180}),we=(0,Y.useRef)(0),Te=(e,t)=>Gy(e.path)!==t&&(e.type!==`directory`||t!==e.path&&!t.startsWith(`${e.path}/`)),De=()=>{be(null),Se(null)};return(0,X.jsx)(Am,{id:`files`,panelRef:t,defaultSize:`16%`,minSize:`12%`,maxSize:`30%`,collapsible:!0,collapsedSize:`0%`,onResize:e=>le(e.asPercentage===0),children:(0,X.jsxs)(`aside`,{className:`left-panel`,children:[(0,X.jsxs)(`section`,{className:`files-panel${l?` drop-active`:``}`,onDragEnter:e=>{Wy(e.dataTransfer)?e.preventDefault():e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),!p&&!u&&R(!0))},onDragOver:e=>{Wy(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)||R(!1)},onDrop:e=>{if(Wy(e.dataTransfer)){e.preventDefault(),e.stopPropagation();return}if(e.preventDefault(),R(!1),p||u)return;let t=Array.from(e.dataTransfer.files);Uy(e.dataTransfer)||t.length===0?me(G(`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":ve,title:G(ve?`editor.hideFileSizes`:`editor.showFileSizes`),onClick:()=>ye(e=>!e),children:G(`common.files`)}),(0,X.jsxs)(`span`,{className:`file-tools`,children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":G(`navigation.quickOpen`),title:`${G(`navigation.quickOpen`)} (Ctrl/Cmd+P)`,onClick:()=>L(!0),children:(0,X.jsx)(S,{size:15})}),!p&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:u,"aria-label":G(`editor.uploadAttachment`),title:G(`editor.uploadTo`,{folder:s||G(`editor.projectRoot`)}),onClick:()=>k.current?.click(),children:(0,X.jsx)(A,{size:15})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":G(`editor.newFolder`),title:G(`editor.newFolder`),onClick:()=>{oe(``),I(!0)},children:(0,X.jsx)(T,{size:15})}),(0,X.jsx)(`button`,{type:`button`,"aria-label":G(`editor.newFile`),title:G(`editor.newFile`),onClick:()=>{se(s?`${s}/`:``),ce(!0)},children:(0,X.jsx)(Mt,{size:15})}),(0,X.jsx)(`input`,{ref:k,type:`file`,multiple:!0,hidden:!0,onChange:e=>void de(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)(je,{className:`spin`,size:14}):f.kind===`success`?(0,X.jsx)(he,{size:14}):(0,X.jsx)(g,{size:14}),(0,X.jsxs)(`span`,{className:`file-upload-feedback-text`,children:[f.kind===`uploading`&&G(`editor.uploadingFile`,{file:f.fileName,current:f.current,total:f.total}),f.kind===`success`&&G(`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":G(`common.close`),title:G(`common.close`),onClick:B,children:(0,X.jsx)(te,{size:13})})]}),l&&(0,X.jsxs)(`div`,{className:`file-drop-overlay`,children:[(0,X.jsx)(A,{size:24}),(0,X.jsx)(`strong`,{children:G(`editor.dropFiles`)}),(0,X.jsx)(`span`,{children:G(`editor.uploadTo`,{folder:s||G(`editor.projectRoot`)})})]}),(0,X.jsx)(`div`,{className:`file-list${s===null?``:` folder-selected`}${xe===``?` root-drop-target`:``}`,style:{fontSize:`${b}px`},onDragOver:e=>{(K||Wy(e.dataTransfer))&&(e.preventDefault(),e.stopPropagation(),K&&(Te(K,``)?(e.dataTransfer.dropEffect=`move`,Se(``)):e.dataTransfer.dropEffect=`none`))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||Se(e=>e===``?null:e)},onDrop:e=>{if(!K&&!Wy(e.dataTransfer)||(e.preventDefault(),e.stopPropagation(),!K))return;let t=K;De(),Te(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:z,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&&q(t.path)}};return t.type===`directory`?(0,Y.createElement)(`div`,{...f,className:`file-entry folder-entry${s===t.path?` selected`:``}${xe===t.path?` move-drop-target`:``}`,style:{paddingLeft:`${r*13+5}px`},key:t.path,onDragOver:e=>{(K||Wy(e.dataTransfer))&&(e.preventDefault(),e.stopPropagation(),K&&(Te(K,t.path)?(e.dataTransfer.dropEffect=`move`,Se(t.path)):e.dataTransfer.dropEffect=`none`))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||Se(e=>e===t.path?null:e)},onDrop:e=>{if(!K&&!Wy(e.dataTransfer)||(e.preventDefault(),e.stopPropagation(),!K))return;let n=K;De(),Te(n,t.path)&&pe(n,t.path)}},(0,X.jsxs)(`button`,{type:`button`,className:`file-entry-main`,onClick:()=>{j(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)(M,{size:13}):(0,X.jsx)(N,{size:13}),(0,X.jsx)(E,{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:G(`editor.move`),"aria-label":G(`editor.move`),onClick:()=>{P(t),F(i??``),ne(``)},children:(0,X.jsx)(Xt,{size:13})}),u&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action danger-text`,title:G(`editor.deletePath`),"aria-label":G(`editor.deletePath`),onClick:()=>{re(t),ae(``)},children:(0,X.jsx)(ue,{size:13})})]})):(0,Y.createElement)(`div`,{...f,className:`file-entry${s===null&&o===t.path?` active`:``}${K?.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=>{we.current=Date.now()+500,Ky(e,t,be)},onDragEnd:De,onClick:()=>{we.current>Date.now()?we.current=0:fe(t)},children:[(0,X.jsx)(Rn,{path:t.path}),(0,X.jsx)(`span`,{children:i}),l&&(0,X.jsx)(`small`,{children:G(`editor.currentMainShort`)})]}),ve&&typeof t.size==`number`&&(0,X.jsx)(`span`,{className:`file-entry-size`,children:Jy(t.size)}),!p&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action`,title:G(`editor.move`),"aria-label":G(`editor.move`),onClick:()=>{P(t),F(i??``),ne(``)},children:(0,X.jsx)(Xt,{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:G(`editor.downloadResource`),"aria-label":G(`editor.downloadResource`),onClick:e=>e.stopPropagation(),children:(0,X.jsx)(h,{size:13})}),!p&&u&&(0,X.jsx)(`button`,{type:`button`,className:`file-entry-action danger-text`,title:G(`editor.deletePath`),"aria-label":G(`editor.deletePath`),onClick:()=>{re(t),ae(``)},children:(0,X.jsx)(ue,{size:13})}))})}),!p&&_&&(0,X.jsxs)(`div`,{className:`file-format-footer`,role:`group`,"aria-label":G(`editor.format`),"aria-busy":m,children:[(0,X.jsxs)(`div`,{className:`file-format-label`,children:[(0,X.jsx)(yn,{size:13}),G(`editor.format`)]}),(0,X.jsxs)(`div`,{className:`file-format-actions`,children:[(0,X.jsx)(`button`,{className:O?``:`active`,type:`button`,title:G(`editor.formatFileHint`),onMouseDown:e=>e.preventDefault(),onClick:H,disabled:m||v||!y,children:G(`editor.formatFile`)}),(0,X.jsx)(`button`,{className:O?`active`:``,type:`button`,title:G(O?`editor.formatSelection`:`editor.formatSelectionHint`),onMouseDown:e=>e.preventDefault(),onClick:ge,disabled:m||v||!y||!O,children:G(`editor.formatSelected`)})]})]})]}),(0,X.jsx)(qy,{outline:x,activeFile:i,activeMainFile:a,sourceCursorStore:C,wordCountBusy:w,hasSelection:D,jumpToSource:_e,syncSourceToPdf:U,onWordCount:W})]})})}function Uy(e){return Array.from(e.items).some(e=>e.webkitGetAsEntry?.()?.isDirectory===!0)}function Wy(e){return Array.from(e.types).includes(By)?!0:Array.from(e.types).includes(`text/plain`)&&e.getData(`text/plain`).startsWith(Vy)}function Gy(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function Ky(e,t,n){e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(By,t.path),e.dataTransfer.setData(`text/plain`,`${Vy}${t.path}`),n(t)}function qy({outline:e,activeFile:t,activeMainFile:n,sourceCursorStore:r,wordCountBusy:i,hasSelection:a,jumpToSource:o,syncSourceToPdf:s,onWordCount:c}){let{t:l}=Ee(),u=(0,Y.useSyncExternalStore)(r.subscribe,r.getOutlineLine,r.getOutlineLine),d=(0,Y.useMemo)(()=>Iy(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)(()=>Ly(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)(m,{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)(je,{className:`spin`,size:12}):(0,X.jsx)(Bt,{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)(je,{className:`spin`,size:12}):(0,X.jsx)(Bt,{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)(N,{size:13}):(0,X.jsx)(M,{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 Jy(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 Yy({children:e,tabs:t,terminal:n}){let{t:r}=Ee(),i=Mm(),[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)(wm,{orientation:`vertical`,className:`agent-editor-group`,children:[(0,X.jsx)(Am,{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)(Fm,{className:`agent-terminal-resizer`,"aria-label":r(`agents.resizeTerminal`)}),(0,X.jsx)(Am,{id:`agent-terminal`,defaultSize:`35%`,minSize:`20%`,children:n({maximized:l,toggleMaximized:()=>{let e=i.current;e?.isCollapsed()?e.expand():e?.collapse()}})})]})]})})}var Xy=(0,Y.lazy)(()=>f(()=>import(`./LatexEditor-BDpqgoOa.js`).then(e=>({default:e.LatexEditor})),__vite__mapDeps([10,2,3,7,1,4,5,6,8,11]),import.meta.url));function Zy({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:w,onCommentClick:T,onSpellCheckReplace:E,onReferenceNavigate:D,onCursor:k,terminal:A}){let{t:j}=Ee(),M=y_(o,t),N=b_(s,t,i);return(0,X.jsx)(Am,{id:`source`,minSize:`22%`,children:(0,X.jsx)(Yy,{terminal:A,tabs:c.openFilesInTabs&&n.length>0&&(0,X.jsx)(`div`,{className:`editor-tabs-bar`,role:`tablist`,"aria-label":j(`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)(ee,{size:13}):(0,X.jsx)(O,{size:13})}),(0,X.jsx)(`span`,{className:`editor-tab-title`,children:o}),a&&(0,X.jsx)(`small`,{className:`editor-tab-badge`,children:j(`editor.currentMainShort`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`editor-tab-close`,title:j(`common.close`),"aria-label":`${j(`common.close`)} ${o}`,onClick:()=>y(n),children:(0,X.jsx)(te,{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)(je,{className:`spin`,size:22}),(0,X.jsx)(`span`,{children:j(`common.loading`)})]}),children:(0,X.jsx)(Xy,{value:r,filePath:t,readOnly:a,comments:M,focusComment:N,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:w,onCommentClick:T,onSpellCheckReplace:E,onReferenceNavigate:D,onCursor:k},t)}),_&&(0,X.jsx)(`div`,{className:`editor-centered-notice`,role:`status`,"aria-live":`polite`,children:_})]})})})}var Qy=t(r(),1);function $y({children:e}){let[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(null);return(0,Y.useLayoutEffect)(()=>{if(!t)return;let e=()=>{let e=t.getBoundingClientRect(),n=e.left+e.width/2,r=e.top+e.height/2;i(e=>e?.left===n&&e.top===r?e:{left:n,top:r})},n=new ResizeObserver(e);n.observe(t);let r=t.parentElement;if(r){n.observe(r);for(let e of r.children)e.hasAttribute(`data-panel`)&&n.observe(e)}return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),e(),()=>{n.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[t]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fm,{className:`resize-handle sync-resize-handle`,elementRef:n,children:(0,X.jsx)(Rt,{className:`resize-grip`,size:12})}),r&&(0,Qy.createPortal)((0,X.jsx)(`span`,{className:`sync-direction-buttons`,style:{position:`fixed`,...r},children:e}),document.body)]})}function eb({diagnostics:e,files:t,empty:n,tone:r,onJump:i}){let{t:a}=Ee(),o=r===`error`?vt:g;return e.length?(0,X.jsx)(`div`,{className:`compile-diagnostic-list compile-${r}`,children:e.map((e,n)=>{let r=ib(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 tb({lines:e,empty:t,tone:n=`log`}){let r=n===`error`?vt:n===`warning`?g:v;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 nb({projectId:e,mainFile:t,artifacts:n,preview:r,loading:i,onView:a}){let{t:o}=Ee(),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)(Rn,{path:e.path,size:14}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:e.path}),(0,X.jsx)(`small`,{children:ab(e.size)})]})]}),(0,X.jsx)(`a`,{href:s(e.path),title:o(`editor.downloadArtifact`),"aria-label":o(`editor.downloadArtifact`),children:(0,X.jsx)(h,{size:14})})]},e.path))}),(0,X.jsx)(`div`,{className:`artifact-preview`,children:i?(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(je,{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)(h,{size:13}),o(`projects.download`)]})]}),(0,X.jsx)(`pre`,{children:r.content})]}):(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(O,{size:24}),(0,X.jsx)(`span`,{children:o(`editor.selectArtifact`)})]})})]}):(0,X.jsxs)(`div`,{className:`compile-empty`,children:[(0,X.jsx)(Qt,{size:26}),(0,X.jsx)(`span`,{children:o(`editor.noArtifacts`)})]})}function rb({mainFile:e,disabled:t,cleaning:n,onCleanCache:r,onCleanArtifacts:i}){let{t:a}=Ee();return(0,X.jsxs)(`div`,{className:`compile-clean-panel`,children:[(0,X.jsxs)(`div`,{className:`compile-clean-intro`,children:[(0,X.jsx)(g,{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)(St,{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)(gt,{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)(je,{className:`spin`,size:14}):(0,X.jsx)(St,{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)(ue,{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)(gt,{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)(je,{className:`spin`,size:14}):(0,X.jsx)(ue,{size:14}),a(`editor.cleanArtifacts`)]})]})]})]})]})}function ib(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 ab(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}var ob=(0,Y.lazy)(()=>Ae().then(e=>({default:e.PdfPreview})));function sb({projectId:e,activeMainFile:t,previewTab:n,diagnosticTab:r,pdfUrl:i,pdfLoadingMode:a,pdfLoading:o,pdfCompiledAt:s,pdfSizeBytes:c,pdfCompiledLabel:u,pdfTargetLabel:d,pdfDownloadUrl:f,pdfTarget:p,pdfViewport:m,activeFile:_,compileBusy:y,compileLog:b,compileDiagnostics:x,compileMessages:S,artifacts:C,artifactPreview:w,artifactLoading:T,cleaning:E,readOnly:D,collaborationSynced:O,workspaceLayout:k,showSyncResize:A,diagnosticCount:j,selectPreviewTab:M,changeWorkspaceLayout:N,onSetPdfViewport:ee,onResetPdfViewport:te,onPdfDisplayed:P,syncVisiblePdfToSource:F,syncCurrentSourceToPdf:ne,syncPdfToSource:re,canSyncWithPdf:ie,canSyncPdfToSource:ae,files:oe,jumpToSource:I,onSetCleanMode:se,viewArtifact:ce}){let{t:L}=Ee(),[R,z]=(0,Y.useState)(``),le=(0,Y.useRef)(``),V=e=>{le.current!==e&&(le.current=e,z(e),te(),P(e))},ue=ae&&!!i&&R===i,de=[c==null?``:cb(c),u?L(`editor.pdfUpdatedAt`,{time:u}):``].filter(Boolean).join(` · `);return(0,X.jsxs)(X.Fragment,{children:[A&&(0,X.jsxs)($y,{children:[(0,X.jsx)(`button`,{disabled:!i||!m||!ue,title:L(ae?ue?`editor.showInSource`:`editor.syncTexWaitingForPdf`:`editor.syncTexOnlyForMain`),"aria-label":L(`editor.showInSource`),onClick:e=>{e.stopPropagation(),ue&&F()},children:(0,X.jsx)(`span`,{"aria-hidden":!0,children:`←`})}),(0,X.jsx)(`button`,{disabled:!_||!i||!ie,title:L(ie?`editor.showInPdf`:`editor.syncTexOnlyForTex`),"aria-label":L(`editor.showInPdf`),onClick:e=>{e.stopPropagation(),_&&i&&ie&&ne()},children:(0,X.jsx)(`span`,{"aria-hidden":!0,children:`→`})})]}),(0,X.jsx)(Am,{id:`preview`,minSize:`22%`,children:(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":L(`editor.outputTabs`),children:[(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":n===`pdf`,className:`pdf-tab${n===`pdf`?` active`:``}`,onClick:()=>M(`pdf`),title:s?L(`editor.pdfCompiledAtFor`,{file:t,time:B(s,l.resolvedLanguage)}):L(`editor.currentMainDocument`,{path:t}),children:[(0,X.jsx)(En,{className:`pdf-tab-icon`}),(0,X.jsxs)(`span`,{className:`pdf-tab-label`,children:[(0,X.jsxs)(`span`,{className:`pdf-tab-title`,children:[`PDF · `,d]}),de&&(0,X.jsx)(`small`,{children:de})]})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":n===`diagnostics`,className:`diagnostics-tab${n===`diagnostics`?` active`:``}`,onClick:()=>M(`diagnostics`),children:[(0,X.jsx)(v,{size:14}),L(`editor.outputTabs`),(0,X.jsx)(`span`,{className:`diagnostic-count`,children:j})]})]}),f&&(0,X.jsxs)(`a`,{className:`pdf-download-top`,href:f,download:!0,title:L(`editor.downloadPdf`),"aria-label":L(`editor.downloadPdf`),children:[(0,X.jsx)(h,{size:15}),(0,X.jsx)(`span`,{children:L(`editor.downloadPdf`)})]})]}),n===`diagnostics`&&(0,X.jsxs)(`div`,{className:`preview-subtabs`,role:`tablist`,"aria-label":L(`editor.outputTabs`),children:[(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":r===`log`,className:r===`log`?`active`:``,onClick:()=>M(`log`),children:[(0,X.jsx)(Kt,{size:13}),L(`editor.log`)]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":r===`warnings`,className:r===`warnings`?`active`:``,onClick:()=>M(`warnings`),children:[(0,X.jsx)(g,{size:13}),L(`editor.warnings`),(0,X.jsx)(`span`,{children:S.warnings.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":r===`errors`,className:r===`errors`?`active`:``,onClick:()=>M(`errors`),children:[(0,X.jsx)(vt,{size:13}),L(`editor.errors`),(0,X.jsx)(`span`,{children:S.errors.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":r===`artifacts`,className:r===`artifacts`?`active`:``,onClick:()=>M(`artifacts`),children:[(0,X.jsx)(Qt,{size:13}),L(`editor.artifacts`),(0,X.jsx)(`span`,{children:C.length})]}),(0,X.jsxs)(`button`,{role:`tab`,"aria-selected":r===`clean`,className:r===`clean`?`active`:``,onClick:()=>M(`clean`),children:[(0,X.jsx)(St,{size:13}),L(`editor.clean`)]})]}),(0,X.jsxs)(`div`,{className:`preview-content preview-${n} ${n===`diagnostics`?`preview-${r}`:``}`,children:[n===`pdf`&&(i?(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(je,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:L(`editor.loadingPdf`)})]}),children:(0,X.jsx)(ob,{url:i,loadingMode:a,target:p,compiling:y,onDisplayedUrlChange:V,onViewportLocation:(e,t,n)=>{le.current===i&&ee({page:e,x:t,y:n})},onDoubleClickLocation:(e,t,n)=>{le.current===i&&ue&&(ee({page:e,x:t,y:n}),re(e,t,n))}})}):o?(0,X.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(je,{className:`spin`,size:24}),(0,X.jsx)(`span`,{children:L(`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:y?(0,X.jsx)(je,{className:`spin`,size:26}):(0,X.jsx)(En,{size:32})}),(0,X.jsx)(`strong`,{children:L(y?`editor.compiling`:`editor.previewEmptyTitle`)}),(0,X.jsx)(`p`,{children:L(y?`editor.previewCompilingHint`:`editor.previewHint`)})]})),n===`diagnostics`&&r===`log`&&(0,X.jsx)(tb,{lines:b?b.split(`
|
|
17
|
+
`):[],empty:L(y?`editor.compiling`:`editor.noLog`)}),n===`diagnostics`&&r===`warnings`&&(x?(0,X.jsx)(eb,{tone:`warning`,diagnostics:x.warnings,files:oe,empty:L(`editor.noWarnings`),onJump:(e,t,n)=>{k===`pdf-only`&&N(`editor-pdf`),I(e,t,n)}}):(0,X.jsx)(tb,{tone:`warning`,lines:S.warnings,empty:L(`editor.noWarnings`)})),n===`diagnostics`&&r===`errors`&&(x?(0,X.jsx)(eb,{tone:`error`,diagnostics:x.errors,files:oe,empty:L(`editor.noErrors`),onJump:(e,t,n)=>{k===`pdf-only`&&N(`editor-pdf`),I(e,t,n)}}):(0,X.jsx)(tb,{tone:`error`,lines:S.errors,empty:L(`editor.noErrors`)})),n===`diagnostics`&&r===`artifacts`&&(0,X.jsx)(nb,{projectId:e,mainFile:t,artifacts:C,preview:w,loading:T,onView:e=>void ce(e)}),n===`diagnostics`&&r===`clean`&&(0,X.jsx)(rb,{mainFile:t,disabled:D||!O||y,cleaning:E,onCleanCache:()=>se(`cache`),onCleanArtifacts:()=>se(`artifacts`)})]})]})})]})}function cb(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 lb({kind:e,onEdit:t,onDelete:n,disabled:r=!1}){let{t:i}=Ee(),a=(0,Y.useRef)(!1);return(0,X.jsx)(`span`,{className:`comment-actions-menu`,onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(Ie,{modal:!1,children:[(0,X.jsx)(Ne,{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)(fe,{size:16,"aria-hidden":!0})})}),(0,X.jsx)(Me,{children:(0,X.jsxs)(Pe,{className:`comment-actions-menu-content`,align:`end`,sideOffset:4,collisionPadding:8,onCloseAutoFocus:e=>{a.current&&e.preventDefault(),a.current=!1},children:[(0,X.jsxs)(Fe,{onSelect:()=>{a.current=!0,t()},children:[(0,X.jsx)(_,{size:13,"aria-hidden":!0}),i(e===`comment`?`editor.editComment`:`editor.editReply`)]}),(0,X.jsxs)(Fe,{className:`danger-text`,onSelect:()=>{a.current=!0,n()},children:[(0,X.jsx)(ue,{size:13,"aria-hidden":!0}),i(e===`comment`?`editor.deleteComment`:`editor.deleteReply`)]})]})})]})})}function ub(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 db({projectId:e,value:t,onChange:n,onKeyDown:r,onFocus:i,...a}){let{t:o}=Ee(),s=(0,Y.useRef)(null),[c,l]=(0,Y.useState)(null),u=Jg({queryKey:Xg.candidates(e),enabled:!!c,queryFn:({signal:t})=>W(`/api/projects/${e}/mention-candidates`,{signal:t})}),d=$g(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=ub(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)(C,{"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 fb({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}=Ee(),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)(db,{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`)}),(0,X.jsxs)(`button`,{className:`primary`,type:`submit`,disabled:p||!t.trim(),children:[a?(0,X.jsx)(je,{className:`spin`,"aria-hidden":!0,size:13}):c?(0,X.jsx)(pn,{"aria-hidden":!0,size:13}):(0,X.jsx)(hn,{"aria-hidden":!0,size:13}),d(a?c?`editor.commentSaving`:`editor.commentSending`:c?`editor.saveChanges`:`editor.sendReply`)]})]})]})}function pb(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 mb=1100;function hb(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`,`${mb}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 gb(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 _b({userId:e,avatarStyle:t,name:n,username:r,highlighted:i,children:a}){return(0,X.jsxs)(`span`,{className:`comment-identity`,children:[(0,X.jsx)(P,{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 vb({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:m,onEdit:h,onDelete:g,onEditReply:_,onDeleteReply:v,selectedParticipantIds:y,highlightReplyParticipants:b,replyExpansion:x,onReplyExpansionChange:S}){let{t:w,i18n:T}=Ee(),E=se(),[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,ee=j[`edit-comment`],te=(0,Y.useId)(),P=pb(t.replies,{expansion:x,current:c,targetReplyId:s,unreadReplyMentionIds:a,selectedParticipantIds:y,highlightReplyParticipants:b,activeDraft:!!(M?.open||M?.pending||t.authorId===r&&ee?.open||t.replies.some(e=>e.authorId===r&&j[`edit-reply:${e.id}`]?.open))}),F=n.isPending(t.id),[ne,re]=(0,Y.useState)(null),[ie,ae]=(0,Y.useState)(!1),[oe,I]=(0,Y.useState)(null),[ce,L]=(0,Y.useState)(``),R=(0,Y.useRef)(null),z=(0,Y.useRef)(!1),[V,ue]=(0,Y.useState)(!1),de=async e=>{if(z.current)return;z.current=!0,ue(!0),L(``);let t=hb(e?R.current?.querySelector(`[data-comment-reply-id="${e}"]`)??null:R.current);try{if(!(e?await v(e):await g())){L(w(`editor.commentDeleteFailed`));return}e?I(null):ae(!1),t()}catch(e){L(U(e))}finally{z.current=!1,ue(!1)}},fe=(e,r=``)=>{f(),S(!0),re(e),n.open(t.id,e,r)},H=(r,i,a)=>{let o=j[r];return o?.open?(0,X.jsx)(fb,{projectId:e,editing:r!==`reply`,label:i,value:o.content,pending:o.pending,error:o.error,disabled:F||D,autoFocus:ne===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},ge=t.authorUsername,_e=e=>le(e,T.resolvedLanguage??`en`,E,(e,t)=>w(e,t)),W=e=>B(e,T.resolvedLanguage,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),G=e=>(0,X.jsx)(`time`,{dateTime:e,"data-tooltip":W(e),"data-texlite-tooltip-always":!0,children:_e(e)}),ve=(e,t)=>(0,X.jsxs)(`span`,{className:`comment-times`,children:[G(e),t&&(0,X.jsx)(`small`,{"data-tooltip":w(`editor.editedAt`,{time:W(t)}),"data-texlite-tooltip-always":!0,children:w(`editor.commentEdited`)})]}),ye=async(e,t)=>{t.stopPropagation(),S(!0),await u(e)};return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`article`,{ref:R,"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)(_b,{userId:t.authorId,avatarStyle:t.authorAvatarStyle,name:t.authorDisplayName??ge??w(`editor.deletedUser`),username:ge,highlighted:y?.has(t.authorId),children:ve(t.createdAt,t.editedAt)}),(0,X.jsxs)(`span`,{className:`comment-header-actions`,children:[(0,X.jsx)(`button`,{type:`button`,className:`resolve`,disabled:D||F,"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)(je,{className:`spin`,size:15,"aria-hidden":!0}):t.resolved?(0,X.jsx)(dn,{size:15,"aria-hidden":!0}):(0,X.jsx)(pe,{size:16,"aria-hidden":!0})}),t.authorId===r&&!ee?.open&&(0,X.jsx)(lb,{kind:`comment`,disabled:F||D,onEdit:()=>fe(`edit-comment`,t.content),onDelete:()=>{L(``),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}),ee?.open&&t.authorId===r?H(`edit-comment`,w(`editor.editComment`),h):(0,X.jsx)(`p`,{className:`comment-content`,children:gb(t.content)}),i&&(0,X.jsxs)(`div`,{className:`comment-mention`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(C,{"aria-hidden":!0,size:12}),w(`editor.mentionedYou`)]}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>void ye(i,e),children:w(`editor.markMentionRead`)})]}),t.replies.length>0&&(0,X.jsxs)(`div`,{className:`comment-replies`,children:[P.canToggle&&(0,X.jsxs)(`button`,{type:`button`,className:`comment-replies-toggle`,"aria-expanded":P.expanded,"aria-controls":te,onClick:e=>{e.stopPropagation(),S(!P.expanded)},children:[P.expanded?(0,X.jsx)(me,{size:12,"aria-hidden":!0}):(0,X.jsx)(N,{size:12,"aria-hidden":!0}),P.expanded?w(`editor.hideEarlierReplies`):w(`editor.showEarlierReplies`,{count:P.hiddenCount})]}),(0,X.jsx)(`div`,{className:`comment-replies-list`,id:te,children:P.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)(_b,{userId:e.authorId,avatarStyle:e.authorAvatarStyle,name:e.authorDisplayName??e.authorUsername??w(`editor.deletedUser`),username:e.authorUsername,highlighted:b&&y?.has(e.authorId),children:ve(e.createdAt,e.editedAt)}),(0,X.jsx)(`span`,{className:`comment-header-actions`,children:e.authorId===r&&!i&&(0,X.jsx)(lb,{kind:`reply`,disabled:F||D,onEdit:()=>fe(n,e.content),onDelete:()=>{L(``),I(e.id)}})})]}),i?H(n,w(`editor.editReply`),t=>_(e.id,t)):(0,X.jsx)(`p`,{className:`comment-content`,children:gb(e.content)}),t&&(0,X.jsxs)(`div`,{className:`comment-mention`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(C,{"aria-hidden":!0,size:12}),w(`editor.mentionedYou`)]}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>void ye(t,e),children:w(`editor.markMentionRead`)})]})]},e.id)})})]}),t.resolved&&t.resolvedAt&&(0,X.jsxs)(`div`,{className:`comment-resolution`,children:[(0,X.jsx)(he,{size:12,"aria-hidden":!0}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(ft,{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})}}),` · `,G(t.resolvedAt)]})]}),!M?.open&&(0,X.jsx)(`button`,{type:`button`,className:`reply-action`,disabled:F||D,onClick:e=>{e.stopPropagation(),fe(`reply`)},children:w(`editor.replyPrompt`)}),H(`reply`,w(`editor.reply`),m)]}),(0,X.jsx)(ke,{open:ie,title:w(`editor.deleteCommentTitle`),description:w(`editor.deleteCommentDescription`),confirmLabel:w(`common.delete`),danger:!0,busy:V,error:ce,onCancel:()=>ae(!1),onConfirm:()=>void de(null)}),(0,X.jsx)(ke,{open:!!oe,title:w(`editor.deleteReplyTitle`),description:w(`editor.deleteReplyDescription`),confirmLabel:w(`common.delete`),danger:!0,busy:V,error:ce,onCancel:()=>I(null),onConfirm:()=>{oe&&de(oe)}})]})}function yb({open:e,onOpenChange:t,project:n,projectId:r}){let{t:i}=Ee(),[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([W(`/api/projects/${r}/members`),W(`/api/users`)]);o(e.members),c(t.users.filter(e=>e.id!==n.ownerId))}catch(e){g(U(e))}};(0,Y.useEffect)(()=>{e&&v()},[e,r]);let y=async()=>{if(l)try{await W(`/api/projects/${r}/members/${l}`,{method:`PUT`,body:JSON.stringify({permission:d})}),u(``),f(`read`),await v()}catch(e){g(U(e))}},b=async(e,t)=>{try{await W(`/api/projects/${r}/members/${e.id}`,{method:`PUT`,body:JSON.stringify({permission:t})}),await v()}catch(e){g(U(e))}},x=async()=>{if(p)try{await W(`/api/projects/${r}/members/${p.id}`,{method:`DELETE`}),m(null),await v()}catch(e){g(U(e))}},S=s.filter(e=>!a.some(t=>t.id===e.id));return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(we,{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)(de,{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`)}),S.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)(ge,{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)(P,{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)(ue,{size:15})})]})]},e.id)),a.length===0&&(0,X.jsxs)(`div`,{className:`share-empty`,children:[(0,X.jsx)(de,{size:24}),(0,X.jsx)(`span`,{children:i(`projectSettings.noMembers`)})]})]})]})}),(0,X.jsx)(ke,{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 bb=(0,Y.lazy)(()=>f(()=>import(`./CitationLibraryDialog-CnQVjovw.js`).then(e=>({default:e.CitationLibraryDialog})),__vite__mapDeps([12,2,3,13,6,1,4,5,7,8,14,15,16,17,18,19,20,21]),import.meta.url)),xb=(0,Y.lazy)(()=>f(()=>import(`./GitDialog-CzgguGGW.js`).then(e=>({default:e.GitDialog})),__vite__mapDeps([22,2,3,13,6,1,4,5,7,8,23,24,25,26,16]),import.meta.url)),Sb=(0,Y.lazy)(()=>f(()=>import(`./HistoryDialog-Bw3GHfbM.js`).then(e=>({default:e.HistoryDialog})),__vite__mapDeps([27,2,3,13,6,1,4,5,7,8,28,29,30,25,26,16,17,31,32]),import.meta.url)),Cb=(0,Y.lazy)(()=>f(()=>import(`./SelectionHistoryDialog-DBL6vVD4.js`).then(e=>({default:e.SelectionHistoryDialog})),__vite__mapDeps([33,2,3,13,6,1,4,5,7,8,29,30,31]),import.meta.url)),wb=(0,Y.lazy)(()=>f(()=>import(`./QuickOpenDialog-CEYxIk4l.js`).then(e=>({default:e.QuickOpenDialog})),__vite__mapDeps([34,2,3,13,6,1,4,5,7,8,14,17]),import.meta.url));function Tb({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:_,uploadFiles:v,cleanMode:y,setCleanMode:b,cleanCompile:x,newFileOpen:S,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:F,moveName:ne,setMoveName:re,moveDestination:ie,setMoveDestination:ae,movePath:oe,deleteEntry:I,setDeleteEntry:se,deleteActiveSessions:ce,removePath:L,commentOpen:R,closeComment:z,commentSelection:B,commentText:le,setCommentText:V,commentSubmitting:de,commentError:fe,addComment:pe,cancelComment:me,commentDraftRestored:he,commentDraftCanRetarget:ge,useCurrentCommentSelection:_e,shareOpen:U,setShareOpen:W,citationLibraryOpen:G,setCitationLibraryOpen:ve,insertCitationAtCursor:ye,quickOpen:K,setQuickOpen:be,openFile:xe,selectionHistoryTarget:Se,closeSelectionHistory:Ce,historyOpen:q,setHistoryOpen:De,gitOpen:Oe,setGitOpen:Ae,save:Me,permissionDowngrade:Ne,permissionDowngradeBusy:Pe,dismissPermissionDowngrade:Fe,discardPermissionDraft:Ie}){let{t:J}=Ee();return(0,X.jsxs)(X.Fragment,{children:[Ne&&(0,X.jsx)(we,{open:!0,title:J(`editor.collaboration.permissionDowngradeTitle`),description:Ne.localDraftReady&&Ne.otherTabDraft?J(`editor.collaboration.permissionDowngradeMultipleDrafts`):Ne.otherTabDraft?J(`editor.collaboration.permissionDowngradeOtherTab`):Ne.localDraftReady?J(`editor.collaboration.permissionDowngradeDescription`,{previous:J(`common.readWrite`)}):J(`editor.collaboration.permissionDowngradeNoDraft`),onOpenChange:e=>{!e&&!Pe&&Fe()},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{type:`button`,disabled:Pe,onClick:Fe,children:Ne.localDraftReady?J(`editor.collaboration.permissionDowngradeKeep`):J(`common.close`)}),!Ne.otherTabDraft&&(0,X.jsxs)(`button`,{type:`button`,className:`danger`,disabled:Pe,onClick:()=>void Ie(),children:[Pe?(0,X.jsx)(je,{className:`spin`,size:14}):Ne.localDraftReady?(0,X.jsx)(ue,{size:14}):(0,X.jsx)(H,{size:14}),Ne.localDraftReady?J(`editor.collaboration.permissionDowngradeDiscard`):J(`editor.collaboration.permissionDowngradeReload`)]})]}),children:(0,X.jsx)(`div`,{})}),(0,X.jsxs)(we,{open:!!l,extraWide:l?.kind===`image`||l?.kind===`pdf`||l?.kind===`text`,title:l?.path??``,description:l?.kind===`large`?J(`editor.resourceTooLarge`,{size:Eb(l.size),limit:Eb(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)(h,{size:14}),J(`editor.downloadResource`)]}),children:[l?.kind===`large`&&(0,X.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,X.jsx)(k,{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)(It,{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)(je,{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)(ke,{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),_()},onConfirm:()=>{let e=p;m(null),e&&v(e.files,new Set(e.collisions),e.directory)}}),(0,X.jsx)(ke,{open:!!y,title:J(y===`cache`?`editor.cleanCacheConfirmTitle`:`editor.cleanArtifactsConfirmTitle`),description:J(y===`cache`?`editor.cleanCacheConfirmDescription`:`editor.cleanArtifactsConfirmDescription`),confirmLabel:J(`editor.cleanConfirm`),danger:y===`artifacts`,onCancel:()=>b(null),onConfirm:()=>{let e=y;b(null),e&&x(e)}}),(0,X.jsx)(we,{open:S,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)(we,{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)(we,{open:!!P,title:J(`editor.moveTitle`,{name:P?.path.split(`/`).at(-1)??``}),description:J(`editor.moveDescription`),onOpenChange:e=>{e||(F(null),re(``),N(``))},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>F(null),children:J(`common.cancel`)}),(0,X.jsx)(`button`,{className:`primary`,disabled:!ne.trim(),onClick:()=>void oe(),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:ne,onChange:e=>re(e.target.value),onKeyDown:e=>{e.key===`Enter`&&oe()}})]}),(0,X.jsxs)(`label`,{className:`form-field`,children:[J(`editor.destinationFolder`),(0,X.jsxs)(`select`,{value:ie,onChange:e=>ae(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)(we,{open:!!I,title:J(`editor.deletePathTitle`,{name:I?.path.split(`/`).at(-1)??``}),description:ce.length?J(`editor.deletePathActiveDescription`,{count:ce.length,path:I?.path??``,users:[...new Set(ce.map(e=>e.name))].join(`, `)}):J(`editor.deletePathDescription`,{path:I?.path??``}),onOpenChange:e=>{e||(se(null),N(``))},footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>se(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}),ce.length>0&&(0,X.jsxs)(`p`,{className:`warning`,children:[(0,X.jsx)(g,{size:15}),J(`editor.deletePathWillClose`)]})]})}),(0,X.jsxs)(we,{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||!le.trim(),onClick:()=>void pe(),children:[de&&(0,X.jsx)(je,{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)(db,{projectId:n,autoFocus:!0,rows:5,disabled:de,value:le,placeholder:J(`editor.commentPlaceholder`),onChange:V,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)(yb,{open:U,onOpenChange:W,project:t,projectId:n}),G&&(0,X.jsx)(Te,{title:J(`citationLibrary.title`),onClose:()=>ve(!1),children:(0,X.jsx)(bb,{open:!0,onOpenChange:ve,currentFile:r,currentSource:i,readOnly:c,currentUserId:e.id,maxBibtexBytes:a,onInsert:ye})}),K&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(wb,{open:!0,files:o,onOpenChange:be,onOpenFile:e=>{let t=o.find(t=>t.path===e);t&&xe(t)}})}),Se&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Cb,{open:!0,onOpenChange:e=>{e||Ce()},project:t,filePath:Se.filePath,selection:Se.selection,currentSource:Se.source})}),q&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Sb,{open:!0,onOpenChange:De,project:t,onBeforeMutation:t.permission===`read`?async()=>!0:Me})}),t.ownerId===e.id&&Oe&&(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(xb,{open:!0,onOpenChange:Ae,project:t,onBeforeMutation:Me})})]})}function Eb(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Db({participants:e,selectedIds:t,topLevelOnly:n,onToggle:r,onClear:i,onTopLevelOnlyChange:a}){let{t:o}=Ee(),[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)(F,{open:s,onOpenChange:c,children:[(0,X.jsx)(re,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`comment-participants-toggle`,"aria-label":`${o(`editor.commentParticipants`)}: ${p}`,children:[(0,X.jsx)(de,{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)(M,{size:12,"aria-hidden":!0,className:s?`expanded`:``})]})}),(0,X.jsx)(L,{children:(0,X.jsxs)(ne,{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)(I,{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)(P,{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)(te,{size:12,"aria-hidden":!0})})]})})}function Ob(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||m_(n,r)||a.splice(Math.min(t,a.length),0,{comment:n,exitAt:e.exitAt??i+280+50})}),a}function kb(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?Ob(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 Ab(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 jb=(0,Y.lazy)(()=>f(()=>import(`./ProjectSettings-B_y5nRgp.js`).then(e=>({default:e.ProjectSettings})),__vite__mapDeps([35,2,3,13,6,1,4,5,7,8,28,24,36,37,38,32,39]),import.meta.url));function Mb({sidePanel:e,onClose:t,project:n,projectId:r,site:i,files:a,currentUserId:o,comments:s,commentDraftStore:c,commentsLoading:l,commentsError:u,onRetryComments:d,unreadMentions:f,activeFile:m,singleCommentId:h,onShowAllComments:g,hasProjectCommentsScope:_,commentScope:v,onCommentScopeChange:y,focusedCommentId:b,commentFocusNonce:S,onMarkMentionRead:w,onMarkAllMentionsRead:T,onClearFocusComment:E,targetCommentId:D,targetReplyId:O,onFocusComment:k,onToggleComment:A,onReplyComment:j,onEditComment:M,onDeleteComment:ee,onEditCommentReply:P,onDeleteCommentReply:F,dictionaryWords:ne,onDictionaryChange:re,editorPreferences:ie,onEditorPreferences:ae,spellCheckCount:oe,spellCheckUniqueCount:I,spellCheckIndex:se,onSpellCheckNavigate:ce,onProject:L}){let{t:R}=Ee(),z=!!h,[B,le]=(0,Y.useState)(`unresolved`),[V,ue]=(0,Y.useState)(!1),[de,fe]=(0,Y.useState)(`source`),pe=R(de===`time`?`editor.commentSortTime`:v===`project`?`editor.commentSortSourceProject`:`editor.commentSortSource`),[me,he]=(0,Y.useState)(()=>new Set),[H,ge]=(0,Y.useState)(!0),[_e,U]=(0,Y.useState)(()=>new Map),[W,G]=(0,Y.useState)(null),ve=(0,Y.useRef)(new Map(s.map(e=>[e.id,e.resolved]))),ye=(0,Y.useMemo)(()=>u_(s),[s]),K=(0,Y.useMemo)(()=>{let e=s.filter(e=>p_(e,{activeFile:m,scope:v})),t=e.filter(e=>e.resolved).length;return{unresolved:e.length-t,resolved:t}},[m,v,s]),be=(0,Y.useMemo)(()=>g_(s,{activeFile:m,scope:v,unreadMentions:f,participantIds:me,topLevelOnly:H,filter:B,unreadMentionsOnly:!0}).length,[m,v,s,f,me,H,B]),xe=(0,Y.useMemo)(()=>h?v_(s,h,m):__(s,{activeFile:m,scope:v,filter:B,unreadMentions:f,sort:de,participantIds:me,topLevelOnly:H,unreadMentionsOnly:V},[D,b]),[m,h,B,v,s,b,D,f,de,me,H,V]),Se=b&&xe.some(e=>e.id===b)?b:D&&xe.some(e=>e.id===D)?D:null,Ce=z?xe[0]?.id??null:W&&xe.some(e=>e.id===W)?W:Se;(0,Y.useEffect)(()=>{G(null)},[b,S,D,O,m,v]),(0,Y.useEffect)(()=>{W&&!xe.some(e=>e.id===W)&&G(null)},[W,xe]);let q=S_(xe,Ce),we=JSON.stringify([e,h,v,v===`file`?m:``,B,de,[...me].sort(),H,V]),Te=JSON.stringify([r,v,v===`file`?m:``,B,de,[...me].sort(),H,V]),{shown:De,hasMore:ke,loadMore:Ae}=Ab(xe,!z&&B===`resolved`,Te,[D,b,W]),{entries:je,finishExit:Me}=kb(De,s,z?`unresolved`:B,we);(0,Y.useEffect)(()=>{let e=s.some(e=>(e.id===b||e.id===D)&&ve.current.has(e.id)&&ve.current.get(e.id)!==e.resolved);ve.current=new Map(s.map(e=>[e.id,e.resolved])),e&&E()},[s,b,D,E]),(0,Y.useEffect)(()=>{if(e!==`comments`||W)return;let t=D&&O?`.comments [data-comment-reply-id="${O}"]`:D?`.comments .comment-thread[data-comment-id="${D}"]`:Se?`.comments .comment-thread[data-comment-id="${Se}"]`:``;if(!t)return;let n=document.querySelector(t);if(!n)return;let r=window.requestAnimationFrame(()=>n.scrollIntoView({block:D?`center`:`nearest`,behavior:`smooth`}));return()=>window.cancelAnimationFrame(r)},[e,W,Se,S,D,O,xe]);let Ne=e=>{G(null),k(e)},Pe=e=>{let t=C_(xe,Ce,e);t?Ne(t):E()},Fe=async e=>{let t=await w(e);if(!t||z||!V)return t;let n=f.find(t=>t.id===e)?.commentId;return n&&(f.some(t=>t.id!==e&&t.commentId===n)||(b===n||D===n)&&E()),t},Ie=async()=>{await T()&&V&&E()},J=e=>{e!==v&&(G(null),E(),y(e))},Le=e=>{e!==B&&(G(null),E(),le(e))},Re=()=>{G(null),E()};return e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Fm,{className:`resize-handle`}),(0,X.jsx)(Am,{id:`context`,defaultSize:`20%`,minSize:`15%`,maxSize:`38%`,children:(0,X.jsxs)(`aside`,{className:`context-panel`,children:[e===`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&&f.length>0&&(0,X.jsxs)(`button`,{className:`drawer-mention-read-all`,type:`button`,onClick:()=>void Ie(),title:R(`editor.markAllMentionsRead`),children:[(0,X.jsx)(C,{"aria-hidden":!0,size:13}),(0,X.jsx)(`span`,{children:R(`editor.markAllMentionsRead`)})]}),(0,X.jsx)(`button`,{"aria-label":R(`common.close`),onClick:t,children:(0,X.jsx)(te,{size:17})})]})]}),z?(0,X.jsx)(`div`,{className:`comment-current-controls`,children:(0,X.jsxs)(`button`,{type:`button`,onClick:g,children:[(0,X.jsx)(Jt,{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:[_&&(0,X.jsxs)(`div`,{className:`comment-review-group`,role:`group`,"aria-label":R(`editor.commentScope`),children:[(0,X.jsx)(`button`,{type:`button`,className:v===`file`?`active`:``,"aria-pressed":v===`file`,onClick:()=>J(`file`),children:R(`editor.commentScopeFile`)}),(0,X.jsx)(`button`,{type:`button`,className:v===`project`?`active`:``,"aria-pressed":v===`project`,onClick:()=>J(`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:()=>Le(`unresolved`),children:R(`editor.commentFilterUnresolved`,{count:K.unresolved})}),(0,X.jsx)(`button`,{type:`button`,className:B===`resolved`?`active`:``,"aria-pressed":B===`resolved`,onClick:()=>Le(`resolved`),children:R(`editor.commentFilterResolved`,{count:K.resolved})})]}),(0,X.jsxs)(`div`,{className:`comment-review-navigation`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:q<=1,"aria-label":R(`editor.commentPrevious`),title:R(`editor.commentPrevious`),onClick:()=>Pe(-1),children:(0,X.jsx)(x,{size:14})}),(0,X.jsx)(`output`,{"aria-live":`polite`,children:R(`editor.commentPosition`,{current:q,total:xe.length})}),(0,X.jsx)(`button`,{type:`button`,disabled:xe.length===0||q>0&&q>=xe.length,"aria-label":R(`editor.commentNext`),title:R(`editor.commentNext`),onClick:()=>Pe(1),children:(0,X.jsx)(N,{size:14})})]})]}),(0,X.jsxs)(`div`,{className:`comment-review-sort-row`,children:[(0,X.jsx)(Db,{participants:ye,selectedIds:me,topLevelOnly:H,onToggle:e=>{Re(),me.size===1&&me.has(e)&&ge(!0),he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},onClear:()=>{Re(),he(new Set),ge(!0)},onTopLevelOnlyChange:e=>{Re(),ge(e)}},`${v}:${v===`file`?m:`project`}`),(0,X.jsxs)(`button`,{type:`button`,className:`comment-unread-toggle${V?` active`:``}`,"aria-pressed":V,"aria-label":R(`editor.commentUnreadMentionsHint`),title:R(`editor.commentUnreadMentionsHint`),onClick:()=>{Re(),ue(e=>!e)},children:[(0,X.jsx)(C,{size:12,"aria-hidden":!0}),R(`editor.commentUnreadMentionsOnly`),(0,X.jsx)(`span`,{children:be})]}),(0,X.jsxs)(`label`,{className:`comment-review-sort`,"data-texlite-tooltip-always":!0,"data-tooltip":pe,children:[(0,X.jsx)(`span`,{className:`sr-only`,children:R(`editor.commentSort`)}),de===`source`?(0,X.jsx)(p,{size:12,"aria-hidden":!0}):(0,X.jsx)(mt,{size:12,"aria-hidden":!0}),(0,X.jsxs)(`select`,{value:de,"aria-label":`${R(`editor.commentSort`)}: ${pe}`,onChange:e=>{Re(),fe(e.target.value)},children:[(0,X.jsx)(`option`,{value:`source`,children:R(`editor.commentSortSourceShort`)}),(0,X.jsx)(`option`,{value:`time`,children:R(`editor.commentSortTimeShort`)})]})]})]})]}),u&&(0,X.jsxs)(`div`,{className:`comment-review-error`,role:`alert`,children:[(0,X.jsx)(`span`,{children:u}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>void d(),children:R(`common.retry`)})]}),l&&(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=f.find(t=>t.commentId===e.id&&!t.replyId)?.id,i=new Map(f.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&&Me(e.id)},children:(0,X.jsx)(`div`,{className:`comment-thread-slot-content`,children:(0,X.jsx)(vb,{projectId:r,comment:e,draftStore:c,currentUserId:o,unreadCommentMentionId:n,unreadReplyMentionIds:i,highlightedComment:D===e.id&&!O,highlightedReplyId:D===e.id?O:null,currentComment:Ce===e.id,showFilePath:!z&&v===`project`&&_,replyExpansion:_e.get(e.id),onReplyExpansionChange:t=>{U(n=>n.get(e.id)===t?n:new Map(n).set(e.id,t))},selectedParticipantIds:z?void 0:me,highlightReplyParticipants:!z&&!H,onMarkMentionRead:Fe,onFocus:()=>Ne(e),onActivate:()=>G(e.id),onToggle:()=>A(e),onReply:t=>j(e,t),onEdit:t=>M(e,t),onDelete:()=>ee(e),onEditReply:(t,n)=>P(e,t,n),onDeleteReply:t=>F(e,t)})})},e.id)}),je.length===0&&!l&&!u&&(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)(Jt,{size:23,strokeWidth:1.5})}),(0,X.jsx)(`p`,{children:z?R(s.some(e=>e.id===h&&e.resolved)?`editor.currentCommentResolved`:`editor.currentCommentUnavailable`):K.unresolved+K.resolved>0?R(`editor.commentNoMatches`):R(`editor.noComments`)})]}),!z&&B===`resolved`&&ke&&(0,X.jsx)(`div`,{className:`comment-review-pagination`,children:(0,X.jsx)(`button`,{type:`button`,onClick:Ae,children:R(`editor.commentLoadMore`)})})]})]}),e===`settings`&&(0,X.jsx)(Oe,{onClose:t,children:(0,X.jsx)(jb,{onClose:t,project:n,projectId:r,site:i,files:a,dictionaryWords:ne,onDictionaryChange:re,editorPreferences:ie,onEditorPreferences:ae,spellCheckCount:oe,spellCheckUniqueCount:I,spellCheckIndex:se,onSpellCheckNavigate:ce,onProject:L},r)})]})})]}):null}function Nb(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 Pb(){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=Nb(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 Fb(e,t,n){return e.mainFile===t?e.items:!t||n.filePath!==t?[]:Ib(n.content).map(e=>({...e,path:t}))}function Ib(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 Lb=e({ProjectWorkspace:()=>Wb}),Rb=(0,Y.lazy)(()=>f(()=>import(`./AgentTerminal-BXH3gHWm.js`).then(e=>({default:e.AgentTerminal})),__vite__mapDeps([40,2,3,7,13,6,1,4,5,8,14,15,41,16,42,43,20,39]),import.meta.url)),zb=(0,Y.lazy)(()=>f(()=>import(`./WordCountDialog-DaHxqArj.js`).then(e=>({default:e.WordCountDialog})),__vite__mapDeps([44,3,2,13,6,1,4,5,7,8,38]),import.meta.url)),Bb=null;function Vb(){return Bb||=f(()=>import(`./citationLibrary-BzlqZiFU.js`),__vite__mapDeps([21,2]),import.meta.url).catch(e=>{throw Bb=null,e}),Bb}function Hb(e){return e instanceof Error&&e.name===`AbortError`}var Ub=300;function Wb(e){return(0,X.jsx)(T_,{children:(0,X.jsx)(ny,{projectId:e.projectId,user:e.user,children:t=>(0,X.jsx)(Gb,{...e,collaboration:t})})},`${e.user.id}:${e.projectId}`)}function Gb({site:e,user:t,projectId:n,preload:r,mentionId:i=null,onMentionTargeted:a,onMentionsRead:o,onBack:s,collaboration:c}){let{t:u}=Ee(),d=(0,Y.useRef)(n),f=ce(t.id,n),[p,m]=(0,Y.useState)(!1);d.current=n;let[h,_]=(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,y]=(0,Y.useState)(!1),[b,x]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(null),[w,T]=(0,Y.useState)({mainFile:``,items:[]}),[E,D]=(0,Y.useState)(``),[O,k]=(0,Y.useState)(``),[A,j]=(0,Y.useState)(``),[M,N]=(0,Y.useState)({filePath:``,content:``}),[ee,P]=(0,Y.useState)({path:``,hasIncludes:!1}),[F,ne]=(0,Y.useState)(``),[re,ie]=(0,Y.useState)(!1),[ae,oe]=(0,Y.useState)(`editor.saved`),[I,se]=(0,Y.useState)(null),L=(0,Y.useRef)(I);L.current=I;let R=(0,Y.useRef)(null);R.current||=Pb();let z=R.current,[le,V]=(0,Y.useState)(`pdf`),[ue,de]=(0,Y.useState)(`log`),fe=e=>{e===`pdf`?V(`pdf`):(e===`diagnostics`||de(e),V(`diagnostics`))},{workspaceLayout:pe,setWorkspaceLayout:me}=Ty(t.id,n),[he,H]=(0,Y.useState)(``),[ge,_e]=(0,Y.useState)(``),[G,ve]=(0,Y.useState)({selectedText:``,startOffset:0,endOffset:0}),ye=(0,Y.useRef)({selectedText:``,startOffset:0,endOffset:0}),K=e=>{let t=ye.current;(t.selectedText!==e.selectedText||t.startOffset!==e.startOffset||t.endOffset!==e.endOffset)&&(ye.current=e,ve(e))},[be,xe]=(0,Y.useState)(null),[Se,q]=(0,Y.useState)(null),[we,De]=(0,Y.useState)(null),[Oe,ke]=(0,Y.useState)(null),[Me,Ne]=(0,Y.useState)(null),[Pe,Fe]=(0,Y.useState)(!1),[Ie,J]=(0,Y.useState)(!1),[Le,Re]=(0,Y.useState)(!1),[ze,Be]=(0,Y.useState)(!1),[Ve,He]=(0,Y.useState)(null),[Ue,We]=(0,Y.useState)(!1),[Ge,Ke]=(0,Y.useState)(null),[qe,Je]=(0,Y.useState)(!1),[Ye,Xe]=(0,Y.useState)(!1),[Ze,Qe]=(0,Y.useState)(`full`),[$e,et]=(0,Y.useState)(``),[tt,nt]=(0,Y.useState)(!1),[rt,it]=(0,Y.useState)(``),[at,ot]=(0,Y.useState)(null),[st,ct]=(0,Y.useState)(!1),[lt,ut]=(0,Y.useState)(null),[dt,ft]=(0,Y.useState)(!1),[pt,mt]=(0,Y.useState)(()=>ed(t.id,n));(0,Y.useEffect)(()=>{let e=document.documentElement,t=pt.showTooltips?`on`:`off`;return e.setAttribute(`data-texlite-tooltips`,t),()=>{e.getAttribute(`data-texlite-tooltips`)===t&&e.removeAttribute(`data-texlite-tooltips`)}},[pt.showTooltips]);let[ht,gt]=(0,Y.useState)([]),_t=(0,Y.useRef)([]);_t.current=ht;let vt=(0,Y.useRef)(null),yt=(0,Y.useRef)(null),bt=(0,Y.useRef)(0),xt=(0,Y.useRef)(0),St=(0,Y.useRef)(``),Ct=(0,Y.useRef)(``),wt=(0,Y.useRef)(()=>void 0),Tt=(0,Y.useRef)(pe),Et=(0,Y.useRef)(0),Dt=(0,Y.useRef)(null),Ot=(0,Y.useRef)(null),kt=(0,Y.useRef)(null),At=(0,Y.useRef)(null),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)(!1),Lt=(0,Y.useRef)(null),zt=(0,Y.useRef)(s),Bt=(0,Y.useRef)(a),Vt=(0,Y.useRef)(o);zt.current=s,Bt.current=a,Vt.current=o,St.current=E,Ct.current=O,Tt.current=pe,(0,Y.useEffect)(()=>{if(!ge)return;let e=window.setTimeout(()=>_e(``),3e3);return()=>window.clearTimeout(e)},[ge]);let Ht=(0,Y.useCallback)((e,t,n=0)=>{z.update(e,t,n)},[z]);(0,Y.useEffect)(()=>()=>z.dispose(),[z]),(0,Y.useEffect)(()=>()=>{Pt.current?.abort(),Pt.current=null},[]);let Ut=e=>{let t=_t.current,n=e(t);n!==t&&(_t.current=n,gt(n))};(0,Y.useEffect)(()=>{_t.current=[],gt([]),ut(null),He(null),Mt.current?.abort(),Mt.current=null,Nt.current?.abort(),Nt.current=null,Pt.current?.abort(),Pt.current=null,Ft.current=null,De(null),ke(null),Ne(null),Xe(!1),nt(!1),it(``),ot(null)},[n]);let Wt=e=>{let t=_t.current,n=t.indexOf(e);if(n<0)return;let r=t.filter(t=>t!==e);if(_t.current=r,gt(r),St.current!==e)return;let i=r.length>0?r[Math.min(n,r.length-1)]:h?.mainFile??``;D(i)},{status:Gt,synced:Kt,activeSessions:qt,formatLeaseStates:Jt,compileState:Yt,setCompileState:Xt,filesEvent:Zt,commentsRevision:Qt,historyWarning:$t,dictionaryRevision:en,chktexSettingsRevision:tn,localDraftReady:nn,permission:rn,reconnect:an,protocolUpgradeRequired:on,permissionDowngrade:sn,dismissPermissionDowngrade:cn,discardLocalDraft:ln}=D_(c,O,h?.permission??`read`,v),{unreadMentions:un,mentionsError:dn,markMentionRead:fn,markAllMentionsRead:pn}=w_(n,Qt,H,(e,t)=>Vt.current?.(e,t)),{pdfTarget:mn,pdfViewport:hn,sourceJump:gn,setPdfViewport:_n,resetPdfViewport:vn,clearPdfViewport:yn,jumpToSource:bn,syncSourceToPdf:xn,syncPdfToSource:Sn,syncVisiblePdfToSource:wn}=Sy({projectId:n,mainFile:O,activeFile:E,onOpenSourceFile:e=>wt.current(e),onError:H,onShowPdf:()=>fe(`pdf`),onShowEditor:()=>{Tt.current===`pdf-only`&&me(`editor-pdf`)}}),Tn=!!(h&&h.chktexEnabled&&E&&Kt&&qd(E)),En=yy({active:Tn,projectId:n,activeFile:E,content:A}),Dn=vy({active:!!(h&&E&&Kt&&Kd(E)&&(pt.spellCheck||h.chktexEnabled&&qd(E))),harperEnabled:pt.spellCheck,projectId:n,activeFile:E,content:A,dictionaryWords:b,additionalIssues:En.issues,additionalIssuesReady:!Tn||En.checked});(0,Y.useEffect)(()=>{mt(ed(t.id,n))},[t.id,n]);let On=e=>{j(e)};(0,Y.useEffect)(()=>{if(!E||F!==E){N(e=>e.filePath||e.content?{filePath:``,content:``}:e);return}let e=E,t=A,n=window.setTimeout(()=>{N(n=>n.filePath===e&&n.content===t?n:{filePath:e,content:t})},Ub);return()=>window.clearTimeout(n)},[E,F,A]),(0,Y.useEffect)(()=>{St.current=E,z.reset(),K({selectedText:``,startOffset:0,endOffset:0}),pt.openFilesInTabs?E&&Ut(e=>e.includes(E)?e:[...e,E]):_t.current.length>0&&(_t.current=[],gt([]))},[E,pt.openFilesInTabs,n,z]),(0,Y.useEffect)(()=>{if(!re)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[re]),(0,Y.useEffect)(()=>{if(Gt!==`disconnected`)return;let e=new AbortController;return W(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||(_(t),H(``))}).catch(e=>{Hb(e)||(e instanceof Ce&&[401,403,404].includes(e.status)?(H(U(e)),zt.current()):H(u(`errors.collaborationUnavailable`)))}),()=>e.abort()},[Gt,n,u]);let kn=async(e={},t=Ct.current)=>{Dt.current?.abort(),Dt.current=null;let r=e.signal?null:new AbortController;r&&(Dt.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await W(`/api/projects/${n}/completions${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&C(a.index)}catch(t){if(Hb(t))return;(!e.isCurrent||e.isCurrent())&&C(null)}finally{r&&Dt.current===r&&(Dt.current=null)}},An=async(e={},t=Ct.current)=>{kt.current?.abort(),kt.current=null;let r=e.signal?null:new AbortController;r&&(kt.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await W(`/api/projects/${n}/outline${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&Ct.current===t&&T({mainFile:t,items:a.outline})}catch(e){if(Hb(e))return}finally{r&&kt.current===r&&(kt.current=null)}},jn=async(e={})=>{At.current?.abort(),At.current=null;let t=e.signal?null:new AbortController;t&&(At.current=t);try{let r=await W(`/api/projects/${n}/dictionary`,{signal:e.signal??t?.signal});(!e.isCurrent||e.isCurrent())&&x(r.words)}catch(t){if(Hb(t))return;(!e.isCurrent||e.isCurrent())&&x([])}finally{t&&At.current===t&&(At.current=null)}};(0,Y.useEffect)(()=>{let e=!1,t=++Et.current,i=new AbortController,a=()=>!e&&Et.current===t,o=!1,s=``;_(null),Un([]),T({mainFile:``,items:[]}),D(``),k(``),P({path:``,hasIncludes:!1}),j(``),ne(``),Xt(null),yn(),C(null),x([]),Ae();let c=(r?.projectId===n?r.project:W(`/api/projects/${n}`,{signal:i.signal})).then(e=>{a()&&(o=!0,s=e.project.mainFile,_(e.project),D(e.project.mainFile),Ct.current=e.project.mainFile,k(e.project.mainFile),ur(new Set(dy(e.project.mainFile))))}).catch(e=>{a()&&H(U(e))}),l=W(`/api/projects/${n}/files`,{signal:i.signal}).then(e=>{a()&&Un(e.files)}).catch(e=>{a()&&H(U(e))}),u=null;return Promise.allSettled([c,l]).then(()=>{a()&&o&&(u=window.setTimeout(()=>{a()&&Promise.all([kn({signal:i.signal,isCurrent:a},Ct.current||s),jn({signal:i.signal,isCurrent:a})])},0))}),()=>{e=!0,u!==null&&window.clearTimeout(u),i.abort(),Dt.current?.abort(),Dt.current=null,kt.current?.abort(),kt.current=null,At.current?.abort(),At.current=null,jt.current?.abort(),jt.current=null}},[n,r]),(0,Y.useEffect)(()=>{h&&O&&(Ot.current===n?kn({},O):Ot.current=n)},[O,h?.id,n]),(0,Y.useEffect)(()=>{if(!i||!h)return;Nt.current?.abort();let e=new AbortController;return Nt.current=e,W(`/api/projects/${n}/mentions/${encodeURIComponent(i)}`,{signal:e.signal}).then(({mention:t})=>{e.signal.aborted||(De(t),q(null),xe(`comments`),D(t.filePath),Bt.current?.(t.id))}).catch(t=>{Hb(t)||e.signal.aborted||(H(U(t)),Bt.current?.(i))}).finally(()=>{Nt.current===e&&(Nt.current=null)}),()=>e.abort()},[i,h?.id,n]),(0,Y.useEffect)(()=>{en&&jn()},[en,n]),(0,Y.useEffect)(()=>{if(!tn)return;let e=new AbortController;return W(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||_(e=>e?{...e,chktexEnabled:t.chktexEnabled}:t)}).catch(e=>{Hb(e)||H(U(e))}),()=>e.abort()},[tn,n]),(0,Y.useEffect)(()=>{h&&Gt===`connected`&&rn!==h.permission&&_(e=>e&&{...e,permission:rn})},[rn,h?.permission]),(0,Y.useEffect)(()=>{if(!Zt)return;let t=Zt.kind===`delete`&&!!Zt.path&&fy(Zt.path,St.current),r=Zt.kind===`delete`&&!!Zt.path&&fy(Zt.path,Ct.current);if(Zt.kind===`move`&&Zt.source&&Zt.destination){let e=Zt.source,t=Zt.destination,n=n=>n===e?t:n.startsWith(`${e}/`)?`${t}${n.slice(e.length)}`:n;D(e=>n(e)),k(e=>n(e)),or(e=>e&&n(e)),cr(e=>e&&n(e)),Ut(e=>e.map(n))}t&&(D(``),ne(``),On(``),_e(u(`editor.fileDeletedByCollaborator`,{path:Zt.path}))),Zt.kind===`delete`&&Zt.path&&(or(e=>e&&fy(Zt.path,e)?null:e),cr(e=>fy(Zt.path,e)?``:e),Xn(e=>e&&fy(Zt.path,e.path)?null:e),Ut(e=>e.filter(e=>!fy(Zt.path,e)))),jt.current?.abort();let i=new AbortController;jt.current=i,Promise.all([Wn({signal:i.signal}),W(`/api/projects/${n}`,{signal:i.signal})]).then(([n,a])=>{if(_(a.project),r&&k(a.project.mainFile),t&&n){let t=n.find(e=>e.type===`file`&&e.path===a.project.mainFile)??n.find(t=>t.type===`file`&&Cn(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024);D(t?.path??``)}kn({signal:i.signal}),An({signal:i.signal},r?a.project.mainFile:Ct.current)}).catch(e=>{Hb(e)}).finally(()=>{jt.current===i&&(jt.current=null)})},[Zt?.revision]),(0,Y.useEffect)(()=>{if(c.setActiveFile(E),!E)return;ne(``),oe(`editor.loading`);let e=c.getText(E),t=(t,n)=>{On(e.toString()),ne(E),n?.local&&h?.permission!==`read`?(bt.current+=1,ie(!0),oe(`editor.pending`)):bt.current<=xt.current&&oe(L.current?`editor.savedAt`:`editor.saved`)};return e.observe(t),(Kt||nn)&&t(),()=>{e.unobserve(t)}},[E,c,Kt,nn,h?.permission]);let Mn=async()=>{if(!Kt)throw Error(`Collaboration is not synchronized`);let e=bt.current,t=await c.flush();return xt.current=Math.max(xt.current,e),se(t.persistedAt),/\.tex$/i.test(St.current)&&An(),bt.current===e?(ie(!1),oe(`editor.savedAt`)):oe(`editor.pending`),t};(0,Y.useEffect)(()=>{if(!re||!E||!Kt)return;oe(`editor.pending`);let e=window.setTimeout(()=>{oe(`editor.saving`),Mn().catch(()=>{oe(`editor.saveFailed`)})},750);return()=>window.clearTimeout(e)},[A,re,E,Kt]);let Nn=async()=>{if(!h||h.permission===`read`||!Kt||!E)return!1;oe(`editor.saving`);try{return await Mn(),kn(),!0}catch(e){return oe(`editor.saveFailed`),H(U(e)||u(`errors.collaborationUnavailable`)),!1}},Pn=async e=>{if(!h||tt)return;let t=e===`full`?Ct.current||h.mainFile:St.current,r=e===`selection`?ye.current.selectedText:``;if(!t)return;if(e===`selection`&&(!r.trim()||!/\.(?:tex|sty|cls)$/i.test(t))){_e(u(`editor.wordCountSelectionEmpty`));return}Mt.current?.abort();let i=new AbortController;Mt.current=i,Qe(e),et(t),ot(null),it(``),Xe(!0),nt(!0);try{if(e===`full`&&re&&h.permission!==`read`&&!await Nn())throw Error(u(`editor.wordCountSaveRequired`));let a=e===`selection`?{mode:e,path:t,source:r}:{mode:e,mainFile:t},o=await W(`/api/projects/${n}/word-count`,{method:`POST`,body:JSON.stringify(a),signal:i.signal});if(i.signal.aborted)return;ot(o)}catch(e){if(Hb(e))return;i.signal.aborted||it(U(e))}finally{Mt.current===i&&(Mt.current=null,nt(!1))}},Fn=async(t,n,r=pt.texFmtConfig)=>{if(/\.bib$/i.test(t))try{return{formatted:await hh(n,e.maxCitationBibtexBytes)}}catch(t){throw t instanceof uh?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 eh(n,r)).output}},In=async(e,t,n,r=0)=>{if(!/\.bib$/i.test(e))return oh(t,n,r);try{return await gh(t,n,r)}catch(e){throw e instanceof uh?Error(u(e.kind===`timeout`?`editor.bibtexFormatterTimeout`:`editor.bibtexFormatterUnavailable`)):e}},Ln=async e=>{if(!h||h.permission===`read`||!Kt||It.current||!rh(St.current))return;let t=St.current,n=c.getText(t);It.current=!0,ct(!0);let r=()=>{},i=new Promise(e=>{r=e});Lt.current=i;let a=null;try{a=await c.acquireFormatLease(t);let r=n.toString(),{formatted:i}=await Fn(t,r,e);if(St.current!==t||n.toString()!==r){H(u(`editor.formatSourceChanged`));return}await a.confirm();let o=await In(t,r,i);if(St.current!==t||n.toString()!==r||(await a.confirm(),St.current!==t||n.toString()!==r)){H(u(`editor.formatSourceChanged`));return}o.length&&c.applyTextEdits(t,o),o.length&&await Mn(),ut(null),H(``),_e(u(`editor.formatFileComplete`))}catch(e){Ym(e)?(ut({action:`file`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFileFailed`,{message:U(e)}))}finally{a&&await a.release(),It.current=!1,ct(!1),r(),Lt.current===i&&(Lt.current=null)}},Rn=async()=>{if(!pt.formatOnCompile||!h||h.permission===`read`||!Kt||!rh(St.current)||It.current)return;let e=St.current,t=c.getText(e);It.current=!0,ct(!0);let n=null;try{n=await c.acquireFormatLease(e);let r=t.toString(),{formatted:i}=await Fn(e,r);await n.confirm();let a=await In(e,r,i);if(St.current!==e||t.toString()!==r||(await n.confirm(),St.current!==e||t.toString()!==r))throw Error(u(`editor.formatSourceChanged`));a.length&&c.applyTextEdits(e,a),a.length&&await c.flush(),ut(null)}catch(e){Ym(e)?(ut({action:`file`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFailedContinue`,{message:U(e)}))}finally{n&&await n.release(),It.current=!1,ct(!1)}},zn=async()=>(Lt.current&&await Lt.current,await Rn(),Nn()),Bn=async e=>{if(!h||h.permission===`read`||!Kt||It.current||!rh(St.current))return;let t=ye.current;if(!t.selectedText.trim()){_e(u(`editor.formatSelectionRequired`));return}let n=St.current,{startOffset:r,endOffset:i,selectedText:a}=t,o=c.getText(n);if(o.toString().slice(r,i)!==a){H(u(`editor.formatSelectionChanged`));return}It.current=!0,ct(!0);let s=()=>{},l=new Promise(e=>{s=e});Lt.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=ah(a,(await Fn(n,a,e)).formatted);await d.confirm();let s=await In(n,a,t,r);if(St.current!==n||o.toString().slice(r,i)!==a||(await d.confirm(),St.current!==n||o.toString().slice(r,i)!==a)){H(u(`editor.formatSelectionChanged`));return}s.length&&c.applyTextEdits(n,s),s.length&&await Mn(),ut(null),H(``),_e(u(`editor.formatSelectionComplete`))}catch(e){Ym(e)?(ut({action:`selection`,kind:e.kind,detail:e.message}),H(``)):H(u(`editor.formatFailed`,{message:U(e)}))}finally{d&&await d.release(),It.current=!1,ct(!1),s(),Lt.current===l&&(Lt.current=null)}},Vn=async t=>{let n=St.current;if(!/\.bib$/i.test(n)||h?.permission===`read`||!Kt)return _e(u(`citationLibrary.importRequiresWrite`)),!1;let r=c.getText(n),i;try{i=await Vb()}catch(e){return H(U(e)),!1}if(St.current!==n||!Kt)return!1;let a=r.toString(),o=i.parseBibEntriesResult(a,e.maxCitationBibtexBytes);if(o.status===`too-large`)return _e(u(`citationLibrary.fileTooLarge`,{size:i.citationBibtexLimitLabel(e.maxCitationBibtexBytes)})),!1;if(o.status===`invalid`)return _e(u(`citationLibrary.fileInvalid`)),!1;if(o.entries.some(e=>e.citationKey.toLowerCase()===t.citationKey.toLowerCase()))return _e(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}`}]),_e(u(`citationLibrary.imported`,{key:t.citationKey})),!0},{files:Hn,setFiles:Un,loadFiles:Wn,newFileOpen:Gn,setNewFileOpen:Kn,newFilePath:qn,setNewFilePath:Jn,resourcePreview:Yn,setResourcePreview:Xn,resourcePreviewLoading:Zn,setResourcePreviewLoading:Qn,newFolderOpen:$n,setNewFolderOpen:er,newFolderName:tr,setNewFolderName:nr,fileDialogError:rr,setFileDialogError:ir,selectedFolder:ar,setSelectedFolder:or,selectedFile:sr,setSelectedFile:cr,expandedFolders:lr,setExpandedFolders:ur,moveEntry:dr,setMoveEntry:fr,moveName:pr,setMoveName:mr,moveDestination:hr,setMoveDestination:gr,deleteEntry:_r,setDeleteEntry:vr,fileDragActive:yr,setFileDragActive:br,uploadConflict:xr,setUploadConflict:Sr,uploadingFiles:Cr,uploadFeedback:wr,dismissUploadFeedback:Tr,directoryEntries:Er,visibleEntries:Z,createFile:Dr,createFolder:Or,uploadFiles:kr,upload:Ar,openFile:jr,movePath:Mr,movePathToFolder:Nr,removePath:Pr}=gy({projectId:n,site:e,activeFile:E,dirty:re,save:Nn,onError:H,onProject:_,onActiveFile:D,onActiveMainFile:k});wt.current=e=>{or(null),cr(e),ur(t=>new Set([...t,...dy(e)])),D(e)};let Fr=e=>{if(e.id!==d.current)return;let t=e.mainFile!==h?.mainFile;_(e),t&&(Ct.current=e.mainFile,St.current=e.mainFile,k(e.mainFile),D(e.mainFile),or(null),cr(e.mainFile),ur(t=>new Set([...t,...dy(e.mainFile)])))},Ir=()=>Ct.current||h?.mainFile||``,Lr=()=>{let e=Ir(),t=St.current;if(!t||!/\.tex$/i.test(t))return e;let n=Hn.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length;return Ay(c.getText(t).toString())||n===1?(e!==t&&(Ct.current=t,k(t)),t):e===t&&h?.mainFile&&h.mainFile!==t?(Ct.current=h.mainFile,k(h.mainFile),h.mainFile):e};(0,Y.useEffect)(()=>{E&&E===O&&F===E&&M.filePath===E&&E.toLocaleLowerCase().endsWith(`.tex`)&&Hn.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length!==0&&E!==h?.mainFile&&!Ay(M.content)&&h?.mainFile&&(Ct.current=h.mainFile,k(h.mainFile))},[E,O,F,M,Hn,h?.mainFile]),(0,Y.useEffect)(()=>{if(!pt.openFilesInTabs||Hn.length===0)return;let t=new Set(Hn.filter(t=>t.type===`file`&&Cn(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024).map(e=>e.path));Ut(e=>{let n=e.filter(e=>t.has(e));return n.length===e.length?e:n})},[Hn,pt.openFilesInTabs]);let{comments:Rr,projectCommentSummary:zr,commentsFilePath:Br,commentsReady:Vr,fileCommentsLoading:Hr,fileCommentsError:Ur,retryFileComments:Wr,reviewComments:Gr,reviewCommentsLoading:Kr,reviewCommentsError:qr,retryReviewComments:Jr,commentScope:Yr,setCommentScope:Xr,focusComment:Zr,setFocusComment:Qr,commentOpen:$r,openComment:ei,closeComment:ti,commentText:ni,setCommentText:Q,commentSelection:ri,commentSubmitting:ii,commentError:ai,addComment:oi,toggleComment:si,replyToComment:ci,editComment:li,deleteComment:ui,editCommentReply:di,deleteCommentReply:fi,commentDraftStore:pi,cancelComment:mi,commentDraftRestored:hi,commentDraftCanRetarget:gi,useCurrentCommentSelection:_i}=l_({projectId:n,activeFile:E,content:A,permission:h?.permission,revision:Qt,sourceOrderRevision:`${h?.mainFile??``}\0${Zt?.revision??``}`,selection:G,save:Nn,saveFailureMessage:u(`errors.collaborationUnavailable`),onError:H,onAdded:()=>{q(null),xe(`comments`)}});(0,Y.useEffect)(()=>{if(!O||M.filePath!==O)return;let e=Md(M.content).length>0;P(t=>t.path===O&&t.hasIncludes===e?t:{path:O,hasIncludes:e})},[O,M]),(0,Y.useEffect)(()=>{if(!O||!Kt||E===O)return;let e=c.getText(O),t=null,n=()=>{let t=Md(e.toString()).length>0;P(e=>e.path===O&&e.hasIncludes===t?e:{path:O,hasIncludes:t})},r=()=>{t!==null&&window.clearTimeout(t),t=window.setTimeout(()=>{t=null,n()},Ub)};return n(),e.observe(r),()=>{t!==null&&window.clearTimeout(t),e.unobserve(r)}},[E,O,c,Kt]);let vi=(0,Y.useMemo)(()=>ee.path===O&&ee.hasIncludes||!!zr?.filePaths.some(e=>e!==E),[O,ee,zr,E]),yi=e=>{Ne(null),xe(`comments`),Qr(null),ke(e),St.current!==e.filePath&&bn(e.filePath,e.startLine,1)},bi=(e,t=!1)=>{let n=Rr.find(t=>t.id===e&&t.filePath===E);!n||n.resolved||n.orphaned||(ke(null),Qr(null),De(null),t&&be===`comments`&&Se===n.id?(q(null),Ne(null),xe(null)):(q(n.id),Ne(e=>({id:n.id,filePath:n.filePath,nonce:(e?.nonce??0)+1})),xe(`comments`)))};(0,Y.useEffect)(()=>{Ne(null),q(null)},[E]),(0,Y.useEffect)(()=>{if(!Oe)return;let e=x_(Oe,E,F,Br,Vr,Rr);e?(Qr({...e}),ke(null)):Oe.filePath===E&&F===E&&Br===E&&Vr&&ke(null)},[E,Rr,Br,Vr,F,Oe,Qr]),(0,Y.useEffect)(()=>{if(!we||E!==we.filePath||be!==`comments`)return;let e=Rr.find(e=>e.id===we.commentId);if(!e||we.replyId&&!e.replies.some(e=>e.id===we.replyId)||Ft.current===we.id)return;Ft.current=we.id,yi(e);let t=window.setTimeout(()=>De(e=>e?.id===we.id?null:e),3e3);return()=>window.clearTimeout(t)},[E,Rr,be,we]);let{pdfUrl:xi,pdfCompiledAt:Si,pdfSizeBytes:Ci,pdfLoadingMode:wi,pdfLoading:Ti,compileLog:Ei,compileDiagnostics:Di,compileOutcome:Oi,artifacts:ki,artifactPreview:Ai,artifactLoading:ji,editorNotice:Mi,localCompiling:Ni,cancelling:Pi,cleaning:Fi,compile:Ii,cancelCompile:Li,cleanCompile:Ri,viewArtifact:zi,pdfDisplayed:Bi}=cy({projectId:n,project:h,mainFile:O,resolveCompileMainFile:Lr,getCurrentMainFile:Ir,initialLatest:r?.projectId===n?r.latestCompile:null,collaborationSynced:Kt,pdfVisible:le===`pdf`&&pe!==`editor-only`,sharedState:Yt,onSharedState:Xt,save:zn,loadOutline:(e,t)=>An({signal:e},t),onPreviewTab:fe,onError:H,onCompileStart:()=>{H(``),_e(``)},onCompileSuccess:()=>{let e=St.current;if(e){let t=z.getCursor();xn(e,t.line,t.column,{silent:!0})}},onPdfChanged:yn});(0,Y.useEffect)(()=>{if(!h||!O||!xi&&Ti)return;let e=window.setTimeout(()=>y(!0),xi?150:0);return()=>window.clearTimeout(e)},[h,Ti,xi]),(0,Y.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&!e.shiftKey&&e.key.toLocaleLowerCase()===`p`&&(e.preventDefault(),Je(!0))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let Vi=e=>{td(t.id,n,e),mt(e)},Hi=(e=!1)=>{let t=lt;if(!t)return;ut(null),H(``),e&&Vi({...pt,texFmtConfig:``});let n=e?``:void 0;t.action===`selection`?Bn(n):Ln(n)},Ui=async()=>{ft(!0);try{await ln()||(H(u(`editor.collaboration.permissionDowngradeOtherTabBlocked`)),ft(!1))}catch(e){H(U(e)),ft(!1)}},Wi=()=>{yt.current?.isCollapsed()?yt.current.expand():yt.current?.collapse()},Gi=(0,Y.useMemo)(()=>Fb(w,O,M),[w,O,M]),Ki=(0,Y.useMemo)(()=>_h(Ei,Oi),[Ei,Oi]),qi=pe!==`pdf-only`,Ji=pe!==`editor-only`,Yi=Oy(qi,Ji,!!be),Xi=e=>{me(e),e===`pdf-only`&&fe(`pdf`)},Zi=(0,Y.useCallback)(e=>{Pt.current?.abort();let t=new AbortController;Pt.current=t;let r=St.current,i=Ct.current,a=new URLSearchParams({kind:e.kind,key:e.key,...r?{path:r}:{},...i?{mainFile:i}:{}});W(`/api/projects/${n}/references/resolve?${a}`,{signal:t.signal}).then(({target:n})=>{t.signal.aborted||St.current!==r||Ct.current!==i||(n?(Tt.current===`pdf-only`&&Xi(`editor-pdf`),bn(n.path,n.line,n.column)):H(u(e.kind===`citation`?`editor.citationTargetNotFound`:`editor.labelTargetNotFound`,{key:e.key})))}).catch(e=>{!t.signal.aborted&&!Hb(e)&&H(U(e))}).finally(()=>{Pt.current===t&&(Pt.current=null)})},[bn,n,u]),Qi=_r?qt.filter(e=>e.filePath&&fy(_r.path,e.filePath)):[];if(!h)return(0,X.jsxs)(`div`,{className:`center-card`,children:[(0,X.jsx)(`p`,{children:he||u(`common.loading`)}),he&&(0,X.jsx)(`button`,{className:`primary`,onClick:s,children:u(`editor.backToProjects`)})]});let $i=h.permission===`read`||!Kt,ea=Jt.find(e=>e.path===E),ta=ea&&!st?ea:null,na=(e,t)=>{if($i)return;let n=St.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(U(e))}}},ra=Yt?.mainFile===O&&(Yt.status===`queued`||Yt.status===`running`),ia=Ni||ra||Fi,aa=E?c.getText(E):null,oa=Si?B(Si,l.resolvedLanguage,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`}):``,sa=O.split(`/`).at(-1)??O,ca=Ki.warnings.length+Ki.errors.length+ki.length,la=xi?`${xi}${xi.includes(`?`)?`&`:`?`}download=1`:``,ua=O||h.mainFile,da=xy(E,ua),fa=!!(ua&&/\.tex$/i.test(ua)),pa=e=>{let t=Hn.find(t=>t.path===e);t&&Cn(t.path,t.textContent)?jr(t):Wt(e)},ma=e=>{document.getElementById(`editor-tab-${encodeURIComponent(e)}`)?.focus()},ha=(e,t)=>{if(![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key))return;e.preventDefault();let n=e.key===`Home`?0:e.key===`End`?ht.length-1:(t+(e.key===`ArrowLeft`?-1:1)+ht.length)%ht.length,r=ht[n];r&&(pa(r),window.requestAnimationFrame(()=>ma(r)))},ga=ia?ra?Yt?.status===`queued`?u(`editor.compileQueued`):u(`editor.compilingBy`,{name:Yt?.requestedBy.name??u(`common.user`)}):u(`editor.compiling`):Oi===`failed`?xi&&Si?u(`editor.compileFailedRetained`,{time:B(Si,l.resolvedLanguage)}):u(`editor.compileFailedNoPdf`):Oi===`cancelled`?u(`compileControls.cancelled`):``,_a=Py(Gt,ae,Gt===`disconnected`&&(re||c.hasWritableDraft)),va=_a===`editor.savedAt`&&I?u(`editor.savedAt`,{time:B(I,l.resolvedLanguage,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}):u(_a);return(0,X.jsxs)(`div`,{className:`workspace`,"data-texlite-tooltips":pt.showTooltips?`on`:`off`,children:[(0,X.jsx)(Ny,{agentTerminal:qi&&f.visible&&h.permission!==`read`?{open:p,activeCount:f.activeCount,toggle:()=>m(e=>!e)}:void 0,site:e,project:h,activeFile:E,saveStateLabel:va,editorPreferences:pt,activeSessions:qt,collaborationStatus:Gt,reconnectCollaboration:an,protocolUpgradeRequired:on,showEditor:qi,filesCollapsed:Pe,toggleFilesPanel:Wi,workspaceLayout:pe,changeWorkspaceLayout:Xi,onBack:s,onShare:()=>J(!0),showCitationLibrary:qi&&/\.bib$/i.test(E),citationLibraryOpen:Ue,onCitationLibrary:()=>We(!0),onHistory:()=>Be(!0),onGit:()=>Re(!0),canManageGit:h.ownerId===t.id,formatting:st,readOnly:$i,collaborationSynced:Kt,onToggleComments:()=>{let e=be!==`comments`||!!Se;q(null),e&&Xr(`project`),xe(e?`comments`:null)},commentsOpen:be===`comments`,unresolvedCommentCount:zr?.unresolvedCount??h.unresolvedCommentCount??0,onToggleSettings:()=>xe(be===`settings`?null:`settings`),settingsOpen:be===`settings`,compileBusy:ia,sharedCompiling:ra,localCompiling:Ni,cancelling:Pi,onCompile:Ii,onCancelCompile:()=>void Li()}),on&&(0,X.jsxs)(`div`,{className:`workspace-update-banner`,role:`alert`,children:[(0,X.jsx)(g,{size:15}),(0,X.jsx)(`span`,{children:u(`workspaceUpdates.protocolUpgrade`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:u(`common.reload`)})]}),ga&&(0,X.jsxs)(`div`,{className:`compile-status-strip${Oi===`failed`?` failed`:``}`,role:`status`,"aria-live":`polite`,children:[(0,X.jsx)(je,{className:ia?`spin`:``,size:14}),(0,X.jsx)(`span`,{children:ga})]}),(Dn.error||En.error||lt||ta)&&(0,X.jsxs)(`div`,{className:`client-tool-recoveries`,children:[Dn.error&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:Dn.error,children:[(0,X.jsx)(g,{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:Dn.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:Dn.dismissError,children:(0,X.jsx)(te,{size:13})})]}),En.error&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:En.error,children:[(0,X.jsx)(g,{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:En.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:En.dismissError,children:(0,X.jsx)(te,{size:13})})]}),lt&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:lt.detail,children:[(0,X.jsx)(g,{size:15}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`strong`,{children:u(lt.kind===`format`?`editor.texFmtOptionsRecoveryTitle`:lt.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:st||$i,onClick:()=>Hi(),children:u(`common.retry`)}),lt.kind===`format`&&pt.texFmtConfig.trim()&&(0,X.jsx)(`button`,{type:`button`,disabled:st||$i,onClick:()=>Hi(!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:()=>ut(null),children:(0,X.jsx)(te,{size:13})})]}),ta&&(0,X.jsxs)(`div`,{className:`client-tool-recovery format-lease-status`,role:`status`,children:[(0,X.jsx)(je,{className:`spin`,size:15}),(0,X.jsx)(`span`,{children:u(`editor.formattingBy`,{name:ta.holderName})})]})]}),$t&&(0,X.jsxs)(`div`,{className:`client-tool-recovery`,role:`status`,children:[(0,X.jsx)(g,{size:15}),(0,X.jsx)(`span`,{children:u(`history.saveWarning`)})]}),he&&(0,X.jsx)(`div`,{className:`toast`,onClick:()=>H(``),children:he}),ge&&(0,X.jsx)(`div`,{className:`toast success`,onClick:()=>_e(``),children:ge}),(0,X.jsxs)(wm,{orientation:`horizontal`,className:`work-grid`,...Yi,children:[qi&&(0,X.jsx)(Hy,{project:h,filesPanel:yt,visibleEntries:Z,deletedPath:Zt?.kind===`delete`?Zt.path:null,activeFile:E,activeMainFile:O,selectedFile:sr,selectedFolder:ar,expandedFolders:lr,fileDragActive:yr,uploadingFiles:Cr,uploadFeedback:wr,readOnly:$i,formatting:st,canFormat:rh(E),activeFormatLease:!!ea,collaborationSynced:Kt,editorFontSize:pt.fontSize,outline:Gi,sourceCursorStore:z,wordCountBusy:tt,hasSelection:!!G.selectedText.trim()&&/\.(?:tex|sty|cls)$/i.test(E),hasFormatSelection:!!G.selectedText.trim(),uploadInput:vt,setSelectedFolder:or,setExpandedFolders:ur,setMoveEntry:fr,setMoveName:mr,setMoveDestination:gr,setDeleteEntry:vr,setFileDialogError:ir,setNewFolderName:nr,setNewFolderOpen:er,setNewFilePath:Jn,setNewFileOpen:Kn,setQuickOpen:Je,setFileDragActive:br,dismissUploadFeedback:Tr,setFilesCollapsed:Fe,onError:H,uploadFiles:kr,upload:Ar,openFile:jr,movePathToFolder:Nr,onFormatFile:()=>void Ln(),onFormatSelection:()=>void Bn(),jumpToSource:bn,syncSourceToPdf:xn,onWordCount:e=>void Pn(e)}),qi&&(0,X.jsx)(Fm,{className:`resize-handle`,children:(0,X.jsx)(Rt,{size:12})}),qi&&(0,X.jsx)(Zy,{terminal:p?({maximized:e,toggleMaximized:t})=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`agent-task-empty`,children:(0,X.jsx)(je,{className:`spin`,size:18})}),children:(0,X.jsx)(Rb,{projectId:n,readOnly:$i,onHide:()=>m(!1),maximized:e,onToggleMaximized:t})}):null,project:h,activeFile:E,openTabs:ht,content:A,loadedFile:F,readOnly:$i,comments:Rr,focusComment:Zr,editorPreferences:pt,completionIndex:S,nativeSpellCheck:Dn.nativeFallback,spellCheckIssues:Dn.issues,spellCheckJump:Dn.jump,sourceJump:gn,collaborativeText:aa,collaborationAwareness:c.awareness,undoManager:E?c.getUndoManager(E):void 0,editorNotice:Mi,activateTab:pa,closeTab:Wt,handleTabKeyDown:ha,updateEditorContent:On,setSelection:(e,t,n)=>K({selectedText:e,startOffset:t,endOffset:n}),onAddComment:(e,t,n,r)=>ei({selectedText:e,startOffset:t,endOffset:n},r),onSelectionHistory:(e,t,n,r)=>{He({filePath:E,selection:{selectedText:e,startOffset:t,endOffset:n},source:r})},onCommentClick:bi,onSpellCheckReplace:na,onReferenceNavigate:Zi,onCursor:Ht}),Ji&&(0,X.jsx)(sb,{projectId:n,activeMainFile:O,previewTab:le,diagnosticTab:ue,pdfUrl:xi,pdfLoadingMode:wi,pdfLoading:Ti,pdfCompiledAt:Si,pdfSizeBytes:Ci,pdfCompiledLabel:oa,pdfTargetLabel:sa,pdfDownloadUrl:la,pdfTarget:mn,pdfViewport:hn,activeFile:E,compileBusy:ia,compileLog:Ei,compileDiagnostics:Di,compileMessages:Ki,artifacts:ki,artifactPreview:Ai,artifactLoading:ji,cleaning:Fi,readOnly:$i,collaborationSynced:Kt,workspaceLayout:pe,showSyncResize:qi&&Ji,diagnosticCount:ca,selectPreviewTab:fe,changeWorkspaceLayout:Xi,onSetPdfViewport:_n,onResetPdfViewport:vn,onPdfDisplayed:Bi,syncVisiblePdfToSource:wn,syncCurrentSourceToPdf:()=>{let e=St.current;if(!e)return Promise.resolve();let t=z.getCursor();return xn(e,t.line,t.column)},syncPdfToSource:Sn,canSyncWithPdf:da,canSyncPdfToSource:fa,files:Hn,jumpToSource:bn,onSetCleanMode:Ke,viewArtifact:zi}),(0,X.jsx)(Mb,{sidePanel:be,onClose:()=>xe(null),project:h,projectId:n,site:e,files:Hn,currentUserId:t.id,comments:Se?Rr:Gr,commentDraftStore:pi,commentsLoading:Se?Hr:Kr,commentsError:(Se?Ur:qr)||dn,onRetryComments:Se?Wr:Jr,activeFile:E,singleCommentId:Se,onShowAllComments:()=>{q(null),Xr(`project`)},hasProjectCommentsScope:vi,commentScope:Yr,onCommentScopeChange:Xr,focusedCommentId:Me?.filePath===E?Me.id:Zr?.id,commentFocusNonce:Me?.nonce,onClearFocusComment:()=>{Ne(null),Qr(null),De(null)},unreadMentions:un,onMarkMentionRead:fn,onMarkAllMentionsRead:pn,targetCommentId:we?.commentId,targetReplyId:we?.replyId,onFocusComment:yi,onToggleComment:si,onReplyComment:ci,onEditComment:li,onDeleteComment:ui,onEditCommentReply:di,onDeleteCommentReply:fi,dictionaryWords:b,onDictionaryChange:x,editorPreferences:pt,onEditorPreferences:Vi,spellCheckCount:Dn.summary?.total??null,spellCheckUniqueCount:Dn.summary?.unique??null,spellCheckIndex:Dn.summary?Dn.index:-1,onSpellCheckNavigate:Dn.jumpToIssue,onProject:Fr},n)]}),Ye&&(0,X.jsx)(Te,{title:u(`editor.wordCountTitle`),onClose:()=>Xe(!1),children:(0,X.jsx)(zb,{open:!0,mode:Ze,path:$e,busy:tt,error:rt,result:at,onOpenChange:Xe})}),(0,X.jsx)(Tb,{user:t,project:h,projectId:n,activeFile:E,content:A,maxCitationBibtexBytes:e.maxCitationBibtexBytes,files:Hn,directoryEntries:Er,readOnly:$i,resourcePreview:Yn,resourcePreviewLoading:Zn,setResourcePreview:Xn,setResourcePreviewLoading:Qn,uploadConflict:xr,setUploadConflict:Sr,dismissUploadFeedback:Tr,uploadFiles:kr,cleanMode:Ge,setCleanMode:Ke,cleanCompile:Ri,newFileOpen:Gn,setNewFileOpen:Kn,newFilePath:qn,setNewFilePath:Jn,newFolderOpen:$n,setNewFolderOpen:er,newFolderName:tr,setNewFolderName:nr,selectedFolder:ar,fileDialogError:rr,setFileDialogError:ir,createFile:Dr,createFolder:Or,moveEntry:dr,setMoveEntry:fr,moveName:pr,setMoveName:mr,moveDestination:hr,setMoveDestination:gr,movePath:Mr,deleteEntry:_r,setDeleteEntry:vr,deleteActiveSessions:Qi,removePath:Pr,commentOpen:$r,closeComment:ti,commentSelection:ri,commentText:ni,setCommentText:Q,commentSubmitting:ii,cancelComment:mi,commentDraftRestored:hi,commentDraftCanRetarget:gi,useCurrentCommentSelection:_i,commentError:ai,addComment:oi,shareOpen:Ie,setShareOpen:J,citationLibraryOpen:Ue,setCitationLibraryOpen:We,insertCitationAtCursor:Vn,quickOpen:qe,setQuickOpen:Je,openFile:jr,selectionHistoryTarget:Ve,closeSelectionHistory:()=>He(null),historyOpen:ze,setHistoryOpen:Be,gitOpen:Le,setGitOpen:Re,save:Nn,permissionDowngrade:sn,permissionDowngradeBusy:dt,dismissPermissionDowngrade:cn,discardPermissionDraft:Ui})]})}export{ec as A,dn as B,$u as C,sc as D,cc as E,nr as F,Bt as H,Rn as I,Sn as L,Mo as M,la as N,tc as O,rr as P,Wb as ProjectWorkspace,_n as R,gd as S,Pc as T,wt as U,ln as V,cd as _,qd as a,ld as b,Hd as c,yd as d,Cd as f,Sd as g,xd as h,Lm as i,jo as j,ac as k,Od as l,Td as m,th as n,Kd as o,wd as p,nh as r,Gd as s,Lb as t,bd as u,id as v,Yu as w,hd as x,pd as y,pn as z};
|