texlite 0.20.0 → 0.22.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 +215 -35
- package/OPERATIONS.md +2 -2
- package/README.md +48 -44
- package/README.zh-CN.md +42 -36
- package/dist/client/assets/AdminUsers-DepqkT6m.js +1 -0
- package/dist/client/assets/AdminUsers-DepqkT6m.js.br +0 -0
- package/dist/client/assets/AdminUsers-DepqkT6m.js.gz +0 -0
- package/dist/client/assets/{AgentIcon-dCMgWJG-.css → AgentIcon-DeoZDwgh.css} +1 -1
- package/dist/client/assets/AgentIcon-DeoZDwgh.css.br +0 -0
- package/dist/client/assets/AgentIcon-DeoZDwgh.css.gz +0 -0
- package/dist/client/assets/{AgentManagement-rIYtm4Bo.js → AgentManagement-DlV6tHez.js} +1 -1
- package/dist/client/assets/AgentManagement-DlV6tHez.js.br +0 -0
- package/dist/client/assets/AgentManagement-DlV6tHez.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-CvOz5X_j.js +2 -0
- package/dist/client/assets/AgentTerminal-CvOz5X_j.js.br +0 -0
- package/dist/client/assets/AgentTerminal-CvOz5X_j.js.gz +0 -0
- package/dist/client/assets/{AgentTerminalSurface-B2rwONYs.js → AgentTerminalSurface-COqg_GdK.js} +1 -1
- package/dist/client/assets/AgentTerminalSurface-COqg_GdK.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-COqg_GdK.js.gz +0 -0
- package/dist/client/assets/{AvatarSettingsDialog-DplRpiJJ.js → AvatarSettingsDialog-C8WQhZBK.js} +1 -1
- package/dist/client/assets/AvatarSettingsDialog-C8WQhZBK.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-C8WQhZBK.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-SpudGDwi.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-DgOIkLwK.js +3 -0
- package/dist/client/assets/CitationLibraryDialog-DgOIkLwK.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-DgOIkLwK.js.gz +0 -0
- package/dist/client/assets/CitationNotesPreview-D3CjBD0p.js +1 -0
- package/dist/client/assets/Dashboard-CD1w42mA.js +5 -0
- package/dist/client/assets/Dashboard-CD1w42mA.js.br +0 -0
- package/dist/client/assets/Dashboard-CD1w42mA.js.gz +0 -0
- package/dist/client/assets/GitDialog-DGzZ3GRj.js +4 -0
- package/dist/client/assets/GitDialog-DGzZ3GRj.js.br +0 -0
- package/dist/client/assets/GitDialog-DGzZ3GRj.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-CGZl3mcY.js +1 -0
- package/dist/client/assets/GitHubAccountDialog-CGZl3mcY.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-CGZl3mcY.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-DTZxCgyT.js +8 -0
- package/dist/client/assets/HistoryDialog-DTZxCgyT.js.br +0 -0
- package/dist/client/assets/HistoryDialog-DTZxCgyT.js.gz +0 -0
- package/dist/client/assets/InfoPopover-Ba7GvcuW.js +1 -0
- package/dist/client/assets/LatexEditor-Boc-45KL.js +25 -0
- package/dist/client/assets/LatexEditor-Boc-45KL.js.br +0 -0
- package/dist/client/assets/LatexEditor-Boc-45KL.js.gz +0 -0
- package/dist/client/assets/MarkdownContent-BeKi2gI5.js +36 -0
- package/dist/client/assets/MarkdownContent-BeKi2gI5.js.br +0 -0
- package/dist/client/assets/MarkdownContent-BeKi2gI5.js.gz +0 -0
- package/dist/client/assets/MarkdownPreview-BH2iwvle.js +1 -0
- package/dist/client/assets/MarkdownPreview-BH2iwvle.js.br +0 -0
- package/dist/client/assets/MarkdownPreview-BH2iwvle.js.gz +0 -0
- package/dist/client/assets/PdfPreview-CIOM7sbu.js +1 -0
- package/dist/client/assets/PdfPreview-CIOM7sbu.js.br +0 -0
- package/dist/client/assets/PdfPreview-CIOM7sbu.js.gz +0 -0
- package/dist/client/assets/{ProjectIconPickerDialog-B9_XvdIC.js → ProjectIconPickerDialog-Bfkaxcnh.js} +1 -1
- package/dist/client/assets/ProjectIconPickerDialog-Bfkaxcnh.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-Bfkaxcnh.js.gz +0 -0
- package/dist/client/assets/ProjectSearchDialog-DPIzxVYj.js +1 -0
- package/dist/client/assets/ProjectSearchDialog-DPIzxVYj.js.br +0 -0
- package/dist/client/assets/ProjectSearchDialog-DPIzxVYj.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-ChXx_cmP.js +4 -0
- package/dist/client/assets/ProjectSettings-ChXx_cmP.js.br +0 -0
- package/dist/client/assets/ProjectSettings-ChXx_cmP.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-B-w2ix8N.js +25 -0
- package/dist/client/assets/ProjectWorkspace-B-w2ix8N.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-B-w2ix8N.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-CHjPlBu2.js +1 -0
- package/dist/client/assets/QuickOpenDialog-CHjPlBu2.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-CHjPlBu2.js.gz +0 -0
- package/dist/client/assets/ReadOnlySource-DKcmDg0e.js +2 -0
- package/dist/client/assets/SelectionHistoryDialog-Dnj22E8N.js +3 -0
- package/dist/client/assets/SelectionHistoryDialog-Dnj22E8N.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dnj22E8N.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-l8GSYTm-.js +2 -0
- package/dist/client/assets/SharedProjectPage-l8GSYTm-.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-l8GSYTm-.js.gz +0 -0
- package/dist/client/assets/{SystemMetricsDialog-BExTHWxg.js → SystemMetricsDialog-DkmBA4o4.js} +1 -1
- package/dist/client/assets/SystemMetricsDialog-DkmBA4o4.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-DkmBA4o4.js.gz +0 -0
- package/dist/client/assets/{TagColorSelect-CzPUDAny.js → TagColorSelect-e-Tq5V3H.js} +1 -1
- package/dist/client/assets/TagManagementDialog-BM1MRuwh.js +1 -0
- package/dist/client/assets/TagManagementDialog-BM1MRuwh.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-BM1MRuwh.js.gz +0 -0
- package/dist/client/assets/TagMarquee-BLmCTTCt.js +1 -0
- package/dist/client/assets/ThemeSwitcher-dcvtWVCO.js +1 -0
- package/dist/client/assets/{WordCountDialog-CgDcnPdJ.js → WordCountDialog-DI0Jv-fg.js} +1 -1
- package/dist/client/assets/WordCountDialog-DI0Jv-fg.js.br +0 -0
- package/dist/client/assets/WordCountDialog-DI0Jv-fg.js.gz +0 -0
- package/dist/client/assets/{bibtexFormatterWorker-B_jvobIv.js → bibtexFormatterWorker-Bp8kjjvw.js} +14 -14
- package/dist/client/assets/bibtexFormatterWorker-Bp8kjjvw.js.br +0 -0
- package/dist/client/assets/bibtexFormatterWorker-Bp8kjjvw.js.gz +0 -0
- package/dist/client/assets/bibtexMetadataWorker-CQozbzep.js +2 -0
- package/dist/client/assets/bibtexMetadataWorker-CQozbzep.js.br +0 -0
- package/dist/client/assets/bibtexMetadataWorker-CQozbzep.js.gz +0 -0
- package/dist/client/assets/bibtexNames-CPGbBJxd.js +1 -0
- package/dist/client/assets/bibtexReferences-xpSF8IXH.js +1 -0
- package/dist/client/assets/bot-ClmnQ29j.js +1 -0
- package/dist/client/assets/{chktex-BeOSrdut.js → chktex-BrzPYHey.js} +2 -2
- package/dist/client/assets/citationAuthors-BWHXhKvT.js +1 -0
- package/dist/client/assets/citationAuthors-BWHXhKvT.js.br +0 -0
- package/dist/client/assets/citationAuthors-BWHXhKvT.js.gz +0 -0
- package/dist/client/assets/citationLibrary-DxGdbZEQ.js +1 -0
- package/dist/client/assets/citationLibrary-DxGdbZEQ.js.br +0 -0
- package/dist/client/assets/citationLibrary-DxGdbZEQ.js.gz +0 -0
- package/dist/client/assets/dist-C9O-A_C4.js +1 -0
- package/dist/client/assets/dist-C9O-A_C4.js.br +0 -0
- package/dist/client/assets/dist-C9O-A_C4.js.gz +0 -0
- package/dist/client/assets/dist-Dxkdrap6.js +2 -0
- package/dist/client/assets/dist-Dxkdrap6.js.br +0 -0
- package/dist/client/assets/dist-Dxkdrap6.js.gz +0 -0
- package/dist/client/assets/editor-CkUEg2La.js +14 -0
- package/dist/client/assets/editor-CkUEg2La.js.br +0 -0
- package/dist/client/assets/editor-CkUEg2La.js.gz +0 -0
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js +36 -0
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js.br +0 -0
- package/dist/client/assets/editor-languages-kcWr1Z3Q.js.gz +0 -0
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js +1 -0
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js.br +0 -0
- package/dist/client/assets/editorThemeExtension-BWtZV1Af.js.gz +0 -0
- package/dist/client/assets/generatedParser-CZa2vsK6.js +1 -0
- package/dist/client/assets/generatedParser-CZa2vsK6.js.br +0 -0
- package/dist/client/assets/generatedParser-CZa2vsK6.js.gz +0 -0
- package/dist/client/assets/git-compare-arrows-158rS_vn.js +1 -0
- package/dist/client/assets/i18n-Dtn6w-qA.js +13 -0
- package/dist/client/assets/i18n-Dtn6w-qA.js.br +0 -0
- package/dist/client/assets/i18n-Dtn6w-qA.js.gz +0 -0
- package/dist/client/assets/index-BbU2fbRw.css +1 -0
- package/dist/client/assets/index-BbU2fbRw.css.br +0 -0
- package/dist/client/assets/index-BbU2fbRw.css.gz +0 -0
- package/dist/client/assets/index-CPR6YZEf.js +2 -0
- package/dist/client/assets/index-CPR6YZEf.js.br +0 -0
- package/dist/client/assets/index-CPR6YZEf.js.gz +0 -0
- package/dist/client/assets/katex-Ca9qmXPj.js +257 -0
- package/dist/client/assets/katex-Ca9qmXPj.js.br +0 -0
- package/dist/client/assets/katex-Ca9qmXPj.js.gz +0 -0
- package/dist/client/assets/katex.min-VLoWtPY0.js +1 -0
- package/dist/client/assets/{latexFormatterWorker-BIDCSZPd.js → latexFormatterWorker-BWiogBYE.js} +1 -1
- package/dist/client/assets/latexFormatterWorker-BWiogBYE.js.br +0 -0
- package/dist/client/assets/latexFormatterWorker-BWiogBYE.js.gz +0 -0
- package/dist/client/assets/latexScanner-D9bMX44Y.js +6 -0
- package/dist/client/assets/latexScanner-D9bMX44Y.js.br +0 -0
- package/dist/client/assets/latexScanner-D9bMX44Y.js.gz +0 -0
- package/dist/client/assets/palette-8_-Y5XON.js +1 -0
- package/dist/client/assets/plus-Cei21TlT.js +1 -0
- package/dist/client/assets/relativeTime-mmWGtWRR.js +1 -0
- package/dist/client/assets/relativeTime-mmWGtWRR.js.br +0 -0
- package/dist/client/assets/relativeTime-mmWGtWRR.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-BVDvDKeP.js +1 -0
- package/dist/client/assets/sourceCursorStore-BVDvDKeP.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-BVDvDKeP.js.gz +0 -0
- package/dist/client/assets/{spellCheck-P-fMO4iR.js → spellCheck-BTyLQAFH.js} +1 -1
- package/dist/client/assets/spellCheck-BTyLQAFH.js.br +0 -0
- package/dist/client/assets/spellCheck-BTyLQAFH.js.gz +0 -0
- package/dist/client/assets/{textLanguageSupport-BSIE7WPM.js → textLanguageSupport-Ck8lMOWz.js} +1 -1
- package/dist/client/assets/textLanguages-CwWstpJ5.js +78 -0
- package/dist/client/assets/textLanguages-CwWstpJ5.js.br +0 -0
- package/dist/client/assets/textLanguages-CwWstpJ5.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-Ba_yhkrl.js +1 -0
- package/dist/client/assets/useDeletionTransitions-Ba_yhkrl.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-Ba_yhkrl.js.gz +0 -0
- package/dist/client/assets/{vimSupport-BwIAfLU0.js → vimSupport-C-WiMLjc.js} +6 -6
- package/dist/client/assets/vimSupport-C-WiMLjc.js.br +0 -0
- package/dist/client/assets/vimSupport-C-WiMLjc.js.gz +0 -0
- package/dist/client/index.html +3 -3
- package/dist/server/agentChanges.js +149 -0
- package/dist/server/agents/sessions.js +1 -1
- package/dist/server/agents/workspaces.js +7 -27
- package/dist/server/app.js +15 -6
- package/dist/server/boundedExpiringCache.js +69 -0
- package/dist/server/citationFolderTransfer.js +5 -5
- package/dist/server/citationInput.js +1 -0
- package/dist/server/collaboration.js +39 -5
- package/dist/server/db.js +23 -0
- package/dist/server/editHistory.js +71 -12
- package/dist/server/git.js +58 -7
- package/dist/server/history.js +58 -9
- package/dist/server/i18n.js +9 -0
- package/dist/server/locales/zh-Hant.js +5 -0
- package/dist/server/projectPreview.js +8 -12
- package/dist/server/projectReferences.js +110 -9
- package/dist/server/projectReplace.js +67 -0
- package/dist/server/projectSearch.js +72 -0
- package/dist/server/routes/auth.js +3 -0
- package/dist/server/routes/citations.js +28 -61
- package/dist/server/routes/commentSuggestions.js +1 -1
- package/dist/server/routes/comments.js +8 -3
- package/dist/server/routes/projectGit.js +10 -0
- package/dist/server/routes/projectHistory.js +42 -0
- package/dist/server/routes/projectSearch.js +72 -0
- package/dist/server/routes/projects.js +1 -2
- package/dist/server/routes/users.js +2 -2
- package/dist/shared/bibtexBraces.js +20 -0
- package/dist/shared/bibtexNames.js +82 -0
- package/dist/shared/bibtexReferences.js +52 -12
- package/dist/shared/bibtexText.js +175 -0
- package/dist/shared/gitProtocol.js +2 -0
- package/dist/shared/historyProtocol.js +5 -0
- package/dist/shared/projectSearch.js +17 -0
- package/dist/shared/textDiff.js +36 -1
- package/package.json +1 -1
- package/dist/client/assets/AdminUsers-BghRo_hC.js +0 -1
- package/dist/client/assets/AdminUsers-BghRo_hC.js.br +0 -0
- package/dist/client/assets/AdminUsers-BghRo_hC.js.gz +0 -0
- package/dist/client/assets/AgentIcon-dCMgWJG-.css.br +0 -0
- package/dist/client/assets/AgentIcon-dCMgWJG-.css.gz +0 -0
- package/dist/client/assets/AgentManagement-rIYtm4Bo.js.br +0 -0
- package/dist/client/assets/AgentManagement-rIYtm4Bo.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-BEjiw51y.js +0 -2
- package/dist/client/assets/AgentTerminal-BEjiw51y.js.br +0 -0
- package/dist/client/assets/AgentTerminal-BEjiw51y.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-B2rwONYs.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-B2rwONYs.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-DplRpiJJ.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-DplRpiJJ.js.gz +0 -0
- package/dist/client/assets/CitationBibtexEditor-BnK6nZPi.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-CZvJiTmT.js +0 -3
- package/dist/client/assets/CitationLibraryDialog-CZvJiTmT.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-CZvJiTmT.js.gz +0 -0
- package/dist/client/assets/CitationNotesPreview-CiIzdjCa.js +0 -36
- package/dist/client/assets/CitationNotesPreview-CiIzdjCa.js.br +0 -0
- package/dist/client/assets/CitationNotesPreview-CiIzdjCa.js.gz +0 -0
- package/dist/client/assets/Dashboard-Dcl0Y_C3.js +0 -5
- package/dist/client/assets/Dashboard-Dcl0Y_C3.js.br +0 -0
- package/dist/client/assets/Dashboard-Dcl0Y_C3.js.gz +0 -0
- package/dist/client/assets/GitDialog-BeYvUCDv.js +0 -3
- package/dist/client/assets/GitDialog-BeYvUCDv.js.br +0 -0
- package/dist/client/assets/GitDialog-BeYvUCDv.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-BGKINOwJ.js +0 -1
- package/dist/client/assets/GitHubAccountDialog-BGKINOwJ.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-BGKINOwJ.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-B-C4Zaef.js +0 -8
- package/dist/client/assets/HistoryDialog-B-C4Zaef.js.br +0 -0
- package/dist/client/assets/HistoryDialog-B-C4Zaef.js.gz +0 -0
- package/dist/client/assets/InfoPopover-Dkz742vJ.js +0 -1
- package/dist/client/assets/LatexEditor-CohUJrGD.js +0 -25
- package/dist/client/assets/LatexEditor-CohUJrGD.js.br +0 -0
- package/dist/client/assets/LatexEditor-CohUJrGD.js.gz +0 -0
- package/dist/client/assets/PdfPreview-BvJxduy3.js +0 -1
- package/dist/client/assets/PdfPreview-BvJxduy3.js.br +0 -0
- package/dist/client/assets/PdfPreview-BvJxduy3.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-B9_XvdIC.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-B9_XvdIC.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-D8uH3PqQ.js +0 -4
- package/dist/client/assets/ProjectSettings-D8uH3PqQ.js.br +0 -0
- package/dist/client/assets/ProjectSettings-D8uH3PqQ.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-BZj-CRZB.js +0 -31
- package/dist/client/assets/ProjectWorkspace-BZj-CRZB.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-BZj-CRZB.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-B9bf5mnw.js +0 -1
- package/dist/client/assets/QuickOpenDialog-B9bf5mnw.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-B9bf5mnw.js.gz +0 -0
- package/dist/client/assets/ReadOnlySource-BZ7WYQO7.js +0 -2
- package/dist/client/assets/SelectionHistoryDialog-DYQb9hXp.js +0 -3
- package/dist/client/assets/SelectionHistoryDialog-DYQb9hXp.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-DYQb9hXp.js.gz +0 -0
- package/dist/client/assets/SharedProjectPage-DJjR-D8d.js +0 -2
- package/dist/client/assets/SharedProjectPage-DJjR-D8d.js.br +0 -0
- package/dist/client/assets/SharedProjectPage-DJjR-D8d.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-BExTHWxg.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-BExTHWxg.js.gz +0 -0
- package/dist/client/assets/TagManagementDialog-BBOpD_62.js +0 -1
- package/dist/client/assets/TagManagementDialog-BBOpD_62.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-BBOpD_62.js.gz +0 -0
- package/dist/client/assets/ThemeSwitcher-BTDUp7Wj.js +0 -1
- package/dist/client/assets/ThemeSwitcher-BTDUp7Wj.js.br +0 -0
- package/dist/client/assets/ThemeSwitcher-BTDUp7Wj.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-CgDcnPdJ.js.br +0 -0
- package/dist/client/assets/WordCountDialog-CgDcnPdJ.js.gz +0 -0
- package/dist/client/assets/bibtexFormatterWorker-B_jvobIv.js.br +0 -0
- package/dist/client/assets/bibtexFormatterWorker-B_jvobIv.js.gz +0 -0
- package/dist/client/assets/citationLibrary-BzlqZiFU.js +0 -26
- package/dist/client/assets/citationLibrary-BzlqZiFU.js.br +0 -0
- package/dist/client/assets/citationLibrary-BzlqZiFU.js.gz +0 -0
- package/dist/client/assets/clipboard-CslquMx4.js +0 -1
- package/dist/client/assets/dist-Bcdl4EAC.js +0 -1
- package/dist/client/assets/dist-Bcdl4EAC.js.br +0 -0
- package/dist/client/assets/dist-Bcdl4EAC.js.gz +0 -0
- package/dist/client/assets/editor-JqCouYk8.js +0 -14
- package/dist/client/assets/editor-JqCouYk8.js.br +0 -0
- package/dist/client/assets/editor-JqCouYk8.js.gz +0 -0
- package/dist/client/assets/editor-languages-CRI2h3Fj.js +0 -36
- package/dist/client/assets/editor-languages-CRI2h3Fj.js.br +0 -0
- package/dist/client/assets/editor-languages-CRI2h3Fj.js.gz +0 -0
- package/dist/client/assets/editorThemeExtension-BNWs0sHh.js +0 -1
- package/dist/client/assets/editorThemeExtension-BNWs0sHh.js.br +0 -0
- package/dist/client/assets/editorThemeExtension-BNWs0sHh.js.gz +0 -0
- package/dist/client/assets/eye-BnslGpqB.js +0 -1
- package/dist/client/assets/i18n-Bv4wFb8D.js +0 -13
- package/dist/client/assets/i18n-Bv4wFb8D.js.br +0 -0
- package/dist/client/assets/i18n-Bv4wFb8D.js.gz +0 -0
- package/dist/client/assets/index-Bdb2ITID.js +0 -2
- package/dist/client/assets/index-Bdb2ITID.js.br +0 -0
- package/dist/client/assets/index-Bdb2ITID.js.gz +0 -0
- package/dist/client/assets/index-wqKiaXZr.css +0 -1
- package/dist/client/assets/index-wqKiaXZr.css.br +0 -0
- package/dist/client/assets/index-wqKiaXZr.css.gz +0 -0
- package/dist/client/assets/katex-CBRBI6nR.js +0 -257
- package/dist/client/assets/katex-CBRBI6nR.js.br +0 -0
- package/dist/client/assets/katex-CBRBI6nR.js.gz +0 -0
- package/dist/client/assets/latexFormatterWorker-BIDCSZPd.js.br +0 -0
- package/dist/client/assets/latexFormatterWorker-BIDCSZPd.js.gz +0 -0
- package/dist/client/assets/relativeTime-DlKXhH_h.js +0 -1
- package/dist/client/assets/relativeTime-DlKXhH_h.js.br +0 -0
- package/dist/client/assets/relativeTime-DlKXhH_h.js.gz +0 -0
- package/dist/client/assets/sourceCursorStore-C7u-3Gbl.js +0 -1
- package/dist/client/assets/sourceCursorStore-C7u-3Gbl.js.br +0 -0
- package/dist/client/assets/sourceCursorStore-C7u-3Gbl.js.gz +0 -0
- package/dist/client/assets/spellCheck-P-fMO4iR.js.br +0 -0
- package/dist/client/assets/spellCheck-P-fMO4iR.js.gz +0 -0
- package/dist/client/assets/tags-GrE3ZIQN.js +0 -1
- package/dist/client/assets/textLanguages-DAJ1OXJA.js +0 -78
- package/dist/client/assets/textLanguages-DAJ1OXJA.js.br +0 -0
- package/dist/client/assets/textLanguages-DAJ1OXJA.js.gz +0 -0
- package/dist/client/assets/useDeletionTransitions-TAZINdHX.js +0 -1
- package/dist/client/assets/useDeletionTransitions-TAZINdHX.js.br +0 -0
- package/dist/client/assets/useDeletionTransitions-TAZINdHX.js.gz +0 -0
- package/dist/client/assets/vimSupport-BwIAfLU0.js.br +0 -0
- package/dist/client/assets/vimSupport-BwIAfLU0.js.gz +0 -0
- /package/dist/client/assets/{AgentIcon-DsoMeMA8.js → AgentIcon-CA-PfOka.js} +0 -0
- /package/dist/client/assets/{AgentIcon-DsoMeMA8.js.br → AgentIcon-CA-PfOka.js.br} +0 -0
- /package/dist/client/assets/{AgentIcon-DsoMeMA8.js.gz → AgentIcon-CA-PfOka.js.gz} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./spellCheck-BTyLQAFH.js","./index-CPR6YZEf.js","./rolldown-runtime-XKyaHtl9.js","./react-DUEFWlB7.js","./useTranslation-DwkoADSz.js","./i18nInstance-CIMFwH0l.js","./i18n-Dtn6w-qA.js","./basePath-B5-c90eh.js","./vite-runtime-CRzLMJPS.js","./createLucideIcon-CDYIzuiB.js","./loader-circle-DKGyi5EK.js","./dist-DdUqlCPw.js","./es2015-D2UDOM09.js","./index-BbU2fbRw.css","./chktex-BrzPYHey.js","./LatexEditor-Boc-45KL.js","./useDeletionTransitions-Ba_yhkrl.js","./dist-B_WjsTVV.js","./editor-CkUEg2La.js","./editorThemeExtension-BWtZV1Af.js","./generatedParser-CZa2vsK6.js","./latexScanner-D9bMX44Y.js","./citationAuthors-BWHXhKvT.js","./bibtexNames-CPGbBJxd.js","./bibtexReferences-xpSF8IXH.js","./textLanguages-CwWstpJ5.js","./MarkdownPreview-BH2iwvle.js","./MarkdownContent-BeKi2gI5.js","./katex.min-VLoWtPY0.js","./katex-CvRo0776.css","./katex-Ca9qmXPj.js","./CitationLibraryDialog-DgOIkLwK.js","./relativeTime-mmWGtWRR.js","./check-Dw16EqG-.js","./chevron-up-BHaMUEEA.js","./TagMarquee-BLmCTTCt.js","./InfoPopover-Ba7GvcuW.js","./library-big-B8e_Fiql.js","./plus-Cei21TlT.js","./SaveButton-wiTpGLho.js","./circle-check-CunlnBPw.js","./search-DjOWqLig.js","./dist-C9O-A_C4.js","./citationLibrary-DxGdbZEQ.js","./SuccessNotice-ubBtzzi_.js","./TagColorSelect-e-Tq5V3H.js","./GitDialog-DGzZ3GRj.js","./GitHubIcon-CExJn0AV.js","./git-compare-arrows-158rS_vn.js","./minimize-2-CkBmeGXp.js","./minus-DrpwqY8Y.js","./HistoryDialog-DTZxCgyT.js","./clock-3-DztJubz_.js","./sourceCursorStore-BVDvDKeP.js","./hard-drive-CXlummIE.js","./dist-Dxkdrap6.js","./SelectionHistoryDialog-Dnj22E8N.js","./bot-ClmnQ29j.js","./QuickOpenDialog-CHjPlBu2.js","./ProjectSearchDialog-DPIzxVYj.js","./ProjectSettings-ChXx_cmP.js","./palette-8_-Y5XON.js","./refresh-cw-IqExWG6S.js","./terminal-DD9WJ56e.js","./type-CKe1tHHo.js","./AgentTerminal-CvOz5X_j.js","./AgentIcon-CA-PfOka.js","./AgentIcon-DeoZDwgh.css","./WordCountDialog-DI0Jv-fg.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{n as e,r as t}from"./rolldown-runtime-XKyaHtl9.js";import{i as n,r,t as i}from"./react-DUEFWlB7.js";import{_ as a,b as o,g as s,h as c,i as l,m as u,n as d,p as f,t as p,u as m,v as h,x as g,y as _}from"./relativeTime-mmWGtWRR.js";import{t as v}from"./useTranslation-DwkoADSz.js";import{t as y}from"./i18n-Dtn6w-qA.js";import{r as b,t as x}from"./basePath-B5-c90eh.js";import{t as S}from"./vite-runtime-CRzLMJPS.js";import{t as C}from"./createLucideIcon-CDYIzuiB.js";import{t as w}from"./arrow-down-C_4f1E-E.js";import{B as T,D as E,E as D,H as O,P as k,R as A,S as j,T as M,U as ee,_ as N,b as P,c as te,d as F,h as I,j as L,k as ne,m as R,o as re,p as ie,s as z,u as ae,v as oe,w as se,x as B,y as ce,z as V}from"./useDeletionTransitions-Ba_yhkrl.js";import{t as H}from"./check-Dw16EqG-.js";import{o as U}from"./dist-B_WjsTVV.js";import{t as le}from"./chevron-up-BHaMUEEA.js";import{t as ue}from"./circle-check-CunlnBPw.js";import{C as de,D as fe,E as pe,O as me,S as he,_ as ge,b as _e,c as ve,d as ye,f as be,g as xe,h as Se,l as Ce,m as we,n as Te,o as Ee,p as De,r as Oe,s as ke,t as Ae,u as je,v as Me,w as Ne,x as Pe,y as Fe}from"./sourceCursorStore-BVDvDKeP.js";import{t as Ie}from"./InfoPopover-Ba7GvcuW.js";import{t as Le}from"./loader-circle-DKGyi5EK.js";import{t as Re}from"./plus-Cei21TlT.js";import{t as ze}from"./refresh-cw-IqExWG6S.js";import{t as Be}from"./SaveButton-wiTpGLho.js";import{t as Ve}from"./user-plus-NNBQOWDP.js";import{C as He,D as W,E as Ue,O as We,S as Ge,a as G,c as Ke,f as qe,g as Je,h as Ye,k as Xe,l as Ze,m as Qe,o as $e,s as et,u as tt,w as K,y as q}from"./index-CPR6YZEf.js";import{a as nt,l as rt,n as it,r as at,t as ot}from"./dist-C9O-A_C4.js";import{a as st,c as ct,h as lt,m as ut,n as dt,p as ft,s as pt,t as mt}from"./latexScanner-D9bMX44Y.js";import{r as ht}from"./dist-Dxkdrap6.js";var gt={name:`arrow-right`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]};gt.node;var _t=C(gt),vt={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};vt.node;var yt=C(vt),bt={name:`circle-question-mark`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`help-circle`,`circle-help`]};bt.node;var xt=C(bt),St={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};St.node;var Ct=C(St),wt={name:`eraser`,size:24,node:[[`path`,{d:`M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21`,key:`g5wo59`}],[`path`,{d:`m5.082 11.09 8.828 8.828`,key:`1wx5vj`}]]};wt.node;var Tt=C(wt),Et={name:`keyboard`,size:24,node:[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]};Et.node;var Dt=C(Et),Ot={name:`link`,size:24,node:[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]};Ot.node;var kt=C(Ot),At={name:`logs`,size:24,node:[[`path`,{d:`M3 5h1`,key:`1mv5vm`}],[`path`,{d:`M3 12h1`,key:`lp3yf2`}],[`path`,{d:`M3 19h1`,key:`w6f3n9`}],[`path`,{d:`M8 5h1`,key:`1nxr5w`}],[`path`,{d:`M8 12h1`,key:`1con00`}],[`path`,{d:`M8 19h1`,key:`k7p10e`}],[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}]]};At.node;var jt=C(At),Mt={name:`messages-square`,size:24,node:[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]};Mt.node;var Nt=C(Mt),Pt={name:`package-open`,size:24,node:[[`path`,{d:`M12 22v-9`,key:`x3hkom`}],[`path`,{d:`M15.17 2.21a1.67 1.67 0 0 1 1.63 0L21 4.57a1.93 1.93 0 0 1 0 3.36L8.82 14.79a1.655 1.655 0 0 1-1.64 0L3 12.43a1.93 1.93 0 0 1 0-3.36z`,key:`2ntwy6`}],[`path`,{d:`M20 13v3.87a2.06 2.06 0 0 1-1.11 1.83l-6 3.08a1.93 1.93 0 0 1-1.78 0l-6-3.08A2.06 2.06 0 0 1 4 16.87V13`,key:`1pmm1c`}],[`path`,{d:`M21 12.43a1.93 1.93 0 0 0 0-3.36L8.83 2.2a1.64 1.64 0 0 0-1.63 0L3 4.57a1.93 1.93 0 0 0 0 3.36l12.18 6.86a1.636 1.636 0 0 0 1.63 0z`,key:`12ttoo`}]]};Pt.node;var Ft=C(Pt),It={name:`rotate-ccw`,size:24,node:[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]};It.node;var Lt=C(It),Rt={name:`send`,size:24,node:[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]};Rt.node;var zt=C(Rt),J=t(n(),1),Y=i(),Bt=()=>new Map,Vt=e=>{let t=Bt();return e.forEach((e,n)=>{t.set(n,e)}),t},Ht=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},Ut=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},Wt=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},Gt=()=>new Set,Kt=e=>e[e.length-1],qt=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Jt=Array.from,Yt=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Xt=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Zt=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},Qt=Array.isArray,$t=class{constructor(){this._observers=Bt()}on(e,t){return Ht(this._observers,e,Gt).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Jt((this._observers.get(e)||Bt()).values()).forEach(e=>e(...t))}destroy(){this._observers=Bt()}},en=class{constructor(){this._observers=Bt()}on(e,t){Ht(this._observers,e,Gt).add(t)}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return Jt((this._observers.get(e)||Bt()).values()).forEach(e=>e(...t))}destroy(){this._observers=Bt()}},tn=Math.floor,nn=Math.abs,rn=(e,t)=>e<t?e:t,an=(e,t)=>e>t?e:t;Number.isNaN;var on=Math.pow,sn=e=>e===0?1/e<0:e<0,cn=1<<29,ln=2**53-1,un=-(2**53-1),dn=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&tn(e)===e);Number.isNaN,Number.parseInt;var fn=String.fromCharCode;String.fromCodePoint,fn(65535);var pn=e=>e.toLowerCase(),mn=/^\s*/g,hn=e=>e.replace(mn,``),gn=/([A-Z])/g,_n=(e,t)=>hn(e.replace(gn,e=>`${t}${pn(e)}`)),vn=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},yn=typeof TextEncoder<`u`?new TextEncoder:null,bn=yn?e=>yn.encode(e):vn,xn=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});xn&&xn.decode(new Uint8Array).length===1&&(xn=null);var Sn=(e,t)=>Zt(t,()=>e).join(``),Cn=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},X=()=>new Cn,wn=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},Tn=e=>{let t=new Uint8Array(wn(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},En=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(an(n,t)*2),e.cpos=0)},Dn=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},On=Dn,Z=(e,t)=>{for(;t>127;)Dn(e,128|127&t),t=tn(t/128);Dn(e,127&t)},kn=(e,t)=>{let n=sn(t);for(n&&(t=-t),Dn(e,(t>63?128:0)|(n?64:0)|63&t),t=tn(t/64);t>0;)Dn(e,(t>127?128:0)|127&t),t=tn(t/128)},An=new Uint8Array(3e4),jn=An.length/3,Mn=yn&&yn.encodeInto?(e,t)=>{if(t.length<jn){let n=yn.encodeInto(t,An).written||0;Z(e,n);for(let t=0;t<n;t++)Dn(e,An[t])}else Pn(e,bn(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;Z(e,r);for(let t=0;t<r;t++)Dn(e,n.codePointAt(t))},Nn=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=rn(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(an(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},Pn=(e,t)=>{Z(e,t.byteLength),Nn(e,t)},Fn=(e,t)=>{En(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},In=(e,t)=>Fn(e,4).setFloat32(0,t,!1),Ln=(e,t)=>Fn(e,8).setFloat64(0,t,!1),Rn=(e,t)=>Fn(e,8).setBigInt64(0,t,!1),zn=new DataView(new ArrayBuffer(4)),Bn=e=>(zn.setFloat32(0,e),zn.getFloat32(0)===e),Vn=(e,t)=>{switch(typeof t){case`string`:Dn(e,119),Mn(e,t);break;case`number`:dn(t)&&nn(t)<=2147483647?(Dn(e,125),kn(e,t)):Bn(t)?(Dn(e,124),In(e,t)):(Dn(e,123),Ln(e,t));break;case`bigint`:Dn(e,122),Rn(e,t);break;case`object`:if(t===null)Dn(e,126);else if(Qt(t)){Dn(e,117),Z(e,t.length);for(let n=0;n<t.length;n++)Vn(e,t[n])}else if(t instanceof Uint8Array)Dn(e,116),Pn(e,t);else{Dn(e,118);let n=Object.keys(t);Z(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];Mn(e,i),Vn(e,t[i])}}break;case`boolean`:Dn(e,t?120:121);break;default:Dn(e,127)}},Hn=class extends Cn{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&Z(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},Un=e=>{e.count>0&&(kn(e.encoder,e.count===1?e.s:-e.s),e.count>1&&Z(e.encoder,e.count-2))},Wn=class{constructor(){this.encoder=new Cn,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Un(this),this.count=1,this.s=e)}toUint8Array(){return Un(this),Tn(this.encoder)}},Gn=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);kn(e.encoder,t),e.count>1&&Z(e.encoder,e.count-2)}},Kn=class{constructor(){this.encoder=new Cn,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Gn(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Gn(this),Tn(this.encoder)}},qn=class{constructor(){this.sarr=[],this.s=``,this.lensE=new Wn}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new Cn;return this.sarr.push(this.s),this.s=``,Mn(e,this.sarr.join(``)),Nn(e,this.lensE.toUint8Array()),Tn(e)}},Jn=e=>Error(e),Yn=()=>{throw Jn(`Method unimplemented`)},Xn=()=>{throw Jn(`Unexpected case`)},Zn=Jn(`Unexpected end of array`),Qn=Jn(`Integer out of Range`),$n=class{constructor(e){this.arr=e,this.pos=0}},er=e=>new $n(e),tr=e=>e.pos!==e.arr.length,nr=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},rr=e=>nr(e,Q(e)),ir=e=>e.arr[e.pos++],Q=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>ln)throw Qn}throw Zn},ar=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>ln)throw Qn}throw Zn},or=xn?e=>xn.decode(rr(e)):e=>{let t=Q(e);if(t===0)return``;{let n=String.fromCodePoint(ir(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(ir(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},sr=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},cr=[e=>void 0,e=>null,ar,e=>sr(e,4).getFloat32(0,!1),e=>sr(e,8).getFloat64(0,!1),e=>sr(e,8).getBigInt64(0,!1),e=>!1,e=>!0,or,e=>{let t=Q(e),n={};for(let r=0;r<t;r++){let t=or(e);n[t]=lr(e)}return n},e=>{let t=Q(e),n=[];for(let r=0;r<t;r++)n.push(lr(e));return n},rr],lr=e=>cr[127-ir(e)](e),ur=class extends $n{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=tr(this)?Q(this)+1:-1),this.count--,this.s}},dr=class extends $n{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=ar(this);let e=sn(this.s);this.count=1,e&&(this.s=-this.s,this.count=Q(this)+2)}return this.count--,this.s}},fr=class extends $n{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=ar(this),t=e&1;this.diff=tn(e/2),this.count=1,t&&(this.count=Q(this)+2)}return this.s+=this.diff,this.count--,this.s}},pr=class{constructor(e){this.decoder=new dr(e),this.str=or(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;var mr=crypto.getRandomValues.bind(crypto),hr=()=>mr(new Uint32Array(1))[0],gr=`10000000-1000-4000-8000-100000000000`,_r=()=>gr.replace(/[018]/g,e=>(e^hr()&15>>e/4).toString(16)),vr=Date.now,yr=e=>new Promise(e);Promise.all.bind(Promise);var br=e=>e===void 0?null:e,xr=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}},Sr=!0;try{typeof localStorage<`u`&&localStorage&&(xr=localStorage,Sr=!1)}catch{}var Cr=xr,wr=e=>Sr||addEventListener(`storage`,e),Tr=e=>Sr||removeEventListener(`storage`,e),Er=Symbol(`Equality`),Dr=(e,t)=>e===t||!!e?.[Er]?.(t)||!1,Or=e=>typeof e==`object`,kr=Object.assign,Ar=Object.keys,jr=(e,t)=>{for(let n in e)t(e[n],n)},Mr=(e,t)=>{let n=[];for(let r in e)n.push(t(e[r],r));return n},Nr=e=>Ar(e).length,Pr=e=>{for(let t in e)return!1;return!0},Fr=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Ir=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Lr=(e,t)=>e===t||Nr(e)===Nr(t)&&Fr(e,(e,n)=>(e!==void 0||Ir(t,n))&&Dr(t[n],e)),Rr=Object.freeze,zr=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&zr(e[t])}return Rr(e)},Br=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Br(e,t,n+1)}},Vr=e=>e,Hr=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Er]!=null)return e[Er](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!Hr(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(Nr(e)!==Nr(t))return!1;for(let n in e)if(!Ir(e,n)||!Hr(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Hr(e[n],t[n]))return!1;break;default:return!1}return!0},Ur=(e,t)=>t.includes(e),Wr=typeof process<`u`&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`,Gr=typeof window<`u`&&typeof document<`u`&&!Wr;typeof navigator<`u`&&/Mac/.test(navigator.platform);var Kr,qr=[],Jr=()=>{if(Kr===void 0){if(Wr){Kr=Bt();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]===`-`?(t!==null&&Kr.set(t,``),t=r):t===null?qr.push(r):(Kr.set(t,r),t=null)}t!==null&&Kr.set(t,``)}else typeof location==`object`?(Kr=Bt(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);Kr.set(`--${_n(t,`-`)}`,n),Kr.set(`-${_n(t,`-`)}`,n)}})):Kr=Bt()}return Kr},Yr=e=>Jr().has(e),Xr=e=>br(Wr?{}[e.toUpperCase().replaceAll(`-`,`_`)]:Cr.getItem(e)),Zr=e=>Yr(`--`+e)||Xr(e)!==null,Qr=Zr(`production`),$r=Wr&&Ur({}.FORCE_COLOR,[`true`,`1`,`2`])||!Yr(`--no-colors`)&&!Zr(`no-color`)&&(!Wr||process.stdout.isTTY)&&(!Wr||Yr(`--color`)||Xr(`COLORTERM`)!==null||(Xr(`TERM`)||``).includes(`color`)),ei=e=>new Uint8Array(e),ti=(e,t,n)=>new Uint8Array(e,t,n),ni=e=>new Uint8Array(e),ri=e=>{let t=``;for(let n=0;n<e.byteLength;n++)t+=fn(e[n]);return btoa(t)},ii=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`),ai=e=>{let t=atob(e),n=ei(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n},oi=e=>{let t=Buffer.from(e,`base64`);return ti(t.buffer,t.byteOffset,t.byteLength)},si=Gr?ri:ii,ci=Gr?ai:oi,li=e=>{let t=ei(e.byteLength);return t.set(e),t},ui=class{constructor(e,t){this.left=e,this.right=t}},di=(e,t)=>new ui(e,t),fi=(e,t)=>e.forEach(e=>t(e.left,e.right)),pi=e=>e.next()>=.5,mi=(e,t,n)=>tn(e.next()*(n+1-t)+t),hi=(e,t,n)=>tn(e.next()*(n+1-t)+t),gi=(e,t,n)=>hi(e,t,n),_i=e=>fn(gi(e,97,122)),vi=(e,t=0,n=20)=>{let r=gi(e,t,n),i=``;for(let t=0;t<r;t++)i+=_i(e);return i},yi=(e,t)=>t[gi(e,0,t.length-1)],bi=Symbol(`0schema`),xi=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(Sn(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join(`
|
|
3
|
+
`)}},Si=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Er]?Dr(e,t):Qt(e)?Yt(e,e=>Xt(t,t=>Si(e,t))):Or(e)?Fr(e,(e,n)=>Si(e,t[n])):!1,Ci=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Si(t,n)}equals(e){return this.constructor===e.constructor&&Hr(this.shape,e.shape)}[bi](){return!0}[Er](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Yn()}get nullable(){return na(this,_a)}get optional(){return new Pi(this)}cast(e){return xa(e,this),e}expect(e){return xa(e,this),e}},wi=class extends Ci{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}},Ti=(e,t=null)=>new wi(e,t);Ti(wi);var Ei=class extends Ci{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}},Di=e=>new Ei(e);Ti(Ei);var Oi=class extends Ci{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}},ki=(...e)=>new Oi(e),Ai=Ti(Oi),ji=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>`\\`+e)),Mi=e=>{if(fa.check(e))return[ji(e)];if(Ai.check(e))return e.shape.map(e=>e+``);if(da.check(e))return[`[+-]?\\d+.?\\d*`];if(pa.check(e))return[`.*`];if(ra.check(e))return e.shape.map(Mi).flat(1);Xn()};Ti(class extends Ci{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Mi).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn't match string template.`),n}});var Ni=Symbol(`optional`),Pi=class extends Ci{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Ni](){return!0}},Fi=Ti(Pi),Ii=class extends Ci{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Ii,Ti(Ii);var Li=class e extends Ci{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):Fr(this.shape,(n,r)=>{let i=this._isPartial&&!Ir(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}},Ri=e=>new Li(e),zi=Ti(Li),Bi=Di(e=>e!=null&&(e.constructor===Object||e.constructor==null)),Vi=class extends Ci{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&Fr(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn't match schema`:`Value doesn't match value`),i&&this.shape.values.check(n,t)})}},Hi=(e,t)=>new Vi(e,t),Ui=Ti(Vi),Wi=class extends Ci{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&Fr(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}},Gi=(...e)=>new Wi(e);Ti(Wi);var Ki=class extends Ci{constructor(e){super(),this.shape=e.length===1?e[0]:new ta(e)}check(e,t){let n=Qt(e)&&Yt(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}},qi=(...e)=>new Ki(e),Ji=Ti(Ki),Yi=Di(e=>Qt(e)),Xi=class extends Ci{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},Zi=(e,t=null)=>new Xi(e,t);Ti(Xi);var Qi=Zi(Ci),$i=Ti(class extends Ci{constructor(e){super(),this.len=e.length-1,this.args=Gi(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),ea=Di(e=>typeof e==`function`);Ti(class extends Ci{constructor(e){super(),this.shape=e}check(e,t){let n=Yt(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var ta=class extends Ci{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=Xt(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}},na=(...e)=>e.findIndex(e=>ra.check(e))>=0?na(...e.map(e=>ba(e)).map(e=>ra.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new ta(e),ra=Ti(ta),ia=()=>!0,aa=Di(ia),oa=Ti(Ei,e=>e.shape===ia),sa=Di(e=>typeof e==`bigint`),ca=Di(e=>e===sa),la=Di(e=>typeof e==`symbol`);Di(e=>e===la);var ua=Di(e=>typeof e==`number`),da=Di(e=>e===ua),fa=Di(e=>typeof e==`string`),pa=Di(e=>e===fa),ma=Di(e=>typeof e==`boolean`),ha=Di(e=>e===ma),ga=ki(void 0);Ti(Oi,e=>e.shape.length===1&&e.shape[0]===void 0),ki(void 0);var _a=ki(null),va=Ti(Oi,e=>e.shape.length===1&&e.shape[0]===null);Ti(Uint8Array),Ti(wi,e=>e.shape===Uint8Array);var ya=na(ua,fa,_a,ga,sa,ma,la);(()=>{let e=qi(aa),t=Hi(fa,aa),n=na(ua,fa,_a,ma,e,t);return e.shape=n,t.shape.values=n,n})();var ba=e=>{if(Qi.check(e))return e;if(Bi.check(e)){let t={};for(let n in e)t[n]=ba(e[n]);return Ri(t)}if(Yi.check(e))return na(...e.map(ba));if(ya.check(e))return ki(e);if(ea.check(e))return Ti(e);Xn()},xa=Qr?()=>{}:(e,t)=>{let n=new xi;if(!t.check(e,n))throw Jn(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Sa=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:ba(e),h:t}),this}else(e){return this.if(aa,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Jn(`Unhandled pattern`)}}},Ca=(e=>new Sa(e))(aa).if(da,(e,t)=>mi(t,un,ln)).if(pa,(e,t)=>vi(t)).if(ha,(e,t)=>pi(t)).if(ca,(e,t)=>BigInt(mi(t,un,ln))).if(ra,(e,t)=>wa(t,yi(t,e.shape))).if(zi,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Fi.check(i)){if(pi(t))continue;i=i.shape}n[r]=Ca(i,t)}return n}).if(Ji,(e,t)=>{let n=[],r=hi(t,0,42);for(let i=0;i<r;i++)n.push(wa(t,e.shape));return n}).if(Ai,(e,t)=>yi(t,e.shape)).if(va,(e,t)=>null).if($i,(e,t)=>{let n=wa(t,e.res);return()=>n}).if(oa,(e,t)=>wa(t,yi(t,[ua,fa,_a,ga,sa,ma,qi(ua),Hi(na(`a`,`b`,`c`),ua)]))).if(Ui,(e,t)=>{let n={},r=mi(t,0,3);for(let i=0;i<r;i++){let r=wa(t,e.shape.keys);n[r]=wa(t,e.shape.values)}return n}).done(),wa=(e,t)=>Ca(ba(t),e),Ta=typeof document<`u`?document:{},Ea=e=>Ta.createElement(e),Da=()=>Ta.createDocumentFragment();Di(e=>e.nodeType===za);var Oa=e=>Ta.createTextNode(e);typeof DOMParser<`u`&&new DOMParser;var ka=(e,t)=>(fi(t,(t,n)=>{n===!1?e.removeAttribute(t):n===!0?e.setAttribute(t,``):e.setAttribute(t,n)}),e),Aa=e=>{let t=Da();for(let n=0;n<e.length;n++)Fa(t,e[n]);return t},ja=(e,t)=>(Fa(e,Aa(t)),e),Ma=(e,t=[],n=[])=>ja(ka(Ea(e),t),n);Di(e=>e.nodeType===Ia);var Na=Oa;Di(e=>e.nodeType===La);var Pa=e=>Ut(e,(e,t)=>`${t}:${e};`).join(``),Fa=(e,t)=>e.appendChild(t),Ia=Ta.ELEMENT_NODE,La=Ta.TEXT_NODE;Ta.CDATA_SECTION_NODE,Ta.COMMENT_NODE;var Ra=Ta.DOCUMENT_NODE;Ta.DOCUMENT_TYPE_NODE;var za=Ta.DOCUMENT_FRAGMENT_NODE;Di(e=>e.nodeType===Ra);var Ba=Symbol,Va=Ba(),Ha=Ba(),Ua=Ba(),Wa=Ba(),Ga=Ba(),Ka=Ba(),qa=Ba(),Ja=Ba(),Ya=Ba(),Xa=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};vr();var Za={[Va]:di(`font-weight`,`bold`),[Ha]:di(`font-weight`,`normal`),[Ua]:di(`color`,`blue`),[Ga]:di(`color`,`green`),[Wa]:di(`color`,`grey`),[Ka]:di(`color`,`red`),[qa]:di(`color`,`purple`),[Ja]:di(`color`,`orange`),[Ya]:di(`color`,`black`)},Qa=$r?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=Bt(),i=[],a=0;for(;a<e.length;a++){let i=e[a],o=Za[i];if(o!==void 0)r.set(o.left,o.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){let e=Pa(r);a>0||e.length>0?(t.push(`%c`+i),n.push(e)):t.push(i)}else break}}for(a>0&&(i=n,i.unshift(t.join(``)));a<e.length;a++){let t=e[a];t instanceof Symbol||i.push(t)}return i}:Xa,$a=(...e)=>{console.log(...Qa(e)),to.forEach(t=>t.print(e))},eo=(...e)=>{console.warn(...Qa(e)),e.unshift(Ja),to.forEach(t=>t.print(e))},to=Gt(),no=e=>({[Symbol.iterator](){return this},next:e}),ro=(e,t)=>no(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),io=(e,t)=>no(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),ao=class{constructor(e,t){this.clock=e,this.len=t}},oo=class{constructor(){this.clients=new Map}},so=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])ws(e,i,o.clock,o.len,n)}}),co=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=tn((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},lo=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&co(n,t.clock)!==null},uo=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new ao(r.clock,an(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},fo=e=>{let t=new oo;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)qt(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return uo(t),t},po=(e,t,n,r)=>{Ht(e.clients,t,()=>[]).push(new ao(n,r))},mo=()=>new oo,ho=e=>{let t=mo();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new ao(i,a))}}r.length>0&&t.clients.set(n,r)}),t},go=(e,t)=>{Z(e.restEncoder,t.clients.size),Jt(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),Z(e.restEncoder,t);let r=n.length;Z(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},_o=e=>{let t=new oo,n=Q(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let n=Q(e.restDecoder),r=Q(e.restDecoder);if(r>0){let i=Ht(t.clients,n,()=>[]);for(let t=0;t<r;t++)i.push(new ao(e.readDsClock(),e.readDsLen()))}}return t},vo=(e,t,n)=>{let r=new oo,i=Q(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=Q(e.restDecoder),a=Q(e.restDecoder),o=n.clients.get(i)||[],s=gs(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&po(r,i,s,a-s);let e=vs(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Bl(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Bl(t,c,a-c.id.clock)),c.delete(t))}else po(r,i,n,a-n)}}if(r.clients.size>0){let e=new Oo;return Z(e.restEncoder,0),go(e,r),e.toUint8Array()}return null},yo=hr,bo=class e extends $t{constructor({guid:e=_r(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=yo(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new ms,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=yr(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>yr(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&Ms(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Jt(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Ms(this,e,t)}get(e,t=cc){let n=Ht(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==cc&&r!==t){if(r===cc){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Oc)}getText(e=``){return this.get(e,Yc)}getMap(e=``){return this.get(e,jc)}getXmlElement(e=``){return this.get(e,el)}getXmlFragment(e=``){return this.get(e,Qc)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Jt(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ms(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},xo=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return Q(this.restDecoder)}readDsLen(){return Q(this.restDecoder)}},So=class extends xo{readLeftID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readRightID(){return $(Q(this.restDecoder),Q(this.restDecoder))}readClient(){return Q(this.restDecoder)}readInfo(){return ir(this.restDecoder)}readString(){return or(this.restDecoder)}readParentInfo(){return Q(this.restDecoder)===1}readTypeRef(){return Q(this.restDecoder)}readLen(){return Q(this.restDecoder)}readAny(){return lr(this.restDecoder)}readBuf(){return li(rr(this.restDecoder))}readJSON(){return JSON.parse(or(this.restDecoder))}readKey(){return or(this.restDecoder)}},Co=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Q(this.restDecoder),this.dsCurrVal}readDsLen(){let e=Q(this.restDecoder)+1;return this.dsCurrVal+=e,e}},wo=class extends Co{constructor(e){super(e),this.keys=[],Q(e),this.keyClockDecoder=new fr(rr(e)),this.clientDecoder=new dr(rr(e)),this.leftClockDecoder=new fr(rr(e)),this.rightClockDecoder=new fr(rr(e)),this.infoDecoder=new ur(rr(e),ir),this.stringDecoder=new pr(rr(e)),this.parentInfoDecoder=new ur(rr(e),ir),this.typeRefDecoder=new dr(rr(e)),this.lenDecoder=new dr(rr(e))}readLeftID(){return new Zo(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Zo(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 lr(this.restDecoder)}readBuf(){return rr(this.restDecoder)}readJSON(){return lr(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},To=class{constructor(){this.restEncoder=X()}toUint8Array(){return Tn(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Z(this.restEncoder,e)}writeDsLen(e){Z(this.restEncoder,e)}},Eo=class extends To{writeLeftID(e){Z(this.restEncoder,e.client),Z(this.restEncoder,e.clock)}writeRightID(e){Z(this.restEncoder,e.client),Z(this.restEncoder,e.clock)}writeClient(e){Z(this.restEncoder,e)}writeInfo(e){On(this.restEncoder,e)}writeString(e){Mn(this.restEncoder,e)}writeParentInfo(e){Z(this.restEncoder,+!!e)}writeTypeRef(e){Z(this.restEncoder,e)}writeLen(e){Z(this.restEncoder,e)}writeAny(e){Vn(this.restEncoder,e)}writeBuf(e){Pn(this.restEncoder,e)}writeJSON(e){Mn(this.restEncoder,JSON.stringify(e))}writeKey(e){Mn(this.restEncoder,e)}},Do=class{constructor(){this.restEncoder=X(),this.dsCurrVal=0}toUint8Array(){return Tn(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,Z(this.restEncoder,t)}writeDsLen(e){e===0&&Xn(),Z(this.restEncoder,e-1),this.dsCurrVal+=e}},Oo=class extends Do{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Kn,this.clientEncoder=new Wn,this.leftClockEncoder=new Kn,this.rightClockEncoder=new Kn,this.infoEncoder=new Hn(On),this.stringEncoder=new qn,this.parentInfoEncoder=new Hn(On),this.typeRefEncoder=new Wn,this.lenEncoder=new Wn}toUint8Array(){let e=X();return Z(e,0),Pn(e,this.keyClockEncoder.toUint8Array()),Pn(e,this.clientEncoder.toUint8Array()),Pn(e,this.leftClockEncoder.toUint8Array()),Pn(e,this.rightClockEncoder.toUint8Array()),Pn(e,Tn(this.infoEncoder)),Pn(e,this.stringEncoder.toUint8Array()),Pn(e,Tn(this.parentInfoEncoder)),Pn(e,this.typeRefEncoder.toUint8Array()),Pn(e,this.lenEncoder.toUint8Array()),Nn(e,Tn(this.restEncoder)),Tn(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Vn(this.restEncoder,e)}writeBuf(e){Pn(this.restEncoder,e)}writeJSON(e){Vn(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},ko=(e,t,n,r)=>{r=an(r,t[0].id.clock);let i=vs(t,r);Z(e.restEncoder,t.length-i),e.writeClient(n),Z(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},Ao=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{gs(t,n)>e&&r.set(n,e)}),hs(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),Z(e.restEncoder,r.size),Jt(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{ko(e,t.clients.get(n),n,r)})},jo=(e,t)=>{let n=Bt(),r=Q(e.restDecoder);for(let i=0;i<r;i++){let r=Q(e.restDecoder),i=Array(r),a=e.readClient(),o=Q(e.restDecoder);n.set(a,{i:0,refs:i});for(let n=0;n<r;n++){let r=e.readInfo();switch(31&r){case 0:{let t=e.readLen();i[n]=new ll($(a,o),t),o+=t;break}case 10:{let t=Q(e.restDecoder);i[n]=new ql($(a,o),t),o+=t;break}default:{let s=!(r&192),c=new Ul($(a,o),null,(r&128)==128?e.readLeftID():null,null,(r&64)==64?e.readRightID():null,s?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,s&&(r&32)==32?e.readString():null,Wl(e,r));i[n]=c,o+=c.length}}}}return n},Mo=(e,t,n)=>{let r=[],i=Jt(n.keys()).sort((e,t)=>e-t);if(i.length===0)return null;let a=()=>{if(i.length===0)return null;let e=n.get(i[i.length-1]);for(;e.refs.length===e.i;)if(i.pop(),i.length>0)e=n.get(i[i.length-1]);else return null;return e},o=a();if(o===null)return null;let s=new ms,c=new Map,l=(e,t)=>{let n=c.get(e);(n==null||n>t)&&c.set(e,t)},u=o.refs[o.i++],d=new Map,f=()=>{for(let e of r){let t=e.id.client,r=n.get(t);r?(r.i--,s.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):s.clients.set(t,[e]),i=i.filter(e=>e!==t)}r.length=0};for(;;){if(u.constructor!==ql){let i=Ht(d,u.id.client,()=>gs(t,u.id.client))-u.id.clock;if(i<0)r.push(u),l(u.id.client,u.id.clock-1),f();else{let a=u.getMissing(e,t);if(a!==null){r.push(u);let e=n.get(a)||{refs:[],i:0};if(e.refs.length===e.i)l(a,gs(t,a)),f();else{u=e.refs[e.i++];continue}}else(i===0||i<u.length)&&(u.integrate(e,i),d.set(u.id.client,u.id.clock+u.length))}}if(r.length>0)u=r.pop();else if(o!==null&&o.i<o.refs.length)u=o.refs[o.i++];else{if(o=a(),o===null)break;u=o.refs[o.i++]}}if(s.clients.size>0){let e=new Oo;return Ao(e,s,new Map),Z(e.restEncoder,0),{missing:c,update:e.toUint8Array()}}return null},No=(e,t)=>Ao(e,t.doc.store,t.beforeState),Po=(e,t,n,r=new wo(e))=>Ms(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Mo(e,i,jo(r,n)),o=i.pendingStructs;if(o){for(let[e,n]of o.missing)if(n<gs(i,e)){t=!0;break}if(a){for(let[e,t]of a.missing){let n=o.missing.get(e);(n==null||n>t)&&o.missing.set(e,t)}o.update=Hs([o.update,a.update])}}else i.pendingStructs=a;let s=vo(r,e,i);if(i.pendingDs){let t=new wo(er(i.pendingDs));Q(t.restDecoder);let n=vo(t,e,i);i.pendingDs=s&&n?Hs([s,n]):s||n}else i.pendingDs=s;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Fo(e.doc,t)}},n,!1),Fo=(e,t,n,r=wo)=>{let i=er(t);Po(i,e,n,new r(i))},Io=(e,t,n)=>Fo(e,t,n,So),Lo=(e,t,n=new Map)=>{Ao(e,t.store,n),go(e,ho(t.store))},Ro=(e,t=new Uint8Array([0]),n=new Oo)=>{Lo(n,e,Vo(t));let r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(Us(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Eo)return Bs(r.map((e,t)=>t===0?e:Js(e)));if(n.constructor===Oo)return Hs(r)}return r[0]},zo=(e,t)=>Ro(e,t,new Eo),Bo=e=>{let t=new Map,n=Q(e.restDecoder);for(let r=0;r<n;r++){let n=Q(e.restDecoder),r=Q(e.restDecoder);t.set(n,r)}return t},Vo=e=>Bo(new xo(er(e))),Ho=(e,t)=>(Z(e.restEncoder,t.size),Jt(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{Z(e.restEncoder,t),Z(e.restEncoder,n)}),e),Uo=(e,t)=>Ho(e,hs(t.store)),Wo=(e,t=new Do)=>(e instanceof Map?Ho(t,e):Uo(t,e),t.toUint8Array()),Go=e=>Wo(e,new To),Ko=class{constructor(){this.l=[]}},qo=()=>new Ko,Jo=(e,t)=>e.l.push(t),Yo=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn't exist.`)},Xo=(e,t,n)=>Br(e.l,[t,n]),Zo=class{constructor(e,t){this.client=e,this.clock=t}},Qo=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,$=(e,t)=>new Zo(e,t),$o=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw Xn()},es=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},ts=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ns=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},rs=e=>new ts(e.type==null?null:$(e.type.client,e.type.clock),e.tname??null,e.item==null?null:$(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),is=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},as=(e,t,n=0)=>new is(e,t,n),os=(e,t,n)=>{let r=null,i=null;return e._item===null?i=$o(e):r=$(e._item.id.client,e._item.id.clock),new ts(r,i,t,n)},ss=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return os(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return os(e,$(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return os(e,r.lastId,n);r=r.right}return os(e,null,n)},cs=(e,t)=>{let n=ys(e,t);return{item:n,diff:t.clock-n.id.clock}},ls=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(gs(r,i.client)<=i.clock)return null;let e=n?Rl(r,i):cs(r,i),t=e.item;if(!(t instanceof Ul))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(gs(r,a.client)<=a.clock)return null;let{item:e}=n?Rl(r,a):{item:ys(r,a)};if(e instanceof Ul&&e.content instanceof Il)c=e.content.type;else return null}else throw Xn();l=s>=0?c._length:0}return as(c,l,e.assoc)},us=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Qo(e.item,t.item)&&Qo(e.type,t.type)&&e.assoc===t.assoc,ds=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new ds(e,t))(mo(),new Map);var fs=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!lo(t.ds,e.id),ps=(e,t)=>{let n=Ht(e.meta,ps,Gt),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<gs(r,n)&&xs(e,$(n,t))}),so(e,t.ds,e=>{}),n.add(t))},ms=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},hs=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},gs=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},_s=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw Xn()}n.push(t)},vs=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=tn(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=tn((n+r)/2)}throw Xn()},ys=(e,t)=>{let n=e.clients.get(t.client);return n[vs(n,t.clock)]},bs=(e,t,n)=>{let r=vs(t,n),i=t[r];return i.id.clock<n&&i instanceof Ul?(t.splice(r+1,0,Bl(e,i,n-i.id.clock)),r+1):r},xs=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[bs(e,n,t.clock)]},Ss=(e,t,n)=>{let r=t.clients.get(n.client),i=vs(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==ll&&r.splice(i+1,0,Bl(e,a,n.clock-a.id.clock+1)),a},Cs=(e,t,n)=>{let r=e.clients.get(t.id.client);r[vs(r,t.id.clock)]=n},ws=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=bs(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&bs(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)},Ts=class{constructor(e,t,n){this.doc=e,this.deleteSet=new oo,this.beforeState=hs(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},Es=(e,t)=>t.deleteSet.clients.size===0&&!Wt(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(uo(t.deleteSet),No(e,t),go(e,t.deleteSet),!0),Ds=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Ht(e.changed,t,Gt).add(n)},Os=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--i-1])n instanceof Ul&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);let a=t-i;return a&&e.splice(t+1-a,a),a},ks=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=vs(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Ul&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},As=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=rn(r.length-1,1+vs(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Os(r,e)}})},js=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{uo(a),n.afterState=hs(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{Xo(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Kc(n)})}),Br(e,[])}finally{r.gc&&ks(a,i,r.gcFilter),As(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=an(vs(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Os(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=vs(r,n);a+1<r.length&&Os(r,a+1)>1||a>0&&Os(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&($a(Ja,Va,`[yjs] `,Ha,Ka,`Changed the client-id because another client seems to be using it.`),r.clientID=yo()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Eo;Es(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new Oo;Es(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):js(e,t+1)}}},Ms=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new Ts(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&js(i,0)}}return o},Ns=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Ps=(e,t,n)=>{so(e,n.deletions,n=>{n instanceof Ul&&t.scope.some(t=>t===e.doc||es(t,n))&&zl(n,!1)})},Fs=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;Ms(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;so(n,o.insertions,e=>{if(e instanceof Ul){if(e.redone!==null){let{item:t,diff:i}=Rl(r,e.id);i>0&&(t=xs(n,$(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||es(t,e))&&c.push(e)}}),so(n,o.deletions,e=>{e instanceof Ul&&a.some(t=>t===n.doc||es(t,e))&&!lo(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Hl(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Is=class extends $t{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=Qt(e)?e[0].doc:e instanceof bo?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new oo;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&po(i,n,r,a)});let a=vr(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=fo([t.deletions,e.deleteSet]),t.insertions=fo([t.insertions,i])}else r.push(new Ns(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),so(e,e.deleteSet,t=>{t instanceof Ul&&this.scope.some(n=>n===e.doc||es(n,t))&&zl(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,()=>{this.destroy()})}addToScope(e){let t=new Set(this.scope);e=Qt(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof cc?e.doc!==this.doc:e!==this.doc)&&eo(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Ps(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Ps(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=Fs(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=Fs(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*Ls(e){let t=Q(e.restDecoder);for(let n=0;n<t;n++){let t=Q(e.restDecoder),n=e.readClient(),r=Q(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=Q(e.restDecoder);yield new ql($(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Ul($(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Wl(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new ll($(n,r),t),r+=t}}}}var Rs=class{constructor(e,t){this.gen=Ls(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===ql);return this.curr}},zs=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},Bs=e=>Hs(e,So,Eo),Vs=(e,t)=>{if(e.constructor===ll){let{client:n,clock:r}=e.id;return new ll($(n,r+t),e.length-t)}if(e.constructor===ql){let{client:n,clock:r}=e.id;return new ql($(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Ul($(r,i+t),null,$(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Hs=(e,t=wo,n=Oo)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(er(e))),i=r.map(e=>new Rs(e,!0)),a=null,o=new n,s=new zs(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===ql?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Gs(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock){if(a.struct.constructor===ql)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Gs(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new ql($(t,a.struct.id.clock+a.struct.length),e),offset:0}}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===ql?a.struct.length-=t:n=Vs(n,t)),a.struct.mergeWith(n)||(Gs(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==ql;n=e.next())Gs(s,a.struct,a.offset),a={struct:n,offset:0}}return a!==null&&(Gs(s,a.struct,a.offset),a=null),Ks(s),go(o,fo(r.map(e=>_o(e)))),o.toUint8Array()},Us=(e,t,n=wo,r=Oo)=>{let i=Vo(t),a=new r,o=new zs(a),s=new n(er(e)),c=new Rs(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===ql)c.next();else if(e.id.clock+e.length>n)for(Gs(o,e,an(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Gs(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}return Ks(o),go(a,_o(s)),a.toUint8Array()},Ws=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Tn(e.encoder.restEncoder)}),e.encoder.restEncoder=X(),e.written=0)},Gs=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Ws(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),Z(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ks=e=>{Ws(e);let t=e.encoder.restEncoder;Z(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];Z(t,r.written),Nn(t,r.restEncoder)}},qs=(e,t,n,r)=>{let i=new n(er(e)),a=new Rs(i,!1),o=new r,s=new zs(o);for(let e=a.curr;e!==null;e=a.next())Gs(s,t(e),0);return Ks(s),go(o,_o(i)),o.toUint8Array()},Js=e=>qs(e,Vr,wo,Eo),Ys=`You must not compute changes after the event-handler fired.`,Xs=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=Zs(this.currentTarget,this.target)}deletes(e){return lo(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Jn(Ys);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=Kt(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=Kt(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=Kt(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Jn(Ys);let t=this.target,n=Gt(),r=Gt(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}},Zs=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},Qs=()=>{eo(`Invalid access: Add Yjs type to a document before reading data.`)},$s=80,ec=0,tc=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ec++}},nc=e=>{e.timestamp=ec++},rc=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ec++},ic=(e,t,n)=>{if(e.length>=$s){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return rc(r,t,n),r}{let r=new tc(t,n);return e.push(r),r}},ac=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>nn(t-e.index)<nn(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,nc(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&nn(n.index-i)<r.parent.length/$s?(rc(n,r,i),n):ic(e._searchMarker,r,i)},oc=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=an(t,i.index+n))}},sc=(e,t,n)=>{let r=e,i=t.changedParentTypes;for(;Ht(i,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Xo(r._eH,n,t)},cc=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=qo(),this._dEH=qo(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Yn()}clone(){throw Yn()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Jo(this._eH,e)}observeDeep(e){Jo(this._dEH,e)}unobserve(e){Yo(this._eH,e)}unobserveDeep(e){Yo(this._dEH,e)}toJSON(){}},lc=(e,t,n)=>{e.doc??Qs(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},uc=e=>{e.doc??Qs();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},dc=(e,t)=>{let n=0,r=e._start;for(e.doc??Qs();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},fc=(e,t)=>{let n=[];return dc(e,(r,i)=>{n.push(t(r,i,e))}),n},pc=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},mc=(e,t)=>{e.doc??Qs();let n=ac(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},hc=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Ul($(o,gs(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new wl(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Ul($(o,gs(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new ul(new Uint8Array(n))),i.integrate(e,0);break;case bo:i=new Ul($(o,gs(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new hl(n)),i.integrate(e,0);break;default:if(n instanceof cc)i=new Ul($(o,gs(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Il(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},gc=()=>Jn(`Length exceeded!`),_c=(e,t,n,r)=>{if(n>t._length)throw gc();if(n===0)return t._searchMarker&&oc(t._searchMarker,n,r.length),hc(e,t,null,r);let i=n,a=ac(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&xs(e,$(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&oc(t._searchMarker,i,r.length),hc(e,t,o,r)},vc=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return hc(e,t,r,n)},yc=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=ac(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&xs(e,$(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&xs(e,$(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw gc();t._searchMarker&&oc(t._searchMarker,i,-a+r)},bc=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},xc=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new wl([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new wl([r]);break;case Uint8Array:s=new ul(r);break;case bo:s=new hl(r);break;default:if(r instanceof cc)s=new Il(r);else throw Error(`Unexpected content type`)}new Ul($(o,gs(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},Sc=(e,t)=>{e.doc??Qs();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},Cc=e=>{let t={};return e.doc??Qs(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},wc=(e,t)=>{e.doc??Qs();let n=e._map.get(t);return n!==void 0&&!n.deleted},Tc=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&fs(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},Ec=e=>(e.doc??Qs(),ro(e._map.entries(),e=>!e[1].deleted)),Dc=class extends Xs{},Oc=class e extends cc{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof cc?e.clone():e)),t}get length(){return this.doc??Qs(),this._length}_callObserver(e,t){super._callObserver(e,t),sc(this,e,new Dc(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ms(this.doc,n=>{_c(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):Ms(this.doc,t=>{vc(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ms(this.doc,n=>{yc(n,this,e,t)})}get(e){return mc(this,e)}toArray(){return uc(this)}slice(e=0,t=this.length){return lc(this,e,t)}toJSON(){return this.map(e=>e instanceof cc?e.toJSON():e)}map(e){return fc(this,e)}forEach(e){dc(this,e)}[Symbol.iterator](){return pc(this)}_write(e){e.writeTypeRef(kl)}},kc=e=>new Oc,Ac=class extends Xs{constructor(e,t,n){super(e,t),this.keysChanged=n}},jc=class e extends cc{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof cc?e.clone():e)}),t}_callObserver(e,t){sc(this,e,new Ac(this,e,t))}toJSON(){this.doc??Qs();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof cc?r.toJSON():r}}),e}get size(){return[...Ec(this)].length}keys(){return io(Ec(this),e=>e[0])}values(){return io(Ec(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return io(Ec(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??Qs(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):Ms(this.doc,t=>{bc(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):Ms(this.doc,n=>{xc(n,this,e,t)}),t}get(e){return Sc(this,e)}has(e){return wc(this,e)}clear(){this.doc===null?this._prelimContent.clear():Ms(this.doc,e=>{this.forEach(function(t,n,r){bc(e,r,n)})})}_write(e){e.writeTypeRef(Al)}},Mc=e=>new jc,Nc=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&Lr(e,t),Pc=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&Xn(),this.right.content.constructor){case yl:this.right.deleted||Rc(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}},Fc=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case yl:t.right.deleted||Rc(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&xs(e,$(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length)}t.left=t.right,t.right=t.right.right}return t},Ic=(e,t,n,r)=>{let i=new Map,a=r?ac(t,n):null;return a?Fc(e,new Pc(a.p.left,a.p,a.index,i),n-a.index):Fc(e,new Pc(null,t._start,0,i),n)},Lc=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===yl&&Nc(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Ul($(a,gs(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new yl(o,r));l.integrate(e,0),n.right=l,n.forward()})},Rc=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},zc=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===yl&&Nc(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Bc=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Nc(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Ul($(a,gs(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new yl(s,c)),n.right.integrate(e,0),n.forward()}}return o},Vc=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;zc(n,i);let s=Bc(e,t,n,i),c=r.constructor===String?new El(r):r instanceof cc?new Il(r):new _l(r),{left:l,right:u,index:d}=n;t._searchMarker&&oc(t._searchMarker,n.index,c.getLength()),u=new Ul($(o,gs(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),Lc(e,t,n,s)},Hc=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;zc(n,i);let s=Bc(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===yl));){if(!n.right.deleted)switch(n.right.content.constructor){case yl:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Nc(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&xs(e,$(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`
|
|
4
|
+
`;n.right=new Ul($(o,gs(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new El(i)),n.right.integrate(e,0),n.forward()}Lc(e,t,n,s)},Uc=(e,t,n,r,i)=>{let a=t,o=Bt();for(;a&&(!a.countable||a.deleted);){if(!a.deleted&&a.content.constructor===yl){let e=a.content;o.set(e.key,e)}a=a.right}let s=0,c=!1;for(;t!==a;){if(n===t&&(c=!0),!t.deleted){let n=t.content;switch(n.constructor){case yl:{let{key:a,value:l}=n,u=r.get(a)??null;(o.get(a)!==n||u===l)&&(t.delete(e),s++,!c&&(i.get(a)??null)===l&&u!==l&&(u===null?i.delete(a):i.set(a,u))),!c&&!t.deleted&&Rc(i,n);break}}}t=t.right}return s},Wc=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===yl){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Gc=e=>{let t=0;return Ms(e.doc,n=>{let r=e._start,i=e._start,a=Bt(),o=Vt(a);for(;i;){if(i.deleted===!1)switch(i.content.constructor){case yl:Rc(o,i.content);break;default:t+=Uc(n,r,i,a,o),a=Vt(o),r=i}i=i.right}}),t},Kc=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&ws(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===yl&&e.constructor!==ll&&t.add(e.parent)})}Ms(n,n=>{so(e,e.deleteSet,e=>{if(e instanceof ll||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===yl?t.add(r):Wc(n,e)});for(let e of t)Gc(e)})},qc=(e,t,n)=>{let r=n,i=Vt(t.currentAttributes),a=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Il:case _l:case El:n<t.right.length&&xs(e,$(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}a&&Uc(e,a,t.right,i,t.currentAttributes);let o=(t.left||t.right).parent;return o._searchMarker&&oc(o._searchMarker,t.index,-r+n),t},Jc=class extends Xs{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];Ms(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},Pr(o)||(e.attributes=kr({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Il:case _l:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case El:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case yl:{let{key:t,value:s}=i.content;if(this.adds(i))this.deletes(i)||(Nc(n.get(t)??null,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Nc(s,r.get(t)??null)?delete o[t]:o[t]=s));else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Nc(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Nc(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Rc(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Yc=class e extends cc{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Qs(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Jc(this,e,t);sc(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??Qs();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===El&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):Ms(this.doc,n=>{let r=new Pc(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`
|
|
5
|
+
`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Vc(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&qc(n,r,a.delete):Hc(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??Qs();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(fs(s,e)||t!==void 0&&fs(s,t))switch(s.content.constructor){case El:{let r=i.get(`ychange`);e!==void 0&&!fs(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!fs(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Il:case _l:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case yl:fs(s,e)&&(c(),Rc(i,s.content))}s=s.right}c()};return e||t?Ms(a,n=>{e&&ps(n,e),t&&ps(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):Ms(r,r=>{let i=Ic(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Vc(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):Ms(r,r=>{let i=Ic(r,this,e,!n);Vc(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):Ms(n,n=>{qc(n,Ic(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):Ms(r,r=>{let i=Ic(r,this,e,!1);i.right!==null&&Hc(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):Ms(this.doc,t=>{bc(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):Ms(this.doc,n=>{xc(n,this,e,t)})}getAttribute(e){return Sc(this,e)}getAttributes(){return Cc(this)}_write(e){e.writeTypeRef(jl)}},Xc=e=>new Yc,Zc=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??Qs()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===el||t.constructor===Qc)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Qc=class e extends cc{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof cc?e.clone():e)),t}get length(){return this.doc??Qs(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Zc(this,e)}querySelector(e){e=e.toUpperCase();let t=new Zc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Jt(new Zc(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){sc(this,e,new nl(this,t,e))}toString(){return fc(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),dc(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):Ms(this.doc,n=>{_c(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)Ms(this.doc,n=>{let r=e&&e instanceof cc?e._item:e;hc(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw Jn(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):Ms(this.doc,n=>{yc(n,this,e,t)})}toArray(){return uc(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return mc(this,e)}slice(e=0,t=this.length){return lc(this,e,t)}forEach(e){dc(this,e)}_write(e){e.writeTypeRef(Nl)}},$c=e=>new Qc,el=class e extends Qc{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName);return jr(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof cc?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):Ms(this.doc,t=>{bc(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):Ms(this.doc,n=>{xc(n,this,e,t)})}getAttribute(e){return Sc(this,e)}hasAttribute(e){return wc(this,e)}getAttributes(e){return e?Tc(this,e):Cc(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return dc(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(Ml),e.writeKey(this.nodeName)}},tl=e=>new el(e.readKey()),nl=class extends Xs{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},rl=class e extends jc{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Pl),e.writeKey(this.hookName)}},il=e=>new rl(e.readKey()),al=class e extends Yc{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Fl)}},ol=e=>new al,sl=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Yn()}mergeWith(e){return!1}write(e,t,n){throw Yn()}integrate(e,t){throw Yn()}},cl=0,ll=class extends sl{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),_s(e.doc.store,this)}write(e,t){e.writeInfo(cl),e.writeLen(this.length-t)}getMissing(e,t){return null}},ul=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw Yn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},dl=e=>new ul(e.readBuf()),fl=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){po(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}},pl=e=>new fl(e.readLen()),ml=(e,t)=>new bo({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),hl=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(ml(this.doc.guid,this.opts))}splice(e){throw Yn()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}},gl=e=>new hl(ml(e.readString(),e.readAny())),_l=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw Yn()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},vl=e=>new _l(e.readJSON()),yl=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw Yn()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}},bl=e=>new yl(e.readKey(),e.readJSON()),xl=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}},Sl=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new xl(n)},Cl=Xr(`node_env`)===`development`,wl=class e{constructor(e){this.arr=e,Cl&&zr(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},Tl=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new wl(n)},El=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}},Dl=e=>new El(e.readString()),Ol=[kc,Mc,Xc,tl,$c,il,ol],kl=0,Al=1,jl=2,Ml=3,Nl=4,Pl=5,Fl=6,Il=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw Yn()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Ll=e=>new Il(Ol[e.readTypeRef()](e)),Rl=(e,t)=>{let n=t,r=0,i;do r>0&&(n=$(n.client,n.clock+r)),i=ys(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Ul);return{item:i,diff:r}},zl=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Bl=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Ul($(r,i+n),t,$(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=$(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},Vl=(e,t)=>Xt(e,e=>lo(e.deletions,t)),Hl=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return xs(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Hl(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=xs(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:xs(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:xs(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||lo(r,d.right.id)||Vl(a.undoStack,d.right.id)||Vl(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=xs(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=$(c,gs(s,c)),h=new Ul(m,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=m,zl(h,!0),h.integrate(e,0),h},Ul=class e extends sl{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=gs(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=gs(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Zo&&this.id.client!==this.parent.client&&this.parent.clock>=gs(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=Ss(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=xs(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===ll||this.right&&this.right.constructor===ll)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Zo){let e=ys(n,this.parent);this.parent=e.constructor===ll?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Ss(e,e.doc.store,$(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),Qo(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if(Qo(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(ys(e.doc.store,n.origin)))r.has(ys(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),_s(e.doc.store,this),this.content.integrate(e,this),Ds(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ll(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:$(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Qo(e.origin,this.lastId)&&this.right===e&&Qo(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),po(e.deleteSet,this.id.client,this.id.clock,this.length),Ds(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw Xn();this.content.gc(e),t?Cs(e,this,new ll(this.id,this.length)):this.content=new fl(this.length)}write(e,t){let n=t>0?$(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=$o(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Zo?(e.writeParentInfo(!1),e.writeLeftID(t)):Xn();i!==null&&e.writeString(i)}this.content.write(e,t)}},Wl=(e,t)=>Gl[t&31](e),Gl=[()=>{Xn()},pl,Sl,dl,Dl,vl,bl,Ll,Tl,gl,()=>{Xn()}],Kl=10,ql=class extends sl{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Xn()}write(e,t){e.writeInfo(Kl),Z(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Jl=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},Yl=`__ $YJS$ __`;Jl[Yl]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Jl[Yl]=!0;function Xl(e,t,n){let r=[],i=t.contentFrom,a=t.contentFrom;for(;a<=t.contentTo;){if(a<t.contentTo&&dt(e,a)){a=pt(e,a),e[a]===`
|
|
6
|
+
`&&(a+=1);continue}if(a!==t.contentTo&&(!n||e[a]!==`,`)){a+=1;continue}let o=Zl(e,i,a);o&&r.push(o),i=a+1,a+=1}return r}function Zl(e,t,n){let r=[],i=t;for(;i<n;)dt(e,i)?(i=pt(e,i),e[i]===`
|
|
7
|
+
`&&(i+=1)):(r.push({character:e[i],index:i}),i+=1);let a=0,o=r.length;for(;a<o&&/\s/.test(r[a].character);)a+=1;for(;o>a&&/\s/.test(r[o-1].character);)--o;return a===o?null:{path:r.slice(a,o).map(e=>e.character).join(``),command:``,from:r[a].index,to:r[o-1].index+1}}function Ql(e,t){let n=ct(e,t);if(n>=e.length||/[\\{}\[\]#~]/.test(e[n]))return null;let r=n;for(;r<e.length&&!/\s/.test(e[r])&&!dt(e,r)&&!/[\\{}\[\]#~]/.test(e[r]);)r+=1;return r===n?null:{path:e.slice(n,r),command:``,from:n,to:r}}function $l(e){let t=[];return mt(e,n=>{let r=n.name.toLowerCase();if(r===`input`||r===`include`||r===`subfile`){let i=st(e,n.to,1)[0];if(i)for(let r of Xl(e,i,!1))t.push({...r,command:n.name});else if(r===`input`){let r=Ql(e,n.to);r&&t.push({...r,command:n.name})}return}if(r!==`import`&&r!==`subimport`&&r!==`includefrom`&&r!==`inputfrom`&&r!==`subinputfrom`&&r!==`subincludefrom`)return;let i=st(e,n.to,2);if(i.length!==2)return;let a=Xl(e,i[0],!1)[0]?.path??``,o=Xl(e,i[1],!1)[0];if(!o)return;let s=a&&!a.endsWith(`/`)?`/`:``;t.push({path:a+s+o.path,command:n.name,from:o.from,to:o.to,directory:a})}),t}var eu=(e,t)=>e>>>t|e<<32-t,tu=e=>eu(e,2)^eu(e,13)^eu(e,22),nu=e=>eu(e,6)^eu(e,11)^eu(e,25),ru=e=>eu(e,7)^eu(e,18)^e>>>3,iu=e=>eu(e,17)^eu(e,19)^e>>>10,au=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]),ou=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),su=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(ou),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let e=16;e<64;e++)t[e]=iu(t[e-2])+t[e-7]+ru(t[e-15])+t[e-16];let n=e[0],r=e[1],i=e[2],a=e[3],o=e[4],s=e[5],c=e[6],l=e[7];for(let e=0,u,d;e<64;e++)u=l+nu(o)+(o&s^~o&c)+au[e]+t[e]>>>0,d=tu(n)+(n&r^n&i^r&i)>>>0,l=c,c=s,s=o,o=a+u>>>0,a=i,i=r,r=n,n=u+d>>>0;e[0]+=n,e[1]+=r,e[2]+=i,e[3]+=a,e[4]+=o,e[5]+=s,e[6]+=c,e[7]+=l}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<(3-t%4)*8,t++;this._W[n]|=128<<(3-t%4)*8}this._updateHash()}let n=t%64!=0;this._W.fill(0,0,16);let r=0;for(;t<e.length;r++)for(let n=3;n>=0&&t<e.length;n--)this._W[r]|=e[t++]<<n*8;n||(this._W[r-(t%4==0?0:1)]|=128<<(3-t%4)*8),this._W[14]=e.byteLength/cn,this._W[15]=e.byteLength*8,this._updateHash();let i=new Uint8Array(32);for(let e=0;e<this._H.length;e++)for(let t=0;t<4;t++)i[e*4+t]=this._H[e]>>>(3-t)*8;return i}},cu=e=>new su().digest(e);function lu(e){return Array.from(cu(new TextEncoder().encode(e)),e=>e.toString(16).padStart(2,`0`)).join(``)}function uu(e){for(let t=0;t<e.length;t+=1)e[t]=Math.floor(Math.random()*256);return e}function du(e){e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function fu(e=globalThis.crypto){if(typeof e?.randomUUID==`function`)return e.randomUUID();let t=new Uint8Array(16);return du(typeof e?.getRandomValues==`function`?e.getRandomValues(t):uu(t))}function pu(e){return/\.(?:tex|sty|cls|ltx|dtx|ins|txt|md|markdown|rst)$/i.test(e.trim())}function mu(e){return/\.(?:tex|sty|cls)$/i.test(e.trim())}function hu(){let e={status:`loading`,error:``},t=new Set,n=(n,r=``)=>{if(e.status!==n||e.error!==r){e={status:n,error:r};for(let e of t)e()}};return{getSnapshot:()=>e,subscribe:e=>(t.add(e),()=>t.delete(e)),loading:()=>n(`loading`),working:()=>n(`working`),failed:e=>n(`error`,e instanceof Error?e.message:String(e))}}var gu=hu(),_u=/\.(?:tex|bib|cls|sty)$/i,vu=3e4,yu=null,bu=!1,xu=null,Su=1,Cu=new Map,wu=[],Tu=null,Eu=null,Du=class extends Error{kind;constructor(e,t){super(t),this.kind=e,this.name=`TexFmtError`}};function Ou(e){return e instanceof Du}function ku(e){yu?.terminate(),yu=null,bu=!1,xu!==null&&window.clearTimeout(xu),xu=null,Tu=null,wu.length=0,Eu=null,gu.failed(e);for(let t of Cu.values())t.timeout!==null&&window.clearTimeout(t.timeout),t.reject(e);Cu.clear()}function Au(){if(Tu!==null||wu.length===0)return;let e;try{e=ju()}catch(e){ku(e instanceof Du?e:new Du(`load`,`The bundled tex-fmt formatter could not be loaded.`));return}if(!bu)return;let t=wu.shift();if(t===void 0)return;let n=Cu.get(t);if(!n)Au();else{Tu=t,n.timeout=window.setTimeout(()=>{Tu===t&&ku(new Du(`result`,`The formatter did not respond within 30 seconds.`))},vu);try{e.postMessage({...n.request,id:t})}catch{ku(new Du(`load`,`The formatter worker could not receive the source.`))}}}function ju(){if(yu)return yu;if(typeof Worker>`u`){let e=new Du(`load`,`This browser does not support formatter workers.`);throw gu.failed(e),e}gu.loading();try{yu=new Worker(new URL(new URL(`latexFormatterWorker-BWiogBYE.js`,import.meta.url).href,``+import.meta.url),{type:`module`,name:`texlite-latex-formatter`}),xu=window.setTimeout(()=>{bu||ku(new Du(`load`,`The formatter did not finish loading within 30 seconds.`))},vu)}catch{let e=new Du(`load`,`The bundled tex-fmt formatter could not be loaded.`);throw gu.failed(e),e}return yu.onmessage=e=>{let t=e.data;if(t&&`type`in t){t.type===`ready`&&(bu=!0,xu!==null&&window.clearTimeout(xu),xu=null,Au());return}if(!t||typeof t.id!=`number`){ku(new Du(`result`,`The formatter worker returned an invalid response.`));return}let n=Cu.get(t.id);if(n){if(Cu.delete(t.id),n.timeout!==null&&window.clearTimeout(n.timeout),Tu===t.id&&(Tu=null),t.ok)gu.working(),n.resolve(t.result),Au();else{let e=new Du(t.kind,t.message);t.kind===`format`?(gu.working(),n.reject(e),Au()):(n.reject(e),ku(e))}}},yu.onerror=()=>{ku(new Du(`load`,`The bundled tex-fmt formatter could not be loaded.`))},yu.onmessageerror=()=>{ku(new Du(`result`,`The formatter worker returned an unreadable response.`))},yu}function Mu(e){let t=Su++;return new Promise((n,r)=>{Cu.set(t,{request:e,resolve:n,reject:r,timeout:null}),wu.push(t),Au()})}function Nu(e,t=``){return Mu({action:`format`,source:e,config:t})}async function Pu(){yu&&gu.getSnapshot().status===`working`||(Eu||=Mu({action:`probe`}).then(()=>void 0).finally(()=>{Eu=null}),await Eu)}async function Fu(){(yu||Cu.size)&&ku(new Du(`load`,`The formatter runtime was reloaded.`)),gu.loading(),await Pu()}function Iu(e){return _u.test(e)}function Lu(e){return e.match(/(?:\r?\n)+$/)?.[0]??``}function Ru(e,t){let n=Lu(e),r=(n?e.slice(0,-n.length):e).split(/\r?\n/).find(e=>e.trim())?.match(/^[\t ]*/)?.[0]??``,i=t.replace(/(?:\r?\n)+$/,``);return`${r?i.split(`
|
|
8
|
+
`).map(e=>e&&`${r}${e}`).join(`
|
|
9
|
+
`):i}${n}`}async function zu(e,t,n=0){return Mu({action:`diff`,source:e,formatted:t,baseOffset:n})}var Bu=null,Vu=1,Hu=new Map,Uu=class extends Error{kind;constructor(e){super(`BibTeX formatter: ${e}`),this.kind=e,this.name=`BibtexFormatterError`}};function Wu(e){Bu?.terminate(),Bu=null;for(let t of Hu.values())clearTimeout(t.timeout),t.reject(new Uu(e));Hu.clear()}function Gu(){if(Bu)return Bu;let e=new Worker(new URL(new URL(`bibtexFormatterWorker-Bp8kjjvw.js`,import.meta.url).href,``+import.meta.url),{type:`module`,name:`texlite-bibtex-formatter`});return Bu=e,e.onmessage=({data:t})=>{if(Bu!==e)return;if(!t||typeof t.id!=`number`||typeof t.ok!=`boolean`){Wu(`unavailable`);return}let n=Hu.get(t.id);n&&(t.ok&&(t.action!==n.action||(t.action===`format`?typeof t.result!=`string`:!Ku(t.result)))?Wu(`unavailable`):(clearTimeout(n.timeout),Hu.delete(t.id),t.ok?n.resolve(t.result):t.kind===`too-large`||t.kind===`invalid`?n.reject(new Uu(t.kind)):(n.reject(new Uu(`unavailable`)),Wu(`unavailable`))))},e.onerror=e.onmessageerror=()=>{Bu===e&&Wu(`unavailable`)},e}function Ku(e){if(!Array.isArray(e))return!1;let t=0;return e.every(e=>!e||!Number.isSafeInteger(e.from)||!Number.isSafeInteger(e.to)||e.from<t||e.to<e.from||typeof e.replacement!=`string`?!1:(t=e.to,!0))}function qu(e){return new Promise((t,n)=>{let r;try{r=Gu()}catch{n(new Uu(`unavailable`));return}let i=Vu++,a=setTimeout(()=>Wu(`timeout`),3e4);Hu.set(i,{action:e.action,resolve:t,reject:n,timeout:a});try{r.postMessage({...e,id:i})}catch{Wu(`unavailable`)}})}function Ju(e,t){return qu({action:`format`,source:e,maxBytes:t})}function Yu(e,t,n=0){return qu({action:`diff`,source:e,formatted:t,baseOffset:n})}function Xu(e,t=null){let n=Zu(e),r=t===`succeeded`||t===null&&ed(e)?[]:Qu(n.filter(td));return{warnings:Qu(Zu($u(e)).filter(e=>!td(e)&&nd(e))),errors:r}}function Zu(e){return e.split(`
|
|
10
|
+
`).map(e=>e.trim()).filter(Boolean)}function Qu(e){return[...new Set(e)]}function $u(e){let t=/^Running ['"][^\n]*(?:pdf|xe|lua)latex(?:\s|['"])[^\n]*$/gim,n=-1;for(let r of e.matchAll(t))n=r.index;return n>=0?e.slice(n):e}function ed(e){return/Latexmk: All targets .* are up-to-date/i.test(e)&&/Output written on .*\.pdf/i.test(e)}function td(e){return/^!\s/.test(e)||/(?:^|:\s)(?:LaTeX|Package|Class|pdfTeX|XeTeX|LuaTeX)?\s*Error:/i.test(e)||/^Latexmk:.*(?:\bErrors?,|did not complete making targets|failure)/i.test(e)||/^Collected error summary/i.test(e)||/\b(?:fatal error|emergency stop|undefined control sequence|no output pdf|no pages of output)\b/i.test(e)||/\b(?:bibtex|biber) errors?:/i.test(e)||/^error, and then rerun latexmk/i.test(e)}function nd(e){return/\bwarnings?\b|overfull|underfull|badness/i.test(e)}var rd=Object.freeze({}),id=class{threads=new Map;listeners=new Map;newComments=new Map;getThread(e){return this.threads.get(e)??rd}subscribe(e,t){let n=this.listeners.get(e)??new Set;return n.add(t),this.listeners.set(e,n),()=>{n.delete(t),n.size||this.listeners.delete(e)}}publish(e,t){Object.keys(t).length?this.threads.set(e,t):this.threads.delete(e);for(let t of this.listeners.get(e)??[])t()}isPending(e){return Object.values(this.getThread(e)).some(e=>e?.pending)}open(e,t,n=``){if(this.isPending(e))return;let r={...this.getThread(e)};if(t.startsWith(`edit-reply:`))for(let[e,t]of Object.entries(r))e.startsWith(`edit-reply:`)&&t?.open&&(r[e]={...t,open:!1});r[t]={content:n,pending:!1,error:``,...r[t],open:!0},this.publish(e,r)}change(e,t,n){let r=this.getThread(e)[t];r&&!this.isPending(e)&&this.publish(e,{...this.getThread(e),[t]:{...r,content:n}})}discard(e,t){let n={...this.getThread(e)};t===void 0?this.publish(e,rd):(delete n[t],this.publish(e,n))}async submit(e,t,n,r){let i=this.getThread(e)[t];if(!i||!i.content.trim()||this.isPending(e))return!1;let a={...i,pending:!0,error:``};this.publish(e,{...this.getThread(e),[t]:a});let o=r;try{if(await n(i.content))return this.getThread(e)[t]===a&&this.discard(e,t),!0}catch(e){o=q(e)}return this.getThread(e)[t]===a&&this.publish(e,{...this.getThread(e),[t]:{...i,pending:!1,error:o}}),!1}getNew(e){return this.newComments.get(e)}setNew(e){this.newComments.set(e.filePath,{...e,selection:{...e.selection},suggestion:e.suggestion?{...e.suggestion}:e.suggestion})}discardNew(e){this.newComments.delete(e)}},ad=J.createContext(void 0),od=e=>{let t=J.useContext(ad);if(e)return e;if(!t)throw Error(`No QueryClient set, use QueryClientProvider to set one`);return t},sd=({client:e,children:t})=>(J.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,Y.jsx)(ad.Provider,{value:e,children:t})),cd={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},ld=new class{#e=cd;setTimeoutProvider(e){this.#e=e}setTimeout(e,t){return this.#e.setTimeout(e,t)}clearTimeout(e){this.#e.clearTimeout(e)}setInterval(e,t){return this.#e.setInterval(e,t)}clearInterval(e){this.#e.clearInterval(e)}};function ud(e){setTimeout(e,0)}var dd=typeof window>`u`||`Deno`in globalThis;function fd(){}function pd(e,t){return typeof e==`function`?e(t):e}function md(e){return typeof e==`number`&&e>=0&&e!==1/0}function hd(e,t){return Math.max(e+(t||0)-Date.now(),0)}function gd(e,t){return typeof e==`function`?e(t):e}function _d(e,t){let{type:n=`all`,exact:r,fetchStatus:i,predicate:a,queryKey:o,stale:s}=e;if(o){if(r){if(t.queryHash!==yd(o,t.options))return!1}else if(!xd(t.queryKey,o))return!1}if(n!==`all`){let e=t.isActive();if(n===`active`&&!e||n===`inactive`&&e)return!1}return!(typeof s==`boolean`&&t.isStale()!==s||i&&i!==t.state.fetchStatus||a&&!a(t))}function vd(e,t){let{exact:n,status:r,predicate:i,mutationKey:a}=e;if(a){if(!t.options.mutationKey)return!1;if(n){if(bd(t.options.mutationKey)!==bd(a))return!1}else if(!xd(t.options.mutationKey,a))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function yd(e,t){return(t?.queryKeyHashFn||bd)(e)}function bd(e){return JSON.stringify(e,(e,t)=>Ed(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}function xd(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e&&t&&typeof e==`object`&&typeof t==`object`){if(Array.isArray(e)&&Array.isArray(t)){if(t.length>e.length)return!1;for(let n=0;n<t.length;n++)if(!xd(e[n],t[n]))return!1;return!0}let n=Object.keys(t);for(let r of n)if(!xd(e[r],t[r]))return!1;return!0}return!1}var Sd=Object.prototype.hasOwnProperty;function Cd(e,t,n=0){if(e===t)return e;if(n>500)return t;let r=Td(e)&&Td(t);if(!r&&!(Ed(e)&&Ed(t)))return t;let i=(r?e:Object.keys(e)).length,a=r?t:Object.keys(t),o=a.length,s=r?Array(o):{},c=0;for(let l=0;l<o;l++){let o=r?l:a[l],u=e[o],d=t[o];if(u===d){s[o]=u,(r?l<i:Sd.call(e,o))&&c++;continue}if(u===null||d===null||typeof u!=`object`||typeof d!=`object`){s[o]=d;continue}let f=Cd(u,d,n+1);s[o]=f,f===u&&c++}return i===o&&c===i?e:s}function wd(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let n in e)if(e[n]!==t[n])return!1;return!0}function Td(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Ed(e){if(!Dd(e))return!1;let t=Object.getPrototypeOf(e),n=t?.constructor;if(n===void 0)return!0;if(typeof n!=`function`)return!1;let r=n.prototype;return!(!Dd(r)||!r.hasOwnProperty(`isPrototypeOf`)||t!==Object.prototype)}function Dd(e){return Object.prototype.toString.call(e)===`[object Object]`}function Od(e){return new Promise(t=>{ld.setTimeout(t,e)})}function kd(e,t,n){return typeof n.structuralSharing==`function`?n.structuralSharing(e,t):n.structuralSharing===!1?t:Cd(e,t)}function Ad(e,t,n=0){let r=[...e,t];return n&&r.length>n?r.slice(1):r}function jd(e,t,n=0){let r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var Md=Symbol();function Nd(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===Md?()=>Promise.reject(Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function Pd(e,t){return typeof e==`function`?e(...t):!!e}function Fd(e,t,n){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r||(r=!0,i.aborted?n():i.addEventListener(`abort`,n,{once:!0})),i)}),e}var Id=()=>dd,Ld=()=>Id(),Rd=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},zd=new class extends Rd{#e;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e();return window.addEventListener(`visibilitychange`,t,!1),()=>{window.removeEventListener(`visibilitychange`,t)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(e=>{typeof e==`boolean`?this.setFocused(e):this.onFocus()})}setFocused(e){this.#e!==e&&(this.#e=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#e==`boolean`?this.#e:globalThis.document?.visibilityState!==`hidden`}},Bd=ud;function Vd(){let e=[],t=0,n=e=>{e()},r=e=>{e()},i=Bd,a=r=>{t?e.push(r):i(()=>{n(r)})},o=()=>{let t=e;e=[],t.length&&i(()=>{r(()=>{t.forEach(e=>{n(e)})})})};return{batch:e=>{let n;t++;try{n=e()}finally{t--,t||o()}return n},batchCalls:e=>(...t)=>{a(()=>{e(...t)})},schedule:a,setNotifyFunction:e=>{n=e},setBatchNotifyFunction:e=>{r=e},setScheduler:e=>{i=e}}}var Hd=Vd(),Ud=new class extends Rd{#e=!0;#t;#n;constructor(){super(),this.#n=e=>{if(typeof window<`u`&&window.addEventListener){let t=()=>e(!0),n=()=>e(!1);return window.addEventListener(`online`,t,!1),window.addEventListener(`offline`,n,!1),()=>{window.removeEventListener(`online`,t),window.removeEventListener(`offline`,n)}}}}onSubscribe(){this.#t||this.setEventListener(this.#n)}onUnsubscribe(){this.hasListeners()||(this.#t?.(),this.#t=void 0)}setEventListener(e){this.#n=e,this.#t?.(),this.#t=e(this.setOnline.bind(this))}setOnline(e){this.#e!==e&&(this.#e=e,this.listeners.forEach(t=>{t(e)}))}isOnline(){return this.#e}};function Wd(e){return Math.min(1e3*2**e,3e4)}function Gd(e){return(e??`online`)!==`online`||Ud.isOnline()}var Kd=class extends Error{constructor(e){super(`CancelledError`),this.revert=e?.revert,this.silent=e?.silent}};function qd(e){let t=!1,n=0,r,i=`pending`,a,o,s=new Promise((e,t)=>{a=e,o=t});s.catch(fd);let c=()=>i!==`pending`,l=t=>{if(!c()){let n=new Kd(t);h(n),e.onCancel?.(n)}},u=()=>{t=!0},d=()=>{t=!1},f=()=>zd.isFocused()&&(e.networkMode===`always`||Ud.isOnline())&&e.canRun(),p=()=>Gd(e.networkMode)&&e.canRun(),m=e=>{c()||(r?.(),i=`resolved`,a(e))},h=e=>{c()||(r?.(),i=`rejected`,o(e))},g=t=>new Promise(n=>{r=e=>{(c()||t())&&n(e)},e.onPause?.()}).then(()=>{r=void 0,c()||e.onContinue?.()}),_=()=>{if(c())return;let r,i=n===0?e.initialPromise:void 0;try{r=i??e.fn()}catch(e){r=Promise.reject(e)}Promise.resolve(r).then(m).catch(r=>{if(c())return;let i=e.retry??(Ld()?0:3),a=e.retryDelay??Wd,o=typeof a==`function`?a(n,r):a,s=i===!0||typeof i==`number`&&n<i||typeof i==`function`&&i(n,r);t||!s?h(r):(n++,e.onFail?.(n,r),Od(o).then(()=>f()?void 0:g(f)).then(()=>{t?h(r):_()}))})};return{promise:s,status:()=>i,cancel:l,continue:()=>(r?.(),s),cancelRetry:u,continueRetry:d,canStart:p,start:()=>(p()?_():g(p).then(_),s)}}var Jd=class{#e;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),md(this.gcTime)&&(this.#e=ld.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Ld()?1/0:3e5))}clearGcTimeout(){this.#e!==void 0&&(ld.clearTimeout(this.#e),this.#e=void 0)}};function Yd(e){return{onFetch:(t,n)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,a=t.state.data?.pages||[],o=t.state.data?.pageParams||[],s={pages:[],pageParams:[]},c=0,l=async()=>{let n=!1,l=e=>{Fd(e,()=>t.signal,()=>n=!0)},u=Nd(t.options,t.fetchOptions),d=async(e,r,i)=>{if(n)return Promise.reject(t.signal.reason);if(r==null&&e.pages.length)return Promise.resolve(e);let a=(()=>{let e={client:t.client,queryKey:t.queryKey,pageParam:r,direction:i?`backward`:`forward`,meta:t.options.meta};return l(e),e})(),o=await u(a),{maxPages:s}=t.options,c=i?jd:Ad;return{pages:c(e.pages,o,s),pageParams:c(e.pageParams,r,s)}};if(i&&a.length){let e=i===`backward`,t=e?Zd:Xd,n={pages:a,pageParams:o};s=await d(n,t(r,n),e)}else{let t=e??a.length;do{let e=c===0?o[0]===void 0?r.initialPageParam:o[0]:Xd(r,s);if(c>0&&e==null)break;s=await d(s,e),c++}while(c<t)}return s};t.fetchFn=t.options.persister?()=>t.options.persister?.(l,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n):l}}}function Xd(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function Zd(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}var Qd=class extends Jd{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e){super(),this.#s=!1,this.#o=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#t=tf(this.options),this.state=e.state??this.#t,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#e}get promise(){return this.#a?.promise}setOptions(e){if(this.options={...this.#o,...e},e?._type&&(this.#e=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let e=tf(this.options);e.data!==void 0&&(this.setState(ef(e.data,e.dataUpdatedAt)),this.#t=e)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus===`idle`&&this.#r.remove(this)}setData(e,t){let n=kd(this.state.data,e,this.options);return this.#c({data:n,type:`success`,dataUpdatedAt:t?.updatedAt,manual:t?.manual}),n}setState(e){this.#c({type:`setState`,state:e})}cancel(e){let t=this.#a?.promise;return this.#a?.cancel(e),t?t.then(fd).catch(fd):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#t}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>gd(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===Md||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0&&this.observers.some(e=>gd(e.options.staleTime,this)===`static`)}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e===`static`?!1:this.state.isInvalidated?!0:!hd(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(e=>e.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#a?.continue()}onOnline(){this.observers.find(e=>e.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#a?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:`observerAdded`,query:this,observer:e}))}removeObserver(e){let t=this.observers.indexOf(e);t!==-1&&(this.observers.splice(t,1),this.observers.length||(this.#a&&(this.#s||this.state.fetchStatus===`paused`&&this.state.status===`pending`?this.#a.cancel({revert:!0}):this.#a.cancelRetry()),this.scheduleGc()),this.#r.notify({type:`observerRemoved`,query:this,observer:e}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||this.#c({type:`invalidate`})}async fetch(e,t){if(this.state.fetchStatus!==`idle`&&this.#a?.status()!==`rejected`){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#a)return this.#a.continueRetry(),this.#a.promise}if(e&&this.setOptions(e),!this.options.queryFn){let e=this.observers.find(e=>e.options.queryFn);e&&this.setOptions(e.options)}let n=new AbortController,r=e=>{Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(this.#s=!0,n.signal)})},i=()=>{let e=Nd(this.options,t),n=(()=>{let e={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(e),e})();return this.#s=!1,this.options.persister?this.options.persister(e,n,this):e(n)},a=(()=>{let e={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(e),e})();(this.#e===`infinite`?Yd(this.options.pages):this.options.behavior)?.onFetch(a,this),this.#n=this.state,(this.state.fetchStatus===`idle`||this.state.fetchMeta!==a.fetchOptions?.meta)&&this.#c({type:`fetch`,meta:a.fetchOptions?.meta});let o=this.#a=qd({initialPromise:t?.initialPromise,fn:a.fetchFn,onCancel:e=>{e instanceof Kd&&e.revert&&this.setState({...this.#n,fetchStatus:`idle`}),n.abort()},onFail:(e,t)=>{this.#c({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#c({type:`pause`})},onContinue:()=>{this.#c({type:`continue`})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0});try{let e=await o.start();if(e===void 0)throw Error(`${this.queryHash} data is undefined`);return this.setData(e),this.#r.config.onSuccess?.(e,this),this.#r.config.onSettled?.(e,this.state.error,this),e}catch(e){if(e instanceof Kd){if(e.silent)return this.#a.promise;if(e.revert){if(this.state.data===void 0)throw e;return this.state.data}}throw this.#c({type:`error`,error:e}),this.#r.config.onError?.(e,this),this.#r.config.onSettled?.(this.state.data,e,this),e}finally{this.#a===o&&(this.#a=void 0),this.scheduleGc()}}#c(e){let t=t=>{switch(e.type){case`failed`:return{...t,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case`pause`:return{...t,fetchStatus:`paused`};case`continue`:return{...t,fetchStatus:`fetching`};case`fetch`:return{...t,...$d(t.data,this.options),fetchMeta:e.meta??null};case`success`:let n={...t,...ef(e.data,e.dataUpdatedAt),dataUpdateCount:t.dataUpdateCount+1,...!e.manual&&{fetchStatus:`idle`,fetchFailureCount:0,fetchFailureReason:null}};return this.#n=e.manual?n:void 0,n;case`error`:let r=e.error;return{...t,error:r,errorUpdateCount:t.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:t.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:`idle`,status:`error`,isInvalidated:!0};case`invalidate`:return{...t,isInvalidated:!0};case`setState`:return{...t,...e.state}}};this.state=t(this.state),Hd.batch(()=>{this.observers.slice().forEach(e=>{e.onQueryUpdate()}),this.#r.notify({query:this,type:`updated`,action:e})})}};function $d(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Gd(t.networkMode)?`fetching`:`paused`,...e===void 0&&{error:null,status:`pending`}}}function ef(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:`success`}}function tf(e){let t=typeof e.initialData==`function`?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt==`function`?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?`success`:`pending`,fetchStatus:`idle`}}var nf=class extends Rd{#e;#t=void 0;#n=void 0;#r=void 0;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p=new Set;constructor(e,t){super(),this.options=t,this.#e=e,this.#o=null,this.bindMethods(),this.setOptions(t)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#t.addObserver(this),af(this.#t,this.options)?this.#m():this.updateResult(),this.#y())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return of(this.#t,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return of(this.#t,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#b(),this.#x(),this.#t.removeObserver(this)}setOptions(e){let t=this.options,n=this.#t;if(this.options=this.#e.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!=`boolean`&&typeof this.options.enabled!=`function`&&typeof gd(this.options.enabled,this.#t)!=`boolean`)throw Error(`Expected enabled to be a boolean or a callback that returns a boolean`);this.#S(),this.#t.setOptions(this.options),t._defaulted&&!wd(this.options,t)&&this.#e.getQueryCache().notify({type:`observerOptionsUpdated`,query:this.#t,observer:this});let r=this.hasListeners();r&&sf(this.#t,n,this.options,t)&&this.#m(),this.updateResult(),r&&(this.#t!==n||gd(this.options.enabled,this.#t)!==gd(t.enabled,this.#t)||gd(this.options.staleTime,this.#t)!==gd(t.staleTime,this.#t))&&this.#g();let i=this.#_();r&&(this.#t!==n||gd(this.options.enabled,this.#t)!==gd(t.enabled,this.#t)||i!==this.#f)&&this.#v(i)}getOptimisticResult(e){let t=this.#e.getQueryCache().build(this.#e,e),n=this.createResult(t,e);return wd(this.getCurrentResult(),n)||(this.#r=n,this.#a=this.options,this.#i=this.#t.state),n}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(e,n)=>(this.trackProp(n),t?.(n),Reflect.get(e,n))})}trackProp(e){this.#p.add(e)}getCurrentQuery(){return this.#t}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#e.defaultQueryOptions(e),n=this.#e.getQueryCache().build(this.#e,t),r=()=>{},i,a=new Promise(e=>{i=e,r=this.#e.getQueryCache().subscribe(i=>{i.type===`updated`&&i.query.queryHash===n.queryHash&&n.state.data!==void 0&&(r(),e(this.createResult(n,t)))})});return Promise.race([n.fetch(t).then(()=>{let e=this.createResult(n,t);return i?.(e),e}).finally(()=>{r()}),a])}fetch(e){return this.#m({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#m(e){this.#S();let t=this.#t.fetch(this.options,e);return e?.throwOnError||(t=t.catch(fd)),t}#h(e){return!Ld()&&gd(this.options.enabled,this.#t)!==!1&&md(e)}#g(){this.#b();let e=gd(this.options.staleTime,this.#t);if(this.#r.isStale||!this.#h(e))return;let t=hd(this.#r.dataUpdatedAt,e)+1;this.#u=ld.setTimeout(()=>{this.#r.isStale||this.updateResult()},t)}#_(){return gd(this.options.refetchInterval,this.#t)??!1}#v(e){this.#x(),this.#f=e,this.#f!==0&&this.#h(this.#f)&&(this.#d=ld.setInterval(()=>{(this.options.refetchIntervalInBackground||zd.isFocused())&&this.#m()},this.#f))}#y(){this.#g(),this.#v(this.#_())}#b(){this.#u!==void 0&&(ld.clearTimeout(this.#u),this.#u=void 0)}#x(){this.#d!==void 0&&(ld.clearInterval(this.#d),this.#d=void 0)}createResult(e,t){let n=this.#t,r=this.options,i=this.#r,a=this.#i,o=this.#a,s=e===n?this.#n:e.state,{state:c}=e,l={...c},u=!1,d;if(t._optimisticResults){let i=this.hasListeners(),a=!i&&af(e,t),o=i&&sf(e,n,t,r);(a||o)&&(l={...l,...$d(c.data,e.options)}),t._optimisticResults===`isRestoring`&&(l.fetchStatus=`idle`)}let{error:f,errorUpdatedAt:p,status:m}=l;d=l.data;let h=!1;if(t.placeholderData!==void 0&&d===void 0&&m===`pending`){let e;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(e=i.data,h=!0):e=typeof t.placeholderData==`function`?t.placeholderData(this.#l?.state.data,this.#l):t.placeholderData,e!==void 0&&(m=`success`,d=kd(i?.data,e,t),u=!0)}if(t.select&&d!==void 0&&!h){if(i&&d===a?.data&&t.select===this.#s)d=this.#c;else try{this.#s=t.select,d=t.select(d),d=kd(i?.data,d,t),this.#c=d,this.#o=null}catch(e){this.#o=e}}else d===void 0&&(this.#o=null);this.#o&&(f=this.#o,d=this.#c,p=Date.now(),m=`error`,u=!1);let g=l.fetchStatus===`fetching`,_=m===`pending`,v=m===`error`,y=_&&g,b=d!==void 0;return{status:m,fetchStatus:l.fetchStatus,isPending:_,isSuccess:m===`success`,isError:v,isInitialLoading:y,isLoading:y,data:d,dataUpdatedAt:l.dataUpdatedAt,error:f,errorUpdatedAt:p,failureCount:l.fetchFailureCount,failureReason:l.fetchFailureReason,errorUpdateCount:l.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:l.dataUpdateCount>s.dataUpdateCount||l.errorUpdateCount>s.errorUpdateCount,isFetching:g,isRefetching:g&&!_,isLoadingError:v&&!b,isPaused:l.fetchStatus===`paused`,isPlaceholderData:u,isRefetchError:v&&b,isStale:cf(e,t),refetch:this.refetch,isEnabled:gd(t.enabled,e)!==!1}}updateResult(){let e=this.#r,t=this.createResult(this.#t,this.options);if(this.#i=this.#t.state,this.#a=this.options,this.#i.data!==void 0&&(this.#l=this.#t),wd(t,e))return;this.#r=t;let n=(()=>{if(!e)return!0;let{notifyOnChangeProps:t}=this.options,n=typeof t==`function`?t():t;if(n===`all`||!n&&!this.#p.size)return!0;let r=new Set(n??this.#p);return this.options.throwOnError&&r.add(`error`),Object.keys(this.#r).some(t=>{let n=t;return this.#r[n]!==e[n]&&r.has(n)})})();Hd.batch(()=>{n&&this.listeners.forEach(e=>{e(this.#r)}),this.#e.getQueryCache().notify({query:this.#t,type:`observerResultsUpdated`})})}#S(){let e=this.#e.getQueryCache().build(this.#e,this.options);if(e===this.#t)return;let t=this.#t;this.#t=e,this.#n=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#y()}};function rf(e,t){return gd(t.enabled,e)!==!1&&e.state.data===void 0&&(e.state.status!==`error`||gd(t.retryOnMount,e)!==!1)}function af(e,t){return rf(e,t)||e.state.data!==void 0&&of(e,t,t.refetchOnMount)}function of(e,t,n){if(gd(t.enabled,e)!==!1&&gd(t.staleTime,e)!==`static`){let r=gd(n,e);return r===`always`||r!==!1&&cf(e,t)}return!1}function sf(e,t,n,r){return(e!==t||gd(r.enabled,e)===!1)&&(!n.suspense||e.state.status!==`error`)&&cf(e,n)}function cf(e,t){return gd(t.enabled,e)!==!1&&e.isStaleByTime(gd(t.staleTime,e))}var lf=class extends Jd{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||uf(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??(this.state.status===`pending`?this.execute(this.state.variables):Promise.resolve())}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey},r=this.#r=qd({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)}),i=this.state.status===`pending`,a=!r.canStart();try{if(i)t();else{this.#i({type:`pending`,variables:e,isPaused:a}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:a})}let o=await r.start();return await this.#n.config.onSuccess?.(o,e,this.state.context,this,n),await this.options.onSuccess?.(o,e,this.state.context,n),await this.#n.config.onSettled?.(o,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(o,null,e,this.state.context,n),this.#i({type:`success`,data:o}),o}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#r===r&&(this.#r=void 0),this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),Hd.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function uf(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var df=class extends Rd{#e;#t;#n;constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}build(e,t,n){let r=new lf({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=ff(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=ff(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=ff(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=ff(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){Hd.batch(()=>{let e=this.getAll();this.#e.clear(),this.#t.clear(),e.forEach(e=>{this.notify({type:`removed`,mutation:e})})})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>vd(t,e))}findAll(e={}){return this.getAll().filter(t=>vd(e,t))}notify(e){Hd.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return Hd.batch(()=>Promise.all(e.map(e=>e.continue().catch(fd))))}};function ff(e){return e.options.scope?.id}var pf=class extends Rd{#e;#t=void 0;#n;#r;constructor(e,t){super(),this.#e=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#e.defaultMutationOptions(e),wd(this.options,t)||this.#e.getMutationCache().notify({type:`observerOptionsUpdated`,mutation:this.#n,observer:this}),t?.mutationKey&&this.options.mutationKey&&bd(t.mutationKey)!==bd(this.options.mutationKey)?this.reset():this.#n?.state.status===`pending`&&this.#n.setOptions(this.options)}onSubscribe(){this.listeners.size===1&&this.#n&&(this.#n.addObserver(this),this.#i())}onUnsubscribe(){this.hasListeners()||this.#n?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#a(e)}getCurrentResult(){return this.#t}reset(){this.#n?.removeObserver(this),this.#n=void 0,this.#i(),this.#a()}mutate(e,t){return this.#r=t,this.#n?.removeObserver(this),this.#n=this.#e.getMutationCache().build(this.#e,this.options),this.#n.addObserver(this),this.#n.execute(e)}#i(){let e=this.#n?.state??uf();this.#t={...e,isPending:e.status===`pending`,isSuccess:e.status===`success`,isError:e.status===`error`,isIdle:e.status===`idle`,mutate:this.mutate,reset:this.reset}}#a(e){Hd.batch(()=>{let t=this.#r;if(t&&this.hasListeners()){let n=this.#t.variables,r=this.#t.context,i={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type===`success`){try{t.onSuccess?.(e.data,n,r,i)}catch(e){Promise.reject(e)}try{t.onSettled?.(e.data,null,n,r,i)}catch(e){Promise.reject(e)}}else if(e?.type===`error`){try{t.onError?.(e.error,n,r,i)}catch(e){Promise.reject(e)}try{t.onSettled?.(void 0,e.error,n,r,i)}catch(e){Promise.reject(e)}}}this.listeners.forEach(e=>{e(this.#t)})})}},mf=class extends Rd{#e;constructor(e={}){super(),this.config=e,this.#e=new Map}build(e,t,n){let r=t.queryKey,i=t.queryHash??yd(r,t),a=this.get(i);return a||(a=new Qd({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){this.#e.get(e.queryHash)===e&&(e.destroy(),this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){Hd.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>_d(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>_d(e,t)):t}notify(e){Hd.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){Hd.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){Hd.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},hf=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new mf,this.#t=e.mutationCache||new df,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=zd.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=Ud.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(gd(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=pd(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return Hd.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;Hd.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return Hd.batch(()=>{let r=n.findAll(e),i=new Set(r);return r.forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,predicate:e=>i.has(e)},t)})}cancelQueries(e,t={}){let n={revert:!0,...t},r=Hd.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(fd).catch(fd)}invalidateQueries(e,t={}){return Hd.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=Hd.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(fd)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(fd)}async query(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t),r=n.isStaleByTime(gd(t.staleTime,n))?await n.fetch(t):n.state.data,i=t.select;return i?i(r):r}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(gd(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(fd).catch(fd)}infiniteQuery(e){return e._type=`infinite`,this.query(e)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(fd).catch(fd)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return Ud.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(bd(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{xd(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(bd(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{xd(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=yd(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===Md&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},gf=J.createContext(!1),_f=()=>J.useContext(gf);gf.Provider;function vf(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var yf=J.createContext(vf()),bf=()=>J.useContext(yf),xf=(e,t,n)=>{let r=n?.state.status===`error`&&typeof e.throwOnError==`function`?Pd(e.throwOnError,[n.state.error,n]):e.throwOnError;(e.suspense||r)&&(t.isReset()||(e.retryOnMount=!1))},Sf=e=>{J.useEffect(()=>{e.clearReset()},[e])},Cf=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||Pd(n,[e.error,r])),wf=e=>{if(e.suspense){let t=1e3,n=e=>e===`static`?e:Math.max(e??t,t),r=e.staleTime;e.staleTime=typeof r==`function`?(...e)=>n(r(...e)):n(r),typeof e.gcTime==`number`&&(e.gcTime=Math.max(e.gcTime,t))}},Tf=(e,t)=>e?.suspense&&t.isPending,Ef=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function Df(e,t,n){let r=_f(),i=bf(),a=od(n),o=a.defaultQueryOptions(e),s=a.getQueryCache().get(o.queryHash),c=e.subscribed!==!1;o._optimisticResults=r?`isRestoring`:c?`optimistic`:void 0,wf(o),xf(o,i,s),Sf(i);let[l]=J.useState(()=>new t(a,o)),u=l.getOptimisticResult(o),d=!r&&c;if(J.useSyncExternalStore(J.useCallback(e=>{let t=d?l.subscribe(Hd.batchCalls(e)):fd;return l.updateResult(),t},[l,d]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),J.useEffect(()=>{l.setOptions(o)},[o,l]),Tf(o,u))throw Ef(o,l,i);if(Cf({result:u,errorResetBoundary:i,throwOnError:o.throwOnError,query:s,suspense:o.suspense}))throw u.error;return o.notifyOnChangeProps?u:l.trackResult(u)}function Of(e,t){return Df(e,nf,t)}function kf(e,t){let n=od(t),[r]=J.useState(()=>new pf(n,e));J.useEffect(()=>{r.setOptions(e)},[r,e]);let i=J.useSyncExternalStore(J.useCallback(e=>r.subscribe(Hd.batchCalls(e)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),a=J.useCallback((...e)=>{r.mutate(e[0],e[1]).catch(fd)},[r]);if(i.error&&Pd(r.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:a,mutateAsync:i.mutate}}var Af={lists:e=>[`discussion`,e,`comments`],file:(e,t)=>[`discussion`,e,`comments`,`file`,t],all:e=>[`discussion`,e,`comments`,`project`],summary:e=>[`discussion`,e,`summary`],mentions:e=>[`discussion`,e,`mentions`],candidates:e=>[`discussion`,e,`candidates`]},jf=[],Mf=[],Nf=e=>e instanceof He&&[401,403,404].includes(e.status);function Pf(){return new hf({defaultOptions:{queries:{staleTime:3e4,gcTime:3e5,retry:(e,t)=>!Nf(t)&&e<2&&(!(t instanceof He)||t.status===0||t.status>=500||t.code===`INVALID_RESPONSE`),retryDelay:e=>Math.min(500*2**e,2e3),refetchOnReconnect:`always`},mutations:{retry:!1}}})}var Ff=new WeakMap;function If(e){let t=Ff.get(e);return t||(t={next:0,summaries:new Map},Ff.set(e,t)),++t.next}function Lf(e,t,n,r){let i=Ff.get(e);!n||!i||r<(i.summaries.get(t)??0)||(i.summaries.set(t,r),e.setQueryData(Af.summary(t),n))}function Rf(e,t){if(t.kind===`created`)return e.some(e=>e.id===t.comment.id)?e:[...e,t.comment];let n=t.kind===`edited`?t.comment.id:t.kind===`resolved`?t.resolution.id:t.commentId;return t.kind===`deleted`?e.filter(e=>e.id!==n):e.map(e=>{if(e.id!==n)return e;if(t.kind===`suggestion`)return{...e,suggestion:t.suggestion};if(t.kind===`edited`)return{...e,...t.comment};if(t.kind===`resolved`)return{...e,...t.resolution};if(t.kind===`reply-deleted`)return{...e,replies:e.replies.filter(e=>e.id!==t.replyId)};let r=e.replies.some(e=>e.id===t.reply.id);return{...e,replies:r?e.replies.map(e=>e.id===t.reply.id?t.reply:e):[...e.replies,t.reply]}})}async function zf(e,t,n){await Promise.all([e.cancelQueries({queryKey:Af.lists(t)}),e.cancelQueries({queryKey:Af.mentions(t)})]);let r=n.change,i=r.kind===`created`||r.kind===`edited`?r.comment.filePath:r.kind===`resolved`?r.resolution.filePath:r.filePath;if(e.setQueriesData({queryKey:Af.lists(t)},e=>{if(!e)return e;let t=e.comments;return r.kind===`created`?e:{...e,comments:Rf(t,r),summary:n.summary}}),r.kind===`created`)for(let a of[Af.file(t,i),Af.all(t)])e.setQueryData(a,e=>e&&{...e,comments:Rf(e.comments,r),summary:n.summary});Lf(e,t,n.summary,If(e)),e.setQueryData(Af.mentions(t),e=>e&&{mentions:e.mentions.filter(e=>r.kind===`deleted`?e.commentId!==r.commentId:r.kind===`resolved`&&r.resolution.resolved?e.commentId!==r.resolution.id:r.kind===`suggestion`&&e.kind===`review`&&e.commentId===r.commentId?r.suggestion.status===`pending`&&e.readAt===null:r.kind!==`reply-deleted`||e.replyId!==r.replyId)})}async function Bf(e,t){await Promise.all([Af.lists(t),Af.mentions(t)].map(async t=>{await e.cancelQueries({queryKey:t}),await e.invalidateQueries({queryKey:t})}))}function Vf(e,t,n,r,i){let a=od(),o=async(t,n)=>{let r=If(a),i=await K(t,{signal:n});return n.aborted||Lf(a,e,i.summary,r),i},s=Of({queryKey:Af.file(e,t),enabled:!!t,queryFn:({signal:n})=>o(`/api/projects/${e}/comments?path=${encodeURIComponent(t)}`,n)}),c=Of({queryKey:Af.all(e),enabled:n===`project`,queryFn:({signal:t})=>o(`/api/projects/${e}/comments?scope=project`,t)}),l=Of({queryKey:Af.summary(e),enabled:!1}),u=(0,J.useRef)({projectId:e,revision:r,sourceOrderRevision:i});(0,J.useEffect)(()=>{let t=u.current;if(u.current={projectId:e,revision:r,sourceOrderRevision:i},t.projectId!==e)return;let n=t.revision===r?t.sourceOrderRevision===i?null:Af.all(e):Af.lists(e);n&&a.cancelQueries({queryKey:n}).then(()=>a.invalidateQueries({queryKey:n}))},[a,e,r,i]);let d=n===`project`?c:s,f=s.error?q(s.error):``;return{comments:Nf(s.error)?jf:s.data?.comments??jf,commentsFilePath:t&&(s.data||s.error)?t:``,commentsReady:!(!t||!s.data||s.isFetching||s.error),fileCommentsLoading:!!(t&&s.isFetching),fileCommentsError:f,reviewComments:Nf(d.error)?jf:d.data?.comments??jf,reviewCommentsLoading:!(n!==`project`&&!t||!d.isFetching),reviewCommentsError:d.error?q(d.error):``,projectCommentSummary:Nf(s.error)||Nf(c.error)?null:l.data??null,refreshComments:()=>Bf(a,e)}}function Hf(e){let t=od(),n=kf({retry:!1,mutationFn:async({id:e,path:n,options:r})=>{let i=await K(`/api/projects/${e}/comments${n}`,r);return await zf(t,e,i),Bf(t,e),i},onError:(e,{id:n})=>{e instanceof He&&[`SUGGESTION_UPDATED`,`SUGGESTION_DECIDED`,`SUGGESTION_APPLYING`].includes(e.code??``)&&Bf(t,n)}});return(t,r)=>n.mutateAsync({id:e,path:t,options:r})}function Uf(e,t,n,r){let i=!!e.trim(),a=n&&t&&n.replacementText!==t?n:null;return{hasComment:i,edit:a,issue:!i&&!a?`empty`:a?.reviewerId&&a.reviewerId===r?`selfReview`:a&&!a.reviewerId?`reviewer`:null,kind:a?i?`commentAndEdit`:`editOnly`:`commentOnly`}}function Wf({projectId:e,activeFile:t,content:n,permission:r,revision:i,sourceOrderRevision:a,selection:o,save:s,saveFailureMessage:c,onError:l,onAdded:u}){let d=(0,J.useMemo)(()=>new id,[e]),f=(0,J.useMemo)(()=>({active:!1}),[e]);(0,J.useEffect)(()=>(f.active=!0,()=>{f.active=!1}),[f]);let[p,m]=(0,J.useState)(`file`),h=Vf(e,t,p,i,a),g=Hf(e),[_,v]=(0,J.useState)(null),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(``),[w,T]=(0,J.useState)(null),E=(0,J.useRef)(w);E.current=w;let[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(null),[j,M]=(0,J.useState)(!1),[ee,N]=(0,J.useState)(!1),[P,te]=(0,J.useState)(``),F=(0,J.useRef)(!1),I=(0,J.useRef)(t),L=(0,J.useRef)(s),ne=(0,J.useRef)(l),R=(0,J.useRef)(u),re=(0,J.useRef)(D),ie=(0,J.useRef)(S);re.current=D,ie.current=S,I.current=t,L.current=s,ne.current=l,R.current=u,(0,J.useEffect)(()=>{v(null),m(`file`),x(!1),O(null),A(null),C(``),T(null),M(!1),te(``)},[e]),(0,J.useEffect)(()=>{x(!1),O(null),A(null),C(``),T(null),M(!1),te(``)},[t]);let z=(e,r)=>{if(!t)return;te(``);let i={filePath:t,selection:{...e??o},sourceHash:lu(r??n)},a=d.getNew(t);O(a??i),C(a?.content??``),T(a?.suggestion??null),A(i),M(!!a),x(!0)},ae=e=>{C(e),D&&(e||w?d.setNew({...D,content:e,suggestion:w}):d.discardNew(D.filePath))},oe=e=>{T(e),D&&(S||e?d.setNew({...D,content:S,suggestion:e}):d.discardNew(D.filePath))},se=()=>{F.current||(x(!1),te(``))},B=()=>{F.current||(D&&d.discardNew(D.filePath),C(``),T(null),O(null),A(null),M(!1),se())},ce=()=>{!F.current&&k&&k.filePath===I.current&&(O(k),(S||w)&&d.setNew({...k,content:S,suggestion:w}),M(!1),te(``))},V=async()=>{let e=D,t=S,n=w;if(!e||F.current)return;let i=Uf(t,e.selection.selectedText,n);if(i.issue)return;let a=i.edit,o=()=>{let r=re.current;return r?.filePath===e.filePath&&r.sourceHash===e.sourceHash&&r.selection.startOffset===e.selection.startOffset&&r.selection.endOffset===e.selection.endOffset&&ie.current===t&&E.current===n};F.current=!0,N(!0),te(``);try{if(r!==`read`&&!await L.current()){o()&&te(c);return}await g(``,{method:`POST`,body:JSON.stringify({path:e.filePath,content:t.trim()||(a?y.t(`suggestions.defaultComment`):t),...e.selection,sourceHash:e.sourceHash,...a?{suggestion:a}:{}})});let i=d.getNew(e.filePath);if(i?.content===t&&JSON.stringify(i.suggestion??null)===JSON.stringify(n)&&i.sourceHash===e.sourceHash&&i.selection.startOffset===e.selection.startOffset&&i.selection.endOffset===e.selection.endOffset&&d.discardNew(e.filePath),!f.active)return;o()&&(x(!1),O(null),C(``),T(null),M(!1)),R.current()}catch(e){o()&&te(q(e))}finally{F.current=!1,N(!1)}},H=async e=>{try{await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({resolved:!e.resolved})})}catch(e){f.active&&ne.current(q(e))}},U=async(e,t)=>(await g(`/${e.id}/replies`,{method:`POST`,body:JSON.stringify({content:t})}),!0),le=async(e,t)=>(await g(`/${e.id}`,{method:`PATCH`,body:JSON.stringify({content:t})}),!0),ue=async e=>(await g(`/${e.id}`,{method:`DELETE`}),f.active&&(v(t=>t?.id===e.id?null:t),d.discard(e.id)),!0),de=async(e,t,n)=>(await g(`/${e.id}/replies/${t}`,{method:`PATCH`,body:JSON.stringify({content:n})}),!0),fe=async(e,t)=>(await g(`/${e.id}/replies/${t}`,{method:`DELETE`}),d.discard(e.id,`edit-reply:${t}`),!0);return{commentDraftStore:d,...h,retryFileComments:h.refreshComments,retryReviewComments:h.refreshComments,commentScope:p,setCommentScope:m,focusComment:_,setFocusComment:v,commentOpen:b,openComment:z,closeComment:se,cancelComment:B,commentDraftRestored:j,commentDraftCanRetarget:!(!D||!k||D.sourceHash===k.sourceHash&&D.selection.startOffset===k.selection.startOffset&&D.selection.endOffset===k.selection.endOffset),useCurrentCommentSelection:ce,commentText:S,commentSuggestion:w,setCommentSuggestion:oe,setCommentText:ae,commentSelection:D?.selection??o,commentSubmitting:ee,commentError:P,addComment:V,toggleComment:H,replyToComment:U,editComment:le,deleteComment:ue,editCommentReply:de,deleteCommentReply:fe}}function Gf(e){let t=new Map;for(let n of e)for(let e of[n,...n.replies])t.has(e.authorId)||t.set(e.authorId,{authorId:e.authorId,authorUsername:e.authorUsername,authorDisplayName:e.authorDisplayName,authorAvatarStyle:e.authorAvatarStyle});return[...t.values()].sort((e,t)=>(e.authorDisplayName??e.authorUsername??``).localeCompare(t.authorDisplayName??t.authorUsername??``))}function Kf(e,t){let n=t.participantIds;return!n?.size||n.has(e.authorId)||!t.topLevelOnly&&e.replies.some(e=>n.has(e.authorId))}function qf(e,t=`source`){return[...e].sort((e,n)=>{if(t===`time`)return Date.parse(n.createdAt)-Date.parse(e.createdAt);let r=e.sourceOrder??1/0,i=n.sourceOrder??1/0;return r===i?e.filePath.localeCompare(n.filePath,`en`,{numeric:!0})||e.startLine-n.startLine||e.startOffset-n.startOffset:r-i})}function Jf(e,t){return t.scope===`project`||e.filePath===t.activeFile}function Yf(e,t){return t===`unresolved`?!e.resolved:e.resolved}function Xf(e,t){return t.some(t=>t.commentId===e.id&&t.readAt===null)}function Zf(e,t){return e.filter(e=>Jf(e,t)&&Kf(e,t)&&Yf(e,t.filter)&&(!t.unreadMentionsOnly||Xf(e,t.unreadMentions)))}function Qf(e,t,n=[]){let r=new Set(n.filter(e=>!!e));return qf(e.filter(e=>Jf(e,t)?r.has(e.id)||Kf(e,t)&&Yf(e,t.filter)&&(!t.unreadMentionsOnly||Xf(e,t.unreadMentions)):!1),t.sort)}function $f(e,t,n){let r=e.find(e=>e.id===t&&e.filePath===n&&!e.resolved);return r?[r]:[]}function ep(e,t){return e.filter(e=>e.filePath===t)}function tp(e,t,n){return!e||e.filePath!==t||n!==t?null:e}function np(e,t,n,r,i,a){return!e||e.filePath!==t||n!==t||r!==t||!i?null:a.find(n=>n.id===e.id&&n.filePath===t)??null}function rp(e,t){if(!t)return 0;let n=e.findIndex(e=>e.id===t);return n<0?0:n+1}function ip(e,t,n){if(!e.length)return null;let r=t?e.findIndex(e=>e.id===t):-1;if(r<0)return n===1?e[0]:null;let i=r+n;return i>=0&&i<e.length?e[i]:null}function ap(e,t,n,r){let i=od(),a=Af.mentions(e),o=Of({queryKey:a,queryFn:({signal:t})=>K(`/api/projects/${e}/mentions?unread=1&limit=100`,{signal:t})}),s=Nf(o.error)?Mf:o.data?.mentions??Mf,c=(0,J.useRef)({onError:n,onRead:r});c.current={onError:n,onRead:r};let l=(0,J.useMemo)(()=>({active:!1,pending:new Map}),[e]);(0,J.useEffect)(()=>(l.active=!0,()=>{l.active=!1}),[l]);let u=(0,J.useRef)({projectId:e,revision:t}),d=async(e=!1)=>{if(!l.active)return;await i.cancelQueries({queryKey:a});let t=await o.refetch();e&&t.error&&l.active&&c.current.onError(q(t.error))};(0,J.useEffect)(()=>{let n=u.current;u.current={projectId:e,revision:t},n.projectId===e&&n.revision!==t&&d()},[e,t]);let f=t=>{let n=t??`all`,r=l.pending.get(n);if(r)return r;let o=(async()=>{try{let n=await K(`/api/projects/${e}/mentions/${t?`${encodeURIComponent(t)}/read`:`read-all`}`,{method:`POST`});if(!l.active||(await i.cancelQueries({queryKey:a}),!l.active))return!1;i.setQueryData(a,e=>e&&{mentions:t?e.mentions.filter(e=>e.id!==t):[]});let r=Number(n.changed)||0;return(r||!t)&&c.current.onRead?.(r,!t),i.invalidateQueries({queryKey:a}),!0}catch(e){return l.active&&c.current.onError(q(e)),!1}finally{l.pending.delete(n)}})();return l.pending.set(n,o),o};return{unreadMentions:s,mentionsError:o.error?q(o.error):``,refresh:d,markMentionRead:e=>f(e),markAllMentionsRead:()=>f()}}function op({children:e}){let[t]=(0,J.useState)(Pf);return(0,Y.jsx)(sd,{client:t,children:e})}function sp(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`update`||t.kind===`move`||t.kind===`delete`)&&typeof t.revision==`string`}function cp(e,t,n,r){let[i,a]=(0,J.useState)(`connecting`),[o,s]=(0,J.useState)(!1),[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(``),[S,C]=(0,J.useState)([]),[w,T]=(0,J.useState)(!1),[E,D]=(0,J.useState)(n),[O,k]=(0,J.useState)(null),[A,j]=(0,J.useState)(!1),M=(0,J.useRef)(t),ee=(0,J.useRef)(r);M.current=t,ee.current=r,(0,J.useEffect)(()=>{let n=e.compileStates();d(n[t]??null)},[t,e]),(0,J.useEffect)(()=>{let t=()=>l(e.sessions()),n=()=>{s(!1),l([]),d(null),p(null),h(``),_(!1),y(``),x(``),C([])},r=({status:t})=>{a(t),t===`connected`?s(e.synced):n()},i=e=>{s(e),e&&(t(),c())},o=()=>{a(`disconnected`),n()},c=()=>{_(e.meta.get(`historyWarning`)===!0);let t=e.meta.get(`filesEvent`);sp(t)&&p(t);let n=e.meta.get(`commentsRevision`);typeof n==`string`&&h(n);let r=e.meta.get(`dictionaryRevision`);typeof r==`string`&&y(r);let i=e.meta.get(`chktexSettingsRevision`);typeof i==`string`&&x(i);let a=e.compileStates();d(a[M.current]??null)},u=()=>{let t=e.compileStates();d(t[M.current]??null)};e.awareness.on(`change`,t),e.provider.on(`status`,r),e.provider.on(`sync`,i),e.provider.on(`connection-close`,o),e.provider.on(`connection-error`,o),e.meta.observe(c);let f=e.onCompileStates(u),m=e.onProtocolUpgrade(()=>{j(!0),a(`disconnected`),n()}),g=e.onFormatLeaseState(()=>C(e.formatLeaseStates())),v=()=>{if(!ee.current||e.currentPermission!==`read`)return;let t=e.hasWritableDraft,n=e.hasOtherWritableDraft;(t||n)&&k({previous:`edit`,localDraftReady:t,otherTabDraft:n})},b=e.onDraftReady(()=>{T(!0),v()}),S=e.onPermissionChanged((t,r)=>{t===`revoked`?(a(`disconnected`),n()):(D(t),t===`read`&&r!==`read`?k({previous:r,localDraftReady:e.hasWritableDraft,otherTabDraft:e.hasOtherWritableDraft}):t!==`read`&&k(null))});return t(),c(),a(e.connected?`connected`:`connecting`),s(e.synced),()=>{e.awareness.off(`change`,t),e.provider.off(`status`,r),e.provider.off(`sync`,i),e.provider.off(`connection-close`,o),e.provider.off(`connection-error`,o),e.meta.unobserve(c),f(),m(),g(),b(),S()}},[e]),(0,J.useEffect)(()=>{e.setPermission(n),D(n),r&&n===`read`&&(e.hasWritableDraft||e.hasOtherWritableDraft)?k({previous:`edit`,localDraftReady:e.hasWritableDraft,otherTabDraft:e.hasOtherWritableDraft}):n!==`read`&&k(null)},[e,n,r]),(0,J.useEffect)(()=>{r&&e.connect()},[e,r]);let N=O!==null;return(0,J.useEffect)(()=>{if(!N)return;let t=()=>{if(e.currentPermission!==`read`)return;let t=e.hasWritableDraft,n=e.hasOtherWritableDraft;k(e=>!e||e.localDraftReady===t&&e.otherTabDraft===n?e:{...e,localDraftReady:t,otherTabDraft:n})};t();let n=window.setInterval(t,2e3);return()=>window.clearInterval(n)},[e,N]),{collaboration:e,status:i===`connected`&&!o?`syncing`:i,synced:i===`connected`&&o,activeSessions:c,compileState:u,setCompileState:d,formatLeaseStates:S,filesEvent:f,commentsRevision:m,historyWarning:g,dictionaryRevision:v,chktexSettingsRevision:b,localDraftReady:w,permission:E,protocolUpgradeRequired:A,reconnect:()=>{A||(a(`connecting`),s(!1),l([]),d(null),C([]),e.reconnect())},permissionDowngrade:O,dismissPermissionDowngrade:()=>k(null),discardLocalDraft:async()=>await e.discardLocalDraft()?(k(null),window.location.reload(),!0):(k(e=>e&&{...e,otherTabDraft:!0}),!1)}}var lp=new Map,up=class{constructor(e){this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&this.onmessage!==null&&this.onmessage({data:ci(t.newValue||``)}),wr(this._onChange)}postMessage(e){Cr.setItem(this.room,si(ni(e)))}close(){Tr(this._onChange)}},dp=typeof BroadcastChannel>`u`?up:BroadcastChannel,fp=e=>Ht(lp,e,()=>{let t=Gt(),n=new dp(e);return n.onmessage=e=>t.forEach(t=>t(e.data,`broadcastchannel`)),{bc:n,subs:t}}),pp=(e,t)=>(fp(e).subs.add(t),t),mp=(e,t)=>{let n=fp(e),r=n.subs.delete(t);return r&&n.subs.size===0&&(n.bc.close(),lp.delete(e)),r},hp=(e,t,n=null)=>{let r=fp(e);r.bc.postMessage(t),r.subs.forEach(e=>e(t,n))},gp=(e,t)=>{Z(e,0),Pn(e,Go(t))},_p=(e,t,n)=>{Z(e,1),Pn(e,zo(t,n))},vp=(e,t,n)=>_p(t,n,rr(e)),yp=(e,t,n,r)=>{try{Io(t,rr(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},bp=(e,t)=>{Z(e,2),Pn(e,t)},xp=yp,Sp=(e,t,n,r,i)=>{let a=Q(e);switch(a){case 0:vp(e,t,n);break;case 1:yp(e,n,r,i);break;case 2:xp(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},Cp=(e,t,n)=>{Q(e)===0&&n(t,or(e))},wp=3e4,Tp=class extends en{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=vr();this.getLocalState()!==null&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&Ep(this,t,`timeout`)},tn(wp/10)),e.on(`destroy`,()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit(`destroy`,[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:vr()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),Hr(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},Ep=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:vr()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},Dp=(e,t,n=e.states)=>{let r=t.length,i=X();Z(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;Z(i,r),Z(i,s),Mn(i,JSON.stringify(o))}return Tn(i)},Op=(e,t,n)=>{let r=er(t),i=vr(),a=[],o=[],s=[],c=[],l=Q(r);for(let t=0;t<l;t++){let t=Q(r),n=Q(r),l=JSON.parse(or(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(Hr(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])},kp=e=>Mr(e,(e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`).join(`&`),Ap=[];Ap[0]=(e,t,n,r,i)=>{Z(e,0);let a=Sp(t,e,n.doc,n);r&&a===1&&!n.synced&&(n.synced=!0)},Ap[3]=(e,t,n,r,i)=>{Z(e,1),Pn(e,Dp(n.awareness,Array.from(n.awareness.getStates().keys())))},Ap[1]=(e,t,n,r,i)=>{Op(n.awareness,rr(t),n)},Ap[2]=(e,t,n,r,i)=>{Cp(t,n.doc,(e,t)=>Mp(n,t))};var jp=3e4,Mp=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),Np=(e,t,n)=>{let r=er(t),i=X(),a=Q(r),o=e.messageHandlers[a];return o?o(i,r,e,n,a):console.error(`Unable to compute message`),i},Pp=(e,t,n)=>{t===e.ws&&(e.emit(`connection-close`,[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Ep(e.awareness,Array.from(e.awareness.getStates().keys()).filter(t=>t!==e.doc.clientID),e),e.emit(`status`,[{status:`disconnected`}])):e.wsUnsuccessfulReconnects++,setTimeout(Fp,rn(on(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},Fp=e=>{if(e.shouldConnect&&e.ws===null){let t=new e._WS(e.url,e.protocols);t.binaryType=`arraybuffer`,e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=vr();let r=Np(e,new Uint8Array(n.data),!0);wn(r)>1&&t.send(Tn(r))},t.onerror=t=>{e.emit(`connection-error`,[t,e])},t.onclose=n=>{Pp(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=vr(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit(`status`,[{status:`connected`}]);let n=X();if(Z(n,0),gp(n,e.doc),t.send(Tn(n)),e.awareness.getLocalState()!==null){let n=X();Z(n,1),Pn(n,Dp(e.awareness,[e.doc.clientID])),t.send(Tn(n))}},e.emit(`status`,[{status:`connecting`}])}},Ip=(e,t)=>{let n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&hp(e.bcChannel,t,e)},Lp=class extends $t{constructor(e,t,n,{connect:r=!0,awareness:i=new Tp(n),params:a={},protocols:o=[],WebSocketPolyfill:s=WebSocket,resyncInterval:c=-1,maxBackoffTime:l=2500,disableBc:u=!1}={}){for(super();e[e.length-1]===`/`;)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+`/`+t,this.maxBackoffTime=l,this.params=a,this.protocols=o,this.roomname=t,this.doc=n,this._WS=s,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Ap.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){let e=X();Z(e,0),gp(e,n),this.ws.send(Tn(e))}},c)),this._bcSubscriber=(e,t)=>{if(t!==this){let t=Np(this,new Uint8Array(e),!1);wn(t)>1&&hp(this.bcChannel,Tn(t),this)}},this._updateHandler=(e,t)=>{if(t!==this){let t=X();Z(t,0),bp(t,e),Ip(this,Tn(t))}},this.doc.on(`update`,this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:n},r)=>{let a=e.concat(t).concat(n),o=X();Z(o,1),Pn(o,Dp(i,a)),Ip(this,Tn(o))},this._exitHandler=()=>{Ep(this.awareness,[n.clientID],`app closed`)},Wr&&typeof process<`u`&&process.on(`exit`,this._exitHandler),i.on(`update`,this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&jp<vr()-this.wsLastMessageReceived&&Pp(this,this.ws,null)},jp/10),r&&this.connect()}get url(){let e=kp(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(),Wr&&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||=(pp(this.bcChannel,this._bcSubscriber),!0);let e=X();Z(e,0),gp(e,this.doc),hp(this.bcChannel,Tn(e),this);let t=X();Z(t,0),_p(t,this.doc),hp(this.bcChannel,Tn(t),this);let n=X();Z(n,3),hp(this.bcChannel,Tn(n),this);let r=X();Z(r,1),Pn(r,Dp(this.awareness,[this.doc.clientID])),hp(this.bcChannel,Tn(r),this)}disconnectBc(){let e=X();Z(e,1),Pn(e,Dp(this.awareness,[this.doc.clientID],new Map)),Ip(this,Tn(e)),this.bcconnected&&=(mp(this.bcChannel,this._bcSubscriber),!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&Pp(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Fp(this),this.connectBc())}},Rp=e=>yr((t,n)=>{e.onerror=e=>n(Error(e.target.error)),e.onsuccess=e=>t(e.target.result)}),zp=(e,t)=>yr((n,r)=>{let i=indexedDB.open(e);i.onupgradeneeded=e=>t(e.target.result),i.onerror=e=>r(Jn(e.target.error)),i.onsuccess=e=>{let t=e.target.result;t.onversionchange=()=>{t.close()},n(t)}}),Bp=e=>Rp(indexedDB.deleteDatabase(e)),Vp=(e,t)=>t.forEach(t=>e.createObjectStore.apply(e,t)),Hp=(e,t,n=`readwrite`)=>{let r=e.transaction(t,n);return t.map(e=>$p(r,e))},Up=(e,t)=>Rp(e.count(t)),Wp=(e,t)=>Rp(e.get(t)),Gp=(e,t)=>Rp(e.delete(t)),Kp=(e,t,n)=>Rp(e.put(t,n)),qp=(e,t)=>Rp(e.add(t)),Jp=(e,t,n)=>Rp(e.getAll(t,n)),Yp=(e,t,n)=>{let r=null;return Qp(e,t,e=>(r=e,!1),n).then(()=>r)},Xp=(e,t=null)=>Yp(e,t,`prev`),Zp=(e,t)=>yr((n,r)=>{e.onerror=r,e.onsuccess=async e=>{let r=e.target.result;if(r===null||await t(r)===!1)return n();r.continue()}}),Qp=(e,t,n,r=`next`)=>Zp(e.openKeyCursor(t,r),e=>n(e.key)),$p=(e,t)=>e.objectStore(t),em=(e,t)=>IDBKeyRange.upperBound(e,t),tm=(e,t)=>IDBKeyRange.lowerBound(e,t),nm=`custom`,rm=`updates`,im=(e,t=()=>{},n=()=>{})=>{let[r]=Hp(e.db,[rm]);return Jp(r,tm(e._dbref,!1)).then(i=>{e._destroyed||(t(r),Ms(e.doc,()=>{i.forEach(t=>Io(e.doc,t))},e,!1),n(r))}).then(()=>Xp(r).then(t=>{e._dbref=t+1})).then(()=>Up(r).then(t=>{e._dbsize=t})).then(()=>r)},am=(e,t=!0)=>im(e).then(n=>{(t||e._dbsize>=500)&&qp(n,zo(e.doc)).then(()=>Gp(n,em(e._dbref,!0))).then(()=>Up(n).then(t=>{e._dbsize=t}))}),om=class extends en{constructor(e,t){super(),this.doc=t,this.name=e,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=zp(e,e=>Vp(e,[[`updates`,{autoIncrement:!0}],[`custom`]])),this.whenSynced=yr(e=>this.on(`synced`,()=>e(this))),this._db.then(e=>{this.db=e,im(this,e=>qp(e,zo(t)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit(`synced`,[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(e,t)=>{if(this.db&&t!==this){let[t]=Hp(this.db,[rm]);qp(t,e),++this._dbsize>=500&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{am(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},t.on(`update`,this._storeUpdate),this.destroy=this.destroy.bind(this),t.on(`destroy`,this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off(`update`,this._storeUpdate),this.doc.off(`destroy`,this.destroy),this._destroyed=!0,this._db.then(e=>{e.close()})}clearData(){return this.destroy().then(()=>{Bp(this.name)})}get(e){return this._db.then(t=>{let[n]=Hp(t,[nm],`readonly`);return Wp(n,e)})}set(e,t){return this._db.then(n=>{let[r]=Hp(n,[nm]);return Kp(r,t,e)})}del(e){return this._db.then(t=>{let[n]=Hp(t,[nm]);return Gp(n,e)})}},sm={Sync:0,Awareness:1,QueryAwareness:3,Flush:4,Protocol:5,Maintenance:6,Permission:7,CompileStates:8,FormatLease:9},cm=[`queued`,`running`,`succeeded`,`failed`,`cleaned`],lm=[`cache`,`artifacts`];function um(e){return typeof e==`string`&&cm.includes(e)}function dm(e){return typeof e==`string`&&lm.includes(e)}var fm=[[`#1677c8`,`#1677c833`],[`#d65745`,`#d6574533`],[`#16866a`,`#16866a33`],[`#9a58b5`,`#9a58b533`],[`#d27b18`,`#d27b1833`],[`#3f7d20`,`#3f7d2033`],[`#be3e7b`,`#be3e7b33`],[`#4964c6`,`#4964c633`],[`#8a6a14`,`#8a6a1433`],[`#087f8c`,`#087f8c33`]],{Sync:pm,Awareness:mm,Flush:hm,Protocol:gm,Maintenance:_m,Permission:vm,CompileStates:ym,FormatLease:bm}=sm,xm=6e4,Sm=2592e6,Cm=15e3,wm=3e5;function Tm(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.requestedBy;return typeof t.mainFile!=`string`||typeof t.runId!=`string`||!um(t.status)||t.status===`cleaned`&&!dm(t.cleanMode)||t.stale!==void 0&&typeof t.stale!=`boolean`||typeof t.updatedAt!=`string`||!n||typeof n.id!=`string`||typeof n.username!=`string`||typeof n.name!=`string`?null:t}function Em(e){if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){let e=Tm(r);e&&e.mainFile===n&&(t[n]=e)}return t}function Dm(e,t,n){return e<=n&&t<=n}function Om(e,t,n){let r=e=>e>0&&n-e<=wm;return{recoverable:e.some(e=>e.tabId===t||!r(e.activeAt)),otherActive:e.some(e=>e.tabId!==t&&r(e.activeAt))}}var km=class{projectId;user;doc=new bo;provider;awareness;persistence;permission=`read`;activeFile=``;epoch=null;destroyed=!1;localDraftReady=!1;draftListeners=new Set;permissionListeners=new Set;protocolUpgradeListeners=new Set;compileStateListeners=new Set;flushRequests=new Map;formatLeaseRequests=new Map;formatLeaseListeners=new Set;formatLeaseStatesByPath=new Map;formatLeaseExpiryTimers=new Map;draftTabId;draftGeneration=0;draftUpdatedAt=0;draftMarkerPresent=!1;draftHeartbeatTimer=null;markDraftTabInactive;markDraftTabActive;undoManagers=new Map;authoritativeCompileStates=null;metaObserver;localDraftTransactionObserver;constructor(e,t){this.projectId=e,this.user=t;let n=window.location.protocol===`https:`?`wss:`:`ws:`;this.draftTabId=Mm(b(`texlite:collaboration-tab:${t.id}:${e}`));let r=this.readOwnWritableDraftMarker();this.draftGeneration=r?.generation??0,this.draftUpdatedAt=r?.updatedAt??0,this.draftMarkerPresent=r!==null,this.markDraftTabInactive=()=>this.setOwnDraftActivity(!1),this.markDraftTabActive=()=>this.resumeOwnDraftActivity(),window.addEventListener(`pagehide`,this.markDraftTabInactive),window.addEventListener(`pageshow`,this.markDraftTabActive),r&&(this.setOwnDraftActivity(!0),this.startDraftHeartbeat()),this.persistence=new om(b(`texlite:${t.id}:${e}`),this.doc),this.localDraftTransactionObserver=e=>{if(e.local){for(let[t,n]of this.doc.share)if(t.startsWith(`source:`)&&(e.changed.has(n)||e.changedParentTypes.has(n))){this.markWritableDraft();return}}},this.doc.on(`afterTransaction`,this.localDraftTransactionObserver),this.persistence.on(`synced`,()=>{this.localDraftReady=!0;for(let e of this.draftListeners)e()}),this.provider=new Lp(`${n}//${window.location.host}${x(`/api/collaboration`)}`,e,this.doc,{connect:!1,disableBc:!0,maxBackoffTime:2500}),this.awareness=this.provider.awareness;let i=this.doc.getMap(`texlite:meta`);this.metaObserver=(e,t)=>{t.origin===this.provider&&e.keysChanged.has(`compileStates`)&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners())},i.observe(this.metaObserver),this.provider.messageHandlers[hm]=(e,t)=>{let n=or(t),r=this.flushRequests.get(n);if(!r)return;let i=Q(t)===1,a=Q(t),o=or(t),s=Q(t),c=[];for(let e=0;e<s;e++)c.push(or(t));if(window.clearTimeout(r.timer),this.flushRequests.delete(n),i)this.clearOwnWritableDraftMarker(r.draftGeneration),r.resolve({revision:a,persistedAt:o,ok:!0,failedPaths:[]});else{let e=Object.assign(Error(c.length?`保存失败:${c.join(`, `)}`:`源码保存到服务器磁盘失败`),{failedPaths:c});r.reject(e)}},this.provider.messageHandlers[gm]=(e,t)=>{let n=or(t),r=this.epochStorageKey(),i=G(r),a=/^([0-9]+):/.exec(n)?.[1]??null,o=i?/^([0-9]+):/.exec(i)?.[1]??null:null,s=!this.epoch&&a===`3`&&o!==null&&o!==a;if((this.epoch&&this.epoch!==n||i&&i!==n)&&!s){this.provider.disconnect(),this.rejectFlushes(Error(`Collaboration state changed`));let e=n.endsWith(`:reload`)||a!==null&&a!==`3`,t=()=>{Ze(r,n.replace(/:reload$/,``)),window.location.reload()};if(e)for(let e of this.protocolUpgradeListeners)e();else this.persistence.clearData().then(()=>{this.clearWritableDraftMarkers(),t()});return}this.epoch=n,Ze(r,n);let c=this.provider.ws;if(!c||c.readyState!==WebSocket.OPEN)return;let l=X();Z(l,gm),Mn(l,n),Z(l,3),c.send(Tn(l));let u=X();Z(u,pm),gp(u,this.doc),c.send(Tn(u));let d=X();Z(d,mm),Pn(d,Dp(this.awareness,[this.doc.clientID])),c.send(Tn(d))},this.provider.messageHandlers[vm]=(e,t)=>{let n=or(t),r=or(t);if(n!==this.user.id)return;if(r===`revoked`){this.rejectFlushes(Error(`Project access revoked`)),this.provider.disconnect();for(let e of this.permissionListeners)e(`revoked`,this.permission);return}if(r!==`read`&&r!==`edit`&&r!==`owner`)return;let i=this.permission;if(this.setPermission(r),i!==r){r===`read`&&this.rejectFlushes(Error(`Project permission changed to read-only`));for(let e of this.permissionListeners)e(r,i)}},this.provider.messageHandlers[_m]=(e,t)=>{or(t)},this.provider.messageHandlers[ym]=(e,t)=>{let n={};try{n=Em(JSON.parse(or(t)))}catch{}this.authoritativeCompileStates=n,this.notifyCompileStateListeners()},this.provider.messageHandlers[bm]=(e,t)=>{let n=or(t),r=or(t),i=or(t),a=or(t),o=or(t),s=or(t);if(n===`state`){let e=tr(t)?or(t):``,n=tr(t)?or(t):``,r=Number(o);if(!e||!Number.isFinite(r)||r<=Date.now())this.removeFormatLeaseState(i),this.notifyFormatLeaseListeners(null);else{let t={path:i,holderUserId:e,holderName:n,expiresAt:r};this.formatLeaseStatesByPath.set(i,t);let a=this.formatLeaseExpiryTimers.get(i);a!==void 0&&window.clearTimeout(a);let o=window.setTimeout(()=>{let e=this.formatLeaseStatesByPath.get(i);!e||e.expiresAt>Date.now()||(this.removeFormatLeaseState(i),this.notifyFormatLeaseListeners(null))},Math.max(0,r-Date.now())+25);this.formatLeaseExpiryTimers.set(i,o),this.notifyFormatLeaseListeners(t)}return}let c=this.formatLeaseRequests.get(r);c&&(window.clearTimeout(c.timer),this.formatLeaseRequests.delete(r),n===`denied`?c.reject(Error(s||`Format lease request was denied`)):c.resolve({status:n,filePath:i,token:a,expiresAt:Number(o)}))},this.provider.on(`status`,({status:e})=>{e===`disconnected`&&(this.authoritativeCompileStates=null,this.notifyCompileStateListeners(),this.rejectFlushes(Error(`Collaboration connection closed`)),this.rejectFormatLeaseRequests(Error(`Collaboration connection closed`)),this.clearFormatLeaseStates())}),this.updateLocalAwareness()}connect(){this.destroyed||(this.provider.connect(),this.updateLocalAwareness())}getText(e){return this.doc.getText(`source:${e}`)}getUndoManager(e){let t=this.undoManagers.get(e);if(t)return t;let n=new Is(this.getText(e));return this.undoManagers.set(e,n),n}applyTextEdits(e,t){if(this.permission===`read`)throw Error(`Read-only collaborators cannot edit source files`);let n=this.getText(e),r=0;for(let e of t){if(!Number.isInteger(e.from)||!Number.isInteger(e.to)||e.from<r||e.to<e.from||e.to>n.length)throw RangeError(`Invalid collaborative text edits`);r=e.to}this.doc.transact(()=>{for(let e=t.length-1;e>=0;--e){let r=t[e];r.to>r.from&&n.delete(r.from,r.to-r.from),r.replacement&&n.insert(r.from,r.replacement)}})}get meta(){return this.doc.getMap(`texlite:meta`)}compileStates(){return this.authoritativeCompileStates??Em(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 currentPermission(){return this.permission}onDraftReady(e){return this.draftListeners.add(e),this.localDraftReady&&e(),()=>this.draftListeners.delete(e)}onPermissionChanged(e){return this.permissionListeners.add(e),()=>this.permissionListeners.delete(e)}onProtocolUpgrade(e){return this.protocolUpgradeListeners.add(e),()=>this.protocolUpgradeListeners.delete(e)}async discardLocalDraft(){return!this.hasOtherWritableDraft&&(await this.persistence.clearData(),this.localDraftReady=!1,this.clearWritableDraftMarkers(),!0)}get hasWritableDraft(){return Om(this.readWritableDraftMarkers().map(({tabId:e,marker:t})=>({tabId:e,activeAt:t.activeAt})),this.draftTabId,Date.now()).recoverable}get hasOtherWritableDraft(){return Om(this.readWritableDraftMarkers().map(({tabId:e,marker:t})=>({tabId:e,activeAt:t.activeAt})),this.draftTabId,Date.now()).otherActive}setPermission(e,t=!1){let n=this.permission;if(this.permission=e,e===`read`&&(n!==`read`&&this.rejectFlushes(Error(`Project permission changed to read-only`)),this.destroyUndoManagers(),this.clearFormatLeaseStates()),this.updateLocalAwareness(),t&&n!==e)for(let t of this.permissionListeners)t(e,n)}setActiveFile(e){this.activeFile!==e&&(this.activeFile=e,this.awareness.setLocalStateField(`cursor`,null),this.updateLocalAwareness())}sessions(){let e=[];return this.awareness.getStates().forEach((t,n)=>{let r=t?.user;r&&typeof r.id==`string`&&typeof r.name==`string`&&e.push({clientId:n,userId:r.id,username:typeof r.username==`string`?r.username:r.name,name:r.name,avatarStyle:ie(r.avatarStyle)?r.avatarStyle:null,color:typeof r.color==`string`?r.color:`#1677c8`,colorLight:typeof r.colorLight==`string`?r.colorLight:`#1677c833`,permission:r.permission===`owner`||r.permission===`edit`?r.permission:`read`,filePath:typeof t.filePath==`string`?t.filePath:``,editing:!!t.cursor,local:n===this.doc.clientID})}),e.sort((e,t)=>Number(t.local)-Number(e.local)||e.name.localeCompare(t.name))}flush(){let e=this.provider.ws;if(!this.provider.synced||!e||e.readyState!==WebSocket.OPEN)return Promise.reject(Error(`Collaboration connection is unavailable`));let t=fu(),n=this.draftGeneration,r=X();return Z(r,hm),Mn(r,t),new Promise((i,a)=>{let o=window.setTimeout(()=>{this.flushRequests.delete(t),a(Error(`Collaboration save timed out`))},5e3);this.flushRequests.set(t,{resolve:i,reject:a,timer:o,draftGeneration:n}),e.send(Tn(r))})}onFormatLeaseState(e){this.formatLeaseListeners.add(e);for(let t of this.formatLeaseStatesByPath.values())e(t);return()=>this.formatLeaseListeners.delete(e)}formatLeaseStates(){let e=Date.now();for(let[t,n]of this.formatLeaseStatesByPath)n.expiresAt<=e&&this.removeFormatLeaseState(t);return[...this.formatLeaseStatesByPath.values()]}async acquireFormatLease(e){if(this.permission===`read`)throw Error(`Formatting requires write permission`);let t=await this.requestFormatLease(`acquire`,e);if(t.status!==`grant`||!t.token||!Number.isFinite(t.expiresAt))throw Error(`Format lease was not granted`);let n=t.token,r=t.expiresAt,i=!1,a=async()=>{if(i)throw Error(`Format lease has already been released`);let t=await this.requestFormatLease(`renew`,e,n);if(t.status!==`renewed`||!Number.isFinite(t.expiresAt))throw Error(`Format lease renewal failed`);n=t.token||n,r=t.expiresAt};return{path:e,get token(){return n},get expiresAt(){return r},confirm:a,renew:a,release:async()=>{if(i)return;i=!0;let t=this.provider.ws;if(t&&t.readyState===WebSocket.OPEN)try{await this.requestFormatLease(`release`,e,n)}catch{}}}}reconnect(){this.destroyed||(this.rejectFlushes(Error(`Collaboration connection reset`)),this.provider.disconnect(),this.provider.connect(),this.updateLocalAwareness())}destroy(){this.destroyed=!0,this.setOwnDraftActivity(!1),this.stopDraftHeartbeat(),window.removeEventListener(`pagehide`,this.markDraftTabInactive),window.removeEventListener(`pageshow`,this.markDraftTabActive),this.rejectFlushes(Error(`Collaboration connection closed`)),this.provider.destroy(),this.persistence.destroy(),this.draftListeners.clear(),this.protocolUpgradeListeners.clear(),this.compileStateListeners.clear(),this.rejectFormatLeaseRequests(Error(`Collaboration connection closed`)),this.clearFormatLeaseStates(),this.formatLeaseListeners.clear(),this.meta.unobserve(this.metaObserver),this.doc.off(`afterTransaction`,this.localDraftTransactionObserver),this.destroyUndoManagers(),this.doc.destroy()}destroyUndoManagers(){for(let e of this.undoManagers.values())e.destroy();this.undoManagers.clear()}notifyCompileStateListeners(){for(let e of this.compileStateListeners)e()}rejectFlushes(e){for(let t of this.flushRequests.values())window.clearTimeout(t.timer),t.reject(e);this.flushRequests.clear()}requestFormatLease(e,t,n=``){let r=this.provider.ws;if(!this.provider.synced||!r||r.readyState!==WebSocket.OPEN)return Promise.reject(Error(`Collaboration connection is unavailable`));let i=fu(),a=X();return Z(a,bm),Mn(a,e),Mn(a,i),Mn(a,t),Mn(a,n),new Promise((n,o)=>{let s=window.setTimeout(()=>{if(this.formatLeaseRequests.delete(i),e===`acquire`){let e=this.provider.ws;if(e?.readyState===WebSocket.OPEN){let n=X();Z(n,bm),Mn(n,`cancel`),Mn(n,i),Mn(n,t),Mn(n,``),e.send(Tn(n))}}o(Error(`Format lease request timed out`))},e===`acquire`?xm:5e3);this.formatLeaseRequests.set(i,{resolve:n,reject:o,timer:s}),r.send(Tn(a))})}rejectFormatLeaseRequests(e){for(let t of this.formatLeaseRequests.values())window.clearTimeout(t.timer),t.reject(e);this.formatLeaseRequests.clear()}clearFormatLeaseStates(){for(let e of this.formatLeaseExpiryTimers.values())window.clearTimeout(e);this.formatLeaseExpiryTimers.clear(),this.formatLeaseStatesByPath.size&&(this.formatLeaseStatesByPath.clear(),this.notifyFormatLeaseListeners(null))}removeFormatLeaseState(e){let t=this.formatLeaseExpiryTimers.get(e);t!==void 0&&window.clearTimeout(t),this.formatLeaseExpiryTimers.delete(e),this.formatLeaseStatesByPath.delete(e)}notifyFormatLeaseListeners(e){for(let t of this.formatLeaseListeners)t(e)}updateLocalAwareness(){let[e,t]=fm[Math.abs(this.doc.clientID)%fm.length],n=this.awareness.getLocalState()?.user,r=n&&Object.hasOwn(n,`avatarStyle`)?n.avatarStyle:this.user.avatarStyle;this.awareness.setLocalStateField(`user`,{id:this.user.id,username:this.user.username,name:this.user.displayName,avatarStyle:ie(r)?r:null,color:e,colorLight:t,permission:this.permission,sessionId:String(this.doc.clientID)}),this.awareness.setLocalStateField(`filePath`,this.activeFile)}epochStorageKey(){return b(`texlite:collaboration-epoch:${this.user.id}:${this.projectId}`)}writableDraftStoragePrefix(){return`${b(`texlite:collaboration-writable:${this.user.id}:${this.projectId}`)}:`}ownWritableDraftStorageKey(){return`${this.writableDraftStoragePrefix()}${this.draftTabId}`}markWritableDraft(){this.draftGeneration+=1,this.draftUpdatedAt=Date.now(),this.draftMarkerPresent||this.writeOwnWritableDraftMarker(!0),this.startDraftHeartbeat()}clearWritableDraftMarkers(){for(let{key:e}of this.readWritableDraftMarkers())et(e);this.draftMarkerPresent=!1,this.stopDraftHeartbeat(),et(this.writableDraftStoragePrefix().slice(0,-1))}clearOwnWritableDraftMarker(e){let t=this.readOwnWritableDraftMarker();t&&Dm(t.generation,this.draftGeneration,e)&&(et(this.ownWritableDraftStorageKey()),this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}readOwnWritableDraftMarker(){return this.readWritableDraftMarker(this.ownWritableDraftStorageKey())}readWritableDraftMarkers(){let e=this.writableDraftStoragePrefix(),t=[];for(let n of Ke()){if(!n.startsWith(e))continue;let r=this.readWritableDraftMarker(n);r&&t.push({key:n,tabId:n.slice(e.length),marker:r})}return t}readWritableDraftMarker(e){let t=G(e);if(!t)return null;try{let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))return null;let r=n,i=Date.now();if(!Number.isInteger(r.generation)||(r.generation??0)<0||typeof r.updatedAt!=`number`||!Number.isFinite(r.updatedAt)||r.updatedAt<=0||i-r.updatedAt>Sm)return et(e),null;let a=typeof r.activeAt==`number`&&Number.isFinite(r.activeAt)?Math.max(0,r.activeAt):0;return{generation:r.generation,updatedAt:r.updatedAt,activeAt:a}}catch{return et(e),null}}writeOwnWritableDraftMarker(e){if(!this.draftMarkerPresent&&this.draftUpdatedAt<=0)return;let t={generation:this.draftGeneration,updatedAt:this.draftUpdatedAt||Date.now(),activeAt:e?Date.now():0};Ze(this.ownWritableDraftStorageKey(),JSON.stringify(t)),this.draftMarkerPresent=!0}setOwnDraftActivity(e){this.draftMarkerPresent&&(this.writeOwnWritableDraftMarker(e),e?this.startDraftHeartbeat():this.stopDraftHeartbeat())}resumeOwnDraftActivity(){let e=this.readOwnWritableDraftMarker();e?(this.draftGeneration=Math.max(this.draftGeneration,e.generation),this.draftUpdatedAt=e.updatedAt,this.draftMarkerPresent=!0,this.setOwnDraftActivity(!0)):(this.draftMarkerPresent=!1,this.stopDraftHeartbeat())}startDraftHeartbeat(){this.draftHeartbeatTimer===null&&this.draftMarkerPresent&&(this.draftHeartbeatTimer=window.setInterval(()=>{this.writeOwnWritableDraftMarker(!0)},Cm))}stopDraftHeartbeat(){this.draftHeartbeatTimer!==null&&(window.clearInterval(this.draftHeartbeatTimer),this.draftHeartbeatTimer=null)}};function Am(e){try{return window.sessionStorage.getItem(e)}catch{return null}}function jm(e,t){try{window.sessionStorage.setItem(e,t)}catch{}}function Mm(e){let t=Am(e);if(t)return t;let n=fu();return jm(e,n),n}function Nm({projectId:e,user:t,children:n}){let{t:r}=v(),i=(0,J.useRef)(t);i.current=t;let[a,o]=(0,J.useState)(null),s=(0,J.useRef)(null),c=(0,J.useRef)(null),l=t.id;return(0,J.useEffect)(()=>{c.current=null;let t=s.current;return(!t||t.projectId!==e||t.userId!==l)&&(t?.collaboration.destroy(),t={projectId:e,userId:l,collaboration:new km(e,i.current)},s.current=t),o(t),()=>{let e={};c.current=e,queueMicrotask(()=>{c.current===e&&s.current===t&&(c.current=null,s.current=null,t.collaboration.destroy())})}},[e,l]),!a||a.projectId!==e||a.userId!==l?(0,Y.jsx)(`div`,{className:`center-card`,role:`status`,children:r(`common.loading`)}):(0,Y.jsx)(J.Fragment,{children:n(a.collaboration)},a.collaboration.doc.guid)}var Pm=class{selection;restoreRetained;value;sharedAllowed;initialAllowed;constructor(e,t){this.selection=e,this.restoreRetained=t,this.value={selection:e,run:null,pdf:null},this.sharedAllowed=t,this.initialAllowed=t}get snapshot(){return this.value}get sharedCompletionAllowed(){return this.sharedAllowed}observeRunning(){this.sharedAllowed=!0}hasRun(e){return this.snapshot.run?.identity.runId===e&&this.snapshot.run.outcome!==null}beginCompile(){this.initialAllowed=!1,this.sharedAllowed=!0,this.value={...this.snapshot,run:null}}clean(e){this.initialAllowed=!1,e===`artifacts`&&(this.value={selection:this.selection,run:null,pdf:null})}receiveLatest(e,t){if(e.mainFile!==this.selection.mainFile||(t===`initial`?!this.initialAllowed:!this.sharedCompletionAllowed)||t===`shared`&&(!e.latestRun||this.hasRun(e.latestRun.id)))return null;let n=e.latestRun,r=n?.status===`succeeded`?`succeeded`:n?.log.includes(`Compilation was cancelled.`)?`cancelled`:n?.status===`failed`?`failed`:null;return this.receive(e,n?{identity:{...this.selection,runId:n.id},log:n.log,diagnostics:n.diagnostics,outcome:r}:null,t!==`initial`)}receiveLocal(e){return e.mainFile===this.selection.mainFile?this.receive(e,{identity:{...this.selection,runId:e.runId},log:e.log,diagnostics:e.diagnostics,outcome:e.cancelled?`cancelled`:e.ok?`succeeded`:`failed`},!0,e.skipped):null}receive(e,t,n,r=!1){let i=this.snapshot,a=t?this.hasRun(t.identity.runId):!1,o=i.pdf;if(e.pdfUrl){let t=new URL(e.pdfUrl,`https://texlite.invalid/`).searchParams.get(`run`);if(!t)throw Error(`PDF response is missing its compile run identity`);o={identity:{...this.selection,runId:t},url:e.pdfUrl,compiledAt:e.pdfCompiledAt,sizeBytes:e.pdfSizeBytes,loadingMode:e.pdfLoadingMode??`full`}}else n||(o=null);return this.initialAllowed=!1,this.value={selection:this.selection,run:t,pdf:o},{snapshot:this.snapshot,pdfChanged:i.pdf?.url!==o?.url,focusPdf:n&&t?.outcome===`succeeded`&&!!e.pdfUrl&&(r||!a)}}},Fm=(e,t)=>`${e}\0${t}`;function Im(e,t){e.current&&(!t||e.current.owner===t)&&(e.current.controller.abort(),e.current=null)}function Lm(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof Element&&!!e.closest(`[role="dialog"], [role="alertdialog"], [data-agent-terminal]`)}function Rm(e){let{projectId:t,project:n,mainFile:r,initialLatest:i,collaborationSynced:a,pdfVisible:o,sharedState:s}=e,{t:c}=v(),l=(0,J.useRef)({...e,t:c});l.current={...e,t:c};let u=(0,J.useRef)(!1),d=(0,J.useRef)(null),f=d.current;(!f||f.selection.projectId!==t||f.selection.mainFile!==r)&&(d.current=new Pm({projectId:t,mainFile:r},!f||f.selection.projectId!==t||!f.selection.mainFile));let p=d.current,[m,h]=(0,J.useState)(p.snapshot),[g,_]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)([]),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(!1),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(()=>new Set),[j,M]=(0,J.useState)(()=>new Set),[ee,N]=(0,J.useState)(``),P=(0,J.useRef)(null),te=(0,J.useRef)(null),F=(0,J.useRef)(null),I=(0,J.useRef)(null),L=(0,J.useRef)(null),ne=(0,J.useRef)(new Map),R=(0,J.useRef)(new Map),re=(0,J.useRef)(new Set),ie=(0,J.useRef)({projectId:t,promise:i});ie.current.projectId!==t&&(ie.current={projectId:t,promise:i});let z=(0,J.useRef)(null),ae=(0,J.useRef)(null),oe=(0,J.useRef)(()=>void 0),se=()=>l.current.getCurrentMainFile?.()||d.current.selection.mainFile,B=(e,t)=>u.current&&!t?.aborted&&d.current===e&&se()===e.selection.mainFile,ce=Fm(t,r),V=m.selection===p.selection,H=k.has(ce),U=D===p,le=e=>{for(let t of[P,te,F,I])Im(t,e);for(let t of re.current)t.owner===e&&(t.controller.abort(),re.current.delete(t));_(t=>t?.owner===e?null:t),b(t=>t?.owner===e?null:t),E(!1)},ue=()=>{ae.current=null,z.current=null,S([]),w(null),E(!1),N(``),l.current.onPdfChanged()},de=async(e,t)=>{if(!B(e))return;let n=t??{owner:e,controller:new AbortController};t||(Im(F),F.current=n);let r=e.snapshot.pdf?.url,i=()=>B(e,n.controller.signal)&&e.snapshot.pdf?.url===r;try{let t=await K(`/api/projects/${e.selection.projectId}/compile/artifacts?mainFile=${encodeURIComponent(e.selection.mainFile)}`,{signal:n.controller.signal});i()&&(S(t.artifacts),w(null))}catch(e){!Ue(e)&&i()&&(S([]),w(null))}finally{F.current===n&&(F.current=null)}},fe=()=>{let e=ae.current;e&&(ae.current=null,B(e.owner)&&e.owner.snapshot.pdf?.url===e.url&&de(e.owner))},pe=e=>{let t=e.snapshot.pdf?.url;t&&(ae.current={owner:e,url:t},(!l.current.pdfVisible||z.current?.owner===e&&z.current.url===t)&&fe())},me=e=>{B(p)&&p.snapshot.pdf?.url===e&&(z.current={owner:p,url:e},ae.current?.owner===p&&ae.current.url===e&&fe())},he=(e,t)=>!t||!B(e)?!1:(h(t.snapshot),t.pdfChanged&&l.current.onPdfChanged(),t.focusPdf&&l.current.onCompileSuccess(),!0),ge=(e,t)=>{le(e),ae.current=null,e.clean(t),h(e.snapshot),t===`artifacts`&&(ue(),l.current.onPreviewTab(`pdf`)),N(l.current.t(t===`cache`?`editor.cleanCacheComplete`:`editor.cleanArtifactsComplete`))};(0,J.useEffect)(()=>(u.current=!0,()=>{u.current=!1;for(let e of[P,te,F,I,L])Im(e);for(let e of[...re.current,...R.current.values(),...ne.current.values()])e.controller.abort();re.current.clear(),R.current.clear(),ne.current.clear()}),[]),(0,J.useEffect)(()=>{o||fe()},[o]),(0,J.useEffect)(()=>{h(p.snapshot),ue();for(let e of[R.current,ne.current])for(let[n,r]of e)r.owner.selection.projectId!==t&&(r.controller.abort(),e.delete(n));let e=Fm(t,``),n=t=>{let n=new Set([...t].filter(t=>t.startsWith(e)));return n.size===t.size?t:n};if(A(n),M(n),L.current?.owner!==p&&Im(L),!r)return;if(!p.restoreRetained){l.current.onPreviewTab(`pdf`);let e={owner:p,controller:new AbortController};return l.current.loadOutline(e.controller.signal,r).catch(()=>void 0),()=>{e.controller.abort(),le(p)}}let i={owner:p,controller:new AbortController};P.current=i,_(i);let a=null,o,s=()=>(o=l.current.sharedState,K(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:i.controller.signal})),c=ie.current.promise;return ie.current.promise=null,(c?c.then(e=>B(p,i.controller.signal)?e.mainFile===r?e:s():null,()=>B(p,i.controller.signal)?s():null):s()).then(e=>{if(e&&B(p,i.controller.signal)&&he(p,p.receiveLatest(e,`initial`))){if(e.latestRun?.requestedBy&&(e.latestRun.status===`queued`||e.latestRun.status===`running`)){let t={mainFile:r,runId:e.latestRun.id,status:e.latestRun.status,requestedBy:e.latestRun.requestedBy,updatedAt:new Date().toISOString()};l.current.onSharedState(e=>!B(p,i.controller.signal)||e?.mainFile===r&&(e!==o||e.runId===t.runId&&(e.status!==`queued`||t.status===`queued`))?e:t)}e.pdfUrl&&l.current.onPreviewTab(`pdf`)}}).catch(e=>{!Ue(e)&&B(p,i.controller.signal)&&l.current.onError(q(e))}).finally(()=>{P.current===i&&(P.current=null),_(e=>e===i?null:e),B(p,i.controller.signal)&&(re.current.add(i),a=window.setTimeout(()=>{B(p,i.controller.signal)?Promise.all([de(p,i),l.current.loadOutline(i.controller.signal,r).catch(()=>void 0)]).finally(()=>re.current.delete(i)):re.current.delete(i)},0))}),()=>{a!==null&&window.clearTimeout(a),i.controller.abort(),le(p)}},[p]),(0,J.useEffect)(()=>{s&&s.mainFile===r&&s.status===`cleaned`&&s.cleanMode&&ge(p,s.cleanMode)},[p,s?.runId,s?.status,s?.cleanMode,s?.mainFile]),(0,J.useEffect)(()=>{s?.mainFile===r&&(s.status===`queued`||s.status===`running`)?p.observeRunning():M(e=>{if(!e.has(ce))return e;let t=new Set(e);return t.delete(ce),t})},[p,s?.mainFile,s?.status,s?.runId]),(0,J.useEffect)(()=>{if(!s||s.mainFile!==r||s.status!==`succeeded`&&s.status!==`failed`||P.current?.owner===p||L.current?.owner===p||U||H||!p.sharedCompletionAllowed||p.hasRun(s.runId))return;let e={owner:p,controller:new AbortController};return Im(te),Im(I),E(!1),te.current=e,b(e),K(`/api/projects/${t}/compile/latest?mainFile=${encodeURIComponent(r)}`,{signal:e.controller.signal}).then(t=>{B(p,e.controller.signal)&&t.latestRun?.id===s.runId&&he(p,p.receiveLatest(t,`shared`))&&(s.status===`succeeded`&&s.stale&&N(l.current.t(`editor.compileSnapshotStale`)),s.status===`succeeded`&&t.pdfUrl?(l.current.onPreviewTab(`pdf`),pe(p)):s.status===`failed`&&l.current.onPreviewTab(t.latestRun.diagnostics.errors.length?`errors`:`log`))}).catch(t=>{!Ue(t)&&B(p,e.controller.signal)&&l.current.onError(q(t))}).finally(()=>{te.current===e&&(te.current=null),b(t=>t===e?null:t)}),()=>{e.controller.abort(),te.current===e&&(te.current=null)}},[p,s?.runId,s?.status,s?.mainFile,s?.stale,H,g,U]);let _e=async()=>{if(!n||n.permission===`read`||!a)return;let e=l.current.resolveCompileMainFile?.()||se(),r=Fm(t,e),i=l.current.sharedState;if(!e||R.current.has(r)||i?.mainFile===e&&(i.status===`queued`||i.status===`running`))return;let o=d.current;o.selection.mainFile!==e&&(le(o),o=new Pm({projectId:t,mainFile:e},!1),d.current=o,ue()),le(o),N(``),l.current.onCompileStart(),l.current.onPreviewTab(o.snapshot.pdf?`pdf`:`log`);let s={owner:o,controller:new AbortController};R.current.set(r,s),A(e=>new Set([...e,r]));try{if(!await l.current.save()||!B(o,s.controller.signal))return;o.beginCompile(),h(o.snapshot);let n=await K(`/api/projects/${t}/compile`,{method:`POST`,signal:s.controller.signal,body:JSON.stringify({mainFile:e})});if(!B(o,s.controller.signal)||!he(o,o.receiveLocal(n)))return;n.cancelled&&N(l.current.t(`compileControls.cancelled`)),n.skipped&&N(l.current.t(`editor.upToDate`)),n.ok&&n.stale&&N(l.current.t(`editor.compileSnapshotStale`)),n.pdfUrl?(pe(o),l.current.onPreviewTab(`pdf`)):l.current.onPreviewTab(n.diagnostics.errors.length?`errors`:`log`)}catch(e){!Ue(e)&&B(o,s.controller.signal)&&l.current.onError(q(e))}finally{R.current.get(r)===s&&(R.current.delete(r),A(e=>{let t=new Set(e);return t.delete(r),t}),M(e=>{let t=new Set(e);return t.delete(r),t}))}},ve=async()=>{if(!n||n.permission===`read`||!a||!B(p))return;let e=Fm(t,r);if(!r||ne.current.has(e))return;let i={owner:p,controller:new AbortController};ne.current.set(e,i),M(t=>new Set([...t,e]));try{!(await K(`/api/projects/${t}/compile/cancel`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r})})).cancelled&&B(p,i.controller.signal)&&M(t=>{let n=new Set(t);return n.delete(e),n})}catch(t){B(p,i.controller.signal)&&(M(t=>{let n=new Set(t);return n.delete(e),n}),Ue(t)||l.current.onError(q(t)))}finally{ne.current.get(e)===i&&ne.current.delete(e)}},ye=async e=>{if(!n||n.permission===`read`||!a||!B(p)||!r||L.current||R.current.has(ce)||s?.mainFile===r&&(s.status===`queued`||s.status===`running`))return;let i={owner:p,controller:new AbortController},o=l.current.sharedState;L.current=i,O(p),le(p);try{let n=await K(`/api/projects/${t}/compile/clean`,{method:`POST`,signal:i.controller.signal,body:JSON.stringify({mainFile:r,mode:e})});if(!B(p,i.controller.signal)||n.mainFile!==r)return;l.current.sharedState===o&&l.current.onSharedState(null),ge(p,e)}catch(e){!Ue(e)&&B(p,i.controller.signal)&&l.current.onError(q(e))}finally{L.current===i&&(L.current=null),O(e=>e===p?null:e)}},be=async e=>{if(!e.viewable||!B(p))return;Im(I);let n={owner:p,controller:new AbortController},i=p.snapshot.pdf?.url;I.current=n,E(!0);try{let a=await K(`/api/projects/${t}/compile/artifacts?mainFile=${encodeURIComponent(r)}&path=${encodeURIComponent(e.path)}`,{signal:n.controller.signal});B(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&w(a)}catch(e){!Ue(e)&&B(p,n.controller.signal)&&p.snapshot.pdf?.url===i&&l.current.onError(q(e))}finally{I.current===n&&(I.current=null,E(!1))}};oe.current=()=>void _e(),(0,J.useEffect)(()=>{if(!ee)return;let e=window.setTimeout(()=>N(``),3e3);return()=>window.clearTimeout(e)},[ee,p]),(0,J.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key.toLocaleLowerCase()===`s`&&(e.preventDefault(),!Lm(e.target)&&(e.stopPropagation(),e.repeat||oe.current()))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let xe=V?m:null;return{pdfUrl:xe?.pdf?.url??``,pdfCompiledAt:xe?.pdf?.compiledAt??null,pdfSizeBytes:xe?.pdf?.sizeBytes??null,pdfLoadingMode:xe?.pdf?.loadingMode??`full`,pdfLoading:g?.owner===p&&!g.controller.signal.aborted||y?.owner===p&&!y.controller.signal.aborted,compileLog:xe?.run?.log??``,compileDiagnostics:xe?.run?.diagnostics??null,compileOutcome:xe?.run?.outcome??null,artifacts:V?x:[],artifactPreview:V?C:null,artifactLoading:V&&T,editorNotice:V?ee:``,localCompiling:H,cancelling:j.has(ce),cleaning:U,pdfDisplayed:me,compile:_e,cancelCompile:ve,cleanCompile:ye,viewArtifact:be}}var zm=10485760;function Bm(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.map((e,n)=>t.slice(0,n+1).join(`/`))}function Vm(e,t){return!!(e&&t)&&(t===e||t.startsWith(`${e}/`))}function Hm(e,t){let n=_e(e);return n===`binary`||n===`other`||n===`text`&&t===!1?`unsupported`:n}function Um(e,t){let n=Hm(e.path,e.textContent);return n===`unsupported`?n:(e.size??0)>10485760||n===`text`&&(e.size??0)>t?`large`:n===`text`?`editor`:n}function Wm(e,t){return x(`/api/projects/${e}/file/raw?path=${encodeURIComponent(t)}`)}function Gm({projectId:e,site:t,activeFile:n,dirty:r,save:i,onError:a,onProject:o,onActiveFile:s,onActiveMainFile:c}){let{t:l}=v(),[u,d]=(0,J.useState)([]),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(null),[y,b]=(0,J.useState)(!1),[x,S]=(0,J.useState)(!1),[C,w]=(0,J.useState)(``),[T,E]=(0,J.useState)(``),[D,O]=(0,J.useState)(null),[k,A]=(0,J.useState)(``),[j,M]=(0,J.useState)(new Set),[ee,N]=(0,J.useState)(null),[P,te]=(0,J.useState)(``),[F,I]=(0,J.useState)(``),[L,ne]=(0,J.useState)(null),[R,re]=(0,J.useState)(!1),[ie,z]=(0,J.useState)(null),[ae,oe]=(0,J.useState)(!1),[se,B]=(0,J.useState)(null),ce=(0,J.useRef)(!1),V=(0,J.useRef)(null),H=(0,J.useRef)(null),U=(0,J.useRef)(null),le=async(t={})=>{H.current?.abort(),H.current=null;let n=t.signal?null:new AbortController;n&&(H.current=n);try{let r=await K(`/api/projects/${e}/files`,{signal:t.signal??n?.signal});return(!t.isCurrent||t.isCurrent())&&d(r.files),r.files}catch(e){if(!Ue(e))throw e;return}finally{n&&H.current===n&&(H.current=null)}},ue=async()=>{if(m.trim()&&!m.trim().endsWith(`/`)){E(``);try{await K(`/api/projects/${e}/file`,{method:`POST`,body:JSON.stringify({path:m,content:``})});let t=(await le())?.find(e=>e.path===m);t&&await ge(t),O(null),M(e=>new Set([...e,...Bm(m)])),p(!1),h(``)}catch(e){E(q(e))}}},de=async()=>{if(!C.trim())return;E(``);let t=D?`${D}/${C.trim()}`:C.trim();try{let n=await K(`/api/projects/${e}/folders`,{method:`POST`,body:JSON.stringify({path:t})});await le(),M(e=>new Set([...e,...Bm(n.path),n.path])),O(n.path),S(!1),w(``)}catch(e){E(q(e))}},fe=async(n,r=new Set,i=D)=>{if(!n.length||ce.current)return;let a=t.maxUploadSizeMB;if(n.find(e=>e.size>a*1024*1024)){B({kind:`error`,message:l(`errors.fileTooLarge`,{size:a})});return}let o=i??``,s=n.map(e=>o?`${o}/${e.name}`:e.name),c=new Map;for(let e of s)c.set(e,(c.get(e)??0)+1);let d=[...c.entries()].filter(([,e])=>e>1).map(([e])=>e);if(d.length){B({kind:`error`,message:l(`errors.duplicateUploadNames`,{files:d.join(`, `)})});return}let f=new Set(u.map(e=>e.path)),p=[...new Set(s.filter(e=>f.has(e)&&!r.has(e)))];if(p.length){B(null),z({files:n,directory:o,collisions:p});return}z(null),V.current!==null&&window.clearTimeout(V.current),V.current=null,B(null),ce.current=!0,oe(!0);let m=0;try{let i=new URLSearchParams;o&&i.set(`directory`,o);let a=``;for(let[t,c]of n.entries()){let l=s[t];i.delete(`overwrite`),r.has(l)&&i.set(`overwrite`,`1`);let u=i.toString()?`?${i.toString()}`:``,d=new FormData;d.append(`file`,c);try{B({kind:`uploading`,fileName:c.name,current:t+1,total:n.length});let r=await K(`/api/projects/${e}/upload${u}`,{method:`POST`,body:d});m+=1,typeof r.path==`string`&&Me(r.path)&&(a=r.path)}catch(e){if(e instanceof He&&e.status===409&&!r.has(l)&&e.code===`FILE_EXISTS`){if(B(null),t>0)try{await le()}catch{}z({files:n.slice(t),directory:o,collisions:[l]});return}throw e}}let c;try{c=(await le())?.find(e=>e.path===a&&Me(e.path,e.textContent)&&(e.size??0)<=t.maxCollaborativeFileSizeMB*1024*1024)}catch(e){B({kind:`error`,message:l(`editor.uploadSucceededRefreshFailed`,{message:q(e)})});return}c&&await ge(c),B({kind:`success`,count:m}),V.current=window.setTimeout(()=>{B(e=>e?.kind===`success`?null:e),V.current=null},3e3)}catch(e){try{await le()}catch{}let t=m>0?l(`editor.uploadFailedPartial`,{count:n.length,uploaded:m,total:n.length,message:q(e)}):l(`editor.uploadFailed`,{message:q(e)});B({kind:`error`,message:t})}finally{ce.current=!1,oe(!1)}},pe=()=>{V.current!==null&&window.clearTimeout(V.current),V.current=null,B(null)},me=async e=>{await fe(Array.from(e.target.files??[])),e.target.value=``},he=async n=>{U.current?.abort(),U.current=null,b(!1);let r=Wm(e,n.path);if(Um(n,t.maxCollaborativeFileSizeMB*1024*1024)===`large`){let e=Me(n.path,n.textContent)?Math.min(zm,t.maxCollaborativeFileSizeMB*1024*1024):zm;_({path:n.path,kind:`large`,size:n.size??0,url:r,limitBytes:e});return}let i=Hm(n.path,n.textContent);if(i!==`text`){_({path:n.path,kind:i,size:n.size??0,url:r});return}_({path:n.path,kind:i,size:n.size??0,url:r,content:``}),b(!0);let o=new AbortController;U.current=o;try{let e;try{e=await fetch(r,{signal:o.signal})}catch(e){throw We(e)}let t=e.headers.get(`content-type`)??``;if(!e.ok){let n=null;try{n=t.includes(`application/json`)?await e.json():await e.text()}catch{}throw new He(W(n,e.status),e.status,Xe(n))}let i=new Uint8Array(await e.arrayBuffer());if(!Fe(i)){_(e=>e?.path===n.path?{...e,kind:`unsupported`,content:void 0}:e);return}let a=new TextDecoder().decode(i);_(e=>e?.path===n.path?{...e,content:a}:e)}catch(e){Ue(e)||(_(null),a(q(e)))}finally{U.current===o&&(U.current=null,b(!1))}},ge=async n=>{if(U.current?.abort(),U.current=null,b(!1),O(null),A(n.path),Um(n,t.maxCollaborativeFileSizeMB*1024*1024)!==`editor`){await he(n);return}let r=new AbortController;U.current=r;try{if(await K(`/api/projects/${e}/file?path=${encodeURIComponent(n.path)}&validate=1`,{signal:r.signal}),r.signal.aborted||U.current!==r)return;s(n.path)}catch(t){if(r.signal.aborted||U.current!==r||Ue(t))return;t instanceof He&&t.code===`FILE_CONTENT_INVALID`?(d(e=>e.map(e=>e.path===n.path?{...e,textContent:!1}:e)),_({path:n.path,kind:`unsupported`,size:n.size??0,url:Wm(e,n.path)})):a(q(t))}finally{U.current===r&&(U.current=null)}},_e=async(t,n,r)=>{if(!await i())return null;let a=await K(`/api/projects/${e}/path`,{method:`PATCH`,body:JSON.stringify({source:t.path,destinationDirectory:n,destinationName:r})}),l=e=>e===t.path?a.path:e.startsWith(`${t.path}/`)?`${a.path}${e.slice(t.path.length)}`:e;s(e=>l(e)),c(e=>l(e)),O(e=>e&&l(e)),A(e=>e&&l(e));let[u,f]=await Promise.all([K(`/api/projects/${e}/files`),K(`/api/projects/${e}`)]);return d(u.files),o(f.project),M(e=>new Set([...e,...Bm(a.path),n].filter(Boolean))),a.path};return(0,J.useEffect)(()=>()=>{H.current?.abort(),U.current?.abort(),V.current!==null&&window.clearTimeout(V.current)},[]),(0,J.useEffect)(()=>{U.current?.abort(),U.current=null,b(!1)},[n]),(0,J.useEffect)(()=>{D!==null&&(U.current?.abort(),U.current=null,b(!1))},[D]),(0,J.useEffect)(()=>{n&&A(n)},[n]),{files:u,setFiles:d,loadFiles:le,newFileOpen:f,setNewFileOpen:p,newFilePath:m,setNewFilePath:h,resourcePreview:g,setResourcePreview:_,resourcePreviewLoading:y,setResourcePreviewLoading:b,newFolderOpen:x,setNewFolderOpen:S,newFolderName:C,setNewFolderName:w,fileDialogError:T,setFileDialogError:E,selectedFolder:D,setSelectedFolder:O,selectedFile:k,setSelectedFile:A,expandedFolders:j,setExpandedFolders:M,moveEntry:ee,setMoveEntry:N,moveName:P,setMoveName:te,moveDestination:F,setMoveDestination:I,deleteEntry:L,setDeleteEntry:ne,fileDragActive:R,setFileDragActive:re,uploadConflict:ie,setUploadConflict:z,uploadingFiles:ae,uploadFeedback:se,dismissUploadFeedback:pe,directoryEntries:u.filter(e=>e.type===`directory`),visibleEntries:u.filter(e=>Bm(e.path).every(e=>j.has(e))),createFile:ue,createFolder:de,uploadFiles:fe,upload:me,openFile:ge,movePath:async()=>{if(!ee)return;let e=P.trim();if(e){E(``);try{if(!await _e(ee,F,e))return;N(null),te(``),I(``)}catch(e){E(q(e))}}},movePathToFolder:async(e,t)=>{if(Km(e.path)!==t&&(e.type!==`directory`||t!==e.path&&!t.startsWith(`${e.path}/`)))try{await _e(e,t,e.path.split(`/`).at(-1)??e.path)}catch(e){a(q(e))}},removePath:async()=>{if(L){E(``);try{if(r&&!await i())return;await K(`/api/projects/${e}/file?path=${encodeURIComponent(L.path)}`,{method:`DELETE`}),ne(null)}catch(e){E(q(e))}}}}}function Km(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function qm({active:e,harperEnabled:t=!0,projectId:n,activeFile:r,content:i,dictionaryWords:a,additionalIssues:o=[],additionalIssuesReady:s=!0}){let[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(``),[m,h]=(0,J.useState)(0),[g,_]=(0,J.useState)(null),[v,y]=(0,J.useState)(null),[b,x]=(0,J.useState)(!1),[C,w]=(0,J.useState)(0),T=(0,J.useRef)(0),E=(0,J.useRef)(!1),D=(0,J.useRef)(!1),O=(0,J.useRef)(i),k=(0,J.useRef)(r),A=(0,J.useRef)(0);O.current=i,k.current=r,D.current=b,(0,J.useEffect)(()=>{l([]),d(``),p(``),_(null),y(null),x(!1)},[r,a,t]),(0,J.useEffect)(()=>{y(null),x(!1)},[n]),(0,J.useEffect)(()=>{let o=++T.current;if(!e||!r){l([]),d(``),p(``),_(null);return}if(!t||v){l([]),d(``),p(``);return}let s=i,c=r,u=!1,f=window.setTimeout(()=>{y(null),(async()=>{try{let{lintLatex:e,isHarperLintSupersededError:t}=await S(async()=>{let{lintLatex:e,isHarperLintSupersededError:t}=await import(`./spellCheck-BTyLQAFH.js`);return{lintLatex:e,isHarperLintSupersededError:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13]),import.meta.url);if(u||o!==T.current||O.current!==s||k.current!==c)return;let r;try{r=await e(n,c,s,a)}catch(e){if(t(e))return;throw e}if(u||o!==T.current||O.current!==s||k.current!==c)return;E.current=!1,x(!1),l(r),d(s),p(c),h(0),_(null)}catch(e){if(u||o!==T.current||O.current!==s||k.current!==c)return;l([]),d(``),p(``),y(e instanceof Error?e.message:String(e));let t=E.current;E.current=!1,x(t?D.current:!1)}})()},700);return()=>{u=!0,window.clearTimeout(f)}},[e,t,n,r,i,a,C,v]),(0,J.useEffect)(()=>{if(!v||!e||!t)return;let n=!1,r=()=>{n||(n=!0,E.current=!0,y(null),w(e=>e+1))},i=window.setTimeout(r,15e3);return window.addEventListener(`online`,r,{once:!0}),()=>{window.clearTimeout(i),window.removeEventListener(`online`,r)}},[v,e,t]);let j=t&&e&&f===r&&u===i,M=(0,J.useMemo)(()=>{if(!e)return[];let t=[...j?c:[],...o].sort((e,t)=>e.from-t.from||e.to-t.to),n=new Set;return t.filter(e=>{let t=`${e.from}:${e.to}:${e.kind}:${e.message}`;return!n.has(t)&&(n.add(t),!0)})},[e,o,j,c]),ee=(0,J.useMemo)(()=>e&&(!t||j)&&s?{total:M.length,unique:new Set(M.map(e=>`${e.kind}:${e.word.toLocaleLowerCase(`en-US`)}`)).size}:null,[e,s,t,j,M]);return(0,J.useEffect)(()=>{h(e=>M.length?Math.min(e,M.length-1):0)},[M]),{issues:M,jump:e?g:null,index:m,summary:ee,jumpToIssue:e=>{if(!M.length)return;let t=Math.max(0,Math.min(e,M.length-1)),n=M[t];h(t),_({from:n.from,to:n.to,nonce:++A.current})},error:e&&t&&!b?v:null,nativeFallback:e&&t&&!!v,retry:()=>{E.current=!1,y(null),x(!1),w(e=>e+1)},dismissError:()=>{E.current=!1,x(!0)}}}function Jm({active:e,projectId:t,activeFile:n,content:r}){let[i,a]=(0,J.useState)([]),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(``),[u,d]=(0,J.useState)(null),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(0),g=(0,J.useRef)(0),_=(0,J.useRef)(r),v=(0,J.useRef)(n);_.current=r,v.current=n,(0,J.useEffect)(()=>{a([]),s(``),l(``),d(null),p(!1)},[t,n]),(0,J.useEffect)(()=>{let i=++g.current;if(!e||!n){a([]),s(``),l(``);return}let o=r,c=n,u=!1,f=window.setTimeout(()=>{(async()=>{try{let{lintChktex:e,isChktexLintSupersededError:n}=await S(async()=>{let{lintChktex:e,isChktexLintSupersededError:t}=await import(`./chktex-BrzPYHey.js`);return{lintChktex:e,isChktexLintSupersededError:t}},__vite__mapDeps([14,1,2,3,4,5,6,7,8,9,10,11,12,13]),import.meta.url);if(u||i!==g.current||_.current!==o||v.current!==c)return;let r;try{r=await e(t,c,o)}catch(e){if(n(e))return;throw e}if(u||i!==g.current||_.current!==o||v.current!==c)return;a(r),s(o),l(c),d(null),p(!1)}catch(e){if(u||i!==g.current||_.current!==o||v.current!==c)return;a([]),s(``),l(``),d(e instanceof Error?e.message:String(e))}})()},2e3);return()=>{u=!0,window.clearTimeout(f)}},[e,t,n,r,m]);let y=e&&c===n&&o===r;return{issues:y?i:[],checked:y,error:e&&!f?u:null,retry:()=>{d(null),p(!1),h(e=>e+1)},dismissError:()=>p(!0)}}function Ym(e,t){return/\.tex$/i.test(e)&&/\.tex$/i.test(t)}function Xm({projectId:e,mainFile:t,activeFile:n,onOpenSourceFile:r,onError:i,onShowPdf:a,onShowEditor:o}){let[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),p=(0,J.useRef)(null),m=(0,J.useRef)(0),h=(0,J.useRef)(n),g=(0,J.useRef)(r),_=(0,J.useRef)(i),v=(0,J.useRef)(a),y=(0,J.useRef)(o);h.current=n,g.current=r,_.current=i,v.current=a,y.current=o,(0,J.useEffect)(()=>(p.current?.abort(),p.current=null,c(null),u(null),f(null),()=>p.current?.abort()),[e,t]);let b=(e,t,n)=>{f({path:e,line:t,column:n,nonce:++m.current}),g.current(e)},x=async(n,r,i,a={})=>{if(!Ym(n,t))return;p.current?.abort();let o=new AbortController;p.current=o;try{let a=await K(`/api/projects/${e}/sync/pdf?mainFile=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}&line=${r}&column=${i}`,{signal:o.signal});if(p.current!==o||!a)return;c({...a,nonce:++m.current}),v.current()}catch(e){!Ue(e)&&!a.silent&&_.current(q(e))}finally{p.current===o&&(p.current=null)}},S=async(n,r,i)=>{let a=h.current;p.current?.abort();let o=new AbortController;p.current=o;try{let s=await K(`/api/projects/${e}/sync/source?mainFile=${encodeURIComponent(t)}&page=${n}&x=${r}&y=${i}`,{signal:o.signal});if(p.current!==o||h.current!==a)return;y.current(),b(s.path,s.line,s.column)}catch(e){Ue(e)||_.current(q(e))}finally{p.current===o&&(p.current=null)}};return{pdfTarget:s,pdfViewport:l,sourceJump:d,setPdfViewport:u,resetPdfViewport:()=>u(null),clearPdfViewport:()=>{p.current?.abort(),p.current=null,u(null),c(null)},jumpToSource:b,syncSourceToPdf:x,syncPdfToSource:S,syncVisiblePdfToSource:()=>l?S(l.page,l.x,l.y):Promise.resolve()}}function Zm(e,t,n){return b(`texlite.workspaceLayout:${encodeURIComponent(e)}:${encodeURIComponent(t)}${n?`:phone`:``}`)}function Qm(e,t,n){let r=G(Zm(e,t,n));return r===`editor-only`||r===`pdf-only`||!n&&r===`editor-pdf`?r:n?`editor-only`:`editor-pdf`}function $m(e,t){let n=ye(),[r,i]=(0,J.useState)(()=>Qm(e,t,n));return(0,J.useEffect)(()=>{i(Qm(e,t,n))},[e,t,n]),{workspaceLayout:n&&r===`editor-pdf`?`editor-only`:r,setWorkspaceLayout:r=>{let a=n&&r===`editor-pdf`?`editor-only`:r;i(a),Ze(Zm(e,t,n),a)},phone:n}}function eh(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function th(e){let t=ft(ut(e));for(let e of t.matchAll(/\\documentclass(?![A-Za-z@])\s*(?:\[[^\]]*\]\s*)?\{/g))if(e.index!==void 0&&!eh(t,e.index))return!0;return!1}function nh(e){return/\.(?:md|markdown|mdown|mkdn)$/i.test(e)}function rh(e,t,n){return e===`diagnostics`?`diagnostics`:t&&n?`markdown`:`pdf`}function ih(e,t){if(t.startsWith(`#`))return{kind:`anchor`,id:ah(t.slice(1))};if(/^[a-z][a-z\d+.-]*:/i.test(t)||t.startsWith(`//`))return{kind:`external`};let n=t.replace(/[?#].*$/s,``);if(!n)return{kind:`invalid`};let r=ah(n),i=e.includes(`/`)?e.slice(0,e.lastIndexOf(`/`)).split(`/`):[],a=r.startsWith(`/`)?[]:[...i];for(let e of r.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(!a.length)return{kind:`invalid`};a.pop()}else a.push(e)}return a.length?{kind:`project`,path:a.join(`/`)}:{kind:`invalid`}}function ah(e){try{return decodeURIComponent(e)}catch{return e}}function oh(e){let t=new Map;return e.map(e=>{let n=e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s_-]/gu,``).replace(/\s/g,`-`),r=t.get(n)??0;return t.set(n,r+1),r?`${n}-${r}`:n})}function sh({site:e,project:t,activeFile:n,saveStateLabel:r,editorPreferences:i,activeSessions:a,collaborationStatus:o,reconnectCollaboration:s,protocolUpgradeRequired:c,showEditor:l,filesCollapsed:u,toggleFilesPanel:d,workspaceLayout:f,changeWorkspaceLayout:p,onBack:h,onShare:g,showCitationLibrary:y,citationLibraryOpen:b,onCitationLibrary:x,onHistory:S,onGit:C,canManageGit:w,formatting:T,readOnly:E,collaborationSynced:O,onToggleComments:k,commentsOpen:A,unresolvedCommentCount:M,onToggleSettings:ee,settingsOpen:N,compileBusy:P,sharedCompiling:te,localCompiling:F,cancelling:I,onCompile:R,onCancelCompile:re,agentTerminal:ie}){let{t:z}=v(),{showExecutionReminder:ae}=m();return(0,Y.jsxs)(ke,{siteName:e.siteName,projectName:t.name,subtitle:(0,Y.jsxs)(Y.Fragment,{children:[n,` · `,r]}),onBack:h,accessory:(0,Y.jsxs)(Y.Fragment,{children:[i.vimMode&&(0,Y.jsxs)(`span`,{className:`vim-status-badge`,title:z(`editor.vimOnHint`),children:[(0,Y.jsx)(Dt,{size:14}),z(`editor.vimOn`)]}),(0,Y.jsx)(ve,{sessions:a,status:o}),o===`disconnected`&&!c&&(0,Y.jsxs)(`div`,{className:`collaboration-recovery`,role:`status`,children:[(0,Y.jsx)(`span`,{children:z(`editor.collaboration.disconnected`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:s,children:z(`editor.collaboration.reconnect`)})]})]}),children:[l&&(0,Y.jsxs)(`button`,{className:`files-action${u?``:` active`}`,"aria-label":z(`common.files`),title:z(`common.files`),"aria-expanded":!u,onClick:d,children:[u?(0,Y.jsx)(de,{size:15}):(0,Y.jsx)(Ne,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`common.files`)})]}),(0,Y.jsx)(Ce,{value:f,onChange:p,workspacePrimary:!0,previewLabel:nh(n)?z(`editor.mobilePreview`):void 0}),(0,Y.jsxs)(`button`,{type:`button`,className:`share-action`,title:z(`projectSettings.share`),"aria-label":t.sharedMemberCount?`${z(`projectSettings.share`)} (${t.sharedMemberCount})`:z(`projectSettings.share`),onClick:g,children:[(0,Y.jsx)(j,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`projectSettings.share`)}),(t.sharedMemberCount??0)>0&&(0,Y.jsx)(`sup`,{className:`share-action-count`,children:t.sharedMemberCount})]}),y&&(0,Y.jsxs)(`button`,{className:`citation-action${b?` active`:``}`,"aria-label":z(`citationProject.button`),title:z(`citationProject.button`),onClick:x,children:[(0,Y.jsx)(_,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`citationProject.button`)})]}),(0,Y.jsxs)(`button`,{type:`button`,className:`snapshots-action`,"aria-label":z(`history.projectSnapshots`),title:z(`history.projectSnapshots`),onClick:S,children:[(0,Y.jsx)(me,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`history.projectSnapshotsButton`)})]}),(0,Y.jsxs)(`button`,{type:`button`,className:`comments-action${A?` active`:``}`,title:z(`editor.commentsAll`),"aria-label":M>0?`${z(`common.comments`)} (${M})`:z(`common.comments`),onClick:k,children:[(0,Y.jsx)(ne,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`common.comments`)}),M>0&&(0,Y.jsx)(`sup`,{className:`comments-action-count`,children:M})]}),(0,Y.jsxs)(`button`,{className:`git-action`,"aria-label":z(`git.title`),title:z(w?`git.title`:`git.ownerOnly`),disabled:!w,onClick:C,children:[(0,Y.jsx)(L,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:`Git`})]}),ie&&(0,Y.jsxs)(`button`,{type:`button`,className:ie.open?`active`:``,"aria-expanded":ie.open,"aria-label":ae&&ie.activeCount>0?`${z(`agents.terminal`)}: ${z(`agents.activeCount`,{count:ie.activeCount})}`:z(`agents.terminal`),title:z(`agents.terminal`),onClick:ie.toggle,children:[(0,Y.jsx)(D,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label`,children:z(`agents.terminal`)}),ae&&ie.activeCount>0&&(0,Y.jsx)(`sup`,{className:`agent-active-count`,"aria-label":z(`agents.activeCount`,{count:ie.activeCount}),children:ie.activeCount})]}),(0,Y.jsxs)(`button`,{className:N?`active`:``,"aria-label":z(`common.settings`),title:z(`common.settings`),onClick:ee,children:[(0,Y.jsx)(Pe,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label workspace-action-label-persistent`,children:z(`common.settings`)})]}),te||F?(0,Y.jsxs)(`button`,{className:`compile cancel-compile`,"aria-label":z(I?`compileControls.cancelling`:`compileControls.cancel`),title:z(`compileControls.cancel`),onClick:re,disabled:I||T||E||!O,children:[I?(0,Y.jsx)(Le,{className:`spin`,size:15}):(0,Y.jsx)(B,{size:15}),(0,Y.jsx)(`span`,{className:`workspace-action-label workspace-action-label-persistent`,children:z(I?`compileControls.cancelling`:`compileControls.cancel`)})]}):(0,Y.jsxs)(`button`,{className:`compile`,"aria-label":z(`editor.compile`,{engine:t.engine}),title:z(`editor.compileShortcut`),onClick:R,disabled:P||T||E||!O,children:[P?(0,Y.jsx)(Le,{className:`spin`,size:15}):(0,Y.jsx)(he,{size:15}),(0,Y.jsxs)(`span`,{className:`workspace-action-label workspace-action-label-persistent`,children:[z(`editor.compileShort`),(0,Y.jsxs)(`span`,{className:`compile-engine-label`,children:[` · `,t.engine]})]})]})]})}function ch(e,t,n){return e===`connected`?t:e===`disconnected`&&n?`editor.offlineDraft`:`editor.collaboration.${e}`}function lh({children:e,tabs:t,terminal:n}){let{t:r}=v(),i=Se(),[a,o]=(0,J.useState)(!1),s=!!n,c=(0,J.useRef)(s),l=s&&a;return(0,J.useLayoutEffect)(()=>{c.current&&!s&&i.current?.resize(`100%`),c.current=s},[i,s]),(0,Y.jsx)(`main`,{className:`source-panel`,children:(0,Y.jsxs)(we,{orientation:`vertical`,className:`agent-editor-group`,children:[(0,Y.jsx)(be,{id:`source-editor`,panelRef:i,minSize:`20%`,collapsible:!!n,collapsedSize:`0%`,onResize:e=>o(e.asPercentage===0),children:(0,Y.jsxs)(`div`,{className:`source-editor-pane`,inert:l,children:[t,e]})}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`agent-terminal-resizer`,"aria-label":r(`agents.resizeTerminal`)}),(0,Y.jsx)(be,{id:`agent-terminal`,defaultSize:`35%`,minSize:`20%`,children:n({maximized:l,toggleMaximized:()=>{let e=i.current;e?.isCollapsed()?e.expand():e?.collapse()}})})]})]})})}function uh({direction:e,disabled:t,onClick:n,label:r}){let{t:i}=v(),[a,o]=(0,J.useState)(!1),s=e===`pdf`?_t:ee,c=r??i(e===`pdf`?`editor.showInPdf`:`editor.showInSource`);return(0,Y.jsx)(`button`,{type:`button`,className:`workspace-mobile-sync workspace-mobile-sync-${e}`,title:c,"aria-label":c,"aria-busy":a,disabled:t||a,onClick:async()=>{o(!0);try{await n()}finally{o(!1)}},children:a?(0,Y.jsx)(Le,{className:`spin`,size:18,"aria-hidden":`true`}):(0,Y.jsx)(s,{size:18,"aria-hidden":`true`})})}var dh=(0,J.lazy)(()=>S(()=>import(`./LatexEditor-Boc-45KL.js`).then(e=>({default:e.LatexEditor})),__vite__mapDeps([15,2,3,4,5,8,16,7,9,17,12,1,6,10,11,13,18,19,20,21,22,23,24,25]),import.meta.url));function fh({project:e,projectId:t,activeFile:n,mainFile:r,openTabs:i,content:a,loadedFile:o,readOnly:s,comments:c,focusComment:l,editorPreferences:u,completionIndex:d,nativeSpellCheck:f,spellCheckIssues:p,spellCheckJump:m,sourceJump:g,collaborativeText:_,collaborationAwareness:y,undoManager:b,editorNotice:x,activateTab:S,closeTab:C,handleTabKeyDown:w,updateEditorContent:T,setSelection:E,onAddComment:D,onSelectionHistory:O,onCommentClick:A,onSpellCheckReplace:j,onReferenceNavigate:M,onCursor:ee,terminal:N,mobileSync:P,agentChanges:te=null,activeAgentChangeId:F=null,agentChangeReveal:I=null,onAgentChangesStale:L,onOpenAgentChange:ne}){let{t:R}=v(),re=ep(c,n),ie=tp(l,n,o);return(0,Y.jsx)(be,{id:`source`,minSize:`22%`,children:(0,Y.jsx)(lh,{terminal:N,tabs:u.openFilesInTabs&&i.length>0&&(0,Y.jsx)(`div`,{className:`editor-tabs-bar`,role:`tablist`,"aria-label":R(`editor.openFiles`),children:(0,Y.jsx)(`div`,{className:`editor-tabs-scroll`,children:i.map((t,r)=>{let i=t===n,a=t===e.mainFile,o=t.split(`/`).at(-1)||t;return(0,Y.jsxs)(`div`,{className:`editor-tab-item${i?` active`:``}`,role:`presentation`,children:[(0,Y.jsxs)(`button`,{id:`editor-tab-${encodeURIComponent(t)}`,type:`button`,role:`tab`,"aria-selected":i,"aria-controls":`editor-source-content`,tabIndex:i?0:-1,className:`editor-tab${i?` active`:``}${a?` main-tab`:``}`,onClick:()=>S(t),onKeyDown:e=>w(e,r),title:t,children:[(0,Y.jsx)(`span`,{className:`editor-tab-icon`,children:a?(0,Y.jsx)(h,{size:13}):(0,Y.jsx)(k,{size:13})}),(0,Y.jsx)(`span`,{className:`editor-tab-title`,children:o}),a&&(0,Y.jsx)(`small`,{className:`editor-tab-badge`,children:R(`editor.currentMainShort`)})]}),(0,Y.jsx)(`button`,{type:`button`,className:`editor-tab-close`,title:R(`common.close`),"aria-label":`${R(`common.close`)} ${o}`,onClick:()=>C(t),children:(0,Y.jsx)(B,{size:12})})]},t)})})}),children:(0,Y.jsxs)(`div`,{id:`editor-source-content`,className:`editor-content-container`,children:[(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`preview-empty`,children:[(0,Y.jsx)(Le,{className:`spin`,size:22}),(0,Y.jsx)(`span`,{children:R(`common.loading`)})]}),children:(0,Y.jsx)(dh,{value:a,projectId:t,filePath:n,mainFile:r,readOnly:s,comments:re,focusComment:ie,preferences:u,nativeSpellCheck:f,completionIndex:d,spellCheckIssues:p,spellCheckJump:m,jumpTo:o===n&&g?.path===n?g:null,searchRequest:0,collaboration:_?{text:_,awareness:y,undoManager:s?void 0:b}:void 0,onChange:T,onSelection:E,onAddComment:D,onSelectionHistory:O,onCommentClick:A,onSpellCheckReplace:j,onReferenceNavigate:M,onCursor:ee,agentChanges:te,activeAgentChangeId:F,agentChangeReveal:I,onAgentChangesStale:L,onOpenAgentChange:ne},n)}),x&&(0,Y.jsx)(`div`,{className:`editor-centered-notice`,role:`status`,"aria-live":`polite`,children:x}),P&&(0,Y.jsx)(uh,{direction:`pdf`,...P})]})})})}var ph=4e3,mh=2e3,hh=3;function gh(e,t){return b(`texlite-agent-review:${encodeURIComponent(e)}:${encodeURIComponent(t)}`)}function _h(e){let t=$e(e);return new Set(Array.isArray(t)?t.filter(e=>typeof e==`string`):[])}function vh(e,t){tt(e,[...t])}function yh(e,t,n){let r=gh(e,t),[i,a]=(0,J.useState)([]),[o,s]=(0,J.useState)(()=>_h(r)),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),f=(0,J.useRef)(null),p=(0,J.useRef)(void 0),m=(0,J.useRef)(0),h=(0,J.useCallback)(e=>{e||(m.current=0),f.current?.abort();let n=new AbortController;f.current=n,l(!0),K(`/api/projects/${encodeURIComponent(t)}/agent-changes`,{signal:n.signal}).then(e=>{if(n.signal.aborted)return;a(e.files),d(``);let t=new Set(e.files.flatMap(e=>e.changes.flatMap(e=>e.ids)));s(e=>{let n=new Set([...e].filter(e=>t.has(e)));return n.size!==e.size&&vh(r,n),n})}).catch(e=>{n.signal.aborted||d(q(e))}).finally(()=>{f.current===n&&l(!1)})},[t,r]),g=(0,J.useCallback)(()=>h(!1),[h]),_=(0,J.useCallback)(()=>{p.current!==void 0||m.current>=hh||(m.current+=1,p.current=window.setTimeout(()=>{p.current=void 0,h(!0)},mh))},[h]);(0,J.useEffect)(()=>{s(_h(r)),a([]),g();let e=()=>g();return window.addEventListener(`texlite:agent-tasks`,e),()=>{window.removeEventListener(`texlite:agent-tasks`,e),f.current?.abort(),window.clearTimeout(p.current),p.current=void 0}},[r,g]),(0,J.useEffect)(()=>{if(!n)return;let e=window.setInterval(()=>{document.visibilityState!==`hidden`&&g()},ph);return()=>window.clearInterval(e)},[n,g]);let v=(0,J.useCallback)(e=>e.ids.some(e=>!o.has(e)),[o]),y=(0,J.useMemo)(()=>i.flatMap(e=>e.changes.filter(v).map(t=>({...t,path:e.path,sourceHash:e.sourceHash}))),[i,v]),b=(0,J.useCallback)(e=>{let t=i.find(t=>t.path===e);return t?{sourceHash:t.sourceHash,changes:t.changes.filter(v)}:null},[i,v]),x=(0,J.useCallback)(e=>s(t=>{let n=new Set(t);for(let t of e)n.add(t);return vh(r,n),n}),[r]);return{pending:y,forFile:b,loading:c,error:u,refresh:g,refreshSoon:_,markReviewed:(0,J.useCallback)(e=>x(e.ids),[x]),markAllReviewed:(0,J.useCallback)(()=>x(i.flatMap(e=>e.changes.flatMap(e=>e.ids))),[x,i])}}var bh=t(r(),1);function xh({children:e,showControls:t=!0}){let[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(null);return(0,J.useLayoutEffect)(()=>{if(!n||!t)return;let e=()=>{let e=n.getBoundingClientRect(),t=e.left+e.width/2,r=e.top+e.height/2;a(e=>e?.left===t&&e.top===r?e:{left:t,top:r})},r=new ResizeObserver(e);r.observe(n);let i=n.parentElement;if(i){r.observe(i);for(let e of i.children)e.hasAttribute(`data-panel`)&&r.observe(e)}return window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),e(),()=>{r.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[n,t]),(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`resize-handle sync-resize-handle`,elementRef:r,children:(0,Y.jsx)(pe,{className:`resize-grip`,size:12})}),t&&i&&(0,bh.createPortal)((0,Y.jsx)(`span`,{className:`sync-direction-buttons`,style:{position:`fixed`,...i},children:e}),document.body)]})}var Sh=360,Ch=280,wh=640,Th=()=>b(`texlite-comments-width`);function Eh(){let e=Number(G(Th()));return Number.isFinite(e)&&e>=Ch&&e<=wh?e:Sh}var Dh=(e,{min:t,max:n})=>Math.min(n,Math.max(t,Math.round(e)));function Oh({open:e,onHost:t}){let{t:n}=v(),r=(0,J.useId)(),i=(0,J.useRef)(null),a=(0,J.useRef)(null),o=(0,J.useRef)(null),[s,c]=(0,J.useState)(Eh),l=(0,J.useRef)(s),[u,d]=(0,J.useState)(!1),[f,p]=(0,J.useState)({now:s,min:Ch,max:wh}),m=(0,J.useCallback)(e=>{i.current=e,t?.(e)},[t]),h=()=>{let e=i.current,t=Number.parseFloat(getComputedStyle(e).getPropertyValue(`--comments-preview-reserve`))||0,n=Math.max(0,Math.min(wh,Math.floor(e.parentElement.getBoundingClientRect().width-t)));return{min:Math.min(Ch,n),max:n}},g=e=>{l.current=e,c(e)},_=e=>{Ze(Th(),String(Math.max(Ch,e)))};(0,J.useEffect)(()=>{if(!e){d(!1);return}let t=i.current,n=a.current,r=()=>{let e={now:Math.round(t.getBoundingClientRect().width),...h()};p(t=>t.now===e.now&&t.min===e.min&&t.max===e.max?t:e)};r();let s=new ResizeObserver(r);return s.observe(t),s.observe(t.parentElement),()=>{s.disconnect();let e=o.current;o.current=null,e&&n.hasPointerCapture(e.pointerId)&&n.releasePointerCapture(e.pointerId)}},[e]);let y=e=>{e.button!==0||o.current||(e.preventDefault(),e.stopPropagation(),o.current={pointerId:e.pointerId,x:e.clientX,width:i.current.getBoundingClientRect().width,preferred:l.current},e.currentTarget.setPointerCapture(e.pointerId),d(!0))},b=e=>{let t=o.current;t&&t.pointerId===e.pointerId&&(e.preventDefault(),e.stopPropagation(),g(Dh(t.width+e.clientX-t.x,h())))},x=(e,t=!1)=>{let n=o.current;n&&n.pointerId===e.pointerId&&(o.current=null,t?g(n.preferred):l.current!==n.preferred&&_(l.current),d(!1),e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))};return(0,Y.jsx)(`div`,{ref:m,id:r,className:`workspace-comments-slot`,hidden:!e,"data-resizing":u||void 0,style:{"--workspace-comments-width":`${s}px`},children:e&&(0,Y.jsx)(`div`,{ref:a,className:`comments-resize-handle`,role:`separator`,tabIndex:0,"aria-orientation":`vertical`,"aria-label":n(`editor.resizeComments`),"aria-controls":r,"aria-valuemin":f.min,"aria-valuemax":f.max,"aria-valuenow":f.now,"aria-valuetext":`${f.now} px`,onPointerDown:y,onPointerMove:b,onPointerUp:x,onPointerCancel:e=>x(e,!0),onLostPointerCapture:e=>x(e,!0),onKeyDown:e=>{let t=h(),n=i.current.getBoundingClientRect().width,r=e.shiftKey?48:16,a=e.key===`ArrowLeft`?n-r:e.key===`ArrowRight`?n+r:e.key===`Home`?t.min:e.key===`End`?t.max:null;if(a===null)return;e.preventDefault(),e.stopPropagation();let o=Dh(a,t);g(o),_(o)},onDoubleClick:e=>{e.preventDefault(),e.stopPropagation(),g(Sh),_(Sh)}})})}function kh({diagnostics:e,files:t,empty:n,tone:r,onJump:i}){let{t:a}=v(),o=r===`error`?Ct:se;return e.length?(0,Y.jsx)(`div`,{className:`compile-diagnostic-list compile-${r}`,children:e.map((e,n)=>{let r=Nh(e.file,t),s=!!(r&&e.line);return(0,Y.jsxs)(`button`,{type:`button`,disabled:!s,className:`compile-diagnostic-row`,onClick:()=>{r&&e.line&&i(r,e.line,e.column??1)},children:[(0,Y.jsx)(o,{size:15}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.message}),(0,Y.jsxs)(`small`,{children:[e.phase,r?` · ${r}${e.line?`:${e.line}`:``}`:e.line?` · ${a(`editor.lineNumber`,{line:e.line})}`:``]})]})]},`${e.phase}-${e.file??``}-${e.line??0}-${n}`)})}):(0,Y.jsxs)(`div`,{className:`compile-empty compile-${r}`,children:[(0,Y.jsx)(o,{size:26}),(0,Y.jsx)(`span`,{children:n})]})}function Ah({lines:e,empty:t,tone:n=`log`}){let r=n===`error`?Ct:n===`warning`?se:E;return e.length?(0,Y.jsx)(`pre`,{className:`compile-output compile-${n}`,children:e.join(`
|
|
11
|
+
`)}):(0,Y.jsxs)(`div`,{className:`compile-empty compile-${n}`,children:[(0,Y.jsx)(r,{size:26}),(0,Y.jsx)(`span`,{children:t})]})}function jh({projectId:e,mainFile:t,artifacts:n,preview:r,loading:i,onView:a}){let{t:o}=v(),s=n=>x(`/api/projects/${e}/compile/artifacts?mainFile=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}&download=1`);return n.length?(0,Y.jsxs)(`div`,{className:`artifact-browser`,children:[(0,Y.jsx)(`div`,{className:`artifact-list`,children:n.map(e=>(0,Y.jsxs)(`div`,{className:`artifact-row${r?.path===e.path?` active`:``}`,children:[(0,Y.jsxs)(`button`,{type:`button`,disabled:!e.viewable,title:e.viewable?o(`editor.viewArtifact`):o(`editor.downloadToView`),onClick:()=>a(e),children:[(0,Y.jsx)(xe,{path:e.path,size:14}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.path}),(0,Y.jsx)(`small`,{children:ae(e.size,{maximumUnit:`MB`})})]})]}),(0,Y.jsx)(`a`,{href:s(e.path),title:o(`editor.downloadArtifact`),"aria-label":o(`editor.downloadArtifact`),children:(0,Y.jsx)(T,{size:14})})]},e.path))}),(0,Y.jsx)(`div`,{className:`artifact-preview`,children:i?(0,Y.jsxs)(`div`,{className:`compile-empty`,children:[(0,Y.jsx)(Le,{className:`spin`,size:24}),(0,Y.jsx)(`span`,{children:o(`common.loading`)})]}):r?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`header`,{children:[(0,Y.jsx)(`strong`,{children:r.path}),(0,Y.jsxs)(`a`,{href:s(r.path),children:[(0,Y.jsx)(T,{size:13}),o(`projects.download`)]})]}),(0,Y.jsx)(`pre`,{children:r.content})]}):(0,Y.jsxs)(`div`,{className:`compile-empty`,children:[(0,Y.jsx)(k,{size:24}),(0,Y.jsx)(`span`,{children:o(`editor.selectArtifact`)})]})})]}):(0,Y.jsxs)(`div`,{className:`compile-empty`,children:[(0,Y.jsx)(Ft,{size:26}),(0,Y.jsx)(`span`,{children:o(`editor.noArtifacts`)})]})}function Mh({mainFile:e,disabled:t,cleaning:n,onCleanCache:r,onCleanArtifacts:i}){let{t:a}=v();return(0,Y.jsxs)(`div`,{className:`compile-clean-panel`,children:[(0,Y.jsxs)(`div`,{className:`compile-clean-intro`,children:[(0,Y.jsx)(se,{size:28}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`strong`,{children:a(`editor.cleanTitle`)}),(0,Y.jsx)(`p`,{children:a(`editor.cleanDescription`,{file:e})})]})]}),(0,Y.jsxs)(`div`,{className:`compile-clean-actions`,children:[(0,Y.jsxs)(`article`,{children:[(0,Y.jsx)(`div`,{className:`compile-clean-action-icon`,children:(0,Y.jsx)(Tt,{size:19})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`compile-clean-action-heading`,children:[(0,Y.jsx)(`strong`,{children:a(`editor.cleanCache`)}),(0,Y.jsx)(Ie,{className:`compile-clean-help`,content:a(`editor.cleanCacheDescription`),icon:xt,size:13})]}),(0,Y.jsxs)(`button`,{type:`button`,className:`compile-clean-operation`,disabled:t||n,onClick:r,children:[n?(0,Y.jsx)(Le,{className:`spin`,size:14}):(0,Y.jsx)(Tt,{size:14}),a(`editor.cleanCache`)]})]})]}),(0,Y.jsxs)(`article`,{className:`danger`,children:[(0,Y.jsx)(`div`,{className:`compile-clean-action-icon`,children:(0,Y.jsx)(M,{size:19})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`compile-clean-action-heading`,children:[(0,Y.jsx)(`strong`,{children:a(`editor.cleanArtifacts`)}),(0,Y.jsx)(Ie,{className:`compile-clean-help`,content:a(`editor.cleanArtifactsDescription`),icon:xt,size:13})]}),(0,Y.jsxs)(`button`,{type:`button`,className:`compile-clean-operation danger`,disabled:t||n,onClick:i,children:[n?(0,Y.jsx)(Le,{className:`spin`,size:14}):(0,Y.jsx)(M,{size:14}),a(`editor.cleanArtifacts`)]})]})]})]})]})}function Nh(e,t){if(!e)return null;let n=t.filter(e=>e.type===`file`).map(e=>e.path),r=e.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(n.includes(r))return r;let i=n.filter(e=>r.endsWith(`/${e}`));if(i.length===1)return i[0];let a=r.split(`/`).at(-1),o=n.filter(e=>e.split(`/`).at(-1)===a);return o.length===1?o[0]:null}var Ph=(0,J.lazy)(()=>Ge().then(e=>({default:e.PdfPreview}))),Fh=(0,J.lazy)(()=>S(()=>import(`./MarkdownPreview-BH2iwvle.js`),__vite__mapDeps([26,2,3,4,5,16,7,9,17,12,1,6,8,10,11,13,27,28,29,30]),import.meta.url));function Ih({commentsOpen:e=!1,onCommentsHost:t,mobileSync:n=!1,projectId:r,activeMainFile:i,previewTab:a,diagnosticTab:o,pdfUrl:s,pdfLoadingMode:c,pdfLoading:l,pdfCompiledAt:u,pdfSizeBytes:d,pdfCompiledLabel:f,pdfTargetLabel:p,pdfDownloadUrl:m,pdfTarget:h,pdfViewport:g,activeFile:_,compileBusy:y,compileLog:b,compileDiagnostics:x,compileMessages:S,artifacts:C,artifactPreview:w,artifactLoading:T,cleaning:E,readOnly:D,collaborationSynced:O,workspaceLayout:k,showSyncResize:A,diagnosticCount:j,selectPreviewTab:M,changeWorkspaceLayout:ee,onSetPdfViewport:N,onResetPdfViewport:P,onPdfDisplayed:te,syncVisiblePdfToSource:F,syncCurrentSourceToPdf:I,syncPdfToSource:L,canSyncWithPdf:ne,canSyncPdfToSource:R,files:re,jumpToSource:ie,onSetCleanMode:z,viewArtifact:ae,markdown:oe=null}){let{t:B}=v(),[ce,V]=(0,J.useState)(``),H=(0,J.useRef)(``),U=e=>{H.current!==e&&(H.current=e,V(e),P(),te(e))},le=R&&!!s&&ce===s,ue=(0,J.useRef)(null),de=a===`markdown`?oe:null,fe=()=>{let e=ue.current?.visibleLine();return e&&oe&&oe.onShowLine(e),Promise.resolve()};return(0,Y.jsxs)(Y.Fragment,{children:[A&&(0,Y.jsx)(xh,{showControls:!e,children:de?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{disabled:de.source===null,title:B(`editor.markdown.showInSource`),"aria-label":B(`editor.markdown.showInSource`),onClick:e=>{e.stopPropagation(),fe()},children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`←`})}),(0,Y.jsx)(`button`,{disabled:de.source===null,title:B(`editor.markdown.showInPreview`),"aria-label":B(`editor.markdown.showInPreview`),onClick:e=>{e.stopPropagation(),de.onShowCursor()},children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`→`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{disabled:!s||!g||!le,title:B(R?le?`editor.showInSource`:`editor.syncTexWaitingForPdf`:`editor.syncTexOnlyForMain`),"aria-label":B(`editor.showInSource`),onClick:e=>{e.stopPropagation(),le&&F()},children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`←`})}),(0,Y.jsx)(`button`,{disabled:!_||!s||!ne,title:B(ne?`editor.showInPdf`:`editor.syncTexOnlyForTex`),"aria-label":B(`editor.showInPdf`),onClick:e=>{e.stopPropagation(),_&&s&&ne&&I()},children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`→`})})]})}),(0,Y.jsx)(be,{id:`preview`,minSize:`22%`,children:(0,Y.jsx)(`div`,{className:`workspace-preview-region`,children:(0,Y.jsxs)(`div`,{className:`workspace-output-layout${e?` has-comments`:``}`,children:[n&&!e&&a===`pdf`&&(0,Y.jsx)(uh,{direction:`source`,disabled:!g||!le,onClick:F}),n&&!e&&de&&(0,Y.jsx)(uh,{direction:`source`,label:B(`editor.markdown.showInSource`),disabled:de.source===null,onClick:fe}),(0,Y.jsx)(Oh,{open:e,onHost:t}),(0,Y.jsxs)(`section`,{className:`preview-panel`,children:[(0,Y.jsx)(Te,{mainFile:i,targetLabel:p,compiledAt:u,compiledLabel:f,sizeBytes:d,downloadUrl:m,activeSurface:a,onSelect:M,diagnosticCount:j,markdownFile:oe?.path}),a===`diagnostics`&&(0,Y.jsxs)(`div`,{className:`preview-subtabs`,role:`tablist`,"aria-label":B(`editor.outputTabs`),children:[(0,Y.jsxs)(`button`,{role:`tab`,"aria-selected":o===`log`,className:o===`log`?`active`:``,onClick:()=>M(`log`),children:[(0,Y.jsx)(jt,{size:13}),B(`editor.log`)]}),(0,Y.jsxs)(`button`,{role:`tab`,"aria-selected":o===`warnings`,className:o===`warnings`?`active`:``,onClick:()=>M(`warnings`),children:[(0,Y.jsx)(se,{size:13}),B(`editor.warnings`),(0,Y.jsx)(`span`,{children:S.warnings.length})]}),(0,Y.jsxs)(`button`,{role:`tab`,"aria-selected":o===`errors`,className:o===`errors`?`active`:``,onClick:()=>M(`errors`),children:[(0,Y.jsx)(Ct,{size:13}),B(`editor.errors`),(0,Y.jsx)(`span`,{children:S.errors.length})]}),(0,Y.jsxs)(`button`,{role:`tab`,"aria-selected":o===`artifacts`,className:o===`artifacts`?`active`:``,onClick:()=>M(`artifacts`),children:[(0,Y.jsx)(Ft,{size:13}),B(`editor.artifacts`),(0,Y.jsx)(`span`,{children:C.length})]}),(0,Y.jsxs)(`button`,{role:`tab`,"aria-selected":o===`clean`,className:o===`clean`?`active`:``,onClick:()=>M(`clean`),children:[(0,Y.jsx)(Tt,{size:13}),B(`editor.clean`)]})]}),(0,Y.jsxs)(`div`,{className:`preview-content preview-${a} ${a===`diagnostics`?`preview-${o}`:``}`,children:[a===`pdf`&&(s?(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,Y.jsx)(Le,{className:`spin`,size:24}),(0,Y.jsx)(`span`,{children:B(`editor.loadingPdf`)})]}),children:(0,Y.jsx)(Ph,{url:s,loadingMode:c,target:h,compiling:y,onDisplayedUrlChange:U,onViewportLocation:(e,t,n)=>{H.current===s&&N({page:e,x:t,y:n})},onDoubleClickLocation:(e,t,n)=>{H.current===s&&le&&(N({page:e,x:t,y:n}),L(e,t,n))}})}):l?(0,Y.jsxs)(`div`,{className:`pdf-loading-state`,role:`status`,"aria-live":`polite`,children:[(0,Y.jsx)(Le,{className:`spin`,size:24}),(0,Y.jsx)(`span`,{children:B(`editor.loadingPdf`)})]}):(0,Y.jsxs)(`div`,{className:`preview-empty preview-empty-uncompiled`,role:`status`,"aria-live":`polite`,children:[(0,Y.jsx)(`span`,{className:`preview-empty-icon`,"aria-hidden":`true`,children:y?(0,Y.jsx)(Le,{className:`spin`,size:26}):(0,Y.jsx)(ge,{size:32})}),(0,Y.jsx)(`strong`,{children:B(y?`editor.compiling`:`editor.previewEmptyTitle`)}),(0,Y.jsx)(`p`,{children:B(y?`editor.previewCompilingHint`:`editor.previewHint`)})]})),de&&(de.source===null?(0,Y.jsxs)(`div`,{className:`preview-empty markdown-preview-empty`,role:`status`,children:[(0,Y.jsx)(Le,{className:`spin`,size:22}),(0,Y.jsx)(`span`,{children:B(`common.loading`)})]}):(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`preview-empty markdown-preview-empty`,role:`status`,children:[(0,Y.jsx)(Le,{className:`spin`,size:22}),(0,Y.jsx)(`span`,{children:B(`common.loading`)})]}),children:(0,Y.jsx)(Fh,{ref:ue,projectId:r,path:de.path,source:de.source,reveal:de.reveal,onOpenPath:de.onOpenPath,onJumpToLine:de.onShowLine},de.path)})),a===`diagnostics`&&o===`log`&&(0,Y.jsx)(Ah,{lines:b?b.split(`
|
|
12
|
+
`):[],empty:B(y?`editor.compiling`:`editor.noLog`)}),a===`diagnostics`&&o===`warnings`&&(x?(0,Y.jsx)(kh,{tone:`warning`,diagnostics:x.warnings,files:re,empty:B(`editor.noWarnings`),onJump:(e,t,n)=>{k===`pdf-only`&&ee(`editor-pdf`),ie(e,t,n)}}):(0,Y.jsx)(Ah,{tone:`warning`,lines:S.warnings,empty:B(`editor.noWarnings`)})),a===`diagnostics`&&o===`errors`&&(x?(0,Y.jsx)(kh,{tone:`error`,diagnostics:x.errors,files:re,empty:B(`editor.noErrors`),onJump:(e,t,n)=>{k===`pdf-only`&&ee(`editor-pdf`),ie(e,t,n)}}):(0,Y.jsx)(Ah,{tone:`error`,lines:S.errors,empty:B(`editor.noErrors`)})),a===`diagnostics`&&o===`artifacts`&&(0,Y.jsx)(jh,{projectId:r,mainFile:i,artifacts:C,preview:w,loading:T,onView:e=>void ae(e)}),a===`diagnostics`&&o===`clean`&&(0,Y.jsx)(Mh,{mainFile:i,disabled:D||!O||y,cleaning:E,onCleanCache:()=>z(`cache`),onCleanArtifacts:()=>z(`artifacts`)})]})]})]})})})]})}function Lh({kind:e,onEdit:t,onDelete:n,onSuggest:r,disabled:i=!1}){let{t:a}=v(),o=(0,J.useRef)(!1);return(0,Y.jsx)(`span`,{className:`comment-actions-menu`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(ot,{modal:!1,children:[(0,Y.jsx)(rt,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,disabled:i,className:`comment-actions-menu-trigger`,"aria-label":a(e===`comment`?`editor.commentActions`:`editor.replyActions`),children:(0,Y.jsx)(V,{size:16,"aria-hidden":!0})})}),(0,Y.jsx)(nt,{children:(0,Y.jsxs)(it,{className:`comment-actions-menu-content`,align:`end`,sideOffset:4,collisionPadding:8,onCloseAutoFocus:e=>{o.current&&e.preventDefault(),o.current=!1},children:[(0,Y.jsxs)(at,{onSelect:()=>{o.current=!0,t()},children:[(0,Y.jsx)(u,{size:13,"aria-hidden":!0}),a(e===`comment`?`editor.editComment`:`editor.editReply`)]}),e===`comment`&&r&&(0,Y.jsxs)(at,{onSelect:()=>{o.current=!0,r()},children:[(0,Y.jsx)(c,{size:13,"aria-hidden":!0}),a(`suggestions.attach`)]}),(0,Y.jsxs)(at,{className:`danger-text`,onSelect:()=>{o.current=!0,n()},children:[(0,Y.jsx)(M,{size:13,"aria-hidden":!0}),a(e===`comment`?`editor.deleteComment`:`editor.deleteReply`)]})]})})]})})}function Rh(e,t){let n=e.slice(0,t),r=/(^|[^\p{L}\p{N}_.-])@([\p{L}\p{N}_.-]*)$/u.exec(n);return r?{start:t-r[2].length-1,end:t,query:r[2]}:null}function zh({projectId:e,value:t,onChange:n,onKeyDown:r,onFocus:i,...a}){let{t:s}=v(),c=(0,J.useRef)(null),[l,u]=(0,J.useState)(null),d=Of({queryKey:Af.candidates(e),enabled:!!l,queryFn:({signal:t})=>K(`/api/projects/${e}/mention-candidates`,{signal:t})}),f=Nf(d.error)?void 0:d.data?.users,[p,m]=(0,J.useState)(0),h=(0,J.useMemo)(()=>{if(!l||!f)return[];let e=l.query.toLocaleLowerCase();return(e?f.filter(t=>t.username.toLocaleLowerCase().includes(e)||t.displayName.toLocaleLowerCase().includes(e)):f).slice(0,8)},[f,l]),g=!!(l&&h.length),_=(e,t)=>{let n=Rh(e,t);u(n),m(0),n&&!d.isFetching&&(d.isError||d.isStale)&&d.refetch()},y=e=>{if(!l)return;let r=`@${e.username} `,i=`${t.slice(0,l.start)}${r}${t.slice(l.end)}`,a=l.start+r.length;n(i),u(null),m(0),window.requestAnimationFrame(()=>{c.current?.focus(),c.current?.setSelectionRange(a,a)})},b=e=>{if(!e.nativeEvent.isComposing&&g){if(e.key===`ArrowDown`){e.preventDefault(),m(e=>(e+1)%h.length);return}if(e.key===`ArrowUp`){e.preventDefault(),m(e=>(e-1+h.length)%h.length);return}if(e.key===`Enter`&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){e.preventDefault(),y(h[p]??h[0]);return}if(e.key===`Escape`){u(null);return}}r?.(e)};return(0,Y.jsxs)(`span`,{className:`mention-textarea`,children:[(0,Y.jsx)(`textarea`,{...a,ref:c,value:t,onFocus:e=>{i?.(e),_(t,e.currentTarget.selectionStart??t.length)},onClick:e=>_(t,e.currentTarget.selectionStart??t.length),onChange:e=>{let t=e.currentTarget.value;n(t),_(t,e.currentTarget.selectionStart??t.length)},onKeyDown:b}),g&&(0,Y.jsx)(`span`,{className:`mention-menu`,role:`listbox`,"aria-label":s(`editor.mentionUsers`),children:h.map((e,t)=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===p,className:t===p?`active`:``,onMouseDown:e=>e.preventDefault(),onClick:()=>y(e),children:[(0,Y.jsx)(o,{"aria-hidden":!0,size:13}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.displayName}),(0,Y.jsxs)(`small`,{children:[`(`,e.username,`)`]})]})]},e.id))})]})}function Bh({projectId:e,value:t,onChange:n,onSubmit:r,onCancel:i,pending:a=!1,error:o=``,label:s,editing:c=!1,originalValue:l,disabled:u=!1,autoFocus:d=!0}){let{t:f}=v(),p=(0,J.useId)(),m=a||u,h=!!t.trim()&&(!c||l===void 0||t.trim()!==l.trim()),g=e=>{e?.preventDefault(),!m&&h&&r()};return(0,Y.jsxs)(`form`,{className:`comment-reply-form${c?` comment-edit-form`:``}`,"aria-busy":a,onSubmit:e=>void g(e),onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(zh,{projectId:e,autoFocus:d,rows:c?4:3,value:t,onChange:n,disabled:m,"aria-label":s,"aria-invalid":!!o,"aria-describedby":o?p:void 0,placeholder:c?void 0:f(`editor.replyPlaceholder`),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.stopPropagation(),g())}}),o&&(0,Y.jsx)(`p`,{id:p,className:`comment-form-error`,role:`alert`,children:o}),(0,Y.jsxs)(`div`,{className:`comment-form-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:m,onClick:i,children:f(`common.cancel`)}),c?(0,Y.jsx)(Be,{type:`submit`,saving:a,disabled:u||!h,iconSize:13,children:f(`common.save`)}):(0,Y.jsxs)(`button`,{className:`primary`,type:`submit`,disabled:m||!h,children:[a?(0,Y.jsx)(Le,{className:`spin`,"aria-hidden":!0,size:13}):(0,Y.jsx)(zt,{"aria-hidden":!0,size:13}),f(a?`editor.commentSending`:`editor.sendReply`)]})]})]})}var Vh=5e4,Hh=new Intl.Segmenter(void 0,{granularity:`word`}),Uh=55296,Wh=2048,Gh=63487;function Kh(e,t){if(e===t)return e?[[0,e]]:[];let n=[``],r=new Map,i=e=>{let t=[];for(let{segment:i}of Hh.segment(e)){let e=r.get(i);if(e===void 0){let t=n.length;if(t>Gh)return null;e=String.fromCharCode(t<Uh?t:t+Wh),n.push(i),r.set(i,e)}t.push(e)}return t.join(``)},a=i(e),o=i(t);return a===null||o===null?[[-1,e],[1,t]].filter(([,e])=>e!==``):ht(a,o,{checkLines:!1,timeout:1}).map(([e,t])=>[e,Array.from(t,e=>{let t=e.charCodeAt(0);return n[t<Uh?t:t-Wh]}).join(``)])}function qh({original:e,replacement:t}){let{t:n}=v(),[r,i]=(0,J.useState)(!1),a=(0,J.useMemo)(()=>Kh(e,t),[e,t]),o=!r&&a.some(([e,t])=>e===0&&t.length>192);return(0,Y.jsxs)(`div`,{className:`suggestion-diff-view`,children:[(0,Y.jsx)(`pre`,{className:`suggestion-diff`,"aria-label":n(`suggestions.diff`),children:a.map(([e,t],n)=>e<0?(0,Y.jsx)(`del`,{children:t},n):e>0?(0,Y.jsx)(`ins`,{children:t},n):(0,Y.jsx)(`span`,{children:r||t.length<=192?t:n===0?`…${t.slice(-96)}`:n===a.length-1?`${t.slice(0,96)}…`:`${t.slice(0,48)}…${t.slice(-48)}`},n))}),(o||r)&&(0,Y.jsx)(`button`,{type:`button`,className:`suggestion-text-action`,onClick:()=>i(!r),children:n(r?`suggestions.collapse`:`suggestions.showFull`)})]})}function Jh({projectId:e,authorId:t,commentId:n,value:r,onChange:i,disabled:a=!1}){let{t:o}=v(),[s,c]=(0,J.useState)([]),[l,u]=(0,J.useState)(``),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(0);return(0,J.useEffect)(()=>{let r=new AbortController;u(``),c([]),f(!1);let i=n?`?${new URLSearchParams({commentId:n})}`:``;return K(`/api/projects/${e}/suggestion-reviewers${i}`,{signal:r.signal}).then(e=>{r.signal.aborted||(c(e.users.filter(e=>e.id!==t)),f(!0))}).catch(e=>{r.signal.aborted||u(q(e))}),()=>r.abort()},[e,t,n,p]),(0,Y.jsxs)(`div`,{className:`suggestion-reviewer-picker`,children:[(0,Y.jsxs)(`label`,{className:`form-field`,children:[o(`suggestions.reviewer`),(0,Y.jsxs)(`select`,{value:r===t?``:r,disabled:a||s.length===0,onChange:e=>i(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,children:o(`suggestions.chooseReviewer`)}),s.map(e=>(0,Y.jsxs)(`option`,{value:e.id,children:[e.displayName,` (@`,e.username,`)`]},e.id))]})]}),d&&s.length===0&&(0,Y.jsx)(`p`,{className:`field-hint`,children:o(`suggestions.noReviewers`)}),l&&(0,Y.jsxs)(`p`,{className:`comment-form-error`,role:`alert`,children:[l,` `,(0,Y.jsx)(`button`,{type:`button`,disabled:a,onClick:()=>m(e=>e+1),children:o(`common.retry`)})]})]})}function Yh({projectId:e,authorId:t,commentId:n,original:r,value:i,onChange:a,disabled:o=!1,autoFocus:s=!1}){let{t:l}=v();return(0,Y.jsxs)(`section`,{className:`suggestion-editor`,"aria-label":l(`suggestions.title`),children:[(0,Y.jsxs)(`header`,{children:[(0,Y.jsxs)(`strong`,{children:[(0,Y.jsx)(c,{size:14}),l(`suggestions.title`)]}),(0,Y.jsx)(`button`,{type:`button`,disabled:o,"aria-label":l(`suggestions.removeAttachment`),onClick:()=>a(null),children:(0,Y.jsx)(B,{size:14})})]}),(0,Y.jsx)(Xh,{original:r,replacement:i.replacementText,onChange:e=>a({...i,replacementText:e}),disabled:o,autoFocus:s}),(0,Y.jsx)(Jh,{projectId:e,authorId:t,commentId:n,value:i.reviewerId,disabled:o,onChange:e=>a({...i,reviewerId:e})})]})}function Xh({original:e,replacement:t,onChange:n,disabled:r=!1,autoFocus:i=!1}){let{t:a}=v();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`label`,{className:`form-field`,children:[a(`suggestions.replacement`),(0,Y.jsx)(`textarea`,{autoFocus:i,rows:4,maxLength:Vh,spellCheck:!1,disabled:r,value:t,onChange:e=>n(e.target.value)})]}),t===``&&(0,Y.jsx)(`p`,{className:`field-hint`,children:a(`suggestions.deletionHint`)}),t!==e&&(0,Y.jsxs)(`details`,{className:`suggestion-preview`,children:[(0,Y.jsx)(`summary`,{children:a(`suggestions.preview`)}),(0,Y.jsx)(qh,{original:e,replacement:t})]})]})}function Zh(e,t){return!e.suggestion&&e.authorId===t&&!e.resolved&&!e.orphaned&&!!e.anchorSourceHash&&e.selectedText.length>0&&e.selectedText.length<=5e4}function Qh({projectId:e,ownerId:t,currentUserId:n,canEdit:r,comment:i,draftTarget:a,onCloseComposer:o}){let{t:s,i18n:c}=v(),l=Hf(e),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(()=>a?{replacementText:a.original,reviewerId:t===n?``:t}:null),[h,_]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(!1),[w,T]=(0,J.useState)(``),E=i.suggestion,D=async(e,t,n)=>{if(!C.current){C.current=!0,S(!0),T(``);try{let r=await l(`/${i.id}/suggestion${e}`,{method:t,body:JSON.stringify(n)});m(null),_(null),t===`PATCH`&&r.change.kind===`suggestion`&&b(r.change.suggestion.replacementText),t===`POST`&&e===``&&o?.()}catch(e){T(q(e))}finally{C.current=!1,S(!1)}}};if(!E)return!a||!p||i.authorId!==n||i.resolved?null:(0,Y.jsxs)(`div`,{className:`suggestion-new`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(Yh,{projectId:e,authorId:n,commentId:i.id,original:a.original,value:p,disabled:x,autoFocus:!0,onChange:e=>{m(e),e||o?.()}}),w&&(0,Y.jsx)(`p`,{className:`comment-form-error`,role:`alert`,children:w}),(0,Y.jsxs)(`button`,{type:`button`,className:`suggestion-submit`,disabled:x||!p.reviewerId||p.reviewerId===i.authorId||p.replacementText===a.original,onClick:()=>void D(``,`POST`,{...p,sourceHash:a.sourceHash}),children:[x&&(0,Y.jsx)(Le,{size:13,className:`spin`}),s(p.replacementText===``?`suggestions.submitDeletion`:`suggestions.submit`)]})]});let k=E.status===`pending`,A=E.reviewerDisplayName??E.reviewerUsername??s(`editor.deletedUser`),j=E.reviewerId!==null&&E.reviewerId===i.authorId,M=r&&!j&&E.reviewerId===n&&E.reviewerAvailable,ee=k&&!E.applying&&i.authorId===n,N=!!(h&&h.expectedReplacementText!==E.replacementText&&h.replacementText!==E.replacementText),P=k?M?s(`suggestions.awaitingYou`):(0,Y.jsx)(g,{i18nKey:`suggestions.awaiting`,values:{name:A},components:{reviewer:(0,Y.jsx)(`strong`,{className:`suggestion-reviewer-name`,"data-tooltip":E.reviewerUsername?`@${E.reviewerUsername}`:void 0,"data-texlite-tooltip-always":!0})}}):s(`suggestions.${E.status}`);return(0,Y.jsxs)(`section`,{className:`comment-suggestion ${E.status}`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`button`,{type:`button`,className:`suggestion-toggle`,"aria-expanded":d,onClick:()=>f(!d),children:[d?(0,Y.jsx)(U,{size:13}):(0,Y.jsx)(O,{size:13}),(0,Y.jsx)(`strong`,{children:s(`suggestions.title`)}),(0,Y.jsx)(`span`,{children:P})]}),d&&(0,Y.jsxs)(`div`,{className:`suggestion-details`,children:[ee&&h?(0,Y.jsxs)(`section`,{className:`suggestion-editor suggestion-revision-editor`,"aria-label":s(`suggestions.edit`),children:[(0,Y.jsx)(Xh,{original:E.originalText,replacement:h.replacementText,autoFocus:!0,disabled:x,onChange:e=>_({...h,replacementText:e})}),N&&(0,Y.jsx)(`p`,{className:`suggestion-warning`,role:`alert`,children:s(`suggestions.updatedWhileEditing`)}),(0,Y.jsxs)(`div`,{className:`suggestion-actions comment-form-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:x,onClick:()=>{_(null),T(``)},children:s(`common.cancel`)}),(0,Y.jsx)(Be,{saving:x,iconSize:13,disabled:N||h.replacementText===E.originalText||h.replacementText===h.expectedReplacementText,onClick:()=>void D(``,`PATCH`,h),children:s(`common.save`)})]})]}):(0,Y.jsx)(qh,{original:E.originalText,replacement:E.replacementText}),k&&!E.applicable&&!E.applying&&(0,Y.jsx)(`p`,{className:`suggestion-warning`,children:s(`suggestions.sourceChanged`)}),k&&(j||!E.reviewerAvailable)&&(0,Y.jsx)(`p`,{className:`suggestion-warning`,children:s(j?`errors.codes.SUGGESTION_SELF_REVIEW`:`suggestions.reviewerUnavailable`)}),E.applying&&(0,Y.jsx)(`p`,{className:`suggestion-warning`,children:s(`suggestions.saving`)}),!k&&(0,Y.jsxs)(`p`,{className:`suggestion-decision`,children:[(0,Y.jsx)(`span`,{children:(0,Y.jsx)(g,{i18nKey:`suggestions.decidedBy`,values:{name:E.decidedByDisplayName??E.decidedByUsername??s(`editor.deletedUser`)},components:{reviewer:(0,Y.jsx)(`strong`,{className:`suggestion-reviewer-name`,"data-tooltip":E.decidedByUsername?`@${E.decidedByUsername}`:void 0,"data-texlite-tooltip-always":!0})}})}),E.decidedAt&&(0,Y.jsx)(`time`,{dateTime:E.decidedAt,children:te(E.decidedAt,c.resolvedLanguage)})]}),w&&(0,Y.jsx)(`p`,{className:`comment-form-error`,role:`alert`,children:w}),k&&M&&(0,Y.jsxs)(`div`,{className:`suggestion-actions`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`primary`,disabled:x||!E.applicable&&!E.applying,onClick:()=>void D(`/review`,`POST`,{action:`accept`,expectedReplacementText:E.replacementText}),children:[x?(0,Y.jsx)(Le,{className:`spin`,size:13}):(0,Y.jsx)(H,{size:13}),s(`suggestions.accept`)]}),(0,Y.jsxs)(`button`,{type:`button`,disabled:x||E.applying,onClick:()=>void D(`/review`,`POST`,{action:`reject`,expectedReplacementText:E.replacementText}),children:[(0,Y.jsx)(B,{size:13}),s(`suggestions.reject`)]})]}),ee&&!h&&(0,Y.jsxs)(`div`,{className:`suggestion-revision-action`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`suggestion-text-action`,disabled:x,onClick:()=>{_({replacementText:E.replacementText,expectedReplacementText:E.replacementText}),b(null),T(``)},children:[(0,Y.jsx)(u,{size:12,"aria-hidden":!0}),s(`suggestions.edit`)]}),y===E.replacementText&&(0,Y.jsxs)(`span`,{className:`suggestion-edit-saved`,role:`status`,children:[(0,Y.jsx)(H,{size:12,"aria-hidden":!0}),s(`suggestions.saved`)]})]})]})]})}function $h(e,t={}){let n=e.slice(0,Math.max(0,e.length-2)),r=!!(t.activeDraft||t.targetReplyId&&e.some(e=>e.id===t.targetReplyId)||n.some(e=>t.unreadReplyMentionIds?.has(e.id)||t.highlightReplyParticipants&&t.selectedParticipantIds?.has(e.authorId))),i=r||(t.expansion??!!t.current),a=i?0:n.length;return{replies:a?e.slice(-2):e,hiddenCount:a,expanded:i,canToggle:n.length>0&&!r}}var eg=1100;function tg(e){let t=()=>{};if(!e||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return t;let n=e.closest(`.comments`)??e.parentElement,r=e.getBoundingClientRect(),i=e.closest(`.context-panel`)?.getBoundingClientRect(),a=Math.max(0,r.left,i?.left??0),o=Math.max(0,r.top,i?.top??0),s=Math.min(window.innerWidth,r.right,i?.right??window.innerWidth)-a,c=Math.min(180,Math.min(window.innerHeight,r.bottom,i?.bottom??window.innerHeight)-o);if(!n||s<=0||c<=0)return t;let l=!1;return()=>{if(l||!n.isConnected||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches)return;l=!0;let e=document.createElement(`div`);e.className=`comment-paper-shred`,e.setAttribute(`aria-hidden`,`true`),e.inert=!0,Object.assign(e.style,{left:`${a}px`,top:`${o}px`,width:`${s}px`,height:`${c}px`}),e.style.setProperty(`--shred-duration`,`${eg}ms`),e.style.setProperty(`--shred-height`,`${c}px`);let t=Math.min(12,Math.max(8,Math.round(s/22))),r=c<96?1:2;for(let n=0;n<t*r;n++){let i=document.createElement(`span`),a=n%t,o=Math.floor(n/t),s=a/(t-1)*2-1,l=n*37;i.style.left=`${a/t*100}%`,i.style.top=`${o/r*100}%`,i.style.width=`${100/t}%`,i.style.height=`${c/r}px`,i.style.setProperty(`--shred-x`,`${s*14+l%7-3}px`),i.style.setProperty(`--shred-y`,`${48+o*16+l%31}px`),i.style.setProperty(`--shred-angle`,`${s*12+l%13-6}deg`),i.style.setProperty(`--shred-flip`,`${(n%2?1:-1)*(18+l%23)}deg`),i.style.setProperty(`--shred-line-offset`,`${-o*c/r}px`),i.style.animationDuration=`${780+l%4*25}ms`,i.style.animationDelay=`${80+a*7+o*35+l%3*9}ms`,e.append(i)}let i=()=>{window.clearTimeout(d),u.disconnect(),window.removeEventListener(`resize`,i),e.remove()},u=new MutationObserver(()=>{n.isConnected||i()}),d=window.setTimeout(i,1300);e.addEventListener(`animationend`,t=>{t.target===e&&!t.pseudoElement&&i()}),window.addEventListener(`resize`,i),u.observe(document.body,{childList:!0,subtree:!0}),document.body.append(e)}}var ng=e=>`${e.displayName?.trim()||e.username} (@${e.username})`;function rg({users:e,value:t,onChange:n,disabled:r=!1}){let{t:i}=v(),a=(0,J.useId)(),[o,s]=(0,J.useState)(``),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(0),f=(0,J.useRef)(null),p=(0,J.useRef)(null),m=(0,J.useRef)(null),h=e.find(e=>e.id===t),g=h?``:o.trim().replace(/^@/,``).toLowerCase(),_=g?e.filter(e=>e.username.toLowerCase().includes(g)||(e.displayName??``).toLowerCase().includes(g)):e,y=Math.min(u,Math.max(0,_.length-1)),b=c&&!r;(0,J.useEffect)(()=>{b&&m.current?.querySelector(`[data-index="${y}"]`)?.scrollIntoView?.({block:`nearest`})},[y,b,o]);let x=e=>{let t=_[e];t&&!r&&(n(t.id),s(``),l(!1))},S=()=>{d(Math.max(0,_.findIndex(e=>e.id===t))),l(!0)},C=`${a}-user`;return(0,Y.jsxs)(`div`,{className:`share-user-picker`,children:[(0,Y.jsx)(`label`,{htmlFor:C,children:i(`common.user`)}),(0,Y.jsxs)(R,{open:b,onOpenChange:l,children:[(0,Y.jsx)(I,{asChild:!0,children:(0,Y.jsxs)(`div`,{className:`share-user-search`,ref:p,onClick:()=>{r||(f.current?.focus(),S())},children:[(0,Y.jsx)(`input`,{id:C,ref:f,role:`combobox`,value:h?ng(h):o,disabled:r,placeholder:i(`projectSettings.searchUsersPlaceholder`),autoComplete:`off`,spellCheck:!1,"aria-autocomplete":`list`,"aria-expanded":b,"aria-controls":b?`${a}-list`:void 0,"aria-activedescendant":b&&_[y]?`${a}-user-${_[y].id}`:void 0,onClick:e=>{h&&e.currentTarget.select()},onFocus:e=>{S(),h&&e.currentTarget.select()},onChange:e=>{s(e.target.value),n(``),d(0),l(!0)},onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),l(!0);let n=e.key===`ArrowDown`?1:-1;if(b)d(e=>_.length?(e+n+_.length)%_.length:0);else{let e=_.findIndex(e=>e.id===t);d(e>=0?e:n===1?0:Math.max(0,_.length-1))}}else e.key===`Enter`?(e.preventDefault(),b&&x(y)):e.key===`Escape`&&b&&(e.preventDefault(),e.stopPropagation(),l(!1))}}}),(0,Y.jsx)(U,{className:`share-user-chevron`,size:14,"aria-hidden":!0})]})}),(0,Y.jsx)(oe,{container:f.current?.closest(`[role="dialog"]`),children:(0,Y.jsxs)(N,{className:`share-user-popover`,"aria-label":i(`projectSettings.chooseUser`),align:`start`,side:`bottom`,sideOffset:5,collisionPadding:12,avoidCollisions:!1,collisionBoundary:f.current?.closest(`[role="dialog"]`)??void 0,onOpenAutoFocus:e=>e.preventDefault(),onCloseAutoFocus:e=>e.preventDefault(),onInteractOutside:e=>{p.current?.contains(e.target)&&e.preventDefault()},onEscapeKeyDown:e=>{e.preventDefault(),e.stopPropagation(),l(!1)},children:[(0,Y.jsx)(`div`,{id:`${a}-list`,ref:m,role:`listbox`,"aria-label":i(`projectSettings.chooseUser`),children:_.map((e,n)=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,tabIndex:-1,id:`${a}-user-${e.id}`,"data-index":n,"data-active":n===y||void 0,"aria-selected":e.id===t,onMouseDown:e=>e.preventDefault(),onMouseMove:()=>d(n),onClick:()=>x(n),children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.displayName?.trim()||e.username}),(0,Y.jsxs)(`small`,{children:[`@`,e.username]})]}),e.id===t&&(0,Y.jsx)(H,{size:14,"aria-hidden":!0})]},e.id))}),_.length===0&&(0,Y.jsx)(`p`,{className:`share-user-no-results`,role:`status`,children:i(e.length?`projectSettings.noMatchingUsers`:`projectSettings.noAvailableUsers`)})]})})]})]})}function ig({projectId:e,onBusyChange:t}){let{t:n,i18n:r}=v(),[i,a]=(0,J.useState)([]),[o,c]=(0,J.useState)(``),[l,u]=(0,J.useState)(`168`),[d,p]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),[g,_]=(0,J.useState)(``),[y,b]=(0,J.useState)(!0),[x,S]=(0,J.useState)(!1),[C,w]=(0,J.useState)(null),[T,E]=(0,J.useState)(Date.now),D=(0,J.useRef)(null),O=(0,J.useRef)(null),k=(0,J.useRef)(!1),A=(0,J.useRef)(!1),j=(0,J.useRef)(void 0),ee=(0,J.useRef)(t);ee.current=t,(0,J.useEffect)(()=>{let t=new AbortController;return O.current=t,b(!0),a([]),_(``),w(null),p(null),E(Date.now()),K(`/api/projects/${e}/view-links`,{signal:t.signal}).then(e=>{t.signal.aborted||a(e.links)}).catch(e=>{t.signal.aborted||_(q(e))}).finally(()=>{t.signal.aborted||b(!1)}),()=>{t.abort(),clearTimeout(j.current),ee.current(!1)}},[e]),(0,J.useEffect)(()=>{let e=i.flatMap(e=>e.expiresAt&&Date.parse(e.expiresAt)>T?[Date.parse(e.expiresAt)]:[]);if(!e.length)return;let t=setTimeout(()=>E(Date.now()),Math.min(Math.max(1,Math.min(...e)-Date.now()),2147483647));return()=>clearTimeout(t)},[i,T]);let N=i.some(e=>!e.expiresAt||Date.parse(e.expiresAt)>T),P=async e=>{let t=O.current;if(!(!t||t.signal.aborted||k.current||A.current)){k.current=!0,S(!0),ee.current(!0),_(``);try{await e(t.signal)}catch(e){t.signal.aborted||_(q(e))}finally{k.current=!1,t.signal.aborted||(S(!1),ee.current(!1))}}},F=()=>P(async t=>{if(!N)try{let n=await K(`/api/projects/${e}/view-links`,{method:`POST`,signal:t,body:JSON.stringify({label:o,expiresAt:l===`never`?null:new Date(Date.now()+Number(l)*36e5).toISOString()})});t.aborted||(a(e=>[n.link,...e]),c(``))}catch(n){if(n instanceof He&&n.code===`VIEW_LINK_EXISTS`){let n=await K(`/api/projects/${e}/view-links`,{signal:t});t.aborted||a(n.links)}throw n}}),I=()=>{if(!C)return;let t=C;P(async n=>{await K(`/api/projects/${e}/view-links/${t.id}`,{method:`DELETE`,signal:n}),n.aborted||a(e=>e.filter(e=>e.id!==t.id)),n.aborted||w(null)})},L=async e=>{let t=O.current;if(!(!t||t.signal.aborted||k.current||A.current)&&e.path){A.current=!0,h(e.id),p(null),_(``),clearTimeout(j.current);try{await lt(new URL(e.path,window.location.origin).href,()=>D.current),t.signal.aborted||(p(e.id),j.current=setTimeout(()=>p(null),2e3))}catch{t.signal.aborted||_(n(`viewLinks.copyFailed`))}finally{A.current=!1,t.signal.aborted||h(null)}}};return(0,Y.jsxs)(`div`,{className:`view-link-manager`,ref:D,"aria-busy":y||x,children:[(0,Y.jsxs)(`p`,{className:`view-link-description`,children:[(0,Y.jsx)(f,{size:17,"aria-hidden":!0}),n(`viewLinks.description`)]}),!y&&!N&&(0,Y.jsxs)(`div`,{className:`view-link-create`,children:[(0,Y.jsxs)(`label`,{className:`form-field`,children:[n(`viewLinks.label`),(0,Y.jsx)(`input`,{maxLength:80,value:o,disabled:x,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`label`,{className:`form-field`,children:[n(`viewLinks.expiry`),(0,Y.jsx)(`select`,{value:l,disabled:x,onChange:e=>u(e.target.value),children:[[`1`,`hour`],[`24`,`day`],[`168`,`week`],[`720`,`month`],[`never`,`never`]].map(([e,t])=>(0,Y.jsx)(`option`,{value:e,children:n(`viewLinks.${t}`)},e))})]}),(0,Y.jsxs)(`button`,{className:`primary icon-button`,disabled:x||y||m!==null,onClick:()=>void F(),children:[(0,Y.jsx)(Re,{size:15}),n(`viewLinks.create`)]})]}),g&&(0,Y.jsx)(`p`,{className:`error`,role:`alert`,children:g}),y?(0,Y.jsxs)(`div`,{className:`share-empty`,role:`status`,children:[(0,Y.jsx)(Le,{size:20,className:`spin`}),n(`common.loading`)]}):(0,Y.jsxs)(`div`,{className:`view-link-list`,children:[i.map(e=>{let t=e.expiresAt&&Date.parse(e.expiresAt)<=T?`expired`:`active`,i=e.path?new URL(e.path,window.location.origin).href:``;return(0,Y.jsxs)(`div`,{className:`view-link-item ${t}`,children:[(0,Y.jsxs)(`div`,{className:`view-link-heading`,children:[(0,Y.jsx)(kt,{size:16,"aria-hidden":!0}),(0,Y.jsxs)(`div`,{className:`view-link-identity`,children:[(0,Y.jsx)(`strong`,{children:e.label||n(`viewLinks.untitled`)}),(0,Y.jsx)(`small`,{children:e.expiresAt?n(`viewLinks.expires`,{time:te(e.expiresAt,r.resolvedLanguage)}):n(`viewLinks.never`)})]}),(0,Y.jsx)(`span`,{className:`view-link-status`,children:n(`viewLinks.${t}`)}),(0,Y.jsx)(`div`,{className:`view-link-actions`,children:(0,Y.jsx)(`button`,{className:`icon-only danger-text`,disabled:x||m!==null,"aria-label":n(`viewLinks.delete`),"data-tooltip":n(`viewLinks.delete`),onClick:()=>{_(``),w(e)},children:(0,Y.jsx)(M,{size:15})})})]}),(0,Y.jsxs)(`div`,{className:`view-link-address`,children:[(0,Y.jsx)(`input`,{readOnly:!0,spellCheck:!1,autoComplete:`off`,"aria-label":n(`viewLinks.address`,{name:e.label||n(`viewLinks.untitled`)}),value:i,placeholder:n(`viewLinks.addressUnavailable`),onFocus:e=>e.target.select()}),(0,Y.jsxs)(`button`,{type:`button`,className:`save-button view-link-copy`,disabled:x||m!==null||t!==`active`||!e.path,"aria-busy":m===e.id,onClick:()=>void L(e),children:[m===e.id?(0,Y.jsx)(Le,{className:`spin`,size:14}):d===e.id?(0,Y.jsx)(H,{className:`save-button-confirmation`,size:14}):(0,Y.jsx)(s,{size:14}),(0,Y.jsx)(`span`,{role:`status`,"aria-live":`polite`,children:n(d===e.id?`viewLinks.copied`:`viewLinks.copy`)})]})]})]},e.id)}),i.length===0&&(0,Y.jsxs)(`div`,{className:`share-empty`,children:[(0,Y.jsx)(kt,{size:24}),(0,Y.jsx)(`span`,{children:n(`viewLinks.empty`)})]})]}),(0,Y.jsx)(Ye,{open:!!C,title:n(`viewLinks.delete`),description:n(`viewLinks.deleteConfirm`),confirmLabel:n(`viewLinks.delete`),danger:!0,busy:x,error:g,onCancel:()=>{x||(w(null),_(``))},onConfirm:I})]})}function ag(e){let t=/(^|\s)(@[\p{L}\p{N}_.-]+)/gu,n=[],r=0;for(let i of e.matchAll(t)){let t=i.index??0,a=i[1],o=i[2],s=t+a.length;s>r&&n.push(e.slice(r,s)),n.push((0,Y.jsx)(`span`,{className:`comment-inline-mention`,children:o},`${s}:${o}`)),r=s+o.length}return n.length?(r<e.length&&n.push(e.slice(r)),n):e}function og({userId:e,avatarStyle:t,name:n,username:r,highlighted:i,children:a}){return(0,Y.jsxs)(`span`,{className:`comment-identity`,children:[(0,Y.jsx)(F,{userId:e,name:n,username:r,avatarStyle:t,className:`comment-avatar`}),(0,Y.jsxs)(`span`,{className:`comment-author-details`,children:[(0,Y.jsx)(`span`,{className:`comment-author${i?` participant-match`:``}`,children:(0,Y.jsx)(`strong`,{"data-tooltip":r?`@${r}`:void 0,"data-texlite-tooltip-always":!0,children:n})}),a]})]})}function sg({projectOwnerId:e=``,canEditSource:t=!1,unreadCommentMentionKind:n,projectId:r,comment:i,draftStore:a,currentUserId:s,unreadCommentMentionId:c,unreadReplyMentionIds:l,highlightedComment:u,highlightedReplyId:f,currentComment:m,showFilePath:h,onMarkMentionRead:_,onFocus:y,onActivate:b,onToggle:x,onReply:S,onEdit:C,onDelete:w,onEditReply:T,onDeleteReply:E,selectedParticipantIds:D,highlightReplyParticipants:k,replyExpansion:A,onReplyExpansionChange:j}){let{t:M,i18n:ee}=v(),N=d(),[P,F]=(0,J.useState)(!1),[I,L]=(0,J.useState)(null),ne=(0,J.useCallback)(e=>a.subscribe(i.id,e),[a,i.id]),R=(0,J.useCallback)(()=>a.getThread(i.id),[a,i.id]),re=(0,J.useSyncExternalStore)(ne,R,R),ie=re.reply,z=re[`edit-comment`],ae=(0,J.useId)(),oe=$h(i.replies,{expansion:A,current:m,targetReplyId:f,unreadReplyMentionIds:l,selectedParticipantIds:D,highlightReplyParticipants:k,activeDraft:!!(ie?.open||ie?.pending||i.authorId===s&&z?.open||i.replies.some(e=>e.authorId===s&&re[`edit-reply:${e.id}`]?.open))}),se=a.isPending(i.id),[B,ce]=(0,J.useState)(null),[V,U]=(0,J.useState)(!1),[de,fe]=(0,J.useState)(null),[pe,me]=(0,J.useState)(``),he=(0,J.useRef)(null),ge=(0,J.useRef)(!1),[_e,ve]=(0,J.useState)(!1),ye=async e=>{if(ge.current)return;ge.current=!0,ve(!0),me(``);let t=tg(e?he.current?.querySelector(`[data-comment-reply-id="${e}"]`)??null:he.current);try{if(!(e?await E(e):await w())){me(M(`editor.commentDeleteFailed`));return}e?fe(null):U(!1),t()}catch(e){me(q(e))}finally{ge.current=!1,ve(!1)}},be=(e,t=``)=>{b(),j(!0),ce(e),a.open(i.id,e,t)},xe=(e,t,n,o)=>{let s=re[e];return s?.open?(0,Y.jsx)(Bh,{projectId:r,editing:e!==`reply`,originalValue:o,label:t,value:s.content,pending:s.pending,error:s.error,disabled:se||P,autoFocus:B===e,onChange:t=>a.change(i.id,e,t),onSubmit:()=>a.submit(i.id,e,n,M(`editor.commentSubmitFailed`)),onCancel:()=>a.discard(i.id,e)},e):null},Se=i.authorUsername,Ce=e=>p(e,ee.resolvedLanguage??`en`,N,(e,t)=>M(e,t)),we=e=>te(e,ee.resolvedLanguage,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),Te=e=>(0,Y.jsx)(`time`,{dateTime:e,"data-tooltip":we(e),"data-texlite-tooltip-always":!0,children:Ce(e)}),Ee=(e,t)=>(0,Y.jsxs)(`span`,{className:`comment-times`,children:[Te(e),t&&(0,Y.jsx)(`small`,{"data-tooltip":M(`editor.editedAt`,{time:we(t)}),"data-texlite-tooltip-always":!0,children:M(`editor.commentEdited`)})]}),De=!i.resolved&&i.suggestion?.status===`pending`&&(i.suggestion.reviewerAvailable||i.suggestion.applying),Oe=async(e,t)=>{t.stopPropagation(),j(!0),await _(e)};return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`article`,{ref:he,"data-comment-id":i.id,className:`comment-thread${i.resolved?` resolved`:``}${i.orphaned?` orphaned`:``}${u?` mention-target`:``}${m?` review-current`:``}`,onFocusCapture:b,onClick:()=>{window.getSelection()?.toString()||y()},children:[(0,Y.jsxs)(`header`,{className:`comment-header`,children:[(0,Y.jsx)(og,{userId:i.authorId,avatarStyle:i.authorAvatarStyle,name:i.authorDisplayName??Se??M(`editor.deletedUser`),username:Se,highlighted:D?.has(i.authorId),children:Ee(i.createdAt,i.editedAt)}),(0,Y.jsxs)(`span`,{className:`comment-header-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`resolve`,disabled:P||se||De,"aria-busy":P,"aria-label":M(i.resolved?`editor.reopen`:`editor.resolve`),"data-tooltip":M(De?`suggestions.reviewBeforeResolve`:i.resolved?`editor.reopen`:`editor.resolve`),"data-texlite-tooltip-always":!0,onClick:e=>{e.stopPropagation(),!P&&(F(!0),x().finally(()=>F(!1)))},children:P?(0,Y.jsx)(Le,{className:`spin`,size:15,"aria-hidden":!0}):i.resolved?(0,Y.jsx)(Lt,{size:15,"aria-hidden":!0}):(0,Y.jsx)(H,{size:16,"aria-hidden":!0})}),i.authorId===s&&!z?.open&&(0,Y.jsx)(Lh,{kind:`comment`,disabled:se||P,onSuggest:e&&!I&&Zh(i,s)?()=>{b(),L({original:i.selectedText,sourceHash:i.anchorSourceHash})}:void 0,onEdit:()=>be(`edit-comment`,i.content),onDelete:()=>{me(``),U(!0)}})]})]}),(0,Y.jsx)(`div`,{className:`comment-location`,children:i.orphaned?M(`editor.orphaned`):h?M(`editor.commentLocation`,{path:i.filePath,line:i.startLine}):M(`editor.line`,{line:i.startLine})}),i.selectedText&&(0,Y.jsx)(`blockquote`,{className:`comment-selected-text`,children:i.selectedText}),z?.open&&i.authorId===s?xe(`edit-comment`,M(`editor.editComment`),C,i.content):(0,Y.jsx)(`p`,{className:`comment-content`,children:ag(i.content)}),e&&(i.suggestion||I)&&(0,Y.jsx)(Qh,{projectId:r,ownerId:e,currentUserId:s,canEdit:t,comment:i,draftTarget:I,onCloseComposer:()=>L(null)}),c&&(0,Y.jsxs)(`div`,{className:`comment-mention`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(o,{"aria-hidden":!0,size:12}),M(n===`review`?`suggestions.reviewRequested`:`editor.mentionedYou`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>void Oe(c,e),children:M(`editor.markMentionRead`)})]}),i.replies.length>0&&(0,Y.jsxs)(`div`,{className:`comment-replies`,children:[oe.canToggle&&(0,Y.jsxs)(`button`,{type:`button`,className:`comment-replies-toggle`,"aria-expanded":oe.expanded,"aria-controls":ae,onClick:e=>{e.stopPropagation(),j(!oe.expanded)},children:[oe.expanded?(0,Y.jsx)(le,{size:12,"aria-hidden":!0}):(0,Y.jsx)(O,{size:12,"aria-hidden":!0}),oe.expanded?M(`editor.hideEarlierReplies`):M(`editor.showEarlierReplies`,{count:oe.hiddenCount})]}),(0,Y.jsx)(`div`,{className:`comment-replies-list`,id:ae,children:oe.replies.map(e=>{let t=l?.get(e.id),n=`edit-reply:${e.id}`,r=re[n]?.open&&e.authorId===s;return(0,Y.jsxs)(`div`,{"data-comment-reply-id":e.id,className:`comment-reply${f===e.id?` mention-target`:``}`,children:[(0,Y.jsxs)(`header`,{children:[(0,Y.jsx)(og,{userId:e.authorId,avatarStyle:e.authorAvatarStyle,name:e.authorDisplayName??e.authorUsername??M(`editor.deletedUser`),username:e.authorUsername,highlighted:k&&D?.has(e.authorId),children:Ee(e.createdAt,e.editedAt)}),(0,Y.jsx)(`span`,{className:`comment-header-actions`,children:e.authorId===s&&!r&&(0,Y.jsx)(Lh,{kind:`reply`,disabled:se||P,onEdit:()=>be(n,e.content),onDelete:()=>{me(``),fe(e.id)}})})]}),r?xe(n,M(`editor.editReply`),t=>T(e.id,t),e.content):(0,Y.jsx)(`p`,{className:`comment-content`,children:ag(e.content)}),t&&(0,Y.jsxs)(`div`,{className:`comment-mention`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(o,{"aria-hidden":!0,size:12}),M(`editor.mentionedYou`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>void Oe(t,e),children:M(`editor.markMentionRead`)})]})]},e.id)})})]}),i.resolved&&i.resolvedAt&&(0,Y.jsxs)(`div`,{className:`comment-resolution`,children:[(0,Y.jsx)(ue,{size:12,"aria-hidden":!0}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(g,{i18nKey:`editor.resolvedBy`,values:{user:i.resolvedByDisplayName??i.resolvedByUsername??M(`editor.deletedUser`)},components:{user:(0,Y.jsx)(`strong`,{className:`comment-resolution-user`,"data-tooltip":i.resolvedByUsername?`@${i.resolvedByUsername}`:void 0,"data-texlite-tooltip-always":!0})}}),` · `,Te(i.resolvedAt)]})]}),!ie?.open&&(0,Y.jsx)(`button`,{type:`button`,className:`reply-action`,disabled:se||P,onClick:e=>{e.stopPropagation(),be(`reply`)},children:M(`editor.replyPrompt`)}),xe(`reply`,M(`editor.reply`),S)]}),(0,Y.jsx)(Ye,{open:V,title:M(`editor.deleteCommentTitle`),description:M(`editor.deleteCommentDescription`),confirmLabel:M(`common.delete`),danger:!0,busy:_e,error:pe,onCancel:()=>U(!1),onConfirm:()=>void ye(null)}),(0,Y.jsx)(Ye,{open:!!de,title:M(`editor.deleteReplyTitle`),description:M(`editor.deleteReplyDescription`),confirmLabel:M(`common.delete`),danger:!0,busy:_e,error:pe,onCancel:()=>fe(null),onConfirm:()=>{de&&ye(de)}})]})}function cg({open:e,onOpenChange:t,project:n,projectId:r,onMemberCountChange:i}){let{t:a}=v(),[o,s]=(0,J.useState)([]),[c,l]=(0,J.useState)([]),[u,d]=(0,J.useState)(`members`),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(`read`),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(``),[C,w]=(0,J.useState)(!1),[T,E]=(0,J.useState)(!1),D=(0,J.useRef)(null),O=(0,J.useRef)(null),k=(0,J.useRef)(null),A=n.permission===`owner`,ee=(0,J.useCallback)(async e=>{let[t,a]=await Promise.all([K(`/api/projects/${r}/members`,{signal:e}),A?K(`/api/users`,{signal:e}):Promise.resolve({users:[]})]);if(e.aborted)return;let o=t.members.filter(e=>e.id!==n.ownerId);s(o),i?.(r,o.length),l(a.users.filter(e=>e.id!==n.ownerId))},[r,n.ownerId,A,i]);(0,J.useEffect)(()=>{if(!e)return;let t=new AbortController;return D.current=t,h(``),_(`read`),b(null),S(``),d(`members`),l([]),s([]),E(!1),w(!0),ee(t.signal).catch(e=>{t.signal.aborted||S(q(e))}).finally(()=>{t.signal.aborted||w(!1)}),()=>{t.abort(),D.current===t&&(D.current=null)}},[e,ee]);let N=async e=>{let t=D.current;if(A&&t&&!t.signal.aborted&&O.current!==t){O.current=t,E(!0),S(``);try{await e(t.signal),t.signal.aborted||await ee(t.signal)}catch(e){t.signal.aborted||S(q(e))}finally{O.current===t&&(O.current=null),t.signal.aborted||E(!1)}}},P=c.filter(e=>!o.some(t=>t.id===e.id)),te=async()=>{P.some(e=>e.id===m)&&await N(async e=>{await K(`/api/projects/${r}/members/${m}`,{method:`PUT`,body:JSON.stringify({permission:g}),signal:e}),e.aborted||(h(``),_(`read`))})},I=async(e,t)=>{await N(n=>K(`/api/projects/${r}/members/${e.id}`,{method:`PUT`,body:JSON.stringify({permission:t}),signal:n}))},L=async()=>{y&&await N(async e=>{await K(`/api/projects/${r}/members/${y.id}`,{method:`DELETE`,signal:e}),e.aborted||b(null)})};return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Je,{open:e,wide:!0,className:`share-dialog-modal`,title:a(`projectSettings.share`),onOpenChange:e=>{!T&&!f&&t(e)},onEscapeKeyDown:e=>{k.current?.querySelector(`[role="combobox"][aria-expanded="true"]`)&&e.preventDefault()},footer:(0,Y.jsx)(`button`,{disabled:T||f,onClick:()=>t(!1),children:a(`common.close`)}),children:(0,Y.jsxs)(`div`,{className:`share-dialog`,ref:k,"aria-busy":C||T,children:[A&&(0,Y.jsxs)(`div`,{className:`share-scope-tabs`,role:`tablist`,"aria-label":a(`projectSettings.share`),children:[(0,Y.jsx)(`button`,{role:`tab`,"aria-selected":u===`members`,disabled:T||f,onClick:()=>d(`members`),children:a(`projectSettings.members`)}),(0,Y.jsx)(`button`,{role:`tab`,"aria-selected":u===`links`,disabled:T||f,onClick:()=>d(`links`),children:a(`viewLinks.tab`)})]}),u===`links`&&A?(0,Y.jsx)(ig,{projectId:r,onBusyChange:p},r):(0,Y.jsxs)(Y.Fragment,{children:[x&&!y&&(0,Y.jsx)(`p`,{className:`error`,role:`alert`,children:x}),(0,Y.jsxs)(`div`,{className:`share-owner`,children:[(0,Y.jsx)(j,{size:17}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`small`,{children:a(`projects.owner`)}),(0,Y.jsx)(`strong`,{children:n.ownerDisplayName??n.ownerUsername})]})]}),A&&(0,Y.jsxs)(`div`,{className:`share-add`,children:[(0,Y.jsx)(rg,{users:P,value:m,onChange:h,disabled:C||T},r),(0,Y.jsxs)(`label`,{className:`form-field`,children:[a(`common.permission`),(0,Y.jsxs)(`select`,{disabled:C||T,value:g,onChange:e=>_(e.target.value),children:[(0,Y.jsx)(`option`,{value:`read`,children:a(`common.readOnly`)}),(0,Y.jsx)(`option`,{value:`edit`,children:a(`common.readWrite`)})]})]}),(0,Y.jsxs)(`button`,{className:`primary icon-button`,disabled:C||T||!P.some(e=>e.id===m),onClick:()=>void te(),children:[T?(0,Y.jsx)(Le,{className:`spin`,size:15}):(0,Y.jsx)(Ve,{size:15}),a(`projectSettings.addMember`)]})]}),(0,Y.jsxs)(`div`,{className:`shared-members-heading`,children:[(0,Y.jsx)(`strong`,{children:a(`projectSettings.members`)}),(0,Y.jsx)(`span`,{children:o.length})]}),(0,Y.jsxs)(`div`,{className:`shared-members`,children:[o.map(e=>(0,Y.jsxs)(`div`,{className:`shared-member`,children:[(0,Y.jsxs)(`span`,{className:`member-identity`,children:[(0,Y.jsx)(F,{userId:e.id,name:e.displayName,username:e.username,avatarStyle:e.avatarStyle,className:`member-avatar`}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:e.displayName??e.username}),(0,Y.jsxs)(`small`,{children:[`@`,e.username]})]})]}),(0,Y.jsxs)(`span`,{className:`member-controls`,children:[(0,Y.jsxs)(`select`,{"aria-label":a(`common.permission`),disabled:!A||T,value:e.permission,onChange:t=>void I(e,t.target.value),children:[(0,Y.jsx)(`option`,{value:`read`,children:a(`common.readOnly`)}),(0,Y.jsx)(`option`,{value:`edit`,children:a(`common.readWrite`)})]}),A&&(0,Y.jsx)(`button`,{disabled:T,className:`icon-only danger-text`,title:a(`common.remove`),"aria-label":a(`common.remove`),onClick:()=>{S(``),b(e)},children:(0,Y.jsx)(M,{size:15})})]})]},e.id)),C?(0,Y.jsxs)(`div`,{className:`share-empty`,role:`status`,children:[(0,Y.jsx)(Le,{className:`spin`,size:20}),(0,Y.jsx)(`span`,{children:a(`common.loading`)})]}):o.length===0&&(0,Y.jsxs)(`div`,{className:`share-empty`,children:[(0,Y.jsx)(j,{size:24}),(0,Y.jsx)(`span`,{children:a(`projectSettings.noMembers`)})]})]})]})]})}),(0,Y.jsx)(Ye,{open:!!y,title:a(`projectSettings.removeTitle`),description:a(`projectSettings.removeDescription`,{username:y?.username??``}),confirmLabel:a(`common.remove`),danger:!0,busy:T,error:x,onCancel:()=>{T||(b(null),S(``))},onConfirm:()=>void L()})]})}function lg({open:e,projectId:t,ownerId:n,authorId:r,selection:i,text:a,onText:o,suggestion:s,onSuggestion:l,submitting:u,error:d,onSubmit:f,onClose:p,onCancel:m,draftRestored:h,canRetarget:g,onRetarget:_}){let{t:y}=v(),b=(0,J.useId)(),[x,S]=(0,J.useState)(!1),[C,w]=(0,J.useState)(!1),T=(0,J.useRef)(null);(0,J.useEffect)(()=>{e||(S(!1),w(!1),T.current=null)},[e]);let E=Uf(a,i.selectedText,s,r),D=!!(i.selectedText&&i.selectedText.length<=5e4),O=E.issue===`selfReview`?`errors.codes.SUGGESTION_SELF_REVIEW`:E.issue===`reviewer`?`commentComposer.chooseReviewer`:D?`commentComposer.empty`:`commentComposer.emptyComment`,k=!!(d||x&&E.issue),A=d||(E.issue?y(O):`${y(`commentComposer.${E.kind}`)}${E.edit?` · ${y(`commentComposer.reviewRequested`)}`:``}`),j=()=>{u||(S(!0),E.issue||f())};return(0,Y.jsxs)(Je,{open:e,draggable:!0,wide:!0,className:`comment-compose-modal`,title:y(`editor.addComment`),description:i.selectedText?y(`editor.commentDescription`,{count:i.endOffset-i.startOffset}):y(`editor.pointComment`),onOpenChange:e=>{!e&&!u&&p()},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`comment-compose-status${k?` has-error`:``}`,role:k?`alert`:`status`,"aria-live":`polite`,children:u?y(`editor.commentSending`):A}),(0,Y.jsxs)(`div`,{className:`comment-compose-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:u,onClick:m,children:y(`common.cancel`)}),(0,Y.jsxs)(`button`,{type:`button`,className:`primary`,"aria-busy":u,disabled:u,onClick:j,children:[u&&(0,Y.jsx)(Le,{className:`spin`,size:14}),y(u?`editor.commentSending`:`editor.addComment`)]})]})]}),children:[h&&(0,Y.jsxs)(`p`,{className:`comment-draft-restored`,children:[(0,Y.jsx)(`span`,{children:y(`editor.commentDraftRestored`)}),g&&(0,Y.jsx)(`button`,{type:`button`,disabled:u,onClick:_,children:y(`editor.commentDraftUseSelection`)})]}),i.selectedText&&(0,Y.jsxs)(`section`,{className:`comment-compose-original`,"aria-label":y(`commentComposer.original`),children:[(0,Y.jsx)(`span`,{children:y(`commentComposer.original`)}),(0,Y.jsx)(`blockquote`,{children:i.selectedText})]}),(0,Y.jsxs)(`label`,{className:`form-field comment-compose-note`,children:[y(`editor.commentContent`),(0,Y.jsx)(zh,{projectId:t,autoFocus:!0,rows:3,disabled:u,value:a,placeholder:y(`commentComposer.placeholder`),onChange:o,onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.stopPropagation(),j())}})]}),D&&(0,Y.jsxs)(`div`,{className:`comment-compose-edit`,children:[(0,Y.jsxs)(`label`,{className:`comment-compose-edit-toggle`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,role:`switch`,disabled:u,checked:!!s,"aria-controls":s?`${b}-edit`:void 0,onChange:e=>{e.target.checked?(w(!0),l(T.current??{replacementText:i.selectedText,reviewerId:n===r?``:n})):(T.current=s,w(!1),l(null))}}),(0,Y.jsx)(c,{size:16,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:y(`commentComposer.suggestEdit`)})]}),s&&(0,Y.jsx)(`div`,{className:`comment-compose-edit-fields`,id:`${b}-edit`,children:(0,Y.jsx)(Xh,{original:i.selectedText,replacement:s.replacementText,onChange:e=>l({...s,replacementText:e}),disabled:u,autoFocus:C})})]}),s&&(0,Y.jsx)(`div`,{className:`comment-compose-reviewer`,children:(0,Y.jsx)(Jh,{projectId:t,authorId:r,value:s.reviewerId,onChange:e=>l({...s,reviewerId:e}),disabled:u})})]})}var ug=(0,J.lazy)(()=>S(()=>import(`./CitationLibraryDialog-DgOIkLwK.js`).then(e=>({default:e.CitationLibraryDialog})),__vite__mapDeps([31,2,3,32,5,4,7,9,16,17,12,1,6,8,10,11,13,33,34,35,36,37,38,39,40,41,42,21,22,23,43,20,18,24,44,45]),import.meta.url)),dg=(0,J.lazy)(()=>S(()=>import(`./GitDialog-DGzZ3GRj.js`).then(e=>({default:e.GitDialog})),__vite__mapDeps([46,2,3,4,5,9,16,7,17,12,1,6,8,10,11,13,47,48,36,49,50,38]),import.meta.url)),fg=(0,J.lazy)(()=>S(()=>import(`./HistoryDialog-DTZxCgyT.js`).then(e=>({default:e.HistoryDialog})),__vite__mapDeps([51,2,3,4,5,9,16,7,17,12,1,6,8,10,11,13,40,52,53,33,37,41,42,54,49,50,38,39,44,55]),import.meta.url)),pg=(0,J.lazy)(()=>S(()=>import(`./SelectionHistoryDialog-Dnj22E8N.js`).then(e=>({default:e.SelectionHistoryDialog})),__vite__mapDeps([56,2,3,4,5,16,7,9,17,12,1,6,8,10,11,13,57,52,54,55]),import.meta.url)),mg=(0,J.lazy)(()=>S(()=>import(`./QuickOpenDialog-CHjPlBu2.js`).then(e=>({default:e.QuickOpenDialog})),__vite__mapDeps([58,2,3,4,5,33,9,53,7,16,17,12,1,6,8,10,11,13,40,37,41,42]),import.meta.url)),hg=(0,J.lazy)(()=>S(()=>import(`./ProjectSearchDialog-DPIzxVYj.js`).then(e=>({default:e.ProjectSearchDialog})),__vite__mapDeps([59,2,3,4,5,6,9,16,7,17,12,1,8,10,11,13,33,53,40,37,41,42]),import.meta.url));function gg({projectSearchOpen:e,setProjectSearchOpen:t,onSearchNavigate:n,commentSuggestion:r,setCommentSuggestion:i,user:a,project:o,projectId:s,activeFile:c,content:l,maxCitationBibtexBytes:u,files:d,directoryEntries:f,readOnly:p,resourcePreview:m,resourcePreviewLoading:h,setResourcePreview:_,setResourcePreviewLoading:y,uploadConflict:b,setUploadConflict:x,dismissUploadFeedback:S,uploadFiles:C,cleanMode:w,setCleanMode:E,cleanCompile:D,newFileOpen:O,setNewFileOpen:k,newFilePath:j,setNewFilePath:ee,newFolderOpen:N,setNewFolderOpen:P,newFolderName:te,setNewFolderName:F,selectedFolder:I,fileDialogError:L,setFileDialogError:ne,createFile:R,createFolder:re,moveEntry:ie,setMoveEntry:z,moveName:oe,setMoveName:B,moveDestination:ce,setMoveDestination:V,movePath:H,deleteEntry:U,setDeleteEntry:le,deleteActiveSessions:ue,removePath:de,commentOpen:pe,closeComment:me,commentSelection:he,commentText:ge,setCommentText:_e,commentSubmitting:ve,commentError:ye,addComment:be,cancelComment:xe,commentDraftRestored:Se,commentDraftCanRetarget:Ce,useCurrentCommentSelection:we,shareOpen:Te,setShareOpen:Ee,onSharedMemberCountChange:De,citationLibraryOpen:Oe,setCitationLibraryOpen:ke,insertCitationAtCursor:Ae,quickOpen:je,setQuickOpen:Me,openFile:Ne,selectionHistoryTarget:Pe,closeSelectionHistory:Fe,historyOpen:Ie,setHistoryOpen:Re,gitOpen:Be,setGitOpen:Ve,save:He,permissionDowngrade:W,permissionDowngradeBusy:Ue,dismissPermissionDowngrade:We,discardPermissionDraft:Ge}){let{t:G}=v();return(0,Y.jsxs)(Y.Fragment,{children:[W&&(0,Y.jsx)(Je,{open:!0,title:G(`editor.collaboration.permissionDowngradeTitle`),description:W.localDraftReady&&W.otherTabDraft?G(`editor.collaboration.permissionDowngradeMultipleDrafts`):W.otherTabDraft?G(`editor.collaboration.permissionDowngradeOtherTab`):W.localDraftReady?G(`editor.collaboration.permissionDowngradeDescription`,{previous:G(`common.readWrite`)}):G(`editor.collaboration.permissionDowngradeNoDraft`),onOpenChange:e=>{!e&&!Ue&&We()},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,disabled:Ue,onClick:We,children:W.localDraftReady?G(`editor.collaboration.permissionDowngradeKeep`):G(`common.close`)}),!W.otherTabDraft&&(0,Y.jsxs)(`button`,{type:`button`,className:`danger`,disabled:Ue,onClick:()=>void Ge(),children:[Ue?(0,Y.jsx)(Le,{className:`spin`,size:14}):W.localDraftReady?(0,Y.jsx)(M,{size:14}):(0,Y.jsx)(ze,{size:14}),W.localDraftReady?G(`editor.collaboration.permissionDowngradeDiscard`):G(`editor.collaboration.permissionDowngradeReload`)]})]}),children:(0,Y.jsx)(`div`,{})}),(0,Y.jsxs)(Je,{open:!!m,extraWide:m?.kind===`image`||m?.kind===`pdf`||m?.kind===`text`,title:m?.path??``,description:m?.kind===`large`?G(`editor.resourceTooLarge`,{size:ae(m.size,{maximumUnit:`MB`}),limit:ae(m.limitBytes??10485760,{maximumUnit:`MB`})}):G(`editor.resourcePreview.${m?.kind??`text`}`),onOpenChange:e=>{e||(_(null),y(!1))},footer:m&&(0,Y.jsxs)(`a`,{className:`primary resource-download`,href:`${m.url}&download=1`,download:!0,children:[(0,Y.jsx)(T,{size:14}),G(`editor.downloadResource`)]}),children:[m?.kind===`large`&&(0,Y.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,Y.jsx)(A,{size:34}),(0,Y.jsx)(`strong`,{children:G(`editor.resourceTooLargeTitle`)}),(0,Y.jsx)(`span`,{children:G(`editor.resourceTooLargeDescription`)})]}),m?.kind===`unsupported`&&(0,Y.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,Y.jsx)(fe,{size:34}),(0,Y.jsx)(`strong`,{children:G(`editor.resourceUnsupportedTitle`)}),(0,Y.jsx)(`span`,{children:G(`editor.resourceUnsupportedDescription`)})]}),m?.kind===`image`&&(0,Y.jsx)(`div`,{className:`resource-image-wrap`,children:(0,Y.jsx)(`img`,{className:`resource-image`,src:m.url,alt:m.path})}),m?.kind===`pdf`&&(0,Y.jsx)(`iframe`,{className:`resource-pdf`,src:m.url,title:m.path}),m?.kind===`text`&&(h?(0,Y.jsxs)(`div`,{className:`resource-preview-message`,children:[(0,Y.jsx)(Le,{className:`spin`,size:24}),(0,Y.jsx)(`span`,{children:G(`common.loading`)})]}):(0,Y.jsx)(`pre`,{className:`resource-text`,children:m.content}))]}),(0,Y.jsx)(Ye,{open:!!b,title:G(`editor.uploadOverwriteTitle`),description:G(`editor.uploadOverwriteDescription`,{count:b?.collisions.length??0,files:b?.collisions.join(`, `)??``}),confirmLabel:G(`editor.uploadOverwrite`),danger:!0,onCancel:()=>{x(null),S()},onConfirm:()=>{let e=b;x(null),e&&C(e.files,new Set(e.collisions),e.directory)}}),(0,Y.jsx)(Ye,{open:!!w,title:G(w===`cache`?`editor.cleanCacheConfirmTitle`:`editor.cleanArtifactsConfirmTitle`),description:G(w===`cache`?`editor.cleanCacheConfirmDescription`:`editor.cleanArtifactsConfirmDescription`),confirmLabel:G(`editor.cleanConfirm`),danger:w===`artifacts`,onCancel:()=>E(null),onConfirm:()=>{let e=w;E(null),e&&D(e)}}),(0,Y.jsx)(Je,{open:O,title:G(`editor.newFile`),description:G(`editor.newFileDescription`),onOpenChange:e=>{k(e),e||ne(``)},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>k(!1),children:G(`common.cancel`)}),(0,Y.jsx)(`button`,{className:`primary`,onClick:()=>void R(),children:G(`common.create`)})]}),children:(0,Y.jsxs)(Y.Fragment,{children:[L&&(0,Y.jsx)(`p`,{className:`error dialog-error`,children:L}),(0,Y.jsxs)(`label`,{className:`form-field`,children:[G(`editor.filePath`),(0,Y.jsx)(`input`,{autoFocus:!0,value:j,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),R())}})]})]})}),(0,Y.jsx)(Je,{open:N,title:G(`editor.newFolder`),description:(0,Y.jsx)(g,{i18nKey:`editor.folderDestination`,values:{folder:I||G(`editor.projectRoot`)},components:{path:(0,Y.jsx)(`strong`,{className:`folder-destination-path`})}}),onOpenChange:e=>{P(e),e||ne(``)},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>P(!1),children:G(`common.cancel`)}),(0,Y.jsx)(`button`,{className:`primary`,onClick:()=>void re(),children:G(`common.create`)})]}),children:(0,Y.jsxs)(Y.Fragment,{children:[L&&(0,Y.jsx)(`p`,{className:`error dialog-error`,children:L}),(0,Y.jsxs)(`label`,{className:`form-field`,children:[G(`editor.folderName`),(0,Y.jsx)(`input`,{autoFocus:!0,value:te,onChange:e=>F(e.target.value),onKeyDown:e=>{e.key===`Enter`&&re()}})]})]})}),(0,Y.jsx)(Je,{open:!!ie,title:G(`editor.moveTitle`,{name:ie?.path.split(`/`).at(-1)??``}),description:G(`editor.moveDescription`),onOpenChange:e=>{e||(z(null),B(``),ne(``))},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>z(null),children:G(`common.cancel`)}),(0,Y.jsx)(`button`,{className:`primary`,disabled:!oe.trim(),onClick:()=>void H(),children:G(`editor.moveApply`)})]}),children:(0,Y.jsxs)(Y.Fragment,{children:[L&&(0,Y.jsx)(`p`,{className:`error dialog-error`,children:L}),(0,Y.jsxs)(`label`,{className:`form-field`,children:[G(`editor.pathName`),(0,Y.jsx)(`input`,{autoFocus:!0,value:oe,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H()}})]}),(0,Y.jsxs)(`label`,{className:`form-field`,children:[G(`editor.destinationFolder`),(0,Y.jsxs)(`select`,{value:ce,onChange:e=>V(e.target.value),children:[(0,Y.jsx)(`option`,{value:``,children:G(`editor.projectRoot`)}),f.filter(e=>ie?.type!==`directory`||e.path!==ie.path&&!e.path.startsWith(`${ie.path}/`)).map(e=>(0,Y.jsx)(`option`,{value:e.path,children:e.path},e.path))]})]})]})}),(0,Y.jsx)(Je,{open:!!U,title:G(`editor.deletePathTitle`,{name:U?.path.split(`/`).at(-1)??``}),description:ue.length?G(`editor.deletePathActiveDescription`,{count:ue.length,path:U?.path??``,users:[...new Set(ue.map(e=>e.name))].join(`, `)}):G(`editor.deletePathDescription`,{path:U?.path??``}),onOpenChange:e=>{e||(le(null),ne(``))},footer:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>le(null),children:G(`common.cancel`)}),(0,Y.jsx)(`button`,{className:`danger`,onClick:()=>void de(),children:G(`common.delete`)})]}),children:(0,Y.jsxs)(Y.Fragment,{children:[L&&(0,Y.jsx)(`p`,{className:`error dialog-error`,children:L}),ue.length>0&&(0,Y.jsxs)(`p`,{className:`warning`,children:[(0,Y.jsx)(se,{size:15}),G(`editor.deletePathWillClose`)]})]})}),(0,Y.jsx)(lg,{open:pe,projectId:s,ownerId:o.ownerId,authorId:a.id,selection:he,text:ge,onText:_e,suggestion:r,onSuggestion:i,submitting:ve,error:ye,onSubmit:be,onClose:me,onCancel:xe,draftRestored:Se,canRetarget:Ce,onRetarget:we}),(0,Y.jsx)(cg,{open:Te,onOpenChange:Ee,project:o,projectId:s,onMemberCountChange:De}),Oe&&(0,Y.jsx)(qe,{title:G(`citationLibrary.title`),onClose:()=>ke(!1),children:(0,Y.jsx)(ug,{open:!0,onOpenChange:ke,currentFile:c,currentSource:l,readOnly:p,currentUserId:a.id,maxBibtexBytes:u,onInsert:Ae})}),je&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(mg,{open:!0,files:d,onOpenChange:Me,onOpenFile:e=>{let t=d.find(t=>t.path===e);t&&Ne(t)}})}),e&&(0,Y.jsx)(qe,{title:G(`projectSearch.title`),onClose:()=>t(!1),children:(0,Y.jsx)(hg,{projectId:s,readOnly:p,onClose:()=>t(!1),onNavigate:n})}),Pe&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(pg,{open:!0,onOpenChange:e=>{e||Fe()},project:o,filePath:Pe.filePath,selection:Pe.selection,currentSource:Pe.source})}),Ie&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(fg,{open:!0,onOpenChange:Re,project:o,onBeforeMutation:o.permission===`read`?async()=>!0:He})}),o.ownerId===a.id&&Be&&(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(dg,{open:!0,onOpenChange:Ve,project:o,onBeforeMutation:He})})]})}function _g({participants:e,selectedIds:t,topLevelOnly:n,onToggle:r,onClear:i,onTopLevelOnlyChange:a}){let{t:o}=v(),[s,c]=(0,J.useState)(!1),l=(0,J.useRef)(null),u=t.size>0,d=e.find(e=>t.has(e.authorId)),f=e=>e.authorDisplayName??e.authorUsername??o(`editor.deletedUser`),p=u?d?t.size===1?f(d):o(`editor.commentParticipantsSelected`,{name:f(d),count:t.size-1}):o(`editor.commentParticipantsCount`,{count:t.size}):o(`editor.commentParticipantsAll`);return(0,Y.jsx)(`div`,{className:`comment-participant-filter`,children:(0,Y.jsxs)(`div`,{className:`comment-participants-trigger-group${u?` active`:``}`,children:[(0,Y.jsxs)(R,{open:s,onOpenChange:c,children:[(0,Y.jsx)(P,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,className:`comment-participants-toggle`,"aria-label":`${o(`editor.commentParticipants`)}: ${p}`,children:[(0,Y.jsx)(j,{size:13,"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`comment-participants-summary`,children:u&&d?f(d):p}),u&&d&&t.size>1&&(0,Y.jsxs)(`span`,{className:`comment-participants-extra-count`,children:[`+`,t.size-1]}),(0,Y.jsx)(U,{size:12,"aria-hidden":!0,className:s?`expanded`:``})]})}),(0,Y.jsx)(oe,{children:(0,Y.jsxs)(N,{ref:l,className:`comment-participants-popover`,side:`bottom`,align:`end`,sideOffset:6,collisionPadding:10,"aria-label":o(`editor.commentParticipants`),onOpenAutoFocus:e=>{e.preventDefault();let t=l.current?.querySelector(`input[type="checkbox"]:not(:disabled)`);t?t.focus():l.current?.focus()},children:[(0,Y.jsxs)(`div`,{className:`comment-participants-heading`,children:[(0,Y.jsx)(ce,{children:o(`editor.commentParticipants`)}),u&&(0,Y.jsx)(`button`,{type:`button`,onClick:i,children:o(`editor.commentParticipantsClear`)})]}),(0,Y.jsxs)(`div`,{className:`comment-participants-list`,children:[e.map(e=>{let n=f(e),i=t.has(e.authorId);return(0,Y.jsxs)(`label`,{className:`comment-participant-option${i?` selected`:``}`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>r(e.authorId)}),(0,Y.jsx)(F,{userId:e.authorId,name:n,username:e.authorUsername,avatarStyle:e.authorAvatarStyle,className:`comment-participant-avatar`}),(0,Y.jsxs)(`span`,{className:`comment-participant-identity`,children:[(0,Y.jsx)(`strong`,{children:n}),e.authorUsername&&(0,Y.jsxs)(`small`,{children:[`@`,e.authorUsername]})]})]},e.authorId??`deleted`)}),e.length===0&&(0,Y.jsx)(`p`,{className:`comment-participants-empty`,children:o(`editor.commentNoParticipants`)})]}),(0,Y.jsxs)(`label`,{className:`comment-participants-root-only`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:n,disabled:!u,onChange:e=>a(e.target.checked)}),o(`editor.commentTopLevelOnly`)]})]})})]}),u&&(0,Y.jsx)(`button`,{type:`button`,className:`comment-participants-clear`,"aria-label":o(`editor.commentParticipantsClear`),onClick:i,children:(0,Y.jsx)(B,{size:12,"aria-hidden":!0})})]})})}function vg(e,t,n,r,i){let a=t.map(e=>({comment:e,exitAt:null})),o=new Set(t.map(e=>e.id)),s=new Map(n.map(e=>[e.id,e]));return e.forEach((e,t)=>{let n=s.get(e.comment.id);o.has(e.comment.id)||!n||Yf(n,r)||a.splice(Math.min(t,a.length),0,{comment:n,exitAt:e.exitAt??i+280+50})}),a}function yg(e,t,n,r){let[i,a]=(0,J.useState)(()=>({contextKey:r,visible:e,comments:t,entries:e.map(e=>({comment:e,exitAt:null}))}));(i.contextKey!==r||i.visible!==e||i.comments!==t)&&a({contextKey:r,visible:e,comments:t,entries:i.contextKey===r?vg(i.entries,e,t,n,Date.now()):e.map(e=>({comment:e,exitAt:null}))});let o=(0,J.useCallback)(e=>{a(t=>({...t,entries:t.entries.filter(t=>t.comment.id!==e||t.exitAt===null)}))},[]);return(0,J.useEffect)(()=>{let e=i.entries.flatMap(e=>e.exitAt===null?[]:[e.exitAt]);if(!e.length)return;let t=window.setTimeout(()=>{let e=Date.now();a(t=>({...t,entries:t.entries.filter(t=>t.exitAt===null||t.exitAt>e)}))},Math.max(0,Math.min(...e)-Date.now()));return()=>window.clearTimeout(t)},[i.entries]),{entries:i.entries,finishExit:o}}function bg(e,t,n,r){let[i,a]=(0,J.useState)(()=>({contextKey:n,limit:50})),o=i.contextKey===n?i.limit:50;if(t)for(let t of r){if(!t)continue;let n=e.findIndex(e=>e.id===t)+1;o=Math.max(o,Math.ceil(n/50)*50)}(i.contextKey!==n||i.limit!==o)&&a({contextKey:n,limit:o});let s=(0,J.useMemo)(()=>t?e.slice(0,o):e,[e,t,o]),c=(0,J.useCallback)(()=>{a(e=>({contextKey:n,limit:(e.contextKey===n?e.limit:50)+50}))},[n]);return{shown:s,hasMore:s.length<e.length,loadMore:c}}var xg=(0,J.lazy)(()=>S(()=>import(`./ProjectSettings-ChXx_cmP.js`).then(e=>({default:e.ProjectSettings})),__vite__mapDeps([60,2,3,32,5,4,7,9,16,17,12,1,6,8,10,11,13,40,53,33,37,41,42,61,62,39,63,64,44]),import.meta.url));function Sg({phone:e=!1,commentsHost:t,sidePanel:n,onClose:r,project:i,projectId:s,site:c,files:l,currentUserId:u,comments:d,commentDraftStore:f,commentsLoading:p,commentsError:m,onRetryComments:h,unreadMentions:g,activeFile:_,singleCommentId:y,onShowAllComments:b,hasProjectCommentsScope:x,commentScope:S,onCommentScopeChange:C,focusedCommentId:T,commentFocusNonce:E,onMarkMentionRead:D,onMarkAllMentionsRead:k,onClearFocusComment:A,targetCommentId:j,targetReplyId:M,onFocusComment:ee,onToggleComment:N,onReplyComment:P,onEditComment:te,onDeleteComment:F,onEditCommentReply:I,onDeleteCommentReply:L,dictionaryWords:ne,onDictionaryChange:R,editorPreferences:re,onEditorPreferences:ie,spellCheckCount:z,spellCheckUniqueCount:ae,spellCheckIndex:oe,onSpellCheckNavigate:se,onProject:ce}){let{t:V}=v(),H=!!y,[U,le]=(0,J.useState)(`unresolved`),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)(`source`),me=V(fe===`time`?`editor.commentSortTime`:S===`project`?`editor.commentSortSourceProject`:`editor.commentSortSource`),[he,ge]=(0,J.useState)(()=>new Set),[_e,ve]=(0,J.useState)(!0),[ye,xe]=(0,J.useState)(()=>new Map),[Se,Ce]=(0,J.useState)(null),we=(0,J.useRef)(new Map(d.map(e=>[e.id,e.resolved]))),Te=(0,J.useMemo)(()=>Gf(d),[d]),Oe=(0,J.useMemo)(()=>{let e=d.filter(e=>Jf(e,{activeFile:_,scope:S})),t=e.filter(e=>e.resolved).length;return{unresolved:e.length-t,resolved:t}},[_,S,d]),ke=(0,J.useMemo)(()=>Zf(d,{activeFile:_,scope:S,unreadMentions:g,participantIds:he,topLevelOnly:_e,filter:U,unreadMentionsOnly:!0}).length,[_,S,d,g,he,_e,U]),Ae=(0,J.useMemo)(()=>y?$f(d,y,_):Qf(d,{activeFile:_,scope:S,filter:U,unreadMentions:g,sort:fe,participantIds:he,topLevelOnly:_e,unreadMentionsOnly:ue},[j,T]),[_,y,U,S,d,T,j,g,fe,he,_e,ue]),je=T&&Ae.some(e=>e.id===T)?T:j&&Ae.some(e=>e.id===j)?j:null,Me=H?Ae[0]?.id??null:Se&&Ae.some(e=>e.id===Se)?Se:je;(0,J.useEffect)(()=>{Ce(null)},[T,E,j,M,_,S]),(0,J.useEffect)(()=>{Se&&!Ae.some(e=>e.id===Se)&&Ce(null)},[Se,Ae]);let Ne=rp(Ae,Me),Pe=JSON.stringify([n,y,S,S===`file`?_:``,U,fe,[...he].sort(),_e,ue]),Fe=JSON.stringify([s,S,S===`file`?_:``,U,fe,[...he].sort(),_e,ue]),{shown:Ie,hasMore:Le,loadMore:Re}=bg(Ae,!H&&U===`resolved`,Fe,[j,T,Se]),{entries:ze,finishExit:Be}=yg(Ie,d,H?`unresolved`:U,Pe);(0,J.useEffect)(()=>{let e=d.some(e=>(e.id===T||e.id===j)&&we.current.has(e.id)&&we.current.get(e.id)!==e.resolved);we.current=new Map(d.map(e=>[e.id,e.resolved])),e&&A()},[d,T,j,A]),(0,J.useEffect)(()=>{if(n!==`comments`||Se)return;let e=j&&M?`.comments [data-comment-reply-id="${M}"]`:j?`.comments .comment-thread[data-comment-id="${j}"]`:je?`.comments .comment-thread[data-comment-id="${je}"]`:``;if(!e)return;let t=document.querySelector(e);if(!t)return;let r=window.requestAnimationFrame(()=>t.scrollIntoView({block:j?`center`:`nearest`,behavior:`smooth`}));return()=>window.cancelAnimationFrame(r)},[n,Se,je,E,j,M,Ae]);let Ve=e=>{Ce(null),ee(e)},He=e=>{let t=ip(Ae,Me,e);t?Ve(t):A()},W=async e=>{let t=await D(e);if(!t||H||!ue)return t;let n=g.find(t=>t.id===e)?.commentId;return n&&(g.some(t=>t.id!==e&&t.commentId===n)||(T===n||j===n)&&A()),t},Ue=async()=>{await k()&&ue&&A()},We=e=>{e!==S&&(Ce(null),A(),C(e))},Ge=e=>{e!==U&&(Ce(null),A(),le(e))},G=()=>{Ce(null),A()},Ke=e=>{G(),he.size===1&&he.has(e)&&ve(!0),ge(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};if(!n)return null;let qe=(0,Y.jsxs)(`aside`,{className:`context-panel`,"aria-label":V(n===`comments`?`editor.sourceComments`:`editor.projectSettings`),children:[n===`comments`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`drawer-title`,children:[(0,Y.jsx)(`strong`,{children:V(H?`editor.currentComment`:`editor.sourceComments`)}),(0,Y.jsxs)(`span`,{className:`drawer-title-actions`,children:[!H&&g.length>0&&(0,Y.jsxs)(`button`,{className:`drawer-mention-read-all`,type:`button`,onClick:()=>void Ue(),title:V(`editor.markAllMentionsRead`),children:[(0,Y.jsx)(o,{"aria-hidden":!0,size:13}),(0,Y.jsx)(`span`,{children:V(`editor.markAllMentionsRead`)})]}),(0,Y.jsx)(`button`,{"aria-label":V(`common.close`),onClick:r,children:(0,Y.jsx)(B,{size:17})})]})]}),H?(0,Y.jsx)(`div`,{className:`comment-current-controls`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:b,children:[(0,Y.jsx)(Nt,{size:14,"aria-hidden":!0}),V(`editor.viewAllComments`)]})}):(0,Y.jsxs)(`div`,{className:`comment-review-controls`,children:[(0,Y.jsxs)(`div`,{className:`comment-review-queue-row`,children:[x&&(0,Y.jsxs)(`div`,{className:`comment-review-group`,role:`group`,"aria-label":V(`editor.commentScope`),children:[(0,Y.jsx)(`button`,{type:`button`,className:S===`file`?`active`:``,"aria-pressed":S===`file`,onClick:()=>We(`file`),children:V(`editor.commentScopeFile`)}),(0,Y.jsx)(`button`,{type:`button`,className:S===`project`?`active`:``,"aria-pressed":S===`project`,onClick:()=>We(`project`),children:V(`editor.commentScopeProject`)})]}),(0,Y.jsxs)(`div`,{className:`comment-review-group`,role:`group`,"aria-label":V(`editor.commentFilter`),children:[(0,Y.jsx)(`button`,{type:`button`,className:U===`unresolved`?`active`:``,"aria-pressed":U===`unresolved`,onClick:()=>Ge(`unresolved`),children:V(`editor.commentFilterUnresolved`,{count:Oe.unresolved})}),(0,Y.jsx)(`button`,{type:`button`,className:U===`resolved`?`active`:``,"aria-pressed":U===`resolved`,onClick:()=>Ge(`resolved`),children:V(`editor.commentFilterResolved`,{count:Oe.resolved})})]}),(0,Y.jsxs)(`div`,{className:`comment-review-navigation`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:Ne<=1,"aria-label":V(`editor.commentPrevious`),title:V(`editor.commentPrevious`),onClick:()=>He(-1),children:(0,Y.jsx)(a,{size:14})}),(0,Y.jsx)(`output`,{"aria-live":`polite`,children:V(`editor.commentPosition`,{current:Ne,total:Ae.length})}),(0,Y.jsx)(`button`,{type:`button`,disabled:Ae.length===0||Ne>0&&Ne>=Ae.length,"aria-label":V(`editor.commentNext`),title:V(`editor.commentNext`),onClick:()=>He(1),children:(0,Y.jsx)(O,{size:14})})]})]}),(0,Y.jsxs)(`div`,{className:`comment-review-sort-row`,children:[(0,Y.jsx)(_g,{participants:Te,selectedIds:he,topLevelOnly:_e,onToggle:Ke,onClear:()=>{G(),ge(new Set),ve(!0)},onTopLevelOnlyChange:e=>{G(),ve(e)}},`${S}:${S===`file`?_:`project`}`),(0,Y.jsxs)(`button`,{type:`button`,className:`comment-unread-toggle${ue?` active`:``}`,"aria-pressed":ue,"aria-label":V(`editor.commentUnreadMentionsHint`),title:V(`editor.commentUnreadMentionsHint`),onClick:()=>{G(),de(e=>!e)},children:[(0,Y.jsx)(o,{size:12,"aria-hidden":!0}),V(`editor.commentUnreadMentionsOnly`),(0,Y.jsx)(`span`,{children:ke})]}),(0,Y.jsxs)(`label`,{className:`comment-review-sort`,"data-texlite-tooltip-always":!0,"data-tooltip":me,children:[(0,Y.jsx)(`span`,{className:`sr-only`,children:V(`editor.commentSort`)}),fe===`source`?(0,Y.jsx)(w,{size:12,"aria-hidden":!0}):(0,Y.jsx)(yt,{size:12,"aria-hidden":!0}),(0,Y.jsxs)(`select`,{value:fe,"aria-label":`${V(`editor.commentSort`)}: ${me}`,onChange:e=>{G(),pe(e.target.value)},children:[(0,Y.jsx)(`option`,{value:`source`,children:V(`editor.commentSortSourceShort`)}),(0,Y.jsx)(`option`,{value:`time`,children:V(`editor.commentSortTimeShort`)})]})]})]})]}),m&&(0,Y.jsxs)(`div`,{className:`comment-review-error`,role:`alert`,children:[(0,Y.jsx)(`span`,{children:m}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>void h(),children:V(`common.retry`)})]}),p&&(0,Y.jsx)(`div`,{className:`comment-review-loading`,role:`status`,children:V(`common.loading`)}),(0,Y.jsxs)(`div`,{className:`comments`,children:[ze.map(({comment:e,exitAt:t})=>{let n=g.find(t=>t.commentId===e.id&&!t.replyId)?.id,r=new Map(g.filter(t=>t.commentId===e.id&&t.replyId).map(e=>[e.replyId,e.id]));return(0,Y.jsx)(`div`,{className:`comment-thread-slot${t===null?``:` is-exiting`}`,inert:t!==null||void 0,"aria-hidden":t!==null||void 0,style:{"--comment-exit-duration":`280ms`},onAnimationEnd:n=>{n.target===n.currentTarget&&t!==null&&Be(e.id)},children:(0,Y.jsx)(`div`,{className:`comment-thread-slot-content`,children:(0,Y.jsx)(sg,{projectId:s,comment:e,draftStore:f,currentUserId:u,projectOwnerId:i.ownerId,canEditSource:i.permission!==`read`,unreadCommentMentionKind:g.find(e=>e.id===n)?.kind,unreadCommentMentionId:n,unreadReplyMentionIds:r,highlightedComment:j===e.id&&!M,highlightedReplyId:j===e.id?M:null,currentComment:Me===e.id,showFilePath:!H&&S===`project`&&x,replyExpansion:ye.get(e.id),onReplyExpansionChange:t=>{xe(n=>n.get(e.id)===t?n:new Map(n).set(e.id,t))},selectedParticipantIds:H?void 0:he,highlightReplyParticipants:!H&&!_e,onMarkMentionRead:W,onFocus:()=>Ve(e),onActivate:()=>Ce(e.id),onToggle:()=>N(e),onReply:t=>P(e,t),onEdit:t=>te(e,t),onDelete:()=>F(e),onEditReply:(t,n)=>I(e,t,n),onDeleteReply:t=>L(e,t)})})},e.id)}),ze.length===0&&!p&&!m&&(0,Y.jsxs)(`div`,{className:`comment-review-empty`,role:`status`,children:[(0,Y.jsx)(`span`,{className:`comment-review-empty-icon`,"aria-hidden":`true`,children:(0,Y.jsx)(Nt,{size:23,strokeWidth:1.5})}),(0,Y.jsx)(`p`,{children:H?V(d.some(e=>e.id===y&&e.resolved)?`editor.currentCommentResolved`:`editor.currentCommentUnavailable`):Oe.unresolved+Oe.resolved>0?V(`editor.commentNoMatches`):V(`editor.noComments`)})]}),!H&&U===`resolved`&&Le&&(0,Y.jsx)(`div`,{className:`comment-review-pagination`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:Re,children:V(`editor.commentLoadMore`)})})]})]}),n===`settings`&&(0,Y.jsx)(Qe,{onClose:r,children:(0,Y.jsx)(xg,{onClose:r,project:i,projectId:s,site:c,files:l,dictionaryWords:ne,onDictionaryChange:R,editorPreferences:re,onEditorPreferences:ie,spellCheckCount:z,spellCheckUniqueCount:ae,spellCheckIndex:oe,onSpellCheckNavigate:se,onProject:ce},s)})]});return e?(0,Y.jsx)(Ee,{open:!0,title:V(n===`comments`?`editor.sourceComments`:`editor.projectSettings`),onClose:r,children:qe}):n===`comments`&&t!==void 0?t?(0,bh.createPortal)(qe,t):null:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`resize-handle`}),(0,Y.jsx)(be,{id:`context`,defaultSize:`20%`,minSize:`15%`,maxSize:`38%`,children:qe})]})}function Cg(e,t){return b(`texlite.markdownPreview:${encodeURIComponent(e)}:${encodeURIComponent(t)}`)}function wg(e,t){let n=()=>G(Cg(e,t))!==`pdf`,[r,i]=(0,J.useState)(n);return(0,J.useEffect)(()=>i(n()),[e,t]),[r,n=>{i(n),Ze(Cg(e,t),n?`markdown`:`pdf`)}]}function Tg(e,t,n){return e.mainFile===t?e.items:!t||n.filePath!==t?[]:Eg(n.content).map(e=>({...e,path:t}))}function Eg(e){let t=[],n=/^\s*\\(part|chapter|section|subsection|subsubsection)\*?(?:\[[^\]]*\])?\{([^}]*)\}/,r={part:0,chapter:0,section:1,subsection:2,subsubsection:3};return e.split(`
|
|
13
|
+
`).forEach((e,i)=>{let a=e.match(n);a&&t.push({level:r[a[1]],title:a[2],line:i+1})}),t}var Dg=e({ProjectWorkspace:()=>Ng}),Og=(0,J.lazy)(()=>S(()=>import(`./AgentTerminal-CvOz5X_j.js`).then(e=>({default:e.AgentTerminal})),__vite__mapDeps([65,2,3,32,5,4,7,9,16,17,12,1,6,8,10,11,13,33,34,66,67,53,40,37,41,42,48,36,38,62,39]),import.meta.url)),kg=(0,J.lazy)(()=>S(()=>import(`./WordCountDialog-DI0Jv-fg.js`).then(e=>({default:e.WordCountDialog})),__vite__mapDeps([68,3,2,4,5,16,7,9,17,12,1,6,8,10,11,13,53,33,40,37,41,42,64]),import.meta.url)),Ag=null;function jg(){return Ag||=S(()=>import(`./citationLibrary-DxGdbZEQ.js`),__vite__mapDeps([43,20,18,21,24]),import.meta.url).catch(e=>{throw Ag=null,e}),Ag}var Mg=300;function Ng(e){return(0,Y.jsx)(op,{children:(0,Y.jsx)(Nm,{projectId:e.projectId,user:e.user,children:t=>(0,Y.jsx)(Pg,{...e,collaboration:t})})},`${e.user.id}:${e.projectId}`)}function Pg({site:e,user:t,projectId:n,preload:r,mentionId:i=null,onMentionTargeted:a,onMentionsRead:o,onBack:s,collaboration:c}){let{t:u}=v(),d=(0,J.useRef)(n),f=l(t.id,n),[p,m]=(0,J.useState)(!1),h=yh(t.id,n,f.activeCount>0),[g,_]=(0,J.useState)(null),[b,x]=(0,J.useState)(null),S=(0,J.useRef)(0),[C,w]=(0,J.useState)(null);d.current=n;let[T,E]=(0,J.useState)(null),D=(0,J.useCallback)((e,t)=>{E(n=>n?.id===e&&n.sharedMemberCount!==t?{...n,sharedMemberCount:t}:n)},[]);(0,J.useEffect)(()=>(document.title=T?.name?`${e.siteName} | ${T.name}`:e.siteName,()=>{document.title=e.siteName}),[T?.name,e.siteName]);let[O,k]=(0,J.useState)([]),[A,j]=(0,J.useState)(null),[M,ee]=(0,J.useState)({mainFile:``,items:[]}),[N,P]=(0,J.useState)(``),[F,I]=(0,J.useState)(``),[L,ne]=(0,J.useState)(``),[R,ie]=(0,J.useState)({filePath:``,content:``}),[ae,oe]=(0,J.useState)({path:``,hasIncludes:!1}),[ce,V]=(0,J.useState)(``),[H,U]=(0,J.useState)(!1),[le,ue]=(0,J.useState)(`editor.saved`),[de,fe]=(0,J.useState)(null),me=(0,J.useRef)(de);me.current=de;let he=(0,J.useRef)(null);he.current||=Ae();let ge=he.current,[_e,ve]=(0,J.useState)(`pdf`),[ye,be]=(0,J.useState)(`log`),xe=e=>{e===`pdf`?ve(`pdf`):(e===`diagnostics`||be(e),ve(`diagnostics`))},{workspaceLayout:Se,setWorkspaceLayout:Ce,phone:Te}=$m(t.id,n),[Ee,ke]=wg(t.id,n),Ne=nh(N),Pe=rh(_e,Ne,Ee),Fe=e=>{e===`markdown`?ke(!0):e===`pdf`&&Ne&&ke(!1),xe(e===`markdown`?`pdf`:e)},[Ie,Re]=(0,J.useState)(null),[ze,Be]=(0,J.useState)(!1),[Ve,W]=(0,J.useState)(``),[We,G]=(0,J.useState)(``),[Ke,Je]=(0,J.useState)({selectedText:``,startOffset:0,endOffset:0}),Ye=(0,J.useRef)({selectedText:``,startOffset:0,endOffset:0}),Xe=e=>{let t=Ye.current;(t.selectedText!==e.selectedText||t.startOffset!==e.startOffset||t.endOffset!==e.endOffset)&&(Ye.current=e,Je(e))},[Ze,Qe]=(0,J.useState)(null),[$e,et]=(0,J.useState)(null),[tt,nt]=(0,J.useState)(null),[rt,it]=(0,J.useState)(null),[at,ot]=(0,J.useState)(null),[st,ct]=(0,J.useState)(null),[lt,ut]=(0,J.useState)(!1),[dt,ft]=(0,J.useState)(!1),[pt,mt]=(0,J.useState)(!1),[ht,gt]=(0,J.useState)(!1),[_t,vt]=(0,J.useState)(null),[yt,bt]=(0,J.useState)(!1),[xt,St]=(0,J.useState)(null),[Ct,wt]=(0,J.useState)(!1),[Tt,Et]=(0,J.useState)(!1),[Dt,Ot]=(0,J.useState)(!1),[kt,At]=(0,J.useState)(`full`),[jt,Mt]=(0,J.useState)(``),[Nt,Pt]=(0,J.useState)(!1),[Ft,It]=(0,J.useState)(``),[Lt,Rt]=(0,J.useState)(null),[zt,Bt]=(0,J.useState)(!1),[Vt,Ht]=(0,J.useState)(null),[Ut,Wt]=(0,J.useState)(!1),[Gt,Kt]=(0,J.useState)(()=>re(t.id,n));(0,J.useEffect)(()=>{let e=document.documentElement,t=Gt.showTooltips?`on`:`off`;return e.setAttribute(`data-texlite-tooltips`,t),()=>{e.getAttribute(`data-texlite-tooltips`)===t&&e.removeAttribute(`data-texlite-tooltips`)}},[Gt.showTooltips]);let[qt,Jt]=(0,J.useState)([]),Yt=(0,J.useRef)([]);Yt.current=qt;let Xt=(0,J.useRef)(null),Zt=(0,J.useRef)(null),Qt=(0,J.useRef)(0),$t=(0,J.useRef)(0),en=(0,J.useRef)(``),tn=(0,J.useRef)(``),nn=(0,J.useRef)(()=>void 0),rn=(0,J.useRef)(Se),an=(0,J.useRef)(0),on=(0,J.useRef)(null),sn=(0,J.useRef)(null),cn=(0,J.useRef)(null),ln=(0,J.useRef)(null),un=(0,J.useRef)(null),dn=(0,J.useRef)(null),fn=(0,J.useRef)(null),pn=(0,J.useRef)(null),mn=(0,J.useRef)(null),hn=(0,J.useRef)(!1),gn=(0,J.useRef)(null),_n=(0,J.useRef)(s),vn=(0,J.useRef)(a),yn=(0,J.useRef)(o);_n.current=s,vn.current=a,yn.current=o,en.current=N,tn.current=F,rn.current=Se,(0,J.useEffect)(()=>{if(!We)return;let e=window.setTimeout(()=>G(``),3e3);return()=>window.clearTimeout(e)},[We]);let bn=(0,J.useCallback)((e,t,n=0)=>{ge.update(e,t,n)},[ge]);(0,J.useEffect)(()=>()=>ge.dispose(),[ge]),(0,J.useEffect)(()=>()=>{pn.current?.abort(),pn.current=null},[]);let xn=e=>{let t=Yt.current,n=e(t);n!==t&&(Yt.current=n,Jt(n))};(0,J.useEffect)(()=>{Yt.current=[],Jt([]),Ht(null),vt(null),dn.current?.abort(),dn.current=null,fn.current?.abort(),fn.current=null,pn.current?.abort(),pn.current=null,mn.current=null,it(null),ot(null),ct(null),Ot(!1),Pt(!1),It(``),Rt(null)},[n]);let Sn=e=>{let t=Yt.current,n=t.indexOf(e);if(n<0)return;let r=t.filter(t=>t!==e);if(Yt.current=r,Jt(r),en.current!==e)return;let i=r.length>0?r[Math.min(n,r.length-1)]:T?.mainFile??``;P(i)},{status:Cn,synced:X,activeSessions:wn,formatLeaseStates:Tn,compileState:En,setCompileState:Dn,filesEvent:On,commentsRevision:Z,historyWarning:kn,dictionaryRevision:An,chktexSettingsRevision:jn,localDraftReady:Mn,permission:Nn,reconnect:Pn,protocolUpgradeRequired:Fn,permissionDowngrade:In,dismissPermissionDowngrade:Ln,discardLocalDraft:Rn}=cp(c,F,T?.permission??`read`,T?.id===n),{unreadMentions:zn,mentionsError:Bn,markMentionRead:Vn,markAllMentionsRead:Hn}=ap(n,Z,W,(e,t)=>yn.current?.(e,t)),{pdfTarget:Un,pdfViewport:Wn,sourceJump:Gn,setPdfViewport:Kn,resetPdfViewport:qn,clearPdfViewport:Jn,jumpToSource:Yn,syncSourceToPdf:Xn,syncPdfToSource:Zn,syncVisiblePdfToSource:Qn}=Xm({projectId:n,mainFile:F,activeFile:N,onOpenSourceFile:e=>nn.current(e),onError:W,onShowPdf:()=>{xe(`pdf`),Te&&Ce(`pdf-only`)},onShowEditor:()=>{rn.current===`pdf-only`&&Ce(`editor-pdf`)}}),$n=!!(T&&T.chktexEnabled&&N&&X&&mu(N)),er=Jm({active:$n,projectId:n,activeFile:N,content:L}),tr=qm({active:!!(T&&N&&X&&pu(N)&&(Gt.spellCheck||T.chktexEnabled&&mu(N))),harperEnabled:Gt.spellCheck,projectId:n,activeFile:N,content:L,dictionaryWords:O,additionalIssues:er.issues,additionalIssuesReady:!$n||er.checked});(0,J.useEffect)(()=>{Kt(re(t.id,n))},[t.id,n]);let nr=e=>{ne(e)};(0,J.useEffect)(()=>{if(!N||ce!==N){ie(e=>e.filePath||e.content?{filePath:``,content:``}:e);return}let e=N,t=L,n=window.setTimeout(()=>{ie(n=>n.filePath===e&&n.content===t?n:{filePath:e,content:t})},Mg);return()=>window.clearTimeout(n)},[N,ce,L]),(0,J.useEffect)(()=>{en.current=N,ge.reset(),Xe({selectedText:``,startOffset:0,endOffset:0}),Gt.openFilesInTabs?N&&xn(e=>e.includes(N)?e:[...e,N]):Yt.current.length>0&&(Yt.current=[],Jt([]))},[N,Gt.openFilesInTabs,n,ge]),(0,J.useEffect)(()=>{if(!H)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[H]),(0,J.useEffect)(()=>{if(Cn!==`disconnected`)return;let e=new AbortController;return K(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||(E(t),W(``))}).catch(e=>{Ue(e)||(e instanceof He&&[401,403,404].includes(e.status)?(W(q(e)),_n.current()):W(u(`errors.collaborationUnavailable`)))}),()=>e.abort()},[Cn,n,u]);let rr=async(e={},t=tn.current)=>{on.current?.abort(),on.current=null;let r=e.signal?null:new AbortController;r&&(on.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await K(`/api/projects/${n}/completions${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&j(a.index)}catch(t){if(Ue(t))return;(!e.isCurrent||e.isCurrent())&&j(null)}finally{r&&on.current===r&&(on.current=null)}},ir=async(e={},t=tn.current)=>{cn.current?.abort(),cn.current=null;let r=e.signal?null:new AbortController;r&&(cn.current=r);try{let i=t?`?mainFile=${encodeURIComponent(t)}`:``,a=await K(`/api/projects/${n}/outline${i}`,{signal:e.signal??r?.signal});(!e.isCurrent||e.isCurrent())&&tn.current===t&&ee({mainFile:t,items:a.outline})}catch(e){if(Ue(e))return}finally{r&&cn.current===r&&(cn.current=null)}},Q=async(e={})=>{ln.current?.abort(),ln.current=null;let t=e.signal?null:new AbortController;t&&(ln.current=t);try{let r=await K(`/api/projects/${n}/dictionary`,{signal:e.signal??t?.signal});(!e.isCurrent||e.isCurrent())&&k(r.words)}catch(t){if(Ue(t))return;(!e.isCurrent||e.isCurrent())&&k([])}finally{t&&ln.current===t&&(ln.current=null)}};(0,J.useEffect)(()=>{let e=!1,t=++an.current,i=new AbortController,a=()=>!e&&an.current===t,o=!1,s=``;E(null),gr([]),ee({mainFile:``,items:[]}),P(``),I(``),oe({path:``,hasIncludes:!1}),ne(``),V(``),Dn(null),Jn(),j(null),k([]),Ge();let c=(r?.projectId===n?r.project:K(`/api/projects/${n}`,{signal:i.signal})).then(e=>{a()&&(o=!0,s=e.project.mainFile,E(e.project),P(e.project.mainFile),tn.current=e.project.mainFile,I(e.project.mainFile),Lr(new Set(Bm(e.project.mainFile))))}).catch(e=>{a()&&W(q(e))}),l=K(`/api/projects/${n}/files`,{signal:i.signal}).then(e=>{a()&&gr(e.files)}).catch(e=>{a()&&W(q(e))}),u=null;return Promise.allSettled([c,l]).then(()=>{a()&&o&&(u=window.setTimeout(()=>{a()&&Promise.all([rr({signal:i.signal,isCurrent:a},tn.current||s),Q({signal:i.signal,isCurrent:a})])},0))}),()=>{e=!0,u!==null&&window.clearTimeout(u),i.abort(),on.current?.abort(),on.current=null,cn.current?.abort(),cn.current=null,ln.current?.abort(),ln.current=null,un.current?.abort(),un.current=null}},[n,r]),(0,J.useEffect)(()=>{T&&F&&(sn.current===n?rr({},F):sn.current=n)},[F,T?.id,n]),(0,J.useEffect)(()=>{if(!i||!T)return;fn.current?.abort();let e=new AbortController;return fn.current=e,K(`/api/projects/${n}/mentions/${encodeURIComponent(i)}`,{signal:e.signal}).then(({mention:t})=>{e.signal.aborted||(it(t),nt(null),Qe(`comments`),P(t.filePath),vn.current?.(t.id))}).catch(t=>{Ue(t)||e.signal.aborted||(W(q(t)),vn.current?.(i))}).finally(()=>{fn.current===e&&(fn.current=null)}),()=>e.abort()},[i,T?.id,n]),(0,J.useEffect)(()=>{An&&Q()},[An,n]),(0,J.useEffect)(()=>{if(!jn)return;let e=new AbortController;return K(`/api/projects/${n}`,{signal:e.signal}).then(({project:t})=>{e.signal.aborted||E(e=>e?{...e,chktexEnabled:t.chktexEnabled}:t)}).catch(e=>{Ue(e)||W(q(e))}),()=>e.abort()},[jn,n]),(0,J.useEffect)(()=>{T&&Cn===`connected`&&Nn!==T.permission&&E(e=>e&&{...e,permission:Nn})},[Nn,T?.permission]),(0,J.useEffect)(()=>{if(!On)return;let t=On.kind===`delete`&&!!On.path&&Vm(On.path,en.current),r=On.kind===`delete`&&!!On.path&&Vm(On.path,tn.current);if(On.kind===`move`&&On.source&&On.destination){let e=On.source,t=On.destination,n=n=>n===e?t:n.startsWith(`${e}/`)?`${t}${n.slice(e.length)}`:n;P(e=>n(e)),I(e=>n(e)),Nr(e=>e&&n(e)),Fr(e=>e&&n(e)),xn(e=>e.map(n))}t&&(P(``),V(``),nr(``),G(u(`editor.fileDeletedByCollaborator`,{path:On.path}))),On.kind===`delete`&&On.path&&(Nr(e=>e&&Vm(On.path,e)?null:e),Fr(e=>Vm(On.path,e)?``:e),Cr(e=>e&&Vm(On.path,e.path)?null:e),xn(e=>e.filter(e=>!Vm(On.path,e)))),un.current?.abort();let i=new AbortController;un.current=i,Promise.all([_r({signal:i.signal}),K(`/api/projects/${n}`,{signal:i.signal})]).then(([n,a])=>{if(E(a.project),r&&I(a.project.mainFile),t&&n){let t=n.find(e=>e.type===`file`&&e.path===a.project.mainFile)??n.find(t=>t.type===`file`&&Me(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024);P(t?.path??``)}rr({signal:i.signal}),ir({signal:i.signal},r?a.project.mainFile:tn.current)}).catch(e=>{Ue(e)}).finally(()=>{un.current===i&&(un.current=null)})},[On?.revision]),(0,J.useEffect)(()=>{if(c.setActiveFile(N),!N)return;V(``),ue(`editor.loading`);let e=c.getText(N),t=(t,n)=>{nr(e.toString()),V(N),n?.local&&T?.permission!==`read`?(Qt.current+=1,U(!0),ue(`editor.pending`)):Qt.current<=$t.current&&ue(me.current?`editor.savedAt`:`editor.saved`)};return e.observe(t),(X||Mn)&&t(),()=>{e.unobserve(t)}},[N,c,X,Mn,T?.permission]);let ar=async()=>{if(!X)throw Error(`Collaboration is not synchronized`);let e=Qt.current,t=await c.flush();return $t.current=Math.max($t.current,e),fe(t.persistedAt),/\.tex$/i.test(en.current)&&ir(),Qt.current===e?(U(!1),ue(`editor.savedAt`)):ue(`editor.pending`),t};(0,J.useEffect)(()=>{if(!H||!N||!X)return;ue(`editor.pending`);let e=window.setTimeout(()=>{ue(`editor.saving`),ar().catch(()=>{ue(`editor.saveFailed`)})},750);return()=>window.clearTimeout(e)},[L,H,N,X]);let or=async()=>{if(!T||T.permission===`read`||!X||!N)return!1;ue(`editor.saving`);try{return await ar(),rr(),!0}catch(e){return ue(`editor.saveFailed`),W(q(e)||u(`errors.collaborationUnavailable`)),!1}},sr=async e=>{if(!T||Nt)return;let t=e===`full`?tn.current||T.mainFile:en.current,r=e===`selection`?Ye.current.selectedText:``;if(!t)return;if(e===`selection`&&(!r.trim()||!/\.(?:tex|sty|cls)$/i.test(t))){G(u(`editor.wordCountSelectionEmpty`));return}dn.current?.abort();let i=new AbortController;dn.current=i,At(e),Mt(t),Rt(null),It(``),Ot(!0),Pt(!0);try{if(e===`full`&&H&&T.permission!==`read`&&!await or())throw Error(u(`editor.wordCountSaveRequired`));let a=e===`selection`?{mode:e,path:t,source:r}:{mode:e,mainFile:t},o=await K(`/api/projects/${n}/word-count`,{method:`POST`,body:JSON.stringify(a),signal:i.signal});if(i.signal.aborted)return;Rt(o)}catch(e){if(Ue(e))return;i.signal.aborted||It(q(e))}finally{dn.current===i&&(dn.current=null,Pt(!1))}},cr=async(t,n,r=Gt.texFmtConfig)=>{if(/\.bib$/i.test(t))try{return{formatted:await Ju(n,e.maxCitationBibtexBytes)}}catch(t){throw t instanceof Uu?t.kind===`too-large`?Error(u(`citationLibrary.fileTooLarge`,{size:`${Math.round(e.maxCitationBibtexBytes/1024)} KB`})):t.kind===`invalid`?Error(u(`citationLibrary.fileInvalid`)):Error(u(t.kind===`timeout`?`editor.bibtexFormatterTimeout`:`editor.bibtexFormatterUnavailable`)):t}return{formatted:(await Nu(n,r)).output}},lr=async(e,t,n,r=0)=>{if(!/\.bib$/i.test(e))return zu(t,n,r);try{return await Yu(t,n,r)}catch(e){throw e instanceof Uu?Error(u(e.kind===`timeout`?`editor.bibtexFormatterTimeout`:`editor.bibtexFormatterUnavailable`)):e}},ur=async e=>{if(!T||T.permission===`read`||!X||hn.current||!Iu(en.current))return;let t=en.current,n=c.getText(t);hn.current=!0,Bt(!0);let r=()=>{},i=new Promise(e=>{r=e});gn.current=i;let a=null;try{a=await c.acquireFormatLease(t);let r=n.toString(),{formatted:i}=await cr(t,r,e);if(en.current!==t||n.toString()!==r){W(u(`editor.formatSourceChanged`));return}await a.confirm();let o=await lr(t,r,i);if(en.current!==t||n.toString()!==r||(await a.confirm(),en.current!==t||n.toString()!==r)){W(u(`editor.formatSourceChanged`));return}o.length&&c.applyTextEdits(t,o),o.length&&await ar(),Ht(null),W(``),G(u(`editor.formatFileComplete`))}catch(e){Ou(e)?(Ht({action:`file`,kind:e.kind,detail:e.message}),W(``)):W(u(`editor.formatFileFailed`,{message:q(e)}))}finally{a&&await a.release(),hn.current=!1,Bt(!1),r(),gn.current===i&&(gn.current=null)}},dr=async()=>{if(!Gt.formatOnCompile||!T||T.permission===`read`||!X||!Iu(en.current)||hn.current)return;let e=en.current,t=c.getText(e);hn.current=!0,Bt(!0);let n=null;try{n=await c.acquireFormatLease(e);let r=t.toString(),{formatted:i}=await cr(e,r);await n.confirm();let a=await lr(e,r,i);if(en.current!==e||t.toString()!==r||(await n.confirm(),en.current!==e||t.toString()!==r))throw Error(u(`editor.formatSourceChanged`));a.length&&c.applyTextEdits(e,a),a.length&&await c.flush(),Ht(null)}catch(e){Ou(e)?(Ht({action:`file`,kind:e.kind,detail:e.message}),W(``)):W(u(`editor.formatFailedContinue`,{message:q(e)}))}finally{n&&await n.release(),hn.current=!1,Bt(!1)}},fr=async()=>(gn.current&&await gn.current,await dr(),or()),pr=async e=>{if(!T||T.permission===`read`||!X||hn.current||!Iu(en.current))return;let t=Ye.current;if(!t.selectedText.trim()){G(u(`editor.formatSelectionRequired`));return}let n=en.current,{startOffset:r,endOffset:i,selectedText:a}=t,o=c.getText(n);if(o.toString().slice(r,i)!==a){W(u(`editor.formatSelectionChanged`));return}hn.current=!0,Bt(!0);let s=()=>{},l=new Promise(e=>{s=e});gn.current=l;let d=null;try{if(d=await c.acquireFormatLease(n),o.toString().slice(r,i)!==a){W(u(`editor.formatSelectionChanged`));return}let t=Ru(a,(await cr(n,a,e)).formatted);await d.confirm();let s=await lr(n,a,t,r);if(en.current!==n||o.toString().slice(r,i)!==a||(await d.confirm(),en.current!==n||o.toString().slice(r,i)!==a)){W(u(`editor.formatSelectionChanged`));return}s.length&&c.applyTextEdits(n,s),s.length&&await ar(),Ht(null),W(``),G(u(`editor.formatSelectionComplete`))}catch(e){Ou(e)?(Ht({action:`selection`,kind:e.kind,detail:e.message}),W(``)):W(u(`editor.formatFailed`,{message:q(e)}))}finally{d&&await d.release(),hn.current=!1,Bt(!1),s(),gn.current===l&&(gn.current=null)}},mr=async t=>{let n=en.current;if(!/\.bib$/i.test(n)||T?.permission===`read`||!X)return G(u(`citationLibrary.importRequiresWrite`)),!1;let r=c.getText(n),i;try{i=await jg()}catch(e){return W(q(e)),!1}if(en.current!==n||!X)return!1;let a=r.toString(),o=i.parseBibEntriesResult(a,e.maxCitationBibtexBytes);if(o.status===`too-large`)return G(u(`citationLibrary.fileTooLarge`,{size:i.citationBibtexLimitLabel(e.maxCitationBibtexBytes)})),!1;if(o.status===`invalid`)return G(u(`citationLibrary.fileInvalid`)),!1;if(o.entries.some(e=>e.citationKey.toLowerCase()===t.citationKey.toLowerCase()))return G(u(`citationErrors.alreadyInFile`,{key:t.citationKey})),!1;let s=Math.max(0,Math.min(a.length,ge.getCursor().offset)),l=a.slice(0,s),d=a.slice(s),f=l?l.endsWith(`
|
|
14
|
+
|
|
15
|
+
`)?``:l.endsWith(`
|
|
16
|
+
`)?`
|
|
17
|
+
`:`
|
|
18
|
+
|
|
19
|
+
`:``,p=d?d.startsWith(`
|
|
20
|
+
|
|
21
|
+
`)?``:d.startsWith(`
|
|
22
|
+
`)?`
|
|
23
|
+
`:`
|
|
24
|
+
|
|
25
|
+
`:``;return c.applyTextEdits(n,[{from:s,to:s,replacement:`${f}${t.bibtex.trim()}${p}`}]),G(u(`citationLibrary.imported`,{key:t.citationKey})),!0},{files:hr,setFiles:gr,loadFiles:_r,newFileOpen:vr,setNewFileOpen:yr,newFilePath:br,setNewFilePath:xr,resourcePreview:Sr,setResourcePreview:Cr,resourcePreviewLoading:wr,setResourcePreviewLoading:Tr,newFolderOpen:Er,setNewFolderOpen:Dr,newFolderName:Or,setNewFolderName:kr,fileDialogError:Ar,setFileDialogError:jr,selectedFolder:Mr,setSelectedFolder:Nr,selectedFile:Pr,setSelectedFile:Fr,expandedFolders:Ir,setExpandedFolders:Lr,moveEntry:Rr,setMoveEntry:zr,moveName:Br,setMoveName:Vr,moveDestination:Hr,setMoveDestination:Ur,deleteEntry:Wr,setDeleteEntry:Gr,fileDragActive:Kr,setFileDragActive:qr,uploadConflict:Jr,setUploadConflict:Yr,uploadingFiles:Xr,uploadFeedback:Zr,dismissUploadFeedback:Qr,directoryEntries:$r,visibleEntries:ei,createFile:ti,createFolder:ni,uploadFiles:ri,upload:ii,openFile:ai,movePath:oi,movePathToFolder:si,removePath:ci}=Gm({projectId:n,site:e,activeFile:N,dirty:H,save:or,onError:W,onProject:E,onActiveFile:P,onActiveMainFile:I});nn.current=e=>{Nr(null),Fr(e),Lr(t=>new Set([...t,...Bm(e)])),P(e)};let li=e=>{if(e.id!==d.current)return;let t=e.mainFile!==T?.mainFile;E(e),t&&(tn.current=e.mainFile,en.current=e.mainFile,I(e.mainFile),P(e.mainFile),Nr(null),Fr(e.mainFile),Lr(t=>new Set([...t,...Bm(e.mainFile)])))},ui=()=>tn.current||T?.mainFile||``,di=()=>{let e=ui(),t=en.current;if(!t||!/\.tex$/i.test(t))return e;let n=hr.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length;return th(c.getText(t).toString())||n===1?(e!==t&&(tn.current=t,I(t)),t):e===t&&T?.mainFile&&T.mainFile!==t?(tn.current=T.mainFile,I(T.mainFile),T.mainFile):e};(0,J.useEffect)(()=>{N&&N===F&&ce===N&&R.filePath===N&&N.toLocaleLowerCase().endsWith(`.tex`)&&hr.filter(e=>e.type===`file`&&/\.tex$/i.test(e.path)).length!==0&&N!==T?.mainFile&&!th(R.content)&&T?.mainFile&&(tn.current=T.mainFile,I(T.mainFile))},[N,F,ce,R,hr,T?.mainFile]),(0,J.useEffect)(()=>{if(!Gt.openFilesInTabs||hr.length===0)return;let t=new Set(hr.filter(t=>t.type===`file`&&Me(t.path,t.textContent)&&(t.size??0)<=e.maxCollaborativeFileSizeMB*1024*1024).map(e=>e.path));xn(e=>{let n=e.filter(e=>t.has(e));return n.length===e.length?e:n})},[hr,Gt.openFilesInTabs]);let{comments:fi,projectCommentSummary:pi,commentsFilePath:mi,commentsReady:hi,fileCommentsLoading:gi,fileCommentsError:_i,retryFileComments:vi,reviewComments:yi,reviewCommentsLoading:bi,reviewCommentsError:xi,retryReviewComments:Si,commentScope:Ci,setCommentScope:wi,focusComment:Ti,setFocusComment:Ei,commentOpen:Di,openComment:Oi,closeComment:ki,commentText:Ai,setCommentText:ji,commentSelection:Mi,commentSuggestion:Ni,setCommentSuggestion:Pi,commentSubmitting:Fi,commentError:Ii,addComment:Li,toggleComment:Ri,replyToComment:zi,editComment:Bi,deleteComment:Vi,editCommentReply:Hi,deleteCommentReply:Ui,commentDraftStore:Wi,cancelComment:Gi,commentDraftRestored:Ki,commentDraftCanRetarget:qi,useCurrentCommentSelection:Ji}=Wf({projectId:n,activeFile:N,content:L,permission:T?.permission,revision:Z,sourceOrderRevision:`${T?.mainFile??``}\0${On?.revision??``}`,selection:Ke,save:or,saveFailureMessage:u(`errors.collaborationUnavailable`),onError:W,onAdded:()=>{nt(null),Qe(`comments`)}});(0,J.useEffect)(()=>{if(!F||R.filePath!==F)return;let e=$l(R.content).length>0;oe(t=>t.path===F&&t.hasIncludes===e?t:{path:F,hasIncludes:e})},[F,R]),(0,J.useEffect)(()=>{if(!F||!X||N===F)return;let e=c.getText(F),t=null,n=()=>{let t=$l(e.toString()).length>0;oe(e=>e.path===F&&e.hasIncludes===t?e:{path:F,hasIncludes:t})},r=()=>{t!==null&&window.clearTimeout(t),t=window.setTimeout(()=>{t=null,n()},Mg)};return n(),e.observe(r),()=>{t!==null&&window.clearTimeout(t),e.unobserve(r)}},[N,F,c,X]);let Yi=(0,J.useMemo)(()=>ae.path===F&&ae.hasIncludes||!!pi?.filePaths.some(e=>e!==N),[F,ae,pi,N]),Xi=e=>{ct(null),Qe(`comments`),Ei(null),ot(e),en.current!==e.filePath&&Yn(e.filePath,e.startLine,1)},Zi=(e,t=!1)=>{let n=fi.find(t=>t.id===e&&t.filePath===N);!n||n.resolved||n.orphaned||(ot(null),Ei(null),it(null),t&&Ze===`comments`&&tt===n.id?(nt(null),ct(null),Qe(null)):(nt(n.id),ct(e=>({id:n.id,filePath:n.filePath,nonce:(e?.nonce??0)+1})),Qe(`comments`)))};(0,J.useEffect)(()=>{ct(null),nt(null)},[N]),(0,J.useEffect)(()=>{if(!at)return;let e=np(at,N,ce,mi,hi,fi);e?(Ei({...e}),ot(null)):at.filePath===N&&ce===N&&mi===N&&hi&&ot(null)},[N,fi,mi,hi,ce,at,Ei]),(0,J.useEffect)(()=>{if(!rt||N!==rt.filePath||Ze!==`comments`)return;let e=fi.find(e=>e.id===rt.commentId);if(!e||rt.replyId&&!e.replies.some(e=>e.id===rt.replyId)||mn.current===rt.id)return;mn.current=rt.id,Xi(e);let t=window.setTimeout(()=>it(e=>e?.id===rt.id?null:e),3e3);return()=>window.clearTimeout(t)},[N,fi,Ze,rt]);let{pdfUrl:Qi,pdfCompiledAt:$i,pdfSizeBytes:ea,pdfLoadingMode:ta,pdfLoading:na,compileLog:ra,compileDiagnostics:ia,compileOutcome:aa,artifacts:oa,artifactPreview:sa,artifactLoading:ca,editorNotice:la,localCompiling:ua,cancelling:da,cleaning:fa,compile:pa,cancelCompile:ma,cleanCompile:ha,viewArtifact:ga,pdfDisplayed:_a}=Rm({projectId:n,project:T,mainFile:F,resolveCompileMainFile:di,getCurrentMainFile:ui,initialLatest:r?.projectId===n?r.latestCompile:null,collaborationSynced:X,pdfVisible:Pe===`pdf`&&Se!==`editor-only`,sharedState:En,onSharedState:Dn,save:fr,loadOutline:(e,t)=>ir({signal:e},t),onPreviewTab:xe,onError:W,onCompileStart:()=>{W(``),G(``)},onCompileSuccess:()=>{let e=en.current;if(e){let t=ge.getCursor();Xn(e,t.line,t.column,{silent:!0})}},onPdfChanged:Jn});(0,J.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&!e.shiftKey&&e.key.toLocaleLowerCase()===`p`&&(e.preventDefault(),wt(!0))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let va=e=>{z(t.id,n,e),Kt(e)},ya=(e=!1)=>{let t=Vt;if(!t)return;Ht(null),W(``),e&&va({...Gt,texFmtConfig:``});let n=e?``:void 0;t.action===`selection`?pr(n):ur(n)},ba=async()=>{Wt(!0);try{await Rn()||(W(u(`editor.collaboration.permissionDowngradeOtherTabBlocked`)),Wt(!1))}catch(e){W(q(e)),Wt(!1)}},xa=()=>{Te?Be(e=>!e):Zt.current?.isCollapsed()?Zt.current.expand():Zt.current?.collapse()},Sa=(0,J.useMemo)(()=>Tg(M,F,R),[M,F,R]),Ca=(0,J.useMemo)(()=>Xu(ra,aa),[ra,aa]),wa=Se!==`pdf-only`,Ta=Se!==`editor-only`,Ea=je(wa,Ta,Ze===`settings`||Ze===`comments`&&!Ta,Te),Da=e=>{Ce(e),e===`pdf-only`&&xe(`pdf`)},Oa=(0,J.useCallback)((e,t)=>{_(e.id),t?Yn(e.path,e.line,1):(e.path!==N&&nn.current(e.path),x({id:e.id,path:e.path,nonce:++S.current}))},[N,Yn]),ka=!!(wa&&f.visible&&T?.permission!==`read`),Aa=(0,J.useCallback)(e=>{m(!0),_(e),w({id:e,nonce:++S.current})},[]),ja=(0,J.useMemo)(()=>N?h.forFile(N):null,[N,h.forFile]),Ma=(0,J.useCallback)(e=>{pn.current?.abort();let t=new AbortController;pn.current=t;let r=en.current,i=tn.current,a=new URLSearchParams({kind:e.kind,key:e.key,...r?{path:r}:{},...i?{mainFile:i}:{}});K(`/api/projects/${n}/references/resolve?${a}`,{signal:t.signal}).then(({target:n})=>{t.signal.aborted||en.current!==r||tn.current!==i||(n?(rn.current===`pdf-only`&&Da(`editor-pdf`),Yn(n.path,n.line,n.column)):W(u(e.kind===`citation`?`editor.citationTargetNotFound`:`editor.labelTargetNotFound`,{key:e.key})))}).catch(e=>{!t.signal.aborted&&!Ue(e)&&W(q(e))}).finally(()=>{pn.current===t&&(pn.current=null)})},[Yn,n,u]),Na=Wr?wn.filter(e=>e.filePath&&Vm(Wr.path,e.filePath)):[];if(!T)return(0,Y.jsxs)(`div`,{className:`center-card`,children:[(0,Y.jsx)(`p`,{children:Ve||u(`common.loading`)}),Ve&&(0,Y.jsx)(`button`,{className:`primary`,onClick:s,children:u(`editor.backToProjects`)})]});let Pa=T.permission===`read`||!X,Fa=Tn.find(e=>e.path===N),Ia=Fa&&!zt?Fa:null,La=(e,t)=>{if(Pa)return;let n=en.current;if(n){if(c.getText(n).toString().slice(e.from,e.to)!==e.word)W(u(`editor.spellCheckSourceChanged`));else try{c.applyTextEdits(n,[{from:e.from,to:e.to,replacement:t}])}catch(e){W(q(e))}}},Ra=En?.mainFile===F&&(En.status===`queued`||En.status===`running`),za=ua||Ra||fa,Ba=N?c.getText(N):null,Va=$i?te($i,y.resolvedLanguage,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`}):``,Ha=F.split(`/`).at(-1)??F,Ua=Ca.warnings.length+Ca.errors.length+oa.length,Wa=Qi?`${Qi}${Qi.includes(`?`)?`&`:`?`}download=1`:``,Ga=F||T.mainFile,Ka=Ym(N,Ga),qa=!!(Ga&&/\.tex$/i.test(Ga)),Ja=()=>{let e=en.current;if(!e)return Promise.resolve();let t=ge.getCursor();return Xn(e,t.line,t.column)},Ya=()=>(Fe(`markdown`),Te&&Ce(`pdf-only`),Re(e=>({line:ge.getCursor().line,nonce:(e?.nonce??0)+1})),Promise.resolve()),Xa=Ne?{path:N,source:ce===N?L:null,reveal:Ie,onOpenPath:e=>{let t=hr.find(t=>t.path===e);t?(!nh(e)&&Me(t.path,t.textContent)&&Se===`pdf-only`&&Ce(`editor-pdf`),ai(t)):W(u(`editor.markdown.linkMissing`,{path:e}))},onShowLine:e=>{rn.current===`pdf-only`&&Ce(`editor-pdf`),Yn(N,e,1)},onShowCursor:()=>void Ya()}:null,Za=e=>{let t=hr.find(t=>t.path===e);t&&Me(t.path,t.textContent)?ai(t):Sn(e)},Qa=e=>{document.getElementById(`editor-tab-${encodeURIComponent(e)}`)?.focus()},$a=(e,t)=>{if(![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key))return;e.preventDefault();let n=e.key===`Home`?0:e.key===`End`?qt.length-1:(t+(e.key===`ArrowLeft`?-1:1)+qt.length)%qt.length,r=qt[n];r&&(Za(r),window.requestAnimationFrame(()=>Qa(r)))},eo=za?Ra?En?.status===`queued`?u(`editor.compileQueued`):u(`editor.compilingBy`,{name:En?.requestedBy.name??u(`common.user`)}):u(`editor.compiling`):aa===`failed`?Qi&&$i?u(`editor.compileFailedRetained`,{time:te($i,y.resolvedLanguage)}):u(`editor.compileFailedNoPdf`):aa===`cancelled`?u(`compileControls.cancelled`):``,to=ch(Cn,le,Cn===`disconnected`&&(H||c.hasWritableDraft)),no=to===`editor.savedAt`&&de?u(`editor.savedAt`,{time:te(de,y.resolvedLanguage,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}):u(to);return(0,Y.jsxs)(`div`,{className:`workspace`,"data-texlite-tooltips":Gt.showTooltips?`on`:`off`,children:[(0,Y.jsx)(sh,{agentTerminal:wa&&f.visible&&T.permission!==`read`?{open:p,activeCount:f.activeCount,toggle:()=>m(e=>!e)}:void 0,site:e,project:T,activeFile:N,saveStateLabel:no,editorPreferences:Gt,activeSessions:wn,collaborationStatus:Cn,reconnectCollaboration:Pn,protocolUpgradeRequired:Fn,showEditor:wa,filesCollapsed:Te?!ze:lt,toggleFilesPanel:xa,workspaceLayout:Se,changeWorkspaceLayout:Da,onBack:s,onShare:()=>ft(!0),showCitationLibrary:wa&&/\.bib$/i.test(N),citationLibraryOpen:yt,onCitationLibrary:()=>bt(!0),onHistory:()=>gt(!0),onGit:()=>mt(!0),canManageGit:T.ownerId===t.id,formatting:zt,readOnly:Pa,collaborationSynced:X,onToggleComments:()=>{let e=Ze!==`comments`||!!tt;nt(null),e&&wi(`project`),Qe(e?`comments`:null)},commentsOpen:Ze===`comments`,unresolvedCommentCount:pi?.unresolvedCount??T.unresolvedCommentCount??0,onToggleSettings:()=>Qe(Ze===`settings`?null:`settings`),settingsOpen:Ze===`settings`,compileBusy:za,sharedCompiling:Ra,localCompiling:ua,cancelling:da,onCompile:pa,onCancelCompile:()=>void ma()}),Fn&&(0,Y.jsxs)(`div`,{className:`workspace-update-banner`,role:`alert`,children:[(0,Y.jsx)(se,{size:15}),(0,Y.jsx)(`span`,{children:u(`workspaceUpdates.protocolUpgrade`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:u(`common.reload`)})]}),eo&&(0,Y.jsxs)(`div`,{className:`compile-status-strip${aa===`failed`?` failed`:``}`,role:`status`,"aria-live":`polite`,children:[(0,Y.jsx)(Le,{className:za?`spin`:``,size:14}),(0,Y.jsx)(`span`,{children:eo})]}),(tr.error||er.error||Vt||Ia)&&(0,Y.jsxs)(`div`,{className:`client-tool-recoveries`,children:[tr.error&&(0,Y.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:tr.error,children:[(0,Y.jsx)(se,{size:15}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:u(`editor.harperRecoveryTitle`)}),u(`editor.harperFallbackHint`)]}),(0,Y.jsx)(`div`,{className:`client-tool-recovery-actions`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:tr.retry,children:u(`common.retry`)})}),(0,Y.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:tr.dismissError,children:(0,Y.jsx)(B,{size:13})})]}),er.error&&(0,Y.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:er.error,children:[(0,Y.jsx)(se,{size:15}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:u(`chktex.recoveryTitle`)}),u(`chktex.recoveryHint`)]}),(0,Y.jsx)(`div`,{className:`client-tool-recovery-actions`,children:(0,Y.jsx)(`button`,{type:`button`,onClick:er.retry,children:u(`common.retry`)})}),(0,Y.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:er.dismissError,children:(0,Y.jsx)(B,{size:13})})]}),Vt&&(0,Y.jsxs)(`div`,{className:`client-tool-recovery`,role:`alert`,title:Vt.detail,children:[(0,Y.jsx)(se,{size:15}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`strong`,{children:u(Vt.kind===`format`?`editor.texFmtOptionsRecoveryTitle`:Vt.kind===`load`?`editor.texFmtRecoveryTitle`:`editor.texFmtRuntimeRecoveryTitle`)}),u(`editor.clientToolRecoveryHint`)]}),(0,Y.jsxs)(`div`,{className:`client-tool-recovery-actions`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:zt||Pa,onClick:()=>ya(),children:u(`common.retry`)}),Vt.kind===`format`&&Gt.texFmtConfig.trim()&&(0,Y.jsx)(`button`,{type:`button`,disabled:zt||Pa,onClick:()=>ya(!0),children:u(`editor.resetFormatterOptions`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:u(`common.reload`)})]}),(0,Y.jsx)(`button`,{type:`button`,className:`formatter-diagnostics-dismiss`,title:u(`common.close`),"aria-label":u(`common.close`),onClick:()=>Ht(null),children:(0,Y.jsx)(B,{size:13})})]}),Ia&&(0,Y.jsxs)(`div`,{className:`client-tool-recovery format-lease-status`,role:`status`,children:[(0,Y.jsx)(Le,{className:`spin`,size:15}),(0,Y.jsx)(`span`,{children:u(`editor.formattingBy`,{name:Ia.holderName})})]})]}),kn&&(0,Y.jsxs)(`div`,{className:`client-tool-recovery`,role:`status`,children:[(0,Y.jsx)(se,{size:15}),(0,Y.jsx)(`span`,{children:u(`history.saveWarning`)})]}),Ve&&(0,Y.jsx)(`div`,{className:`toast`,onClick:()=>W(``),children:Ve}),We&&(0,Y.jsx)(`div`,{className:`toast success`,onClick:()=>G(``),children:We}),(0,Y.jsxs)(we,{orientation:`horizontal`,className:`work-grid`,...Ea,children:[wa&&(0,Y.jsx)(Oe,{phoneDrawer:Te?{open:ze,onClose:()=>Be(!1)}:void 0,project:T,filesPanel:Zt,visibleEntries:ei,deletedPath:On?.kind===`delete`?On.path:null,activeFile:N,activeMainFile:F,selectedFile:Pr,selectedFolder:Mr,expandedFolders:Ir,fileDragActive:Kr,uploadingFiles:Xr,uploadFeedback:Zr,readOnly:Pa,formatting:zt,canFormat:Iu(N),activeFormatLease:!!Fa,collaborationSynced:X,editorFontSize:Gt.fontSize,outline:Sa,sourceCursorStore:ge,wordCountBusy:Nt,hasSelection:!!Ke.selectedText.trim()&&/\.(?:tex|sty|cls)$/i.test(N),hasFormatSelection:!!Ke.selectedText.trim(),uploadInput:Xt,setSelectedFolder:Nr,setExpandedFolders:Lr,setMoveEntry:zr,setMoveName:Vr,setMoveDestination:Ur,setDeleteEntry:Gr,setFileDialogError:jr,setNewFolderName:kr,setNewFolderOpen:Dr,setNewFilePath:xr,setNewFileOpen:yr,setQuickOpen:wt,onProjectSearch:()=>Et(!0),setFileDragActive:qr,dismissUploadFeedback:Qr,setFilesCollapsed:ut,onError:W,uploadFiles:ri,upload:ii,openFile:e=>{ai(e),Te&&Be(!1)},movePathToFolder:si,onFormatFile:()=>void ur(),onFormatSelection:()=>void pr(),jumpToSource:(...e)=>{Yn(...e),Te&&Be(!1)},syncSourceToPdf:Xn,onWordCount:e=>void sr(e)}),wa&&!Te&&(0,Y.jsx)(De,{className:`resize-handle`,children:(0,Y.jsx)(pe,{size:12})}),wa&&(0,Y.jsx)(fh,{mobileSync:Te&&Ze!==`comments`?Ne?{disabled:ce!==N,onClick:Ya,label:u(`editor.markdown.showInPreview`)}:{disabled:!Qi||!Ka,onClick:Ja}:void 0,terminal:p?({maximized:e,toggleMaximized:t})=>(0,Y.jsx)(J.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`agent-task-empty`,children:(0,Y.jsx)(Le,{className:`spin`,size:18})}),children:(0,Y.jsx)(Og,{projectId:n,readOnly:Pa,onHide:()=>m(!1),maximized:e,onToggleMaximized:t,review:h,activeChangeId:g,onShowChange:Oa,reviewFocus:C})}):null,project:T,projectId:n,activeFile:N,mainFile:F,openTabs:qt,content:L,loadedFile:ce,readOnly:Pa,comments:fi,focusComment:Ti,editorPreferences:Gt,completionIndex:A,nativeSpellCheck:tr.nativeFallback,spellCheckIssues:tr.issues,spellCheckJump:tr.jump,sourceJump:Gn,collaborativeText:Ba,collaborationAwareness:c.awareness,undoManager:N?c.getUndoManager(N):void 0,editorNotice:la,activateTab:Za,closeTab:Sn,handleTabKeyDown:$a,updateEditorContent:nr,setSelection:(e,t,n)=>Xe({selectedText:e,startOffset:t,endOffset:n}),onAddComment:(e,t,n,r)=>Oi({selectedText:e,startOffset:t,endOffset:n},r),onSelectionHistory:(e,t,n,r)=>{vt({filePath:N,selection:{selectedText:e,startOffset:t,endOffset:n},source:r})},onCommentClick:Zi,onSpellCheckReplace:La,onReferenceNavigate:Ma,onCursor:bn,agentChanges:ja,activeAgentChangeId:g,agentChangeReveal:b?.path===N?b:null,onAgentChangesStale:h.refreshSoon,onOpenAgentChange:ka?Aa:void 0}),Ta&&(0,Y.jsx)(Ih,{mobileSync:Te,commentsOpen:Ze===`comments`,onCommentsHost:et,projectId:n,activeMainFile:F,previewTab:Pe,diagnosticTab:ye,pdfUrl:Qi,pdfLoadingMode:ta,pdfLoading:na,pdfCompiledAt:$i,pdfSizeBytes:ea,pdfCompiledLabel:Va,pdfTargetLabel:Ha,pdfDownloadUrl:Wa,pdfTarget:Un,pdfViewport:Wn,activeFile:N,compileBusy:za,compileLog:ra,compileDiagnostics:ia,compileMessages:Ca,artifacts:oa,artifactPreview:sa,artifactLoading:ca,cleaning:fa,readOnly:Pa,collaborationSynced:X,workspaceLayout:Se,showSyncResize:wa&&Ta,diagnosticCount:Ua,selectPreviewTab:Fe,markdown:Xa,changeWorkspaceLayout:Da,onSetPdfViewport:Kn,onResetPdfViewport:qn,onPdfDisplayed:_a,syncVisiblePdfToSource:Qn,syncCurrentSourceToPdf:Ja,syncPdfToSource:Zn,canSyncWithPdf:Ka,canSyncPdfToSource:qa,files:hr,jumpToSource:Yn,onSetCleanMode:St,viewArtifact:ga}),(0,Y.jsx)(Sg,{phone:Te,commentsHost:Ta?$e:void 0,sidePanel:Ze,onClose:()=>Qe(null),project:T,projectId:n,site:e,files:hr,currentUserId:t.id,comments:tt?fi:yi,commentDraftStore:Wi,commentsLoading:tt?gi:bi,commentsError:(tt?_i:xi)||Bn,onRetryComments:tt?vi:Si,activeFile:N,singleCommentId:tt,onShowAllComments:()=>{nt(null),wi(`project`)},hasProjectCommentsScope:Yi,commentScope:Ci,onCommentScopeChange:wi,focusedCommentId:st?.filePath===N?st.id:Ti?.id,commentFocusNonce:st?.nonce,onClearFocusComment:()=>{ct(null),Ei(null),it(null)},unreadMentions:zn,onMarkMentionRead:Vn,onMarkAllMentionsRead:Hn,targetCommentId:rt?.commentId,targetReplyId:rt?.replyId,onFocusComment:Xi,onToggleComment:Ri,onReplyComment:zi,onEditComment:Bi,onDeleteComment:Vi,onEditCommentReply:Hi,onDeleteCommentReply:Ui,dictionaryWords:O,onDictionaryChange:k,editorPreferences:Gt,onEditorPreferences:va,spellCheckCount:tr.summary?.total??null,spellCheckUniqueCount:tr.summary?.unique??null,spellCheckIndex:tr.summary?tr.index:-1,onSpellCheckNavigate:tr.jumpToIssue,onProject:li},n)]}),Dt&&(0,Y.jsx)(qe,{title:u(`editor.wordCountTitle`),onClose:()=>Ot(!1),children:(0,Y.jsx)(kg,{open:!0,mode:kt,path:jt,busy:Nt,error:Ft,result:Lt,onOpenChange:Ot})}),(0,Y.jsx)(gg,{projectSearchOpen:Tt,setProjectSearchOpen:Et,onSearchNavigate:(e,t,n)=>{Se===`pdf-only`&&Da(Te?`editor-only`:`editor-pdf`),Te&&Be(!1),Yn(e,t,n)},user:t,project:T,projectId:n,activeFile:N,content:L,maxCitationBibtexBytes:e.maxCitationBibtexBytes,files:hr,directoryEntries:$r,readOnly:Pa,resourcePreview:Sr,resourcePreviewLoading:wr,setResourcePreview:Cr,setResourcePreviewLoading:Tr,uploadConflict:Jr,setUploadConflict:Yr,dismissUploadFeedback:Qr,uploadFiles:ri,cleanMode:xt,setCleanMode:St,cleanCompile:ha,newFileOpen:vr,setNewFileOpen:yr,newFilePath:br,setNewFilePath:xr,newFolderOpen:Er,setNewFolderOpen:Dr,newFolderName:Or,setNewFolderName:kr,selectedFolder:Mr,fileDialogError:Ar,setFileDialogError:jr,createFile:ti,createFolder:ni,moveEntry:Rr,setMoveEntry:zr,moveName:Br,setMoveName:Vr,moveDestination:Hr,setMoveDestination:Ur,movePath:oi,deleteEntry:Wr,setDeleteEntry:Gr,deleteActiveSessions:Na,removePath:ci,commentOpen:Di,closeComment:ki,commentSelection:Mi,commentSuggestion:Ni,setCommentSuggestion:Pi,commentText:Ai,setCommentText:ji,commentSubmitting:Fi,cancelComment:Gi,commentDraftRestored:Ki,commentDraftCanRetarget:qi,useCurrentCommentSelection:Ji,commentError:Ii,addComment:Li,shareOpen:dt,setShareOpen:ft,onSharedMemberCountChange:D,citationLibraryOpen:yt,setCitationLibraryOpen:bt,insertCitationAtCursor:mr,quickOpen:Ct,setQuickOpen:wt,openFile:ai,selectionHistoryTarget:_t,closeSelectionHistory:()=>vt(null),historyOpen:ht,setHistoryOpen:gt,gitOpen:pt,setGitOpen:mt,save:or,permissionDowngrade:In,permissionDowngradeBusy:Ut,dismissPermissionDowngrade:Ln,discardPermissionDraft:ba})]})}export{rn as C,Ng as ProjectWorkspace,an as S,Dt as T,ss as _,Wm as a,Na as b,gu as c,fu as d,lu as f,rs as g,ls as h,ih as i,mu as l,us as m,qh as n,Pu as o,Is as p,oh as r,Fu as s,Dg as t,pu as u,ns as v,Lt as w,di as x,Ma as y};
|