texlite 0.16.0 → 0.17.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 +87 -5
- package/OPERATIONS.md +27 -0
- package/dist/client/assets/AdminUsers-5cAOkdRO.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-G2kKkA2f.js +1 -0
- package/dist/client/assets/Dashboard-BJDFbzQa.js +5 -0
- package/dist/client/assets/GitDialog-BEtLh2S_.js +3 -0
- package/dist/client/assets/GitHubAccountDialog-D2kdCzOs.js +1 -0
- package/dist/client/assets/{HistoryDialog-DWYErBwj.js → HistoryDialog-BwxDdj-j.js} +3 -3
- package/dist/client/assets/LatexEditor-sMjmvA6V.js +141 -0
- package/dist/client/assets/{PdfPreview-BjghzUb1.js → PdfPreview-z5KnowpL.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-DNV7M7vH.js +1 -0
- package/dist/client/assets/ProjectSettings-Mf8zDGRu.js +1 -0
- package/dist/client/assets/ProjectWorkspace-BJFxjMCn.js +32 -0
- package/dist/client/assets/QuickOpenDialog-C758pouQ.js +1 -0
- package/dist/client/assets/{SelectionHistoryDialog-CR5c3I8k.js → SelectionHistoryDialog-p8L2n4RS.js} +2 -2
- package/dist/client/assets/SystemMetricsDialog-DDiSuglF.js +1 -0
- package/dist/client/assets/TagManagementDialog-BTVERmQS.js +1 -0
- package/dist/client/assets/WordCountDialog-B6RvAI6V.js +1 -0
- package/dist/client/assets/check-Hlb-tLSh.js +1 -0
- package/dist/client/assets/chevron-up-D0psXvTv.js +1 -0
- package/dist/client/assets/chktex-ZnIx425m.js +3 -0
- package/dist/client/assets/clock-3-C71NmJZI.js +1 -0
- package/dist/client/assets/{editor-CLY5CgkY.js → editor-_i6aPXT4.js} +1 -1
- package/dist/client/assets/eye-swovgNYS.js +1 -0
- package/dist/client/assets/github-y6i0qxSV.js +1 -0
- package/dist/client/assets/{hard-drive-Ctj3K_zx.js → hard-drive-BqcHPdoY.js} +1 -1
- package/dist/client/assets/index-7WrjzKvC.js +5 -0
- package/dist/client/assets/index-C5T8_lAl.js +1 -0
- package/dist/client/assets/index-DF5cor0N.js +10 -0
- package/dist/client/assets/index-Do5FsFqg.js +1 -0
- package/dist/client/assets/index-Y-wXUwwe.css +1 -0
- package/dist/client/assets/{minimize-2-BiVyoWZA.js → minimize-2-CK7jUy7-.js} +1 -1
- package/dist/client/assets/{minus-Bl8l4LXq.js → minus-B2sswwWT.js} +1 -1
- package/dist/client/assets/{plus-CCxK-HNt.js → plus-Co7iyp5m.js} +1 -1
- package/dist/client/assets/{refresh-cw-BE8IbaHI.js → refresh-cw-BHVcjInn.js} +1 -1
- package/dist/client/assets/{search-CPbhRWQE.js → search-Tpi6WAga.js} +1 -1
- package/dist/client/assets/{sigma-LxGD9tK2.js → sigma-DoHJQYf7.js} +1 -1
- package/dist/client/assets/spellCheck-BSbFJY9f.js +1 -0
- package/dist/client/assets/{tags-DuN89PsZ.js → tags-BHDlIcSb.js} +1 -1
- package/dist/client/assets/{type-BiettCiY.js → type-C-6Jq_0r.js} +1 -1
- package/dist/client/index.html +15 -3
- package/dist/server/app.js +6 -1
- package/dist/server/cgroups.js +35 -0
- package/dist/server/compilerVersions.js +46 -0
- package/dist/server/config.js +8 -0
- package/dist/server/cpuMetrics.js +122 -0
- package/dist/server/db.js +13 -0
- package/dist/server/environment.js +11 -0
- package/dist/server/i18n.js +0 -2
- package/dist/server/resourceMetrics.js +214 -0
- package/dist/server/routes/projectFiles.js +1 -59
- package/dist/server/routes/system.js +32 -1
- package/dist/server/systemMemory.js +51 -0
- package/dist/server/updates.js +116 -0
- package/dist/shared/compilerVersions.js +11 -0
- package/dist/shared/resourceMetrics.js +1 -0
- package/dist/shared/updates.js +5 -0
- package/package.json +3 -1
- package/texlite.config.example.json +3 -0
- package/dist/client/assets/AdminUsers-Dyapv-3c.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-CU7Q7r0Z.js +0 -1
- package/dist/client/assets/Dashboard-DsdhFENx.js +0 -2
- package/dist/client/assets/GitDialog-CZpnKw-J.js +0 -3
- package/dist/client/assets/GitHubAccountDialog-CZ8O_PjD.js +0 -1
- package/dist/client/assets/LatexEditor-CssVgypt.js +0 -141
- package/dist/client/assets/ProjectIconPickerDialog-CqRmgFBM.js +0 -1
- package/dist/client/assets/ProjectNavigationDialogs-BZxI3PJO.js +0 -1
- package/dist/client/assets/ProjectSettings-CZE_xDKn.js +0 -1
- package/dist/client/assets/ProjectWorkspace-CAX3qEYr.js +0 -32
- package/dist/client/assets/SystemMetricsDialog-DDpFwgXh.js +0 -1
- package/dist/client/assets/TagManagementDialog-CXLA9h_j.js +0 -1
- package/dist/client/assets/WordCountDialog-DUyR24vv.js +0 -1
- package/dist/client/assets/check-CwBYzomT.js +0 -1
- package/dist/client/assets/chevron-up-D5lCNKlk.js +0 -1
- package/dist/client/assets/chktex-CRkLYKcV.js +0 -3
- package/dist/client/assets/external-link-C9Td1CCj.js +0 -1
- package/dist/client/assets/github-D-JDXb-w.js +0 -1
- package/dist/client/assets/index-9hnQ8Q9x.js +0 -5
- package/dist/client/assets/index-C0qg2Ylw.css +0 -1
- package/dist/client/assets/index-DkpU9Fgs.js +0 -10
- package/dist/client/assets/index-_eYe7K9T.js +0 -1
- package/dist/client/assets/spellCheck-hpm8qZTr.js +0 -1
- package/dist/client/assets/x-C_3swJOC.js +0 -1
- package/dist/server/projectSearch.js +0 -113
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./spellCheck-BSbFJY9f.js","./index-DF5cor0N.js","./react-CltQJflK.js","./index-Y-wXUwwe.css","./index-C5T8_lAl.js","./check-Hlb-tLSh.js","./index-Do5FsFqg.js","./chevron-up-D0psXvTv.js","./refresh-cw-BHVcjInn.js","./chktex-ZnIx425m.js","./LatexEditor-sMjmvA6V.js","./editor-_i6aPXT4.js","./CitationLibraryDialog-G2kKkA2f.js","./tags-BHDlIcSb.js","./plus-Co7iyp5m.js","./citationLibrary-C9WnXB-1.js","./search-Tpi6WAga.js","./GitDialog-BEtLh2S_.js","./github-y6i0qxSV.js","./eye-swovgNYS.js","./minus-B2sswwWT.js","./minimize-2-CK7jUy7-.js","./HistoryDialog-BwxDdj-j.js","./index-7WrjzKvC.js","./hard-drive-BqcHPdoY.js","./clock-3-C71NmJZI.js","./SelectionHistoryDialog-p8L2n4RS.js","./QuickOpenDialog-C758pouQ.js","./ProjectSettings-Mf8zDGRu.js","./type-C-6Jq_0r.js","./sigma-DoHJQYf7.js","./WordCountDialog-B6RvAI6V.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Ae,d as Cn,e as we,a as pe,A as xr,b as fs,n as hf,l as ff,r as mf,_ as Lt,S as pf,L as lt,i as Rs,k as nc,C as Ns,M as rn,g as sc,m as gf}from"./index-DF5cor0N.js";import{r as u,u as Ye,j as o,P as zr,d as xo,T as wf,e as yf}from"./react-CltQJflK.js";import{C as Hs,j as bf,U as kr,B as xf,M as kf,G as Sf,X as cn,h as Ur,o as Yi,e as Cf,f as Jl,N as vf,g as rc,F as jf,k as Yl,l as Ef,p as Dt,m as ko,d as Df,T as Tn,L as Tf,S as Xi,D as Sr,E as _f,i as Rf,A as Ms,P as Lf,a as Af,b as Nf,c as Mf,q as Of,n as Ff}from"./index-C5T8_lAl.js";import{C as $f}from"./check-Hlb-tLSh.js";import{D as Pf,a as If,b as zf,c as Uf,d as Xl,U as Bf}from"./index-Do5FsFqg.js";import{C as qf}from"./chevron-up-D0psXvTv.js";import{R as Wf}from"./refresh-cw-BHVcjInn.js";const Vf=Ae("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);const Hf=Ae("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);const Kf=Ae("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);const Zi=Ae("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const So=Ae("CircleX",[["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"}]]);const Zl=Ae("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);const Qi=Ae("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);const Gf=Ae("FileAudio",[["path",{d:"M17.5 22h.5a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"rslqgf"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 19a2 2 0 1 1 4 0v1a2 2 0 1 1-4 0v-4a6 6 0 0 1 12 0v4a2 2 0 1 1-4 0v-1a2 2 0 1 1 4 0",key:"9f7x3i"}]]);const Jf=Ae("FileClock",[["path",{d:"M16 22h2a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"37hlfg"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}],["path",{d:"M9.5 17.5 8 16.25V14",key:"1o80t2"}]]);const Yf=Ae("FileCog",[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m3.2 12.9-.9-.4",key:"1i3dj5"}],["path",{d:"m3.2 15.1-.9.4",key:"1fvgj0"}],["path",{d:"M4.677 21.5a2 2 0 0 0 1.313.5H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v2.5",key:"1yo3oz"}],["path",{d:"m4.9 11.2-.4-.9",key:"otmhb9"}],["path",{d:"m4.9 16.8-.4.9",key:"1b8z07"}],["path",{d:"m7.5 10.3-.4.9",key:"11k65u"}],["path",{d:"m7.5 17.7-.4-.9",key:"431x55"}],["path",{d:"m9.7 12.5-.9.4",key:"87sjan"}],["path",{d:"m9.7 15.5-.9-.4",key:"khqm91"}],["circle",{cx:"6",cy:"14",r:"3",key:"a1xfv6"}]]);const Xf=Ae("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["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"}]]);const Zf=Ae("FilePlus2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M3 15h6",key:"4e2qda"}],["path",{d:"M6 12v6",key:"1u72j0"}]]);const Qf=Ae("FileType2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M2 13v-1h6v1",key:"1dh9dg"}],["path",{d:"M5 12v6",key:"150t9c"}],["path",{d:"M4 18h2",key:"1xrofg"}]]);const em=Ae("FileVideo",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m10 11 5 3-5 3v-6Z",key:"7ntvm4"}]]);const tm=Ae("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);const ic=Ae("GripVertical",[["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"}]]);const Ql=Ae("Hash",[["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"}]]);const nm=Ae("Keyboard",[["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"}]]);const sm=Ae("LibraryBig",[["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"}]]);const rm=Ae("MessagesSquare",[["path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z",key:"p1xzt8"}],["path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1",key:"1cx29u"}]]);const ea=Ae("Move",[["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"}]]);const oc=Ae("PackageOpen",[["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"}]]);const im=Ae("PanelLeftClose",[["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"}]]);const om=Ae("PanelLeftOpen",[["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"}]]);const lm=Ae("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);const am=Ae("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const cm=Ae("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);const um=Ae("Reply",[["polyline",{points:"9 17 4 12 9 7",key:"hvgpf2"}],["path",{d:"M20 18v-2a4 4 0 0 0-4-4H4",key:"5vmcpk"}]]);const dm=Ae("RotateCcw",[["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"}]]);const hm=Ae("Save",[["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"}]]);const fm=Ae("Send",[["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"}]]);const mm=Ae("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),pm="wrap = false",eo=[{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'}],Ct={font:"jetbrains",fontSize:14,lineHeight:1.65,lineWrapping:!0,showTooltips:!1,spellCheck:!0,mathPreviewOnHover:!1,vimMode:!1,formatOnCompile:!1,texFmtConfig:pm,texFmtConfigInitialized:!0,openFilesInTabs:!1},gm="texlite-editor-preferences";function lc(t,e){return Cn(`${gm}:${encodeURIComponent(t)}:${encodeURIComponent(e)}`)}function c0(t){return eo.find(e=>e.id===t)?.stack??eo[0].stack}function ta(t,e){try{const n=JSON.parse(localStorage.getItem(lc(t,e))??"{}"),s=typeof n.texFmtConfig=="string"&&n.texFmtConfig.length<=16*1024?n.texFmtConfig:null,r=s!==null&&(n.texFmtConfigInitialized===!0||s.trim().length>0)?s:Ct.texFmtConfig;return{font:eo.some(i=>i.id===n.font)?n.font:Ct.font,fontSize:[12,13,14,15,16,18,20].includes(Number(n.fontSize))?Number(n.fontSize):Ct.fontSize,lineHeight:[1.45,1.65,1.85].includes(Number(n.lineHeight))?Number(n.lineHeight):Ct.lineHeight,lineWrapping:typeof n.lineWrapping=="boolean"?n.lineWrapping:Ct.lineWrapping,showTooltips:typeof n.showTooltips=="boolean"?n.showTooltips:Ct.showTooltips,spellCheck:typeof n.spellCheck=="boolean"?n.spellCheck:Ct.spellCheck,mathPreviewOnHover:typeof n.mathPreviewOnHover=="boolean"?n.mathPreviewOnHover:Ct.mathPreviewOnHover,vimMode:typeof n.vimMode=="boolean"?n.vimMode:Ct.vimMode,formatOnCompile:typeof n.formatOnCompile=="boolean"?n.formatOnCompile:Ct.formatOnCompile,texFmtConfig:r,texFmtConfigInitialized:!0,openFilesInTabs:typeof n.openFilesInTabs=="boolean"?n.openFilesInTabs:Ct.openFilesInTabs}}catch{return Ct}}function wm(t,e,n){localStorage.setItem(lc(t,e),JSON.stringify(n))}function ym(){let t={status:"loading",error:""};const e=new Set,n=(s,r="")=>{if(!(t.status===s&&t.error===r)){t={status:s,error:r};for(const i of e)i()}};return{getSnapshot:()=>t,subscribe:s=>(e.add(s),()=>e.delete(s)),loading:()=>n("loading"),working:()=>n("working"),failed:s=>n("error",s instanceof Error?s.message:String(s))}}const on=ym(),bm=/\.(?:tex|bib|cls|sty)$/i,ac=3e4;let Et=null,Cr=!1,vn=null,xm=1;const _n=new Map,vr=[];let Jn=null,Ts=null;class kt extends Error{constructor(e,n){super(n),this.kind=e,this.name="TexFmtError"}kind}function _i(t){return t instanceof kt}function Gt(t){Et?.terminate(),Et=null,Cr=!1,vn!==null&&window.clearTimeout(vn),vn=null,Jn=null,vr.length=0,Ts=null,on.failed(t);for(const e of _n.values())e.timeout!==null&&window.clearTimeout(e.timeout),e.reject(t);_n.clear()}function Ls(){if(Jn!==null||vr.length===0)return;let t;try{t=km()}catch(s){Gt(s instanceof kt?s:new kt("load","The bundled tex-fmt formatter could not be loaded."));return}if(!Cr)return;const e=vr.shift();if(e===void 0)return;const n=_n.get(e);if(!n){Ls();return}Jn=e,n.timeout=window.setTimeout(()=>{Jn===e&&Gt(new kt("result","The formatter did not respond within 30 seconds."))},ac);try{t.postMessage({...n.request,id:e})}catch{Gt(new kt("load","The formatter worker could not receive the source."))}}function km(){if(Et)return Et;if(typeof Worker>"u"){const t=new kt("load","This browser does not support formatter workers.");throw on.failed(t),t}on.loading();try{Et=new Worker(new URL(""+new URL("latexFormatterWorker-BRmsns8a.js",import.meta.url).href,import.meta.url),{type:"module",name:"texlite-latex-formatter"}),vn=window.setTimeout(()=>{Cr||Gt(new kt("load","The formatter did not finish loading within 30 seconds."))},ac)}catch{const t=new kt("load","The bundled tex-fmt formatter could not be loaded.");throw on.failed(t),t}return Et.onmessage=t=>{const e=t.data;if(e&&"type"in e){e.type==="ready"&&(Cr=!0,vn!==null&&window.clearTimeout(vn),vn=null,Ls());return}if(!e||typeof e.id!="number"){Gt(new kt("result","The formatter worker returned an invalid response."));return}const n=_n.get(e.id);if(n)if(_n.delete(e.id),n.timeout!==null&&window.clearTimeout(n.timeout),Jn===e.id&&(Jn=null),e.ok)on.working(),n.resolve(e.result),Ls();else{const s=new kt(e.kind,e.message);e.kind==="format"?(on.working(),n.reject(s),Ls()):(n.reject(s),Gt(s))}},Et.onerror=()=>{Gt(new kt("load","The bundled tex-fmt formatter could not be loaded."))},Et.onmessageerror=()=>{Gt(new kt("result","The formatter worker returned an unreadable response."))},Et}function Co(t){const e=xm++;return new Promise((n,s)=>{_n.set(e,{request:t,resolve:n,reject:s,timeout:null}),vr.push(e),Ls()})}function Sm(t,e=""){return Co({action:"format",source:t,config:e})}async function Cm(){Et&&on.getSnapshot().status==="working"||(Ts||(Ts=Co({action:"probe"}).then(()=>{}).finally(()=>{Ts=null})),await Ts)}async function u0(){(Et||_n.size)&&Gt(new kt("load","The formatter runtime was reloaded.")),on.loading(),await Cm()}function dr(t){return bm.test(t)}function vm(t){return t.match(/(?:\r?\n)+$/)?.[0]??""}function jm(t,e){const n=vm(t),l=(n?t.slice(0,-n.length):t).split(/\r?\n/).find(h=>h.trim())?.match(/^[\t ]*/)?.[0]??"",a=e.replace(/(?:\r?\n)+$/,"");return`${l?a.split(`
|
|
3
|
+
`).map(h=>h&&`${l}${h}`).join(`
|
|
4
|
+
`):a}${n}`}async function Ri(t,e,n=0){return Co({action:"diff",source:t,formatted:e,baseOffset:n})}function Em(t,e=null){const n=na(t),r=e==="succeeded"||e===null&&Tm(t)?[]:sa(n.filter(ra)),i=na(Dm(t));return{warnings:sa(i.filter(a=>!ra(a)&&_m(a))),errors:r}}function na(t){return t.split(`
|
|
5
|
+
`).map(e=>e.trim()).filter(Boolean)}function sa(t){return[...new Set(t)]}function Dm(t){const e=/^Running ['"][^\n]*(?:pdf|xe|lua)latex(?:\s|['"])[^\n]*$/gim;let n=-1;for(const s of t.matchAll(e))n=s.index;return n>=0?t.slice(n):t}function Tm(t){return/Latexmk: All targets .* are up-to-date/i.test(t)&&/Output written on .*\.pdf/i.test(t)}function ra(t){return/^!\s/.test(t)||/(?:^|:\s)(?:LaTeX|Package|Class|pdfTeX|XeTeX|LuaTeX)?\s*Error:/i.test(t)||/^Latexmk:.*(?:\bErrors?,|did not complete making targets|failure)/i.test(t)||/^Collected error summary/i.test(t)||/\b(?:fatal error|emergency stop|undefined control sequence|no output pdf|no pages of output)\b/i.test(t)||/\b(?:bibtex|biber) errors?:/i.test(t)||/^error, and then rerun latexmk/i.test(t)}function _m(t){return/\bwarnings?\b|overfull|underfull|badness/i.test(t)}const ia=1,oa=2,Li=4,Ai=8,Os=32,Jt=64,dt=128,Rm=1<<29,Br=31,to=63,Dn=127,Lm=2147483647,Ft=(t,e)=>t>>>e|t<<32-e,Am=t=>Ft(t,2)^Ft(t,13)^Ft(t,22),Nm=t=>Ft(t,6)^Ft(t,11)^Ft(t,25),Mm=t=>Ft(t,7)^Ft(t,18)^t>>>3,Om=t=>Ft(t,17)^Ft(t,19)^t>>>10,Fm=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]),$m=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class Pm{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set($m),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let f=16;f<64;f++)n[f]=Om(n[f-2])+n[f-7]+Mm(n[f-15])+n[f-16];let s=e[0],r=e[1],i=e[2],l=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let f=0,m,g;f<64;f++)m=d+Nm(a)+(a&c^~a&h)+Fm[f]+n[f]>>>0,g=Am(s)+(s&r^s&i^r&i)>>>0,d=h,h=c,c=a,a=l+m>>>0,l=i,i=r,r=s,s=m+g>>>0;e[0]+=s,e[1]+=r,e[2]+=i,e[3]+=l,e[4]+=a,e[5]+=c,e[6]+=h,e[7]+=d}digest(e){let n=0;for(;n+56<=e.length;){let l=0;for(;l<16&&n+3<e.length;l++)this._W[l]=e[n++]<<24|e[n++]<<16|e[n++]<<8|e[n++];if(n%64!==0){for(this._W.fill(0,l,16);n<e.length;)this._W[l]|=e[n]<<(3-n%4)*8,n++;this._W[l]|=dt<<(3-n%4)*8}this._updateHash()}const s=n%64!==0;this._W.fill(0,0,16);let r=0;for(;n<e.length;r++)for(let l=3;l>=0&&n<e.length;l--)this._W[r]|=e[n++]<<l*8;s||(this._W[r-(n%4===0?0:1)]|=dt<<(3-n%4)*8),this._W[14]=e.byteLength/Rm,this._W[15]=e.byteLength*8,this._updateHash();const i=new Uint8Array(32);for(let l=0;l<this._H.length;l++)for(let a=0;a<4;a++)i[l*4+a]=this._H[l]>>>(3-a)*8;return i}}const Im=t=>new Pm().digest(t);function zm(t){return Array.from(Im(new TextEncoder().encode(t)),e=>e.toString(16).padStart(2,"0")).join("")}const la=Object.freeze({});class Um{threads=new Map;listeners=new Map;newComments=new Map;getThread(e){return this.threads.get(e)??la}subscribe(e,n){const s=this.listeners.get(e)??new Set;return s.add(n),this.listeners.set(e,s),()=>{s.delete(n),s.size||this.listeners.delete(e)}}publish(e,n){Object.keys(n).length?this.threads.set(e,n):this.threads.delete(e);for(const s of this.listeners.get(e)??[])s()}isPending(e){return Object.values(this.getThread(e)).some(n=>n?.pending)}open(e,n,s=""){if(this.isPending(e))return;const r={...this.getThread(e)};if(n.startsWith("edit-reply:"))for(const[l,a]of Object.entries(r))l.startsWith("edit-reply:")&&a?.open&&(r[l]={...a,open:!1});const i=r[n];r[n]={content:s,pending:!1,error:"",...i,open:!0},this.publish(e,r)}change(e,n,s){const r=this.getThread(e)[n];!r||this.isPending(e)||this.publish(e,{...this.getThread(e),[n]:{...r,content:s}})}hide(e,n){const s=this.getThread(e)[n];!s||this.isPending(e)||this.publish(e,{...this.getThread(e),[n]:{...s,open:!1}})}discard(e,n){const s={...this.getThread(e)};if(n===void 0){this.publish(e,la);return}delete s[n],this.publish(e,s)}async submit(e,n,s,r){const i=this.getThread(e)[n];if(!i||!i.content.trim()||this.isPending(e))return!1;const l={...i,pending:!0,error:""};this.publish(e,{...this.getThread(e),[n]:l});let a=r;try{if(await s(i.content))return this.getThread(e)[n]===l&&this.discard(e,n),!0}catch(c){a=we(c)}return this.getThread(e)[n]===l&&this.publish(e,{...this.getThread(e),[n]:{...i,pending:!1,error:a}}),!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)}}function Bm(t,e,n){const s=n instanceof xr&&[401,403,404].includes(n.status);return{filePath:e,comments:!s&&t.filePath===e?t.comments:[],loading:!1,error:we(n)}}function aa(t){return t instanceof Error&&t.name==="AbortError"}function qm({projectId:t,activeFile:e,content:n,permission:s,revision:r,selection:i,save:l,saveFailureMessage:a,onError:c,onAdded:h,onChanged:d}){const f=u.useMemo(()=>new Um,[t]),[m,g]=u.useState({filePath:"",comments:[],loading:!1,error:""}),[w,S]=u.useState([]),[L,v]=u.useState(!1),[q,A]=u.useState(""),[x,P]=u.useState("file"),[j,C]=u.useState(null),[M,H]=u.useState(!1),[J,le]=u.useState(""),[B,se]=u.useState(null),[W,te]=u.useState(null),[Y,Ce]=u.useState(!1),[ae,Z]=u.useState(!1),[$,ue]=u.useState(""),Ee=u.useRef(null),ke=u.useRef(null),ve=u.useRef(!1),X=u.useRef(e),I=u.useRef(x),fe=u.useRef(l),ye=u.useRef(c),O=u.useRef(h),z=u.useRef(d),De=u.useRef(B),U=u.useRef(J);De.current=B,U.current=J,X.current=e,I.current=x,fe.current=l,ye.current=c,O.current=h,z.current=d;const R=m.filePath===e?m.comments:[],he=m.filePath,K=he===e?m.error:"",Ne=!!e&&(he!==e||m.loading),Ve=he===e&&!m.loading&&!K,Me=async N=>{Ee.current?.abort();const G=new AbortController;Ee.current=G,X.current===N&&g(Te=>Te.filePath===N?{...Te,loading:!0,error:""}:{filePath:"",comments:[],loading:!0,error:""});try{const Te=await pe(`/api/projects/${t}/comments?path=${encodeURIComponent(N)}`,{signal:G.signal});Ee.current===G&&X.current===N&&g({filePath:N,comments:Te.comments,loading:!1,error:""})}catch(Te){!aa(Te)&&Ee.current===G&&X.current===N&&g(Q=>Bm(Q,N,Te))}finally{Ee.current===G&&(Ee.current=null)}},Fe=()=>X.current?Me(X.current):Promise.resolve(),ne=async()=>{ke.current?.abort();const N=new AbortController;ke.current=N,I.current==="project"&&(v(!0),A(""));try{const G=await pe(`/api/projects/${t}/comments?scope=project`,{signal:N.signal});ke.current===N&&I.current==="project"&&S(G.comments)}catch(G){!aa(G)&&ke.current===N&&I.current==="project"&&A(we(G))}finally{ke.current===N&&(ke.current=null,I.current==="project"&&v(!1))}};u.useEffect(()=>{Ee.current?.abort(),Ee.current=null,ke.current?.abort(),ke.current=null,C(null),g({filePath:"",comments:[],loading:!1,error:""}),S([]),v(!1),A(""),P("file"),H(!1),se(null),te(null),le(""),Ce(!1),ue("")},[t]),u.useEffect(()=>{H(!1),se(null),te(null),le(""),Ce(!1),ue("")},[e]),u.useEffect(()=>(e?Me(e):g({filePath:"",comments:[],loading:!1,error:""}),()=>{Ee.current?.abort(),Ee.current=null}),[t,e,r]),u.useEffect(()=>{if(x!=="project"){ke.current?.abort(),ke.current=null,S([]),v(!1),A("");return}return ne(),()=>{ke.current?.abort(),ke.current=null}},[t,x,r]);const be=async N=>{const G=[];X.current===N&&G.push(Me(N)),I.current==="project"&&G.push(ne()),await Promise.all(G)},_=(N,G)=>{if(!e)return;ue("");const Te={filePath:e,selection:{...N??i},sourceHash:zm(G??n)},Q=f.getNew(e);se(Q??Te),le(Q?.content??""),te(Te),Ce(!!Q),H(!0)},ge=N=>{le(N),B&&(N?f.setNew({...B,content:N}):f.discardNew(B.filePath))},xe=()=>{ve.current||(H(!1),ue(""))},Le=()=>{ve.current||(B&&f.discardNew(B.filePath),le(""),se(null),te(null),Ce(!1),xe())},Ue=()=>{ve.current||!W||W.filePath!==X.current||(se(W),J&&f.setNew({...W,content:J}),Ce(!1),ue(""))},Ge=async()=>{const N=B,G=J;if(!J.trim()||!N||ve.current)return;const Te=()=>{const Q=De.current;return Q?.filePath===N.filePath&&Q.sourceHash===N.sourceHash&&Q.selection.startOffset===N.selection.startOffset&&Q.selection.endOffset===N.selection.endOffset&&U.current===G};ve.current=!0,Z(!0),ue("");try{if(s!=="read"&&!await fe.current()){Te()&&ue(a);return}await pe(`/api/projects/${t}/comments`,{method:"POST",body:JSON.stringify({path:N.filePath,content:G,...N.selection,sourceHash:N.sourceHash})}),await be(N.filePath);const Q=f.getNew(N.filePath);Q?.content===G&&Q.sourceHash===N.sourceHash&&Q.selection.startOffset===N.selection.startOffset&&Q.selection.endOffset===N.selection.endOffset&&f.discardNew(N.filePath),Te()&&(H(!1),se(null),le(""),Ce(!1)),O.current(),z.current?.()}catch(Q){Te()&&ue(we(Q))}finally{ve.current=!1,Z(!1)}},Re=async N=>{try{await pe(`/api/projects/${t}/comments/${N.id}`,{method:"PATCH",body:JSON.stringify({resolved:!N.resolved})}),await be(N.filePath),z.current?.()}catch(G){ye.current(we(G))}},re=async(N,G)=>(await pe(`/api/projects/${t}/comments/${N.id}/replies`,{method:"POST",body:JSON.stringify({content:G})}),await be(N.filePath),z.current?.(),!0),F=async(N,G)=>(await pe(`/api/projects/${t}/comments/${N.id}`,{method:"PATCH",body:JSON.stringify({content:G})}),await be(N.filePath),z.current?.(),!0),oe=async N=>{try{return await pe(`/api/projects/${t}/comments/${N.id}`,{method:"DELETE"}),await be(N.filePath),C(G=>G?.id===N.id?null:G),f.discard(N.id),z.current?.(),!0}catch(G){return ye.current(we(G)),!1}},Oe=async(N,G,Te)=>(await pe(`/api/projects/${t}/comments/${N.id}/replies/${G}`,{method:"PATCH",body:JSON.stringify({content:Te})}),await be(N.filePath),z.current?.(),!0),Be=async(N,G)=>{try{return await pe(`/api/projects/${t}/comments/${N.id}/replies/${G}`,{method:"DELETE"}),await be(N.filePath),f.discard(N.id,`edit-reply:${G}`),z.current?.(),!0}catch(Te){return ye.current(we(Te)),!1}};return{commentDraftStore:f,comments:R,commentsFilePath:he,commentsReady:Ve,fileCommentsLoading:Ne,fileCommentsError:K,retryFileComments:Fe,reviewComments:x==="file"?R:w,reviewCommentsLoading:x==="project"?L:Ne,reviewCommentsError:x==="project"?q:K,retryReviewComments:x==="project"?ne:Fe,commentScope:x,setCommentScope:P,focusComment:j,setFocusComment:C,commentOpen:M,openComment:_,closeComment:xe,cancelComment:Le,commentDraftRestored:Y,commentDraftCanRetarget:!!(B&&W&&(B.sourceHash!==W.sourceHash||B.selection.startOffset!==W.selection.startOffset||B.selection.endOffset!==W.selection.endOffset)),useCurrentCommentSelection:Ue,commentText:J,setCommentText:ge,commentSelection:B?.selection??i,commentSubmitting:ae,commentError:$,addComment:Ge,toggleComment:Re,replyToComment:re,editComment:F,deleteComment:oe,editCommentReply:Oe,deleteCommentReply:Be}}function Wm(t){const e=new Map;for(const n of t)for(const s of[n,...n.replies])e.has(s.authorId)||e.set(s.authorId,{authorId:s.authorId,authorUsername:s.authorUsername,authorDisplayName:s.authorDisplayName});return[...e.values()].sort((n,s)=>(n.authorDisplayName??n.authorUsername??"").localeCompare(s.authorDisplayName??s.authorUsername??""))}function cc(t,e){const n=e.participantIds;return n?.size?n.has(t.authorId)||!e.topLevelOnly&&t.replies.some(s=>n.has(s.authorId)):!0}function Vm(t,e="source"){return[...t].sort((n,s)=>e==="time"?Date.parse(s.createdAt)-Date.parse(n.createdAt):n.filePath.localeCompare(s.filePath,"en",{numeric:!0})||n.startLine-s.startLine||n.startOffset-s.startOffset)}function uc(t,e){return e.scope==="project"||t.filePath===e.activeFile}function vo(t,e){return e==="unresolved"?!t.resolved:t.resolved}function dc(t,e){return e.some(n=>n.commentId===t.id&&n.readAt===null)}function Ni(t,e){return t.filter(n=>uc(n,e)&&cc(n,e)&&vo(n,e.filter)&&(!e.unreadMentionsOnly||dc(n,e.unreadMentions)))}function Hm(t,e,n=[]){const s=new Set(n.filter(r=>!!r));return Vm(t.filter(r=>uc(r,e)?s.has(r.id)||cc(r,e)&&vo(r,e.filter)&&(!e.unreadMentionsOnly||dc(r,e.unreadMentions)):!1),e.sort)}function Km(t,e,n){const s=t.find(r=>r.id===e&&r.filePath===n&&!r.resolved);return s?[s]:[]}function Gm(t,e){return t.filter(n=>n.filePath===e)}function Jm(t,e,n){return!t||t.filePath!==e||n!==e?null:t}function Ym(t,e,n,s,r,i){return!t||t.filePath!==e||n!==e||s!==e||!r?null:i.find(l=>l.id===t.id&&l.filePath===e)??null}function Xm(t,e){if(!e)return 0;const n=t.findIndex(s=>s.id===e);return n<0?0:n+1}function Zm(t,e,n){if(!t.length)return null;const s=e?t.findIndex(i=>i.id===e):-1;if(s<0)return n===1?t[0]:null;const r=s+n;return r>=0&&r<t.length?t[r]:null}function Qm(t){return t instanceof Error&&t.name==="AbortError"}function ep(t,e,n){const[s,r]=u.useState([]),i=u.useRef(null),l=u.useRef(n);l.current=n;const a=u.useCallback(async(d=!1)=>{i.current?.abort();const f=new AbortController;i.current=f;try{const m=await pe(`/api/projects/${t}/mentions?unread=1&limit=100`,{signal:f.signal});i.current===f&&r(m.mentions)}catch(m){i.current===f&&!Qm(m)&&(r([]),d&&l.current(we(m)))}finally{i.current===f&&(i.current=null)}},[t]);return u.useEffect(()=>(a(),()=>{i.current?.abort(),i.current=null}),[a,e]),{unreadMentions:s,refresh:a,markMentionRead:async d=>{try{return await pe(`/api/projects/${t}/mentions/${encodeURIComponent(d)}/read`,{method:"POST"}),r(f=>f.filter(m=>m.id!==d)),!0}catch(f){return l.current(we(f)),!1}},markAllMentionsRead:async()=>{if(!s.length)return!0;try{return await pe(`/api/projects/${t}/mentions/read-all`,{method:"POST"}),r([]),!0}catch(d){return l.current(we(d)),!1}}}}const wt=()=>new Map,no=t=>{const e=wt();return t.forEach((n,s)=>{e.set(s,n)}),e},It=(t,e,n)=>{let s=t.get(e);return s===void 0&&t.set(e,s=n()),s},tp=(t,e)=>{const n=[];for(const[s,r]of t)n.push(e(r,s));return n},np=(t,e)=>{for(const[n,s]of t)if(e(s,n))return!0;return!1},un=()=>new Set,Mi=t=>t[t.length-1],sp=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Yt=Array.from,jo=(t,e)=>{for(let n=0;n<t.length;n++)if(!e(t[n],n,t))return!1;return!0},Eo=(t,e)=>{for(let n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},rp=(t,e)=>{const n=new Array(t);for(let s=0;s<t;s++)n[s]=e(s,n);return n},rs=Array.isArray;class Do{constructor(){this._observers=wt()}on(e,n){return It(this._observers,e,un).add(n),n}once(e,n){const s=(...r)=>{this.off(e,s),n(...r)};this.on(e,s)}off(e,n){const s=this._observers.get(e);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(e))}emit(e,n){return Yt((this._observers.get(e)||wt()).values()).forEach(s=>s(...n))}destroy(){this._observers=wt()}}class hc{constructor(){this._observers=wt()}on(e,n){It(this._observers,e,un).add(n)}once(e,n){const s=(...r)=>{this.off(e,s),n(...r)};this.on(e,s)}off(e,n){const s=this._observers.get(e);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(e))}emit(e,n){return Yt((this._observers.get(e)||wt()).values()).forEach(s=>s(...n))}destroy(){this._observers=wt()}}const _t=Math.floor,gr=Math.abs,To=(t,e)=>t<e?t:e,Nn=(t,e)=>t>e?t:e,ip=Math.pow,fc=t=>t!==0?t<0:1/t<0,jr=Number.MAX_SAFE_INTEGER,ca=Number.MIN_SAFE_INTEGER,op=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&_t(t)===t),mc=String.fromCharCode,lp=t=>t.toLowerCase(),ap=/^\s*/g,cp=t=>t.replace(ap,""),up=/([A-Z])/g,ua=(t,e)=>cp(t.replace(up,n=>`${e}${lp(n)}`)),dp=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,s=new Uint8Array(n);for(let r=0;r<n;r++)s[r]=e.codePointAt(r);return s},Fs=typeof TextEncoder<"u"?new TextEncoder:null,hp=t=>Fs.encode(t),fp=Fs?hp:dp;let As=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});As&&As.decode(new Uint8Array).length===1&&(As=null);const mp=(t,e)=>rp(e,()=>t).join("");class Ks{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Ke=()=>new Ks,_o=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},Pe=t=>{const e=new Uint8Array(_o(t));let n=0;for(let s=0;s<t.bufs.length;s++){const r=t.bufs[s];e.set(r,n),n+=r.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),n),e},pp=(t,e)=>{const n=t.cbuf.length;n-t.cpos<e&&(t.bufs.push(new Uint8Array(t.cbuf.buffer,0,t.cpos)),t.cbuf=new Uint8Array(Nn(n,e)*2),t.cpos=0)},nt=(t,e)=>{const n=t.cbuf.length;t.cpos===n&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(n*2),t.cpos=0),t.cbuf[t.cpos++]=e},so=nt,ee=(t,e)=>{for(;e>Dn;)nt(t,dt|Dn&e),e=_t(e/128);nt(t,Dn&e)},Ro=(t,e)=>{const n=fc(e);for(n&&(e=-e),nt(t,(e>to?dt:0)|(n?Jt:0)|to&e),e=_t(e/64);e>0;)nt(t,(e>Dn?dt:0)|Dn&e),e=_t(e/128)},ro=new Uint8Array(3e4),gp=ro.length/3,wp=(t,e)=>{if(e.length<gp){const n=Fs.encodeInto(e,ro).written||0;ee(t,n);for(let s=0;s<n;s++)nt(t,ro[s])}else He(t,fp(e))},yp=(t,e)=>{const n=unescape(encodeURIComponent(e)),s=n.length;ee(t,s);for(let r=0;r<s;r++)nt(t,n.codePointAt(r))},ot=Fs&&Fs.encodeInto?wp:yp,qr=(t,e)=>{const n=t.cbuf.length,s=t.cpos,r=To(n-s,e.length),i=e.length-r;t.cbuf.set(e.subarray(0,r),s),t.cpos+=r,i>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(Nn(n*2,i)),t.cbuf.set(e.subarray(r)),t.cpos=i)},He=(t,e)=>{ee(t,e.byteLength),qr(t,e)},Lo=(t,e)=>{pp(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},bp=(t,e)=>Lo(t,4).setFloat32(0,e,!1),xp=(t,e)=>Lo(t,8).setFloat64(0,e,!1),kp=(t,e)=>Lo(t,8).setBigInt64(0,e,!1),da=new DataView(new ArrayBuffer(4)),Sp=t=>(da.setFloat32(0,t),da.getFloat32(0)===t),$s=(t,e)=>{switch(typeof e){case"string":nt(t,119),ot(t,e);break;case"number":op(e)&&gr(e)<=Lm?(nt(t,125),Ro(t,e)):Sp(e)?(nt(t,124),bp(t,e)):(nt(t,123),xp(t,e));break;case"bigint":nt(t,122),kp(t,e);break;case"object":if(e===null)nt(t,126);else if(rs(e)){nt(t,117),ee(t,e.length);for(let n=0;n<e.length;n++)$s(t,e[n])}else if(e instanceof Uint8Array)nt(t,116),He(t,e);else{nt(t,118);const n=Object.keys(e);ee(t,n.length);for(let s=0;s<n.length;s++){const r=n[s];ot(t,r),$s(t,e[r])}}break;case"boolean":nt(t,e?120:121);break;default:nt(t,127)}};class ha extends Ks{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ee(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const fa=t=>{t.count>0&&(Ro(t.encoder,t.count===1?t.s:-t.s),t.count>1&&ee(t.encoder,t.count-2))};class wr{constructor(){this.encoder=new Ks,this.s=0,this.count=0}write(e){this.s===e?this.count++:(fa(this),this.count=1,this.s=e)}toUint8Array(){return fa(this),Pe(this.encoder)}}const ma=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Ro(t.encoder,e),t.count>1&&ee(t.encoder,t.count-2)}};class Oi{constructor(){this.encoder=new Ks,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(ma(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return ma(this),Pe(this.encoder)}}class Cp{constructor(){this.sarr=[],this.s="",this.lensE=new wr}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new Ks;return this.sarr.push(this.s),this.s="",ot(e,this.sarr.join("")),qr(e,this.lensE.toUint8Array()),Pe(e)}}const Rt=t=>new Error(t),Tt=()=>{throw Rt("Method unimplemented")},St=()=>{throw Rt("Unexpected case")},pc=Rt("Unexpected end of array"),gc=Rt("Integer out of Range");class Wr{constructor(e){this.arr=e,this.pos=0}}const fn=t=>new Wr(t),io=t=>t.pos!==t.arr.length,vp=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},ct=t=>vp(t,me(t)),is=t=>t.arr[t.pos++],me=t=>{let e=0,n=1;const s=t.arr.length;for(;t.pos<s;){const r=t.arr[t.pos++];if(e=e+(r&Dn)*n,n*=128,r<dt)return e;if(e>jr)throw gc}throw pc},Ao=t=>{let e=t.arr[t.pos++],n=e&to,s=64;const r=(e&Jt)>0?-1:1;if((e&dt)===0)return r*n;const i=t.arr.length;for(;t.pos<i;){if(e=t.arr[t.pos++],n=n+(e&Dn)*s,s*=128,e<dt)return r*n;if(n>jr)throw gc}throw pc},jp=t=>{let e=me(t);if(e===0)return"";{let n=String.fromCodePoint(is(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(is(t));else for(;e>0;){const s=e<1e4?e:1e4,r=t.arr.subarray(t.pos,t.pos+s);t.pos+=s,n+=String.fromCodePoint.apply(null,r),e-=s}return decodeURIComponent(escape(n))}},Ep=t=>As.decode(ct(t)),We=As?Ep:jp,No=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Dp=t=>No(t,4).getFloat32(0,!1),Tp=t=>No(t,8).getFloat64(0,!1),_p=t=>No(t,8).getBigInt64(0,!1),Rp=[t=>{},t=>null,Ao,Dp,Tp,_p,t=>!1,t=>!0,We,t=>{const e=me(t),n={};for(let s=0;s<e;s++){const r=We(t);n[r]=Ps(t)}return n},t=>{const e=me(t),n=[];for(let s=0;s<e;s++)n.push(Ps(t));return n},ct],Ps=t=>Rp[127-is(t)](t);class pa extends Wr{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),io(this)?this.count=me(this)+1:this.count=-1),this.count--,this.s}}class yr extends Wr{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ao(this);const e=fc(this.s);this.count=1,e&&(this.s=-this.s,this.count=me(this)+2)}return this.count--,this.s}}class Fi extends Wr{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Ao(this),n=e&1;this.diff=_t(e/2),this.count=1,n&&(this.count=me(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Lp{constructor(e){this.decoder=new yr(e),this.str=We(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),n=this.str.slice(this.spos,e);return this.spos=e,n}}const Ap=crypto.getRandomValues.bind(crypto),wc=()=>Ap(new Uint32Array(1))[0],Np="10000000-1000-4000-8000"+-1e11,Mp=()=>Np.replace(/[018]/g,t=>(t^wc()&15>>t/4).toString(16)),dn=Date.now,os=t=>new Promise(t);Promise.all.bind(Promise);const ga=t=>t===void 0?null:t;class Op{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let yc=new Op,Mo=!0;try{typeof localStorage<"u"&&localStorage&&(yc=localStorage,Mo=!1)}catch{}const bc=yc,Fp=t=>Mo||addEventListener("storage",t),$p=t=>Mo||removeEventListener("storage",t),Is=Symbol("Equality"),xc=(t,e)=>t===e||!!t?.[Is]?.(e)||!1,Pp=t=>typeof t=="object",Ip=Object.assign,zp=Object.keys,Up=(t,e)=>{for(const n in t)e(t[n],n)},Bp=(t,e)=>{const n=[];for(const s in t)n.push(e(t[s],s));return n},Er=t=>zp(t).length,qp=t=>{for(const e in t)return!1;return!0},Gs=(t,e)=>{for(const n in t)if(!e(t[n],n))return!1;return!0},Oo=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Wp=(t,e)=>t===e||Er(t)===Er(e)&&Gs(t,(n,s)=>(n!==void 0||Oo(e,s))&&xc(e[s],n)),Vp=Object.freeze,kc=t=>{for(const e in t){const n=t[e];(typeof n=="object"||typeof n=="function")&&kc(t[e])}return Vp(t)},Fo=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&Fo(t,e,n+1)}},Hp=t=>t,Yn=(t,e)=>{if(t===e)return!0;if(t==null||e==null||t.constructor!==e.constructor&&(t.constructor||Object)!==(e.constructor||Object))return!1;if(t[Is]!=null)return t[Is](e);switch(t.constructor){case ArrayBuffer:t=new Uint8Array(t),e=new Uint8Array(e);case Uint8Array:{if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;break}case Set:{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;break}case Map:{if(t.size!==e.size)return!1;for(const n of t.keys())if(!e.has(n)||!Yn(t.get(n),e.get(n)))return!1;break}case void 0:case Object:if(Er(t)!==Er(e))return!1;for(const n in t)if(!Oo(t,n)||!Yn(t[n],e[n]))return!1;break;case Array:if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!Yn(t[n],e[n]))return!1;break;default:return!1}return!0},Kp=(t,e)=>e.includes(t);var Sc={};const hn=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",Cc=typeof window<"u"&&typeof document<"u"&&!hn;let Ot;const Gp=()=>{if(Ot===void 0)if(hn){Ot=wt();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const s=t[n];s[0]==="-"?(e!==null&&Ot.set(e,""),e=s):e!==null&&(Ot.set(e,s),e=null)}e!==null&&Ot.set(e,"")}else typeof location=="object"?(Ot=wt(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");Ot.set(`--${ua(e,"-")}`,n),Ot.set(`-${ua(e,"-")}`,n)}})):Ot=wt();return Ot},oo=t=>Gp().has(t),Dr=t=>ga(hn?Sc[t.toUpperCase().replaceAll("-","_")]:bc.getItem(t)),vc=t=>oo("--"+t)||Dr(t)!==null,Jp=vc("production"),Yp=hn&&Kp(Sc.FORCE_COLOR,["true","1","2"]),Xp=Yp||!oo("--no-colors")&&!vc("no-color")&&(!hn||process.stdout.isTTY)&&(!hn||oo("--color")||Dr("COLORTERM")!==null||(Dr("TERM")||"").includes("color")),jc=t=>new Uint8Array(t),Zp=(t,e,n)=>new Uint8Array(t,e,n),Qp=t=>new Uint8Array(t),eg=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=mc(t[n]);return btoa(e)},tg=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),ng=t=>{const e=atob(t),n=jc(e.length);for(let s=0;s<e.length;s++)n[s]=e.charCodeAt(s);return n},sg=t=>{const e=Buffer.from(t,"base64");return Zp(e.buffer,e.byteOffset,e.byteLength)},rg=Cc?eg:tg,ig=Cc?ng:sg,og=t=>{const e=jc(t.byteLength);return e.set(t),e};class lg{constructor(e,n){this.left=e,this.right=n}}const Ht=(t,e)=>new lg(t,e),ag=(t,e)=>t.forEach(n=>e(n.left,n.right)),wa=t=>t.next()>=.5,$i=(t,e,n)=>_t(t.next()*(n+1-e)+e),Ec=(t,e,n)=>_t(t.next()*(n+1-e)+e),$o=(t,e,n)=>Ec(t,e,n),cg=t=>mc($o(t,97,122)),ug=(t,e=0,n=20)=>{const s=$o(t,e,n);let r="";for(let i=0;i<s;i++)r+=cg(t);return r},Pi=(t,e)=>e[$o(t,0,e.length-1)],dg=Symbol("0schema");class hg{constructor(){this._rerrs=[]}extend(e,n,s,r=null){this._rerrs.push({path:e,expected:n,has:s,message:r})}toString(){const e=[];for(let n=this._rerrs.length-1;n>0;n--){const s=this._rerrs[n];e.push(mp(" ",(this._rerrs.length-n)*2)+`${s.path!=null?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`)}return e.join(`
|
|
6
|
+
`)}}const lo=(t,e)=>t===e?!0:t==null||e==null||t.constructor!==e.constructor?!1:t[Is]?xc(t,e):rs(t)?jo(t,n=>Eo(e,s=>lo(n,s))):Pp(t)?Gs(t,(n,s)=>lo(n,e[s])):!1;class ht{static _dilutes=!1;extends(e){let[n,s]=[this.shape,e.shape];return this.constructor._dilutes&&([s,n]=[n,s]),lo(n,s)}equals(e){return this.constructor===e.constructor&&Yn(this.shape,e.shape)}[dg](){return!0}[Is](e){return this.equals(e)}validate(e){return this.check(e)}check(e,n){Tt()}get nullable(){return ms(this,Jr)}get optional(){return new _c(this)}cast(e){return ya(e,this),e}expect(e){return ya(e,this),e}}class Po extends ht{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n=void 0){const s=e?.constructor===this.shape&&(this._c==null||this._c(e));return!s&&n?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),s}}const et=(t,e=null)=>new Po(t,e);et(Po);class Io extends ht{constructor(e){super(),this.shape=e}check(e,n){const s=this.shape(e);return!s&&n?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),s}}const rt=t=>new Io(t);et(Io);class Vr extends ht{constructor(e){super(),this.shape=e}check(e,n){const s=this.shape.some(r=>r===e);return!s&&n?.extend(null,this.shape.join(" | "),e.toString()),s}}const Hr=(...t)=>new Vr(t),Dc=et(Vr),fg=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Tc=t=>{if(ls.check(t))return[fg(t)];if(Dc.check(t))return t.shape.map(e=>e+"");if(Pc.check(t))return["[+-]?\\d+.?\\d*"];if(Ic.check(t))return[".*"];if(Tr.check(t))return t.shape.map(Tc).flat(1);St()};class mg extends ht{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Tc).map(n=>`(${n.join("|")})`).join("")+"$")}check(e,n){const s=this._r.exec(e)!=null;return!s&&n?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),s}}et(mg);const pg=Symbol("optional");class _c extends ht{constructor(e){super(),this.shape=e}check(e,n){const s=e===void 0||this.shape.check(e);return!s&&n?.extend(null,"undefined (optional)","()"),s}get[pg](){return!0}}const gg=et(_c);class wg extends ht{check(e,n){return n?.extend(null,"never",typeof e),!1}}et(wg);class Kr extends ht{constructor(e,n=!1){super(),this.shape=e,this._isPartial=n}static _dilutes=!0;get partial(){return new Kr(this.shape,!0)}check(e,n){return e==null?(n?.extend(null,"object","null"),!1):Gs(this.shape,(s,r)=>{const i=this._isPartial&&!Oo(e,r)||s.check(e[r],n);return!i&&n?.extend(r.toString(),s.toString(),typeof e[r],"Object property does not match"),i})}}const yg=t=>new Kr(t),bg=et(Kr),xg=rt(t=>t!=null&&(t.constructor===Object||t.constructor==null));class Rc extends ht{constructor(e,n){super(),this.shape={keys:e,values:n}}check(e,n){return e!=null&&Gs(e,(s,r)=>{const i=this.shape.keys.check(r,n);return!i&&n?.extend(r+"","Record",typeof e,i?"Key doesn't match schema":"Value doesn't match value"),i&&this.shape.values.check(s,n)})}}const Lc=(t,e)=>new Rc(t,e),kg=et(Rc);class Ac extends ht{constructor(e){super(),this.shape=e}check(e,n){return e!=null&&Gs(this.shape,(s,r)=>{const i=s.check(e[r],n);return!i&&n?.extend(r.toString(),"Tuple",typeof s),i})}}const Sg=(...t)=>new Ac(t);et(Ac);class Nc extends ht{constructor(e){super(),this.shape=e.length===1?e[0]:new zo(e)}check(e,n){const s=rs(e)&&jo(e,r=>this.shape.check(r));return!s&&n?.extend(null,"Array",""),s}}const Mc=(...t)=>new Nc(t),Cg=et(Nc),vg=rt(t=>rs(t));class Oc extends ht{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n){const s=e instanceof this.shape&&(this._c==null||this._c(e));return!s&&n?.extend(null,this.shape.name,e?.constructor.name),s}}const jg=(t,e=null)=>new Oc(t,e);et(Oc);const Eg=jg(ht);class Dg extends ht{constructor(e){super(),this.len=e.length-1,this.args=Sg(...e.slice(-1)),this.res=e[this.len]}check(e,n){const s=e.constructor===Function&&e.length<=this.len;return!s&&n?.extend(null,"function",typeof e),s}}const Tg=et(Dg),_g=rt(t=>typeof t=="function");class Rg extends ht{constructor(e){super(),this.shape=e}check(e,n){const s=jo(this.shape,r=>r.check(e,n));return!s&&n?.extend(null,"Intersectinon",typeof e),s}}et(Rg,t=>t.shape.length>0);class zo extends ht{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,n){const s=Eo(this.shape,r=>r.check(e,n));return n?.extend(null,"Union",typeof e),s}}const ms=(...t)=>t.findIndex(e=>Tr.check(e))>=0?ms(...t.map(e=>zs(e)).map(e=>Tr.check(e)?e.shape:[e]).flat(1)):t.length===1?t[0]:new zo(t),Tr=et(zo),Fc=()=>!0,_r=rt(Fc),Lg=et(Io,t=>t.shape===Fc),Uo=rt(t=>typeof t=="bigint"),Ag=rt(t=>t===Uo),$c=rt(t=>typeof t=="symbol");rt(t=>t===$c);const Xn=rt(t=>typeof t=="number"),Pc=rt(t=>t===Xn),ls=rt(t=>typeof t=="string"),Ic=rt(t=>t===ls),Gr=rt(t=>typeof t=="boolean"),Ng=rt(t=>t===Gr),zc=Hr(void 0);et(Vr,t=>t.shape.length===1&&t.shape[0]===void 0);Hr(void 0);const Jr=Hr(null),Mg=et(Vr,t=>t.shape.length===1&&t.shape[0]===null);et(Uint8Array);et(Po,t=>t.shape===Uint8Array);const Og=ms(Xn,ls,Jr,zc,Uo,Gr,$c);(()=>{const t=Mc(_r),e=Lc(ls,_r),n=ms(Xn,ls,Jr,Gr,t,e);return t.shape=n,e.shape.values=n,n})();const zs=t=>{if(Eg.check(t))return t;if(xg.check(t)){const e={};for(const n in t)e[n]=zs(t[n]);return yg(e)}else{if(vg.check(t))return ms(...t.map(zs));if(Og.check(t))return Hr(t);if(_g.check(t))return et(t)}St()},ya=Jp?()=>{}:(t,e)=>{const n=new hg;if(!e.check(t,n))throw Rt(`Expected value to be of type ${e.constructor.name}.
|
|
7
|
+
${n.toString()}`)};class Fg{constructor(e){this.patterns=[],this.$state=e}if(e,n){return this.patterns.push({if:zs(e),h:n}),this}else(e){return this.if(_r,e)}done(){return(e,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(e))return r.h(e,n)}throw Rt("Unhandled pattern")}}}const $g=t=>new Fg(t),Uc=$g(_r).if(Pc,(t,e)=>$i(e,ca,jr)).if(Ic,(t,e)=>ug(e)).if(Ng,(t,e)=>wa(e)).if(Ag,(t,e)=>BigInt($i(e,ca,jr))).if(Tr,(t,e)=>Vn(e,Pi(e,t.shape))).if(bg,(t,e)=>{const n={};for(const s in t.shape){let r=t.shape[s];if(gg.check(r)){if(wa(e))continue;r=r.shape}n[s]=Uc(r,e)}return n}).if(Cg,(t,e)=>{const n=[],s=Ec(e,0,42);for(let r=0;r<s;r++)n.push(Vn(e,t.shape));return n}).if(Dc,(t,e)=>Pi(e,t.shape)).if(Mg,(t,e)=>null).if(Tg,(t,e)=>{const n=Vn(e,t.res);return()=>n}).if(Lg,(t,e)=>Vn(e,Pi(e,[Xn,ls,Jr,zc,Uo,Gr,Mc(Xn),Lc(ms("a","b","c"),Xn)]))).if(kg,(t,e)=>{const n={},s=$i(e,0,3);for(let r=0;r<s;r++){const i=Vn(e,t.shape.keys),l=Vn(e,t.shape.values);n[i]=l}return n}).done(),Vn=(t,e)=>Uc(zs(e),t),zt=typeof document<"u"?document:{},Pg=t=>zt.createElement(t),Ig=()=>zt.createDocumentFragment();rt(t=>t.nodeType===Gg);const zg=t=>zt.createTextNode(t);typeof DOMParser<"u"&&new DOMParser;const Ug=(t,e)=>(ag(e,(n,s)=>{s===!1?t.removeAttribute(n):s===!0?t.setAttribute(n,""):t.setAttribute(n,s)}),t),Bg=t=>{const e=Ig();for(let n=0;n<t.length;n++)Bc(e,t[n]);return e},qg=(t,e)=>(Bc(t,Bg(e)),t),d0=(t,e=[],n=[])=>qg(Ug(Pg(t),e),n);rt(t=>t.nodeType===Vg);const h0=zg;rt(t=>t.nodeType===Hg);const Wg=t=>tp(t,(e,n)=>`${n}:${e};`).join(""),Bc=(t,e)=>t.appendChild(e),Vg=zt.ELEMENT_NODE,Hg=zt.TEXT_NODE;zt.CDATA_SECTION_NODE;zt.COMMENT_NODE;const Kg=zt.DOCUMENT_NODE;zt.DOCUMENT_TYPE_NODE;const Gg=zt.DOCUMENT_FRAGMENT_NODE;rt(t=>t.nodeType===Kg);const Xt=Symbol,qc=Xt(),Wc=Xt(),Jg=Xt(),Yg=Xt(),Xg=Xt(),Vc=Xt(),Zg=Xt(),Bo=Xt(),Qg=Xt(),ew=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[];let s=0;for(;s<t.length;s++){const r=t[s];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(s>0&&n.push(e.join(""));s<t.length;s++){const r=t[s];r instanceof Symbol||n.push(r)}return n},tw={[qc]:Ht("font-weight","bold"),[Wc]:Ht("font-weight","normal"),[Jg]:Ht("color","blue"),[Xg]:Ht("color","green"),[Yg]:Ht("color","grey"),[Vc]:Ht("color","red"),[Zg]:Ht("color","purple"),[Bo]:Ht("color","orange"),[Qg]:Ht("color","black")},nw=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[],s=wt();let r=[],i=0;for(;i<t.length;i++){const l=t[i],a=tw[l];if(a!==void 0)s.set(a.left,a.right);else{if(l===void 0)break;if(l.constructor===String||l.constructor===Number){const c=Wg(s);i>0||c.length>0?(e.push("%c"+l),n.push(c)):e.push(l)}else break}}for(i>0&&(r=n,r.unshift(e.join("")));i<t.length;i++){const l=t[i];l instanceof Symbol||r.push(l)}return r},Hc=Xp?nw:ew,sw=(...t)=>{console.log(...Hc(t)),Gc.forEach(e=>e.print(t))},Kc=(...t)=>{console.warn(...Hc(t)),t.unshift(Bo),Gc.forEach(e=>e.print(t))},Gc=un(),Jc=t=>({[Symbol.iterator](){return this},next:t}),rw=(t,e)=>Jc(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),Ii=(t,e)=>Jc(()=>{const{done:n,value:s}=t.next();return{done:n,value:n?void 0:e(s)}});class Yr{constructor(e,n){this.clock=e,this.len=n}}class ps{constructor(){this.clients=new Map}}const as=(t,e,n)=>e.clients.forEach((s,r)=>{const i=t.doc.store.clients.get(r);if(i!=null){const l=i[i.length-1],a=l.id.clock+l.length;for(let c=0,h=s[c];c<s.length&&h.clock<a;h=s[++c])uu(t,i,h.clock,h.len,n)}}),iw=(t,e)=>{let n=0,s=t.length-1;for(;n<=s;){const r=_t((n+s)/2),i=t[r],l=i.clock;if(l<=e){if(e<l+i.len)return r;n=r+1}else s=r-1}return null},Js=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&iw(n,e.clock)!==null},qo=t=>{t.clients.forEach(e=>{e.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<e.length;n++){const r=e[s-1],i=e[n];r.clock+r.len>=i.clock?e[s-1]=new Yr(r.clock,Nn(r.len,i.clock+i.len-r.clock)):(s<n&&(e[s]=i),s++)}e.length=s})},ao=t=>{const e=new ps;for(let n=0;n<t.length;n++)t[n].clients.forEach((s,r)=>{if(!e.clients.has(r)){const i=s.slice();for(let l=n+1;l<t.length;l++)sp(i,t[l].clients.get(r)||[]);e.clients.set(r,i)}});return qo(e),e},Us=(t,e,n,s)=>{It(t.clients,e,()=>[]).push(new Yr(n,s))},ow=()=>new ps,lw=t=>{const e=ow();return t.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const l=n[i];if(l.deleted){const a=l.id.clock;let c=l.length;if(i+1<n.length)for(let h=n[i+1];i+1<n.length&&h.deleted;h=n[++i+1])c+=h.length;r.push(new Yr(a,c))}}r.length>0&&e.clients.set(s,r)}),e},gs=(t,e)=>{ee(t.restEncoder,e.clients.size),Yt(e.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{t.resetDsCurVal(),ee(t.restEncoder,n);const r=s.length;ee(t.restEncoder,r);for(let i=0;i<r;i++){const l=s[i];t.writeDsClock(l.clock),t.writeDsLen(l.len)}})},Wo=t=>{const e=new ps,n=me(t.restDecoder);for(let s=0;s<n;s++){t.resetDsCurVal();const r=me(t.restDecoder),i=me(t.restDecoder);if(i>0){const l=It(e.clients,r,()=>[]);for(let a=0;a<i;a++)l.push(new Yr(t.readDsClock(),t.readDsLen()))}}return e},ba=(t,e,n)=>{const s=new ps,r=me(t.restDecoder);for(let i=0;i<r;i++){t.resetDsCurVal();const l=me(t.restDecoder),a=me(t.restDecoder),c=n.clients.get(l)||[],h=Je(n,l);for(let d=0;d<a;d++){const f=t.readDsClock(),m=f+t.readDsLen();if(f<h){h<m&&Us(s,l,h,m-h);let g=$t(c,f),w=c[g];for(!w.deleted&&w.id.clock<f&&(c.splice(g+1,0,$r(e,w,f-w.id.clock)),g++);g<c.length&&(w=c[g++],w.id.clock<m);)w.deleted||(m<w.id.clock+w.length&&c.splice(g,0,$r(e,w,m-w.id.clock)),w.delete(e))}else Us(s,l,f,m-f)}}if(s.clients.size>0){const i=new Rn;return ee(i.restEncoder,0),gs(i,s),i.toUint8Array()}return null},Yc=wc;class Mn extends Do{constructor({guid:e=Mp(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:l=!1,shouldLoad:a=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=Yc(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new au,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=a,this.autoLoad=l,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=os(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const c=()=>os(h=>{const d=f=>{(f===void 0||f===!0)&&(this.off("sync",d),h())};this.on("sync",d)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=c()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Ie(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Yt(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Ie(this,e,n)}get(e,n=st){const s=It(this.share,e,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==st&&r!==n)if(r===st){const i=new n;i._map=s._map,s._map.forEach(l=>{for(;l!==null;l=l.left)l.parent=i}),i._start=s._start;for(let l=i._start;l!==null;l=l.right)l.parent=i;return i._length=s._length,this.share.set(e,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return s}getArray(e=""){return this.get(e,es)}getText(e=""){return this.get(e,ds)}getMap(e=""){return this.get(e,us)}getXmlElement(e=""){return this.get(e,hs)}getXmlFragment(e=""){return this.get(e,Ln)}toJSON(){const e={};return this.share.forEach((n,s)=>{e[s]=n.toJSON()}),e}destroy(){this.isDestroyed=!0,Yt(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new Mn({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Ie(e.parent.doc,s=>{const r=n.doc;e.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Xc{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return me(this.restDecoder)}readDsLen(){return me(this.restDecoder)}}class Zc extends Xc{readLeftID(){return je(me(this.restDecoder),me(this.restDecoder))}readRightID(){return je(me(this.restDecoder),me(this.restDecoder))}readClient(){return me(this.restDecoder)}readInfo(){return is(this.restDecoder)}readString(){return We(this.restDecoder)}readParentInfo(){return me(this.restDecoder)===1}readTypeRef(){return me(this.restDecoder)}readLen(){return me(this.restDecoder)}readAny(){return Ps(this.restDecoder)}readBuf(){return og(ct(this.restDecoder))}readJSON(){return JSON.parse(We(this.restDecoder))}readKey(){return We(this.restDecoder)}}class aw{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=me(this.restDecoder),this.dsCurrVal}readDsLen(){const e=me(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class cs extends aw{constructor(e){super(e),this.keys=[],me(e),this.keyClockDecoder=new Fi(ct(e)),this.clientDecoder=new yr(ct(e)),this.leftClockDecoder=new Fi(ct(e)),this.rightClockDecoder=new Fi(ct(e)),this.infoDecoder=new pa(ct(e),is),this.stringDecoder=new Lp(ct(e)),this.parentInfoDecoder=new pa(ct(e),is),this.typeRefDecoder=new yr(ct(e)),this.lenDecoder=new yr(ct(e))}readLeftID(){return new Zn(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Zn(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 Ps(this.restDecoder)}readBuf(){return ct(this.restDecoder)}readJSON(){return Ps(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class Qc{constructor(){this.restEncoder=Ke()}toUint8Array(){return Pe(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ee(this.restEncoder,e)}writeDsLen(e){ee(this.restEncoder,e)}}class Ys extends Qc{writeLeftID(e){ee(this.restEncoder,e.client),ee(this.restEncoder,e.clock)}writeRightID(e){ee(this.restEncoder,e.client),ee(this.restEncoder,e.clock)}writeClient(e){ee(this.restEncoder,e)}writeInfo(e){so(this.restEncoder,e)}writeString(e){ot(this.restEncoder,e)}writeParentInfo(e){ee(this.restEncoder,e?1:0)}writeTypeRef(e){ee(this.restEncoder,e)}writeLen(e){ee(this.restEncoder,e)}writeAny(e){$s(this.restEncoder,e)}writeBuf(e){He(this.restEncoder,e)}writeJSON(e){ot(this.restEncoder,JSON.stringify(e))}writeKey(e){ot(this.restEncoder,e)}}class eu{constructor(){this.restEncoder=Ke(),this.dsCurrVal=0}toUint8Array(){return Pe(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,ee(this.restEncoder,n)}writeDsLen(e){e===0&&St(),ee(this.restEncoder,e-1),this.dsCurrVal+=e}}class Rn extends eu{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Oi,this.clientEncoder=new wr,this.leftClockEncoder=new Oi,this.rightClockEncoder=new Oi,this.infoEncoder=new ha(so),this.stringEncoder=new Cp,this.parentInfoEncoder=new ha(so),this.typeRefEncoder=new wr,this.lenEncoder=new wr}toUint8Array(){const e=Ke();return ee(e,0),He(e,this.keyClockEncoder.toUint8Array()),He(e,this.clientEncoder.toUint8Array()),He(e,this.leftClockEncoder.toUint8Array()),He(e,this.rightClockEncoder.toUint8Array()),He(e,Pe(this.infoEncoder)),He(e,this.stringEncoder.toUint8Array()),He(e,Pe(this.parentInfoEncoder)),He(e,this.typeRefEncoder.toUint8Array()),He(e,this.lenEncoder.toUint8Array()),qr(e,Pe(this.restEncoder)),Pe(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?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){$s(this.restEncoder,e)}writeBuf(e){He(this.restEncoder,e)}writeJSON(e){$s(this.restEncoder,e)}writeKey(e){const n=this.keyMap.get(e);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(n)}}const cw=(t,e,n,s)=>{s=Nn(s,e[0].id.clock);const r=$t(e,s);ee(t.restEncoder,e.length-r),t.writeClient(n),ee(t.restEncoder,s);const i=e[r];i.write(t,s-i.id.clock);for(let l=r+1;l<e.length;l++)e[l].write(t,0)},Vo=(t,e,n)=>{const s=new Map;n.forEach((r,i)=>{Je(e,i)>r&&s.set(i,r)}),Xr(e).forEach((r,i)=>{n.has(i)||s.set(i,0)}),ee(t.restEncoder,s.size),Yt(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{cw(t,e.clients.get(r),r,i)})},uw=(t,e)=>{const n=wt(),s=me(t.restDecoder);for(let r=0;r<s;r++){const i=me(t.restDecoder),l=new Array(i),a=t.readClient();let c=me(t.restDecoder);n.set(a,{i:0,refs:l});for(let h=0;h<i;h++){const d=t.readInfo();switch(Br&d){case 0:{const f=t.readLen();l[h]=new vt(je(a,c),f),c+=f;break}case 10:{const f=me(t.restDecoder);l[h]=new jt(je(a,c),f),c+=f;break}default:{const f=(d&(Jt|dt))===0,m=new ze(je(a,c),null,(d&dt)===dt?t.readLeftID():null,null,(d&Jt)===Jt?t.readRightID():null,f?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,f&&(d&Os)===Os?t.readString():null,Ru(t,d));l[h]=m,c+=m.length}}}}return n},dw=(t,e,n)=>{const s=[];let r=Yt(n.keys()).sort((g,w)=>g-w);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let g=n.get(r[r.length-1]);for(;g.refs.length===g.i;)if(r.pop(),r.length>0)g=n.get(r[r.length-1]);else return null;return g};let l=i();if(l===null)return null;const a=new au,c=new Map,h=(g,w)=>{const S=c.get(g);(S==null||S>w)&&c.set(g,w)};let d=l.refs[l.i++];const f=new Map,m=()=>{for(const g of s){const w=g.id.client,S=n.get(w);S?(S.i--,a.clients.set(w,S.refs.slice(S.i)),n.delete(w),S.i=0,S.refs=[]):a.clients.set(w,[g]),r=r.filter(L=>L!==w)}s.length=0};for(;;){if(d.constructor!==jt){const w=It(f,d.id.client,()=>Je(e,d.id.client))-d.id.clock;if(w<0)s.push(d),h(d.id.client,d.id.clock-1),m();else{const S=d.getMissing(t,e);if(S!==null){s.push(d);const L=n.get(S)||{refs:[],i:0};if(L.refs.length===L.i)h(S,Je(e,S)),m();else{d=L.refs[L.i++];continue}}else(w===0||w<d.length)&&(d.integrate(t,w),f.set(d.id.client,d.id.clock+d.length))}}if(s.length>0)d=s.pop();else if(l!==null&&l.i<l.refs.length)d=l.refs[l.i++];else{if(l=i(),l===null)break;d=l.refs[l.i++]}}if(a.clients.size>0){const g=new Rn;return Vo(g,a,new Map),ee(g.restEncoder,0),{missing:c,update:g.toUint8Array()}}return null},hw=(t,e)=>Vo(t,e.doc.store,e.beforeState),fw=(t,e,n,s=new cs(t))=>Ie(e,r=>{r.local=!1;let i=!1;const l=r.doc,a=l.store,c=uw(s,l),h=dw(r,a,c),d=a.pendingStructs;if(d){for(const[m,g]of d.missing)if(g<Je(a,m)){i=!0;break}if(h){for(const[m,g]of h.missing){const w=d.missing.get(m);(w==null||w>g)&&d.missing.set(m,g)}d.update=Lr([d.update,h.update])}}else a.pendingStructs=h;const f=ba(s,r,a);if(a.pendingDs){const m=new cs(fn(a.pendingDs));me(m.restDecoder);const g=ba(m,r,a);f&&g?a.pendingDs=Lr([f,g]):a.pendingDs=f||g}else a.pendingDs=f;if(i){const m=a.pendingStructs.update;a.pendingStructs=null,tu(r.doc,m)}},n,!1),tu=(t,e,n,s=cs)=>{const r=fn(e);fw(r,t,n,new s(r))},nu=(t,e,n)=>tu(t,e,n,Zc),mw=(t,e,n=new Map)=>{Vo(t,e.store,n),gs(t,lw(e.store))},pw=(t,e=new Uint8Array([0]),n=new Rn)=>{const s=su(e);mw(n,t,s);const r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(Mw(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===Ys)return Aw(r.map((i,l)=>l===0?i:Fw(i)));if(n.constructor===Rn)return Lr(r)}return r[0]},Ho=(t,e)=>pw(t,e,new Ys),gw=t=>{const e=new Map,n=me(t.restDecoder);for(let s=0;s<n;s++){const r=me(t.restDecoder),i=me(t.restDecoder);e.set(r,i)}return e},su=t=>gw(new Xc(fn(t))),ru=(t,e)=>(ee(t.restEncoder,e.size),Yt(e.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{ee(t.restEncoder,n),ee(t.restEncoder,s)}),t),ww=(t,e)=>ru(t,Xr(e.store)),yw=(t,e=new eu)=>(t instanceof Map?ru(e,t):ww(e,t),e.toUint8Array()),bw=t=>yw(t,new Qc);class xw{constructor(){this.l=[]}}const xa=()=>new xw,ka=(t,e)=>t.l.push(e),Sa=(t,e)=>{const n=t.l,s=n.length;t.l=n.filter(r=>e!==r),s===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},iu=(t,e,n)=>Fo(t.l,[e,n]);class Zn{constructor(e,n){this.client=e,this.clock=n}}const Gn=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,je=(t,e)=>new Zn(t,e),ou=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw St()},Rr=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1};class lu{constructor(e,n,s,r=0){this.type=e,this.tname=n,this.item=s,this.assoc=r}}const f0=t=>{const e={};return t.type&&(e.type=t.type),t.tname&&(e.tname=t.tname),t.item&&(e.item=t.item),t.assoc!=null&&(e.assoc=t.assoc),e},m0=t=>new lu(t.type==null?null:je(t.type.client,t.type.clock),t.tname??null,t.item==null?null:je(t.item.client,t.item.clock),t.assoc==null?0:t.assoc);class kw{constructor(e,n,s=0){this.type=e,this.index=n,this.assoc=s}}const Sw=(t,e,n=0)=>new kw(t,e,n),hr=(t,e,n)=>{let s=null,r=null;return t._item===null?r=ou(t):s=je(t._item.id.client,t._item.id.clock),new lu(s,r,e,n)},p0=(t,e,n=0)=>{let s=t._start;if(n<0){if(e===0)return hr(t,null,n);e--}for(;s!==null;){if(!s.deleted&&s.countable){if(s.length>e)return hr(t,je(s.id.client,s.id.clock+e),n);e-=s.length}if(s.right===null&&n<0)return hr(t,s.lastId,n);s=s.right}return hr(t,null,n)},Cw=(t,e)=>{const n=Qn(t,e),s=e.clock-n.id.clock;return{item:n,diff:s}},g0=(t,e,n=!0)=>{const s=e.store,r=t.item,i=t.type,l=t.tname,a=t.assoc;let c=null,h=0;if(r!==null){if(Je(s,r.client)<=r.clock)return null;const d=n?fo(s,r):Cw(s,r),f=d.item;if(!(f instanceof ze))return null;if(c=f.parent,c._item===null||!c._item.deleted){h=f.deleted||!f.countable?0:d.diff+(a>=0?0:1);let m=f.left;for(;m!==null;)!m.deleted&&m.countable&&(h+=m.length),m=m.left}}else{if(l!==null)c=e.get(l);else if(i!==null){if(Je(s,i.client)<=i.clock)return null;const{item:d}=n?fo(s,i):{item:Qn(s,i)};if(d instanceof ze&&d.content instanceof Ut)c=d.content.type;else return null}else throw St();a>=0?h=c._length:h=0}return Sw(c,h,t.assoc)},w0=(t,e)=>t===e||t!==null&&e!==null&&t.tname===e.tname&&Gn(t.item,e.item)&&Gn(t.type,e.type)&&t.assoc===e.assoc,Hn=(t,e)=>e===void 0?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!Js(e.ds,t.id),co=(t,e)=>{const n=It(t.meta,co,un),s=t.doc.store;n.has(e)||(e.sv.forEach((r,i)=>{r<Je(s,i)&>(t,je(i,r))}),as(t,e.ds,r=>{}),n.add(e))};class au{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Xr=t=>{const e=new Map;return t.clients.forEach((n,s)=>{const r=n[n.length-1];e.set(s,r.id.clock+r.length)}),e},Je=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},cu=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==e.id.clock)throw St()}n.push(e)},$t=(t,e)=>{let n=0,s=t.length-1,r=t[s],i=r.id.clock;if(i===e)return s;let l=_t(e/(i+r.length-1)*s);for(;n<=s;){if(r=t[l],i=r.id.clock,i<=e){if(e<i+r.length)return l;n=l+1}else s=l-1;l=_t((n+s)/2)}throw St()},vw=(t,e)=>{const n=t.clients.get(e.client);return n[$t(n,e.clock)]},Qn=vw,uo=(t,e,n)=>{const s=$t(e,n),r=e[s];return r.id.clock<n&&r instanceof ze?(e.splice(s+1,0,$r(t,r,n-r.id.clock)),s+1):s},gt=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[uo(t,n,e.clock)]},Ca=(t,e,n)=>{const s=e.clients.get(n.client),r=$t(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==vt&&s.splice(r+1,0,$r(t,i,n.clock-i.id.clock+1)),i},jw=(t,e,n)=>{const s=t.clients.get(e.id.client);s[$t(s,e.id.clock)]=n},uu=(t,e,n,s,r)=>{if(s===0)return;const i=n+s;let l=uo(t,e,n),a;do a=e[l++],i<a.id.clock+a.length&&uo(t,e,i),r(a);while(l<e.length&&e[l].id.clock<i)};class Ew{constructor(e,n,s){this.doc=e,this.deleteSet=new ps,this.beforeState=Xr(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const va=(t,e)=>e.deleteSet.clients.size===0&&!np(e.afterState,(n,s)=>e.beforeState.get(s)!==n)?!1:(qo(e.deleteSet),hw(t,e),gs(t,e.deleteSet),!0),ja=(t,e,n)=>{const s=e._item;(s===null||s.id.clock<(t.beforeState.get(s.id.client)||0)&&!s.deleted)&&It(t.changed,e,un).add(n)},br=(t,e)=>{let n=t[e],s=t[e-1],r=e;for(;r>0;n=s,s=t[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof ze&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=e-r;return i&&t.splice(e+1-i,i),i},Dw=(t,e,n)=>{for(const[s,r]of t.clients.entries()){const i=e.clients.get(s);for(let l=r.length-1;l>=0;l--){const a=r[l],c=a.clock+a.len;for(let h=$t(i,a.clock),d=i[h];h<i.length&&d.id.clock<c;d=i[++h]){const f=i[h];if(a.clock+a.len<=f.id.clock)break;f instanceof ze&&f.deleted&&!f.keep&&n(f)&&f.gc(e,!1)}}}},Tw=(t,e)=>{t.clients.forEach((n,s)=>{const r=e.clients.get(s);for(let i=n.length-1;i>=0;i--){const l=n[i],a=To(r.length-1,1+$t(r,l.clock+l.len-1));for(let c=a,h=r[c];c>0&&h.id.clock>=l.clock;h=r[c])c-=1+br(r,c)}})},du=(t,e)=>{if(e<t.length){const n=t[e],s=n.doc,r=s.store,i=n.deleteSet,l=n._mergeStructs;try{qo(i),n.afterState=Xr(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const a=[];n.changed.forEach((c,h)=>a.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(n,c)})),a.push(()=>{n.changedParentTypes.forEach((c,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(c=c.filter(d=>d.target._item===null||!d.target._item.deleted),c.forEach(d=>{d.currentTarget=h,d._path=null}),c.sort((d,f)=>d.path.length-f.path.length),a.push(()=>{iu(h._dEH,c,n)}))}),a.push(()=>s.emit("afterTransaction",[n,s])),a.push(()=>{n._needFormattingCleanup&&Yw(n)})}),Fo(a,[])}finally{s.gc&&Dw(i,r,s.gcFilter),Tw(i,r),n.afterState.forEach((d,f)=>{const m=n.beforeState.get(f)||0;if(m!==d){const g=r.clients.get(f),w=Nn($t(g,m),1);for(let S=g.length-1;S>=w;)S-=1+br(g,S)}});for(let d=l.length-1;d>=0;d--){const{client:f,clock:m}=l[d].id,g=r.clients.get(f),w=$t(g,m);w+1<g.length&&br(g,w+1)>1||w>0&&br(g,w)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(sw(Bo,qc,"[yjs] ",Wc,Vc,"Changed the client-id because another client seems to be using it."),s.clientID=Yc()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const d=new Ys;va(d,n)&&s.emit("update",[d.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const d=new Rn;va(d,n)&&s.emit("updateV2",[d.toUint8Array(),n.origin,s,n])}const{subdocsAdded:a,subdocsLoaded:c,subdocsRemoved:h}=n;(a.size>0||h.size>0||c.size>0)&&(a.forEach(d=>{d.clientID=s.clientID,d.collectionid==null&&(d.collectionid=s.collectionid),s.subdocs.add(d)}),h.forEach(d=>s.subdocs.delete(d)),s.emit("subdocs",[{loaded:c,added:a,removed:h},s,n]),h.forEach(d=>d.destroy())),t.length<=e+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,t])):du(t,e+1)}}},Ie=(t,e,n=null,s=!0)=>{const r=t._transactionCleanups;let i=!1,l=null;t._transaction===null&&(i=!0,t._transaction=new Ew(t,n,s),r.push(t._transaction),r.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{l=e(t._transaction)}finally{if(i){const a=t._transaction===r[0];t._transaction=null,a&&du(r,0)}}return l};class _w{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const Ea=(t,e,n)=>{as(t,n.deletions,s=>{s instanceof ze&&e.scope.some(r=>r===t.doc||Rr(r,s))&&el(s,!1)})},Da=(t,e,n)=>{let s=null;const r=t.doc,i=t.scope;Ie(r,a=>{for(;e.length>0&&t.currStackItem===null;){const c=r.store,h=e.pop(),d=new Set,f=[];let m=!1;as(a,h.insertions,g=>{if(g instanceof ze){if(g.redone!==null){let{item:w,diff:S}=fo(c,g.id);S>0&&(w=gt(a,je(w.id.client,w.id.clock+S))),g=w}!g.deleted&&i.some(w=>w===a.doc||Rr(w,g))&&f.push(g)}}),as(a,h.deletions,g=>{g instanceof ze&&i.some(w=>w===a.doc||Rr(w,g))&&!Js(h.insertions,g.id)&&d.add(g)}),d.forEach(g=>{m=_u(a,g,d,h.insertions,t.ignoreRemoteMapChanges,t)!==null||m});for(let g=f.length-1;g>=0;g--){const w=f[g];t.deleteFilter(w)&&(w.delete(a),m=!0)}t.currStackItem=m?h:null}a.changed.forEach((c,h)=>{c.has(null)&&h._searchMarker&&(h._searchMarker.length=0)}),s=a},t);const l=t.currStackItem;if(l!=null){const a=s.changedParentTypes;t.emit("stack-item-popped",[{stackItem:l,type:n,changedParentTypes:a,origin:t},t]),t.currStackItem=null}return l};class Rw extends Do{constructor(e,{captureTimeout:n=500,captureTransaction:s=c=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:l=!1,doc:a=rs(e)?e[0].doc:e instanceof Mn?e:e.doc}={}){super(),this.scope=[],this.doc=a,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=s,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=l,this.captureTimeout=n,this.afterTransactionHandler=c=>{if(!this.captureTransaction(c)||!this.scope.some(L=>c.changedParentTypes.has(L)||L===this.doc)||!this.trackedOrigins.has(c.origin)&&(!c.origin||!this.trackedOrigins.has(c.origin.constructor)))return;const h=this.undoing,d=this.redoing,f=h?this.redoStack:this.undoStack;h?this.stopCapturing():d||this.clear(!1,!0);const m=new ps;c.afterState.forEach((L,v)=>{const q=c.beforeState.get(v)||0,A=L-q;A>0&&Us(m,v,q,A)});const g=dn();let w=!1;if(this.lastChange>0&&g-this.lastChange<this.captureTimeout&&f.length>0&&!h&&!d){const L=f[f.length-1];L.deletions=ao([L.deletions,c.deleteSet]),L.insertions=ao([L.insertions,m])}else f.push(new _w(c.deleteSet,m)),w=!0;!h&&!d&&(this.lastChange=g),as(c,c.deleteSet,L=>{L instanceof ze&&this.scope.some(v=>v===c.doc||Rr(v,L))&&el(L,!0)});const S=[{stackItem:f[f.length-1],origin:c.origin,type:h?"redo":"undo",changedParentTypes:c.changedParentTypes},this];w?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){const n=new Set(this.scope);e=rs(e)?e:[e],e.forEach(s=>{n.has(s)||(n.add(s),(s instanceof st?s.doc!==this.doc:s!==this.doc)&&Kc("[yjs#509] Not same Y.Doc"),this.scope.push(s))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,n=!0){(e&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(s=>{e&&(this.undoStack.forEach(r=>Ea(s,this,r)),this.undoStack=[]),n&&(this.redoStack.forEach(r=>Ea(s,this,r)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Da(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Da(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*Lw(t){const e=me(t.restDecoder);for(let n=0;n<e;n++){const s=me(t.restDecoder),r=t.readClient();let i=me(t.restDecoder);for(let l=0;l<s;l++){const a=t.readInfo();if(a===10){const c=me(t.restDecoder);yield new jt(je(r,i),c),i+=c}else if((Br&a)!==0){const c=(a&(Jt|dt))===0,h=new ze(je(r,i),null,(a&dt)===dt?t.readLeftID():null,null,(a&Jt)===Jt?t.readRightID():null,c?t.readParentInfo()?t.readString():t.readLeftID():null,c&&(a&Os)===Os?t.readString():null,Ru(t,a));yield h,i+=h.length}else{const c=t.readLen();yield new vt(je(r,i),c),i+=c}}}}class Ko{constructor(e,n){this.gen=Lw(e),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===jt);return this.curr}}class Go{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const Aw=t=>Lr(t,Zc,Ys),Nw=(t,e)=>{if(t.constructor===vt){const{client:n,clock:s}=t.id;return new vt(je(n,s+e),t.length-e)}else if(t.constructor===jt){const{client:n,clock:s}=t.id;return new jt(je(n,s+e),t.length-e)}else{const n=t,{client:s,clock:r}=n.id;return new ze(je(s,r+e),null,je(s,r+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},Lr=(t,e=cs,n=Rn)=>{if(t.length===1)return t[0];const s=t.map(d=>new e(fn(d)));let r=s.map(d=>new Ko(d,!0)),i=null;const l=new n,a=new Go(l);for(;r=r.filter(m=>m.curr!==null),r.sort((m,g)=>{if(m.curr.id.client===g.curr.id.client){const w=m.curr.id.clock-g.curr.id.clock;return w===0?m.curr.constructor===g.curr.constructor?0:m.curr.constructor===jt?1:-1:w}else return g.curr.id.client-m.curr.id.client}),r.length!==0;){const d=r[0],f=d.curr.id.client;if(i!==null){let m=d.curr,g=!1;for(;m!==null&&m.id.clock+m.length<=i.struct.id.clock+i.struct.length&&m.id.client>=i.struct.id.client;)m=d.next(),g=!0;if(m===null||m.id.client!==f||g&&m.id.clock>i.struct.id.clock+i.struct.length)continue;if(f!==i.struct.id.client)ln(a,i.struct,i.offset),i={struct:m,offset:0},d.next();else if(i.struct.id.clock+i.struct.length<m.id.clock)if(i.struct.constructor===jt)i.struct.length=m.id.clock+m.length-i.struct.id.clock;else{ln(a,i.struct,i.offset);const w=m.id.clock-i.struct.id.clock-i.struct.length;i={struct:new jt(je(f,i.struct.id.clock+i.struct.length),w),offset:0}}else{const w=i.struct.id.clock+i.struct.length-m.id.clock;w>0&&(i.struct.constructor===jt?i.struct.length-=w:m=Nw(m,w)),i.struct.mergeWith(m)||(ln(a,i.struct,i.offset),i={struct:m,offset:0},d.next())}}else i={struct:d.curr,offset:0},d.next();for(let m=d.curr;m!==null&&m.id.client===f&&m.id.clock===i.struct.id.clock+i.struct.length&&m.constructor!==jt;m=d.next())ln(a,i.struct,i.offset),i={struct:m,offset:0}}i!==null&&(ln(a,i.struct,i.offset),i=null),Jo(a);const c=s.map(d=>Wo(d)),h=ao(c);return gs(l,h),l.toUint8Array()},Mw=(t,e,n=cs,s=Rn)=>{const r=su(e),i=new s,l=new Go(i),a=new n(fn(t)),c=new Ko(a,!1);for(;c.curr;){const d=c.curr,f=d.id.client,m=r.get(f)||0;if(c.curr.constructor===jt){c.next();continue}if(d.id.clock+d.length>m)for(ln(l,d,Nn(m-d.id.clock,0)),c.next();c.curr&&c.curr.id.client===f;)ln(l,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===f&&c.curr.id.clock+c.curr.length<=m;)c.next()}Jo(l);const h=Wo(a);return gs(i,h),i.toUint8Array()},hu=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:Pe(t.encoder.restEncoder)}),t.encoder.restEncoder=Ke(),t.written=0)},ln=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&hu(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),ee(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},Jo=t=>{hu(t);const e=t.encoder.restEncoder;ee(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const s=t.clientStructs[n];ee(e,s.written),qr(e,s.restEncoder)}},Ow=(t,e,n,s)=>{const r=new n(fn(t)),i=new Ko(r,!1),l=new s,a=new Go(l);for(let h=i.curr;h!==null;h=i.next())ln(a,e(h),0);Jo(a);const c=Wo(r);return gs(l,c),l.toUint8Array()},Fw=t=>Ow(t,Hp,cs,Ys),Ta="You must not compute changes after the event-handler fired.";class Zr{constructor(e,n){this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=$w(this.currentTarget,this.target))}deletes(e){return Js(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Rt(Ta);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let l,a;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))l="delete",a=Mi(c.content.getContent());else return;else c!==null&&this.deletes(c)?(l="update",a=Mi(c.content.getContent())):(l="add",a=void 0)}else if(this.deletes(i))l="delete",a=Mi(i.content.getContent());else return;e.set(r,{action:l,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 Rt(Ta);const n=this.target,s=un(),r=un(),i=[];if(e={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let a=null;const c=()=>{a&&i.push(a)};for(let h=n._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((a===null||a.delete===void 0)&&(c(),a={delete:0}),a.delete+=h.length,r.add(h)):this.adds(h)?((a===null||a.insert===void 0)&&(c(),a={insert:[]}),a.insert=a.insert.concat(h.content.getContent()),s.add(h)):((a===null||a.retain===void 0)&&(c(),a={retain:0}),a.retain+=h.length);a!==null&&a.retain===void 0&&c()}this._changes=e}return e}}const $w=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let s=0,r=e._item.parent._start;for(;r!==e._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}e=e._item.parent}return n},ut=()=>{Kc("Invalid access: Add Yjs type to a document before reading data.")},fu=80;let Yo=0;class Pw{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=Yo++}}const Iw=t=>{t.timestamp=Yo++},mu=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=Yo++},zw=(t,e,n)=>{if(t.length>=fu){const s=t.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return mu(s,e,n),s}else{const s=new Pw(e,n);return t.push(s),s}},Qr=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((i,l)=>gr(e-i.index)<gr(e-l.index)?i:l);let s=t._start,r=0;for(n!==null&&(s=n.p,r=n.index,Iw(n));s.right!==null&&r<e;){if(!s.deleted&&s.countable){if(e<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>e;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return n!==null&&gr(n.index-r)<s.parent.length/fu?(mu(n,s,r),n):zw(t._searchMarker,s,r)},Bs=(t,e,n)=>{for(let s=t.length-1;s>=0;s--){const r=t[s];if(n>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){t.splice(s,1);continue}r.p=i,i.marker=!0}(e<r.index||n>0&&e===r.index)&&(r.index=Nn(e,r.index+n))}},ei=(t,e,n)=>{const s=t,r=e.changedParentTypes;for(;It(r,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;iu(s._eH,n,e)};class st{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=xa(),this._dEH=xa(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw Tt()}clone(){throw Tt()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,n){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){ka(this._eH,e)}observeDeep(e){ka(this._dEH,e)}unobserve(e){Sa(this._eH,e)}unobserveDeep(e){Sa(this._dEH,e)}toJSON(){}}const pu=(t,e,n)=>{t.doc??ut(),e<0&&(e=t._length+e),n<0&&(n=t._length+n);let s=n-e;const r=[];let i=t._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const l=i.content.getContent();if(l.length<=e)e-=l.length;else{for(let a=e;a<l.length&&s>0;a++)r.push(l[a]),s--;e=0}}i=i.right}return r},gu=t=>{t.doc??ut();const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}n=n.right}return e},qs=(t,e)=>{let n=0,s=t._start;for(t.doc??ut();s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)e(r[i],n++,t)}s=s.right}},wu=(t,e)=>{const n=[];return qs(t,(s,r)=>{n.push(e(s,r,t))}),n},Uw=t=>{let e=t._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};n=e.content.getContent(),s=0,e=e.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},yu=(t,e)=>{t.doc??ut();const n=Qr(t,e);let s=t._start;for(n!==null&&(s=n.p,e-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(e<s.length)return s.content.getContent()[e];e-=s.length}},Ar=(t,e,n,s)=>{let r=n;const i=t.doc,l=i.clientID,a=i.store,c=n===null?e._start:n.right;let h=[];const d=()=>{h.length>0&&(r=new ze(je(l,Je(a,l)),r,r&&r.lastId,c,c&&c.id,e,null,new An(h)),r.integrate(t,0),h=[])};s.forEach(f=>{if(f===null)h.push(f);else switch(f.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(f);break;default:switch(d(),f.constructor){case Uint8Array:case ArrayBuffer:r=new ze(je(l,Je(a,l)),r,r&&r.lastId,c,c&&c.id,e,null,new Xs(new Uint8Array(f))),r.integrate(t,0);break;case Mn:r=new ze(je(l,Je(a,l)),r,r&&r.lastId,c,c&&c.id,e,null,new Zs(f)),r.integrate(t,0);break;default:if(f instanceof st)r=new ze(je(l,Je(a,l)),r,r&&r.lastId,c,c&&c.id,e,null,new Ut(f)),r.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},bu=()=>Rt("Length exceeded!"),xu=(t,e,n,s)=>{if(n>e._length)throw bu();if(n===0)return e._searchMarker&&Bs(e._searchMarker,n,s.length),Ar(t,e,null,s);const r=n,i=Qr(e,n);let l=e._start;for(i!==null&&(l=i.p,n-=i.index,n===0&&(l=l.prev,n+=l&&l.countable&&!l.deleted?l.length:0));l!==null;l=l.right)if(!l.deleted&&l.countable){if(n<=l.length){n<l.length&>(t,je(l.id.client,l.id.clock+n));break}n-=l.length}return e._searchMarker&&Bs(e._searchMarker,r,s.length),Ar(t,e,l,s)},Bw=(t,e,n)=>{let r=(e._searchMarker||[]).reduce((i,l)=>l.index>i.index?l:i,{index:0,p:e._start}).p;if(r)for(;r.right;)r=r.right;return Ar(t,e,r,n)},ku=(t,e,n,s)=>{if(s===0)return;const r=n,i=s,l=Qr(e,n);let a=e._start;for(l!==null&&(a=l.p,n-=l.index);a!==null&&n>0;a=a.right)!a.deleted&&a.countable&&(n<a.length&>(t,je(a.id.client,a.id.clock+n)),n-=a.length);for(;s>0&&a!==null;)a.deleted||(s<a.length&>(t,je(a.id.client,a.id.clock+s)),a.delete(t),s-=a.length),a=a.right;if(s>0)throw bu();e._searchMarker&&Bs(e._searchMarker,r,-i+s)},Nr=(t,e,n)=>{const s=e._map.get(n);s!==void 0&&s.delete(t)},Xo=(t,e,n,s)=>{const r=e._map.get(n)||null,i=t.doc,l=i.clientID;let a;if(s==null)a=new An([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:a=new An([s]);break;case Uint8Array:a=new Xs(s);break;case Mn:a=new Zs(s);break;default:if(s instanceof st)a=new Ut(s);else throw new Error("Unexpected content type")}new ze(je(l,Je(i.store,l)),r,r&&r.lastId,null,null,e,n,a).integrate(t,0)},Zo=(t,e)=>{t.doc??ut();const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Su=t=>{const e={};return t.doc??ut(),t._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Cu=(t,e)=>{t.doc??ut();const n=t._map.get(e);return n!==void 0&&!n.deleted},qw=(t,e)=>{const n={};return t._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!e.sv.has(i.id.client)||i.id.clock>=(e.sv.get(i.id.client)||0));)i=i.left;i!==null&&Hn(i,e)&&(n[r]=i.content.getContent()[i.length-1])}),n},fr=t=>(t.doc??ut(),rw(t._map.entries(),e=>!e[1].deleted));class Ww extends Zr{}class es extends st{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new es;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new es}clone(){const e=new es;return e.insert(0,this.toArray().map(n=>n instanceof st?n.clone():n)),e}get length(){return this.doc??ut(),this._length}_callObserver(e,n){super._callObserver(e,n),ei(this,e,new Ww(this,e))}insert(e,n){this.doc!==null?Ie(this.doc,s=>{xu(s,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Ie(this.doc,n=>{Bw(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Ie(this.doc,s=>{ku(s,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return yu(this,e)}toArray(){return gu(this)}slice(e=0,n=this.length){return pu(this,e,n)}toJSON(){return this.map(e=>e instanceof st?e.toJSON():e)}map(e){return wu(this,e)}forEach(e){qs(this,e)}[Symbol.iterator](){return Uw(this)}_write(e){e.writeTypeRef(py)}}const Vw=t=>new es;class Hw extends Zr{constructor(e,n,s){super(e,n),this.keysChanged=s}}class us extends st{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,n){super._integrate(e,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new us}clone(){const e=new us;return this.forEach((n,s)=>{e.set(s,n instanceof st?n.clone():n)}),e}_callObserver(e,n){ei(this,e,new Hw(this,e,n))}toJSON(){this.doc??ut();const e={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof st?r.toJSON():r}}),e}get size(){return[...fr(this)].length}keys(){return Ii(fr(this),e=>e[0])}values(){return Ii(fr(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Ii(fr(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ut(),this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Ie(this.doc,n=>{Nr(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Ie(this.doc,s=>{Xo(s,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return Zo(this,e)}has(e){return Cu(this,e)}clear(){this.doc!==null?Ie(this.doc,e=>{this.forEach(function(n,s,r){Nr(e,r,s)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(gy)}}const Kw=t=>new us,an=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&Wp(t,e);class ho{constructor(e,n,s,r){this.left=e,this.right=n,this.index=s,this.currentAttributes=r}forward(){this.right===null&&St(),this.right.content.constructor===tt?this.right.deleted||ws(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const _a=(t,e,n)=>{for(;e.right!==null&&n>0;)e.right.content.constructor===tt?e.right.deleted||ws(e.currentAttributes,e.right.content):e.right.deleted||(n<e.right.length&>(t,je(e.right.id.client,e.right.id.clock+n)),e.index+=e.right.length,n-=e.right.length),e.left=e.right,e.right=e.right.right;return e},mr=(t,e,n,s)=>{const r=new Map,i=s?Qr(e,n):null;if(i){const l=new ho(i.p.left,i.p,i.index,r);return _a(t,l,n-i.index)}else{const l=new ho(null,e._start,0,r);return _a(t,l,n)}},vu=(t,e,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===tt&&an(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=t.doc,i=r.clientID;s.forEach((l,a)=>{const c=n.left,h=n.right,d=new ze(je(i,Je(r.store,i)),c,c&&c.lastId,h,h&&h.id,e,null,new tt(a,l));d.integrate(t,0),n.right=d,n.forward()})},ws=(t,e)=>{const{key:n,value:s}=e;s===null?t.delete(n):t.set(n,s)},ju=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===tt&&an(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},Eu=(t,e,n,s)=>{const r=t.doc,i=r.clientID,l=new Map;for(const a in s){const c=s[a],h=n.currentAttributes.get(a)??null;if(!an(h,c)){l.set(a,h);const{left:d,right:f}=n;n.right=new ze(je(i,Je(r.store,i)),d,d&&d.lastId,f,f&&f.id,e,null,new tt(a,c)),n.right.integrate(t,0),n.forward()}}return l},zi=(t,e,n,s,r)=>{n.currentAttributes.forEach((m,g)=>{r[g]===void 0&&(r[g]=null)});const i=t.doc,l=i.clientID;ju(n,r);const a=Eu(t,e,n,r),c=s.constructor===String?new Pt(s):s instanceof st?new Ut(s):new On(s);let{left:h,right:d,index:f}=n;e._searchMarker&&Bs(e._searchMarker,n.index,c.getLength()),d=new ze(je(l,Je(i.store,l)),h,h&&h.lastId,d,d&&d.id,e,null,c),d.integrate(t,0),n.right=d,n.index=f,n.forward(),vu(t,e,n,a)},Ra=(t,e,n,s,r)=>{const i=t.doc,l=i.clientID;ju(n,r);const a=Eu(t,e,n,r);e:for(;n.right!==null&&(s>0||a.size>0&&(n.right.deleted||n.right.content.constructor===tt));){if(!n.right.deleted)switch(n.right.content.constructor){case tt:{const{key:c,value:h}=n.right.content,d=r[c];if(d!==void 0){if(an(d,h))a.delete(c);else{if(s===0)break e;a.set(c,h)}n.right.delete(t)}else n.currentAttributes.set(c,h);break}default:s<n.right.length&>(t,je(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let c="";for(;s>0;s--)c+=`
|
|
8
|
+
`;n.right=new ze(je(l,Je(i.store,l)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new Pt(c)),n.right.integrate(t,0),n.forward()}vu(t,e,n,a)},Du=(t,e,n,s,r)=>{let i=e;const l=wt();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===tt){const h=i.content;l.set(h.key,h)}i=i.right}let a=0,c=!1;for(;e!==i;){if(n===e&&(c=!0),!e.deleted){const h=e.content;if(h.constructor===tt){const{key:d,value:f}=h,m=s.get(d)??null;(l.get(d)!==h||m===f)&&(e.delete(t),a++,!c&&(r.get(d)??null)===f&&m!==f&&(m===null?r.delete(d):r.set(d,m))),!c&&!e.deleted&&ws(r,h)}}e=e.right}return a},Gw=(t,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const n=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===tt){const s=e.content.key;n.has(s)?e.delete(t):n.add(s)}e=e.left}},Jw=t=>{let e=0;return Ie(t.doc,n=>{let s=t._start,r=t._start,i=wt();const l=no(i);for(;r;)r.deleted===!1&&(r.content.constructor===tt?ws(l,r.content):(e+=Du(n,s,r,i,l),i=no(l),s=r)),r=r.right}),e},Yw=t=>{const e=new Set,n=t.doc;for(const[s,r]of t.afterState.entries()){const i=t.beforeState.get(s)||0;r!==i&&uu(t,n.store.clients.get(s),i,r,l=>{!l.deleted&&l.content.constructor===tt&&l.constructor!==vt&&e.add(l.parent)})}Ie(n,s=>{as(t,t.deleteSet,r=>{if(r instanceof vt||!r.parent._hasFormatting||e.has(r.parent))return;const i=r.parent;r.content.constructor===tt?e.add(i):Gw(s,r)});for(const r of e)Jw(r)})},La=(t,e,n)=>{const s=n,r=no(e.currentAttributes),i=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case Ut:case On:case Pt:n<e.right.length&>(t,je(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}i&&Du(t,i,e.right,r,e.currentAttributes);const l=(e.left||e.right).parent;return l._searchMarker&&Bs(l._searchMarker,e.index,-s+n),e};class Xw extends Zr{constructor(e,n,s){super(e,n),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const 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){const e=this.target.doc,n=[];Ie(e,s=>{const r=new Map,i=new Map;let l=this.target._start,a=null;const c={};let h="",d=0,f=0;const m=()=>{if(a!==null){let g=null;switch(a){case"delete":f>0&&(g={delete:f}),f=0;break;case"insert":(typeof h=="object"||h.length>0)&&(g={insert:h},r.size>0&&(g.attributes={},r.forEach((w,S)=>{w!==null&&(g.attributes[S]=w)}))),h="";break;case"retain":d>0&&(g={retain:d},qp(c)||(g.attributes=Ip({},c))),d=0;break}g&&n.push(g),a=null}};for(;l!==null;){switch(l.content.constructor){case Ut:case On:this.adds(l)?this.deletes(l)||(m(),a="insert",h=l.content.getContent()[0],m()):this.deletes(l)?(a!=="delete"&&(m(),a="delete"),f+=1):l.deleted||(a!=="retain"&&(m(),a="retain"),d+=1);break;case Pt:this.adds(l)?this.deletes(l)||(a!=="insert"&&(m(),a="insert"),h+=l.content.str):this.deletes(l)?(a!=="delete"&&(m(),a="delete"),f+=l.length):l.deleted||(a!=="retain"&&(m(),a="retain"),d+=l.length);break;case tt:{const{key:g,value:w}=l.content;if(this.adds(l)){if(!this.deletes(l)){const S=r.get(g)??null;an(S,w)?w!==null&&l.delete(s):(a==="retain"&&m(),an(w,i.get(g)??null)?delete c[g]:c[g]=w)}}else if(this.deletes(l)){i.set(g,w);const S=r.get(g)??null;an(S,w)||(a==="retain"&&m(),c[g]=S)}else if(!l.deleted){i.set(g,w);const S=c[g];S!==void 0&&(an(S,w)?S!==null&&l.delete(s):(a==="retain"&&m(),w===null?delete c[g]:c[g]=w))}l.deleted||(a==="insert"&&m(),ws(r,l.content));break}}l=l.right}for(m();n.length>0;){const g=n[n.length-1];if(g.retain!==void 0&&g.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class ds extends st{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ut(),this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new ds}clone(){const e=new ds;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const s=new Xw(this,e,n);ei(this,e,s),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ut();let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===Pt&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?Ie(this.doc,s=>{const r=new ho(null,this._start,0,new Map);for(let i=0;i<e.length;i++){const l=e[i];if(l.insert!==void 0){const a=!n&&typeof l.insert=="string"&&i===e.length-1&&r.right===null&&l.insert.slice(-1)===`
|
|
9
|
+
`?l.insert.slice(0,-1):l.insert;(typeof a!="string"||a.length>0)&&zi(s,this,r,a,l.attributes||{})}else l.retain!==void 0?Ra(s,this,r,l.retain,l.attributes||{}):l.delete!==void 0&&La(s,r,l.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,s){this.doc??ut();const r=[],i=new Map,l=this.doc;let a="",c=this._start;function h(){if(a.length>0){const f={};let m=!1;i.forEach((w,S)=>{m=!0,f[S]=w});const g={insert:a};m&&(g.attributes=f),r.push(g),a=""}}const d=()=>{for(;c!==null;){if(Hn(c,e)||n!==void 0&&Hn(c,n))switch(c.content.constructor){case Pt:{const f=i.get("ychange");e!==void 0&&!Hn(c,e)?(f===void 0||f.user!==c.id.client||f.type!=="removed")&&(h(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):n!==void 0&&!Hn(c,n)?(f===void 0||f.user!==c.id.client||f.type!=="added")&&(h(),i.set("ychange",s?s("added",c.id):{type:"added"})):f!==void 0&&(h(),i.delete("ychange")),a+=c.content.str;break}case Ut:case On:{h();const f={insert:c.content.getContent()[0]};if(i.size>0){const m={};f.attributes=m,i.forEach((g,w)=>{m[w]=g})}r.push(f);break}case tt:Hn(c,e)&&(h(),ws(i,c.content));break}c=c.right}h()};return e||n?Ie(l,f=>{e&&co(f,e),n&&co(f,n),d()},"cleanup"):d(),r}insert(e,n,s){if(n.length<=0)return;const r=this.doc;r!==null?Ie(r,i=>{const l=mr(i,this,e,!s);s||(s={},l.currentAttributes.forEach((a,c)=>{s[c]=a})),zi(i,this,l,n,s)}):this._pending.push(()=>this.insert(e,n,s))}insertEmbed(e,n,s){const r=this.doc;r!==null?Ie(r,i=>{const l=mr(i,this,e,!s);zi(i,this,l,n,s||{})}):this._pending.push(()=>this.insertEmbed(e,n,s||{}))}delete(e,n){if(n===0)return;const s=this.doc;s!==null?Ie(s,r=>{La(r,mr(r,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,s){if(n===0)return;const r=this.doc;r!==null?Ie(r,i=>{const l=mr(i,this,e,!1);l.right!==null&&Ra(i,this,l,n,s)}):this._pending.push(()=>this.format(e,n,s))}removeAttribute(e){this.doc!==null?Ie(this.doc,n=>{Nr(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Ie(this.doc,s=>{Xo(s,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return Zo(this,e)}getAttributes(){return Su(this)}_write(e){e.writeTypeRef(wy)}}const Zw=t=>new ds;class Ui{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ut()}[Symbol.iterator](){return this}next(){let e=this._currentNode,n=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(n)))do if(n=e.content.type,!e.deleted&&(n.constructor===hs||n.constructor===Ln)&&n._start!==null)e=n._start;else for(;e!==null;){const s=e.next;if(s!==null){e=s;break}else e.parent===this._root?e=null:e=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})}}class Ln extends st{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ln}clone(){const e=new Ln;return e.insert(0,this.toArray().map(n=>n instanceof st?n.clone():n)),e}get length(){return this.doc??ut(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ui(this,e)}querySelector(e){e=e.toUpperCase();const s=new Ui(this,r=>r.nodeName&&r.nodeName.toUpperCase()===e).next();return s.done?null:s.value}querySelectorAll(e){return e=e.toUpperCase(),Yt(new Ui(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){ei(this,e,new ty(this,n,e))}toString(){return wu(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},s){const r=e.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),qs(this,i=>{r.insertBefore(i.toDOM(e,n,s),null)}),r}insert(e,n){this.doc!==null?Ie(this.doc,s=>{xu(s,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Ie(this.doc,s=>{const r=e&&e instanceof st?e._item:e;Ar(s,this,r,n)});else{const s=this._prelimContent,r=e===null?0:s.findIndex(i=>i===e)+1;if(r===0&&e!==null)throw Rt("Reference item not found");s.splice(r,0,...n)}}delete(e,n=1){this.doc!==null?Ie(this.doc,s=>{ku(s,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return gu(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return yu(this,e)}slice(e=0,n=this.length){return pu(this,e,n)}forEach(e){qs(this,e)}_write(e){e.writeTypeRef(by)}}const Qw=t=>new Ln;class hs extends Ln{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,n){super._integrate(e,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new hs(this.nodeName)}clone(){const e=new hs(this.nodeName),n=this.getAttributes();return Up(n,(s,r)=>{e.setAttribute(r,s)}),e.insert(0,this.toArray().map(s=>s instanceof st?s.clone():s)),e}toString(){const e=this.getAttributes(),n=[],s=[];for(const a in e)s.push(a);s.sort();const r=s.length;for(let a=0;a<r;a++){const c=s[a];n.push(c+'="'+e[c]+'"')}const i=this.nodeName.toLocaleLowerCase(),l=n.length>0?" "+n.join(" "):"";return`<${i}${l}>${super.toString()}</${i}>`}removeAttribute(e){this.doc!==null?Ie(this.doc,n=>{Nr(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Ie(this.doc,s=>{Xo(s,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return Zo(this,e)}hasAttribute(e){return Cu(this,e)}getAttributes(e){return e?qw(this,e):Su(this)}toDOM(e=document,n={},s){const r=e.createElement(this.nodeName),i=this.getAttributes();for(const l in i){const a=i[l];typeof a=="string"&&r.setAttribute(l,a)}return qs(this,l=>{r.appendChild(l.toDOM(e,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(e){e.writeTypeRef(yy),e.writeKey(this.nodeName)}}const ey=t=>new hs(t.readKey());class ty extends Zr{constructor(e,n,s){super(e,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Mr extends us{constructor(e){super(),this.hookName=e}_copy(){return new Mr(this.hookName)}clone(){const e=new Mr(this.hookName);return this.forEach((n,s)=>{e.set(s,n)}),e}toDOM(e=document,n={},s){const r=n[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(e){e.writeTypeRef(xy),e.writeKey(this.hookName)}}const ny=t=>new Mr(t.readKey());class Or extends ds{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new Or}clone(){const e=new Or;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,s){const r=e.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{const n=[];for(const r in e.attributes){const i=[];for(const l in e.attributes[r])i.push({key:l,value:e.attributes[r][l]});i.sort((l,a)=>l.key<a.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let l=0;l<i.attrs.length;l++){const a=i.attrs[l];s+=` ${a.key}="${a.value}"`}s+=">"}s+=e.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(ky)}}const sy=t=>new Or;class Qo{constructor(e,n){this.id=e,this.length=n}get deleted(){throw Tt()}mergeWith(e){return!1}write(e,n,s){throw Tt()}integrate(e,n){throw Tt()}}const ry=0;class vt extends Qo{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){n>0&&(this.id.clock+=n,this.length-=n),cu(e.doc.store,this)}write(e,n){e.writeInfo(ry),e.writeLen(this.length-n)}getMissing(e,n){return null}}class Xs{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Xs(this.content)}splice(e){throw Tt()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const iy=t=>new Xs(t.readBuf());class Ws{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ws(this.len)}splice(e){const n=new Ws(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Us(e.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(e){}gc(e){}write(e,n){e.writeLen(this.len-n)}getRef(){return 1}}const oy=t=>new Ws(t.readLen()),Tu=(t,e)=>new Mn({guid:t,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class Zs{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;const n={};this.opts=n,e.gc||(n.gc=!1),e.autoLoad&&(n.autoLoad=!0),e.meta!==null&&(n.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Zs(Tu(this.doc.guid,this.opts))}splice(e){throw Tt()}mergeWith(e){return!1}integrate(e,n){this.doc._item=n,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,n){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}const ly=t=>new Zs(Tu(t.readString(),t.readAny()));class On{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new On(this.embed)}splice(e){throw Tt()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const ay=t=>new On(t.readJSON());class tt{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new tt(this.key,this.value)}splice(e){throw Tt()}mergeWith(e){return!1}integrate(e,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const cy=t=>new tt(t.readKey(),t.readJSON());class Fr{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Fr(this.arr)}splice(e){const n=new Fr(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const s=this.arr.length;e.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];e.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const uy=t=>{const e=t.readLen(),n=[];for(let s=0;s<e;s++){const r=t.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Fr(n)},dy=Dr("node_env")==="development";class An{constructor(e){this.arr=e,dy&&kc(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new An(this.arr)}splice(e){const n=new An(this.arr.slice(e));return this.arr=this.arr.slice(0,e),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){const s=this.arr.length;e.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];e.writeAny(i)}}getRef(){return 8}}const hy=t=>{const e=t.readLen(),n=[];for(let s=0;s<e;s++)n.push(t.readAny());return new An(n)};class Pt{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Pt(this.str)}splice(e){const n=new Pt(this.str.slice(e));this.str=this.str.slice(0,e);const s=this.str.charCodeAt(e-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,e-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const fy=t=>new Pt(t.readString()),my=[Vw,Kw,Zw,ey,Qw,ny,sy],py=0,gy=1,wy=2,yy=3,by=4,xy=5,ky=6;class Ut{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new Ut(this.type._copy())}splice(e){throw Tt()}mergeWith(e){return!1}integrate(e,n){this.type._integrate(e.doc,n)}delete(e){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e),n=n.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(e.beforeState.get(s.id.client)||0)&&e._mergeStructs.push(s):s.delete(e)}),e.changed.delete(this.type)}gc(e){let n=this.type._start;for(;n!==null;)n.gc(e,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(e,!0),s=s.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const Sy=t=>new Ut(my[t.readTypeRef()](t)),fo=(t,e)=>{let n=e,s=0,r;do s>0&&(n=je(n.client,n.clock+s)),r=Qn(t,n),s=n.clock-r.id.clock,n=r.redone;while(n!==null&&r instanceof ze);return{item:r,diff:s}},el=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},$r=(t,e,n)=>{const{client:s,clock:r}=e.id,i=new ze(je(s,r+n),e,je(s,r+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&i.markDeleted(),e.keep&&(i.keep=!0),e.redone!==null&&(i.redone=je(e.redone.client,e.redone.clock+n)),e.right=i,i.right!==null&&(i.right.left=i),t._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),e.length=n,i},Aa=(t,e)=>Eo(t,n=>Js(n.deletions,e)),_u=(t,e,n,s,r,i)=>{const l=t.doc,a=l.store,c=l.clientID,h=e.redone;if(h!==null)return gt(t,h);let d=e.parent._item,f=null,m;if(d!==null&&d.deleted===!0){if(d.redone===null&&(!n.has(d)||_u(t,d,n,s,r,i)===null))return null;for(;d.redone!==null;)d=gt(t,d.redone)}const g=d===null?e.parent:d.content.type;if(e.parentSub===null){for(f=e.left,m=e;f!==null;){let v=f;for(;v!==null&&v.parent._item!==d;)v=v.redone===null?null:gt(t,v.redone);if(v!==null&&v.parent._item===d){f=v;break}f=f.left}for(;m!==null;){let v=m;for(;v!==null&&v.parent._item!==d;)v=v.redone===null?null:gt(t,v.redone);if(v!==null&&v.parent._item===d){m=v;break}m=m.right}}else{if(m=null,e.right&&!r){for(f=e;f!==null&&f.right!==null&&(f.right.redone||Js(s,f.right.id)||Aa(i.undoStack,f.right.id)||Aa(i.redoStack,f.right.id));)for(f=f.right;f.redone;)f=gt(t,f.redone);if(f&&f.right!==null)return null}else f=g._map.get(e.parentSub)||null;f!==null&&f.parent._item!==d&&(f=g._map.get(e.parentSub)||null)}const w=Je(a,c),S=je(c,w),L=new ze(S,f,f&&f.lastId,m,m&&m.id,g,e.parentSub,e.content.copy());return e.redone=S,el(L,!0),L.integrate(t,0),L};class ze extends Qo{constructor(e,n,s,r,i,l,a,c){super(e,c.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=l,this.parentSub=a,this.redone=null,this.content=c,this.info=this.content.isCountable()?oa:0}set marker(e){(this.info&Ai)>0!==e&&(this.info^=Ai)}get marker(){return(this.info&Ai)>0}get keep(){return(this.info&ia)>0}set keep(e){this.keep!==e&&(this.info^=ia)}get countable(){return(this.info&oa)>0}get deleted(){return(this.info&Li)>0}set deleted(e){this.deleted!==e&&(this.info^=Li)}markDeleted(){this.info|=Li}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Je(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Je(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zn&&this.id.client!==this.parent.client&&this.parent.clock>=Je(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Ca(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=gt(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===vt||this.right&&this.right.constructor===vt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===ze?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===ze&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Zn){const s=Qn(n,this.parent);s.constructor===vt?this.parent=null:this.parent=s.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=Ca(e,e.doc.store,je(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,l=new Set;for(;r!==null&&r!==this.right;){if(l.add(r),i.add(r),Gn(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(Gn(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&l.has(Qn(e.doc.store,r.origin)))i.has(Qn(e.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),cu(e.doc.store,this),this.content.integrate(e,this),ja(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new vt(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:je(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Gn(e.origin,this.lastId)&&this.right===e&&Gn(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)){const n=this.parent._searchMarker;return n&&n.forEach(s=>{s.p===e&&(s.p=this,!this.deleted&&this.countable&&(s.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){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Us(e.deleteSet,this.id.client,this.id.clock,this.length),ja(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw St();this.content.gc(e),n?jw(e,this,new vt(this.id,this.length)):this.content=new Ws(this.length)}write(e,n){const s=n>0?je(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,l=this.content.getRef()&Br|(s===null?0:dt)|(r===null?0:Jt)|(i===null?0:Os);if(e.writeInfo(l),s!==null&&e.writeLeftID(s),r!==null&&e.writeRightID(r),s===null&&r===null){const a=this.parent;if(a._item!==void 0){const c=a._item;if(c===null){const h=ou(a);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(c.id)}else a.constructor===String?(e.writeParentInfo(!0),e.writeString(a)):a.constructor===Zn?(e.writeParentInfo(!1),e.writeLeftID(a)):St();i!==null&&e.writeString(i)}this.content.write(e,n)}}const Ru=(t,e)=>Cy[e&Br](t),Cy=[()=>{St()},oy,uy,iy,fy,ay,cy,Sy,hy,ly,()=>{St()}],vy=10;class jt extends Qo{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){St()}write(e,n){e.writeInfo(vy),ee(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const Lu=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Au="__ $YJS$ __";Lu[Au]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Lu[Au]=!0;function jy(t){for(let e=0;e<t.length;e+=1)t[e]=Math.floor(Math.random()*256);return t}function Ey(t){t[6]=t[6]&15|64,t[8]=t[8]&63|128;const e=Array.from(t,n=>n.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function mo(t=globalThis.crypto){if(typeof t?.randomUUID=="function")return t.randomUUID();const e=new Uint8Array(16),n=typeof t?.getRandomValues=="function"?t.getRandomValues(e):jy(e);return Ey(n)}const Nu=new Map;class Dy{constructor(e){this.room=e,this.onmessage=null,this._onChange=n=>n.key===e&&this.onmessage!==null&&this.onmessage({data:ig(n.newValue||"")}),Fp(this._onChange)}postMessage(e){bc.setItem(this.room,rg(Qp(e)))}close(){$p(this._onChange)}}const Ty=typeof BroadcastChannel>"u"?Dy:BroadcastChannel,tl=t=>It(Nu,t,()=>{const e=un(),n=new Ty(t);return n.onmessage=s=>e.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:e}}),_y=(t,e)=>(tl(t).subs.add(e),e),Ry=(t,e)=>{const n=tl(t),s=n.subs.delete(e);return s&&n.subs.size===0&&(n.bc.close(),Nu.delete(t)),s},Kn=(t,e,n=null)=>{const s=tl(t);s.bc.postMessage(e),s.subs.forEach(r=>r(e,n))},Mu=0,nl=1,Ou=2,Pr=(t,e)=>{ee(t,Mu);const n=bw(e);He(t,n)},Fu=(t,e,n)=>{ee(t,nl),He(t,Ho(e,n))},Ly=(t,e,n)=>Fu(e,n,ct(t)),$u=(t,e,n,s)=>{try{nu(e,ct(t),n)}catch(r){s?.(r),console.error("Caught error while handling a Yjs update",r)}},Ay=(t,e)=>{ee(t,Ou),He(t,e)},Ny=$u,My=(t,e,n,s,r)=>{const i=me(t);switch(i){case Mu:Ly(t,e,n);break;case nl:$u(t,n,s,r);break;case Ou:Ny(t,n,s,r);break;default:throw new Error("Unknown message type")}return i},Oy=0,Fy=(t,e,n)=>{me(t)===Oy&&n(e,We(t))},Bi=3e4;class $y extends hc{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=dn();this.getLocalState()!==null&&Bi/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Bi<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&sl(this,s,"timeout")},_t(Bi/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){const n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);e===null?this.states.delete(n):this.states.set(n,e),this.meta.set(n,{clock:r,lastUpdated:dn()});const l=[],a=[],c=[],h=[];e===null?h.push(n):i==null?e!=null&&l.push(n):(a.push(n),Yn(i,e)||c.push(n)),(l.length>0||c.length>0||h.length>0)&&this.emit("change",[{added:l,updated:c,removed:h},"local"]),this.emit("update",[{added:l,updated:a,removed:h},"local"])}setLocalStateField(e,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[e]:n})}getStates(){return this.states}}const sl=(t,e,n)=>{const s=[];for(let r=0;r<e.length;r++){const i=e[r];if(t.states.has(i)){if(t.states.delete(i),i===t.clientID){const l=t.meta.get(i);t.meta.set(i,{clock:l.clock+1,lastUpdated:dn()})}s.push(i)}}s.length>0&&(t.emit("change",[{added:[],updated:[],removed:s},n]),t.emit("update",[{added:[],updated:[],removed:s},n]))},ts=(t,e,n=t.states)=>{const s=e.length,r=Ke();ee(r,s);for(let i=0;i<s;i++){const l=e[i],a=n.get(l)||null,c=t.meta.get(l).clock;ee(r,l),ee(r,c),ot(r,JSON.stringify(a))}return Pe(r)},Py=(t,e,n)=>{const s=fn(e),r=dn(),i=[],l=[],a=[],c=[],h=me(s);for(let d=0;d<h;d++){const f=me(s);let m=me(s);const g=JSON.parse(We(s)),w=t.meta.get(f),S=t.states.get(f),L=w===void 0?0:w.clock;(L<m||L===m&&g===null&&t.states.has(f))&&(g===null?f===t.clientID&&t.getLocalState()!=null?m++:t.states.delete(f):t.states.set(f,g),t.meta.set(f,{clock:m,lastUpdated:r}),w===void 0&&g!==null?i.push(f):w!==void 0&&g===null?c.push(f):g!==null&&(Yn(g,S)||a.push(f),l.push(f)))}(i.length>0||a.length>0||c.length>0)&&t.emit("change",[{added:i,updated:a,removed:c},n]),(i.length>0||l.length>0||c.length>0)&&t.emit("update",[{added:i,updated:l,removed:c},n])},Iy=t=>Bp(t,(e,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(e)}`).join("&"),jn=0,Pu=3,ns=1,zy=2,Qs=[];Qs[jn]=(t,e,n,s,r)=>{ee(t,jn);const i=My(e,t,n.doc,n);s&&i===nl&&!n.synced&&(n.synced=!0)};Qs[Pu]=(t,e,n,s,r)=>{ee(t,ns),He(t,ts(n.awareness,Array.from(n.awareness.getStates().keys())))};Qs[ns]=(t,e,n,s,r)=>{Py(n.awareness,ct(e),n)};Qs[zy]=(t,e,n,s,r)=>{Fy(e,n.doc,(i,l)=>Uy(n,l))};const Na=3e4,Uy=(t,e)=>console.warn(`Permission denied to access ${t.url}.
|
|
10
|
+
${e}`),Iu=(t,e,n)=>{const s=fn(e),r=Ke(),i=me(s),l=t.messageHandlers[i];return l?l(r,s,t,n,i):console.error("Unable to compute message"),r},po=(t,e,n)=>{e===t.ws&&(t.emit("connection-close",[n,t]),t.ws=null,e.close(),t.wsconnecting=!1,t.wsconnected?(t.wsconnected=!1,t.synced=!1,sl(t.awareness,Array.from(t.awareness.getStates().keys()).filter(s=>s!==t.doc.clientID),t),t.emit("status",[{status:"disconnected"}])):t.wsUnsuccessfulReconnects++,setTimeout(zu,To(ip(2,t.wsUnsuccessfulReconnects)*100,t.maxBackoffTime),t))},zu=t=>{if(t.shouldConnect&&t.ws===null){const e=new t._WS(t.url,t.protocols);e.binaryType="arraybuffer",t.ws=e,t.wsconnecting=!0,t.wsconnected=!1,t.synced=!1,e.onmessage=n=>{t.wsLastMessageReceived=dn();const s=Iu(t,new Uint8Array(n.data),!0);_o(s)>1&&e.send(Pe(s))},e.onerror=n=>{t.emit("connection-error",[n,t])},e.onclose=n=>{po(t,e,n)},e.onopen=()=>{t.wsLastMessageReceived=dn(),t.wsconnecting=!1,t.wsconnected=!0,t.wsUnsuccessfulReconnects=0,t.emit("status",[{status:"connected"}]);const n=Ke();if(ee(n,jn),Pr(n,t.doc),e.send(Pe(n)),t.awareness.getLocalState()!==null){const s=Ke();ee(s,ns),He(s,ts(t.awareness,[t.doc.clientID])),e.send(Pe(s))}},t.emit("status",[{status:"connecting"}])}},qi=(t,e)=>{const n=t.ws;t.wsconnected&&n&&n.readyState===n.OPEN&&n.send(e),t.bcconnected&&Kn(t.bcChannel,e,t)};class By extends Do{constructor(e,n,s,{connect:r=!0,awareness:i=new $y(s),params:l={},protocols:a=[],WebSocketPolyfill:c=WebSocket,resyncInterval:h=-1,maxBackoffTime:d=2500,disableBc:f=!1}={}){for(super();e[e.length-1]==="/";)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+n,this.maxBackoffTime=d,this.params=l,this.protocols=a,this.roomname=n,this.doc=s,this._WS=c,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=f,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Qs.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,h>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const m=Ke();ee(m,jn),Pr(m,s),this.ws.send(Pe(m))}},h)),this._bcSubscriber=(m,g)=>{if(g!==this){const w=Iu(this,new Uint8Array(m),!1);_o(w)>1&&Kn(this.bcChannel,Pe(w),this)}},this._updateHandler=(m,g)=>{if(g!==this){const w=Ke();ee(w,jn),Ay(w,m),qi(this,Pe(w))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:m,updated:g,removed:w},S)=>{const L=m.concat(g).concat(w),v=Ke();ee(v,ns),He(v,ts(i,L)),qi(this,Pe(v))},this._exitHandler=()=>{sl(this.awareness,[s.clientID],"app closed")},hn&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Na<dn()-this.wsLastMessageReceived&&po(this,this.ws,null)},Na/10),r&&this.connect()}get url(){const e=Iy(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(),hn&&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||(_y(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=Ke();ee(e,jn),Pr(e,this.doc),Kn(this.bcChannel,Pe(e),this);const n=Ke();ee(n,jn),Fu(n,this.doc),Kn(this.bcChannel,Pe(n),this);const s=Ke();ee(s,Pu),Kn(this.bcChannel,Pe(s),this);const r=Ke();ee(r,ns),He(r,ts(this.awareness,[this.doc.clientID])),Kn(this.bcChannel,Pe(r),this)}disconnectBc(){const e=Ke();ee(e,ns),He(e,ts(this.awareness,[this.doc.clientID],new Map)),qi(this,Pe(e)),this.bcconnected&&(Ry(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&po(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(zu(this),this.connectBc())}}const Fn=t=>os((e,n)=>{t.onerror=s=>n(new Error(s.target.error)),t.onsuccess=s=>e(s.target.result)}),qy=(t,e)=>os((n,s)=>{const r=indexedDB.open(t);r.onupgradeneeded=i=>e(i.target.result),r.onerror=i=>s(Rt(i.target.error)),r.onsuccess=i=>{const l=i.target.result;l.onversionchange=()=>{l.close()},n(l)}}),Wy=t=>Fn(indexedDB.deleteDatabase(t)),Vy=(t,e)=>e.forEach(n=>t.createObjectStore.apply(t,n)),_s=(t,e,n="readwrite")=>{const s=t.transaction(e,n);return e.map(r=>Qy(s,r))},Uu=(t,e)=>Fn(t.count(e)),Hy=(t,e)=>Fn(t.get(e)),Bu=(t,e)=>Fn(t.delete(e)),Ky=(t,e,n)=>Fn(t.put(e,n)),go=(t,e)=>Fn(t.add(e)),Gy=(t,e,n)=>Fn(t.getAll(e,n)),Jy=(t,e,n)=>{let s=null;return Zy(t,e,r=>(s=r,!1),n).then(()=>s)},Yy=(t,e=null)=>Jy(t,e,"prev"),Xy=(t,e)=>os((n,s)=>{t.onerror=s,t.onsuccess=async r=>{const i=r.target.result;if(i===null||await e(i)===!1)return n();i.continue()}}),Zy=(t,e,n,s="next")=>Xy(t.openKeyCursor(e,s),r=>n(r.key)),Qy=(t,e)=>t.objectStore(e),eb=(t,e)=>IDBKeyRange.upperBound(t,e),tb=(t,e)=>IDBKeyRange.lowerBound(t,e),Wi="custom",qu="updates",Wu=500,Vu=(t,e=()=>{},n=()=>{})=>{const[s]=_s(t.db,[qu]);return Gy(s,tb(t._dbref,!1)).then(r=>{t._destroyed||(e(s),Ie(t.doc,()=>{r.forEach(i=>nu(t.doc,i))},t,!1),n(s))}).then(()=>Yy(s).then(r=>{t._dbref=r+1})).then(()=>Uu(s).then(r=>{t._dbsize=r})).then(()=>s)},nb=(t,e=!0)=>Vu(t).then(n=>{(e||t._dbsize>=Wu)&&go(n,Ho(t.doc)).then(()=>Bu(n,eb(t._dbref,!0))).then(()=>Uu(n).then(s=>{t._dbsize=s}))});class sb extends hc{constructor(e,n){super(),this.doc=n,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=qy(e,s=>Vy(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=os(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,Vu(this,l=>go(l,Ho(n)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(s,r)=>{if(this.db&&r!==this){const[i]=_s(this.db,[qu]);go(i,s),++this._dbsize>=Wu&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{nb(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},n.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),n.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(()=>{Wy(this.name)})}get(e){return this._db.then(n=>{const[s]=_s(n,[Wi],"readonly");return Hy(s,e)})}set(e,n){return this._db.then(s=>{const[r]=_s(s,[Wi]);return Ky(r,n,e)})}del(e){return this._db.then(n=>{const[s]=_s(n,[Wi]);return Bu(s,e)})}}const rb={Sync:0,Awareness:1,Flush:4,Protocol:5,Maintenance:6,Permission:7,CompileStates:8,FormatLease:9},Vi=3,ib=["queued","running","succeeded","failed","cleaned"],ob=["cache","artifacts"];function lb(t){return typeof t=="string"&&ib.includes(t)}function ab(t){return typeof t=="string"&&ob.includes(t)}const Ma=[["#1677c8","#1677c833"],["#d65745","#d6574533"],["#16866a","#16866a33"],["#9a58b5","#9a58b533"],["#d27b18","#d27b1833"],["#3f7d20","#3f7d2033"],["#be3e7b","#be3e7b33"],["#4964c6","#4964c633"],["#8a6a14","#8a6a1433"],["#087f8c","#087f8c33"]],{Sync:cb,Awareness:ub,Flush:Oa,Protocol:Fa,Maintenance:db,Permission:hb,CompileStates:fb,FormatLease:Hi}=rb,mb=6e4,pb=720*60*60*1e3,gb=15e3,wb=5*6e4;function yb(t){if(!t||typeof t!="object")return null;const e=t,n=e.requestedBy;return typeof e.mainFile!="string"||typeof e.runId!="string"||!lb(e.status)||e.status==="cleaned"&&!ab(e.cleanMode)||e.stale!==void 0&&typeof e.stale!="boolean"||typeof e.updatedAt!="string"||!n||typeof n.id!="string"||typeof n.username!="string"||typeof n.name!="string"?null:e}function $a(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e={};for(const[n,s]of Object.entries(t)){const r=yb(s);r&&r.mainFile===n&&(e[n]=r)}return e}function bb(t,e,n){return t<=n&&e<=n}function Pa(t,e,n){const s=r=>r>0&&n-r<=wb;return{recoverable:t.some(r=>r.tabId===e||!s(r.activeAt)),otherActive:t.some(r=>r.tabId!==e&&s(r.activeAt))}}class xb{constructor(e,n){this.projectId=e,this.user=n;const s=window.location.protocol==="https:"?"wss:":"ws:";this.draftTabId=vb(Cn(`texlite:collaboration-tab:${n.id}:${e}`));const 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 sb(Cn(`texlite:${n.id}:${e}`),this.doc),this.localDraftTransactionObserver=l=>{if(l.local){for(const[a,c]of this.doc.share)if(a.startsWith("source:")&&(l.changed.has(c)||l.changedParentTypes.has(c))){this.markWritableDraft();return}}},this.doc.on("afterTransaction",this.localDraftTransactionObserver),this.persistence.on("synced",()=>{this.localDraftReady=!0;for(const l of this.draftListeners)l()}),this.provider=new By(`${s}//${window.location.host}${fs("/api/collaboration")}`,e,this.doc,{connect:!1,disableBc:!0,maxBackoffTime:2500}),this.awareness=this.provider.awareness;const i=this.doc.getMap("texlite:meta");this.metaObserver=(l,a)=>{a.origin===this.provider&&l.keysChanged.has("compileStates")&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners())},i.observe(this.metaObserver),this.provider.messageHandlers[Oa]=(l,a)=>{const c=We(a),h=this.flushRequests.get(c);if(!h)return;const d=me(a)===1,f=me(a),m=We(a),g=me(a),w=[];for(let S=0;S<g;S++)w.push(We(a));if(window.clearTimeout(h.timer),this.flushRequests.delete(c),d)this.clearOwnWritableDraftMarker(h.draftGeneration),h.resolve({revision:f,persistedAt:m,ok:!0,failedPaths:[]});else{const S=Object.assign(new Error(w.length?`保存失败:${w.join(", ")}`:"源码保存到服务器磁盘失败"),{failedPaths:w});h.reject(S)}},this.provider.messageHandlers[Fa]=(l,a)=>{const c=We(a),h=this.epochStorageKey(),d=Ia(h),f=/^([0-9]+):/.exec(c)?.[1]??null,m=d?/^([0-9]+):/.exec(d)?.[1]??null:null,g=!this.epoch&&f===String(Vi)&&m!==null&&m!==f;if((this.epoch&&this.epoch!==c||d&&d!==c)&&!g){this.provider.disconnect(),this.rejectFlushes(new Error("Collaboration state changed"));const q=c.endsWith(":reload")||f!==null&&f!==String(Vi),A=()=>{Ki(h,c.replace(/:reload$/,"")),window.location.reload()};if(q)for(const x of this.protocolUpgradeListeners)x();else this.persistence.clearData().then(()=>{this.clearWritableDraftMarkers(),A()});return}this.epoch=c,Ki(h,c);const w=this.provider.ws;if(!w||w.readyState!==WebSocket.OPEN)return;const S=Ke();ee(S,Fa),ot(S,c),ee(S,Vi),w.send(Pe(S));const L=Ke();ee(L,cb),Pr(L,this.doc),w.send(Pe(L));const v=Ke();ee(v,ub),He(v,ts(this.awareness,[this.doc.clientID])),w.send(Pe(v))},this.provider.messageHandlers[hb]=(l,a)=>{const c=We(a),h=We(a);if(c!==this.user.id)return;if(h==="revoked"){this.rejectFlushes(new Error("Project access revoked")),this.provider.disconnect();for(const f of this.permissionListeners)f("revoked",this.permission);return}if(h!=="read"&&h!=="edit"&&h!=="owner")return;const d=this.permission;if(this.setPermission(h),d!==h){h==="read"&&this.rejectFlushes(new Error("Project permission changed to read-only"));for(const f of this.permissionListeners)f(h,d)}},this.provider.messageHandlers[db]=(l,a)=>{We(a)},this.provider.messageHandlers[fb]=(l,a)=>{let c={};try{c=$a(JSON.parse(We(a)))}catch{}this.authoritativeCompileStates=c,this.notifyCompileStateListeners()},this.provider.messageHandlers[Hi]=(l,a)=>{const c=We(a),h=We(a),d=We(a),f=We(a),m=We(a),g=We(a);if(c==="state"){const S=io(a)?We(a):"",L=io(a)?We(a):"",v=Number(m);if(!S||!Number.isFinite(v)||v<=Date.now())this.removeFormatLeaseState(d),this.notifyFormatLeaseListeners(null);else{const q={path:d,holderUserId:S,holderName:L,expiresAt:v};this.formatLeaseStatesByPath.set(d,q);const A=this.formatLeaseExpiryTimers.get(d);A!==void 0&&window.clearTimeout(A);const x=window.setTimeout(()=>{const P=this.formatLeaseStatesByPath.get(d);!P||P.expiresAt>Date.now()||(this.removeFormatLeaseState(d),this.notifyFormatLeaseListeners(null))},Math.max(0,v-Date.now())+25);this.formatLeaseExpiryTimers.set(d,x),this.notifyFormatLeaseListeners(q)}return}const w=this.formatLeaseRequests.get(h);w&&(window.clearTimeout(w.timer),this.formatLeaseRequests.delete(h),c==="denied"?w.reject(new Error(g||"Format lease request was denied")):w.resolve({status:c,filePath:d,token:f,expiresAt:Number(m)}))},this.provider.on("status",({status:l})=>{l==="disconnected"&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners(),this.rejectFlushes(new Error("Collaboration connection closed")),this.rejectFormatLeaseRequests(new Error("Collaboration connection closed")),this.clearFormatLeaseStates())}),this.updateLocalAwareness()}projectId;user;doc=new Mn;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;connect(){this.destroyed||(this.provider.connect(),this.updateLocalAwareness())}getText(e){return this.doc.getText(`source:${e}`)}getUndoManager(e){const n=this.undoManagers.get(e);if(n)return n;const s=new Rw(this.getText(e));return this.undoManagers.set(e,s),s}applyTextEdits(e,n){if(this.permission==="read")throw new Error("Read-only collaborators cannot edit source files");const s=this.getText(e);let r=0;for(const i of n){if(!Number.isInteger(i.from)||!Number.isInteger(i.to)||i.from<r||i.to<i.from||i.to>s.length)throw new RangeError("Invalid collaborative text edits");r=i.to}this.doc.transact(()=>{for(let i=n.length-1;i>=0;i-=1){const l=n[i];l.to>l.from&&s.delete(l.from,l.to-l.from),l.replacement&&s.insert(l.from,l.replacement)}})}get meta(){return this.doc.getMap("texlite:meta")}compileStates(){return this.authoritativeCompileStates??$a(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?!1:(await this.persistence.clearData(),this.localDraftReady=!1,this.clearWritableDraftMarkers(),!0)}get hasWritableDraft(){const e=this.readWritableDraftMarkers();return Pa(e.map(({tabId:n,marker:s})=>({tabId:n,activeAt:s.activeAt})),this.draftTabId,Date.now()).recoverable}get hasOtherWritableDraft(){const e=this.readWritableDraftMarkers();return Pa(e.map(({tabId:n,marker:s})=>({tabId:n,activeAt:s.activeAt})),this.draftTabId,Date.now()).otherActive}setPermission(e,n=!1){const s=this.permission;if(this.permission=e,e==="read"&&(s!=="read"&&this.rejectFlushes(new Error("Project permission changed to read-only")),this.destroyUndoManagers(),this.clearFormatLeaseStates()),this.updateLocalAwareness(),n&&s!==e)for(const r of this.permissionListeners)r(e,s)}setActiveFile(e){this.activeFile!==e&&(this.activeFile=e,this.awareness.setLocalStateField("cursor",null),this.updateLocalAwareness())}sessions(){const e=[];return this.awareness.getStates().forEach((n,s)=>{const r=n?.user;!r||typeof r.id!="string"||typeof r.name!="string"||e.push({clientId:s,userId:r.id,username:typeof r.username=="string"?r.username:r.name,name:r.name,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 n.filePath=="string"?n.filePath:"",editing:!!n.cursor,local:s===this.doc.clientID})}),e.sort((n,s)=>Number(s.local)-Number(n.local)||n.name.localeCompare(s.name))}flush(){const e=this.provider.ws;if(!this.provider.synced||!e||e.readyState!==WebSocket.OPEN)return Promise.reject(new Error("Collaboration connection is unavailable"));const n=mo(),s=this.draftGeneration,r=Ke();return ee(r,Oa),ot(r,n),new Promise((i,l)=>{const a=window.setTimeout(()=>{this.flushRequests.delete(n),l(new Error("Collaboration save timed out"))},5e3);this.flushRequests.set(n,{resolve:i,reject:l,timer:a,draftGeneration:s}),e.send(Pe(r))})}onFormatLeaseState(e){this.formatLeaseListeners.add(e);for(const n of this.formatLeaseStatesByPath.values())e(n);return()=>this.formatLeaseListeners.delete(e)}formatLeaseStates(){const e=Date.now();for(const[n,s]of this.formatLeaseStatesByPath)s.expiresAt<=e&&this.removeFormatLeaseState(n);return[...this.formatLeaseStatesByPath.values()]}async acquireFormatLease(e){if(this.permission==="read")throw new Error("Formatting requires write permission");const n=await this.requestFormatLease("acquire",e);if(n.status!=="grant"||!n.token||!Number.isFinite(n.expiresAt))throw new Error("Format lease was not granted");let s=n.token,r=n.expiresAt,i=!1;const l=async()=>{if(i)throw new Error("Format lease has already been released");const c=await this.requestFormatLease("renew",e,s);if(c.status!=="renewed"||!Number.isFinite(c.expiresAt))throw new Error("Format lease renewal failed");s=c.token||s,r=c.expiresAt};return{path:e,get token(){return s},get expiresAt(){return r},confirm:l,renew:l,release:async()=>{if(i)return;i=!0;const c=this.provider.ws;if(!(!c||c.readyState!==WebSocket.OPEN))try{await this.requestFormatLease("release",e,s)}catch{}}}}reconnect(){this.destroyed||(this.rejectFlushes(new 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(new Error("Collaboration connection closed")),this.provider.destroy(),this.persistence.destroy(),this.draftListeners.clear(),this.protocolUpgradeListeners.clear(),this.compileStateListeners.clear(),this.rejectFormatLeaseRequests(new 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(const e of this.undoManagers.values())e.destroy();this.undoManagers.clear()}notifyCompileStateListeners(){for(const e of this.compileStateListeners)e()}rejectFlushes(e){for(const n of this.flushRequests.values())window.clearTimeout(n.timer),n.reject(e);this.flushRequests.clear()}requestFormatLease(e,n,s=""){const r=this.provider.ws;if(!this.provider.synced||!r||r.readyState!==WebSocket.OPEN)return Promise.reject(new Error("Collaboration connection is unavailable"));const i=mo(),l=Ke();return ee(l,Hi),ot(l,e),ot(l,i),ot(l,n),ot(l,s),new Promise((a,c)=>{const h=window.setTimeout(()=>{if(this.formatLeaseRequests.delete(i),e==="acquire"){const d=this.provider.ws;if(d?.readyState===WebSocket.OPEN){const f=Ke();ee(f,Hi),ot(f,"cancel"),ot(f,i),ot(f,n),ot(f,""),d.send(Pe(f))}}c(new Error("Format lease request timed out"))},e==="acquire"?mb:5e3);this.formatLeaseRequests.set(i,{resolve:a,reject:c,timer:h}),r.send(Pe(l))})}rejectFormatLeaseRequests(e){for(const n of this.formatLeaseRequests.values())window.clearTimeout(n.timer),n.reject(e);this.formatLeaseRequests.clear()}clearFormatLeaseStates(){for(const e of this.formatLeaseExpiryTimers.values())window.clearTimeout(e);this.formatLeaseExpiryTimers.clear(),this.formatLeaseStatesByPath.size&&(this.formatLeaseStatesByPath.clear(),this.notifyFormatLeaseListeners(null))}removeFormatLeaseState(e){const n=this.formatLeaseExpiryTimers.get(e);n!==void 0&&window.clearTimeout(n),this.formatLeaseExpiryTimers.delete(e),this.formatLeaseStatesByPath.delete(e)}notifyFormatLeaseListeners(e){for(const n of this.formatLeaseListeners)n(e)}updateLocalAwareness(){const[e,n]=Ma[Math.abs(this.doc.clientID)%Ma.length];this.awareness.setLocalStateField("user",{id:this.user.id,username:this.user.username,name:this.user.displayName,color:e,colorLight:n,permission:this.permission,sessionId:String(this.doc.clientID)}),this.awareness.setLocalStateField("filePath",this.activeFile)}epochStorageKey(){return Cn(`texlite:collaboration-epoch:${this.user.id}:${this.projectId}`)}writableDraftStoragePrefix(){return`${Cn(`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(const{key:e}of this.readWritableDraftMarkers())Ds(e);this.draftMarkerPresent=!1,this.stopDraftHeartbeat(),Ds(this.writableDraftStoragePrefix().slice(0,-1))}clearOwnWritableDraftMarker(e){const n=this.readOwnWritableDraftMarker();!n||!bb(n.generation,this.draftGeneration,e)||(Ds(this.ownWritableDraftStorageKey()),this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}readOwnWritableDraftMarker(){return this.readWritableDraftMarker(this.ownWritableDraftStorageKey())}readWritableDraftMarkers(){const e=this.writableDraftStoragePrefix(),n=[];for(const s of kb()){if(!s.startsWith(e))continue;const r=this.readWritableDraftMarker(s);r&&n.push({key:s,tabId:s.slice(e.length),marker:r})}return n}readWritableDraftMarker(e){const n=Ia(e);if(!n)return null;try{const s=JSON.parse(n);if(!s||typeof s!="object"||Array.isArray(s))return null;const r=s,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>pb)return Ds(e),null;const l=typeof r.activeAt=="number"&&Number.isFinite(r.activeAt)?Math.max(0,r.activeAt):0;return{generation:r.generation,updatedAt:r.updatedAt,activeAt:l}}catch{return Ds(e),null}}writeOwnWritableDraftMarker(e){if(!this.draftMarkerPresent&&this.draftUpdatedAt<=0)return;const n={generation:this.draftGeneration,updatedAt:this.draftUpdatedAt||Date.now(),activeAt:e?Date.now():0};Ki(this.ownWritableDraftStorageKey(),JSON.stringify(n)),this.draftMarkerPresent=!0}setOwnDraftActivity(e){this.draftMarkerPresent&&(this.writeOwnWritableDraftMarker(e),e?this.startDraftHeartbeat():this.stopDraftHeartbeat())}resumeOwnDraftActivity(){const e=this.readOwnWritableDraftMarker();if(!e){this.draftMarkerPresent=!1,this.stopDraftHeartbeat();return}this.draftGeneration=Math.max(this.draftGeneration,e.generation),this.draftUpdatedAt=e.updatedAt,this.draftMarkerPresent=!0,this.setOwnDraftActivity(!0)}startDraftHeartbeat(){this.draftHeartbeatTimer!==null||!this.draftMarkerPresent||(this.draftHeartbeatTimer=window.setInterval(()=>{this.writeOwnWritableDraftMarker(!0)},gb))}stopDraftHeartbeat(){this.draftHeartbeatTimer!==null&&(window.clearInterval(this.draftHeartbeatTimer),this.draftHeartbeatTimer=null)}}function Ia(t){try{return window.localStorage.getItem(t)}catch{return null}}function Ki(t,e){try{window.localStorage.setItem(t,e)}catch{}}function Ds(t){try{window.localStorage.removeItem(t)}catch{}}function kb(){try{const t=[];for(let e=0;e<window.localStorage.length;e+=1){const n=window.localStorage.key(e);n&&t.push(n)}return t}catch{return[]}}function Sb(t){try{return window.sessionStorage.getItem(t)}catch{return null}}function Cb(t,e){try{window.sessionStorage.setItem(t,e)}catch{}}function vb(t){const e=Sb(t);if(e)return e;const n=mo();return Cb(t,n),n}function jb(t,e){return Array.from(t.trim()||e.trim()||"?")[0]?.toLocaleUpperCase()??"?"}function Eb(t){if(!t||typeof t!="object")return!1;const e=t;return(e.kind==="update"||e.kind==="move"||e.kind==="delete")&&typeof e.revision=="string"}function Db(t,e,n,s,r,i){const[l]=u.useState(()=>new xb(t,e)),[a,c]=u.useState("connecting"),[h,d]=u.useState(!1),[f,m]=u.useState([]),[g,w]=u.useState(null),[S,L]=u.useState(null),[v,q]=u.useState(""),[A,x]=u.useState(!1),[P,j]=u.useState(""),[C,M]=u.useState(""),[H,J]=u.useState([]),[le,B]=u.useState(!1),[se,W]=u.useState(s),[te,Y]=u.useState(null),[Ce,ae]=u.useState(!1),Z=u.useRef(n),$=u.useRef(i),ue=u.useRef(r);Z.current=n,$.current=i,ue.current=r,u.useEffect(()=>{const I=l.compileStates();w(I[n]??null)},[n,l]),u.useEffect(()=>{const I=()=>m(l.sessions()),fe=()=>{d(!1),m([]),w(null),L(null),q(""),x(!1),j(""),M(""),J([]),$.current()},ye=({status:ne})=>{c(ne),ne!=="connected"&&fe()},O=ne=>{d(ne),ne||fe()},z=()=>{c("disconnected"),fe()},De=()=>{x(l.meta.get("historyWarning")===!0);const ne=l.meta.get("filesEvent");Eb(ne)&&L(ne);const be=l.meta.get("commentsRevision");typeof be=="string"&&q(be);const _=l.meta.get("dictionaryRevision");typeof _=="string"&&j(_);const ge=l.meta.get("chktexSettingsRevision");typeof ge=="string"&&M(ge);const xe=l.compileStates();w(xe[Z.current]??null)},U=()=>{const ne=l.compileStates();w(ne[Z.current]??null)};l.awareness.on("change",I),l.provider.on("status",ye),l.provider.on("sync",O),l.provider.on("connection-close",z),l.provider.on("connection-error",z),l.meta.observe(De);const R=l.onCompileStates(U),he=l.onProtocolUpgrade(()=>{ae(!0),c("disconnected"),fe()}),K=()=>J(l.formatLeaseStates()),Ne=l.onFormatLeaseState(K),Ve=()=>{if(!ue.current||l.currentPermission!=="read")return;const ne=l.hasWritableDraft,be=l.hasOtherWritableDraft;!ne&&!be||Y({previous:"edit",localDraftReady:ne,otherTabDraft:be})},Me=l.onDraftReady(()=>{B(!0),Ve()}),Fe=l.onPermissionChanged((ne,be)=>{if(ne==="revoked"){c("disconnected"),d(!1),$.current();return}W(ne),ne==="read"&&be!=="read"?Y({previous:be,localDraftReady:l.hasWritableDraft,otherTabDraft:l.hasOtherWritableDraft}):ne!=="read"&&Y(null)});return I(),De(),c(l.connected?"connected":"connecting"),d(l.synced),()=>{l.awareness.off("change",I),l.provider.off("status",ye),l.provider.off("sync",O),l.provider.off("connection-close",z),l.provider.off("connection-error",z),l.meta.unobserve(De),R(),he(),Ne(),Me(),Fe(),l.destroy()}},[l]),u.useEffect(()=>{r&&l.connect()},[l,r]),u.useEffect(()=>{l.setPermission(s),W(s),r&&s==="read"&&(l.hasWritableDraft||l.hasOtherWritableDraft)?Y({previous:"edit",localDraftReady:l.hasWritableDraft,otherTabDraft:l.hasOtherWritableDraft}):s!=="read"&&Y(null)},[l,s,r]);const Ee=te!==null;return u.useEffect(()=>{if(!Ee)return;const I=()=>{if(l.currentPermission!=="read")return;const ye=l.hasWritableDraft,O=l.hasOtherWritableDraft;Y(z=>!z||z.localDraftReady===ye&&z.otherTabDraft===O?z:{...z,localDraftReady:ye,otherTabDraft:O})};I();const fe=window.setInterval(I,2e3);return()=>window.clearInterval(fe)},[l,Ee]),{collaboration:l,status:a,synced:h,activeSessions:f,compileState:g,setCompileState:w,formatLeaseStates:H,filesEvent:S,commentsRevision:v,historyWarning:A,dictionaryRevision:P,chktexSettingsRevision:C,localDraftReady:le,permission:se,protocolUpgradeRequired:Ce,reconnect:()=>{Ce||(c("connecting"),d(!1),m([]),w(null),J([]),l.reconnect())},permissionDowngrade:te,dismissPermissionDowngrade:()=>Y(null),discardLocalDraft:async()=>await l.discardLocalDraft()?(Y(null),window.location.reload(),!0):(Y(fe=>fe&&{...fe,otherTabDraft:!0}),!1)}}function za(t){return t?.status==="succeeded"?"succeeded":t?.log.includes("Compilation was cancelled.")?"cancelled":t?.status==="failed"?"failed":null}function xn(t){return t instanceof Error&&t.name==="AbortError"}function Tb(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement}function _b(t){return t instanceof Element&&!!t.closest('[role="dialog"], [role="alertdialog"]')}function Rb({projectId:t,project:e,mainFile:n,resolveCompileMainFile:s,getCurrentMainFile:r,initialLatest:i,collaborationSynced:l,sharedState:a,onSharedState:c,save:h,loadOutline:d,onPreviewTab:f,onError:m,onCompileStart:g,onCompileSuccess:w,onPdfChanged:S}){const{t:L}=Ye(),[v,q]=u.useState(""),[A,x]=u.useState(!0),[P,j]=u.useState(null),[C,M]=u.useState(null),[H,J]=u.useState("full"),[le,B]=u.useState(""),[se,W]=u.useState(null),[te,Y]=u.useState(null),[Ce,ae]=u.useState([]),[Z,$]=u.useState(null),[ue,Ee]=u.useState(!1),[ke,ve]=u.useState(!1),[X,I]=u.useState(()=>new Set),[fe,ye]=u.useState(()=>new Set),[O,z]=u.useState(""),[De,U]=u.useState({projectId:t,mainFile:n}),R=u.useRef(n),he=u.useRef(""),K=u.useRef(""),Ne=u.useRef({projectId:t,mainFile:n}),Ve=u.useRef(!0),Me=u.useRef(null),Fe=u.useRef(null),ne=u.useRef(null),be=u.useRef(i),_=u.useRef(!1),ge=u.useRef(null),xe=u.useRef(null),Le=u.useRef(new Set),Ue=u.useRef(new Map),Ge=u.useRef(null),Re=u.useRef(()=>{}),re=u.useRef({onSharedState:c,save:h,loadOutline:d,onPreviewTab:f,onError:m,onCompileStart:g,onCompileSuccess:w,onPdfChanged:S,resolveCompileMainFile:s,getCurrentMainFile:r});R.current=n,re.current={onSharedState:c,save:h,loadOutline:d,onPreviewTab:f,onError:m,onCompileStart:g,onCompileSuccess:w,onPdfChanged:S,resolveCompileMainFile:s,getCurrentMainFile:r};const F=()=>re.current.getCurrentMainFile?.()||R.current,oe=De.projectId===t&&De.mainFile===n,Oe=k=>{Ge.current!==k&&(Ge.current=k,re.current.onCompileSuccess())},Be=(k,y,T,V,ft)=>{(K.current!==y||he.current!==k)&&re.current.onPdfChanged(),K.current=y,he.current=k,q(y),j(T),M(V),J(ft??"full")},N=async(k,y)=>{y||(ge.current?.abort(),ge.current=new AbortController,y=ge.current.signal);try{const T=k?`?mainFile=${encodeURIComponent(k)}`:"",V=await pe(`/api/projects/${t}/compile/artifacts${T}`,{signal:y});R.current===k&&(ae(V.artifacts),$(null))}catch(T){!xn(T)&&R.current===k&&(ae([]),$(null))}finally{ge.current?.signal===y&&(ge.current=null)}};u.useEffect(()=>{Me.current?.abort(),Me.current=null;const k=Ne.current,y=k.projectId===t,T=y&&!!k.mainFile&&!!n&&k.mainFile!==n;if(Ne.current={projectId:t,mainFile:n},U(_e=>_e.projectId===t&&_e.mainFile===n?_e:{projectId:t,mainFile:n}),y||(be.current=i,_.current=!1,ne.current=null,he.current="",K.current=""),!n){x(!1),K.current="",q(""),j(null),M(null),J("full"),B(""),W(null),Y(null),ae([]),$(null),Ee(!1),z(""),ne.current=null,re.current.onPdfChanged();return}if(ne.current?.mainFile!==n&&(ne.current=null),B(""),W(null),Y(null),T){Ve.current=!1,Fe.current?.abort(),ge.current?.abort(),xe.current?.abort(),he.current="",K.current="",q(""),j(null),M(null),J("full"),x(!1),ae([]),$(null),Ee(!1),z(""),re.current.onPdfChanged(),re.current.onPreviewTab("pdf");const _e=new AbortController;return re.current.loadOutline(_e.signal,n).catch(()=>{}),()=>_e.abort()}Ve.current=!0;const V=new AbortController;Me.current=V,x(!0),y&&v&&n&&he.current===n||(K.current="",q(""),j(null),M(null),J("full")),ae([]),$(null),re.current.onPdfChanged();let Se=null;const mt=`?mainFile=${encodeURIComponent(n)}`,Bt=_.current?null:be.current;Bt&&(_.current=!0);const At=()=>pe(`/api/projects/${t}/compile/latest${mt}`,{signal:V.signal}),$n=Bt?Bt.then(_e=>_e.mainFile!==n?At():_e,()=>At()):At();let bt=!1;const ti=()=>{if(bt||V.signal.aborted||!n)return;bt=!0;const _e=new AbortController;Le.current.add(_e),N(n,_e.signal).finally(()=>{Le.current.delete(_e)}),re.current.loadOutline(V.signal,n).catch(()=>{})};return $n.then(_e=>{if(V.signal.aborted||n&&_e.mainFile!==R.current)return;const mn=ne.current;mn&&mn.mainFile===n&&_e.latestRun?.id!==mn.runId||(B(_e.latestRun?.log??""),W(_e.latestRun?.diagnostics??null),Y(za(_e.latestRun)),n&&_e.latestRun?.requestedBy&&(_e.latestRun.status==="queued"||_e.latestRun.status==="running")&&re.current.onSharedState({mainFile:n,runId:_e.latestRun.id,status:_e.latestRun.status,requestedBy:_e.latestRun.requestedBy,updatedAt:new Date().toISOString()}),_e.pdfUrl&&(Be(_e.mainFile,_e.pdfUrl,_e.pdfCompiledAt,_e.pdfSizeBytes,_e.pdfLoadingMode),re.current.onPreviewTab("pdf")))}).catch(_e=>{!xn(_e)&&R.current===n&&re.current.onError(we(_e))}).finally(()=>{Me.current===V&&(Me.current=null),V.signal.aborted||(x(!1),Se=window.setTimeout(ti,0))}),()=>{Se!==null&&window.clearTimeout(Se),V.abort(),xe.current?.abort();for(const _e of Le.current)_e.abort();Le.current.clear()}},[t,n]),u.useEffect(()=>{if(!(!a||a.mainFile!==n||a.status!=="cleaned"||!a.cleanMode)){Me.current?.abort(),Fe.current?.abort(),ge.current?.abort(),xe.current?.abort();for(const k of Le.current)k.abort();Le.current.clear(),a.cleanMode==="artifacts"?(ne.current=null,B(""),W(null),Y(null),K.current="",q(""),j(null),M(null),J("full"),ae([]),$(null),re.current.onPdfChanged(),re.current.onPreviewTab("pdf"),z(L("editor.cleanArtifactsComplete"))):z(L("editor.cleanCacheComplete"))}},[a?.runId,a?.status,a?.cleanMode,a?.mainFile,n,L]),u.useEffect(()=>{!n||a?.mainFile===n&&(a.status==="queued"||a.status==="running")||ye(k=>{if(!k.has(n))return k;const y=new Set(k);return y.delete(n),y})},[n,a?.mainFile,a?.status]),u.useEffect(()=>{a?.mainFile===n&&(a.status==="queued"||a.status==="running")&&(Ve.current=!0)},[n,a?.mainFile,a?.status,a?.runId]),u.useEffect(()=>{if(!a||a.mainFile!==n||a.status!=="succeeded"&&a.status!=="failed"||!Ve.current)return;let k=!1;Fe.current?.abort(),xe.current?.abort();const y=new AbortController;return Fe.current=y,x(!0),pe(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(n)}`,{signal:y.signal}).then(T=>{k||T.mainFile!==R.current||T.latestRun?.id!==a.runId||(B(T.latestRun.log),W(T.latestRun.diagnostics),Y(za(T.latestRun)),a.status==="succeeded"&&a.stale&&z(L("editor.compileSnapshotStale")),a.status==="succeeded"&&T.pdfUrl?(ne.current={mainFile:n,runId:a.runId},Be(n,T.pdfUrl,T.pdfCompiledAt,T.pdfSizeBytes,T.pdfLoadingMode),re.current.onPreviewTab("pdf"),Oe(a.runId),N(n)):a.status==="failed"&&re.current.onPreviewTab(T.latestRun.diagnostics.errors.length?"errors":"log"))}).catch(T=>{!xn(T)&&!k&&re.current.onError(we(T))}).finally(()=>{Fe.current===y&&(Fe.current=null),k||x(!1)}),()=>{k=!0,y.abort(),Fe.current===y&&(Fe.current=null)}},[a?.runId,a?.status,a?.mainFile,a?.stale,n,t,L]);const G=async()=>{if(!e||e.permission==="read"||!l)return;const k=re.current.resolveCompileMainFile?.()||F();if(!k||Ue.current.has(k)||a?.mainFile===k&&(a.status==="queued"||a.status==="running"))return;I(T=>new Set([...T,k])),re.current.onCompileStart(),z(""),xe.current?.abort(),xe.current=null,B(""),W(null),Y(null),re.current.onPreviewTab(oe&&v?"pdf":"log");const y=new AbortController;Ue.current.set(k,y);try{if(!await re.current.save())return;Ve.current=!0;const T=await pe(`/api/projects/${t}/compile`,{method:"POST",signal:y.signal,body:JSON.stringify({mainFile:k})});if(T.mainFile!==k||F()!==k)return;B(T.log),W(T.diagnostics),Y(T.cancelled?"cancelled":T.ok?"succeeded":"failed"),T.cancelled&&z(L("compileControls.cancelled")),T.skipped&&z(L("editor.upToDate")),T.ok&&T.stale&&z(L("editor.compileSnapshotStale")),T.pdfUrl?(T.ok&&(ne.current={mainFile:k,runId:T.runId}),Be(k,T.pdfUrl,T.pdfCompiledAt,T.pdfSizeBytes,T.pdfLoadingMode),re.current.onPreviewTab("pdf"),T.ok&&(T.skipped?re.current.onCompileSuccess():Oe(T.runId))):re.current.onPreviewTab(T.diagnostics.errors.length?"errors":"log")}catch(T){!xn(T)&&F()===k&&re.current.onError(we(T))}finally{Ue.current.get(k)===y&&(Ue.current.delete(k),I(T=>{const V=new Set(T);return V.delete(k),V}),ye(T=>{if(!T.has(k))return T;const V=new Set(T);return V.delete(k),V}))}},Te=async()=>{if(!e||e.permission==="read"||!l)return;const k=F();if(k){ye(y=>new Set([...y,k]));try{(await pe(`/api/projects/${t}/compile/cancel`,{method:"POST",body:JSON.stringify({mainFile:k})})).cancelled||ye(T=>{const V=new Set(T);return V.delete(k),V})}catch(y){ye(T=>{const V=new Set(T);return V.delete(k),V}),!xn(y)&&F()===k&&re.current.onError(we(y))}}},Q=async k=>{if(!e||e.permission==="read"||!l||ke)return;const y=F();if(!(!y||Ue.current.has(y)||a?.mainFile===y&&(a.status==="queued"||a.status==="running"))){ve(!0),Me.current?.abort(),Fe.current?.abort(),ge.current?.abort(),xe.current?.abort();try{if((await pe(`/api/projects/${t}/compile/clean`,{method:"POST",body:JSON.stringify({mainFile:y,mode:k})})).mainFile!==y||F()!==y)return;re.current.onSharedState(null),k==="artifacts"&&(ne.current=null,B(""),W(null),Y(null),K.current="",q(""),j(null),M(null),J("full"),ae([]),$(null),re.current.onPdfChanged()),z(L(k==="cache"?"editor.cleanCacheComplete":"editor.cleanArtifactsComplete"))}catch(T){!xn(T)&&F()===y&&re.current.onError(we(T))}finally{ve(!1)}}};Re.current=()=>{G()},u.useEffect(()=>{if(!O)return;const k=window.setTimeout(()=>z(""),3e3);return()=>window.clearTimeout(k)},[O]),u.useEffect(()=>{const k=y=>{if(!(!(y.ctrlKey||y.metaKey)||y.key.toLocaleLowerCase()!=="s")){if(Tb(y.target)||_b(y.target)){y.preventDefault();return}y.preventDefault(),y.stopPropagation(),y.repeat||Re.current()}};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[]),u.useEffect(()=>()=>{Me.current?.abort(),Fe.current?.abort(),ge.current?.abort(),xe.current?.abort();for(const k of Le.current)k.abort();Le.current.clear();for(const k of Ue.current.values())k.abort();Ue.current.clear()},[]);const yt=async k=>{if(!k.viewable)return;xe.current?.abort();const y=new AbortController;xe.current=y,Ee(!0);try{const T=await pe(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(n)}&path=${encodeURIComponent(k.path)}`,{signal:y.signal});!y.signal.aborted&&xe.current===y&&R.current===n&&$(T)}catch(T){xn(T)||re.current.onError(we(T))}finally{xe.current===y&&(xe.current=null,Ee(!1))}};return{pdfUrl:oe?v:"",pdfCompiledAt:oe?P:null,pdfSizeBytes:oe?C:null,pdfLoadingMode:H,pdfLoading:oe?A:!1,compileLog:oe?le:"",compileDiagnostics:oe?se:null,compileOutcome:oe?te:null,artifacts:oe?Ce:[],artifactPreview:oe?Z:null,artifactLoading:oe&&ue,editorNotice:oe?O:"",localCompiling:X.has(n),cancelling:fe.has(n),cleaning:ke,compile:G,cancelCompile:Te,cleanCompile:Q,viewArtifact:yt}}const wo=10*1024*1024,Lb=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif",".pdf",".zip",".gz",".bz2",".xz",".tar",".rar",".7z",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".odt",".ods",".odp",".mp3",".mp4",".wav",".ogg",".webm",".mov",".avi",".wasm",".exe",".bin",".so",".dll",".class",".jar"]);function Ua(t){return t instanceof Error&&t.name==="AbortError"}function En(t){const e=t.split("/").filter(Boolean);return e.pop(),e.map((n,s)=>e.slice(0,s+1).join("/"))}function kn(t,e){return!!(t&&e)&&(e===t||e.startsWith(`${t}/`))}function Ab(t){const e=`.${t.split(".").at(-1)?.toLocaleLowerCase()??""}`;return!Lb.has(e)}function ss(t){return/(?:\.(?:tex|bib|bst|sty|cls|txt|md)|latexmkrc)$/i.test(t)}function Ba(t){const e=t.split(".").at(-1)?.toLocaleLowerCase()??"";return e==="pdf"?"pdf":["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"].includes(e)?"image":Ab(t)?"text":"unsupported"}function Nb(t,e){return fs(`/api/projects/${t}/file/raw?path=${encodeURIComponent(e)}`)}function Mb({projectId:t,site:e,activeFile:n,dirty:s,save:r,onError:i,onProject:l,onActiveFile:a,onActiveMainFile:c}){const{t:h}=Ye(),[d,f]=u.useState([]),[m,g]=u.useState(!1),[w,S]=u.useState(""),[L,v]=u.useState(null),[q,A]=u.useState(!1),[x,P]=u.useState(!1),[j,C]=u.useState(""),[M,H]=u.useState(""),[J,le]=u.useState(null),[B,se]=u.useState(""),[W,te]=u.useState(new Set),[Y,Ce]=u.useState(null),[ae,Z]=u.useState(""),[$,ue]=u.useState(""),[Ee,ke]=u.useState(null),[ve,X]=u.useState(!1),[I,fe]=u.useState(null),[ye,O]=u.useState(!1),[z,De]=u.useState(null),U=u.useRef(!1),R=u.useRef(null),he=u.useRef(null),K=u.useRef(null),Ne=async(F={})=>{he.current?.abort(),he.current=null;const oe=F.signal?null:new AbortController;oe&&(he.current=oe);try{const Oe=await pe(`/api/projects/${t}/files`,{signal:F.signal??oe?.signal});return(!F.isCurrent||F.isCurrent())&&f(Oe.files),Oe.files}catch(Oe){if(!Ua(Oe))throw Oe;return}finally{oe&&he.current===oe&&(he.current=null)}},Ve=async()=>{if(!(!w.trim()||w.trim().endsWith("/"))){H("");try{await pe(`/api/projects/${t}/file`,{method:"POST",body:JSON.stringify({path:w,content:""})}),await Ne(),a(w),le(null),te(F=>new Set([...F,...En(w)])),g(!1),S("")}catch(F){H(we(F))}}},Me=async()=>{if(!j.trim())return;H("");const F=J?`${J}/${j.trim()}`:j.trim();try{const oe=await pe(`/api/projects/${t}/folders`,{method:"POST",body:JSON.stringify({path:F})});await Ne(),te(Oe=>new Set([...Oe,...En(oe.path),oe.path])),le(oe.path),P(!1),C("")}catch(oe){H(we(oe))}},Fe=async(F,oe=new Set,Oe=J)=>{if(!F.length||U.current)return;const Be=e.maxUploadSizeMB;if(F.find(V=>V.size>Be*1024*1024)){De({kind:"error",message:h("errors.fileTooLarge",{size:Be})});return}const G=Oe??"",Te=F.map(V=>G?`${G}/${V.name}`:V.name),Q=new Map;for(const V of Te)Q.set(V,(Q.get(V)??0)+1);const yt=[...Q.entries()].filter(([,V])=>V>1).map(([V])=>V);if(yt.length){De({kind:"error",message:h("errors.duplicateUploadNames",{files:yt.join(", ")})});return}const k=new Set(d.map(V=>V.path)),y=[...new Set(Te.filter(V=>k.has(V)&&!oe.has(V)))];if(y.length){De(null),fe({files:F,directory:G,collisions:y});return}fe(null),R.current!==null&&window.clearTimeout(R.current),R.current=null,De(null),U.current=!0,O(!0);let T=0;try{const V=new URLSearchParams;G&&V.set("directory",G);let ft="";for(const[Se,mt]of F.entries()){const Bt=Te[Se];V.delete("overwrite"),oe.has(Bt)&&V.set("overwrite","1");const At=V.toString()?`?${V.toString()}`:"",$n=new FormData;$n.append("file",mt);try{De({kind:"uploading",fileName:mt.name,current:Se+1,total:F.length});const bt=await pe(`/api/projects/${t}/upload${At}`,{method:"POST",body:$n});T+=1,typeof bt.path=="string"&&ss(bt.path)&&(ft=bt.path)}catch(bt){if(bt instanceof xr&&bt.status===409&&!oe.has(Bt)&&bt.code==="FILE_EXISTS"){if(De(null),Se>0)try{await Ne()}catch{}fe({files:F.slice(Se),directory:G,collisions:[Bt]});return}throw bt}}try{await Ne()}catch(Se){De({kind:"error",message:h("editor.uploadSucceededRefreshFailed",{message:we(Se)})});return}ft&&(a(ft),le(null)),De({kind:"success",count:T}),R.current=window.setTimeout(()=>{De(Se=>Se?.kind==="success"?null:Se),R.current=null},3e3)}catch(V){try{await Ne()}catch{}const ft=T>0?h("editor.uploadFailedPartial",{uploaded:T,total:F.length,message:we(V)}):h("editor.uploadFailed",{message:we(V)});De({kind:"error",message:ft})}finally{U.current=!1,O(!1)}},ne=()=>{R.current!==null&&window.clearTimeout(R.current),R.current=null,De(null)},be=async F=>{await Fe(Array.from(F.target.files??[])),F.target.value=""},_=async F=>{K.current?.abort(),K.current=null,A(!1);const oe=Nb(t,F.path);if((F.size??0)>wo){v({path:F.path,kind:"large",size:F.size??0,url:oe});return}const Oe=Ba(F.path);if(Oe!=="text"){v({path:F.path,kind:Oe,size:F.size??0,url:oe});return}v({path:F.path,kind:Oe,size:F.size??0,url:oe,content:""}),A(!0);const Be=new AbortController;K.current=Be;try{let N;try{N=await fetch(oe,{signal:Be.signal})}catch(Q){throw hf(Q)}const G=N.headers.get("content-type")??"";if(!N.ok){let Q=null;try{Q=G.includes("application/json")?await N.json():await N.text()}catch{}throw new xr(ff(Q,N.status),N.status,mf(Q))}const Te=await N.text();v(Q=>Q?.path===F.path?{...Q,content:Te}:Q)}catch(N){Ua(N)||(v(null),i(we(N)))}finally{K.current===Be&&(K.current=null,A(!1))}},ge=F=>{le(null),se(F.path);const oe=Ba(F.path),Oe=e.maxCollaborativeFileSizeMB*1024*1024;(F.size??0)>wo||ss(F.path)&&(F.size??0)>Oe||oe!=="text"||!ss(F.path)?_(F):a(F.path)},xe=async(F,oe,Oe)=>{if(!await r())return null;const Be=await pe(`/api/projects/${t}/path`,{method:"PATCH",body:JSON.stringify({source:F.path,destinationDirectory:oe,destinationName:Oe})}),N=Q=>Q===F.path?Be.path:Q.startsWith(`${F.path}/`)?`${Be.path}${Q.slice(F.path.length)}`:Q;a(Q=>N(Q)),c(Q=>N(Q)),le(Q=>Q&&N(Q)),se(Q=>Q&&N(Q));const[G,Te]=await Promise.all([pe(`/api/projects/${t}/files`),pe(`/api/projects/${t}`)]);return f(G.files),l(Te.project),te(Q=>new Set([...Q,...En(Be.path),oe].filter(Boolean))),Be.path},Le=async()=>{if(!Y)return;const F=ae.trim();if(F){H("");try{if(!await xe(Y,$,F))return;Ce(null),Z(""),ue("")}catch(oe){H(we(oe))}}},Ue=async(F,oe)=>{if(Ob(F.path)!==oe&&!(F.type==="directory"&&(oe===F.path||oe.startsWith(`${F.path}/`))))try{await xe(F,oe,F.path.split("/").at(-1)??F.path)}catch(Oe){i(we(Oe))}},Ge=async()=>{if(Ee){H("");try{if(s&&!await r())return;await pe(`/api/projects/${t}/file?path=${encodeURIComponent(Ee.path)}`,{method:"DELETE"}),ke(null)}catch(F){H(we(F))}}};u.useEffect(()=>()=>{he.current?.abort(),K.current?.abort(),R.current!==null&&window.clearTimeout(R.current)},[]),u.useEffect(()=>{K.current?.abort(),K.current=null,A(!1)},[n]),u.useEffect(()=>{n&&se(n)},[n]);const Re=d.filter(F=>F.type==="directory"),re=d.filter(F=>En(F.path).every(oe=>W.has(oe)));return{files:d,setFiles:f,loadFiles:Ne,newFileOpen:m,setNewFileOpen:g,newFilePath:w,setNewFilePath:S,resourcePreview:L,setResourcePreview:v,resourcePreviewLoading:q,setResourcePreviewLoading:A,newFolderOpen:x,setNewFolderOpen:P,newFolderName:j,setNewFolderName:C,fileDialogError:M,setFileDialogError:H,selectedFolder:J,setSelectedFolder:le,selectedFile:B,setSelectedFile:se,expandedFolders:W,setExpandedFolders:te,moveEntry:Y,setMoveEntry:Ce,moveName:ae,setMoveName:Z,moveDestination:$,setMoveDestination:ue,deleteEntry:Ee,setDeleteEntry:ke,fileDragActive:ve,setFileDragActive:X,uploadConflict:I,setUploadConflict:fe,uploadingFiles:ye,uploadFeedback:z,dismissUploadFeedback:ne,directoryEntries:Re,visibleEntries:re,createFile:Ve,createFolder:Me,uploadFiles:Fe,upload:be,openFile:ge,movePath:Le,movePathToFolder:Ue,removePath:Ge}}function Ob(t){const e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function Fb({active:t,harperEnabled:e=!0,projectId:n,activeFile:s,content:r,dictionaryWords:i,additionalIssues:l=[],additionalIssuesReady:a=!0}){const[c,h]=u.useState([]),[d,f]=u.useState(""),[m,g]=u.useState(""),[w,S]=u.useState(0),[L,v]=u.useState(null),[q,A]=u.useState(null),[x,P]=u.useState(!1),[j,C]=u.useState(0),M=u.useRef(0),H=u.useRef(!1),J=u.useRef(!1),le=u.useRef(r),B=u.useRef(s),se=u.useRef(0);le.current=r,B.current=s,J.current=x,u.useEffect(()=>{h([]),f(""),g(""),v(null),A(null),P(!1)},[s,i,e]),u.useEffect(()=>{A(null),P(!1)},[n]),u.useEffect(()=>{const ae=++M.current;if(!t||!s){h([]),f(""),g(""),v(null);return}if(!e){h([]),f(""),g("");return}if(q){h([]),f(""),g("");return}const Z=r,$=s;let ue=!1;const Ee=window.setTimeout(()=>{A(null),(async()=>{try{const{lintLatex:ke,isHarperLintSupersededError:ve}=await Lt(async()=>{const{lintLatex:I,isHarperLintSupersededError:fe}=await import("./spellCheck-BSbFJY9f.js");return{lintLatex:I,isHarperLintSupersededError:fe}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url);if(ue||ae!==M.current||le.current!==Z||B.current!==$)return;let X;try{X=await ke(n,$,Z,i)}catch(I){if(ve(I))return;throw I}if(ue||ae!==M.current||le.current!==Z||B.current!==$)return;H.current=!1,P(!1),h(X),f(Z),g($),S(0),v(null)}catch(ke){if(ue||ae!==M.current||le.current!==Z||B.current!==$)return;h([]),f(""),g(""),A(ke instanceof Error?ke.message:String(ke));const ve=H.current;H.current=!1,P(ve?J.current:!1)}})()},700);return()=>{ue=!0,window.clearTimeout(Ee)}},[t,e,n,s,r,i,j,q]),u.useEffect(()=>{if(!q||!t||!e)return;let ae=!1;const Z=()=>{ae||(ae=!0,H.current=!0,A(null),C(ue=>ue+1))},$=window.setTimeout(Z,15e3);return window.addEventListener("online",Z,{once:!0}),()=>{window.clearTimeout($),window.removeEventListener("online",Z)}},[q,t,e]);const W=e&&t&&m===s&&d===r,te=u.useMemo(()=>{if(!t)return[];const ae=[...W?c:[],...l].sort(($,ue)=>$.from-ue.from||$.to-ue.to),Z=new Set;return ae.filter($=>{const ue=`${$.from}:${$.to}:${$.kind}:${$.message}`;return Z.has(ue)?!1:(Z.add(ue),!0)})},[t,l,W,c]),Y=u.useMemo(()=>t&&(!e||W)&&a?{total:te.length,unique:new Set(te.map(ae=>`${ae.kind}:${ae.word.toLocaleLowerCase("en-US")}`)).size}:null,[t,a,e,W,te]);return u.useEffect(()=>{S(ae=>te.length?Math.min(ae,te.length-1):0)},[te]),{issues:te,jump:t?L:null,index:w,summary:Y,jumpToIssue:ae=>{if(!te.length)return;const Z=Math.max(0,Math.min(ae,te.length-1)),$=te[Z];S(Z),v({from:$.from,to:$.to,nonce:++se.current})},error:t&&e&&!x?q:null,nativeFallback:t&&e&&!!q,retry:()=>{H.current=!1,A(null),P(!1),C(ae=>ae+1)},dismissError:()=>{H.current=!1,P(!0)}}}function $b({active:t,projectId:e,activeFile:n,content:s}){const[r,i]=u.useState([]),[l,a]=u.useState(""),[c,h]=u.useState(""),[d,f]=u.useState(null),[m,g]=u.useState(!1),[w,S]=u.useState(0),L=u.useRef(0),v=u.useRef(s),q=u.useRef(n);v.current=s,q.current=n,u.useEffect(()=>{i([]),a(""),h(""),f(null),g(!1)},[e,n]),u.useEffect(()=>{const x=++L.current;if(!t||!n){i([]),a(""),h("");return}const P=s,j=n;let C=!1;const M=window.setTimeout(()=>{(async()=>{try{const{lintChktex:H,isChktexLintSupersededError:J}=await Lt(async()=>{const{lintChktex:B,isChktexLintSupersededError:se}=await import("./chktex-ZnIx425m.js");return{lintChktex:B,isChktexLintSupersededError:se}},__vite__mapDeps([9,1,2,3,4,5,6,7,8]),import.meta.url);if(C||x!==L.current||v.current!==P||q.current!==j)return;let le;try{le=await H(e,j,P)}catch(B){if(J(B))return;throw B}if(C||x!==L.current||v.current!==P||q.current!==j)return;i(le),a(P),h(j),f(null),g(!1)}catch(H){if(C||x!==L.current||v.current!==P||q.current!==j)return;i([]),a(""),h(""),f(H instanceof Error?H.message:String(H))}})()},2e3);return()=>{C=!0,window.clearTimeout(M)}},[t,e,n,s,w]);const A=t&&c===n&&l===s;return{issues:A?r:[],checked:A,error:t&&!m?d:null,retry:()=>{f(null),g(!1),S(x=>x+1)},dismissError:()=>g(!0)}}function qa(t){return t instanceof Error&&t.name==="AbortError"}function Pb({projectId:t,mainFile:e,activeFile:n,onOpenSourceFile:s,onError:r,onShowPdf:i,onShowEditor:l}){const[a,c]=u.useState(null),[h,d]=u.useState(null),[f,m]=u.useState(null),g=u.useRef(null),w=u.useRef(0),S=u.useRef(n),L=u.useRef(s),v=u.useRef(r),q=u.useRef(i),A=u.useRef(l),x=J=>J===e&&/\.tex$/i.test(J);S.current=n,L.current=s,v.current=r,q.current=i,A.current=l,u.useEffect(()=>(g.current?.abort(),g.current=null,c(null),d(null),m(null),()=>g.current?.abort()),[t,e]);const P=(J,le,B)=>{m({path:J,line:le,column:B,nonce:++w.current}),L.current(J)},j=async(J,le,B,se={})=>{if(!x(J))return;g.current?.abort();const W=new AbortController;g.current=W;try{const te=await pe(`/api/projects/${t}/sync/pdf?mainFile=${encodeURIComponent(e)}&path=${encodeURIComponent(J)}&line=${le}&column=${B}`,{signal:W.signal});if(g.current!==W||!te)return;c({...te,nonce:++w.current}),q.current()}catch(te){!qa(te)&&!se.silent&&v.current(we(te))}finally{g.current===W&&(g.current=null)}},C=async(J,le,B)=>{const se=S.current;g.current?.abort();const W=new AbortController;g.current=W;try{const te=await pe(`/api/projects/${t}/sync/source?mainFile=${encodeURIComponent(e)}&page=${J}&x=${le}&y=${B}`,{signal:W.signal});if(g.current!==W||S.current!==se)return;A.current(),P(te.path,te.line,te.column)}catch(te){qa(te)||v.current(we(te))}finally{g.current===W&&(g.current=null)}};return{pdfTarget:a,pdfViewport:h,sourceJump:f,setPdfViewport:d,resetPdfViewport:()=>d(null),clearPdfViewport:()=>{g.current?.abort(),g.current=null,d(null),c(null)},jumpToSource:P,syncSourceToPdf:j,syncPdfToSource:C,syncVisiblePdfToSource:()=>{h&&C(h.page,h.x,h.y)}}}function Hu(t,e){return Cn(`texlite.workspaceLayout:${encodeURIComponent(t)}:${encodeURIComponent(e)}`)}function Wa(t,e){try{const n=window.localStorage.getItem(Hu(t,e));if(n==="editor-pdf"||n==="editor-only"||n==="pdf-only")return n}catch{}return"editor-pdf"}function Ib(t,e){const[n,s]=u.useState(()=>Wa(t,e));return u.useEffect(()=>{s(Wa(t,e))},[t,e]),{workspaceLayout:n,setWorkspaceLayout:i=>{s(i);try{window.localStorage.setItem(Hu(t,e),i)}catch{}}}}function zb(t){return!/\.(?:bib|bst)$/i.test(t.trim())}function Va(t){return/\.(?:tex|sty|cls)$/i.test(t.trim())}const Ku=["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"],Ub=new Set(Ku);function Bb(t){return Ub.has(t)}function qb(t,e,n){if(t[e]!=="[")return e;let s=1;for(let r=e+1;r<n;r+=1){if(t[r]==="\\"){r+=1;continue}if(t[r]==="["&&(s+=1),t[r]==="]"&&(s-=1,s===0))return r+1}return null}function Ha(t,e,n){if(t[e]!=="{")return null;let s=1;for(let r=e+1;r<n;r+=1){if(t[r]==="\\"){r+=1;continue}if(t[r]==="{"&&(s+=1),t[r]==="}"&&(s-=1,s===0))return r+1}return null}function Gu(t,e,n=t.length){const s=t.indexOf(`
|
|
11
|
+
`,e);s>=0&&(n=Math.min(n,s));const r=/^\\(verb\*?|Verb\*?|lstinline\*?|mintinline\*?)(?![A-Za-z@])/.exec(t.slice(e,n));if(!r)return null;const i=r[1].replace(/\*$/,"");let l=e+r[0].length;if(i!=="verb"){const h=qb(t,l,n);if(h===null)return null;l=h}if(i==="mintinline"){const h=Ha(t,l,n);if(h===null)return null;l=h}const a=t[l];if(!a||/\s/.test(a))return null;if(a==="{"&&i!=="verb"){const h=Ha(t,l,n);return{end:h??n,closed:h!==null}}const c=t.indexOf(a,l+1);return c<0||c>=n?{end:n,closed:!1}:{end:c+1,closed:!0}}function Ju(t,e,n=t.length){return Gu(t,e,n)?.end??null}function rl(t,e,n){const s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(String.raw`\\end\s*\{\s*${s}\s*\}`,"g");r.lastIndex=e;const i=r.exec(t);return i?{from:i.index,to:i.index+i[0].length}:null}function Vs(t,e){let n=0;for(let s=e-1;s>=0&&t[s]==="\\";s-=1)n+=1;return n%2===1}function Wb(t,e){let n=e+1;if(/[A-Za-z@]/.test(t[n]??"")){for(;/[A-Za-z@]/.test(t[n]??"");)n+=1;return t[n]==="*"&&(n+=1),n}return Math.min(t.length,n+1)}function Yu(t,e){const n=/^\\begin\s*\{\s*([A-Za-z0-9@:_*.\-]+)\s*\}/.exec(t.slice(e));return!n||!Bb(n[1])?null:{name:n[1],to:e+n[0].length}}function y0(t,e){const n=Math.max(0,Math.min(t.length,e));for(let s=0;s<n;){if(t[s]==="%"&&!Vs(t,s)){const l=t.indexOf(`
|
|
12
|
+
`,s),a=l<0?t.length:l;if(n<=a)return"comment";s=a+1;continue}if(t[s]!=="\\"||Vs(t,s)){s+=1;continue}const r=Gu(t,s);if(r!==null){if(n<r.end||!r.closed&&n<=r.end)return"literal";s=r.end;continue}const i=Yu(t,s);if(i){const l=rl(t,i.to,i.name),a=l?.to??t.length;if(n<a||!l&&n<=a)return"literal";s=a;continue}s=Wb(t,s)}return null}function Ka(t,e,n){return t.slice(e,n).replace(/[^\r\n]/g," ")}function Vb(t){const e=t.split("");for(let n=0;n<t.length;n+=1){if(t[n]!=="%"||Vs(t,n))continue;const s=t.indexOf(`
|
|
13
|
+
`,n),r=s<0?t.length:s;for(let i=n;i<r;i+=1)e[i]=" ";n=r}return e.join("")}function Hb(t){let e="",n=0;for(;n<t.length;){if(t[n]==="%"&&!Vs(t,n)){const i=t.indexOf(`
|
|
14
|
+
`,n),l=i<0?t.length:i;e+=t.slice(n,l),n=l;continue}if(t[n]!=="\\"||Vs(t,n)){e+=t[n],n+=1;continue}const s=Ju(t,n);if(s!==null){e+=Ka(t,n,s),n=s;continue}const r=Yu(t,n);if(r){const l=rl(t,r.to,r.name)?.to??t.length;e+=Ka(t,n,l),n=l;continue}e+=t[n],n+=1}return e}function Kb(t,e){let n=0;for(let s=e-1;s>=0&&t[s]==="\\";s-=1)n+=1;return n%2===1}function Ga(t){const e=Vb(Hb(t)),n=/\\documentclass(?![A-Za-z@])\s*(?:\[[^\]]*\]\s*)?\{/g;for(const s of e.matchAll(n))if(s.index!==void 0&&!Kb(e,s.index))return!0;return!1}const Gb=new Set(Ku);function Jb(t){return/[A-Za-z@0-9:_-]/.test(t)}function Yb(t,e){let n=0;for(let s=e-1;s>=0&&t[s]==="\\";s-=1)n+=1;return n%2===1}function ys(t,e){return t[e]==="%"&&!Yb(t,e)}function er(t,e){const n=t.indexOf(`
|
|
15
|
+
`,e);return n===-1?t.length:n}function Ir(t,e){let n=e;for(;n<t.length;){if(/\s/.test(t[n])){n+=1;continue}if(ys(t,n)){n=er(t,n);continue}break}return n}function yo(t,e,n,s){if(t[e]!==n)return null;let r=0,i=0;for(let l=e;l<t.length;l+=1){const a=t[l];if(a==="\\"&&l+1<t.length){l+=1;continue}if(ys(t,l)){l=er(t,l)-1;continue}if(n==="["){if(a==="{"){i+=1;continue}if(a==="}"&&i>0){i-=1;continue}if(i>0)continue}if(a===n){r+=1;continue}if(a===s&&(r-=1,r===0))return{from:e,to:l+1,contentFrom:e+1,contentTo:l}}return null}function bo(t,e,n){const s=[];let r=e;for(;s.length<n;){for(r=Ir(t,r);t[r]==="[";){const l=yo(t,r,"[","]");if(!l)return s;r=Ir(t,l.to)}if(t[r]!=="{")break;const i=yo(t,r,"{","}");if(!i)break;s.push(i),r=i.to}return s}function b0(t,e,n){const s=[];let r=e;for(;s.length<n&&(r=Ir(t,r),t[r]==="[");){const i=yo(t,r,"[","]");if(!i)break;s.push(i),r=i.to}return s}function Xb(t,e){if(t[e]!=="\\"||e+1>=t.length)return null;let n=e+1;if(!/[A-Za-z@]/.test(t[n]))return{name:t[n],from:e,to:n+1};for(;n<t.length&&Jb(t[n]);)n+=1;const s=t.slice(e+1,n);return t[n]==="*"&&(n+=1),{name:s,from:e,to:n}}function Zb(t,e){if(e.name!=="begin")return e.to;const n=bo(t,e.to,1)[0];if(!n)return e.to;const s=t.slice(n.contentFrom,n.contentTo).trim();return Gb.has(s)?rl(t,n.to,s)?.to??t.length:e.to}function Qb(t,e){let n=0;for(;n<t.length;){if(ys(t,n)){n=er(t,n);continue}if(t[n]!=="\\"){n+=1;continue}const s=Xb(t,n);if(!s){n+=1;continue}const r=Ju(t,s.from);if(r!==null&&r>s.to){n=r;continue}const i=Zb(t,s);if(i>s.to){n=i;continue}e(s),n=s.to}}function Gi(t,e,n){const s=[];let r=e.contentFrom,i=e.contentFrom;for(;i<=e.contentTo;){if(i<e.contentTo&&ys(t,i)){i=er(t,i),t[i]===`
|
|
16
|
+
`&&(i+=1);continue}if(i!==e.contentTo){i+=1;continue}const l=ex(t,r,i);l&&s.push(l),r=i+1,i+=1}return s}function ex(t,e,n){const s=[];let r=e;for(;r<n;){if(ys(t,r)){r=er(t,r),t[r]===`
|
|
17
|
+
`&&(r+=1);continue}s.push({character:t[r],index:r}),r+=1}let i=0,l=s.length;for(;i<l&&/\s/.test(s[i].character);)i+=1;for(;l>i&&/\s/.test(s[l-1].character);)l-=1;return i===l?null:{path:s.slice(i,l).map(a=>a.character).join(""),command:"",from:s[i].index,to:s[l-1].index+1}}function tx(t,e){const n=Ir(t,e);if(n>=t.length||/[\\{}\[\]#~]/.test(t[n]))return null;let s=n;for(;s<t.length&&!/\s/.test(t[s])&&!ys(t,s)&&!/[\\{}\[\]#~]/.test(t[s]);)s+=1;return s===n?null:{path:t.slice(n,s),command:"",from:n,to:s}}function Ja(t){const e=[];return Qb(t,n=>{const s=n.name.toLowerCase();if(s==="input"||s==="include"||s==="subfile"){const c=bo(t,n.to,1)[0];if(c)for(const h of Gi(t,c))e.push({...h,command:n.name});else if(s==="input"){const h=tx(t,n.to);h&&e.push({...h,command:n.name})}return}if(s!=="import"&&s!=="subimport"&&s!=="includefrom"&&s!=="inputfrom"&&s!=="subinputfrom"&&s!=="subincludefrom")return;const r=bo(t,n.to,2);if(r.length!==2)return;const i=Gi(t,r[0])[0]?.path??"",l=Gi(t,r[1])[0];if(!l)return;const a=i&&!i.endsWith("/")?"/":"";e.push({path:i+a+l.path,command:n.name,from:l.from,to:l.to,directory:i})}),e}function nx({sessions:t,status:e}){const{t:n}=Ye(),[s,r]=u.useState(!1),i=Math.max(0,t.length-5),l=s&&i>0,a=l?t:t.slice(0,5);return u.useEffect(()=>{t.length<=5&&r(!1)},[t.length]),t.length<=1?null:o.jsxs("div",{className:`collaboration-presence collaboration-${e}`,children:[o.jsx("span",{className:"collaboration-status-dot","data-tooltip":n(`editor.collaboration.${e}`),"aria-label":n(`editor.collaboration.${e}`)}),o.jsxs("div",{className:"collaboration-avatars","aria-label":n("editor.collaboration.activeSessions",{count:t.length}),children:[a.map(c=>{const h=c.editing?n("editor.collaboration.editing"):n("editor.collaboration.viewing"),d=c.permission==="read"?n("common.readOnly"):n("common.readWrite"),f=n("editor.collaboration.sessionTooltip",{name:c.name,username:c.username,file:c.filePath||n("editor.collaboration.joining"),activity:h,permission:d});return o.jsxs("span",{className:`collaboration-avatar${c.editing?" editing":""}${c.local?" local":""}`,style:{"--session-color":c.color},"aria-label":f,tabIndex:0,children:[jb(c.name,c.username),o.jsxs("span",{className:"collaboration-avatar-tooltip",role:"tooltip",children:[o.jsx("strong",{children:c.name}),o.jsxs("span",{children:["@",c.username]}),o.jsxs("small",{children:[c.filePath||n("editor.collaboration.joining")," · ",h," · ",d]})]})]},c.clientId)}),i>0&&o.jsx("button",{type:"button",className:"collaboration-avatar collaboration-avatar-overflow","aria-expanded":l,"aria-label":l?n("editor.collaboration.showFewerSessions"):n("editor.collaboration.showMoreSessions",{count:i}),title:l?n("editor.collaboration.showFewerSessions"):n("editor.collaboration.showMoreSessions",{count:i}),onClick:()=>r(c=>!c),children:l?"−":`+${i}`})]})]})}function sx({value:t,onChange:e}){const{t:n}=Ye(),[s,r]=u.useState(!1),i=u.useRef(null),l=[{value:"editor-pdf",icon:Zl},{value:"editor-only",icon:lm},{value:"pdf-only",icon:am}];return u.useEffect(()=>{if(!s)return;const a=h=>{i.current?.contains(h.target)||r(!1)},c=h=>{h.key==="Escape"&&r(!1)};return document.addEventListener("pointerdown",a),document.addEventListener("keydown",c),()=>{document.removeEventListener("pointerdown",a),document.removeEventListener("keydown",c)}},[s]),o.jsxs("div",{className:"layout-menu",ref:i,children:[o.jsxs("button",{type:"button",className:`layout-trigger${s?" active":""}`,"aria-haspopup":"menu","aria-expanded":s,title:n("editor.layout.current",{layout:n(`editor.layout.${t}.name`)}),onClick:()=>r(a=>!a),children:[o.jsx(Zl,{size:15}),o.jsxs("span",{children:[o.jsx("small",{children:n("editor.layout.label")}),n(`editor.layout.${t}.name`)]}),o.jsx(Hs,{size:13})]}),s&&o.jsxs("div",{className:"layout-popover",role:"menu","aria-label":n("editor.layout.label"),children:[o.jsx("div",{className:"layout-popover-title",children:n("editor.layout.choose")}),l.map(a=>{const c=a.icon,h=a.value===t;return o.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":h,className:`layout-option${h?" selected":""}`,onClick:()=>{e(a.value),r(!1)},children:[o.jsx(c,{size:19}),o.jsxs("span",{children:[o.jsx("strong",{children:n(`editor.layout.${a.value}.name`)}),o.jsx("small",{children:n(`editor.layout.${a.value}.description`)})]}),h&&o.jsx($f,{size:16})]},a.value)})]})]})}function rx({site:t,project:e,activeFile:n,saveStateLabel:s,editorPreferences:r,activeSessions:i,collaborationStatus:l,reconnectCollaboration:a,protocolUpgradeRequired:c,showEditor:h,filesCollapsed:d,toggleFilesPanel:f,workspaceLayout:m,changeWorkspaceLayout:g,onBack:w,onShare:S,showCitationLibrary:L,citationLibraryOpen:v,onCitationLibrary:q,onHistory:A,onGit:x,canManageGit:P,formatting:j,readOnly:C,collaborationSynced:M,onToggleComments:H,commentsOpen:J,unresolvedCommentCount:le,onToggleSettings:B,settingsOpen:se,compileBusy:W,sharedCompiling:te,localCompiling:Y,cancelling:Ce,onCompile:ae,onCancelCompile:Z}){const{t:$}=Ye();return o.jsxs("header",{className:"editor-topbar",children:[o.jsx("button",{className:"back",title:$("editor.backToProjects"),"aria-label":$("editor.backToProjects"),onClick:w,children:o.jsx(bf,{size:18})}),o.jsx("a",{className:"brand-link compact-brand-link",href:fs("/"),"aria-label":t.siteName,onClick:ue=>{ue.preventDefault(),w()},children:o.jsx(pf,{siteName:t.siteName,compact:!0})}),o.jsxs("div",{className:"project-heading",children:[o.jsx("strong",{children:e.name}),o.jsxs("small",{children:[n," · ",s]})]}),r.vimMode&&o.jsxs("span",{className:"vim-status-badge",title:$("editor.vimOnHint"),children:[o.jsx(nm,{size:14}),$("editor.vimOn")]}),o.jsx(nx,{sessions:i,status:l}),l==="disconnected"&&!c&&o.jsxs("div",{className:"collaboration-recovery",role:"status",children:[o.jsx("span",{children:$("editor.collaboration.disconnected")}),o.jsx("button",{type:"button",onClick:a,children:$("editor.collaboration.reconnect")})]}),o.jsxs("div",{className:"editor-actions",children:[h&&o.jsxs("button",{className:d?"":"active",onClick:f,children:[d?o.jsx(om,{size:15}):o.jsx(im,{size:15}),$("common.files")]}),o.jsx(sx,{value:m,onChange:g}),o.jsxs("button",{onClick:S,children:[o.jsx(kr,{size:15}),$("projectSettings.share")]}),L&&o.jsxs("button",{className:v?"active":"",onClick:q,children:[o.jsx(xf,{size:15}),$("citationLibrary.title")]}),o.jsxs("button",{type:"button",className:"snapshots-action",title:$("history.projectSnapshots"),onClick:A,children:[o.jsx(Jf,{size:15}),$("history.projectSnapshotsButton")]}),o.jsxs("button",{type:"button",className:`comments-action${J?" active":""}`,title:$("editor.commentsAll"),"aria-label":le>0?`${$("common.comments")} (${le})`:$("common.comments"),onClick:H,children:[o.jsx(kf,{size:15}),o.jsx("span",{children:$("common.comments")}),le>0&&o.jsx("sup",{className:"comments-action-count",children:le})]}),o.jsxs("button",{className:"git-action",title:$(P?"git.title":"git.ownerOnly"),disabled:!P,onClick:x,children:[o.jsx(Sf,{size:15}),"Git"]}),o.jsxs("button",{className:se?"active":"",onClick:B,children:[o.jsx(mm,{size:15}),$("common.settings")]}),te||Y?o.jsxs("button",{className:"compile cancel-compile",title:$("compileControls.cancel"),onClick:Z,disabled:Ce||j||C||!M,children:[Ce?o.jsx(lt,{className:"spin",size:15}):o.jsx(cn,{size:15}),$(Ce?"compileControls.cancelling":"compileControls.cancel")]}):o.jsxs("button",{className:"compile",title:$("editor.compileShortcut"),onClick:ae,disabled:W||j||C||!M,children:[W?o.jsx(lt,{className:"spin",size:15}):o.jsx(cm,{size:15}),$("editor.compile",{engine:e.engine})]})]})]})}function ix(t){return`${t.path}\0${t.line}`}function ox(t){const e=[],n=[];for(const s of t){for(;n.length&&n.at(-1).level>=s.level;)n.pop();const r=n.at(-1);r&&(e[r.index].hasChildren=!0),e.push({item:s,key:ix(s),ancestorKeys:n.map(({index:i})=>e[i].key),hasChildren:!1}),n.push({level:s.level,index:e.length-1})}return e}function lx(t,e){return t.filter(n=>!n.ancestorKeys.some(s=>e.has(s)))}const ax=new Set(["avif","bmp","gif","ico","jpeg","jpg","png","svg","webp","eps"]),cx=new Set(["latex","ltx","tex"]),ux=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"]),dx=new Set(["cfg","conf","dat","env","ini","text","toml","txt"]),hx=new Set(["csv","ods","tsv","xls","xlsx"]),fx=new Set(["7z","bz2","gz","rar","tar","xz","zip"]),mx=new Set(["m4a","mp3","ogg","wav"]),px=new Set(["avi","mkv","mov","mp4","webm"]);function gx(t){const e=t.split("/").at(-1)?.toLocaleLowerCase()??"";if(e===".latexmkrc"||e==="latexmkrc")return"latexmkrc";if(e==="makefile"||e==="dockerfile")return"code";if(e==="readme"||e.startsWith("readme."))return"markdown";const n=e.includes(".")?e.slice(e.lastIndexOf(".")+1):"";return n==="pdf"?"pdf":ax.has(n)?"image":n==="md"||n==="markdown"||n==="mdown"||n==="mkdn"?"markdown":cx.has(n)?"tex":n==="bib"||n==="bibtex"?"bib":ux.has(n)?"code":dx.has(n)?"text":hx.has(n)?"spreadsheet":fx.has(n)?"archive":mx.has(n)?"audio":px.has(n)?"video":"file"}const wx={pdf:Qf,tex:Jl,bib:sm,latexmkrc:Yf,image:Xf,markdown:rc,text:vf,code:Jl,spreadsheet:Cf,archive:Yi,audio:Gf,video:em,file:Ur};function Xu({path:t,size:e=13}){const n=gx(t);if(n==="pdf"||n==="tex")return o.jsx("img",{className:`file-type-icon file-type-icon-${n}`,src:fs(`/${n==="pdf"?"pdf-file":"tex-file"}.svg`),width:e,height:e,alt:"","aria-hidden":"true"});const s=wx[n]??tm;return o.jsx(s,{className:`file-type-icon file-type-icon-${n}`,size:e,"aria-hidden":"true"})}const Zu="application/x-texlite-project-path",Qu="texlite-path:";function yx({project:t,filesPanel:e,visibleEntries:n,activeFile:s,activeMainFile:r,selectedFile:i,selectedFolder:l,expandedFolders:a,fileDragActive:c,uploadingFiles:h,uploadFeedback:d,readOnly:f,formatting:m,canFormat:g,activeFormatLease:w,collaborationSynced:S,editorFontSize:L,outline:v,sourceCursorStore:q,wordCountBusy:A,hasSelection:x,hasFormatSelection:P,uploadInput:j,setSelectedFolder:C,setExpandedFolders:M,setMoveEntry:H,setMoveName:J,setMoveDestination:le,setDeleteEntry:B,setFileDialogError:se,setNewFolderName:W,setNewFolderOpen:te,setNewFilePath:Y,setNewFileOpen:Ce,setQuickOpen:ae,setFileDragActive:Z,dismissUploadFeedback:$,setFilesCollapsed:ue,uploadFiles:Ee,upload:ke,openFile:ve,movePathToFolder:X,onError:I,onFormatFile:fe,onFormatSelection:ye,jumpToSource:O,syncSourceToPdf:z,onWordCount:De}){const{t:U}=Ye(),[R,he]=u.useState(!1),[K,Ne]=u.useState(null),[Ve,Me]=u.useState(null),Fe=u.useRef(0),ne=(_,ge)=>xx(_.path)!==ge&&(_.type!=="directory"||ge!==_.path&&!ge.startsWith(`${_.path}/`)),be=()=>{Ne(null),Me(null)};return o.jsx(zr,{id:"files",order:1,ref:e,defaultSize:16,minSize:12,maxSize:30,collapsible:!0,collapsedSize:0,onCollapse:()=>ue(!0),onExpand:()=>ue(!1),children:o.jsxs("aside",{className:"left-panel",children:[o.jsxs("section",{className:`files-panel${c?" drop-active":""}`,onDragEnter:_=>{if(Sn(_.dataTransfer)){_.preventDefault();return}_.dataTransfer.types.includes("Files")&&(_.preventDefault(),!f&&!h&&Z(!0))},onDragOver:_=>{if(Sn(_.dataTransfer)){_.preventDefault(),_.dataTransfer.dropEffect="move";return}_.dataTransfer.types.includes("Files")&&(_.preventDefault(),_.dataTransfer.dropEffect=f||h?"none":"copy")},onDragLeave:_=>{_.currentTarget.contains(_.relatedTarget)||Z(!1)},onDrop:_=>{if(Sn(_.dataTransfer)){_.preventDefault(),_.stopPropagation();return}if(_.preventDefault(),Z(!1),f||h)return;const ge=Array.from(_.dataTransfer.files);if(bx(_.dataTransfer)||ge.length===0){I(U("editor.dropFoldersUnsupported"));return}Ee(ge)},children:[o.jsxs("div",{className:"panel-title",children:[o.jsx("button",{className:"file-size-toggle",type:"button","aria-pressed":R,title:U(R?"editor.hideFileSizes":"editor.showFileSizes"),onClick:()=>he(_=>!_),children:U("common.files")}),o.jsxs("span",{className:"file-tools",children:[o.jsx("button",{type:"button","aria-label":U("navigation.quickOpen"),title:`${U("navigation.quickOpen")} (Ctrl/Cmd+P)`,onClick:()=>ae(!0),children:o.jsx(jf,{size:15})}),!f&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",disabled:h,"aria-label":U("editor.uploadAttachment"),title:U("editor.uploadTo",{folder:l||U("editor.projectRoot")}),onClick:()=>j.current?.click(),children:o.jsx(Yl,{size:15})}),o.jsx("button",{type:"button","aria-label":U("editor.newFolder"),title:U("editor.newFolder"),onClick:()=>{W(""),te(!0)},children:o.jsx(Ef,{size:15})}),o.jsx("button",{type:"button","aria-label":U("editor.newFile"),title:U("editor.newFile"),onClick:()=>{Y(l?`${l}/`:""),Ce(!0)},children:o.jsx(Zf,{size:15})}),o.jsx("input",{ref:j,type:"file",multiple:!0,hidden:!0,onChange:_=>{ke(_)}})]})]})]}),d&&o.jsxs("div",{className:`file-upload-feedback ${d.kind}`,role:d.kind==="error"?"alert":"status","aria-live":d.kind==="error"?"assertive":"polite","aria-busy":d.kind==="uploading",children:[d.kind==="uploading"?o.jsx(lt,{className:"spin",size:14}):d.kind==="success"?o.jsx(Zi,{size:14}):o.jsx(Dt,{size:14}),o.jsxs("span",{className:"file-upload-feedback-text",children:[d.kind==="uploading"&&U("editor.uploadingFile",{file:d.fileName,current:d.current,total:d.total}),d.kind==="success"&&U("editor.uploadSucceeded",{count:d.count}),d.kind==="error"&&d.message]}),d.kind!=="uploading"&&o.jsx("button",{type:"button",className:"file-upload-feedback-dismiss","aria-label":U("common.close"),title:U("common.close"),onClick:$,children:o.jsx(cn,{size:13})})]}),c&&o.jsxs("div",{className:"file-drop-overlay",children:[o.jsx(Yl,{size:24}),o.jsx("strong",{children:U("editor.dropFiles")}),o.jsx("span",{children:U("editor.uploadTo",{folder:l||U("editor.projectRoot")})})]}),o.jsx("div",{className:`file-list${l!==null?" folder-selected":""}${Ve===""?" root-drop-target":""}`,style:{fontSize:`${L}px`},onDragOver:_=>{if(!(!K&&!Sn(_.dataTransfer))&&(_.preventDefault(),_.stopPropagation(),!!K)){if(!ne(K,"")){_.dataTransfer.dropEffect="none";return}_.dataTransfer.dropEffect="move",Me("")}},onDragLeave:_=>{_.currentTarget.contains(_.relatedTarget)||Me(ge=>ge===""?null:ge)},onDrop:_=>{if(!K&&!Sn(_.dataTransfer)||(_.preventDefault(),_.stopPropagation(),!K))return;const ge=K;be(),ne(ge,"")&&X(ge,"")},children:n.map(_=>{const ge=_.path.split("/").length-1,xe=_.path.split("/").at(-1),Le=a.has(_.path),Ue=t.mainFile===_.path,Ge=_.path!==t.mainFile&&!t.mainFile.startsWith(`${_.path}/`);return _.type==="directory"?o.jsxs("div",{className:`file-entry folder-entry${l===_.path?" selected":""}${Ve===_.path?" move-drop-target":""}`,style:{paddingLeft:`${ge*13+5}px`},onDragOver:Re=>{if(!(!K&&!Sn(Re.dataTransfer))&&(Re.preventDefault(),Re.stopPropagation(),!!K)){if(!ne(K,_.path)){Re.dataTransfer.dropEffect="none";return}Re.dataTransfer.dropEffect="move",Me(_.path)}},onDragLeave:Re=>{Re.currentTarget.contains(Re.relatedTarget)||Me(re=>re===_.path?null:re)},onDrop:Re=>{if(!K&&!Sn(Re.dataTransfer)||(Re.preventDefault(),Re.stopPropagation(),!K))return;const re=K;be(),ne(re,_.path)&&X(re,_.path)},children:[o.jsxs("button",{type:"button",className:"file-entry-main",onClick:()=>{C(_.path),M(Re=>{const re=new Set(Re);return re.has(_.path)?re.delete(_.path):re.add(_.path),re})},children:[Le?o.jsx(Hs,{size:13}):o.jsx(ko,{size:13}),o.jsx(Df,{size:14}),o.jsx("span",{children:xe})]}),!f&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"file-entry-action","data-texlite-tooltip-always":!0,title:U("editor.move"),"aria-label":U("editor.move"),onClick:()=>{H(_),J(xe??""),le("")},children:o.jsx(ea,{size:13})}),Ge&&o.jsx("button",{type:"button",className:"file-entry-action danger-text",title:U("editor.deletePath"),"aria-label":U("editor.deletePath"),onClick:()=>{B(_),se("")},children:o.jsx(Tn,{size:13})})]})]},_.path):o.jsxs("div",{className:`file-entry${l===null&&i===_.path?" active":""}${K?.path===_.path?" move-drag-source":""}`,style:{paddingLeft:`${ge*13+18}px`},children:[o.jsxs("button",{type:"button",className:"file-entry-main",draggable:!f,onDragStart:Re=>{Fe.current=Date.now()+500,kx(Re,_,Ne)},onDragEnd:be,onClick:()=>{if(Fe.current>Date.now()){Fe.current=0;return}ve(_)},children:[o.jsx(Xu,{path:_.path}),o.jsx("span",{children:xe}),Ue&&o.jsx("small",{children:U("editor.currentMainShort")})]}),R&&typeof _.size=="number"&&o.jsx("span",{className:"file-entry-size",children:Cx(_.size)}),!f&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"file-entry-action","data-texlite-tooltip-always":!0,title:U("editor.move"),"aria-label":U("editor.move"),onClick:()=>{H(_),J(xe??""),le("")},children:o.jsx(ea,{size:13})}),Ge&&o.jsx("button",{type:"button",className:"file-entry-action danger-text",title:U("editor.deletePath"),"aria-label":U("editor.deletePath"),onClick:()=>{B(_),se("")},children:o.jsx(Tn,{size:13})})]})]},_.path)})}),!f&&g&&o.jsxs("div",{className:"file-format-footer",role:"group","aria-label":U("editor.format"),"aria-busy":m,children:[o.jsxs("div",{className:"file-format-label",children:[o.jsx(Vf,{size:13}),U("editor.format")]}),o.jsxs("div",{className:"file-format-actions",children:[o.jsx("button",{className:P?"":"active",type:"button",title:U("editor.formatFileHint"),onMouseDown:_=>_.preventDefault(),onClick:fe,disabled:m||w||!S,children:U("editor.formatFile")}),o.jsx("button",{className:P?"active":"",type:"button",title:U(P?"editor.formatSelection":"editor.formatSelectionHint"),onMouseDown:_=>_.preventDefault(),onClick:ye,disabled:m||w||!S||!P,children:U("editor.formatSelected")})]})]})]}),o.jsx(Sx,{outline:v,activeFile:s,activeMainFile:r,sourceCursorStore:q,wordCountBusy:A,hasSelection:x,jumpToSource:O,syncSourceToPdf:z,onWordCount:De})]})})}function bx(t){return Array.from(t.items).some(e=>e.webkitGetAsEntry?.()?.isDirectory===!0)}function Sn(t){return Array.from(t.types).includes(Zu)?!0:Array.from(t.types).includes("text/plain")&&t.getData("text/plain").startsWith(Qu)}function xx(t){const e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function kx(t,e,n){t.dataTransfer.effectAllowed="move",t.dataTransfer.setData(Zu,e.path),t.dataTransfer.setData("text/plain",`${Qu}${e.path}`),n(e)}function Sx({outline:t,activeFile:e,activeMainFile:n,sourceCursorStore:s,wordCountBusy:r,hasSelection:i,jumpToSource:l,syncSourceToPdf:a,onWordCount:c}){const{t:h}=Ye(),d=u.useSyncExternalStore(s.subscribe,s.getOutlineLine,s.getOutlineLine),f=u.useMemo(()=>ox(t),[t]),m=u.useMemo(()=>f.filter(A=>A.hasChildren).map(A=>A.key),[f]),[g,w]=u.useState(()=>new Set);u.useEffect(()=>{const A=new Set(m);w(x=>{const P=new Set([...x].filter(j=>A.has(j)));return P.size===x.size?x:P})},[m]);const S=m.length>0&&m.every(A=>g.has(A)),L=u.useMemo(()=>lx(f,g),[f,g]),v=()=>w(A=>S?new Set([...A].filter(x=>!m.includes(x))):new Set([...A,...m])),q=A=>w(x=>{const P=new Set(x);return P.has(A)?P.delete(A):P.add(A),P});return o.jsxs("section",{className:"outline-panel",children:[o.jsxs("div",{className:"panel-title",children:[o.jsxs("button",{className:"outline-heading",type:"button","aria-expanded":!S,title:h(S?"editor.expandOutline":"editor.collapseOutline"),onClick:v,disabled:m.length===0,children:[o.jsx(Tf,{size:14}),h("common.outline")]}),o.jsxs("span",{className:"word-count-actions",role:"group","aria-label":h("editor.wordCountTitle"),children:[o.jsxs("button",{type:"button",title:h("editor.wordCountFullHint"),onClick:()=>c("full"),disabled:r||!n,children:[r?o.jsx(lt,{className:"spin",size:12}):o.jsx(Ql,{size:12}),h("editor.wordCountFull")]}),o.jsxs("button",{type:"button",title:h("editor.wordCountSelectionHint"),onClick:()=>c("selection"),disabled:r||!i,children:[r?o.jsx(lt,{className:"spin",size:12}):o.jsx(Ql,{size:12}),h("editor.wordCountSelection")]})]})]}),o.jsxs("div",{className:"outline",children:[L.map(A=>{const{item:x}=A,P=g.has(A.key),j=e===x.path&&d===x.line,C=x.path===n||x.path===e;return o.jsxs("div",{className:`outline-row${j?" current":""}`,children:[o.jsx("span",{className:"outline-guides","aria-hidden":!0,style:{width:`${x.level*12}px`}}),A.hasChildren?o.jsx("button",{className:"outline-toggle",type:"button","aria-label":h(P?"editor.expandOutlineItem":"editor.collapseOutlineItem",{title:x.title}),"aria-expanded":!P,onClick:()=>q(A.key),children:P?o.jsx(ko,{size:13}):o.jsx(Hs,{size:13})}):o.jsx("span",{className:"outline-toggle-spacer","aria-hidden":!0}),o.jsxs("button",{className:"outline-item",type:"button",onClick:()=>{l(x.path,x.line,1),a(x.path,x.line,1)},children:[o.jsx("small",{children:C?x.line:x.path.split("/").at(-1)}),o.jsx("span",{className:"outline-title",children:x.title})]})]},A.key)}),t.length===0&&o.jsx("p",{className:"muted padded",children:h("editor.noOutline")})]})]})}function Cx(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/1024/1024).toFixed(1)} MB`:`${(t/1024/1024/1024).toFixed(1)} GB`}const vx=u.lazy(()=>Lt(()=>import("./LatexEditor-sMjmvA6V.js"),__vite__mapDeps([10,2,11,1,3,4,5,6,7,8]),import.meta.url).then(t=>({default:t.LatexEditor})));function jx({project:t,activeFile:e,openTabs:n,content:s,loadedFile:r,readOnly:i,comments:l,focusComment:a,editorPreferences:c,completionIndex:h,nativeSpellCheck:d,spellCheckIssues:f,spellCheckJump:m,sourceJump:g,collaborativeText:w,collaborationAwareness:S,undoManager:L,editorNotice:v,activateTab:q,closeTab:A,handleTabKeyDown:x,updateEditorContent:P,setSelection:j,onAddComment:C,onSelectionHistory:M,onCommentClick:H,onSpellCheckReplace:J,onReferenceNavigate:le,onCursor:B}){const{t:se}=Ye(),W=Gm(l,e),te=Jm(a,e,r);return o.jsx(zr,{id:"source",order:2,defaultSize:42,minSize:22,children:o.jsxs("main",{className:"source-panel",children:[c.openFilesInTabs&&n.length>0&&o.jsx("div",{className:"editor-tabs-bar",role:"tablist","aria-label":se("editor.openFiles"),children:o.jsx("div",{className:"editor-tabs-scroll",children:n.map((Y,Ce)=>{const ae=Y===e,Z=Y===t.mainFile,$=Y.split("/").at(-1)||Y;return o.jsxs("div",{className:`editor-tab-item${ae?" active":""}`,role:"presentation",children:[o.jsxs("button",{id:`editor-tab-${encodeURIComponent(Y)}`,type:"button",role:"tab","aria-selected":ae,"aria-controls":"editor-source-content",tabIndex:ae?0:-1,className:`editor-tab${ae?" active":""}${Z?" main-tab":""}`,onClick:()=>q(Y),onKeyDown:ue=>x(ue,Ce),title:Y,children:[o.jsx("span",{className:"editor-tab-icon",children:Z?o.jsx(rc,{size:13}):o.jsx(Ur,{size:13})}),o.jsx("span",{className:"editor-tab-title",children:$}),Z&&o.jsx("small",{className:"editor-tab-badge",children:se("editor.currentMainShort")})]}),o.jsx("button",{type:"button",className:"editor-tab-close",title:se("common.close"),"aria-label":`${se("common.close")} ${$}`,onClick:()=>A(Y),children:o.jsx(cn,{size:12})})]},Y)})})}),o.jsxs("div",{id:"editor-source-content",className:"editor-content-container",children:[o.jsx(u.Suspense,{fallback:o.jsxs("div",{className:"preview-empty",children:[o.jsx(lt,{className:"spin",size:22}),o.jsx("span",{children:se("common.loading")})]}),children:o.jsx(vx,{value:s,filePath:e,readOnly:i,comments:W,focusComment:te,preferences:c,nativeSpellCheck:d,completionIndex:h,spellCheckIssues:f,spellCheckJump:m,jumpTo:r===e&&g?.path===e?g:null,searchRequest:0,collaboration:w?{text:w,awareness:S,undoManager:i?void 0:L}:void 0,onChange:P,onSelection:j,onAddComment:C,onSelectionHistory:M,onCommentClick:H,onSpellCheckReplace:J,onReferenceNavigate:le,onCursor:B},e)}),v&&o.jsx("div",{className:"editor-centered-notice",role:"status","aria-live":"polite",children:v})]})]})})}function Ya({diagnostics:t,files:e,empty:n,tone:s,onJump:r}){const{t:i}=Ye(),l=s==="error"?So:Dt;return t.length?o.jsx("div",{className:`compile-diagnostic-list compile-${s}`,children:t.map((a,c)=>{const h=Tx(a.file,e),d=!!(h&&a.line);return o.jsxs("button",{type:"button",disabled:!d,className:"compile-diagnostic-row",onClick:()=>{h&&a.line&&r(h,a.line,a.column??1)},children:[o.jsx(l,{size:15}),o.jsxs("span",{children:[o.jsx("strong",{children:a.message}),o.jsxs("small",{children:[a.phase,h?` · ${h}${a.line?`:${a.line}`:""}`:a.line?` · ${i("editor.lineNumber",{line:a.line})}`:""]})]})]},`${a.phase}-${a.file??""}-${a.line??0}-${c}`)})}):o.jsxs("div",{className:`compile-empty compile-${s}`,children:[o.jsx(l,{size:26}),o.jsx("span",{children:n})]})}function Ji({lines:t,empty:e,tone:n="log"}){const s=n==="error"?So:n==="warning"?Dt:Xi;return t.length?o.jsx("pre",{className:`compile-output compile-${n}`,children:t.join(`
|
|
18
|
+
`)}):o.jsxs("div",{className:`compile-empty compile-${n}`,children:[o.jsx(s,{size:26}),o.jsx("span",{children:e})]})}function Ex({projectId:t,mainFile:e,artifacts:n,preview:s,loading:r,onView:i}){const{t:l}=Ye(),a=c=>fs(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(e)}&path=${encodeURIComponent(c)}&download=1`);return n.length?o.jsxs("div",{className:"artifact-browser",children:[o.jsx("div",{className:"artifact-list",children:n.map(c=>o.jsxs("div",{className:`artifact-row${s?.path===c.path?" active":""}`,children:[o.jsxs("button",{type:"button",disabled:!c.viewable,title:c.viewable?l("editor.viewArtifact"):l("editor.downloadToView"),onClick:()=>i(c),children:[o.jsx(Xu,{path:c.path,size:14}),o.jsxs("span",{children:[o.jsx("strong",{children:c.path}),o.jsx("small",{children:_x(c.size)})]})]}),o.jsx("a",{href:a(c.path),title:l("editor.downloadArtifact"),"aria-label":l("editor.downloadArtifact"),children:o.jsx(Sr,{size:14})})]},c.path))}),o.jsx("div",{className:"artifact-preview",children:r?o.jsxs("div",{className:"compile-empty",children:[o.jsx(lt,{className:"spin",size:24}),o.jsx("span",{children:l("common.loading")})]}):s?o.jsxs(o.Fragment,{children:[o.jsxs("header",{children:[o.jsx("strong",{children:s.path}),o.jsxs("a",{href:a(s.path),children:[o.jsx(Sr,{size:13}),l("projects.download")]})]}),o.jsx("pre",{children:s.content})]}):o.jsxs("div",{className:"compile-empty",children:[o.jsx(Ur,{size:24}),o.jsx("span",{children:l("editor.selectArtifact")})]})})]}):o.jsxs("div",{className:"compile-empty",children:[o.jsx(oc,{size:26}),o.jsx("span",{children:l("editor.noArtifacts")})]})}function Dx({mainFile:t,disabled:e,cleaning:n,onCleanCache:s,onCleanArtifacts:r}){const{t:i}=Ye();return o.jsxs("div",{className:"compile-clean-panel",children:[o.jsxs("div",{className:"compile-clean-intro",children:[o.jsx(Dt,{size:28}),o.jsxs("div",{children:[o.jsx("strong",{children:i("editor.cleanTitle")}),o.jsx("p",{children:i("editor.cleanDescription",{file:t})})]})]}),o.jsxs("div",{className:"compile-clean-actions",children:[o.jsxs("article",{children:[o.jsx("div",{className:"compile-clean-action-icon",children:o.jsx(Qi,{size:19})}),o.jsxs("div",{children:[o.jsx("strong",{children:i("editor.cleanCache")}),o.jsx("p",{children:i("editor.cleanCacheDescription")}),o.jsxs("button",{type:"button",disabled:e||n,onClick:s,children:[n?o.jsx(lt,{className:"spin",size:14}):o.jsx(Qi,{size:14}),i("editor.cleanCache")]})]})]}),o.jsxs("article",{className:"danger",children:[o.jsx("div",{className:"compile-clean-action-icon",children:o.jsx(Tn,{size:19})}),o.jsxs("div",{children:[o.jsx("strong",{children:i("editor.cleanArtifacts")}),o.jsx("p",{children:i("editor.cleanArtifactsDescription")}),o.jsxs("button",{type:"button",className:"danger",disabled:e||n,onClick:r,children:[n?o.jsx(lt,{className:"spin",size:14}):o.jsx(Tn,{size:14}),i("editor.cleanArtifacts")]})]})]})]})]})}function Tx(t,e){if(!t)return null;const n=e.filter(a=>a.type==="file").map(a=>a.path),s=t.replaceAll("\\","/").replace(/^\.\//,"");if(n.includes(s))return s;const r=n.filter(a=>s.endsWith(`/${a}`));if(r.length===1)return r[0];const i=s.split("/").at(-1),l=n.filter(a=>a.split("/").at(-1)===i);return l.length===1?l[0]:null}function _x(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}const Rx=u.lazy(()=>nc().then(t=>({default:t.PdfPreview})));function Lx({projectId:t,activeMainFile:e,previewTab:n,diagnosticTab:s,pdfUrl:r,pdfLoadingMode:i,pdfLoading:l,pdfCompiledAt:a,pdfSizeBytes:c,pdfCompiledLabel:h,pdfTargetLabel:d,pdfDownloadUrl:f,pdfTarget:m,pdfViewport:g,activeFile:w,compileBusy:S,compileLog:L,compileDiagnostics:v,compileMessages:q,artifacts:A,artifactPreview:x,artifactLoading:P,cleaning:j,readOnly:C,collaborationSynced:M,workspaceLayout:H,showSyncResize:J,diagnosticCount:le,selectPreviewTab:B,changeWorkspaceLayout:se,onSetPdfViewport:W,onResetPdfViewport:te,syncVisiblePdfToSource:Y,syncCurrentSourceToPdf:Ce,syncPdfToSource:ae,canSyncWithPdf:Z,canSyncPdfToSource:$,files:ue,jumpToSource:Ee,onSetCleanMode:ke,viewArtifact:ve}){const{t:X}=Ye(),[I,fe]=u.useState(""),ye=u.useRef(""),O=R=>{ye.current!==R&&(ye.current=R,fe(R),te())},z=$&&!!r&&I===r,U=[c==null?"":Ax(c),h?X("editor.pdfUpdatedAt",{time:h}):""].filter(Boolean).join(" · ");return o.jsxs(o.Fragment,{children:[J&&o.jsxs(xo,{className:"resize-handle sync-resize-handle",children:[o.jsx(ic,{className:"resize-grip",size:12}),o.jsxs("span",{className:"sync-direction-buttons",onPointerDown:R=>R.stopPropagation(),children:[o.jsx("button",{disabled:!r||!g||!z,title:X($?z?"editor.showInSource":"editor.syncTexWaitingForPdf":"editor.syncTexOnlyForMain"),"aria-label":X("editor.showInSource"),onClick:()=>{z&&Y()},children:o.jsx("span",{"aria-hidden":!0,children:"←"})}),o.jsx("button",{disabled:!w||!r||!Z,title:X(Z?"editor.showInPdf":"editor.syncTexOnlyForMain"),"aria-label":X("editor.showInPdf"),onClick:()=>{!w||!r||!Z||Ce()},children:o.jsx("span",{"aria-hidden":!0,children:"→"})})]})]}),o.jsx(zr,{id:"preview",order:3,defaultSize:42,minSize:22,children:o.jsxs("section",{className:"preview-panel",children:[o.jsxs("div",{className:"preview-tabs",children:[o.jsxs("div",{className:"preview-tab-list",role:"tablist","aria-label":X("editor.outputTabs"),children:[o.jsxs("button",{role:"tab","aria-selected":n==="pdf",className:`pdf-tab${n==="pdf"?" active":""}`,onClick:()=>B("pdf"),title:a?X("editor.pdfCompiledAtFor",{file:e,time:new Date(a).toLocaleString(Rs.resolvedLanguage)}):X("editor.currentMainDocument",{path:e}),children:[o.jsx("img",{className:"pdf-tab-icon",src:fs("/pdf-download.svg"),alt:"","aria-hidden":"true"}),o.jsxs("span",{className:"pdf-tab-label",children:["PDF · ",d,U&&o.jsx("small",{children:U})]})]}),o.jsxs("button",{role:"tab","aria-selected":n==="diagnostics",className:`diagnostics-tab${n==="diagnostics"?" active":""}`,onClick:()=>B("diagnostics"),children:[o.jsx(Xi,{size:14}),X("editor.outputTabs"),o.jsx("span",{children:le})]})]}),f&&o.jsxs("a",{className:"pdf-download-top",href:f,download:!0,title:X("editor.downloadPdf"),"aria-label":X("editor.downloadPdf"),children:[o.jsx(Sr,{size:15}),o.jsx("span",{children:X("editor.downloadPdf")})]})]}),n==="diagnostics"&&o.jsxs("div",{className:"preview-subtabs",role:"tablist","aria-label":X("editor.outputTabs"),children:[o.jsxs("button",{role:"tab","aria-selected":s==="log",className:s==="log"?"active":"",onClick:()=>B("log"),children:[o.jsx(Xi,{size:13}),X("editor.log")]}),o.jsxs("button",{role:"tab","aria-selected":s==="warnings",className:s==="warnings"?"active":"",onClick:()=>B("warnings"),children:[o.jsx(Dt,{size:13}),X("editor.warnings"),o.jsx("span",{children:q.warnings.length})]}),o.jsxs("button",{role:"tab","aria-selected":s==="errors",className:s==="errors"?"active":"",onClick:()=>B("errors"),children:[o.jsx(So,{size:13}),X("editor.errors"),o.jsx("span",{children:q.errors.length})]}),o.jsxs("button",{role:"tab","aria-selected":s==="artifacts",className:s==="artifacts"?"active":"",onClick:()=>B("artifacts"),children:[o.jsx(oc,{size:13}),X("editor.artifacts"),o.jsx("span",{children:A.length})]}),o.jsxs("button",{role:"tab","aria-selected":s==="clean",className:s==="clean"?"active":"",onClick:()=>B("clean"),children:[o.jsx(Qi,{size:13}),X("editor.clean")]})]}),o.jsxs("div",{className:`preview-content preview-${n} ${n==="diagnostics"?`preview-${s}`:""}`,children:[n==="pdf"&&(r?o.jsx(u.Suspense,{fallback:o.jsxs("div",{className:"pdf-loading-state",role:"status","aria-live":"polite",children:[o.jsx(lt,{className:"spin",size:24}),o.jsx("span",{children:X("editor.loadingPdf")})]}),children:o.jsx(Rx,{url:r,loadingMode:i,target:m,compiling:S,onDisplayedUrlChange:O,onViewportLocation:(R,he,K)=>{ye.current===r&&W({page:R,x:he,y:K})},onDoubleClickLocation:(R,he,K)=>{ye.current!==r||!z||(W({page:R,x:he,y:K}),ae(R,he,K))}})}):l?o.jsxs("div",{className:"pdf-loading-state",role:"status","aria-live":"polite",children:[o.jsx(lt,{className:"spin",size:24}),o.jsx("span",{children:X("editor.loadingPdf")})]}):o.jsxs("div",{className:"preview-empty",children:[o.jsx(Ur,{size:28}),o.jsx("strong",{children:X("editor.preview")}),o.jsx("span",{children:X("editor.previewHint")})]})),n==="diagnostics"&&s==="log"&&o.jsx(Ji,{lines:L?L.split(`
|
|
19
|
+
`):[],empty:X(S?"editor.compiling":"editor.noLog")}),n==="diagnostics"&&s==="warnings"&&(v?o.jsx(Ya,{tone:"warning",diagnostics:v.warnings,files:ue,empty:X("editor.noWarnings"),onJump:(R,he,K)=>{H==="pdf-only"&&se("editor-pdf"),Ee(R,he,K)}}):o.jsx(Ji,{tone:"warning",lines:q.warnings,empty:X("editor.noWarnings")})),n==="diagnostics"&&s==="errors"&&(v?o.jsx(Ya,{tone:"error",diagnostics:v.errors,files:ue,empty:X("editor.noErrors"),onJump:(R,he,K)=>{H==="pdf-only"&&se("editor-pdf"),Ee(R,he,K)}}):o.jsx(Ji,{tone:"error",lines:q.errors,empty:X("editor.noErrors")})),n==="diagnostics"&&s==="artifacts"&&o.jsx(Ex,{projectId:t,mainFile:e,artifacts:A,preview:x,loading:P,onView:R=>{ve(R)}}),n==="diagnostics"&&s==="clean"&&o.jsx(Dx,{mainFile:e,disabled:C||!M||S,cleaning:j,onCleanCache:()=>ke("cache"),onCleanArtifacts:()=>ke("artifacts")})]})]})})]})}function Ax(t){return!Number.isFinite(t)||t<0?"":t<1024?`${Math.round(t)} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Xa({kind:t,onEdit:e,onDelete:n,disabled:s=!1}){const{t:r}=Ye(),i=u.useRef(!1);return o.jsx("span",{className:"comment-actions-menu",onClick:l=>l.stopPropagation(),children:o.jsxs(Pf,{modal:!1,children:[o.jsx(If,{asChild:!0,children:o.jsx("button",{type:"button",disabled:s,className:"comment-actions-menu-trigger","aria-label":r(t==="comment"?"editor.commentActions":"editor.replyActions"),children:o.jsx(_f,{size:16,"aria-hidden":!0})})}),o.jsx(zf,{children:o.jsxs(Uf,{className:"comment-actions-menu-content",align:"end",sideOffset:4,collisionPadding:8,onCloseAutoFocus:l=>{i.current&&l.preventDefault(),i.current=!1},children:[o.jsxs(Xl,{onSelect:()=>{i.current=!0,e()},children:[o.jsx(Rf,{size:13,"aria-hidden":!0}),r(t==="comment"?"editor.editComment":"editor.editReply")]}),o.jsxs(Xl,{className:"danger-text",onSelect:()=>{i.current=!0,n()},children:[o.jsx(Tn,{size:13,"aria-hidden":!0}),r(t==="comment"?"editor.deleteComment":"editor.deleteReply")]})]})})]})})}function Nx(t,e){const n=t.slice(0,e),s=/(^|[^\p{L}\p{N}_.-])@([\p{L}\p{N}_.-]*)$/u.exec(n);return s?{start:e-s[2].length-1,end:e,query:s[2]}:null}function ed({projectId:t,value:e,onChange:n,onKeyDown:s,onFocus:r,...i}){const{t:l}=Ye(),a=u.useRef(null),[c,h]=u.useState(null),[d,f]=u.useState(!1),[m,g]=u.useState(null),[w,S]=u.useState(0),L=u.useMemo(()=>{if(!m||!c)return[];const j=m.query.toLocaleLowerCase();return(j?c.filter(M=>M.username.toLocaleLowerCase().includes(j)||M.displayName.toLocaleLowerCase().includes(j)):c).slice(0,8)},[c,m]),v=!!(m&&L.length),q=async()=>{if(!(c||d)){f(!0);try{const j=await pe(`/api/projects/${t}/mention-candidates`);h(j.users)}catch{h([])}finally{f(!1)}}},A=(j,C)=>{const M=Nx(j,C);g(M),S(0),M&&q()},x=j=>{if(!m)return;const C=`@${j.username} `,M=`${e.slice(0,m.start)}${C}${e.slice(m.end)}`,H=m.start+C.length;n(M),g(null),S(0),window.requestAnimationFrame(()=>{a.current?.focus(),a.current?.setSelectionRange(H,H)})},P=j=>{if(!j.nativeEvent.isComposing&&v){if(j.key==="ArrowDown"){j.preventDefault(),S(C=>(C+1)%L.length);return}if(j.key==="ArrowUp"){j.preventDefault(),S(C=>(C-1+L.length)%L.length);return}if(j.key==="Enter"&&!j.ctrlKey&&!j.metaKey&&!j.shiftKey){j.preventDefault(),x(L[w]??L[0]);return}if(j.key==="Escape"){g(null);return}}s?.(j)};return o.jsxs("span",{className:"mention-textarea",children:[o.jsx("textarea",{...i,ref:a,value:e,onFocus:j=>{r?.(j),A(e,j.currentTarget.selectionStart??e.length)},onClick:j=>A(e,j.currentTarget.selectionStart??e.length),onChange:j=>{const C=j.currentTarget.value;n(C),A(C,j.currentTarget.selectionStart??C.length)},onKeyDown:P}),v&&o.jsx("span",{className:"mention-menu",role:"listbox","aria-label":l("editor.mentionUsers"),children:L.map((j,C)=>o.jsxs("button",{type:"button",role:"option","aria-selected":C===w,className:C===w?"active":"",onMouseDown:M=>M.preventDefault(),onClick:()=>x(j),children:[o.jsx(Ms,{"aria-hidden":!0,size:13}),o.jsxs("span",{children:[o.jsx("strong",{children:j.displayName}),o.jsxs("small",{children:["(",j.username,")"]})]})]},j.id))})]})}function Mx({projectId:t,value:e,onChange:n,onSubmit:s,onCancel:r,pending:i=!1,error:l="",label:a,editing:c=!1,disabled:h=!1,autoFocus:d=!0}){const{t:f}=Ye(),m=u.useId(),g=i||h,w=S=>{S?.preventDefault(),!(g||!e.trim())&&s()};return o.jsxs("form",{className:`comment-reply-form${c?" comment-edit-form":""}`,"aria-busy":i,onSubmit:S=>{w(S)},onClick:S=>S.stopPropagation(),children:[o.jsx(ed,{projectId:t,autoFocus:d,rows:c?4:3,value:e,onChange:n,disabled:g,"aria-label":a,"aria-invalid":!!l,"aria-describedby":l?m:void 0,placeholder:c?void 0:f("editor.replyPlaceholder"),onKeyDown:S=>{!(S.ctrlKey||S.metaKey)||S.key!=="Enter"||S.nativeEvent.isComposing||(S.preventDefault(),S.stopPropagation(),w())}}),l&&o.jsx("p",{id:m,className:"comment-form-error",role:"alert",children:l}),o.jsxs("div",{children:[o.jsx("button",{type:"button",disabled:g,onClick:r,children:f("common.cancel")}),o.jsxs("button",{className:"primary",type:"submit",disabled:g||!e.trim(),children:[i?o.jsx(lt,{className:"spin","aria-hidden":!0,size:13}):c?o.jsx(hm,{"aria-hidden":!0,size:13}):o.jsx(fm,{"aria-hidden":!0,size:13}),f(i?c?"editor.commentSaving":"editor.commentSending":c?"editor.saveChanges":"editor.sendReply")]})]})]})}const Za=2;function Ox(t,e={}){const n=t.slice(0,Math.max(0,t.length-Za)),s=!!(e.activeDraft||e.targetReplyId&&t.some(l=>l.id===e.targetReplyId)||n.some(l=>e.unreadReplyMentionIds?.has(l.id)||e.highlightReplyParticipants&&e.selectedParticipantIds?.has(l.authorId))),r=s||(e.expansion??!!e.current),i=r?0:n.length;return{replies:i?t.slice(-Za):t,hiddenCount:i,expanded:r,canToggle:n.length>0&&!s}}function Qa(t){const e=/(^|\s)(@[\p{L}\p{N}_.-]+)/gu,n=[];let s=0;for(const r of t.matchAll(e)){const i=r.index??0,l=r[1],a=r[2],c=i+l.length;c>s&&n.push(t.slice(s,c)),n.push(o.jsx("span",{className:"comment-inline-mention",children:a},`${c}:${a}`)),s=c+a.length}return n.length?(s<t.length&&n.push(t.slice(s)),n):t}function Fx({projectId:t,comment:e,draftStore:n,currentUserId:s,unreadCommentMentionId:r,unreadReplyMentionIds:i,highlightedComment:l,highlightedReplyId:a,currentComment:c,showFilePath:h,onMarkMentionRead:d,onFocus:f,onActivate:m,onToggle:g,onReply:w,onEdit:S,onDelete:L,onEditReply:v,onDeleteReply:q,selectedParticipantIds:A,highlightReplyParticipants:x,replyExpansion:P,onReplyExpansionChange:j}){const{t:C}=Ye(),[M,H]=u.useState(!1),J=u.useCallback(O=>n.subscribe(e.id,O),[n,e.id]),le=u.useCallback(()=>n.getThread(e.id),[n,e.id]),B=u.useSyncExternalStore(J,le,le),se=B.reply,W=B["edit-comment"],te=u.useId(),Y=Ox(e.replies,{expansion:P,current:c,targetReplyId:a,unreadReplyMentionIds:i,selectedParticipantIds:A,highlightReplyParticipants:x,activeDraft:!!(se?.open||se?.pending||e.authorId===s&&W?.open||e.replies.some(O=>O.authorId===s&&B[`edit-reply:${O.id}`]?.open))}),Ce=n.isPending(e.id),[ae,Z]=u.useState(null),[$,ue]=u.useState(!1),[Ee,ke]=u.useState(null),ve=(O,z="")=>{m(),j(!0),Z(O),n.open(e.id,O,z)},X=(O,z,De)=>{const U=B[O];return U?.open?o.jsx(Mx,{projectId:t,editing:O!=="reply",label:z,value:U.content,pending:U.pending,error:U.error,disabled:Ce||M,autoFocus:ae===O,onChange:R=>n.change(e.id,O,R),onSubmit:()=>n.submit(e.id,O,De,C("editor.commentSubmitFailed")),onCancel:()=>n.discard(e.id,O)},O):null},I=e.authorUsername,fe=O=>new Date(O).toLocaleString(Rs.resolvedLanguage),ye=async(O,z)=>{z.stopPropagation(),j(!0),await d(O)};return o.jsxs(o.Fragment,{children:[o.jsxs("article",{"data-comment-id":e.id,className:`comment-thread${e.resolved?" resolved":""}${e.orphaned?" orphaned":""}${l?" mention-target":""}${c?" review-current":""}`,onFocusCapture:m,onClick:()=>{window.getSelection()?.toString()||f()},children:[o.jsxs("header",{className:"comment-header",children:[o.jsxs("span",{className:`comment-author${A?.has(e.authorId)?" participant-match":""}`,children:[o.jsx("strong",{children:e.authorDisplayName??I??C("editor.deletedUser")}),I&&o.jsxs("small",{children:["@",I]})]}),o.jsxs("span",{className:"comment-header-actions",children:[o.jsxs("span",{className:"comment-times",children:[o.jsx("time",{dateTime:e.createdAt,title:new Date(e.createdAt).toISOString(),children:fe(e.createdAt)}),e.editedAt&&o.jsx("small",{children:C("editor.editedAt",{time:fe(e.editedAt)})})]}),e.authorId===s&&!W?.open&&o.jsx(Xa,{kind:"comment",disabled:Ce||M,onEdit:()=>ve("edit-comment",e.content),onDelete:()=>ue(!0)})]})]}),o.jsx("div",{className:"comment-location",children:e.orphaned?C("editor.orphaned"):h?C("editor.commentLocation",{path:e.filePath,line:e.startLine}):C("editor.line",{line:e.startLine})}),e.selectedText&&o.jsx("blockquote",{className:"comment-selected-text",children:e.selectedText}),W?.open&&e.authorId===s?X("edit-comment",C("editor.editComment"),S):o.jsx("p",{className:"comment-content",children:Qa(e.content)}),r&&o.jsxs("div",{className:"comment-mention",children:[o.jsxs("span",{children:[o.jsx(Ms,{"aria-hidden":!0,size:12}),C("editor.mentionedYou")]}),o.jsx("button",{type:"button",onClick:O=>{ye(r,O)},children:C("editor.markMentionRead")})]}),e.replies.length>0&&o.jsxs("div",{className:"comment-replies",children:[Y.canToggle&&o.jsxs("button",{type:"button",className:"comment-replies-toggle","aria-expanded":Y.expanded,"aria-controls":te,onClick:O=>{O.stopPropagation(),j(!Y.expanded)},children:[Y.expanded?o.jsx(qf,{size:13,"aria-hidden":!0}):o.jsx(Hs,{size:13,"aria-hidden":!0}),Y.expanded?C("editor.hideEarlierReplies"):C("editor.showEarlierReplies",{count:Y.hiddenCount})]}),o.jsx("div",{className:"comment-replies-list",id:te,children:Y.replies.map(O=>{const z=i?.get(O.id),De=`edit-reply:${O.id}`,U=B[De]?.open&&O.authorId===s;return o.jsxs("div",{"data-comment-reply-id":O.id,className:`comment-reply${a===O.id?" mention-target":""}`,children:[o.jsxs("header",{children:[o.jsxs("span",{className:`comment-author${x&&A?.has(O.authorId)?" participant-match":""}`,children:[o.jsx("strong",{children:O.authorDisplayName??O.authorUsername??C("editor.deletedUser")}),O.authorUsername&&o.jsxs("small",{children:["@",O.authorUsername]})]}),o.jsxs("span",{className:"comment-header-actions",children:[o.jsxs("span",{className:"comment-times",children:[o.jsx("time",{dateTime:O.createdAt,title:new Date(O.createdAt).toISOString(),children:fe(O.createdAt)}),O.editedAt&&o.jsx("small",{children:C("editor.editedAt",{time:fe(O.editedAt)})})]}),O.authorId===s&&!U&&o.jsx(Xa,{kind:"reply",disabled:Ce||M,onEdit:()=>ve(De,O.content),onDelete:()=>ke(O.id)})]})]}),U?X(De,C("editor.editReply"),R=>v(O.id,R)):o.jsx("p",{className:"comment-content",children:Qa(O.content)}),z&&o.jsxs("div",{className:"comment-mention",children:[o.jsxs("span",{children:[o.jsx(Ms,{"aria-hidden":!0,size:12}),C("editor.mentionedYou")]}),o.jsx("button",{type:"button",onClick:R=>{ye(z,R)},children:C("editor.markMentionRead")})]})]},O.id)})})]}),e.resolved&&e.resolvedAt&&o.jsxs("div",{className:"comment-resolution",children:[o.jsx(Zi,{size:12,"aria-hidden":!0}),o.jsxs("span",{children:[o.jsx(wf,{i18nKey:"editor.resolvedBy",values:{user:e.resolvedByDisplayName??e.resolvedByUsername??C("editor.deletedUser")},components:{user:o.jsx("strong",{className:"comment-resolution-user"})}}),e.resolvedByUsername&&o.jsxs("small",{className:"comment-resolution-user",children:[" @",e.resolvedByUsername]})," · ",o.jsx("time",{dateTime:e.resolvedAt,children:fe(e.resolvedAt)})]})]}),o.jsxs("div",{className:"comment-actions",children:[o.jsxs("button",{className:"resolve",disabled:M||Ce,"aria-busy":M,onClick:O=>{O.stopPropagation(),!M&&(H(!0),g().finally(()=>H(!1)))},children:[e.resolved?o.jsx(dm,{size:13}):o.jsx(Zi,{size:13}),e.resolved?C("editor.reopen"):C("editor.resolve")]}),o.jsxs("button",{className:"reply-action",disabled:Ce||M,onClick:O=>{O.stopPropagation(),se?.open?n.hide(e.id,"reply"):ve("reply")},children:[o.jsx(um,{size:13}),C(se?.content&&!se.open?"editor.resumeReply":"editor.reply")]})]}),X("reply",C("editor.reply"),w)]}),o.jsx(Ns,{open:$,title:C("editor.deleteCommentTitle"),description:C("editor.deleteCommentDescription",{count:e.replies.length}),confirmLabel:C("common.delete"),danger:!0,onCancel:()=>ue(!1),onConfirm:()=>{L().then(O=>{O&&ue(!1)})}}),o.jsx(Ns,{open:!!Ee,title:C("editor.deleteReplyTitle"),description:C("editor.deleteReplyDescription"),confirmLabel:C("common.delete"),danger:!0,onCancel:()=>ke(null),onConfirm:()=>{Ee&&q(Ee).then(O=>{O&&ke(null)})}})]})}function $x({open:t,onOpenChange:e,project:n,projectId:s}){const{t:r}=Ye(),[i,l]=u.useState([]),[a,c]=u.useState([]),[h,d]=u.useState(""),[f,m]=u.useState("read"),[g,w]=u.useState(null),[S,L]=u.useState(""),v=n.permission==="owner",q=async()=>{try{const[C,M]=await Promise.all([pe(`/api/projects/${s}/members`),pe("/api/users")]);l(C.members),c(M.users.filter(H=>H.id!==n.ownerId))}catch(C){L(we(C))}};u.useEffect(()=>{t&&q()},[t,s]);const A=async()=>{if(h)try{await pe(`/api/projects/${s}/members/${h}`,{method:"PUT",body:JSON.stringify({permission:f})}),d(""),m("read"),await q()}catch(C){L(we(C))}},x=async(C,M)=>{try{await pe(`/api/projects/${s}/members/${C.id}`,{method:"PUT",body:JSON.stringify({permission:M})}),await q()}catch(H){L(we(H))}},P=async()=>{if(g)try{await pe(`/api/projects/${s}/members/${g.id}`,{method:"DELETE"}),w(null),await q()}catch(C){L(we(C))}},j=a.filter(C=>!i.some(M=>M.id===C.id));return o.jsxs(o.Fragment,{children:[o.jsx(rn,{open:t,wide:!0,title:r("projectSettings.share"),description:r("projectSettings.shareDescription"),onOpenChange:e,footer:o.jsx("button",{onClick:()=>e(!1),children:r("common.close")}),children:o.jsxs("div",{className:"share-dialog",children:[S&&o.jsx("p",{className:"error",children:S}),o.jsxs("div",{className:"share-owner",children:[o.jsx(kr,{size:17}),o.jsxs("span",{children:[o.jsx("small",{children:r("projects.owner")}),o.jsx("strong",{children:n.ownerDisplayName??n.ownerUsername})]})]}),v&&o.jsxs("div",{className:"share-add",children:[o.jsxs("label",{className:"form-field",children:[r("common.user"),o.jsxs("select",{value:h,onChange:C=>d(C.target.value),children:[o.jsx("option",{value:"",children:r("projectSettings.chooseUser")}),j.map(C=>o.jsx("option",{value:C.id,children:C.displayName??C.username},C.id))]})]}),o.jsxs("label",{className:"form-field",children:[r("common.permission"),o.jsxs("select",{value:f,onChange:C=>m(C.target.value),children:[o.jsx("option",{value:"read",children:r("common.readOnly")}),o.jsx("option",{value:"edit",children:r("common.readWrite")})]})]}),o.jsxs("button",{className:"primary icon-button",disabled:!h,onClick:()=>{A()},children:[o.jsx(Bf,{size:15}),r("projectSettings.addMember")]})]}),o.jsxs("div",{className:"shared-members-heading",children:[o.jsx("strong",{children:r("projectSettings.members")}),o.jsx("span",{children:i.length})]}),o.jsxs("div",{className:"shared-members",children:[i.map(C=>o.jsxs("div",{className:"shared-member",children:[o.jsxs("span",{className:"member-identity",children:[o.jsx("span",{className:"member-avatar",children:(C.displayName??C.username).slice(0,1).toLocaleUpperCase()}),o.jsxs("span",{children:[o.jsx("strong",{children:C.displayName??C.username}),o.jsxs("small",{children:["@",C.username]})]})]}),o.jsxs("span",{className:"member-controls",children:[o.jsxs("select",{"aria-label":r("common.permission"),disabled:!v,value:C.permission,onChange:M=>{x(C,M.target.value)},children:[o.jsx("option",{value:"read",children:r("common.readOnly")}),o.jsx("option",{value:"edit",children:r("common.readWrite")})]}),v&&o.jsx("button",{className:"icon-only danger-text",title:r("common.remove"),"aria-label":r("common.remove"),onClick:()=>w(C),children:o.jsx(Tn,{size:15})})]})]},C.id)),i.length===0&&o.jsxs("div",{className:"share-empty",children:[o.jsx(kr,{size:24}),o.jsx("span",{children:r("projectSettings.noMembers")})]})]})]})}),o.jsx(Ns,{open:!!g,title:r("projectSettings.removeTitle"),description:r("projectSettings.removeDescription",{username:g?.username??""}),confirmLabel:r("common.remove"),danger:!0,onCancel:()=>w(null),onConfirm:()=>{P()}})]})}const Px=u.lazy(()=>Lt(()=>import("./CitationLibraryDialog-G2kKkA2f.js"),__vite__mapDeps([12,2,1,3,7,4,13,5,14,15,16]),import.meta.url).then(t=>({default:t.CitationLibraryDialog}))),Ix=u.lazy(()=>Lt(()=>import("./GitDialog-BEtLh2S_.js"),__vite__mapDeps([17,2,1,3,4,18,19,20,14,21,5,6,7,8]),import.meta.url).then(t=>({default:t.GitDialog}))),zx=u.lazy(()=>Lt(()=>import("./HistoryDialog-BwxDdj-j.js"),__vite__mapDeps([22,2,1,3,23,24,4,25,20,14,21,5,6,7,8]),import.meta.url).then(t=>({default:t.HistoryDialog}))),Ux=u.lazy(()=>Lt(()=>import("./SelectionHistoryDialog-p8L2n4RS.js"),__vite__mapDeps([26,2,1,3,23,25,4,5,6,7,8]),import.meta.url).then(t=>({default:t.SelectionHistoryDialog}))),Bx=u.lazy(()=>Lt(()=>import("./QuickOpenDialog-C758pouQ.js"),__vite__mapDeps([27,2,1,3,16,4,5]),import.meta.url).then(t=>({default:t.QuickOpenDialog})));function qx({user:t,project:e,projectId:n,activeFile:s,content:r,maxCitationBibtexBytes:i,files:l,directoryEntries:a,readOnly:c,resourcePreview:h,resourcePreviewLoading:d,setResourcePreview:f,setResourcePreviewLoading:m,uploadConflict:g,setUploadConflict:w,dismissUploadFeedback:S,uploadFiles:L,cleanMode:v,setCleanMode:q,cleanCompile:A,newFileOpen:x,setNewFileOpen:P,newFilePath:j,setNewFilePath:C,newFolderOpen:M,setNewFolderOpen:H,newFolderName:J,setNewFolderName:le,selectedFolder:B,fileDialogError:se,setFileDialogError:W,createFile:te,createFolder:Y,moveEntry:Ce,setMoveEntry:ae,moveName:Z,setMoveName:$,moveDestination:ue,setMoveDestination:Ee,movePath:ke,deleteEntry:ve,setDeleteEntry:X,deleteActiveSessions:I,removePath:fe,commentOpen:ye,closeComment:O,commentSelection:z,commentText:De,setCommentText:U,commentSubmitting:R,commentError:he,addComment:K,cancelComment:Ne,commentDraftRestored:Ve,commentDraftCanRetarget:Me,useCurrentCommentSelection:Fe,shareOpen:ne,setShareOpen:be,citationLibraryOpen:_,setCitationLibraryOpen:ge,insertCitationAtCursor:xe,quickOpen:Le,setQuickOpen:Ue,openFile:Ge,selectionHistoryTarget:Re,closeSelectionHistory:re,historyOpen:F,setHistoryOpen:oe,gitOpen:Oe,setGitOpen:Be,save:N,permissionDowngrade:G,permissionDowngradeBusy:Te,dismissPermissionDowngrade:Q,discardPermissionDraft:yt}){const{t:k}=Ye();return o.jsxs(o.Fragment,{children:[G&&o.jsx(rn,{open:!0,title:k("editor.collaboration.permissionDowngradeTitle"),description:G.localDraftReady&&G.otherTabDraft?k("editor.collaboration.permissionDowngradeMultipleDrafts"):G.otherTabDraft?k("editor.collaboration.permissionDowngradeOtherTab"):G.localDraftReady?k("editor.collaboration.permissionDowngradeDescription",{previous:k("common.readWrite")}):k("editor.collaboration.permissionDowngradeNoDraft"),onOpenChange:y=>{!y&&!Te&&Q()},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",disabled:Te,onClick:Q,children:G.localDraftReady?k("editor.collaboration.permissionDowngradeKeep"):k("common.close")}),!G.otherTabDraft&&o.jsxs("button",{type:"button",className:"danger",disabled:Te,onClick:()=>{yt()},children:[Te?o.jsx(lt,{className:"spin",size:14}):G.localDraftReady?o.jsx(Tn,{size:14}):o.jsx(Wf,{size:14}),G.localDraftReady?k("editor.collaboration.permissionDowngradeDiscard"):k("editor.collaboration.permissionDowngradeReload")]})]}),children:o.jsx("div",{})}),o.jsxs(rn,{open:!!h,extraWide:h?.kind==="image"||h?.kind==="pdf"||h?.kind==="text",title:h?.path??"",description:h?.kind==="large"?k("editor.resourceTooLarge",{size:Wx(h.size),limit:`${wo/1024/1024} MB`}):k(`editor.resourcePreview.${h?.kind??"text"}`),onOpenChange:y=>{y||(f(null),m(!1))},footer:h&&o.jsxs("a",{className:"primary resource-download",href:`${h.url}&download=1`,download:!0,children:[o.jsx(Sr,{size:14}),k("editor.downloadResource")]}),children:[h?.kind==="large"&&o.jsxs("div",{className:"resource-preview-message",children:[o.jsx(Yi,{size:34}),o.jsx("strong",{children:k("editor.resourceTooLargeTitle")}),o.jsx("span",{children:k("editor.resourceTooLargeDescription")})]}),h?.kind==="unsupported"&&o.jsxs("div",{className:"resource-preview-message",children:[o.jsx(Yi,{size:34}),o.jsx("strong",{children:k("editor.resourceUnsupportedTitle")}),o.jsx("span",{children:k("editor.resourceUnsupportedDescription")})]}),h?.kind==="image"&&o.jsx("div",{className:"resource-image-wrap",children:o.jsx("img",{className:"resource-image",src:h.url,alt:h.path})}),h?.kind==="pdf"&&o.jsx("iframe",{className:"resource-pdf",src:h.url,title:h.path}),h?.kind==="text"&&(d?o.jsxs("div",{className:"resource-preview-message",children:[o.jsx(lt,{className:"spin",size:24}),o.jsx("span",{children:k("common.loading")})]}):o.jsx("pre",{className:"resource-text",children:h.content}))]}),o.jsx(Ns,{open:!!g,title:k("editor.uploadOverwriteTitle"),description:k("editor.uploadOverwriteDescription",{files:g?.collisions.join(", ")??""}),confirmLabel:k("editor.uploadOverwrite"),danger:!0,onCancel:()=>{w(null),S()},onConfirm:()=>{const y=g;w(null),y&&L(y.files,new Set(y.collisions),y.directory)}}),o.jsx(Ns,{open:!!v,title:k(v==="cache"?"editor.cleanCacheConfirmTitle":"editor.cleanArtifactsConfirmTitle"),description:k(v==="cache"?"editor.cleanCacheConfirmDescription":"editor.cleanArtifactsConfirmDescription"),confirmLabel:k("editor.cleanConfirm"),danger:v==="artifacts",onCancel:()=>q(null),onConfirm:()=>{const y=v;q(null),y&&A(y)}}),o.jsx(rn,{open:x,title:k("editor.newFile"),description:k("editor.newFileDescription"),onOpenChange:y=>{P(y),y||W("")},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>P(!1),children:k("common.cancel")}),o.jsx("button",{className:"primary",onClick:()=>{te()},children:k("common.create")})]}),children:o.jsxs(o.Fragment,{children:[se&&o.jsx("p",{className:"error dialog-error",children:se}),o.jsxs("label",{className:"form-field",children:[k("editor.filePath"),o.jsx("input",{autoFocus:!0,value:j,onChange:y=>C(y.target.value),onKeyDown:y=>{y.key==="Enter"&&!y.nativeEvent.isComposing&&(y.preventDefault(),te())}})]})]})}),o.jsx(rn,{open:M,title:k("editor.newFolder"),description:k("editor.folderDestination",{folder:B||k("editor.projectRoot")}),onOpenChange:y=>{H(y),y||W("")},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>H(!1),children:k("common.cancel")}),o.jsx("button",{className:"primary",onClick:()=>{Y()},children:k("common.create")})]}),children:o.jsxs(o.Fragment,{children:[se&&o.jsx("p",{className:"error dialog-error",children:se}),o.jsxs("label",{className:"form-field",children:[k("editor.folderName"),o.jsx("input",{autoFocus:!0,value:J,onChange:y=>le(y.target.value),onKeyDown:y=>{y.key==="Enter"&&Y()}})]})]})}),o.jsx(rn,{open:!!Ce,title:k("editor.moveTitle",{name:Ce?.path.split("/").at(-1)??""}),description:k("editor.moveDescription"),onOpenChange:y=>{y||(ae(null),$(""),W(""))},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>ae(null),children:k("common.cancel")}),o.jsx("button",{className:"primary",disabled:!Z.trim(),onClick:()=>{ke()},children:k("editor.moveApply")})]}),children:o.jsxs(o.Fragment,{children:[se&&o.jsx("p",{className:"error dialog-error",children:se}),o.jsxs("label",{className:"form-field",children:[k("editor.pathName"),o.jsx("input",{autoFocus:!0,value:Z,onChange:y=>$(y.target.value),onKeyDown:y=>{y.key==="Enter"&&ke()}})]}),o.jsxs("label",{className:"form-field",children:[k("editor.destinationFolder"),o.jsxs("select",{value:ue,onChange:y=>Ee(y.target.value),children:[o.jsx("option",{value:"",children:k("editor.projectRoot")}),a.filter(y=>Ce?.type!=="directory"||y.path!==Ce.path&&!y.path.startsWith(`${Ce.path}/`)).map(y=>o.jsx("option",{value:y.path,children:y.path},y.path))]})]})]})}),o.jsx(rn,{open:!!ve,title:k("editor.deletePathTitle",{name:ve?.path.split("/").at(-1)??""}),description:I.length?k("editor.deletePathActiveDescription",{path:ve?.path??"",users:[...new Set(I.map(y=>y.name))].join(", ")}):k("editor.deletePathDescription",{path:ve?.path??""}),onOpenChange:y=>{y||(X(null),W(""))},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{onClick:()=>X(null),children:k("common.cancel")}),o.jsx("button",{className:"danger",onClick:()=>{fe()},children:k("common.delete")})]}),children:o.jsxs(o.Fragment,{children:[se&&o.jsx("p",{className:"error dialog-error",children:se}),I.length>0&&o.jsxs("p",{className:"warning",children:[o.jsx(Dt,{size:15}),k("editor.deletePathWillClose")]})]})}),o.jsxs(rn,{open:ye,draggable:!0,title:k("editor.addComment"),description:z.selectedText?k("editor.commentDescription",{count:z.endOffset-z.startOffset}):k("editor.pointComment"),onOpenChange:y=>{y||O()},footer:o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",disabled:R,onClick:Ne,children:k("common.cancel")}),o.jsxs("button",{type:"button",className:"primary","aria-busy":R,disabled:R||!De.trim(),onClick:()=>{K()},children:[R&&o.jsx(lt,{className:"spin",size:14}),k(R?"editor.commentSending":"editor.addComment")]})]}),children:[he&&o.jsx("p",{className:"error dialog-error",children:he}),Ve&&o.jsxs("p",{className:"comment-draft-restored",children:[o.jsx("span",{children:k("editor.commentDraftRestored")}),Me&&o.jsx("button",{type:"button",disabled:R,onClick:Fe,children:k("editor.commentDraftUseSelection")})]}),o.jsxs("label",{className:"form-field",children:[k("editor.commentContent"),o.jsx(ed,{projectId:n,autoFocus:!0,rows:5,disabled:R,value:De,placeholder:k("editor.commentPlaceholder"),onChange:U,onKeyDown:y=>{(y.ctrlKey||y.metaKey)&&y.key==="Enter"&&!y.nativeEvent.isComposing&&(y.preventDefault(),y.stopPropagation(),K())}})]}),z.selectedText&&o.jsx("blockquote",{className:"selection-preview",children:z.selectedText})]}),o.jsx($x,{open:ne,onOpenChange:be,project:e,projectId:n}),_&&o.jsx(sc,{title:k("citationLibrary.title"),onClose:()=>ge(!1),children:o.jsx(Px,{open:!0,onOpenChange:ge,currentFile:s,currentSource:r,readOnly:c,currentUserId:t.id,maxBibtexBytes:i,onInsert:xe})}),Le&&o.jsx(u.Suspense,{fallback:null,children:o.jsx(Bx,{open:!0,files:l,onOpenChange:Ue,onOpenFile:y=>{const T=l.find(V=>V.path===y);T&&Ge(T)}})}),Re&&o.jsx(u.Suspense,{fallback:null,children:o.jsx(Ux,{open:!0,onOpenChange:y=>{y||re()},project:e,filePath:Re.filePath,selection:Re.selection,currentSource:Re.source})}),F&&o.jsx(u.Suspense,{fallback:null,children:o.jsx(zx,{open:!0,onOpenChange:oe,project:e,onBeforeMutation:e.permission==="read"?async()=>!0:N})}),e.ownerId===t.id&&Oe&&o.jsx(u.Suspense,{fallback:null,children:o.jsx(Ix,{open:!0,onOpenChange:Be,project:e,onBeforeMutation:N})})]})}function Wx(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}function Vx({participants:t,selectedIds:e,topLevelOnly:n,onToggle:s,onClear:r,onTopLevelOnlyChange:i}){const{t:l}=Ye(),[a,c]=u.useState(!1),h=u.useRef(null),d=e.size>0,f=t.find(w=>e.has(w.authorId)),m=w=>w.authorDisplayName??w.authorUsername??l("editor.deletedUser"),g=d?f?e.size===1?m(f):l("editor.commentParticipantsSelected",{name:m(f),count:e.size-1}):l("editor.commentParticipantsCount",{count:e.size}):l("editor.commentParticipantsAll");return o.jsxs("div",{className:"comment-participant-filter",children:[o.jsxs("div",{className:`comment-participants-trigger-group${d?" active":""}`,children:[o.jsxs(Lf,{open:a,onOpenChange:c,children:[o.jsx(Af,{asChild:!0,children:o.jsxs("button",{type:"button",className:"comment-participants-toggle","aria-label":`${l("editor.commentParticipants")}: ${g}`,children:[o.jsx(kr,{size:13,"aria-hidden":!0}),o.jsx("span",{className:"comment-participants-summary",children:d&&f?m(f):g}),d&&f&&e.size>1&&o.jsxs("span",{className:"comment-participants-extra-count",children:["+",e.size-1]}),o.jsx(Hs,{size:12,"aria-hidden":!0,className:a?"expanded":""})]})}),o.jsx(Nf,{children:o.jsxs(Mf,{ref:h,className:"comment-participants-popover",side:"bottom",align:"end",sideOffset:6,collisionPadding:10,"aria-label":l("editor.commentParticipants"),onOpenAutoFocus:w=>{w.preventDefault();const S=h.current?.querySelector('input[type="checkbox"]:not(:disabled)');S?S.focus():h.current?.focus()},children:[o.jsxs("div",{className:"comment-participants-heading",children:[o.jsx(Of,{children:l("editor.commentParticipants")}),d&&o.jsx("button",{type:"button",onClick:r,children:l("editor.commentParticipantsClear")})]}),o.jsxs("div",{className:"comment-participants-list",children:[t.map(w=>{const S=m(w),L=e.has(w.authorId);return o.jsxs("label",{className:`comment-participant-option${L?" selected":""}`,children:[o.jsx("input",{type:"checkbox",checked:L,onChange:()=>s(w.authorId)}),o.jsx("span",{className:"comment-participant-avatar","aria-hidden":!0,children:Array.from(S.trim())[0]?.toLocaleUpperCase()??"?"}),o.jsxs("span",{className:"comment-participant-identity",children:[o.jsx("strong",{children:S}),w.authorUsername&&o.jsxs("small",{children:["@",w.authorUsername]})]})]},w.authorId??"deleted")}),t.length===0&&o.jsx("p",{className:"comment-participants-empty",children:l("editor.commentNoParticipants")})]}),o.jsxs("label",{className:"comment-participants-root-only",children:[o.jsx("input",{type:"checkbox",checked:n,disabled:!d,onChange:w=>i(w.target.checked)}),l("editor.commentTopLevelOnly")]})]})})]}),d&&o.jsx("button",{type:"button",className:"comment-participants-clear","aria-label":l("editor.commentParticipantsClear"),onClick:r,children:o.jsx(cn,{size:12,"aria-hidden":!0})})]}),d&&n&&o.jsx("span",{className:"comment-participants-scope",children:l("editor.commentTopLevelOnly")})]})}const td=280;function Hx(t,e,n,s,r){const i=e.map(c=>({comment:c,exitAt:null})),l=new Set(e.map(c=>c.id)),a=new Map(n.map(c=>[c.id,c]));return t.forEach((c,h)=>{const d=a.get(c.comment.id);l.has(c.comment.id)||!d||vo(d,s)||i.splice(Math.min(h,i.length),0,{comment:d,exitAt:c.exitAt??r+td+50})}),i}function Kx(t,e,n,s){const[r,i]=u.useState(()=>({contextKey:s,visible:t,comments:e,entries:t.map(a=>({comment:a,exitAt:null}))}));(r.contextKey!==s||r.visible!==t||r.comments!==e)&&i({contextKey:s,visible:t,comments:e,entries:r.contextKey!==s?t.map(a=>({comment:a,exitAt:null})):Hx(r.entries,t,e,n,Date.now())});const l=u.useCallback(a=>{i(c=>({...c,entries:c.entries.filter(h=>h.comment.id!==a||h.exitAt===null)}))},[]);return u.useEffect(()=>{const a=r.entries.flatMap(h=>h.exitAt===null?[]:[h.exitAt]);if(!a.length)return;const c=window.setTimeout(()=>{const h=Date.now();i(d=>({...d,entries:d.entries.filter(f=>f.exitAt===null||f.exitAt>h)}))},Math.max(0,Math.min(...a)-Date.now()));return()=>window.clearTimeout(c)},[r.entries]),{entries:r.entries,finishExit:l}}const Gx=u.lazy(()=>Lt(()=>import("./ProjectSettings-Mf8zDGRu.js"),__vite__mapDeps([28,2,1,3,19,4,29,30,8,5,6,7]),import.meta.url).then(t=>({default:t.ProjectSettings})));function Jx({sidePanel:t,onClose:e,project:n,projectId:s,site:r,files:i,currentUserId:l,comments:a,commentDraftStore:c,commentsLoading:h,commentsError:d,onRetryComments:f,unreadMentions:m,activeFile:g,singleCommentId:w,onShowAllComments:S,hasProjectCommentsScope:L,commentScope:v,onCommentScopeChange:q,focusedCommentId:A,commentFocusNonce:x,onMarkMentionRead:P,onMarkAllMentionsRead:j,onClearFocusComment:C,targetCommentId:M,targetReplyId:H,onFocusComment:J,onToggleComment:le,onReplyComment:B,onEditComment:se,onDeleteComment:W,onEditCommentReply:te,onDeleteCommentReply:Y,dictionaryWords:Ce,onDictionaryChange:ae,editorPreferences:Z,onEditorPreferences:$,spellCheckCount:ue,spellCheckUniqueCount:Ee,spellCheckIndex:ke,onSpellCheckNavigate:ve,onProject:X}){const{t:I}=Ye(),fe=!!w,[ye,O]=u.useState("unresolved"),[z,De]=u.useState(!1),[U,R]=u.useState("source"),[he,K]=u.useState(()=>new Set),[Ne,Ve]=u.useState(!0),[Me,Fe]=u.useState(()=>new Map),[ne,be]=u.useState(null),_=u.useRef(new Map(a.map(y=>[y.id,y.resolved]))),ge=u.useMemo(()=>Wm(a),[a]),xe=u.useMemo(()=>{const y={activeFile:g,scope:v,unreadMentions:m,participantIds:he,topLevelOnly:Ne,unreadMentionsOnly:z};return{unresolved:Ni(a,{...y,filter:"unresolved"}).length,resolved:Ni(a,{...y,filter:"resolved"}).length,mentions:Ni(a,{...y,filter:ye,unreadMentionsOnly:!0}).length}},[g,v,a,m,he,Ne,ye,z]),Le=u.useMemo(()=>w?Km(a,w,g):Hm(a,{activeFile:g,scope:v,filter:ye,unreadMentions:m,sort:U,participantIds:he,topLevelOnly:Ne,unreadMentionsOnly:z},[M,A]),[g,w,ye,v,a,A,M,m,U,he,Ne,z]),Ue=A&&Le.some(y=>y.id===A)?A:M&&Le.some(y=>y.id===M)?M:null,Ge=fe?Le[0]?.id??null:ne&&Le.some(y=>y.id===ne)?ne:Ue;u.useEffect(()=>{be(null)},[A,x,M,H,g,v]),u.useEffect(()=>{ne&&!Le.some(y=>y.id===ne)&&be(null)},[ne,Le]);const Re=Xm(Le,Ge),re=JSON.stringify([t,w,v,v==="file"?g:"",ye,U,[...he].sort(),Ne,z]),{entries:F,finishExit:oe}=Kx(Le,a,fe?"unresolved":ye,re);u.useEffect(()=>{const y=a.some(T=>(T.id===A||T.id===M)&&_.current.has(T.id)&&_.current.get(T.id)!==T.resolved);_.current=new Map(a.map(T=>[T.id,T.resolved])),y&&C()},[a,A,M,C]),u.useEffect(()=>{!L&&v!=="file"&&(C(),q("file"))},[v,L,C,q]),u.useEffect(()=>{if(t!=="comments"||ne)return;const y=M&&H?`.comments [data-comment-reply-id="${H}"]`:M?`.comments .comment-thread[data-comment-id="${M}"]`:Ue?`.comments .comment-thread[data-comment-id="${Ue}"]`:"";if(!y)return;const T=document.querySelector(y);if(!T)return;const V=window.requestAnimationFrame(()=>T.scrollIntoView({block:M?"center":"nearest",behavior:"smooth"}));return()=>window.cancelAnimationFrame(V)},[t,ne,Ue,x,M,H,Le]);const Oe=y=>{be(null),J(y)},Be=y=>{const T=Zm(Le,Ge,y);T?Oe(T):C()},N=async y=>{const T=await P(y);if(!T||fe||!z)return T;const V=m.find(Se=>Se.id===y)?.commentId;return V&&(m.some(Se=>Se.id!==y&&Se.commentId===V)||(A===V||M===V)&&C()),T},G=async()=>{await j()&&z&&C()},Te=y=>{y!==v&&(be(null),C(),q(y))},Q=y=>{y!==ye&&(be(null),C(),O(y))},yt=()=>{be(null),C()},k=y=>{yt(),he.size===1&&he.has(y)&&Ve(!0),K(T=>{const V=new Set(T);return V.has(y)?V.delete(y):V.add(y),V})};return t?o.jsxs(o.Fragment,{children:[o.jsx(xo,{className:"resize-handle"}),o.jsx(zr,{id:"context",order:4,defaultSize:20,minSize:15,maxSize:38,children:o.jsxs("aside",{className:"context-panel",children:[t==="comments"&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"drawer-title",children:[o.jsx("strong",{children:I(fe?"editor.currentComment":"editor.sourceComments")}),o.jsxs("span",{className:"drawer-title-actions",children:[!fe&&m.length>0&&o.jsxs("button",{className:"drawer-mention-read-all",type:"button",onClick:()=>{G()},title:I("editor.markAllMentionsRead"),children:[o.jsx(Ms,{"aria-hidden":!0,size:13}),o.jsx("span",{children:I("editor.markAllMentionsRead")})]}),o.jsx("button",{"aria-label":I("common.close"),onClick:e,children:o.jsx(cn,{size:17})})]})]}),fe?o.jsx("div",{className:"comment-current-controls",children:o.jsxs("button",{type:"button",onClick:S,children:[o.jsx(rm,{size:14,"aria-hidden":!0}),I("editor.viewAllComments")]})}):o.jsxs("div",{className:"comment-review-controls",children:[o.jsxs("div",{className:"comment-review-queue-row",children:[L&&o.jsxs("div",{className:"comment-review-group",role:"group","aria-label":I("editor.commentScope"),children:[o.jsx("button",{type:"button",className:v==="file"?"active":"","aria-pressed":v==="file",onClick:()=>Te("file"),children:I("editor.commentScopeFile")}),o.jsx("button",{type:"button",className:v==="project"?"active":"","aria-pressed":v==="project",onClick:()=>Te("project"),children:I("editor.commentScopeProject")})]}),o.jsxs("div",{className:"comment-review-group",role:"group","aria-label":I("editor.commentFilter"),children:[o.jsx("button",{type:"button",className:ye==="unresolved"?"active":"","aria-pressed":ye==="unresolved",onClick:()=>Q("unresolved"),children:I("editor.commentFilterUnresolved",{count:xe.unresolved})}),o.jsx("button",{type:"button",className:ye==="resolved"?"active":"","aria-pressed":ye==="resolved",onClick:()=>Q("resolved"),children:I("editor.commentFilterResolved",{count:xe.resolved})})]}),o.jsxs("div",{className:"comment-review-navigation",children:[o.jsx("button",{type:"button",disabled:Re<=1,"aria-label":I("editor.commentPrevious"),title:I("editor.commentPrevious"),onClick:()=>Be(-1),children:o.jsx(Ff,{size:14})}),o.jsx("output",{"aria-live":"polite",children:I("editor.commentPosition",{current:Re,total:Le.length})}),o.jsx("button",{type:"button",disabled:Le.length===0||Re>0&&Re>=Le.length,"aria-label":I("editor.commentNext"),title:I("editor.commentNext"),onClick:()=>Be(1),children:o.jsx(ko,{size:14})})]})]}),o.jsxs("div",{className:"comment-review-sort-row",children:[o.jsx(Vx,{participants:ge,selectedIds:he,topLevelOnly:Ne,onToggle:k,onClear:()=>{yt(),K(new Set),Ve(!0)},onTopLevelOnlyChange:y=>{yt(),Ve(y)}},`${v}:${v==="file"?g:"project"}`),o.jsxs("button",{type:"button",className:`comment-unread-toggle${z?" active":""}`,"aria-pressed":z,"aria-label":I("editor.commentUnreadMentionsHint"),title:I("editor.commentUnreadMentionsHint"),onClick:()=>{yt(),De(y=>!y)},children:[o.jsx(Ms,{size:12,"aria-hidden":!0}),I("editor.commentUnreadMentionsOnly"),o.jsx("span",{children:xe.mentions})]}),o.jsxs("label",{className:"comment-review-sort","data-texlite-tooltip-always":!0,"data-tooltip":I(U==="source"?"editor.commentSortSource":"editor.commentSortTime"),children:[o.jsx("span",{className:"sr-only",children:I("editor.commentSort")}),U==="source"?o.jsx(Hf,{size:12,"aria-hidden":!0}):o.jsx(Kf,{size:12,"aria-hidden":!0}),o.jsxs("select",{value:U,"aria-label":`${I("editor.commentSort")}: ${I(U==="source"?"editor.commentSortSource":"editor.commentSortTime")}`,onChange:y=>R(y.target.value),children:[o.jsx("option",{value:"source",children:I("editor.commentSortSourceShort")}),o.jsx("option",{value:"time",children:I("editor.commentSortTimeShort")})]})]})]})]}),d&&o.jsxs("div",{className:"comment-review-error",role:"alert",children:[o.jsx("span",{children:d}),o.jsx("button",{type:"button",onClick:()=>{f()},children:I("common.retry")})]}),h&&o.jsx("div",{className:"comment-review-loading",role:"status",children:I("common.loading")}),o.jsxs("div",{className:"comments",children:[F.map(({comment:y,exitAt:T})=>{const V=m.find(Se=>Se.commentId===y.id&&!Se.replyId)?.id,ft=new Map(m.filter(Se=>Se.commentId===y.id&&Se.replyId).map(Se=>[Se.replyId,Se.id]));return o.jsx("div",{className:`comment-thread-slot${T!==null?" is-exiting":""}`,inert:T!==null?!0:void 0,"aria-hidden":T!==null?!0:void 0,style:{"--comment-exit-duration":`${td}ms`},onAnimationEnd:Se=>{Se.target===Se.currentTarget&&T!==null&&oe(y.id)},children:o.jsx("div",{className:"comment-thread-slot-content",children:o.jsx(Fx,{projectId:s,comment:y,draftStore:c,currentUserId:l,unreadCommentMentionId:V,unreadReplyMentionIds:ft,highlightedComment:M===y.id&&!H,highlightedReplyId:M===y.id?H:null,currentComment:Ge===y.id,showFilePath:!fe&&v==="project",replyExpansion:Me.get(y.id),onReplyExpansionChange:Se=>{Fe(mt=>mt.get(y.id)===Se?mt:new Map(mt).set(y.id,Se))},selectedParticipantIds:fe?void 0:he,highlightReplyParticipants:!fe&&!Ne,onMarkMentionRead:N,onFocus:()=>Oe(y),onActivate:()=>be(y.id),onToggle:()=>le(y),onReply:Se=>B(y,Se),onEdit:Se=>se(y,Se),onDelete:()=>W(y),onEditReply:(Se,mt)=>te(y,Se,mt),onDeleteReply:Se=>Y(y,Se)})})},y.id)}),F.length===0&&!h&&!d&&o.jsx("p",{className:"muted padded",role:"status",children:fe?I(a.some(y=>y.id===w&&y.resolved)?"editor.currentCommentResolved":"editor.currentCommentUnavailable"):a.length?I("editor.commentNoMatches"):I("editor.noComments")})]})]}),t==="settings"&&o.jsx(gf,{onClose:e,children:o.jsx(Gx,{onClose:e,project:n,projectId:s,site:r,files:i,dictionaryWords:Ce,onDictionaryChange:ae,editorPreferences:Z,onEditorPreferences:$,spellCheckCount:ue,spellCheckUniqueCount:Ee,spellCheckIndex:ke,onSpellCheckNavigate:ve,onProject:X},s)})]})})]}):null}function Yx(t){if(typeof globalThis.requestAnimationFrame=="function"){const n=globalThis.requestAnimationFrame(t);return()=>globalThis.cancelAnimationFrame(n)}const e=globalThis.setTimeout(t,0);return()=>globalThis.clearTimeout(e)}function Xx(){let t={line:1,column:1,offset:0},e=t.line,n=null,s=null;const r=new Set,i=()=>{for(const c of r)c()},l=()=>{s=null;const c=n;n=null,!(c===null||c===e)&&(e=c,i())},a=c=>{n=c,s===null&&(s=Yx(l))};return{getCursor:()=>t,getOutlineLine:()=>e,subscribe:c=>(r.add(c),()=>r.delete(c)),update:(c,h,d)=>{t.line===c&&t.column===h&&t.offset===d||(t={line:c,column:h,offset:d},(c!==e||s!==null)&&a(c))},reset:()=>{s?.(),s=null,n=null,t={line:1,column:1,offset:0},e!==1&&(e=1,i())},dispose:()=>{s?.(),s=null,n=null}}}function Zx(t,e,n){return t.mainFile===e?t.items:!e||n.filePath!==e?[]:Qx(n.content).map(s=>({...s,path:e}))}function Qx(t){const e=[],n=/^\s*\\(part|chapter|section|subsection|subsubsection)\*?(?:\[[^\]]*\])?\{([^}]*)\}/,s={part:0,chapter:0,section:1,subsection:2,subsubsection:3};return t.split(`
|
|
20
|
+
`).forEach((r,i)=>{const l=r.match(n);l&&e.push({level:s[l[1]],title:l[2],line:i+1})}),e}const e0=u.lazy(()=>Lt(()=>import("./WordCountDialog-B6RvAI6V.js"),__vite__mapDeps([31,2,1,3,29,4,5,6,7,8]),import.meta.url).then(t=>({default:t.WordCountDialog})));let pr=null;function ec(){return pr||(pr=Lt(()=>import("./citationLibrary-C9WnXB-1.js"),[],import.meta.url).catch(t=>{throw pr=null,t})),pr}function Kt(t){return t instanceof Error&&t.name==="AbortError"}const tc=300;function t0({site:t,user:e,projectId:n,preload:s,mentionId:r=null,onMentionTargeted:i,onMentionsRead:l,onBack:a}){const{t:c}=Ye(),h=u.useRef(n);h.current=n;const[d,f]=u.useState(null);u.useEffect(()=>(document.title=d?.name?`${t.siteName} | ${d.name}`:t.siteName,()=>{document.title=t.siteName}),[d?.name,t.siteName]);const[m,g]=u.useState(!1),[w,S]=u.useState([]),[L,v]=u.useState(null),[q,A]=u.useState({mainFile:"",items:[]}),[x,P]=u.useState(""),[j,C]=u.useState(""),[M,H]=u.useState(""),[J,le]=u.useState({filePath:"",content:""}),[B,se]=u.useState({path:"",hasIncludes:!1}),[W,te]=u.useState(""),[Y,Ce]=u.useState(!1),[ae,Z]=u.useState("editor.saved"),[$,ue]=u.useState(null),Ee=u.useRef($);Ee.current=$;const ke=u.useRef(null);ke.current||(ke.current=Xx());const ve=ke.current,[X,I]=u.useState("pdf"),[fe,ye]=u.useState("log"),O=p=>{if(p==="pdf"){I("pdf");return}if(p==="diagnostics"){I("diagnostics");return}ye(p),I("diagnostics")},{workspaceLayout:z,setWorkspaceLayout:De}=Ib(e.id,n),[U,R]=u.useState(""),[he,K]=u.useState(""),[Ne,Ve]=u.useState({selectedText:"",startOffset:0,endOffset:0}),Me=u.useRef({selectedText:"",startOffset:0,endOffset:0}),Fe=p=>{const b=Me.current;b.selectedText===p.selectedText&&b.startOffset===p.startOffset&&b.endOffset===p.endOffset||(Me.current=p,Ve(p))},[ne,be]=u.useState(null),[_,ge]=u.useState(null),[xe,Le]=u.useState(null),[Ue,Ge]=u.useState(null),[Re,re]=u.useState(null),[F,oe]=u.useState(!1),[Oe,Be]=u.useState(!1),[N,G]=u.useState(!1),[Te,Q]=u.useState(!1),[yt,k]=u.useState(null),[y,T]=u.useState(!1),[V,ft]=u.useState(null),[Se,mt]=u.useState(!1),[Bt,At]=u.useState(!1),[$n,bt]=u.useState("full"),[ti,_e]=u.useState(""),[mn,ni]=u.useState(!1),[nd,si]=u.useState(""),[sd,ri]=u.useState(null),[bs,Pn]=u.useState(!1),[pn,qt]=u.useState(null),[rd,ii]=u.useState(!1),[it,il]=u.useState(()=>ta(e.id,n));u.useEffect(()=>{const p=document.documentElement,b=it.showTooltips?"on":"off";return p.setAttribute("data-texlite-tooltips",b),()=>{p.getAttribute("data-texlite-tooltips")===b&&p.removeAttribute("data-texlite-tooltips")}},[it.showTooltips]);const[In,tr]=u.useState([]),Zt=u.useRef([]);Zt.current=In;const id=u.useRef(null),nr=u.useRef(null),sr=u.useRef(0),oi=u.useRef(0),$e=u.useRef(""),at=u.useRef(""),ol=u.useRef(()=>{}),li=u.useRef(z),ll=u.useRef(0),gn=u.useRef(null),al=u.useRef(null),wn=u.useRef(null),yn=u.useRef(null),zn=u.useRef(null),Un=u.useRef(null),Bn=u.useRef(null),Qt=u.useRef(null),ai=u.useRef(null),Wt=u.useRef(!1),en=u.useRef(null),cl=u.useRef(a),ci=u.useRef(i),ui=u.useRef(l);cl.current=a,ci.current=i,ui.current=l,$e.current=x,at.current=j,li.current=z,u.useEffect(()=>{if(!he)return;const p=window.setTimeout(()=>K(""),3e3);return()=>window.clearTimeout(p)},[he]);const od=u.useCallback((p,b,E=0)=>{ve.update(p,b,E)},[ve]);u.useEffect(()=>()=>ve.dispose(),[ve]),u.useEffect(()=>()=>{Qt.current?.abort(),Qt.current=null},[]);const rr=p=>{const b=Zt.current,E=p(b);E!==b&&(Zt.current=E,tr(E))};u.useEffect(()=>{Zt.current=[],tr([]),qt(null),k(null),Un.current?.abort(),Un.current=null,Bn.current?.abort(),Bn.current=null,Qt.current?.abort(),Qt.current=null,ai.current=null,Le(null),Ge(null),re(null),At(!1),ni(!1),si(""),ri(null)},[n]);const ul=p=>{const b=Zt.current,E=b.indexOf(p);if(E<0)return;const D=b.filter(ie=>ie!==p);if(Zt.current=D,tr(D),$e.current!==p)return;const de=D.length>0?D[Math.min(E,D.length-1)]:d?.mainFile??"";P(de)},{collaboration:qe,status:ir,synced:Xe,activeSessions:dl,formatLeaseStates:ld,compileState:qn,setCompileState:hl,filesEvent:Ze,commentsRevision:fl,historyWarning:ad,dictionaryRevision:ml,chktexSettingsRevision:pl,localDraftReady:gl,permission:di,reconnect:cd,protocolUpgradeRequired:wl,permissionDowngrade:ud,dismissPermissionDowngrade:dd,discardLocalDraft:hd}=Db(n,e,j,d?.permission??"read",m,()=>Z("editor.offlineDraft")),{unreadMentions:yl,refresh:fd,markMentionRead:md,markAllMentionsRead:pd}=ep(n,fl,R),{pdfTarget:gd,pdfViewport:wd,sourceJump:yd,setPdfViewport:bd,resetPdfViewport:xd,clearPdfViewport:bl,jumpToSource:xs,syncSourceToPdf:hi,syncPdfToSource:kd,syncVisiblePdfToSource:Sd}=Pb({projectId:n,mainFile:j,activeFile:x,onOpenSourceFile:p=>ol.current(p),onError:R,onShowPdf:()=>O("pdf"),onShowEditor:()=>{li.current==="pdf-only"&&De("editor-pdf")}}),xl=!!(d&&d.chktexEnabled&&x&&Xe&&Va(x)),bn=$b({active:xl,projectId:n,activeFile:x,content:M}),Cd=!!(d&&x&&Xe&&zb(x)&&(it.spellCheck||d.chktexEnabled&&Va(x))),xt=Fb({active:Cd,harperEnabled:it.spellCheck,projectId:n,activeFile:x,content:M,dictionaryWords:w,additionalIssues:bn.issues,additionalIssuesReady:!xl||bn.checked});u.useEffect(()=>{il(ta(e.id,n))},[e.id,n]);const fi=p=>{H(p)};u.useEffect(()=>{if(!x||W!==x){le(D=>D.filePath||D.content?{filePath:"",content:""}:D);return}const p=x,b=M,E=window.setTimeout(()=>{le(D=>D.filePath===p&&D.content===b?D:{filePath:p,content:b})},tc);return()=>window.clearTimeout(E)},[x,W,M]),u.useEffect(()=>{if($e.current=x,ve.reset(),Fe({selectedText:"",startOffset:0,endOffset:0}),!it.openFilesInTabs){Zt.current.length>0&&(Zt.current=[],tr([]));return}x&&rr(p=>p.includes(x)?p:[...p,x])},[x,it.openFilesInTabs,n,ve]),u.useEffect(()=>{if(!Y)return;const p=b=>{b.preventDefault(),b.returnValue=""};return window.addEventListener("beforeunload",p),()=>window.removeEventListener("beforeunload",p)},[Y]),u.useEffect(()=>{if(ir!=="disconnected")return;const p=new AbortController;return pe(`/api/projects/${n}`,{signal:p.signal}).then(({project:b})=>{p.signal.aborted||(f(b),R(""))}).catch(b=>{if(!Kt(b)){if(b instanceof xr&&[401,403,404].includes(b.status)){R(we(b)),cl.current();return}R(c("errors.collaborationUnavailable"))}}),()=>p.abort()},[ir,n,c]);const or=async(p={},b=at.current)=>{gn.current?.abort(),gn.current=null;const E=p.signal?null:new AbortController;E&&(gn.current=E);try{const D=b?`?mainFile=${encodeURIComponent(b)}`:"",de=await pe(`/api/projects/${n}/completions${D}`,{signal:p.signal??E?.signal});(!p.isCurrent||p.isCurrent())&&v(de.index)}catch(D){if(Kt(D))return;(!p.isCurrent||p.isCurrent())&&v(null)}finally{E&&gn.current===E&&(gn.current=null)}},mi=async(p={},b=at.current)=>{wn.current?.abort(),wn.current=null;const E=p.signal?null:new AbortController;E&&(wn.current=E);try{const D=b?`?mainFile=${encodeURIComponent(b)}`:"",de=await pe(`/api/projects/${n}/outline${D}`,{signal:p.signal??E?.signal});(!p.isCurrent||p.isCurrent())&&at.current===b&&A({mainFile:b,items:de.outline})}catch(D){if(Kt(D))return}finally{E&&wn.current===E&&(wn.current=null)}},kl=async(p={})=>{yn.current?.abort(),yn.current=null;const b=p.signal?null:new AbortController;b&&(yn.current=b);try{const E=await pe(`/api/projects/${n}/dictionary`,{signal:p.signal??b?.signal});(!p.isCurrent||p.isCurrent())&&S(E.words)}catch(E){if(Kt(E))return;(!p.isCurrent||p.isCurrent())&&S([])}finally{b&&yn.current===b&&(yn.current=null)}};u.useEffect(()=>{let p=!1;const b=++ll.current,E=new AbortController,D=()=>!p&&ll.current===b;let de=!1,ie="";f(null),vl([]),A({mainFile:"",items:[]}),P(""),C(""),se({path:"",hasIncludes:!1}),H(""),te(""),hl(null),bl(),v(null),S([]),nc();const ce=(s?.projectId===n?s.project:pe(`/api/projects/${n}`,{signal:E.signal})).then(Qe=>{D()&&(de=!0,ie=Qe.project.mainFile,f(Qe.project),P(Qe.project.mainFile),at.current=Qe.project.mainFile,C(Qe.project.mainFile),cr(new Set(En(Qe.project.mainFile))))}).catch(Qe=>{D()&&R(we(Qe))}),Mt=pe(`/api/projects/${n}/files`,{signal:E.signal}).then(Qe=>{D()&&vl(Qe.files)}).catch(Qe=>{D()&&R(we(Qe))});let pt=null;return Promise.allSettled([ce,Mt]).then(()=>{!D()||!de||(pt=window.setTimeout(()=>{D()&&Promise.all([or({signal:E.signal,isCurrent:D},at.current||ie),kl({signal:E.signal,isCurrent:D})])},0))}),()=>{p=!0,pt!==null&&window.clearTimeout(pt),E.abort(),gn.current?.abort(),gn.current=null,wn.current?.abort(),wn.current=null,yn.current?.abort(),yn.current=null,zn.current?.abort(),zn.current=null}},[n,s]),u.useEffect(()=>{if(!(!d||!j)){if(al.current!==n){al.current=n;return}or({},j)}},[j,d?.id,n]),u.useEffect(()=>{if(!r||!d)return;Bn.current?.abort();const p=new AbortController;return Bn.current=p,pe(`/api/projects/${n}/mentions/${encodeURIComponent(r)}`,{signal:p.signal}).then(({mention:b})=>{p.signal.aborted||(Le(b),ge(null),be("comments"),P(b.filePath),ci.current?.(b.id))}).catch(b=>{Kt(b)||p.signal.aborted||(R(we(b)),ci.current?.(r))}).finally(()=>{Bn.current===p&&(Bn.current=null)}),()=>p.abort()},[r,d?.id,n]),u.useEffect(()=>{ml&&kl()},[ml,n]),u.useEffect(()=>{if(!pl)return;const p=new AbortController;return pe(`/api/projects/${n}`,{signal:p.signal}).then(({project:b})=>{p.signal.aborted||f(E=>E?{...E,chktexEnabled:b.chktexEnabled}:b)}).catch(b=>{Kt(b)||R(we(b))}),()=>p.abort()},[pl,n]),u.useEffect(()=>{!d||ir!=="connected"||di===d.permission||f(p=>p&&{...p,permission:di})},[di,d?.permission]),u.useEffect(()=>{if(!Ze)return;const p=Ze.kind==="delete"&&!!Ze.path&&kn(Ze.path,$e.current),b=Ze.kind==="delete"&&!!Ze.path&&kn(Ze.path,at.current);if(Ze.kind==="move"&&Ze.source&&Ze.destination){const D=Ze.source,de=Ze.destination,ie=ce=>ce===D?de:ce.startsWith(`${D}/`)?`${de}${ce.slice(D.length)}`:ce;P(ce=>ie(ce)),C(ce=>ie(ce)),Ss(ce=>ce&&ie(ce)),ar(ce=>ce&&ie(ce)),rr(ce=>ce.map(ie))}p&&(P(""),te(""),fi(""),K(c("editor.fileDeletedByCollaborator",{path:Ze.path}))),Ze.kind==="delete"&&Ze.path&&(Ss(D=>D&&kn(Ze.path,D)?null:D),ar(D=>kn(Ze.path,D)?"":D),Dl(D=>D&&kn(Ze.path,D.path)?null:D),rr(D=>D.filter(de=>!kn(Ze.path,de)))),zn.current?.abort();const E=new AbortController;zn.current=E,Promise.all([Td({signal:E.signal}),pe(`/api/projects/${n}`,{signal:E.signal})]).then(([D,de])=>{if(f(de.project),b&&C(de.project.mainFile),p&&D){const ie=D.find(ce=>ce.type==="file"&&ce.path===de.project.mainFile)??D.find(ce=>ce.type==="file"&&ss(ce.path));P(ie?.path??"")}or({signal:E.signal}),mi({signal:E.signal},b?de.project.mainFile:at.current)}).catch(D=>{Kt(D)}).finally(()=>{zn.current===E&&(zn.current=null)})},[Ze?.revision]),u.useEffect(()=>{if(qe.setActiveFile(x),!x)return;te(""),Z("editor.loading");const p=qe.getText(x),b=(E,D)=>{fi(p.toString()),te(x),D?.local&&d?.permission!=="read"?(sr.current+=1,Ce(!0),Z("editor.pending")):sr.current<=oi.current&&Z(Ee.current?"editor.savedAt":"editor.saved")};return p.observe(b),(Xe||gl)&&b(),()=>{p.unobserve(b)}},[x,qe,Xe,gl,d?.permission]);const lr=async()=>{if(!Xe)throw new Error("Collaboration is not synchronized");const p=sr.current,b=await qe.flush();return oi.current=Math.max(oi.current,p),ue(b.persistedAt),/\.tex$/i.test($e.current)&&mi(),sr.current===p?(Ce(!1),Z("editor.savedAt")):Z("editor.pending"),b};u.useEffect(()=>{if(!Y||!x)return;if(!Xe){Z("editor.offlineDraft");return}Z("editor.pending");const p=window.setTimeout(()=>{Z("editor.saving"),lr().catch(()=>{Z(qe.connected?"editor.saveFailed":"editor.offlineDraft")})},750);return()=>window.clearTimeout(p)},[M,Y,x,Xe]);const ks=async()=>{if(!d||d.permission==="read"||!Xe||!x)return!1;Z("editor.saving");try{return await lr(),or(),!0}catch(p){return Z("editor.saveFailed"),R(we(p)||c("errors.collaborationUnavailable")),!1}},vd=async p=>{if(!d||mn)return;const b=p==="full"?at.current||d.mainFile:$e.current,E=p==="selection"?Me.current.selectedText:"";if(!b)return;if(p==="selection"&&(!E.trim()||!/\.(?:tex|sty|cls)$/i.test(b))){K(c("editor.wordCountSelectionEmpty"));return}Un.current?.abort();const D=new AbortController;Un.current=D,bt(p),_e(b),ri(null),si(""),At(!0),ni(!0);try{if(p==="full"&&Y&&d.permission!=="read"&&!await ks())throw new Error(c("editor.wordCountSaveRequired"));const de=p==="selection"?{mode:p,path:b,source:E}:{mode:p,mainFile:b},ie=await pe(`/api/projects/${n}/word-count`,{method:"POST",body:JSON.stringify(de),signal:D.signal});if(D.signal.aborted)return;ri(ie)}catch(de){if(Kt(de))return;D.signal.aborted||si(we(de))}finally{Un.current===D&&(Un.current=null,ni(!1))}},pi=async(p,b,E=it.texFmtConfig)=>{if(/\.bib$/i.test(p)){const de=await ec();try{return{formatted:de.formatBibtex(b,t.maxCitationBibtexBytes)}}catch(ie){throw ie instanceof de.BibtexFormatError?ie.kind==="too-large"?new Error(c("citationLibrary.fileTooLarge",{size:de.citationBibtexLimitLabel(t.maxCitationBibtexBytes)})):new Error(c("citationLibrary.fileInvalid")):ie}}return{formatted:(await Sm(b,E)).output}},Sl=async p=>{if(!d||d.permission==="read"||!Xe||Wt.current||!dr($e.current))return;const b=$e.current,E=qe.getText(b);Wt.current=!0,Pn(!0);let D=()=>{};const de=new Promise(ce=>{D=ce});en.current=de;let ie=null;try{ie=await qe.acquireFormatLease(b);const ce=E.toString(),{formatted:Mt}=await pi(b,ce,p);if($e.current!==b||E.toString()!==ce){R(c("editor.formatSourceChanged"));return}await ie.confirm();const pt=await Ri(ce,Mt);if($e.current!==b||E.toString()!==ce){R(c("editor.formatSourceChanged"));return}if(await ie.confirm(),$e.current!==b||E.toString()!==ce){R(c("editor.formatSourceChanged"));return}pt.length&&qe.applyTextEdits(b,pt),pt.length&&await lr(),qt(null),R(""),K(c("editor.formatFileComplete"))}catch(ce){_i(ce)?(qt({action:"file",kind:ce.kind,detail:ce.message}),R("")):R(c("editor.formatFileFailed",{message:we(ce)}))}finally{ie&&await ie.release(),Wt.current=!1,Pn(!1),D(),en.current===de&&(en.current=null)}},jd=async()=>{if(!it.formatOnCompile||!d||d.permission==="read"||!Xe||!dr($e.current)||Wt.current)return;const p=$e.current,b=qe.getText(p);Wt.current=!0,Pn(!0);let E=null;try{E=await qe.acquireFormatLease(p);const D=b.toString(),{formatted:de}=await pi(p,D);await E.confirm();const ie=await Ri(D,de);if($e.current!==p||b.toString()!==D)throw new Error(c("editor.formatSourceChanged"));if(await E.confirm(),$e.current!==p||b.toString()!==D)throw new Error(c("editor.formatSourceChanged"));ie.length&&qe.applyTextEdits(p,ie),ie.length&&await qe.flush(),qt(null)}catch(D){_i(D)?(qt({action:"file",kind:D.kind,detail:D.message}),R("")):R(c("editor.formatFailedContinue",{message:we(D)}))}finally{E&&await E.release(),Wt.current=!1,Pn(!1)}},Ed=async()=>(en.current&&await en.current,await jd(),ks()),Cl=async p=>{if(!d||d.permission==="read"||!Xe||Wt.current||!dr($e.current))return;const b=Me.current;if(!b.selectedText.trim()){K(c("editor.formatSelectionRequired"));return}const E=$e.current,{startOffset:D,endOffset:de,selectedText:ie}=b,ce=qe.getText(E);if(ce.toString().slice(D,de)!==ie){R(c("editor.formatSelectionChanged"));return}Wt.current=!0,Pn(!0);let Mt=()=>{};const pt=new Promise(Vt=>{Mt=Vt});en.current=pt;let Qe=null;try{if(Qe=await qe.acquireFormatLease(E),ce.toString().slice(D,de)!==ie){R(c("editor.formatSelectionChanged"));return}const Es=await pi(E,ie,p),df=jm(ie,Es.formatted);await Qe.confirm();const Ti=await Ri(ie,df,D);if($e.current!==E||ce.toString().slice(D,de)!==ie){R(c("editor.formatSelectionChanged"));return}if(await Qe.confirm(),$e.current!==E||ce.toString().slice(D,de)!==ie){R(c("editor.formatSelectionChanged"));return}Ti.length&&qe.applyTextEdits(E,Ti),Ti.length&&await lr(),qt(null),R(""),K(c("editor.formatSelectionComplete"))}catch(Vt){_i(Vt)?(qt({action:"selection",kind:Vt.kind,detail:Vt.message}),R("")):R(c("editor.formatFailed",{message:we(Vt)}))}finally{Qe&&await Qe.release(),Wt.current=!1,Pn(!1),Mt(),en.current===pt&&(en.current=null)}},Dd=async p=>{const b=$e.current;if(!/\.bib$/i.test(b)||d?.permission==="read"||!Xe)return K(c("citationLibrary.importRequiresWrite")),!1;const E=qe.getText(b);let D;try{D=await ec()}catch(Es){return R(we(Es)),!1}if($e.current!==b||!Xe)return!1;const de=E.toString(),ie=D.parseBibEntriesResult(de,t.maxCitationBibtexBytes);if(ie.status==="too-large")return K(c("citationLibrary.fileTooLarge",{size:D.citationBibtexLimitLabel(t.maxCitationBibtexBytes)})),!1;if(ie.status==="invalid")return K(c("citationLibrary.fileInvalid")),!1;if(ie.entries.some(Es=>Es.citationKey.toLowerCase()===p.citationKey.toLowerCase()))return K(c("citationErrors.alreadyInFile",{key:p.citationKey})),!1;const ce=Math.max(0,Math.min(de.length,ve.getCursor().offset)),Mt=de.slice(0,ce),pt=de.slice(ce),Qe=Mt?Mt.endsWith(`
|
|
21
|
+
|
|
22
|
+
`)?"":Mt.endsWith(`
|
|
23
|
+
`)?`
|
|
24
|
+
`:`
|
|
25
|
+
|
|
26
|
+
`:"",Vt=pt?pt.startsWith(`
|
|
27
|
+
|
|
28
|
+
`)?"":pt.startsWith(`
|
|
29
|
+
`)?`
|
|
30
|
+
`:`
|
|
31
|
+
|
|
32
|
+
`:"";return qe.applyTextEdits(b,[{from:ce,to:ce,replacement:`${Qe}${p.bibtex.trim()}${Vt}`}]),K(c("citationLibrary.imported",{key:p.citationKey})),!0},{files:Nt,setFiles:vl,loadFiles:Td,newFileOpen:_d,setNewFileOpen:jl,newFilePath:Rd,setNewFilePath:El,resourcePreview:Ld,setResourcePreview:Dl,resourcePreviewLoading:Ad,setResourcePreviewLoading:Nd,newFolderOpen:Md,setNewFolderOpen:Tl,newFolderName:Od,setNewFolderName:_l,fileDialogError:Fd,setFileDialogError:Rl,selectedFolder:Ll,setSelectedFolder:Ss,selectedFile:$d,setSelectedFile:ar,expandedFolders:Pd,setExpandedFolders:cr,moveEntry:Id,setMoveEntry:Al,moveName:zd,setMoveName:Nl,moveDestination:Ud,setMoveDestination:Ml,deleteEntry:gi,setDeleteEntry:Ol,fileDragActive:Bd,setFileDragActive:qd,uploadConflict:Wd,setUploadConflict:Vd,uploadingFiles:Hd,uploadFeedback:Kd,dismissUploadFeedback:Fl,directoryEntries:Gd,visibleEntries:Jd,createFile:Yd,createFolder:Xd,uploadFiles:$l,upload:Zd,openFile:wi,movePath:Qd,movePathToFolder:eh,removePath:th}=Mb({projectId:n,site:t,activeFile:x,dirty:Y,save:ks,onError:R,onProject:f,onActiveFile:P,onActiveMainFile:C});ol.current=p=>{Ss(null),ar(p),cr(b=>new Set([...b,...En(p)])),P(p)};const nh=p=>{if(p.id!==h.current)return;const b=p.mainFile!==d?.mainFile;f(p),b&&(at.current=p.mainFile,$e.current=p.mainFile,C(p.mainFile),P(p.mainFile),Ss(null),ar(p.mainFile),cr(E=>new Set([...E,...En(p.mainFile)])))},Pl=()=>at.current||d?.mainFile||"",sh=()=>{const p=Pl(),b=$e.current;if(!b||!/\.tex$/i.test(b))return p;const E=Nt.filter(ie=>ie.type==="file"&&/\.tex$/i.test(ie.path)).length,D=qe.getText(b).toString();return Ga(D)||E===1?(p!==b&&(at.current=b,C(b)),b):p===b&&d?.mainFile&&d.mainFile!==b?(at.current=d.mainFile,C(d.mainFile),d.mainFile):p};u.useEffect(()=>{!x||x!==j||W!==x||J.filePath!==x||!x.toLocaleLowerCase().endsWith(".tex")||Nt.filter(b=>b.type==="file"&&/\.tex$/i.test(b.path)).length===0||x===d?.mainFile||!Ga(J.content)&&d?.mainFile&&(at.current=d.mainFile,C(d.mainFile))},[x,j,W,J,Nt,d?.mainFile]),u.useEffect(()=>{if(!it.openFilesInTabs||Nt.length===0)return;const p=new Set(Nt.filter(b=>b.type==="file"&&ss(b.path)).map(b=>b.path));rr(b=>{const E=b.filter(D=>p.has(D));return E.length===b.length?b:E})},[Nt,it.openFilesInTabs]);const{comments:tn,commentsFilePath:yi,commentsReady:bi,fileCommentsLoading:rh,fileCommentsError:ih,retryFileComments:oh,reviewComments:lh,reviewCommentsLoading:ah,reviewCommentsError:ch,retryReviewComments:uh,commentScope:dh,setCommentScope:hh,focusComment:Il,setFocusComment:Cs,commentOpen:fh,openComment:mh,closeComment:ph,commentText:gh,setCommentText:wh,commentSelection:yh,commentSubmitting:bh,commentError:xh,addComment:kh,toggleComment:Sh,replyToComment:Ch,editComment:vh,deleteComment:jh,editCommentReply:Eh,deleteCommentReply:Dh,commentDraftStore:Th,cancelComment:_h,commentDraftRestored:Rh,commentDraftCanRetarget:Lh,useCurrentCommentSelection:Ah}=qm({projectId:n,activeFile:x,content:M,permission:d?.permission,revision:fl,selection:Ne,save:ks,saveFailureMessage:c("errors.collaborationUnavailable"),onError:R,onAdded:()=>{ge(null),be("comments")},onChanged:()=>{fd()}});u.useEffect(()=>{if(!j||J.filePath!==j)return;const p=Ja(J.content).length>0;se(b=>b.path===j&&b.hasIncludes===p?b:{path:j,hasIncludes:p})},[j,J]),u.useEffect(()=>{if(!j||!Xe||x===j)return;const p=qe.getText(j);let b=null;const E=()=>{const de=Ja(p.toString()).length>0;se(ie=>ie.path===j&&ie.hasIncludes===de?ie:{path:j,hasIncludes:de})},D=()=>{b!==null&&window.clearTimeout(b),b=window.setTimeout(()=>{b=null,E()},tc)};return E(),p.observe(D),()=>{b!==null&&window.clearTimeout(b),p.unobserve(D)}},[x,j,qe,Xe]);const Nh=u.useMemo(()=>B.path===j&&B.hasIncludes,[j,B]),zl=p=>{re(null),be("comments"),Cs(null),Ge(p),$e.current!==p.filePath&&xs(p.filePath,p.startLine,1)},Mh=(p,b=!1)=>{const E=tn.find(D=>D.id===p&&D.filePath===x);if(!(!E||E.resolved||E.orphaned)){if(Ge(null),Cs(null),Le(null),b&&ne==="comments"&&_===E.id){ge(null),re(null),be(null);return}ge(E.id),re(D=>({id:E.id,filePath:E.filePath,nonce:(D?.nonce??0)+1})),be("comments")}};u.useEffect(()=>{re(null),ge(null)},[x]),u.useEffect(()=>{if(!Ue)return;const p=Ym(Ue,x,W,yi,bi,tn);if(p){Cs({...p}),Ge(null);return}Ue.filePath===x&&W===x&&yi===x&&bi&&Ge(null)},[x,tn,yi,bi,W,Ue,Cs]);const Oh=async p=>{const b=await md(p);return b&&ui.current?.(1),b},Fh=async()=>{const p=yl.length,b=await pd();return b&&p&&ui.current?.(p,!0),b};u.useEffect(()=>{if(!xe||x!==xe.filePath||ne!=="comments")return;const p=tn.find(E=>E.id===xe.commentId);if(!p||xe.replyId&&!p.replies.some(E=>E.id===xe.replyId)||ai.current===xe.id)return;ai.current=xe.id,zl(p);const b=window.setTimeout(()=>Le(E=>E?.id===xe.id?null:E),3e3);return()=>window.clearTimeout(b)},[x,tn,ne,xe]);const{pdfUrl:nn,pdfCompiledAt:vs,pdfSizeBytes:$h,pdfLoadingMode:Ph,pdfLoading:xi,compileLog:ki,compileDiagnostics:Ih,compileOutcome:js,artifacts:Ul,artifactPreview:zh,artifactLoading:Uh,editorNotice:Bh,localCompiling:Bl,cancelling:qh,cleaning:ql,compile:Wh,cancelCompile:Vh,cleanCompile:Hh,viewArtifact:Kh}=Rb({projectId:n,project:d,mainFile:j,resolveCompileMainFile:sh,getCurrentMainFile:Pl,initialLatest:s?.projectId===n?s.latestCompile:null,collaborationSynced:Xe,sharedState:qn,onSharedState:hl,save:Ed,loadOutline:(p,b)=>mi({signal:p},b),onPreviewTab:O,onError:R,onCompileStart:()=>{R(""),K("")},onCompileSuccess:()=>{const p=$e.current;if(p){const b=ve.getCursor();hi(p,b.line,b.column,{silent:!0})}},onPdfChanged:bl});u.useEffect(()=>{if(!d||!j||!nn&&xi)return;const p=window.setTimeout(()=>g(!0),nn?150:0);return()=>window.clearTimeout(p)},[d,xi,nn]),u.useEffect(()=>{const p=b=>{(b.ctrlKey||b.metaKey)&&!b.shiftKey&&b.key.toLocaleLowerCase()==="p"&&(b.preventDefault(),mt(!0))};return window.addEventListener("keydown",p,!0),()=>window.removeEventListener("keydown",p,!0)},[]);const Wl=p=>{il(p),wm(e.id,n,p)},Vl=(p=!1)=>{const b=pn;if(!b)return;qt(null),R(""),p&&Wl({...it,texFmtConfig:""});const E=p?"":void 0;b.action==="selection"?Cl(E):Sl(E)},Gh=async()=>{ii(!0);try{await hd()||(R(c("editor.collaboration.permissionDowngradeOtherTabBlocked")),ii(!1))}catch(p){R(we(p)),ii(!1)}},Jh=()=>{nr.current?.isCollapsed()?nr.current.expand():nr.current?.collapse()},Yh=u.useMemo(()=>Zx(q,j,J),[q,j,J]),Si=u.useMemo(()=>Em(ki,js),[ki,js]),Wn=z!=="pdf-only",Hl=z!=="editor-only",Ci=p=>{De(p),p==="pdf-only"&&O("pdf")},Xh=u.useCallback(p=>{Qt.current?.abort();const b=new AbortController;Qt.current=b;const E=$e.current,D=at.current,de=new URLSearchParams({kind:p.kind,key:p.key,...E?{path:E}:{},...D?{mainFile:D}:{}});pe(`/api/projects/${n}/references/resolve?${de}`,{signal:b.signal}).then(({target:ie})=>{if(!(b.signal.aborted||$e.current!==E||at.current!==D)){if(!ie){R(c(p.kind==="citation"?"editor.citationTargetNotFound":"editor.labelTargetNotFound",{key:p.key}));return}li.current==="pdf-only"&&Ci("editor-pdf"),xs(ie.path,ie.line,ie.column)}}).catch(ie=>{!b.signal.aborted&&!Kt(ie)&&R(we(ie))}).finally(()=>{Qt.current===b&&(Qt.current=null)})},[xs,n,c]),Zh=gi?dl.filter(p=>p.filePath&&kn(gi.path,p.filePath)):[];if(!d)return o.jsxs("div",{className:"center-card",children:[o.jsx("p",{children:U||c("common.loading")}),U&&o.jsx("button",{className:"primary",onClick:a,children:c("editor.backToProjects")})]});const sn=d.permission==="read"||!Xe,vi=ld.find(p=>p.path===x),ji=vi&&!bs?vi:null,Qh=(p,b)=>{if(sn)return;const E=$e.current;if(!E)return;if(qe.getText(E).toString().slice(p.from,p.to)!==p.word){R(c("editor.spellCheckSourceChanged"));return}try{qe.applyTextEdits(E,[{from:p.from,to:p.to,replacement:b}])}catch(ie){R(we(ie))}},Ei=qn?.mainFile===j&&(qn.status==="queued"||qn.status==="running"),ur=Bl||Ei||ql,ef=x?qe.getText(x):null,tf=vs?new Date(vs).toLocaleString(Rs.resolvedLanguage,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"",nf=j.split("/").at(-1)??j,sf=Si.warnings.length+Si.errors.length+Ul.length,rf=nn?`${nn}${nn.includes("?")?"&":"?"}download=1`:"",Di=j||d.mainFile,of=!!(x&&x===Di&&/\.tex$/i.test(x)),lf=!!(Di&&/\.tex$/i.test(Di)),Kl=p=>{const b=Nt.find(E=>E.path===p);b&&ss(b.path)?wi(b):ul(p)},af=p=>{document.getElementById(`editor-tab-${encodeURIComponent(p)}`)?.focus()},cf=(p,b)=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(p.key))return;p.preventDefault();const E=p.key==="Home"?0:p.key==="End"?In.length-1:(b+(p.key==="ArrowLeft"?-1:1)+In.length)%In.length,D=In[E];D&&(Kl(D),window.requestAnimationFrame(()=>af(D)))},Gl=ur?Ei?qn?.status==="queued"?c("editor.compileQueued"):c("editor.compilingBy",{name:qn?.requestedBy.name??c("common.user")}):c("editor.compiling"):js==="failed"?nn&&vs?c("editor.compileFailedRetained",{time:new Date(vs).toLocaleString(Rs.resolvedLanguage)}):c("editor.compileFailedNoPdf"):js==="cancelled"?c("compileControls.cancelled"):"",uf=ae==="editor.savedAt"&&$?c("editor.savedAt",{time:new Date($).toLocaleTimeString(Rs.resolvedLanguage,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}):c(ae);return o.jsxs("div",{className:"workspace","data-texlite-tooltips":it.showTooltips?"on":"off",children:[o.jsx(rx,{site:t,project:d,activeFile:x,saveStateLabel:uf,editorPreferences:it,activeSessions:dl,collaborationStatus:ir,reconnectCollaboration:cd,protocolUpgradeRequired:wl,showEditor:Wn,filesCollapsed:F,toggleFilesPanel:Jh,workspaceLayout:z,changeWorkspaceLayout:Ci,onBack:a,onShare:()=>Be(!0),showCitationLibrary:Wn&&/\.bib$/i.test(x),citationLibraryOpen:y,onCitationLibrary:()=>T(!0),onHistory:()=>Q(!0),onGit:()=>G(!0),canManageGit:d.ownerId===e.id,formatting:bs,readOnly:sn,collaborationSynced:Xe,onToggleComments:()=>{ge(null),be(ne==="comments"&&!_?null:"comments")},commentsOpen:ne==="comments",unresolvedCommentCount:tn.filter(p=>!p.resolved).length,onToggleSettings:()=>be(ne==="settings"?null:"settings"),settingsOpen:ne==="settings",compileBusy:ur,sharedCompiling:Ei,localCompiling:Bl,cancelling:qh,onCompile:Wh,onCancelCompile:()=>{Vh()}}),wl&&o.jsxs("div",{className:"workspace-update-banner",role:"alert",children:[o.jsx(Dt,{size:15}),o.jsx("span",{children:c("workspaceUpdates.protocolUpgrade")}),o.jsx("button",{type:"button",onClick:()=>window.location.reload(),children:c("common.reload")})]}),Gl&&o.jsxs("div",{className:`compile-status-strip${js==="failed"?" failed":""}`,role:"status","aria-live":"polite",children:[o.jsx(lt,{className:ur?"spin":"",size:14}),o.jsx("span",{children:Gl})]}),(xt.error||bn.error||pn||ji)&&o.jsxs("div",{className:"client-tool-recoveries",children:[xt.error&&o.jsxs("div",{className:"client-tool-recovery",role:"alert",title:xt.error,children:[o.jsx(Dt,{size:15}),o.jsxs("span",{children:[o.jsx("strong",{children:c("editor.harperRecoveryTitle")}),c("editor.harperFallbackHint")]}),o.jsx("div",{className:"client-tool-recovery-actions",children:o.jsx("button",{type:"button",onClick:xt.retry,children:c("common.retry")})}),o.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:c("common.close"),"aria-label":c("common.close"),onClick:xt.dismissError,children:o.jsx(cn,{size:13})})]}),bn.error&&o.jsxs("div",{className:"client-tool-recovery",role:"alert",title:bn.error,children:[o.jsx(Dt,{size:15}),o.jsxs("span",{children:[o.jsx("strong",{children:c("chktex.recoveryTitle")}),c("chktex.recoveryHint")]}),o.jsx("div",{className:"client-tool-recovery-actions",children:o.jsx("button",{type:"button",onClick:bn.retry,children:c("common.retry")})}),o.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:c("common.close"),"aria-label":c("common.close"),onClick:bn.dismissError,children:o.jsx(cn,{size:13})})]}),pn&&o.jsxs("div",{className:"client-tool-recovery",role:"alert",title:pn.detail,children:[o.jsx(Dt,{size:15}),o.jsxs("span",{children:[o.jsx("strong",{children:c(pn.kind==="format"?"editor.texFmtOptionsRecoveryTitle":pn.kind==="load"?"editor.texFmtRecoveryTitle":"editor.texFmtRuntimeRecoveryTitle")}),c("editor.clientToolRecoveryHint")]}),o.jsxs("div",{className:"client-tool-recovery-actions",children:[o.jsx("button",{type:"button",disabled:bs||sn,onClick:()=>Vl(),children:c("common.retry")}),pn.kind==="format"&&it.texFmtConfig.trim()&&o.jsx("button",{type:"button",disabled:bs||sn,onClick:()=>Vl(!0),children:c("editor.resetFormatterOptions")}),o.jsx("button",{type:"button",onClick:()=>window.location.reload(),children:c("common.reload")})]}),o.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:c("common.close"),"aria-label":c("common.close"),onClick:()=>qt(null),children:o.jsx(cn,{size:13})})]}),ji&&o.jsxs("div",{className:"client-tool-recovery format-lease-status",role:"status",children:[o.jsx(lt,{className:"spin",size:15}),o.jsx("span",{children:c("editor.formattingBy",{name:ji.holderName})})]})]}),ad&&o.jsxs("div",{className:"client-tool-recovery",role:"status",children:[o.jsx(Dt,{size:15}),o.jsx("span",{children:c("history.saveWarning")})]}),U&&o.jsx("div",{className:"toast",onClick:()=>R(""),children:U}),he&&o.jsx("div",{className:"toast success",onClick:()=>K(""),children:he}),o.jsxs(yf,{autoSaveId:Cn("texlite-workspace-layout"),direction:"horizontal",className:"work-grid",children:[Wn&&o.jsx(yx,{project:d,filesPanel:nr,visibleEntries:Jd,activeFile:x,activeMainFile:j,selectedFile:$d,selectedFolder:Ll,expandedFolders:Pd,fileDragActive:Bd,uploadingFiles:Hd,uploadFeedback:Kd,readOnly:sn,formatting:bs,canFormat:dr(x),activeFormatLease:!!vi,collaborationSynced:Xe,editorFontSize:it.fontSize,outline:Yh,sourceCursorStore:ve,wordCountBusy:mn,hasSelection:!!Ne.selectedText.trim()&&/\.(?:tex|sty|cls)$/i.test(x),hasFormatSelection:!!Ne.selectedText.trim(),uploadInput:id,setSelectedFolder:Ss,setExpandedFolders:cr,setMoveEntry:Al,setMoveName:Nl,setMoveDestination:Ml,setDeleteEntry:Ol,setFileDialogError:Rl,setNewFolderName:_l,setNewFolderOpen:Tl,setNewFilePath:El,setNewFileOpen:jl,setQuickOpen:mt,setFileDragActive:qd,dismissUploadFeedback:Fl,setFilesCollapsed:oe,onError:R,uploadFiles:$l,upload:Zd,openFile:wi,movePathToFolder:eh,onFormatFile:()=>{Sl()},onFormatSelection:()=>{Cl()},jumpToSource:xs,syncSourceToPdf:hi,onWordCount:p=>{vd(p)}}),Wn&&o.jsx(xo,{className:"resize-handle",children:o.jsx(ic,{size:12})}),Wn&&o.jsx(jx,{project:d,activeFile:x,openTabs:In,content:M,loadedFile:W,readOnly:sn,comments:tn,focusComment:Il,editorPreferences:it,completionIndex:L,nativeSpellCheck:xt.nativeFallback,spellCheckIssues:xt.issues,spellCheckJump:xt.jump,sourceJump:yd,collaborativeText:ef,collaborationAwareness:qe.awareness,undoManager:x?qe.getUndoManager(x):void 0,editorNotice:Bh,activateTab:Kl,closeTab:ul,handleTabKeyDown:cf,updateEditorContent:fi,setSelection:(p,b,E)=>Fe({selectedText:p,startOffset:b,endOffset:E}),onAddComment:(p,b,E,D)=>mh({selectedText:p,startOffset:b,endOffset:E},D),onSelectionHistory:(p,b,E,D)=>{k({filePath:x,selection:{selectedText:p,startOffset:b,endOffset:E},source:D})},onCommentClick:Mh,onSpellCheckReplace:Qh,onReferenceNavigate:Xh,onCursor:od}),Hl&&o.jsx(Lx,{projectId:n,activeMainFile:j,previewTab:X,diagnosticTab:fe,pdfUrl:nn,pdfLoadingMode:Ph,pdfLoading:xi,pdfCompiledAt:vs,pdfSizeBytes:$h,pdfCompiledLabel:tf,pdfTargetLabel:nf,pdfDownloadUrl:rf,pdfTarget:gd,pdfViewport:wd,activeFile:x,compileBusy:ur,compileLog:ki,compileDiagnostics:Ih,compileMessages:Si,artifacts:Ul,artifactPreview:zh,artifactLoading:Uh,cleaning:ql,readOnly:sn,collaborationSynced:Xe,workspaceLayout:z,showSyncResize:Wn&&Hl,diagnosticCount:sf,selectPreviewTab:O,changeWorkspaceLayout:Ci,onSetPdfViewport:bd,onResetPdfViewport:xd,syncVisiblePdfToSource:Sd,syncCurrentSourceToPdf:()=>{const p=$e.current;if(!p)return Promise.resolve();const b=ve.getCursor();return hi(p,b.line,b.column)},syncPdfToSource:kd,canSyncWithPdf:of,canSyncPdfToSource:lf,files:Nt,jumpToSource:xs,onSetCleanMode:ft,viewArtifact:Kh}),o.jsx(Jx,{sidePanel:ne,onClose:()=>be(null),project:d,projectId:n,site:t,files:Nt,currentUserId:e.id,comments:_?tn:lh,commentDraftStore:Th,commentsLoading:_?rh:ah,commentsError:_?ih:ch,onRetryComments:_?oh:uh,activeFile:x,singleCommentId:_,onShowAllComments:()=>ge(null),hasProjectCommentsScope:Nh,commentScope:dh,onCommentScopeChange:hh,focusedCommentId:Re?.filePath===x?Re.id:Il?.id,commentFocusNonce:Re?.nonce,onClearFocusComment:()=>{re(null),Cs(null),Le(null)},unreadMentions:yl,onMarkMentionRead:Oh,onMarkAllMentionsRead:Fh,targetCommentId:xe?.commentId,targetReplyId:xe?.replyId,onFocusComment:zl,onToggleComment:Sh,onReplyComment:Ch,onEditComment:vh,onDeleteComment:jh,onEditCommentReply:Eh,onDeleteCommentReply:Dh,dictionaryWords:w,onDictionaryChange:S,editorPreferences:it,onEditorPreferences:Wl,spellCheckCount:xt.summary?.total??null,spellCheckUniqueCount:xt.summary?.unique??null,spellCheckIndex:xt.summary?xt.index:-1,onSpellCheckNavigate:xt.jumpToIssue,onProject:nh},n)]}),Bt&&o.jsx(sc,{title:c("editor.wordCountTitle"),onClose:()=>At(!1),children:o.jsx(e0,{open:!0,mode:$n,path:ti,busy:mn,error:nd,result:sd,onOpenChange:At})}),o.jsx(qx,{user:e,project:d,projectId:n,activeFile:x,content:M,maxCitationBibtexBytes:t.maxCitationBibtexBytes,files:Nt,directoryEntries:Gd,readOnly:sn,resourcePreview:Ld,resourcePreviewLoading:Ad,setResourcePreview:Dl,setResourcePreviewLoading:Nd,uploadConflict:Wd,setUploadConflict:Vd,dismissUploadFeedback:Fl,uploadFiles:$l,cleanMode:V,setCleanMode:ft,cleanCompile:Hh,newFileOpen:_d,setNewFileOpen:jl,newFilePath:Rd,setNewFilePath:El,newFolderOpen:Md,setNewFolderOpen:Tl,newFolderName:Od,setNewFolderName:_l,selectedFolder:Ll,fileDialogError:Fd,setFileDialogError:Rl,createFile:Yd,createFolder:Xd,moveEntry:Id,setMoveEntry:Al,moveName:zd,setMoveName:Nl,moveDestination:Ud,setMoveDestination:Ml,movePath:Qd,deleteEntry:gi,setDeleteEntry:Ol,deleteActiveSessions:Zh,removePath:th,commentOpen:fh,closeComment:ph,commentSelection:yh,commentText:gh,setCommentText:wh,commentSubmitting:bh,cancelComment:_h,commentDraftRestored:Rh,commentDraftCanRetarget:Lh,useCurrentCommentSelection:Ah,commentError:xh,addComment:kh,shareOpen:Oe,setShareOpen:Be,citationLibraryOpen:y,setCitationLibraryOpen:T,insertCitationAtCursor:Dd,quickOpen:Se,setQuickOpen:mt,openFile:wi,selectionHistoryTarget:yt,closeSelectionHistory:()=>k(null),historyOpen:Te,setHistoryOpen:Q,gitOpen:N,setGitOpen:G,save:ks,permissionDowngrade:ud,permissionDowngradeBusy:rd,dismissPermissionDowngrade:dd,discardPermissionDraft:Gh})]})}const x0=Object.freeze(Object.defineProperty({__proto__:null,ProjectWorkspace:t0},Symbol.toStringTag,{value:"Module"}));export{Hb as A,c0 as B,Zi as C,zm as D,on as E,Jf as F,Cm as G,Ql as H,mm as I,eo as J,Vf as K,u0 as L,x0 as P,dm as R,hm as S,Rw as U,Va as a,m0 as b,mo as c,p0 as d,g0 as e,w0 as f,Nn as g,d0 as h,Ht as i,Bb as j,Ju as k,rl as l,To as m,Vb as n,yo as o,Ir as p,y0 as q,f0 as r,zb as s,h0 as t,ys as u,er as v,Qb as w,b0 as x,bo as y,Yb as z};
|