texlite 0.15.0 → 0.16.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 +11 -0
- package/README.md +6 -0
- package/README.zh-CN.md +6 -0
- package/dist/client/assets/AdminUsers-Dyapv-3c.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-CU7Q7r0Z.js +1 -0
- package/dist/client/assets/Dashboard-DsdhFENx.js +2 -0
- package/dist/client/assets/GitDialog-CZpnKw-J.js +3 -0
- package/dist/client/assets/{GitHubAccountDialog-Cqcezf6G.js → GitHubAccountDialog-CZ8O_PjD.js} +1 -1
- package/dist/client/assets/{HistoryDialog-IurkSJuU.js → HistoryDialog-DWYErBwj.js} +3 -3
- package/dist/client/assets/LatexEditor-CssVgypt.js +141 -0
- package/dist/client/assets/{PdfPreview-BTmvQDCV.js → PdfPreview-BjghzUb1.js} +1 -1
- package/dist/client/assets/{ProjectIconPickerDialog-Cbm-0YQW.js → ProjectIconPickerDialog-CqRmgFBM.js} +1 -1
- package/dist/client/assets/{ProjectNavigationDialogs-CozcEa2v.js → ProjectNavigationDialogs-BZxI3PJO.js} +1 -1
- package/dist/client/assets/ProjectSettings-CZE_xDKn.js +1 -0
- package/dist/client/assets/ProjectWorkspace-CAX3qEYr.js +32 -0
- package/dist/client/assets/{SelectionHistoryDialog-DiRKiMEt.js → SelectionHistoryDialog-CR5c3I8k.js} +2 -2
- package/dist/client/assets/{SystemMetricsDialog-DJJZueSr.js → SystemMetricsDialog-DDpFwgXh.js} +1 -1
- package/dist/client/assets/{TagManagementDialog-3c-WAWQd.js → TagManagementDialog-CXLA9h_j.js} +1 -1
- package/dist/client/assets/WordCountDialog-DUyR24vv.js +1 -0
- package/dist/client/assets/check-CwBYzomT.js +1 -0
- package/dist/client/assets/chevron-up-D5lCNKlk.js +1 -0
- package/dist/client/assets/chktex-CRkLYKcV.js +3 -0
- package/dist/client/assets/{citationLibrary-ZeQPCv5O.js → citationLibrary-C9WnXB-1.js} +2 -2
- package/dist/client/assets/{external-link-DGfNJFKy.js → external-link-C9Td1CCj.js} +1 -1
- package/dist/client/assets/{github-DJezB5ef.js → github-D-JDXb-w.js} +1 -1
- package/dist/client/assets/{hard-drive-B9h-a7KY.js → hard-drive-Ctj3K_zx.js} +1 -1
- package/dist/client/assets/{index-DmBKxZf9.js → index-9hnQ8Q9x.js} +1 -1
- package/dist/client/assets/index-C0qg2Ylw.css +1 -0
- package/dist/client/assets/index-DkpU9Fgs.js +10 -0
- package/dist/client/assets/index-_eYe7K9T.js +1 -0
- package/dist/client/assets/{minimize-2-Crq_SyYM.js → minimize-2-BiVyoWZA.js} +1 -1
- package/dist/client/assets/{minus-Dn3USloe.js → minus-Bl8l4LXq.js} +1 -1
- package/dist/client/assets/{plus-BwKRQJHI.js → plus-CCxK-HNt.js} +1 -1
- package/dist/client/assets/{refresh-cw-C5yVKb1r.js → refresh-cw-BE8IbaHI.js} +1 -1
- package/dist/client/assets/{search-CDyQWr9H.js → search-CPbhRWQE.js} +1 -1
- package/dist/client/assets/{sigma-9fiQHdlo.js → sigma-LxGD9tK2.js} +1 -1
- package/dist/client/assets/spellCheck-hpm8qZTr.js +1 -0
- package/dist/client/assets/{tags-C_3BvsxV.js → tags-DuN89PsZ.js} +1 -1
- package/dist/client/assets/{type-CnT0mBxu.js → type-BiettCiY.js} +1 -1
- package/dist/client/assets/{x-DN0Ol4Ya.js → x-C_3swJOC.js} +1 -1
- package/dist/client/index.html +3 -3
- package/dist/client/texlite-icon.svg +8 -0
- package/dist/server/auth.js +0 -3
- package/dist/server/chktex.js +3 -4
- package/dist/server/i18n.js +4 -0
- package/dist/server/latexCompletion.js +11 -88
- package/dist/server/projectOutline.js +4 -39
- package/dist/server/projectSearch.js +0 -4
- package/dist/server/routes/citations.js +22 -0
- package/dist/server/routes/users.js +21 -3
- package/dist/shared/bibtexReferences.js +5 -1
- package/dist/shared/latexCompletion.js +1 -0
- package/dist/shared/latexReferences.js +13 -3
- package/dist/shared/latexSymbols.js +77 -0
- package/package.json +1 -1
- package/dist/client/assets/AdminUsers-Cau9nlv9.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-Cf_bbSq3.js +0 -1
- package/dist/client/assets/Dashboard-JQ8pJe2d.js +0 -2
- package/dist/client/assets/GitDialog-BcqqWKr-.js +0 -3
- package/dist/client/assets/LatexEditor-msdbtTyG.js +0 -141
- package/dist/client/assets/ProjectSettings-BlthcpdA.js +0 -1
- package/dist/client/assets/ProjectWorkspace-DUPLJCQ3.js +0 -32
- package/dist/client/assets/WordCountDialog-BqlX2s36.js +0 -1
- package/dist/client/assets/check-EZ2H-iDj.js +0 -1
- package/dist/client/assets/chktex-CZIYuMLb.js +0 -3
- package/dist/client/assets/index-BgeOKYIx.js +0 -10
- package/dist/client/assets/index-CMBalIBd.css +0 -1
- package/dist/client/assets/spellCheck-BCpcq-VN.js +0 -1
- package/dist/client/assets/user-plus-pxz36w4w.js +0 -1
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./spellCheck-BCpcq-VN.js","./index-BgeOKYIx.js","./react-CltQJflK.js","./index-CMBalIBd.css","./check-EZ2H-iDj.js","./x-DN0Ol4Ya.js","./search-CDyQWr9H.js","./user-plus-pxz36w4w.js","./refresh-cw-C5yVKb1r.js","./chktex-CZIYuMLb.js","./LatexEditor-msdbtTyG.js","./editor-CLY5CgkY.js","./CitationLibraryDialog-Cf_bbSq3.js","./citationLibrary-ZeQPCv5O.js","./plus-BwKRQJHI.js","./tags-C_3BvsxV.js","./GitDialog-BcqqWKr-.js","./github-DJezB5ef.js","./external-link-DGfNJFKy.js","./minus-Dn3USloe.js","./minimize-2-Crq_SyYM.js","./HistoryDialog-IurkSJuU.js","./index-DmBKxZf9.js","./hard-drive-B9h-a7KY.js","./SelectionHistoryDialog-DiRKiMEt.js","./ProjectNavigationDialogs-CozcEa2v.js","./ProjectSettings-BlthcpdA.js","./type-CnT0mBxu.js","./sigma-9fiQHdlo.js","./WordCountDialog-BqlX2s36.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as Le,s as ir,h as Se,g as xe,A as No,a as cs,n as Fw,l as Iw,r as $w,_ as $t,S as Uw,d as gt,i as Rs,k as rf,u as He,m as wr,o as Ot,p as Ne,q as It,t as zr,v as Da,w as sf,x as of,C as _s,M as Ln,e as cf,y as zw}from"./index-BgeOKYIx.js";import{r as u,u as Qe,j as a,P as ii,d as ja,R as br,a as Kn,b as af,T as Bw,e as Ww}from"./react-CltQJflK.js";import{C as Vw}from"./check-EZ2H-iDj.js";import{f as Hw,U as Mo,B as qw,M as Kw,G as Gw,X as $n,e as ci,j as Mc,b as Jw,c as _u,N as Yw,d as lf,F as Xw,g as Tu,h as Zw,k as Gt,C as _a,a as Qw,T as dr,L as eb,S as Fc,D as Fo,E as tb,P as nb,A as Ts,i as rb}from"./x-DN0Ol4Ya.js";import{S as sb}from"./search-CDyQWr9H.js";import{U as ob}from"./user-plus-pxz36w4w.js";import{R as ib}from"./refresh-cw-C5yVKb1r.js";const cb=Le("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);const ab=Le("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);const lb=Le("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);const qs=Le("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);const ub=Le("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);const Ic=Le("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);const Ta=Le("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 Pu=Le("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);const $c=Le("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 db=Le("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 fb=Le("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 hb=Le("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 pb=Le("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 mb=Le("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 gb=Le("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 yb=Le("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 wb=Le("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 uf=Le("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 Au=Le("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 bb=Le("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 xb=Le("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 vb=Le("List",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);const Ou=Le("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 df=Le("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 ff=Le("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 Sb=Le("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 Cb=Le("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);const Eb=Le("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);const kb=Le("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);const Rb=Le("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 Db=Le("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 jb=Le("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 _b=Le("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 Tb=Le("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"}]]),Pb="wrap = false",Uc=[{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'}],Nt={font:"jetbrains",fontSize:14,lineHeight:1.65,lineWrapping:!0,showTooltips:!1,spellCheck:!0,mathPreviewOnHover:!1,vimMode:!1,formatOnCompile:!1,texFmtConfig:Pb,texFmtConfigInitialized:!0,openFilesInTabs:!1},Ab="texlite-editor-preferences";function hf(t,e){return ir(`${Ab}:${encodeURIComponent(t)}:${encodeURIComponent(e)}`)}function vj(t){return Uc.find(e=>e.id===t)?.stack??Uc[0].stack}function Lu(t,e){try{const n=JSON.parse(localStorage.getItem(hf(t,e))??"{}"),r=typeof n.texFmtConfig=="string"&&n.texFmtConfig.length<=16*1024?n.texFmtConfig:null,s=r!==null&&(n.texFmtConfigInitialized===!0||r.trim().length>0)?r:Nt.texFmtConfig;return{font:Uc.some(o=>o.id===n.font)?n.font:Nt.font,fontSize:[12,13,14,15,16,18,20].includes(Number(n.fontSize))?Number(n.fontSize):Nt.fontSize,lineHeight:[1.45,1.65,1.85].includes(Number(n.lineHeight))?Number(n.lineHeight):Nt.lineHeight,lineWrapping:typeof n.lineWrapping=="boolean"?n.lineWrapping:Nt.lineWrapping,showTooltips:typeof n.showTooltips=="boolean"?n.showTooltips:Nt.showTooltips,spellCheck:typeof n.spellCheck=="boolean"?n.spellCheck:Nt.spellCheck,mathPreviewOnHover:typeof n.mathPreviewOnHover=="boolean"?n.mathPreviewOnHover:Nt.mathPreviewOnHover,vimMode:typeof n.vimMode=="boolean"?n.vimMode:Nt.vimMode,formatOnCompile:typeof n.formatOnCompile=="boolean"?n.formatOnCompile:Nt.formatOnCompile,texFmtConfig:s,texFmtConfigInitialized:!0,openFilesInTabs:typeof n.openFilesInTabs=="boolean"?n.openFilesInTabs:Nt.openFilesInTabs}}catch{return Nt}}function Ob(t,e,n){localStorage.setItem(hf(t,e),JSON.stringify(n))}function Lb(){let t={status:"loading",error:""};const e=new Set,n=(r,s="")=>{if(!(t.status===r&&t.error===s)){t={status:r,error:s};for(const o of e)o()}};return{getSnapshot:()=>t,subscribe:r=>(e.add(r),()=>e.delete(r)),loading:()=>n("loading"),working:()=>n("working"),failed:r=>n("error",r instanceof Error?r.message:String(r))}}const Mn=Lb(),Nb=/\.(?:tex|bib|cls|sty)$/i,pf=3e4;let Kt=null,Io=!1,cr=null,Mb=1;const fr=new Map,$o=[];let Br=null,Es=null;class At extends Error{constructor(e,n){super(n),this.kind=e,this.name="TexFmtError"}kind}function oc(t){return t instanceof At}function wn(t){Kt?.terminate(),Kt=null,Io=!1,cr!==null&&window.clearTimeout(cr),cr=null,Br=null,$o.length=0,Es=null,Mn.failed(t);for(const e of fr.values())e.timeout!==null&&window.clearTimeout(e.timeout),e.reject(t);fr.clear()}function Ds(){if(Br!==null||$o.length===0)return;let t;try{t=Fb()}catch(r){wn(r instanceof At?r:new At("load","The bundled tex-fmt formatter could not be loaded."));return}if(!Io)return;const e=$o.shift();if(e===void 0)return;const n=fr.get(e);if(!n){Ds();return}Br=e,n.timeout=window.setTimeout(()=>{Br===e&&wn(new At("result","The formatter did not respond within 30 seconds."))},pf);try{t.postMessage({...n.request,id:e})}catch{wn(new At("load","The formatter worker could not receive the source."))}}function Fb(){if(Kt)return Kt;if(typeof Worker>"u"){const t=new At("load","This browser does not support formatter workers.");throw Mn.failed(t),t}Mn.loading();try{Kt=new Worker(new URL(""+new URL("latexFormatterWorker-BRmsns8a.js",import.meta.url).href,import.meta.url),{type:"module",name:"texlite-latex-formatter"}),cr=window.setTimeout(()=>{Io||wn(new At("load","The formatter did not finish loading within 30 seconds."))},pf)}catch{const t=new At("load","The bundled tex-fmt formatter could not be loaded.");throw Mn.failed(t),t}return Kt.onmessage=t=>{const e=t.data;if(e&&"type"in e){e.type==="ready"&&(Io=!0,cr!==null&&window.clearTimeout(cr),cr=null,Ds());return}if(!e||typeof e.id!="number"){wn(new At("result","The formatter worker returned an invalid response."));return}const n=fr.get(e.id);if(n)if(fr.delete(e.id),n.timeout!==null&&window.clearTimeout(n.timeout),Br===e.id&&(Br=null),e.ok)Mn.working(),n.resolve(e.result),Ds();else{const r=new At(e.kind,e.message);e.kind==="format"?(Mn.working(),n.reject(r),Ds()):(n.reject(r),wn(r))}},Kt.onerror=()=>{wn(new At("load","The bundled tex-fmt formatter could not be loaded."))},Kt.onmessageerror=()=>{wn(new At("result","The formatter worker returned an unreadable response."))},Kt}function Pa(t){const e=Mb++;return new Promise((n,r)=>{fr.set(e,{request:t,resolve:n,reject:r,timeout:null}),$o.push(e),Ds()})}function Ib(t,e=""){return Pa({action:"format",source:t,config:e})}async function $b(){Kt&&Mn.getSnapshot().status==="working"||(Es||(Es=Pa({action:"probe"}).then(()=>{}).finally(()=>{Es=null})),await Es)}async function Sj(){(Kt||fr.size)&&wn(new At("load","The formatter runtime was reloaded.")),Mn.loading(),await $b()}function yo(t){return Nb.test(t)}function Ub(t){return t.match(/(?:\r?\n)+$/)?.[0]??""}function zb(t,e){const n=Ub(t),i=(n?t.slice(0,-n.length):t).split(/\r?\n/).find(d=>d.trim())?.match(/^[\t ]*/)?.[0]??"",c=e.replace(/(?:\r?\n)+$/,"");return`${i?c.split(`
|
|
3
|
-
`).map(d=>d&&`${i}${d}`).join(`
|
|
4
|
-
`):c}${n}`}async function ic(t,e,n=0){return Pa({action:"diff",source:t,formatted:e,baseOffset:n})}function Bb(t,e=null){const n=Nu(t),s=e==="succeeded"||e===null&&Vb(t)?[]:Mu(n.filter(Fu)),o=Nu(Wb(t));return{warnings:Mu(o.filter(c=>!Fu(c)&&Hb(c))),errors:s}}function Nu(t){return t.split(`
|
|
5
|
-
`).map(e=>e.trim()).filter(Boolean)}function Mu(t){return[...new Set(t)]}function Wb(t){const e=/^Running ['"][^\n]*(?:pdf|xe|lua)latex(?:\s|['"])[^\n]*$/gim;let n=-1;for(const r of t.matchAll(e))n=r.index;return n>=0?t.slice(n):t}function Vb(t){return/Latexmk: All targets .* are up-to-date/i.test(t)&&/Output written on .*\.pdf/i.test(t)}function Fu(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 Hb(t){return/\bwarnings?\b|overfull|underfull|badness/i.test(t)}const Iu=1,$u=2,cc=4,ac=8,Ps=32,bn=64,St=128,qb=1<<29,ai=31,zc=63,ur=127,Kb=2147483647,tn=(t,e)=>t>>>e|t<<32-e,Gb=t=>tn(t,2)^tn(t,13)^tn(t,22),Jb=t=>tn(t,6)^tn(t,11)^tn(t,25),Yb=t=>tn(t,7)^tn(t,18)^t>>>3,Xb=t=>tn(t,17)^tn(t,19)^t>>>10,Zb=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]),Qb=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);class ex{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Qb),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,n=this._W;for(let f=16;f<64;f++)n[f]=Xb(n[f-2])+n[f-7]+Yb(n[f-15])+n[f-16];let r=e[0],s=e[1],o=e[2],i=e[3],c=e[4],l=e[5],d=e[6],h=e[7];for(let f=0,p,m;f<64;f++)p=h+Jb(c)+(c&l^~c&d)+Zb[f]+n[f]>>>0,m=Gb(r)+(r&s^r&o^s&o)>>>0,h=d,d=l,l=c,c=i+p>>>0,i=o,o=s,s=r,r=p+m>>>0;e[0]+=r,e[1]+=s,e[2]+=o,e[3]+=i,e[4]+=c,e[5]+=l,e[6]+=d,e[7]+=h}digest(e){let n=0;for(;n+56<=e.length;){let i=0;for(;i<16&&n+3<e.length;i++)this._W[i]=e[n++]<<24|e[n++]<<16|e[n++]<<8|e[n++];if(n%64!==0){for(this._W.fill(0,i,16);n<e.length;)this._W[i]|=e[n]<<(3-n%4)*8,n++;this._W[i]|=St<<(3-n%4)*8}this._updateHash()}const r=n%64!==0;this._W.fill(0,0,16);let s=0;for(;n<e.length;s++)for(let i=3;i>=0&&n<e.length;i--)this._W[s]|=e[n++]<<i*8;r||(this._W[s-(n%4===0?0:1)]|=St<<(3-n%4)*8),this._W[14]=e.byteLength/qb,this._W[15]=e.byteLength*8,this._updateHash();const o=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let c=0;c<4;c++)o[i*4+c]=this._H[i]>>>(3-c)*8;return o}}const tx=t=>new ex().digest(t);function nx(t){return Array.from(tx(new TextEncoder().encode(t)),e=>e.toString(16).padStart(2,"0")).join("")}const Uu=Object.freeze({});class rx{threads=new Map;listeners=new Map;newComments=new Map;getThread(e){return this.threads.get(e)??Uu}subscribe(e,n){const r=this.listeners.get(e)??new Set;return r.add(n),this.listeners.set(e,r),()=>{r.delete(n),r.size||this.listeners.delete(e)}}publish(e,n){Object.keys(n).length?this.threads.set(e,n):this.threads.delete(e);for(const r of this.listeners.get(e)??[])r()}isPending(e){return Object.values(this.getThread(e)).some(n=>n?.pending)}open(e,n,r=""){if(this.isPending(e))return;const s={...this.getThread(e)};if(n.startsWith("edit-reply:"))for(const[i,c]of Object.entries(s))i.startsWith("edit-reply:")&&c?.open&&(s[i]={...c,open:!1});const o=s[n];s[n]={content:r,pending:!1,error:"",...o,open:!0},this.publish(e,s)}change(e,n,r){const s=this.getThread(e)[n];!s||this.isPending(e)||this.publish(e,{...this.getThread(e),[n]:{...s,content:r}})}hide(e,n){const r=this.getThread(e)[n];!r||this.isPending(e)||this.publish(e,{...this.getThread(e),[n]:{...r,open:!1}})}discard(e,n){const r={...this.getThread(e)};if(n===void 0){this.publish(e,Uu);return}delete r[n],this.publish(e,r)}async submit(e,n,r,s){const o=this.getThread(e)[n];if(!o||!o.content.trim()||this.isPending(e))return!1;const i={...o,pending:!0,error:""};this.publish(e,{...this.getThread(e),[n]:i});let c=s;try{if(await r(o.content))return this.getThread(e)[n]===i&&this.discard(e,n),!0}catch(l){c=Se(l)}return this.getThread(e)[n]===i&&this.publish(e,{...this.getThread(e),[n]:{...o,pending:!1,error:c}}),!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 sx(t,e,n){const r=n instanceof No&&[401,403,404].includes(n.status);return{filePath:e,comments:!r&&t.filePath===e?t.comments:[],loading:!1,error:Se(n)}}function zu(t){return t instanceof Error&&t.name==="AbortError"}function ox({projectId:t,activeFile:e,content:n,permission:r,revision:s,selection:o,save:i,saveFailureMessage:c,onError:l,onAdded:d,onChanged:h}){const f=u.useMemo(()=>new rx,[t]),[p,m]=u.useState({filePath:"",comments:[],loading:!1,error:""}),[g,y]=u.useState([]),[C,v]=u.useState(!1),[D,b]=u.useState(""),[w,R]=u.useState("file"),[S,E]=u.useState(null),[j,P]=u.useState(!1),[$,J]=u.useState(""),[T,V]=u.useState(null),[U,B]=u.useState(null),[z,re]=u.useState(!1),[H,X]=u.useState(!1),[Q,Z]=u.useState(""),ge=u.useRef(null),ye=u.useRef(null),Ce=u.useRef(!1),_e=u.useRef(e),A=u.useRef(w),q=u.useRef(i),fe=u.useRef(l),W=u.useRef(d),ee=u.useRef(h),Ee=u.useRef(T),pe=u.useRef($);Ee.current=T,pe.current=$,_e.current=e,A.current=w,q.current=i,fe.current=l,W.current=d,ee.current=h;const K=p.filePath===e?p.comments:[],ae=p.filePath,L=ae===e?p.error:"",Re=!!e&&(ae!==e||p.loading),Fe=ae===e&&!p.loading&&!L,Te=async G=>{ge.current?.abort();const le=new AbortController;ge.current=le,_e.current===G&&m(Oe=>Oe.filePath===G?{...Oe,loading:!0,error:""}:{filePath:"",comments:[],loading:!0,error:""});try{const Oe=await xe(`/api/projects/${t}/comments?path=${encodeURIComponent(G)}`,{signal:le.signal});ge.current===le&&_e.current===G&&m({filePath:G,comments:Oe.comments,loading:!1,error:""})}catch(Oe){!zu(Oe)&&ge.current===le&&_e.current===G&&m(ce=>sx(ce,G,Oe))}finally{ge.current===le&&(ge.current=null)}},Ue=()=>_e.current?Te(_e.current):Promise.resolve(),de=async()=>{ye.current?.abort();const G=new AbortController;ye.current=G,A.current==="project"&&(v(!0),b(""));try{const le=await xe(`/api/projects/${t}/comments?scope=project`,{signal:G.signal});ye.current===G&&A.current==="project"&&y(le.comments)}catch(le){!zu(le)&&ye.current===G&&A.current==="project"&&b(Se(le))}finally{ye.current===G&&(ye.current=null,A.current==="project"&&v(!1))}};u.useEffect(()=>{ge.current?.abort(),ge.current=null,ye.current?.abort(),ye.current=null,E(null),m({filePath:"",comments:[],loading:!1,error:""}),y([]),v(!1),b(""),R("file"),P(!1),V(null),B(null),J(""),re(!1),Z("")},[t]),u.useEffect(()=>{P(!1),V(null),B(null),J(""),re(!1),Z("")},[e]),u.useEffect(()=>(e?Te(e):m({filePath:"",comments:[],loading:!1,error:""}),()=>{ge.current?.abort(),ge.current=null}),[t,e,s]),u.useEffect(()=>{if(w!=="project"){ye.current?.abort(),ye.current=null,y([]),v(!1),b("");return}return de(),()=>{ye.current?.abort(),ye.current=null}},[t,w,s]);const ve=async G=>{const le=[];_e.current===G&&le.push(Te(G)),A.current==="project"&&le.push(de()),await Promise.all(le)},We=(G,le)=>{if(!e)return;Z("");const Oe={filePath:e,selection:{...G??o},sourceHash:nx(le??n)},ce=f.getNew(e);V(ce??Oe),J(ce?.content??""),B(Oe),re(!!ce),P(!0)},Me=G=>{J(G),T&&(G?f.setNew({...T,content:G}):f.discardNew(T.filePath))},ke=()=>{Ce.current||(P(!1),Z(""))},O=()=>{Ce.current||(T&&f.discardNew(T.filePath),J(""),V(null),B(null),re(!1),ke())},Pe=()=>{Ce.current||!U||U.filePath!==_e.current||(V(U),$&&f.setNew({...U,content:$}),re(!1),Z(""))},Je=async()=>{const G=T,le=$;if(!$.trim()||!G||Ce.current)return;const Oe=()=>{const ce=Ee.current;return ce?.filePath===G.filePath&&ce.sourceHash===G.sourceHash&&ce.selection.startOffset===G.selection.startOffset&&ce.selection.endOffset===G.selection.endOffset&&pe.current===le};Ce.current=!0,X(!0),Z("");try{if(r!=="read"&&!await q.current()){Oe()&&Z(c);return}await xe(`/api/projects/${t}/comments`,{method:"POST",body:JSON.stringify({path:G.filePath,content:le,...G.selection,sourceHash:G.sourceHash})}),await ve(G.filePath);const ce=f.getNew(G.filePath);ce?.content===le&&ce.sourceHash===G.sourceHash&&ce.selection.startOffset===G.selection.startOffset&&ce.selection.endOffset===G.selection.endOffset&&f.discardNew(G.filePath),Oe()&&(P(!1),V(null),J(""),re(!1)),W.current(),ee.current?.()}catch(ce){Oe()&&Z(Se(ce))}finally{Ce.current=!1,X(!1)}},it=async G=>{try{await xe(`/api/projects/${t}/comments/${G.id}`,{method:"PATCH",body:JSON.stringify({resolved:!G.resolved})}),await ve(G.filePath),ee.current?.()}catch(le){fe.current(Se(le))}},we=async(G,le)=>(await xe(`/api/projects/${t}/comments/${G.id}/replies`,{method:"POST",body:JSON.stringify({content:le})}),await ve(G.filePath),ee.current?.(),!0),Y=async(G,le)=>(await xe(`/api/projects/${t}/comments/${G.id}`,{method:"PATCH",body:JSON.stringify({content:le})}),await ve(G.filePath),ee.current?.(),!0),se=async G=>{try{return await xe(`/api/projects/${t}/comments/${G.id}`,{method:"DELETE"}),await ve(G.filePath),E(le=>le?.id===G.id?null:le),f.discard(G.id),ee.current?.(),!0}catch(le){return fe.current(Se(le)),!1}},De=async(G,le,Oe)=>(await xe(`/api/projects/${t}/comments/${G.id}/replies/${le}`,{method:"PATCH",body:JSON.stringify({content:Oe})}),await ve(G.filePath),ee.current?.(),!0),ze=async(G,le)=>{try{return await xe(`/api/projects/${t}/comments/${G.id}/replies/${le}`,{method:"DELETE"}),await ve(G.filePath),f.discard(G.id,`edit-reply:${le}`),ee.current?.(),!0}catch(Oe){return fe.current(Se(Oe)),!1}};return{commentDraftStore:f,comments:K,commentsFilePath:ae,commentsReady:Fe,fileCommentsLoading:Re,fileCommentsError:L,retryFileComments:Ue,reviewComments:w==="file"?K:g,reviewCommentsLoading:w==="project"?C:Re,reviewCommentsError:w==="project"?D:L,retryReviewComments:w==="project"?de:Ue,commentScope:w,setCommentScope:R,focusComment:S,setFocusComment:E,commentOpen:j,openComment:We,closeComment:ke,cancelComment:O,commentDraftRestored:z,commentDraftCanRetarget:!!(T&&U&&(T.sourceHash!==U.sourceHash||T.selection.startOffset!==U.selection.startOffset||T.selection.endOffset!==U.selection.endOffset)),useCurrentCommentSelection:Pe,commentText:$,setCommentText:Me,commentSelection:T?.selection??o,commentSubmitting:H,commentError:Q,addComment:Je,toggleComment:it,replyToComment:we,editComment:Y,deleteComment:se,editCommentReply:De,deleteCommentReply:ze}}function ix(t){const e=new Map;for(const n of t)for(const r of[n,...n.replies])e.has(r.authorId)||e.set(r.authorId,{authorId:r.authorId,authorUsername:r.authorUsername,authorDisplayName:r.authorDisplayName});return[...e.values()].sort((n,r)=>(n.authorDisplayName??n.authorUsername??"").localeCompare(r.authorDisplayName??r.authorUsername??""))}function mf(t,e){const n=e.participantIds;return n?.size?n.has(t.authorId)||!e.topLevelOnly&&t.replies.some(r=>n.has(r.authorId)):!0}function cx(t,e="source"){return[...t].sort((n,r)=>e==="time"?Date.parse(r.createdAt)-Date.parse(n.createdAt):n.filePath.localeCompare(r.filePath,"en",{numeric:!0})||n.startLine-r.startLine||n.startOffset-r.startOffset)}function gf(t,e){return e.scope==="project"||t.filePath===e.activeFile}function Aa(t,e){return e==="unresolved"?!t.resolved:t.resolved}function yf(t,e){return e.some(n=>n.commentId===t.id&&n.readAt===null)}function lc(t,e){return t.filter(n=>gf(n,e)&&mf(n,e)&&Aa(n,e.filter)&&(!e.unreadMentionsOnly||yf(n,e.unreadMentions)))}function ax(t,e,n=[]){const r=new Set(n.filter(s=>!!s));return cx(t.filter(s=>gf(s,e)?r.has(s.id)||mf(s,e)&&Aa(s,e.filter)&&(!e.unreadMentionsOnly||yf(s,e.unreadMentions)):!1),e.sort)}function lx(t,e,n){const r=t.find(s=>s.id===e&&s.filePath===n&&!s.resolved);return r?[r]:[]}function ux(t,e){return t.filter(n=>n.filePath===e)}function dx(t,e,n){return!t||t.filePath!==e||n!==e?null:t}function fx(t,e,n,r,s,o){return!t||t.filePath!==e||n!==e||r!==e||!s?null:o.find(i=>i.id===t.id&&i.filePath===e)??null}function hx(t,e){if(!e)return 0;const n=t.findIndex(r=>r.id===e);return n<0?0:n+1}function px(t,e,n){if(!t.length)return null;const r=e?t.findIndex(o=>o.id===e):-1;if(r<0)return n===1?t[0]:null;const s=r+n;return s>=0&&s<t.length?t[s]:null}function mx(t){return t instanceof Error&&t.name==="AbortError"}function gx(t,e,n){const[r,s]=u.useState([]),o=u.useRef(null),i=u.useRef(n);i.current=n;const c=u.useCallback(async(h=!1)=>{o.current?.abort();const f=new AbortController;o.current=f;try{const p=await xe(`/api/projects/${t}/mentions?unread=1&limit=100`,{signal:f.signal});o.current===f&&s(p.mentions)}catch(p){o.current===f&&!mx(p)&&(s([]),h&&i.current(Se(p)))}finally{o.current===f&&(o.current=null)}},[t]);return u.useEffect(()=>(c(),()=>{o.current?.abort(),o.current=null}),[c,e]),{unreadMentions:r,refresh:c,markMentionRead:async h=>{try{return await xe(`/api/projects/${t}/mentions/${encodeURIComponent(h)}/read`,{method:"POST"}),s(f=>f.filter(p=>p.id!==h)),!0}catch(f){return i.current(Se(f)),!1}},markAllMentionsRead:async()=>{if(!r.length)return!0;try{return await xe(`/api/projects/${t}/mentions/read-all`,{method:"POST"}),s([]),!0}catch(h){return i.current(Se(h)),!1}}}}const Dt=()=>new Map,Bc=t=>{const e=Dt();return t.forEach((n,r)=>{e.set(r,n)}),e},cn=(t,e,n)=>{let r=t.get(e);return r===void 0&&t.set(e,r=n()),r},yx=(t,e)=>{const n=[];for(const[r,s]of t)n.push(e(s,r));return n},wx=(t,e)=>{for(const[n,r]of t)if(e(r,n))return!0;return!1},Bn=()=>new Set,uc=t=>t[t.length-1],bx=(t,e)=>{for(let n=0;n<e.length;n++)t.push(e[n])},Sn=Array.from,Oa=(t,e)=>{for(let n=0;n<t.length;n++)if(!e(t[n],n,t))return!1;return!0},La=(t,e)=>{for(let n=0;n<t.length;n++)if(e(t[n],n,t))return!0;return!1},xx=(t,e)=>{const n=new Array(t);for(let r=0;r<t;r++)n[r]=e(r,n);return n},Zr=Array.isArray;class Na{constructor(){this._observers=Dt()}on(e,n){return cn(this._observers,e,Bn).add(n),n}once(e,n){const r=(...s)=>{this.off(e,r),n(...s)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return Sn((this._observers.get(e)||Dt()).values()).forEach(r=>r(...n))}destroy(){this._observers=Dt()}}class wf{constructor(){this._observers=Dt()}on(e,n){cn(this._observers,e,Bn).add(n)}once(e,n){const r=(...s)=>{this.off(e,r),n(...s)};this.on(e,r)}off(e,n){const r=this._observers.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(e))}emit(e,n){return Sn((this._observers.get(e)||Dt()).values()).forEach(r=>r(...n))}destroy(){this._observers=Dt()}}const Yt=Math.floor,_o=Math.abs,Ma=(t,e)=>t<e?t:e,xr=(t,e)=>t>e?t:e,vx=Math.pow,bf=t=>t!==0?t<0:1/t<0,Uo=Number.MAX_SAFE_INTEGER,Bu=Number.MIN_SAFE_INTEGER,Sx=Number.isInteger||(t=>typeof t=="number"&&isFinite(t)&&Yt(t)===t),xf=String.fromCharCode,Cx=t=>t.toLowerCase(),Ex=/^\s*/g,kx=t=>t.replace(Ex,""),Rx=/([A-Z])/g,Wu=(t,e)=>kx(t.replace(Rx,n=>`${e}${Cx(n)}`)),Dx=t=>{const e=unescape(encodeURIComponent(t)),n=e.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=e.codePointAt(s);return r},As=typeof TextEncoder<"u"?new TextEncoder:null,jx=t=>As.encode(t),_x=As?jx:Dx;let js=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});js&&js.decode(new Uint8Array).length===1&&(js=null);const Tx=(t,e)=>xx(e,()=>t).join("");class Ks{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Xe=()=>new Ks,Fa=t=>{let e=t.cpos;for(let n=0;n<t.bufs.length;n++)e+=t.bufs[n].length;return e},$e=t=>{const e=new Uint8Array(Fa(t));let n=0;for(let r=0;r<t.bufs.length;r++){const s=t.bufs[r];e.set(s,n),n+=s.length}return e.set(new Uint8Array(t.cbuf.buffer,0,t.cpos),n),e},Px=(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(xr(n,e)*2),t.cpos=0)},at=(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},Wc=at,ie=(t,e)=>{for(;e>ur;)at(t,St|ur&e),e=Yt(e/128);at(t,ur&e)},Ia=(t,e)=>{const n=bf(e);for(n&&(e=-e),at(t,(e>zc?St:0)|(n?bn:0)|zc&e),e=Yt(e/64);e>0;)at(t,(e>ur?St:0)|ur&e),e=Yt(e/128)},Vc=new Uint8Array(3e4),Ax=Vc.length/3,Ox=(t,e)=>{if(e.length<Ax){const n=As.encodeInto(e,Vc).written||0;ie(t,n);for(let r=0;r<n;r++)at(t,Vc[r])}else Ye(t,_x(e))},Lx=(t,e)=>{const n=unescape(encodeURIComponent(e)),r=n.length;ie(t,r);for(let s=0;s<r;s++)at(t,n.codePointAt(s))},mt=As&&As.encodeInto?Ox:Lx,li=(t,e)=>{const n=t.cbuf.length,r=t.cpos,s=Ma(n-r,e.length),o=e.length-s;t.cbuf.set(e.subarray(0,s),r),t.cpos+=s,o>0&&(t.bufs.push(t.cbuf),t.cbuf=new Uint8Array(xr(n*2,o)),t.cbuf.set(e.subarray(s)),t.cpos=o)},Ye=(t,e)=>{ie(t,e.byteLength),li(t,e)},$a=(t,e)=>{Px(t,e);const n=new DataView(t.cbuf.buffer,t.cpos,e);return t.cpos+=e,n},Nx=(t,e)=>$a(t,4).setFloat32(0,e,!1),Mx=(t,e)=>$a(t,8).setFloat64(0,e,!1),Fx=(t,e)=>$a(t,8).setBigInt64(0,e,!1),Vu=new DataView(new ArrayBuffer(4)),Ix=t=>(Vu.setFloat32(0,t),Vu.getFloat32(0)===t),Os=(t,e)=>{switch(typeof e){case"string":at(t,119),mt(t,e);break;case"number":Sx(e)&&_o(e)<=Kb?(at(t,125),Ia(t,e)):Ix(e)?(at(t,124),Nx(t,e)):(at(t,123),Mx(t,e));break;case"bigint":at(t,122),Fx(t,e);break;case"object":if(e===null)at(t,126);else if(Zr(e)){at(t,117),ie(t,e.length);for(let n=0;n<e.length;n++)Os(t,e[n])}else if(e instanceof Uint8Array)at(t,116),Ye(t,e);else{at(t,118);const n=Object.keys(e);ie(t,n.length);for(let r=0;r<n.length;r++){const s=n[r];mt(t,s),Os(t,e[s])}}break;case"boolean":at(t,e?120:121);break;default:at(t,127)}};class Hu extends Ks{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ie(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const qu=t=>{t.count>0&&(Ia(t.encoder,t.count===1?t.s:-t.s),t.count>1&&ie(t.encoder,t.count-2))};class To{constructor(){this.encoder=new Ks,this.s=0,this.count=0}write(e){this.s===e?this.count++:(qu(this),this.count=1,this.s=e)}toUint8Array(){return qu(this),$e(this.encoder)}}const Ku=t=>{if(t.count>0){const e=t.diff*2+(t.count===1?0:1);Ia(t.encoder,e),t.count>1&&ie(t.encoder,t.count-2)}};class dc{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++):(Ku(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Ku(this),$e(this.encoder)}}class $x{constructor(){this.sarr=[],this.s="",this.lensE=new To}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="",mt(e,this.sarr.join("")),li(e,this.lensE.toUint8Array()),$e(e)}}const Xt=t=>new Error(t),Jt=()=>{throw Xt("Method unimplemented")},Lt=()=>{throw Xt("Unexpected case")},vf=Xt("Unexpected end of array"),Sf=Xt("Integer out of Range");class ui{constructor(e){this.arr=e,this.pos=0}}const Gn=t=>new ui(t),Hc=t=>t.pos!==t.arr.length,Ux=(t,e)=>{const n=new Uint8Array(t.arr.buffer,t.pos+t.arr.byteOffset,e);return t.pos+=e,n},xt=t=>Ux(t,be(t)),Qr=t=>t.arr[t.pos++],be=t=>{let e=0,n=1;const r=t.arr.length;for(;t.pos<r;){const s=t.arr[t.pos++];if(e=e+(s&ur)*n,n*=128,s<St)return e;if(e>Uo)throw Sf}throw vf},Ua=t=>{let e=t.arr[t.pos++],n=e&zc,r=64;const s=(e&bn)>0?-1:1;if((e&St)===0)return s*n;const o=t.arr.length;for(;t.pos<o;){if(e=t.arr[t.pos++],n=n+(e&ur)*r,r*=128,e<St)return s*n;if(n>Uo)throw Sf}throw vf},zx=t=>{let e=be(t);if(e===0)return"";{let n=String.fromCodePoint(Qr(t));if(--e<100)for(;e--;)n+=String.fromCodePoint(Qr(t));else for(;e>0;){const r=e<1e4?e:1e4,s=t.arr.subarray(t.pos,t.pos+r);t.pos+=r,n+=String.fromCodePoint.apply(null,s),e-=r}return decodeURIComponent(escape(n))}},Bx=t=>js.decode(xt(t)),Ge=js?Bx:zx,za=(t,e)=>{const n=new DataView(t.arr.buffer,t.arr.byteOffset+t.pos,e);return t.pos+=e,n},Wx=t=>za(t,4).getFloat32(0,!1),Vx=t=>za(t,8).getFloat64(0,!1),Hx=t=>za(t,8).getBigInt64(0,!1),qx=[t=>{},t=>null,Ua,Wx,Vx,Hx,t=>!1,t=>!0,Ge,t=>{const e=be(t),n={};for(let r=0;r<e;r++){const s=Ge(t);n[s]=Ls(t)}return n},t=>{const e=be(t),n=[];for(let r=0;r<e;r++)n.push(Ls(t));return n},xt],Ls=t=>qx[127-Qr(t)](t);class Gu extends ui{constructor(e,n){super(e),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Hc(this)?this.count=be(this)+1:this.count=-1),this.count--,this.s}}class Po extends ui{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ua(this);const e=bf(this.s);this.count=1,e&&(this.s=-this.s,this.count=be(this)+2)}return this.count--,this.s}}class fc extends ui{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const e=Ua(this),n=e&1;this.diff=Yt(e/2),this.count=1,n&&(this.count=be(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Kx{constructor(e){this.decoder=new Po(e),this.str=Ge(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 Gx=crypto.getRandomValues.bind(crypto),Cf=()=>Gx(new Uint32Array(1))[0],Jx="10000000-1000-4000-8000"+-1e11,Yx=()=>Jx.replace(/[018]/g,t=>(t^Cf()&15>>t/4).toString(16)),Wn=Date.now,es=t=>new Promise(t);Promise.all.bind(Promise);const Ju=t=>t===void 0?null:t;class Xx{constructor(){this.map=new Map}setItem(e,n){this.map.set(e,n)}getItem(e){return this.map.get(e)}}let Ef=new Xx,Ba=!0;try{typeof localStorage<"u"&&localStorage&&(Ef=localStorage,Ba=!1)}catch{}const kf=Ef,Zx=t=>Ba||addEventListener("storage",t),Qx=t=>Ba||removeEventListener("storage",t),Ns=Symbol("Equality"),Rf=(t,e)=>t===e||!!t?.[Ns]?.(e)||!1,ev=t=>typeof t=="object",tv=Object.assign,nv=Object.keys,rv=(t,e)=>{for(const n in t)e(t[n],n)},sv=(t,e)=>{const n=[];for(const r in t)n.push(e(t[r],r));return n},zo=t=>nv(t).length,ov=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},Wa=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),iv=(t,e)=>t===e||zo(t)===zo(e)&&Gs(t,(n,r)=>(n!==void 0||Wa(e,r))&&Rf(e[r],n)),cv=Object.freeze,Df=t=>{for(const e in t){const n=t[e];(typeof n=="object"||typeof n=="function")&&Df(t[e])}return cv(t)},Va=(t,e,n=0)=>{try{for(;n<t.length;n++)t[n](...e)}finally{n<t.length&&Va(t,e,n+1)}},av=t=>t,Wr=(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[Ns]!=null)return t[Ns](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)||!Wr(t.get(n),e.get(n)))return!1;break}case void 0:case Object:if(zo(t)!==zo(e))return!1;for(const n in t)if(!Wa(t,n)||!Wr(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(!Wr(t[n],e[n]))return!1;break;default:return!1}return!0},lv=(t,e)=>e.includes(t);var jf={};const Vn=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",_f=typeof window<"u"&&typeof document<"u"&&!Vn;let Qt;const uv=()=>{if(Qt===void 0)if(Vn){Qt=Dt();const t=process.argv;let e=null;for(let n=0;n<t.length;n++){const r=t[n];r[0]==="-"?(e!==null&&Qt.set(e,""),e=r):e!==null&&(Qt.set(e,r),e=null)}e!==null&&Qt.set(e,"")}else typeof location=="object"?(Qt=Dt(),(location.search||"?").slice(1).split("&").forEach(t=>{if(t.length!==0){const[e,n]=t.split("=");Qt.set(`--${Wu(e,"-")}`,n),Qt.set(`-${Wu(e,"-")}`,n)}})):Qt=Dt();return Qt},qc=t=>uv().has(t),Bo=t=>Ju(Vn?jf[t.toUpperCase().replaceAll("-","_")]:kf.getItem(t)),Tf=t=>qc("--"+t)||Bo(t)!==null,dv=Tf("production"),fv=Vn&&lv(jf.FORCE_COLOR,["true","1","2"]),hv=fv||!qc("--no-colors")&&!Tf("no-color")&&(!Vn||process.stdout.isTTY)&&(!Vn||qc("--color")||Bo("COLORTERM")!==null||(Bo("TERM")||"").includes("color")),Pf=t=>new Uint8Array(t),pv=(t,e,n)=>new Uint8Array(t,e,n),mv=t=>new Uint8Array(t),gv=t=>{let e="";for(let n=0;n<t.byteLength;n++)e+=xf(t[n]);return btoa(e)},yv=t=>Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("base64"),wv=t=>{const e=atob(t),n=Pf(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n},bv=t=>{const e=Buffer.from(t,"base64");return pv(e.buffer,e.byteOffset,e.byteLength)},xv=_f?gv:yv,vv=_f?wv:bv,Sv=t=>{const e=Pf(t.byteLength);return e.set(t),e};class Cv{constructor(e,n){this.left=e,this.right=n}}const pn=(t,e)=>new Cv(t,e),Ev=(t,e)=>t.forEach(n=>e(n.left,n.right)),Yu=t=>t.next()>=.5,hc=(t,e,n)=>Yt(t.next()*(n+1-e)+e),Af=(t,e,n)=>Yt(t.next()*(n+1-e)+e),Ha=(t,e,n)=>Af(t,e,n),kv=t=>xf(Ha(t,97,122)),Rv=(t,e=0,n=20)=>{const r=Ha(t,e,n);let s="";for(let o=0;o<r;o++)s+=kv(t);return s},pc=(t,e)=>e[Ha(t,0,e.length-1)],Dv=Symbol("0schema");class jv{constructor(){this._rerrs=[]}extend(e,n,r,s=null){this._rerrs.push({path:e,expected:n,has:r,message:s})}toString(){const e=[];for(let n=this._rerrs.length-1;n>0;n--){const r=this._rerrs[n];e.push(Tx(" ",(this._rerrs.length-n)*2)+`${r.path!=null?`[${r.path}] `:""}${r.has} doesn't match ${r.expected}. ${r.message}`)}return e.join(`
|
|
6
|
-
`)}}const Kc=(t,e)=>t===e?!0:t==null||e==null||t.constructor!==e.constructor?!1:t[Ns]?Rf(t,e):Zr(t)?Oa(t,n=>La(e,r=>Kc(n,r))):ev(t)?Gs(t,(n,r)=>Kc(n,e[r])):!1;class Ct{static _dilutes=!1;extends(e){let[n,r]=[this.shape,e.shape];return this.constructor._dilutes&&([r,n]=[n,r]),Kc(n,r)}equals(e){return this.constructor===e.constructor&&Wr(this.shape,e.shape)}[Dv](){return!0}[Ns](e){return this.equals(e)}validate(e){return this.check(e)}check(e,n){Jt()}get nullable(){return as(this,mi)}get optional(){return new Nf(this)}cast(e){return Xu(e,this),e}expect(e){return Xu(e,this),e}}class qa extends Ct{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n=void 0){const r=e?.constructor===this.shape&&(this._c==null||this._c(e));return!r&&n?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),r}}const ot=(t,e=null)=>new qa(t,e);ot(qa);class Ka extends Ct{constructor(e){super(),this.shape=e}check(e,n){const r=this.shape(e);return!r&&n?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),r}}const ht=t=>new Ka(t);ot(Ka);class di extends Ct{constructor(e){super(),this.shape=e}check(e,n){const r=this.shape.some(s=>s===e);return!r&&n?.extend(null,this.shape.join(" | "),e.toString()),r}}const fi=(...t)=>new di(t),Of=ot(di),_v=RegExp.escape||(t=>t.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Lf=t=>{if(ts.check(t))return[_v(t)];if(Of.check(t))return t.shape.map(e=>e+"");if(Vf.check(t))return["[+-]?\\d+.?\\d*"];if(Hf.check(t))return[".*"];if(Wo.check(t))return t.shape.map(Lf).flat(1);Lt()};class Tv extends Ct{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Lf).map(n=>`(${n.join("|")})`).join("")+"$")}check(e,n){const r=this._r.exec(e)!=null;return!r&&n?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),r}}ot(Tv);const Pv=Symbol("optional");class Nf extends Ct{constructor(e){super(),this.shape=e}check(e,n){const r=e===void 0||this.shape.check(e);return!r&&n?.extend(null,"undefined (optional)","()"),r}get[Pv](){return!0}}const Av=ot(Nf);class Ov extends Ct{check(e,n){return n?.extend(null,"never",typeof e),!1}}ot(Ov);class hi extends Ct{constructor(e,n=!1){super(),this.shape=e,this._isPartial=n}static _dilutes=!0;get partial(){return new hi(this.shape,!0)}check(e,n){return e==null?(n?.extend(null,"object","null"),!1):Gs(this.shape,(r,s)=>{const o=this._isPartial&&!Wa(e,s)||r.check(e[s],n);return!o&&n?.extend(s.toString(),r.toString(),typeof e[s],"Object property does not match"),o})}}const Lv=t=>new hi(t),Nv=ot(hi),Mv=ht(t=>t!=null&&(t.constructor===Object||t.constructor==null));class Mf extends Ct{constructor(e,n){super(),this.shape={keys:e,values:n}}check(e,n){return e!=null&&Gs(e,(r,s)=>{const o=this.shape.keys.check(s,n);return!o&&n?.extend(s+"","Record",typeof e,o?"Key doesn't match schema":"Value doesn't match value"),o&&this.shape.values.check(r,n)})}}const Ff=(t,e)=>new Mf(t,e),Fv=ot(Mf);class If extends Ct{constructor(e){super(),this.shape=e}check(e,n){return e!=null&&Gs(this.shape,(r,s)=>{const o=r.check(e[s],n);return!o&&n?.extend(s.toString(),"Tuple",typeof r),o})}}const Iv=(...t)=>new If(t);ot(If);class $f extends Ct{constructor(e){super(),this.shape=e.length===1?e[0]:new Ga(e)}check(e,n){const r=Zr(e)&&Oa(e,s=>this.shape.check(s));return!r&&n?.extend(null,"Array",""),r}}const Uf=(...t)=>new $f(t),$v=ot($f),Uv=ht(t=>Zr(t));class zf extends Ct{constructor(e,n){super(),this.shape=e,this._c=n}check(e,n){const r=e instanceof this.shape&&(this._c==null||this._c(e));return!r&&n?.extend(null,this.shape.name,e?.constructor.name),r}}const zv=(t,e=null)=>new zf(t,e);ot(zf);const Bv=zv(Ct);class Wv extends Ct{constructor(e){super(),this.len=e.length-1,this.args=Iv(...e.slice(-1)),this.res=e[this.len]}check(e,n){const r=e.constructor===Function&&e.length<=this.len;return!r&&n?.extend(null,"function",typeof e),r}}const Vv=ot(Wv),Hv=ht(t=>typeof t=="function");class qv extends Ct{constructor(e){super(),this.shape=e}check(e,n){const r=Oa(this.shape,s=>s.check(e,n));return!r&&n?.extend(null,"Intersectinon",typeof e),r}}ot(qv,t=>t.shape.length>0);class Ga extends Ct{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,n){const r=La(this.shape,s=>s.check(e,n));return n?.extend(null,"Union",typeof e),r}}const as=(...t)=>t.findIndex(e=>Wo.check(e))>=0?as(...t.map(e=>Ms(e)).map(e=>Wo.check(e)?e.shape:[e]).flat(1)):t.length===1?t[0]:new Ga(t),Wo=ot(Ga),Bf=()=>!0,Vo=ht(Bf),Kv=ot(Ka,t=>t.shape===Bf),Ja=ht(t=>typeof t=="bigint"),Gv=ht(t=>t===Ja),Wf=ht(t=>typeof t=="symbol");ht(t=>t===Wf);const Vr=ht(t=>typeof t=="number"),Vf=ht(t=>t===Vr),ts=ht(t=>typeof t=="string"),Hf=ht(t=>t===ts),pi=ht(t=>typeof t=="boolean"),Jv=ht(t=>t===pi),qf=fi(void 0);ot(di,t=>t.shape.length===1&&t.shape[0]===void 0);fi(void 0);const mi=fi(null),Yv=ot(di,t=>t.shape.length===1&&t.shape[0]===null);ot(Uint8Array);ot(qa,t=>t.shape===Uint8Array);const Xv=as(Vr,ts,mi,qf,Ja,pi,Wf);(()=>{const t=Uf(Vo),e=Ff(ts,Vo),n=as(Vr,ts,mi,pi,t,e);return t.shape=n,e.shape.values=n,n})();const Ms=t=>{if(Bv.check(t))return t;if(Mv.check(t)){const e={};for(const n in t)e[n]=Ms(t[n]);return Lv(e)}else{if(Uv.check(t))return as(...t.map(Ms));if(Xv.check(t))return fi(t);if(Hv.check(t))return ot(t)}Lt()},Xu=dv?()=>{}:(t,e)=>{const n=new jv;if(!e.check(t,n))throw Xt(`Expected value to be of type ${e.constructor.name}.
|
|
7
|
-
${n.toString()}`)};class Zv{constructor(e){this.patterns=[],this.$state=e}if(e,n){return this.patterns.push({if:Ms(e),h:n}),this}else(e){return this.if(Vo,e)}done(){return(e,n)=>{for(let r=0;r<this.patterns.length;r++){const s=this.patterns[r];if(s.if.check(e))return s.h(e,n)}throw Xt("Unhandled pattern")}}}const Qv=t=>new Zv(t),Kf=Qv(Vo).if(Vf,(t,e)=>hc(e,Bu,Uo)).if(Hf,(t,e)=>Rv(e)).if(Jv,(t,e)=>Yu(e)).if(Gv,(t,e)=>BigInt(hc(e,Bu,Uo))).if(Wo,(t,e)=>Nr(e,pc(e,t.shape))).if(Nv,(t,e)=>{const n={};for(const r in t.shape){let s=t.shape[r];if(Av.check(s)){if(Yu(e))continue;s=s.shape}n[r]=Kf(s,e)}return n}).if($v,(t,e)=>{const n=[],r=Af(e,0,42);for(let s=0;s<r;s++)n.push(Nr(e,t.shape));return n}).if(Of,(t,e)=>pc(e,t.shape)).if(Yv,(t,e)=>null).if(Vv,(t,e)=>{const n=Nr(e,t.res);return()=>n}).if(Kv,(t,e)=>Nr(e,pc(e,[Vr,ts,mi,qf,Ja,pi,Uf(Vr),Ff(as("a","b","c"),Vr)]))).if(Fv,(t,e)=>{const n={},r=hc(e,0,3);for(let s=0;s<r;s++){const o=Nr(e,t.shape.keys),i=Nr(e,t.shape.values);n[o]=i}return n}).done(),Nr=(t,e)=>Kf(Ms(e),t),an=typeof document<"u"?document:{},eS=t=>an.createElement(t),tS=()=>an.createDocumentFragment();ht(t=>t.nodeType===uS);const nS=t=>an.createTextNode(t);typeof DOMParser<"u"&&new DOMParser;const rS=(t,e)=>(Ev(e,(n,r)=>{r===!1?t.removeAttribute(n):r===!0?t.setAttribute(n,""):t.setAttribute(n,r)}),t),sS=t=>{const e=tS();for(let n=0;n<t.length;n++)Gf(e,t[n]);return e},oS=(t,e)=>(Gf(t,sS(e)),t),Cj=(t,e=[],n=[])=>oS(rS(eS(t),e),n);ht(t=>t.nodeType===cS);const Ej=nS;ht(t=>t.nodeType===aS);const iS=t=>yx(t,(e,n)=>`${n}:${e};`).join(""),Gf=(t,e)=>t.appendChild(e),cS=an.ELEMENT_NODE,aS=an.TEXT_NODE;an.CDATA_SECTION_NODE;an.COMMENT_NODE;const lS=an.DOCUMENT_NODE;an.DOCUMENT_TYPE_NODE;const uS=an.DOCUMENT_FRAGMENT_NODE;ht(t=>t.nodeType===lS);const Rn=Symbol,Jf=Rn(),Yf=Rn(),dS=Rn(),fS=Rn(),hS=Rn(),Xf=Rn(),pS=Rn(),Ya=Rn(),mS=Rn(),gS=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[];let r=0;for(;r<t.length;r++){const s=t[r];if(s===void 0)break;if(s.constructor===String||s.constructor===Number)e.push(s);else if(s.constructor===Object)break}for(r>0&&n.push(e.join(""));r<t.length;r++){const s=t[r];s instanceof Symbol||n.push(s)}return n},yS={[Jf]:pn("font-weight","bold"),[Yf]:pn("font-weight","normal"),[dS]:pn("color","blue"),[hS]:pn("color","green"),[fS]:pn("color","grey"),[Xf]:pn("color","red"),[pS]:pn("color","purple"),[Ya]:pn("color","orange"),[mS]:pn("color","black")},wS=t=>{t.length===1&&t[0]?.constructor===Function&&(t=t[0]());const e=[],n=[],r=Dt();let s=[],o=0;for(;o<t.length;o++){const i=t[o],c=yS[i];if(c!==void 0)r.set(c.left,c.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){const l=iS(r);o>0||l.length>0?(e.push("%c"+i),n.push(l)):e.push(i)}else break}}for(o>0&&(s=n,s.unshift(e.join("")));o<t.length;o++){const i=t[o];i instanceof Symbol||s.push(i)}return s},Zf=hv?wS:gS,bS=(...t)=>{console.log(...Zf(t)),eh.forEach(e=>e.print(t))},Qf=(...t)=>{console.warn(...Zf(t)),t.unshift(Ya),eh.forEach(e=>e.print(t))},eh=Bn(),th=t=>({[Symbol.iterator](){return this},next:t}),xS=(t,e)=>th(()=>{let n;do n=t.next();while(!n.done&&!e(n.value));return n}),mc=(t,e)=>th(()=>{const{done:n,value:r}=t.next();return{done:n,value:n?void 0:e(r)}});class gi{constructor(e,n){this.clock=e,this.len=n}}class ls{constructor(){this.clients=new Map}}const ns=(t,e,n)=>e.clients.forEach((r,s)=>{const o=t.doc.store.clients.get(s);if(o!=null){const i=o[o.length-1],c=i.id.clock+i.length;for(let l=0,d=r[l];l<r.length&&d.clock<c;d=r[++l])gh(t,o,d.clock,d.len,n)}}),vS=(t,e)=>{let n=0,r=t.length-1;for(;n<=r;){const s=Yt((n+r)/2),o=t[s],i=o.clock;if(i<=e){if(e<i+o.len)return s;n=s+1}else r=s-1}return null},Js=(t,e)=>{const n=t.clients.get(e.client);return n!==void 0&&vS(n,e.clock)!==null},Xa=t=>{t.clients.forEach(e=>{e.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<e.length;n++){const s=e[r-1],o=e[n];s.clock+s.len>=o.clock?e[r-1]=new gi(s.clock,xr(s.len,o.clock+o.len-s.clock)):(r<n&&(e[r]=o),r++)}e.length=r})},Gc=t=>{const e=new ls;for(let n=0;n<t.length;n++)t[n].clients.forEach((r,s)=>{if(!e.clients.has(s)){const o=r.slice();for(let i=n+1;i<t.length;i++)bx(o,t[i].clients.get(s)||[]);e.clients.set(s,o)}});return Xa(e),e},Fs=(t,e,n,r)=>{cn(t.clients,e,()=>[]).push(new gi(n,r))},SS=()=>new ls,CS=t=>{const e=SS();return t.clients.forEach((n,r)=>{const s=[];for(let o=0;o<n.length;o++){const i=n[o];if(i.deleted){const c=i.id.clock;let l=i.length;if(o+1<n.length)for(let d=n[o+1];o+1<n.length&&d.deleted;d=n[++o+1])l+=d.length;s.push(new gi(c,l))}}s.length>0&&e.clients.set(r,s)}),e},us=(t,e)=>{ie(t.restEncoder,e.clients.size),Sn(e.clients.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{t.resetDsCurVal(),ie(t.restEncoder,n);const s=r.length;ie(t.restEncoder,s);for(let o=0;o<s;o++){const i=r[o];t.writeDsClock(i.clock),t.writeDsLen(i.len)}})},Za=t=>{const e=new ls,n=be(t.restDecoder);for(let r=0;r<n;r++){t.resetDsCurVal();const s=be(t.restDecoder),o=be(t.restDecoder);if(o>0){const i=cn(e.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new gi(t.readDsClock(),t.readDsLen()))}}return e},Zu=(t,e,n)=>{const r=new ls,s=be(t.restDecoder);for(let o=0;o<s;o++){t.resetDsCurVal();const i=be(t.restDecoder),c=be(t.restDecoder),l=n.clients.get(i)||[],d=Ze(n,i);for(let h=0;h<c;h++){const f=t.readDsClock(),p=f+t.readDsLen();if(f<d){d<p&&Fs(r,i,d,p-d);let m=nn(l,f),g=l[m];for(!g.deleted&&g.id.clock<f&&(l.splice(m+1,0,Zo(e,g,f-g.id.clock)),m++);m<l.length&&(g=l[m++],g.id.clock<p);)g.deleted||(p<g.id.clock+g.length&&l.splice(m,0,Zo(e,g,p-g.id.clock)),g.delete(e))}else Fs(r,i,f,p-f)}}if(r.clients.size>0){const o=new hr;return ie(o.restEncoder,0),us(o,r),o.toUint8Array()}return null},nh=Cf;class vr extends Na{constructor({guid:e=Yx(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=nh(),this.guid=e,this.collectionid=n,this.share=new Map,this.store=new ph,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=es(d=>{this.on("load",()=>{this.isLoaded=!0,d(this)})});const l=()=>es(d=>{const h=f=>{(f===void 0||f===!0)&&(this.off("sync",h),d())};this.on("sync",h)});this.on("sync",d=>{d===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=d===void 0||d===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&Be(e.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Sn(this.subdocs).map(e=>e.guid))}transact(e,n=null){return Be(this,e,n)}get(e,n=ft){const r=cn(this.share,e,()=>{const o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==ft&&s!==n)if(s===ft){const o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(e,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return r}getArray(e=""){return this.get(e,Kr)}getText(e=""){return this.get(e,os)}getMap(e=""){return this.get(e,ss)}getXmlElement(e=""){return this.get(e,is)}getXmlFragment(e=""){return this.get(e,pr)}toJSON(){const e={};return this.share.forEach((n,r)=>{e[r]=n.toJSON()}),e}destroy(){this.isDestroyed=!0,Sn(this.subdocs).forEach(n=>n.destroy());const e=this._item;if(e!==null){this._item=null;const n=e.content;n.doc=new vr({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=e,Be(e.parent.doc,r=>{const s=n.doc;e.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class rh{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return be(this.restDecoder)}readDsLen(){return be(this.restDecoder)}}class sh extends rh{readLeftID(){return je(be(this.restDecoder),be(this.restDecoder))}readRightID(){return je(be(this.restDecoder),be(this.restDecoder))}readClient(){return be(this.restDecoder)}readInfo(){return Qr(this.restDecoder)}readString(){return Ge(this.restDecoder)}readParentInfo(){return be(this.restDecoder)===1}readTypeRef(){return be(this.restDecoder)}readLen(){return be(this.restDecoder)}readAny(){return Ls(this.restDecoder)}readBuf(){return Sv(xt(this.restDecoder))}readJSON(){return JSON.parse(Ge(this.restDecoder))}readKey(){return Ge(this.restDecoder)}}class ES{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=be(this.restDecoder),this.dsCurrVal}readDsLen(){const e=be(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class rs extends ES{constructor(e){super(e),this.keys=[],be(e),this.keyClockDecoder=new fc(xt(e)),this.clientDecoder=new Po(xt(e)),this.leftClockDecoder=new fc(xt(e)),this.rightClockDecoder=new fc(xt(e)),this.infoDecoder=new Gu(xt(e),Qr),this.stringDecoder=new Kx(xt(e)),this.parentInfoDecoder=new Gu(xt(e),Qr),this.typeRefDecoder=new Po(xt(e)),this.lenDecoder=new Po(xt(e))}readLeftID(){return new Hr(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Hr(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 Ls(this.restDecoder)}readBuf(){return xt(this.restDecoder)}readJSON(){return Ls(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 oh{constructor(){this.restEncoder=Xe()}toUint8Array(){return $e(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ie(this.restEncoder,e)}writeDsLen(e){ie(this.restEncoder,e)}}class Ys extends oh{writeLeftID(e){ie(this.restEncoder,e.client),ie(this.restEncoder,e.clock)}writeRightID(e){ie(this.restEncoder,e.client),ie(this.restEncoder,e.clock)}writeClient(e){ie(this.restEncoder,e)}writeInfo(e){Wc(this.restEncoder,e)}writeString(e){mt(this.restEncoder,e)}writeParentInfo(e){ie(this.restEncoder,e?1:0)}writeTypeRef(e){ie(this.restEncoder,e)}writeLen(e){ie(this.restEncoder,e)}writeAny(e){Os(this.restEncoder,e)}writeBuf(e){Ye(this.restEncoder,e)}writeJSON(e){mt(this.restEncoder,JSON.stringify(e))}writeKey(e){mt(this.restEncoder,e)}}class ih{constructor(){this.restEncoder=Xe(),this.dsCurrVal=0}toUint8Array(){return $e(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const n=e-this.dsCurrVal;this.dsCurrVal=e,ie(this.restEncoder,n)}writeDsLen(e){e===0&&Lt(),ie(this.restEncoder,e-1),this.dsCurrVal+=e}}class hr extends ih{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new dc,this.clientEncoder=new To,this.leftClockEncoder=new dc,this.rightClockEncoder=new dc,this.infoEncoder=new Hu(Wc),this.stringEncoder=new $x,this.parentInfoEncoder=new Hu(Wc),this.typeRefEncoder=new To,this.lenEncoder=new To}toUint8Array(){const e=Xe();return ie(e,0),Ye(e,this.keyClockEncoder.toUint8Array()),Ye(e,this.clientEncoder.toUint8Array()),Ye(e,this.leftClockEncoder.toUint8Array()),Ye(e,this.rightClockEncoder.toUint8Array()),Ye(e,$e(this.infoEncoder)),Ye(e,this.stringEncoder.toUint8Array()),Ye(e,$e(this.parentInfoEncoder)),Ye(e,this.typeRefEncoder.toUint8Array()),Ye(e,this.lenEncoder.toUint8Array()),li(e,$e(this.restEncoder)),$e(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){Os(this.restEncoder,e)}writeBuf(e){Ye(this.restEncoder,e)}writeJSON(e){Os(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 kS=(t,e,n,r)=>{r=xr(r,e[0].id.clock);const s=nn(e,r);ie(t.restEncoder,e.length-s),t.writeClient(n),ie(t.restEncoder,r);const o=e[s];o.write(t,r-o.id.clock);for(let i=s+1;i<e.length;i++)e[i].write(t,0)},Qa=(t,e,n)=>{const r=new Map;n.forEach((s,o)=>{Ze(e,o)>s&&r.set(o,s)}),yi(e).forEach((s,o)=>{n.has(o)||r.set(o,0)}),ie(t.restEncoder,r.size),Sn(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{kS(t,e.clients.get(s),s,o)})},RS=(t,e)=>{const n=Dt(),r=be(t.restDecoder);for(let s=0;s<r;s++){const o=be(t.restDecoder),i=new Array(o),c=t.readClient();let l=be(t.restDecoder);n.set(c,{i:0,refs:i});for(let d=0;d<o;d++){const h=t.readInfo();switch(ai&h){case 0:{const f=t.readLen();i[d]=new Mt(je(c,l),f),l+=f;break}case 10:{const f=be(t.restDecoder);i[d]=new Ft(je(c,l),f),l+=f;break}default:{const f=(h&(bn|St))===0,p=new Ve(je(c,l),null,(h&St)===St?t.readLeftID():null,null,(h&bn)===bn?t.readRightID():null,f?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,f&&(h&Ps)===Ps?t.readString():null,Mh(t,h));i[d]=p,l+=p.length}}}}return n},DS=(t,e,n)=>{const r=[];let s=Sn(n.keys()).sort((m,g)=>m-g);if(s.length===0)return null;const o=()=>{if(s.length===0)return null;let m=n.get(s[s.length-1]);for(;m.refs.length===m.i;)if(s.pop(),s.length>0)m=n.get(s[s.length-1]);else return null;return m};let i=o();if(i===null)return null;const c=new ph,l=new Map,d=(m,g)=>{const y=l.get(m);(y==null||y>g)&&l.set(m,g)};let h=i.refs[i.i++];const f=new Map,p=()=>{for(const m of r){const g=m.id.client,y=n.get(g);y?(y.i--,c.clients.set(g,y.refs.slice(y.i)),n.delete(g),y.i=0,y.refs=[]):c.clients.set(g,[m]),s=s.filter(C=>C!==g)}r.length=0};for(;;){if(h.constructor!==Ft){const g=cn(f,h.id.client,()=>Ze(e,h.id.client))-h.id.clock;if(g<0)r.push(h),d(h.id.client,h.id.clock-1),p();else{const y=h.getMissing(t,e);if(y!==null){r.push(h);const C=n.get(y)||{refs:[],i:0};if(C.refs.length===C.i)d(y,Ze(e,y)),p();else{h=C.refs[C.i++];continue}}else(g===0||g<h.length)&&(h.integrate(t,g),f.set(h.id.client,h.id.clock+h.length))}}if(r.length>0)h=r.pop();else if(i!==null&&i.i<i.refs.length)h=i.refs[i.i++];else{if(i=o(),i===null)break;h=i.refs[i.i++]}}if(c.clients.size>0){const m=new hr;return Qa(m,c,new Map),ie(m.restEncoder,0),{missing:l,update:m.toUint8Array()}}return null},jS=(t,e)=>Qa(t,e.doc.store,e.beforeState),_S=(t,e,n,r=new rs(t))=>Be(e,s=>{s.local=!1;let o=!1;const i=s.doc,c=i.store,l=RS(r,i),d=DS(s,c,l),h=c.pendingStructs;if(h){for(const[p,m]of h.missing)if(m<Ze(c,p)){o=!0;break}if(d){for(const[p,m]of d.missing){const g=h.missing.get(p);(g==null||g>m)&&h.missing.set(p,m)}h.update=qo([h.update,d.update])}}else c.pendingStructs=d;const f=Zu(r,s,c);if(c.pendingDs){const p=new rs(Gn(c.pendingDs));be(p.restDecoder);const m=Zu(p,s,c);f&&m?c.pendingDs=qo([f,m]):c.pendingDs=f||m}else c.pendingDs=f;if(o){const p=c.pendingStructs.update;c.pendingStructs=null,ch(s.doc,p)}},n,!1),ch=(t,e,n,r=rs)=>{const s=Gn(e);_S(s,t,n,new r(s))},ah=(t,e,n)=>ch(t,e,n,sh),TS=(t,e,n=new Map)=>{Qa(t,e.store,n),us(t,CS(e.store))},PS=(t,e=new Uint8Array([0]),n=new hr)=>{const r=lh(e);TS(n,t,r);const s=[n.toUint8Array()];if(t.store.pendingDs&&s.push(t.store.pendingDs),t.store.pendingStructs&&s.push(YS(t.store.pendingStructs.update,e)),s.length>1){if(n.constructor===Ys)return GS(s.map((o,i)=>i===0?o:ZS(o)));if(n.constructor===hr)return qo(s)}return s[0]},el=(t,e)=>PS(t,e,new Ys),AS=t=>{const e=new Map,n=be(t.restDecoder);for(let r=0;r<n;r++){const s=be(t.restDecoder),o=be(t.restDecoder);e.set(s,o)}return e},lh=t=>AS(new rh(Gn(t))),uh=(t,e)=>(ie(t.restEncoder,e.size),Sn(e.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{ie(t.restEncoder,n),ie(t.restEncoder,r)}),t),OS=(t,e)=>uh(t,yi(e.store)),LS=(t,e=new ih)=>(t instanceof Map?uh(e,t):OS(e,t),e.toUint8Array()),NS=t=>LS(t,new oh);class MS{constructor(){this.l=[]}}const Qu=()=>new MS,ed=(t,e)=>t.l.push(e),td=(t,e)=>{const n=t.l,r=n.length;t.l=n.filter(s=>e!==s),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},dh=(t,e,n)=>Va(t.l,[e,n]);class Hr{constructor(e,n){this.client=e,this.clock=n}}const Ur=(t,e)=>t===e||t!==null&&e!==null&&t.client===e.client&&t.clock===e.clock,je=(t,e)=>new Hr(t,e),fh=t=>{for(const[e,n]of t.doc.share.entries())if(n===t)return e;throw Lt()},Ho=(t,e)=>{for(;e!==null;){if(e.parent===t)return!0;e=e.parent._item}return!1};class hh{constructor(e,n,r,s=0){this.type=e,this.tname=n,this.item=r,this.assoc=s}}const kj=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},Rj=t=>new hh(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 FS{constructor(e,n,r=0){this.type=e,this.index=n,this.assoc=r}}const IS=(t,e,n=0)=>new FS(t,e,n),wo=(t,e,n)=>{let r=null,s=null;return t._item===null?s=fh(t):r=je(t._item.id.client,t._item.id.clock),new hh(r,s,e,n)},Dj=(t,e,n=0)=>{let r=t._start;if(n<0){if(e===0)return wo(t,null,n);e--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>e)return wo(t,je(r.id.client,r.id.clock+e),n);e-=r.length}if(r.right===null&&n<0)return wo(t,r.lastId,n);r=r.right}return wo(t,null,n)},$S=(t,e)=>{const n=qr(t,e),r=e.clock-n.id.clock;return{item:n,diff:r}},jj=(t,e,n=!0)=>{const r=e.store,s=t.item,o=t.type,i=t.tname,c=t.assoc;let l=null,d=0;if(s!==null){if(Ze(r,s.client)<=s.clock)return null;const h=n?Zc(r,s):$S(r,s),f=h.item;if(!(f instanceof Ve))return null;if(l=f.parent,l._item===null||!l._item.deleted){d=f.deleted||!f.countable?0:h.diff+(c>=0?0:1);let p=f.left;for(;p!==null;)!p.deleted&&p.countable&&(d+=p.length),p=p.left}}else{if(i!==null)l=e.get(i);else if(o!==null){if(Ze(r,o.client)<=o.clock)return null;const{item:h}=n?Zc(r,o):{item:qr(r,o)};if(h instanceof Ve&&h.content instanceof ln)l=h.content.type;else return null}else throw Lt();c>=0?d=l._length:d=0}return IS(l,d,t.assoc)},_j=(t,e)=>t===e||t!==null&&e!==null&&t.tname===e.tname&&Ur(t.item,e.item)&&Ur(t.type,e.type)&&t.assoc===e.assoc,Mr=(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),Jc=(t,e)=>{const n=cn(t.meta,Jc,Bn),r=t.doc.store;n.has(e)||(e.sv.forEach((s,o)=>{s<Ze(r,o)&&Rt(t,je(o,s))}),ns(t,e.ds,s=>{}),n.add(e))};class ph{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const yi=t=>{const e=new Map;return t.clients.forEach((n,r)=>{const s=n[n.length-1];e.set(r,s.id.clock+s.length)}),e},Ze=(t,e)=>{const n=t.clients.get(e);if(n===void 0)return 0;const r=n[n.length-1];return r.id.clock+r.length},mh=(t,e)=>{let n=t.clients.get(e.id.client);if(n===void 0)n=[],t.clients.set(e.id.client,n);else{const r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw Lt()}n.push(e)},nn=(t,e)=>{let n=0,r=t.length-1,s=t[r],o=s.id.clock;if(o===e)return r;let i=Yt(e/(o+s.length-1)*r);for(;n<=r;){if(s=t[i],o=s.id.clock,o<=e){if(e<o+s.length)return i;n=i+1}else r=i-1;i=Yt((n+r)/2)}throw Lt()},US=(t,e)=>{const n=t.clients.get(e.client);return n[nn(n,e.clock)]},qr=US,Yc=(t,e,n)=>{const r=nn(e,n),s=e[r];return s.id.clock<n&&s instanceof Ve?(e.splice(r+1,0,Zo(t,s,n-s.id.clock)),r+1):r},Rt=(t,e)=>{const n=t.doc.store.clients.get(e.client);return n[Yc(t,n,e.clock)]},nd=(t,e,n)=>{const r=e.clients.get(n.client),s=nn(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==Mt&&r.splice(s+1,0,Zo(t,o,n.clock-o.id.clock+1)),o},zS=(t,e,n)=>{const r=t.clients.get(e.id.client);r[nn(r,e.id.clock)]=n},gh=(t,e,n,r,s)=>{if(r===0)return;const o=n+r;let i=Yc(t,e,n),c;do c=e[i++],o<c.id.clock+c.length&&Yc(t,e,o),s(c);while(i<e.length&&e[i].id.clock<o)};class BS{constructor(e,n,r){this.doc=e,this.deleteSet=new ls,this.beforeState=yi(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=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const rd=(t,e)=>e.deleteSet.clients.size===0&&!wx(e.afterState,(n,r)=>e.beforeState.get(r)!==n)?!1:(Xa(e.deleteSet),jS(t,e),us(t,e.deleteSet),!0),sd=(t,e,n)=>{const r=e._item;(r===null||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&cn(t.changed,e,Bn).add(n)},Ao=(t,e)=>{let n=t[e],r=t[e-1],s=e;for(;s>0;n=r,r=t[--s-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Ve&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}const o=e-s;return o&&t.splice(e+1-o,o),o},WS=(t,e,n)=>{for(const[r,s]of t.clients.entries()){const o=e.clients.get(r);for(let i=s.length-1;i>=0;i--){const c=s[i],l=c.clock+c.len;for(let d=nn(o,c.clock),h=o[d];d<o.length&&h.id.clock<l;h=o[++d]){const f=o[d];if(c.clock+c.len<=f.id.clock)break;f instanceof Ve&&f.deleted&&!f.keep&&n(f)&&f.gc(e,!1)}}}},VS=(t,e)=>{t.clients.forEach((n,r)=>{const s=e.clients.get(r);for(let o=n.length-1;o>=0;o--){const i=n[o],c=Ma(s.length-1,1+nn(s,i.clock+i.len-1));for(let l=c,d=s[l];l>0&&d.id.clock>=i.clock;d=s[l])l-=1+Ao(s,l)}})},yh=(t,e)=>{if(e<t.length){const n=t[e],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{Xa(o),n.afterState=yi(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const c=[];n.changed.forEach((l,d)=>c.push(()=>{(d._item===null||!d._item.deleted)&&d._callObserver(n,l)})),c.push(()=>{n.changedParentTypes.forEach((l,d)=>{d._dEH.l.length>0&&(d._item===null||!d._item.deleted)&&(l=l.filter(h=>h.target._item===null||!h.target._item.deleted),l.forEach(h=>{h.currentTarget=d,h._path=null}),l.sort((h,f)=>h.path.length-f.path.length),c.push(()=>{dh(d._dEH,l,n)}))}),c.push(()=>r.emit("afterTransaction",[n,r])),c.push(()=>{n._needFormattingCleanup&&fC(n)})}),Va(c,[])}finally{r.gc&&WS(o,s,r.gcFilter),VS(o,s),n.afterState.forEach((h,f)=>{const p=n.beforeState.get(f)||0;if(p!==h){const m=s.clients.get(f),g=xr(nn(m,p),1);for(let y=m.length-1;y>=g;)y-=1+Ao(m,y)}});for(let h=i.length-1;h>=0;h--){const{client:f,clock:p}=i[h].id,m=s.clients.get(f),g=nn(m,p);g+1<m.length&&Ao(m,g+1)>1||g>0&&Ao(m,g)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(bS(Ya,Jf,"[yjs] ",Yf,Xf,"Changed the client-id because another client seems to be using it."),r.clientID=nh()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const h=new Ys;rd(h,n)&&r.emit("update",[h.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const h=new hr;rd(h,n)&&r.emit("updateV2",[h.toUint8Array(),n.origin,r,n])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:d}=n;(c.size>0||d.size>0||l.size>0)&&(c.forEach(h=>{h.clientID=r.clientID,h.collectionid==null&&(h.collectionid=r.collectionid),r.subdocs.add(h)}),d.forEach(h=>r.subdocs.delete(h)),r.emit("subdocs",[{loaded:l,added:c,removed:d},r,n]),d.forEach(h=>h.destroy())),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):yh(t,e+1)}}},Be=(t,e,n=null,r=!0)=>{const s=t._transactionCleanups;let o=!1,i=null;t._transaction===null&&(o=!0,t._transaction=new BS(t,n,r),s.push(t._transaction),s.length===1&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{i=e(t._transaction)}finally{if(o){const c=t._transaction===s[0];t._transaction=null,c&&yh(s,0)}}return i};class HS{constructor(e,n){this.insertions=n,this.deletions=e,this.meta=new Map}}const od=(t,e,n)=>{ns(t,n.deletions,r=>{r instanceof Ve&&e.scope.some(s=>s===t.doc||Ho(s,r))&&al(r,!1)})},id=(t,e,n)=>{let r=null;const s=t.doc,o=t.scope;Be(s,c=>{for(;e.length>0&&t.currStackItem===null;){const l=s.store,d=e.pop(),h=new Set,f=[];let p=!1;ns(c,d.insertions,m=>{if(m instanceof Ve){if(m.redone!==null){let{item:g,diff:y}=Zc(l,m.id);y>0&&(g=Rt(c,je(g.id.client,g.id.clock+y))),m=g}!m.deleted&&o.some(g=>g===c.doc||Ho(g,m))&&f.push(m)}}),ns(c,d.deletions,m=>{m instanceof Ve&&o.some(g=>g===c.doc||Ho(g,m))&&!Js(d.insertions,m.id)&&h.add(m)}),h.forEach(m=>{p=Nh(c,m,h,d.insertions,t.ignoreRemoteMapChanges,t)!==null||p});for(let m=f.length-1;m>=0;m--){const g=f[m];t.deleteFilter(g)&&(g.delete(c),p=!0)}t.currStackItem=p?d:null}c.changed.forEach((l,d)=>{l.has(null)&&d._searchMarker&&(d._searchMarker.length=0)}),r=c},t);const i=t.currStackItem;if(i!=null){const c=r.changedParentTypes;t.emit("stack-item-popped",[{stackItem:i,type:n,changedParentTypes:c,origin:t},t]),t.currStackItem=null}return i};class qS extends Na{constructor(e,{captureTimeout:n=500,captureTransaction:r=l=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=Zr(e)?e[0].doc:e instanceof vr?e:e.doc}={}){super(),this.scope=[],this.doc=c,this.addToScope(e),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.captureTimeout=n,this.afterTransactionHandler=l=>{if(!this.captureTransaction(l)||!this.scope.some(C=>l.changedParentTypes.has(C)||C===this.doc)||!this.trackedOrigins.has(l.origin)&&(!l.origin||!this.trackedOrigins.has(l.origin.constructor)))return;const d=this.undoing,h=this.redoing,f=d?this.redoStack:this.undoStack;d?this.stopCapturing():h||this.clear(!1,!0);const p=new ls;l.afterState.forEach((C,v)=>{const D=l.beforeState.get(v)||0,b=C-D;b>0&&Fs(p,v,D,b)});const m=Wn();let g=!1;if(this.lastChange>0&&m-this.lastChange<this.captureTimeout&&f.length>0&&!d&&!h){const C=f[f.length-1];C.deletions=Gc([C.deletions,l.deleteSet]),C.insertions=Gc([C.insertions,p])}else f.push(new HS(l.deleteSet,p)),g=!0;!d&&!h&&(this.lastChange=m),ns(l,l.deleteSet,C=>{C instanceof Ve&&this.scope.some(v=>v===l.doc||Ho(v,C))&&al(C,!0)});const y=[{stackItem:f[f.length-1],origin:l.origin,type:d?"redo":"undo",changedParentTypes:l.changedParentTypes},this];g?this.emit("stack-item-added",y):this.emit("stack-item-updated",y)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const n=new Set(this.scope);e=Zr(e)?e:[e],e.forEach(r=>{n.has(r)||(n.add(r),(r instanceof ft?r.doc!==this.doc:r!==this.doc)&&Qf("[yjs#509] Not same Y.Doc"),this.scope.push(r))})}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(r=>{e&&(this.undoStack.forEach(s=>od(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>od(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=id(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=id(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*KS(t){const e=be(t.restDecoder);for(let n=0;n<e;n++){const r=be(t.restDecoder),s=t.readClient();let o=be(t.restDecoder);for(let i=0;i<r;i++){const c=t.readInfo();if(c===10){const l=be(t.restDecoder);yield new Ft(je(s,o),l),o+=l}else if((ai&c)!==0){const l=(c&(bn|St))===0,d=new Ve(je(s,o),null,(c&St)===St?t.readLeftID():null,null,(c&bn)===bn?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(c&Ps)===Ps?t.readString():null,Mh(t,c));yield d,o+=d.length}else{const l=t.readLen();yield new Mt(je(s,o),l),o+=l}}}}class tl{constructor(e,n){this.gen=KS(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===Ft);return this.curr}}class nl{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}}const GS=t=>qo(t,sh,Ys),JS=(t,e)=>{if(t.constructor===Mt){const{client:n,clock:r}=t.id;return new Mt(je(n,r+e),t.length-e)}else if(t.constructor===Ft){const{client:n,clock:r}=t.id;return new Ft(je(n,r+e),t.length-e)}else{const n=t,{client:r,clock:s}=n.id;return new Ve(je(r,s+e),null,je(r,s+e-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(e))}},qo=(t,e=rs,n=hr)=>{if(t.length===1)return t[0];const r=t.map(h=>new e(Gn(h)));let s=r.map(h=>new tl(h,!0)),o=null;const i=new n,c=new nl(i);for(;s=s.filter(p=>p.curr!==null),s.sort((p,m)=>{if(p.curr.id.client===m.curr.id.client){const g=p.curr.id.clock-m.curr.id.clock;return g===0?p.curr.constructor===m.curr.constructor?0:p.curr.constructor===Ft?1:-1:g}else return m.curr.id.client-p.curr.id.client}),s.length!==0;){const h=s[0],f=h.curr.id.client;if(o!==null){let p=h.curr,m=!1;for(;p!==null&&p.id.clock+p.length<=o.struct.id.clock+o.struct.length&&p.id.client>=o.struct.id.client;)p=h.next(),m=!0;if(p===null||p.id.client!==f||m&&p.id.clock>o.struct.id.clock+o.struct.length)continue;if(f!==o.struct.id.client)Fn(c,o.struct,o.offset),o={struct:p,offset:0},h.next();else if(o.struct.id.clock+o.struct.length<p.id.clock)if(o.struct.constructor===Ft)o.struct.length=p.id.clock+p.length-o.struct.id.clock;else{Fn(c,o.struct,o.offset);const g=p.id.clock-o.struct.id.clock-o.struct.length;o={struct:new Ft(je(f,o.struct.id.clock+o.struct.length),g),offset:0}}else{const g=o.struct.id.clock+o.struct.length-p.id.clock;g>0&&(o.struct.constructor===Ft?o.struct.length-=g:p=JS(p,g)),o.struct.mergeWith(p)||(Fn(c,o.struct,o.offset),o={struct:p,offset:0},h.next())}}else o={struct:h.curr,offset:0},h.next();for(let p=h.curr;p!==null&&p.id.client===f&&p.id.clock===o.struct.id.clock+o.struct.length&&p.constructor!==Ft;p=h.next())Fn(c,o.struct,o.offset),o={struct:p,offset:0}}o!==null&&(Fn(c,o.struct,o.offset),o=null),rl(c);const l=r.map(h=>Za(h)),d=Gc(l);return us(i,d),i.toUint8Array()},YS=(t,e,n=rs,r=hr)=>{const s=lh(e),o=new r,i=new nl(o),c=new n(Gn(t)),l=new tl(c,!1);for(;l.curr;){const h=l.curr,f=h.id.client,p=s.get(f)||0;if(l.curr.constructor===Ft){l.next();continue}if(h.id.clock+h.length>p)for(Fn(i,h,xr(p-h.id.clock,0)),l.next();l.curr&&l.curr.id.client===f;)Fn(i,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===f&&l.curr.id.clock+l.curr.length<=p;)l.next()}rl(i);const d=Za(c);return us(o,d),o.toUint8Array()},wh=t=>{t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:$e(t.encoder.restEncoder)}),t.encoder.restEncoder=Xe(),t.written=0)},Fn=(t,e,n)=>{t.written>0&&t.currClient!==e.id.client&&wh(t),t.written===0&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),ie(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},rl=t=>{wh(t);const e=t.encoder.restEncoder;ie(e,t.clientStructs.length);for(let n=0;n<t.clientStructs.length;n++){const r=t.clientStructs[n];ie(e,r.written),li(e,r.restEncoder)}},XS=(t,e,n,r)=>{const s=new n(Gn(t)),o=new tl(s,!1),i=new r,c=new nl(i);for(let d=o.curr;d!==null;d=o.next())Fn(c,e(d),0);rl(c);const l=Za(s);return us(i,l),i.toUint8Array()},ZS=t=>XS(t,av,rs,Ys),cd="You must not compute changes after the event-handler fired.";class wi{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=QS(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 Xt(cd);const e=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){const o=n._map.get(s);let i,c;if(this.adds(o)){let l=o.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(o))if(l!==null&&this.deletes(l))i="delete",c=uc(l.content.getContent());else return;else l!==null&&this.deletes(l)?(i="update",c=uc(l.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=uc(o.content.getContent());else return;e.set(s,{action:i,oldValue:c})}}),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 Xt(cd);const n=this.target,r=Bn(),s=Bn(),o=[];if(e={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null;const l=()=>{c&&o.push(c)};for(let d=n._start;d!==null;d=d.right)d.deleted?this.deletes(d)&&!this.adds(d)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=d.length,s.add(d)):this.adds(d)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(d.content.getContent()),r.add(d)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=d.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const QS=(t,e)=>{const n=[];for(;e._item!==null&&e!==t;){if(e._item.parentSub!==null)n.unshift(e._item.parentSub);else{let r=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(r+=s.length),s=s.right;n.unshift(r)}e=e._item.parent}return n},vt=()=>{Qf("Invalid access: Add Yjs type to a document before reading data.")},bh=80;let sl=0;class eC{constructor(e,n){e.marker=!0,this.p=e,this.index=n,this.timestamp=sl++}}const tC=t=>{t.timestamp=sl++},xh=(t,e,n)=>{t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=sl++},nC=(t,e,n)=>{if(t.length>=bh){const r=t.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return xh(r,e,n),r}else{const r=new eC(e,n);return t.push(r),r}},bi=(t,e)=>{if(t._start===null||e===0||t._searchMarker===null)return null;const n=t._searchMarker.length===0?null:t._searchMarker.reduce((o,i)=>_o(e-o.index)<_o(e-i.index)?o:i);let r=t._start,s=0;for(n!==null&&(r=n.p,s=n.index,tC(n));r.right!==null&&s<e;){if(!r.deleted&&r.countable){if(e<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>e;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&_o(n.index-s)<r.parent.length/bh?(xh(n,r,s),n):nC(t._searchMarker,r,s)},Is=(t,e,n)=>{for(let r=t.length-1;r>=0;r--){const s=t[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){t.splice(r,1);continue}s.p=o,o.marker=!0}(e<s.index||n>0&&e===s.index)&&(s.index=xr(e,s.index+n))}},xi=(t,e,n)=>{const r=t,s=e.changedParentTypes;for(;cn(s,t,()=>[]).push(n),t._item!==null;)t=t._item.parent;dh(r._eH,n,e)};class ft{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Qu(),this._dEH=Qu(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,n){this.doc=e,this._item=n}_copy(){throw Jt()}clone(){throw Jt()}_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){ed(this._eH,e)}observeDeep(e){ed(this._dEH,e)}unobserve(e){td(this._eH,e)}unobserveDeep(e){td(this._dEH,e)}toJSON(){}}const vh=(t,e,n)=>{t.doc??vt(),e<0&&(e=t._length+e),n<0&&(n=t._length+n);let r=n-e;const s=[];let o=t._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){const i=o.content.getContent();if(i.length<=e)e-=i.length;else{for(let c=e;c<i.length&&r>0;c++)s.push(i[c]),r--;e=0}}o=o.right}return s},Sh=t=>{t.doc??vt();const e=[];let n=t._start;for(;n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let s=0;s<r.length;s++)e.push(r[s])}n=n.right}return e},$s=(t,e)=>{let n=0,r=t._start;for(t.doc??vt();r!==null;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let o=0;o<s.length;o++)e(s[o],n++,t)}r=r.right}},Ch=(t,e)=>{const n=[];return $s(t,(r,s)=>{n.push(e(r,s,t))}),n},rC=t=>{let e=t._start,n=null,r=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(),r=0,e=e.right}const s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},Eh=(t,e)=>{t.doc??vt();const n=bi(t,e);let r=t._start;for(n!==null&&(r=n.p,e-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(e<r.length)return r.content.getContent()[e];e-=r.length}},Ko=(t,e,n,r)=>{let s=n;const o=t.doc,i=o.clientID,c=o.store,l=n===null?e._start:n.right;let d=[];const h=()=>{d.length>0&&(s=new Ve(je(i,Ze(c,i)),s,s&&s.lastId,l,l&&l.id,e,null,new mr(d)),s.integrate(t,0),d=[])};r.forEach(f=>{if(f===null)d.push(f);else switch(f.constructor){case Number:case Object:case Boolean:case Array:case String:d.push(f);break;default:switch(h(),f.constructor){case Uint8Array:case ArrayBuffer:s=new Ve(je(i,Ze(c,i)),s,s&&s.lastId,l,l&&l.id,e,null,new Xs(new Uint8Array(f))),s.integrate(t,0);break;case vr:s=new Ve(je(i,Ze(c,i)),s,s&&s.lastId,l,l&&l.id,e,null,new Zs(f)),s.integrate(t,0);break;default:if(f instanceof ft)s=new Ve(je(i,Ze(c,i)),s,s&&s.lastId,l,l&&l.id,e,null,new ln(f)),s.integrate(t,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},kh=()=>Xt("Length exceeded!"),Rh=(t,e,n,r)=>{if(n>e._length)throw kh();if(n===0)return e._searchMarker&&Is(e._searchMarker,n,r.length),Ko(t,e,null,r);const s=n,o=bi(e,n);let i=e._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&Rt(t,je(i.id.client,i.id.clock+n));break}n-=i.length}return e._searchMarker&&Is(e._searchMarker,s,r.length),Ko(t,e,i,r)},sC=(t,e,n)=>{let s=(e._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return Ko(t,e,s,n)},Dh=(t,e,n,r)=>{if(r===0)return;const s=n,o=r,i=bi(e,n);let c=e._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&Rt(t,je(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&Rt(t,je(c.id.client,c.id.clock+r)),c.delete(t),r-=c.length),c=c.right;if(r>0)throw kh();e._searchMarker&&Is(e._searchMarker,s,-o+r)},Go=(t,e,n)=>{const r=e._map.get(n);r!==void 0&&r.delete(t)},ol=(t,e,n,r)=>{const s=e._map.get(n)||null,o=t.doc,i=o.clientID;let c;if(r==null)c=new mr([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:c=new mr([r]);break;case Uint8Array:c=new Xs(r);break;case vr:c=new Zs(r);break;default:if(r instanceof ft)c=new ln(r);else throw new Error("Unexpected content type")}new Ve(je(i,Ze(o.store,i)),s,s&&s.lastId,null,null,e,n,c).integrate(t,0)},il=(t,e)=>{t.doc??vt();const n=t._map.get(e);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},jh=t=>{const e={};return t.doc??vt(),t._map.forEach((n,r)=>{n.deleted||(e[r]=n.content.getContent()[n.length-1])}),e},_h=(t,e)=>{t.doc??vt();const n=t._map.get(e);return n!==void 0&&!n.deleted},oC=(t,e)=>{const n={};return t._map.forEach((r,s)=>{let o=r;for(;o!==null&&(!e.sv.has(o.id.client)||o.id.clock>=(e.sv.get(o.id.client)||0));)o=o.left;o!==null&&Mr(o,e)&&(n[s]=o.content.getContent()[o.length-1])}),n},bo=t=>(t.doc??vt(),xS(t._map.entries(),e=>!e[1].deleted));class iC extends wi{}class Kr extends ft{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const n=new Kr;return n.push(e),n}_integrate(e,n){super._integrate(e,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Kr}clone(){const e=new Kr;return e.insert(0,this.toArray().map(n=>n instanceof ft?n.clone():n)),e}get length(){return this.doc??vt(),this._length}_callObserver(e,n){super._callObserver(e,n),xi(this,e,new iC(this,e))}insert(e,n){this.doc!==null?Be(this.doc,r=>{Rh(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}push(e){this.doc!==null?Be(this.doc,n=>{sC(n,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,n=1){this.doc!==null?Be(this.doc,r=>{Dh(r,this,e,n)}):this._prelimContent.splice(e,n)}get(e){return Eh(this,e)}toArray(){return Sh(this)}slice(e=0,n=this.length){return vh(this,e,n)}toJSON(){return this.map(e=>e instanceof ft?e.toJSON():e)}map(e){return Ch(this,e)}forEach(e){$s(this,e)}[Symbol.iterator](){return rC(this)}_write(e){e.writeTypeRef(PC)}}const cC=t=>new Kr;class aC extends wi{constructor(e,n,r){super(e,n),this.keysChanged=r}}class ss extends ft{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((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new ss}clone(){const e=new ss;return this.forEach((n,r)=>{e.set(r,n instanceof ft?n.clone():n)}),e}_callObserver(e,n){xi(this,e,new aC(this,e,n))}toJSON(){this.doc??vt();const e={};return this._map.forEach((n,r)=>{if(!n.deleted){const s=n.content.getContent()[n.length-1];e[r]=s instanceof ft?s.toJSON():s}}),e}get size(){return[...bo(this)].length}keys(){return mc(bo(this),e=>e[0])}values(){return mc(bo(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return mc(bo(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??vt(),this._map.forEach((n,r)=>{n.deleted||e(n.content.getContent()[n.length-1],r,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?Be(this.doc,n=>{Go(n,this,e)}):this._prelimContent.delete(e)}set(e,n){return this.doc!==null?Be(this.doc,r=>{ol(r,this,e,n)}):this._prelimContent.set(e,n),n}get(e){return il(this,e)}has(e){return _h(this,e)}clear(){this.doc!==null?Be(this.doc,e=>{this.forEach(function(n,r,s){Go(e,s,r)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(AC)}}const lC=t=>new ss,In=(t,e)=>t===e||typeof t=="object"&&typeof e=="object"&&t&&e&&iv(t,e);class Xc{constructor(e,n,r,s){this.left=e,this.right=n,this.index=r,this.currentAttributes=s}forward(){this.right===null&&Lt(),this.right.content.constructor===ct?this.right.deleted||ds(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}}const ad=(t,e,n)=>{for(;e.right!==null&&n>0;)e.right.content.constructor===ct?e.right.deleted||ds(e.currentAttributes,e.right.content):e.right.deleted||(n<e.right.length&&Rt(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},xo=(t,e,n,r)=>{const s=new Map,o=r?bi(e,n):null;if(o){const i=new Xc(o.p.left,o.p,o.index,s);return ad(t,i,n-o.index)}else{const i=new Xc(null,e._start,0,s);return ad(t,i,n)}},Th=(t,e,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===ct&&In(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=t.doc,o=s.clientID;r.forEach((i,c)=>{const l=n.left,d=n.right,h=new Ve(je(o,Ze(s.store,o)),l,l&&l.lastId,d,d&&d.id,e,null,new ct(c,i));h.integrate(t,0),n.right=h,n.forward()})},ds=(t,e)=>{const{key:n,value:r}=e;r===null?t.delete(n):t.set(n,r)},Ph=(t,e)=>{for(;t.right!==null;){if(!(t.right.deleted||t.right.content.constructor===ct&&In(e[t.right.content.key]??null,t.right.content.value)))break;t.forward()}},Ah=(t,e,n,r)=>{const s=t.doc,o=s.clientID,i=new Map;for(const c in r){const l=r[c],d=n.currentAttributes.get(c)??null;if(!In(d,l)){i.set(c,d);const{left:h,right:f}=n;n.right=new Ve(je(o,Ze(s.store,o)),h,h&&h.lastId,f,f&&f.id,e,null,new ct(c,l)),n.right.integrate(t,0),n.forward()}}return i},gc=(t,e,n,r,s)=>{n.currentAttributes.forEach((p,m)=>{s[m]===void 0&&(s[m]=null)});const o=t.doc,i=o.clientID;Ph(n,s);const c=Ah(t,e,n,s),l=r.constructor===String?new rn(r):r instanceof ft?new ln(r):new Sr(r);let{left:d,right:h,index:f}=n;e._searchMarker&&Is(e._searchMarker,n.index,l.getLength()),h=new Ve(je(i,Ze(o.store,i)),d,d&&d.lastId,h,h&&h.id,e,null,l),h.integrate(t,0),n.right=h,n.index=f,n.forward(),Th(t,e,n,c)},ld=(t,e,n,r,s)=>{const o=t.doc,i=o.clientID;Ph(n,s);const c=Ah(t,e,n,s);e:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===ct));){if(!n.right.deleted)switch(n.right.content.constructor){case ct:{const{key:l,value:d}=n.right.content,h=s[l];if(h!==void 0){if(In(h,d))c.delete(l);else{if(r===0)break e;c.set(l,d)}n.right.delete(t)}else n.currentAttributes.set(l,d);break}default:r<n.right.length&&Rt(t,je(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let l="";for(;r>0;r--)l+=`
|
|
8
|
-
`;n.right=new Ve(je(i,Ze(o.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,e,null,new rn(l)),n.right.integrate(t,0),n.forward()}Th(t,e,n,c)},Oh=(t,e,n,r,s)=>{let o=e;const i=Dt();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===ct){const d=o.content;i.set(d.key,d)}o=o.right}let c=0,l=!1;for(;e!==o;){if(n===e&&(l=!0),!e.deleted){const d=e.content;if(d.constructor===ct){const{key:h,value:f}=d,p=r.get(h)??null;(i.get(h)!==d||p===f)&&(e.delete(t),c++,!l&&(s.get(h)??null)===f&&p!==f&&(p===null?s.delete(h):s.set(h,p))),!l&&!e.deleted&&ds(s,d)}}e=e.right}return c},uC=(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===ct){const r=e.content.key;n.has(r)?e.delete(t):n.add(r)}e=e.left}},dC=t=>{let e=0;return Be(t.doc,n=>{let r=t._start,s=t._start,o=Dt();const i=Bc(o);for(;s;)s.deleted===!1&&(s.content.constructor===ct?ds(i,s.content):(e+=Oh(n,r,s,o,i),o=Bc(i),r=s)),s=s.right}),e},fC=t=>{const e=new Set,n=t.doc;for(const[r,s]of t.afterState.entries()){const o=t.beforeState.get(r)||0;s!==o&&gh(t,n.store.clients.get(r),o,s,i=>{!i.deleted&&i.content.constructor===ct&&i.constructor!==Mt&&e.add(i.parent)})}Be(n,r=>{ns(t,t.deleteSet,s=>{if(s instanceof Mt||!s.parent._hasFormatting||e.has(s.parent))return;const o=s.parent;s.content.constructor===ct?e.add(o):uC(r,s)});for(const s of e)dC(s)})},ud=(t,e,n)=>{const r=n,s=Bc(e.currentAttributes),o=e.right;for(;n>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case ln:case Sr:case rn:n<e.right.length&&Rt(t,je(e.right.id.client,e.right.id.clock+n)),n-=e.right.length,e.right.delete(t);break}e.forward()}o&&Oh(t,o,e.right,s,e.currentAttributes);const i=(e.left||e.right).parent;return i._searchMarker&&Is(i._searchMarker,e.index,-r+n),e};class hC extends wi{constructor(e,n,r){super(e,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}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=[];Be(e,r=>{const s=new Map,o=new Map;let i=this.target._start,c=null;const l={};let d="",h=0,f=0;const p=()=>{if(c!==null){let m=null;switch(c){case"delete":f>0&&(m={delete:f}),f=0;break;case"insert":(typeof d=="object"||d.length>0)&&(m={insert:d},s.size>0&&(m.attributes={},s.forEach((g,y)=>{g!==null&&(m.attributes[y]=g)}))),d="";break;case"retain":h>0&&(m={retain:h},ov(l)||(m.attributes=tv({},l))),h=0;break}m&&n.push(m),c=null}};for(;i!==null;){switch(i.content.constructor){case ln:case Sr:this.adds(i)?this.deletes(i)||(p(),c="insert",d=i.content.getContent()[0],p()):this.deletes(i)?(c!=="delete"&&(p(),c="delete"),f+=1):i.deleted||(c!=="retain"&&(p(),c="retain"),h+=1);break;case rn:this.adds(i)?this.deletes(i)||(c!=="insert"&&(p(),c="insert"),d+=i.content.str):this.deletes(i)?(c!=="delete"&&(p(),c="delete"),f+=i.length):i.deleted||(c!=="retain"&&(p(),c="retain"),h+=i.length);break;case ct:{const{key:m,value:g}=i.content;if(this.adds(i)){if(!this.deletes(i)){const y=s.get(m)??null;In(y,g)?g!==null&&i.delete(r):(c==="retain"&&p(),In(g,o.get(m)??null)?delete l[m]:l[m]=g)}}else if(this.deletes(i)){o.set(m,g);const y=s.get(m)??null;In(y,g)||(c==="retain"&&p(),l[m]=y)}else if(!i.deleted){o.set(m,g);const y=l[m];y!==void 0&&(In(y,g)?y!==null&&i.delete(r):(c==="retain"&&p(),g===null?delete l[m]:l[m]=g))}i.deleted||(c==="insert"&&p(),ds(s,i.content));break}}i=i.right}for(p();n.length>0;){const m=n[n.length-1];if(m.retain!==void 0&&m.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class os extends ft{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??vt(),this._length}_integrate(e,n){super._integrate(e,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new os}clone(){const e=new os;return e.applyDelta(this.toDelta()),e}_callObserver(e,n){super._callObserver(e,n);const r=new hC(this,e,n);xi(this,e,r),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??vt();let e="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===rn&&(e+=n.content.str),n=n.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:n=!0}={}){this.doc!==null?Be(this.doc,r=>{const s=new Xc(null,this._start,0,new Map);for(let o=0;o<e.length;o++){const i=e[o];if(i.insert!==void 0){const c=!n&&typeof i.insert=="string"&&o===e.length-1&&s.right===null&&i.insert.slice(-1)===`
|
|
9
|
-
`?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&gc(r,this,s,c,i.attributes||{})}else i.retain!==void 0?ld(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&ud(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,n,r){this.doc??vt();const s=[],o=new Map,i=this.doc;let c="",l=this._start;function d(){if(c.length>0){const f={};let p=!1;o.forEach((g,y)=>{p=!0,f[y]=g});const m={insert:c};p&&(m.attributes=f),s.push(m),c=""}}const h=()=>{for(;l!==null;){if(Mr(l,e)||n!==void 0&&Mr(l,n))switch(l.content.constructor){case rn:{const f=o.get("ychange");e!==void 0&&!Mr(l,e)?(f===void 0||f.user!==l.id.client||f.type!=="removed")&&(d(),o.set("ychange",r?r("removed",l.id):{type:"removed"})):n!==void 0&&!Mr(l,n)?(f===void 0||f.user!==l.id.client||f.type!=="added")&&(d(),o.set("ychange",r?r("added",l.id):{type:"added"})):f!==void 0&&(d(),o.delete("ychange")),c+=l.content.str;break}case ln:case Sr:{d();const f={insert:l.content.getContent()[0]};if(o.size>0){const p={};f.attributes=p,o.forEach((m,g)=>{p[g]=m})}s.push(f);break}case ct:Mr(l,e)&&(d(),ds(o,l.content));break}l=l.right}d()};return e||n?Be(i,f=>{e&&Jc(f,e),n&&Jc(f,n),h()},"cleanup"):h(),s}insert(e,n,r){if(n.length<=0)return;const s=this.doc;s!==null?Be(s,o=>{const i=xo(o,this,e,!r);r||(r={},i.currentAttributes.forEach((c,l)=>{r[l]=c})),gc(o,this,i,n,r)}):this._pending.push(()=>this.insert(e,n,r))}insertEmbed(e,n,r){const s=this.doc;s!==null?Be(s,o=>{const i=xo(o,this,e,!r);gc(o,this,i,n,r||{})}):this._pending.push(()=>this.insertEmbed(e,n,r||{}))}delete(e,n){if(n===0)return;const r=this.doc;r!==null?Be(r,s=>{ud(s,xo(s,this,e,!0),n)}):this._pending.push(()=>this.delete(e,n))}format(e,n,r){if(n===0)return;const s=this.doc;s!==null?Be(s,o=>{const i=xo(o,this,e,!1);i.right!==null&&ld(o,this,i,n,r)}):this._pending.push(()=>this.format(e,n,r))}removeAttribute(e){this.doc!==null?Be(this.doc,n=>{Go(n,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,n){this.doc!==null?Be(this.doc,r=>{ol(r,this,e,n)}):this._pending.push(()=>this.setAttribute(e,n))}getAttribute(e){return il(this,e)}getAttributes(){return jh(this)}_write(e){e.writeTypeRef(OC)}}const pC=t=>new os;class yc{constructor(e,n=()=>!0){this._filter=n,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??vt()}[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===is||n.constructor===pr)&&n._start!==null)e=n._start;else for(;e!==null;){const r=e.next;if(r!==null){e=r;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 pr extends ft{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 pr}clone(){const e=new pr;return e.insert(0,this.toArray().map(n=>n instanceof ft?n.clone():n)),e}get length(){return this.doc??vt(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new yc(this,e)}querySelector(e){e=e.toUpperCase();const r=new yc(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return r.done?null:r.value}querySelectorAll(e){return e=e.toUpperCase(),Sn(new yc(this,n=>n.nodeName&&n.nodeName.toUpperCase()===e))}_callObserver(e,n){xi(this,e,new yC(this,n,e))}toString(){return Ch(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,n={},r){const s=e.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),$s(this,o=>{s.insertBefore(o.toDOM(e,n,r),null)}),s}insert(e,n){this.doc!==null?Be(this.doc,r=>{Rh(r,this,e,n)}):this._prelimContent.splice(e,0,...n)}insertAfter(e,n){if(this.doc!==null)Be(this.doc,r=>{const s=e&&e instanceof ft?e._item:e;Ko(r,this,s,n)});else{const r=this._prelimContent,s=e===null?0:r.findIndex(o=>o===e)+1;if(s===0&&e!==null)throw Xt("Reference item not found");r.splice(s,0,...n)}}delete(e,n=1){this.doc!==null?Be(this.doc,r=>{Dh(r,this,e,n)}):this._prelimContent.splice(e,n)}toArray(){return Sh(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return Eh(this,e)}slice(e=0,n=this.length){return vh(this,e,n)}forEach(e){$s(this,e)}_write(e){e.writeTypeRef(NC)}}const mC=t=>new pr;class is extends pr{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((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new is(this.nodeName)}clone(){const e=new is(this.nodeName),n=this.getAttributes();return rv(n,(r,s)=>{e.setAttribute(s,r)}),e.insert(0,this.toArray().map(r=>r instanceof ft?r.clone():r)),e}toString(){const e=this.getAttributes(),n=[],r=[];for(const c in e)r.push(c);r.sort();const s=r.length;for(let c=0;c<s;c++){const l=r[c];n.push(l+'="'+e[l]+'"')}const o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(e){this.doc!==null?Be(this.doc,n=>{Go(n,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,n){this.doc!==null?Be(this.doc,r=>{ol(r,this,e,n)}):this._prelimAttrs.set(e,n)}getAttribute(e){return il(this,e)}hasAttribute(e){return _h(this,e)}getAttributes(e){return e?oC(this,e):jh(this)}toDOM(e=document,n={},r){const s=e.createElement(this.nodeName),o=this.getAttributes();for(const i in o){const c=o[i];typeof c=="string"&&s.setAttribute(i,c)}return $s(this,i=>{s.appendChild(i.toDOM(e,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(e){e.writeTypeRef(LC),e.writeKey(this.nodeName)}}const gC=t=>new is(t.readKey());class yC extends wi{constructor(e,n,r){super(e,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class Jo extends ss{constructor(e){super(),this.hookName=e}_copy(){return new Jo(this.hookName)}clone(){const e=new Jo(this.hookName);return this.forEach((n,r)=>{e.set(r,n)}),e}toDOM(e=document,n={},r){const s=n[this.hookName];let o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(e){e.writeTypeRef(MC),e.writeKey(this.hookName)}}const wC=t=>new Jo(t.readKey());class Yo extends os{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 Yo}clone(){const e=new Yo;return e.applyDelta(this.toDelta()),e}toDOM(e=document,n,r){const s=e.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(e=>{const n=[];for(const s in e.attributes){const o=[];for(const i in e.attributes[s])o.push({key:i,value:e.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){const o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){const c=o.attrs[i];r+=` ${c.key}="${c.value}"`}r+=">"}r+=e.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(FC)}}const bC=t=>new Yo;class cl{constructor(e,n){this.id=e,this.length=n}get deleted(){throw Jt()}mergeWith(e){return!1}write(e,n,r){throw Jt()}integrate(e,n){throw Jt()}}const xC=0;class Mt extends cl{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),mh(e.doc.store,this)}write(e,n){e.writeInfo(xC),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 Jt()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeBuf(this.content)}getRef(){return 3}}const vC=t=>new Xs(t.readBuf());class Us{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Us(this.len)}splice(e){const n=new Us(this.len-e);return this.len=e,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,n){Fs(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 SC=t=>new Us(t.readLen()),Lh=(t,e)=>new vr({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(Lh(this.doc.guid,this.opts))}splice(e){throw Jt()}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 CC=t=>new Zs(Lh(t.readString(),t.readAny()));class Sr{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Sr(this.embed)}splice(e){throw Jt()}mergeWith(e){return!1}integrate(e,n){}delete(e){}gc(e){}write(e,n){e.writeJSON(this.embed)}getRef(){return 5}}const EC=t=>new Sr(t.readJSON());class ct{constructor(e,n){this.key=e,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new ct(this.key,this.value)}splice(e){throw Jt()}mergeWith(e){return!1}integrate(e,n){const r=n.parent;r._searchMarker=null,r._hasFormatting=!0}delete(e){}gc(e){}write(e,n){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const kC=t=>new ct(t.readKey(),t.readJSON());class Xo{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Xo(this.arr)}splice(e){const n=new Xo(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 r=this.arr.length;e.writeLen(r-n);for(let s=n;s<r;s++){const o=this.arr[s];e.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}}const RC=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++){const s=t.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new Xo(n)},DC=Bo("node_env")==="development";class mr{constructor(e){this.arr=e,DC&&Df(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new mr(this.arr)}splice(e){const n=new mr(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 r=this.arr.length;e.writeLen(r-n);for(let s=n;s<r;s++){const o=this.arr[s];e.writeAny(o)}}getRef(){return 8}}const jC=t=>{const e=t.readLen(),n=[];for(let r=0;r<e;r++)n.push(t.readAny());return new mr(n)};class rn{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new rn(this.str)}splice(e){const n=new rn(this.str.slice(e));this.str=this.str.slice(0,e);const r=this.str.charCodeAt(e-1);return r>=55296&&r<=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 _C=t=>new rn(t.readString()),TC=[cC,lC,pC,gC,mC,wC,bC],PC=0,AC=1,OC=2,LC=3,NC=4,MC=5,FC=6;class ln{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ln(this.type._copy())}splice(e){throw Jt()}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(r=>{r.deleted?r.id.clock<(e.beforeState.get(r.id.client)||0)&&e._mergeStructs.push(r):r.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(r=>{for(;r!==null;)r.gc(e,!0),r=r.left}),this.type._map=new Map}write(e,n){this.type._write(e)}getRef(){return 7}}const IC=t=>new ln(TC[t.readTypeRef()](t)),Zc=(t,e)=>{let n=e,r=0,s;do r>0&&(n=je(n.client,n.clock+r)),s=qr(t,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof Ve);return{item:s,diff:r}},al=(t,e)=>{for(;t!==null&&t.keep!==e;)t.keep=e,t=t.parent._item},Zo=(t,e,n)=>{const{client:r,clock:s}=e.id,o=new Ve(je(r,s+n),e,je(r,s+n-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(n));return e.deleted&&o.markDeleted(),e.keep&&(o.keep=!0),e.redone!==null&&(o.redone=je(e.redone.client,e.redone.clock+n)),e.right=o,o.right!==null&&(o.right.left=o),t._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),e.length=n,o},dd=(t,e)=>La(t,n=>Js(n.deletions,e)),Nh=(t,e,n,r,s,o)=>{const i=t.doc,c=i.store,l=i.clientID,d=e.redone;if(d!==null)return Rt(t,d);let h=e.parent._item,f=null,p;if(h!==null&&h.deleted===!0){if(h.redone===null&&(!n.has(h)||Nh(t,h,n,r,s,o)===null))return null;for(;h.redone!==null;)h=Rt(t,h.redone)}const m=h===null?e.parent:h.content.type;if(e.parentSub===null){for(f=e.left,p=e;f!==null;){let v=f;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:Rt(t,v.redone);if(v!==null&&v.parent._item===h){f=v;break}f=f.left}for(;p!==null;){let v=p;for(;v!==null&&v.parent._item!==h;)v=v.redone===null?null:Rt(t,v.redone);if(v!==null&&v.parent._item===h){p=v;break}p=p.right}}else{if(p=null,e.right&&!s){for(f=e;f!==null&&f.right!==null&&(f.right.redone||Js(r,f.right.id)||dd(o.undoStack,f.right.id)||dd(o.redoStack,f.right.id));)for(f=f.right;f.redone;)f=Rt(t,f.redone);if(f&&f.right!==null)return null}else f=m._map.get(e.parentSub)||null;f!==null&&f.parent._item!==h&&(f=m._map.get(e.parentSub)||null)}const g=Ze(c,l),y=je(l,g),C=new Ve(y,f,f&&f.lastId,p,p&&p.id,m,e.parentSub,e.content.copy());return e.redone=y,al(C,!0),C.integrate(t,0),C};class Ve extends cl{constructor(e,n,r,s,o,i,c,l){super(e,l.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?$u:0}set marker(e){(this.info&ac)>0!==e&&(this.info^=ac)}get marker(){return(this.info&ac)>0}get keep(){return(this.info&Iu)>0}set keep(e){this.keep!==e&&(this.info^=Iu)}get countable(){return(this.info&$u)>0}get deleted(){return(this.info&cc)>0}set deleted(e){this.deleted!==e&&(this.info^=cc)}markDeleted(){this.info|=cc}getMissing(e,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Ze(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Ze(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Hr&&this.id.client!==this.parent.client&&this.parent.clock>=Ze(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=nd(e,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Rt(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Mt||this.right&&this.right.constructor===Mt)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Ve?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===Ve&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Hr){const r=qr(n,this.parent);r.constructor===Mt?this.parent=null:this.parent=r.content.type}return null}integrate(e,n){if(n>0&&(this.id.clock+=n,this.left=nd(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 r=this.left,s;if(r!==null)s=r.right;else 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;const o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),Ur(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(Ur(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(qr(e.doc.store,s.origin)))o.has(qr(e.doc.store,s.origin))||(r=s,o.clear());else break;s=s.right}this.left=r}if(this.left!==null){const r=this.left.right;this.right=r,this.left.right=this}else{let r;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,this.parent._start=this;this.right=r}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),mh(e.doc.store,this),this.content.integrate(e,this),sd(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Mt(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&&Ur(e.origin,this.lastId)&&this.right===e&&Ur(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(r=>{r.p===e&&(r.p=this,!this.deleted&&this.countable&&(r.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(),Fs(e.deleteSet,this.id.client,this.id.clock,this.length),sd(e,n,this.parentSub),this.content.delete(e)}}gc(e,n){if(!this.deleted)throw Lt();this.content.gc(e),n?zS(e,this,new Mt(this.id,this.length)):this.content=new Us(this.length)}write(e,n){const r=n>0?je(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&ai|(r===null?0:St)|(s===null?0:bn)|(o===null?0:Ps);if(e.writeInfo(i),r!==null&&e.writeLeftID(r),s!==null&&e.writeRightID(s),r===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const d=fh(c);e.writeParentInfo(!0),e.writeString(d)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Hr?(e.writeParentInfo(!1),e.writeLeftID(c)):Lt();o!==null&&e.writeString(o)}this.content.write(e,n)}}const Mh=(t,e)=>$C[e&ai](t),$C=[()=>{Lt()},SC,RC,vC,_C,EC,kC,IC,jC,CC,()=>{Lt()}],UC=10;class Ft extends cl{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,n){Lt()}write(e,n){e.writeInfo(UC),ie(e.restEncoder,this.length-n)}getMissing(e,n){return null}}const Fh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ih="__ $YJS$ __";Fh[Ih]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Fh[Ih]=!0;function zC(t){for(let e=0;e<t.length;e+=1)t[e]=Math.floor(Math.random()*256);return t}function BC(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 Qc(t=globalThis.crypto){if(typeof t?.randomUUID=="function")return t.randomUUID();const e=new Uint8Array(16),n=typeof t?.getRandomValues=="function"?t.getRandomValues(e):zC(e);return BC(n)}const $h=new Map;class WC{constructor(e){this.room=e,this.onmessage=null,this._onChange=n=>n.key===e&&this.onmessage!==null&&this.onmessage({data:vv(n.newValue||"")}),Zx(this._onChange)}postMessage(e){kf.setItem(this.room,xv(mv(e)))}close(){Qx(this._onChange)}}const VC=typeof BroadcastChannel>"u"?WC:BroadcastChannel,ll=t=>cn($h,t,()=>{const e=Bn(),n=new VC(t);return n.onmessage=r=>e.forEach(s=>s(r.data,"broadcastchannel")),{bc:n,subs:e}}),HC=(t,e)=>(ll(t).subs.add(e),e),qC=(t,e)=>{const n=ll(t),r=n.subs.delete(e);return r&&n.subs.size===0&&(n.bc.close(),$h.delete(t)),r},Fr=(t,e,n=null)=>{const r=ll(t);r.bc.postMessage(e),r.subs.forEach(s=>s(e,n))},Uh=0,ul=1,zh=2,Qo=(t,e)=>{ie(t,Uh);const n=NS(e);Ye(t,n)},Bh=(t,e,n)=>{ie(t,ul),Ye(t,el(e,n))},KC=(t,e,n)=>Bh(e,n,xt(t)),Wh=(t,e,n,r)=>{try{ah(e,xt(t),n)}catch(s){r?.(s),console.error("Caught error while handling a Yjs update",s)}},GC=(t,e)=>{ie(t,zh),Ye(t,e)},JC=Wh,YC=(t,e,n,r,s)=>{const o=be(t);switch(o){case Uh:KC(t,e,n);break;case ul:Wh(t,n,r,s);break;case zh:JC(t,n,r,s);break;default:throw new Error("Unknown message type")}return o},XC=0,ZC=(t,e,n)=>{be(t)===XC&&n(e,Ge(t))},wc=3e4;class QC extends wf{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=Wn();this.getLocalState()!==null&&wc/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const r=[];this.meta.forEach((s,o)=>{o!==this.clientID&&wc<=n-s.lastUpdated&&this.states.has(o)&&r.push(o)}),r.length>0&&dl(this,r,"timeout")},Yt(wc/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,r=this.meta.get(n),s=r===void 0?0:r.clock+1,o=this.states.get(n);e===null?this.states.delete(n):this.states.set(n,e),this.meta.set(n,{clock:s,lastUpdated:Wn()});const i=[],c=[],l=[],d=[];e===null?d.push(n):o==null?e!=null&&i.push(n):(c.push(n),Wr(o,e)||l.push(n)),(i.length>0||l.length>0||d.length>0)&&this.emit("change",[{added:i,updated:l,removed:d},"local"]),this.emit("update",[{added:i,updated:c,removed:d},"local"])}setLocalStateField(e,n){const r=this.getLocalState();r!==null&&this.setLocalState({...r,[e]:n})}getStates(){return this.states}}const dl=(t,e,n)=>{const r=[];for(let s=0;s<e.length;s++){const o=e[s];if(t.states.has(o)){if(t.states.delete(o),o===t.clientID){const i=t.meta.get(o);t.meta.set(o,{clock:i.clock+1,lastUpdated:Wn()})}r.push(o)}}r.length>0&&(t.emit("change",[{added:[],updated:[],removed:r},n]),t.emit("update",[{added:[],updated:[],removed:r},n]))},Gr=(t,e,n=t.states)=>{const r=e.length,s=Xe();ie(s,r);for(let o=0;o<r;o++){const i=e[o],c=n.get(i)||null,l=t.meta.get(i).clock;ie(s,i),ie(s,l),mt(s,JSON.stringify(c))}return $e(s)},e0=(t,e,n)=>{const r=Gn(e),s=Wn(),o=[],i=[],c=[],l=[],d=be(r);for(let h=0;h<d;h++){const f=be(r);let p=be(r);const m=JSON.parse(Ge(r)),g=t.meta.get(f),y=t.states.get(f),C=g===void 0?0:g.clock;(C<p||C===p&&m===null&&t.states.has(f))&&(m===null?f===t.clientID&&t.getLocalState()!=null?p++:t.states.delete(f):t.states.set(f,m),t.meta.set(f,{clock:p,lastUpdated:s}),g===void 0&&m!==null?o.push(f):g!==void 0&&m===null?l.push(f):m!==null&&(Wr(m,y)||c.push(f),i.push(f)))}(o.length>0||c.length>0||l.length>0)&&t.emit("change",[{added:o,updated:c,removed:l},n]),(o.length>0||i.length>0||l.length>0)&&t.emit("update",[{added:o,updated:i,removed:l},n])},t0=t=>sv(t,(e,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(e)}`).join("&"),ar=0,Vh=3,Jr=1,n0=2,Qs=[];Qs[ar]=(t,e,n,r,s)=>{ie(t,ar);const o=YC(e,t,n.doc,n);r&&o===ul&&!n.synced&&(n.synced=!0)};Qs[Vh]=(t,e,n,r,s)=>{ie(t,Jr),Ye(t,Gr(n.awareness,Array.from(n.awareness.getStates().keys())))};Qs[Jr]=(t,e,n,r,s)=>{e0(n.awareness,xt(e),n)};Qs[n0]=(t,e,n,r,s)=>{ZC(e,n.doc,(o,i)=>r0(n,i))};const fd=3e4,r0=(t,e)=>console.warn(`Permission denied to access ${t.url}.
|
|
10
|
-
${e}`),Hh=(t,e,n)=>{const r=Gn(e),s=Xe(),o=be(r),i=t.messageHandlers[o];return i?i(s,r,t,n,o):console.error("Unable to compute message"),s},ea=(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,dl(t.awareness,Array.from(t.awareness.getStates().keys()).filter(r=>r!==t.doc.clientID),t),t.emit("status",[{status:"disconnected"}])):t.wsUnsuccessfulReconnects++,setTimeout(qh,Ma(vx(2,t.wsUnsuccessfulReconnects)*100,t.maxBackoffTime),t))},qh=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=Wn();const r=Hh(t,new Uint8Array(n.data),!0);Fa(r)>1&&e.send($e(r))},e.onerror=n=>{t.emit("connection-error",[n,t])},e.onclose=n=>{ea(t,e,n)},e.onopen=()=>{t.wsLastMessageReceived=Wn(),t.wsconnecting=!1,t.wsconnected=!0,t.wsUnsuccessfulReconnects=0,t.emit("status",[{status:"connected"}]);const n=Xe();if(ie(n,ar),Qo(n,t.doc),e.send($e(n)),t.awareness.getLocalState()!==null){const r=Xe();ie(r,Jr),Ye(r,Gr(t.awareness,[t.doc.clientID])),e.send($e(r))}},t.emit("status",[{status:"connecting"}])}},bc=(t,e)=>{const n=t.ws;t.wsconnected&&n&&n.readyState===n.OPEN&&n.send(e),t.bcconnected&&Fr(t.bcChannel,e,t)};class s0 extends Na{constructor(e,n,r,{connect:s=!0,awareness:o=new QC(r),params:i={},protocols:c=[],WebSocketPolyfill:l=WebSocket,resyncInterval:d=-1,maxBackoffTime:h=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=h,this.params=i,this.protocols=c,this.roomname=n,this.doc=r,this._WS=l,this.awareness=o,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=s,this._resyncInterval=0,d>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const p=Xe();ie(p,ar),Qo(p,r),this.ws.send($e(p))}},d)),this._bcSubscriber=(p,m)=>{if(m!==this){const g=Hh(this,new Uint8Array(p),!1);Fa(g)>1&&Fr(this.bcChannel,$e(g),this)}},this._updateHandler=(p,m)=>{if(m!==this){const g=Xe();ie(g,ar),GC(g,p),bc(this,$e(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:p,updated:m,removed:g},y)=>{const C=p.concat(m).concat(g),v=Xe();ie(v,Jr),Ye(v,Gr(o,C)),bc(this,$e(v))},this._exitHandler=()=>{dl(this.awareness,[r.clientID],"app closed")},Vn&&typeof process<"u"&&process.on("exit",this._exitHandler),o.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&fd<Wn()-this.wsLastMessageReceived&&ea(this,this.ws,null)},fd/10),s&&this.connect()}get url(){const e=t0(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(),Vn&&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||(HC(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const e=Xe();ie(e,ar),Qo(e,this.doc),Fr(this.bcChannel,$e(e),this);const n=Xe();ie(n,ar),Bh(n,this.doc),Fr(this.bcChannel,$e(n),this);const r=Xe();ie(r,Vh),Fr(this.bcChannel,$e(r),this);const s=Xe();ie(s,Jr),Ye(s,Gr(this.awareness,[this.doc.clientID])),Fr(this.bcChannel,$e(s),this)}disconnectBc(){const e=Xe();ie(e,Jr),Ye(e,Gr(this.awareness,[this.doc.clientID],new Map)),bc(this,$e(e)),this.bcconnected&&(qC(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&ea(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(qh(this),this.connectBc())}}const Cr=t=>es((e,n)=>{t.onerror=r=>n(new Error(r.target.error)),t.onsuccess=r=>e(r.target.result)}),o0=(t,e)=>es((n,r)=>{const s=indexedDB.open(t);s.onupgradeneeded=o=>e(o.target.result),s.onerror=o=>r(Xt(o.target.error)),s.onsuccess=o=>{const i=o.target.result;i.onversionchange=()=>{i.close()},n(i)}}),i0=t=>Cr(indexedDB.deleteDatabase(t)),c0=(t,e)=>e.forEach(n=>t.createObjectStore.apply(t,n)),ks=(t,e,n="readwrite")=>{const r=t.transaction(e,n);return e.map(s=>m0(r,s))},Kh=(t,e)=>Cr(t.count(e)),a0=(t,e)=>Cr(t.get(e)),Gh=(t,e)=>Cr(t.delete(e)),l0=(t,e,n)=>Cr(t.put(e,n)),ta=(t,e)=>Cr(t.add(e)),u0=(t,e,n)=>Cr(t.getAll(e,n)),d0=(t,e,n)=>{let r=null;return p0(t,e,s=>(r=s,!1),n).then(()=>r)},f0=(t,e=null)=>d0(t,e,"prev"),h0=(t,e)=>es((n,r)=>{t.onerror=r,t.onsuccess=async s=>{const o=s.target.result;if(o===null||await e(o)===!1)return n();o.continue()}}),p0=(t,e,n,r="next")=>h0(t.openKeyCursor(e,r),s=>n(s.key)),m0=(t,e)=>t.objectStore(e),g0=(t,e)=>IDBKeyRange.upperBound(t,e),y0=(t,e)=>IDBKeyRange.lowerBound(t,e),xc="custom",Jh="updates",Yh=500,Xh=(t,e=()=>{},n=()=>{})=>{const[r]=ks(t.db,[Jh]);return u0(r,y0(t._dbref,!1)).then(s=>{t._destroyed||(e(r),Be(t.doc,()=>{s.forEach(o=>ah(t.doc,o))},t,!1),n(r))}).then(()=>f0(r).then(s=>{t._dbref=s+1})).then(()=>Kh(r).then(s=>{t._dbsize=s})).then(()=>r)},w0=(t,e=!0)=>Xh(t).then(n=>{(e||t._dbsize>=Yh)&&ta(n,el(t.doc)).then(()=>Gh(n,g0(t._dbref,!0))).then(()=>Kh(n).then(r=>{t._dbsize=r}))});class b0 extends wf{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=o0(e,r=>c0(r,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=es(r=>this.on("synced",()=>r(this))),this._db.then(r=>{this.db=r,Xh(this,i=>ta(i,el(n)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(r,s)=>{if(this.db&&s!==this){const[o]=ks(this.db,[Jh]);ta(o,r),++this._dbsize>=Yh&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{w0(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(()=>{i0(this.name)})}get(e){return this._db.then(n=>{const[r]=ks(n,[xc],"readonly");return a0(r,e)})}set(e,n){return this._db.then(r=>{const[s]=ks(r,[xc]);return l0(s,n,e)})}del(e){return this._db.then(n=>{const[r]=ks(n,[xc]);return Gh(r,e)})}}const x0={Sync:0,Awareness:1,Flush:4,Protocol:5,Maintenance:6,Permission:7,CompileStates:8,FormatLease:9},vc=3,v0=["queued","running","succeeded","failed","cleaned"],S0=["cache","artifacts"];function C0(t){return typeof t=="string"&&v0.includes(t)}function E0(t){return typeof t=="string"&&S0.includes(t)}const hd=[["#1677c8","#1677c833"],["#d65745","#d6574533"],["#16866a","#16866a33"],["#9a58b5","#9a58b533"],["#d27b18","#d27b1833"],["#3f7d20","#3f7d2033"],["#be3e7b","#be3e7b33"],["#4964c6","#4964c633"],["#8a6a14","#8a6a1433"],["#087f8c","#087f8c33"]],{Sync:k0,Awareness:R0,Flush:pd,Protocol:md,Maintenance:D0,Permission:j0,CompileStates:_0,FormatLease:Sc}=x0,T0=6e4,P0=720*60*60*1e3,A0=15e3,O0=5*6e4;function L0(t){if(!t||typeof t!="object")return null;const e=t,n=e.requestedBy;return typeof e.mainFile!="string"||typeof e.runId!="string"||!C0(e.status)||e.status==="cleaned"&&!E0(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 gd(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e={};for(const[n,r]of Object.entries(t)){const s=L0(r);s&&s.mainFile===n&&(e[n]=s)}return e}function N0(t,e,n){return t<=n&&e<=n}function yd(t,e,n){const r=s=>s>0&&n-s<=O0;return{recoverable:t.some(s=>s.tabId===e||!r(s.activeAt)),otherActive:t.some(s=>s.tabId!==e&&r(s.activeAt))}}class M0{constructor(e,n){this.projectId=e,this.user=n;const r=window.location.protocol==="https:"?"wss:":"ws:";this.draftTabId=U0(ir(`texlite:collaboration-tab:${n.id}:${e}`));const s=this.readOwnWritableDraftMarker();this.draftGeneration=s?.generation??0,this.draftUpdatedAt=s?.updatedAt??0,this.draftMarkerPresent=s!==null,this.markDraftTabInactive=()=>this.setOwnDraftActivity(!1),this.markDraftTabActive=()=>this.resumeOwnDraftActivity(),window.addEventListener("pagehide",this.markDraftTabInactive),window.addEventListener("pageshow",this.markDraftTabActive),s&&(this.setOwnDraftActivity(!0),this.startDraftHeartbeat()),this.persistence=new b0(ir(`texlite:${n.id}:${e}`),this.doc),this.localDraftTransactionObserver=i=>{if(i.local){for(const[c,l]of this.doc.share)if(c.startsWith("source:")&&(i.changed.has(l)||i.changedParentTypes.has(l))){this.markWritableDraft();return}}},this.doc.on("afterTransaction",this.localDraftTransactionObserver),this.persistence.on("synced",()=>{this.localDraftReady=!0;for(const i of this.draftListeners)i()}),this.provider=new s0(`${r}//${window.location.host}${cs("/api/collaboration")}`,e,this.doc,{connect:!1,disableBc:!0,maxBackoffTime:2500}),this.awareness=this.provider.awareness;const o=this.doc.getMap("texlite:meta");this.metaObserver=(i,c)=>{c.origin===this.provider&&i.keysChanged.has("compileStates")&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners())},o.observe(this.metaObserver),this.provider.messageHandlers[pd]=(i,c)=>{const l=Ge(c),d=this.flushRequests.get(l);if(!d)return;const h=be(c)===1,f=be(c),p=Ge(c),m=be(c),g=[];for(let y=0;y<m;y++)g.push(Ge(c));if(window.clearTimeout(d.timer),this.flushRequests.delete(l),h)this.clearOwnWritableDraftMarker(d.draftGeneration),d.resolve({revision:f,persistedAt:p,ok:!0,failedPaths:[]});else{const y=Object.assign(new Error(g.length?`保存失败:${g.join(", ")}`:"源码保存到服务器磁盘失败"),{failedPaths:g});d.reject(y)}},this.provider.messageHandlers[md]=(i,c)=>{const l=Ge(c),d=this.epochStorageKey(),h=wd(d),f=/^([0-9]+):/.exec(l)?.[1]??null,p=h?/^([0-9]+):/.exec(h)?.[1]??null:null,m=!this.epoch&&f===String(vc)&&p!==null&&p!==f;if((this.epoch&&this.epoch!==l||h&&h!==l)&&!m){this.provider.disconnect(),this.rejectFlushes(new Error("Collaboration state changed"));const D=l.endsWith(":reload")||f!==null&&f!==String(vc),b=()=>{Cc(d,l.replace(/:reload$/,"")),window.location.reload()};if(D)for(const w of this.protocolUpgradeListeners)w();else this.persistence.clearData().then(()=>{this.clearWritableDraftMarkers(),b()});return}this.epoch=l,Cc(d,l);const g=this.provider.ws;if(!g||g.readyState!==WebSocket.OPEN)return;const y=Xe();ie(y,md),mt(y,l),ie(y,vc),g.send($e(y));const C=Xe();ie(C,k0),Qo(C,this.doc),g.send($e(C));const v=Xe();ie(v,R0),Ye(v,Gr(this.awareness,[this.doc.clientID])),g.send($e(v))},this.provider.messageHandlers[j0]=(i,c)=>{const l=Ge(c),d=Ge(c);if(l!==this.user.id)return;if(d==="revoked"){this.rejectFlushes(new Error("Project access revoked")),this.provider.disconnect();for(const f of this.permissionListeners)f("revoked",this.permission);return}if(d!=="read"&&d!=="edit"&&d!=="owner")return;const h=this.permission;if(this.setPermission(d),h!==d){d==="read"&&this.rejectFlushes(new Error("Project permission changed to read-only"));for(const f of this.permissionListeners)f(d,h)}},this.provider.messageHandlers[D0]=(i,c)=>{Ge(c)},this.provider.messageHandlers[_0]=(i,c)=>{let l={};try{l=gd(JSON.parse(Ge(c)))}catch{}this.authoritativeCompileStates=l,this.notifyCompileStateListeners()},this.provider.messageHandlers[Sc]=(i,c)=>{const l=Ge(c),d=Ge(c),h=Ge(c),f=Ge(c),p=Ge(c),m=Ge(c);if(l==="state"){const y=Hc(c)?Ge(c):"",C=Hc(c)?Ge(c):"",v=Number(p);if(!y||!Number.isFinite(v)||v<=Date.now())this.removeFormatLeaseState(h),this.notifyFormatLeaseListeners(null);else{const D={path:h,holderUserId:y,holderName:C,expiresAt:v};this.formatLeaseStatesByPath.set(h,D);const b=this.formatLeaseExpiryTimers.get(h);b!==void 0&&window.clearTimeout(b);const w=window.setTimeout(()=>{const R=this.formatLeaseStatesByPath.get(h);!R||R.expiresAt>Date.now()||(this.removeFormatLeaseState(h),this.notifyFormatLeaseListeners(null))},Math.max(0,v-Date.now())+25);this.formatLeaseExpiryTimers.set(h,w),this.notifyFormatLeaseListeners(D)}return}const g=this.formatLeaseRequests.get(d);g&&(window.clearTimeout(g.timer),this.formatLeaseRequests.delete(d),l==="denied"?g.reject(new Error(m||"Format lease request was denied")):g.resolve({status:l,filePath:h,token:f,expiresAt:Number(p)}))},this.provider.on("status",({status:i})=>{i==="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 vr;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 r=new qS(this.getText(e));return this.undoManagers.set(e,r),r}applyTextEdits(e,n){if(this.permission==="read")throw new Error("Read-only collaborators cannot edit source files");const r=this.getText(e);let s=0;for(const o of n){if(!Number.isInteger(o.from)||!Number.isInteger(o.to)||o.from<s||o.to<o.from||o.to>r.length)throw new RangeError("Invalid collaborative text edits");s=o.to}this.doc.transact(()=>{for(let o=n.length-1;o>=0;o-=1){const i=n[o];i.to>i.from&&r.delete(i.from,i.to-i.from),i.replacement&&r.insert(i.from,i.replacement)}})}get meta(){return this.doc.getMap("texlite:meta")}compileStates(){return this.authoritativeCompileStates??gd(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 yd(e.map(({tabId:n,marker:r})=>({tabId:n,activeAt:r.activeAt})),this.draftTabId,Date.now()).recoverable}get hasOtherWritableDraft(){const e=this.readWritableDraftMarkers();return yd(e.map(({tabId:n,marker:r})=>({tabId:n,activeAt:r.activeAt})),this.draftTabId,Date.now()).otherActive}setPermission(e,n=!1){const r=this.permission;if(this.permission=e,e==="read"&&(r!=="read"&&this.rejectFlushes(new Error("Project permission changed to read-only")),this.destroyUndoManagers(),this.clearFormatLeaseStates()),this.updateLocalAwareness(),n&&r!==e)for(const s of this.permissionListeners)s(e,r)}setActiveFile(e){this.activeFile!==e&&(this.activeFile=e,this.awareness.setLocalStateField("cursor",null),this.updateLocalAwareness())}sessions(){const e=[];return this.awareness.getStates().forEach((n,r)=>{const s=n?.user;!s||typeof s.id!="string"||typeof s.name!="string"||e.push({clientId:r,userId:s.id,username:typeof s.username=="string"?s.username:s.name,name:s.name,color:typeof s.color=="string"?s.color:"#1677c8",colorLight:typeof s.colorLight=="string"?s.colorLight:"#1677c833",permission:s.permission==="owner"||s.permission==="edit"?s.permission:"read",filePath:typeof n.filePath=="string"?n.filePath:"",editing:!!n.cursor,local:r===this.doc.clientID})}),e.sort((n,r)=>Number(r.local)-Number(n.local)||n.name.localeCompare(r.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=Qc(),r=this.draftGeneration,s=Xe();return ie(s,pd),mt(s,n),new Promise((o,i)=>{const c=window.setTimeout(()=>{this.flushRequests.delete(n),i(new Error("Collaboration save timed out"))},5e3);this.flushRequests.set(n,{resolve:o,reject:i,timer:c,draftGeneration:r}),e.send($e(s))})}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,r]of this.formatLeaseStatesByPath)r.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 r=n.token,s=n.expiresAt,o=!1;const i=async()=>{if(o)throw new Error("Format lease has already been released");const l=await this.requestFormatLease("renew",e,r);if(l.status!=="renewed"||!Number.isFinite(l.expiresAt))throw new Error("Format lease renewal failed");r=l.token||r,s=l.expiresAt};return{path:e,get token(){return r},get expiresAt(){return s},confirm:i,renew:i,release:async()=>{if(o)return;o=!0;const l=this.provider.ws;if(!(!l||l.readyState!==WebSocket.OPEN))try{await this.requestFormatLease("release",e,r)}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,r=""){const s=this.provider.ws;if(!this.provider.synced||!s||s.readyState!==WebSocket.OPEN)return Promise.reject(new Error("Collaboration connection is unavailable"));const o=Qc(),i=Xe();return ie(i,Sc),mt(i,e),mt(i,o),mt(i,n),mt(i,r),new Promise((c,l)=>{const d=window.setTimeout(()=>{if(this.formatLeaseRequests.delete(o),e==="acquire"){const h=this.provider.ws;if(h?.readyState===WebSocket.OPEN){const f=Xe();ie(f,Sc),mt(f,"cancel"),mt(f,o),mt(f,n),mt(f,""),h.send($e(f))}}l(new Error("Format lease request timed out"))},e==="acquire"?T0:5e3);this.formatLeaseRequests.set(o,{resolve:c,reject:l,timer:d}),s.send($e(i))})}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]=hd[Math.abs(this.doc.clientID)%hd.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 ir(`texlite:collaboration-epoch:${this.user.id}:${this.projectId}`)}writableDraftStoragePrefix(){return`${ir(`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())Cs(e);this.draftMarkerPresent=!1,this.stopDraftHeartbeat(),Cs(this.writableDraftStoragePrefix().slice(0,-1))}clearOwnWritableDraftMarker(e){const n=this.readOwnWritableDraftMarker();!n||!N0(n.generation,this.draftGeneration,e)||(Cs(this.ownWritableDraftStorageKey()),this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}readOwnWritableDraftMarker(){return this.readWritableDraftMarker(this.ownWritableDraftStorageKey())}readWritableDraftMarkers(){const e=this.writableDraftStoragePrefix(),n=[];for(const r of F0()){if(!r.startsWith(e))continue;const s=this.readWritableDraftMarker(r);s&&n.push({key:r,tabId:r.slice(e.length),marker:s})}return n}readWritableDraftMarker(e){const n=wd(e);if(!n)return null;try{const r=JSON.parse(n);if(!r||typeof r!="object"||Array.isArray(r))return null;const s=r,o=Date.now();if(!Number.isInteger(s.generation)||(s.generation??0)<0||typeof s.updatedAt!="number"||!Number.isFinite(s.updatedAt)||s.updatedAt<=0||o-s.updatedAt>P0)return Cs(e),null;const i=typeof s.activeAt=="number"&&Number.isFinite(s.activeAt)?Math.max(0,s.activeAt):0;return{generation:s.generation,updatedAt:s.updatedAt,activeAt:i}}catch{return Cs(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};Cc(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)},A0))}stopDraftHeartbeat(){this.draftHeartbeatTimer!==null&&(window.clearInterval(this.draftHeartbeatTimer),this.draftHeartbeatTimer=null)}}function wd(t){try{return window.localStorage.getItem(t)}catch{return null}}function Cc(t,e){try{window.localStorage.setItem(t,e)}catch{}}function Cs(t){try{window.localStorage.removeItem(t)}catch{}}function F0(){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 I0(t){try{return window.sessionStorage.getItem(t)}catch{return null}}function $0(t,e){try{window.sessionStorage.setItem(t,e)}catch{}}function U0(t){const e=I0(t);if(e)return e;const n=Qc();return $0(t,n),n}function z0(t,e){return Array.from(t.trim()||e.trim()||"?")[0]?.toLocaleUpperCase()??"?"}function B0(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 W0(t,e,n,r,s,o){const[i]=u.useState(()=>new M0(t,e)),[c,l]=u.useState("connecting"),[d,h]=u.useState(!1),[f,p]=u.useState([]),[m,g]=u.useState(null),[y,C]=u.useState(null),[v,D]=u.useState(""),[b,w]=u.useState(!1),[R,S]=u.useState(""),[E,j]=u.useState(""),[P,$]=u.useState([]),[J,T]=u.useState(!1),[V,U]=u.useState(r),[B,z]=u.useState(null),[re,H]=u.useState(!1),X=u.useRef(n),Q=u.useRef(o),Z=u.useRef(s);X.current=n,Q.current=o,Z.current=s,u.useEffect(()=>{const A=i.compileStates();g(A[n]??null)},[n,i]),u.useEffect(()=>{const A=()=>p(i.sessions()),q=()=>{h(!1),p([]),g(null),C(null),D(""),w(!1),S(""),j(""),$([]),Q.current()},fe=({status:de})=>{l(de),de!=="connected"&&q()},W=de=>{h(de),de||q()},ee=()=>{l("disconnected"),q()},Ee=()=>{w(i.meta.get("historyWarning")===!0);const de=i.meta.get("filesEvent");B0(de)&&C(de);const ve=i.meta.get("commentsRevision");typeof ve=="string"&&D(ve);const We=i.meta.get("dictionaryRevision");typeof We=="string"&&S(We);const Me=i.meta.get("chktexSettingsRevision");typeof Me=="string"&&j(Me);const ke=i.compileStates();g(ke[X.current]??null)},pe=()=>{const de=i.compileStates();g(de[X.current]??null)};i.awareness.on("change",A),i.provider.on("status",fe),i.provider.on("sync",W),i.provider.on("connection-close",ee),i.provider.on("connection-error",ee),i.meta.observe(Ee);const K=i.onCompileStates(pe),ae=i.onProtocolUpgrade(()=>{H(!0),l("disconnected"),q()}),L=()=>$(i.formatLeaseStates()),Re=i.onFormatLeaseState(L),Fe=()=>{if(!Z.current||i.currentPermission!=="read")return;const de=i.hasWritableDraft,ve=i.hasOtherWritableDraft;!de&&!ve||z({previous:"edit",localDraftReady:de,otherTabDraft:ve})},Te=i.onDraftReady(()=>{T(!0),Fe()}),Ue=i.onPermissionChanged((de,ve)=>{if(de==="revoked"){l("disconnected"),h(!1),Q.current();return}U(de),de==="read"&&ve!=="read"?z({previous:ve,localDraftReady:i.hasWritableDraft,otherTabDraft:i.hasOtherWritableDraft}):de!=="read"&&z(null)});return A(),Ee(),l(i.connected?"connected":"connecting"),h(i.synced),()=>{i.awareness.off("change",A),i.provider.off("status",fe),i.provider.off("sync",W),i.provider.off("connection-close",ee),i.provider.off("connection-error",ee),i.meta.unobserve(Ee),K(),ae(),Re(),Te(),Ue(),i.destroy()}},[i]),u.useEffect(()=>{s&&i.connect()},[i,s]),u.useEffect(()=>{i.setPermission(r),U(r),s&&r==="read"&&(i.hasWritableDraft||i.hasOtherWritableDraft)?z({previous:"edit",localDraftReady:i.hasWritableDraft,otherTabDraft:i.hasOtherWritableDraft}):r!=="read"&&z(null)},[i,r,s]);const ge=B!==null;return u.useEffect(()=>{if(!ge)return;const A=()=>{if(i.currentPermission!=="read")return;const fe=i.hasWritableDraft,W=i.hasOtherWritableDraft;z(ee=>!ee||ee.localDraftReady===fe&&ee.otherTabDraft===W?ee:{...ee,localDraftReady:fe,otherTabDraft:W})};A();const q=window.setInterval(A,2e3);return()=>window.clearInterval(q)},[i,ge]),{collaboration:i,status:c,synced:d,activeSessions:f,compileState:m,setCompileState:g,formatLeaseStates:P,filesEvent:y,commentsRevision:v,historyWarning:b,dictionaryRevision:R,chktexSettingsRevision:E,localDraftReady:J,permission:V,protocolUpgradeRequired:re,reconnect:()=>{re||(l("connecting"),h(!1),p([]),g(null),$([]),i.reconnect())},permissionDowngrade:B,dismissPermissionDowngrade:()=>z(null),discardLocalDraft:async()=>await i.discardLocalDraft()?(z(null),window.location.reload(),!0):(z(q=>q&&{...q,otherTabDraft:!0}),!1)}}function bd(t){return t?.status==="succeeded"?"succeeded":t?.log.includes("Compilation was cancelled.")?"cancelled":t?.status==="failed"?"failed":null}function nr(t){return t instanceof Error&&t.name==="AbortError"}function V0(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement}function H0(t){return t instanceof Element&&!!t.closest('[role="dialog"], [role="alertdialog"]')}function q0({projectId:t,project:e,mainFile:n,resolveCompileMainFile:r,getCurrentMainFile:s,initialLatest:o,collaborationSynced:i,sharedState:c,onSharedState:l,save:d,loadOutline:h,onPreviewTab:f,onError:p,onCompileStart:m,onCompileSuccess:g,onPdfChanged:y}){const{t:C}=Qe(),[v,D]=u.useState(""),[b,w]=u.useState(!0),[R,S]=u.useState(null),[E,j]=u.useState(null),[P,$]=u.useState("full"),[J,T]=u.useState(""),[V,U]=u.useState(null),[B,z]=u.useState(null),[re,H]=u.useState([]),[X,Q]=u.useState(null),[Z,ge]=u.useState(!1),[ye,Ce]=u.useState(!1),[_e,A]=u.useState(()=>new Set),[q,fe]=u.useState(()=>new Set),[W,ee]=u.useState(""),[Ee,pe]=u.useState({projectId:t,mainFile:n}),K=u.useRef(n),ae=u.useRef(""),L=u.useRef(""),Re=u.useRef({projectId:t,mainFile:n}),Fe=u.useRef(!0),Te=u.useRef(null),Ue=u.useRef(null),de=u.useRef(null),ve=u.useRef(o),We=u.useRef(!1),Me=u.useRef(null),ke=u.useRef(null),O=u.useRef(new Set),Pe=u.useRef(new Map),Je=u.useRef(null),it=u.useRef(()=>{}),we=u.useRef({onSharedState:l,save:d,loadOutline:h,onPreviewTab:f,onError:p,onCompileStart:m,onCompileSuccess:g,onPdfChanged:y,resolveCompileMainFile:r,getCurrentMainFile:s});K.current=n,we.current={onSharedState:l,save:d,loadOutline:h,onPreviewTab:f,onError:p,onCompileStart:m,onCompileSuccess:g,onPdfChanged:y,resolveCompileMainFile:r,getCurrentMainFile:s};const Y=()=>we.current.getCurrentMainFile?.()||K.current,se=Ee.projectId===t&&Ee.mainFile===n,De=te=>{Je.current!==te&&(Je.current=te,we.current.onCompileSuccess())},ze=(te,_,M,oe,yt)=>{(L.current!==_||ae.current!==te)&&we.current.onPdfChanged(),L.current=_,ae.current=te,D(_),S(M),j(oe),$(yt??"full")},G=async(te,_)=>{_||(Me.current?.abort(),Me.current=new AbortController,_=Me.current.signal);try{const M=te?`?mainFile=${encodeURIComponent(te)}`:"",oe=await xe(`/api/projects/${t}/compile/artifacts${M}`,{signal:_});K.current===te&&(H(oe.artifacts),Q(null))}catch(M){!nr(M)&&K.current===te&&(H([]),Q(null))}finally{Me.current?.signal===_&&(Me.current=null)}};u.useEffect(()=>{Te.current?.abort(),Te.current=null;const te=Re.current,_=te.projectId===t,M=_&&!!te.mainFile&&!!n&&te.mainFile!==n;if(Re.current={projectId:t,mainFile:n},pe(Ae=>Ae.projectId===t&&Ae.mainFile===n?Ae:{projectId:t,mainFile:n}),_||(ve.current=o,We.current=!1,de.current=null,ae.current="",L.current=""),!n){w(!1),L.current="",D(""),S(null),j(null),$("full"),T(""),U(null),z(null),H([]),Q(null),ge(!1),ee(""),de.current=null,we.current.onPdfChanged();return}if(de.current?.mainFile!==n&&(de.current=null),T(""),U(null),z(null),M){Fe.current=!1,Ue.current?.abort(),Me.current?.abort(),ke.current?.abort(),ae.current="",L.current="",D(""),S(null),j(null),$("full"),w(!1),H([]),Q(null),ge(!1),ee(""),we.current.onPdfChanged(),we.current.onPreviewTab("pdf");const Ae=new AbortController;return we.current.loadOutline(Ae.signal,n).catch(()=>{}),()=>Ae.abort()}Fe.current=!0;const oe=new AbortController;Te.current=oe,w(!0),_&&v&&n&&ae.current===n||(L.current="",D(""),S(null),j(null),$("full")),H([]),Q(null),we.current.onPdfChanged();let I=null;const ne=`?mainFile=${encodeURIComponent(n)}`,Et=We.current?null:ve.current;Et&&(We.current=!0);const Tt=()=>xe(`/api/projects/${t}/compile/latest${ne}`,{signal:oe.signal}),Dr=Et?Et.then(Ae=>Ae.mainFile!==n?Tt():Ae,()=>Tt()):Tt();let wt=!1;const Pi=()=>{if(wt||oe.signal.aborted||!n)return;wt=!0;const Ae=new AbortController;O.current.add(Ae),G(n,Ae.signal).finally(()=>{O.current.delete(Ae)}),we.current.loadOutline(oe.signal,n).catch(()=>{})};return Dr.then(Ae=>{if(oe.signal.aborted||n&&Ae.mainFile!==K.current)return;const ms=de.current;ms&&ms.mainFile===n&&Ae.latestRun?.id!==ms.runId||(T(Ae.latestRun?.log??""),U(Ae.latestRun?.diagnostics??null),z(bd(Ae.latestRun)),n&&Ae.latestRun?.requestedBy&&(Ae.latestRun.status==="queued"||Ae.latestRun.status==="running")&&we.current.onSharedState({mainFile:n,runId:Ae.latestRun.id,status:Ae.latestRun.status,requestedBy:Ae.latestRun.requestedBy,updatedAt:new Date().toISOString()}),Ae.pdfUrl&&(ze(Ae.mainFile,Ae.pdfUrl,Ae.pdfCompiledAt,Ae.pdfSizeBytes,Ae.pdfLoadingMode),we.current.onPreviewTab("pdf")))}).catch(Ae=>{!nr(Ae)&&K.current===n&&we.current.onError(Se(Ae))}).finally(()=>{Te.current===oe&&(Te.current=null),oe.signal.aborted||(w(!1),I=window.setTimeout(Pi,0))}),()=>{I!==null&&window.clearTimeout(I),oe.abort(),ke.current?.abort();for(const Ae of O.current)Ae.abort();O.current.clear()}},[t,n]),u.useEffect(()=>{if(!(!c||c.mainFile!==n||c.status!=="cleaned"||!c.cleanMode)){Te.current?.abort(),Ue.current?.abort(),Me.current?.abort(),ke.current?.abort();for(const te of O.current)te.abort();O.current.clear(),c.cleanMode==="artifacts"?(de.current=null,T(""),U(null),z(null),L.current="",D(""),S(null),j(null),$("full"),H([]),Q(null),we.current.onPdfChanged(),we.current.onPreviewTab("pdf"),ee(C("editor.cleanArtifactsComplete"))):ee(C("editor.cleanCacheComplete"))}},[c?.runId,c?.status,c?.cleanMode,c?.mainFile,n,C]),u.useEffect(()=>{!n||c?.mainFile===n&&(c.status==="queued"||c.status==="running")||fe(te=>{if(!te.has(n))return te;const _=new Set(te);return _.delete(n),_})},[n,c?.mainFile,c?.status]),u.useEffect(()=>{c?.mainFile===n&&(c.status==="queued"||c.status==="running")&&(Fe.current=!0)},[n,c?.mainFile,c?.status,c?.runId]),u.useEffect(()=>{if(!c||c.mainFile!==n||c.status!=="succeeded"&&c.status!=="failed"||!Fe.current)return;let te=!1;Ue.current?.abort(),ke.current?.abort();const _=new AbortController;return Ue.current=_,w(!0),xe(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(n)}`,{signal:_.signal}).then(M=>{te||M.mainFile!==K.current||M.latestRun?.id!==c.runId||(T(M.latestRun.log),U(M.latestRun.diagnostics),z(bd(M.latestRun)),c.status==="succeeded"&&c.stale&&ee(C("editor.compileSnapshotStale")),c.status==="succeeded"&&M.pdfUrl?(de.current={mainFile:n,runId:c.runId},ze(n,M.pdfUrl,M.pdfCompiledAt,M.pdfSizeBytes,M.pdfLoadingMode),we.current.onPreviewTab("pdf"),De(c.runId),G(n)):c.status==="failed"&&we.current.onPreviewTab(M.latestRun.diagnostics.errors.length?"errors":"log"))}).catch(M=>{!nr(M)&&!te&&we.current.onError(Se(M))}).finally(()=>{Ue.current===_&&(Ue.current=null),te||w(!1)}),()=>{te=!0,_.abort(),Ue.current===_&&(Ue.current=null)}},[c?.runId,c?.status,c?.mainFile,c?.stale,n,t,C]);const le=async()=>{if(!e||e.permission==="read"||!i)return;const te=we.current.resolveCompileMainFile?.()||Y();if(!te||Pe.current.has(te)||c?.mainFile===te&&(c.status==="queued"||c.status==="running"))return;A(M=>new Set([...M,te])),we.current.onCompileStart(),ee(""),ke.current?.abort(),ke.current=null,T(""),U(null),z(null),we.current.onPreviewTab(se&&v?"pdf":"log");const _=new AbortController;Pe.current.set(te,_);try{if(!await we.current.save())return;Fe.current=!0;const M=await xe(`/api/projects/${t}/compile`,{method:"POST",signal:_.signal,body:JSON.stringify({mainFile:te})});if(M.mainFile!==te||Y()!==te)return;T(M.log),U(M.diagnostics),z(M.cancelled?"cancelled":M.ok?"succeeded":"failed"),M.cancelled&&ee(C("compileControls.cancelled")),M.skipped&&ee(C("editor.upToDate")),M.ok&&M.stale&&ee(C("editor.compileSnapshotStale")),M.pdfUrl?(M.ok&&(de.current={mainFile:te,runId:M.runId}),ze(te,M.pdfUrl,M.pdfCompiledAt,M.pdfSizeBytes,M.pdfLoadingMode),we.current.onPreviewTab("pdf"),M.ok&&(M.skipped?we.current.onCompileSuccess():De(M.runId))):we.current.onPreviewTab(M.diagnostics.errors.length?"errors":"log")}catch(M){!nr(M)&&Y()===te&&we.current.onError(Se(M))}finally{Pe.current.get(te)===_&&(Pe.current.delete(te),A(M=>{const oe=new Set(M);return oe.delete(te),oe}),fe(M=>{if(!M.has(te))return M;const oe=new Set(M);return oe.delete(te),oe}))}},Oe=async()=>{if(!e||e.permission==="read"||!i)return;const te=Y();if(te){fe(_=>new Set([..._,te]));try{(await xe(`/api/projects/${t}/compile/cancel`,{method:"POST",body:JSON.stringify({mainFile:te})})).cancelled||fe(M=>{const oe=new Set(M);return oe.delete(te),oe})}catch(_){fe(M=>{const oe=new Set(M);return oe.delete(te),oe}),!nr(_)&&Y()===te&&we.current.onError(Se(_))}}},ce=async te=>{if(!e||e.permission==="read"||!i||ye)return;const _=Y();if(!(!_||Pe.current.has(_)||c?.mainFile===_&&(c.status==="queued"||c.status==="running"))){Ce(!0),Te.current?.abort(),Ue.current?.abort(),Me.current?.abort(),ke.current?.abort();try{if((await xe(`/api/projects/${t}/compile/clean`,{method:"POST",body:JSON.stringify({mainFile:_,mode:te})})).mainFile!==_||Y()!==_)return;we.current.onSharedState(null),te==="artifacts"&&(de.current=null,T(""),U(null),z(null),L.current="",D(""),S(null),j(null),$("full"),H([]),Q(null),we.current.onPdfChanged()),ee(C(te==="cache"?"editor.cleanCacheComplete":"editor.cleanArtifactsComplete"))}catch(M){!nr(M)&&Y()===_&&we.current.onError(Se(M))}finally{Ce(!1)}}};it.current=()=>{le()},u.useEffect(()=>{if(!W)return;const te=window.setTimeout(()=>ee(""),3e3);return()=>window.clearTimeout(te)},[W]),u.useEffect(()=>{const te=_=>{if(!(!(_.ctrlKey||_.metaKey)||_.key.toLocaleLowerCase()!=="s")){if(V0(_.target)||H0(_.target)){_.preventDefault();return}_.preventDefault(),_.stopPropagation(),_.repeat||it.current()}};return window.addEventListener("keydown",te,!0),()=>window.removeEventListener("keydown",te,!0)},[]),u.useEffect(()=>()=>{Te.current?.abort(),Ue.current?.abort(),Me.current?.abort(),ke.current?.abort();for(const te of O.current)te.abort();O.current.clear();for(const te of Pe.current.values())te.abort();Pe.current.clear()},[]);const _t=async te=>{if(!te.viewable)return;ke.current?.abort();const _=new AbortController;ke.current=_,ge(!0);try{const M=await xe(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(n)}&path=${encodeURIComponent(te.path)}`,{signal:_.signal});!_.signal.aborted&&ke.current===_&&K.current===n&&Q(M)}catch(M){nr(M)||we.current.onError(Se(M))}finally{ke.current===_&&(ke.current=null,ge(!1))}};return{pdfUrl:se?v:"",pdfCompiledAt:se?R:null,pdfSizeBytes:se?E:null,pdfLoadingMode:P,pdfLoading:se?b:!1,compileLog:se?J:"",compileDiagnostics:se?V:null,compileOutcome:se?B:null,artifacts:se?re:[],artifactPreview:se?X:null,artifactLoading:se&&Z,editorNotice:se?W:"",localCompiling:_e.has(n),cancelling:q.has(n),cleaning:ye,compile:le,cancelCompile:Oe,cleanCompile:ce,viewArtifact:_t}}const na=10*1024*1024,K0=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 xd(t){return t instanceof Error&&t.name==="AbortError"}function lr(t){const e=t.split("/").filter(Boolean);return e.pop(),e.map((n,r)=>e.slice(0,r+1).join("/"))}function rr(t,e){return!!(t&&e)&&(e===t||e.startsWith(`${t}/`))}function G0(t){const e=`.${t.split(".").at(-1)?.toLocaleLowerCase()??""}`;return!K0.has(e)}function Yr(t){return/(?:\.(?:tex|bib|bst|sty|cls|txt|md)|latexmkrc)$/i.test(t)}function vd(t){const e=t.split(".").at(-1)?.toLocaleLowerCase()??"";return e==="pdf"?"pdf":["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"].includes(e)?"image":G0(t)?"text":"unsupported"}function J0(t,e){return cs(`/api/projects/${t}/file/raw?path=${encodeURIComponent(e)}`)}function Y0({projectId:t,site:e,activeFile:n,dirty:r,save:s,onError:o,onProject:i,onActiveFile:c,onActiveMainFile:l}){const{t:d}=Qe(),[h,f]=u.useState([]),[p,m]=u.useState(!1),[g,y]=u.useState(""),[C,v]=u.useState(null),[D,b]=u.useState(!1),[w,R]=u.useState(!1),[S,E]=u.useState(""),[j,P]=u.useState(""),[$,J]=u.useState(null),[T,V]=u.useState(""),[U,B]=u.useState(new Set),[z,re]=u.useState(null),[H,X]=u.useState(""),[Q,Z]=u.useState(""),[ge,ye]=u.useState(null),[Ce,_e]=u.useState(!1),[A,q]=u.useState(null),[fe,W]=u.useState(!1),[ee,Ee]=u.useState(null),pe=u.useRef(!1),K=u.useRef(null),ae=u.useRef(null),L=u.useRef(null),Re=async(Y={})=>{ae.current?.abort(),ae.current=null;const se=Y.signal?null:new AbortController;se&&(ae.current=se);try{const De=await xe(`/api/projects/${t}/files`,{signal:Y.signal??se?.signal});return(!Y.isCurrent||Y.isCurrent())&&f(De.files),De.files}catch(De){if(!xd(De))throw De;return}finally{se&&ae.current===se&&(ae.current=null)}},Fe=async()=>{if(!(!g.trim()||g.trim().endsWith("/"))){P("");try{await xe(`/api/projects/${t}/file`,{method:"POST",body:JSON.stringify({path:g,content:""})}),await Re(),c(g),J(null),B(Y=>new Set([...Y,...lr(g)])),m(!1),y("")}catch(Y){P(Se(Y))}}},Te=async()=>{if(!S.trim())return;P("");const Y=$?`${$}/${S.trim()}`:S.trim();try{const se=await xe(`/api/projects/${t}/folders`,{method:"POST",body:JSON.stringify({path:Y})});await Re(),B(De=>new Set([...De,...lr(se.path),se.path])),J(se.path),R(!1),E("")}catch(se){P(Se(se))}},Ue=async(Y,se=new Set,De=$)=>{if(!Y.length||pe.current)return;const ze=e.maxUploadSizeMB;if(Y.find(oe=>oe.size>ze*1024*1024)){Ee({kind:"error",message:d("errors.fileTooLarge",{size:ze})});return}const le=De??"",Oe=Y.map(oe=>le?`${le}/${oe.name}`:oe.name),ce=new Map;for(const oe of Oe)ce.set(oe,(ce.get(oe)??0)+1);const _t=[...ce.entries()].filter(([,oe])=>oe>1).map(([oe])=>oe);if(_t.length){Ee({kind:"error",message:d("errors.duplicateUploadNames",{files:_t.join(", ")})});return}const te=new Set(h.map(oe=>oe.path)),_=[...new Set(Oe.filter(oe=>te.has(oe)&&!se.has(oe)))];if(_.length){Ee(null),q({files:Y,directory:le,collisions:_});return}q(null),K.current!==null&&window.clearTimeout(K.current),K.current=null,Ee(null),pe.current=!0,W(!0);let M=0;try{const oe=new URLSearchParams;le&&oe.set("directory",le);let yt="";for(const[I,ne]of Y.entries()){const Et=Oe[I];oe.delete("overwrite"),se.has(Et)&&oe.set("overwrite","1");const Tt=oe.toString()?`?${oe.toString()}`:"",Dr=new FormData;Dr.append("file",ne);try{Ee({kind:"uploading",fileName:ne.name,current:I+1,total:Y.length});const wt=await xe(`/api/projects/${t}/upload${Tt}`,{method:"POST",body:Dr});M+=1,typeof wt.path=="string"&&Yr(wt.path)&&(yt=wt.path)}catch(wt){if(wt instanceof No&&wt.status===409&&!se.has(Et)&&wt.code==="FILE_EXISTS"){if(Ee(null),I>0)try{await Re()}catch{}q({files:Y.slice(I),directory:le,collisions:[Et]});return}throw wt}}try{await Re()}catch(I){Ee({kind:"error",message:d("editor.uploadSucceededRefreshFailed",{message:Se(I)})});return}yt&&(c(yt),J(null)),Ee({kind:"success",count:M}),K.current=window.setTimeout(()=>{Ee(I=>I?.kind==="success"?null:I),K.current=null},3e3)}catch(oe){try{await Re()}catch{}const yt=M>0?d("editor.uploadFailedPartial",{uploaded:M,total:Y.length,message:Se(oe)}):d("editor.uploadFailed",{message:Se(oe)});Ee({kind:"error",message:yt})}finally{pe.current=!1,W(!1)}},de=()=>{K.current!==null&&window.clearTimeout(K.current),K.current=null,Ee(null)},ve=async Y=>{await Ue(Array.from(Y.target.files??[])),Y.target.value=""},We=async Y=>{L.current?.abort(),L.current=null,b(!1);const se=J0(t,Y.path);if((Y.size??0)>na){v({path:Y.path,kind:"large",size:Y.size??0,url:se});return}const De=vd(Y.path);if(De!=="text"){v({path:Y.path,kind:De,size:Y.size??0,url:se});return}v({path:Y.path,kind:De,size:Y.size??0,url:se,content:""}),b(!0);const ze=new AbortController;L.current=ze;try{let G;try{G=await fetch(se,{signal:ze.signal})}catch(ce){throw Fw(ce)}const le=G.headers.get("content-type")??"";if(!G.ok){let ce=null;try{ce=le.includes("application/json")?await G.json():await G.text()}catch{}throw new No(Iw(ce,G.status),G.status,$w(ce))}const Oe=await G.text();v(ce=>ce?.path===Y.path?{...ce,content:Oe}:ce)}catch(G){xd(G)||(v(null),o(Se(G)))}finally{L.current===ze&&(L.current=null,b(!1))}},Me=Y=>{J(null),V(Y.path);const se=vd(Y.path),De=e.maxCollaborativeFileSizeMB*1024*1024;(Y.size??0)>na||Yr(Y.path)&&(Y.size??0)>De||se!=="text"||!Yr(Y.path)?We(Y):c(Y.path)},ke=async(Y,se,De)=>{if(!await s())return null;const ze=await xe(`/api/projects/${t}/path`,{method:"PATCH",body:JSON.stringify({source:Y.path,destinationDirectory:se,destinationName:De})}),G=ce=>ce===Y.path?ze.path:ce.startsWith(`${Y.path}/`)?`${ze.path}${ce.slice(Y.path.length)}`:ce;c(ce=>G(ce)),l(ce=>G(ce)),J(ce=>ce&&G(ce)),V(ce=>ce&&G(ce));const[le,Oe]=await Promise.all([xe(`/api/projects/${t}/files`),xe(`/api/projects/${t}`)]);return f(le.files),i(Oe.project),B(ce=>new Set([...ce,...lr(ze.path),se].filter(Boolean))),ze.path},O=async()=>{if(!z)return;const Y=H.trim();if(Y){P("");try{if(!await ke(z,Q,Y))return;re(null),X(""),Z("")}catch(se){P(Se(se))}}},Pe=async(Y,se)=>{if(X0(Y.path)!==se&&!(Y.type==="directory"&&(se===Y.path||se.startsWith(`${Y.path}/`))))try{await ke(Y,se,Y.path.split("/").at(-1)??Y.path)}catch(De){o(Se(De))}},Je=async()=>{if(ge){P("");try{if(r&&!await s())return;await xe(`/api/projects/${t}/file?path=${encodeURIComponent(ge.path)}`,{method:"DELETE"}),ye(null)}catch(Y){P(Se(Y))}}};u.useEffect(()=>()=>{ae.current?.abort(),L.current?.abort(),K.current!==null&&window.clearTimeout(K.current)},[]),u.useEffect(()=>{L.current?.abort(),L.current=null,b(!1)},[n]),u.useEffect(()=>{n&&V(n)},[n]);const it=h.filter(Y=>Y.type==="directory"),we=h.filter(Y=>lr(Y.path).every(se=>U.has(se)));return{files:h,setFiles:f,loadFiles:Re,newFileOpen:p,setNewFileOpen:m,newFilePath:g,setNewFilePath:y,resourcePreview:C,setResourcePreview:v,resourcePreviewLoading:D,setResourcePreviewLoading:b,newFolderOpen:w,setNewFolderOpen:R,newFolderName:S,setNewFolderName:E,fileDialogError:j,setFileDialogError:P,selectedFolder:$,setSelectedFolder:J,selectedFile:T,setSelectedFile:V,expandedFolders:U,setExpandedFolders:B,moveEntry:z,setMoveEntry:re,moveName:H,setMoveName:X,moveDestination:Q,setMoveDestination:Z,deleteEntry:ge,setDeleteEntry:ye,fileDragActive:Ce,setFileDragActive:_e,uploadConflict:A,setUploadConflict:q,uploadingFiles:fe,uploadFeedback:ee,dismissUploadFeedback:de,directoryEntries:it,visibleEntries:we,createFile:Fe,createFolder:Te,uploadFiles:Ue,upload:ve,openFile:Me,movePath:O,movePathToFolder:Pe,removePath:Je}}function X0(t){const e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function Z0({active:t,harperEnabled:e=!0,projectId:n,activeFile:r,content:s,dictionaryWords:o,additionalIssues:i=[],additionalIssuesReady:c=!0}){const[l,d]=u.useState([]),[h,f]=u.useState(""),[p,m]=u.useState(""),[g,y]=u.useState(0),[C,v]=u.useState(null),[D,b]=u.useState(null),[w,R]=u.useState(!1),[S,E]=u.useState(0),j=u.useRef(0),P=u.useRef(!1),$=u.useRef(!1),J=u.useRef(s),T=u.useRef(r),V=u.useRef(0);J.current=s,T.current=r,$.current=w,u.useEffect(()=>{d([]),f(""),m(""),v(null),b(null),R(!1)},[r,o,e]),u.useEffect(()=>{b(null),R(!1)},[n]),u.useEffect(()=>{const H=++j.current;if(!t||!r){d([]),f(""),m(""),v(null);return}if(!e){d([]),f(""),m("");return}if(D){d([]),f(""),m("");return}const X=s,Q=r;let Z=!1;const ge=window.setTimeout(()=>{b(null),(async()=>{try{const{lintLatex:ye,isHarperLintSupersededError:Ce}=await $t(async()=>{const{lintLatex:A,isHarperLintSupersededError:q}=await import("./spellCheck-BCpcq-VN.js");return{lintLatex:A,isHarperLintSupersededError:q}},__vite__mapDeps([0,1,2,3,4,5,6,7,8]),import.meta.url);if(Z||H!==j.current||J.current!==X||T.current!==Q)return;let _e;try{_e=await ye(n,Q,X,o)}catch(A){if(Ce(A))return;throw A}if(Z||H!==j.current||J.current!==X||T.current!==Q)return;P.current=!1,R(!1),d(_e),f(X),m(Q),y(0),v(null)}catch(ye){if(Z||H!==j.current||J.current!==X||T.current!==Q)return;d([]),f(""),m(""),b(ye instanceof Error?ye.message:String(ye));const Ce=P.current;P.current=!1,R(Ce?$.current:!1)}})()},700);return()=>{Z=!0,window.clearTimeout(ge)}},[t,e,n,r,s,o,S,D]),u.useEffect(()=>{if(!D||!t||!e)return;let H=!1;const X=()=>{H||(H=!0,P.current=!0,b(null),E(Z=>Z+1))},Q=window.setTimeout(X,15e3);return window.addEventListener("online",X,{once:!0}),()=>{window.clearTimeout(Q),window.removeEventListener("online",X)}},[D,t,e]);const U=e&&t&&p===r&&h===s,B=u.useMemo(()=>{if(!t)return[];const H=[...U?l:[],...i].sort((Q,Z)=>Q.from-Z.from||Q.to-Z.to),X=new Set;return H.filter(Q=>{const Z=`${Q.from}:${Q.to}:${Q.kind}:${Q.message}`;return X.has(Z)?!1:(X.add(Z),!0)})},[t,i,U,l]),z=u.useMemo(()=>t&&(!e||U)&&c?{total:B.length,unique:new Set(B.map(H=>`${H.kind}:${H.word.toLocaleLowerCase("en-US")}`)).size}:null,[t,c,e,U,B]);return u.useEffect(()=>{y(H=>B.length?Math.min(H,B.length-1):0)},[B]),{issues:B,jump:t?C:null,index:g,summary:z,jumpToIssue:H=>{if(!B.length)return;const X=Math.max(0,Math.min(H,B.length-1)),Q=B[X];y(X),v({from:Q.from,to:Q.to,nonce:++V.current})},error:t&&e&&!w?D:null,nativeFallback:t&&e&&!!D,retry:()=>{P.current=!1,b(null),R(!1),E(H=>H+1)},dismissError:()=>{P.current=!1,R(!0)}}}function Q0({active:t,projectId:e,activeFile:n,content:r}){const[s,o]=u.useState([]),[i,c]=u.useState(""),[l,d]=u.useState(""),[h,f]=u.useState(null),[p,m]=u.useState(!1),[g,y]=u.useState(0),C=u.useRef(0),v=u.useRef(r),D=u.useRef(n);v.current=r,D.current=n,u.useEffect(()=>{o([]),c(""),d(""),f(null),m(!1)},[e,n]),u.useEffect(()=>{const w=++C.current;if(!t||!n){o([]),c(""),d("");return}const R=r,S=n;let E=!1;const j=window.setTimeout(()=>{(async()=>{try{const{lintChktex:P,isChktexLintSupersededError:$}=await $t(async()=>{const{lintChktex:T,isChktexLintSupersededError:V}=await import("./chktex-CZIYuMLb.js");return{lintChktex:T,isChktexLintSupersededError:V}},__vite__mapDeps([9,1,2,3,4,5,6,7,8]),import.meta.url);if(E||w!==C.current||v.current!==R||D.current!==S)return;let J;try{J=await P(e,S,R)}catch(T){if($(T))return;throw T}if(E||w!==C.current||v.current!==R||D.current!==S)return;o(J),c(R),d(S),f(null),m(!1)}catch(P){if(E||w!==C.current||v.current!==R||D.current!==S)return;o([]),c(""),d(""),f(P instanceof Error?P.message:String(P))}})()},2e3);return()=>{E=!0,window.clearTimeout(j)}},[t,e,n,r,g]);const b=t&&l===n&&i===r;return{issues:b?s:[],checked:b,error:t&&!p?h:null,retry:()=>{f(null),m(!1),y(w=>w+1)},dismissError:()=>m(!0)}}function Sd(t){return t instanceof Error&&t.name==="AbortError"}function eE({projectId:t,mainFile:e,activeFile:n,onOpenSourceFile:r,onError:s,onShowPdf:o,onShowEditor:i}){const[c,l]=u.useState(null),[d,h]=u.useState(null),[f,p]=u.useState(null),m=u.useRef(null),g=u.useRef(0),y=u.useRef(n),C=u.useRef(r),v=u.useRef(s),D=u.useRef(o),b=u.useRef(i),w=$=>$===e&&/\.tex$/i.test($);y.current=n,C.current=r,v.current=s,D.current=o,b.current=i,u.useEffect(()=>(m.current?.abort(),m.current=null,l(null),h(null),p(null),()=>m.current?.abort()),[t,e]);const R=($,J,T)=>{p({path:$,line:J,column:T,nonce:++g.current}),C.current($)},S=async($,J,T,V={})=>{if(!w($))return;m.current?.abort();const U=new AbortController;m.current=U;try{const B=await xe(`/api/projects/${t}/sync/pdf?mainFile=${encodeURIComponent(e)}&path=${encodeURIComponent($)}&line=${J}&column=${T}`,{signal:U.signal});if(m.current!==U||!B)return;l({...B,nonce:++g.current}),D.current()}catch(B){!Sd(B)&&!V.silent&&v.current(Se(B))}finally{m.current===U&&(m.current=null)}},E=async($,J,T)=>{const V=y.current;m.current?.abort();const U=new AbortController;m.current=U;try{const B=await xe(`/api/projects/${t}/sync/source?mainFile=${encodeURIComponent(e)}&page=${$}&x=${J}&y=${T}`,{signal:U.signal});if(m.current!==U||y.current!==V)return;b.current(),R(B.path,B.line,B.column)}catch(B){Sd(B)||v.current(Se(B))}finally{m.current===U&&(m.current=null)}};return{pdfTarget:c,pdfViewport:d,sourceJump:f,setPdfViewport:h,resetPdfViewport:()=>h(null),clearPdfViewport:()=>{m.current?.abort(),m.current=null,h(null),l(null)},jumpToSource:R,syncSourceToPdf:S,syncPdfToSource:E,syncVisiblePdfToSource:()=>{d&&E(d.page,d.x,d.y)}}}function Zh(t,e){return ir(`texlite.workspaceLayout:${encodeURIComponent(t)}:${encodeURIComponent(e)}`)}function Cd(t,e){try{const n=window.localStorage.getItem(Zh(t,e));if(n==="editor-pdf"||n==="editor-only"||n==="pdf-only")return n}catch{}return"editor-pdf"}function tE(t,e){const[n,r]=u.useState(()=>Cd(t,e));return u.useEffect(()=>{r(Cd(t,e))},[t,e]),{workspaceLayout:n,setWorkspaceLayout:o=>{r(o);try{window.localStorage.setItem(Zh(t,e),o)}catch{}}}}function nE(t){return!/\.(?:bib|bst)$/i.test(t.trim())}function Ed(t){return/\.(?:tex|sty|cls)$/i.test(t.trim())}const Qh=["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"],rE=new Set(Qh);function sE(t){return rE.has(t)}function oE(t,e,n){if(t[e]!=="[")return e;let r=1;for(let s=e+1;s<n;s+=1){if(t[s]==="\\"){s+=1;continue}if(t[s]==="["&&(r+=1),t[s]==="]"&&(r-=1,r===0))return s+1}return null}function kd(t,e,n){if(t[e]!=="{")return null;let r=1;for(let s=e+1;s<n;s+=1){if(t[s]==="\\"){s+=1;continue}if(t[s]==="{"&&(r+=1),t[s]==="}"&&(r-=1,r===0))return s+1}return null}function ep(t,e,n=t.length){const r=t.indexOf(`
|
|
11
|
-
`,e);r>=0&&(n=Math.min(n,r));const s=/^\\(verb\*?|Verb\*?|lstinline\*?|mintinline\*?)(?![A-Za-z@])/.exec(t.slice(e,n));if(!s)return null;const o=s[1].replace(/\*$/,"");let i=e+s[0].length;if(o!=="verb"){const d=oE(t,i,n);if(d===null)return null;i=d}if(o==="mintinline"){const d=kd(t,i,n);if(d===null)return null;i=d}const c=t[i];if(!c||/\s/.test(c))return null;if(c==="{"&&o!=="verb"){const d=kd(t,i,n);return{end:d??n,closed:d!==null}}const l=t.indexOf(c,i+1);return l<0||l>=n?{end:n,closed:!1}:{end:l+1,closed:!0}}function tp(t,e,n=t.length){return ep(t,e,n)?.end??null}function fl(t,e,n){const r=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(String.raw`\\end\s*\{\s*${r}\s*\}`,"g");s.lastIndex=e;const o=s.exec(t);return o?{from:o.index,to:o.index+o[0].length}:null}function zs(t,e){let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1}function iE(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 np(t,e){const n=/^\\begin\s*\{\s*([A-Za-z0-9@:_*.\-]+)\s*\}/.exec(t.slice(e));return!n||!sE(n[1])?null:{name:n[1],to:e+n[0].length}}function Tj(t,e){const n=Math.max(0,Math.min(t.length,e));for(let r=0;r<n;){if(t[r]==="%"&&!zs(t,r)){const i=t.indexOf(`
|
|
12
|
-
`,r),c=i<0?t.length:i;if(n<=c)return"comment";r=c+1;continue}if(t[r]!=="\\"||zs(t,r)){r+=1;continue}const s=ep(t,r);if(s!==null){if(n<s.end||!s.closed&&n<=s.end)return"literal";r=s.end;continue}const o=np(t,r);if(o){const i=fl(t,o.to,o.name),c=i?.to??t.length;if(n<c||!i&&n<=c)return"literal";r=c;continue}r=iE(t,r)}return null}function Rd(t,e,n){return t.slice(e,n).replace(/[^\r\n]/g," ")}function cE(t){const e=t.split("");for(let n=0;n<t.length;n+=1){if(t[n]!=="%"||zs(t,n))continue;const r=t.indexOf(`
|
|
13
|
-
`,n),s=r<0?t.length:r;for(let o=n;o<s;o+=1)e[o]=" ";n=s}return e.join("")}function aE(t){let e="",n=0;for(;n<t.length;){if(t[n]==="%"&&!zs(t,n)){const o=t.indexOf(`
|
|
14
|
-
`,n),i=o<0?t.length:o;e+=t.slice(n,i),n=i;continue}if(t[n]!=="\\"||zs(t,n)){e+=t[n],n+=1;continue}const r=tp(t,n);if(r!==null){e+=Rd(t,n,r),n=r;continue}const s=np(t,n);if(s){const i=fl(t,s.to,s.name)?.to??t.length;e+=Rd(t,n,i),n=i;continue}e+=t[n],n+=1}return e}function lE(t,e){let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1}function Dd(t){const e=cE(aE(t)),n=/\\documentclass(?![A-Za-z@])\s*(?:\[[^\]]*\]\s*)?\{/g;for(const r of e.matchAll(n))if(r.index!==void 0&&!lE(e,r.index))return!0;return!1}const uE=new Set(Qh);function dE(t){return/[A-Za-z@0-9:_-]/.test(t)}function fE(t,e){let n=0;for(let r=e-1;r>=0&&t[r]==="\\";r-=1)n+=1;return n%2===1}function fs(t,e){return t[e]==="%"&&!fE(t,e)}function eo(t,e){const n=t.indexOf(`
|
|
15
|
-
`,e);return n===-1?t.length:n}function ei(t,e){let n=e;for(;n<t.length;){if(/\s/.test(t[n])){n+=1;continue}if(fs(t,n)){n=eo(t,n);continue}break}return n}function ra(t,e,n,r){if(t[e]!==n)return null;let s=0,o=0;for(let i=e;i<t.length;i+=1){const c=t[i];if(c==="\\"&&i+1<t.length){i+=1;continue}if(fs(t,i)){i=eo(t,i)-1;continue}if(n==="["){if(c==="{"){o+=1;continue}if(c==="}"&&o>0){o-=1;continue}if(o>0)continue}if(c===n){s+=1;continue}if(c===r&&(s-=1,s===0))return{from:e,to:i+1,contentFrom:e+1,contentTo:i}}return null}function sa(t,e,n){const r=[];let s=e;for(;r.length<n;){for(s=ei(t,s);t[s]==="[";){const i=ra(t,s,"[","]");if(!i)return r;s=ei(t,i.to)}if(t[s]!=="{")break;const o=ra(t,s,"{","}");if(!o)break;r.push(o),s=o.to}return r}function Pj(t,e,n){const r=[];let s=e;for(;r.length<n&&(s=ei(t,s),t[s]==="[");){const o=ra(t,s,"[","]");if(!o)break;r.push(o),s=o.to}return r}function hE(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&&dE(t[n]);)n+=1;const r=t.slice(e+1,n);return t[n]==="*"&&(n+=1),{name:r,from:e,to:n}}function pE(t,e){if(e.name!=="begin")return e.to;const n=sa(t,e.to,1)[0];if(!n)return e.to;const r=t.slice(n.contentFrom,n.contentTo).trim();return uE.has(r)?fl(t,n.to,r)?.to??t.length:e.to}function mE(t,e){let n=0;for(;n<t.length;){if(fs(t,n)){n=eo(t,n);continue}if(t[n]!=="\\"){n+=1;continue}const r=hE(t,n);if(!r){n+=1;continue}const s=tp(t,r.from);if(s!==null&&s>r.to){n=s;continue}const o=pE(t,r);if(o>r.to){n=o;continue}e(r),n=r.to}}function Ec(t,e,n){const r=[];let s=e.contentFrom,o=e.contentFrom;for(;o<=e.contentTo;){if(o<e.contentTo&&fs(t,o)){o=eo(t,o),t[o]===`
|
|
16
|
-
`&&(o+=1);continue}if(o!==e.contentTo){o+=1;continue}const i=gE(t,s,o);i&&r.push(i),s=o+1,o+=1}return r}function gE(t,e,n){const r=[];let s=e;for(;s<n;){if(fs(t,s)){s=eo(t,s),t[s]===`
|
|
17
|
-
`&&(s+=1);continue}r.push({character:t[s],index:s}),s+=1}let o=0,i=r.length;for(;o<i&&/\s/.test(r[o].character);)o+=1;for(;i>o&&/\s/.test(r[i-1].character);)i-=1;return o===i?null:{path:r.slice(o,i).map(c=>c.character).join(""),command:"",from:r[o].index,to:r[i-1].index+1}}function yE(t,e){const n=ei(t,e);if(n>=t.length||/[\\{}\[\]#~]/.test(t[n]))return null;let r=n;for(;r<t.length&&!/\s/.test(t[r])&&!fs(t,r)&&!/[\\{}\[\]#~]/.test(t[r]);)r+=1;return r===n?null:{path:t.slice(n,r),command:"",from:n,to:r}}function jd(t){const e=[];return mE(t,n=>{const r=n.name.toLowerCase();if(r==="input"||r==="include"||r==="subfile"){const l=sa(t,n.to,1)[0];if(l)for(const d of Ec(t,l))e.push({...d,command:n.name});else if(r==="input"){const d=yE(t,n.to);d&&e.push({...d,command:n.name})}return}if(r!=="import"&&r!=="subimport"&&r!=="includefrom"&&r!=="inputfrom"&&r!=="subinputfrom"&&r!=="subincludefrom")return;const s=sa(t,n.to,2);if(s.length!==2)return;const o=Ec(t,s[0])[0]?.path??"",i=Ec(t,s[1])[0];if(!i)return;const c=o&&!o.endsWith("/")?"/":"";e.push({path:o+c+i.path,command:n.name,from:i.from,to:i.to,directory:o})}),e}function wE({sessions:t,status:e}){const{t:n}=Qe(),[r,s]=u.useState(!1),o=Math.max(0,t.length-5),i=r&&o>0,c=i?t:t.slice(0,5);return u.useEffect(()=>{t.length<=5&&s(!1)},[t.length]),t.length<=1?null:a.jsxs("div",{className:`collaboration-presence collaboration-${e}`,children:[a.jsx("span",{className:"collaboration-status-dot","data-tooltip":n(`editor.collaboration.${e}`),"aria-label":n(`editor.collaboration.${e}`)}),a.jsxs("div",{className:"collaboration-avatars","aria-label":n("editor.collaboration.activeSessions",{count:t.length}),children:[c.map(l=>{const d=l.editing?n("editor.collaboration.editing"):n("editor.collaboration.viewing"),h=l.permission==="read"?n("common.readOnly"):n("common.readWrite"),f=n("editor.collaboration.sessionTooltip",{name:l.name,username:l.username,file:l.filePath||n("editor.collaboration.joining"),activity:d,permission:h});return a.jsxs("span",{className:`collaboration-avatar${l.editing?" editing":""}${l.local?" local":""}`,style:{"--session-color":l.color},"aria-label":f,tabIndex:0,children:[z0(l.name,l.username),a.jsxs("span",{className:"collaboration-avatar-tooltip",role:"tooltip",children:[a.jsx("strong",{children:l.name}),a.jsxs("span",{children:["@",l.username]}),a.jsxs("small",{children:[l.filePath||n("editor.collaboration.joining")," · ",d," · ",h]})]})]},l.clientId)}),o>0&&a.jsx("button",{type:"button",className:"collaboration-avatar collaboration-avatar-overflow","aria-expanded":i,"aria-label":i?n("editor.collaboration.showFewerSessions"):n("editor.collaboration.showMoreSessions",{count:o}),title:i?n("editor.collaboration.showFewerSessions"):n("editor.collaboration.showMoreSessions",{count:o}),onClick:()=>s(l=>!l),children:i?"−":`+${o}`})]})]})}function bE({value:t,onChange:e}){const{t:n}=Qe(),[r,s]=u.useState(!1),o=u.useRef(null),i=[{value:"editor-pdf",icon:Pu},{value:"editor-only",icon:Cb},{value:"pdf-only",icon:Eb}];return u.useEffect(()=>{if(!r)return;const c=d=>{o.current?.contains(d.target)||s(!1)},l=d=>{d.key==="Escape"&&s(!1)};return document.addEventListener("pointerdown",c),document.addEventListener("keydown",l),()=>{document.removeEventListener("pointerdown",c),document.removeEventListener("keydown",l)}},[r]),a.jsxs("div",{className:"layout-menu",ref:o,children:[a.jsxs("button",{type:"button",className:`layout-trigger${r?" active":""}`,"aria-haspopup":"menu","aria-expanded":r,title:n("editor.layout.current",{layout:n(`editor.layout.${t}.name`)}),onClick:()=>s(c=>!c),children:[a.jsx(Pu,{size:15}),a.jsxs("span",{children:[a.jsx("small",{children:n("editor.layout.label")}),n(`editor.layout.${t}.name`)]}),a.jsx(qs,{size:13})]}),r&&a.jsxs("div",{className:"layout-popover",role:"menu","aria-label":n("editor.layout.label"),children:[a.jsx("div",{className:"layout-popover-title",children:n("editor.layout.choose")}),i.map(c=>{const l=c.icon,d=c.value===t;return a.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":d,className:`layout-option${d?" selected":""}`,onClick:()=>{e(c.value),s(!1)},children:[a.jsx(l,{size:19}),a.jsxs("span",{children:[a.jsx("strong",{children:n(`editor.layout.${c.value}.name`)}),a.jsx("small",{children:n(`editor.layout.${c.value}.description`)})]}),d&&a.jsx(Vw,{size:16})]},c.value)})]})]})}function xE({site:t,project:e,activeFile:n,saveStateLabel:r,editorPreferences:s,activeSessions:o,collaborationStatus:i,reconnectCollaboration:c,protocolUpgradeRequired:l,showEditor:d,filesCollapsed:h,toggleFilesPanel:f,workspaceLayout:p,changeWorkspaceLayout:m,onBack:g,onShare:y,showCitationLibrary:C,citationLibraryOpen:v,onCitationLibrary:D,onHistory:b,onGit:w,canManageGit:R,formatting:S,readOnly:E,collaborationSynced:j,onToggleComments:P,commentsOpen:$,unresolvedCommentCount:J,onToggleSettings:T,settingsOpen:V,compileBusy:U,sharedCompiling:B,localCompiling:z,cancelling:re,compileState:H,onCompile:X,onCancelCompile:Q}){const{t:Z}=Qe();return a.jsxs("header",{className:"editor-topbar",children:[a.jsx("button",{className:"back",title:Z("editor.backToProjects"),"aria-label":Z("editor.backToProjects"),onClick:g,children:a.jsx(Hw,{size:18})}),a.jsx("a",{className:"brand-link compact-brand-link",href:cs("/"),"aria-label":t.siteName,onClick:ge=>{ge.preventDefault(),g()},children:a.jsx(Uw,{siteName:t.siteName,compact:!0})}),a.jsxs("div",{className:"project-heading",children:[a.jsx("strong",{children:e.name}),a.jsxs("small",{children:[n," · ",r]})]}),s.vimMode&&a.jsxs("span",{className:"vim-status-badge",title:Z("editor.vimOnHint"),children:[a.jsx(bb,{size:14}),Z("editor.vimOn")]}),a.jsx(wE,{sessions:o,status:i}),i==="disconnected"&&!l&&a.jsxs("div",{className:"collaboration-recovery",role:"status",children:[a.jsx("span",{children:Z("editor.collaboration.disconnected")}),a.jsx("button",{type:"button",onClick:c,children:Z("editor.collaboration.reconnect")})]}),a.jsxs("div",{className:"editor-actions",children:[d&&a.jsxs("button",{className:h?"":"active",onClick:f,children:[h?a.jsx(Sb,{size:15}):a.jsx(ff,{size:15}),Z("common.files")]}),a.jsx(bE,{value:p,onChange:m}),a.jsxs("button",{onClick:y,children:[a.jsx(Mo,{size:15}),Z("projectSettings.share")]}),C&&a.jsxs("button",{className:v?"active":"",onClick:D,children:[a.jsx(qw,{size:15}),Z("citationLibrary.title")]}),a.jsxs("button",{type:"button",className:"snapshots-action",title:Z("history.projectSnapshots"),onClick:b,children:[a.jsx(fb,{size:15}),Z("history.projectSnapshotsButton")]}),a.jsxs("button",{type:"button",className:`comments-action${$?" active":""}`,title:Z("editor.commentsAll"),"aria-label":J>0?`${Z("common.comments")} (${J})`:Z("common.comments"),onClick:P,children:[a.jsx(Kw,{size:15}),a.jsx("span",{children:Z("common.comments")}),J>0&&a.jsx("sup",{className:"comments-action-count",children:J})]}),a.jsxs("button",{className:"git-action",title:Z(R?"git.title":"git.ownerOnly"),disabled:!R,onClick:w,children:[a.jsx(Gw,{size:15}),"Git"]}),a.jsxs("button",{className:V?"active":"",onClick:T,children:[a.jsx(Tb,{size:15}),Z("common.settings")]}),B||z?a.jsxs("button",{className:"compile cancel-compile",title:Z("compileControls.cancel"),onClick:Q,disabled:re||S||E||!j,children:[re?a.jsx(gt,{className:"spin",size:15}):a.jsx($n,{size:15}),Z(re?"compileControls.cancelling":"compileControls.cancel")]}):a.jsxs("button",{className:"compile",title:Z("editor.compileShortcut"),onClick:X,disabled:U||S||E||!j,children:[U?a.jsx(gt,{className:"spin",size:15}):a.jsx(kb,{size:15}),Z("editor.compile",{engine:e.engine})]})]})]})}function vE(t){return`${t.path}\0${t.line}`}function SE(t){const e=[],n=[];for(const r of t){for(;n.length&&n.at(-1).level>=r.level;)n.pop();const s=n.at(-1);s&&(e[s.index].hasChildren=!0),e.push({item:r,key:vE(r),ancestorKeys:n.map(({index:o})=>e[o].key),hasChildren:!1}),n.push({level:r.level,index:e.length-1})}return e}function CE(t,e){return t.filter(n=>!n.ancestorKeys.some(r=>e.has(r)))}const EE=new Set(["avif","bmp","gif","ico","jpeg","jpg","png","svg","webp","eps"]),kE=new Set(["latex","ltx","tex"]),RE=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"]),DE=new Set(["cfg","conf","dat","env","ini","text","toml","txt"]),jE=new Set(["csv","ods","tsv","xls","xlsx"]),_E=new Set(["7z","bz2","gz","rar","tar","xz","zip"]),TE=new Set(["m4a","mp3","ogg","wav"]),PE=new Set(["avi","mkv","mov","mp4","webm"]);function AE(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":EE.has(n)?"image":n==="md"||n==="markdown"||n==="mdown"||n==="mkdn"?"markdown":kE.has(n)?"tex":n==="bib"||n==="bibtex"?"bib":RE.has(n)?"code":DE.has(n)?"text":jE.has(n)?"spreadsheet":_E.has(n)?"archive":TE.has(n)?"audio":PE.has(n)?"video":"file"}const OE={pdf:gb,tex:_u,bib:xb,latexmkrc:hb,image:pb,markdown:lf,text:Yw,code:_u,spreadsheet:Jw,archive:Mc,audio:db,video:yb,file:ci};function rp({path:t,size:e=13}){const n=AE(t);if(n==="pdf"||n==="tex")return a.jsx("img",{className:`file-type-icon file-type-icon-${n}`,src:cs(`/${n==="pdf"?"pdf-file":"tex-file"}.svg`),width:e,height:e,alt:"","aria-hidden":"true"});const r=OE[n]??wb;return a.jsx(r,{className:`file-type-icon file-type-icon-${n}`,size:e,"aria-hidden":"true"})}const sp="application/x-texlite-project-path",op="texlite-path:";function LE({project:t,filesPanel:e,files:n,visibleEntries:r,activeFile:s,activeMainFile:o,selectedFile:i,selectedFolder:c,expandedFolders:l,fileDragActive:d,uploadingFiles:h,uploadFeedback:f,readOnly:p,formatting:m,canFormat:g,activeFormatLease:y,collaborationSynced:C,editorFontSize:v,outline:D,sourceCursorStore:b,wordCountBusy:w,hasSelection:R,hasFormatSelection:S,uploadInput:E,setSelectedFolder:j,setExpandedFolders:P,setMoveEntry:$,setMoveName:J,setMoveDestination:T,setDeleteEntry:V,setFileDialogError:U,setNewFolderName:B,setNewFolderOpen:z,setNewFilePath:re,setNewFileOpen:H,setQuickOpen:X,setProjectSearchOpen:Q,setFileDragActive:Z,dismissUploadFeedback:ge,setFilesCollapsed:ye,toggleFilesPanel:Ce,uploadFiles:_e,upload:A,openFile:q,movePathToFolder:fe,onError:W,onFormatFile:ee,onFormatSelection:Ee,jumpToSource:pe,syncSourceToPdf:K,onWordCount:ae}){const{t:L}=Qe(),[Re,Fe]=u.useState(!1),[Te,Ue]=u.useState(null),[de,ve]=u.useState(null),We=u.useRef(0),Me=(O,Pe)=>ME(O.path)!==Pe&&(O.type!=="directory"||Pe!==O.path&&!Pe.startsWith(`${O.path}/`)),ke=()=>{Ue(null),ve(null)};return a.jsx(ii,{id:"files",order:1,ref:e,defaultSize:16,minSize:12,maxSize:30,collapsible:!0,collapsedSize:0,onCollapse:()=>ye(!0),onExpand:()=>ye(!1),children:a.jsxs("aside",{className:"left-panel",children:[a.jsxs("section",{className:`files-panel${d?" drop-active":""}`,onDragEnter:O=>{if(sr(O.dataTransfer)){O.preventDefault();return}O.dataTransfer.types.includes("Files")&&(O.preventDefault(),!p&&!h&&Z(!0))},onDragOver:O=>{if(sr(O.dataTransfer)){O.preventDefault(),O.dataTransfer.dropEffect="move";return}O.dataTransfer.types.includes("Files")&&(O.preventDefault(),O.dataTransfer.dropEffect=p||h?"none":"copy")},onDragLeave:O=>{O.currentTarget.contains(O.relatedTarget)||Z(!1)},onDrop:O=>{if(sr(O.dataTransfer)){O.preventDefault(),O.stopPropagation();return}if(O.preventDefault(),Z(!1),p||h)return;const Pe=Array.from(O.dataTransfer.files);if(NE(O.dataTransfer)||Pe.length===0){W(L("editor.dropFoldersUnsupported"));return}_e(Pe)},children:[a.jsxs("div",{className:"panel-title",children:[a.jsx("button",{className:"file-size-toggle",type:"button","aria-pressed":Re,title:L(Re?"editor.hideFileSizes":"editor.showFileSizes"),onClick:()=>Fe(O=>!O),children:L("common.files")}),a.jsxs("span",{className:"file-tools",children:[a.jsx("button",{type:"button","aria-label":L("navigation.quickOpen"),title:`${L("navigation.quickOpen")} (Ctrl/Cmd+P)`,onClick:()=>X(!0),children:a.jsx(Xw,{size:15})}),a.jsx("button",{type:"button","aria-label":L("navigation.projectSearch"),title:`${L("navigation.projectSearch")} (Ctrl/Cmd+Shift+F)`,onClick:()=>Q(!0),children:a.jsx(sb,{size:15})}),!p&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",disabled:h,"aria-label":L("editor.uploadAttachment"),title:L("editor.uploadTo",{folder:c||L("editor.projectRoot")}),onClick:()=>E.current?.click(),children:a.jsx(Tu,{size:15})}),a.jsx("button",{type:"button","aria-label":L("editor.newFolder"),title:L("editor.newFolder"),onClick:()=>{B(""),z(!0)},children:a.jsx(Zw,{size:15})}),a.jsx("button",{type:"button","aria-label":L("editor.newFile"),title:L("editor.newFile"),onClick:()=>{re(c?`${c}/`:""),H(!0)},children:a.jsx(mb,{size:15})}),a.jsx("input",{ref:E,type:"file",multiple:!0,hidden:!0,onChange:O=>{A(O)}})]}),a.jsx("button",{type:"button","aria-label":L("editor.collapseFiles"),title:L("editor.collapseFiles"),onClick:Ce,children:a.jsx(ff,{size:15})})]})]}),f&&a.jsxs("div",{className:`file-upload-feedback ${f.kind}`,role:f.kind==="error"?"alert":"status","aria-live":f.kind==="error"?"assertive":"polite","aria-busy":f.kind==="uploading",children:[f.kind==="uploading"?a.jsx(gt,{className:"spin",size:14}):f.kind==="success"?a.jsx(Ic,{size:14}):a.jsx(Gt,{size:14}),a.jsxs("span",{className:"file-upload-feedback-text",children:[f.kind==="uploading"&&L("editor.uploadingFile",{file:f.fileName,current:f.current,total:f.total}),f.kind==="success"&&L("editor.uploadSucceeded",{count:f.count}),f.kind==="error"&&f.message]}),f.kind!=="uploading"&&a.jsx("button",{type:"button",className:"file-upload-feedback-dismiss","aria-label":L("common.close"),title:L("common.close"),onClick:ge,children:a.jsx($n,{size:13})})]}),d&&a.jsxs("div",{className:"file-drop-overlay",children:[a.jsx(Tu,{size:24}),a.jsx("strong",{children:L("editor.dropFiles")}),a.jsx("span",{children:L("editor.uploadTo",{folder:c||L("editor.projectRoot")})})]}),a.jsx("div",{className:`file-list${c!==null?" folder-selected":""}${de===""?" root-drop-target":""}`,style:{fontSize:`${v}px`},onDragOver:O=>{if(!(!Te&&!sr(O.dataTransfer))&&(O.preventDefault(),O.stopPropagation(),!!Te)){if(!Me(Te,"")){O.dataTransfer.dropEffect="none";return}O.dataTransfer.dropEffect="move",ve("")}},onDragLeave:O=>{O.currentTarget.contains(O.relatedTarget)||ve(Pe=>Pe===""?null:Pe)},onDrop:O=>{if(!Te&&!sr(O.dataTransfer)||(O.preventDefault(),O.stopPropagation(),!Te))return;const Pe=Te;ke(),Me(Pe,"")&&fe(Pe,"")},children:r.map(O=>{const Pe=O.path.split("/").length-1,Je=O.path.split("/").at(-1),it=l.has(O.path),we=t.mainFile===O.path,Y=O.path!==t.mainFile&&!t.mainFile.startsWith(`${O.path}/`);return O.type==="directory"?a.jsxs("div",{className:`file-entry folder-entry${c===O.path?" selected":""}${de===O.path?" move-drop-target":""}`,style:{paddingLeft:`${Pe*13+5}px`},onDragOver:se=>{if(!(!Te&&!sr(se.dataTransfer))&&(se.preventDefault(),se.stopPropagation(),!!Te)){if(!Me(Te,O.path)){se.dataTransfer.dropEffect="none";return}se.dataTransfer.dropEffect="move",ve(O.path)}},onDragLeave:se=>{se.currentTarget.contains(se.relatedTarget)||ve(De=>De===O.path?null:De)},onDrop:se=>{if(!Te&&!sr(se.dataTransfer)||(se.preventDefault(),se.stopPropagation(),!Te))return;const De=Te;ke(),Me(De,O.path)&&fe(De,O.path)},children:[a.jsxs("button",{type:"button",className:"file-entry-main",onClick:()=>{j(O.path),P(se=>{const De=new Set(se);return De.has(O.path)?De.delete(O.path):De.add(O.path),De})},children:[it?a.jsx(qs,{size:13}):a.jsx(_a,{size:13}),a.jsx(Qw,{size:14}),a.jsx("span",{children:Je})]}),!p&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"file-entry-action","data-texlite-tooltip-always":!0,title:L("editor.move"),"aria-label":L("editor.move"),onClick:()=>{$(O),J(Je??""),T("")},children:a.jsx(Ou,{size:13})}),Y&&a.jsx("button",{type:"button",className:"file-entry-action danger-text",title:L("editor.deletePath"),"aria-label":L("editor.deletePath"),onClick:()=>{V(O),U("")},children:a.jsx(dr,{size:13})})]})]},O.path):a.jsxs("div",{className:`file-entry${c===null&&i===O.path?" active":""}${Te?.path===O.path?" move-drag-source":""}`,style:{paddingLeft:`${Pe*13+18}px`},children:[a.jsxs("button",{type:"button",className:"file-entry-main",draggable:!p,onDragStart:se=>{We.current=Date.now()+500,FE(se,O,Ue)},onDragEnd:ke,onClick:()=>{if(We.current>Date.now()){We.current=0;return}q(O)},children:[a.jsx(rp,{path:O.path}),a.jsx("span",{children:Je}),we&&a.jsx("small",{children:L("editor.currentMainShort")})]}),Re&&typeof O.size=="number"&&a.jsx("span",{className:"file-entry-size",children:$E(O.size)}),!p&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",className:"file-entry-action","data-texlite-tooltip-always":!0,title:L("editor.move"),"aria-label":L("editor.move"),onClick:()=>{$(O),J(Je??""),T("")},children:a.jsx(Ou,{size:13})}),Y&&a.jsx("button",{type:"button",className:"file-entry-action danger-text",title:L("editor.deletePath"),"aria-label":L("editor.deletePath"),onClick:()=>{V(O),U("")},children:a.jsx(dr,{size:13})})]})]},O.path)})}),!p&&g&&a.jsxs("div",{className:"file-format-footer",role:"group","aria-label":L("editor.format"),"aria-busy":m,children:[a.jsxs("div",{className:"file-format-label",children:[a.jsx(cb,{size:13}),L("editor.format")]}),a.jsxs("div",{className:"file-format-actions",children:[a.jsx("button",{className:S?"":"active",type:"button",title:L("editor.formatFileHint"),onMouseDown:O=>O.preventDefault(),onClick:ee,disabled:m||y||!C,children:L("editor.formatFile")}),a.jsx("button",{className:S?"active":"",type:"button",title:L(S?"editor.formatSelection":"editor.formatSelectionHint"),onMouseDown:O=>O.preventDefault(),onClick:Ee,disabled:m||y||!C||!S,children:L("editor.formatSelected")})]})]})]}),a.jsx(IE,{outline:D,activeFile:s,activeMainFile:o,sourceCursorStore:b,wordCountBusy:w,hasSelection:R,jumpToSource:pe,syncSourceToPdf:K,onWordCount:ae})]})})}function NE(t){return Array.from(t.items).some(e=>e.webkitGetAsEntry?.()?.isDirectory===!0)}function sr(t){return Array.from(t.types).includes(sp)?!0:Array.from(t.types).includes("text/plain")&&t.getData("text/plain").startsWith(op)}function ME(t){const e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function FE(t,e,n){t.dataTransfer.effectAllowed="move",t.dataTransfer.setData(sp,e.path),t.dataTransfer.setData("text/plain",`${op}${e.path}`),n(e)}function IE({outline:t,activeFile:e,activeMainFile:n,sourceCursorStore:r,wordCountBusy:s,hasSelection:o,jumpToSource:i,syncSourceToPdf:c,onWordCount:l}){const{t:d}=Qe(),h=u.useSyncExternalStore(r.subscribe,r.getOutlineLine,r.getOutlineLine),f=u.useMemo(()=>SE(t),[t]),p=u.useMemo(()=>f.filter(b=>b.hasChildren).map(b=>b.key),[f]),[m,g]=u.useState(()=>new Set);u.useEffect(()=>{const b=new Set(p);g(w=>{const R=new Set([...w].filter(S=>b.has(S)));return R.size===w.size?w:R})},[p]);const y=p.length>0&&p.every(b=>m.has(b)),C=u.useMemo(()=>CE(f,m),[f,m]),v=()=>g(b=>y?new Set([...b].filter(w=>!p.includes(w))):new Set([...b,...p])),D=b=>g(w=>{const R=new Set(w);return R.has(b)?R.delete(b):R.add(b),R});return a.jsxs("section",{className:"outline-panel",children:[a.jsxs("div",{className:"panel-title",children:[a.jsxs("button",{className:"outline-heading",type:"button","aria-expanded":!y,title:d(y?"editor.expandOutline":"editor.collapseOutline"),onClick:v,disabled:p.length===0,children:[a.jsx(eb,{size:14}),d("common.outline")]}),a.jsxs("span",{className:"word-count-actions",role:"group","aria-label":d("editor.wordCountTitle"),children:[a.jsxs("button",{type:"button",title:d("editor.wordCountFullHint"),onClick:()=>l("full"),disabled:s||!n,children:[s?a.jsx(gt,{className:"spin",size:12}):a.jsx(Au,{size:12}),d("editor.wordCountFull")]}),a.jsxs("button",{type:"button",title:d("editor.wordCountSelectionHint"),onClick:()=>l("selection"),disabled:s||!o,children:[s?a.jsx(gt,{className:"spin",size:12}):a.jsx(Au,{size:12}),d("editor.wordCountSelection")]})]})]}),a.jsxs("div",{className:"outline",children:[C.map(b=>{const{item:w}=b,R=m.has(b.key),S=e===w.path&&h===w.line,E=w.path===n||w.path===e;return a.jsxs("div",{className:`outline-row${S?" current":""}`,children:[a.jsx("span",{className:"outline-guides","aria-hidden":!0,style:{width:`${w.level*12}px`}}),b.hasChildren?a.jsx("button",{className:"outline-toggle",type:"button","aria-label":d(R?"editor.expandOutlineItem":"editor.collapseOutlineItem",{title:w.title}),"aria-expanded":!R,onClick:()=>D(b.key),children:R?a.jsx(_a,{size:13}):a.jsx(qs,{size:13})}):a.jsx("span",{className:"outline-toggle-spacer","aria-hidden":!0}),a.jsxs("button",{className:"outline-item",type:"button",onClick:()=>{i(w.path,w.line,1),c(w.path,w.line,1)},children:[a.jsx("small",{children:E?w.line:w.path.split("/").at(-1)}),a.jsx("span",{className:"outline-title",children:w.title})]})]},b.key)}),t.length===0&&a.jsx("p",{className:"muted padded",children:d("editor.noOutline")})]})]})}function $E(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 UE=u.lazy(()=>$t(()=>import("./LatexEditor-msdbtTyG.js"),__vite__mapDeps([10,2,11,1,3,4,5,6,7,8]),import.meta.url).then(t=>({default:t.LatexEditor})));function zE({project:t,activeFile:e,openTabs:n,content:r,loadedFile:s,readOnly:o,comments:i,focusComment:c,editorPreferences:l,completionIndex:d,nativeSpellCheck:h,spellCheckIssues:f,spellCheckJump:p,sourceJump:m,collaborativeText:g,collaborationAwareness:y,undoManager:C,editorNotice:v,activateTab:D,closeTab:b,handleTabKeyDown:w,updateEditorContent:R,setSelection:S,onAddComment:E,onSelectionHistory:j,onCommentClick:P,onSpellCheckReplace:$,onReferenceNavigate:J,onCursor:T}){const{t:V}=Qe(),U=ux(i,e),B=dx(c,e,s);return a.jsx(ii,{id:"source",order:2,defaultSize:42,minSize:22,children:a.jsxs("main",{className:"source-panel",children:[l.openFilesInTabs&&n.length>0&&a.jsx("div",{className:"editor-tabs-bar",role:"tablist","aria-label":V("editor.openFiles"),children:a.jsx("div",{className:"editor-tabs-scroll",children:n.map((z,re)=>{const H=z===e,X=z===t.mainFile,Q=z.split("/").at(-1)||z;return a.jsxs("div",{className:`editor-tab-item${H?" active":""}`,role:"presentation",children:[a.jsxs("button",{id:`editor-tab-${encodeURIComponent(z)}`,type:"button",role:"tab","aria-selected":H,"aria-controls":"editor-source-content",tabIndex:H?0:-1,className:`editor-tab${H?" active":""}${X?" main-tab":""}`,onClick:()=>D(z),onKeyDown:Z=>w(Z,re),title:z,children:[a.jsx("span",{className:"editor-tab-icon",children:X?a.jsx(lf,{size:13}):a.jsx(ci,{size:13})}),a.jsx("span",{className:"editor-tab-title",children:Q}),X&&a.jsx("small",{className:"editor-tab-badge",children:V("editor.currentMainShort")})]}),a.jsx("button",{type:"button",className:"editor-tab-close",title:V("common.close"),"aria-label":`${V("common.close")} ${Q}`,onClick:()=>b(z),children:a.jsx($n,{size:12})})]},z)})})}),a.jsxs("div",{id:"editor-source-content",className:"editor-content-container",children:[a.jsx(u.Suspense,{fallback:a.jsxs("div",{className:"preview-empty",children:[a.jsx(gt,{className:"spin",size:22}),a.jsx("span",{children:V("common.loading")})]}),children:a.jsx(UE,{value:r,filePath:e,readOnly:o,comments:U,focusComment:B,preferences:l,nativeSpellCheck:h,completionIndex:d,spellCheckIssues:f,spellCheckJump:p,jumpTo:s===e&&m?.path===e?m:null,searchRequest:0,collaboration:g?{text:g,awareness:y,undoManager:o?void 0:C}:void 0,onChange:R,onSelection:S,onAddComment:E,onSelectionHistory:j,onCommentClick:P,onSpellCheckReplace:$,onReferenceNavigate:J,onCursor:T},e)}),v&&a.jsx("div",{className:"editor-centered-notice",role:"status","aria-live":"polite",children:v})]})]})})}function _d({diagnostics:t,files:e,empty:n,tone:r,onJump:s}){const{t:o}=Qe(),i=r==="error"?Ta:Gt;return t.length?a.jsx("div",{className:`compile-diagnostic-list compile-${r}`,children:t.map((c,l)=>{const d=VE(c.file,e),h=!!(d&&c.line);return a.jsxs("button",{type:"button",disabled:!h,className:"compile-diagnostic-row",onClick:()=>{d&&c.line&&s(d,c.line,c.column??1)},children:[a.jsx(i,{size:15}),a.jsxs("span",{children:[a.jsx("strong",{children:c.message}),a.jsxs("small",{children:[c.phase,d?` · ${d}${c.line?`:${c.line}`:""}`:c.line?` · ${o("editor.lineNumber",{line:c.line})}`:""]})]})]},`${c.phase}-${c.file??""}-${c.line??0}-${l}`)})}):a.jsxs("div",{className:`compile-empty compile-${r}`,children:[a.jsx(i,{size:26}),a.jsx("span",{children:n})]})}function kc({lines:t,empty:e,tone:n="log"}){const r=n==="error"?Ta:n==="warning"?Gt:Fc;return t.length?a.jsx("pre",{className:`compile-output compile-${n}`,children:t.join(`
|
|
18
|
-
`)}):a.jsxs("div",{className:`compile-empty compile-${n}`,children:[a.jsx(r,{size:26}),a.jsx("span",{children:e})]})}function BE({projectId:t,mainFile:e,artifacts:n,preview:r,loading:s,onView:o}){const{t:i}=Qe(),c=l=>cs(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(e)}&path=${encodeURIComponent(l)}&download=1`);return n.length?a.jsxs("div",{className:"artifact-browser",children:[a.jsx("div",{className:"artifact-list",children:n.map(l=>a.jsxs("div",{className:`artifact-row${r?.path===l.path?" active":""}`,children:[a.jsxs("button",{type:"button",disabled:!l.viewable,title:l.viewable?i("editor.viewArtifact"):i("editor.downloadToView"),onClick:()=>o(l),children:[a.jsx(rp,{path:l.path,size:14}),a.jsxs("span",{children:[a.jsx("strong",{children:l.path}),a.jsx("small",{children:HE(l.size)})]})]}),a.jsx("a",{href:c(l.path),title:i("editor.downloadArtifact"),"aria-label":i("editor.downloadArtifact"),children:a.jsx(Fo,{size:14})})]},l.path))}),a.jsx("div",{className:"artifact-preview",children:s?a.jsxs("div",{className:"compile-empty",children:[a.jsx(gt,{className:"spin",size:24}),a.jsx("span",{children:i("common.loading")})]}):r?a.jsxs(a.Fragment,{children:[a.jsxs("header",{children:[a.jsx("strong",{children:r.path}),a.jsxs("a",{href:c(r.path),children:[a.jsx(Fo,{size:13}),i("projects.download")]})]}),a.jsx("pre",{children:r.content})]}):a.jsxs("div",{className:"compile-empty",children:[a.jsx(ci,{size:24}),a.jsx("span",{children:i("editor.selectArtifact")})]})})]}):a.jsxs("div",{className:"compile-empty",children:[a.jsx(df,{size:26}),a.jsx("span",{children:i("editor.noArtifacts")})]})}function WE({mainFile:t,disabled:e,cleaning:n,onCleanCache:r,onCleanArtifacts:s}){const{t:o}=Qe();return a.jsxs("div",{className:"compile-clean-panel",children:[a.jsxs("div",{className:"compile-clean-intro",children:[a.jsx(Gt,{size:28}),a.jsxs("div",{children:[a.jsx("strong",{children:o("editor.cleanTitle")}),a.jsx("p",{children:o("editor.cleanDescription",{file:t})})]})]}),a.jsxs("div",{className:"compile-clean-actions",children:[a.jsxs("article",{children:[a.jsx("div",{className:"compile-clean-action-icon",children:a.jsx($c,{size:19})}),a.jsxs("div",{children:[a.jsx("strong",{children:o("editor.cleanCache")}),a.jsx("p",{children:o("editor.cleanCacheDescription")}),a.jsxs("button",{type:"button",disabled:e||n,onClick:r,children:[n?a.jsx(gt,{className:"spin",size:14}):a.jsx($c,{size:14}),o("editor.cleanCache")]})]})]}),a.jsxs("article",{className:"danger",children:[a.jsx("div",{className:"compile-clean-action-icon",children:a.jsx(dr,{size:19})}),a.jsxs("div",{children:[a.jsx("strong",{children:o("editor.cleanArtifacts")}),a.jsx("p",{children:o("editor.cleanArtifactsDescription")}),a.jsxs("button",{type:"button",className:"danger",disabled:e||n,onClick:s,children:[n?a.jsx(gt,{className:"spin",size:14}):a.jsx(dr,{size:14}),o("editor.cleanArtifacts")]})]})]})]})]})}function VE(t,e){if(!t)return null;const n=e.filter(c=>c.type==="file").map(c=>c.path),r=t.replaceAll("\\","/").replace(/^\.\//,"");if(n.includes(r))return r;const s=n.filter(c=>r.endsWith(`/${c}`));if(s.length===1)return s[0];const o=r.split("/").at(-1),i=n.filter(c=>c.split("/").at(-1)===o);return i.length===1?i[0]:null}function HE(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}const qE=u.lazy(()=>rf().then(t=>({default:t.PdfPreview})));function KE({projectId:t,activeMainFile:e,previewTab:n,diagnosticTab:r,pdfUrl:s,pdfLoadingMode:o,pdfLoading:i,pdfCompiledAt:c,pdfSizeBytes:l,pdfCompiledLabel:d,pdfTargetLabel:h,pdfDownloadUrl:f,pdfTarget:p,pdfViewport:m,activeFile:g,compileBusy:y,compileLog:C,compileDiagnostics:v,compileMessages:D,artifacts:b,artifactPreview:w,artifactLoading:R,cleaning:S,readOnly:E,collaborationSynced:j,workspaceLayout:P,showSyncResize:$,diagnosticCount:J,selectPreviewTab:T,changeWorkspaceLayout:V,onSetNotice:U,onSetPdfViewport:B,onResetPdfViewport:z,syncVisiblePdfToSource:re,syncCurrentSourceToPdf:H,syncPdfToSource:X,canSyncWithPdf:Q,canSyncPdfToSource:Z,files:ge,jumpToSource:ye,onSetCleanMode:Ce,cleanCompile:_e,viewArtifact:A}){const{t:q}=Qe(),[fe,W]=u.useState(""),ee=u.useRef(""),Ee=L=>{ee.current!==L&&(ee.current=L,W(L),z())},pe=Z&&!!s&&fe===s,ae=[l==null?"":GE(l),d?q("editor.pdfUpdatedAt",{time:d}):""].filter(Boolean).join(" · ");return a.jsxs(a.Fragment,{children:[$&&a.jsxs(ja,{className:"resize-handle sync-resize-handle",children:[a.jsx(uf,{className:"resize-grip",size:12}),a.jsxs("span",{className:"sync-direction-buttons",onPointerDown:L=>L.stopPropagation(),children:[a.jsx("button",{disabled:!s||!m||!pe,title:q(Z?pe?"editor.showInSource":"editor.syncTexWaitingForPdf":"editor.syncTexOnlyForMain"),"aria-label":q("editor.showInSource"),onClick:()=>{pe&&re()},children:a.jsx("span",{"aria-hidden":!0,children:"←"})}),a.jsx("button",{disabled:!g||!s||!Q,title:q(Q?"editor.showInPdf":"editor.syncTexOnlyForMain"),"aria-label":q("editor.showInPdf"),onClick:()=>{!g||!s||!Q||H()},children:a.jsx("span",{"aria-hidden":!0,children:"→"})})]})]}),a.jsx(ii,{id:"preview",order:3,defaultSize:42,minSize:22,children:a.jsxs("section",{className:"preview-panel",children:[a.jsxs("div",{className:"preview-tabs",children:[a.jsxs("div",{className:"preview-tab-list",role:"tablist","aria-label":q("editor.outputTabs"),children:[a.jsxs("button",{role:"tab","aria-selected":n==="pdf",className:`pdf-tab${n==="pdf"?" active":""}`,onClick:()=>T("pdf"),title:c?q("editor.pdfCompiledAtFor",{file:e,time:new Date(c).toLocaleString(Rs.resolvedLanguage)}):q("editor.currentMainDocument",{path:e}),children:[a.jsx("img",{className:"pdf-tab-icon",src:cs("/pdf-download.svg"),alt:"","aria-hidden":"true"}),a.jsxs("span",{className:"pdf-tab-label",children:["PDF · ",h,ae&&a.jsx("small",{children:ae})]})]}),a.jsxs("button",{role:"tab","aria-selected":n==="diagnostics",className:`diagnostics-tab${n==="diagnostics"?" active":""}`,onClick:()=>T("diagnostics"),children:[a.jsx(Fc,{size:14}),q("editor.outputTabs"),a.jsx("span",{children:J})]})]}),f&&a.jsxs("a",{className:"pdf-download-top",href:f,download:!0,title:q("editor.downloadPdf"),"aria-label":q("editor.downloadPdf"),children:[a.jsx(Fo,{size:15}),a.jsx("span",{children:q("editor.downloadPdf")})]})]}),n==="diagnostics"&&a.jsxs("div",{className:"preview-subtabs",role:"tablist","aria-label":q("editor.outputTabs"),children:[a.jsxs("button",{role:"tab","aria-selected":r==="log",className:r==="log"?"active":"",onClick:()=>T("log"),children:[a.jsx(Fc,{size:13}),q("editor.log")]}),a.jsxs("button",{role:"tab","aria-selected":r==="warnings",className:r==="warnings"?"active":"",onClick:()=>T("warnings"),children:[a.jsx(Gt,{size:13}),q("editor.warnings"),a.jsx("span",{children:D.warnings.length})]}),a.jsxs("button",{role:"tab","aria-selected":r==="errors",className:r==="errors"?"active":"",onClick:()=>T("errors"),children:[a.jsx(Ta,{size:13}),q("editor.errors"),a.jsx("span",{children:D.errors.length})]}),a.jsxs("button",{role:"tab","aria-selected":r==="artifacts",className:r==="artifacts"?"active":"",onClick:()=>T("artifacts"),children:[a.jsx(df,{size:13}),q("editor.artifacts"),a.jsx("span",{children:b.length})]}),a.jsxs("button",{role:"tab","aria-selected":r==="clean",className:r==="clean"?"active":"",onClick:()=>T("clean"),children:[a.jsx($c,{size:13}),q("editor.clean")]})]}),a.jsxs("div",{className:`preview-content preview-${n} ${n==="diagnostics"?`preview-${r}`:""}`,children:[n==="pdf"&&(s?a.jsx(u.Suspense,{fallback:a.jsxs("div",{className:"pdf-loading-state",role:"status","aria-live":"polite",children:[a.jsx(gt,{className:"spin",size:24}),a.jsx("span",{children:q("editor.loadingPdf")})]}),children:a.jsx(qE,{url:s,loadingMode:o,target:p,compiling:y,onDisplayedUrlChange:Ee,onViewportLocation:(L,Re,Fe)=>{ee.current===s&&B({page:L,x:Re,y:Fe})},onDoubleClickLocation:(L,Re,Fe)=>{ee.current!==s||!pe||(B({page:L,x:Re,y:Fe}),X(L,Re,Fe))}})}):i?a.jsxs("div",{className:"pdf-loading-state",role:"status","aria-live":"polite",children:[a.jsx(gt,{className:"spin",size:24}),a.jsx("span",{children:q("editor.loadingPdf")})]}):a.jsxs("div",{className:"preview-empty",children:[a.jsx(ci,{size:28}),a.jsx("strong",{children:q("editor.preview")}),a.jsx("span",{children:q("editor.previewHint")})]})),n==="diagnostics"&&r==="log"&&a.jsx(kc,{lines:C?C.split(`
|
|
19
|
-
`):[],empty:q(y?"editor.compiling":"editor.noLog")}),n==="diagnostics"&&r==="warnings"&&(v?a.jsx(_d,{tone:"warning",diagnostics:v.warnings,files:ge,empty:q("editor.noWarnings"),onJump:(L,Re,Fe)=>{P==="pdf-only"&&V("editor-pdf"),ye(L,Re,Fe)}}):a.jsx(kc,{tone:"warning",lines:D.warnings,empty:q("editor.noWarnings")})),n==="diagnostics"&&r==="errors"&&(v?a.jsx(_d,{tone:"error",diagnostics:v.errors,files:ge,empty:q("editor.noErrors"),onJump:(L,Re,Fe)=>{P==="pdf-only"&&V("editor-pdf"),ye(L,Re,Fe)}}):a.jsx(kc,{tone:"error",lines:D.errors,empty:q("editor.noErrors")})),n==="diagnostics"&&r==="artifacts"&&a.jsx(BE,{projectId:t,mainFile:e,artifacts:b,preview:w,loading:R,onView:L=>{A(L)}}),n==="diagnostics"&&r==="clean"&&a.jsx(WE,{mainFile:e,disabled:E||!j||y,cleaning:S,onCleanCache:()=>Ce("cache"),onCleanArtifacts:()=>Ce("artifacts")})]})]})})]})}function GE(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`}var JE=Object.defineProperty,Ut=(t,e)=>JE(t,"name",{value:e,configurable:!0});function ip(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];oa(s)&&typeof vo=="function"&&(s=vo(s._payload)),u.Children.forEach(s,p=>{if(up(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;oa(g)&&typeof vo=="function"&&(g=vo(g._payload)),i=XE(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?lp(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?e1(t):QE(t));return s}const f=ap(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}Ut(ip,"createSlot");var cp=Symbol.for("radix.slottable");function YE(t){const e=Ut(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=cp,e}Ut(YE,"createSlottable");var XE=Ut((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function ap(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=fp(o,s))}return{...t,...n}}Ut(ap,"mergeProps");function lp(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}Ut(lp,"getElementRef");function up(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===cp}Ut(up,"isSlottable");var ZE=Symbol.for("react.lazy");function oa(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===ZE&&"_payload"in t&&dp(t._payload)}Ut(oa,"isLazyComponent");function dp(t){return typeof t=="object"&&t!==null&&"then"in t}Ut(dp,"isPromiseLike");function fp(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}Ut(fp,"concatAriaDescribedby");var QE=Ut(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),e1=Ut(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),vo=br[" use ".trim().toString()],t1=Object.defineProperty,n1=(t,e)=>t1(t,"name",{value:e,configurable:!0}),r1=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],s1=r1.reduce((t,e)=>{const n=ip(`Primitive.${e}`),r=u.forwardRef((s,o)=>{const{asChild:i,...c}=s,l=i?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(l,{...c,ref:o})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function o1(t,e){t&&Kn.flushSync(()=>t.dispatchEvent(e))}n1(o1,"dispatchDiscreteCustomEvent");var i1=Object.defineProperty,zt=(t,e)=>i1(t,"name",{value:e,configurable:!0});function Bs(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];ia(s)&&typeof So=="function"&&(s=So(s._payload)),u.Children.forEach(s,p=>{if(gp(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;ia(g)&&typeof So=="function"&&(g=So(g._payload)),i=a1(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?mp(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?d1(t):u1(t));return s}const f=pp(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}zt(Bs,"createSlot");var hp=Symbol.for("radix.slottable");function c1(t){const e=zt(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=hp,e}zt(c1,"createSlottable");var a1=zt((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function pp(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=wp(o,s))}return{...t,...n}}zt(pp,"mergeProps");function mp(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}zt(mp,"getElementRef");function gp(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===hp}zt(gp,"isSlottable");var l1=Symbol.for("react.lazy");function ia(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===l1&&"_payload"in t&&yp(t._payload)}zt(ia,"isLazyComponent");function yp(t){return typeof t=="object"&&t!==null&&"then"in t}zt(yp,"isPromiseLike");function wp(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}zt(wp,"concatAriaDescribedby");var u1=zt(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),d1=zt(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),So=br[" use ".trim().toString()],f1=Object.defineProperty,dt=(t,e)=>f1(t,"name",{value:e,configurable:!0});function hl(t){const e=t+"CollectionProvider",[n,r]=wr(e),[s,o]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=dt(y=>{const{scope:C,children:v}=y,D=u.useRef(null),b=u.useRef(new Map).current;return a.jsx(s,{scope:C,itemMap:b,collectionRef:D,children:v})},"CollectionProvider");i.displayName=e;const c=t+"CollectionSlot",l=Bs(c),d=u.forwardRef((y,C)=>{const{scope:v,children:D}=y,b=o(c,v),w=He(C,b.collectionRef);return a.jsx(l,{ref:w,children:D})});d.displayName=c;const h=t+"CollectionItemSlot",f="data-radix-collection-item",p=Bs(h),m=u.forwardRef((y,C)=>{const{scope:v,children:D,...b}=y,w=u.useRef(null),R=He(C,w),S=o(h,v);return u.useEffect(()=>(S.itemMap.set(w,{ref:w,...b}),()=>{S.itemMap.delete(w)})),a.jsx(p,{[f]:"",ref:R,children:D})});m.displayName=h;function g(y){const C=o(t+"CollectionConsumer",y);return u.useCallback(()=>{const D=C.collectionRef.current;if(!D)return[];const b=Array.from(D.querySelectorAll(`[${f}]`));return Array.from(C.itemMap.values()).sort((S,E)=>b.indexOf(S.ref.current)-b.indexOf(E.ref.current))},[C.collectionRef,C.itemMap])}return dt(g,"useCollection"),[{Provider:i,Slot:d,ItemSlot:m},g,r]}dt(hl,"createCollection");var Td=new WeakMap,Rc=class Nn extends Map{static{dt(this,"OrderedDict")}#e;constructor(e){super(e),this.#e=[...super.keys()],Td.set(this,!0)}set(e,n){return Td.get(this)&&(this.has(e)?this.#e[this.#e.indexOf(e)]=e:this.#e.push(e)),super.set(e,n),this}insert(e,n,r){const s=this.has(n),o=this.#e.length,i=pl(e);let c=i>=0?i:o+i;const l=c<0||c>=o?-1:c;if(l===this.size||s&&l===this.size-1||l===-1)return this.set(n,r),this;const d=this.size+(s?0:1);i<0&&c++;const h=[...this.#e];let f,p=!1;for(let m=c;m<d;m++)if(c===m){let g=h[m];h[m]===n&&(g=h[m+1]),s&&this.delete(n),f=this.get(g),this.set(n,r)}else{!p&&h[m-1]===n&&(p=!0);const g=h[p?m:m-1],y=f;f=this.get(g),this.delete(g),this.set(g,y)}return this}with(e,n,r){const s=new Nn(this);return s.insert(e,n,r),s}before(e){const n=this.#e.indexOf(e)-1;if(!(n<0))return this.entryAt(n)}setBefore(e,n,r){const s=this.#e.indexOf(e);return s===-1?this:this.insert(s,n,r)}after(e){let n=this.#e.indexOf(e);if(n=n===-1||n===this.size-1?-1:n+1,n!==-1)return this.entryAt(n)}setAfter(e,n,r){const s=this.#e.indexOf(e);return s===-1?this:this.insert(s+1,n,r)}first(){return this.entryAt(0)}last(){return this.entryAt(-1)}clear(){return this.#e=[],super.clear()}delete(e){const n=super.delete(e);return n&&this.#e.splice(this.#e.indexOf(e),1),n}deleteAt(e){const n=this.keyAt(e);return n!==void 0?this.delete(n):!1}at(e){const n=Oo(this.#e,e);if(n!==void 0)return this.get(n)}entryAt(e){const n=Oo(this.#e,e);if(n!==void 0)return[n,this.get(n)]}indexOf(e){return this.#e.indexOf(e)}keyAt(e){return Oo(this.#e,e)}from(e,n){const r=this.indexOf(e);if(r===-1)return;let s=r+n;return s<0&&(s=0),s>=this.size&&(s=this.size-1),this.at(s)}keyFrom(e,n){const r=this.indexOf(e);if(r===-1)return;let s=r+n;return s<0&&(s=0),s>=this.size&&(s=this.size-1),this.keyAt(s)}find(e,n){let r=0;for(const s of this){if(Reflect.apply(e,n,[s,r,this]))return s;r++}}findIndex(e,n){let r=0;for(const s of this){if(Reflect.apply(e,n,[s,r,this]))return r;r++}return-1}filter(e,n){const r=[];let s=0;for(const o of this)Reflect.apply(e,n,[o,s,this])&&r.push(o),s++;return new Nn(r)}map(e,n){const r=[];let s=0;for(const o of this)r.push([o[0],Reflect.apply(e,n,[o,s,this])]),s++;return new Nn(r)}reduce(...e){const[n,r]=e;let s=0,o=r??this.at(0);for(const i of this)s===0&&e.length===1?o=i:o=Reflect.apply(n,this,[o,i,s,this]),s++;return o}reduceRight(...e){const[n,r]=e;let s=r??this.at(-1);for(let o=this.size-1;o>=0;o--){const i=this.at(o);o===this.size-1&&e.length===1?s=i:s=Reflect.apply(n,this,[s,i,o,this])}return s}toSorted(e){const n=[...this.entries()].sort(e);return new Nn(n)}toReversed(){const e=new Nn;for(let n=this.size-1;n>=0;n--){const r=this.keyAt(n),s=this.get(r);e.set(r,s)}return e}toSpliced(...e){const n=[...this.entries()];return n.splice(...e),new Nn(n)}slice(e,n){const r=new Nn;let s=this.size-1;if(e===void 0)return r;e<0&&(e=e+this.size),n!==void 0&&n>0&&(s=n-1);for(let o=e;o<=s;o++){const i=this.keyAt(o),c=this.get(i);r.set(i,c)}return r}every(e,n){let r=0;for(const s of this){if(!Reflect.apply(e,n,[s,r,this]))return!1;r++}return!0}some(e,n){let r=0;for(const s of this){if(Reflect.apply(e,n,[s,r,this]))return!0;r++}return!1}};function Oo(t,e){if("at"in Array.prototype)return Array.prototype.at.call(t,e);const n=bp(t,e);return n===-1?void 0:t[n]}dt(Oo,"at");function bp(t,e){const n=t.length,r=pl(e),s=r>=0?r:n+r;return s<0||s>=n?-1:s}dt(bp,"toSafeIndex");function pl(t){return t!==t||t===0?0:Math.trunc(t)}dt(pl,"toSafeInteger");function h1(t){const e=t+"CollectionProvider",[n,r]=wr(e),[s,o]=n(e,{collectionElement:null,collectionRef:{current:null},collectionRefObject:{current:null},itemMap:new Rc,setItemMap:dt(()=>{},"setItemMap")}),i=dt(({state:b,...w})=>b?a.jsx(l,{...w,state:b}):a.jsx(c,{...w}),"CollectionProvider");i.displayName=e;const c=dt(b=>{const w=C();return a.jsx(l,{...b,state:w})},"CollectionInit");c.displayName=e+"Init";const l=dt(b=>{const{scope:w,children:R,state:S}=b,E=u.useRef(null),[j,P]=u.useState(null),$=He(E,P),[J,T]=S;return u.useEffect(()=>{if(!j)return;const V=Sp(()=>{});return V.observe(j,{childList:!0,subtree:!0}),()=>{V.disconnect()}},[j]),a.jsx(s,{scope:w,itemMap:J,setItemMap:T,collectionRef:$,collectionRefObject:E,collectionElement:j,children:R})},"CollectionProviderImpl");l.displayName=e+"Impl";const d=t+"CollectionSlot",h=Bs(d),f=u.forwardRef((b,w)=>{const{scope:R,children:S}=b,E=o(d,R),j=He(w,E.collectionRef);return a.jsx(h,{ref:j,children:S})});f.displayName=d;const p=t+"CollectionItemSlot",m="data-radix-collection-item",g=Bs(p),y=u.forwardRef((b,w)=>{const{scope:R,children:S,...E}=b,j=u.useRef(null),[P,$]=u.useState(null),J=He(w,j,$),T=o(p,R),{setItemMap:V}=T,U=u.useRef(E);xp(U.current,E)||(U.current=E);const B=U.current;return u.useEffect(()=>{const z=B;return V(re=>P?re.has(P)?re.set(P,{...z,element:P}).toSorted(ca):(re.set(P,{...z,element:P}),re.toSorted(ca)):re),()=>{V(re=>!P||!re.has(P)?re:(re.delete(P),new Rc(re)))}},[P,B,V]),a.jsx(g,{[m]:"",ref:J,children:S})});y.displayName=p;function C(){return u.useState(new Rc)}dt(C,"useInitCollection");function v(b){const{itemMap:w}=o(t+"CollectionConsumer",b);return w}return dt(v,"useCollection"),[{Provider:i,Slot:f,ItemSlot:y},{createCollectionScope:r,useCollection:v,useInitCollection:C}]}dt(h1,"createCollection");function xp(t,e){if(t===e)return!0;if(typeof t!="object"||typeof e!="object"||t==null||e==null)return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(e,s)||t[s]!==e[s])return!1;return!0}dt(xp,"shallowEqual");function vp(t,e){return!!(e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING)}dt(vp,"isElementPreceding");function ca(t,e){return!t[1].element||!e[1].element?0:vp(t[1].element,e[1].element)?-1:1}dt(ca,"sortByDocumentPosition");function Sp(t){return new MutationObserver(n=>{for(const r of n)if(r.type==="childList"){t();return}})}dt(Sp,"getChildListObserver");var p1=Object.defineProperty,m1=(t,e)=>p1(t,"name",{value:e,configurable:!0}),g1={LTR:"ltr"},y1=u.createContext(void 0);function ml(t){const e=u.useContext(y1);return t||e||g1.LTR}m1(ml,"useDirection");var w1=Object.defineProperty,Bt=(t,e)=>w1(t,"name",{value:e,configurable:!0});function gl(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];aa(s)&&typeof Co=="function"&&(s=Co(s._payload)),u.Children.forEach(s,p=>{if(Rp(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;aa(g)&&typeof Co=="function"&&(g=Co(g._payload)),i=x1(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?kp(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?C1(t):S1(t));return s}const f=Ep(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}Bt(gl,"createSlot");var Cp=Symbol.for("radix.slottable");function b1(t){const e=Bt(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=Cp,e}Bt(b1,"createSlottable");var x1=Bt((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function Ep(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=jp(o,s))}return{...t,...n}}Bt(Ep,"mergeProps");function kp(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}Bt(kp,"getElementRef");function Rp(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Cp}Bt(Rp,"isSlottable");var v1=Symbol.for("react.lazy");function aa(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===v1&&"_payload"in t&&Dp(t._payload)}Bt(aa,"isLazyComponent");function Dp(t){return typeof t=="object"&&t!==null&&"then"in t}Bt(Dp,"isPromiseLike");function jp(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}Bt(jp,"concatAriaDescribedby");var S1=Bt(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),C1=Bt(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Co=br[" use ".trim().toString()],E1=Object.defineProperty,k1=(t,e)=>E1(t,"name",{value:e,configurable:!0}),R1=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],vi=R1.reduce((t,e)=>{const n=gl(`Primitive.${e}`),r=u.forwardRef((s,o)=>{const{asChild:i,...c}=s,l=i?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(l,{...c,ref:o})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function yl(t,e){t&&Kn.flushSync(()=>t.dispatchEvent(e))}k1(yl,"dispatchDiscreteCustomEvent");var D1=Object.defineProperty,lt=(t,e)=>D1(t,"name",{value:e,configurable:!0}),la="dismissableLayer.update",j1="dismissableLayer.pointerDownOutside",_1="dismissableLayer.focusOutside",Pd,_p=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),T1=u.forwardRef(lt(function(e,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:s=!1,onEscapeKeyDown:o,onPointerDownOutside:i,onFocusOutside:c,onInteractOutside:l,onDismiss:d,...h}=e,f=u.useContext(_p),[p,m]=u.useState(null),g=p?.ownerDocument??globalThis?.document,[,y]=u.useState({}),C=He(n,m),v=Array.from(f.layers),[D]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),b=D?v.indexOf(D):-1,w=p?v.indexOf(p):-1,R=f.layersWithOutsidePointerEventsDisabled.size>0,S=w>=b,E=u.useRef(!1),j=Tp(T=>{i?.(T),l?.(T),T.defaultPrevented||d?.()},{ownerDocument:g,deferPointerDownOutside:s,isDeferredPointerDownOutsideRef:E,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:u.useCallback(T=>{if(!(T instanceof Node))return!1;const V=[...f.branches].some(U=>U.contains(T));return S&&!V},[f.branches,S])}),P=Pp(T=>{if(s&&E.current)return;const V=T.target;[...f.branches].some(B=>B.contains(V))||(c?.(T),l?.(T),T.defaultPrevented||d?.())},g),$=p?w===v.length-1:!1,J=Ot(T=>{T.key==="Escape"&&(o?.(T),!T.defaultPrevented&&d&&(T.preventDefault(),d()))});return u.useEffect(()=>{if($)return g.addEventListener("keydown",J,{capture:!0}),()=>g.removeEventListener("keydown",J,{capture:!0})},[g,$,J]),u.useEffect(()=>{if(p)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Pd=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(p)),f.layers.add(p),ua(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(p),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Pd))}},[p,g,r,f]),u.useEffect(()=>()=>{p&&(f.layers.delete(p),f.layersWithOutsidePointerEventsDisabled.delete(p),ua())},[p,f]),u.useEffect(()=>{const T=lt(()=>y({}),"handleUpdate");return document.addEventListener(la,T),()=>document.removeEventListener(la,T)},[]),a.jsx(vi.div,{...h,ref:C,style:{pointerEvents:R?S?"auto":"none":void 0,...e.style},onFocusCapture:Ne(e.onFocusCapture,P.onFocusCapture),onBlurCapture:Ne(e.onBlurCapture,P.onBlurCapture),onPointerDownCapture:Ne(e.onPointerDownCapture,j.onPointerDownCapture)})},"DismissableLayer"));function P1(){const t=u.useContext(_p),[e,n]=u.useState(null);return u.useEffect(()=>{if(e)return t.dismissableSurfaces.add(e),()=>{t.dismissableSurfaces.delete(e)}},[e,t.dismissableSurfaces]),n}lt(P1,"useDismissableLayerSurface");var A1=lt(()=>!0,"IS_TRUE");function Tp(t,e){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:s,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=A1}=e,c=Ot(t),l=u.useRef(!1),d=u.useRef(!1),h=u.useRef(new Map),f=u.useRef(()=>{});return u.useEffect(()=>{function p(){d.current=!1,s.current=!1,h.current.clear()}lt(p,"resetOutsideInteraction");function m(){return Array.from(h.current.values()).some(Boolean)}lt(m,"isOutsideInteractionIntercepted");function g(b){if(!d.current)return;const w=b.target;w instanceof Node&&[...o].some(S=>S.contains(w))||h.current.set(b.type,!0),b.type==="click"&&window.setTimeout(()=>{d.current&&f.current()},0)}lt(g,"handleInteractionCapture");function y(b){d.current&&h.current.set(b.type,!1)}lt(y,"handleInteractionBubble");const C=lt(b=>{if(b.target&&!l.current){let w=function(){n.removeEventListener("click",f.current);const S=m();p(),S||wl(j1,c,R,{discrete:!0})};if(lt(w,"handleAndDispatchPointerDownOutsideEvent"),!i(b.target)){n.removeEventListener("click",f.current),p(),l.current=!1;return}const R={originalEvent:b};d.current=!0,s.current=r&&b.button===0,h.current.clear(),!r||b.button!==0?w():(n.removeEventListener("click",f.current),f.current=w,n.addEventListener("click",f.current,{once:!0}))}else n.removeEventListener("click",f.current),p();l.current=!1},"handlePointerDown"),v=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const b of v)n.addEventListener(b,g,!0),n.addEventListener(b,y);const D=window.setTimeout(()=>{n.addEventListener("pointerdown",C)},0);return()=>{window.clearTimeout(D),n.removeEventListener("pointerdown",C),n.removeEventListener("click",f.current);for(const b of v)n.removeEventListener(b,g,!0),n.removeEventListener(b,y)}},[n,c,r,s,o,i]),{onPointerDownCapture:lt(()=>l.current=!0,"onPointerDownCapture")}}lt(Tp,"usePointerDownOutside");function Pp(t,e=globalThis?.document){const n=Ot(t),r=u.useRef(!1);return u.useEffect(()=>{const s=lt(o=>{o.target&&!r.current&&wl(_1,n,{originalEvent:o},{discrete:!1})},"handleFocus");return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,n]),{onFocusCapture:lt(()=>r.current=!0,"onFocusCapture"),onBlurCapture:lt(()=>r.current=!1,"onBlurCapture")}}lt(Pp,"useFocusOutside");function ua(){const t=new CustomEvent(la);document.dispatchEvent(t)}lt(ua,"dispatchUpdate");function wl(t,e,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?yl(s,o):s.dispatchEvent(o)}lt(wl,"handleAndDispatchCustomEvent");var O1=Object.defineProperty,rt=(t,e)=>O1(t,"name",{value:e,configurable:!0}),Dc="focusScope.autoFocusOnMount",jc="focusScope.autoFocusOnUnmount",Ad={bubbles:!1,cancelable:!0},L1=u.forwardRef(rt(function(e,n){const{loop:r=!1,trapped:s=!1,branches:o,onMountAutoFocus:i,onUnmountAutoFocus:c,...l}=e,[d,h]=u.useState(null),f=Ot(i),p=Ot(c),m=u.useRef(null),g=He(n,h),y=u.useRef(o);u.useEffect(()=>{y.current=o});const C=u.useCallback(b=>b?d?.contains(b)?!0:!!y.current?.some(w=>w.contains(b)):!1,[d]),v=u.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;u.useEffect(()=>{if(s){let b=function(E){if(v.paused||!d)return;const j=E.target;C(j)?m.current=j:gn(m.current,{select:!0})},w=function(E){if(v.paused||!d)return;const j=E.relatedTarget;j!==null&&(C(j)||gn(m.current,{select:!0}))},R=function(E){if(document.activeElement===document.body)for(const P of E)P.removedNodes.length>0&&gn(d)};rt(b,"handleFocusIn"),rt(w,"handleFocusOut"),rt(R,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",w);const S=new MutationObserver(R);return d&&S.observe(d,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",w),S.disconnect()}}},[s,d,v.paused,C]),u.useEffect(()=>{if(d){Od.add(v);const b=document.activeElement;if(!d.contains(b)){const R=new CustomEvent(Dc,Ad);d.addEventListener(Dc,f),d.dispatchEvent(R),R.defaultPrevented||(Mp(zp(bl(d)),{select:!0}),document.activeElement===b&&gn(d))}return()=>{d.removeEventListener(Dc,f),setTimeout(()=>{const R=new CustomEvent(jc,Ad);d.addEventListener(jc,p),d.dispatchEvent(R),R.defaultPrevented||gn(b??document.body,{select:!0}),d.removeEventListener(jc,p),Od.remove(v)},0)}}},[d,f,p,v]);const D=u.useCallback(b=>{if(!r&&!s||v.paused)return;const w=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,R=document.activeElement;if(w&&R){const S=b.currentTarget,[E,j]=Fp(S);E&&j?!b.shiftKey&&R===j?(b.preventDefault(),r&&gn(E,{select:!0})):b.shiftKey&&R===E&&(b.preventDefault(),r&&gn(j,{select:!0})):R===S&&b.preventDefault()}},[r,s,v.paused]);return a.jsx(vi.div,{tabIndex:-1,...l,ref:g,onKeyDown:D})},"FocusScope")),Ap=u.createContext(null);function Op({registry:t,children:e}){return t?a.jsx(Ap.Provider,{value:t,children:e}):e}rt(Op,"FocusScopeBranchProvider");function Lp(){const[t,e]=u.useState([]),n=u.useMemo(()=>({add:rt(r=>e(s=>s.includes(r)?s:[...s,r]),"add"),remove:rt(r=>e(s=>s.filter(o=>o!==r)),"remove")}),[]);return{nodes:t,registry:n}}rt(Lp,"useFocusScopeBranchRegistry");function Np(t){const e=u.useContext(Ap);u.useEffect(()=>{if(!(!t||!e))return e.add(t),()=>e.remove(t)},[t,e])}rt(Np,"useFocusScopeBranch");function Mp(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(gn(r,{select:e}),document.activeElement!==n)return}rt(Mp,"focusFirst");function Fp(t){const e=bl(t),n=da(e,t),r=da(e.reverse(),t);return[n,r]}rt(Fp,"getTabbableEdges");function bl(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:rt(r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)e.push(n.currentNode);return e}rt(bl,"getTabbableCandidates");function da(t,e){const n=typeof e.checkVisibility=="function"&&e.checkVisibility({checkVisibilityCSS:!0});for(const r of t)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):Ip(r,{upTo:e})))return r}rt(da,"findVisible");function Ip(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}rt(Ip,"isHidden");function $p(t){return t instanceof HTMLInputElement&&"select"in t}rt($p,"isSelectableInput");function gn(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&$p(t)&&e&&t.select()}}rt(gn,"focus");var Od=Up();function Up(){let t=[];return{add(e){const n=t[0];e!==n&&n?.pause(),t=fa(t,e),t.unshift(e)},remove(e){t=fa(t,e),t[0]?.resume()}}}rt(Up,"createFocusScopesStack");function fa(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}rt(fa,"arrayRemove");function zp(t){return t.filter(e=>e.tagName!=="A")}rt(zp,"removeLinks");const N1=["top","right","bottom","left"],Hn=Math.min,xn=Math.max,ti=Math.round,Eo=Math.floor,vn=t=>({x:t,y:t}),M1={left:"right",right:"left",bottom:"top",top:"bottom"};function Bp(t,e,n){return xn(t,Hn(e,n))}function Cn(t,e){return typeof t=="function"?t(e):t}function qn(t){return t.split("-")[0]}function hs(t){return t.split("-")[1]}function xl(t){return t==="x"?"y":"x"}function vl(t){return t==="y"?"height":"width"}function en(t){const e=t[0];return e==="t"||e==="b"?"y":"x"}function Sl(t){return xl(en(t))}function F1(t,e,n){n===void 0&&(n=!1);const r=hs(t),s=Sl(t),o=vl(s);let i=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=ni(i)),[i,ni(i)]}function I1(t){const e=ni(t);return[ha(t),e,ha(e)]}function ha(t){return t.includes("start")?t.replace("start","end"):t.replace("end","start")}const Ld=["left","right"],Nd=["right","left"],$1=["top","bottom"],U1=["bottom","top"];function z1(t,e,n){switch(t){case"top":case"bottom":return n?e?Nd:Ld:e?Ld:Nd;case"left":case"right":return e?$1:U1;default:return[]}}function B1(t,e,n,r){const s=hs(t);let o=z1(qn(t),n==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map(ha)))),o}function ni(t){const e=qn(t);return M1[e]+t.slice(e.length)}function W1(t){var e,n,r,s;return{top:(e=t.top)!=null?e:0,right:(n=t.right)!=null?n:0,bottom:(r=t.bottom)!=null?r:0,left:(s=t.left)!=null?s:0}}function Wp(t){return typeof t!="number"?W1(t):{top:t,right:t,bottom:t,left:t}}function ri(t){const{x:e,y:n,width:r,height:s}=t;return{width:r,height:s,top:n,left:e,right:e+r,bottom:n+s,x:e,y:n}}function Md(t,e,n){let{reference:r,floating:s}=t;const o=en(e),i=Sl(e),c=vl(i),l=qn(e),d=o==="y",h=r.x+r.width/2-s.width/2,f=r.y+r.height/2-s.height/2,p=r[c]/2-s[c]/2;let m;switch(l){case"top":m={x:h,y:r.y-s.height};break;case"bottom":m={x:h,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:f};break;case"left":m={x:r.x-s.width,y:f};break;default:m={x:r.x,y:r.y}}const g=hs(e);return g&&(m[i]+=p*(g==="end"?1:-1)*(n&&d?-1:1)),m}async function V1(t,e){var n;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:c,strategy:l}=t,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:f="floating",altBoundary:p=!1,padding:m=0}=Cn(e,t),g=Wp(m),C=c[p?f==="floating"?"reference":"floating":f],v=ri(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(C)))==null||n?C:C.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(c.floating)),boundary:d,rootBoundary:h,strategy:l})),D=f==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,b=await(o.getOffsetParent==null?void 0:o.getOffsetParent(c.floating)),w=await(o.isElement==null?void 0:o.isElement(b))&&await(o.getScale==null?void 0:o.getScale(b))||{x:1,y:1},R=ri(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:D,offsetParent:b,strategy:l}):D);return{top:(v.top-R.top+g.top)/w.y,bottom:(R.bottom-v.bottom+g.bottom)/w.y,left:(v.left-R.left+g.left)/w.x,right:(R.right-v.right+g.right)/w.x}}const H1=50,q1=async(t,e,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=n,c=i.detectOverflow?i:{...i,detectOverflow:V1},l=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:t,floating:e,strategy:s}),{x:h,y:f}=Md(d,r,l),p=r,m=0;const g={};for(let y=0;y<o.length;y++){const C=o[y];if(!C)continue;const{name:v,fn:D}=C,{x:b,y:w,data:R,reset:S}=await D({x:h,y:f,initialPlacement:r,placement:p,strategy:s,middlewareData:g,rects:d,platform:c,elements:{reference:t,floating:e}});h=b??h,f=w??f,g[v]={...g[v],...R},S&&m<H1&&(m++,typeof S=="object"&&(S.placement&&(p=S.placement),S.rects&&(d=S.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:s}):S.rects),{x:h,y:f}=Md(d,p,l)),y=-1)}return{x:h,y:f,placement:p,strategy:s,middlewareData:g}},K1=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:s,rects:o,platform:i,elements:c,middlewareData:l}=e,{element:d,padding:h=0}=Cn(t,e)||{};if(d==null)return{};const f=Wp(h),p={x:n,y:r},m=Sl(s),g=vl(m),y=await i.getDimensions(d),C=m==="y",v=C?"top":"left",D=C?"bottom":"right",b=C?"clientHeight":"clientWidth",w=o.reference[g]+o.reference[m]-p[m]-o.floating[g],R=p[m]-o.reference[m],S=await(i.getOffsetParent==null?void 0:i.getOffsetParent(d));let E=S?S[b]:0;(!E||!await(i.isElement==null?void 0:i.isElement(S)))&&(E=c.floating[b]||o.floating[g]);const j=w/2-R/2,P=E/2-y[g]/2-1,$=Hn(f[v],P),J=Hn(f[D],P),T=E-y[g]-J,V=E/2-y[g]/2+j,U=Bp($,V,T),B=!l.arrow&&hs(s)!=null&&V!==U&&o.reference[g]/2-(V<$?$:J)-y[g]/2<0,z=B?V<$?V-$:V-T:0;return{[m]:p[m]+z,data:{[m]:U,centerOffset:V-U-z,...B&&{alignmentOffset:z}},reset:B}}}),G1=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:c,platform:l,elements:d}=e,{mainAxis:h=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:m="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:y=!0,...C}=Cn(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};const v=qn(s),D=en(c),b=qn(c)===c,w=await(l.isRTL==null?void 0:l.isRTL(d.floating)),R=p||(b||!y?[ni(c)]:I1(c)),S=g!=="none";!p&&S&&R.push(...B1(c,y,g,w));const E=[c,...R],j=await l.detectOverflow(e,C),P=[];let $=((r=o.flip)==null?void 0:r.overflows)||[];if(h&&P.push(j[v]),f){const U=F1(s,i,w);P.push(j[U[0]],j[U[1]])}if($=[...$,{placement:s,overflows:P}],!P.every(U=>U<=0)){var J,T;const U=(((J=o.flip)==null?void 0:J.index)||0)+1,B=E[U];if(B&&(!(f==="alignment"?D!==en(B):!1)||$.every(H=>en(H.placement)===D?H.overflows[0]>0:!0)))return{data:{index:U,overflows:$},reset:{placement:B}};let z=(T=$.filter(re=>re.overflows[0]<=0).sort((re,H)=>re.overflows[1]-H.overflows[1])[0])==null?void 0:T.placement;if(!z)switch(m){case"bestFit":{var V;const re=(V=$.filter(H=>{if(S){const X=en(H.placement);return X===D||X==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(X=>X>0).reduce((X,Q)=>X+Q,0)]).sort((H,X)=>H[1]-X[1])[0])==null?void 0:V[0];re&&(z=re);break}case"initialPlacement":z=c;break}if(s!==z)return{reset:{placement:z}}}return{}}}};function Fd(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function Id(t){return N1.some(e=>t[e]>=0)}const J1=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n,platform:r}=e,{strategy:s="referenceHidden",...o}=Cn(t,e);switch(s){case"referenceHidden":{const i=await r.detectOverflow(e,{...o,elementContext:"reference"}),c=Fd(i,n.reference);return{data:{referenceHiddenOffsets:c,referenceHidden:Id(c)}}}case"escaped":{const i=await r.detectOverflow(e,{...o,altBoundary:!0}),c=Fd(i,n.floating);return{data:{escapedOffsets:c,escaped:Id(c)}}}default:return{}}}}},Vp=new Set(["left","top"]);async function Y1(t,e){const{placement:n,platform:r,elements:s}=t,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=qn(n),c=hs(n),l=en(n)==="y",d=Vp.has(i)?-1:1,h=o&&l?-1:1,f=Cn(e,t);let{mainAxis:p,crossAxis:m,alignmentAxis:g}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return c&&typeof g=="number"&&(m=c==="end"?g*-1:g),l?{x:m*h,y:p*d}:{x:p*d,y:m*h}}const X1=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:s,y:o,placement:i,middlewareData:c}=e,l=await Y1(e,t);return i===((n=c.offset)==null?void 0:n.placement)&&(r=c.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},Z1=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:s,platform:o}=e,{mainAxis:i=!0,crossAxis:c=!1,limiter:l={fn:D=>{let{x:b,y:w}=D;return{x:b,y:w}}},...d}=Cn(t,e),h={x:n,y:r},f=await o.detectOverflow(e,d),p=en(s),m=xl(p);let g=h[m],y=h[p];const C=(D,b)=>Bp(b+f[D==="y"?"top":"left"],b,b-f[D==="y"?"bottom":"right"]);i&&(g=C(m,g)),c&&(y=C(p,y));const v=l.fn({...e,[m]:g,[p]:y});return{...v,data:{x:v.x-n,y:v.y-r,enabled:{[m]:i,[p]:c}}}}}},Q1=function(t){return t===void 0&&(t={}),{options:t,fn(e){var n,r;const{x:s,y:o,placement:i,rects:c,middlewareData:l}=e,{offset:d=0,mainAxis:h=!0,crossAxis:f=!0}=Cn(t,e),p={x:s,y:o},m=en(i),g=xl(m);let y=p[g],C=p[m];const v=Cn(d,e),D=typeof v=="number"?{mainAxis:v,crossAxis:0}:{mainAxis:(n=v.mainAxis)!=null?n:0,crossAxis:(r=v.crossAxis)!=null?r:0};if(h){const R=g==="y"?"height":"width",S=c.reference[g]-c.floating[R]+D.mainAxis,E=c.reference[g]+c.reference[R]-D.mainAxis;y<S?y=S:y>E&&(y=E)}if(f){var b,w;const R=g==="y"?"width":"height",S=Vp.has(qn(i)),E=c.reference[m]-c.floating[R]+(S&&((b=l.offset)==null?void 0:b[m])||0)+(S?0:D.crossAxis),j=c.reference[m]+c.reference[R]+(S?0:((w=l.offset)==null?void 0:w[m])||0)-(S?D.crossAxis:0);C<E?C=E:C>j&&(C=j)}return{[g]:y,[m]:C}}}},ek=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){const{placement:n,rects:r,platform:s,elements:o}=e,{apply:i=()=>{},...c}=Cn(t,e),l=await s.detectOverflow(e,c),d=qn(n),h=hs(n),f=en(n)==="y",{width:p,height:m}=r.floating;let g,y;d==="top"||d==="bottom"?(g=d,y=h===(await(s.isRTL==null?void 0:s.isRTL(o.floating))?"start":"end")?"left":"right"):(y=d,g=h==="end"?"top":"bottom");const C=m-l.top-l.bottom,v=p-l.left-l.right,D=Hn(m-l[g],C),b=Hn(p-l[y],v),w=e.middlewareData.shift,R=!w;let S=D,E=b;w!=null&&w.enabled.x&&(E=v),w!=null&&w.enabled.y&&(S=C),R&&!h&&(f?E=p-2*xn(l.left,l.right):S=m-2*xn(l.top,l.bottom)),await i({...e,availableWidth:E,availableHeight:S});const j=await s.getDimensions(o.floating);return p!==j.width||m!==j.height?{reset:{rects:!0}}:{}}}};function Si(){return typeof window<"u"}function ps(t){return Hp(t)?(t.nodeName||"").toLowerCase():"#document"}function jt(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Dn(t){var e;return(e=(Hp(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Hp(t){return Si()?t instanceof Node||t instanceof jt(t).Node:!1}function sn(t){return Si()?t instanceof Element||t instanceof jt(t).Element:!1}function Jn(t){return Si()?t instanceof HTMLElement||t instanceof jt(t).HTMLElement:!1}function $d(t){return!Si()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof jt(t).ShadowRoot}function Ci(t){const{overflow:e,overflowX:n,overflowY:r,display:s}=on(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&s!=="inline"&&s!=="contents"}function tk(t){return/^(table|td|th)$/.test(ps(t))}function Ei(t){try{if(t.matches(":popover-open"))return!0}catch{}try{return t.matches(":modal")}catch{return!1}}const nk=/transform|translate|scale|rotate|perspective|filter/,rk=/paint|layout|strict|content/,or=t=>!!t&&t!=="none";let _c;function Cl(t){const e=sn(t)?on(t):t;return or(e.transform)||or(e.translate)||or(e.scale)||or(e.rotate)||or(e.perspective)||!El()&&(or(e.backdropFilter)||or(e.filter))||nk.test(e.willChange||"")||rk.test(e.contain||"")}function sk(t){let e=gr(t);for(;Jn(e)&&!Ws(e);){if(Cl(e))return e;if(Ei(e))return null;e=gr(e)}return null}function El(){return _c==null&&(_c=typeof CSS<"u"&&CSS.supports&&CSS.supports("-webkit-backdrop-filter","none")),_c}function Ws(t){return/^(html|body|#document)$/.test(ps(t))}function on(t){return jt(t).getComputedStyle(t)}function ki(t){return sn(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function gr(t){if(ps(t)==="html")return t;const e=t.assignedSlot||t.parentNode||$d(t)&&t.host||Dn(t);return $d(e)?e.host:e}function qp(t){const e=gr(t);return Ws(e)?(t.ownerDocument||t).body:Jn(e)&&Ci(e)?e:qp(e)}function Vs(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const s=qp(t),o=s===((r=t.ownerDocument)==null?void 0:r.body),i=jt(s);if(o){const c=pa(i);return e.concat(i,i.visualViewport||[],Ci(s)?s:[],c&&n?Vs(c):[])}else return e.concat(s,Vs(s,[],n))}function pa(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Kp(t){const e=on(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Jn(t),o=s?t.offsetWidth:n,i=s?t.offsetHeight:r,c=ti(n)!==o||ti(r)!==i;return c&&(n=o,r=i),{width:n,height:r,$:c}}function kl(t){return sn(t)?t:t.contextElement}function Xr(t){const e=kl(t);if(!Jn(e))return vn(1);const n=e.getBoundingClientRect(),{width:r,height:s,$:o}=Kp(e);let i=(o?ti(n.width):n.width)/r,c=(o?ti(n.height):n.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!c||!Number.isFinite(c))&&(c=1),{x:i,y:c}}const ok=vn(0);function Gp(t){const e=jt(t);return!El()||!e.visualViewport?ok:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ik(t,e,n){return e===void 0&&(e=!1),!!n&&e&&n===jt(t)}function yr(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const s=t.getBoundingClientRect(),o=kl(t);let i=vn(1);e&&(r?sn(r)&&(i=Xr(r)):i=Xr(t));const c=ik(o,n,r)?Gp(o):vn(0);let l=(s.left+c.x)/i.x,d=(s.top+c.y)/i.y,h=s.width/i.x,f=s.height/i.y;if(o&&r){const p=jt(o),m=sn(r)?jt(r):r;let g=p,y=pa(g);for(;y&&m!==g;){const C=Xr(y),v=y.getBoundingClientRect(),D=on(y),b=v.left+(y.clientLeft+parseFloat(D.paddingLeft))*C.x,w=v.top+(y.clientTop+parseFloat(D.paddingTop))*C.y;l*=C.x,d*=C.y,h*=C.x,f*=C.y,l+=b,d+=w,g=jt(y),y=pa(g)}}return ri({width:h,height:f,x:l,y:d})}function Ri(t,e){const n=ki(t).scrollLeft;return e?e.left+n:yr(Dn(t)).left+n}function Jp(t,e){const n=t.getBoundingClientRect(),r=n.left+e.scrollLeft-Ri(t,n),s=n.top+e.scrollTop;return{x:r,y:s}}function ck(t){let{elements:e,rect:n,offsetParent:r,strategy:s}=t;const o=s==="fixed",i=Dn(r),c=e?Ei(e.floating):!1;if(r===i||c&&o)return n;let l={scrollLeft:0,scrollTop:0},d=vn(1);const h=vn(0),f=Jn(r);if((f||!o)&&((ps(r)!=="body"||Ci(i))&&(l=ki(r)),f)){const m=yr(r);d=Xr(r),h.x=m.x+r.clientLeft,h.y=m.y+r.clientTop}const p=i&&!f&&!o?Jp(i,l):vn(0);return{width:n.width*d.x,height:n.height*d.y,x:n.x*d.x-l.scrollLeft*d.x+h.x+p.x,y:n.y*d.y-l.scrollTop*d.y+h.y+p.y}}function ak(t){return t.getClientRects?Array.from(t.getClientRects()):[]}function lk(t){const e=ki(t),n=t.ownerDocument.body,r=xn(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),s=xn(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight);let o=-e.scrollLeft+Ri(t);const i=-e.scrollTop;return on(n).direction==="rtl"&&(o+=xn(t.clientWidth,n.clientWidth)-r),{width:r,height:s,x:o,y:i}}const uk=25;function dk(t,e,n){n===void 0&&(n="viewport");const r=n==="layoutViewport",s=jt(t),o=Dn(t),i=s.visualViewport;let c=o.clientWidth,l=o.clientHeight,d=0,h=0;if(i){const p=!El()||e==="fixed";r?p||(d=-i.offsetLeft,h=-i.offsetTop):(c=i.width,l=i.height,p&&(d=i.offsetLeft,h=i.offsetTop))}if(Ri(o)<=0){const p=o.ownerDocument,m=p.body,g=getComputedStyle(m),y=p.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,C=Math.abs(o.clientWidth-m.clientWidth-y),v=getComputedStyle(o).scrollbarGutter==="stable both-edges"?C/2:C;v<=uk&&(c-=v)}return{width:c,height:l,x:d,y:h}}function fk(t,e){const n=yr(t,!0,e==="fixed"),r=n.top+t.clientTop,s=n.left+t.clientLeft,o=Xr(t),i=t.clientWidth*o.x,c=t.clientHeight*o.y,l=s*o.x,d=r*o.y;return{width:i,height:c,x:l,y:d}}function Ud(t,e,n){let r;if(e==="viewport"||e==="layoutViewport")r=dk(t,n,e);else if(e==="document")r=lk(Dn(t));else if(sn(e))r=fk(e,n);else{const s=Gp(t);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return ri(r)}function hk(t,e){const n=e.get(t);if(n)return n;let r=Vs(t,[],!1).filter(c=>sn(c)&&ps(c)!=="body"),s=null;const o=on(t).position==="fixed";let i=o?gr(t):t;for(;sn(i)&&!Ws(i);){const c=on(i),l=Cl(i),d=s?s.position:o?"fixed":"";!l&&(d==="fixed"||d==="absolute"&&c.position==="static")?r=r.filter(f=>f!==i):s=c,i=gr(i)}return e.set(t,r),r}function pk(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const i=[...n==="clippingAncestors"?Ei(e)?[]:hk(e,this._c):[].concat(n),r],c=Ud(e,i[0],s);let l=c.top,d=c.right,h=c.bottom,f=c.left;for(let p=1;p<i.length;p++){const m=Ud(e,i[p],s);l=xn(m.top,l),d=Hn(m.right,d),h=Hn(m.bottom,h),f=xn(m.left,f)}return{width:d-f,height:h-l,x:f,y:l}}function mk(t){const{width:e,height:n}=Kp(t);return{width:e,height:n}}function gk(t,e,n){const r=Jn(e),s=Dn(e),o=n==="fixed",i=yr(t,!0,o,e);let c={scrollLeft:0,scrollTop:0};const l=vn(0);if((r||!o)&&((ps(e)!=="body"||Ci(s))&&(c=ki(e)),r)){const p=yr(e,!0,o,e);l.x=p.x+e.clientLeft,l.y=p.y+e.clientTop}!r&&s&&(l.x=Ri(s));const d=s&&!r&&!o?Jp(s,c):vn(0),h=i.left+c.scrollLeft-l.x-d.x,f=i.top+c.scrollTop-l.y-d.y;return{x:h,y:f,width:i.width,height:i.height}}function Tc(t){return on(t).position==="static"}function zd(t,e){if(!Jn(t)||on(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Dn(t)===n&&(n=n.ownerDocument.body),n}function Yp(t,e){const n=jt(t);if(Ei(t))return n;if(!Jn(t)){let s=gr(t);for(;s&&!Ws(s);){if(sn(s)&&!Tc(s))return s;s=gr(s)}return n}let r=zd(t,e);for(;r&&tk(r)&&Tc(r);)r=zd(r,e);return r&&Ws(r)&&Tc(r)&&!Cl(r)?n:r||sk(t)||n}const yk=async function(t){const e=this.getOffsetParent||Yp,n=this.getDimensions,r=await n(t.floating);return{reference:gk(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function wk(t){return on(t).direction==="rtl"}const bk={convertOffsetParentRelativeRectToViewportRelativeRect:ck,getDocumentElement:Dn,getClippingRect:pk,getOffsetParent:Yp,getElementRects:yk,getClientRects:ak,getDimensions:mk,getScale:Xr,isElement:sn,isRTL:wk};function Xp(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function xk(t,e,n){let r=null,s;const o=Dn(t);function i(){var h;clearTimeout(s),(h=r)==null||h.disconnect(),r=null}function c(h,f){h===void 0&&(h=!1),f===void 0&&(f=1),i();const p=t.getBoundingClientRect(),{left:m,top:g,width:y,height:C}=p;if(h||e(),!y||!C)return;const v=Eo(g),D=Eo(o.clientWidth-(m+y)),b=Eo(o.clientHeight-(g+C)),w=Eo(m),S={rootMargin:-v+"px "+-D+"px "+-b+"px "+-w+"px",threshold:xn(0,Hn(1,f))||1};let E=!0;function j(P){const $=P[0].intersectionRatio;if(!Xp(p,t.getBoundingClientRect()))return c();if($!==f){if(!E)return c();$?c(!1,$):s=setTimeout(()=>{c(!1,1e-7)},1e3)}E=!1}try{r=new IntersectionObserver(j,{...S,root:o.ownerDocument})}catch{r=new IntersectionObserver(j,S)}r.observe(t)}const l=jt(t),d=()=>c(n);return l.addEventListener("resize",d),c(!0),()=>{l.removeEventListener("resize",d),i()}}function vk(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,d=kl(t),h=s||o?[...d?Vs(d):[],...e?Vs(e):[]]:[];h.forEach(v=>{s&&v.addEventListener("scroll",n),o&&v.addEventListener("resize",n)});const f=d&&c?xk(d,n,o):null;let p=-1,m=null;i&&(m=new ResizeObserver(v=>{let[D]=v;D&&D.target===d&&m&&e&&(m.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=m)==null||b.observe(e)})),n()}),d&&!l&&m.observe(d),e&&m.observe(e));let g,y=l?yr(t):null;l&&C();function C(){const v=yr(t);y&&!Xp(y,v)&&n(),y=v,g=requestAnimationFrame(C)}return n(),()=>{var v;h.forEach(D=>{s&&D.removeEventListener("scroll",n),o&&D.removeEventListener("resize",n)}),f?.(),(v=m)==null||v.disconnect(),m=null,l&&cancelAnimationFrame(g)}}const Sk=X1,Ck=Z1,Ek=G1,kk=ek,Rk=J1,Bd=K1,Dk=Q1,jk=(t,e,n)=>{const r=new Map,s=n??{},o={...bk,...s.platform,_c:r};return q1(t,e,{...s,platform:o})};var _k=typeof document<"u",Tk=function(){},Lo=_k?u.useLayoutEffect:Tk;function si(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!si(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!si(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function Zp(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function Wd(t,e){const n=Zp(t);return Math.round(e*n)/n}function Pc(t){const e=u.useRef(t);return Lo(()=>{e.current=t}),e}function Pk(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:c=!0,whileElementsMounted:l,open:d}=t,[h,f]=u.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[p,m]=u.useState(r);si(p,r)||m(r);const[g,y]=u.useState(null),[C,v]=u.useState(null),D=u.useCallback(H=>{H!==S.current&&(S.current=H,y(H))},[]),b=u.useCallback(H=>{H!==E.current&&(E.current=H,v(H))},[]),w=o||g,R=i||C,S=u.useRef(null),E=u.useRef(null),j=u.useRef(h),P=l!=null,$=Pc(l),J=Pc(s),T=Pc(d),V=u.useCallback(()=>{if(!S.current||!E.current)return;const H={placement:e,strategy:n,middleware:p};J.current&&(H.platform=J.current),jk(S.current,E.current,H).then(X=>{const Q={...X,isPositioned:T.current!==!1};U.current&&!si(j.current,Q)&&(j.current=Q,Kn.flushSync(()=>{f(Q)}))})},[p,e,n,J,T]);Lo(()=>{d===!1&&j.current.isPositioned&&(j.current.isPositioned=!1,f(H=>({...H,isPositioned:!1})))},[d]);const U=u.useRef(!1);Lo(()=>(U.current=!0,()=>{U.current=!1}),[]),Lo(()=>{if(w&&(S.current=w),R&&(E.current=R),w&&R){if($.current)return $.current(w,R,V);V()}},[w,R,V,$,P]);const B=u.useMemo(()=>({reference:S,floating:E,setReference:D,setFloating:b}),[D,b]),z=u.useMemo(()=>({reference:w,floating:R}),[w,R]),re=u.useMemo(()=>{const H={position:n,left:0,top:0};if(!z.floating)return H;const X=Wd(z.floating,h.x),Q=Wd(z.floating,h.y);return c?{...H,transform:"translate("+X+"px, "+Q+"px)",...Zp(z.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:X,top:Q}},[n,c,z.floating,h.x,h.y]);return u.useMemo(()=>({...h,update:V,refs:B,elements:z,floatingStyles:re}),[h,V,B,z,re])}const Ak=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:s}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?Bd({element:r.current,padding:s}).fn(n):{}:r?Bd({element:r,padding:s}).fn(n):{}}}},Ok=(t,e)=>{const n=Sk(t);return{name:n.name,fn:n.fn,options:[t,e]}},Lk=(t,e)=>{const n=Ck(t);return{name:n.name,fn:n.fn,options:[t,e]}},Nk=(t,e)=>({fn:Dk(t).fn,options:[t,e]}),Mk=(t,e)=>{const n=Ek(t);return{name:n.name,fn:n.fn,options:[t,e]}},Fk=(t,e)=>{const n=kk(t);return{name:n.name,fn:n.fn,options:[t,e]}},Ik=(t,e)=>{const n=Rk(t);return{name:n.name,fn:n.fn,options:[t,e]}},$k=(t,e)=>{const n=Ak(t);return{name:n.name,fn:n.fn,options:[t,e]}};var Uk=Object.defineProperty,Wt=(t,e)=>Uk(t,"name",{value:e,configurable:!0});function Qp(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];ma(s)&&typeof ko=="function"&&(s=ko(s._payload)),u.Children.forEach(s,p=>{if(rm(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;ma(g)&&typeof ko=="function"&&(g=ko(g._payload)),i=Bk(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?nm(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?Hk(t):Vk(t));return s}const f=tm(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}Wt(Qp,"createSlot");var em=Symbol.for("radix.slottable");function zk(t){const e=Wt(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=em,e}Wt(zk,"createSlottable");var Bk=Wt((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function tm(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=om(o,s))}return{...t,...n}}Wt(tm,"mergeProps");function nm(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}Wt(nm,"getElementRef");function rm(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===em}Wt(rm,"isSlottable");var Wk=Symbol.for("react.lazy");function ma(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===Wk&&"_payload"in t&&sm(t._payload)}Wt(ma,"isLazyComponent");function sm(t){return typeof t=="object"&&t!==null&&"then"in t}Wt(sm,"isPromiseLike");function om(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}Wt(om,"concatAriaDescribedby");var Vk=Wt(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),Hk=Wt(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),ko=br[" use ".trim().toString()],qk=Object.defineProperty,Kk=(t,e)=>qk(t,"name",{value:e,configurable:!0}),Gk=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],im=Gk.reduce((t,e)=>{const n=Qp(`Primitive.${e}`),r=u.forwardRef((s,o)=>{const{asChild:i,...c}=s,l=i?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(l,{...c,ref:o})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function Jk(t,e){t&&Kn.flushSync(()=>t.dispatchEvent(e))}Kk(Jk,"dispatchDiscreteCustomEvent");var Yk=Object.defineProperty,Xk=(t,e)=>Yk(t,"name",{value:e,configurable:!0});function cm(t){const[e,n]=u.useState(void 0);return It(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});let r=0;const s=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const i=o[0];window.cancelAnimationFrame(r),r=window.requestAnimationFrame(()=>{let c,l;if("borderBoxSize"in i){const d=i.borderBoxSize,h=Array.isArray(d)?d[0]:d;c=h.inlineSize,l=h.blockSize}else c=t.offsetWidth,l=t.offsetHeight;n({width:c,height:l})})});return s.observe(t,{box:"border-box"}),()=>{window.cancelAnimationFrame(r),s.unobserve(t)}}else n(void 0)},[t]),e}Xk(cm,"useSize");var Zk=Object.defineProperty,Un=(t,e)=>Zk(t,"name",{value:e,configurable:!0}),Vd={Partial:"partial"},Hd={Optimized:"optimized",Always:"always"},am="Popper",[lm,Di]=wr(am),[Qk,um]=lm(am),dm=Un(t=>{const{__scopePopper:e,children:n}=t,[r,s]=u.useState(null),[o,i]=u.useState(void 0);return a.jsx(Qk,{scope:e,anchor:r,onAnchorChange:s,placementState:o,setPlacementState:i,children:n})},"Popper"),eR="PopperAnchor",fm=u.forwardRef(Un(function(e,n){const{__scopePopper:r,virtualRef:s,...o}=e,i=um(eR,r),c=u.useRef(null),l=i.onAnchorChange,d=u.useCallback(y=>{c.current=y,y&&l(y)},[l]),h=He(n,d),f=u.useRef(null);u.useEffect(()=>{if(!s)return;const y=f.current;f.current=s.current,y!==f.current&&l(f.current)});const p=i.placementState&&ji(i.placementState),m=p?.[0],g=p?.[1];return s?null:a.jsx(im.div,{"data-radix-popper-side":m,"data-radix-popper-align":g,...o,ref:h})},"PopperAnchor")),hm="PopperContent",[tR,Aj]=lm(hm),pm=u.forwardRef(Un(function(e,n){const{__scopePopper:r,side:s="bottom",sideOffset:o=0,align:i="center",alignOffset:c=0,arrowPadding:l=0,avoidCollisions:d=!0,collisionBoundary:h=[],collisionPadding:f=0,sticky:p=Vd.Partial,hideWhenDetached:m=!1,updatePositionStrategy:g=Hd.Optimized,onPlaced:y,...C}=e,v=um(hm,r),[D,b]=u.useState(null),w=He(n,b),[R,S]=u.useState(null),E=cm(R),j=E?.width??0,P=E?.height??0,$=s+(i!=="center"?"-"+i:""),J=typeof f=="number"?f:{top:0,right:0,bottom:0,left:0,...f},T=Array.isArray(h)?h:[h],V=T.length>0,U={padding:J,boundary:T.filter(mm),altBoundary:V},{refs:B,floatingStyles:z,placement:re,isPositioned:H,middlewareData:X}=Pk({strategy:"fixed",placement:$,whileElementsMounted:Un((...W)=>vk(...W,{animationFrame:g===Hd.Always}),"whileElementsMounted"),elements:{reference:v.anchor},middleware:[Ok({mainAxis:o+P,alignmentAxis:c}),d&&Lk({mainAxis:!0,crossAxis:!1,limiter:p===Vd.Partial?Nk():void 0,...U}),d&&Mk({...U}),Fk({...U,apply:Un(({elements:W,rects:ee,availableWidth:Ee,availableHeight:pe})=>{const{width:K,height:ae}=ee.reference,L=W.floating.style;L.setProperty("--radix-popper-available-width",`${Ee}px`),L.setProperty("--radix-popper-available-height",`${pe}px`),L.setProperty("--radix-popper-anchor-width",`${K}px`),L.setProperty("--radix-popper-anchor-height",`${ae}px`)},"apply")}),R&&$k({element:R,padding:l}),nR({arrowWidth:j,arrowHeight:P}),m&&Ik({strategy:"referenceHidden",...U,boundary:V?U.boundary:void 0})]}),Q=v.setPlacementState;It(()=>(Q(re),()=>{Q(void 0)}),[re,Q]);const[Z,ge]=ji(re),ye=Ot(y);It(()=>{H&&ye?.()},[H,ye]);const Ce=X.arrow?.x,_e=X.arrow?.y,A=X.arrow?.centerOffset!==0,[q,fe]=u.useState();return It(()=>{D&&fe(window.getComputedStyle(D).zIndex)},[D]),a.jsx("div",{ref:B.setFloating,"data-radix-popper-content-wrapper":"",style:{...z,transform:H?z.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:q,"--radix-popper-transform-origin":[X.transformOrigin?.x,X.transformOrigin?.y].join(" "),...X.hide?.referenceHidden&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:a.jsx(tR,{scope:r,placedSide:Z,placedAlign:ge,onArrowChange:S,arrowX:Ce,arrowY:_e,shouldHideArrow:A,children:a.jsx(im.div,{"data-side":Z,"data-align":ge,...C,ref:w,style:{...C.style,animation:H?C.style?.animation:"none"}})})})},"PopperContent"));function mm(t){return t!==null}Un(mm,"isNotNull");var nR=Un(t=>({name:"transformOrigin",options:t,fn(e){const{placement:n,rects:r,middlewareData:s}=e,i=s.arrow?.centerOffset!==0,c=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[d,h]=ji(n),f={start:"0%",center:"50%",end:"100%"}[h],p=(s.arrow?.x??0)+c/2,m=(s.arrow?.y??0)+l/2;let g="",y="";return d==="bottom"?(g=i?f:`${p}px`,y=`${-l}px`):d==="top"?(g=i?f:`${p}px`,y=`${r.floating.height+l}px`):d==="right"?(g=`${-l}px`,y=i?f:`${m}px`):d==="left"&&(g=`${r.floating.width+l}px`,y=i?f:`${m}px`),{data:{x:g,y}}}}),"transformOrigin");function ji(t){const[e,n="center"]=t.split("-");return[e,n]}Un(ji,"getSideAndAlignFromPlacement");var rR=Object.defineProperty,sR=(t,e)=>rR(t,"name",{value:e,configurable:!0}),oR=u.forwardRef(sR(function(e,n){const{container:r,...s}=e,[o,i]=u.useState(!1);It(()=>i(!0),[]);const c=r||o&&globalThis?.document?.body;return c?Kn.createPortal(a.jsx(vi.div,{...s,ref:n}),c):null},"Portal")),iR=Object.defineProperty,En=(t,e)=>iR(t,"name",{value:e,configurable:!0});function gm(t,e){return u.useReducer((n,r)=>e[n][r]??n,t)}En(gm,"useStateMachine");var ym=En(t=>{const{present:e,children:n}=t,r=wm(e),s=typeof n=="function"?n({present:r.isPresent}):u.Children.only(n),o=bm(r.ref,xm(s));return typeof n=="function"||r.isPresent?u.cloneElement(s,{ref:o}):null},"Presence");function wm(t){const[e,n]=u.useState(),r=u.useRef(null),s=u.useRef(t),o=u.useRef("none"),i=u.useRef(void 0),c=t?"mounted":"unmounted",[l,d]=gm(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{l==="mounted"?(o.current=i.current??Ir(r.current),i.current=void 0):o.current="none"},[l]),It(()=>{const h=r.current,f=s.current;if(f!==t){const m=o.current,g=Ir(h);t?(i.current=g,d("MOUNT")):g==="none"||h?.display==="none"?d("UNMOUNT"):d(f&&m!==g?"ANIMATION_OUT":"UNMOUNT"),s.current=t}},[t,d]),It(()=>{if(e){let h;const f=e.ownerDocument.defaultView??window,p=En(g=>{const C=Ir(r.current).includes(CSS.escape(g.animationName));if(g.target===e&&C&&(d("ANIMATION_END"),!s.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",h=f.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},"handleAnimationEnd"),m=En(g=>{g.target===e&&(o.current=Ir(r.current))},"handleAnimationStart");return e.addEventListener("animationstart",m),e.addEventListener("animationcancel",p),e.addEventListener("animationend",p),()=>{f.clearTimeout(h),e.removeEventListener("animationstart",m),e.removeEventListener("animationcancel",p),e.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[e,d]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,i.current=Ir(f)}else r.current=null;n(h)},[])}}En(wm,"usePresence");function ga(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}En(ga,"setRef");function bm(...t){const e=u.useRef(t);return e.current=t,u.useCallback(n=>{const r=e.current;let s=!1;const o=r.map(i=>{const c=ga(i,n);return!s&&typeof c=="function"&&(s=!0),c});if(s)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():ga(r[i],null)}}},[])}En(bm,"useStableComposedRefs");function Ir(t){return t?.animationName||"none"}En(Ir,"getAnimationName");function xm(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}En(xm,"getElementRef");var cR=Object.defineProperty,Vt=(t,e)=>cR(t,"name",{value:e,configurable:!0});function vm(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];ya(s)&&typeof Ro=="function"&&(s=Ro(s._payload)),u.Children.forEach(s,p=>{if(km(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;ya(g)&&typeof Ro=="function"&&(g=Ro(g._payload)),i=lR(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?Em(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?fR(t):dR(t));return s}const f=Cm(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}Vt(vm,"createSlot");var Sm=Symbol.for("radix.slottable");function aR(t){const e=Vt(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=Sm,e}Vt(aR,"createSlottable");var lR=Vt((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function Cm(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=Dm(o,s))}return{...t,...n}}Vt(Cm,"mergeProps");function Em(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}Vt(Em,"getElementRef");function km(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Sm}Vt(km,"isSlottable");var uR=Symbol.for("react.lazy");function ya(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===uR&&"_payload"in t&&Rm(t._payload)}Vt(ya,"isLazyComponent");function Rm(t){return typeof t=="object"&&t!==null&&"then"in t}Vt(Rm,"isPromiseLike");function Dm(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}Vt(Dm,"concatAriaDescribedby");var dR=Vt(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),fR=Vt(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Ro=br[" use ".trim().toString()],hR=Object.defineProperty,pR=(t,e)=>hR(t,"name",{value:e,configurable:!0}),mR=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],jm=mR.reduce((t,e)=>{const n=vm(`Primitive.${e}`),r=u.forwardRef((s,o)=>{const{asChild:i,...c}=s,l=i?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(l,{...c,ref:o})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function gR(t,e){t&&Kn.flushSync(()=>t.dispatchEvent(e))}pR(gR,"dispatchDiscreteCustomEvent");var yR=Object.defineProperty,Rl=(t,e)=>yR(t,"name",{value:e,configurable:!0}),Ac=!1;function _m(){const[t,e]=u.useState(Ac);return u.useEffect(()=>{Ac||(Ac=!0,e(!0))},[]),t}Rl(_m,"useIsHydrated");var Tm=br[" useSyncExternalStore ".trim().toString()];function Pm(){return()=>{}}Rl(Pm,"subscribe");function Am(){return Tm(Pm,()=>!0,()=>!1)}Rl(Am,"useIsHydratedModern");var wR=typeof Tm=="function"?Am:_m,bR=Object.defineProperty,Er=(t,e)=>bR(t,"name",{value:e,configurable:!0}),Oc="rovingFocusGroup.onEntryFocus",xR={bubbles:!1,cancelable:!0},_i="RovingFocusGroup",[wa,Om,vR]=hl(_i),[SR,Lm]=wr(_i,[vR]),qd={Vertical:"vertical",Horizontal:"horizontal"},CR={RTL:"rtl"},[ER,kR]=SR(_i),RR=u.forwardRef(Er(function(e,n){return a.jsx(wa.Provider,{scope:e.__scopeRovingFocusGroup,children:a.jsx(wa.Slot,{scope:e.__scopeRovingFocusGroup,children:a.jsx(DR,{...e,ref:n})})})},"RovingFocusGroup")),DR=u.forwardRef(Er(function(e,n){const{__scopeRovingFocusGroup:r,orientation:s,loop:o=!1,dir:i,currentTabStopId:c,defaultCurrentTabStopId:l,onCurrentTabStopIdChange:d,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...p}=e,m=u.useRef(null),g=He(n,m),y=ml(i),[C,v]=Da({prop:c,defaultProp:l??null,onChange:d,caller:_i}),[D,b]=u.useState(!1),w=Ot(h),R=Om(r),S=u.useRef(!1),[E,j]=u.useState(0);return u.useEffect(()=>{const P=m.current;if(P)return P.addEventListener(Oc,w),()=>P.removeEventListener(Oc,w)},[w]),a.jsx(ER,{scope:r,orientation:s,dir:y,loop:o,currentTabStopId:C,onItemFocus:u.useCallback(P=>v(P),[v]),onItemShiftTab:u.useCallback(()=>b(!0),[]),onFocusableItemAdd:u.useCallback(()=>j(P=>P+1),[]),onFocusableItemRemove:u.useCallback(()=>j(P=>P-1),[]),children:a.jsx(jm.div,{tabIndex:D||E===0?-1:0,"data-orientation":s,...p,ref:g,style:{outline:"none",...e.style},onMouseDown:Ne(e.onMouseDown,()=>{S.current=!0}),onFocus:Ne(e.onFocus,P=>{const $=!S.current;if(P.target===P.currentTarget&&$&&!D){const J=new CustomEvent(Oc,xR);if(P.currentTarget.dispatchEvent(J),!J.defaultPrevented){const T=R().filter(re=>re.focusable),V=T.find(re=>re.active),U=T.find(re=>re.id===C),z=[V,U,...T].filter(Boolean).map(re=>re.ref.current);Dl(z,f)}}S.current=!1}),onBlur:Ne(e.onBlur,()=>b(!1))})})},"RovingFocusGroupImpl")),jR="RovingFocusGroupItem",_R=u.forwardRef(Er(function(e,n){const{__scopeRovingFocusGroup:r,focusable:s=!0,active:o=!1,tabStopId:i,children:c,...l}=e,d=zr(),h=i||d,f=kR(jR,r),p=f.currentTabStopId===h,m=Om(r),{onFocusableItemAdd:g,onFocusableItemRemove:y,currentTabStopId:C}=f,v=wR();return It(()=>{if(!(!v||!s))return g(),()=>y()},[v,s,g,y]),u.useEffect(()=>{if(!(v||!s))return g(),()=>y()},[v,s,g,y]),a.jsx(wa.ItemSlot,{scope:r,id:h,focusable:s,active:o,children:a.jsx(jm.span,{tabIndex:p?0:-1,"data-orientation":f.orientation,...l,ref:n,onMouseDown:Ne(e.onMouseDown,D=>{s?f.onItemFocus(h):D.preventDefault()}),onFocus:Ne(e.onFocus,()=>f.onItemFocus(h)),onKeyDown:Ne(e.onKeyDown,D=>{if(D.key==="Tab"&&D.shiftKey){f.onItemShiftTab();return}if(D.target!==D.currentTarget)return;const b=Mm(D,f.orientation,f.dir);if(b!==void 0){if(D.metaKey||D.ctrlKey||D.altKey||D.shiftKey)return;D.preventDefault();let R=m().filter(S=>S.focusable).map(S=>S.ref.current);if(b==="last")R.reverse();else if(b==="prev"||b==="next"){b==="prev"&&R.reverse();const S=R.indexOf(D.currentTarget);R=f.loop?Fm(R,S+1):R.slice(S+1)}setTimeout(()=>Dl(R))}}),children:typeof c=="function"?c({isCurrentTabStop:p,hasTabStop:C!=null}):c})})},"RovingFocusGroupItem")),TR={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function Nm(t,e){return e!==CR.RTL?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}Er(Nm,"getDirectionAwareKey");function Mm(t,e,n){const r=Nm(t.key,n);if(!(e===qd.Vertical&&["ArrowLeft","ArrowRight"].includes(r))&&!(e===qd.Horizontal&&["ArrowUp","ArrowDown"].includes(r)))return TR[r]}Er(Mm,"getFocusIntent");function Dl(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}Er(Dl,"focusFirst");function Fm(t,e){return t.map((n,r)=>t[(e+r)%t.length])}Er(Fm,"wrapArray");var PR=Object.defineProperty,Ke=(t,e)=>PR(t,"name",{value:e,configurable:!0}),AR=["Enter"," "],OR=["ArrowDown","PageUp","Home"],Im=["ArrowUp","PageDown","End"],LR=[...OR,...Im],Ti="Menu",[ba,NR,MR]=hl(Ti),[kr,$m]=wr(Ti,[MR,Di,Lm]),jl=Di(),Um=Lm(),[FR,to]=kr(Ti),[IR,_l]=kr(Ti),$R=Ke(t=>{const{__scopeMenu:e,open:n=!1,children:r,dir:s,onOpenChange:o,modal:i=!0}=t,c=jl(e),[l,d]=u.useState(null),h=u.useRef(!1),f=Ot(o),p=ml(s);return u.useEffect(()=>{const m=Ke(()=>{h.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},"handleKeyDown"),g=Ke(()=>h.current=!1,"handlePointer");return document.addEventListener("keydown",m,{capture:!0}),()=>{document.removeEventListener("keydown",m,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),u.useEffect(()=>{if(!n)return;const m=Ke(()=>f(!1),"handleBlur");return window.addEventListener("blur",m),()=>window.removeEventListener("blur",m)},[n,f]),a.jsx(dm,{...c,children:a.jsx(FR,{scope:e,open:n,onOpenChange:f,content:l,onContentChange:d,children:a.jsx(IR,{scope:e,onClose:u.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:h,dir:p,modal:i,children:r})})})},"Menu"),UR=u.forwardRef(Ke(function(e,n){const{__scopeMenu:r,...s}=e,o=jl(r);return a.jsx(fm,{...o,...s,ref:n})},"MenuAnchor")),zm="MenuPortal",[zR,BR]=kr(zm,{forceMount:void 0}),WR=Ke(t=>{const{__scopeMenu:e,forceMount:n,children:r,container:s}=t,o=to(zm,e);return a.jsx(zR,{scope:e,forceMount:n,children:a.jsx(ym,{present:n||o.open,children:a.jsx(oR,{asChild:!0,container:s,children:r})})})},"MenuPortal"),zn="MenuContent",[VR,Bm]=kr(zn),HR=u.forwardRef(Ke(function(e,n){const r=BR(zn,e.__scopeMenu),{forceMount:s=r.forceMount,...o}=e,i=to(zn,e.__scopeMenu),c=_l(zn,e.__scopeMenu);return a.jsx(ba.Provider,{scope:e.__scopeMenu,children:a.jsx(ym,{present:s||i.open,children:a.jsx(ba.Slot,{scope:e.__scopeMenu,children:c.modal?a.jsx(qR,{...o,ref:n}):a.jsx(KR,{...o,ref:n})})})})},"MenuContent")),qR=u.forwardRef(Ke(function(e,n){const r=to(zn,e.__scopeMenu),s=u.useRef(null),o=He(n,s);return u.useEffect(()=>{const i=s.current;if(i)return sf(i)},[]),a.jsx(Wm,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:Ne(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentModal")),KR=u.forwardRef(Ke(function(e,n){const r=to(zn,e.__scopeMenu);return a.jsx(Wm,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})},"MenuRootContentNonModal")),GR=gl("MenuContent.ScrollLock"),Wm=u.forwardRef(Ke(function(e,n){const{__scopeMenu:r,loop:s=!1,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:c,disableOutsidePointerEvents:l,onEntryFocus:d,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,disableOutsideScroll:y,...C}=e,v=to(zn,r),D=_l(zn,r),b=jl(r),w=Um(r),R=NR(r),[S,E]=u.useState(null),j=u.useRef(null),[P,$]=u.useState(null);Np(P);const{nodes:J,registry:T}=Lp(),V=!!(o||y),U=He(n,j,v.onContentChange,$),B=u.useRef(0),z=u.useRef(""),re=u.useRef(0),H=u.useRef(null),X=u.useRef("right"),Q=u.useRef(0),Z=u.useMemo(()=>y?[j,...J.map(A=>({current:A}))]:[],[j,J,y]),ge=y?af:u.Fragment,ye=y?{as:GR,allowPinchZoom:!0,shards:Z}:void 0,Ce=Ke(A=>{const q=z.current+A,fe=R().filter(ae=>!ae.disabled),W=document.activeElement,ee=fe.find(ae=>ae.ref.current===W)?.textValue,Ee=fe.map(ae=>ae.textValue),pe=Gm(Ee,q,ee),K=fe.find(ae=>ae.textValue===pe)?.ref.current;Ke((function ae(L){z.current=L,window.clearTimeout(B.current),L!==""&&(B.current=window.setTimeout(()=>ae(""),1e3))}),"updateSearch")(q),K&&setTimeout(()=>K.focus())},"handleTypeaheadSearch");u.useEffect(()=>()=>window.clearTimeout(B.current),[]),of();const _e=u.useCallback(A=>X.current===H.current?.side&&Ym(A,H.current?.area),[]);return a.jsx(VR,{scope:r,searchRef:z,onItemEnter:u.useCallback(A=>{_e(A)&&A.preventDefault()},[_e]),onItemLeave:u.useCallback(A=>{_e(A)||(j.current?.focus(),E(null))},[_e]),onTriggerLeave:u.useCallback(A=>{_e(A)&&A.preventDefault()},[_e]),pointerGraceTimerRef:re,onPointerGraceIntentChange:u.useCallback(A=>{H.current=A},[]),children:a.jsx(Op,{registry:V?T:null,children:a.jsx(ge,{...ye,children:a.jsx(L1,{asChild:!0,trapped:o,branches:J,onMountAutoFocus:Ne(i,A=>{A.preventDefault(),j.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:c,children:a.jsx(T1,{asChild:!0,disableOutsidePointerEvents:l,onEscapeKeyDown:h,onPointerDownOutside:f,onFocusOutside:p,onInteractOutside:m,onDismiss:g,children:a.jsx(RR,{asChild:!0,...w,dir:D.dir,orientation:"vertical",loop:s,currentTabStopId:S,onCurrentTabStopIdChange:E,onEntryFocus:Ne(d,A=>{D.isUsingKeyboardRef.current||A.preventDefault()}),preventScrollOnEntryFocus:!0,children:a.jsx(pm,{role:"menu","aria-orientation":"vertical","data-state":Vm(v.open),"data-radix-menu-content":"",dir:D.dir,...b,...C,ref:U,style:{outline:"none",...C.style},onKeyDown:Ne(C.onKeyDown,A=>{const fe=A.target.closest("[data-radix-menu-content]")===A.currentTarget,W=A.ctrlKey||A.altKey||A.metaKey,ee=A.key.length===1;fe&&(A.key==="Tab"&&A.preventDefault(),!W&&ee&&Ce(A.key));const Ee=j.current;if(A.target!==Ee||!LR.includes(A.key))return;A.preventDefault();const K=R().filter(ae=>!ae.disabled).map(ae=>ae.ref.current);Im.includes(A.key)&&K.reverse(),qm(K)}),onBlur:Ne(e.onBlur,A=>{A.currentTarget.contains(A.target)||(window.clearTimeout(B.current),z.current="")}),onPointerMove:Ne(e.onPointerMove,oi(A=>{const q=A.target,fe=Q.current!==A.clientX;if(A.currentTarget.contains(q)&&fe){const W=A.clientX>Q.current?"right":"left";X.current=W,Q.current=A.clientX}}))})})})})})})})},"MenuContentImpl")),xa="MenuItem",Kd="menu.itemSelect",JR=u.forwardRef(Ke(function(e,n){const{disabled:r=!1,onSelect:s,...o}=e,i=u.useRef(null),c=_l(xa,e.__scopeMenu),l=Bm(xa,e.__scopeMenu),d=He(n,i),h=u.useRef(!1),f=Ke(()=>{const p=i.current;if(!r&&p){const m=new CustomEvent(Kd,{bubbles:!0,cancelable:!0});p.addEventListener(Kd,g=>s?.(g),{once:!0}),yl(p,m),m.defaultPrevented?h.current=!1:c.onClose()}},"handleSelect");return a.jsx(YR,{...o,ref:d,disabled:r,onClick:Ne(e.onClick,f),onPointerDown:p=>{e.onPointerDown?.(p),h.current=!0},onPointerUp:Ne(e.onPointerUp,p=>{h.current||p.currentTarget?.click()}),onKeyDown:Ne(e.onKeyDown,p=>{r||p.target!==p.currentTarget||l.searchRef.current!==""&&p.key===" "||AR.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})},"MenuItem")),YR=u.forwardRef(Ke(function(e,n){const{__scopeMenu:r,disabled:s=!1,textValue:o,...i}=e,c=Bm(xa,r),l=Um(r),d=u.useRef(null),h=He(n,d),[f,p]=u.useState(!1),[m,g]=u.useState("");return u.useEffect(()=>{const y=d.current;y&&g((y.textContent??"").trim())},[i.children]),a.jsx(ba.ItemSlot,{scope:r,disabled:s,textValue:o??m,children:a.jsx(_R,{asChild:!0,...l,focusable:!s,children:a.jsx(vi.div,{role:"menuitem","data-highlighted":f?"":void 0,"aria-disabled":s||void 0,"data-disabled":s?"":void 0,...i,ref:h,onPointerMove:Ne(e.onPointerMove,oi(y=>{s?c.onItemLeave(y):(c.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:Ne(e.onPointerLeave,oi(y=>c.onItemLeave(y))),onFocus:Ne(e.onFocus,()=>p(!0)),onBlur:Ne(e.onBlur,()=>p(!1))})})})},"MenuItemImpl")),XR="MenuRadioGroup",[Oj,Lj]=kr(XR,{value:void 0,onValueChange:Ke(()=>{},"onValueChange")}),ZR="MenuItemIndicator",[Nj,Mj]=kr(ZR,{checked:!1}),QR="MenuSub",[Fj,Ij]=kr(QR);function Vm(t){return t?"open":"closed"}Ke(Vm,"getOpenState");function Hm(t){return t==="indeterminate"}Ke(Hm,"isIndeterminate");function eD(t){return Hm(t)?"indeterminate":t?"checked":"unchecked"}Ke(eD,"getCheckedState");function qm(t){const e=document.activeElement;for(const n of t)if(n===e||(n.focus(),document.activeElement!==e))return}Ke(qm,"focusFirst");function Km(t,e){return t.map((n,r)=>t[(e+r)%t.length])}Ke(Km,"wrapArray");function Gm(t,e,n){const s=e.length>1&&Array.from(e).every(d=>d===e[0])?e[0]:e,o=n?t.indexOf(n):-1;let i=Km(t,Math.max(o,0));s.length===1&&(i=i.filter(d=>d!==n));const l=i.find(d=>d.toLowerCase().startsWith(s.toLowerCase()));return l!==n?l:void 0}Ke(Gm,"getNextMatch");function Jm(t,e){const{x:n,y:r}=t;let s=!1;for(let o=0,i=e.length-1;o<e.length;i=o++){const c=e[o],l=e[i],d=c.x,h=c.y,f=l.x,p=l.y;h>r!=p>r&&n<(f-d)*(r-h)/(p-h)+d&&(s=!s)}return s}Ke(Jm,"isPointInPolygon");function Ym(t,e){if(!e)return!1;const n={x:t.clientX,y:t.clientY};return Jm(n,e)}Ke(Ym,"isPointerInGraceArea");function oi(t){return e=>e.pointerType==="mouse"?t(e):void 0}Ke(oi,"whenMouse");var tD=Object.defineProperty,no=(t,e)=>tD(t,"name",{value:e,configurable:!0}),Tl="DropdownMenu",[nD,$j]=wr(Tl,[$m]),ro=$m(),[rD,Xm]=nD(Tl),sD=no(t=>{const{__scopeDropdownMenu:e,children:n,dir:r,open:s,defaultOpen:o,onOpenChange:i,modal:c=!0}=t,l=ro(e),d=u.useRef(null),[h,f]=Da({prop:s,defaultProp:o??!1,onChange:i,caller:Tl});return a.jsx(rD,{scope:e,triggerId:zr(),triggerRef:d,contentId:zr(),open:h,onOpenChange:f,onOpenToggle:u.useCallback(()=>f(p=>!p),[f]),modal:c,children:a.jsx($R,{...l,open:h,onOpenChange:f,dir:r,modal:c,children:n})})},"DropdownMenu"),oD="DropdownMenuTrigger",iD=u.forwardRef(no(function(e,n){const{__scopeDropdownMenu:r,disabled:s=!1,...o}=e,i=Xm(oD,r),c=ro(r),l=He(n,i.triggerRef);return a.jsx(UR,{asChild:!0,...c,children:a.jsx(s1.button,{type:"button",id:i.triggerId,"aria-haspopup":"menu","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":i.open?"open":"closed","data-disabled":s?"":void 0,disabled:s,...o,ref:l,onPointerDown:Ne(e.onPointerDown,d=>{!s&&d.button===0&&d.ctrlKey===!1&&(i.onOpenToggle(),i.open||d.preventDefault())}),onKeyDown:Ne(e.onKeyDown,d=>{s||(["Enter"," "].includes(d.key)&&i.onOpenToggle(),d.key==="ArrowDown"&&i.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(d.key)&&d.preventDefault())})})})},"DropdownMenuTrigger")),cD=no(t=>{const{__scopeDropdownMenu:e,...n}=t,r=ro(e);return a.jsx(WR,{...r,...n})},"DropdownMenuPortal"),aD="DropdownMenuContent",lD=u.forwardRef(no(function(e,n){const{__scopeDropdownMenu:r,...s}=e,o=Xm(aD,r),i=ro(r),c=u.useRef(!1);return a.jsx(HR,{id:o.contentId,"aria-labelledby":o.triggerId,...i,...s,ref:n,onCloseAutoFocus:Ne(e.onCloseAutoFocus,l=>{c.current||o.triggerRef.current?.focus(),c.current=!1,l.preventDefault()}),onInteractOutside:Ne(e.onInteractOutside,l=>{const d=l.detail.originalEvent,h=d.button===0&&d.ctrlKey===!0,f=d.button===2||h;(!o.modal||f)&&(c.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})},"DropdownMenuContent")),Gd=u.forwardRef(no(function(e,n){const{__scopeDropdownMenu:r,...s}=e,o=ro(r);return a.jsx(JR,{...o,...s,ref:n})},"DropdownMenuItem"));function Jd({kind:t,onEdit:e,onDelete:n,disabled:r=!1}){const{t:s}=Qe(),o=u.useRef(!1);return a.jsx("span",{className:"comment-actions-menu",onClick:i=>i.stopPropagation(),children:a.jsxs(sD,{modal:!1,children:[a.jsx(iD,{asChild:!0,children:a.jsx("button",{type:"button",disabled:r,className:"comment-actions-menu-trigger","aria-label":s(t==="comment"?"editor.commentActions":"editor.replyActions"),children:a.jsx(tb,{size:16,"aria-hidden":!0})})}),a.jsx(cD,{children:a.jsxs(lD,{className:"comment-actions-menu-content",align:"end",sideOffset:4,collisionPadding:8,onCloseAutoFocus:i=>{o.current&&i.preventDefault(),o.current=!1},children:[a.jsxs(Gd,{onSelect:()=>{o.current=!0,e()},children:[a.jsx(nb,{size:13,"aria-hidden":!0}),s(t==="comment"?"editor.editComment":"editor.editReply")]}),a.jsxs(Gd,{className:"danger-text",onSelect:()=>{o.current=!0,n()},children:[a.jsx(dr,{size:13,"aria-hidden":!0}),s(t==="comment"?"editor.deleteComment":"editor.deleteReply")]})]})})]})})}function uD(t,e){const n=t.slice(0,e),r=/(^|[^\p{L}\p{N}_.-])@([\p{L}\p{N}_.-]*)$/u.exec(n);return r?{start:e-r[2].length-1,end:e,query:r[2]}:null}function Zm({projectId:t,value:e,onChange:n,onKeyDown:r,onFocus:s,...o}){const{t:i}=Qe(),c=u.useRef(null),[l,d]=u.useState(null),[h,f]=u.useState(!1),[p,m]=u.useState(null),[g,y]=u.useState(0),C=u.useMemo(()=>{if(!p||!l)return[];const S=p.query.toLocaleLowerCase();return(S?l.filter(j=>j.username.toLocaleLowerCase().includes(S)||j.displayName.toLocaleLowerCase().includes(S)):l).slice(0,8)},[l,p]),v=!!(p&&C.length),D=async()=>{if(!(l||h)){f(!0);try{const S=await xe(`/api/projects/${t}/mention-candidates`);d(S.users)}catch{d([])}finally{f(!1)}}},b=(S,E)=>{const j=uD(S,E);m(j),y(0),j&&D()},w=S=>{if(!p)return;const E=`@${S.username} `,j=`${e.slice(0,p.start)}${E}${e.slice(p.end)}`,P=p.start+E.length;n(j),m(null),y(0),window.requestAnimationFrame(()=>{c.current?.focus(),c.current?.setSelectionRange(P,P)})},R=S=>{if(!S.nativeEvent.isComposing&&v){if(S.key==="ArrowDown"){S.preventDefault(),y(E=>(E+1)%C.length);return}if(S.key==="ArrowUp"){S.preventDefault(),y(E=>(E-1+C.length)%C.length);return}if(S.key==="Enter"&&!S.ctrlKey&&!S.metaKey&&!S.shiftKey){S.preventDefault(),w(C[g]??C[0]);return}if(S.key==="Escape"){m(null);return}}r?.(S)};return a.jsxs("span",{className:"mention-textarea",children:[a.jsx("textarea",{...o,ref:c,value:e,onFocus:S=>{s?.(S),b(e,S.currentTarget.selectionStart??e.length)},onClick:S=>b(e,S.currentTarget.selectionStart??e.length),onChange:S=>{const E=S.currentTarget.value;n(E),b(E,S.currentTarget.selectionStart??E.length)},onKeyDown:R}),v&&a.jsx("span",{className:"mention-menu",role:"listbox","aria-label":i("editor.mentionUsers"),children:C.map((S,E)=>a.jsxs("button",{type:"button",role:"option","aria-selected":E===g,className:E===g?"active":"",onMouseDown:j=>j.preventDefault(),onClick:()=>w(S),children:[a.jsx(Ts,{"aria-hidden":!0,size:13}),a.jsxs("span",{children:[a.jsx("strong",{children:S.displayName}),a.jsxs("small",{children:["(",S.username,")"]})]})]},S.id))})]})}function dD({projectId:t,value:e,onChange:n,onSubmit:r,onCancel:s,pending:o=!1,error:i="",label:c,editing:l=!1,disabled:d=!1,autoFocus:h=!0}){const{t:f}=Qe(),p=u.useId(),m=o||d,g=y=>{y?.preventDefault(),!(m||!e.trim())&&r()};return a.jsxs("form",{className:`comment-reply-form${l?" comment-edit-form":""}`,"aria-busy":o,onSubmit:y=>{g(y)},onClick:y=>y.stopPropagation(),children:[a.jsx(Zm,{projectId:t,autoFocus:h,rows:l?4:3,value:e,onChange:n,disabled:m,"aria-label":c,"aria-invalid":!!i,"aria-describedby":i?p:void 0,placeholder:l?void 0:f("editor.replyPlaceholder"),onKeyDown:y=>{!(y.ctrlKey||y.metaKey)||y.key!=="Enter"||y.nativeEvent.isComposing||(y.preventDefault(),y.stopPropagation(),g())}}),i&&a.jsx("p",{id:p,className:"comment-form-error",role:"alert",children:i}),a.jsxs("div",{children:[a.jsx("button",{type:"button",disabled:m,onClick:s,children:f("common.cancel")}),a.jsxs("button",{className:"primary",type:"submit",disabled:m||!e.trim(),children:[o?a.jsx(gt,{className:"spin","aria-hidden":!0,size:13}):l?a.jsx(jb,{"aria-hidden":!0,size:13}):a.jsx(_b,{"aria-hidden":!0,size:13}),f(o?l?"editor.commentSaving":"editor.commentSending":l?"editor.saveChanges":"editor.sendReply")]})]})]})}const Yd=2;function fD(t,e={}){const n=t.slice(0,Math.max(0,t.length-Yd)),r=!!(e.activeDraft||e.targetReplyId&&t.some(i=>i.id===e.targetReplyId)||n.some(i=>e.unreadReplyMentionIds?.has(i.id)||e.highlightReplyParticipants&&e.selectedParticipantIds?.has(i.authorId))),s=r||(e.expansion??!!e.current),o=s?0:n.length;return{replies:o?t.slice(-Yd):t,hiddenCount:o,expanded:s,canToggle:n.length>0&&!r}}function Xd(t){const e=/(^|\s)(@[\p{L}\p{N}_.-]+)/gu,n=[];let r=0;for(const s of t.matchAll(e)){const o=s.index??0,i=s[1],c=s[2],l=o+i.length;l>r&&n.push(t.slice(r,l)),n.push(a.jsx("span",{className:"comment-inline-mention",children:c},`${l}:${c}`)),r=l+c.length}return n.length?(r<t.length&&n.push(t.slice(r)),n):t}function hD({projectId:t,comment:e,draftStore:n,currentUserId:r,unreadCommentMentionId:s,unreadReplyMentionIds:o,highlightedComment:i,highlightedReplyId:c,currentComment:l,showFilePath:d,onMarkMentionRead:h,onFocus:f,onActivate:p,onToggle:m,onReply:g,onEdit:y,onDelete:C,onEditReply:v,onDeleteReply:D,selectedParticipantIds:b,highlightReplyParticipants:w,replyExpansion:R,onReplyExpansionChange:S}){const{t:E}=Qe(),[j,P]=u.useState(!1),$=u.useCallback(W=>n.subscribe(e.id,W),[n,e.id]),J=u.useCallback(()=>n.getThread(e.id),[n,e.id]),T=u.useSyncExternalStore($,J,J),V=T.reply,U=T["edit-comment"],B=u.useId(),z=fD(e.replies,{expansion:R,current:l,targetReplyId:c,unreadReplyMentionIds:o,selectedParticipantIds:b,highlightReplyParticipants:w,activeDraft:!!(V?.open||V?.pending||e.authorId===r&&U?.open||e.replies.some(W=>W.authorId===r&&T[`edit-reply:${W.id}`]?.open))}),re=n.isPending(e.id),[H,X]=u.useState(null),[Q,Z]=u.useState(!1),[ge,ye]=u.useState(null),Ce=(W,ee="")=>{p(),S(!0),X(W),n.open(e.id,W,ee)},_e=(W,ee,Ee)=>{const pe=T[W];return pe?.open?a.jsx(dD,{projectId:t,editing:W!=="reply",label:ee,value:pe.content,pending:pe.pending,error:pe.error,disabled:re||j,autoFocus:H===W,onChange:K=>n.change(e.id,W,K),onSubmit:()=>n.submit(e.id,W,Ee,E("editor.commentSubmitFailed")),onCancel:()=>n.discard(e.id,W)},W):null},A=e.authorUsername,q=W=>new Date(W).toLocaleString(Rs.resolvedLanguage),fe=async(W,ee)=>{ee.stopPropagation(),S(!0),await h(W)};return a.jsxs(a.Fragment,{children:[a.jsxs("article",{"data-comment-id":e.id,className:`comment-thread${e.resolved?" resolved":""}${e.orphaned?" orphaned":""}${i?" mention-target":""}${l?" review-current":""}`,onFocusCapture:p,onClick:()=>{window.getSelection()?.toString()||f()},children:[a.jsxs("header",{className:"comment-header",children:[a.jsxs("span",{className:`comment-author${b?.has(e.authorId)?" participant-match":""}`,children:[a.jsx("strong",{children:e.authorDisplayName??A??E("editor.deletedUser")}),A&&a.jsxs("small",{children:["@",A]})]}),a.jsxs("span",{className:"comment-header-actions",children:[a.jsxs("span",{className:"comment-times",children:[a.jsx("time",{dateTime:e.createdAt,title:new Date(e.createdAt).toISOString(),children:q(e.createdAt)}),e.editedAt&&a.jsx("small",{children:E("editor.editedAt",{time:q(e.editedAt)})})]}),e.authorId===r&&!U?.open&&a.jsx(Jd,{kind:"comment",disabled:re||j,onEdit:()=>Ce("edit-comment",e.content),onDelete:()=>Z(!0)})]})]}),a.jsx("div",{className:"comment-location",children:e.orphaned?E("editor.orphaned"):d?E("editor.commentLocation",{path:e.filePath,line:e.startLine}):E("editor.line",{line:e.startLine})}),e.selectedText&&a.jsx("blockquote",{className:"comment-selected-text",children:e.selectedText}),U?.open&&e.authorId===r?_e("edit-comment",E("editor.editComment"),y):a.jsx("p",{className:"comment-content",children:Xd(e.content)}),s&&a.jsxs("div",{className:"comment-mention",children:[a.jsxs("span",{children:[a.jsx(Ts,{"aria-hidden":!0,size:12}),E("editor.mentionedYou")]}),a.jsx("button",{type:"button",onClick:W=>{fe(s,W)},children:E("editor.markMentionRead")})]}),e.replies.length>0&&a.jsxs("div",{className:"comment-replies",children:[z.canToggle&&a.jsxs("button",{type:"button",className:"comment-replies-toggle","aria-expanded":z.expanded,"aria-controls":B,onClick:W=>{W.stopPropagation(),S(!z.expanded)},children:[z.expanded?a.jsx(ub,{size:13,"aria-hidden":!0}):a.jsx(qs,{size:13,"aria-hidden":!0}),z.expanded?E("editor.hideEarlierReplies"):E("editor.showEarlierReplies",{count:z.hiddenCount})]}),a.jsx("div",{className:"comment-replies-list",id:B,children:z.replies.map(W=>{const ee=o?.get(W.id),Ee=`edit-reply:${W.id}`,pe=T[Ee]?.open&&W.authorId===r;return a.jsxs("div",{"data-comment-reply-id":W.id,className:`comment-reply${c===W.id?" mention-target":""}`,children:[a.jsxs("header",{children:[a.jsxs("span",{className:`comment-author${w&&b?.has(W.authorId)?" participant-match":""}`,children:[a.jsx("strong",{children:W.authorDisplayName??W.authorUsername??E("editor.deletedUser")}),W.authorUsername&&a.jsxs("small",{children:["@",W.authorUsername]})]}),a.jsxs("span",{className:"comment-header-actions",children:[a.jsxs("span",{className:"comment-times",children:[a.jsx("time",{dateTime:W.createdAt,title:new Date(W.createdAt).toISOString(),children:q(W.createdAt)}),W.editedAt&&a.jsx("small",{children:E("editor.editedAt",{time:q(W.editedAt)})})]}),W.authorId===r&&!pe&&a.jsx(Jd,{kind:"reply",disabled:re||j,onEdit:()=>Ce(Ee,W.content),onDelete:()=>ye(W.id)})]})]}),pe?_e(Ee,E("editor.editReply"),K=>v(W.id,K)):a.jsx("p",{className:"comment-content",children:Xd(W.content)}),ee&&a.jsxs("div",{className:"comment-mention",children:[a.jsxs("span",{children:[a.jsx(Ts,{"aria-hidden":!0,size:12}),E("editor.mentionedYou")]}),a.jsx("button",{type:"button",onClick:K=>{fe(ee,K)},children:E("editor.markMentionRead")})]})]},W.id)})})]}),e.resolved&&e.resolvedAt&&a.jsxs("div",{className:"comment-resolution",children:[a.jsx(Ic,{size:12,"aria-hidden":!0}),a.jsxs("span",{children:[a.jsx(Bw,{i18nKey:"editor.resolvedBy",values:{user:e.resolvedByDisplayName??e.resolvedByUsername??E("editor.deletedUser")},components:{user:a.jsx("strong",{className:"comment-resolution-user"})}}),e.resolvedByUsername&&a.jsxs("small",{className:"comment-resolution-user",children:[" @",e.resolvedByUsername]})," · ",a.jsx("time",{dateTime:e.resolvedAt,children:q(e.resolvedAt)})]})]}),a.jsxs("div",{className:"comment-actions",children:[a.jsxs("button",{className:"resolve",disabled:j||re,"aria-busy":j,onClick:W=>{W.stopPropagation(),!j&&(P(!0),m().finally(()=>P(!1)))},children:[e.resolved?a.jsx(Db,{size:13}):a.jsx(Ic,{size:13}),e.resolved?E("editor.reopen"):E("editor.resolve")]}),a.jsxs("button",{className:"reply-action",disabled:re||j,onClick:W=>{W.stopPropagation(),V?.open?n.hide(e.id,"reply"):Ce("reply")},children:[a.jsx(Rb,{size:13}),E(V?.content&&!V.open?"editor.resumeReply":"editor.reply")]})]}),_e("reply",E("editor.reply"),g)]}),a.jsx(_s,{open:Q,title:E("editor.deleteCommentTitle"),description:E("editor.deleteCommentDescription",{count:e.replies.length}),confirmLabel:E("common.delete"),danger:!0,onCancel:()=>Z(!1),onConfirm:()=>{C().then(W=>{W&&Z(!1)})}}),a.jsx(_s,{open:!!ge,title:E("editor.deleteReplyTitle"),description:E("editor.deleteReplyDescription"),confirmLabel:E("common.delete"),danger:!0,onCancel:()=>ye(null),onConfirm:()=>{ge&&D(ge).then(W=>{W&&ye(null)})}})]})}function pD({open:t,onOpenChange:e,project:n,projectId:r}){const{t:s}=Qe(),[o,i]=u.useState([]),[c,l]=u.useState([]),[d,h]=u.useState(""),[f,p]=u.useState("read"),[m,g]=u.useState(null),[y,C]=u.useState(""),v=n.permission==="owner",D=async()=>{try{const[E,j]=await Promise.all([xe(`/api/projects/${r}/members`),xe("/api/users")]);i(E.members),l(j.users.filter(P=>P.id!==n.ownerId))}catch(E){C(Se(E))}};u.useEffect(()=>{t&&D()},[t,r]);const b=async()=>{if(d)try{await xe(`/api/projects/${r}/members/${d}`,{method:"PUT",body:JSON.stringify({permission:f})}),h(""),p("read"),await D()}catch(E){C(Se(E))}},w=async(E,j)=>{try{await xe(`/api/projects/${r}/members/${E.id}`,{method:"PUT",body:JSON.stringify({permission:j})}),await D()}catch(P){C(Se(P))}},R=async()=>{if(m)try{await xe(`/api/projects/${r}/members/${m.id}`,{method:"DELETE"}),g(null),await D()}catch(E){C(Se(E))}},S=c.filter(E=>!o.some(j=>j.id===E.id));return a.jsxs(a.Fragment,{children:[a.jsx(Ln,{open:t,wide:!0,title:s("projectSettings.share"),description:s("projectSettings.shareDescription"),onOpenChange:e,footer:a.jsx("button",{onClick:()=>e(!1),children:s("common.close")}),children:a.jsxs("div",{className:"share-dialog",children:[y&&a.jsx("p",{className:"error",children:y}),a.jsxs("div",{className:"share-owner",children:[a.jsx(Mo,{size:17}),a.jsxs("span",{children:[a.jsx("small",{children:s("projects.owner")}),a.jsx("strong",{children:n.ownerDisplayName??n.ownerUsername})]})]}),v&&a.jsxs("div",{className:"share-add",children:[a.jsxs("label",{className:"form-field",children:[s("common.user"),a.jsxs("select",{value:d,onChange:E=>h(E.target.value),children:[a.jsx("option",{value:"",children:s("projectSettings.chooseUser")}),S.map(E=>a.jsx("option",{value:E.id,children:E.displayName??E.username},E.id))]})]}),a.jsxs("label",{className:"form-field",children:[s("common.permission"),a.jsxs("select",{value:f,onChange:E=>p(E.target.value),children:[a.jsx("option",{value:"read",children:s("common.readOnly")}),a.jsx("option",{value:"edit",children:s("common.readWrite")})]})]}),a.jsxs("button",{className:"primary icon-button",disabled:!d,onClick:()=>{b()},children:[a.jsx(ob,{size:15}),s("projectSettings.addMember")]})]}),a.jsxs("div",{className:"shared-members-heading",children:[a.jsx("strong",{children:s("projectSettings.members")}),a.jsx("span",{children:o.length})]}),a.jsxs("div",{className:"shared-members",children:[o.map(E=>a.jsxs("div",{className:"shared-member",children:[a.jsxs("span",{className:"member-identity",children:[a.jsx("span",{className:"member-avatar",children:(E.displayName??E.username).slice(0,1).toLocaleUpperCase()}),a.jsxs("span",{children:[a.jsx("strong",{children:E.displayName??E.username}),a.jsxs("small",{children:["@",E.username]})]})]}),a.jsxs("span",{className:"member-controls",children:[a.jsxs("select",{"aria-label":s("common.permission"),disabled:!v,value:E.permission,onChange:j=>{w(E,j.target.value)},children:[a.jsx("option",{value:"read",children:s("common.readOnly")}),a.jsx("option",{value:"edit",children:s("common.readWrite")})]}),v&&a.jsx("button",{className:"icon-only danger-text",title:s("common.remove"),"aria-label":s("common.remove"),onClick:()=>g(E),children:a.jsx(dr,{size:15})})]})]},E.id)),o.length===0&&a.jsxs("div",{className:"share-empty",children:[a.jsx(Mo,{size:24}),a.jsx("span",{children:s("projectSettings.noMembers")})]})]})]})}),a.jsx(_s,{open:!!m,title:s("projectSettings.removeTitle"),description:s("projectSettings.removeDescription",{username:m?.username??""}),confirmLabel:s("common.remove"),danger:!0,onCancel:()=>g(null),onConfirm:()=>{R()}})]})}const mD=u.lazy(()=>$t(()=>import("./CitationLibraryDialog-Cf_bbSq3.js"),__vite__mapDeps([12,2,1,3,13,5,14,4,6,15]),import.meta.url).then(t=>({default:t.CitationLibraryDialog}))),gD=u.lazy(()=>$t(()=>import("./GitDialog-BcqqWKr-.js"),__vite__mapDeps([16,2,1,3,5,17,18,19,14,20,4,6,7,8]),import.meta.url).then(t=>({default:t.GitDialog}))),yD=u.lazy(()=>$t(()=>import("./HistoryDialog-IurkSJuU.js"),__vite__mapDeps([21,2,1,3,22,23,5,19,14,20,4,6,7,8]),import.meta.url).then(t=>({default:t.HistoryDialog}))),wD=u.lazy(()=>$t(()=>import("./SelectionHistoryDialog-DiRKiMEt.js"),__vite__mapDeps([24,2,1,3,22,4,5,6,7,8]),import.meta.url).then(t=>({default:t.SelectionHistoryDialog}))),bD=u.lazy(()=>$t(()=>import("./ProjectNavigationDialogs-CozcEa2v.js"),__vite__mapDeps([25,2,1,3,6,5,4]),import.meta.url).then(t=>({default:t.ProjectSearchDialog}))),xD=u.lazy(()=>$t(()=>import("./ProjectNavigationDialogs-CozcEa2v.js"),__vite__mapDeps([25,2,1,3,6,5,4]),import.meta.url).then(t=>({default:t.QuickOpenDialog})));function vD({user:t,project:e,projectId:n,activeFile:r,content:s,maxCitationBibtexBytes:o,files:i,directoryEntries:c,readOnly:l,workspaceLayout:d,changeWorkspaceLayout:h,resourcePreview:f,resourcePreviewLoading:p,setResourcePreview:m,setResourcePreviewLoading:g,uploadConflict:y,setUploadConflict:C,dismissUploadFeedback:v,uploadFiles:D,cleanMode:b,setCleanMode:w,cleanCompile:R,newFileOpen:S,setNewFileOpen:E,newFilePath:j,setNewFilePath:P,newFolderOpen:$,setNewFolderOpen:J,newFolderName:T,setNewFolderName:V,selectedFolder:U,fileDialogError:B,setFileDialogError:z,createFile:re,createFolder:H,moveEntry:X,setMoveEntry:Q,moveName:Z,setMoveName:ge,moveDestination:ye,setMoveDestination:Ce,movePath:_e,deleteEntry:A,setDeleteEntry:q,deleteActiveSessions:fe,removePath:W,commentOpen:ee,closeComment:Ee,commentSelection:pe,commentText:K,setCommentText:ae,commentSubmitting:L,commentError:Re,addComment:Fe,cancelComment:Te,commentDraftRestored:Ue,commentDraftCanRetarget:de,useCurrentCommentSelection:ve,shareOpen:We,setShareOpen:Me,citationLibraryOpen:ke,setCitationLibraryOpen:O,insertCitationAtCursor:Pe,quickOpen:Je,setQuickOpen:it,projectSearchOpen:we,setProjectSearchOpen:Y,openFile:se,jumpToSource:De,selectionHistoryTarget:ze,closeSelectionHistory:G,historyOpen:le,setHistoryOpen:Oe,gitOpen:ce,setGitOpen:_t,save:te,permissionDowngrade:_,permissionDowngradeBusy:M,dismissPermissionDowngrade:oe,discardPermissionDraft:yt}){const{t:I}=Qe();return a.jsxs(a.Fragment,{children:[_&&a.jsx(Ln,{open:!0,title:I("editor.collaboration.permissionDowngradeTitle"),description:_.localDraftReady&&_.otherTabDraft?I("editor.collaboration.permissionDowngradeMultipleDrafts"):_.otherTabDraft?I("editor.collaboration.permissionDowngradeOtherTab"):_.localDraftReady?I("editor.collaboration.permissionDowngradeDescription",{previous:I("common.readWrite")}):I("editor.collaboration.permissionDowngradeNoDraft"),onOpenChange:ne=>{!ne&&!M&&oe()},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",disabled:M,onClick:oe,children:_.localDraftReady?I("editor.collaboration.permissionDowngradeKeep"):I("common.close")}),!_.otherTabDraft&&a.jsxs("button",{type:"button",className:"danger",disabled:M,onClick:()=>{yt()},children:[M?a.jsx(gt,{className:"spin",size:14}):_.localDraftReady?a.jsx(dr,{size:14}):a.jsx(ib,{size:14}),_.localDraftReady?I("editor.collaboration.permissionDowngradeDiscard"):I("editor.collaboration.permissionDowngradeReload")]})]}),children:a.jsx("div",{})}),a.jsxs(Ln,{open:!!f,extraWide:f?.kind==="image"||f?.kind==="pdf"||f?.kind==="text",title:f?.path??"",description:f?.kind==="large"?I("editor.resourceTooLarge",{size:SD(f.size),limit:`${na/1024/1024} MB`}):I(`editor.resourcePreview.${f?.kind??"text"}`),onOpenChange:ne=>{ne||(m(null),g(!1))},footer:f&&a.jsxs("a",{className:"primary resource-download",href:`${f.url}&download=1`,download:!0,children:[a.jsx(Fo,{size:14}),I("editor.downloadResource")]}),children:[f?.kind==="large"&&a.jsxs("div",{className:"resource-preview-message",children:[a.jsx(Mc,{size:34}),a.jsx("strong",{children:I("editor.resourceTooLargeTitle")}),a.jsx("span",{children:I("editor.resourceTooLargeDescription")})]}),f?.kind==="unsupported"&&a.jsxs("div",{className:"resource-preview-message",children:[a.jsx(Mc,{size:34}),a.jsx("strong",{children:I("editor.resourceUnsupportedTitle")}),a.jsx("span",{children:I("editor.resourceUnsupportedDescription")})]}),f?.kind==="image"&&a.jsx("div",{className:"resource-image-wrap",children:a.jsx("img",{className:"resource-image",src:f.url,alt:f.path})}),f?.kind==="pdf"&&a.jsx("iframe",{className:"resource-pdf",src:f.url,title:f.path}),f?.kind==="text"&&(p?a.jsxs("div",{className:"resource-preview-message",children:[a.jsx(gt,{className:"spin",size:24}),a.jsx("span",{children:I("common.loading")})]}):a.jsx("pre",{className:"resource-text",children:f.content}))]}),a.jsx(_s,{open:!!y,title:I("editor.uploadOverwriteTitle"),description:I("editor.uploadOverwriteDescription",{files:y?.collisions.join(", ")??""}),confirmLabel:I("editor.uploadOverwrite"),danger:!0,onCancel:()=>{C(null),v()},onConfirm:()=>{const ne=y;C(null),ne&&D(ne.files,new Set(ne.collisions),ne.directory)}}),a.jsx(_s,{open:!!b,title:I(b==="cache"?"editor.cleanCacheConfirmTitle":"editor.cleanArtifactsConfirmTitle"),description:I(b==="cache"?"editor.cleanCacheConfirmDescription":"editor.cleanArtifactsConfirmDescription"),confirmLabel:I("editor.cleanConfirm"),danger:b==="artifacts",onCancel:()=>w(null),onConfirm:()=>{const ne=b;w(null),ne&&R(ne)}}),a.jsx(Ln,{open:S,title:I("editor.newFile"),description:I("editor.newFileDescription"),onOpenChange:ne=>{E(ne),ne||z("")},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{onClick:()=>E(!1),children:I("common.cancel")}),a.jsx("button",{className:"primary",onClick:()=>{re()},children:I("common.create")})]}),children:a.jsxs(a.Fragment,{children:[B&&a.jsx("p",{className:"error dialog-error",children:B}),a.jsxs("label",{className:"form-field",children:[I("editor.filePath"),a.jsx("input",{autoFocus:!0,value:j,onChange:ne=>P(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&!ne.nativeEvent.isComposing&&(ne.preventDefault(),re())}})]})]})}),a.jsx(Ln,{open:$,title:I("editor.newFolder"),description:I("editor.folderDestination",{folder:U||I("editor.projectRoot")}),onOpenChange:ne=>{J(ne),ne||z("")},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{onClick:()=>J(!1),children:I("common.cancel")}),a.jsx("button",{className:"primary",onClick:()=>{H()},children:I("common.create")})]}),children:a.jsxs(a.Fragment,{children:[B&&a.jsx("p",{className:"error dialog-error",children:B}),a.jsxs("label",{className:"form-field",children:[I("editor.folderName"),a.jsx("input",{autoFocus:!0,value:T,onChange:ne=>V(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&H()}})]})]})}),a.jsx(Ln,{open:!!X,title:I("editor.moveTitle",{name:X?.path.split("/").at(-1)??""}),description:I("editor.moveDescription"),onOpenChange:ne=>{ne||(Q(null),ge(""),z(""))},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{onClick:()=>Q(null),children:I("common.cancel")}),a.jsx("button",{className:"primary",disabled:!Z.trim(),onClick:()=>{_e()},children:I("editor.moveApply")})]}),children:a.jsxs(a.Fragment,{children:[B&&a.jsx("p",{className:"error dialog-error",children:B}),a.jsxs("label",{className:"form-field",children:[I("editor.pathName"),a.jsx("input",{autoFocus:!0,value:Z,onChange:ne=>ge(ne.target.value),onKeyDown:ne=>{ne.key==="Enter"&&_e()}})]}),a.jsxs("label",{className:"form-field",children:[I("editor.destinationFolder"),a.jsxs("select",{value:ye,onChange:ne=>Ce(ne.target.value),children:[a.jsx("option",{value:"",children:I("editor.projectRoot")}),c.filter(ne=>X?.type!=="directory"||ne.path!==X.path&&!ne.path.startsWith(`${X.path}/`)).map(ne=>a.jsx("option",{value:ne.path,children:ne.path},ne.path))]})]})]})}),a.jsx(Ln,{open:!!A,title:I("editor.deletePathTitle",{name:A?.path.split("/").at(-1)??""}),description:fe.length?I("editor.deletePathActiveDescription",{path:A?.path??"",users:[...new Set(fe.map(ne=>ne.name))].join(", ")}):I("editor.deletePathDescription",{path:A?.path??""}),onOpenChange:ne=>{ne||(q(null),z(""))},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{onClick:()=>q(null),children:I("common.cancel")}),a.jsx("button",{className:"danger",onClick:()=>{W()},children:I("common.delete")})]}),children:a.jsxs(a.Fragment,{children:[B&&a.jsx("p",{className:"error dialog-error",children:B}),fe.length>0&&a.jsxs("p",{className:"warning",children:[a.jsx(Gt,{size:15}),I("editor.deletePathWillClose")]})]})}),a.jsxs(Ln,{open:ee,draggable:!0,title:I("editor.addComment"),description:pe.selectedText?I("editor.commentDescription",{count:pe.endOffset-pe.startOffset}):I("editor.pointComment"),onOpenChange:ne=>{ne||Ee()},footer:a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",disabled:L,onClick:Te,children:I("common.cancel")}),a.jsxs("button",{type:"button",className:"primary","aria-busy":L,disabled:L||!K.trim(),onClick:()=>{Fe()},children:[L&&a.jsx(gt,{className:"spin",size:14}),I(L?"editor.commentSending":"editor.addComment")]})]}),children:[Re&&a.jsx("p",{className:"error dialog-error",children:Re}),Ue&&a.jsxs("p",{className:"comment-draft-restored",children:[a.jsx("span",{children:I("editor.commentDraftRestored")}),de&&a.jsx("button",{type:"button",disabled:L,onClick:ve,children:I("editor.commentDraftUseSelection")})]}),a.jsxs("label",{className:"form-field",children:[I("editor.commentContent"),a.jsx(Zm,{projectId:n,autoFocus:!0,rows:5,disabled:L,value:K,placeholder:I("editor.commentPlaceholder"),onChange:ae,onKeyDown:ne=>{(ne.ctrlKey||ne.metaKey)&&ne.key==="Enter"&&!ne.nativeEvent.isComposing&&(ne.preventDefault(),ne.stopPropagation(),Fe())}})]}),pe.selectedText&&a.jsx("blockquote",{className:"selection-preview",children:pe.selectedText})]}),a.jsx(pD,{open:We,onOpenChange:Me,project:e,projectId:n}),ke&&a.jsx(cf,{title:I("citationLibrary.title"),onClose:()=>O(!1),children:a.jsx(mD,{open:!0,onOpenChange:O,currentFile:r,currentSource:s,readOnly:l,currentUserId:t.id,maxBibtexBytes:o,onInsert:Pe})}),Je&&a.jsx(u.Suspense,{fallback:null,children:a.jsx(xD,{open:!0,files:i,onOpenChange:it,onOpenFile:ne=>{const Et=i.find(Tt=>Tt.path===ne);Et&&se(Et)}})}),we&&a.jsx(u.Suspense,{fallback:null,children:a.jsx(bD,{open:!0,project:e,onOpenChange:Y,onJump:(ne,Et,Tt)=>{d==="pdf-only"&&h("editor-pdf"),De(ne,Et,Tt)}})}),ze&&a.jsx(u.Suspense,{fallback:null,children:a.jsx(wD,{open:!0,onOpenChange:ne=>{ne||G()},project:e,filePath:ze.filePath,selection:ze.selection,currentSource:ze.source})}),le&&a.jsx(u.Suspense,{fallback:null,children:a.jsx(yD,{open:!0,onOpenChange:Oe,project:e,onBeforeMutation:e.permission==="read"?async()=>!0:te})}),e.ownerId===t.id&&ce&&a.jsx(u.Suspense,{fallback:null,children:a.jsx(gD,{open:!0,onOpenChange:_t,project:e,onBeforeMutation:te})})]})}function SD(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(1)} MB`}var CD=Object.defineProperty,Ht=(t,e)=>CD(t,"name",{value:e,configurable:!0});function Pl(t){const e=u.forwardRef((n,r)=>{let{children:s,...o}=n,i=null,c=!1;const l=[];va(s)&&typeof Do=="function"&&(s=Do(s._payload)),u.Children.forEach(s,p=>{if(ng(p)){c=!0;const m=p;let g="child"in m.props?m.props.child:m.props.children;va(g)&&typeof Do=="function"&&(g=Do(g._payload)),i=kD(m,g),l.push(i?.props?.children)}else l.push(p)}),i?i=u.cloneElement(i,void 0,l):!c&&u.Children.count(s)===1&&u.isValidElement(s)&&(i=s);const d=i?tg(i):void 0,h=He(r,d);if(!i){if(s||s===0)throw new Error(c?jD(t):DD(t));return s}const f=eg(o,i.props??{});return i.type!==u.Fragment&&(f.ref=r?h:d),u.cloneElement(i,f)});return e.displayName=`${t}.Slot`,e}Ht(Pl,"createSlot");var Qm=Symbol.for("radix.slottable");function ED(t){const e=Ht(n=>"child"in n?n.children(n.child):n.children,"Slottable");return e.displayName=`${t}.Slottable`,e.__radixId=Qm,e}Ht(ED,"createSlottable");var kD=Ht((t,e)=>{if("child"in t.props){const n=t.props.child;return u.isValidElement(n)?u.cloneElement(n,void 0,t.props.children(n.props.children)):null}return u.isValidElement(e)?e:null},"getSlottableElementFromSlottable");function eg(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...c)=>{const l=o(...c);return s(...c),l}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"?n[r]=[s,o].filter(Boolean).join(" "):r==="aria-describedby"&&(n[r]=sg(o,s))}return{...t,...n}}Ht(eg,"mergeProps");function tg(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}Ht(tg,"getElementRef");function ng(t){return u.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Qm}Ht(ng,"isSlottable");var RD=Symbol.for("react.lazy");function va(t){return t!=null&&typeof t=="object"&&"$$typeof"in t&&t.$$typeof===RD&&"_payload"in t&&rg(t._payload)}Ht(va,"isLazyComponent");function rg(t){return typeof t=="object"&&t!==null&&"then"in t}Ht(rg,"isPromiseLike");function sg(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}Ht(sg,"concatAriaDescribedby");var DD=Ht(t=>`${t} failed to slot onto its children. Expected a single React element child or \`Slottable\`.`,"createSlotError"),jD=Ht(t=>`${t} failed to slot onto its \`Slottable\`. Expected \`Slottable\` to receive a single React element child.`,"createSlottableError"),Do=br[" use ".trim().toString()],_D=Object.defineProperty,TD=(t,e)=>_D(t,"name",{value:e,configurable:!0}),PD=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],so=PD.reduce((t,e)=>{const n=Pl(`Primitive.${e}`),r=u.forwardRef((s,o)=>{const{asChild:i,...c}=s,l=i?n:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(l,{...c,ref:o})});return r.displayName=`Primitive.${e}`,{...t,[e]:r}},{});function og(t,e){t&&Kn.flushSync(()=>t.dispatchEvent(e))}TD(og,"dispatchDiscreteCustomEvent");var AD=Object.defineProperty,ut=(t,e)=>AD(t,"name",{value:e,configurable:!0}),Sa="dismissableLayer.update",OD="dismissableLayer.pointerDownOutside",LD="dismissableLayer.focusOutside",Zd,ig=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set,dismissableSurfaces:new Set}),ND=u.forwardRef(ut(function(e,n){const{disableOutsidePointerEvents:r=!1,deferPointerDownOutside:s=!1,onEscapeKeyDown:o,onPointerDownOutside:i,onFocusOutside:c,onInteractOutside:l,onDismiss:d,...h}=e,f=u.useContext(ig),[p,m]=u.useState(null),g=p?.ownerDocument??globalThis?.document,[,y]=u.useState({}),C=He(n,m),v=Array.from(f.layers),[D]=[...f.layersWithOutsidePointerEventsDisabled].slice(-1),b=D?v.indexOf(D):-1,w=p?v.indexOf(p):-1,R=f.layersWithOutsidePointerEventsDisabled.size>0,S=w>=b,E=u.useRef(!1),j=cg(T=>{i?.(T),l?.(T),T.defaultPrevented||d?.()},{ownerDocument:g,deferPointerDownOutside:s,isDeferredPointerDownOutsideRef:E,dismissableSurfaces:f.dismissableSurfaces,shouldHandlePointerDownOutside:u.useCallback(T=>{if(!(T instanceof Node))return!1;const V=[...f.branches].some(U=>U.contains(T));return S&&!V},[f.branches,S])}),P=ag(T=>{if(s&&E.current)return;const V=T.target;[...f.branches].some(B=>B.contains(V))||(c?.(T),l?.(T),T.defaultPrevented||d?.())},g),$=p?w===v.length-1:!1,J=Ot(T=>{T.key==="Escape"&&(o?.(T),!T.defaultPrevented&&d&&(T.preventDefault(),d()))});return u.useEffect(()=>{if($)return g.addEventListener("keydown",J,{capture:!0}),()=>g.removeEventListener("keydown",J,{capture:!0})},[g,$,J]),u.useEffect(()=>{if(p)return r&&(f.layersWithOutsidePointerEventsDisabled.size===0&&(Zd=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),f.layersWithOutsidePointerEventsDisabled.add(p)),f.layers.add(p),Ca(),()=>{r&&(f.layersWithOutsidePointerEventsDisabled.delete(p),f.layersWithOutsidePointerEventsDisabled.size===0&&(g.body.style.pointerEvents=Zd))}},[p,g,r,f]),u.useEffect(()=>()=>{p&&(f.layers.delete(p),f.layersWithOutsidePointerEventsDisabled.delete(p),Ca())},[p,f]),u.useEffect(()=>{const T=ut(()=>y({}),"handleUpdate");return document.addEventListener(Sa,T),()=>document.removeEventListener(Sa,T)},[]),a.jsx(so.div,{...h,ref:C,style:{pointerEvents:R?S?"auto":"none":void 0,...e.style},onFocusCapture:Ne(e.onFocusCapture,P.onFocusCapture),onBlurCapture:Ne(e.onBlurCapture,P.onBlurCapture),onPointerDownCapture:Ne(e.onPointerDownCapture,j.onPointerDownCapture)})},"DismissableLayer"));function MD(){const t=u.useContext(ig),[e,n]=u.useState(null);return u.useEffect(()=>{if(e)return t.dismissableSurfaces.add(e),()=>{t.dismissableSurfaces.delete(e)}},[e,t.dismissableSurfaces]),n}ut(MD,"useDismissableLayerSurface");var FD=ut(()=>!0,"IS_TRUE");function cg(t,e){const{ownerDocument:n=globalThis?.document,deferPointerDownOutside:r=!1,isDeferredPointerDownOutsideRef:s,dismissableSurfaces:o,shouldHandlePointerDownOutside:i=FD}=e,c=Ot(t),l=u.useRef(!1),d=u.useRef(!1),h=u.useRef(new Map),f=u.useRef(()=>{});return u.useEffect(()=>{function p(){d.current=!1,s.current=!1,h.current.clear()}ut(p,"resetOutsideInteraction");function m(){return Array.from(h.current.values()).some(Boolean)}ut(m,"isOutsideInteractionIntercepted");function g(b){if(!d.current)return;const w=b.target;w instanceof Node&&[...o].some(S=>S.contains(w))||h.current.set(b.type,!0),b.type==="click"&&window.setTimeout(()=>{d.current&&f.current()},0)}ut(g,"handleInteractionCapture");function y(b){d.current&&h.current.set(b.type,!1)}ut(y,"handleInteractionBubble");const C=ut(b=>{if(b.target&&!l.current){let w=function(){n.removeEventListener("click",f.current);const S=m();p(),S||Al(OD,c,R,{discrete:!0})};if(ut(w,"handleAndDispatchPointerDownOutsideEvent"),!i(b.target)){n.removeEventListener("click",f.current),p(),l.current=!1;return}const R={originalEvent:b};d.current=!0,s.current=r&&b.button===0,h.current.clear(),!r||b.button!==0?w():(n.removeEventListener("click",f.current),f.current=w,n.addEventListener("click",f.current,{once:!0}))}else n.removeEventListener("click",f.current),p();l.current=!1},"handlePointerDown"),v=["pointerup","mousedown","mouseup","touchstart","touchend","click"];for(const b of v)n.addEventListener(b,g,!0),n.addEventListener(b,y);const D=window.setTimeout(()=>{n.addEventListener("pointerdown",C)},0);return()=>{window.clearTimeout(D),n.removeEventListener("pointerdown",C),n.removeEventListener("click",f.current);for(const b of v)n.removeEventListener(b,g,!0),n.removeEventListener(b,y)}},[n,c,r,s,o,i]),{onPointerDownCapture:ut(()=>l.current=!0,"onPointerDownCapture")}}ut(cg,"usePointerDownOutside");function ag(t,e=globalThis?.document){const n=Ot(t),r=u.useRef(!1);return u.useEffect(()=>{const s=ut(o=>{o.target&&!r.current&&Al(LD,n,{originalEvent:o},{discrete:!1})},"handleFocus");return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,n]),{onFocusCapture:ut(()=>r.current=!0,"onFocusCapture"),onBlurCapture:ut(()=>r.current=!1,"onBlurCapture")}}ut(ag,"useFocusOutside");function Ca(){const t=new CustomEvent(Sa);document.dispatchEvent(t)}ut(Ca,"dispatchUpdate");function Al(t,e,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?og(s,o):s.dispatchEvent(o)}ut(Al,"handleAndDispatchCustomEvent");var ID=Object.defineProperty,st=(t,e)=>ID(t,"name",{value:e,configurable:!0}),Lc="focusScope.autoFocusOnMount",Nc="focusScope.autoFocusOnUnmount",Qd={bubbles:!1,cancelable:!0},$D=u.forwardRef(st(function(e,n){const{loop:r=!1,trapped:s=!1,branches:o,onMountAutoFocus:i,onUnmountAutoFocus:c,...l}=e,[d,h]=u.useState(null),f=Ot(i),p=Ot(c),m=u.useRef(null),g=He(n,h),y=u.useRef(o);u.useEffect(()=>{y.current=o});const C=u.useCallback(b=>b?d?.contains(b)?!0:!!y.current?.some(w=>w.contains(b)):!1,[d]),v=u.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;u.useEffect(()=>{if(s){let b=function(E){if(v.paused||!d)return;const j=E.target;C(j)?m.current=j:yn(m.current,{select:!0})},w=function(E){if(v.paused||!d)return;const j=E.relatedTarget;j!==null&&(C(j)||yn(m.current,{select:!0}))},R=function(E){if(document.activeElement===document.body)for(const P of E)P.removedNodes.length>0&&yn(d)};st(b,"handleFocusIn"),st(w,"handleFocusOut"),st(R,"handleMutations"),document.addEventListener("focusin",b),document.addEventListener("focusout",w);const S=new MutationObserver(R);return d&&S.observe(d,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",w),S.disconnect()}}},[s,d,v.paused,C]),u.useEffect(()=>{if(d){ef.add(v);const b=document.activeElement;if(!d.contains(b)){const R=new CustomEvent(Lc,Qd);d.addEventListener(Lc,f),d.dispatchEvent(R),R.defaultPrevented||(hg(wg(Ol(d)),{select:!0}),document.activeElement===b&&yn(d))}return()=>{d.removeEventListener(Lc,f),setTimeout(()=>{const R=new CustomEvent(Nc,Qd);d.addEventListener(Nc,p),d.dispatchEvent(R),R.defaultPrevented||yn(b??document.body,{select:!0}),d.removeEventListener(Nc,p),ef.remove(v)},0)}}},[d,f,p,v]);const D=u.useCallback(b=>{if(!r&&!s||v.paused)return;const w=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,R=document.activeElement;if(w&&R){const S=b.currentTarget,[E,j]=pg(S);E&&j?!b.shiftKey&&R===j?(b.preventDefault(),r&&yn(E,{select:!0})):b.shiftKey&&R===E&&(b.preventDefault(),r&&yn(j,{select:!0})):R===S&&b.preventDefault()}},[r,s,v.paused]);return a.jsx(so.div,{tabIndex:-1,...l,ref:g,onKeyDown:D})},"FocusScope")),lg=u.createContext(null);function ug({registry:t,children:e}){return t?a.jsx(lg.Provider,{value:t,children:e}):e}st(ug,"FocusScopeBranchProvider");function dg(){const[t,e]=u.useState([]),n=u.useMemo(()=>({add:st(r=>e(s=>s.includes(r)?s:[...s,r]),"add"),remove:st(r=>e(s=>s.filter(o=>o!==r)),"remove")}),[]);return{nodes:t,registry:n}}st(dg,"useFocusScopeBranchRegistry");function fg(t){const e=u.useContext(lg);u.useEffect(()=>{if(!(!t||!e))return e.add(t),()=>e.remove(t)},[t,e])}st(fg,"useFocusScopeBranch");function hg(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(yn(r,{select:e}),document.activeElement!==n)return}st(hg,"focusFirst");function pg(t){const e=Ol(t),n=Ea(e,t),r=Ea(e.reverse(),t);return[n,r]}st(pg,"getTabbableEdges");function Ol(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:st(r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},"acceptNode")});for(;n.nextNode();)e.push(n.currentNode);return e}st(Ol,"getTabbableCandidates");function Ea(t,e){const n=typeof e.checkVisibility=="function"&&e.checkVisibility({checkVisibilityCSS:!0});for(const r of t)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):mg(r,{upTo:e})))return r}st(Ea,"findVisible");function mg(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}st(mg,"isHidden");function gg(t){return t instanceof HTMLInputElement&&"select"in t}st(gg,"isSelectableInput");function yn(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&gg(t)&&e&&t.select()}}st(yn,"focus");var ef=yg();function yg(){let t=[];return{add(e){const n=t[0];e!==n&&n?.pause(),t=ka(t,e),t.unshift(e)},remove(e){t=ka(t,e),t[0]?.resume()}}}st(yg,"createFocusScopesStack");function ka(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}st(ka,"arrayRemove");function wg(t){return t.filter(e=>e.tagName!=="A")}st(wg,"removeLinks");var UD=Object.defineProperty,zD=(t,e)=>UD(t,"name",{value:e,configurable:!0}),BD=u.forwardRef(zD(function(e,n){const{container:r,...s}=e,[o,i]=u.useState(!1);It(()=>i(!0),[]);const c=r||o&&globalThis?.document?.body;return c?Kn.createPortal(a.jsx(so.div,{...s,ref:n}),c):null},"Portal")),WD=Object.defineProperty,kn=(t,e)=>WD(t,"name",{value:e,configurable:!0});function bg(t,e){return u.useReducer((n,r)=>e[n][r]??n,t)}kn(bg,"useStateMachine");var xg=kn(t=>{const{present:e,children:n}=t,r=vg(e),s=typeof n=="function"?n({present:r.isPresent}):u.Children.only(n),o=Sg(r.ref,Cg(s));return typeof n=="function"||r.isPresent?u.cloneElement(s,{ref:o}):null},"Presence");function vg(t){const[e,n]=u.useState(),r=u.useRef(null),s=u.useRef(t),o=u.useRef("none"),i=u.useRef(void 0),c=t?"mounted":"unmounted",[l,d]=bg(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{l==="mounted"?(o.current=i.current??$r(r.current),i.current=void 0):o.current="none"},[l]),It(()=>{const h=r.current,f=s.current;if(f!==t){const m=o.current,g=$r(h);t?(i.current=g,d("MOUNT")):g==="none"||h?.display==="none"?d("UNMOUNT"):d(f&&m!==g?"ANIMATION_OUT":"UNMOUNT"),s.current=t}},[t,d]),It(()=>{if(e){let h;const f=e.ownerDocument.defaultView??window,p=kn(g=>{const C=$r(r.current).includes(CSS.escape(g.animationName));if(g.target===e&&C&&(d("ANIMATION_END"),!s.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",h=f.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},"handleAnimationEnd"),m=kn(g=>{g.target===e&&(o.current=$r(r.current))},"handleAnimationStart");return e.addEventListener("animationstart",m),e.addEventListener("animationcancel",p),e.addEventListener("animationend",p),()=>{f.clearTimeout(h),e.removeEventListener("animationstart",m),e.removeEventListener("animationcancel",p),e.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[e,d]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(h=>{if(h){const f=getComputedStyle(h);r.current=f,i.current=$r(f)}else r.current=null;n(h)},[])}}kn(vg,"usePresence");function Ra(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}kn(Ra,"setRef");function Sg(...t){const e=u.useRef(t);return e.current=t,u.useCallback(n=>{const r=e.current;let s=!1;const o=r.map(i=>{const c=Ra(i,n);return!s&&typeof c=="function"&&(s=!0),c});if(s)return()=>{for(let i=0;i<o.length;i++){const c=o[i];typeof c=="function"?c():Ra(r[i],null)}}},[])}kn(Sg,"useStableComposedRefs");function $r(t){return t?.animationName||"none"}kn($r,"getAnimationName");function Cg(t){let e=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}kn(Cg,"getElementRef");var VD=Object.defineProperty,un=(t,e)=>VD(t,"name",{value:e,configurable:!0}),Ll="Popover",[Eg,Uj]=wr(Ll,[Di]),Nl=Di(),[HD,Rr]=Eg(Ll),qD=un(t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=t,c=Nl(e),l=u.useRef(null),[d,h]=u.useState(!1),[f,p]=u.useState(0),[m,g]=u.useState(0),[y,C]=Da({prop:r,defaultProp:s??!1,onChange:o,caller:Ll});return a.jsx(dm,{...c,children:a.jsx(HD,{scope:e,contentId:zr(),titleId:zr(),descriptionId:zr(),titlePresent:f>0,descriptionPresent:m>0,setTitleCount:p,setDescriptionCount:g,triggerRef:l,open:y,onOpenChange:C,onOpenToggle:u.useCallback(()=>C(v=>!v),[C]),hasCustomAnchor:d,onCustomAnchorAdd:u.useCallback(()=>h(!0),[]),onCustomAnchorRemove:u.useCallback(()=>h(!1),[]),modal:i,children:n})})},"Popover"),KD="PopoverTrigger",GD=u.forwardRef(un(function(e,n){const{__scopePopover:r,...s}=e,o=Rr(KD,r),i=Nl(r),c=He(n,o.triggerRef),l=a.jsx(so.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.open?o.contentId:void 0,"data-state":Ml(o.open),...s,ref:c,onClick:Ne(e.onClick,o.onOpenToggle)});return o.hasCustomAnchor?l:a.jsx(fm,{asChild:!0,...i,children:l})},"PopoverTrigger")),kg="PopoverPortal",[JD,YD]=Eg(kg,{forceMount:void 0}),XD=un(t=>{const{__scopePopover:e,forceMount:n,children:r,container:s}=t,o=Rr(kg,e);return a.jsx(JD,{scope:e,forceMount:n,children:a.jsx(xg,{present:n||o.open,children:a.jsx(BD,{asChild:!0,container:s,children:r})})})},"PopoverPortal"),Hs="PopoverContent",ZD=u.forwardRef(un(function(e,n){const r=YD(Hs,e.__scopePopover),{forceMount:s=r.forceMount,...o}=e,i=Rr(Hs,e.__scopePopover);return a.jsx(xg,{present:s||i.open,children:i.modal?a.jsx(ej,{...o,ref:n}):a.jsx(tj,{...o,ref:n})})},"PopoverContent")),QD=Pl("PopoverContent.RemoveScroll"),ej=u.forwardRef(un(function(e,n){const r=Rr(Hs,e.__scopePopover),s=u.useRef(null),o=He(n,s),i=u.useRef(!1),{nodes:c,registry:l}=dg();return u.useEffect(()=>{const d=s.current;if(d)return sf(d)},[]),a.jsx(af,{as:QD,allowPinchZoom:!0,shards:u.useMemo(()=>[s,...c.map(d=>({current:d}))],[s,c]),children:a.jsx(Rg,{...e,ref:o,branchNodes:c,branchRegistry:l,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Ne(e.onCloseAutoFocus,d=>{d.preventDefault(),i.current||r.triggerRef.current?.focus()}),onPointerDownOutside:Ne(e.onPointerDownOutside,d=>{const h=d.detail.originalEvent,f=h.button===0&&h.ctrlKey===!0,p=h.button===2||f;i.current=p},{checkForDefaultPrevented:!1}),onFocusOutside:Ne(e.onFocusOutside,d=>d.preventDefault(),{checkForDefaultPrevented:!1})})})},"PopoverContentModal")),tj=u.forwardRef(un(function(e,n){const r=Rr(Hs,e.__scopePopover),s=u.useRef(!1),o=u.useRef(!1);return a.jsx(Rg,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{e.onCloseAutoFocus?.(i),i.defaultPrevented||(s.current||r.triggerRef.current?.focus(),i.preventDefault()),s.current=!1,o.current=!1},onInteractOutside:i=>{e.onInteractOutside?.(i),i.defaultPrevented||(s.current=!0,i.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=i.target;r.triggerRef.current?.contains(c)&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&o.current&&i.preventDefault()}})},"PopoverContentNonModal")),Rg=u.forwardRef(un(function(e,n){const{__scopePopover:r,trapFocus:s,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:c,onEscapeKeyDown:l,onPointerDownOutside:d,onFocusOutside:h,onInteractOutside:f,"aria-describedby":p,branchNodes:m,branchRegistry:g,...y}=e,C=Rr(Hs,r),v=Nl(r),[D,b]=u.useState(null),w=He(n,b);return fg(D),of(),a.jsx(ug,{registry:g,children:a.jsx($D,{asChild:!0,loop:!0,trapped:s,branches:m,onMountAutoFocus:o,onUnmountAutoFocus:i,children:a.jsx(ND,{asChild:!0,disableOutsidePointerEvents:c,onInteractOutside:f,onEscapeKeyDown:l,onPointerDownOutside:d,onFocusOutside:h,onDismiss:()=>C.onOpenChange(!1),deferPointerDownOutside:!0,children:a.jsx(pm,{"data-state":Ml(C.open),role:"dialog",id:C.contentId,"aria-labelledby":C.titlePresent?C.titleId:void 0,"aria-describedby":C.descriptionPresent?Dg(p,C.descriptionId):p,...v,...y,ref:w,style:{...y.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})})},"PopoverContentImpl")),nj=u.forwardRef(un(function(e,n){const{__scopePopover:r,...s}=e,o=Rr("PopoverTitle",r),{setTitleCount:i}=o;return It(()=>(i(c=>c+1),()=>i(c=>c-1)),[i]),a.jsx(so.h2,{id:o.titleId,...s,ref:n})},"PopoverTitle"));function Ml(t){return t?"open":"closed"}un(Ml,"getState");function Dg(...t){const e=new Set;for(const n of t)if(typeof n=="string")for(const r of String(n).trim().split(/\s+/))r&&e.add(r);return e.size>0?Array.from(e).join(" "):void 0}un(Dg,"concatAriaDescribedby");function rj({participants:t,selectedIds:e,topLevelOnly:n,onToggle:r,onClear:s,onTopLevelOnlyChange:o}){const{t:i}=Qe(),[c,l]=u.useState(!1),d=u.useRef(null),h=e.size>0,f=t.find(g=>e.has(g.authorId)),p=g=>g.authorDisplayName??g.authorUsername??i("editor.deletedUser"),m=h?f?e.size===1?p(f):i("editor.commentParticipantsSelected",{name:p(f),count:e.size-1}):i("editor.commentParticipantsCount",{count:e.size}):i("editor.commentParticipantsAll");return a.jsxs("div",{className:"comment-participant-filter",children:[a.jsxs("div",{className:`comment-participants-trigger-group${h?" active":""}`,children:[a.jsxs(qD,{open:c,onOpenChange:l,children:[a.jsx(GD,{asChild:!0,children:a.jsxs("button",{type:"button",className:"comment-participants-toggle","aria-label":`${i("editor.commentParticipants")}: ${m}`,children:[a.jsx(Mo,{size:13,"aria-hidden":!0}),a.jsx("span",{className:"comment-participants-summary",children:h&&f?p(f):m}),h&&f&&e.size>1&&a.jsxs("span",{className:"comment-participants-extra-count",children:["+",e.size-1]}),a.jsx(qs,{size:12,"aria-hidden":!0,className:c?"expanded":""})]})}),a.jsx(XD,{children:a.jsxs(ZD,{ref:d,className:"comment-participants-popover",side:"bottom",align:"end",sideOffset:6,collisionPadding:10,"aria-label":i("editor.commentParticipants"),onOpenAutoFocus:g=>{g.preventDefault();const y=d.current?.querySelector('input[type="checkbox"]:not(:disabled)');y?y.focus():d.current?.focus()},children:[a.jsxs("div",{className:"comment-participants-heading",children:[a.jsx(nj,{children:i("editor.commentParticipants")}),h&&a.jsx("button",{type:"button",onClick:s,children:i("editor.commentParticipantsClear")})]}),a.jsxs("div",{className:"comment-participants-list",children:[t.map(g=>{const y=p(g),C=e.has(g.authorId);return a.jsxs("label",{className:`comment-participant-option${C?" selected":""}`,children:[a.jsx("input",{type:"checkbox",checked:C,onChange:()=>r(g.authorId)}),a.jsx("span",{className:"comment-participant-avatar","aria-hidden":!0,children:Array.from(y.trim())[0]?.toLocaleUpperCase()??"?"}),a.jsxs("span",{className:"comment-participant-identity",children:[a.jsx("strong",{children:y}),g.authorUsername&&a.jsxs("small",{children:["@",g.authorUsername]})]})]},g.authorId??"deleted")}),t.length===0&&a.jsx("p",{className:"comment-participants-empty",children:i("editor.commentNoParticipants")})]}),a.jsxs("label",{className:"comment-participants-root-only",children:[a.jsx("input",{type:"checkbox",checked:n,disabled:!h,onChange:g=>o(g.target.checked)}),i("editor.commentTopLevelOnly")]})]})})]}),h&&a.jsx("button",{type:"button",className:"comment-participants-clear","aria-label":i("editor.commentParticipantsClear"),onClick:s,children:a.jsx($n,{size:12,"aria-hidden":!0})})]}),h&&n&&a.jsx("span",{className:"comment-participants-scope",children:i("editor.commentTopLevelOnly")})]})}const jg=280;function sj(t,e,n,r,s){const o=e.map(l=>({comment:l,exitAt:null})),i=new Set(e.map(l=>l.id)),c=new Map(n.map(l=>[l.id,l]));return t.forEach((l,d)=>{const h=c.get(l.comment.id);i.has(l.comment.id)||!h||Aa(h,r)||o.splice(Math.min(d,o.length),0,{comment:h,exitAt:l.exitAt??s+jg+50})}),o}function oj(t,e,n,r){const[s,o]=u.useState(()=>({contextKey:r,visible:t,comments:e,entries:t.map(c=>({comment:c,exitAt:null}))}));(s.contextKey!==r||s.visible!==t||s.comments!==e)&&o({contextKey:r,visible:t,comments:e,entries:s.contextKey!==r?t.map(c=>({comment:c,exitAt:null})):sj(s.entries,t,e,n,Date.now())});const i=u.useCallback(c=>{o(l=>({...l,entries:l.entries.filter(d=>d.comment.id!==c||d.exitAt===null)}))},[]);return u.useEffect(()=>{const c=s.entries.flatMap(d=>d.exitAt===null?[]:[d.exitAt]);if(!c.length)return;const l=window.setTimeout(()=>{const d=Date.now();o(h=>({...h,entries:h.entries.filter(f=>f.exitAt===null||f.exitAt>d)}))},Math.max(0,Math.min(...c)-Date.now()));return()=>window.clearTimeout(l)},[s.entries]),{entries:s.entries,finishExit:i}}const ij=u.lazy(()=>$t(()=>import("./ProjectSettings-BlthcpdA.js"),__vite__mapDeps([26,2,1,3,5,27,28,8,4,6,7]),import.meta.url).then(t=>({default:t.ProjectSettings})));function cj({sidePanel:t,onClose:e,project:n,projectId:r,site:s,files:o,currentUserId:i,comments:c,commentDraftStore:l,commentsLoading:d,commentsError:h,onRetryComments:f,unreadMentions:p,activeFile:m,singleCommentId:g,onShowAllComments:y,hasProjectCommentsScope:C,commentScope:v,onCommentScopeChange:D,focusedCommentId:b,commentFocusNonce:w,onMarkMentionRead:R,onMarkAllMentionsRead:S,onClearFocusComment:E,targetCommentId:j,targetReplyId:P,onFocusComment:$,onToggleComment:J,onReplyComment:T,onEditComment:V,onDeleteComment:U,onEditCommentReply:B,onDeleteCommentReply:z,dictionaryWords:re,onDictionaryChange:H,editorPreferences:X,onEditorPreferences:Q,spellCheckCount:Z,spellCheckUniqueCount:ge,spellCheckIndex:ye,onSpellCheckNavigate:Ce,onProject:_e}){const{t:A}=Qe(),q=!!g,[fe,W]=u.useState("unresolved"),[ee,Ee]=u.useState(!1),[pe,K]=u.useState("source"),[ae,L]=u.useState(()=>new Set),[Re,Fe]=u.useState(!0),[Te,Ue]=u.useState(()=>new Map),[de,ve]=u.useState(null),We=u.useRef(new Map(c.map(_=>[_.id,_.resolved]))),Me=u.useMemo(()=>ix(c),[c]),ke=u.useMemo(()=>{const _={activeFile:m,scope:v,unreadMentions:p,participantIds:ae,topLevelOnly:Re,unreadMentionsOnly:ee};return{unresolved:lc(c,{..._,filter:"unresolved"}).length,resolved:lc(c,{..._,filter:"resolved"}).length,mentions:lc(c,{..._,filter:fe,unreadMentionsOnly:!0}).length}},[m,v,c,p,ae,Re,fe,ee]),O=u.useMemo(()=>g?lx(c,g,m):ax(c,{activeFile:m,scope:v,filter:fe,unreadMentions:p,sort:pe,participantIds:ae,topLevelOnly:Re,unreadMentionsOnly:ee},[j,b]),[m,g,fe,v,c,b,j,p,pe,ae,Re,ee]),Pe=b&&O.some(_=>_.id===b)?b:j&&O.some(_=>_.id===j)?j:null,Je=q?O[0]?.id??null:de&&O.some(_=>_.id===de)?de:Pe;u.useEffect(()=>{ve(null)},[b,w,j,P,m,v]),u.useEffect(()=>{de&&!O.some(_=>_.id===de)&&ve(null)},[de,O]);const it=hx(O,Je),we=JSON.stringify([t,g,v,v==="file"?m:"",fe,pe,[...ae].sort(),Re,ee]),{entries:Y,finishExit:se}=oj(O,c,q?"unresolved":fe,we);u.useEffect(()=>{const _=c.some(M=>(M.id===b||M.id===j)&&We.current.has(M.id)&&We.current.get(M.id)!==M.resolved);We.current=new Map(c.map(M=>[M.id,M.resolved])),_&&E()},[c,b,j,E]),u.useEffect(()=>{!C&&v!=="file"&&(E(),D("file"))},[v,C,E,D]),u.useEffect(()=>{if(t!=="comments"||de)return;const _=j&&P?`.comments [data-comment-reply-id="${P}"]`:j?`.comments .comment-thread[data-comment-id="${j}"]`:Pe?`.comments .comment-thread[data-comment-id="${Pe}"]`:"";if(!_)return;const M=document.querySelector(_);if(!M)return;const oe=window.requestAnimationFrame(()=>M.scrollIntoView({block:j?"center":"nearest",behavior:"smooth"}));return()=>window.cancelAnimationFrame(oe)},[t,de,Pe,w,j,P,O]);const De=_=>{ve(null),$(_)},ze=_=>{const M=px(O,Je,_);M?De(M):E()},G=async _=>{const M=await R(_);if(!M||q||!ee)return M;const oe=p.find(I=>I.id===_)?.commentId;return oe&&(p.some(I=>I.id!==_&&I.commentId===oe)||(b===oe||j===oe)&&E()),M},le=async()=>{await S()&&ee&&E()},Oe=_=>{_!==v&&(ve(null),E(),D(_))},ce=_=>{_!==fe&&(ve(null),E(),W(_))},_t=()=>{ve(null),E()},te=_=>{_t(),ae.size===1&&ae.has(_)&&Fe(!0),L(M=>{const oe=new Set(M);return oe.has(_)?oe.delete(_):oe.add(_),oe})};return t?a.jsxs(a.Fragment,{children:[a.jsx(ja,{className:"resize-handle"}),a.jsx(ii,{id:"context",order:4,defaultSize:20,minSize:15,maxSize:38,children:a.jsxs("aside",{className:"context-panel",children:[t==="comments"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"drawer-title",children:[a.jsx("strong",{children:A(q?"editor.currentComment":"editor.sourceComments")}),a.jsxs("span",{className:"drawer-title-actions",children:[!q&&p.length>0&&a.jsxs("button",{className:"drawer-mention-read-all",type:"button",onClick:()=>{le()},title:A("editor.markAllMentionsRead"),children:[a.jsx(Ts,{"aria-hidden":!0,size:13}),a.jsx("span",{children:A("editor.markAllMentionsRead")})]}),a.jsx("button",{"aria-label":A("common.close"),onClick:e,children:a.jsx($n,{size:17})})]})]}),q?a.jsx("div",{className:"comment-current-controls",children:a.jsxs("button",{type:"button",onClick:y,children:[a.jsx(vb,{size:13,"aria-hidden":!0}),A("editor.viewAllComments")]})}):a.jsxs("div",{className:"comment-review-controls",children:[a.jsxs("div",{className:"comment-review-queue-row",children:[C&&a.jsxs("div",{className:"comment-review-group",role:"group","aria-label":A("editor.commentScope"),children:[a.jsx("button",{type:"button",className:v==="file"?"active":"","aria-pressed":v==="file",onClick:()=>Oe("file"),children:A("editor.commentScopeFile")}),a.jsx("button",{type:"button",className:v==="project"?"active":"","aria-pressed":v==="project",onClick:()=>Oe("project"),children:A("editor.commentScopeProject")})]}),a.jsxs("div",{className:"comment-review-group",role:"group","aria-label":A("editor.commentFilter"),children:[a.jsx("button",{type:"button",className:fe==="unresolved"?"active":"","aria-pressed":fe==="unresolved",onClick:()=>ce("unresolved"),children:A("editor.commentFilterUnresolved",{count:ke.unresolved})}),a.jsx("button",{type:"button",className:fe==="resolved"?"active":"","aria-pressed":fe==="resolved",onClick:()=>ce("resolved"),children:A("editor.commentFilterResolved",{count:ke.resolved})})]}),a.jsxs("div",{className:"comment-review-navigation",children:[a.jsx("button",{type:"button",disabled:it<=1,"aria-label":A("editor.commentPrevious"),title:A("editor.commentPrevious"),onClick:()=>ze(-1),children:a.jsx(rb,{size:14})}),a.jsx("output",{"aria-live":"polite",children:A("editor.commentPosition",{current:it,total:O.length})}),a.jsx("button",{type:"button",disabled:O.length===0||it>0&&it>=O.length,"aria-label":A("editor.commentNext"),title:A("editor.commentNext"),onClick:()=>ze(1),children:a.jsx(_a,{size:14})})]})]}),a.jsxs("div",{className:"comment-review-sort-row",children:[a.jsx(rj,{participants:Me,selectedIds:ae,topLevelOnly:Re,onToggle:te,onClear:()=>{_t(),L(new Set),Fe(!0)},onTopLevelOnlyChange:_=>{_t(),Fe(_)}},`${v}:${v==="file"?m:"project"}`),a.jsxs("button",{type:"button",className:`comment-unread-toggle${ee?" active":""}`,"aria-pressed":ee,"aria-label":A("editor.commentUnreadMentionsHint"),title:A("editor.commentUnreadMentionsHint"),onClick:()=>{_t(),Ee(_=>!_)},children:[a.jsx(Ts,{size:12,"aria-hidden":!0}),A("editor.commentUnreadMentionsOnly"),a.jsx("span",{children:ke.mentions})]}),a.jsxs("label",{className:"comment-review-sort","data-texlite-tooltip-always":!0,"data-tooltip":A(pe==="source"?"editor.commentSortSource":"editor.commentSortTime"),children:[a.jsx("span",{className:"sr-only",children:A("editor.commentSort")}),pe==="source"?a.jsx(ab,{size:12,"aria-hidden":!0}):a.jsx(lb,{size:12,"aria-hidden":!0}),a.jsxs("select",{value:pe,"aria-label":`${A("editor.commentSort")}: ${A(pe==="source"?"editor.commentSortSource":"editor.commentSortTime")}`,onChange:_=>K(_.target.value),children:[a.jsx("option",{value:"source",children:A("editor.commentSortSourceShort")}),a.jsx("option",{value:"time",children:A("editor.commentSortTimeShort")})]})]})]})]}),h&&a.jsxs("div",{className:"comment-review-error",role:"alert",children:[a.jsx("span",{children:h}),a.jsx("button",{type:"button",onClick:()=>{f()},children:A("common.retry")})]}),d&&a.jsx("div",{className:"comment-review-loading",role:"status",children:A("common.loading")}),a.jsxs("div",{className:"comments",children:[Y.map(({comment:_,exitAt:M})=>{const oe=p.find(I=>I.commentId===_.id&&!I.replyId)?.id,yt=new Map(p.filter(I=>I.commentId===_.id&&I.replyId).map(I=>[I.replyId,I.id]));return a.jsx("div",{className:`comment-thread-slot${M!==null?" is-exiting":""}`,inert:M!==null?!0:void 0,"aria-hidden":M!==null?!0:void 0,style:{"--comment-exit-duration":`${jg}ms`},onAnimationEnd:I=>{I.target===I.currentTarget&&M!==null&&se(_.id)},children:a.jsx("div",{className:"comment-thread-slot-content",children:a.jsx(hD,{projectId:r,comment:_,draftStore:l,currentUserId:i,unreadCommentMentionId:oe,unreadReplyMentionIds:yt,highlightedComment:j===_.id&&!P,highlightedReplyId:j===_.id?P:null,currentComment:Je===_.id,showFilePath:!q&&v==="project",replyExpansion:Te.get(_.id),onReplyExpansionChange:I=>{Ue(ne=>ne.get(_.id)===I?ne:new Map(ne).set(_.id,I))},selectedParticipantIds:q?void 0:ae,highlightReplyParticipants:!q&&!Re,onMarkMentionRead:G,onFocus:()=>De(_),onActivate:()=>ve(_.id),onToggle:()=>J(_),onReply:I=>T(_,I),onEdit:I=>V(_,I),onDelete:()=>U(_),onEditReply:(I,ne)=>B(_,I,ne),onDeleteReply:I=>z(_,I)})})},_.id)}),Y.length===0&&!d&&!h&&a.jsx("p",{className:"muted padded",role:"status",children:q?A(c.some(_=>_.id===g&&_.resolved)?"editor.currentCommentResolved":"editor.currentCommentUnavailable"):c.length?A("editor.commentNoMatches"):A("editor.noComments")})]})]}),t==="settings"&&a.jsx(zw,{onClose:e,children:a.jsx(ij,{onClose:e,project:n,projectId:r,site:s,files:o,dictionaryWords:re,onDictionaryChange:H,editorPreferences:X,onEditorPreferences:Q,spellCheckCount:Z,spellCheckUniqueCount:ge,spellCheckIndex:ye,onSpellCheckNavigate:Ce,onProject:_e},r)})]})})]}):null}function aj(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 lj(){let t={line:1,column:1,offset:0},e=t.line,n=null,r=null;const s=new Set,o=()=>{for(const l of s)l()},i=()=>{r=null;const l=n;n=null,!(l===null||l===e)&&(e=l,o())},c=l=>{n=l,r===null&&(r=aj(i))};return{getCursor:()=>t,getOutlineLine:()=>e,subscribe:l=>(s.add(l),()=>s.delete(l)),update:(l,d,h)=>{t.line===l&&t.column===d&&t.offset===h||(t={line:l,column:d,offset:h},(l!==e||r!==null)&&c(l))},reset:()=>{r?.(),r=null,n=null,t={line:1,column:1,offset:0},e!==1&&(e=1,o())},dispose:()=>{r?.(),r=null,n=null}}}function uj(t,e,n){return t.mainFile===e?t.items:!e||n.filePath!==e?[]:dj(n.content).map(r=>({...r,path:e}))}function dj(t){const e=[],n=/^\s*\\(part|chapter|section|subsection|subsubsection)\*?(?:\[[^\]]*\])?\{([^}]*)\}/,r={part:0,chapter:0,section:1,subsection:2,subsubsection:3};return t.split(`
|
|
20
|
-
`).forEach((s,o)=>{const i=s.match(n);i&&e.push({level:r[i[1]],title:i[2],line:o+1})}),e}const fj=u.lazy(()=>$t(()=>import("./WordCountDialog-BqlX2s36.js"),__vite__mapDeps([29,2,1,3,27,5,4,6,7,8]),import.meta.url).then(t=>({default:t.WordCountDialog})));let jo=null;function tf(){return jo||(jo=$t(()=>import("./citationLibrary-ZeQPCv5O.js"),[],import.meta.url).catch(t=>{throw jo=null,t})),jo}function mn(t){return t instanceof Error&&t.name==="AbortError"}const nf=300;function hj({site:t,user:e,projectId:n,preload:r,mentionId:s=null,onMentionTargeted:o,onMentionsRead:i,onBack:c}){const{t:l}=Qe(),d=u.useRef(n);d.current=n;const[h,f]=u.useState(null);u.useEffect(()=>(document.title=h?.name?`${t.siteName} | ${h.name}`:t.siteName,()=>{document.title=t.siteName}),[h?.name,t.siteName]);const[p,m]=u.useState(!1),[g,y]=u.useState([]),[C,v]=u.useState(null),[D,b]=u.useState({mainFile:"",items:[]}),[w,R]=u.useState(""),[S,E]=u.useState(""),[j,P]=u.useState(""),[$,J]=u.useState({filePath:"",content:""}),[T,V]=u.useState({path:"",hasIncludes:!1}),[U,B]=u.useState(""),[z,re]=u.useState(!1),[H,X]=u.useState("editor.saved"),[Q,Z]=u.useState(null),ge=u.useRef(Q);ge.current=Q;const ye=u.useRef(null);ye.current||(ye.current=lj());const Ce=ye.current,[_e,A]=u.useState("pdf"),[q,fe]=u.useState("log"),W=x=>{if(x==="pdf"){A("pdf");return}if(x==="diagnostics"){A("diagnostics");return}fe(x),A("diagnostics")},{workspaceLayout:ee,setWorkspaceLayout:Ee}=tE(e.id,n),[pe,K]=u.useState(""),[ae,L]=u.useState(""),[Re,Fe]=u.useState({selectedText:"",startOffset:0,endOffset:0}),Te=u.useRef({selectedText:"",startOffset:0,endOffset:0}),Ue=x=>{const k=Te.current;k.selectedText===x.selectedText&&k.startOffset===x.startOffset&&k.endOffset===x.endOffset||(Te.current=x,Fe(x))},[de,ve]=u.useState(null),[We,Me]=u.useState(null),[ke,O]=u.useState(null),[Pe,Je]=u.useState(null),[it,we]=u.useState(null),[Y,se]=u.useState(!1),[De,ze]=u.useState(!1),[G,le]=u.useState(!1),[Oe,ce]=u.useState(!1),[_t,te]=u.useState(null),[_,M]=u.useState(!1),[oe,yt]=u.useState(null),[I,ne]=u.useState(!1),[Et,Tt]=u.useState(!1),[Dr,wt]=u.useState(!1),[Pi,Ae]=u.useState("full"),[ms,_g]=u.useState(""),[Ai,Oi]=u.useState(!1),[Tg,Li]=u.useState(""),[Pg,Ni]=u.useState(null),[gs,jr]=u.useState(!1),[Yn,dn]=u.useState(null),[Ag,Mi]=u.useState(!1),[pt,Fl]=u.useState(()=>Lu(e.id,n));u.useEffect(()=>{const x=document.documentElement,k=pt.showTooltips?"on":"off";return x.setAttribute("data-texlite-tooltips",k),()=>{x.getAttribute("data-texlite-tooltips")===k&&x.removeAttribute("data-texlite-tooltips")}},[pt.showTooltips]);const[_r,oo]=u.useState([]),jn=u.useRef([]);jn.current=_r;const Og=u.useRef(null),io=u.useRef(null),co=u.useRef(0),Fi=u.useRef(0),Ie=u.useRef(""),bt=u.useRef(""),Il=u.useRef(()=>{}),Ii=u.useRef(ee),$l=u.useRef(0),Xn=u.useRef(null),Ul=u.useRef(null),Zn=u.useRef(null),Qn=u.useRef(null),Tr=u.useRef(null),Pr=u.useRef(null),Ar=u.useRef(null),_n=u.useRef(null),$i=u.useRef(null),fn=u.useRef(!1),Tn=u.useRef(null),zl=u.useRef(c),Ui=u.useRef(o),zi=u.useRef(i);zl.current=c,Ui.current=o,zi.current=i,Ie.current=w,bt.current=S,Ii.current=ee,u.useEffect(()=>{if(!ae)return;const x=window.setTimeout(()=>L(""),3e3);return()=>window.clearTimeout(x)},[ae]);const Lg=u.useCallback((x,k,N=0)=>{Ce.update(x,k,N)},[Ce]);u.useEffect(()=>()=>Ce.dispose(),[Ce]),u.useEffect(()=>()=>{_n.current?.abort(),_n.current=null},[]);const ao=x=>{const k=jn.current,N=x(k);N!==k&&(jn.current=N,oo(N))};u.useEffect(()=>{jn.current=[],oo([]),dn(null),te(null),Pr.current?.abort(),Pr.current=null,Ar.current?.abort(),Ar.current=null,_n.current?.abort(),_n.current=null,$i.current=null,O(null),Je(null),we(null),wt(!1),Oi(!1),Li(""),Ni(null)},[n]);const Bl=x=>{const k=jn.current,N=k.indexOf(x);if(N<0)return;const F=k.filter(ue=>ue!==x);if(jn.current=F,oo(F),Ie.current!==x)return;const me=F.length>0?F[Math.min(N,F.length-1)]:h?.mainFile??"";R(me)},{collaboration:qe,status:lo,synced:et,activeSessions:Wl,formatLeaseStates:Ng,compileState:er,setCompileState:Vl,filesEvent:tt,commentsRevision:Hl,historyWarning:Mg,dictionaryRevision:ql,chktexSettingsRevision:Kl,localDraftReady:Gl,permission:Bi,reconnect:Fg,protocolUpgradeRequired:Jl,permissionDowngrade:Ig,dismissPermissionDowngrade:$g,discardLocalDraft:Ug}=W0(n,e,S,h?.permission??"read",p,()=>X("editor.offlineDraft")),{unreadMentions:Yl,refresh:zg,markMentionRead:Bg,markAllMentionsRead:Wg}=gx(n,Hl,K),{pdfTarget:Vg,pdfViewport:Hg,sourceJump:qg,setPdfViewport:Kg,resetPdfViewport:Gg,clearPdfViewport:Xl,jumpToSource:Or,syncSourceToPdf:Wi,syncPdfToSource:Jg,syncVisiblePdfToSource:Yg}=eE({projectId:n,mainFile:S,activeFile:w,onOpenSourceFile:x=>Il.current(x),onError:K,onShowPdf:()=>W("pdf"),onShowEditor:()=>{Ii.current==="pdf-only"&&Ee("editor-pdf")}}),Zl=!!(h&&h.chktexEnabled&&w&&et&&Ed(w)),tr=Q0({active:Zl,projectId:n,activeFile:w,content:j}),Xg=!!(h&&w&&et&&nE(w)&&(pt.spellCheck||h.chktexEnabled&&Ed(w))),Pt=Z0({active:Xg,harperEnabled:pt.spellCheck,projectId:n,activeFile:w,content:j,dictionaryWords:g,additionalIssues:tr.issues,additionalIssuesReady:!Zl||tr.checked});u.useEffect(()=>{Fl(Lu(e.id,n))},[e.id,n]);const Vi=x=>{P(x)};u.useEffect(()=>{if(!w||U!==w){J(F=>F.filePath||F.content?{filePath:"",content:""}:F);return}const x=w,k=j,N=window.setTimeout(()=>{J(F=>F.filePath===x&&F.content===k?F:{filePath:x,content:k})},nf);return()=>window.clearTimeout(N)},[w,U,j]),u.useEffect(()=>{if(Ie.current=w,Ce.reset(),Ue({selectedText:"",startOffset:0,endOffset:0}),!pt.openFilesInTabs){jn.current.length>0&&(jn.current=[],oo([]));return}w&&ao(x=>x.includes(w)?x:[...x,w])},[w,pt.openFilesInTabs,n,Ce]),u.useEffect(()=>{if(!z)return;const x=k=>{k.preventDefault(),k.returnValue=""};return window.addEventListener("beforeunload",x),()=>window.removeEventListener("beforeunload",x)},[z]),u.useEffect(()=>{if(lo!=="disconnected")return;const x=new AbortController;return xe(`/api/projects/${n}`,{signal:x.signal}).then(({project:k})=>{x.signal.aborted||(f(k),K(""))}).catch(k=>{if(!mn(k)){if(k instanceof No&&[401,403,404].includes(k.status)){K(Se(k)),zl.current();return}K(l("errors.collaborationUnavailable"))}}),()=>x.abort()},[lo,n,l]);const uo=async(x={},k=bt.current)=>{Xn.current?.abort(),Xn.current=null;const N=x.signal?null:new AbortController;N&&(Xn.current=N);try{const F=k?`?mainFile=${encodeURIComponent(k)}`:"",me=await xe(`/api/projects/${n}/completions${F}`,{signal:x.signal??N?.signal});(!x.isCurrent||x.isCurrent())&&v(me.index)}catch(F){if(mn(F))return;(!x.isCurrent||x.isCurrent())&&v(null)}finally{N&&Xn.current===N&&(Xn.current=null)}},Hi=async(x={},k=bt.current)=>{Zn.current?.abort(),Zn.current=null;const N=x.signal?null:new AbortController;N&&(Zn.current=N);try{const F=k?`?mainFile=${encodeURIComponent(k)}`:"",me=await xe(`/api/projects/${n}/outline${F}`,{signal:x.signal??N?.signal});(!x.isCurrent||x.isCurrent())&&bt.current===k&&b({mainFile:k,items:me.outline})}catch(F){if(mn(F))return}finally{N&&Zn.current===N&&(Zn.current=null)}},Ql=async(x={})=>{Qn.current?.abort(),Qn.current=null;const k=x.signal?null:new AbortController;k&&(Qn.current=k);try{const N=await xe(`/api/projects/${n}/dictionary`,{signal:x.signal??k?.signal});(!x.isCurrent||x.isCurrent())&&y(N.words)}catch(N){if(mn(N))return;(!x.isCurrent||x.isCurrent())&&y([])}finally{k&&Qn.current===k&&(Qn.current=null)}};u.useEffect(()=>{let x=!1;const k=++$l.current,N=new AbortController,F=()=>!x&&$l.current===k;let me=!1,ue="";f(null),nu([]),b({mainFile:"",items:[]}),R(""),E(""),V({path:"",hasIncludes:!1}),P(""),B(""),Vl(null),Xl(),v(null),y([]),rf();const he=(r?.projectId===n?r.project:xe(`/api/projects/${n}`,{signal:N.signal})).then(nt=>{F()&&(me=!0,ue=nt.project.mainFile,f(nt.project),R(nt.project.mainFile),bt.current=nt.project.mainFile,E(nt.project.mainFile),po(new Set(lr(nt.project.mainFile))))}).catch(nt=>{F()&&K(Se(nt))}),Zt=xe(`/api/projects/${n}/files`,{signal:N.signal}).then(nt=>{F()&&nu(nt.files)}).catch(nt=>{F()&&K(Se(nt))});let kt=null;return Promise.allSettled([he,Zt]).then(()=>{!F()||!me||(kt=window.setTimeout(()=>{F()&&Promise.all([uo({signal:N.signal,isCurrent:F},bt.current||ue),Ql({signal:N.signal,isCurrent:F})])},0))}),()=>{x=!0,kt!==null&&window.clearTimeout(kt),N.abort(),Xn.current?.abort(),Xn.current=null,Zn.current?.abort(),Zn.current=null,Qn.current?.abort(),Qn.current=null,Tr.current?.abort(),Tr.current=null}},[n,r]),u.useEffect(()=>{if(!(!h||!S)){if(Ul.current!==n){Ul.current=n;return}uo({},S)}},[S,h?.id,n]),u.useEffect(()=>{if(!s||!h)return;Ar.current?.abort();const x=new AbortController;return Ar.current=x,xe(`/api/projects/${n}/mentions/${encodeURIComponent(s)}`,{signal:x.signal}).then(({mention:k})=>{x.signal.aborted||(O(k),Me(null),ve("comments"),R(k.filePath),Ui.current?.(k.id))}).catch(k=>{mn(k)||x.signal.aborted||(K(Se(k)),Ui.current?.(s))}).finally(()=>{Ar.current===x&&(Ar.current=null)}),()=>x.abort()},[s,h?.id,n]),u.useEffect(()=>{ql&&Ql()},[ql,n]),u.useEffect(()=>{if(!Kl)return;const x=new AbortController;return xe(`/api/projects/${n}`,{signal:x.signal}).then(({project:k})=>{x.signal.aborted||f(N=>N?{...N,chktexEnabled:k.chktexEnabled}:k)}).catch(k=>{mn(k)||K(Se(k))}),()=>x.abort()},[Kl,n]),u.useEffect(()=>{!h||lo!=="connected"||Bi===h.permission||f(x=>x&&{...x,permission:Bi})},[Bi,h?.permission]),u.useEffect(()=>{if(!tt)return;const x=tt.kind==="delete"&&!!tt.path&&rr(tt.path,Ie.current),k=tt.kind==="delete"&&!!tt.path&&rr(tt.path,bt.current);if(tt.kind==="move"&&tt.source&&tt.destination){const F=tt.source,me=tt.destination,ue=he=>he===F?me:he.startsWith(`${F}/`)?`${me}${he.slice(F.length)}`:he;R(he=>ue(he)),E(he=>ue(he)),ws(he=>he&&ue(he)),ho(he=>he&&ue(he)),ao(he=>he.map(ue))}x&&(R(""),B(""),Vi(""),L(l("editor.fileDeletedByCollaborator",{path:tt.path}))),tt.kind==="delete"&&tt.path&&(ws(F=>F&&rr(tt.path,F)?null:F),ho(F=>rr(tt.path,F)?"":F),ou(F=>F&&rr(tt.path,F.path)?null:F),ao(F=>F.filter(me=>!rr(tt.path,me)))),Tr.current?.abort();const N=new AbortController;Tr.current=N,Promise.all([ny({signal:N.signal}),xe(`/api/projects/${n}`,{signal:N.signal})]).then(([F,me])=>{if(f(me.project),k&&E(me.project.mainFile),x&&F){const ue=F.find(he=>he.type==="file"&&he.path===me.project.mainFile)??F.find(he=>he.type==="file"&&Yr(he.path));R(ue?.path??"")}uo({signal:N.signal}),Hi({signal:N.signal},k?me.project.mainFile:bt.current)}).catch(F=>{mn(F)}).finally(()=>{Tr.current===N&&(Tr.current=null)})},[tt?.revision]),u.useEffect(()=>{if(qe.setActiveFile(w),!w)return;B(""),X("editor.loading");const x=qe.getText(w),k=(N,F)=>{Vi(x.toString()),B(w),F?.local&&h?.permission!=="read"?(co.current+=1,re(!0),X("editor.pending")):co.current<=Fi.current&&X(ge.current?"editor.savedAt":"editor.saved")};return x.observe(k),(et||Gl)&&k(),()=>{x.unobserve(k)}},[w,qe,et,Gl,h?.permission]);const fo=async()=>{if(!et)throw new Error("Collaboration is not synchronized");const x=co.current,k=await qe.flush();return Fi.current=Math.max(Fi.current,x),Z(k.persistedAt),/\.tex$/i.test(Ie.current)&&Hi(),co.current===x?(re(!1),X("editor.savedAt")):X("editor.pending"),k};u.useEffect(()=>{if(!z||!w)return;if(!et){X("editor.offlineDraft");return}X("editor.pending");const x=window.setTimeout(()=>{X("editor.saving"),fo().catch(()=>{X(qe.connected?"editor.saveFailed":"editor.offlineDraft")})},750);return()=>window.clearTimeout(x)},[j,z,w,et]);const ys=async()=>{if(!h||h.permission==="read"||!et||!w)return!1;X("editor.saving");try{return await fo(),uo(),!0}catch(x){return X("editor.saveFailed"),K(Se(x)||l("errors.collaborationUnavailable")),!1}},Zg=async x=>{if(!h||Ai)return;const k=x==="full"?bt.current||h.mainFile:Ie.current,N=x==="selection"?Te.current.selectedText:"";if(!k)return;if(x==="selection"&&(!N.trim()||!/\.(?:tex|sty|cls)$/i.test(k))){L(l("editor.wordCountSelectionEmpty"));return}Pr.current?.abort();const F=new AbortController;Pr.current=F,Ae(x),_g(k),Ni(null),Li(""),wt(!0),Oi(!0);try{if(x==="full"&&z&&h.permission!=="read"&&!await ys())throw new Error(l("editor.wordCountSaveRequired"));const me=x==="selection"?{mode:x,path:k,source:N}:{mode:x,mainFile:k},ue=await xe(`/api/projects/${n}/word-count`,{method:"POST",body:JSON.stringify(me),signal:F.signal});if(F.signal.aborted)return;Ni(ue)}catch(me){if(mn(me))return;F.signal.aborted||Li(Se(me))}finally{Pr.current===F&&(Pr.current=null,Oi(!1))}},qi=async(x,k,N=pt.texFmtConfig)=>{if(/\.bib$/i.test(x)){const me=await tf();try{return{formatted:me.formatBibtex(k,t.maxCitationBibtexBytes)}}catch(ue){throw ue instanceof me.BibtexFormatError?ue.kind==="too-large"?new Error(l("citationLibrary.fileTooLarge",{size:me.citationBibtexLimitLabel(t.maxCitationBibtexBytes)})):new Error(l("citationLibrary.fileInvalid")):ue}}return{formatted:(await Ib(k,N)).output}},eu=async x=>{if(!h||h.permission==="read"||!et||fn.current||!yo(Ie.current))return;const k=Ie.current,N=qe.getText(k);fn.current=!0,jr(!0);let F=()=>{};const me=new Promise(he=>{F=he});Tn.current=me;let ue=null;try{ue=await qe.acquireFormatLease(k);const he=N.toString(),{formatted:Zt}=await qi(k,he,x);if(Ie.current!==k||N.toString()!==he){K(l("editor.formatSourceChanged"));return}await ue.confirm();const kt=await ic(he,Zt);if(Ie.current!==k||N.toString()!==he){K(l("editor.formatSourceChanged"));return}if(await ue.confirm(),Ie.current!==k||N.toString()!==he){K(l("editor.formatSourceChanged"));return}kt.length&&qe.applyTextEdits(k,kt),kt.length&&await fo(),dn(null),K(""),L(l("editor.formatFileComplete"))}catch(he){oc(he)?(dn({action:"file",kind:he.kind,detail:he.message}),K("")):K(l("editor.formatFileFailed",{message:Se(he)}))}finally{ue&&await ue.release(),fn.current=!1,jr(!1),F(),Tn.current===me&&(Tn.current=null)}},Qg=async()=>{if(!pt.formatOnCompile||!h||h.permission==="read"||!et||!yo(Ie.current)||fn.current)return;const x=Ie.current,k=qe.getText(x);fn.current=!0,jr(!0);let N=null;try{N=await qe.acquireFormatLease(x);const F=k.toString(),{formatted:me}=await qi(x,F);await N.confirm();const ue=await ic(F,me);if(Ie.current!==x||k.toString()!==F)throw new Error(l("editor.formatSourceChanged"));if(await N.confirm(),Ie.current!==x||k.toString()!==F)throw new Error(l("editor.formatSourceChanged"));ue.length&&qe.applyTextEdits(x,ue),ue.length&&await qe.flush(),dn(null)}catch(F){oc(F)?(dn({action:"file",kind:F.kind,detail:F.message}),K("")):K(l("editor.formatFailedContinue",{message:Se(F)}))}finally{N&&await N.release(),fn.current=!1,jr(!1)}},ey=async()=>(Tn.current&&await Tn.current,await Qg(),ys()),tu=async x=>{if(!h||h.permission==="read"||!et||fn.current||!yo(Ie.current))return;const k=Te.current;if(!k.selectedText.trim()){L(l("editor.formatSelectionRequired"));return}const N=Ie.current,{startOffset:F,endOffset:me,selectedText:ue}=k,he=qe.getText(N);if(he.toString().slice(F,me)!==ue){K(l("editor.formatSelectionChanged"));return}fn.current=!0,jr(!0);let Zt=()=>{};const kt=new Promise(hn=>{Zt=hn});Tn.current=kt;let nt=null;try{if(nt=await qe.acquireFormatLease(N),he.toString().slice(F,me)!==ue){K(l("editor.formatSelectionChanged"));return}const Ss=await qi(N,ue,x),Mw=zb(ue,Ss.formatted);await nt.confirm();const sc=await ic(ue,Mw,F);if(Ie.current!==N||he.toString().slice(F,me)!==ue){K(l("editor.formatSelectionChanged"));return}if(await nt.confirm(),Ie.current!==N||he.toString().slice(F,me)!==ue){K(l("editor.formatSelectionChanged"));return}sc.length&&qe.applyTextEdits(N,sc),sc.length&&await fo(),dn(null),K(""),L(l("editor.formatSelectionComplete"))}catch(hn){oc(hn)?(dn({action:"selection",kind:hn.kind,detail:hn.message}),K("")):K(l("editor.formatFailed",{message:Se(hn)}))}finally{nt&&await nt.release(),fn.current=!1,jr(!1),Zt(),Tn.current===kt&&(Tn.current=null)}},ty=async x=>{const k=Ie.current;if(!/\.bib$/i.test(k)||h?.permission==="read"||!et)return L(l("citationLibrary.importRequiresWrite")),!1;const N=qe.getText(k);let F;try{F=await tf()}catch(Ss){return K(Se(Ss)),!1}if(Ie.current!==k||!et)return!1;const me=N.toString(),ue=F.parseBibEntriesResult(me,t.maxCitationBibtexBytes);if(ue.status==="too-large")return L(l("citationLibrary.fileTooLarge",{size:F.citationBibtexLimitLabel(t.maxCitationBibtexBytes)})),!1;if(ue.status==="invalid")return L(l("citationLibrary.fileInvalid")),!1;if(ue.entries.some(Ss=>Ss.citationKey.toLowerCase()===x.citationKey.toLowerCase()))return L(l("citationErrors.alreadyInFile",{key:x.citationKey})),!1;const he=Math.max(0,Math.min(me.length,Ce.getCursor().offset)),Zt=me.slice(0,he),kt=me.slice(he),nt=Zt?Zt.endsWith(`
|
|
21
|
-
|
|
22
|
-
`)?"":Zt.endsWith(`
|
|
23
|
-
`)?`
|
|
24
|
-
`:`
|
|
25
|
-
|
|
26
|
-
`:"",hn=kt?kt.startsWith(`
|
|
27
|
-
|
|
28
|
-
`)?"":kt.startsWith(`
|
|
29
|
-
`)?`
|
|
30
|
-
`:`
|
|
31
|
-
|
|
32
|
-
`:"";return qe.applyTextEdits(k,[{from:he,to:he,replacement:`${nt}${x.bibtex.trim()}${hn}`}]),L(l("citationLibrary.imported",{key:x.citationKey})),!0},{files:qt,setFiles:nu,loadFiles:ny,newFileOpen:ry,setNewFileOpen:ru,newFilePath:sy,setNewFilePath:su,resourcePreview:oy,setResourcePreview:ou,resourcePreviewLoading:iy,setResourcePreviewLoading:cy,newFolderOpen:ay,setNewFolderOpen:iu,newFolderName:ly,setNewFolderName:cu,fileDialogError:uy,setFileDialogError:au,selectedFolder:lu,setSelectedFolder:ws,selectedFile:dy,setSelectedFile:ho,expandedFolders:fy,setExpandedFolders:po,moveEntry:hy,setMoveEntry:uu,moveName:py,setMoveName:du,moveDestination:my,setMoveDestination:fu,deleteEntry:Ki,setDeleteEntry:hu,fileDragActive:gy,setFileDragActive:yy,uploadConflict:wy,setUploadConflict:by,uploadingFiles:xy,uploadFeedback:vy,dismissUploadFeedback:pu,directoryEntries:Sy,visibleEntries:Cy,createFile:Ey,createFolder:ky,uploadFiles:mu,upload:Ry,openFile:Gi,movePath:Dy,movePathToFolder:jy,removePath:_y}=Y0({projectId:n,site:t,activeFile:w,dirty:z,save:ys,onError:K,onProject:f,onActiveFile:R,onActiveMainFile:E});Il.current=x=>{ws(null),ho(x),po(k=>new Set([...k,...lr(x)])),R(x)};const Ty=x=>{if(x.id!==d.current)return;const k=x.mainFile!==h?.mainFile;f(x),k&&(bt.current=x.mainFile,Ie.current=x.mainFile,E(x.mainFile),R(x.mainFile),ws(null),ho(x.mainFile),po(N=>new Set([...N,...lr(x.mainFile)])))},gu=()=>bt.current||h?.mainFile||"",Py=()=>{const x=gu(),k=Ie.current;if(!k||!/\.tex$/i.test(k))return x;const N=qt.filter(ue=>ue.type==="file"&&/\.tex$/i.test(ue.path)).length,F=qe.getText(k).toString();return Dd(F)||N===1?(x!==k&&(bt.current=k,E(k)),k):x===k&&h?.mainFile&&h.mainFile!==k?(bt.current=h.mainFile,E(h.mainFile),h.mainFile):x};u.useEffect(()=>{!w||w!==S||U!==w||$.filePath!==w||!w.toLocaleLowerCase().endsWith(".tex")||qt.filter(k=>k.type==="file"&&/\.tex$/i.test(k.path)).length===0||w===h?.mainFile||!Dd($.content)&&h?.mainFile&&(bt.current=h.mainFile,E(h.mainFile))},[w,S,U,$,qt,h?.mainFile]),u.useEffect(()=>{if(!pt.openFilesInTabs||qt.length===0)return;const x=new Set(qt.filter(k=>k.type==="file"&&Yr(k.path)).map(k=>k.path));ao(k=>{const N=k.filter(F=>x.has(F));return N.length===k.length?k:N})},[qt,pt.openFilesInTabs]);const{comments:Pn,commentsFilePath:Ji,commentsReady:Yi,fileCommentsLoading:Ay,fileCommentsError:Oy,retryFileComments:Ly,reviewComments:Ny,reviewCommentsLoading:My,reviewCommentsError:Fy,retryReviewComments:Iy,commentScope:$y,setCommentScope:Uy,focusComment:yu,setFocusComment:bs,commentOpen:zy,openComment:By,closeComment:Wy,commentText:Vy,setCommentText:Hy,commentSelection:qy,commentSubmitting:Ky,commentError:Gy,addComment:Jy,toggleComment:Yy,replyToComment:Xy,editComment:Zy,deleteComment:Qy,editCommentReply:ew,deleteCommentReply:tw,commentDraftStore:nw,cancelComment:rw,commentDraftRestored:sw,commentDraftCanRetarget:ow,useCurrentCommentSelection:iw}=ox({projectId:n,activeFile:w,content:j,permission:h?.permission,revision:Hl,selection:Re,save:ys,saveFailureMessage:l("errors.collaborationUnavailable"),onError:K,onAdded:()=>{Me(null),ve("comments")},onChanged:()=>{zg()}});u.useEffect(()=>{if(!S||$.filePath!==S)return;const x=jd($.content).length>0;V(k=>k.path===S&&k.hasIncludes===x?k:{path:S,hasIncludes:x})},[S,$]),u.useEffect(()=>{if(!S||!et||w===S)return;const x=qe.getText(S);let k=null;const N=()=>{const me=jd(x.toString()).length>0;V(ue=>ue.path===S&&ue.hasIncludes===me?ue:{path:S,hasIncludes:me})},F=()=>{k!==null&&window.clearTimeout(k),k=window.setTimeout(()=>{k=null,N()},nf)};return N(),x.observe(F),()=>{k!==null&&window.clearTimeout(k),x.unobserve(F)}},[w,S,qe,et]);const cw=u.useMemo(()=>T.path===S&&T.hasIncludes,[S,T]),wu=x=>{we(null),ve("comments"),bs(null),Je(x),Ie.current!==x.filePath&&Or(x.filePath,x.startLine,1)},aw=x=>{const k=Pn.find(N=>N.id===x&&N.filePath===w);!k||k.resolved||k.orphaned||(Je(null),bs(null),O(null),Me(k.id),we(N=>({id:k.id,filePath:k.filePath,nonce:(N?.nonce??0)+1})),ve("comments"))};u.useEffect(()=>{we(null),Me(null)},[w]),u.useEffect(()=>{if(!Pe)return;const x=fx(Pe,w,U,Ji,Yi,Pn);if(x){bs({...x}),Je(null);return}Pe.filePath===w&&U===w&&Ji===w&&Yi&&Je(null)},[w,Pn,Ji,Yi,U,Pe,bs]);const lw=async x=>{const k=await Bg(x);return k&&zi.current?.(1),k},uw=async()=>{const x=Yl.length,k=await Wg();return k&&x&&zi.current?.(x,!0),k};u.useEffect(()=>{if(!ke||w!==ke.filePath||de!=="comments")return;const x=Pn.find(N=>N.id===ke.commentId);if(!x||ke.replyId&&!x.replies.some(N=>N.id===ke.replyId)||$i.current===ke.id)return;$i.current=ke.id,wu(x);const k=window.setTimeout(()=>O(N=>N?.id===ke.id?null:N),3e3);return()=>window.clearTimeout(k)},[w,Pn,de,ke]);const{pdfUrl:An,pdfCompiledAt:xs,pdfSizeBytes:dw,pdfLoadingMode:fw,pdfLoading:Xi,compileLog:Zi,compileDiagnostics:hw,compileOutcome:vs,artifacts:bu,artifactPreview:pw,artifactLoading:mw,editorNotice:gw,localCompiling:xu,cancelling:yw,cleaning:vu,compile:ww,cancelCompile:bw,cleanCompile:Su,viewArtifact:xw}=q0({projectId:n,project:h,mainFile:S,resolveCompileMainFile:Py,getCurrentMainFile:gu,initialLatest:r?.projectId===n?r.latestCompile:null,collaborationSynced:et,sharedState:er,onSharedState:Vl,save:ey,loadOutline:(x,k)=>Hi({signal:x},k),onPreviewTab:W,onError:K,onCompileStart:()=>{K(""),L("")},onCompileSuccess:()=>{const x=Ie.current;if(x){const k=Ce.getCursor();Wi(x,k.line,k.column,{silent:!0})}},onPdfChanged:Xl});u.useEffect(()=>{if(!h||!S||!An&&Xi)return;const x=window.setTimeout(()=>m(!0),An?150:0);return()=>window.clearTimeout(x)},[h,Xi,An]),u.useEffect(()=>{const x=k=>{(k.ctrlKey||k.metaKey)&&(!k.shiftKey&&k.key.toLocaleLowerCase()==="p"?(k.preventDefault(),ne(!0)):k.shiftKey&&k.key.toLocaleLowerCase()==="f"&&(k.preventDefault(),Tt(!0)))};return window.addEventListener("keydown",x,!0),()=>window.removeEventListener("keydown",x,!0)},[]);const Cu=x=>{Fl(x),Ob(e.id,n,x)},Eu=(x=!1)=>{const k=Yn;if(!k)return;dn(null),K(""),x&&Cu({...pt,texFmtConfig:""});const N=x?"":void 0;k.action==="selection"?tu(N):eu(N)},vw=async()=>{Mi(!0);try{await Ug()||(K(l("editor.collaboration.permissionDowngradeOtherTabBlocked")),Mi(!1))}catch(x){K(Se(x)),Mi(!1)}},ku=()=>{io.current?.isCollapsed()?io.current.expand():io.current?.collapse()},Sw=u.useMemo(()=>uj(D,S,$),[D,S,$]),Qi=u.useMemo(()=>Bb(Zi,vs),[Zi,vs]),Lr=ee!=="pdf-only",Ru=ee!=="editor-only",mo=x=>{Ee(x),x==="pdf-only"&&W("pdf")},Cw=u.useCallback(x=>{_n.current?.abort();const k=new AbortController;_n.current=k;const N=Ie.current,F=bt.current,me=new URLSearchParams({kind:x.kind,key:x.key,...N?{path:N}:{},...F?{mainFile:F}:{}});xe(`/api/projects/${n}/references/resolve?${me}`,{signal:k.signal}).then(({target:ue})=>{if(!(k.signal.aborted||Ie.current!==N||bt.current!==F)){if(!ue){K(l(x.kind==="citation"?"editor.citationTargetNotFound":"editor.labelTargetNotFound",{key:x.key}));return}Ii.current==="pdf-only"&&mo("editor-pdf"),Or(ue.path,ue.line,ue.column)}}).catch(ue=>{!k.signal.aborted&&!mn(ue)&&K(Se(ue))}).finally(()=>{_n.current===k&&(_n.current=null)})},[Or,n,l]),Ew=Ki?Wl.filter(x=>x.filePath&&rr(Ki.path,x.filePath)):[];if(!h)return a.jsxs("div",{className:"center-card",children:[a.jsx("p",{children:pe||l("common.loading")}),pe&&a.jsx("button",{className:"primary",onClick:c,children:l("editor.backToProjects")})]});const On=h.permission==="read"||!et,ec=Ng.find(x=>x.path===w),tc=ec&&!gs?ec:null,kw=(x,k)=>{if(On)return;const N=Ie.current;if(!N)return;if(qe.getText(N).toString().slice(x.from,x.to)!==x.word){K(l("editor.spellCheckSourceChanged"));return}try{qe.applyTextEdits(N,[{from:x.from,to:x.to,replacement:k}])}catch(ue){K(Se(ue))}},nc=er?.mainFile===S&&(er.status==="queued"||er.status==="running"),go=xu||nc||vu,Rw=w?qe.getText(w):null,Dw=xs?new Date(xs).toLocaleString(Rs.resolvedLanguage,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"",jw=S.split("/").at(-1)??S,_w=Qi.warnings.length+Qi.errors.length+bu.length,Tw=An?`${An}${An.includes("?")?"&":"?"}download=1`:"",rc=S||h.mainFile,Pw=!!(w&&w===rc&&/\.tex$/i.test(w)),Aw=!!(rc&&/\.tex$/i.test(rc)),Du=x=>{const k=qt.find(N=>N.path===x);k&&Yr(k.path)?Gi(k):Bl(x)},Ow=x=>{document.getElementById(`editor-tab-${encodeURIComponent(x)}`)?.focus()},Lw=(x,k)=>{if(!["ArrowLeft","ArrowRight","Home","End"].includes(x.key))return;x.preventDefault();const N=x.key==="Home"?0:x.key==="End"?_r.length-1:(k+(x.key==="ArrowLeft"?-1:1)+_r.length)%_r.length,F=_r[N];F&&(Du(F),window.requestAnimationFrame(()=>Ow(F)))},ju=go?nc?er?.status==="queued"?l("editor.compileQueued"):l("editor.compilingBy",{name:er?.requestedBy.name??l("common.user")}):l("editor.compiling"):vs==="failed"?An&&xs?l("editor.compileFailedRetained",{time:new Date(xs).toLocaleString(Rs.resolvedLanguage)}):l("editor.compileFailedNoPdf"):vs==="cancelled"?l("compileControls.cancelled"):"",Nw=H==="editor.savedAt"&&Q?l("editor.savedAt",{time:new Date(Q).toLocaleTimeString(Rs.resolvedLanguage,{hour:"2-digit",minute:"2-digit",second:"2-digit"})}):l(H);return a.jsxs("div",{className:"workspace","data-texlite-tooltips":pt.showTooltips?"on":"off",children:[a.jsx(xE,{site:t,project:h,activeFile:w,saveStateLabel:Nw,editorPreferences:pt,activeSessions:Wl,collaborationStatus:lo,reconnectCollaboration:Fg,protocolUpgradeRequired:Jl,showEditor:Lr,filesCollapsed:Y,toggleFilesPanel:ku,workspaceLayout:ee,changeWorkspaceLayout:mo,onBack:c,onShare:()=>ze(!0),showCitationLibrary:Lr&&/\.bib$/i.test(w),citationLibraryOpen:_,onCitationLibrary:()=>M(!0),onHistory:()=>ce(!0),onGit:()=>le(!0),canManageGit:h.ownerId===e.id,formatting:gs,readOnly:On,collaborationSynced:et,onToggleComments:()=>{Me(null),ve(de==="comments"&&!We?null:"comments")},commentsOpen:de==="comments",unresolvedCommentCount:Pn.filter(x=>!x.resolved).length,onToggleSettings:()=>ve(de==="settings"?null:"settings"),settingsOpen:de==="settings",compileBusy:go,sharedCompiling:nc,localCompiling:xu,cancelling:yw,compileState:er,onCompile:ww,onCancelCompile:()=>{bw()}}),Jl&&a.jsxs("div",{className:"workspace-update-banner",role:"alert",children:[a.jsx(Gt,{size:15}),a.jsx("span",{children:l("workspaceUpdates.protocolUpgrade")}),a.jsx("button",{type:"button",onClick:()=>window.location.reload(),children:l("common.reload")})]}),ju&&a.jsxs("div",{className:`compile-status-strip${vs==="failed"?" failed":""}`,role:"status","aria-live":"polite",children:[a.jsx(gt,{className:go?"spin":"",size:14}),a.jsx("span",{children:ju})]}),(Pt.error||tr.error||Yn||tc)&&a.jsxs("div",{className:"client-tool-recoveries",children:[Pt.error&&a.jsxs("div",{className:"client-tool-recovery",role:"alert",title:Pt.error,children:[a.jsx(Gt,{size:15}),a.jsxs("span",{children:[a.jsx("strong",{children:l("editor.harperRecoveryTitle")}),l("editor.harperFallbackHint")]}),a.jsx("div",{className:"client-tool-recovery-actions",children:a.jsx("button",{type:"button",onClick:Pt.retry,children:l("common.retry")})}),a.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:l("common.close"),"aria-label":l("common.close"),onClick:Pt.dismissError,children:a.jsx($n,{size:13})})]}),tr.error&&a.jsxs("div",{className:"client-tool-recovery",role:"alert",title:tr.error,children:[a.jsx(Gt,{size:15}),a.jsxs("span",{children:[a.jsx("strong",{children:l("chktex.recoveryTitle")}),l("chktex.recoveryHint")]}),a.jsx("div",{className:"client-tool-recovery-actions",children:a.jsx("button",{type:"button",onClick:tr.retry,children:l("common.retry")})}),a.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:l("common.close"),"aria-label":l("common.close"),onClick:tr.dismissError,children:a.jsx($n,{size:13})})]}),Yn&&a.jsxs("div",{className:"client-tool-recovery",role:"alert",title:Yn.detail,children:[a.jsx(Gt,{size:15}),a.jsxs("span",{children:[a.jsx("strong",{children:l(Yn.kind==="format"?"editor.texFmtOptionsRecoveryTitle":Yn.kind==="load"?"editor.texFmtRecoveryTitle":"editor.texFmtRuntimeRecoveryTitle")}),l("editor.clientToolRecoveryHint")]}),a.jsxs("div",{className:"client-tool-recovery-actions",children:[a.jsx("button",{type:"button",disabled:gs||On,onClick:()=>Eu(),children:l("common.retry")}),Yn.kind==="format"&&pt.texFmtConfig.trim()&&a.jsx("button",{type:"button",disabled:gs||On,onClick:()=>Eu(!0),children:l("editor.resetFormatterOptions")}),a.jsx("button",{type:"button",onClick:()=>window.location.reload(),children:l("common.reload")})]}),a.jsx("button",{type:"button",className:"formatter-diagnostics-dismiss",title:l("common.close"),"aria-label":l("common.close"),onClick:()=>dn(null),children:a.jsx($n,{size:13})})]}),tc&&a.jsxs("div",{className:"client-tool-recovery format-lease-status",role:"status",children:[a.jsx(gt,{className:"spin",size:15}),a.jsx("span",{children:l("editor.formattingBy",{name:tc.holderName})})]})]}),Mg&&a.jsxs("div",{className:"client-tool-recovery",role:"status",children:[a.jsx(Gt,{size:15}),a.jsx("span",{children:l("history.saveWarning")})]}),pe&&a.jsx("div",{className:"toast",onClick:()=>K(""),children:pe}),ae&&a.jsx("div",{className:"toast success",onClick:()=>L(""),children:ae}),a.jsxs(Ww,{autoSaveId:ir("texlite-workspace-layout"),direction:"horizontal",className:"work-grid",children:[Lr&&a.jsx(LE,{project:h,filesPanel:io,files:qt,visibleEntries:Cy,activeFile:w,activeMainFile:S,selectedFile:dy,selectedFolder:lu,expandedFolders:fy,fileDragActive:gy,uploadingFiles:xy,uploadFeedback:vy,readOnly:On,formatting:gs,canFormat:yo(w),activeFormatLease:!!ec,collaborationSynced:et,editorFontSize:pt.fontSize,outline:Sw,sourceCursorStore:Ce,wordCountBusy:Ai,hasSelection:!!Re.selectedText.trim()&&/\.(?:tex|sty|cls)$/i.test(w),hasFormatSelection:!!Re.selectedText.trim(),uploadInput:Og,setSelectedFolder:ws,setExpandedFolders:po,setMoveEntry:uu,setMoveName:du,setMoveDestination:fu,setDeleteEntry:hu,setFileDialogError:au,setNewFolderName:cu,setNewFolderOpen:iu,setNewFilePath:su,setNewFileOpen:ru,setQuickOpen:ne,setProjectSearchOpen:Tt,setFileDragActive:yy,dismissUploadFeedback:pu,setFilesCollapsed:se,toggleFilesPanel:ku,onError:K,uploadFiles:mu,upload:Ry,openFile:Gi,movePathToFolder:jy,onFormatFile:()=>{eu()},onFormatSelection:()=>{tu()},jumpToSource:Or,syncSourceToPdf:Wi,onWordCount:x=>{Zg(x)}}),Lr&&a.jsx(ja,{className:"resize-handle",children:a.jsx(uf,{size:12})}),Lr&&a.jsx(zE,{project:h,activeFile:w,openTabs:_r,content:j,loadedFile:U,readOnly:On,comments:Pn,focusComment:yu,editorPreferences:pt,completionIndex:C,nativeSpellCheck:Pt.nativeFallback,spellCheckIssues:Pt.issues,spellCheckJump:Pt.jump,sourceJump:qg,collaborativeText:Rw,collaborationAwareness:qe.awareness,undoManager:w?qe.getUndoManager(w):void 0,editorNotice:gw,activateTab:Du,closeTab:Bl,handleTabKeyDown:Lw,updateEditorContent:Vi,setSelection:(x,k,N)=>Ue({selectedText:x,startOffset:k,endOffset:N}),onAddComment:(x,k,N,F)=>By({selectedText:x,startOffset:k,endOffset:N},F),onSelectionHistory:(x,k,N,F)=>{te({filePath:w,selection:{selectedText:x,startOffset:k,endOffset:N},source:F})},onCommentClick:aw,onSpellCheckReplace:kw,onReferenceNavigate:Cw,onCursor:Lg}),Ru&&a.jsx(KE,{projectId:n,activeMainFile:S,previewTab:_e,diagnosticTab:q,pdfUrl:An,pdfLoadingMode:fw,pdfLoading:Xi,pdfCompiledAt:xs,pdfSizeBytes:dw,pdfCompiledLabel:Dw,pdfTargetLabel:jw,pdfDownloadUrl:Tw,pdfTarget:Vg,pdfViewport:Hg,activeFile:w,compileBusy:go,compileLog:Zi,compileDiagnostics:hw,compileMessages:Qi,artifacts:bu,artifactPreview:pw,artifactLoading:mw,cleaning:vu,readOnly:On,collaborationSynced:et,workspaceLayout:ee,showSyncResize:Lr&&Ru,diagnosticCount:_w,selectPreviewTab:W,changeWorkspaceLayout:mo,onSetNotice:L,onSetPdfViewport:Kg,onResetPdfViewport:Gg,syncVisiblePdfToSource:Yg,syncCurrentSourceToPdf:()=>{const x=Ie.current;if(!x)return Promise.resolve();const k=Ce.getCursor();return Wi(x,k.line,k.column)},syncPdfToSource:Jg,canSyncWithPdf:Pw,canSyncPdfToSource:Aw,files:qt,jumpToSource:Or,onSetCleanMode:yt,cleanCompile:Su,viewArtifact:xw}),a.jsx(cj,{sidePanel:de,onClose:()=>ve(null),project:h,projectId:n,site:t,files:qt,currentUserId:e.id,comments:We?Pn:Ny,commentDraftStore:nw,commentsLoading:We?Ay:My,commentsError:We?Oy:Fy,onRetryComments:We?Ly:Iy,activeFile:w,singleCommentId:We,onShowAllComments:()=>Me(null),hasProjectCommentsScope:cw,commentScope:$y,onCommentScopeChange:Uy,focusedCommentId:it?.filePath===w?it.id:yu?.id,commentFocusNonce:it?.nonce,onClearFocusComment:()=>{we(null),bs(null),O(null)},unreadMentions:Yl,onMarkMentionRead:lw,onMarkAllMentionsRead:uw,targetCommentId:ke?.commentId,targetReplyId:ke?.replyId,onFocusComment:wu,onToggleComment:Yy,onReplyComment:Xy,onEditComment:Zy,onDeleteComment:Qy,onEditCommentReply:ew,onDeleteCommentReply:tw,dictionaryWords:g,onDictionaryChange:y,editorPreferences:pt,onEditorPreferences:Cu,spellCheckCount:Pt.summary?.total??null,spellCheckUniqueCount:Pt.summary?.unique??null,spellCheckIndex:Pt.summary?Pt.index:-1,onSpellCheckNavigate:Pt.jumpToIssue,onProject:Ty},n)]}),Dr&&a.jsx(cf,{title:l("editor.wordCountTitle"),onClose:()=>wt(!1),children:a.jsx(fj,{open:!0,mode:Pi,path:ms,busy:Ai,error:Tg,result:Pg,onOpenChange:wt})}),a.jsx(vD,{user:e,project:h,projectId:n,activeFile:w,content:j,maxCitationBibtexBytes:t.maxCitationBibtexBytes,files:qt,directoryEntries:Sy,readOnly:On,workspaceLayout:ee,changeWorkspaceLayout:mo,resourcePreview:oy,resourcePreviewLoading:iy,setResourcePreview:ou,setResourcePreviewLoading:cy,uploadConflict:wy,setUploadConflict:by,dismissUploadFeedback:pu,uploadFiles:mu,cleanMode:oe,setCleanMode:yt,cleanCompile:Su,newFileOpen:ry,setNewFileOpen:ru,newFilePath:sy,setNewFilePath:su,newFolderOpen:ay,setNewFolderOpen:iu,newFolderName:ly,setNewFolderName:cu,selectedFolder:lu,fileDialogError:uy,setFileDialogError:au,createFile:Ey,createFolder:ky,moveEntry:hy,setMoveEntry:uu,moveName:py,setMoveName:du,moveDestination:my,setMoveDestination:fu,movePath:Dy,deleteEntry:Ki,setDeleteEntry:hu,deleteActiveSessions:Ew,removePath:_y,commentOpen:zy,closeComment:Wy,commentSelection:qy,commentText:Vy,setCommentText:Hy,commentSubmitting:Ky,cancelComment:rw,commentDraftRestored:sw,commentDraftCanRetarget:ow,useCurrentCommentSelection:iw,commentError:Gy,addComment:Jy,shareOpen:De,setShareOpen:ze,citationLibraryOpen:_,setCitationLibraryOpen:M,insertCitationAtCursor:ty,quickOpen:I,setQuickOpen:ne,projectSearchOpen:Et,setProjectSearchOpen:Tt,openFile:Gi,jumpToSource:Or,selectionHistoryTarget:_t,closeSelectionHistory:()=>te(null),historyOpen:Oe,setHistoryOpen:ce,gitOpen:G,setGitOpen:le,save:ys,permissionDowngrade:Ig,permissionDowngradeBusy:Ag,dismissPermissionDowngrade:$g,discardPermissionDraft:vw})]})}const zj=Object.freeze(Object.defineProperty({__proto__:null,ProjectWorkspace:hj},Symbol.toStringTag,{value:"Module"}));export{aE as A,vj as B,qs as C,Ic as D,nx as E,fb as F,Mn as G,Au as H,$b as I,Tb as J,Uc as K,cb as L,Sj as M,zj as P,Db as R,jb as S,qS as U,Ed as a,Rj as b,Qc as c,Dj as d,jj as e,_j as f,xr as g,Cj as h,pn as i,sE as j,tp as k,fl as l,Ma as m,cE as n,ra as o,ei as p,Tj as q,kj as r,nE as s,Ej as t,fs as u,eo as v,mE as w,Pj as x,sa as y,fE as z};
|